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

Commit 41c2aed9 authored by Eran Messeri's avatar Eran Messeri
Browse files

Make the method for finding out if a device is org-owned public.

Make isOrganizationOwnedDeviceWithManagedProfile a public method, as
there is no reason to keep this information hidden from apps.

Test: atest CtsDevicePolicyManagerTestCases:com.android.cts.devicepolicy.OrgOwnedProfileOwnerTest#testIsDeviceOrganizationOwnedWithManagedProfile
Test: atest CtsDevicePolicyManagerTestCases:com.android.cts.devicepolicy.MixedProfileOwnerTest#testIsDeviceOrganizationOwnedWithManagedProfile
Test: atest CtsDevicePolicyManagerTestCases:com.android.cts.devicepolicy.MixedDeviceOwnerTest#testIsDeviceOrganizationOwnedWithManagedProfile
Bug: 143518237
Bug: 144978467
Bug: 147340575
Bug: 146123237
Change-Id: Iab45f20c9150a6b8bd48eea610484f36f199d3d7
parent 06a258a3
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -6836,6 +6836,7 @@ package android.app.admin {
    method public boolean isManagedProfile(@NonNull android.content.ComponentName);
    method public boolean isMasterVolumeMuted(@NonNull android.content.ComponentName);
    method public boolean isNetworkLoggingEnabled(@Nullable android.content.ComponentName);
    method public boolean isOrganizationOwnedDeviceWithManagedProfile();
    method public boolean isOverrideApnEnabled(@NonNull android.content.ComponentName);
    method public boolean isPackageSuspended(@NonNull android.content.ComponentName, String) throws android.content.pm.PackageManager.NameNotFoundException;
    method public boolean isProfileOwnerApp(String);
+0 −1
Original line number Diff line number Diff line
@@ -804,7 +804,6 @@ package android.app.admin {
    method @RequiresPermission(android.Manifest.permission.MANAGE_USERS) public boolean isDeviceProvisioned();
    method @RequiresPermission(android.Manifest.permission.MANAGE_USERS) public boolean isDeviceProvisioningConfigApplied();
    method @RequiresPermission(android.Manifest.permission.MANAGE_USERS) public boolean isManagedKiosk();
    method @RequiresPermission(android.Manifest.permission.MANAGE_USERS) public boolean isOrganizationOwnedDeviceWithManagedProfile();
    method @RequiresPermission(android.Manifest.permission.MANAGE_USERS) public boolean isUnattendedManagedKiosk();
    method @RequiresPermission("android.permission.NOTIFY_PENDING_SYSTEM_UPDATE") public void notifyPendingSystemUpdate(long);
    method @RequiresPermission("android.permission.NOTIFY_PENDING_SYSTEM_UPDATE") public void notifyPendingSystemUpdate(long, boolean);
+4 −7
Original line number Diff line number Diff line
@@ -6850,21 +6850,18 @@ public class DevicePolicyManager {
    }
    /**
     * @hide
     * Privileged apps can use this method to find out if the device was provisioned as
     * Apps can use this method to find out if the device was provisioned as
     * organization-owend device with a managed profile.
     *
     * This, together with checking whether the device has a device owner (by calling
     * {@link #isDeviceManaged()}), could be used to learn whether the device is owned by an
     * {@link #isDeviceOwnerApp}), could be used to learn whether the device is owned by an
     * organization or an individual:
     * If this method returns true OR {@link #isDeviceManaged()} returns true, then
     * the device is owned by an organization. Otherwise, it's owned by an individual.
     * If this method returns true OR {@link #isDeviceOwnerApp} returns true (for any package),
     * then the device is owned by an organization. Otherwise, it's owned by an individual.
     *
     * @return {@code true} if the device was provisioned as organization-owned device,
     * {@code false} otherwise.
     */
    @SystemApi
    @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
    public boolean isOrganizationOwnedDeviceWithManagedProfile() {
        throwIfParentInstance("isOrganizationOwnedDeviceWithManagedProfile");
        if (mService != null) {
+0 −1
Original line number Diff line number Diff line
@@ -8724,7 +8724,6 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        if (!mHasFeature) {
            return false;
        }
        enforceManageUsers();
        return mInjector.binderWithCleanCallingIdentity(() -> {
            for (UserInfo ui : mUserManager.getUsers()) {
+1 −5
Original line number Diff line number Diff line
@@ -3801,11 +3801,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
        when(getServices().userManager.getUsers())
                .thenReturn(Arrays.asList(managedProfileUserInfo));

        // Any caller without the MANAGE_USERS permission should get a security exception.
        assertExpectException(SecurityException.class, null, () ->
                dpm.isOrganizationOwnedDeviceWithManagedProfile());
        // But when the right permission is granted, this should succeed.
        mContext.permissions.add(android.Manifest.permission.MANAGE_USERS);
        // Any caller should be able to call this method.
        assertFalse(dpm.isOrganizationOwnedDeviceWithManagedProfile());
        configureProfileOwnerOfOrgOwnedDevice(admin1, DpmMockContext.CALLER_USER_HANDLE);
        assertTrue(dpm.isOrganizationOwnedDeviceWithManagedProfile());