Add User Switcher log to user creation actions

Bug: 260731667
Test: croot && make RunSettingsRoboTests -j40
Change-Id: I24603f93e484cf0eb85fc6d983aba53e060f7607
This commit is contained in:
Anna Bauza
2022-12-02 12:55:07 +00:00
parent f21acd4bfc
commit 693dcd3326
5 changed files with 54 additions and 5 deletions

View File

@@ -31,6 +31,7 @@ import android.os.UserHandle
import android.os.UserManager
import android.provider.Settings
import android.util.Log
import com.android.internal.logging.UiEventLogger
import com.android.internal.util.UserIcons
import com.android.systemui.R
import com.android.systemui.SystemUISecondaryUserService
@@ -54,6 +55,7 @@ import com.android.systemui.user.domain.model.ShowDialogRequestModel
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.util.kotlin.pairwise
import java.io.PrintWriter
import javax.inject.Inject
@@ -93,6 +95,7 @@ constructor(
private val activityManager: ActivityManager,
private val refreshUsersScheduler: RefreshUsersScheduler,
private val guestUserInteractor: GuestUserInteractor,
private val uiEventLogger: UiEventLogger,
) {
/**
* Defines interface for classes that can be notified when the state of users on the device is
@@ -115,9 +118,7 @@ constructor(
private val callbackMutex = Mutex()
private val callbacks = mutableSetOf<UserCallback>()
private val userInfos: Flow<List<UserInfo>> =
repository.userInfos.map { userInfos ->
userInfos.filter { it.isFull }
}
repository.userInfos.map { userInfos -> userInfos.filter { it.isFull } }
/** List of current on-device users to select from. */
val users: Flow<List<UserModel>>
@@ -427,14 +428,17 @@ constructor(
dialogShower: UserSwitchDialogController.DialogShower? = null,
) {
when (action) {
UserActionModel.ENTER_GUEST_MODE ->
UserActionModel.ENTER_GUEST_MODE -> {
uiEventLogger.log(MultiUserActionsEvent.CREATE_GUEST_FROM_USER_SWITCHER)
guestUserInteractor.createAndSwitchTo(
this::showDialog,
this::dismissDialog,
) { userId ->
selectUser(userId, dialogShower)
}
}
UserActionModel.ADD_USER -> {
uiEventLogger.log(MultiUserActionsEvent.CREATE_USER_FROM_USER_SWITCHER)
val currentUser = repository.getSelectedUserInfo()
showDialog(
ShowDialogRequestModel.ShowAddUserDialog(
@@ -445,7 +449,8 @@ constructor(
)
)
}
UserActionModel.ADD_SUPERVISED_USER ->
UserActionModel.ADD_SUPERVISED_USER -> {
uiEventLogger.log(MultiUserActionsEvent.CREATE_RESTRICTED_USER_FROM_USER_SWITCHER)
activityStarter.startActivity(
Intent()
.setAction(UserManager.ACTION_CREATE_SUPERVISED_USER)
@@ -453,6 +458,7 @@ constructor(
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK),
/* dismissShade= */ true,
)
}
UserActionModel.NAVIGATE_TO_USER_MANAGEMENT ->
activityStarter.startActivity(
Intent(Settings.ACTION_USER_SETTINGS),

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 com.android.internal.logging.UiEvent
import com.android.internal.logging.UiEventLogger
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);
override fun getId(): Int {
return value
}
}

View File

@@ -52,6 +52,7 @@ import com.android.systemui.user.data.source.UserRecord
import com.android.systemui.user.domain.model.ShowDialogRequestModel
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.util.mockito.any
import com.android.systemui.util.mockito.argumentCaptor
import com.android.systemui.util.mockito.eq
@@ -74,6 +75,7 @@ import org.mockito.ArgumentMatchers.anyBoolean
import org.mockito.ArgumentMatchers.anyInt
import org.mockito.Mock
import org.mockito.Mockito.never
import org.mockito.Mockito.times
import org.mockito.Mockito.verify
import org.mockito.MockitoAnnotations
@@ -158,6 +160,7 @@ class UserInteractorTest : SysuiTestCase() {
resumeSessionReceiver = resumeSessionReceiver,
resetOrExitSessionReceiver = resetOrExitSessionReceiver,
),
uiEventLogger = uiEventLogger,
featureFlags = featureFlags,
)
}
@@ -457,6 +460,9 @@ class UserInteractorTest : SysuiTestCase() {
val dialogShower: UserSwitchDialogController.DialogShower = mock()
underTest.executeAction(UserActionModel.ADD_USER, dialogShower)
verify(uiEventLogger, times(1))
.log(MultiUserActionsEvent.CREATE_USER_FROM_USER_SWITCHER)
assertThat(dialogRequest)
.isEqualTo(
ShowDialogRequestModel.ShowAddUserDialog(
@@ -478,6 +484,8 @@ class UserInteractorTest : SysuiTestCase() {
runBlocking(IMMEDIATE) {
underTest.executeAction(UserActionModel.ADD_SUPERVISED_USER)
verify(uiEventLogger, times(1))
.log(MultiUserActionsEvent.CREATE_RESTRICTED_USER_FROM_USER_SWITCHER)
val intentCaptor = kotlinArgumentCaptor<Intent>()
verify(activityStarter).startActivity(intentCaptor.capture(), eq(true))
assertThat(intentCaptor.value.action)
@@ -525,6 +533,8 @@ class UserInteractorTest : SysuiTestCase() {
underTest.executeAction(UserActionModel.ENTER_GUEST_MODE)
verify(uiEventLogger, times(1))
.log(MultiUserActionsEvent.CREATE_GUEST_FROM_USER_SWITCHER)
assertThat(dialogRequests)
.contains(
ShowDialogRequestModel.ShowUserCreationDialog(isGuest = true),

View File

@@ -255,6 +255,7 @@ class StatusBarUserChipViewModelTest : SysuiTestCase() {
activityManager = activityManager,
refreshUsersScheduler = refreshUsersScheduler,
guestUserInteractor = guestUserInteractor,
uiEventLogger = uiEventLogger,
)
)
}

View File

@@ -158,6 +158,7 @@ class UserSwitcherViewModelTest : SysuiTestCase() {
activityManager = activityManager,
refreshUsersScheduler = refreshUsersScheduler,
guestUserInteractor = guestUserInteractor,
uiEventLogger = uiEventLogger,
),
powerInteractor =
PowerInteractor(