Skip to content

Commit

Permalink
[Refactor] Fix suspending packages in Android 14 r29 onwards
Browse files Browse the repository at this point in the history
Signed-off-by: Muntashir Al-Islam <[email protected]>
  • Loading branch information
MuntashirAkon committed Nov 11, 2024
1 parent 00c30da commit b2e4ed4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,13 @@ public static int getApplicationEnabledSetting(String packageName, @UserIdInt in
@RequiresPermission(allOf = {"android.permission.SUSPEND_APPS", ManifestCompat.permission.MANAGE_USERS})
public static void suspendPackages(String[] packageNames, @UserIdInt int userId, boolean suspend) throws RemoteException {
String callingPackage = SelfPermissions.getCallingPackage(Users.getSelfOrRemoteUid());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
try {
getPackageManager().setPackagesSuspendedAsUser(packageNames, suspend, null, null, null, 0, callingPackage, 0, userId);
} catch (NoSuchMethodError e) {
getPackageManager().setPackagesSuspendedAsUser(packageNames, suspend, null, null, (SuspendDialogInfo) null, callingPackage, userId);
}
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
getPackageManager().setPackagesSuspendedAsUser(packageNames, suspend, null, null, (SuspendDialogInfo) null, callingPackage, userId);
} else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.P) {
getPackageManager().setPackagesSuspendedAsUser(packageNames, suspend, null, null, (String) null, callingPackage, userId);
Expand Down
17 changes: 15 additions & 2 deletions hiddenapi/src/main/java/android/content/pm/IPackageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -544,26 +544,39 @@ String[] setDistractingPackageRestrictionsAsUser(String[] packageNames, int rest
int userId) throws RemoteException;

/**
* @deprecated Removed in API 28 (Android P)
* @deprecated Replaced in API 28 (Android P) by {@link #setPackagesSuspendedAsUser(String[], boolean, PersistableBundle, PersistableBundle, String, String, int)}
*/
@Deprecated
@RequiresApi(Build.VERSION_CODES.N)
String[] setPackagesSuspendedAsUser(String[] packageNames, boolean suspended, int userId) throws RemoteException;

/**
* @deprecated Removed in API 29 (Android Q)
* @deprecated Replaced in API 29 (Android Q) by {@link #setPackagesSuspendedAsUser(String[], boolean, PersistableBundle, PersistableBundle, SuspendDialogInfo, String, int)}
*/
@Deprecated
@RequiresApi(Build.VERSION_CODES.P)
String[] setPackagesSuspendedAsUser(String[] packageNames, boolean suspended,
PersistableBundle appExtras, PersistableBundle launcherExtras,
String dialogMessage, String callingPackage, int userId) throws RemoteException;

/**
* @deprecated Replaced in API 34 r29 (Android U) by {@link #setPackagesSuspendedAsUser(String[], boolean, PersistableBundle, PersistableBundle, SuspendDialogInfo, int, String, int, int)}
*/
@Deprecated
@RequiresApi(Build.VERSION_CODES.Q)
String[] setPackagesSuspendedAsUser(String[] packageNames, boolean suspended,
PersistableBundle appExtras, PersistableBundle launcherExtras,
SuspendDialogInfo dialogInfo, String callingPackage, int userId) throws RemoteException;

/**
* Introduced in API 34 r29
*/
@RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
String[] setPackagesSuspendedAsUser(String[] packageNames, boolean suspended,
PersistableBundle appExtras, PersistableBundle launcherExtras,
SuspendDialogInfo dialogInfo, int flags, String suspendingPackage,
int suspendingUserId, int targetUserId) throws RemoteException;

@RequiresApi(Build.VERSION_CODES.N)
boolean isPackageSuspendedForUser(String packageName, int userId) throws RemoteException;

Expand Down

0 comments on commit b2e4ed4

Please sign in to comment.