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