[RESTRICT AUTOMERGE] Make WPMS look for DOs and POs in the correct calling user am: 72704403aa

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/13144052

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Ia9fa890f6b0582997173c9cef54c397c679db23e
This commit is contained in:
Alex Kershaw
2021-01-06 16:00:40 +00:00
committed by Automerger Merge Worker
3 changed files with 32 additions and 5 deletions

View File

@@ -16,6 +16,7 @@
package android.app.admin;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.content.ComponentName;
import android.content.Intent;
@@ -241,6 +242,7 @@ public abstract class DevicePolicyManagerInternal {
/**
* Returns the profile owner component for the given user, or {@code null} if there is not one.
*/
@Nullable
public abstract ComponentName getProfileOwnerAsUser(int userHandle);
/**
@@ -254,4 +256,9 @@ public abstract class DevicePolicyManagerInternal {
* {@link #supportsResetOp(int)} is true.
*/
public abstract void resetOp(int op, String packageName, @UserIdInt int userId);
/**
* Returns whether the given package is a device owner or a profile owner in the calling user.
*/
public abstract boolean isDeviceOrProfileOwnerInCallingUser(String packageName);
}

View File

@@ -39,7 +39,7 @@ import android.app.WallpaperColors;
import android.app.WallpaperInfo;
import android.app.WallpaperManager;
import android.app.WallpaperManager.SetWallpaperFlags;
import android.app.admin.DevicePolicyManager;
import android.app.admin.DevicePolicyManagerInternal;
import android.app.backup.WallpaperBackupHelper;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
@@ -2861,10 +2861,10 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
if (!uidMatchPackage) {
return false; // callingPackage was faked.
}
// TODO(b/144048540): DPM needs to take into account the userId, not just the package.
final DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class);
if (dpm.isDeviceOwnerApp(callingPackage) || dpm.isProfileOwnerApp(callingPackage)) {
DevicePolicyManagerInternal devicePolicyManagerInternal =
LocalServices.getService(DevicePolicyManagerInternal.class);
if (devicePolicyManagerInternal != null &&
devicePolicyManagerInternal.isDeviceOrProfileOwnerInCallingUser(callingPackage)) {
return true;
}
final int callingUserId = UserHandle.getCallingUserId();

View File

@@ -12857,6 +12857,26 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
? AppOpsManager.MODE_ALLOWED
: AppOpsManager.opToDefaultMode(AppOpsManager.OP_INTERACT_ACROSS_PROFILES);
}
public boolean isDeviceOrProfileOwnerInCallingUser(String packageName) {
return isDeviceOwnerInCallingUser(packageName)
|| isProfileOwnerInCallingUser(packageName);
}
private boolean isDeviceOwnerInCallingUser(String packageName) {
final ComponentName deviceOwnerInCallingUser =
DevicePolicyManagerService.this.getDeviceOwnerComponent(
/* callingUserOnly= */ true);
return deviceOwnerInCallingUser != null
&& packageName.equals(deviceOwnerInCallingUser.getPackageName());
}
private boolean isProfileOwnerInCallingUser(String packageName) {
final ComponentName profileOwnerInCallingUser =
getProfileOwnerAsUser(UserHandle.getCallingUserId());
return profileOwnerInCallingUser != null
&& packageName.equals(profileOwnerInCallingUser.getPackageName());
}
}
private Intent createShowAdminSupportIntent(ComponentName admin, int userId) {