Moves enforcedAdmin into UserRecord.

In an effort to move logic out of the old UserSwitcherController
implementation, we are moving the concept of an enforced admin for user
actions that are disabled by an administrator into the actual
UserRecord itself.

This CL has no logical changes beyond moving where the state is being
held to a more common one.

Bug: 246631653
Test: Manually verified the old implementation of the full-screen user
switcher, the quick settings button, and the lock-screen user dropdown
all still work properly.

Change-Id: I8b6bd8f3424fe531aa4889f530968f6f48fec536
This commit is contained in:
Alejandro Nijamkin
2022-09-19 09:55:51 -07:00
parent df2bdd5135
commit 963f710d4c
7 changed files with 74 additions and 75 deletions

View File

@@ -134,7 +134,7 @@ public class UserDetailView extends PseudoGridView {
v.bind(name, drawable, item.info.id);
}
v.setActivated(item.isCurrent);
v.setDisabledByAdmin(mController.isDisabledByAdmin(item));
v.setDisabledByAdmin(item.isDisabledByAdmin());
v.setEnabled(item.isSwitchToEnabled);
UserSwitcherController.setSelectableAlpha(v);
@@ -173,16 +173,16 @@ public class UserDetailView extends PseudoGridView {
Trace.beginSection("UserDetailView.Adapter#onClick");
UserRecord userRecord =
(UserRecord) view.getTag();
if (mController.isDisabledByAdmin(userRecord)) {
if (userRecord.isDisabledByAdmin()) {
final Intent intent = RestrictedLockUtils.getShowAdminSupportDetailsIntent(
mContext, mController.getEnforcedAdmin(userRecord));
mContext, userRecord.enforcedAdmin);
mController.startActivity(intent);
} else if (userRecord.isSwitchToEnabled) {
MetricsLogger.action(mContext, MetricsEvent.QS_SWITCH_USER);
mUiEventLogger.log(QSUserSwitcherEvent.QS_USER_SWITCH);
if (!userRecord.isAddUser
&& !userRecord.isRestricted
&& !mController.isDisabledByAdmin(userRecord)) {
&& !userRecord.isDisabledByAdmin()) {
if (mCurrentUserView != null) {
mCurrentUserView.setActivated(false);
}

View File

@@ -505,7 +505,7 @@ public class KeyguardUserSwitcherController extends ViewController<KeyguardUserS
v.bind(name, drawable, item.info.id);
}
v.setActivated(item.isCurrent);
v.setDisabledByAdmin(getController().isDisabledByAdmin(item));
v.setDisabledByAdmin(item.isDisabledByAdmin());
v.setEnabled(item.isSwitchToEnabled);
UserSwitcherController.setSelectableAlpha(v);

View File

@@ -19,7 +19,6 @@ package com.android.systemui.statusbar.policy
import android.annotation.UserIdInt
import android.content.Intent
import android.view.View
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin
import com.android.systemui.Dumpable
import com.android.systemui.qs.user.UserSwitchDialogController.DialogShower
import com.android.systemui.user.data.source.UserRecord
@@ -130,12 +129,6 @@ interface UserSwitcherController : Dumpable {
/** Whether keyguard is showing. */
val isKeyguardShowing: Boolean
/** Returns the [EnforcedAdmin] for the given record, or `null` if there isn't one. */
fun getEnforcedAdmin(record: UserRecord): EnforcedAdmin?
/** Returns `true` if the given record is disabled by the admin; `false` otherwise. */
fun isDisabledByAdmin(record: UserRecord): Boolean
/** Starts an activity with the given [Intent]. */
fun startActivity(intent: Intent)

View File

@@ -19,7 +19,6 @@ package com.android.systemui.statusbar.policy
import android.content.Intent
import android.view.View
import com.android.settingslib.RestrictedLockUtils
import com.android.systemui.flags.FeatureFlags
import com.android.systemui.flags.Flags
import com.android.systemui.qs.user.UserSwitchDialogController
@@ -211,22 +210,6 @@ constructor(
_oldImpl.isKeyguardShowing
}
override fun getEnforcedAdmin(record: UserRecord): RestrictedLockUtils.EnforcedAdmin? {
return if (isNewImpl) {
notYetImplemented()
} else {
_oldImpl.getEnforcedAdmin(record)
}
}
override fun isDisabledByAdmin(record: UserRecord): Boolean {
return if (isNewImpl) {
notYetImplemented()
} else {
_oldImpl.isDisabledByAdmin(record)
}
}
override fun startActivity(intent: Intent) {
if (isNewImpl) {
notYetImplemented()

View File

@@ -40,7 +40,6 @@ import android.os.UserManager;
import android.provider.Settings;
import android.telephony.TelephonyCallback;
import android.text.TextUtils;
import android.util.ArraySet;
import android.util.Log;
import android.util.SparseArray;
import android.util.SparseBooleanArray;
@@ -49,7 +48,6 @@ import android.view.WindowManagerGlobal;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.collection.SimpleArrayMap;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.jank.InteractionJankMonitor;
@@ -139,9 +137,6 @@ public class UserSwitcherControllerOldImpl implements UserSwitcherController {
private final InteractionJankMonitor mInteractionJankMonitor;
private final LatencyTracker mLatencyTracker;
private final DialogLaunchAnimator mDialogLaunchAnimator;
private final SimpleArrayMap<UserRecord, EnforcedAdmin> mEnforcedAdminByUserRecord =
new SimpleArrayMap<>();
private final ArraySet<UserRecord> mDisabledByAdmin = new ArraySet<>();
private ArrayList<UserRecord> mUsers = new ArrayList<>();
@VisibleForTesting
@@ -346,7 +341,7 @@ public class UserSwitcherControllerOldImpl implements UserSwitcherController {
guestRecord = new UserRecord(info, null /* picture */,
true /* isGuest */, isCurrent, false /* isAddUser */,
false /* isRestricted */, canSwitchUsers,
false /* isAddSupervisedUser */);
false /* isAddSupervisedUser */, null /* enforcedAdmin */);
} else if (info.supportsSwitchToByUser()) {
Bitmap picture = bitmaps.get(info.id);
if (picture == null) {
@@ -361,7 +356,8 @@ public class UserSwitcherControllerOldImpl implements UserSwitcherController {
}
records.add(new UserRecord(info, picture, false /* isGuest */,
isCurrent, false /* isAddUser */, false /* isRestricted */,
switchToEnabled, false /* isAddSupervisedUser */));
switchToEnabled, false /* isAddSupervisedUser */,
null /* enforcedAdmin */));
}
}
}
@@ -372,18 +368,28 @@ public class UserSwitcherControllerOldImpl implements UserSwitcherController {
// we will just use it as an indicator for "Resetting guest...".
// Otherwise, default to canSwitchUsers.
boolean isSwitchToGuestEnabled = !mGuestIsResetting.get() && canSwitchUsers;
guestRecord = new UserRecord(null /* info */, null /* picture */,
true /* isGuest */, false /* isCurrent */,
false /* isAddUser */, false /* isRestricted */,
isSwitchToGuestEnabled, false /* isAddSupervisedUser */);
checkIfAddUserDisallowedByAdminOnly(guestRecord);
guestRecord = new UserRecord(
null /* info */,
null /* picture */,
true /* isGuest */,
false /* isCurrent */,
false /* isAddUser */,
false /* isRestricted */,
isSwitchToGuestEnabled,
false /* isAddSupervisedUser */,
getEnforcedAdmin());
records.add(guestRecord);
} else if (canCreateGuest(guestRecord != null)) {
guestRecord = new UserRecord(null /* info */, null /* picture */,
true /* isGuest */, false /* isCurrent */,
false /* isAddUser */, createIsRestricted(), canSwitchUsers,
false /* isAddSupervisedUser */);
checkIfAddUserDisallowedByAdminOnly(guestRecord);
guestRecord = new UserRecord(
null /* info */,
null /* picture */,
true /* isGuest */,
false /* isCurrent */,
false /* isAddUser */,
createIsRestricted(),
canSwitchUsers,
false /* isAddSupervisedUser */,
getEnforcedAdmin());
records.add(guestRecord);
}
} else {
@@ -391,19 +397,30 @@ public class UserSwitcherControllerOldImpl implements UserSwitcherController {
}
if (canCreateUser()) {
UserRecord addUserRecord = new UserRecord(null /* info */, null /* picture */,
false /* isGuest */, false /* isCurrent */, true /* isAddUser */,
createIsRestricted(), canSwitchUsers,
false /* isAddSupervisedUser */);
checkIfAddUserDisallowedByAdminOnly(addUserRecord);
UserRecord addUserRecord = new UserRecord(
null /* info */,
null /* picture */,
false /* isGuest */,
false /* isCurrent */,
true /* isAddUser */,
createIsRestricted(),
canSwitchUsers,
false /* isAddSupervisedUser */,
getEnforcedAdmin());
records.add(addUserRecord);
}
if (canCreateSupervisedUser()) {
UserRecord addUserRecord = new UserRecord(null /* info */, null /* picture */,
false /* isGuest */, false /* isCurrent */, false /* isAddUser */,
createIsRestricted(), canSwitchUsers, true /* isAddSupervisedUser */);
checkIfAddUserDisallowedByAdminOnly(addUserRecord);
UserRecord addUserRecord = new UserRecord(
null /* info */,
null /* picture */,
false /* isGuest */,
false /* isCurrent */,
false /* isAddUser */,
createIsRestricted(),
canSwitchUsers,
true /* isAddSupervisedUser */,
getEnforcedAdmin());
records.add(addUserRecord);
}
@@ -964,27 +981,19 @@ public class UserSwitcherControllerOldImpl implements UserSwitcherController {
return mKeyguardStateController.isShowing();
}
@Override
@Nullable
public EnforcedAdmin getEnforcedAdmin(UserRecord record) {
return mEnforcedAdminByUserRecord.get(record);
}
@Override
public boolean isDisabledByAdmin(UserRecord record) {
return mDisabledByAdmin.contains(record);
}
private void checkIfAddUserDisallowedByAdminOnly(UserRecord record) {
EnforcedAdmin admin = RestrictedLockUtilsInternal.checkIfRestrictionEnforced(mContext,
UserManager.DISALLOW_ADD_USER, mUserTracker.getUserId());
if (admin != null && !RestrictedLockUtilsInternal.hasBaseUserRestriction(mContext,
UserManager.DISALLOW_ADD_USER, mUserTracker.getUserId())) {
mDisabledByAdmin.add(record);
mEnforcedAdminByUserRecord.put(record, admin);
private EnforcedAdmin getEnforcedAdmin() {
final EnforcedAdmin admin = RestrictedLockUtilsInternal.checkIfRestrictionEnforced(
mContext,
UserManager.DISALLOW_ADD_USER,
mUserTracker.getUserId());
if (admin != null && !RestrictedLockUtilsInternal.hasBaseUserRestriction(
mContext,
UserManager.DISALLOW_ADD_USER,
mUserTracker.getUserId())) {
return admin;
} else {
mDisabledByAdmin.remove(record);
mEnforcedAdminByUserRecord.put(record, null);
return null;
}
}

View File

@@ -19,6 +19,7 @@ package com.android.systemui.user.data.source
import android.content.pm.UserInfo
import android.graphics.Bitmap
import android.os.UserHandle
import com.android.settingslib.RestrictedLockUtils
/** Encapsulates raw data for a user or an option item related to managing users on the device. */
data class UserRecord(
@@ -41,6 +42,11 @@ data class UserRecord(
@JvmField val isSwitchToEnabled: Boolean = false,
/** Whether this record represents an option to add another supervised user to the device. */
@JvmField val isAddSupervisedUser: Boolean = false,
/**
* An enforcing admin, if the user action represented by this record is disabled by the admin.
* If not disabled, this is `null`.
*/
@JvmField val enforcedAdmin: RestrictedLockUtils.EnforcedAdmin? = null,
) {
/** Returns a new instance of [UserRecord] with its [isCurrent] set to the given value. */
fun copyWithIsCurrent(isCurrent: Boolean): UserRecord {
@@ -59,6 +65,14 @@ data class UserRecord(
}
}
/**
* Returns `true` if the user action represented by this record has been disabled by an admin;
* `false` otherwise.
*/
fun isDisabledByAdmin(): Boolean {
return enforcedAdmin != null
}
companion object {
@JvmStatic
fun createForGuest(): UserRecord {

View File

@@ -411,7 +411,7 @@ public class KeyguardSecurityContainerTest extends SysuiTestCase {
0 /* flags */);
users.add(new UserRecord(info, null, false /* isGuest */, false /* isCurrent */,
false /* isAddUser */, false /* isRestricted */, true /* isSwitchToEnabled */,
false /* isAddSupervisedUser */));
false /* isAddSupervisedUser */, null /* enforcedAdmin */));
}
return users;
}