From b0d1e7a2bb357f539f0d41d0dfb55f483cdaec8a Mon Sep 17 00:00:00 2001 From: LoveSy Date: Fri, 11 Feb 2022 09:12:10 +0800 Subject: [PATCH] Support Android 13 DP1 (#1666) --- README.md | 2 +- core/magisk_module/module.prop | 2 +- .../lsposed/lspd/service/PackageService.java | 25 ++++++++++++------- .../android/content/pm/IPackageManager.java | 25 ++++++++++++++++++- 4 files changed, 42 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 2efaa7f7..a40a869f 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ A Riru module trying to provide an ART hooking framework which delivers consiste ## Supported Versions -Android 8.1 ~ 12, 12L Beta2 +Android 8.1 ~ 12, 12L Beta3, 13 DP1 ## Install diff --git a/core/magisk_module/module.prop b/core/magisk_module/module.prop index a3ab9f10..1299320e 100644 --- a/core/magisk_module/module.prop +++ b/core/magisk_module/module.prop @@ -3,5 +3,5 @@ name=${api} - LSPosed version=${versionName} (${versionCode}) versionCode=${versionCode} author=${authorList} -description=Another enhanced implementation of Xposed Framework. Supports Android 8.1 ~ 12, 12L Beta2. ${requirement}. +description=Another enhanced implementation of Xposed Framework. Supports Android 8.1 ~ 12, 12L Beta3, 13 DP1. ${requirement}. updateJson=${updateJson} diff --git a/daemon/src/main/java/org/lsposed/lspd/service/PackageService.java b/daemon/src/main/java/org/lsposed/lspd/service/PackageService.java index 979e3e29..4ce39c82 100644 --- a/daemon/src/main/java/org/lsposed/lspd/service/PackageService.java +++ b/daemon/src/main/java/org/lsposed/lspd/service/PackageService.java @@ -107,6 +107,9 @@ public class PackageService { public static PackageInfo getPackageInfo(String packageName, int flags, int userId) throws RemoteException { IPackageManager pm = getPackageManager(); if (pm == null) return null; + if (Build.VERSION.SDK_INT + Build.VERSION.PREVIEW_SDK_INT > Build.VERSION_CODES.S) { + return pm.getPackageInfo(packageName, (long) flags, userId); + } return pm.getPackageInfo(packageName, flags, userId); } @@ -116,7 +119,7 @@ public class PackageService { Map res = new HashMap<>(); if (pm == null) return res; for (var user : UserService.getUsers()) { - var info = pm.getPackageInfo(packageName, flags, user.id); + var info = getPackageInfo(packageName, flags, user.id); if (info != null && info.applicationInfo != null) res.put(user.id, info); } return res; @@ -125,6 +128,9 @@ public class PackageService { public static ApplicationInfo getApplicationInfo(String packageName, int flags, int userId) throws RemoteException { IPackageManager pm = getPackageManager(); if (pm == null) return null; + if (Build.VERSION.SDK_INT + Build.VERSION.PREVIEW_SDK_INT > Build.VERSION_CODES.S) { + return pm.getApplicationInfo(packageName, (long) flags, userId); + } return pm.getApplicationInfo(packageName, flags, userId); } @@ -135,7 +141,8 @@ public class PackageService { if (pm == null) return ParceledListSlice.emptyList(); for (var user : UserService.getUsers()) { // in case pkginfo of other users in primary user - res.addAll(pm.getInstalledPackages(flags, user.id).getList().parallelStream() + res.addAll((Build.VERSION.SDK_INT + Build.VERSION.PREVIEW_SDK_INT > Build.VERSION_CODES.S ? pm.getInstalledPackages((long) flags, user.id) : pm.getInstalledPackages(flags, user.id)) + .getList().parallelStream() .filter(info -> info.applicationInfo != null && info.applicationInfo.uid / PER_USER_RANGE == user.id) .filter(info -> { try { @@ -196,27 +203,27 @@ public class PackageService { if (pm == null) return null; PackageInfo pkgInfo; try { - pkgInfo = pm.getPackageInfo(packageName, flags | PackageManager.GET_ACTIVITIES | PackageManager.GET_SERVICES | PackageManager.GET_RECEIVERS | PackageManager.GET_PROVIDERS, userId); + pkgInfo = getPackageInfo(packageName, flags | PackageManager.GET_ACTIVITIES | PackageManager.GET_SERVICES | PackageManager.GET_RECEIVERS | PackageManager.GET_PROVIDERS, userId); } catch (Exception e) { - pkgInfo = pm.getPackageInfo(packageName, flags, userId); + pkgInfo = getPackageInfo(packageName, flags, userId); if (pkgInfo == null) return null; try { - pkgInfo.activities = pm.getPackageInfo(packageName, flags | PackageManager.GET_ACTIVITIES, userId).activities; + pkgInfo.activities = getPackageInfo(packageName, flags | PackageManager.GET_ACTIVITIES, userId).activities; } catch (Exception ignored) { } try { - pkgInfo.services = pm.getPackageInfo(packageName, flags | PackageManager.GET_SERVICES, userId).services; + pkgInfo.services = getPackageInfo(packageName, flags | PackageManager.GET_SERVICES, userId).services; } catch (Exception ignored) { } try { - pkgInfo.receivers = pm.getPackageInfo(packageName, flags | PackageManager.GET_RECEIVERS, userId).receivers; + pkgInfo.receivers = getPackageInfo(packageName, flags | PackageManager.GET_RECEIVERS, userId).receivers; } catch (Exception ignored) { } try { - pkgInfo.providers = pm.getPackageInfo(packageName, flags | PackageManager.GET_PROVIDERS, userId).providers; + pkgInfo.providers = getPackageInfo(packageName, flags | PackageManager.GET_PROVIDERS, userId).providers; } catch (Exception ignored) { } @@ -279,7 +286,7 @@ public class PackageService { public static ParceledListSlice queryIntentActivities(Intent intent, String resolvedType, int flags, int userId) throws RemoteException { IPackageManager pm = getPackageManager(); if (pm == null) return null; - return new ParceledListSlice<>(pm.queryIntentActivities(intent, resolvedType, flags, userId).getList()); + return new ParceledListSlice<>((Build.VERSION.SDK_INT + Build.VERSION.PREVIEW_SDK_INT > Build.VERSION_CODES.S ? pm.queryIntentActivities(intent, resolvedType, (long) flags, userId) : pm.queryIntentActivities(intent, resolvedType, flags, userId)).getList()); } public static Intent getLaunchIntentForPackage(String packageName) throws RemoteException { diff --git a/hiddenapi-stubs/src/main/java/android/content/pm/IPackageManager.java b/hiddenapi-stubs/src/main/java/android/content/pm/IPackageManager.java index 08c1cd75..36ef13dc 100644 --- a/hiddenapi-stubs/src/main/java/android/content/pm/IPackageManager.java +++ b/hiddenapi-stubs/src/main/java/android/content/pm/IPackageManager.java @@ -19,20 +19,39 @@ public interface IPackageManager extends IInterface { ApplicationInfo getApplicationInfo(String packageName, int flags, int userId) throws RemoteException; + @RequiresApi(33) + ApplicationInfo getApplicationInfo(String packageName, long flags, int userId) + throws RemoteException; + PackageInfo getPackageInfo(String packageName, int flags, int userId) throws RemoteException; + @RequiresApi(33) + PackageInfo getPackageInfo(String packageName, long flags, int userId) + throws RemoteException; + int getPackageUid(String packageName, int flags, int userId) throws RemoteException; + @RequiresApi(33) + int getPackageUid(String packageName, long flags, int userId) throws RemoteException; + String[] getPackagesForUid(int uid) throws RemoteException; ParceledListSlice getInstalledPackages(int flags, int userId) throws RemoteException; + @RequiresApi(33) + ParceledListSlice getInstalledPackages(long flags, int userId) + throws RemoteException; + ParceledListSlice getInstalledApplications(int flags, int userId) throws RemoteException; + @RequiresApi(33) + ParceledListSlice getInstalledApplications(long flags, int userId) + throws RemoteException; + int getUidForSharedUser(String sharedUserName) throws RemoteException; @@ -64,7 +83,11 @@ public interface IPackageManager extends IInterface { int installReason, List whiteListedPermissions) throws RemoteException; ParceledListSlice queryIntentActivities(Intent intent, - String resolvedType, int flags, int userId) throws RemoteException; + String resolvedType, int flags, int userId) throws RemoteException; + + @RequiresApi(33) + ParceledListSlice queryIntentActivities(Intent intent, + String resolvedType, long flags, int userId) throws RemoteException; boolean performDexOptMode(String packageName, boolean checkProfiles, String targetCompilerFilter, boolean force, boolean bootComplete, String splitName)