Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file |
| 5 | * except in compliance with the License. You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software distributed under the |
| 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 11 | * KIND, either express or implied. See the License for the specific language governing |
| 12 | * permissions and limitations under the License. |
| 13 | */ |
| 14 | |
| 15 | package com.android.systemui.globalactions; |
| 16 | |
Adrian Roos | edfab3b | 2018-03-08 18:39:20 +0100 | [diff] [blame] | 17 | import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; |
Adrian Roos | 2f05bb3 | 2018-02-19 16:42:27 +0100 | [diff] [blame] | 18 | import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; |
| 19 | |
Chad Brubaker | f4075fe | 2018-01-03 13:23:22 -0800 | [diff] [blame] | 20 | import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_USER_REQUEST; |
| 21 | import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_NOT_REQUIRED; |
Chad Brubaker | 4f28f0d | 2017-09-07 14:28:13 -0700 | [diff] [blame] | 22 | import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN; |
| 23 | |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 24 | import android.annotation.Nullable; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 25 | import android.app.ActivityManager; |
| 26 | import android.app.Dialog; |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 27 | import android.app.IActivityManager; |
Chad Brubaker | f4075fe | 2018-01-03 13:23:22 -0800 | [diff] [blame] | 28 | import android.app.KeyguardManager; |
Steve Elliott | 4c86885 | 2019-03-14 16:25:41 -0400 | [diff] [blame] | 29 | import android.app.PendingIntent; |
Steve Elliott | 53f12ae | 2019-05-13 17:14:15 -0400 | [diff] [blame] | 30 | import android.app.StatusBarManager; |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 31 | import android.app.WallpaperManager; |
Alex Chau | 0445885 | 2017-11-27 18:21:23 +0000 | [diff] [blame] | 32 | import android.app.admin.DevicePolicyManager; |
Pavel Grafov | 059021b | 2018-05-02 13:44:46 +0100 | [diff] [blame] | 33 | import android.app.trust.TrustManager; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 34 | import android.content.BroadcastReceiver; |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 35 | import android.content.ContentResolver; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 36 | import android.content.Context; |
| 37 | import android.content.DialogInterface; |
| 38 | import android.content.Intent; |
| 39 | import android.content.IntentFilter; |
| 40 | import android.content.pm.UserInfo; |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 41 | import android.content.res.Resources; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 42 | import android.database.ContentObserver; |
| 43 | import android.graphics.drawable.Drawable; |
| 44 | import android.media.AudioManager; |
| 45 | import android.net.ConnectivityManager; |
Steve Elliott | 53f12ae | 2019-05-13 17:14:15 -0400 | [diff] [blame] | 46 | import android.os.Binder; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 47 | import android.os.Handler; |
Steve Elliott | 53f12ae | 2019-05-13 17:14:15 -0400 | [diff] [blame] | 48 | import android.os.IBinder; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 49 | import android.os.Message; |
| 50 | import android.os.RemoteException; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 51 | import android.os.SystemProperties; |
| 52 | import android.os.UserHandle; |
| 53 | import android.os.UserManager; |
| 54 | import android.os.Vibrator; |
| 55 | import android.provider.Settings; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 56 | import android.service.dreams.IDreamManager; |
Inseob Kim | 5e82f73 | 2019-11-08 15:08:38 +0900 | [diff] [blame] | 57 | import android.sysprop.TelephonyProperties; |
Fan Zhang | f991476 | 2019-11-01 15:58:38 -0700 | [diff] [blame] | 58 | import android.telecom.TelecomManager; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 59 | import android.telephony.PhoneStateListener; |
| 60 | import android.telephony.ServiceState; |
| 61 | import android.telephony.TelephonyManager; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 62 | import android.util.ArraySet; |
yuanjiahsu | 88363e9 | 2018-09-06 19:23:52 +0800 | [diff] [blame] | 63 | import android.util.FeatureFlagUtils; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 64 | import android.util.Log; |
Lucas Dupin | 448786c | 2017-07-24 17:44:25 -0700 | [diff] [blame] | 65 | import android.view.ContextThemeWrapper; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 66 | import android.view.LayoutInflater; |
| 67 | import android.view.View; |
| 68 | import android.view.ViewGroup; |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 69 | import android.view.Window; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 70 | import android.view.WindowManager; |
| 71 | import android.view.WindowManagerGlobal; |
| 72 | import android.view.accessibility.AccessibilityEvent; |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 73 | import android.widget.FrameLayout; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 74 | import android.widget.ImageView; |
| 75 | import android.widget.ImageView.ScaleType; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 76 | import android.widget.TextView; |
| 77 | |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 78 | import com.android.internal.R; |
| 79 | import com.android.internal.colorextraction.ColorExtractor; |
| 80 | import com.android.internal.colorextraction.ColorExtractor.GradientColors; |
Lucas Dupin | 2bd3af6 | 2019-03-25 17:44:28 -0700 | [diff] [blame] | 81 | import com.android.internal.colorextraction.drawable.ScrimDrawable; |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 82 | import com.android.internal.logging.MetricsLogger; |
| 83 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Steve Elliott | 53f12ae | 2019-05-13 17:14:15 -0400 | [diff] [blame] | 84 | import com.android.internal.statusbar.IStatusBarService; |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 85 | import com.android.internal.util.EmergencyAffordanceManager; |
Beth Thibodeau | 5898ac4 | 2018-10-26 13:00:09 -0400 | [diff] [blame] | 86 | import com.android.internal.util.ScreenRecordHelper; |
Alison Cichowlas | a2cd19e | 2017-12-06 10:51:21 -0500 | [diff] [blame] | 87 | import com.android.internal.util.ScreenshotHelper; |
Steve Elliott | 48f75db | 2019-05-03 15:03:38 -0400 | [diff] [blame] | 88 | import com.android.internal.view.RotationPolicy; |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 89 | import com.android.internal.widget.LockPatternUtils; |
| 90 | import com.android.systemui.Dependency; |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 91 | import com.android.systemui.Interpolators; |
Aaron Heuckroth | f708d47 | 2019-01-10 16:54:51 -0500 | [diff] [blame] | 92 | import com.android.systemui.MultiListLayout; |
Aaron Heuckroth | 57d60d2 | 2019-03-05 14:00:12 -0500 | [diff] [blame] | 93 | import com.android.systemui.MultiListLayout.MultiListAdapter; |
Fabian Kozynski | ff5e91f | 2019-09-24 15:38:08 -0400 | [diff] [blame] | 94 | import com.android.systemui.broadcast.BroadcastDispatcher; |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 95 | import com.android.systemui.colorextraction.SysuiColorExtractor; |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame^] | 96 | import com.android.systemui.controls.ui.ControlsUiController; |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 97 | import com.android.systemui.dagger.qualifiers.Main; |
Steve Elliott | 4c86885 | 2019-03-14 16:25:41 -0400 | [diff] [blame] | 98 | import com.android.systemui.plugins.ActivityStarter; |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 99 | import com.android.systemui.plugins.GlobalActions.GlobalActionsManager; |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 100 | import com.android.systemui.plugins.GlobalActionsPanelPlugin; |
Lucas Dupin | 991415e | 2019-11-25 17:48:58 -0800 | [diff] [blame] | 101 | import com.android.systemui.statusbar.BlurUtils; |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame^] | 102 | import com.android.systemui.statusbar.phone.NotificationShadeWindowController; |
Steve Elliott | bfa314a | 2019-03-06 13:53:19 -0500 | [diff] [blame] | 103 | import com.android.systemui.statusbar.phone.ScrimController; |
Lucas Dupin | e5b7dc7 | 2018-10-02 15:18:05 -0700 | [diff] [blame] | 104 | import com.android.systemui.statusbar.policy.ConfigurationController; |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 105 | import com.android.systemui.statusbar.policy.KeyguardStateController; |
Shaotang Li | 5c42263 | 2018-07-04 14:18:40 +0800 | [diff] [blame] | 106 | import com.android.systemui.util.EmergencyDialerConstants; |
Aaron Heuckroth | 75e249f | 2019-02-01 15:59:57 -0500 | [diff] [blame] | 107 | import com.android.systemui.util.leak.RotationUtils; |
Julia Reynolds | 4241192 | 2017-11-08 11:19:09 -0500 | [diff] [blame] | 108 | import com.android.systemui.volume.SystemUIInterpolators.LogAccelerateInterpolator; |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 109 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 110 | import java.util.ArrayList; |
| 111 | import java.util.List; |
| 112 | |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 113 | import javax.inject.Inject; |
| 114 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 115 | /** |
| 116 | * Helper to show the global actions dialog. Each item is an {@link Action} that |
| 117 | * may show depending on whether the keyguard is showing, and whether the device |
| 118 | * is provisioned. |
| 119 | */ |
Aaron Heuckroth | 57d60d2 | 2019-03-05 14:00:12 -0500 | [diff] [blame] | 120 | public class GlobalActionsDialog implements DialogInterface.OnDismissListener, |
| 121 | DialogInterface.OnShowListener, ConfigurationController.ConfigurationListener { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 122 | |
| 123 | static public final String SYSTEM_DIALOG_REASON_KEY = "reason"; |
| 124 | static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions"; |
Lucas Dupin | 1d4a579 | 2018-04-02 15:14:59 -0700 | [diff] [blame] | 125 | static public final String SYSTEM_DIALOG_REASON_DREAM = "dream"; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 126 | |
| 127 | private static final String TAG = "GlobalActionsDialog"; |
| 128 | |
| 129 | private static final boolean SHOW_SILENT_TOGGLE = true; |
| 130 | |
| 131 | /* Valid settings for global actions keys. |
| 132 | * see config.xml config_globalActionList */ |
| 133 | private static final String GLOBAL_ACTION_KEY_POWER = "power"; |
| 134 | private static final String GLOBAL_ACTION_KEY_AIRPLANE = "airplane"; |
| 135 | private static final String GLOBAL_ACTION_KEY_BUGREPORT = "bugreport"; |
| 136 | private static final String GLOBAL_ACTION_KEY_SILENT = "silent"; |
| 137 | private static final String GLOBAL_ACTION_KEY_USERS = "users"; |
| 138 | private static final String GLOBAL_ACTION_KEY_SETTINGS = "settings"; |
| 139 | private static final String GLOBAL_ACTION_KEY_LOCKDOWN = "lockdown"; |
| 140 | private static final String GLOBAL_ACTION_KEY_VOICEASSIST = "voiceassist"; |
| 141 | private static final String GLOBAL_ACTION_KEY_ASSIST = "assist"; |
| 142 | private static final String GLOBAL_ACTION_KEY_RESTART = "restart"; |
Alex Chau | 0445885 | 2017-11-27 18:21:23 +0000 | [diff] [blame] | 143 | private static final String GLOBAL_ACTION_KEY_LOGOUT = "logout"; |
Wesley.CW Wang | 8d07276 | 2018-05-28 16:39:27 +0800 | [diff] [blame] | 144 | private static final String GLOBAL_ACTION_KEY_EMERGENCY = "emergency"; |
Alison Cichowlas | a2cd19e | 2017-12-06 10:51:21 -0500 | [diff] [blame] | 145 | private static final String GLOBAL_ACTION_KEY_SCREENSHOT = "screenshot"; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 146 | |
| 147 | private final Context mContext; |
| 148 | private final GlobalActionsManager mWindowManagerFuncs; |
| 149 | private final AudioManager mAudioManager; |
| 150 | private final IDreamManager mDreamManager; |
Alex Chau | 0445885 | 2017-11-27 18:21:23 +0000 | [diff] [blame] | 151 | private final DevicePolicyManager mDevicePolicyManager; |
Chad Brubaker | f4075fe | 2018-01-03 13:23:22 -0800 | [diff] [blame] | 152 | private final LockPatternUtils mLockPatternUtils; |
| 153 | private final KeyguardManager mKeyguardManager; |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 154 | private final BroadcastDispatcher mBroadcastDispatcher; |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 155 | private final ContentResolver mContentResolver; |
| 156 | private final Resources mResources; |
| 157 | private final UserManager mUserManager; |
| 158 | private final TrustManager mTrustManager; |
| 159 | private final IActivityManager mIActivityManager; |
| 160 | private final TelecomManager mTelecomManager; |
| 161 | private final MetricsLogger mMetricsLogger; |
Lucas Dupin | 991415e | 2019-11-25 17:48:58 -0800 | [diff] [blame] | 162 | private final BlurUtils mBlurUtils; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 163 | |
| 164 | private ArrayList<Action> mItems; |
| 165 | private ActionsDialog mDialog; |
| 166 | |
| 167 | private Action mSilentModeAction; |
| 168 | private ToggleAction mAirplaneModeOn; |
| 169 | |
| 170 | private MyAdapter mAdapter; |
| 171 | |
| 172 | private boolean mKeyguardShowing = false; |
| 173 | private boolean mDeviceProvisioned = false; |
| 174 | private ToggleAction.State mAirplaneState = ToggleAction.State.Off; |
| 175 | private boolean mIsWaitingForEcmExit = false; |
| 176 | private boolean mHasTelephony; |
| 177 | private boolean mHasVibrator; |
| 178 | private final boolean mShowSilentToggle; |
| 179 | private final EmergencyAffordanceManager mEmergencyAffordanceManager; |
Alison Cichowlas | a2cd19e | 2017-12-06 10:51:21 -0500 | [diff] [blame] | 180 | private final ScreenshotHelper mScreenshotHelper; |
Beth Thibodeau | 5898ac4 | 2018-10-26 13:00:09 -0400 | [diff] [blame] | 181 | private final ScreenRecordHelper mScreenRecordHelper; |
Steve Elliott | a3f520792 | 2019-03-18 13:37:22 -0400 | [diff] [blame] | 182 | private final ActivityStarter mActivityStarter; |
Lucas Dupin | 991415e | 2019-11-25 17:48:58 -0800 | [diff] [blame] | 183 | private final SysuiColorExtractor mSysuiColorExtractor; |
| 184 | private final IStatusBarService mStatusBarService; |
| 185 | private final NotificationShadeWindowController mNotificationShadeWindowController; |
Steve Elliott | a3f520792 | 2019-03-18 13:37:22 -0400 | [diff] [blame] | 186 | private GlobalActionsPanelPlugin mPanelPlugin; |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame^] | 187 | private ControlsUiController mControlsUiController; |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 188 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 189 | /** |
| 190 | * @param context everything needs a context :( |
| 191 | */ |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 192 | @Inject |
| 193 | public GlobalActionsDialog(Context context, GlobalActionsManager windowManagerFuncs, |
| 194 | AudioManager audioManager, IDreamManager iDreamManager, |
| 195 | DevicePolicyManager devicePolicyManager, LockPatternUtils lockPatternUtils, |
| 196 | KeyguardManager keyguardManager, BroadcastDispatcher broadcastDispatcher, |
| 197 | ConnectivityManager connectivityManager, TelephonyManager telephonyManager, |
| 198 | ContentResolver contentResolver, @Nullable Vibrator vibrator, @Main Resources resources, |
| 199 | ConfigurationController configurationController, ActivityStarter activityStarter, |
| 200 | KeyguardStateController keyguardStateController, UserManager userManager, |
| 201 | TrustManager trustManager, IActivityManager iActivityManager, |
Lucas Dupin | 991415e | 2019-11-25 17:48:58 -0800 | [diff] [blame] | 202 | TelecomManager telecomManager, MetricsLogger metricsLogger, |
| 203 | BlurUtils blurUtils, SysuiColorExtractor colorExtractor, |
| 204 | IStatusBarService statusBarService, |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame^] | 205 | NotificationShadeWindowController notificationShadeWindowController, |
| 206 | ControlsUiController controlsUiController) { |
Lucas Dupin | 448786c | 2017-07-24 17:44:25 -0700 | [diff] [blame] | 207 | mContext = new ContextThemeWrapper(context, com.android.systemui.R.style.qs_theme); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 208 | mWindowManagerFuncs = windowManagerFuncs; |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 209 | mAudioManager = audioManager; |
| 210 | mDreamManager = iDreamManager; |
| 211 | mDevicePolicyManager = devicePolicyManager; |
| 212 | mLockPatternUtils = lockPatternUtils; |
| 213 | mKeyguardManager = keyguardManager; |
| 214 | mBroadcastDispatcher = broadcastDispatcher; |
| 215 | mContentResolver = contentResolver; |
| 216 | mResources = resources; |
| 217 | mUserManager = userManager; |
| 218 | mTrustManager = trustManager; |
| 219 | mIActivityManager = iActivityManager; |
| 220 | mTelecomManager = telecomManager; |
| 221 | mMetricsLogger = metricsLogger; |
Lucas Dupin | 991415e | 2019-11-25 17:48:58 -0800 | [diff] [blame] | 222 | mBlurUtils = blurUtils; |
| 223 | mSysuiColorExtractor = colorExtractor; |
| 224 | mStatusBarService = statusBarService; |
| 225 | mNotificationShadeWindowController = notificationShadeWindowController; |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame^] | 226 | mControlsUiController = controlsUiController; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 227 | |
| 228 | // receive broadcasts |
| 229 | IntentFilter filter = new IntentFilter(); |
| 230 | filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); |
| 231 | filter.addAction(Intent.ACTION_SCREEN_OFF); |
Jayachandran C | 142eae0 | 2019-12-13 19:29:20 -0800 | [diff] [blame] | 232 | filter.addAction(TelephonyManager.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED); |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 233 | mBroadcastDispatcher.registerReceiver(mBroadcastReceiver, filter); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 234 | |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 235 | mHasTelephony = connectivityManager.isNetworkSupported(ConnectivityManager.TYPE_MOBILE); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 236 | |
| 237 | // get notified of phone state changes |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 238 | telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE); |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 239 | contentResolver.registerContentObserver( |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 240 | Settings.Global.getUriFor(Settings.Global.AIRPLANE_MODE_ON), true, |
| 241 | mAirplaneModeObserver); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 242 | mHasVibrator = vibrator != null && vibrator.hasVibrator(); |
| 243 | |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 244 | mShowSilentToggle = SHOW_SILENT_TOGGLE && !resources.getBoolean( |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 245 | R.bool.config_useFixedVolume); |
| 246 | |
| 247 | mEmergencyAffordanceManager = new EmergencyAffordanceManager(context); |
Alison Cichowlas | a2cd19e | 2017-12-06 10:51:21 -0500 | [diff] [blame] | 248 | mScreenshotHelper = new ScreenshotHelper(context); |
Beth Thibodeau | 5898ac4 | 2018-10-26 13:00:09 -0400 | [diff] [blame] | 249 | mScreenRecordHelper = new ScreenRecordHelper(context); |
Lucas Dupin | e5b7dc7 | 2018-10-02 15:18:05 -0700 | [diff] [blame] | 250 | |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 251 | configurationController.addCallback(this); |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 252 | |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 253 | mActivityStarter = activityStarter; |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 254 | keyguardStateController.addCallback(new KeyguardStateController.Callback() { |
| 255 | @Override |
| 256 | public void onUnlockedChanged() { |
| 257 | if (mDialog != null && mDialog.mPanelController != null) { |
| 258 | boolean locked = !keyguardStateController.canDismissLockScreen(); |
| 259 | mDialog.mPanelController.onDeviceLockStateChanged(locked); |
| 260 | } |
| 261 | } |
| 262 | }); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | /** |
| 266 | * Show the global actions dialog (creating if necessary) |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 267 | * |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 268 | * @param keyguardShowing True if keyguard is showing |
| 269 | */ |
Steve Elliott | a3f520792 | 2019-03-18 13:37:22 -0400 | [diff] [blame] | 270 | public void showDialog(boolean keyguardShowing, boolean isDeviceProvisioned, |
| 271 | GlobalActionsPanelPlugin panelPlugin) { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 272 | mKeyguardShowing = keyguardShowing; |
| 273 | mDeviceProvisioned = isDeviceProvisioned; |
Steve Elliott | a3f520792 | 2019-03-18 13:37:22 -0400 | [diff] [blame] | 274 | mPanelPlugin = panelPlugin; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 275 | if (mDialog != null) { |
| 276 | mDialog.dismiss(); |
| 277 | mDialog = null; |
| 278 | // Show delayed, so that the dismiss of the previous dialog completes |
| 279 | mHandler.sendEmptyMessage(MESSAGE_SHOW); |
| 280 | } else { |
| 281 | handleShow(); |
| 282 | } |
| 283 | } |
| 284 | |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 285 | /** |
| 286 | * Dismiss the global actions dialog, if it's currently shown |
| 287 | */ |
| 288 | public void dismissDialog() { |
| 289 | mHandler.removeMessages(MESSAGE_DISMISS); |
| 290 | mHandler.sendEmptyMessage(MESSAGE_DISMISS); |
| 291 | } |
| 292 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 293 | private void awakenIfNecessary() { |
| 294 | if (mDreamManager != null) { |
| 295 | try { |
| 296 | if (mDreamManager.isDreaming()) { |
| 297 | mDreamManager.awaken(); |
| 298 | } |
| 299 | } catch (RemoteException e) { |
| 300 | // we tried |
| 301 | } |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | private void handleShow() { |
| 306 | awakenIfNecessary(); |
| 307 | mDialog = createDialog(); |
| 308 | prepareDialog(); |
| 309 | |
| 310 | // If we only have 1 item and it's a simple press action, just do this action. |
| 311 | if (mAdapter.getCount() == 1 |
| 312 | && mAdapter.getItem(0) instanceof SinglePressAction |
| 313 | && !(mAdapter.getItem(0) instanceof LongPressAction)) { |
| 314 | ((SinglePressAction) mAdapter.getItem(0)).onPress(); |
| 315 | } else { |
| 316 | WindowManager.LayoutParams attrs = mDialog.getWindow().getAttributes(); |
| 317 | attrs.setTitle("ActionsDialog"); |
Adrian Roos | 2f05bb3 | 2018-02-19 16:42:27 +0100 | [diff] [blame] | 318 | attrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 319 | mDialog.getWindow().setAttributes(attrs); |
| 320 | mDialog.show(); |
| 321 | mWindowManagerFuncs.onGlobalActionsShown(); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 322 | } |
| 323 | } |
| 324 | |
| 325 | /** |
| 326 | * Create the global actions dialog. |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 327 | * |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 328 | * @return A new dialog. |
| 329 | */ |
| 330 | private ActionsDialog createDialog() { |
| 331 | // Simple toggle style if there's no vibrator, otherwise use a tri-state |
| 332 | if (!mHasVibrator) { |
| 333 | mSilentModeAction = new SilentModeToggleAction(); |
| 334 | } else { |
Lucas Dupin | 40ec6b78 | 2018-06-05 19:07:16 -0700 | [diff] [blame] | 335 | mSilentModeAction = new SilentModeTriStateAction(mAudioManager, mHandler); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 336 | } |
| 337 | mAirplaneModeOn = new ToggleAction( |
| 338 | R.drawable.ic_lock_airplane_mode, |
| 339 | R.drawable.ic_lock_airplane_mode_off, |
| 340 | R.string.global_actions_toggle_airplane_mode, |
| 341 | R.string.global_actions_airplane_mode_on_status, |
| 342 | R.string.global_actions_airplane_mode_off_status) { |
| 343 | |
| 344 | void onToggle(boolean on) { |
Inseob Kim | 5e82f73 | 2019-11-08 15:08:38 +0900 | [diff] [blame] | 345 | if (mHasTelephony && TelephonyProperties.in_ecm_mode().orElse(false)) { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 346 | mIsWaitingForEcmExit = true; |
| 347 | // Launch ECM exit dialog |
| 348 | Intent ecmDialogIntent = |
Jayachandran C | 142eae0 | 2019-12-13 19:29:20 -0800 | [diff] [blame] | 349 | new Intent(TelephonyManager.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 350 | ecmDialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 351 | mContext.startActivity(ecmDialogIntent); |
| 352 | } else { |
| 353 | changeAirplaneModeSystemSetting(on); |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | @Override |
| 358 | protected void changeStateFromPress(boolean buttonOn) { |
| 359 | if (!mHasTelephony) return; |
| 360 | |
| 361 | // In ECM mode airplane state cannot be changed |
Inseob Kim | 5e82f73 | 2019-11-08 15:08:38 +0900 | [diff] [blame] | 362 | if (!TelephonyProperties.in_ecm_mode().orElse(false)) { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 363 | mState = buttonOn ? State.TurningOn : State.TurningOff; |
| 364 | mAirplaneState = mState; |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | public boolean showDuringKeyguard() { |
| 369 | return true; |
| 370 | } |
| 371 | |
| 372 | public boolean showBeforeProvisioning() { |
| 373 | return false; |
| 374 | } |
| 375 | }; |
| 376 | onAirplaneModeChanged(); |
| 377 | |
| 378 | mItems = new ArrayList<Action>(); |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 379 | String[] defaultActions = mResources.getStringArray(R.array.config_globalActionsList); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 380 | |
| 381 | ArraySet<String> addedKeys = new ArraySet<String>(); |
| 382 | for (int i = 0; i < defaultActions.length; i++) { |
| 383 | String actionKey = defaultActions[i]; |
| 384 | if (addedKeys.contains(actionKey)) { |
| 385 | // If we already have added this, don't add it again. |
| 386 | continue; |
| 387 | } |
| 388 | if (GLOBAL_ACTION_KEY_POWER.equals(actionKey)) { |
| 389 | mItems.add(new PowerAction()); |
| 390 | } else if (GLOBAL_ACTION_KEY_AIRPLANE.equals(actionKey)) { |
| 391 | mItems.add(mAirplaneModeOn); |
| 392 | } else if (GLOBAL_ACTION_KEY_BUGREPORT.equals(actionKey)) { |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 393 | if (Settings.Global.getInt(mContentResolver, |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 394 | Settings.Global.BUGREPORT_IN_POWER_MENU, 0) != 0 && isCurrentUserOwner()) { |
| 395 | mItems.add(new BugReportAction()); |
| 396 | } |
| 397 | } else if (GLOBAL_ACTION_KEY_SILENT.equals(actionKey)) { |
| 398 | if (mShowSilentToggle) { |
| 399 | mItems.add(mSilentModeAction); |
| 400 | } |
| 401 | } else if (GLOBAL_ACTION_KEY_USERS.equals(actionKey)) { |
| 402 | if (SystemProperties.getBoolean("fw.power_user_switcher", false)) { |
| 403 | addUsersToMenu(mItems); |
| 404 | } |
| 405 | } else if (GLOBAL_ACTION_KEY_SETTINGS.equals(actionKey)) { |
| 406 | mItems.add(getSettingsAction()); |
| 407 | } else if (GLOBAL_ACTION_KEY_LOCKDOWN.equals(actionKey)) { |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 408 | if (Settings.Secure.getIntForUser(mContentResolver, |
Chad Brubaker | 02cd6cf | 2018-05-01 14:59:33 -0700 | [diff] [blame] | 409 | Settings.Secure.LOCKDOWN_IN_POWER_MENU, 0, getCurrentUser().id) != 0 |
Chad Brubaker | f4075fe | 2018-01-03 13:23:22 -0800 | [diff] [blame] | 410 | && shouldDisplayLockdown()) { |
Chad Brubaker | 4f28f0d | 2017-09-07 14:28:13 -0700 | [diff] [blame] | 411 | mItems.add(getLockdownAction()); |
| 412 | } |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 413 | } else if (GLOBAL_ACTION_KEY_VOICEASSIST.equals(actionKey)) { |
| 414 | mItems.add(getVoiceAssistAction()); |
| 415 | } else if (GLOBAL_ACTION_KEY_ASSIST.equals(actionKey)) { |
| 416 | mItems.add(getAssistAction()); |
| 417 | } else if (GLOBAL_ACTION_KEY_RESTART.equals(actionKey)) { |
| 418 | mItems.add(new RestartAction()); |
Alison Cichowlas | a2cd19e | 2017-12-06 10:51:21 -0500 | [diff] [blame] | 419 | } else if (GLOBAL_ACTION_KEY_SCREENSHOT.equals(actionKey)) { |
| 420 | mItems.add(new ScreenshotAction()); |
Alex Chau | 0445885 | 2017-11-27 18:21:23 +0000 | [diff] [blame] | 421 | } else if (GLOBAL_ACTION_KEY_LOGOUT.equals(actionKey)) { |
Alex Chau | d795827 | 2017-12-08 11:30:52 +0000 | [diff] [blame] | 422 | if (mDevicePolicyManager.isLogoutEnabled() |
Alex Chau | 0445885 | 2017-11-27 18:21:23 +0000 | [diff] [blame] | 423 | && getCurrentUser().id != UserHandle.USER_SYSTEM) { |
| 424 | mItems.add(new LogoutAction()); |
Alex Chau | 0445885 | 2017-11-27 18:21:23 +0000 | [diff] [blame] | 425 | } |
Wesley.CW Wang | a9de792 | 2018-07-06 15:26:21 +0800 | [diff] [blame] | 426 | } else if (GLOBAL_ACTION_KEY_EMERGENCY.equals(actionKey)) { |
Aaron Heuckroth | c834340 | 2019-03-13 16:27:15 -0400 | [diff] [blame] | 427 | if (!mEmergencyAffordanceManager.needsEmergencyAffordance()) { |
Wesley.CW Wang | a9de792 | 2018-07-06 15:26:21 +0800 | [diff] [blame] | 428 | mItems.add(new EmergencyDialerAction()); |
| 429 | } |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 430 | } else { |
| 431 | Log.e(TAG, "Invalid global action key " + actionKey); |
| 432 | } |
| 433 | // Add here so we don't add more than one. |
| 434 | addedKeys.add(actionKey); |
| 435 | } |
| 436 | |
| 437 | if (mEmergencyAffordanceManager.needsEmergencyAffordance()) { |
Aaron Heuckroth | c834340 | 2019-03-13 16:27:15 -0400 | [diff] [blame] | 438 | mItems.add(new EmergencyAffordanceAction()); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | mAdapter = new MyAdapter(); |
| 442 | |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 443 | GlobalActionsPanelPlugin.PanelViewController panelViewController = |
Steve Elliott | a3f520792 | 2019-03-18 13:37:22 -0400 | [diff] [blame] | 444 | mPanelPlugin != null |
| 445 | ? mPanelPlugin.onPanelShown( |
Steve Elliott | 4c86885 | 2019-03-14 16:25:41 -0400 | [diff] [blame] | 446 | new GlobalActionsPanelPlugin.Callbacks() { |
| 447 | @Override |
| 448 | public void dismissGlobalActionsMenu() { |
Steve Elliott | c3147e2 | 2019-11-20 19:34:57 -0500 | [diff] [blame] | 449 | dismissDialog(); |
Steve Elliott | 4c86885 | 2019-03-14 16:25:41 -0400 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | @Override |
| 453 | public void startPendingIntentDismissingKeyguard( |
| 454 | PendingIntent intent) { |
| 455 | mActivityStarter |
| 456 | .startPendingIntentDismissingKeyguard(intent); |
| 457 | } |
Steve Elliott | e2a2e9b | 2019-04-30 21:31:03 -0400 | [diff] [blame] | 458 | }, |
| 459 | mKeyguardManager.isDeviceLocked()) |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 460 | : null; |
Steve Elliott | 02bbaaa | 2019-05-01 16:55:33 -0400 | [diff] [blame] | 461 | |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame^] | 462 | boolean showControls = !mKeyguardManager.isDeviceLocked() && isControlsEnabled(mContext); |
| 463 | |
Lucas Dupin | 991415e | 2019-11-25 17:48:58 -0800 | [diff] [blame] | 464 | ActionsDialog dialog = new ActionsDialog(mContext, mAdapter, panelViewController, |
| 465 | mBlurUtils, mSysuiColorExtractor, mStatusBarService, |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame^] | 466 | mNotificationShadeWindowController, |
| 467 | showControls ? mControlsUiController : null); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 468 | dialog.setCanceledOnTouchOutside(false); // Handled by the custom class. |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 469 | dialog.setKeyguardShowing(mKeyguardShowing); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 470 | |
| 471 | dialog.setOnDismissListener(this); |
Shaotang Li | 786da90 | 2018-08-02 11:18:00 +0800 | [diff] [blame] | 472 | dialog.setOnShowListener(this); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 473 | |
| 474 | return dialog; |
| 475 | } |
| 476 | |
Chad Brubaker | f4075fe | 2018-01-03 13:23:22 -0800 | [diff] [blame] | 477 | private boolean shouldDisplayLockdown() { |
| 478 | int userId = getCurrentUser().id; |
| 479 | // Lockdown is meaningless without a place to go. |
| 480 | if (!mKeyguardManager.isDeviceSecure(userId)) { |
| 481 | return false; |
| 482 | } |
| 483 | |
| 484 | // Only show the lockdown button if the device isn't locked down (for whatever reason). |
| 485 | int state = mLockPatternUtils.getStrongAuthForUser(userId); |
| 486 | return (state == STRONG_AUTH_NOT_REQUIRED |
| 487 | || state == SOME_AUTH_REQUIRED_AFTER_USER_REQUEST); |
| 488 | } |
| 489 | |
Lucas Dupin | e5b7dc7 | 2018-10-02 15:18:05 -0700 | [diff] [blame] | 490 | @Override |
| 491 | public void onUiModeChanged() { |
| 492 | mContext.getTheme().applyStyle(mContext.getThemeResId(), true); |
Lucas Dupin | a4e12ba | 2019-04-18 11:56:28 -0700 | [diff] [blame] | 493 | if (mDialog != null && mDialog.isShowing()) { |
Aaron Heuckroth | 4ef3a54 | 2019-04-01 14:17:23 -0400 | [diff] [blame] | 494 | mDialog.refreshDialog(); |
| 495 | } |
Lucas Dupin | e5b7dc7 | 2018-10-02 15:18:05 -0700 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | public void destroy() { |
| 499 | Dependency.get(ConfigurationController.class).removeCallback(this); |
| 500 | } |
| 501 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 502 | private final class PowerAction extends SinglePressAction implements LongPressAction { |
| 503 | private PowerAction() { |
| 504 | super(R.drawable.ic_lock_power_off, |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 505 | R.string.global_action_power_off); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | @Override |
| 509 | public boolean onLongPress() { |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 510 | if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 511 | mWindowManagerFuncs.reboot(true); |
| 512 | return true; |
| 513 | } |
| 514 | return false; |
| 515 | } |
| 516 | |
| 517 | @Override |
| 518 | public boolean showDuringKeyguard() { |
| 519 | return true; |
| 520 | } |
| 521 | |
| 522 | @Override |
| 523 | public boolean showBeforeProvisioning() { |
| 524 | return true; |
| 525 | } |
| 526 | |
| 527 | @Override |
| 528 | public void onPress() { |
| 529 | // shutdown by making sure radio and power are handled accordingly. |
| 530 | mWindowManagerFuncs.shutdown(); |
| 531 | } |
| 532 | } |
| 533 | |
Aaron Heuckroth | c834340 | 2019-03-13 16:27:15 -0400 | [diff] [blame] | 534 | private abstract class EmergencyAction extends SinglePressAction { |
| 535 | EmergencyAction(int iconResId, int messageResId) { |
| 536 | super(iconResId, messageResId); |
| 537 | } |
| 538 | |
| 539 | @Override |
| 540 | public boolean shouldBeSeparated() { |
Matt Pietal | fd3b6cb | 2020-01-08 09:43:54 -0500 | [diff] [blame] | 541 | return !isControlsEnabled(mContext); |
Aaron Heuckroth | c834340 | 2019-03-13 16:27:15 -0400 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | @Override |
| 545 | public View create( |
| 546 | Context context, View convertView, ViewGroup parent, LayoutInflater inflater) { |
| 547 | View v = super.create(context, convertView, parent, inflater); |
| 548 | int textColor; |
| 549 | if (shouldBeSeparated()) { |
| 550 | textColor = v.getResources().getColor( |
| 551 | com.android.systemui.R.color.global_actions_alert_text); |
| 552 | } else { |
| 553 | textColor = v.getResources().getColor( |
| 554 | com.android.systemui.R.color.global_actions_text); |
| 555 | } |
| 556 | TextView messageView = v.findViewById(R.id.message); |
| 557 | messageView.setTextColor(textColor); |
Aaron Heuckroth | 3f2d8b5 | 2019-04-05 13:27:51 -0400 | [diff] [blame] | 558 | messageView.setSelected(true); // necessary for marquee to work |
Aaron Heuckroth | c834340 | 2019-03-13 16:27:15 -0400 | [diff] [blame] | 559 | ImageView icon = (ImageView) v.findViewById(R.id.icon); |
| 560 | icon.getDrawable().setTint(textColor); |
| 561 | return v; |
| 562 | } |
| 563 | |
| 564 | @Override |
| 565 | public boolean showDuringKeyguard() { |
| 566 | return true; |
| 567 | } |
| 568 | |
| 569 | @Override |
| 570 | public boolean showBeforeProvisioning() { |
| 571 | return true; |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | private class EmergencyAffordanceAction extends EmergencyAction { |
| 576 | EmergencyAffordanceAction() { |
| 577 | super(R.drawable.emergency_icon, |
| 578 | R.string.global_action_emergency); |
| 579 | } |
| 580 | |
| 581 | @Override |
| 582 | public void onPress() { |
| 583 | mEmergencyAffordanceManager.performEmergencyCall(); |
| 584 | } |
| 585 | } |
| 586 | |
| 587 | private class EmergencyDialerAction extends EmergencyAction { |
Wesley.CW Wang | a9de792 | 2018-07-06 15:26:21 +0800 | [diff] [blame] | 588 | private EmergencyDialerAction() { |
Aran Ink | 5019526 | 2019-05-30 10:55:37 -0400 | [diff] [blame] | 589 | super(com.android.systemui.R.drawable.ic_emergency_star, |
Wesley.CW Wang | 3004fcb | 2018-06-15 16:24:57 +0800 | [diff] [blame] | 590 | R.string.global_action_emergency); |
Wesley.CW Wang | 8d07276 | 2018-05-28 16:39:27 +0800 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | @Override |
| 594 | public void onPress() { |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 595 | mMetricsLogger.action(MetricsEvent.ACTION_EMERGENCY_DIALER_FROM_POWER_MENU); |
| 596 | Intent intent = mTelecomManager.createLaunchEmergencyDialerIntent(null /* number */); |
Leo Hsu | e4cc312 | 2019-03-06 15:25:28 +0800 | [diff] [blame] | 597 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 598 | | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS |
| 599 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
Shaotang Li | 5c42263 | 2018-07-04 14:18:40 +0800 | [diff] [blame] | 600 | intent.putExtra(EmergencyDialerConstants.EXTRA_ENTRY_TYPE, |
| 601 | EmergencyDialerConstants.ENTRY_TYPE_POWER_MENU); |
Wesley.CW Wang | 8d07276 | 2018-05-28 16:39:27 +0800 | [diff] [blame] | 602 | mContext.startActivityAsUser(intent, UserHandle.CURRENT); |
| 603 | } |
Wesley.CW Wang | 8d07276 | 2018-05-28 16:39:27 +0800 | [diff] [blame] | 604 | } |
| 605 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 606 | private final class RestartAction extends SinglePressAction implements LongPressAction { |
| 607 | private RestartAction() { |
| 608 | super(R.drawable.ic_restart, R.string.global_action_restart); |
| 609 | } |
| 610 | |
| 611 | @Override |
| 612 | public boolean onLongPress() { |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 613 | if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 614 | mWindowManagerFuncs.reboot(true); |
| 615 | return true; |
| 616 | } |
| 617 | return false; |
| 618 | } |
| 619 | |
| 620 | @Override |
| 621 | public boolean showDuringKeyguard() { |
| 622 | return true; |
| 623 | } |
| 624 | |
| 625 | @Override |
| 626 | public boolean showBeforeProvisioning() { |
| 627 | return true; |
| 628 | } |
| 629 | |
| 630 | @Override |
| 631 | public void onPress() { |
| 632 | mWindowManagerFuncs.reboot(false); |
| 633 | } |
| 634 | } |
| 635 | |
Beth Thibodeau | 5898ac4 | 2018-10-26 13:00:09 -0400 | [diff] [blame] | 636 | private class ScreenshotAction extends SinglePressAction implements LongPressAction { |
Alison Cichowlas | a2cd19e | 2017-12-06 10:51:21 -0500 | [diff] [blame] | 637 | public ScreenshotAction() { |
| 638 | super(R.drawable.ic_screenshot, R.string.global_action_screenshot); |
| 639 | } |
| 640 | |
| 641 | @Override |
| 642 | public void onPress() { |
| 643 | // Add a little delay before executing, to give the |
| 644 | // dialog a chance to go away before it takes a |
| 645 | // screenshot. |
| 646 | // TODO: instead, omit global action dialog layer |
| 647 | mHandler.postDelayed(new Runnable() { |
| 648 | @Override |
| 649 | public void run() { |
James O'Leary | fa5bb7a | 2019-09-05 13:43:29 -0400 | [diff] [blame] | 650 | mScreenshotHelper.takeScreenshot(1, true, true, mHandler, null); |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 651 | mMetricsLogger.action(MetricsEvent.ACTION_SCREENSHOT_POWER_MENU); |
Alison Cichowlas | a2cd19e | 2017-12-06 10:51:21 -0500 | [diff] [blame] | 652 | } |
| 653 | }, 500); |
| 654 | } |
| 655 | |
| 656 | @Override |
| 657 | public boolean showDuringKeyguard() { |
| 658 | return true; |
| 659 | } |
| 660 | |
| 661 | @Override |
| 662 | public boolean showBeforeProvisioning() { |
| 663 | return false; |
| 664 | } |
Beth Thibodeau | 5898ac4 | 2018-10-26 13:00:09 -0400 | [diff] [blame] | 665 | |
| 666 | @Override |
| 667 | public boolean onLongPress() { |
| 668 | if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SCREENRECORD_LONG_PRESS)) { |
| 669 | mScreenRecordHelper.launchRecordPrompt(); |
| 670 | } else { |
| 671 | onPress(); |
| 672 | } |
| 673 | return true; |
| 674 | } |
Alison Cichowlas | a2cd19e | 2017-12-06 10:51:21 -0500 | [diff] [blame] | 675 | } |
| 676 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 677 | private class BugReportAction extends SinglePressAction implements LongPressAction { |
| 678 | |
| 679 | public BugReportAction() { |
| 680 | super(R.drawable.ic_lock_bugreport, R.string.bugreport_title); |
| 681 | } |
| 682 | |
| 683 | @Override |
| 684 | public void onPress() { |
| 685 | // don't actually trigger the bugreport if we are running stability |
| 686 | // tests via monkey |
| 687 | if (ActivityManager.isUserAMonkey()) { |
| 688 | return; |
| 689 | } |
| 690 | // Add a little delay before executing, to give the |
| 691 | // dialog a chance to go away before it takes a |
| 692 | // screenshot. |
| 693 | mHandler.postDelayed(new Runnable() { |
| 694 | @Override |
| 695 | public void run() { |
| 696 | try { |
| 697 | // Take an "interactive" bugreport. |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 698 | mMetricsLogger.action( |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 699 | MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_INTERACTIVE); |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 700 | if (!mIActivityManager.launchBugReportHandlerApp()) { |
Paul Chang | c40f578 | 2019-11-04 18:55:31 +0800 | [diff] [blame] | 701 | Log.w(TAG, "Bugreport handler could not be launched"); |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 702 | mIActivityManager.requestInteractiveBugReport(); |
Paul Chang | c40f578 | 2019-11-04 18:55:31 +0800 | [diff] [blame] | 703 | } |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 704 | } catch (RemoteException e) { |
| 705 | } |
| 706 | } |
| 707 | }, 500); |
| 708 | } |
| 709 | |
| 710 | @Override |
| 711 | public boolean onLongPress() { |
| 712 | // don't actually trigger the bugreport if we are running stability |
| 713 | // tests via monkey |
| 714 | if (ActivityManager.isUserAMonkey()) { |
| 715 | return false; |
| 716 | } |
| 717 | try { |
| 718 | // Take a "full" bugreport. |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 719 | mMetricsLogger.action(MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_FULL); |
| 720 | mIActivityManager.requestFullBugReport(); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 721 | } catch (RemoteException e) { |
| 722 | } |
| 723 | return false; |
| 724 | } |
| 725 | |
| 726 | public boolean showDuringKeyguard() { |
| 727 | return true; |
| 728 | } |
| 729 | |
| 730 | @Override |
| 731 | public boolean showBeforeProvisioning() { |
| 732 | return false; |
| 733 | } |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 734 | } |
| 735 | |
Alex Chau | 0445885 | 2017-11-27 18:21:23 +0000 | [diff] [blame] | 736 | private final class LogoutAction extends SinglePressAction { |
| 737 | private LogoutAction() { |
| 738 | super(R.drawable.ic_logout, R.string.global_action_logout); |
| 739 | } |
| 740 | |
| 741 | @Override |
| 742 | public boolean showDuringKeyguard() { |
| 743 | return true; |
| 744 | } |
| 745 | |
| 746 | @Override |
| 747 | public boolean showBeforeProvisioning() { |
| 748 | return false; |
| 749 | } |
| 750 | |
| 751 | @Override |
| 752 | public void onPress() { |
| 753 | // Add a little delay before executing, to give the dialog a chance to go away before |
| 754 | // switching user |
| 755 | mHandler.postDelayed(() -> { |
| 756 | try { |
Alex Chau | edb6a01 | 2018-01-26 12:52:43 +0000 | [diff] [blame] | 757 | int currentUserId = getCurrentUser().id; |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 758 | mIActivityManager.switchUser(UserHandle.USER_SYSTEM); |
| 759 | mIActivityManager.stopUser(currentUserId, true /*force*/, null); |
Alex Chau | 0445885 | 2017-11-27 18:21:23 +0000 | [diff] [blame] | 760 | } catch (RemoteException re) { |
| 761 | Log.e(TAG, "Couldn't logout user " + re); |
| 762 | } |
| 763 | }, 500); |
| 764 | } |
| 765 | } |
| 766 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 767 | private Action getSettingsAction() { |
| 768 | return new SinglePressAction(R.drawable.ic_settings, |
| 769 | R.string.global_action_settings) { |
| 770 | |
| 771 | @Override |
| 772 | public void onPress() { |
| 773 | Intent intent = new Intent(Settings.ACTION_SETTINGS); |
| 774 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 775 | mContext.startActivity(intent); |
| 776 | } |
| 777 | |
| 778 | @Override |
| 779 | public boolean showDuringKeyguard() { |
| 780 | return true; |
| 781 | } |
| 782 | |
| 783 | @Override |
| 784 | public boolean showBeforeProvisioning() { |
| 785 | return true; |
| 786 | } |
| 787 | }; |
| 788 | } |
| 789 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 790 | private Action getAssistAction() { |
| 791 | return new SinglePressAction(R.drawable.ic_action_assist_focused, |
| 792 | R.string.global_action_assist) { |
| 793 | @Override |
| 794 | public void onPress() { |
| 795 | Intent intent = new Intent(Intent.ACTION_ASSIST); |
| 796 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 797 | mContext.startActivity(intent); |
| 798 | } |
| 799 | |
| 800 | @Override |
| 801 | public boolean showDuringKeyguard() { |
| 802 | return true; |
| 803 | } |
| 804 | |
| 805 | @Override |
| 806 | public boolean showBeforeProvisioning() { |
| 807 | return true; |
| 808 | } |
| 809 | }; |
| 810 | } |
| 811 | |
| 812 | private Action getVoiceAssistAction() { |
| 813 | return new SinglePressAction(R.drawable.ic_voice_search, |
| 814 | R.string.global_action_voice_assist) { |
| 815 | @Override |
| 816 | public void onPress() { |
| 817 | Intent intent = new Intent(Intent.ACTION_VOICE_ASSIST); |
| 818 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 819 | mContext.startActivity(intent); |
| 820 | } |
| 821 | |
| 822 | @Override |
| 823 | public boolean showDuringKeyguard() { |
| 824 | return true; |
| 825 | } |
| 826 | |
| 827 | @Override |
| 828 | public boolean showBeforeProvisioning() { |
| 829 | return true; |
| 830 | } |
| 831 | }; |
| 832 | } |
| 833 | |
| 834 | private Action getLockdownAction() { |
Alison Cichowlas | 2112543 | 2018-05-16 15:40:45 -0400 | [diff] [blame] | 835 | return new SinglePressAction(R.drawable.ic_lock_lockdown, |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 836 | R.string.global_action_lockdown) { |
| 837 | |
| 838 | @Override |
| 839 | public void onPress() { |
Chad Brubaker | 4f28f0d | 2017-09-07 14:28:13 -0700 | [diff] [blame] | 840 | new LockPatternUtils(mContext) |
| 841 | .requireStrongAuth(STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN, |
| 842 | UserHandle.USER_ALL); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 843 | try { |
| 844 | WindowManagerGlobal.getWindowManagerService().lockNow(null); |
Pavel Grafov | 059021b | 2018-05-02 13:44:46 +0100 | [diff] [blame] | 845 | // Lock profiles (if any) on the background thread. |
| 846 | final Handler bgHandler = new Handler(Dependency.get(Dependency.BG_LOOPER)); |
| 847 | bgHandler.post(() -> lockProfiles()); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 848 | } catch (RemoteException e) { |
| 849 | Log.e(TAG, "Error while trying to lock device.", e); |
| 850 | } |
| 851 | } |
| 852 | |
| 853 | @Override |
| 854 | public boolean showDuringKeyguard() { |
| 855 | return true; |
| 856 | } |
| 857 | |
| 858 | @Override |
| 859 | public boolean showBeforeProvisioning() { |
| 860 | return false; |
| 861 | } |
| 862 | }; |
| 863 | } |
| 864 | |
Pavel Grafov | 059021b | 2018-05-02 13:44:46 +0100 | [diff] [blame] | 865 | private void lockProfiles() { |
Pavel Grafov | 059021b | 2018-05-02 13:44:46 +0100 | [diff] [blame] | 866 | final int currentUserId = getCurrentUser().id; |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 867 | final int[] profileIds = mUserManager.getEnabledProfileIds(currentUserId); |
Pavel Grafov | 059021b | 2018-05-02 13:44:46 +0100 | [diff] [blame] | 868 | for (final int id : profileIds) { |
| 869 | if (id != currentUserId) { |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 870 | mTrustManager.setDeviceLockedForUser(id, true); |
Pavel Grafov | 059021b | 2018-05-02 13:44:46 +0100 | [diff] [blame] | 871 | } |
| 872 | } |
| 873 | } |
| 874 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 875 | private UserInfo getCurrentUser() { |
| 876 | try { |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 877 | return mIActivityManager.getCurrentUser(); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 878 | } catch (RemoteException re) { |
| 879 | return null; |
| 880 | } |
| 881 | } |
| 882 | |
| 883 | private boolean isCurrentUserOwner() { |
| 884 | UserInfo currentUser = getCurrentUser(); |
| 885 | return currentUser == null || currentUser.isPrimary(); |
| 886 | } |
| 887 | |
| 888 | private void addUsersToMenu(ArrayList<Action> items) { |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 889 | if (mUserManager.isUserSwitcherEnabled()) { |
| 890 | List<UserInfo> users = mUserManager.getUsers(); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 891 | UserInfo currentUser = getCurrentUser(); |
| 892 | for (final UserInfo user : users) { |
| 893 | if (user.supportsSwitchToByUser()) { |
| 894 | boolean isCurrentUser = currentUser == null |
| 895 | ? user.id == 0 : (currentUser.id == user.id); |
| 896 | Drawable icon = user.iconPath != null ? Drawable.createFromPath(user.iconPath) |
| 897 | : null; |
| 898 | SinglePressAction switchToUser = new SinglePressAction( |
| 899 | R.drawable.ic_menu_cc, icon, |
| 900 | (user.name != null ? user.name : "Primary") |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 901 | + (isCurrentUser ? " \u2714" : "")) { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 902 | public void onPress() { |
| 903 | try { |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 904 | mIActivityManager.switchUser(user.id); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 905 | } catch (RemoteException re) { |
| 906 | Log.e(TAG, "Couldn't switch user " + re); |
| 907 | } |
| 908 | } |
| 909 | |
| 910 | public boolean showDuringKeyguard() { |
| 911 | return true; |
| 912 | } |
| 913 | |
| 914 | public boolean showBeforeProvisioning() { |
| 915 | return false; |
| 916 | } |
| 917 | }; |
| 918 | items.add(switchToUser); |
| 919 | } |
| 920 | } |
| 921 | } |
| 922 | } |
| 923 | |
| 924 | private void prepareDialog() { |
| 925 | refreshSilentMode(); |
| 926 | mAirplaneModeOn.updateState(mAirplaneState); |
| 927 | mAdapter.notifyDataSetChanged(); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 928 | if (mShowSilentToggle) { |
| 929 | IntentFilter filter = new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION); |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 930 | mBroadcastDispatcher.registerReceiver(mRingerModeReceiver, filter); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 931 | } |
| 932 | } |
| 933 | |
| 934 | private void refreshSilentMode() { |
| 935 | if (!mHasVibrator) { |
| 936 | final boolean silentModeOn = |
| 937 | mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL; |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 938 | ((ToggleAction) mSilentModeAction).updateState( |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 939 | silentModeOn ? ToggleAction.State.On : ToggleAction.State.Off); |
| 940 | } |
| 941 | } |
| 942 | |
| 943 | /** {@inheritDoc} */ |
| 944 | public void onDismiss(DialogInterface dialog) { |
Steve Elliott | c3147e2 | 2019-11-20 19:34:57 -0500 | [diff] [blame] | 945 | if (mDialog == dialog) { |
| 946 | mDialog = null; |
| 947 | } |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 948 | mWindowManagerFuncs.onGlobalActionsHidden(); |
| 949 | if (mShowSilentToggle) { |
| 950 | try { |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 951 | mBroadcastDispatcher.unregisterReceiver(mRingerModeReceiver); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 952 | } catch (IllegalArgumentException ie) { |
| 953 | // ignore this |
| 954 | Log.w(TAG, ie); |
| 955 | } |
| 956 | } |
| 957 | } |
| 958 | |
| 959 | /** {@inheritDoc} */ |
Shaotang Li | 786da90 | 2018-08-02 11:18:00 +0800 | [diff] [blame] | 960 | public void onShow(DialogInterface dialog) { |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 961 | mMetricsLogger.visible(MetricsEvent.POWER_MENU); |
Shaotang Li | 786da90 | 2018-08-02 11:18:00 +0800 | [diff] [blame] | 962 | } |
| 963 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 964 | /** |
| 965 | * The adapter used for the list within the global actions dialog, taking |
| 966 | * into account whether the keyguard is showing via |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 967 | * {@link com.android.systemui.globalactions.GlobalActionsDialog#mKeyguardShowing} and whether |
| 968 | * the device is provisioned |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 969 | * via {@link com.android.systemui.globalactions.GlobalActionsDialog#mDeviceProvisioned}. |
| 970 | */ |
Aaron Heuckroth | 57d60d2 | 2019-03-05 14:00:12 -0500 | [diff] [blame] | 971 | public class MyAdapter extends MultiListAdapter { |
Aaron Heuckroth | 5e28f8c8 | 2019-04-24 13:26:12 -0400 | [diff] [blame] | 972 | private int countItems(boolean separated) { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 973 | int count = 0; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 974 | for (int i = 0; i < mItems.size(); i++) { |
| 975 | final Action action = mItems.get(i); |
| 976 | |
Aaron Heuckroth | 5e28f8c8 | 2019-04-24 13:26:12 -0400 | [diff] [blame] | 977 | if (shouldBeShown(action) && action.shouldBeSeparated() == separated) { |
| 978 | count++; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 979 | } |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 980 | } |
| 981 | return count; |
| 982 | } |
| 983 | |
Aaron Heuckroth | 5e28f8c8 | 2019-04-24 13:26:12 -0400 | [diff] [blame] | 984 | private boolean shouldBeShown(Action action) { |
| 985 | if (mKeyguardShowing && !action.showDuringKeyguard()) { |
| 986 | return false; |
| 987 | } |
| 988 | if (!mDeviceProvisioned && !action.showBeforeProvisioning()) { |
| 989 | return false; |
| 990 | } |
| 991 | return true; |
| 992 | } |
| 993 | |
| 994 | @Override |
| 995 | public int countSeparatedItems() { |
| 996 | return countItems(true); |
| 997 | } |
| 998 | |
| 999 | @Override |
| 1000 | public int countListItems() { |
| 1001 | return countItems(false); |
| 1002 | } |
| 1003 | |
| 1004 | @Override |
| 1005 | public int getCount() { |
| 1006 | return countSeparatedItems() + countListItems(); |
| 1007 | } |
| 1008 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1009 | @Override |
| 1010 | public boolean isEnabled(int position) { |
| 1011 | return getItem(position).isEnabled(); |
| 1012 | } |
| 1013 | |
Aaron Heuckroth | 57d60d2 | 2019-03-05 14:00:12 -0500 | [diff] [blame] | 1014 | @Override |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1015 | public boolean areAllItemsEnabled() { |
| 1016 | return false; |
| 1017 | } |
| 1018 | |
Aaron Heuckroth | 57d60d2 | 2019-03-05 14:00:12 -0500 | [diff] [blame] | 1019 | @Override |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1020 | public Action getItem(int position) { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1021 | int filteredPos = 0; |
| 1022 | for (int i = 0; i < mItems.size(); i++) { |
| 1023 | final Action action = mItems.get(i); |
Aaron Heuckroth | 5e28f8c8 | 2019-04-24 13:26:12 -0400 | [diff] [blame] | 1024 | if (!shouldBeShown(action)) { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1025 | continue; |
| 1026 | } |
| 1027 | if (filteredPos == position) { |
| 1028 | return action; |
| 1029 | } |
| 1030 | filteredPos++; |
| 1031 | } |
| 1032 | |
| 1033 | throw new IllegalArgumentException("position " + position |
| 1034 | + " out of range of showable actions" |
| 1035 | + ", filtered count=" + getCount() |
| 1036 | + ", keyguardshowing=" + mKeyguardShowing |
| 1037 | + ", provisioned=" + mDeviceProvisioned); |
| 1038 | } |
| 1039 | |
| 1040 | |
| 1041 | public long getItemId(int position) { |
| 1042 | return position; |
| 1043 | } |
| 1044 | |
Aaron Heuckroth | 57d60d2 | 2019-03-05 14:00:12 -0500 | [diff] [blame] | 1045 | @Override |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1046 | public View getView(int position, View convertView, ViewGroup parent) { |
| 1047 | Action action = getItem(position); |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1048 | View view = action.create(mContext, convertView, parent, LayoutInflater.from(mContext)); |
Aaron Heuckroth | 5e28f8c8 | 2019-04-24 13:26:12 -0400 | [diff] [blame] | 1049 | view.setOnClickListener(v -> onClickItem(position)); |
| 1050 | view.setOnLongClickListener(v -> onLongClickItem(position)); |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1051 | return view; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1052 | } |
Aaron Heuckroth | 57d60d2 | 2019-03-05 14:00:12 -0500 | [diff] [blame] | 1053 | |
| 1054 | @Override |
| 1055 | public boolean onLongClickItem(int position) { |
| 1056 | final Action action = mAdapter.getItem(position); |
| 1057 | if (action instanceof LongPressAction) { |
Aran Ink | baa2586 | 2019-06-11 15:48:55 -0400 | [diff] [blame] | 1058 | if (mDialog != null) { |
| 1059 | mDialog.dismiss(); |
| 1060 | } else { |
| 1061 | Log.w(TAG, "Action long-clicked while mDialog is null."); |
| 1062 | } |
Aaron Heuckroth | 57d60d2 | 2019-03-05 14:00:12 -0500 | [diff] [blame] | 1063 | return ((LongPressAction) action).onLongPress(); |
| 1064 | } |
| 1065 | return false; |
| 1066 | } |
| 1067 | |
| 1068 | @Override |
| 1069 | public void onClickItem(int position) { |
| 1070 | Action item = mAdapter.getItem(position); |
| 1071 | if (!(item instanceof SilentModeTriStateAction)) { |
Aran Ink | baa2586 | 2019-06-11 15:48:55 -0400 | [diff] [blame] | 1072 | if (mDialog != null) { |
| 1073 | mDialog.dismiss(); |
| 1074 | } else { |
| 1075 | Log.w(TAG, "Action clicked while mDialog is null."); |
| 1076 | } |
| 1077 | item.onPress(); |
Aaron Heuckroth | 57d60d2 | 2019-03-05 14:00:12 -0500 | [diff] [blame] | 1078 | } |
Aaron Heuckroth | 57d60d2 | 2019-03-05 14:00:12 -0500 | [diff] [blame] | 1079 | } |
Aaron Heuckroth | 5e28f8c8 | 2019-04-24 13:26:12 -0400 | [diff] [blame] | 1080 | |
| 1081 | @Override |
| 1082 | public boolean shouldBeSeparated(int position) { |
| 1083 | return getItem(position).shouldBeSeparated(); |
| 1084 | } |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1085 | } |
| 1086 | |
| 1087 | // note: the scheme below made more sense when we were planning on having |
| 1088 | // 8 different things in the global actions dialog. seems overkill with |
| 1089 | // only 3 items now, but may as well keep this flexible approach so it will |
| 1090 | // be easy should someone decide at the last minute to include something |
| 1091 | // else, such as 'enable wifi', or 'enable bluetooth' |
| 1092 | |
| 1093 | /** |
| 1094 | * What each item in the global actions dialog must be able to support. |
| 1095 | */ |
Aaron Heuckroth | 57d60d2 | 2019-03-05 14:00:12 -0500 | [diff] [blame] | 1096 | public interface Action { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1097 | /** |
| 1098 | * @return Text that will be announced when dialog is created. null |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1099 | * for none. |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1100 | */ |
| 1101 | CharSequence getLabelForAccessibility(Context context); |
| 1102 | |
| 1103 | View create(Context context, View convertView, ViewGroup parent, LayoutInflater inflater); |
| 1104 | |
| 1105 | void onPress(); |
| 1106 | |
| 1107 | /** |
| 1108 | * @return whether this action should appear in the dialog when the keygaurd |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1109 | * is showing. |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1110 | */ |
| 1111 | boolean showDuringKeyguard(); |
| 1112 | |
| 1113 | /** |
| 1114 | * @return whether this action should appear in the dialog before the |
Aaron Heuckroth | 57d60d2 | 2019-03-05 14:00:12 -0500 | [diff] [blame] | 1115 | * device is provisioned.onlongpress |
| 1116 | * |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1117 | */ |
| 1118 | boolean showBeforeProvisioning(); |
| 1119 | |
| 1120 | boolean isEnabled(); |
Aaron Heuckroth | f708d47 | 2019-01-10 16:54:51 -0500 | [diff] [blame] | 1121 | |
| 1122 | default boolean shouldBeSeparated() { |
| 1123 | return false; |
| 1124 | } |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1125 | } |
| 1126 | |
| 1127 | /** |
| 1128 | * An action that also supports long press. |
| 1129 | */ |
| 1130 | private interface LongPressAction extends Action { |
| 1131 | boolean onLongPress(); |
| 1132 | } |
| 1133 | |
| 1134 | /** |
| 1135 | * A single press action maintains no state, just responds to a press |
| 1136 | * and takes an action. |
| 1137 | */ |
| 1138 | private static abstract class SinglePressAction implements Action { |
| 1139 | private final int mIconResId; |
| 1140 | private final Drawable mIcon; |
| 1141 | private final int mMessageResId; |
| 1142 | private final CharSequence mMessage; |
| 1143 | |
| 1144 | protected SinglePressAction(int iconResId, int messageResId) { |
| 1145 | mIconResId = iconResId; |
| 1146 | mMessageResId = messageResId; |
| 1147 | mMessage = null; |
| 1148 | mIcon = null; |
| 1149 | } |
| 1150 | |
| 1151 | protected SinglePressAction(int iconResId, Drawable icon, CharSequence message) { |
| 1152 | mIconResId = iconResId; |
| 1153 | mMessageResId = 0; |
| 1154 | mMessage = message; |
| 1155 | mIcon = icon; |
| 1156 | } |
| 1157 | |
| 1158 | public boolean isEnabled() { |
| 1159 | return true; |
| 1160 | } |
| 1161 | |
| 1162 | public String getStatus() { |
| 1163 | return null; |
| 1164 | } |
| 1165 | |
| 1166 | abstract public void onPress(); |
| 1167 | |
| 1168 | public CharSequence getLabelForAccessibility(Context context) { |
| 1169 | if (mMessage != null) { |
| 1170 | return mMessage; |
| 1171 | } else { |
| 1172 | return context.getString(mMessageResId); |
| 1173 | } |
| 1174 | } |
| 1175 | |
Aaron Heuckroth | 166392f | 2019-01-17 16:50:59 -0500 | [diff] [blame] | 1176 | protected int getActionLayoutId(Context context) { |
Matt Pietal | fd3b6cb | 2020-01-08 09:43:54 -0500 | [diff] [blame] | 1177 | if (isControlsEnabled(context)) { |
| 1178 | return com.android.systemui.R.layout.global_actions_grid_item_v2; |
| 1179 | } |
Aaron Heuckroth | c792661 | 2019-04-02 14:21:57 -0400 | [diff] [blame] | 1180 | return com.android.systemui.R.layout.global_actions_grid_item; |
Aaron Heuckroth | 166392f | 2019-01-17 16:50:59 -0500 | [diff] [blame] | 1181 | } |
| 1182 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1183 | public View create( |
| 1184 | Context context, View convertView, ViewGroup parent, LayoutInflater inflater) { |
Aaron Heuckroth | 166392f | 2019-01-17 16:50:59 -0500 | [diff] [blame] | 1185 | View v = inflater.inflate(getActionLayoutId(context), parent, |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1186 | false); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1187 | |
| 1188 | ImageView icon = (ImageView) v.findViewById(R.id.icon); |
| 1189 | TextView messageView = (TextView) v.findViewById(R.id.message); |
Aaron Heuckroth | 3f2d8b5 | 2019-04-05 13:27:51 -0400 | [diff] [blame] | 1190 | messageView.setSelected(true); // necessary for marquee to work |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1191 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1192 | if (mIcon != null) { |
| 1193 | icon.setImageDrawable(mIcon); |
| 1194 | icon.setScaleType(ScaleType.CENTER_CROP); |
| 1195 | } else if (mIconResId != 0) { |
| 1196 | icon.setImageDrawable(context.getDrawable(mIconResId)); |
| 1197 | } |
| 1198 | if (mMessage != null) { |
| 1199 | messageView.setText(mMessage); |
| 1200 | } else { |
| 1201 | messageView.setText(mMessageResId); |
| 1202 | } |
| 1203 | |
| 1204 | return v; |
| 1205 | } |
| 1206 | } |
| 1207 | |
| 1208 | /** |
| 1209 | * A toggle action knows whether it is on or off, and displays an icon |
| 1210 | * and status message accordingly. |
| 1211 | */ |
| 1212 | private static abstract class ToggleAction implements Action { |
| 1213 | |
| 1214 | enum State { |
| 1215 | Off(false), |
| 1216 | TurningOn(true), |
| 1217 | TurningOff(true), |
| 1218 | On(false); |
| 1219 | |
| 1220 | private final boolean inTransition; |
| 1221 | |
| 1222 | State(boolean intermediate) { |
| 1223 | inTransition = intermediate; |
| 1224 | } |
| 1225 | |
| 1226 | public boolean inTransition() { |
| 1227 | return inTransition; |
| 1228 | } |
| 1229 | } |
| 1230 | |
| 1231 | protected State mState = State.Off; |
| 1232 | |
| 1233 | // prefs |
| 1234 | protected int mEnabledIconResId; |
| 1235 | protected int mDisabledIconResid; |
| 1236 | protected int mMessageResId; |
| 1237 | protected int mEnabledStatusMessageResId; |
| 1238 | protected int mDisabledStatusMessageResId; |
| 1239 | |
| 1240 | /** |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1241 | * @param enabledIconResId The icon for when this action is on. |
| 1242 | * @param disabledIconResid The icon for when this action is off. |
| 1243 | * @param message The general information message, e.g 'Silent Mode' |
| 1244 | * @param enabledStatusMessageResId The on status message, e.g 'sound disabled' |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1245 | * @param disabledStatusMessageResId The off status message, e.g. 'sound enabled' |
| 1246 | */ |
| 1247 | public ToggleAction(int enabledIconResId, |
| 1248 | int disabledIconResid, |
| 1249 | int message, |
| 1250 | int enabledStatusMessageResId, |
| 1251 | int disabledStatusMessageResId) { |
| 1252 | mEnabledIconResId = enabledIconResId; |
| 1253 | mDisabledIconResid = disabledIconResid; |
| 1254 | mMessageResId = message; |
| 1255 | mEnabledStatusMessageResId = enabledStatusMessageResId; |
| 1256 | mDisabledStatusMessageResId = disabledStatusMessageResId; |
| 1257 | } |
| 1258 | |
| 1259 | /** |
| 1260 | * Override to make changes to resource IDs just before creating the |
| 1261 | * View. |
| 1262 | */ |
| 1263 | void willCreate() { |
| 1264 | |
| 1265 | } |
| 1266 | |
| 1267 | @Override |
| 1268 | public CharSequence getLabelForAccessibility(Context context) { |
| 1269 | return context.getString(mMessageResId); |
| 1270 | } |
| 1271 | |
| 1272 | public View create(Context context, View convertView, ViewGroup parent, |
| 1273 | LayoutInflater inflater) { |
| 1274 | willCreate(); |
| 1275 | |
Koji Fukui | 5c010ee | 2019-12-24 16:12:07 +0900 | [diff] [blame] | 1276 | View v = inflater.inflate(com.android.systemui.R |
| 1277 | .layout.global_actions_grid_item, parent, false); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1278 | |
| 1279 | ImageView icon = (ImageView) v.findViewById(R.id.icon); |
| 1280 | TextView messageView = (TextView) v.findViewById(R.id.message); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1281 | final boolean enabled = isEnabled(); |
Koji Fukui | 5c010ee | 2019-12-24 16:12:07 +0900 | [diff] [blame] | 1282 | boolean on = ((mState == State.On) || (mState == State.TurningOn)); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1283 | |
| 1284 | if (messageView != null) { |
Koji Fukui | 5c010ee | 2019-12-24 16:12:07 +0900 | [diff] [blame] | 1285 | messageView.setText(on ? mEnabledStatusMessageResId : mDisabledStatusMessageResId); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1286 | messageView.setEnabled(enabled); |
Aaron Heuckroth | 3f2d8b5 | 2019-04-05 13:27:51 -0400 | [diff] [blame] | 1287 | messageView.setSelected(true); // necessary for marquee to work |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1288 | } |
| 1289 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1290 | if (icon != null) { |
| 1291 | icon.setImageDrawable(context.getDrawable( |
| 1292 | (on ? mEnabledIconResId : mDisabledIconResid))); |
| 1293 | icon.setEnabled(enabled); |
| 1294 | } |
| 1295 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1296 | v.setEnabled(enabled); |
| 1297 | |
| 1298 | return v; |
| 1299 | } |
| 1300 | |
| 1301 | public final void onPress() { |
| 1302 | if (mState.inTransition()) { |
| 1303 | Log.w(TAG, "shouldn't be able to toggle when in transition"); |
| 1304 | return; |
| 1305 | } |
| 1306 | |
| 1307 | final boolean nowOn = !(mState == State.On); |
| 1308 | onToggle(nowOn); |
| 1309 | changeStateFromPress(nowOn); |
| 1310 | } |
| 1311 | |
| 1312 | public boolean isEnabled() { |
| 1313 | return !mState.inTransition(); |
| 1314 | } |
| 1315 | |
| 1316 | /** |
| 1317 | * Implementations may override this if their state can be in on of the intermediate |
| 1318 | * states until some notification is received (e.g airplane mode is 'turning off' until |
| 1319 | * we know the wireless connections are back online |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1320 | * |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1321 | * @param buttonOn Whether the button was turned on or off |
| 1322 | */ |
| 1323 | protected void changeStateFromPress(boolean buttonOn) { |
| 1324 | mState = buttonOn ? State.On : State.Off; |
| 1325 | } |
| 1326 | |
| 1327 | abstract void onToggle(boolean on); |
| 1328 | |
| 1329 | public void updateState(State state) { |
| 1330 | mState = state; |
| 1331 | } |
| 1332 | } |
| 1333 | |
| 1334 | private class SilentModeToggleAction extends ToggleAction { |
| 1335 | public SilentModeToggleAction() { |
| 1336 | super(R.drawable.ic_audio_vol_mute, |
| 1337 | R.drawable.ic_audio_vol, |
| 1338 | R.string.global_action_toggle_silent_mode, |
| 1339 | R.string.global_action_silent_mode_on_status, |
| 1340 | R.string.global_action_silent_mode_off_status); |
| 1341 | } |
| 1342 | |
| 1343 | void onToggle(boolean on) { |
| 1344 | if (on) { |
| 1345 | mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT); |
| 1346 | } else { |
| 1347 | mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL); |
| 1348 | } |
| 1349 | } |
| 1350 | |
| 1351 | public boolean showDuringKeyguard() { |
| 1352 | return true; |
| 1353 | } |
| 1354 | |
| 1355 | public boolean showBeforeProvisioning() { |
| 1356 | return false; |
| 1357 | } |
| 1358 | } |
| 1359 | |
| 1360 | private static class SilentModeTriStateAction implements Action, View.OnClickListener { |
| 1361 | |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1362 | private final int[] ITEM_IDS = {R.id.option1, R.id.option2, R.id.option3}; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1363 | |
| 1364 | private final AudioManager mAudioManager; |
| 1365 | private final Handler mHandler; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1366 | |
Lucas Dupin | 40ec6b78 | 2018-06-05 19:07:16 -0700 | [diff] [blame] | 1367 | SilentModeTriStateAction(AudioManager audioManager, Handler handler) { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1368 | mAudioManager = audioManager; |
| 1369 | mHandler = handler; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1370 | } |
| 1371 | |
| 1372 | private int ringerModeToIndex(int ringerMode) { |
| 1373 | // They just happen to coincide |
| 1374 | return ringerMode; |
| 1375 | } |
| 1376 | |
| 1377 | private int indexToRingerMode(int index) { |
| 1378 | // They just happen to coincide |
| 1379 | return index; |
| 1380 | } |
| 1381 | |
| 1382 | @Override |
| 1383 | public CharSequence getLabelForAccessibility(Context context) { |
| 1384 | return null; |
| 1385 | } |
| 1386 | |
| 1387 | public View create(Context context, View convertView, ViewGroup parent, |
| 1388 | LayoutInflater inflater) { |
| 1389 | View v = inflater.inflate(R.layout.global_actions_silent_mode, parent, false); |
| 1390 | |
| 1391 | int selectedIndex = ringerModeToIndex(mAudioManager.getRingerMode()); |
| 1392 | for (int i = 0; i < 3; i++) { |
| 1393 | View itemView = v.findViewById(ITEM_IDS[i]); |
| 1394 | itemView.setSelected(selectedIndex == i); |
| 1395 | // Set up click handler |
| 1396 | itemView.setTag(i); |
| 1397 | itemView.setOnClickListener(this); |
| 1398 | } |
| 1399 | return v; |
| 1400 | } |
| 1401 | |
| 1402 | public void onPress() { |
| 1403 | } |
| 1404 | |
| 1405 | public boolean showDuringKeyguard() { |
| 1406 | return true; |
| 1407 | } |
| 1408 | |
| 1409 | public boolean showBeforeProvisioning() { |
| 1410 | return false; |
| 1411 | } |
| 1412 | |
| 1413 | public boolean isEnabled() { |
| 1414 | return true; |
| 1415 | } |
| 1416 | |
| 1417 | void willCreate() { |
| 1418 | } |
| 1419 | |
| 1420 | public void onClick(View v) { |
| 1421 | if (!(v.getTag() instanceof Integer)) return; |
| 1422 | |
| 1423 | int index = (Integer) v.getTag(); |
| 1424 | mAudioManager.setRingerMode(indexToRingerMode(index)); |
| 1425 | mHandler.sendEmptyMessageDelayed(MESSAGE_DISMISS, DIALOG_DISMISS_DELAY); |
| 1426 | } |
| 1427 | } |
| 1428 | |
| 1429 | private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 1430 | public void onReceive(Context context, Intent intent) { |
| 1431 | String action = intent.getAction(); |
| 1432 | if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action) |
| 1433 | || Intent.ACTION_SCREEN_OFF.equals(action)) { |
| 1434 | String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY); |
| 1435 | if (!SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS.equals(reason)) { |
Lucas Dupin | 1d4a579 | 2018-04-02 15:14:59 -0700 | [diff] [blame] | 1436 | mHandler.sendMessage(mHandler.obtainMessage(MESSAGE_DISMISS, reason)); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1437 | } |
Jayachandran C | 142eae0 | 2019-12-13 19:29:20 -0800 | [diff] [blame] | 1438 | } else if (TelephonyManager.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED.equals(action)) { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1439 | // Airplane mode can be changed after ECM exits if airplane toggle button |
| 1440 | // is pressed during ECM mode |
Daniel Bright | 4bcbfce | 2020-01-09 21:58:16 -0800 | [diff] [blame] | 1441 | if (!(intent.getBooleanExtra(TelephonyManager.EXTRA_PHONE_IN_ECM_STATE, false)) |
| 1442 | && mIsWaitingForEcmExit) { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1443 | mIsWaitingForEcmExit = false; |
| 1444 | changeAirplaneModeSystemSetting(true); |
| 1445 | } |
| 1446 | } |
| 1447 | } |
| 1448 | }; |
| 1449 | |
| 1450 | PhoneStateListener mPhoneStateListener = new PhoneStateListener() { |
| 1451 | @Override |
| 1452 | public void onServiceStateChanged(ServiceState serviceState) { |
| 1453 | if (!mHasTelephony) return; |
| 1454 | final boolean inAirplaneMode = serviceState.getState() == ServiceState.STATE_POWER_OFF; |
| 1455 | mAirplaneState = inAirplaneMode ? ToggleAction.State.On : ToggleAction.State.Off; |
| 1456 | mAirplaneModeOn.updateState(mAirplaneState); |
| 1457 | mAdapter.notifyDataSetChanged(); |
| 1458 | } |
| 1459 | }; |
| 1460 | |
| 1461 | private BroadcastReceiver mRingerModeReceiver = new BroadcastReceiver() { |
| 1462 | @Override |
| 1463 | public void onReceive(Context context, Intent intent) { |
| 1464 | if (intent.getAction().equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) { |
| 1465 | mHandler.sendEmptyMessage(MESSAGE_REFRESH); |
| 1466 | } |
| 1467 | } |
| 1468 | }; |
| 1469 | |
| 1470 | private ContentObserver mAirplaneModeObserver = new ContentObserver(new Handler()) { |
| 1471 | @Override |
| 1472 | public void onChange(boolean selfChange) { |
| 1473 | onAirplaneModeChanged(); |
| 1474 | } |
| 1475 | }; |
| 1476 | |
| 1477 | private static final int MESSAGE_DISMISS = 0; |
| 1478 | private static final int MESSAGE_REFRESH = 1; |
| 1479 | private static final int MESSAGE_SHOW = 2; |
| 1480 | private static final int DIALOG_DISMISS_DELAY = 300; // ms |
| 1481 | |
| 1482 | private Handler mHandler = new Handler() { |
| 1483 | public void handleMessage(Message msg) { |
| 1484 | switch (msg.what) { |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1485 | case MESSAGE_DISMISS: |
| 1486 | if (mDialog != null) { |
Lucas Dupin | 1d4a579 | 2018-04-02 15:14:59 -0700 | [diff] [blame] | 1487 | if (SYSTEM_DIALOG_REASON_DREAM.equals(msg.obj)) { |
| 1488 | mDialog.dismissImmediately(); |
| 1489 | } else { |
| 1490 | mDialog.dismiss(); |
| 1491 | } |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1492 | mDialog = null; |
| 1493 | } |
| 1494 | break; |
| 1495 | case MESSAGE_REFRESH: |
| 1496 | refreshSilentMode(); |
| 1497 | mAdapter.notifyDataSetChanged(); |
| 1498 | break; |
| 1499 | case MESSAGE_SHOW: |
| 1500 | handleShow(); |
| 1501 | break; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1502 | } |
| 1503 | } |
| 1504 | }; |
| 1505 | |
| 1506 | private void onAirplaneModeChanged() { |
| 1507 | // Let the service state callbacks handle the state. |
| 1508 | if (mHasTelephony) return; |
| 1509 | |
| 1510 | boolean airplaneModeOn = Settings.Global.getInt( |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 1511 | mContentResolver, |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1512 | Settings.Global.AIRPLANE_MODE_ON, |
| 1513 | 0) == 1; |
| 1514 | mAirplaneState = airplaneModeOn ? ToggleAction.State.On : ToggleAction.State.Off; |
| 1515 | mAirplaneModeOn.updateState(mAirplaneState); |
| 1516 | } |
| 1517 | |
| 1518 | /** |
| 1519 | * Change the airplane mode system setting |
| 1520 | */ |
| 1521 | private void changeAirplaneModeSystemSetting(boolean on) { |
| 1522 | Settings.Global.putInt( |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 1523 | mContentResolver, |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1524 | Settings.Global.AIRPLANE_MODE_ON, |
| 1525 | on ? 1 : 0); |
| 1526 | Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); |
| 1527 | intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); |
| 1528 | intent.putExtra("state", on); |
| 1529 | mContext.sendBroadcastAsUser(intent, UserHandle.ALL); |
| 1530 | if (!mHasTelephony) { |
| 1531 | mAirplaneState = on ? ToggleAction.State.On : ToggleAction.State.Off; |
| 1532 | } |
| 1533 | } |
| 1534 | |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1535 | private static final class ActionsDialog extends Dialog implements DialogInterface, |
| 1536 | ColorExtractor.OnColorsChangedListener { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1537 | |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1538 | private final Context mContext; |
| 1539 | private final MyAdapter mAdapter; |
Steve Elliott | 53f12ae | 2019-05-13 17:14:15 -0400 | [diff] [blame] | 1540 | private final IStatusBarService mStatusBarService; |
| 1541 | private final IBinder mToken = new Binder(); |
Aaron Heuckroth | 75e249f | 2019-02-01 15:59:57 -0500 | [diff] [blame] | 1542 | private MultiListLayout mGlobalActionsLayout; |
Steve Elliott | e9e7e1f | 2019-03-18 15:54:59 -0400 | [diff] [blame] | 1543 | private Drawable mBackgroundDrawable; |
Lucas Dupin | 2bd3af6 | 2019-03-25 17:44:28 -0700 | [diff] [blame] | 1544 | private final SysuiColorExtractor mColorExtractor; |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 1545 | private final GlobalActionsPanelPlugin.PanelViewController mPanelController; |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1546 | private boolean mKeyguardShowing; |
Beverly | 526d2d6 | 2018-08-15 12:55:33 -0400 | [diff] [blame] | 1547 | private boolean mShowing; |
Steve Elliott | e9e7e1f | 2019-03-18 15:54:59 -0400 | [diff] [blame] | 1548 | private float mScrimAlpha; |
Steve Elliott | 48f75db | 2019-05-03 15:03:38 -0400 | [diff] [blame] | 1549 | private ResetOrientationData mResetOrientationData; |
Steve Elliott | ff2c0d9 | 2019-07-30 15:09:54 -0400 | [diff] [blame] | 1550 | private boolean mHadTopUi; |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 1551 | private final NotificationShadeWindowController mNotificationShadeWindowController; |
Lucas Dupin | 991415e | 2019-11-25 17:48:58 -0800 | [diff] [blame] | 1552 | private final BlurUtils mBlurUtils; |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame^] | 1553 | |
| 1554 | private ControlsUiController mControlsUiController; |
| 1555 | private ViewGroup mControlsView; |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1556 | |
Aaron Heuckroth | f19d272 | 2019-03-11 17:06:02 -0400 | [diff] [blame] | 1557 | ActionsDialog(Context context, MyAdapter adapter, |
Lucas Dupin | 991415e | 2019-11-25 17:48:58 -0800 | [diff] [blame] | 1558 | GlobalActionsPanelPlugin.PanelViewController plugin, BlurUtils blurUtils, |
| 1559 | SysuiColorExtractor sysuiColorExtractor, IStatusBarService statusBarService, |
| 1560 | NotificationShadeWindowController notificationShadeWindowController, |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame^] | 1561 | ControlsUiController controlsUiController) { |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1562 | super(context, com.android.systemui.R.style.Theme_SystemUI_Dialog_GlobalActions); |
Lucas Dupin | 448786c | 2017-07-24 17:44:25 -0700 | [diff] [blame] | 1563 | mContext = context; |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1564 | mAdapter = adapter; |
Lucas Dupin | 991415e | 2019-11-25 17:48:58 -0800 | [diff] [blame] | 1565 | mBlurUtils = blurUtils; |
| 1566 | mColorExtractor = sysuiColorExtractor; |
| 1567 | mStatusBarService = statusBarService; |
| 1568 | mNotificationShadeWindowController = notificationShadeWindowController; |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame^] | 1569 | mControlsUiController = controlsUiController; |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1570 | |
| 1571 | // Window initialization |
| 1572 | Window window = getWindow(); |
| 1573 | window.requestFeature(Window.FEATURE_NO_TITLE); |
Adrian Roos | edfab3b | 2018-03-08 18:39:20 +0100 | [diff] [blame] | 1574 | // Inflate the decor view, so the attributes below are not overwritten by the theme. |
| 1575 | window.getDecorView(); |
| 1576 | window.getAttributes().systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| 1577 | | View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
| 1578 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; |
| 1579 | window.setLayout(MATCH_PARENT, MATCH_PARENT); |
| 1580 | window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
Alison Cichowlas | 4f19f4a | 2017-07-25 10:56:16 -0400 | [diff] [blame] | 1581 | window.addFlags( |
| 1582 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1583 | | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
Adrian Roos | edfab3b | 2018-03-08 18:39:20 +0100 | [diff] [blame] | 1584 | | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1585 | | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
| 1586 | | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH |
| 1587 | | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED); |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1588 | window.setType(WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY); |
Tiger Huang | 5272444 | 2020-01-20 21:38:42 +0800 | [diff] [blame] | 1589 | window.getAttributes().setFitInsetsTypes(0 /* types */); |
Aaron Heuckroth | 75e249f | 2019-02-01 15:59:57 -0500 | [diff] [blame] | 1590 | setTitle(R.string.global_actions); |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 1591 | |
| 1592 | mPanelController = plugin; |
Steve Elliott | e9e7e1f | 2019-03-18 15:54:59 -0400 | [diff] [blame] | 1593 | initializeLayout(); |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 1594 | } |
| 1595 | |
Aaron Heuckroth | c792661 | 2019-04-02 14:21:57 -0400 | [diff] [blame] | 1596 | private boolean shouldUsePanel() { |
Aran Ink | 3f59455 | 2019-05-13 14:29:35 -0400 | [diff] [blame] | 1597 | return mPanelController != null && mPanelController.getPanelContent() != null; |
Aaron Heuckroth | c792661 | 2019-04-02 14:21:57 -0400 | [diff] [blame] | 1598 | } |
| 1599 | |
| 1600 | private void initializePanel() { |
Steve Elliott | 48f75db | 2019-05-03 15:03:38 -0400 | [diff] [blame] | 1601 | int rotation = RotationUtils.getRotation(mContext); |
| 1602 | boolean rotationLocked = RotationPolicy.isRotationLocked(mContext); |
| 1603 | if (rotation != RotationUtils.ROTATION_NONE) { |
| 1604 | if (rotationLocked) { |
| 1605 | if (mResetOrientationData == null) { |
| 1606 | mResetOrientationData = new ResetOrientationData(); |
| 1607 | mResetOrientationData.locked = true; |
| 1608 | mResetOrientationData.rotation = rotation; |
| 1609 | } |
| 1610 | |
| 1611 | // Unlock rotation, so user can choose to rotate to portrait to see the panel. |
Steve Elliott | e05817f | 2019-05-17 14:39:53 -0400 | [diff] [blame] | 1612 | // This call is posted so that the rotation does not change until post-layout, |
| 1613 | // otherwise onConfigurationChanged() may not get invoked. |
| 1614 | mGlobalActionsLayout.post(() -> |
| 1615 | RotationPolicy.setRotationLockAtAngle( |
| 1616 | mContext, false, RotationUtils.ROTATION_NONE)); |
Steve Elliott | 48f75db | 2019-05-03 15:03:38 -0400 | [diff] [blame] | 1617 | } |
| 1618 | } else { |
| 1619 | if (!rotationLocked) { |
| 1620 | if (mResetOrientationData == null) { |
| 1621 | mResetOrientationData = new ResetOrientationData(); |
| 1622 | mResetOrientationData.locked = false; |
| 1623 | } |
| 1624 | |
| 1625 | // Lock to portrait, so the user doesn't accidentally hide the panel. |
Steve Elliott | e05817f | 2019-05-17 14:39:53 -0400 | [diff] [blame] | 1626 | // This call is posted so that the rotation does not change until post-layout, |
| 1627 | // otherwise onConfigurationChanged() may not get invoked. |
| 1628 | mGlobalActionsLayout.post(() -> |
| 1629 | RotationPolicy.setRotationLockAtAngle( |
| 1630 | mContext, true, RotationUtils.ROTATION_NONE)); |
Steve Elliott | 48f75db | 2019-05-03 15:03:38 -0400 | [diff] [blame] | 1631 | } |
| 1632 | |
Steve Elliott | 53f12ae | 2019-05-13 17:14:15 -0400 | [diff] [blame] | 1633 | // Disable rotation suggestions, if enabled |
| 1634 | setRotationSuggestionsEnabled(false); |
| 1635 | |
Steve Elliott | 300b48f | 2019-05-29 14:13:50 -0400 | [diff] [blame] | 1636 | FrameLayout panelContainer = |
| 1637 | findViewById(com.android.systemui.R.id.global_actions_panel_container); |
Steve Elliott | 48f75db | 2019-05-03 15:03:38 -0400 | [diff] [blame] | 1638 | FrameLayout.LayoutParams panelParams = |
| 1639 | new FrameLayout.LayoutParams( |
| 1640 | FrameLayout.LayoutParams.MATCH_PARENT, |
Steve Elliott | 300b48f | 2019-05-29 14:13:50 -0400 | [diff] [blame] | 1641 | FrameLayout.LayoutParams.MATCH_PARENT); |
Steve Elliott | 48f75db | 2019-05-03 15:03:38 -0400 | [diff] [blame] | 1642 | panelContainer.addView(mPanelController.getPanelContent(), panelParams); |
Steve Elliott | 86ef628 | 2019-05-08 14:45:04 -0400 | [diff] [blame] | 1643 | mBackgroundDrawable = mPanelController.getBackgroundDrawable(); |
| 1644 | mScrimAlpha = 1f; |
Steve Elliott | 48f75db | 2019-05-03 15:03:38 -0400 | [diff] [blame] | 1645 | } |
Aaron Heuckroth | 75e249f | 2019-02-01 15:59:57 -0500 | [diff] [blame] | 1646 | } |
| 1647 | |
| 1648 | private void initializeLayout() { |
| 1649 | setContentView(getGlobalActionsLayoutId(mContext)); |
Steve Elliott | 300b48f | 2019-05-29 14:13:50 -0400 | [diff] [blame] | 1650 | fixNavBarClipping(); |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame^] | 1651 | mControlsView = findViewById(com.android.systemui.R.id.global_actions_controls); |
Steve Elliott | e9e7e1f | 2019-03-18 15:54:59 -0400 | [diff] [blame] | 1652 | mGlobalActionsLayout = findViewById(com.android.systemui.R.id.global_actions_view); |
Aaron Heuckroth | f708d47 | 2019-01-10 16:54:51 -0500 | [diff] [blame] | 1653 | mGlobalActionsLayout.setOutsideTouchListener(view -> dismiss()); |
Steve Elliott | 300b48f | 2019-05-29 14:13:50 -0400 | [diff] [blame] | 1654 | ((View) mGlobalActionsLayout.getParent()).setOnClickListener(view -> dismiss()); |
Aaron Heuckroth | f708d47 | 2019-01-10 16:54:51 -0500 | [diff] [blame] | 1655 | mGlobalActionsLayout.setListViewAccessibilityDelegate(new View.AccessibilityDelegate() { |
Phil Weaver | 9054e09 | 2018-04-27 16:28:50 -0700 | [diff] [blame] | 1656 | @Override |
| 1657 | public boolean dispatchPopulateAccessibilityEvent( |
| 1658 | View host, AccessibilityEvent event) { |
| 1659 | // Populate the title here, just as Activity does |
| 1660 | event.getText().add(mContext.getString(R.string.global_actions)); |
| 1661 | return true; |
| 1662 | } |
| 1663 | }); |
Aaron Heuckroth | 4ea2fdb | 2019-02-14 16:28:35 -0500 | [diff] [blame] | 1664 | mGlobalActionsLayout.setRotationListener(this::onRotate); |
Aaron Heuckroth | 57d60d2 | 2019-03-05 14:00:12 -0500 | [diff] [blame] | 1665 | mGlobalActionsLayout.setAdapter(mAdapter); |
Steve Elliott | e9e7e1f | 2019-03-18 15:54:59 -0400 | [diff] [blame] | 1666 | |
Steve Elliott | 86ef628 | 2019-05-08 14:45:04 -0400 | [diff] [blame] | 1667 | if (shouldUsePanel()) { |
Steve Elliott | c59eb34 | 2019-04-23 16:59:06 -0400 | [diff] [blame] | 1668 | initializePanel(); |
Steve Elliott | e9e7e1f | 2019-03-18 15:54:59 -0400 | [diff] [blame] | 1669 | } |
Steve Elliott | 86ef628 | 2019-05-08 14:45:04 -0400 | [diff] [blame] | 1670 | if (mBackgroundDrawable == null) { |
| 1671 | mBackgroundDrawable = new ScrimDrawable(); |
| 1672 | mScrimAlpha = ScrimController.GRADIENT_SCRIM_ALPHA; |
| 1673 | } |
Steve Elliott | e9e7e1f | 2019-03-18 15:54:59 -0400 | [diff] [blame] | 1674 | getWindow().setBackgroundDrawable(mBackgroundDrawable); |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 1675 | } |
| 1676 | |
Steve Elliott | 300b48f | 2019-05-29 14:13:50 -0400 | [diff] [blame] | 1677 | private void fixNavBarClipping() { |
| 1678 | ViewGroup content = findViewById(android.R.id.content); |
| 1679 | content.setClipChildren(false); |
| 1680 | content.setClipToPadding(false); |
| 1681 | ViewGroup contentParent = (ViewGroup) content.getParent(); |
| 1682 | contentParent.setClipChildren(false); |
| 1683 | contentParent.setClipToPadding(false); |
| 1684 | } |
| 1685 | |
Aaron Heuckroth | 166392f | 2019-01-17 16:50:59 -0500 | [diff] [blame] | 1686 | private int getGlobalActionsLayoutId(Context context) { |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame^] | 1687 | if (mControlsUiController != null) { |
Matt Pietal | fd3b6cb | 2020-01-08 09:43:54 -0500 | [diff] [blame] | 1688 | return com.android.systemui.R.layout.global_actions_grid_v2; |
| 1689 | } |
| 1690 | |
Steve Elliott | dc16563 | 2019-05-23 14:26:31 -0400 | [diff] [blame] | 1691 | int rotation = RotationUtils.getRotation(context); |
| 1692 | boolean useGridLayout = isForceGridEnabled(context) |
| 1693 | || (shouldUsePanel() && rotation == RotationUtils.ROTATION_NONE); |
| 1694 | if (rotation == RotationUtils.ROTATION_SEASCAPE) { |
Aaron Heuckroth | e2d92ac | 2019-05-01 10:44:59 -0400 | [diff] [blame] | 1695 | if (useGridLayout) { |
Aaron Heuckroth | 75e249f | 2019-02-01 15:59:57 -0500 | [diff] [blame] | 1696 | return com.android.systemui.R.layout.global_actions_grid_seascape; |
Aaron Heuckroth | e2d92ac | 2019-05-01 10:44:59 -0400 | [diff] [blame] | 1697 | } else { |
| 1698 | return com.android.systemui.R.layout.global_actions_column_seascape; |
Aaron Heuckroth | 75e249f | 2019-02-01 15:59:57 -0500 | [diff] [blame] | 1699 | } |
Aaron Heuckroth | e2d92ac | 2019-05-01 10:44:59 -0400 | [diff] [blame] | 1700 | } else { |
| 1701 | if (useGridLayout) { |
| 1702 | return com.android.systemui.R.layout.global_actions_grid; |
| 1703 | } else { |
| 1704 | return com.android.systemui.R.layout.global_actions_column; |
| 1705 | } |
Aaron Heuckroth | 166392f | 2019-01-17 16:50:59 -0500 | [diff] [blame] | 1706 | } |
Aaron Heuckroth | 166392f | 2019-01-17 16:50:59 -0500 | [diff] [blame] | 1707 | } |
| 1708 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1709 | @Override |
| 1710 | protected void onStart() { |
| 1711 | super.setCanceledOnTouchOutside(true); |
| 1712 | super.onStart(); |
Aaron Heuckroth | 57d60d2 | 2019-03-05 14:00:12 -0500 | [diff] [blame] | 1713 | mGlobalActionsLayout.updateList(); |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1714 | |
Lucas Dupin | 2bd3af6 | 2019-03-25 17:44:28 -0700 | [diff] [blame] | 1715 | if (mBackgroundDrawable instanceof ScrimDrawable) { |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 1716 | mColorExtractor.addOnColorsChangedListener(this); |
Lucas Dupin | 2bd3af6 | 2019-03-25 17:44:28 -0700 | [diff] [blame] | 1717 | GradientColors colors = mColorExtractor.getNeutralColors(); |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 1718 | updateColors(colors, false /* animate */); |
| 1719 | } |
Lucas Dupin | b5f59fe | 2017-09-14 17:09:39 -0700 | [diff] [blame] | 1720 | } |
| 1721 | |
| 1722 | /** |
| 1723 | * Updates background and system bars according to current GradientColors. |
| 1724 | * @param colors Colors and hints to use. |
| 1725 | * @param animate Interpolates gradient if true, just sets otherwise. |
| 1726 | */ |
| 1727 | private void updateColors(GradientColors colors, boolean animate) { |
Lucas Dupin | 2bd3af6 | 2019-03-25 17:44:28 -0700 | [diff] [blame] | 1728 | if (!(mBackgroundDrawable instanceof ScrimDrawable)) { |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 1729 | return; |
| 1730 | } |
Lucas Dupin | 2bd3af6 | 2019-03-25 17:44:28 -0700 | [diff] [blame] | 1731 | ((ScrimDrawable) mBackgroundDrawable).setColor(colors.getMainColor(), animate); |
Lucas Dupin | b5f59fe | 2017-09-14 17:09:39 -0700 | [diff] [blame] | 1732 | View decorView = getWindow().getDecorView(); |
| 1733 | if (colors.supportsDarkText()) { |
| 1734 | decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR | |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 1735 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); |
Lucas Dupin | b5f59fe | 2017-09-14 17:09:39 -0700 | [diff] [blame] | 1736 | } else { |
| 1737 | decorView.setSystemUiVisibility(0); |
| 1738 | } |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1739 | } |
| 1740 | |
| 1741 | @Override |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1742 | protected void onStop() { |
| 1743 | super.onStop(); |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1744 | mColorExtractor.removeOnColorsChangedListener(this); |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1745 | } |
| 1746 | |
| 1747 | @Override |
| 1748 | public void show() { |
| 1749 | super.show(); |
Beverly | 526d2d6 | 2018-08-15 12:55:33 -0400 | [diff] [blame] | 1750 | mShowing = true; |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 1751 | mHadTopUi = mNotificationShadeWindowController.getForceHasTopUi(); |
| 1752 | mNotificationShadeWindowController.setForceHasTopUi(true); |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 1753 | mBackgroundDrawable.setAlpha(0); |
Aaron Heuckroth | c792661 | 2019-04-02 14:21:57 -0400 | [diff] [blame] | 1754 | mGlobalActionsLayout.setTranslationX(mGlobalActionsLayout.getAnimationOffsetX()); |
| 1755 | mGlobalActionsLayout.setTranslationY(mGlobalActionsLayout.getAnimationOffsetY()); |
Aaron Heuckroth | f708d47 | 2019-01-10 16:54:51 -0500 | [diff] [blame] | 1756 | mGlobalActionsLayout.setAlpha(0); |
| 1757 | mGlobalActionsLayout.animate() |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1758 | .alpha(1) |
| 1759 | .translationX(0) |
Aaron Heuckroth | c792661 | 2019-04-02 14:21:57 -0400 | [diff] [blame] | 1760 | .translationY(0) |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1761 | .setDuration(300) |
Lucas Dupin | de9db42 | 2017-07-19 17:15:41 -0700 | [diff] [blame] | 1762 | .setInterpolator(Interpolators.FAST_OUT_SLOW_IN) |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1763 | .setUpdateListener(animation -> { |
Lucas Dupin | 991415e | 2019-11-25 17:48:58 -0800 | [diff] [blame] | 1764 | float animatedValue = animation.getAnimatedFraction(); |
| 1765 | int alpha = (int) (animatedValue * mScrimAlpha * 255); |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 1766 | mBackgroundDrawable.setAlpha(alpha); |
Lucas Dupin | 991415e | 2019-11-25 17:48:58 -0800 | [diff] [blame] | 1767 | mBlurUtils.applyBlur(mGlobalActionsLayout.getViewRootImpl(), |
| 1768 | mBlurUtils.radiusForRatio(animatedValue)); |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1769 | }) |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1770 | .start(); |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame^] | 1771 | if (mControlsUiController != null) { |
| 1772 | mControlsUiController.show(mControlsView); |
| 1773 | } |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1774 | } |
| 1775 | |
| 1776 | @Override |
| 1777 | public void dismiss() { |
Beverly | 526d2d6 | 2018-08-15 12:55:33 -0400 | [diff] [blame] | 1778 | if (!mShowing) { |
| 1779 | return; |
| 1780 | } |
| 1781 | mShowing = false; |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame^] | 1782 | if (mControlsUiController != null) mControlsUiController.hide(); |
Aaron Heuckroth | f708d47 | 2019-01-10 16:54:51 -0500 | [diff] [blame] | 1783 | mGlobalActionsLayout.setTranslationX(0); |
Aaron Heuckroth | c792661 | 2019-04-02 14:21:57 -0400 | [diff] [blame] | 1784 | mGlobalActionsLayout.setTranslationY(0); |
Aaron Heuckroth | f708d47 | 2019-01-10 16:54:51 -0500 | [diff] [blame] | 1785 | mGlobalActionsLayout.setAlpha(1); |
| 1786 | mGlobalActionsLayout.animate() |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1787 | .alpha(0) |
Aaron Heuckroth | c792661 | 2019-04-02 14:21:57 -0400 | [diff] [blame] | 1788 | .translationX(mGlobalActionsLayout.getAnimationOffsetX()) |
| 1789 | .translationY(mGlobalActionsLayout.getAnimationOffsetY()) |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1790 | .setDuration(300) |
Steve Elliott | ff2c0d9 | 2019-07-30 15:09:54 -0400 | [diff] [blame] | 1791 | .withEndAction(this::completeDismiss) |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1792 | .setInterpolator(new LogAccelerateInterpolator()) |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1793 | .setUpdateListener(animation -> { |
Lucas Dupin | 991415e | 2019-11-25 17:48:58 -0800 | [diff] [blame] | 1794 | float animatedValue = 1f - animation.getAnimatedFraction(); |
| 1795 | int alpha = (int) (animatedValue * mScrimAlpha * 255); |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 1796 | mBackgroundDrawable.setAlpha(alpha); |
Lucas Dupin | 991415e | 2019-11-25 17:48:58 -0800 | [diff] [blame] | 1797 | mBlurUtils.applyBlur(mGlobalActionsLayout.getViewRootImpl(), |
| 1798 | mBlurUtils.radiusForRatio(animatedValue)); |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1799 | }) |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1800 | .start(); |
Steve Elliott | 48f75db | 2019-05-03 15:03:38 -0400 | [diff] [blame] | 1801 | dismissPanel(); |
| 1802 | resetOrientation(); |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1803 | } |
| 1804 | |
Lucas Dupin | 1d4a579 | 2018-04-02 15:14:59 -0700 | [diff] [blame] | 1805 | void dismissImmediately() { |
Beverly | 526d2d6 | 2018-08-15 12:55:33 -0400 | [diff] [blame] | 1806 | mShowing = false; |
Steve Elliott | 48f75db | 2019-05-03 15:03:38 -0400 | [diff] [blame] | 1807 | dismissPanel(); |
| 1808 | resetOrientation(); |
Steve Elliott | ff2c0d9 | 2019-07-30 15:09:54 -0400 | [diff] [blame] | 1809 | completeDismiss(); |
| 1810 | } |
| 1811 | |
| 1812 | private void completeDismiss() { |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 1813 | mNotificationShadeWindowController.setForceHasTopUi(mHadTopUi); |
Steve Elliott | ff2c0d9 | 2019-07-30 15:09:54 -0400 | [diff] [blame] | 1814 | super.dismiss(); |
Steve Elliott | 48f75db | 2019-05-03 15:03:38 -0400 | [diff] [blame] | 1815 | } |
| 1816 | |
| 1817 | private void dismissPanel() { |
Steve Elliott | 2d206d3 | 2019-03-14 16:30:33 -0400 | [diff] [blame] | 1818 | if (mPanelController != null) { |
| 1819 | mPanelController.onDismissed(); |
| 1820 | } |
Lucas Dupin | 1d4a579 | 2018-04-02 15:14:59 -0700 | [diff] [blame] | 1821 | } |
| 1822 | |
Steve Elliott | 53f12ae | 2019-05-13 17:14:15 -0400 | [diff] [blame] | 1823 | private void setRotationSuggestionsEnabled(boolean enabled) { |
| 1824 | try { |
| 1825 | final int userId = Binder.getCallingUserHandle().getIdentifier(); |
| 1826 | final int what = enabled |
| 1827 | ? StatusBarManager.DISABLE2_NONE |
| 1828 | : StatusBarManager.DISABLE2_ROTATE_SUGGESTIONS; |
| 1829 | mStatusBarService.disable2ForUser(what, mToken, mContext.getPackageName(), userId); |
| 1830 | } catch (RemoteException ex) { |
| 1831 | throw ex.rethrowFromSystemServer(); |
| 1832 | } |
| 1833 | } |
| 1834 | |
Steve Elliott | 48f75db | 2019-05-03 15:03:38 -0400 | [diff] [blame] | 1835 | private void resetOrientation() { |
| 1836 | if (mResetOrientationData != null) { |
| 1837 | RotationPolicy.setRotationLockAtAngle(mContext, mResetOrientationData.locked, |
| 1838 | mResetOrientationData.rotation); |
| 1839 | } |
Steve Elliott | 53f12ae | 2019-05-13 17:14:15 -0400 | [diff] [blame] | 1840 | setRotationSuggestionsEnabled(true); |
Steve Elliott | 48f75db | 2019-05-03 15:03:38 -0400 | [diff] [blame] | 1841 | } |
| 1842 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1843 | @Override |
Lucas Dupin | 7aaa353 | 2017-05-28 08:51:07 -0700 | [diff] [blame] | 1844 | public void onColorsChanged(ColorExtractor extractor, int which) { |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1845 | if (mKeyguardShowing) { |
| 1846 | if ((WallpaperManager.FLAG_LOCK & which) != 0) { |
Lucas Dupin | b5f59fe | 2017-09-14 17:09:39 -0700 | [diff] [blame] | 1847 | updateColors(extractor.getColors(WallpaperManager.FLAG_LOCK), |
| 1848 | true /* animate */); |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1849 | } |
| 1850 | } else { |
| 1851 | if ((WallpaperManager.FLAG_SYSTEM & which) != 0) { |
Lucas Dupin | b5f59fe | 2017-09-14 17:09:39 -0700 | [diff] [blame] | 1852 | updateColors(extractor.getColors(WallpaperManager.FLAG_SYSTEM), |
| 1853 | true /* animate */); |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1854 | } |
| 1855 | } |
| 1856 | } |
| 1857 | |
| 1858 | public void setKeyguardShowing(boolean keyguardShowing) { |
| 1859 | mKeyguardShowing = keyguardShowing; |
| 1860 | } |
Aaron Heuckroth | 4ea2fdb | 2019-02-14 16:28:35 -0500 | [diff] [blame] | 1861 | |
Aaron Heuckroth | 4ef3a54 | 2019-04-01 14:17:23 -0400 | [diff] [blame] | 1862 | public void refreshDialog() { |
| 1863 | initializeLayout(); |
| 1864 | mGlobalActionsLayout.updateList(); |
| 1865 | } |
| 1866 | |
Aaron Heuckroth | 4ea2fdb | 2019-02-14 16:28:35 -0500 | [diff] [blame] | 1867 | public void onRotate(int from, int to) { |
Aaron Heuckroth | e2d92ac | 2019-05-01 10:44:59 -0400 | [diff] [blame] | 1868 | if (mShowing) { |
Aaron Heuckroth | 4ef3a54 | 2019-04-01 14:17:23 -0400 | [diff] [blame] | 1869 | refreshDialog(); |
Aaron Heuckroth | 4ea2fdb | 2019-02-14 16:28:35 -0500 | [diff] [blame] | 1870 | } |
| 1871 | } |
Steve Elliott | 48f75db | 2019-05-03 15:03:38 -0400 | [diff] [blame] | 1872 | |
| 1873 | private static class ResetOrientationData { |
| 1874 | public boolean locked; |
| 1875 | public int rotation; |
| 1876 | } |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1877 | } |
Aaron Heuckroth | 75e249f | 2019-02-01 15:59:57 -0500 | [diff] [blame] | 1878 | |
| 1879 | /** |
Aran Ink | 93dd25c | 2019-05-09 14:42:14 -0400 | [diff] [blame] | 1880 | * Determines whether or not debug mode has been activated for the Global Actions Panel. |
| 1881 | */ |
| 1882 | private static boolean isPanelDebugModeEnabled(Context context) { |
| 1883 | return Settings.Secure.getInt(context.getContentResolver(), |
| 1884 | Settings.Secure.GLOBAL_ACTIONS_PANEL_DEBUG_ENABLED, 0) == 1; |
| 1885 | } |
| 1886 | |
| 1887 | /** |
Aaron Heuckroth | c792661 | 2019-04-02 14:21:57 -0400 | [diff] [blame] | 1888 | * Determines whether or not the Global Actions menu should be forced to |
| 1889 | * use the newer grid-style layout. |
Aaron Heuckroth | 75e249f | 2019-02-01 15:59:57 -0500 | [diff] [blame] | 1890 | */ |
Aaron Heuckroth | c792661 | 2019-04-02 14:21:57 -0400 | [diff] [blame] | 1891 | private static boolean isForceGridEnabled(Context context) { |
Aran Ink | 93dd25c | 2019-05-09 14:42:14 -0400 | [diff] [blame] | 1892 | return isPanelDebugModeEnabled(context); |
Aaron Heuckroth | 75e249f | 2019-02-01 15:59:57 -0500 | [diff] [blame] | 1893 | } |
Aaron Heuckroth | f19d272 | 2019-03-11 17:06:02 -0400 | [diff] [blame] | 1894 | |
Aaron Heuckroth | f19d272 | 2019-03-11 17:06:02 -0400 | [diff] [blame] | 1895 | |
| 1896 | /** |
| 1897 | * Determines whether the Global Actions menu should use a separated view for emergency actions. |
| 1898 | */ |
| 1899 | private static boolean shouldUseSeparatedView() { |
| 1900 | return true; |
| 1901 | } |
Matt Pietal | fd3b6cb | 2020-01-08 09:43:54 -0500 | [diff] [blame] | 1902 | |
| 1903 | private static boolean isControlsEnabled(Context context) { |
| 1904 | return Settings.Secure.getInt( |
| 1905 | context.getContentResolver(), "systemui.controls_available", 0) == 1; |
| 1906 | } |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1907 | } |