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