Loading packages/SystemUI/src/com/android/systemui/qs/tiles/UserDetailView.java +1 −1 Original line number Diff line number Diff line Loading @@ -76,7 +76,7 @@ public class UserDetailView extends PseudoGridView { UserSwitcherController.UserRecord item) { UserDetailItemView v = UserDetailItemView.convertOrInflate( mContext, convertView, parent); if ((v != convertView && !item.isCurrent) || item.isGuest) { if (!item.isCurrent || item.isGuest) { v.setOnClickListener(this); } else { v.setOnClickListener(null); Loading packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyguardMonitor.java +0 −1 Original line number Diff line number Diff line Loading @@ -19,7 +19,6 @@ import com.android.systemui.statusbar.policy.KeyguardMonitor.Callback; public interface KeyguardMonitor extends CallbackController<Callback> { boolean isSecure(); boolean canSkipBouncer(); boolean isShowing(); boolean isOccluded(); boolean isKeyguardFadingAway(); Loading packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyguardMonitorImpl.java +0 −26 Original line number Diff line number Diff line Loading @@ -17,13 +17,11 @@ package com.android.systemui.statusbar.policy; import android.annotation.NonNull; import android.app.ActivityManager; import android.content.Context; import com.android.internal.util.Preconditions; import com.android.keyguard.KeyguardUpdateMonitor; import com.android.keyguard.KeyguardUpdateMonitorCallback; import com.android.systemui.settings.CurrentUserTracker; import java.util.ArrayList; Loading @@ -39,14 +37,11 @@ public class KeyguardMonitorImpl extends KeyguardUpdateMonitorCallback private final ArrayList<Callback> mCallbacks = new ArrayList<>(); private final Context mContext; private final CurrentUserTracker mUserTracker; private final KeyguardUpdateMonitor mKeyguardUpdateMonitor; private int mCurrentUser; private boolean mShowing; private boolean mSecure; private boolean mOccluded; private boolean mCanSkipBouncer; private boolean mListening; private boolean mKeyguardFadingAway; Loading @@ -62,13 +57,6 @@ public class KeyguardMonitorImpl extends KeyguardUpdateMonitorCallback public KeyguardMonitorImpl(Context context) { mContext = context; mKeyguardUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext); mUserTracker = new CurrentUserTracker(mContext) { @Override public void onUserSwitched(int newUserId) { mCurrentUser = newUserId; updateCanSkipBouncerState(); } }; } @Override Loading @@ -77,10 +65,7 @@ public class KeyguardMonitorImpl extends KeyguardUpdateMonitorCallback mCallbacks.add(callback); if (mCallbacks.size() != 0 && !mListening) { mListening = true; mCurrentUser = ActivityManager.getCurrentUser(); updateCanSkipBouncerState(); mKeyguardUpdateMonitor.registerCallback(this); mUserTracker.startTracking(); } } Loading @@ -90,7 +75,6 @@ public class KeyguardMonitorImpl extends KeyguardUpdateMonitorCallback if (mCallbacks.remove(callback) && mCallbacks.size() == 0 && mListening) { mListening = false; mKeyguardUpdateMonitor.removeCallback(this); mUserTracker.stopTracking(); } } Loading @@ -109,11 +93,6 @@ public class KeyguardMonitorImpl extends KeyguardUpdateMonitorCallback return mOccluded; } @Override public boolean canSkipBouncer() { return mCanSkipBouncer; } public void notifyKeyguardState(boolean showing, boolean secure, boolean occluded) { if (mShowing == showing && mSecure == secure && mOccluded == occluded) return; mShowing = showing; Loading @@ -124,7 +103,6 @@ public class KeyguardMonitorImpl extends KeyguardUpdateMonitorCallback @Override public void onTrustChanged(int userId) { updateCanSkipBouncerState(); notifyKeyguardChanged(); } Loading @@ -132,10 +110,6 @@ public class KeyguardMonitorImpl extends KeyguardUpdateMonitorCallback return mKeyguardUpdateMonitor.isDeviceInteractive(); } private void updateCanSkipBouncerState() { mCanSkipBouncer = mKeyguardUpdateMonitor.getUserCanSkipBouncer(mCurrentUser); } private void notifyKeyguardChanged() { // Copy the list to allow removal during callback. new ArrayList<>(mCallbacks).forEach(Callback::onKeyguardShowingChanged); Loading packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java +5 −2 Original line number Diff line number Diff line Loading @@ -61,6 +61,7 @@ import com.android.systemui.plugins.ActivityStarter; import com.android.systemui.plugins.qs.DetailAdapter; import com.android.systemui.qs.tiles.UserDetailView; import com.android.systemui.statusbar.phone.SystemUIDialog; import com.android.systemui.statusbar.phone.UnlockMethodCache; import java.io.FileDescriptor; import java.io.PrintWriter; Loading Loading @@ -595,17 +596,19 @@ public class UserSwitcherController implements Dumpable { final UserSwitcherController mController; private final KeyguardMonitor mKeyguardMonitor; private final UnlockMethodCache mUnlockMethodCache; protected BaseUserAdapter(UserSwitcherController controller) { mController = controller; mKeyguardMonitor = controller.mKeyguardMonitor; mUnlockMethodCache = UnlockMethodCache.getInstance(controller.mContext); controller.addAdapter(new WeakReference<>(this)); } public int getUserCount() { boolean secureKeyguardShowing = mKeyguardMonitor.isShowing() && mKeyguardMonitor.isSecure() && !mKeyguardMonitor.canSkipBouncer(); && !mUnlockMethodCache.canSkipBouncer(); if (!secureKeyguardShowing) { return mController.getUsers().size(); } Loading @@ -627,7 +630,7 @@ public class UserSwitcherController implements Dumpable { public int getCount() { boolean secureKeyguardShowing = mKeyguardMonitor.isShowing() && mKeyguardMonitor.isSecure() && !mKeyguardMonitor.canSkipBouncer(); && !mUnlockMethodCache.canSkipBouncer(); if (!secureKeyguardShowing) { return mController.getUsers().size(); } Loading packages/SystemUI/tests/src/com/android/systemui/qs/tiles/UserDetailViewAdapterTest.kt 0 → 100644 +128 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 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.qs.tiles import android.content.Context import android.content.pm.UserInfo import android.graphics.Bitmap import android.testing.AndroidTestingRunner import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.statusbar.policy.UserSwitcherController import org.junit.Before import org.junit.Test import org.junit.runner.RunWith 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.MockitoAnnotations @RunWith(AndroidTestingRunner::class) @SmallTest class UserDetailViewAdapterTest : SysuiTestCase() { @Mock private lateinit var mUserSwitcherController: UserSwitcherController @Mock private lateinit var mParent: ViewGroup @Mock private lateinit var mUserDetailItemView: UserDetailItemView @Mock private lateinit var mOtherView: View @Mock private lateinit var mInflatedUserDetailItemView: UserDetailItemView @Mock private lateinit var mUserInfo: UserInfo @Mock private lateinit var mPicture: Bitmap @Mock private lateinit var mLayoutInflater: LayoutInflater private lateinit var adapter: UserDetailView.Adapter @Before fun setUp() { MockitoAnnotations.initMocks(this) mContext.addMockSystemService(Context.LAYOUT_INFLATER_SERVICE, mLayoutInflater) `when`(mLayoutInflater.inflate(anyInt(), any(ViewGroup::class.java), anyBoolean())) .thenReturn(mInflatedUserDetailItemView) adapter = UserDetailView.Adapter(mContext, mUserSwitcherController) } private fun clickableTest( current: Boolean, guest: Boolean, convertView: View, shouldBeClickable: Boolean ) { val user = createUserRecord(current, guest) val v = adapter.createUserDetailItemView(convertView, mParent, user) if (shouldBeClickable) { verify(v).setOnClickListener(adapter) } else { verify(v).setOnClickListener(null) } } @Test fun testGuestIsClickable_differentViews_notCurrent() { clickableTest(false, true, mOtherView, true) } @Test fun testGuestIsClickable_differentViews_Current() { clickableTest(true, true, mOtherView, true) } @Test fun testGuestIsClickable_sameView_notCurrent() { clickableTest(false, true, mUserDetailItemView, true) } @Test fun testGuestIsClickable_sameView_Current() { clickableTest(true, true, mUserDetailItemView, true) } @Test fun testNotGuestCurrentUserIsNotClickable_otherView() { clickableTest(true, false, mOtherView, false) } @Test fun testNotGuestCurrentUserIsNotClickable_sameView() { clickableTest(true, false, mUserDetailItemView, false) } @Test fun testNotGuestNotCurrentUserIsClickable_otherView() { clickableTest(false, false, mOtherView, true) } @Test fun testNotGuestNotCurrentUserIsClickable_sameView() { clickableTest(false, false, mUserDetailItemView, true) } private fun createUserRecord(current: Boolean, guest: Boolean) = UserSwitcherController.UserRecord( mUserInfo, mPicture, guest, current, false /* isAddUser */, false /* isRestricted */, true /* isSwitchToEnabled */) } No newline at end of file Loading
packages/SystemUI/src/com/android/systemui/qs/tiles/UserDetailView.java +1 −1 Original line number Diff line number Diff line Loading @@ -76,7 +76,7 @@ public class UserDetailView extends PseudoGridView { UserSwitcherController.UserRecord item) { UserDetailItemView v = UserDetailItemView.convertOrInflate( mContext, convertView, parent); if ((v != convertView && !item.isCurrent) || item.isGuest) { if (!item.isCurrent || item.isGuest) { v.setOnClickListener(this); } else { v.setOnClickListener(null); Loading
packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyguardMonitor.java +0 −1 Original line number Diff line number Diff line Loading @@ -19,7 +19,6 @@ import com.android.systemui.statusbar.policy.KeyguardMonitor.Callback; public interface KeyguardMonitor extends CallbackController<Callback> { boolean isSecure(); boolean canSkipBouncer(); boolean isShowing(); boolean isOccluded(); boolean isKeyguardFadingAway(); Loading
packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyguardMonitorImpl.java +0 −26 Original line number Diff line number Diff line Loading @@ -17,13 +17,11 @@ package com.android.systemui.statusbar.policy; import android.annotation.NonNull; import android.app.ActivityManager; import android.content.Context; import com.android.internal.util.Preconditions; import com.android.keyguard.KeyguardUpdateMonitor; import com.android.keyguard.KeyguardUpdateMonitorCallback; import com.android.systemui.settings.CurrentUserTracker; import java.util.ArrayList; Loading @@ -39,14 +37,11 @@ public class KeyguardMonitorImpl extends KeyguardUpdateMonitorCallback private final ArrayList<Callback> mCallbacks = new ArrayList<>(); private final Context mContext; private final CurrentUserTracker mUserTracker; private final KeyguardUpdateMonitor mKeyguardUpdateMonitor; private int mCurrentUser; private boolean mShowing; private boolean mSecure; private boolean mOccluded; private boolean mCanSkipBouncer; private boolean mListening; private boolean mKeyguardFadingAway; Loading @@ -62,13 +57,6 @@ public class KeyguardMonitorImpl extends KeyguardUpdateMonitorCallback public KeyguardMonitorImpl(Context context) { mContext = context; mKeyguardUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext); mUserTracker = new CurrentUserTracker(mContext) { @Override public void onUserSwitched(int newUserId) { mCurrentUser = newUserId; updateCanSkipBouncerState(); } }; } @Override Loading @@ -77,10 +65,7 @@ public class KeyguardMonitorImpl extends KeyguardUpdateMonitorCallback mCallbacks.add(callback); if (mCallbacks.size() != 0 && !mListening) { mListening = true; mCurrentUser = ActivityManager.getCurrentUser(); updateCanSkipBouncerState(); mKeyguardUpdateMonitor.registerCallback(this); mUserTracker.startTracking(); } } Loading @@ -90,7 +75,6 @@ public class KeyguardMonitorImpl extends KeyguardUpdateMonitorCallback if (mCallbacks.remove(callback) && mCallbacks.size() == 0 && mListening) { mListening = false; mKeyguardUpdateMonitor.removeCallback(this); mUserTracker.stopTracking(); } } Loading @@ -109,11 +93,6 @@ public class KeyguardMonitorImpl extends KeyguardUpdateMonitorCallback return mOccluded; } @Override public boolean canSkipBouncer() { return mCanSkipBouncer; } public void notifyKeyguardState(boolean showing, boolean secure, boolean occluded) { if (mShowing == showing && mSecure == secure && mOccluded == occluded) return; mShowing = showing; Loading @@ -124,7 +103,6 @@ public class KeyguardMonitorImpl extends KeyguardUpdateMonitorCallback @Override public void onTrustChanged(int userId) { updateCanSkipBouncerState(); notifyKeyguardChanged(); } Loading @@ -132,10 +110,6 @@ public class KeyguardMonitorImpl extends KeyguardUpdateMonitorCallback return mKeyguardUpdateMonitor.isDeviceInteractive(); } private void updateCanSkipBouncerState() { mCanSkipBouncer = mKeyguardUpdateMonitor.getUserCanSkipBouncer(mCurrentUser); } private void notifyKeyguardChanged() { // Copy the list to allow removal during callback. new ArrayList<>(mCallbacks).forEach(Callback::onKeyguardShowingChanged); Loading
packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java +5 −2 Original line number Diff line number Diff line Loading @@ -61,6 +61,7 @@ import com.android.systemui.plugins.ActivityStarter; import com.android.systemui.plugins.qs.DetailAdapter; import com.android.systemui.qs.tiles.UserDetailView; import com.android.systemui.statusbar.phone.SystemUIDialog; import com.android.systemui.statusbar.phone.UnlockMethodCache; import java.io.FileDescriptor; import java.io.PrintWriter; Loading Loading @@ -595,17 +596,19 @@ public class UserSwitcherController implements Dumpable { final UserSwitcherController mController; private final KeyguardMonitor mKeyguardMonitor; private final UnlockMethodCache mUnlockMethodCache; protected BaseUserAdapter(UserSwitcherController controller) { mController = controller; mKeyguardMonitor = controller.mKeyguardMonitor; mUnlockMethodCache = UnlockMethodCache.getInstance(controller.mContext); controller.addAdapter(new WeakReference<>(this)); } public int getUserCount() { boolean secureKeyguardShowing = mKeyguardMonitor.isShowing() && mKeyguardMonitor.isSecure() && !mKeyguardMonitor.canSkipBouncer(); && !mUnlockMethodCache.canSkipBouncer(); if (!secureKeyguardShowing) { return mController.getUsers().size(); } Loading @@ -627,7 +630,7 @@ public class UserSwitcherController implements Dumpable { public int getCount() { boolean secureKeyguardShowing = mKeyguardMonitor.isShowing() && mKeyguardMonitor.isSecure() && !mKeyguardMonitor.canSkipBouncer(); && !mUnlockMethodCache.canSkipBouncer(); if (!secureKeyguardShowing) { return mController.getUsers().size(); } Loading
packages/SystemUI/tests/src/com/android/systemui/qs/tiles/UserDetailViewAdapterTest.kt 0 → 100644 +128 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 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.qs.tiles import android.content.Context import android.content.pm.UserInfo import android.graphics.Bitmap import android.testing.AndroidTestingRunner import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.statusbar.policy.UserSwitcherController import org.junit.Before import org.junit.Test import org.junit.runner.RunWith 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.MockitoAnnotations @RunWith(AndroidTestingRunner::class) @SmallTest class UserDetailViewAdapterTest : SysuiTestCase() { @Mock private lateinit var mUserSwitcherController: UserSwitcherController @Mock private lateinit var mParent: ViewGroup @Mock private lateinit var mUserDetailItemView: UserDetailItemView @Mock private lateinit var mOtherView: View @Mock private lateinit var mInflatedUserDetailItemView: UserDetailItemView @Mock private lateinit var mUserInfo: UserInfo @Mock private lateinit var mPicture: Bitmap @Mock private lateinit var mLayoutInflater: LayoutInflater private lateinit var adapter: UserDetailView.Adapter @Before fun setUp() { MockitoAnnotations.initMocks(this) mContext.addMockSystemService(Context.LAYOUT_INFLATER_SERVICE, mLayoutInflater) `when`(mLayoutInflater.inflate(anyInt(), any(ViewGroup::class.java), anyBoolean())) .thenReturn(mInflatedUserDetailItemView) adapter = UserDetailView.Adapter(mContext, mUserSwitcherController) } private fun clickableTest( current: Boolean, guest: Boolean, convertView: View, shouldBeClickable: Boolean ) { val user = createUserRecord(current, guest) val v = adapter.createUserDetailItemView(convertView, mParent, user) if (shouldBeClickable) { verify(v).setOnClickListener(adapter) } else { verify(v).setOnClickListener(null) } } @Test fun testGuestIsClickable_differentViews_notCurrent() { clickableTest(false, true, mOtherView, true) } @Test fun testGuestIsClickable_differentViews_Current() { clickableTest(true, true, mOtherView, true) } @Test fun testGuestIsClickable_sameView_notCurrent() { clickableTest(false, true, mUserDetailItemView, true) } @Test fun testGuestIsClickable_sameView_Current() { clickableTest(true, true, mUserDetailItemView, true) } @Test fun testNotGuestCurrentUserIsNotClickable_otherView() { clickableTest(true, false, mOtherView, false) } @Test fun testNotGuestCurrentUserIsNotClickable_sameView() { clickableTest(true, false, mUserDetailItemView, false) } @Test fun testNotGuestNotCurrentUserIsClickable_otherView() { clickableTest(false, false, mOtherView, true) } @Test fun testNotGuestNotCurrentUserIsClickable_sameView() { clickableTest(false, false, mUserDetailItemView, true) } private fun createUserRecord(current: Boolean, guest: Boolean) = UserSwitcherController.UserRecord( mUserInfo, mPicture, guest, current, false /* isAddUser */, false /* isRestricted */, true /* isSwitchToEnabled */) } No newline at end of file