rovo89 / XposedBridge

The Java part of the Xposed framework.
3.91k stars 1.11k forks source link

Any place to store world readable preferences on Nougat? #206

Open bluesky139 opened 7 years ago

bluesky139 commented 7 years ago

I've updated to Android 7.1.2 with Xposed v88 recently, I want to hook system method, yes, package name is android, but I need to read preferences.

I tried to put preferences in /data/data/[package name]/shared_prefs/xxx.xml or /data/user_de/0/[package name]/shared_prefs/xxx.xml, and modify permission to 664 (checked it still be 664 after reboot), it can't be read in initZygote() or handleLoadPackage().

I can't use content provider (something like RemotePreferences) to provide preferences, because system it not boot up yet.

Or find a way to put it in /data/system?

aviraxp commented 7 years ago

Weird enough that my module still works without any changes, at least in handleLoadPackage(), But maybe you want to look at https://github.com/GravityBox/GravityBox/commit/d825b7be445c18de9a90eb8f77c1c5eb2b74deb8?

bluesky139 commented 7 years ago

I already checked GravityBox, they put it in /data/user_de/, but I tried with failure.

I don't know if it's a problem related to my ROM. My device is Nexus 5, flashed latest RR ROM, it's based on CM ROM.

I can read it on Genymotion simulator.

I also think it's weird, maybe I have to try another ROM? I don't know how to investigate more.

C3C0 commented 7 years ago

It's been reported by some of my users that there are strange issues with Device Protected Storage on Lineage and possibly other derivatives like RR. I don't have additional details as I didn't do any tests on custom ROMs myself. @bluesky139 Also note that if you use settings activity together with its SharedPreferences you have to tell preference manager to use Protected Storage. getPreferenceManager().setStorageDeviceProtected()

bluesky139 commented 7 years ago

Thanks @C3C0 I have used setStorageDeviceProtected(), then preferences will be stored in /data/user_de/.

And, plus your report, my guess is all Lineage users have this problem.

bluesky139 commented 7 years ago

OK, I think I figured out something, but I don't know why.

I noticed this folder /data/user_de/0/[package name] is 700 permission, if I changed it to 711, then I can read preferences in handleLoadPackage().

Why need "execute" permission on this folder?

C3C0 commented 7 years ago

Execute permission on a folder is needed for others to be able to descend into it and access files and subfolders.

bluesky139 commented 7 years ago

Even though, it still can't be accessed in initZygote(), but at least I can use it in handleLoadPackage().

bluesky139 commented 7 years ago

More weird thing happened, I'm using File.canRead() to check preferences readability, it returns false, but if I use XSharedPreferences to get value by key, it returns right value.

File file = new File(Prefs.PATH); Logger.d("file exists " + file.exists() + ", read " + file.canRead()); // false XSharedPreferences xprefs = new XSharedPreferences(file); Logger.d("read pref " + xprefs.getBoolean("xxx", false)); // true

zhougy0717 commented 6 years ago

I don't know your special case. As C3C0 said, you need to set up correct permission on the package folder and also the preference.xml. Then you should be unblocked. The typical setting for the package folder is 711 and for the preference file is 664.

chengxuncc commented 5 years ago

I write a file based SharedPreferences library, it work for me: FileSharedPreferences