Crashes when using same preferences in different applications
VRiznyk opened this issue · 2 comments
I have a pool of apps and try to share data between them.
Binaryprefs uses in the library for sharing codebase between apps. So dependency ladder looks like
binaryprefs -> lib -> app1
binaryprefs -> lib -> app2
build.gradle (module lib):
compile "com.github.iamironz:binaryprefs:1.0.0-BETA-2"
creating instance in lib:
public class BinaryPreferenceHelper {
private static final String PREF_NAME = "intercom_options";
private static final String DIRECTORY_PATH = "dnake/cfg";
public static Preferences getPreferencesInstance(Context context){
return new BinaryPreferencesBuilder(context)
.name(PREF_NAME)
.customDirectory(new File(DIRECTORY_PATH))
.keyEncryption(KeyEncryption.NO_OP)
.valueEncryption(ValueEncryption.NO_OP)
.supportInterProcess(true)
.build();
}
}
instances init in app1 and app2 classes like this:
public class DesktopApp extends Application {
private static Preferences sSetting;
public static Preferences getSetting() {
return sSetting;
}
@Override
public void onCreate() {
super.onCreate();
sSetting = BinaryPreferenceHelper.getPreferencesInstance(this);
}
}
using in apps like this:
mIsUnit = IntercomOptions.MonitorMode.get(TalkApp.getSetting());
where
public static class MonitorMode {
public static boolean get(Preferences preferences) {
return preferences.getBoolean("pref_monitor_mode", false);
}
public static void set(Preferences preferences, boolean isUnit) {
preferences.edit().putBoolean("pref_monitor_mode", isUnit).apply();
}
}
and if I open firs app everything is ok, but when I run second, I'll get a crash:
java.lang.RuntimeException: Unable to create application com.dnake.talk.TalkApp: com.ironz.binaryprefs.exception.FileOperationException: java.util.concurrent.ExecutionException: com.ironz.binaryprefs.exception.FileOperationException: java.io.FileNotFoundException: /dnake/cfg/preferences/intercom_options/values/pref_monitor_mode: open failed: EACCES (Permission denied) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4347) at android.app.ActivityThread.access$1500(ActivityThread.java:135) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5017) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) at dalvik.system.NativeStart.main(Native Method) Caused by: com.ironz.binaryprefs.exception.FileOperationException: java.util.concurrent.ExecutionException: com.ironz.binaryprefs.exception.FileOperationException: java.io.FileNotFoundException: /dnake/cfg/preferences/intercom_options/values/pref_monitor_mode: open failed: EACCES (Permission denied) at com.ironz.binaryprefs.task.FutureBarrier.completeBlockingUnsafe(FutureBarrier.java:44) at com.ironz.binaryprefs.BinaryPreferences.fetchCache(BinaryPreferences.java:52) at com.ironz.binaryprefs.BinaryPreferences.<init>(BinaryPreferences.java:40) at com.ironz.binaryprefs.BinaryPreferencesBuilder.createInstance(BinaryPreferencesBuilder.java:251) at com.ironz.binaryprefs.BinaryPreferencesBuilder.build(BinaryPreferencesBuilder.java:226) at com.basip.intercom.binary.BinaryPreferenceHelper.getPreferencesInstance(BinaryPreferenceHelper.java:25) at com.dnake.talk.TalkApp.onCreate(TalkApp.java:20) at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4344) at android.app.ActivityThread.access$1500(ActivityThread.java:135) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5017) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) at dalvik.system.NativeStart.main(Native Method) Caused by: java.util.concurrent.ExecutionException: com.ironz.binaryprefs.exception.FileOperationException: java.io.FileNotFoundException: /dnake/cfg/preferences/intercom_options/values/pref_monitor_mode: open failed: EACCES (Permission denied) at java.util.concurrent.FutureTask.report(FutureTask.java:93) at java.util.concurrent.FutureTask.get(FutureTask.java:163) at com.ironz.binaryprefs.task.FutureBarrier.completeBlockingUnsafe(FutureBarrier.java:42) at com.ironz.binaryprefs.BinaryPreferences.fetchCache(BinaryPreferences.java:52) at com.ironz.binaryprefs.BinaryPreferences.<init>(BinaryPreferences.java:40) at com.ironz.binaryprefs.BinaryPreferencesBuilder.createInstance(BinaryPreferencesBuilder.java:251) at com.ironz.binaryprefs.BinaryPreferencesBuilder.build(BinaryPreferencesBuilder.java:226) at com.basip.intercom.binary.BinaryPreferenceHelper.getPreferencesInstance(BinaryPreferenceHelper.java:25) at com.dnake.talk.TalkApp.onCreate(TalkApp.java:20) at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4344) at android.app.ActivityThread.access$1500(ActivityThread.java:135) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5017) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) at dalvik.system.NativeStart.main(Native Method) Caused by: com.ironz.binaryprefs.exception.FileOperationException: java.io.FileNotFoundException: /dnake/cfg/preferences/intercom_options/values/pref_monitor_mode: open failed: EACCES (Permission denied) at com.ironz.binaryprefs.file.adapter.NioFileAdapter.fetchInternal(NioFileAdapter.java:77) at com.ironz.binaryprefs.file.adapter.NioFileAdapter.fetchBackupOrOriginal(NioFileAdapter.java:62) at com.ironz.binaryprefs.file.adapter.NioFileAdapter.fetch(NioFileAdapter.java:52) at com.ironz.binaryprefs.file.transaction.MultiProcessTransactionImpl.fetchInternal(MultiProcessTransactionImpl.java:55) at com.ironz.binaryprefs.file.transaction.MultiProcessTransactionImpl.fetch(MultiProcessTransactionImpl.java:34) at com.ironz.binaryprefs.BinaryPreferences.fetchInternal(BinaryPreferences.java:62) at com.ironz.binaryprefs.BinaryPreferences.access$000(BinaryPreferences.java:17) at com.ironz.binaryprefs.BinaryPreferences$1.run(BinaryPreferences.java:49) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) at java.lang.Thread.run(Thread.java:841) Caused by: java.io.FileNotFoundException: /dnake/cfg/preferences/intercom_opt
Hello Volodymyr! Thanks for issue submitting. It will be processed ass soon as possible.
Regards,
Alexander.
@VRiznyk Thanks for waiting, it's looks like appropriate WRITE_EXTERNAL_STORAGE
permissions for one of the applications haven't defined yet. Please use following scheme:
<manifest>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
...
<application>
...
<activity>
...
</activity>
</application>
</manifest>
Also check for granted runtime permissions if you use API 23+.
And looks like your directory path is incorrect.
private static final String DIRECTORY_PATH = "dnake/cfg";
You should use following variant of directory:
File directory = new File(Environment.getExternalStorageDirectory().getAbsoluteFile(), "dnake/cfg");
of course you should grant WRITE_EXTERNAL_STORAGE
and runtime permission for API 23+ too.
Please let me know if issue was resolved.
Regards,
Alexander.