Skip to content

Commit 04ed88d

Browse files
committed
Update hidden API from Android 16 [2/2]
Signed-off-by: Muntashir Al-Islam <muntashirakon@riseup.net>
1 parent 3bf9785 commit 04ed88d

6 files changed

Lines changed: 400 additions & 324 deletions

File tree

app/src/main/java/io/github/muntashirakon/AppManager/compat/ActivityManagerCompat.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,7 @@ public static int sendBroadcast(Intent intent, @UserIdInt int userHandle)
146146
throws RemoteException {
147147
IActivityManager am = getActivityManager();
148148
int res;
149-
IIntentReceiver receiver = new IntentReceiver();
150-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
151-
res = am.broadcastIntentWithFeature(null, null, intent, null, receiver, 0, null, null, null, AppOpsManagerCompat.OP_NONE, null, true, false, userHandle);
152-
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
149+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
153150
res = am.broadcastIntent(null, intent, null, null, 0, null, null, null, AppOpsManagerCompat.OP_NONE, null, true, false, userHandle);
154151
} else {
155152
res = am.broadcastIntent(null, intent, null, null, 0, null, null, null, AppOpsManagerCompat.OP_NONE, true, false, userHandle);

app/src/main/java/io/github/muntashirakon/AppManager/compat/PackageManagerCompat.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,16 @@ public static int installExistingPackageAsUser(@NonNull String packageName, @Use
525525
@RequiresPermission(ManifestCompat.permission.CLEAR_APP_USER_DATA)
526526
public static void clearApplicationUserData(@NonNull UserPackagePair pair) throws AndroidException {
527527
IPackageManager pm = getPackageManager();
528+
// TODO: 5/25/26 We can use IActivityManager#clearApplicationUserData() instead which is more stable
528529
ClearDataObserver obs = new ClearDataObserver();
529-
pm.clearApplicationUserData(pair.getPackageName(), obs, pair.getUserId());
530+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
531+
try {
532+
pm.clearApplicationUserData(pair.getPackageName(), obs, pair.getUserId(), false);
533+
} catch (NoSuchMethodError e) {
534+
// Fall back to the old API
535+
pm.clearApplicationUserData(pair.getPackageName(), obs, pair.getUserId());
536+
}
537+
} else pm.clearApplicationUserData(pair.getPackageName(), obs, pair.getUserId());
530538
//noinspection SynchronizationOnLocalVariableOrMethodParameter
531539
synchronized (obs) {
532540
while (!obs.isCompleted()) {

0 commit comments

Comments
 (0)