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