Thursday, December 31, 2015

Noob development question: avc permission denied { open } on zip file, Marshmallow

This question was also asked in StackOverflow by me. (http://ift.tt/1SpogqZ)

My apologies if this has been asked, but the only articles/threads for SELinux explained the policies and didn't have a procedure on Android, OR were not for Android.

Currently writing an app where content (in a small zip file) is downloaded from an external location and stored inside /data/data/package_name_removed/user1/, to be read later.

I currently have a zip file in that directory "Test.zip".

A try-catch loop containing:

Code:

//where filename is Test.zip
//and userDir = "user1"
//and sourceContext is passed from the base Activity calling this class that does not inherit Activity
Log.d("Target file is", sourceContext.getFilesDir()+"/"+userDir +"/"+ fileName);
File file = new File(sourceContext.getFilesDir()+"/"+userDir +"/"+ fileName);
ZipFile loadedFile = new ZipFile(file);

Doesn't seem to work in Marshmallow:

Code:

D/Target file is: /data/data/package_name_removed/files/user1/Test.zip
W/package_name_removed: type=1400 audit(0.0:11699): avc: denied { open } for name="Test.zip" dev="mmcblk0p29" ino=57426 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:app_data_file:s0 tclass=file permissive=0

"avc" is a SELINUX error according to the documentation.

This is a Log.d of the IOException getMessage; I think this one's generated from the new File() statement:

Code:

D/Log_title_omitted: /data/data/package_name_removed/files/user1/Test.zip: open failed: EACCES (Permission denied)
I'm pretty sure I do not need READ/WRITE_EXTERNAL_STORAGE at this point as I'm in a directory that is the app's personal directory, which the app is supposed to have access to anyway.

I don't think I should change SELINUX to Permissive in order for this to work, I can't guarantee this flag is set on any other device but mine.

Any help here? Or is the procedure now to get write permissions to a location that isn't guaranteed to exist?


via xda-developers http://ift.tt/1Spogr1

IFTTT

Put the internet to work for you.

Turn off or edit this Recipe

No comments:

Post a Comment