Why do I need the WRITE_EXTERNAL_STORAGE permission with getExternalCacheDir() on Android Lollipop? -
my app writes (and reads) cache files getexternalcachedir() location. before android lollipop (api 21) i've been using permission success:
<uses-permission android:name="android.permission.write_external_storage" android:maxsdkversion="18" />
the maxsdkversion there because permission shouldn't needed after api v18: http://developer.android.com/reference/android/manifest.permission.html#write_external_storage
but on android lollipop (5.0) i'm getting access permission (with log output show actual path used):
11-19 13:01:59.257 4462-4541/com.murrayc.galaxyzoo.app e/android-galaxyzoo﹕ createcachefile(): ioexception filename=/storage/emulated/0/android/data/com.murrayc.galaxyzoo.app/cache/52 java.io.ioexception: open failed: eacces (permission denied) @ java.io.file.createnewfile(file.java:941) @ com.murrayc.galaxyzoo.app.provider.itemscontentprovider.createcachefile(itemscontentprovider.java:528)
i see both in emulator , on nexus 4. has changed, or doing wrong along? want access own app's cache.
update: see on device (nexus 4 running standard android 5.1.1, has had fresh android reflash since first had problem). no longer see in emulator - of course system images have been updated several times.
we've seen same behaviour on api 21 (lollipop) on nexus 5:
java.io.filenotfoundexception: /storage/emulated/0/android/data/[package name]/cache/http/journal.tmp: open failed: eacces (permission denied) @ libcore.io.iobridge.open(iobridge.java:456) @ java.io.fileoutputstream.<init>(fileoutputstream.java:87) @ java.io.fileoutputstream.<init>(fileoutputstream.java:72) @ com.android.okhttp.internal.disklrucache.rebuildjournal(disklrucache.java:346) @ com.android.okhttp.internal.disklrucache.open(disklrucache.java:239) @ com.android.okhttp.httpresponsecache.<init>(httpresponsecache.java:140) @ android.net.http.httpresponsecache.install(httpresponsecache.java:199) ... @ android.app.instrumentation.callapplicationoncreate(instrumentation.java:1011) @ android.app.activitythread.handlebindapplication(activitythread.java:4518) @ android.app.activitythread.access$1500(activitythread.java:144) @ android.app.activitythread$h.handlemessage(activitythread.java:1339) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:135) @ android.app.activitythread.main(activitythread.java:5221) @ java.lang.reflect.method.invoke(method.java) @ java.lang.reflect.method.invoke(method.java:372) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:899) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:694) caused by: android.system.errnoexception: open failed: eacces (permission denied) @ libcore.io.posix.open(posix.java) @ libcore.io.blockguardos.open(blockguardos.java:186) @ libcore.io.iobridge.open(iobridge.java:442) @ java.io.fileoutputstream.<init>(fileoutputstream.java:87) @ java.io.fileoutputstream.<init>(fileoutputstream.java:72) @ com.android.okhttp.internal.disklrucache.rebuildjournal(disklrucache.java:346) @ com.android.okhttp.internal.disklrucache.open(disklrucache.java:239) @ com.android.okhttp.httpresponsecache.<init>(httpresponsecache.java:140) @ android.net.http.httpresponsecache.install(httpresponsecache.java:199) ... @ android.app.instrumentation.callapplicationoncreate(instrumentation.java:1011) @ android.app.activitythread.handlebindapplication(activitythread.java:4518) @ android.app.activitythread.access$1500(activitythread.java:144) @ android.app.activitythread$h.handlemessage(activitythread.java:1339) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:135) @ android.app.activitythread.main(activitythread.java:5221) @ java.lang.reflect.method.invoke(method.java) @ java.lang.reflect.method.invoke(method.java:372) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:899) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:694)
until google push android 5.0 aosp won't able work out if bug or deliberate (but undocumented) change, i've raised bug regardless: https://code.google.com/p/android/issues/detail?id=81357
adding write_external_storage permission prevents above exception being thrown, require end user permission upgrade existing apps. since our app doesn't use permission , don't want add it, we're falling using internal cache except kitkat devices.
as aside, found interesting background changes introduced in kitkat: http://www.doubleencore.com/2014/03/android-external-storage/
Comments
Post a Comment