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

Commit c64fa36e authored by Eric Biggers's avatar Eric Biggers
Browse files

Complete removal of device policy from UserManagerInternal

DEPRECATE_USERMANAGERINTERNAL_DEVICEPOLICY_FLAG defaults to true, and no
one appears to be overriding it via DeviceConfig.  Therefore, all the
code that is conditional on this flag being false is unused.  Remove it.
Then remove the UserManagerInternal methods that were only "used" by
this unused code, and the mIsDeviceManaged and mIsUserManaged fields in
UserManagerService which existed only to support these methods.

Bug: 258213147
Flag: EXEMPT removing already-launched flag
Test: atest Frameworks{,Mocking}ServicesTests:com.android.server.{devicepolicy,locksettings}
Change-Id: I06ce80ad2eba5ad2c04ed73055c4d2289cbc3be6
parent 23d4a978
Loading
Loading
Loading
Loading
+0 −5
Original line number Diff line number Diff line
@@ -318,11 +318,6 @@ import java.util.function.Consumer;
@RequiresFeature(PackageManager.FEATURE_DEVICE_ADMIN)
public class DevicePolicyManager {
    /** @hide */
    public static final String DEPRECATE_USERMANAGERINTERNAL_DEVICEPOLICY_FLAG =
            "deprecate_usermanagerinternal_devicepolicy";
    /** @hide */
    public static final boolean DEPRECATE_USERMANAGERINTERNAL_DEVICEPOLICY_DEFAULT = true;
    /** @hide */
    public static final String ADD_ISFINANCED_DEVICE_FLAG =
            "add-isfinanced-device";
+3 −26
Original line number Diff line number Diff line
@@ -21,8 +21,6 @@ import static android.Manifest.permission.CONFIGURE_FACTORY_RESET_PROTECTION;
import static android.Manifest.permission.MANAGE_BIOMETRIC;
import static android.Manifest.permission.SET_AND_VERIFY_LOCKSCREEN_CREDENTIALS;
import static android.Manifest.permission.SET_INITIAL_LOCK;
import static android.app.admin.DevicePolicyManager.DEPRECATE_USERMANAGERINTERNAL_DEVICEPOLICY_DEFAULT;
import static android.app.admin.DevicePolicyManager.DEPRECATE_USERMANAGERINTERNAL_DEVICEPOLICY_FLAG;
import static android.app.admin.DevicePolicyResources.Strings.Core.PROFILE_ENCRYPTED_DETAIL;
import static android.app.admin.DevicePolicyResources.Strings.Core.PROFILE_ENCRYPTED_MESSAGE;
import static android.app.admin.DevicePolicyResources.Strings.Core.PROFILE_ENCRYPTED_TITLE;
@@ -106,7 +104,6 @@ import android.os.storage.ICeStorageLockEventListener;
import android.os.storage.IStorageManager;
import android.os.storage.StorageManager;
import android.os.storage.StorageManagerInternal;
import android.provider.DeviceConfig;
import android.provider.Settings;
import android.security.AndroidKeyStoreMaintenance;
import android.security.KeyStoreAuthorization;
@@ -3539,32 +3536,12 @@ public class LockSettingsService extends ILockSettings.Stub {
            return;
        }

        // TODO(b/258213147): Remove
        final long identity = Binder.clearCallingIdentity();
        try {
            if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_DEVICE_POLICY_MANAGER,
                    DEPRECATE_USERMANAGERINTERNAL_DEVICEPOLICY_FLAG,
                    DEPRECATE_USERMANAGERINTERNAL_DEVICEPOLICY_DEFAULT)) {

            if (mInjector.getDeviceStateCache().isUserOrganizationManaged(userId)) {
                Slog.i(TAG, "Organization managed users can have escrow token");
                return;
            }
            } else {
                final UserManagerInternal userManagerInternal = mInjector.getUserManagerInternal();

                // Managed profile should have escrow enabled
                if (userManagerInternal.isUserManaged(userId)) {
                    Slog.i(TAG, "Managed profile can have escrow token");
                    return;
                }

                // Devices with Device Owner should have escrow enabled on all users.
                if (userManagerInternal.isDeviceManaged()) {
                    Slog.i(TAG, "Corp-owned device can have escrow token");
                    return;
                }
            }
        } finally {
            Binder.restoreCallingIdentity(identity);
        }
+0 −38
Original line number Diff line number Diff line
@@ -197,44 +197,6 @@ public abstract class UserManagerInternal {
    /** Removes a {@link UserLifecycleListener}. */
    public abstract void removeUserLifecycleListener(UserLifecycleListener listener);

    /**
     * Called by {@link com.android.server.devicepolicy.DevicePolicyManagerService} to update
     * whether the device is managed by device owner.
     *
     * @deprecated Use methods in {@link android.app.admin.DevicePolicyManagerInternal}.
     */
    @Deprecated
    // TODO(b/258213147): Remove
    public abstract void setDeviceManaged(boolean isManaged);

    /**
     * Returns whether the device is managed by device owner.
     *
     * @deprecated Use methods in {@link android.app.admin.DevicePolicyManagerInternal}.
     */
    @Deprecated
    // TODO(b/258213147): Remove
    public abstract boolean isDeviceManaged();

    /**
     * Called by {@link com.android.server.devicepolicy.DevicePolicyManagerService} to update
     * whether the user is managed by profile owner.
     *
     * @deprecated Use methods in {@link android.app.admin.DevicePolicyManagerInternal}.
     */
    // TODO(b/258213147): Remove
    @Deprecated
    public abstract void setUserManaged(int userId, boolean isManaged);

    /**
     * Whether a profile owner manages this user.
     *
     * @deprecated Use methods in {@link android.app.admin.DevicePolicyManagerInternal}.
     */
    // TODO(b/258213147): Remove
    @Deprecated
    public abstract boolean isUserManaged(int userId);

    /**
     * Called by {@link com.android.server.devicepolicy.DevicePolicyManagerService} to omit
     * restriction check, because DevicePolicyManager must always be able to set user icon
+4 −44
Original line number Diff line number Diff line
@@ -563,12 +563,6 @@ public class UserManagerService extends IUserManager.Stub {

    private final LocalService mLocalService;

    @GuardedBy("mUsersLock")
    private boolean mIsDeviceManaged;

    @GuardedBy("mUsersLock")
    private final SparseBooleanArray mIsUserManaged = new SparseBooleanArray();

    @GuardedBy("mUserRestrictionsListeners")
    private final ArrayList<UserRestrictionsListener> mUserRestrictionsListeners =
            new ArrayList<>();
@@ -6769,7 +6763,6 @@ public class UserManagerService extends IUserManager.Stub {
        // Remove this user from the list
        synchronized (mUsersLock) {
            removeUserDataLU(userId);
            mIsUserManaged.delete(userId);
            getActivityManagerInternal().onUserRemoved(userId);
        }
        synchronized (mUserStates) {
@@ -7550,11 +7543,9 @@ public class UserManagerService extends IUserManager.Stub {
            synchronized (mGuestRestrictions) {
                UserRestrictionsUtils.dumpRestrictions(pw, "    ", mGuestRestrictions);
            }
            synchronized (mUsersLock) {
            pw.println();
                pw.println("  Device managed: " + mIsDeviceManaged);
            synchronized (mUsersLock) {
                if (mRemovingUserIds.size() > 0) {
                    pw.println();
                    pw.println("  Recently removed userIds: " + mRecentlyRemovedIds);
                }
            }
@@ -7728,8 +7719,9 @@ public class UserManagerService extends IUserManager.Stub {
        pw.print("    Last entered foreground: ");
        dumpTimeAgo(pw, tempStringBuilder, now, userData.mLastEnteredForegroundTimeMillis);

        pw.print("    Has profile owner: ");
        pw.println(mIsUserManaged.get(userId));
        // bedstead relies on this being here, even though since Android 14 this has always been
        // false. TODO(b/258213147) update bedstead and remove this.
        pw.println("    Has profile owner: false");

        pw.println("    Restrictions:");
        synchronized (mRestrictionsLock) {
@@ -7869,38 +7861,6 @@ public class UserManagerService extends IUserManager.Stub {
            }
        }

        // TODO(b/258213147): Remove
        @Override
        public void setDeviceManaged(boolean isManaged) {
            synchronized (mUsersLock) {
                mIsDeviceManaged = isManaged;
            }
        }

        // TODO(b/258213147): Remove
        @Override
        public boolean isDeviceManaged() {
            synchronized (mUsersLock) {
                return mIsDeviceManaged;
            }
        }

        // TODO(b/258213147): Remove
        @Override
        public void setUserManaged(@UserIdInt int userId, boolean isManaged) {
            synchronized (mUsersLock) {
                mIsUserManaged.put(userId, isManaged);
            }
        }

        // TODO(b/258213147): Remove
        @Override
        public boolean isUserManaged(@UserIdInt int userId) {
            synchronized (mUsersLock) {
                return mIsUserManaged.get(userId);
            }
        }

        @Override
        public void setUserIcon(@UserIdInt int userId, Bitmap bitmap) {
            final long ident = Binder.clearCallingIdentity();
+1 −1
Original line number Diff line number Diff line
@@ -2306,7 +2306,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
    private Owners makeOwners(Injector injector, PolicyPathProvider pathProvider) {
        return new Owners(
                injector.getUserManager(), injector.getUserManagerInternal(),
                injector.getUserManager(),
                injector.getPackageManagerInternal(),
                injector.getActivityTaskManagerInternal(),
                injector.getActivityManagerInternal(), mStateCache, pathProvider);
Loading