rovo89 / XposedBridge

The Java part of the Xposed framework.
3.89k stars 1.1k forks source link

about shardpreferences reload #149

Closed netstu closed 7 years ago

netstu commented 7 years ago

I do not want to use the reload function of sharedpreferences, because in xposed I need to read the sharedpreferences very frequently, so I want the value of sharedpreferences one-time load into memory, do not know how to do?

That is, to modify the configuration does not need to restart the phone case to achieve

rovo89 commented 7 years ago

So you don't want to reload the preferences, but you always want to have the latest values? That's kind of contradictory...

If you want to stick to XSharedPreferences, you could do some kind of rate-limiting. For example, you could create a reload function remembers when the last reload was done. If the data was reloaded within the last second, you skip any further reloads. That way, you get a rather easy trade-off between performance and waiting times.

MolotovCherry commented 7 years ago

Just curious, but couldn't handling of XSharedPreferences be more efficient if it implemented (or at least had the option to) some kind of system where it watched was able to watch for the file changes and execute a callback rather than having to reload it all the time?

In Android docs I found the FileObserver class.. Certainly beats having to check it every x seconds.

OP could also probably implement this FileObserver functionality himself.

rovo89 commented 7 years ago

XSharedPreferences is actually very complex because it needs to work around SELinux restrictions. You usually wouldn't be able to access the preferences files, so it uses various services, binders etc. to load the file. That wouldn't work with callbacks. Besides that, I'm not sure whether FileObserver uses threads, which wouldn't work in some places (like Zygote).