Loading core/java/android/app/admin/DevicePolicyManager.java +4 −8 Original line number Diff line number Diff line Loading @@ -8969,7 +8969,7 @@ public class DevicePolicyManager { try { final int myUserId = myUserId(); mService.setActiveAdmin(admin, false, myUserId); return mService.setProfileOwner(admin, ownerName, myUserId); return mService.setProfileOwner(admin, myUserId); } catch (RemoteException re) { throw re.rethrowFromSystemServer(); } Loading Loading @@ -9031,20 +9031,16 @@ public class DevicePolicyManager { * - the caller is SYSTEM_UID. * - or the caller is the shell uid, and there are no accounts on the specified user. * @param admin the component name to be registered as profile owner. * @param ownerName the human readable name of the organisation associated with this DPM. * @param userHandle the userId to set the profile owner for. * @return whether the component was successfully registered as the profile owner. * @throws IllegalArgumentException if admin is null, the package isn't installed, or the * preconditions mentioned are not met. */ public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName, int userHandle) throws IllegalArgumentException { public boolean setProfileOwner(@NonNull ComponentName admin, int userHandle) throws IllegalArgumentException { if (mService != null) { try { if (ownerName == null) { ownerName = ""; } return mService.setProfileOwner(admin, ownerName, userHandle); return mService.setProfileOwner(admin, userHandle); } catch (RemoteException re) { throw re.rethrowFromSystemServer(); } Loading core/java/android/app/admin/IDevicePolicyManager.aidl +1 −1 Original line number Diff line number Diff line Loading @@ -175,7 +175,7 @@ interface IDevicePolicyManager { void clearDeviceOwner(String packageName); int getDeviceOwnerUserId(); boolean setProfileOwner(in ComponentName who, String ownerName, int userHandle); boolean setProfileOwner(in ComponentName who, int userHandle); ComponentName getProfileOwnerAsUser(int userHandle); ComponentName getProfileOwnerOrDeviceOwnerSupervisionComponent(in UserHandle userHandle); boolean isSupervisionComponent(in ComponentName who); Loading services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +5 −10 Original line number Diff line number Diff line Loading @@ -8793,9 +8793,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { }); } // TODO(b/240562946): Remove owner name from API parameters. @Override public boolean setProfileOwner(ComponentName who, String ownerName, int userHandle) { public boolean setProfileOwner(ComponentName who, int userHandle) { if (!mHasFeature) { logMissingFeatureAction("Cannot set " + ComponentName.flattenToShortString(who) + " as profile owner for user " + userHandle); Loading Loading @@ -10816,9 +10815,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { // Set admin. setActiveAdmin(profileOwner, /* refreshing= */ true, userId); final String ownerName = getProfileOwnerNameUnchecked( Process.myUserHandle().getIdentifier()); setProfileOwner(profileOwner, ownerName, userId); setProfileOwner(profileOwner, userId); synchronized (getLockObject()) { DevicePolicyData policyData = getUserData(userId); Loading Loading @@ -17657,8 +17654,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { maybeInstallDevicePolicyManagementRoleHolderInUser(userInfo.id); installExistingAdminPackage(userInfo.id, admin.getPackageName()); if (!enableAdminAndSetProfileOwner( userInfo.id, caller.getUserId(), admin, provisioningParams.getOwnerName())) { if (!enableAdminAndSetProfileOwner(userInfo.id, caller.getUserId(), admin)) { throw new ServiceSpecificException( ERROR_SETTING_PROFILE_OWNER_FAILED, "Error setting profile owner."); Loading Loading @@ -17847,10 +17843,9 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { } private boolean enableAdminAndSetProfileOwner( @UserIdInt int userId, @UserIdInt int callingUserId, ComponentName adminComponent, String ownerName) { @UserIdInt int userId, @UserIdInt int callingUserId, ComponentName adminComponent) { enableAndSetActiveAdmin(userId, callingUserId, adminComponent); return setProfileOwner(adminComponent, ownerName, userId); return setProfileOwner(adminComponent, userId); } private void enableAndSetActiveAdmin( services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerServiceShellCommand.java +2 −1 Original line number Diff line number Diff line Loading @@ -50,6 +50,7 @@ final class DevicePolicyManagerServiceShellCommand extends ShellCommand { private final DevicePolicyManagerService mService; private int mUserId = UserHandle.USER_SYSTEM; //TODO(b/240562946): remove mName once it is not used by setDeviceOwner private String mName = ""; private ComponentName mComponent; private boolean mSetDoOnly; Loading Loading @@ -287,7 +288,7 @@ final class DevicePolicyManagerServiceShellCommand extends ShellCommand { mService.setActiveAdmin(mComponent, /* refreshing= */ true, mUserId); try { if (!mService.setProfileOwner(mComponent, mName, mUserId)) { if (!mService.setProfileOwner(mComponent, mUserId)) { throw new RuntimeException("Can't set component " + mComponent.flattenToShortString() + " as profile owner for user " + mUserId); Loading services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java +11 −11 Original line number Diff line number Diff line Loading @@ -402,7 +402,7 @@ public class DevicePolicyManagerTest extends DpmTestBase { // PO needs to be a DA. dpm.setActiveAdmin(admin, /*replace=*/ false); // Fire! assertThat(dpm.setProfileOwner(admin, "owner-name", CALLER_USER_HANDLE)).isTrue(); assertThat(dpm.setProfileOwner(admin, CALLER_USER_HANDLE)).isTrue(); // Check assertThat(dpm.getProfileOwnerAsUser(CALLER_USER_HANDLE)).isEqualTo(admin); }); Loading Loading @@ -1074,7 +1074,7 @@ public class DevicePolicyManagerTest extends DpmTestBase { dpm.setActiveAdmin(admin2, /* refreshing= */ true, UserHandle.USER_SYSTEM); assertExpectException(IllegalStateException.class, /* messageRegex= */ "already has a device owner", () -> dpm.setProfileOwner(admin2, "owner-name", UserHandle.USER_SYSTEM)); () -> dpm.setProfileOwner(admin2, UserHandle.USER_SYSTEM)); // DO admin can't be deactivated. dpm.removeActiveAdmin(admin1); Loading @@ -1098,7 +1098,7 @@ public class DevicePolicyManagerTest extends DpmTestBase { dpm.setActiveAdmin(admin2, /* refreshing= */ true, CALLER_USER_HANDLE); assertExpectException(IllegalStateException.class, /* messageRegex= */ "profile owner is already set", () -> dpm.setProfileOwner(admin2, "owner-name", CALLER_USER_HANDLE)); () -> dpm.setProfileOwner(admin2, CALLER_USER_HANDLE)); // DO admin can't be deactivated. dpm.removeActiveAdmin(admin1); Loading Loading @@ -1603,13 +1603,13 @@ public class DevicePolicyManagerTest extends DpmTestBase { // Package doesn't exist and caller is not system assertExpectException(SecurityException.class, /* messageRegex= */ "Calling identity is not authorized", () -> dpm.setProfileOwner(admin1, "owner-name", UserHandle.USER_SYSTEM)); () -> dpm.setProfileOwner(admin1, UserHandle.USER_SYSTEM)); // Package exists, but caller is not system setUpPackageManagerForAdmin(admin1, DpmMockContext.CALLER_SYSTEM_USER_UID); assertExpectException(SecurityException.class, /* messageRegex= */ "Calling identity is not authorized", () -> dpm.setProfileOwner(admin1, "owner-name", UserHandle.USER_SYSTEM)); () -> dpm.setProfileOwner(admin1, UserHandle.USER_SYSTEM)); } @Test Loading Loading @@ -2683,7 +2683,7 @@ public class DevicePolicyManagerTest extends DpmTestBase { () -> dpm.getWifiMacAddress(admin1)); // Test 3. Caller has PO, but not DO. assertThat(dpm.setProfileOwner(admin1, null, UserHandle.USER_SYSTEM)).isTrue(); assertThat(dpm.setProfileOwner(admin1, UserHandle.USER_SYSTEM)).isTrue(); assertExpectException(SecurityException.class, /* messageRegex= */ INVALID_CALLING_IDENTITY_MSG, () -> dpm.getWifiMacAddress(admin1)); Loading Loading @@ -2735,7 +2735,7 @@ public class DevicePolicyManagerTest extends DpmTestBase { INVALID_CALLING_IDENTITY_MSG, () -> dpm.reboot(admin1)); // Set admin1 as PO. assertThat(dpm.setProfileOwner(admin1, null, UserHandle.USER_SYSTEM)).isTrue(); assertThat(dpm.setProfileOwner(admin1, UserHandle.USER_SYSTEM)).isTrue(); assertExpectException(SecurityException.class, /* messageRegex= */ INVALID_CALLING_IDENTITY_MSG, () -> dpm.reboot(admin1)); Loading Loading @@ -3231,7 +3231,7 @@ public class DevicePolicyManagerTest extends DpmTestBase { setUpPackageManagerForAdmin(admin1, DpmMockContext.CALLER_UID); dpm.setActiveAdmin(admin1, false); assertThat(dpm.setProfileOwner(admin1, null, CALLER_USER_HANDLE)).isTrue(); assertThat(dpm.setProfileOwner(admin1, CALLER_USER_HANDLE)).isTrue(); mContext.callerPermissions.removeAll(OWNER_SETUP_PERMISSIONS); } Loading @@ -3241,7 +3241,7 @@ public class DevicePolicyManagerTest extends DpmTestBase { setUpPackageManagerForAdmin(admin1, DpmMockContext.SYSTEM_UID); dpm.setActiveAdmin(admin1, false); assertThat(dpm.setProfileOwner(admin1, null, UserHandle.USER_SYSTEM)).isTrue(); assertThat(dpm.setProfileOwner(admin1, UserHandle.USER_SYSTEM)).isTrue(); mContext.callerPermissions.removeAll(OWNER_SETUP_PERMISSIONS); } Loading Loading @@ -3764,7 +3764,7 @@ public class DevicePolicyManagerTest extends DpmTestBase { mContext.callerPermissions.addAll(OWNER_SETUP_PERMISSIONS); setUpPackageManagerForFakeAdmin(admin1, managedProfileAdminUid, admin1); dpm.setActiveAdmin(admin1, false, userId); assertThat(dpm.setProfileOwner(admin1, null, userId)).isFalse(); assertThat(dpm.setProfileOwner(admin1, userId)).isFalse(); mContext.callerPermissions.removeAll(OWNER_SETUP_PERMISSIONS); } Loading Loading @@ -8710,7 +8710,7 @@ public class DevicePolicyManagerTest extends DpmTestBase { setUpPackageManagerForFakeAdmin(admin, adminUid, /* enabledSetting= */ null, appTargetSdk, copyFromAdmin); dpm.setActiveAdmin(admin, false, userId); assertThat(dpm.setProfileOwner(admin, null, userId)).isTrue(); assertThat(dpm.setProfileOwner(admin, userId)).isTrue(); mContext.callerPermissions.removeAll(OWNER_SETUP_PERMISSIONS); } Loading Loading
core/java/android/app/admin/DevicePolicyManager.java +4 −8 Original line number Diff line number Diff line Loading @@ -8969,7 +8969,7 @@ public class DevicePolicyManager { try { final int myUserId = myUserId(); mService.setActiveAdmin(admin, false, myUserId); return mService.setProfileOwner(admin, ownerName, myUserId); return mService.setProfileOwner(admin, myUserId); } catch (RemoteException re) { throw re.rethrowFromSystemServer(); } Loading Loading @@ -9031,20 +9031,16 @@ public class DevicePolicyManager { * - the caller is SYSTEM_UID. * - or the caller is the shell uid, and there are no accounts on the specified user. * @param admin the component name to be registered as profile owner. * @param ownerName the human readable name of the organisation associated with this DPM. * @param userHandle the userId to set the profile owner for. * @return whether the component was successfully registered as the profile owner. * @throws IllegalArgumentException if admin is null, the package isn't installed, or the * preconditions mentioned are not met. */ public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName, int userHandle) throws IllegalArgumentException { public boolean setProfileOwner(@NonNull ComponentName admin, int userHandle) throws IllegalArgumentException { if (mService != null) { try { if (ownerName == null) { ownerName = ""; } return mService.setProfileOwner(admin, ownerName, userHandle); return mService.setProfileOwner(admin, userHandle); } catch (RemoteException re) { throw re.rethrowFromSystemServer(); } Loading
core/java/android/app/admin/IDevicePolicyManager.aidl +1 −1 Original line number Diff line number Diff line Loading @@ -175,7 +175,7 @@ interface IDevicePolicyManager { void clearDeviceOwner(String packageName); int getDeviceOwnerUserId(); boolean setProfileOwner(in ComponentName who, String ownerName, int userHandle); boolean setProfileOwner(in ComponentName who, int userHandle); ComponentName getProfileOwnerAsUser(int userHandle); ComponentName getProfileOwnerOrDeviceOwnerSupervisionComponent(in UserHandle userHandle); boolean isSupervisionComponent(in ComponentName who); Loading
services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +5 −10 Original line number Diff line number Diff line Loading @@ -8793,9 +8793,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { }); } // TODO(b/240562946): Remove owner name from API parameters. @Override public boolean setProfileOwner(ComponentName who, String ownerName, int userHandle) { public boolean setProfileOwner(ComponentName who, int userHandle) { if (!mHasFeature) { logMissingFeatureAction("Cannot set " + ComponentName.flattenToShortString(who) + " as profile owner for user " + userHandle); Loading Loading @@ -10816,9 +10815,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { // Set admin. setActiveAdmin(profileOwner, /* refreshing= */ true, userId); final String ownerName = getProfileOwnerNameUnchecked( Process.myUserHandle().getIdentifier()); setProfileOwner(profileOwner, ownerName, userId); setProfileOwner(profileOwner, userId); synchronized (getLockObject()) { DevicePolicyData policyData = getUserData(userId); Loading Loading @@ -17657,8 +17654,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { maybeInstallDevicePolicyManagementRoleHolderInUser(userInfo.id); installExistingAdminPackage(userInfo.id, admin.getPackageName()); if (!enableAdminAndSetProfileOwner( userInfo.id, caller.getUserId(), admin, provisioningParams.getOwnerName())) { if (!enableAdminAndSetProfileOwner(userInfo.id, caller.getUserId(), admin)) { throw new ServiceSpecificException( ERROR_SETTING_PROFILE_OWNER_FAILED, "Error setting profile owner."); Loading Loading @@ -17847,10 +17843,9 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { } private boolean enableAdminAndSetProfileOwner( @UserIdInt int userId, @UserIdInt int callingUserId, ComponentName adminComponent, String ownerName) { @UserIdInt int userId, @UserIdInt int callingUserId, ComponentName adminComponent) { enableAndSetActiveAdmin(userId, callingUserId, adminComponent); return setProfileOwner(adminComponent, ownerName, userId); return setProfileOwner(adminComponent, userId); } private void enableAndSetActiveAdmin(
services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerServiceShellCommand.java +2 −1 Original line number Diff line number Diff line Loading @@ -50,6 +50,7 @@ final class DevicePolicyManagerServiceShellCommand extends ShellCommand { private final DevicePolicyManagerService mService; private int mUserId = UserHandle.USER_SYSTEM; //TODO(b/240562946): remove mName once it is not used by setDeviceOwner private String mName = ""; private ComponentName mComponent; private boolean mSetDoOnly; Loading Loading @@ -287,7 +288,7 @@ final class DevicePolicyManagerServiceShellCommand extends ShellCommand { mService.setActiveAdmin(mComponent, /* refreshing= */ true, mUserId); try { if (!mService.setProfileOwner(mComponent, mName, mUserId)) { if (!mService.setProfileOwner(mComponent, mUserId)) { throw new RuntimeException("Can't set component " + mComponent.flattenToShortString() + " as profile owner for user " + mUserId); Loading
services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java +11 −11 Original line number Diff line number Diff line Loading @@ -402,7 +402,7 @@ public class DevicePolicyManagerTest extends DpmTestBase { // PO needs to be a DA. dpm.setActiveAdmin(admin, /*replace=*/ false); // Fire! assertThat(dpm.setProfileOwner(admin, "owner-name", CALLER_USER_HANDLE)).isTrue(); assertThat(dpm.setProfileOwner(admin, CALLER_USER_HANDLE)).isTrue(); // Check assertThat(dpm.getProfileOwnerAsUser(CALLER_USER_HANDLE)).isEqualTo(admin); }); Loading Loading @@ -1074,7 +1074,7 @@ public class DevicePolicyManagerTest extends DpmTestBase { dpm.setActiveAdmin(admin2, /* refreshing= */ true, UserHandle.USER_SYSTEM); assertExpectException(IllegalStateException.class, /* messageRegex= */ "already has a device owner", () -> dpm.setProfileOwner(admin2, "owner-name", UserHandle.USER_SYSTEM)); () -> dpm.setProfileOwner(admin2, UserHandle.USER_SYSTEM)); // DO admin can't be deactivated. dpm.removeActiveAdmin(admin1); Loading @@ -1098,7 +1098,7 @@ public class DevicePolicyManagerTest extends DpmTestBase { dpm.setActiveAdmin(admin2, /* refreshing= */ true, CALLER_USER_HANDLE); assertExpectException(IllegalStateException.class, /* messageRegex= */ "profile owner is already set", () -> dpm.setProfileOwner(admin2, "owner-name", CALLER_USER_HANDLE)); () -> dpm.setProfileOwner(admin2, CALLER_USER_HANDLE)); // DO admin can't be deactivated. dpm.removeActiveAdmin(admin1); Loading Loading @@ -1603,13 +1603,13 @@ public class DevicePolicyManagerTest extends DpmTestBase { // Package doesn't exist and caller is not system assertExpectException(SecurityException.class, /* messageRegex= */ "Calling identity is not authorized", () -> dpm.setProfileOwner(admin1, "owner-name", UserHandle.USER_SYSTEM)); () -> dpm.setProfileOwner(admin1, UserHandle.USER_SYSTEM)); // Package exists, but caller is not system setUpPackageManagerForAdmin(admin1, DpmMockContext.CALLER_SYSTEM_USER_UID); assertExpectException(SecurityException.class, /* messageRegex= */ "Calling identity is not authorized", () -> dpm.setProfileOwner(admin1, "owner-name", UserHandle.USER_SYSTEM)); () -> dpm.setProfileOwner(admin1, UserHandle.USER_SYSTEM)); } @Test Loading Loading @@ -2683,7 +2683,7 @@ public class DevicePolicyManagerTest extends DpmTestBase { () -> dpm.getWifiMacAddress(admin1)); // Test 3. Caller has PO, but not DO. assertThat(dpm.setProfileOwner(admin1, null, UserHandle.USER_SYSTEM)).isTrue(); assertThat(dpm.setProfileOwner(admin1, UserHandle.USER_SYSTEM)).isTrue(); assertExpectException(SecurityException.class, /* messageRegex= */ INVALID_CALLING_IDENTITY_MSG, () -> dpm.getWifiMacAddress(admin1)); Loading Loading @@ -2735,7 +2735,7 @@ public class DevicePolicyManagerTest extends DpmTestBase { INVALID_CALLING_IDENTITY_MSG, () -> dpm.reboot(admin1)); // Set admin1 as PO. assertThat(dpm.setProfileOwner(admin1, null, UserHandle.USER_SYSTEM)).isTrue(); assertThat(dpm.setProfileOwner(admin1, UserHandle.USER_SYSTEM)).isTrue(); assertExpectException(SecurityException.class, /* messageRegex= */ INVALID_CALLING_IDENTITY_MSG, () -> dpm.reboot(admin1)); Loading Loading @@ -3231,7 +3231,7 @@ public class DevicePolicyManagerTest extends DpmTestBase { setUpPackageManagerForAdmin(admin1, DpmMockContext.CALLER_UID); dpm.setActiveAdmin(admin1, false); assertThat(dpm.setProfileOwner(admin1, null, CALLER_USER_HANDLE)).isTrue(); assertThat(dpm.setProfileOwner(admin1, CALLER_USER_HANDLE)).isTrue(); mContext.callerPermissions.removeAll(OWNER_SETUP_PERMISSIONS); } Loading @@ -3241,7 +3241,7 @@ public class DevicePolicyManagerTest extends DpmTestBase { setUpPackageManagerForAdmin(admin1, DpmMockContext.SYSTEM_UID); dpm.setActiveAdmin(admin1, false); assertThat(dpm.setProfileOwner(admin1, null, UserHandle.USER_SYSTEM)).isTrue(); assertThat(dpm.setProfileOwner(admin1, UserHandle.USER_SYSTEM)).isTrue(); mContext.callerPermissions.removeAll(OWNER_SETUP_PERMISSIONS); } Loading Loading @@ -3764,7 +3764,7 @@ public class DevicePolicyManagerTest extends DpmTestBase { mContext.callerPermissions.addAll(OWNER_SETUP_PERMISSIONS); setUpPackageManagerForFakeAdmin(admin1, managedProfileAdminUid, admin1); dpm.setActiveAdmin(admin1, false, userId); assertThat(dpm.setProfileOwner(admin1, null, userId)).isFalse(); assertThat(dpm.setProfileOwner(admin1, userId)).isFalse(); mContext.callerPermissions.removeAll(OWNER_SETUP_PERMISSIONS); } Loading Loading @@ -8710,7 +8710,7 @@ public class DevicePolicyManagerTest extends DpmTestBase { setUpPackageManagerForFakeAdmin(admin, adminUid, /* enabledSetting= */ null, appTargetSdk, copyFromAdmin); dpm.setActiveAdmin(admin, false, userId); assertThat(dpm.setProfileOwner(admin, null, userId)).isTrue(); assertThat(dpm.setProfileOwner(admin, userId)).isTrue(); mContext.callerPermissions.removeAll(OWNER_SETUP_PERMISSIONS); } Loading