Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 365a3db4 authored by Bartosz Fabianowski's avatar Bartosz Fabianowski
Browse files

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
parent 0f10b2f1
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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);
+1 −0
Original line number Diff line number Diff line
@@ -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();
+21 −2
Original line number Diff line number Diff line
@@ -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.
     *
+1 −0
Original line number Diff line number Diff line
@@ -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();
+13 −1
Original line number Diff line number Diff line
@@ -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) {
Loading