diff options
4 files changed, 75 insertions, 1 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/user/domain/interactor/UserInteractor.kt b/packages/SystemUI/src/com/android/systemui/user/domain/interactor/UserInteractor.kt index 74295f0b8859..45cb11e80172 100644 --- a/packages/SystemUI/src/com/android/systemui/user/domain/interactor/UserInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/user/domain/interactor/UserInteractor.kt @@ -56,6 +56,7 @@ import com.android.systemui.user.legacyhelper.data.LegacyUserDataHelper import com.android.systemui.user.shared.model.UserActionModel import com.android.systemui.user.shared.model.UserModel import com.android.systemui.user.utils.MultiUserActionsEvent +import com.android.systemui.user.utils.MultiUserActionsEventHelper import com.android.systemui.util.kotlin.pairwise import java.io.PrintWriter import javax.inject.Inject @@ -372,6 +373,9 @@ constructor( if (LegacyUserDataHelper.isUser(record)) { // It's safe to use checkNotNull around record.info because isUser only returns true // if record.info is not null. + uiEventLogger.log( + MultiUserActionsEventHelper.userSwitchMetric(checkNotNull(record.info)) + ) selectUser(checkNotNull(record.info).id, dialogShower) } else { executeAction(LegacyUserDataHelper.toUserActionModel(record), dialogShower) diff --git a/packages/SystemUI/src/com/android/systemui/user/utils/MultiUserActionsEvent.kt b/packages/SystemUI/src/com/android/systemui/user/utils/MultiUserActionsEvent.kt index bfedac9e6f2c..ec79b6d8ba98 100644 --- a/packages/SystemUI/src/com/android/systemui/user/utils/MultiUserActionsEvent.kt +++ b/packages/SystemUI/src/com/android/systemui/user/utils/MultiUserActionsEvent.kt @@ -23,7 +23,13 @@ enum class MultiUserActionsEvent(val value: Int) : UiEventLogger.UiEventEnum { @UiEvent(doc = "Add User tap from User Switcher.") CREATE_USER_FROM_USER_SWITCHER(1257), @UiEvent(doc = "Add Guest tap from User Switcher.") CREATE_GUEST_FROM_USER_SWITCHER(1258), @UiEvent(doc = "Add Restricted User tap from User Switcher.") - CREATE_RESTRICTED_USER_FROM_USER_SWITCHER(1259); + CREATE_RESTRICTED_USER_FROM_USER_SWITCHER(1259), + @UiEvent(doc = "Switch to User tap from User Switcher.") + SWITCH_TO_USER_FROM_USER_SWITCHER(1266), + @UiEvent(doc = "Switch to Guest User tap from User Switcher.") + SWITCH_TO_GUEST_FROM_USER_SWITCHER(1267), + @UiEvent(doc = "Switch to Restricted User tap from User Switcher.") + SWITCH_TO_RESTRICTED_USER_FROM_USER_SWITCHER(1268); override fun getId(): Int { return value diff --git a/packages/SystemUI/src/com/android/systemui/user/utils/MultiUserActionsEventHelper.kt b/packages/SystemUI/src/com/android/systemui/user/utils/MultiUserActionsEventHelper.kt new file mode 100644 index 000000000000..d12a7881af4a --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/user/utils/MultiUserActionsEventHelper.kt @@ -0,0 +1,31 @@ +/* + * 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.utils + +import android.content.pm.UserInfo + +class MultiUserActionsEventHelper { + /** Return MultiUserActionsEvent based on UserInfo. */ + companion object { + fun userSwitchMetric(userInfo: UserInfo): MultiUserActionsEvent { + if (userInfo.isGuest) return MultiUserActionsEvent.SWITCH_TO_GUEST_FROM_USER_SWITCHER + if (userInfo.isRestricted) + return MultiUserActionsEvent.SWITCH_TO_RESTRICTED_USER_FROM_USER_SWITCHER + return MultiUserActionsEvent.SWITCH_TO_USER_FROM_USER_SWITCHER + } + } +} diff --git a/packages/SystemUI/tests/src/com/android/systemui/user/domain/interactor/UserInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/user/domain/interactor/UserInteractorTest.kt index ffa4e2d8f158..95345756f4ae 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/user/domain/interactor/UserInteractorTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/user/domain/interactor/UserInteractorTest.kt @@ -175,6 +175,8 @@ class UserInteractorTest : SysuiTestCase() { underTest.onRecordSelected(UserRecord(info = userInfos[1]), dialogShower) + verify(uiEventLogger, times(1)) + .log(MultiUserActionsEvent.SWITCH_TO_USER_FROM_USER_SWITCHER) verify(dialogShower).dismiss() verify(activityManager).switchUser(userInfos[1].id) Unit @@ -190,6 +192,33 @@ class UserInteractorTest : SysuiTestCase() { underTest.onRecordSelected(UserRecord(info = userInfos.last())) + verify(uiEventLogger, times(1)) + .log(MultiUserActionsEvent.SWITCH_TO_GUEST_FROM_USER_SWITCHER) + verify(activityManager).switchUser(userInfos.last().id) + Unit + } + + @Test + fun `onRecordSelected - switch to restricted user`() = + runBlocking(IMMEDIATE) { + var userInfos = createUserInfos(count = 2, includeGuest = false).toMutableList() + userInfos.add( + UserInfo( + 60, + "Restricted user", + /* iconPath= */ "", + /* flags= */ UserInfo.FLAG_FULL, + UserManager.USER_TYPE_FULL_RESTRICTED, + ) + ) + userRepository.setUserInfos(userInfos) + userRepository.setSelectedUserInfo(userInfos[0]) + userRepository.setSettings(UserSwitcherSettingsModel(isUserSwitcherEnabled = true)) + + underTest.onRecordSelected(UserRecord(info = userInfos.last())) + + verify(uiEventLogger, times(1)) + .log(MultiUserActionsEvent.SWITCH_TO_RESTRICTED_USER_FROM_USER_SWITCHER) verify(activityManager).switchUser(userInfos.last().id) Unit } @@ -206,6 +235,8 @@ class UserInteractorTest : SysuiTestCase() { underTest.onRecordSelected(UserRecord(isGuest = true), dialogShower) + verify(uiEventLogger, times(1)) + .log(MultiUserActionsEvent.CREATE_GUEST_FROM_USER_SWITCHER) verify(dialogShower).dismiss() verify(manager).createGuest(any()) Unit @@ -221,6 +252,8 @@ class UserInteractorTest : SysuiTestCase() { underTest.onRecordSelected(UserRecord(isAddSupervisedUser = true), dialogShower) + verify(uiEventLogger, times(1)) + .log(MultiUserActionsEvent.CREATE_RESTRICTED_USER_FROM_USER_SWITCHER) verify(dialogShower, never()).dismiss() verify(activityStarter).startActivity(any(), anyBoolean()) } |