getDeviceOwnerDeletedPackageMsg() should call clearCallingIdentity()

DevicePolicyResourcesManager should be called in the context of
system_server instead of the calling app to avoid UID and package
name mismatch.

Bug: 246487618
Test: atest SessionCommitBroadcastTest
Change-Id: I1d27c7cd879d440abcf834830563368e50f521f2
This commit is contained in:
JW Wang
2022-09-16 09:53:02 +08:00
parent 833fb8b820
commit 9321e8c9d9

View File

@@ -1344,9 +1344,14 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
}
private String getDeviceOwnerDeletedPackageMsg() {
DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class);
return dpm.getResources().getString(PACKAGE_DELETED_BY_DO,
() -> mContext.getString(R.string.package_deleted_device_owner));
final long ident = Binder.clearCallingIdentity();
try {
DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class);
return dpm.getResources().getString(PACKAGE_DELETED_BY_DO,
() -> mContext.getString(R.string.package_deleted_device_owner));
} finally {
Binder.restoreCallingIdentity(ident);
}
}
@Override