apsun / RemotePreferences

A drop-in solution for inter-app access to SharedPreferences.
MIT License
138 stars 32 forks source link

Android 13:RemotePreferenceAccessException: query() failed or returned null cursor #26

Closed xseruer closed 2 years ago

xseruer commented 2 years ago

Error Message :

2022-07-17 01:32:38.286 1646-3403/? W/WakePathChecker: MIUILOG-AutoStart, Service/Provider/Broadcast Reject userId= 0 caller= com.eg.android.******** callee= com.example.fuck*** classname=com.example.fuck***.utils.MyPreferenceProvider action=null wakeType=4
2022-07-17 01:32:38.286 15540-15540/? E/ActivityThread: Failed to find provider info for com.example.fuck***preferences
2022-07-17 01:32:38.287 15540-15540/? E/LSPosed-Bridge: com.crossbowffs.remotepreferences.RemotePreferenceAccessException: query() failed or returned null cursor
        at com.crossbowffs.remotepreferences.RemotePreferences.query(RemotePreferences.java:214)
        at com.crossbowffs.remotepreferences.RemotePreferences.queryAll(RemotePreferences.java:290)
        at com.crossbowffs.remotepreferences.RemotePreferences.getAll(RemotePreferences.java:97)
        at com.example.fuck***.HookCore$1.afterHookedMethod(HookCore.java:54)
        at de.robv.android.xposed.XposedBridge$AdditionalHookInfo.callback(Unknown Source:147)
        at LSPHooker_.attachBaseContext(Unknown Source:11)
        at com.***.mobile.***.LauncherApplication.attachBaseContext(LauncherApplication.java:100008)
        at android.app.Application.attach(Application.java:333)
        at android.app.Instrumentation.newApplication(Instrumentation.java:1178)
        at android.app.LoadedApk.makeApplication(LoadedApk.java:1369)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7052)
        at android.app.ActivityThread.access$1600(ActivityThread.java:276)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2131)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loopOnce(Looper.java:210)
        at android.os.Looper.loop(Looper.java:299)
        at android.app.ActivityThread.main(ActivityThread.java:8291)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:556)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1045)

AndroidManifest.xml Code:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.fuck***">

    <queries>
        <provider android:authorities="${applicationId}.preferences" />
    </queries>

    <application
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:requestLegacyExternalStorage="true">

...

        <provider
            android:name=".utils.MyPreferenceProvider"
            android:authorities="${applicationId}.preferences"
            android:enabled="true"
            android:exported="true" />
    </application>
</manifest>

Xposed Hook Code:

  @Override
    public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
        if (!"com.android.****".equals(lpparam.packageName)) {
            return;
        }

        XposedHelpers.findAndHookMethod(ContextWrapper.class, "attachBaseContext", Context.class, new XC_MethodHook() {
            protected void afterHookedMethod(XC_MethodHook.MethodHookParam param) {
                Context context = (Context) param.args[0];
                RemotePreferences prefs = new RemotePreferences(context, Const.PROVIDER_AUTHORITIES, Const.PREFERENCE_FILE_NAME, true);

                // getString() is null, not work.
                XposedBridge.log("[xxx] read-conf CHECK_TIME:" + prefs.getString(Const.CHECK_TIME, "null"));
            }
        });
        XposedHelpers.findAndHookMethod(Activity.class, "onResume", new XC_MethodHook() {
            @Override
            protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                Context context = (Activity) param.thisObject;
                RemotePreferences prefs = new RemotePreferences(context, Const.PROVIDER_AUTHORITIES, Const.PREFERENCE_FILE_NAME, true);

                   // getString() is null, not work.
                XposedBridge.log("[xxx] read-conf CHECK_TIME1:" + prefs.getString(Const.CHECK_TIME, "null"));
            }
        });
    }
xseruer commented 2 years ago

I found the cause, the provider application must be active in the background. thks.