Comments (6)
Thank to all which reply me. I found a solution.
newApplication is invoked before a new Activity is created and should invoked also when there is no activity but only a service.
Class<?> clsInstrumentation = findClass("android.app.Instrumentation", classLoader);
XposedBridge.hookAllMethods(instrumentation, "newApplication", new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param)
{
SharedPreferences spXMain = new RemotePreferences((Context)param.getResult(), Utils.PREFS, Utils.XMAIN);
// processHook((Context)param.getResult(), sPackageName, classLoader);
}
});
I do think we should have an official guide on "where do I get a
Context
instance from"
@apsun would be great
A quick question, did you look around if you could disable this check?
@MPeti1 I tried to analyze, but it wasn't easy for me
from remotepreferences.
Is the app you are hooking (and the class) having context as a parameter somewhere? If so, you can hook it to get context.
from remotepreferences.
It should have an Application Context in Application.onCreate()
, if I remember it correctly, but in cases it's not practical to wait until that. I'm not entirely sure why, but I remember thinking about this and not taking this path.
Edit: yeah, I'm starting #3 with why it's not a good idea. Basically it's because I need the preferences while handleLoadPackage()
is running, so I can read my settings so I can decide early if I want to hook something.
But now that I'm thinking about this, is it really needed? I could just hook everything where a that early hook is crucial, and when I receive some kind of context (from a hook made to do just that) in my settings class, I could unload hooks that are not actually needed.
Or an other solution would probably be making my own IPC capable services with Binder, but that's not done as easily as said, and even more I know of apps where it's been found that my phone (and apparently there are more) fails in the middle of transferring arrays, except when not but that's rare and still don't know what does it depend on.
from remotepreferences.
So I think this project is useless with *Posed and new Android if this check can't be disabled.
A quick question, did you look around if you could disable this check (possibly only for once every time you request it, so other apps couldn't abuse it)?
from remotepreferences.
From @MPeti1:
I could just hook everything where a that early hook is crucial, and when I receive some kind of context (from a hook made to do just that) in my settings class, I could unload hooks that are not actually needed.
This is the approach I would recommend. Hook everything, and decide what to do within the callback based on the preferences. I am not a fan of grabbing random context objects out of internal APIs exactly for this reason: they can and will break with system updates.
RemotePreferences isn't magic, it's just SharedPreferences
implemented on top of ContentResolver
. If Android says you can't use the "system context" with ContentResolver
, there isn't really much choice other than to either: a) change where you obtain the Context
, or b) use a different preference sharing solution that doesn't rely on Context
.
from remotepreferences.
I do think we should have an official guide on "where do I get a Context
instance from", since this is probably the most frequently asked question on this project. Obviously a "one-size-fits-all" approach would be ideal, like hooking Application.onCreate
and deferring all the initialization logic to there, although it's been so long since I've touched Xposed that I'm not even sure if that works.
from remotepreferences.
Related Issues (20)
- [QUESTION] How to get preferences from Android system package? HOT 6
- I don't understand how to declare "context" HOT 2
- Android 10 return default value HOT 8
- Exception thrown when accessing preferences from Xposed (Android 11) HOT 10
- [Please Delete] Non-issue. HOT 2
- No exception thrown when Key is NULL HOT 2
- Unable to get provider HOT 9
- Move away from jcenter HOT 2
- Is it Solve Xsharedpreference Canβt Access Preference XML HOT 3
- App closed when try to use RemotePreference HOT 5
- Variable preference name? HOT 5
- Does not work when trying to access via Xposed on an app targeting Android 11 HOT 16
- multiple apps use the library but they have same authority for a content provider, which creates conflict HOT 1
- Android 13:RemotePreferenceAccessException: query() failed or returned null cursor HOT 1
- Doesn't work in initZygote
- [Question] RemotePreferences not loaded after Android reboot HOT 4
- Cannot get preferences when application get killed HOT 6
- Should checkAccess check for the preferences owner package? HOT 4
- Unable to launch app **** for provider **** process is bad HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from remotepreferences.