Merge "Remove ownerName as argument in DPMS.setDeviceOwner"
This commit is contained in:
committed by
Android (Google) Code Review
commit
af7d9b6c3c
@@ -523,8 +523,8 @@ package android.app.admin {
|
||||
method @NonNull public static String operationToString(int);
|
||||
method @RequiresPermission(android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS) public void resetDefaultCrossProfileIntentFilters(int);
|
||||
method @RequiresPermission(allOf={android.Manifest.permission.MANAGE_DEVICE_ADMINS, android.Manifest.permission.INTERACT_ACROSS_USERS_FULL}) public void setActiveAdmin(@NonNull android.content.ComponentName, boolean, int);
|
||||
method @RequiresPermission(android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS) public boolean setDeviceOwner(@NonNull android.content.ComponentName, @Nullable String, int);
|
||||
method @RequiresPermission(android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS) public boolean setDeviceOwnerOnly(@NonNull android.content.ComponentName, @Nullable String, int);
|
||||
method @RequiresPermission(android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS) public boolean setDeviceOwner(@NonNull android.content.ComponentName, int);
|
||||
method @RequiresPermission(android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS) public boolean setDeviceOwnerOnly(@NonNull android.content.ComponentName, int);
|
||||
method public void setDeviceOwnerType(@NonNull android.content.ComponentName, int);
|
||||
method @RequiresPermission(android.Manifest.permission.MANAGE_DEVICE_ADMINS) public void setNextOperationSafety(int, int);
|
||||
method @RequiresPermission(anyOf={android.Manifest.permission.MARK_DEVICE_ORGANIZATION_OWNED, android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS}, conditional=true) public void setProfileOwnerOnOrganizationOwnedDevice(@NonNull android.content.ComponentName, boolean);
|
||||
|
||||
@@ -8689,7 +8689,6 @@ public class DevicePolicyManager {
|
||||
* and no accounts.
|
||||
*
|
||||
* @param who the component name to be registered as device owner.
|
||||
* @param ownerName the human readable name of the institution that owns this device.
|
||||
* @param userId ID of the user on which the device owner runs.
|
||||
*
|
||||
* @return whether the package was successfully registered as the device owner.
|
||||
@@ -8701,11 +8700,10 @@ public class DevicePolicyManager {
|
||||
*/
|
||||
@TestApi
|
||||
@RequiresPermission(android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS)
|
||||
public boolean setDeviceOwner(@NonNull ComponentName who, @Nullable String ownerName,
|
||||
@UserIdInt int userId) {
|
||||
public boolean setDeviceOwner(@NonNull ComponentName who, @UserIdInt int userId) {
|
||||
if (mService != null) {
|
||||
try {
|
||||
return mService.setDeviceOwner(who, ownerName, userId,
|
||||
return mService.setDeviceOwner(who, userId,
|
||||
/* setProfileOwnerOnCurrentUserIfNecessary= */ true);
|
||||
} catch (RemoteException re) {
|
||||
throw re.rethrowFromSystemServer();
|
||||
@@ -8715,7 +8713,7 @@ public class DevicePolicyManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as {@link #setDeviceOwner(ComponentName, String, int)}, but without setting the profile
|
||||
* Same as {@link #setDeviceOwner(ComponentName, int)}, but without setting the profile
|
||||
* owner on current user when running on headless system user mode - should be used only by
|
||||
* testing infra.
|
||||
*
|
||||
@@ -8724,10 +8722,10 @@ public class DevicePolicyManager {
|
||||
@TestApi
|
||||
@RequiresPermission(android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS)
|
||||
public boolean setDeviceOwnerOnly(
|
||||
@NonNull ComponentName who, @Nullable String ownerName, @UserIdInt int userId) {
|
||||
@NonNull ComponentName who, @UserIdInt int userId) {
|
||||
if (mService != null) {
|
||||
try {
|
||||
return mService.setDeviceOwner(who, ownerName, userId,
|
||||
return mService.setDeviceOwner(who, userId,
|
||||
/* setProfileOwnerOnCurrentUserIfNecessary= */ false);
|
||||
} catch (RemoteException re) {
|
||||
throw re.rethrowFromSystemServer();
|
||||
|
||||
@@ -168,7 +168,7 @@ interface IDevicePolicyManager {
|
||||
void reportKeyguardDismissed(int userHandle);
|
||||
void reportKeyguardSecured(int userHandle);
|
||||
|
||||
boolean setDeviceOwner(in ComponentName who, String ownerName, int userId, boolean setProfileOwnerOnCurrentUserIfNecessary);
|
||||
boolean setDeviceOwner(in ComponentName who, int userId, boolean setProfileOwnerOnCurrentUserIfNecessary);
|
||||
ComponentName getDeviceOwnerComponent(boolean callingUserOnly);
|
||||
boolean hasDeviceOwner();
|
||||
String getDeviceOwnerName();
|
||||
|
||||
@@ -8336,9 +8336,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
|
||||
+ PackageManager.FEATURE_DEVICE_ADMIN + " feature.");
|
||||
}
|
||||
|
||||
// TODO(b/240562946): Remove owner name from API parameters.
|
||||
@Override
|
||||
public boolean setDeviceOwner(ComponentName admin, String ownerName, int userId,
|
||||
public boolean setDeviceOwner(ComponentName admin, int userId,
|
||||
boolean setProfileOwnerOnCurrentUserIfNecessary) {
|
||||
if (!mHasFeature) {
|
||||
logMissingFeatureAction("Cannot set " + ComponentName.flattenToShortString(admin)
|
||||
@@ -18048,11 +18047,9 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
|
||||
}
|
||||
|
||||
|
||||
if (!setActiveAdminAndDeviceOwner(
|
||||
deviceOwnerUserId, deviceAdmin, provisioningParams.getOwnerName())) {
|
||||
if (!setActiveAdminAndDeviceOwner(deviceOwnerUserId, deviceAdmin)) {
|
||||
throw new ServiceSpecificException(
|
||||
ERROR_SET_DEVICE_OWNER_FAILED,
|
||||
"Failed to set device owner.");
|
||||
ERROR_SET_DEVICE_OWNER_FAILED, "Failed to set device owner.");
|
||||
}
|
||||
|
||||
disallowAddUser();
|
||||
@@ -18179,12 +18176,12 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
|
||||
}
|
||||
|
||||
private boolean setActiveAdminAndDeviceOwner(
|
||||
@UserIdInt int userId, ComponentName adminComponent, String name) {
|
||||
@UserIdInt int userId, ComponentName adminComponent) {
|
||||
enableAndSetActiveAdmin(userId, userId, adminComponent);
|
||||
// TODO(b/178187130): Directly set DO and remove the check once silent provisioning is no
|
||||
// longer used.
|
||||
if (getDeviceOwnerComponent(/* callingUserOnly= */ true) == null) {
|
||||
return setDeviceOwner(adminComponent, name, userId,
|
||||
return setDeviceOwner(adminComponent, userId,
|
||||
/* setProfileOwnerOnCurrentUserIfNecessary= */ true);
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -256,7 +256,7 @@ final class DevicePolicyManagerServiceShellCommand extends ShellCommand {
|
||||
mService.setActiveAdmin(mComponent, /* refreshing= */ true, mUserId);
|
||||
|
||||
try {
|
||||
if (!mService.setDeviceOwner(mComponent, mName, mUserId,
|
||||
if (!mService.setDeviceOwner(mComponent, mUserId,
|
||||
/* setProfileOwnerOnCurrentUserIfNecessary= */ !mSetDoOnly)) {
|
||||
throw new RuntimeException(
|
||||
"Can't set package " + mComponent + " as device owner.");
|
||||
|
||||
@@ -966,7 +966,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
||||
|
||||
// Set admin1 to active admin and device owner
|
||||
dpm.setActiveAdmin(admin1, false);
|
||||
dpm.setDeviceOwner(admin1, null, UserHandle.USER_SYSTEM);
|
||||
dpm.setDeviceOwner(admin1, UserHandle.USER_SYSTEM);
|
||||
|
||||
// Save password history length
|
||||
dpm.setPasswordHistoryLength(admin1, passwordHistoryLength);
|
||||
@@ -1124,7 +1124,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
||||
dpm.setActiveAdmin(admin1, /* replace =*/ false);
|
||||
|
||||
// Fire!
|
||||
assertThat(dpm.setDeviceOwner(admin1, "owner-name", UserHandle.USER_SYSTEM)).isTrue();
|
||||
assertThat(dpm.setDeviceOwner(admin1, UserHandle.USER_SYSTEM)).isTrue();
|
||||
|
||||
// getDeviceOwnerComponent should return the admin1 component.
|
||||
assertThat(dpm.getDeviceOwnerComponentOnCallingUser()).isEqualTo(admin1);
|
||||
@@ -1181,7 +1181,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
||||
// DO needs to be a DA
|
||||
dpm.setActiveAdmin(admin1, /* replace =*/ false, UserHandle.USER_SYSTEM);
|
||||
// DO should be set on headless system user
|
||||
assertThat(dpm.setDeviceOwner(admin1, "owner-name", UserHandle.USER_SYSTEM)).isTrue();
|
||||
assertThat(dpm.setDeviceOwner(admin1, UserHandle.USER_SYSTEM)).isTrue();
|
||||
// PO should be set on calling user.
|
||||
assertThat(dpm.getProfileOwnerAsUser(CALLER_USER_HANDLE)).isEqualTo(admin1);
|
||||
});
|
||||
@@ -1353,7 +1353,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
||||
|
||||
assertExpectException(IllegalArgumentException.class,
|
||||
/* messageRegex= */ "Invalid component",
|
||||
() -> dpm.setDeviceOwner(new ComponentName("a.b.c", ".def"), /* ownerName= */ null,
|
||||
() -> dpm.setDeviceOwner(new ComponentName("a.b.c", ".def"),
|
||||
UserHandle.USER_SYSTEM));
|
||||
}
|
||||
|
||||
@@ -1363,13 +1363,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.setDeviceOwner(admin1, "owner-name", UserHandle.USER_SYSTEM));
|
||||
() -> dpm.setDeviceOwner(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.setDeviceOwner(admin1, "owner-name", UserHandle.USER_SYSTEM));
|
||||
() -> dpm.setDeviceOwner(admin1, UserHandle.USER_SYSTEM));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1389,7 +1389,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
||||
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
|
||||
setUpPackageManagerForAdmin(admin1, DpmMockContext.CALLER_SYSTEM_USER_UID);
|
||||
dpm.setActiveAdmin(admin1, /* replace =*/ false);
|
||||
assertThat(dpm.setDeviceOwner(admin1, "owner-name", UserHandle.USER_SYSTEM)).isTrue();
|
||||
assertThat(dpm.setDeviceOwner(admin1, UserHandle.USER_SYSTEM)).isTrue();
|
||||
assertThat(dpm.getDeviceOwnerComponentOnAnyUser()).isEqualTo(admin1);
|
||||
|
||||
dpm.addUserRestriction(admin1, UserManager.DISALLOW_ADD_USER);
|
||||
@@ -1452,7 +1452,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
||||
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
|
||||
setUpPackageManagerForAdmin(admin1, DpmMockContext.CALLER_SYSTEM_USER_UID);
|
||||
dpm.setActiveAdmin(admin1, /* replace =*/ false);
|
||||
assertThat(dpm.setDeviceOwner(admin1, "owner-name", UserHandle.USER_SYSTEM)).isTrue();
|
||||
assertThat(dpm.setDeviceOwner(admin1, UserHandle.USER_SYSTEM)).isTrue();
|
||||
|
||||
verify(getServices().ibackupManager, times(1)).setBackupServiceActive(
|
||||
eq(UserHandle.USER_SYSTEM), eq(false));
|
||||
@@ -1493,7 +1493,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
||||
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
|
||||
setUpPackageManagerForAdmin(admin1, DpmMockContext.CALLER_SYSTEM_USER_UID);
|
||||
dpm.setActiveAdmin(admin1, /* replace =*/ false);
|
||||
assertThat(dpm.setDeviceOwner(admin1, "owner-name", UserHandle.USER_SYSTEM)).isTrue();
|
||||
assertThat(dpm.setDeviceOwner(admin1, UserHandle.USER_SYSTEM)).isTrue();
|
||||
assertThat(dpm.getDeviceOwnerComponentOnAnyUser()).isEqualTo(admin1);
|
||||
|
||||
// Now call clear from the secondary user, which should throw.
|
||||
@@ -1527,7 +1527,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
||||
|
||||
// Set admin1 to active admin and device owner
|
||||
dpm.setActiveAdmin(admin1, /* replace =*/ false);
|
||||
dpm.setDeviceOwner(admin1, null, UserHandle.USER_SYSTEM);
|
||||
dpm.setDeviceOwner(admin1, UserHandle.USER_SYSTEM);
|
||||
|
||||
// Add reset password token
|
||||
final long handle = 12000;
|
||||
@@ -1566,8 +1566,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
||||
dpm.setActiveAdmin(admin2, /* refreshing= */ true, CALLER_USER_HANDLE);
|
||||
assertExpectException(IllegalStateException.class,
|
||||
/* messageRegex= */ "already has a profile owner",
|
||||
() -> dpm.setDeviceOwner(admin2, "owner-name",
|
||||
CALLER_USER_HANDLE));
|
||||
() -> dpm.setDeviceOwner(admin2, CALLER_USER_HANDLE));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1656,7 +1655,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
||||
|
||||
// Set DO on the system user which is only allowed during first boot.
|
||||
setUserSetupCompleteForUser(false, UserHandle.USER_SYSTEM);
|
||||
assertThat(dpm.setDeviceOwner(admin3, "owner-name", UserHandle.USER_SYSTEM)).isTrue();
|
||||
assertThat(dpm.setDeviceOwner(admin3, UserHandle.USER_SYSTEM)).isTrue();
|
||||
assertThat(dpms.getDeviceOwnerComponent(/* callingUserOnly =*/ false)).isEqualTo(admin3);
|
||||
|
||||
// Then check getDeviceOwnerAdminLocked().
|
||||
@@ -1979,8 +1978,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
||||
|
||||
// Call.
|
||||
dpm.setActiveAdmin(admin1, /* replace =*/ false, UserHandle.USER_SYSTEM);
|
||||
assertThat(dpm.setDeviceOwner(admin1, "owner-name",
|
||||
UserHandle.USER_SYSTEM)).isTrue();
|
||||
assertThat(dpm.setDeviceOwner(admin1, UserHandle.USER_SYSTEM)).isTrue();
|
||||
|
||||
assertNoDeviceOwnerRestrictions();
|
||||
reset(getServices().userManagerInternal);
|
||||
@@ -2358,8 +2356,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
||||
setUpPackageManagerForAdmin(admin1, DpmMockContext.CALLER_SYSTEM_USER_UID);
|
||||
|
||||
dpm.setActiveAdmin(admin1, /* replace =*/ false, UserHandle.USER_SYSTEM);
|
||||
assertThat(dpm.setDeviceOwner(admin1, "owner-name",
|
||||
UserHandle.USER_SYSTEM)).isTrue();
|
||||
assertThat(dpm.setDeviceOwner(admin1, UserHandle.USER_SYSTEM)).isTrue();
|
||||
|
||||
assertNoDeviceOwnerRestrictions();
|
||||
|
||||
@@ -2695,7 +2692,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
||||
dpm.clearProfileOwner(admin1);
|
||||
dpm.setActiveAdmin(admin1, false);
|
||||
// Test 4, Caller is DO now.
|
||||
assertThat(dpm.setDeviceOwner(admin1, null, UserHandle.USER_SYSTEM)).isTrue();
|
||||
assertThat(dpm.setDeviceOwner(admin1, UserHandle.USER_SYSTEM)).isTrue();
|
||||
|
||||
// 4-1. But WifiManager is not ready.
|
||||
assertThat(dpm.getWifiMacAddress(admin1)).isNull();
|
||||
@@ -2745,7 +2742,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
||||
// Remove PO and add DO.
|
||||
dpm.clearProfileOwner(admin1);
|
||||
dpm.setActiveAdmin(admin1, false);
|
||||
assertThat(dpm.setDeviceOwner(admin1, null, UserHandle.USER_SYSTEM)).isTrue();
|
||||
assertThat(dpm.setDeviceOwner(admin1, UserHandle.USER_SYSTEM)).isTrue();
|
||||
|
||||
// admin1 is DO.
|
||||
// Set current call state of device to ringing.
|
||||
@@ -3030,7 +3027,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
||||
// Set a device owner on the system user. Check that the system user becomes affiliated.
|
||||
setUpPackageManagerForAdmin(admin1, DpmMockContext.CALLER_SYSTEM_USER_UID);
|
||||
dpm.setActiveAdmin(admin1, /* replace =*/ false);
|
||||
assertThat(dpm.setDeviceOwner(admin1, "owner-name", UserHandle.USER_SYSTEM)).isTrue();
|
||||
assertThat(dpm.setDeviceOwner(admin1, UserHandle.USER_SYSTEM)).isTrue();
|
||||
assertThat(dpm.isAffiliatedUser()).isTrue();
|
||||
assertThat(dpm.getAffiliationIds(admin1).isEmpty()).isTrue();
|
||||
|
||||
@@ -3254,7 +3251,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
||||
|
||||
setUpPackageManagerForAdmin(admin1, DpmMockContext.CALLER_SYSTEM_USER_UID);
|
||||
dpm.setActiveAdmin(admin1, false);
|
||||
assertThat(dpm.setDeviceOwner(admin1, null, UserHandle.USER_SYSTEM)).isTrue();
|
||||
assertThat(dpm.setDeviceOwner(admin1, UserHandle.USER_SYSTEM)).isTrue();
|
||||
|
||||
mContext.callerPermissions.removeAll(OWNER_SETUP_PERMISSIONS);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user