[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 f8f07e22f1
commit fcdc62081c

View File

@@ -18181,6 +18181,20 @@ public class PackageManagerService extends IPackageManager.Stub
final String packageName = versionedPackage.getPackageName();
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;
synchronized (mLock) {
// Normalize package name to handle renamed packages and static libs