1 /* <lambda>null2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.systemui.qs.user 18 19 import android.app.Dialog 20 import android.content.Context 21 import android.content.DialogInterface 22 import android.content.DialogInterface.BUTTON_NEUTRAL 23 import android.content.Intent 24 import android.provider.Settings 25 import android.view.LayoutInflater 26 import androidx.annotation.VisibleForTesting 27 import com.android.internal.jank.InteractionJankMonitor 28 import com.android.internal.logging.UiEventLogger 29 import com.android.systemui.R 30 import com.android.systemui.animation.DialogCuj 31 import com.android.systemui.animation.DialogLaunchAnimator 32 import com.android.systemui.animation.Expandable 33 import com.android.systemui.dagger.SysUISingleton 34 import com.android.systemui.plugins.ActivityStarter 35 import com.android.systemui.plugins.FalsingManager 36 import com.android.systemui.qs.QSUserSwitcherEvent 37 import com.android.systemui.qs.tiles.UserDetailView 38 import com.android.systemui.statusbar.phone.SystemUIDialog 39 import com.android.systemui.user.ui.dialog.DialogShowerImpl 40 import javax.inject.Inject 41 import javax.inject.Provider 42 43 /** 44 * Controller for [UserDialog]. 45 */ 46 @SysUISingleton 47 class UserSwitchDialogController @VisibleForTesting constructor( 48 private val userDetailViewAdapterProvider: Provider<UserDetailView.Adapter>, 49 private val activityStarter: ActivityStarter, 50 private val falsingManager: FalsingManager, 51 private val dialogLaunchAnimator: DialogLaunchAnimator, 52 private val uiEventLogger: UiEventLogger, 53 private val dialogFactory: (Context) -> SystemUIDialog 54 ) { 55 56 @Inject 57 constructor( 58 userDetailViewAdapterProvider: Provider<UserDetailView.Adapter>, 59 activityStarter: ActivityStarter, 60 falsingManager: FalsingManager, 61 dialogLaunchAnimator: DialogLaunchAnimator, 62 uiEventLogger: UiEventLogger 63 ) : this( 64 userDetailViewAdapterProvider, 65 activityStarter, 66 falsingManager, 67 dialogLaunchAnimator, 68 uiEventLogger, 69 { SystemUIDialog(it) } 70 ) 71 72 companion object { 73 private const val INTERACTION_JANK_TAG = "switch_user" 74 private val USER_SETTINGS_INTENT = Intent(Settings.ACTION_USER_SETTINGS) 75 } 76 77 /** 78 * Show a [UserDialog]. 79 * 80 * Populate the dialog with information from and adapter obtained from 81 * [userDetailViewAdapterProvider] and show it as launched from [expandable]. 82 */ 83 fun showDialog(context: Context, expandable: Expandable) { 84 with(dialogFactory(context)) { 85 setShowForAllUsers(true) 86 setCanceledOnTouchOutside(true) 87 88 setTitle(R.string.qs_user_switch_dialog_title) 89 setPositiveButton(R.string.quick_settings_done) { _, _ -> 90 uiEventLogger.log(QSUserSwitcherEvent.QS_USER_DETAIL_CLOSE) 91 } 92 setNeutralButton(R.string.quick_settings_more_user_settings, { _, _ -> 93 if (!falsingManager.isFalseTap(FalsingManager.LOW_PENALTY)) { 94 uiEventLogger.log(QSUserSwitcherEvent.QS_USER_MORE_SETTINGS) 95 val controller = dialogLaunchAnimator.createActivityLaunchController( 96 getButton(BUTTON_NEUTRAL) 97 ) 98 99 if (controller == null) { 100 dismiss() 101 } 102 103 activityStarter.postStartActivityDismissingKeyguard( 104 USER_SETTINGS_INTENT, 0, controller 105 ) 106 } 107 }, false /* dismissOnClick */) 108 val gridFrame = LayoutInflater.from(this.context) 109 .inflate(R.layout.qs_user_dialog_content, null) 110 setView(gridFrame) 111 112 val adapter = userDetailViewAdapterProvider.get() 113 114 adapter.linkToViewGroup(gridFrame.findViewById(R.id.grid)) 115 116 val controller = 117 expandable.dialogLaunchController( 118 DialogCuj(InteractionJankMonitor.CUJ_SHADE_DIALOG_OPEN, INTERACTION_JANK_TAG) 119 ) 120 if (controller != null) { 121 dialogLaunchAnimator.show( 122 this, 123 controller, 124 ) 125 } else { 126 show() 127 } 128 129 uiEventLogger.log(QSUserSwitcherEvent.QS_USER_DETAIL_OPEN) 130 adapter.injectDialogShower(DialogShowerImpl(this, dialogLaunchAnimator)) 131 } 132 } 133 134 interface DialogShower : DialogInterface { 135 fun showDialog(dialog: Dialog, cuj: DialogCuj) 136 } 137 } 138