RikkaApps / Shizuku

Using system APIs directly with adb/root privileges from normal apps through a Java process started with app_process.
Apache License 2.0
11.34k stars 652 forks source link

Android 13 Compatibility #191

Closed KieronQuinn closed 2 years ago

KieronQuinn commented 2 years ago

Please report bugs of Shizuku itself.

Requirements:

Change "[ ]" to "[x]" if it meets the requirements.

Reports not meet the requirements will be immediately closed.

Information:

Logs:

Relevant lines:

02-11 00:14:31.010 31841 31841 I Service : starting server... 02-11 00:14:31.011 31841 31841 I shizuku_server: System.exit called, status: 50 02-11 00:14:31.011 31841 31841 I AndroidRuntime: VM exiting with result code 50.

Related full logcat.

Describe the bug:

In Android 13 the method signature for IPackageManager.getApplicationInfo has changed from

ApplicationInfo getApplicationInfo(String packageName, int flags, int userId)
            throws RemoteException;

to

ApplicationInfo getApplicationInfo(String packageName, long flags, int userId)
            throws RemoteException;

This causes the server to not find the manager, and thus exit with code 50. Changing the method signature (simply casting to long) fixes it, and I would make a PR, except it's not pretty:

@Nullable
public static ApplicationInfo getApplicationInfo(@Nullable String packageName, int flags, int userId) throws RemoteException {
    int SDK = Build.VERSION.SDK_INT;
    int PREVIEW_SDK = SDK >= 23 ? Build.VERSION.PREVIEW_SDK_INT : 0;
    if(SDK >= 33 || SDK == 32 && PREVIEW_SDK > 0) {
        return packageManager.getService().getApplicationInfo(packageName, (long) flags, userId);
    }else{
        return packageManager.getService().getApplicationInfo(packageName, flags, userId);
    }
}

Of course, there are SDK checks in BuildUtils.java in the common module, but this module is not a dependency for the server, and is tagged with a todo to be replaced with rikka.core.util.BuildUtils, so I suggest it might be a good time to do that migration and use it in the server at the same time instead.

Additional context:

The suggested fix works on 13 DP1:

image

KieronQuinn commented 2 years ago

With further testing, it seems that while the server can now start, apps are unable to request permissions or connect to the service. There's probably been some more method signature changes.

RikkaW commented 2 years ago

About rikka.core.util.BuildUtils, rikka.core.util.BuildUtils use kotlin inline, but Android Studio lint cannot recogonize it, so actually I want to replace it with normal Build.VERSION.SDK_INT (and androidx.core.os.BuildCompat for preview systems).

KieronQuinn commented 2 years ago

Fixed in b09ac2580045ce182d49b4cf17cd5bf8fdf805f3, thank you!