[pm] forbid deletion of protected packages

BUG: 242996180
Test: adb shell pm uninstall --user 0 com.google.android.apps.work.oobconfig
Test: Verified with the command above. Before this CL, the package can
be deleted. After this CL, the deletion will fail.

Change-Id: Iba408e536b340ea5d66ab499442c0c4f828fa36f
(cherry picked from commit 15f85c7fa9)
Merged-In: Iba408e536b340ea5d66ab499442c0c4f828fa36f
This commit is contained in:
Songchun Fan
2022-09-09 14:50:31 -07:00
parent 3bf1fa1198
commit cbda45eb95

View File

@@ -21354,6 +21354,20 @@ public class PackageManagerService extends IPackageManager.Stub
final String packageName = versionedPackage.getPackageName(); final String packageName = versionedPackage.getPackageName();
final long versionCode = versionedPackage.getLongVersionCode(); final long versionCode = versionedPackage.getLongVersionCode();
if (mProtectedPackages.isPackageStateProtected(userId, packageName)) {
mHandler.post(() -> {
try {
Slog.w(TAG, "Attempted to delete protected package: " + packageName);
observer.onPackageDeleted(packageName,
PackageManager.DELETE_FAILED_INTERNAL_ERROR, null);
} catch (RemoteException re) {
}
});
return;
}
final String internalPackageName; final String internalPackageName;
try { try {