• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.DialogInterface
21 import android.content.DialogInterface.BUTTON_NEUTRAL
22 import android.content.Intent
23 import android.provider.Settings
24 import android.view.LayoutInflater
25 import com.android.internal.jank.InteractionJankMonitor
26 import com.android.internal.logging.UiEventLogger
27 import com.android.systemui.animation.DialogCuj
28 import com.android.systemui.animation.DialogTransitionAnimator
29 import com.android.systemui.animation.Expandable
30 import com.android.systemui.dagger.SysUISingleton
31 import com.android.systemui.plugins.ActivityStarter
32 import com.android.systemui.plugins.FalsingManager
33 import com.android.systemui.qs.QSUserSwitcherEvent
34 import com.android.systemui.qs.tiles.UserDetailView
35 import com.android.systemui.res.R
36 import com.android.systemui.shade.domain.interactor.ShadeDialogContextInteractor
37 import com.android.systemui.statusbar.phone.SystemUIDialog
38 import com.android.systemui.user.ui.dialog.DialogShowerImpl
39 import javax.inject.Inject
40 import javax.inject.Provider
41 
42 /** Controller for [UserDialog]. */
43 @SysUISingleton
44 class UserSwitchDialogController
45 @Inject
46 constructor(
47     private val userDetailViewAdapterProvider: Provider<UserDetailView.Adapter>,
48     private val activityStarter: ActivityStarter,
49     private val falsingManager: FalsingManager,
50     private val dialogTransitionAnimator: DialogTransitionAnimator,
51     private val uiEventLogger: UiEventLogger,
52     private val dialogFactory: SystemUIDialog.Factory,
53     private val shadeDialogContextInteractor: ShadeDialogContextInteractor,
54 ) {
55 
56     companion object {
57         private const val INTERACTION_JANK_TAG = "switch_user"
58         private val USER_SETTINGS_INTENT = Intent(Settings.ACTION_USER_SETTINGS)
59     }
60 
61     /**
62      * Show a [UserDialog].
63      *
64      * Populate the dialog with information from and adapter obtained from
65      * [userDetailViewAdapterProvider] and show it as launched from [expandable].
66      */
67     fun showDialog(expandable: Expandable) {
68         with(dialogFactory.create(shadeDialogContextInteractor.context)) {
69             setShowForAllUsers(true)
70             setCanceledOnTouchOutside(true)
71 
72             setTitle(R.string.qs_user_switch_dialog_title)
73             setPositiveButton(R.string.quick_settings_done) { _, _ ->
74                 uiEventLogger.log(QSUserSwitcherEvent.QS_USER_DETAIL_CLOSE)
75             }
76             setNeutralButton(
77                 R.string.quick_settings_more_user_settings,
78                 { _, _ ->
79                     if (!falsingManager.isFalseTap(FalsingManager.LOW_PENALTY)) {
80                         uiEventLogger.log(QSUserSwitcherEvent.QS_USER_MORE_SETTINGS)
81                         val controller =
82                             dialogTransitionAnimator.createActivityTransitionController(
83                                 getButton(BUTTON_NEUTRAL)
84                             )
85 
86                         if (controller == null) {
87                             dismiss()
88                         }
89 
90                         activityStarter.postStartActivityDismissingKeyguard(
91                             USER_SETTINGS_INTENT,
92                             0,
93                             controller,
94                         )
95                     }
96                 },
97                 false, /* dismissOnClick */
98             )
99             val gridFrame =
100                 LayoutInflater.from(this.context).inflate(R.layout.qs_user_dialog_content, null)
101             setView(gridFrame)
102 
103             val adapter = userDetailViewAdapterProvider.get()
104 
105             adapter.linkToViewGroup(gridFrame.findViewById(R.id.grid))
106 
107             val controller =
108                 expandable.dialogTransitionController(
109                     DialogCuj(InteractionJankMonitor.CUJ_SHADE_DIALOG_OPEN, INTERACTION_JANK_TAG)
110                 )
111             if (controller != null) {
112                 dialogTransitionAnimator.show(this, controller)
113             } else {
114                 show()
115             }
116 
117             uiEventLogger.log(QSUserSwitcherEvent.QS_USER_DETAIL_OPEN)
118             adapter.injectDialogShower(DialogShowerImpl(this, dialogTransitionAnimator))
119         }
120     }
121 
122     interface DialogShower : DialogInterface {
123         fun showDialog(dialog: Dialog, cuj: DialogCuj)
124     }
125 }
126