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