Merge "add ui event metric for user switch"

This commit is contained in:
Anna Bauza
2022-12-21 21:39:11 +00:00
committed by Android (Google) Code Review
4 changed files with 75 additions and 1 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -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
}
}
}

View File

@@ -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())
}