Allow setting managing organization for the device
The Profile Owner of a managed profile can set a string that will be shown in the UI to identify the organization managing the profile. This CL extends the functionality to the Device Owner of a managed device. Bug: 32692748 Test: DevicePolicyManagerTest unit test + CTS test in separate CL Change-Id: I47295da2fd6485ebf0e890da13990a044accaf17
This commit is contained in:
@@ -6205,6 +6205,7 @@ package android.app.admin {
|
||||
method public java.lang.String getDeviceOwner();
|
||||
method public java.lang.CharSequence getDeviceOwnerLockScreenInfo();
|
||||
method public java.lang.String getDeviceOwnerNameOnAnyUser();
|
||||
method public java.lang.CharSequence getDeviceOwnerOrganizationName();
|
||||
method public java.util.List<byte[]> getInstalledCaCerts(android.content.ComponentName);
|
||||
method public int getKeyguardDisabledFeatures(android.content.ComponentName);
|
||||
method public java.lang.CharSequence getLongSupportMessage(android.content.ComponentName);
|
||||
|
||||
@@ -6046,6 +6046,7 @@ package android.app.admin {
|
||||
method public java.util.List<java.lang.String> getCrossProfileWidgetProviders(android.content.ComponentName);
|
||||
method public int getCurrentFailedPasswordAttempts();
|
||||
method public java.lang.CharSequence getDeviceOwnerLockScreenInfo();
|
||||
method public java.lang.CharSequence getDeviceOwnerOrganizationName();
|
||||
method public java.util.List<byte[]> getInstalledCaCerts(android.content.ComponentName);
|
||||
method public int getKeyguardDisabledFeatures(android.content.ComponentName);
|
||||
method public long getLastBugReportRequestTime();
|
||||
|
||||
@@ -6424,7 +6424,7 @@ public class DevicePolicyManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by a profile owner of a managed profile to set the name of the organization under
|
||||
* Called by the device owner or profile owner to set the name of the organization under
|
||||
* management.
|
||||
* <p>
|
||||
* If the organization name needs to be localized, it is the responsibility of the
|
||||
@@ -6433,7 +6433,7 @@ public class DevicePolicyManager {
|
||||
*
|
||||
* @param admin Which {@link DeviceAdminReceiver} this request is associated with.
|
||||
* @param title The organization name or {@code null} to clear a previously set name.
|
||||
* @throws SecurityException if {@code admin} is not a profile owner.
|
||||
* @throws SecurityException if {@code admin} is not a device or profile owner.
|
||||
*/
|
||||
public void setOrganizationName(@NonNull ComponentName admin, @Nullable CharSequence title) {
|
||||
throwIfParentInstance("setOrganizationName");
|
||||
@@ -6461,6 +6461,25 @@ public class DevicePolicyManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the system to retrieve the name of the organization managing the device.
|
||||
*
|
||||
* @return The organization name or {@code null} if none is set.
|
||||
* @throws SecurityException if the caller is not the device owner, does not hold the
|
||||
* MANAGE_USERS permission and is not the system.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@SystemApi
|
||||
@TestApi
|
||||
public @Nullable CharSequence getDeviceOwnerOrganizationName() {
|
||||
try {
|
||||
return mService.getDeviceOwnerOrganizationName();
|
||||
} catch (RemoteException re) {
|
||||
throw re.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the default title message used in the confirm credentials screen for a given user.
|
||||
*
|
||||
|
||||
@@ -294,6 +294,7 @@ interface IDevicePolicyManager {
|
||||
|
||||
void setOrganizationName(in ComponentName admin, in CharSequence title);
|
||||
CharSequence getOrganizationName(in ComponentName admin);
|
||||
CharSequence getDeviceOwnerOrganizationName();
|
||||
CharSequence getOrganizationNameForUser(int userHandle);
|
||||
|
||||
int getUserProvisioningState();
|
||||
|
||||
@@ -9126,7 +9126,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
|
||||
}
|
||||
Preconditions.checkNotNull(who, "ComponentName is null");
|
||||
final int userHandle = mInjector.userHandleGetCallingUserId();
|
||||
enforceManagedProfile(userHandle, "set organization name");
|
||||
|
||||
synchronized (this) {
|
||||
ActiveAdmin admin = getActiveAdminForCallerLocked(who,
|
||||
DeviceAdminInfo.USES_POLICY_PROFILE_OWNER);
|
||||
@@ -9152,6 +9152,18 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getDeviceOwnerOrganizationName() {
|
||||
if (!mHasFeature) {
|
||||
return null;
|
||||
}
|
||||
enforceDeviceOwnerOrManageUsers();
|
||||
synchronized(this) {
|
||||
final ActiveAdmin deviceOwnerAdmin = getDeviceOwnerAdminLocked();
|
||||
return deviceOwnerAdmin == null ? null : deviceOwnerAdmin.organizationName;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getOrganizationNameForUser(int userHandle) {
|
||||
if (!mHasFeature) {
|
||||
|
||||
@@ -2532,6 +2532,30 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
||||
assertFalse(dpm.isDeviceManaged());
|
||||
}
|
||||
|
||||
public void testDeviceOwnerOrganizationName() throws Exception {
|
||||
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
|
||||
setupDeviceOwner();
|
||||
|
||||
dpm.setOrganizationName(admin1, "organization");
|
||||
|
||||
// Device owner can retrieve organization managing the device.
|
||||
assertEquals("organization", dpm.getDeviceOwnerOrganizationName());
|
||||
|
||||
// Any uid holding MANAGE_USERS permission can retrieve organization managing the device.
|
||||
mContext.binder.callingUid = 1234567;
|
||||
mContext.callerPermissions.add(permission.MANAGE_USERS);
|
||||
assertEquals("organization", dpm.getDeviceOwnerOrganizationName());
|
||||
mContext.callerPermissions.remove(permission.MANAGE_USERS);
|
||||
|
||||
// System can retrieve organization managing the device.
|
||||
mContext.binder.clearCallingIdentity();
|
||||
assertEquals("organization", dpm.getDeviceOwnerOrganizationName());
|
||||
|
||||
// Removing the device owner clears the organization managing the device.
|
||||
clearDeviceOwner();
|
||||
assertNull(dpm.getDeviceOwnerOrganizationName());
|
||||
}
|
||||
|
||||
private void setUserSetupCompleteForUser(boolean isUserSetupComplete, int userhandle) {
|
||||
when(mContext.settings.settingsSecureGetIntForUser(Settings.Secure.USER_SETUP_COMPLETE, 0,
|
||||
userhandle)).thenReturn(isUserSetupComplete ? 1 : 0);
|
||||
|
||||
Reference in New Issue
Block a user