XposedBridge icon indicating copy to clipboard operation
XposedBridge copied to clipboard

Any place to store world readable preferences on Nougat?

Open bluesky139 opened this issue 7 years ago • 10 comments

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?

bluesky139 avatar Oct 14 '17 12:10 bluesky139

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?

aviraxp avatar Oct 14 '17 13:10 aviraxp

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.

bluesky139 avatar Oct 14 '17 13:10 bluesky139

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()

C3C0 avatar Oct 14 '17 15:10 C3C0

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 avatar Oct 15 '17 00:10 bluesky139

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?

bluesky139 avatar Oct 15 '17 15:10 bluesky139

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

C3C0 avatar Oct 15 '17 15:10 C3C0

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

bluesky139 avatar Oct 16 '17 00:10 bluesky139

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

bluesky139 avatar Oct 28 '17 00:10 bluesky139

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.

zhougy0717 avatar Jan 19 '18 03:01 zhougy0717

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

chengxuncc avatar Apr 25 '19 19:04 chengxuncc