Skip to content

Commit

Permalink
[Refactor] Fix blocking components in Android 14
Browse files Browse the repository at this point in the history
Co-authored-by: Craig Gomez <[email protected]>
Signed-off-by: Muntashir Al-Islam <[email protected]>
  • Loading branch information
MuntashirAkon and craigacgomez committed Nov 2, 2023
1 parent 98ef1ce commit 5a78375
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -343,13 +343,19 @@ public static int getComponentEnabledSetting(ComponentName componentName, @UserI
}
}

@OptIn(markerClass = BuildCompat.PrereleaseSdkCheck.class)
@SuppressWarnings("deprecation")
@RequiresPermission(value = Manifest.permission.CHANGE_COMPONENT_ENABLED_STATE)
public static void setComponentEnabledSetting(ComponentName componentName,
@EnabledState int newState,
@EnabledFlags int flags,
@UserIdInt int userId)
throws RemoteException {
getPackageManager().setComponentEnabledSetting(componentName, newState, flags, userId);
IPackageManager pm = getPackageManager();
if (BuildCompat.isAtLeastU()) {
String callingPackage = SelfPermissions.getCallingPackage(Users.getSelfOrRemoteUid());
pm.setComponentEnabledSetting(componentName, newState, flags, userId, callingPackage);
} else pm.setComponentEnabledSetting(componentName, newState, flags, userId);
if (userId != UserHandleHidden.myUserId()) {
BroadcastUtils.sendPackageAltered(ContextUtils.getContext(), new String[]{componentName.getPackageName()});
}
Expand Down
10 changes: 10 additions & 0 deletions hiddenapi/src/main/java/android/content/pm/IPackageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -646,9 +646,18 @@ void overrideLabelAndIcon(ComponentName componentName, String nonLocalizedLabel,

/**
* As per {@link android.content.pm.PackageManager#setComponentEnabledSetting}.
*
* @deprecated Replaced by {@link #setComponentEnabledSetting(ComponentName, int, int, int, String)} in Android 14 (SDK 34)
*/
@Deprecated
void setComponentEnabledSetting(ComponentName componentName, int newState, int flags, int userId) throws RemoteException;

/**
* As per {@link android.content.pm.PackageManager#setComponentEnabledSetting}.
*/
@RequiresApi(34)
void setComponentEnabledSetting(ComponentName componentName, int newState, int flags, int userId, String callingPackage) throws RemoteException;

/**
* As per {@link android.content.pm.PackageManager#getComponentEnabledSetting}.
*/
Expand Down Expand Up @@ -959,6 +968,7 @@ boolean performDexOptMode(String packageName, boolean checkProfiles,

/**
* Ask the package manager to compile layouts in the given package.
*
* @deprecated Removed in API 31 (Android 12)
*/
@RequiresApi(Build.VERSION_CODES.Q)
Expand Down

0 comments on commit 5a78375

Please sign in to comment.