diff options
| author | 2022-08-31 22:03:12 +0000 | |
|---|---|---|
| committer | 2022-08-31 22:03:12 +0000 | |
| commit | 94c3f13849d9f770ce62394976ce0a24ee6e6075 (patch) | |
| tree | 4a1496ac115d6f69722aa204526992f57bb58b38 | |
| parent | dc56080d6ebd7ecfe1c0f92a66abbd6627c124f3 (diff) | |
| parent | e3812679b0da71a9a717e729730ed542bad8c9e0 (diff) | |
Merge "Extracts UserRecord out of UserSwitcherController." into tm-qpr-dev am: 8006376ff7 am: e3812679b0
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19775120
Change-Id: I8c6d7a9123bb690af4fc44db2505f342ee446212
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
11 files changed, 214 insertions, 160 deletions
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java index 3517d22ae50d..d0baf3dad79d 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java @@ -89,7 +89,7 @@ import com.android.systemui.plugins.FalsingManager; import com.android.systemui.shared.system.SysUiStatsLog; import com.android.systemui.statusbar.policy.UserSwitcherController; import com.android.systemui.statusbar.policy.UserSwitcherController.BaseUserAdapter; -import com.android.systemui.statusbar.policy.UserSwitcherController.UserRecord; +import com.android.systemui.user.data.source.UserRecord; import com.android.systemui.util.settings.GlobalSettings; import java.util.ArrayList; diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/UserDetailView.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/UserDetailView.java index ce6aaae6e98c..0ec4eef1e551 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/UserDetailView.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/UserDetailView.java @@ -43,6 +43,7 @@ import com.android.systemui.qs.QSUserSwitcherEvent; import com.android.systemui.qs.user.UserSwitchDialogController; import com.android.systemui.statusbar.phone.SystemUIDialog; import com.android.systemui.statusbar.policy.UserSwitcherController; +import com.android.systemui.user.data.source.UserRecord; import javax.inject.Inject; @@ -95,7 +96,7 @@ public class UserDetailView extends PseudoGridView { @Override public View getView(int position, View convertView, ViewGroup parent) { - UserSwitcherController.UserRecord item = getItem(position); + UserRecord item = getItem(position); return createUserDetailItemView(convertView, parent, item); } @@ -113,7 +114,7 @@ public class UserDetailView extends PseudoGridView { } public UserDetailItemView createUserDetailItemView(View convertView, ViewGroup parent, - UserSwitcherController.UserRecord item) { + UserRecord item) { UserDetailItemView v = UserDetailItemView.convertOrInflate( parent.getContext(), convertView, parent); if (!item.isCurrent || item.isGuest) { @@ -134,7 +135,7 @@ public class UserDetailView extends PseudoGridView { v.bind(name, drawable, item.info.id); } v.setActivated(item.isCurrent); - v.setDisabledByAdmin(item.isDisabledByAdmin); + v.setDisabledByAdmin(mController.isDisabledByAdmin(item)); v.setEnabled(item.isSwitchToEnabled); v.setAlpha(v.isEnabled() ? USER_SWITCH_ENABLED_ALPHA : USER_SWITCH_DISABLED_ALPHA); @@ -146,7 +147,7 @@ public class UserDetailView extends PseudoGridView { } private static Drawable getDrawable(Context context, - UserSwitcherController.UserRecord item) { + UserRecord item) { Drawable icon = getIconDrawable(context, item); int iconColorRes; if (item.isCurrent) { @@ -171,22 +172,24 @@ public class UserDetailView extends PseudoGridView { } Trace.beginSection("UserDetailView.Adapter#onClick"); - UserSwitcherController.UserRecord tag = - (UserSwitcherController.UserRecord) view.getTag(); - if (tag.isDisabledByAdmin) { + UserRecord userRecord = + (UserRecord) view.getTag(); + if (mController.isDisabledByAdmin(userRecord)) { final Intent intent = RestrictedLockUtils.getShowAdminSupportDetailsIntent( - mContext, tag.enforcedAdmin); + mContext, mController.getEnforcedAdmin(userRecord)); mController.startActivity(intent); - } else if (tag.isSwitchToEnabled) { + } else if (userRecord.isSwitchToEnabled) { MetricsLogger.action(mContext, MetricsEvent.QS_SWITCH_USER); mUiEventLogger.log(QSUserSwitcherEvent.QS_USER_SWITCH); - if (!tag.isAddUser && !tag.isRestricted && !tag.isDisabledByAdmin) { + if (!userRecord.isAddUser + && !userRecord.isRestricted + && !mController.isDisabledByAdmin(userRecord)) { if (mCurrentUserView != null) { mCurrentUserView.setActivated(false); } view.setActivated(true); } - onUserListItemClicked(tag, mDialogShower); + onUserListItemClicked(userRecord, mDialogShower); } Trace.endSection(); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyguardQsUserSwitchController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyguardQsUserSwitchController.java index 169347a5ac1a..163060814545 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyguardQsUserSwitchController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyguardQsUserSwitchController.java @@ -49,6 +49,7 @@ import com.android.systemui.statusbar.phone.DozeParameters; import com.android.systemui.statusbar.phone.LockscreenGestureLogger; import com.android.systemui.statusbar.phone.ScreenOffAnimationController; import com.android.systemui.statusbar.phone.UserAvatarView; +import com.android.systemui.user.data.source.UserRecord; import com.android.systemui.util.ViewController; import javax.inject.Inject; @@ -79,7 +80,7 @@ public class KeyguardQsUserSwitchController extends ViewController<FrameLayout> @VisibleForTesting UserAvatarView mUserAvatarView; private View mUserAvatarViewWithBackground; - UserSwitcherController.UserRecord mCurrentUser; + UserRecord mCurrentUser; private boolean mIsKeyguardShowing; // State info for the user switch and keyguard @@ -269,10 +270,10 @@ public class KeyguardQsUserSwitchController extends ViewController<FrameLayout> * @return true if the current user has changed */ private boolean updateCurrentUser() { - UserSwitcherController.UserRecord previousUser = mCurrentUser; + UserRecord previousUser = mCurrentUser; mCurrentUser = null; for (int i = 0; i < mAdapter.getCount(); i++) { - UserSwitcherController.UserRecord r = mAdapter.getItem(i); + UserRecord r = mAdapter.getItem(i); if (r.isCurrent) { mCurrentUser = r; return !mCurrentUser.equals(previousUser); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyguardUserSwitcherController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyguardUserSwitcherController.java index 03ab888d1253..e2f5734cb4f9 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyguardUserSwitcherController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyguardUserSwitcherController.java @@ -52,6 +52,7 @@ import com.android.systemui.statusbar.notification.stack.AnimationProperties; import com.android.systemui.statusbar.notification.stack.StackStateAnimator; import com.android.systemui.statusbar.phone.DozeParameters; import com.android.systemui.statusbar.phone.ScreenOffAnimationController; +import com.android.systemui.user.data.source.UserRecord; import com.android.systemui.util.ViewController; import java.util.ArrayList; @@ -287,8 +288,8 @@ public class KeyguardUserSwitcherController extends ViewController<KeyguardUserS } KeyguardUserDetailItemView newView = (KeyguardUserDetailItemView) mAdapter.getView(i, oldView, mListView); - UserSwitcherController.UserRecord userTag = - (UserSwitcherController.UserRecord) newView.getTag(); + UserRecord userTag = + (UserRecord) newView.getTag(); if (userTag.isCurrent) { if (i != 0) { Log.w(TAG, "Current user is not the first view in the list"); @@ -443,7 +444,7 @@ public class KeyguardUserSwitcherController extends ViewController<KeyguardUserS private KeyguardUserSwitcherController mKeyguardUserSwitcherController; private View mCurrentUserView; // List of users where the first entry is always the current user - private ArrayList<UserSwitcherController.UserRecord> mUsersOrdered = new ArrayList<>(); + private ArrayList<UserRecord> mUsersOrdered = new ArrayList<>(); KeyguardUserAdapter(Context context, Resources resources, LayoutInflater layoutInflater, UserSwitcherController controller, @@ -464,10 +465,10 @@ public class KeyguardUserSwitcherController extends ViewController<KeyguardUserS } void refreshUserOrder() { - ArrayList<UserSwitcherController.UserRecord> users = super.getUsers(); + ArrayList<UserRecord> users = super.getUsers(); mUsersOrdered = new ArrayList<>(users.size()); for (int i = 0; i < users.size(); i++) { - UserSwitcherController.UserRecord record = users.get(i); + UserRecord record = users.get(i); if (record.isCurrent) { mUsersOrdered.add(0, record); } else { @@ -477,19 +478,19 @@ public class KeyguardUserSwitcherController extends ViewController<KeyguardUserS } @Override - protected ArrayList<UserSwitcherController.UserRecord> getUsers() { + protected ArrayList<UserRecord> getUsers() { return mUsersOrdered; } @Override public View getView(int position, View convertView, ViewGroup parent) { - UserSwitcherController.UserRecord item = getItem(position); + UserRecord item = getItem(position); return createUserDetailItemView(convertView, parent, item); } KeyguardUserDetailItemView convertOrInflate(View convertView, ViewGroup parent) { if (!(convertView instanceof KeyguardUserDetailItemView) - || !(convertView.getTag() instanceof UserSwitcherController.UserRecord)) { + || !(convertView.getTag() instanceof UserRecord)) { convertView = mLayoutInflater.inflate( R.layout.keyguard_user_switcher_item, parent, false); } @@ -497,7 +498,7 @@ public class KeyguardUserSwitcherController extends ViewController<KeyguardUserS } KeyguardUserDetailItemView createUserDetailItemView(View convertView, ViewGroup parent, - UserSwitcherController.UserRecord item) { + UserRecord item) { KeyguardUserDetailItemView v = convertOrInflate(convertView, parent); v.setOnClickListener(this); @@ -513,7 +514,7 @@ public class KeyguardUserSwitcherController extends ViewController<KeyguardUserS v.bind(name, drawable, item.info.id); } v.setActivated(item.isCurrent); - v.setDisabledByAdmin(item.isDisabledByAdmin); + v.setDisabledByAdmin(mController.isDisabledByAdmin(item)); v.setEnabled(item.isSwitchToEnabled); v.setAlpha(v.isEnabled() ? USER_SWITCH_ENABLED_ALPHA : USER_SWITCH_DISABLED_ALPHA); @@ -524,7 +525,7 @@ public class KeyguardUserSwitcherController extends ViewController<KeyguardUserS return v; } - private Drawable getDrawable(UserSwitcherController.UserRecord item) { + private Drawable getDrawable(UserRecord item) { Drawable drawable; if (item.isCurrent && item.isGuest) { drawable = mContext.getDrawable(R.drawable.ic_avatar_guest_user); @@ -547,7 +548,7 @@ public class KeyguardUserSwitcherController extends ViewController<KeyguardUserS @Override public void onClick(View v) { - UserSwitcherController.UserRecord user = (UserSwitcherController.UserRecord) v.getTag(); + UserRecord user = (UserRecord) v.getTag(); if (mKeyguardUserSwitcherController.isListAnimating()) { return; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java index 836d57131fac..e2d16015235e 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java @@ -45,6 +45,7 @@ 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; @@ -54,6 +55,7 @@ import android.widget.BaseAdapter; import android.widget.Toast; import androidx.annotation.Nullable; +import androidx.collection.SimpleArrayMap; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.jank.InteractionJankMonitor; @@ -83,6 +85,7 @@ import com.android.systemui.settings.UserTracker; import com.android.systemui.statusbar.phone.SystemUIDialog; import com.android.systemui.telephony.TelephonyListenerManager; import com.android.systemui.user.CreateUserActivity; +import com.android.systemui.user.data.source.UserRecord; import com.android.systemui.util.settings.GlobalSettings; import com.android.systemui.util.settings.SecureSettings; @@ -138,6 +141,9 @@ public class UserSwitcherController implements Dumpable { 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 @@ -975,6 +981,21 @@ public class UserSwitcherController implements Dumpable { return mKeyguardStateController; } + /** + * Returns the {@link EnforcedAdmin} for the given record, or {@code null} if there isn't one. + */ + @Nullable + public EnforcedAdmin getEnforcedAdmin(UserRecord record) { + return mEnforcedAdminByUserRecord.get(record); + } + + /** + * Returns {@code true} if the given record is disabled by the admin; {@code false} otherwise. + */ + public boolean isDisabledByAdmin(UserRecord record) { + return mDisabledByAdmin.contains(record); + } + public static abstract class BaseUserAdapter extends BaseAdapter { final UserSwitcherController mController; @@ -1106,11 +1127,11 @@ public class UserSwitcherController implements Dumpable { UserManager.DISALLOW_ADD_USER, mUserTracker.getUserId()); if (admin != null && !RestrictedLockUtilsInternal.hasBaseUserRestriction(mContext, UserManager.DISALLOW_ADD_USER, mUserTracker.getUserId())) { - record.isDisabledByAdmin = true; - record.enforcedAdmin = admin; + mDisabledByAdmin.add(record); + mEnforcedAdminByUserRecord.put(record, admin); } else { - record.isDisabledByAdmin = false; - record.enforcedAdmin = null; + mDisabledByAdmin.remove(record); + mEnforcedAdminByUserRecord.put(record, null); } } @@ -1152,74 +1173,6 @@ public class UserSwitcherController implements Dumpable { } } - public static final class UserRecord { - public final UserInfo info; - public final Bitmap picture; - public final boolean isGuest; - public final boolean isCurrent; - public final boolean isAddUser; - public final boolean isAddSupervisedUser; - /** If true, the record is only visible to the owner and only when unlocked. */ - public final boolean isRestricted; - public boolean isDisabledByAdmin; - public EnforcedAdmin enforcedAdmin; - public boolean isSwitchToEnabled; - - public UserRecord(UserInfo info, Bitmap picture, boolean isGuest, boolean isCurrent, - boolean isAddUser, boolean isRestricted, boolean isSwitchToEnabled, - boolean isAddSupervisedUser) { - this.info = info; - this.picture = picture; - this.isGuest = isGuest; - this.isCurrent = isCurrent; - this.isAddUser = isAddUser; - this.isRestricted = isRestricted; - this.isSwitchToEnabled = isSwitchToEnabled; - this.isAddSupervisedUser = isAddSupervisedUser; - } - - public UserRecord copyWithIsCurrent(boolean _isCurrent) { - return new UserRecord(info, picture, isGuest, _isCurrent, isAddUser, isRestricted, - isSwitchToEnabled, isAddSupervisedUser); - } - - public int resolveId() { - if (isGuest || info == null) { - return UserHandle.USER_NULL; - } - return info.id; - } - - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("UserRecord("); - if (info != null) { - sb.append("name=\"").append(info.name).append("\" id=").append(info.id); - } else { - if (isGuest) { - sb.append("<add guest placeholder>"); - } else if (isAddUser) { - sb.append("<add user placeholder>"); - } - } - if (isGuest) sb.append(" <isGuest>"); - if (isAddUser) sb.append(" <isAddUser>"); - if (isAddSupervisedUser) sb.append(" <isAddSupervisedUser>"); - if (isCurrent) sb.append(" <isCurrent>"); - if (picture != null) sb.append(" <hasPicture>"); - if (isRestricted) sb.append(" <isRestricted>"); - if (isDisabledByAdmin) { - sb.append(" <isDisabledByAdmin>"); - sb.append(" enforcedAdmin=").append(enforcedAdmin); - } - if (isSwitchToEnabled) { - sb.append(" <isSwitchToEnabled>"); - } - sb.append(')'); - return sb.toString(); - } - } - private final KeyguardStateController.Callback mCallback = new KeyguardStateController.Callback() { @Override diff --git a/packages/SystemUI/src/com/android/systemui/user/UserSwitcherActivity.kt b/packages/SystemUI/src/com/android/systemui/user/UserSwitcherActivity.kt index 80c55c0bad07..ff0f0d48a7c5 100644 --- a/packages/SystemUI/src/com/android/systemui/user/UserSwitcherActivity.kt +++ b/packages/SystemUI/src/com/android/systemui/user/UserSwitcherActivity.kt @@ -51,7 +51,7 @@ import com.android.systemui.statusbar.policy.UserSwitcherController import com.android.systemui.statusbar.policy.UserSwitcherController.BaseUserAdapter import com.android.systemui.statusbar.policy.UserSwitcherController.USER_SWITCH_DISABLED_ALPHA import com.android.systemui.statusbar.policy.UserSwitcherController.USER_SWITCH_ENABLED_ALPHA -import com.android.systemui.statusbar.policy.UserSwitcherController.UserRecord +import com.android.systemui.user.data.source.UserRecord import javax.inject.Inject import kotlin.math.ceil @@ -81,16 +81,17 @@ class UserSwitcherActivity @Inject constructor( } } // When the add users options become available, insert another option to manage users - private val manageUserRecord = UserRecord( - null /* info */, - null /* picture */, - false /* isGuest */, - false /* isCurrent */, - false /* isAddUser */, - false /* isRestricted */, - false /* isSwitchToEnabled */, - false /* isAddSupervisedUser */ - ) + private val manageUserRecord = + UserRecord( + null /* info */, + null /* picture */, + false /* isGuest */, + false /* isCurrent */, + false /* isAddUser */, + false /* isRestricted */, + false /* isSwitchToEnabled */, + false /* isAddSupervisedUser */ + ) private val adapter = object : BaseUserAdapter(userSwitcherController) { override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { diff --git a/packages/SystemUI/src/com/android/systemui/user/data/source/UserRecord.kt b/packages/SystemUI/src/com/android/systemui/user/data/source/UserRecord.kt new file mode 100644 index 000000000000..6ab6d7d7891a --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/user/data/source/UserRecord.kt @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package com.android.systemui.user.data.source + +import android.content.pm.UserInfo +import android.graphics.Bitmap +import android.os.UserHandle + +/** + * Encapsulates raw data for a user or an option item related to managing users on the device. + */ +data class UserRecord( + /** Relevant user information. If `null`, this record is not a user but an option item. */ + @JvmField + val info: UserInfo?, + /** An image representing the user. */ + @JvmField + val picture: Bitmap?, + /** Whether this record represents an option to switch to a guest user. */ + @JvmField + val isGuest: Boolean, + /** Whether this record represents the currently-selected user. */ + @JvmField + val isCurrent: Boolean, + /** Whether this record represents an option to add another user to the device. */ + @JvmField + val isAddUser: Boolean, + /** If true, the record is only visible to the owner and only when unlocked. */ + @JvmField + val isRestricted: Boolean, + /** Whether it is possible to switch to this user. */ + @JvmField + val isSwitchToEnabled: Boolean, + /** Whether this record represents an option to add another supervised user to the device. */ + @JvmField + val isAddSupervisedUser: Boolean, +) { + /** + * Returns a new instance of [UserRecord] with its [isCurrent] set to the given value. + */ + fun copyWithIsCurrent(isCurrent: Boolean): UserRecord { + return copy(isCurrent = isCurrent) + } + + /** + * Returns the user ID for the user represented by this instance or [UserHandle.USER_NULL] if + * this instance if a guest or does not represent a user (represents an option item). + */ + fun resolveId(): Int { + return if (isGuest || info == null) { + UserHandle.USER_NULL + } else { + info.id + } + } +} diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityContainerTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityContainerTest.java index f2ac0c7a7736..28e99da49496 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityContainerTest.java +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityContainerTest.java @@ -57,7 +57,7 @@ import com.android.systemui.SysuiTestCase; import com.android.systemui.plugins.FalsingManager; import com.android.systemui.statusbar.policy.KeyguardStateController; import com.android.systemui.statusbar.policy.UserSwitcherController; -import com.android.systemui.statusbar.policy.UserSwitcherController.UserRecord; +import com.android.systemui.user.data.source.UserRecord; import com.android.systemui.util.settings.GlobalSettings; import org.junit.Before; diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/UserDetailViewAdapterTest.kt b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/UserDetailViewAdapterTest.kt index 9b0142d6a8fe..5db3b9caa007 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/UserDetailViewAdapterTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/UserDetailViewAdapterTest.kt @@ -31,6 +31,7 @@ import com.android.systemui.SysuiTestCase import com.android.systemui.classifier.FalsingManagerFake import com.android.systemui.qs.QSUserSwitcherEvent import com.android.systemui.statusbar.policy.UserSwitcherController +import com.android.systemui.user.data.source.UserRecord import org.junit.Assert.assertEquals import org.junit.Before import org.junit.Test @@ -39,8 +40,8 @@ import org.mockito.ArgumentMatchers.any import org.mockito.ArgumentMatchers.anyBoolean import org.mockito.ArgumentMatchers.anyInt import org.mockito.Mock -import org.mockito.Mockito.`when` import org.mockito.Mockito.verify +import org.mockito.Mockito.`when` import org.mockito.MockitoAnnotations @RunWith(AndroidTestingRunner::class) @@ -140,13 +141,14 @@ class UserDetailViewAdapterTest : SysuiTestCase() { } private fun createUserRecord(current: Boolean, guest: Boolean) = - UserSwitcherController.UserRecord( - mUserInfo, - mPicture, - guest, - current, - false /* isAddUser */, - false /* isRestricted */, - true /* isSwitchToEnabled */, - false /* isAddSupervisedUser */) + UserRecord( + mUserInfo, + mPicture, + guest, + current, + false /* isAddUser */, + false /* isRestricted */, + true /* isSwitchToEnabled */, + false /* isAddSupervisedUser */ + ) } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/KeyguardUserSwitcherAdapterTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/KeyguardUserSwitcherAdapterTest.kt index 0dd6cbb7995a..c3805ad36533 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/KeyguardUserSwitcherAdapterTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/KeyguardUserSwitcherAdapterTest.kt @@ -28,6 +28,7 @@ import com.android.internal.util.UserIcons import com.android.systemui.R import com.android.systemui.SysuiTestCase import com.android.systemui.qs.tiles.UserDetailItemView +import com.android.systemui.user.data.source.UserRecord import org.junit.Assert.assertFalse import org.junit.Assert.assertNotNull import org.junit.Assert.assertTrue @@ -38,8 +39,8 @@ import org.mockito.ArgumentMatchers.any import org.mockito.ArgumentMatchers.anyBoolean import org.mockito.ArgumentMatchers.anyInt import org.mockito.Mock -import org.mockito.Mockito.`when` import org.mockito.Mockito.verify +import org.mockito.Mockito.`when` import org.mockito.MockitoAnnotations @RunWith(AndroidTestingRunner::class) @@ -186,13 +187,14 @@ class KeyguardUserSwitcherAdapterTest : SysuiTestCase() { } private fun createUserRecord(isCurrentUser: Boolean, isGuestUser: Boolean) = - UserSwitcherController.UserRecord( - userInfo, - picture, - isGuestUser, - isCurrentUser, - false /* isAddUser */, - false /* isRestricted */, - true /* isSwitchToEnabled */, - false /* isAddSupervisedUser */) + UserRecord( + userInfo, + picture, + isGuestUser, + isCurrentUser, + false /* isAddUser */, + false /* isRestricted */, + true /* isSwitchToEnabled */, + false /* isAddSupervisedUser */ + ) } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/UserSwitcherControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/UserSwitcherControllerTest.kt index 359a780d2a94..8dcd4bb3b738 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/UserSwitcherControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/UserSwitcherControllerTest.kt @@ -56,6 +56,7 @@ import com.android.systemui.qs.user.UserSwitchDialogController import com.android.systemui.settings.UserTracker import com.android.systemui.shade.NotificationShadeWindowView import com.android.systemui.telephony.TelephonyListenerManager +import com.android.systemui.user.data.source.UserRecord import com.android.systemui.util.concurrency.FakeExecutor import com.android.systemui.util.mockito.any import com.android.systemui.util.mockito.argumentCaptor @@ -235,15 +236,16 @@ class UserSwitcherControllerTest : SysuiTestCase() { @Test fun testSwitchUser_parentDialogDismissed() { - val otherUserRecord = UserSwitcherController.UserRecord( - secondaryUser, - picture, - false /* guest */, - false /* current */, - false /* isAddUser */, - false /* isRestricted */, - true /* isSwitchToEnabled */, - false /* isAddSupervisedUser */) + val otherUserRecord = UserRecord( + secondaryUser, + picture, + false /* guest */, + false /* current */, + false /* isAddUser */, + false /* isRestricted */, + true /* isSwitchToEnabled */, + false /* isAddSupervisedUser */ + ) `when`(userTracker.userId).thenReturn(ownerId) `when`(userTracker.userInfo).thenReturn(ownerInfo) @@ -255,7 +257,8 @@ class UserSwitcherControllerTest : SysuiTestCase() { @Test fun testAddGuest_okButtonPressed() { - val emptyGuestUserRecord = UserSwitcherController.UserRecord( + val emptyGuestUserRecord = + UserRecord( null, null, true /* guest */, @@ -263,7 +266,8 @@ class UserSwitcherControllerTest : SysuiTestCase() { false /* isAddUser */, false /* isRestricted */, true /* isSwitchToEnabled */, - false /* isAddSupervisedUser */) + false /* isAddSupervisedUser */ + ) `when`(userTracker.userId).thenReturn(ownerId) `when`(userTracker.userInfo).thenReturn(ownerInfo) @@ -282,7 +286,8 @@ class UserSwitcherControllerTest : SysuiTestCase() { @Test fun testAddGuest_parentDialogDismissed() { - val emptyGuestUserRecord = UserSwitcherController.UserRecord( + val emptyGuestUserRecord = + UserRecord( null, null, true /* guest */, @@ -290,7 +295,8 @@ class UserSwitcherControllerTest : SysuiTestCase() { false /* isAddUser */, false /* isRestricted */, true /* isSwitchToEnabled */, - false /* isAddSupervisedUser */) + false /* isAddSupervisedUser */ + ) `when`(userTracker.userId).thenReturn(ownerId) `when`(userTracker.userInfo).thenReturn(ownerInfo) @@ -305,7 +311,8 @@ class UserSwitcherControllerTest : SysuiTestCase() { @Test fun testRemoveGuest_removeButtonPressed_isLogged() { - val currentGuestUserRecord = UserSwitcherController.UserRecord( + val currentGuestUserRecord = + UserRecord( guestInfo, picture, true /* guest */, @@ -313,7 +320,8 @@ class UserSwitcherControllerTest : SysuiTestCase() { false /* isAddUser */, false /* isRestricted */, true /* isSwitchToEnabled */, - false /* isAddSupervisedUser */) + false /* isAddSupervisedUser */ + ) `when`(userTracker.userId).thenReturn(guestInfo.id) `when`(userTracker.userInfo).thenReturn(guestInfo) @@ -331,7 +339,8 @@ class UserSwitcherControllerTest : SysuiTestCase() { @Test fun testRemoveGuest_removeButtonPressed_dialogDismissed() { - val currentGuestUserRecord = UserSwitcherController.UserRecord( + val currentGuestUserRecord = + UserRecord( guestInfo, picture, true /* guest */, @@ -339,7 +348,8 @@ class UserSwitcherControllerTest : SysuiTestCase() { false /* isAddUser */, false /* isRestricted */, true /* isSwitchToEnabled */, - false /* isAddSupervisedUser */) + false /* isAddSupervisedUser */ + ) `when`(userTracker.userId).thenReturn(guestInfo.id) `when`(userTracker.userInfo).thenReturn(guestInfo) @@ -353,7 +363,8 @@ class UserSwitcherControllerTest : SysuiTestCase() { @Test fun testRemoveGuest_dialogShowerUsed() { - val currentGuestUserRecord = UserSwitcherController.UserRecord( + val currentGuestUserRecord = + UserRecord( guestInfo, picture, true /* guest */, @@ -361,7 +372,8 @@ class UserSwitcherControllerTest : SysuiTestCase() { false /* isAddUser */, false /* isRestricted */, true /* isSwitchToEnabled */, - false /* isAddSupervisedUser */) + false /* isAddSupervisedUser */ + ) `when`(userTracker.userId).thenReturn(guestInfo.id) `when`(userTracker.userInfo).thenReturn(guestInfo) @@ -376,7 +388,8 @@ class UserSwitcherControllerTest : SysuiTestCase() { @Test fun testRemoveGuest_cancelButtonPressed_isNotLogged() { - val currentGuestUserRecord = UserSwitcherController.UserRecord( + val currentGuestUserRecord = + UserRecord( guestInfo, picture, true /* guest */, @@ -384,7 +397,8 @@ class UserSwitcherControllerTest : SysuiTestCase() { false /* isAddUser */, false /* isRestricted */, true /* isSwitchToEnabled */, - false /* isAddSupervisedUser */) + false /* isAddSupervisedUser */ + ) `when`(userTracker.userId).thenReturn(guestId) `when`(userTracker.userInfo).thenReturn(guestInfo) @@ -398,7 +412,8 @@ class UserSwitcherControllerTest : SysuiTestCase() { @Test fun testWipeGuest_startOverButtonPressed_isLogged() { - val currentGuestUserRecord = UserSwitcherController.UserRecord( + val currentGuestUserRecord = + UserRecord( guestInfo, picture, true /* guest */, @@ -406,7 +421,8 @@ class UserSwitcherControllerTest : SysuiTestCase() { false /* isAddUser */, false /* isRestricted */, true /* isSwitchToEnabled */, - false /* isAddSupervisedUser */) + false /* isAddSupervisedUser */ + ) `when`(userTracker.userId).thenReturn(guestId) `when`(userTracker.userInfo).thenReturn(guestInfo) @@ -433,7 +449,8 @@ class UserSwitcherControllerTest : SysuiTestCase() { @Test fun testWipeGuest_continueButtonPressed_isLogged() { - val currentGuestUserRecord = UserSwitcherController.UserRecord( + val currentGuestUserRecord = + UserRecord( guestInfo, picture, true /* guest */, @@ -441,7 +458,8 @@ class UserSwitcherControllerTest : SysuiTestCase() { false /* isAddUser */, false /* isRestricted */, true /* isSwitchToEnabled */, - false /* isAddSupervisedUser */) + false /* isAddSupervisedUser */ + ) `when`(userTracker.userId).thenReturn(guestId) `when`(userTracker.userInfo).thenReturn(guestInfo) @@ -470,11 +488,13 @@ class UserSwitcherControllerTest : SysuiTestCase() { @Test fun test_getCurrentUserName_shouldReturnNameOfTheCurrentUser() { fun addUser(id: Int, name: String, isCurrent: Boolean) { - userSwitcherController.users.add(UserSwitcherController.UserRecord( + userSwitcherController.users.add( + UserRecord( UserInfo(id, name, 0), null, false, isCurrent, false, false, false, false - )) + ) + ) } val bgUserName = "background_user" val fgUserName = "foreground_user" @@ -593,7 +613,7 @@ class UserSwitcherControllerTest : SysuiTestCase() { @Test fun onUserItemClicked_guest_runsOnBgThread() { val dialogShower = mock(UserSwitchDialogController.DialogShower::class.java) - val guestUserRecord = UserSwitcherController.UserRecord( + val guestUserRecord = UserRecord( null, picture, true /* guest */, @@ -601,7 +621,8 @@ class UserSwitcherControllerTest : SysuiTestCase() { false /* isAddUser */, false /* isRestricted */, true /* isSwitchToEnabled */, - false /* isAddSupervisedUser */) + false /* isAddSupervisedUser */ + ) userSwitcherController.onUserListItemClicked(guestUserRecord, dialogShower) assertTrue(bgExecutor.numPending() > 0) |