question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[INFO] java.lang.SecurityException: Given calling package android does not match caller's uid

See original GitHub issue

I don’t know it’s a real issue of RemotePreferences, I report for info to other users. With Xposed and similar projects, it is not possible to have the Context of hooked application, thank to @MPeti1 and the info in issue #3 there was a good alternative for old versions of Android.

Context systemContext = (Context) XposedHelpers.callMethod( XposedHelpers.callStaticMethod( XposedHelpers.findClass("android.app.ActivityThread", loadPackageParam.classLoader), "currentActivityThread"), "getSystemContext" );

With this row we can get the context of package “android” and is good for create the object RemotePreferences. With Android 8 and 8.1, the context “android” can query the Provider without exception. I’m testing an old module which use RemotePreferences on Android 10 (LineageOS 17.1) and LSPosed, but everytime my module from handleLoadPackage try to query the provider I got this exception:


java.lang.SecurityException: Given calling package android does not match caller's uid 10161
 	at android.os.Parcel.createException(Parcel.java:2071)
 	at android.os.Parcel.readException(Parcel.java:2039)
 	at android.os.Parcel.readException(Parcel.java:1987)
 	at android.app.IActivityManager$Stub$Proxy.getContentProvider(IActivityManager.java:5056)
 	at android.app.ActivityThread.acquireProvider(ActivityThread.java:6561)
 	at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2725)
 	at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:2117)
 	at android.content.ContentResolver.query(ContentResolver.java:928)
 	at android.content.ContentResolver.query(ContentResolver.java:880)
 	at android.content.ContentResolver.query(ContentResolver.java:836)
 	at com.crossbowffs.remotepreferences.RemotePreferences.query(RemotePreferences.java:214)
 	at com.crossbowffs.remotepreferences.RemotePreferences.querySingle(RemotePreferences.java:263)
 	at com.crossbowffs.remotepreferences.RemotePreferences.getBoolean(RemotePreferences.java:135)

I tried to set strictmode to true without success, I tried the solution in issue #12 setExecutable(true, false) and setReadable(true, false) without success. Android check the name of package in context (“android”) and the uid of caller (my hooked application) and with mismatch throw an exception.

So I think this project is useless with *Posed and new Android if this check can’t be disabled.

From Readme: "This library was developed to simplify Xposed module preference access. " In the past sure, now not more.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
ghostcommented, Mar 26, 2021

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

1reaction
aviraxpcommented, Mar 24, 2021

Is the app you are hooking (and the class) having context as a parameter somewhere? If so, you can hook it to get context.

See https://github.com/apsun/NekoSMS/blob/82205ebed9cd57fd59a59457d2a65b10a5e17751/app/src/main/java/com/crossbowffs/nekosms/xposed/SmsHandlerHook.java#L182

Read more comments on GitHub >

github_iconTop Results From Across the Web

Securityexception "given calling package does not match ...
This occurs in XPrivacyLua v1.27 on Android 10 inside the VirtualXposed v0.18.2. THIS DEVICE HAS A RECENTLY UPDATED SECURITY PATCH ! (Feb/2021)
Read more >
java.lang.SecurityException: Package com.android.phone (uid ...
Android: java.lang.SecurityException: Package com.android.phone (uid=1001) does not match provided uid 10246 · Ask Question.
Read more >
java.lang.SecurityException: caller uid 10109 is different than ...
Got this completing J-PAKE setup on Galaxy S2, Android 2.3.4. E/AndroidRuntime( 5446): FATAL EXCEPTION: Timer-0 E/AndroidRuntime( 5446): java.lang.
Read more >
SecurityException: Package android does not belong to Uid
I can confirm that this happens when the app is in background, probably woken up by WorkManager or a reboot Broadcast receiver &...
Read more >
caller uid xxxx is different than the authenticator's uid after App ...
MainActivity}: java.lang.SecurityException: caller uid 10113 is different than the authenticator's uid at android.app.ActivityThread.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found