apsun / RemotePreferences

A drop-in solution for inter-app access to SharedPreferences.
MIT License
138 stars 32 forks source link

Cannot get preferences when application get killed #7

Closed chengxuncc closed 5 years ago

chengxuncc commented 5 years ago

I test a demo, it work great while app is running, which was configured contentProvider. But when I kill the app, RemotePreferences cannot ruturn correct preferences. If on strict mode, it will throw Exception:

Caused by: com.crossbowffs.remotepreferences.RemotePreferenceAccessException: query() failed or returned null cursor
        at com.crossbowffs.remotepreferences.RemotePreferences.query(RemotePreferences.java:190)
        at com.crossbowffs.remotepreferences.RemotePreferences.querySingle(RemotePreferences.java:233)
        at com.crossbowffs.remotepreferences.RemotePreferences.getInt(RemotePreferences.java:92)
...
Caused by: com.crossbowffs.remotepreferences.RemotePreferenceAccessException: java.lang.SecurityException: Isolated process not allowed to call getContentProvider
        at com.crossbowffs.remotepreferences.RemotePreferences.wrapException(RemotePreferences.java:169)
        at com.crossbowffs.remotepreferences.RemotePreferences.query(RemotePreferences.java:187)
        at com.crossbowffs.remotepreferences.RemotePreferences.querySingle(RemotePreferences.java:233)
        at com.crossbowffs.remotepreferences.RemotePreferences.getInt(RemotePreferences.java:92)

I'm using Android 8.0 Oreo, and I had try device encrypted preferences described on README.

apsun commented 5 years ago

What is "the app", the one implementing the RemotePreferenceProvider or the one using RemotePreferences? And by kill do you mean removing the app from the app switcher, or force stopping the app, or something else?

I can't tell if this is one exception or two, can you post the full logs and the demo you are testing, if possible? Thanks!

chengxuncc commented 5 years ago

The app is the one implementing the RemotePreferenceProvider, and I am writing a Xposed module. When I kill the Xposed module application from either app switcher or force stopping, other hooked apps that using RemotePreferences to get preferences will not work.

apsun commented 5 years ago

What phone/ROM are you using? I ask because some phones will disable providers if you quit the app (to "save battery").

chengxuncc commented 5 years ago

oneplus 3 H2OS

apsun commented 5 years ago

OnePlus has a particularly bad track record (I would know, I used to use a 3T). Disable battery optimization for the app and see if that fixes it.

chengxuncc commented 5 years ago

Although I had disabled battery optimization, it still not working when got killed. Maybe I should find an another way.