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