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 | |
| 1093 | public View create( |
| 1094 | Context context, View convertView, ViewGroup parent, LayoutInflater inflater) { |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1095 | View v = inflater.inflate(com.android.systemui.R.layout.global_actions_item, parent, |
| 1096 | false); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1097 | |
| 1098 | ImageView icon = (ImageView) v.findViewById(R.id.icon); |
| 1099 | TextView messageView = (TextView) v.findViewById(R.id.message); |
| 1100 | |
| 1101 | TextView statusView = (TextView) v.findViewById(R.id.status); |
| 1102 | final String status = getStatus(); |
| 1103 | if (!TextUtils.isEmpty(status)) { |
| 1104 | statusView.setText(status); |
| 1105 | } else { |
| 1106 | statusView.setVisibility(View.GONE); |
| 1107 | } |
| 1108 | if (mIcon != null) { |
| 1109 | icon.setImageDrawable(mIcon); |
| 1110 | icon.setScaleType(ScaleType.CENTER_CROP); |
| 1111 | } else if (mIconResId != 0) { |
| 1112 | icon.setImageDrawable(context.getDrawable(mIconResId)); |
| 1113 | } |
| 1114 | if (mMessage != null) { |
| 1115 | messageView.setText(mMessage); |
| 1116 | } else { |
| 1117 | messageView.setText(mMessageResId); |
| 1118 | } |
| 1119 | |
| 1120 | return v; |
| 1121 | } |
| 1122 | } |
| 1123 | |
| 1124 | /** |
| 1125 | * A toggle action knows whether it is on or off, and displays an icon |
| 1126 | * and status message accordingly. |
| 1127 | */ |
| 1128 | private static abstract class ToggleAction implements Action { |
| 1129 | |
| 1130 | enum State { |
| 1131 | Off(false), |
| 1132 | TurningOn(true), |
| 1133 | TurningOff(true), |
| 1134 | On(false); |
| 1135 | |
| 1136 | private final boolean inTransition; |
| 1137 | |
| 1138 | State(boolean intermediate) { |
| 1139 | inTransition = intermediate; |
| 1140 | } |
| 1141 | |
| 1142 | public boolean inTransition() { |
| 1143 | return inTransition; |
| 1144 | } |
| 1145 | } |
| 1146 | |
| 1147 | protected State mState = State.Off; |
| 1148 | |
| 1149 | // prefs |
| 1150 | protected int mEnabledIconResId; |
| 1151 | protected int mDisabledIconResid; |
| 1152 | protected int mMessageResId; |
| 1153 | protected int mEnabledStatusMessageResId; |
| 1154 | protected int mDisabledStatusMessageResId; |
| 1155 | |
| 1156 | /** |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1157 | * @param enabledIconResId The icon for when this action is on. |
| 1158 | * @param disabledIconResid The icon for when this action is off. |
| 1159 | * @param message The general information message, e.g 'Silent Mode' |
| 1160 | * @param enabledStatusMessageResId The on status message, e.g 'sound disabled' |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1161 | * @param disabledStatusMessageResId The off status message, e.g. 'sound enabled' |
| 1162 | */ |
| 1163 | public ToggleAction(int enabledIconResId, |
| 1164 | int disabledIconResid, |
| 1165 | int message, |
| 1166 | int enabledStatusMessageResId, |
| 1167 | int disabledStatusMessageResId) { |
| 1168 | mEnabledIconResId = enabledIconResId; |
| 1169 | mDisabledIconResid = disabledIconResid; |
| 1170 | mMessageResId = message; |
| 1171 | mEnabledStatusMessageResId = enabledStatusMessageResId; |
| 1172 | mDisabledStatusMessageResId = disabledStatusMessageResId; |
| 1173 | } |
| 1174 | |
| 1175 | /** |
| 1176 | * Override to make changes to resource IDs just before creating the |
| 1177 | * View. |
| 1178 | */ |
| 1179 | void willCreate() { |
| 1180 | |
| 1181 | } |
| 1182 | |
| 1183 | @Override |
| 1184 | public CharSequence getLabelForAccessibility(Context context) { |
| 1185 | return context.getString(mMessageResId); |
| 1186 | } |
| 1187 | |
| 1188 | public View create(Context context, View convertView, ViewGroup parent, |
| 1189 | LayoutInflater inflater) { |
| 1190 | willCreate(); |
| 1191 | |
| 1192 | View v = inflater.inflate(R |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1193 | .layout.global_actions_item, parent, false); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1194 | |
| 1195 | ImageView icon = (ImageView) v.findViewById(R.id.icon); |
| 1196 | TextView messageView = (TextView) v.findViewById(R.id.message); |
| 1197 | TextView statusView = (TextView) v.findViewById(R.id.status); |
| 1198 | final boolean enabled = isEnabled(); |
| 1199 | |
| 1200 | if (messageView != null) { |
| 1201 | messageView.setText(mMessageResId); |
| 1202 | messageView.setEnabled(enabled); |
| 1203 | } |
| 1204 | |
| 1205 | boolean on = ((mState == State.On) || (mState == State.TurningOn)); |
| 1206 | if (icon != null) { |
| 1207 | icon.setImageDrawable(context.getDrawable( |
| 1208 | (on ? mEnabledIconResId : mDisabledIconResid))); |
| 1209 | icon.setEnabled(enabled); |
| 1210 | } |
| 1211 | |
| 1212 | if (statusView != null) { |
| 1213 | statusView.setText(on ? mEnabledStatusMessageResId : mDisabledStatusMessageResId); |
| 1214 | statusView.setVisibility(View.VISIBLE); |
| 1215 | statusView.setEnabled(enabled); |
| 1216 | } |
| 1217 | v.setEnabled(enabled); |
| 1218 | |
| 1219 | return v; |
| 1220 | } |
| 1221 | |
| 1222 | public final void onPress() { |
| 1223 | if (mState.inTransition()) { |
| 1224 | Log.w(TAG, "shouldn't be able to toggle when in transition"); |
| 1225 | return; |
| 1226 | } |
| 1227 | |
| 1228 | final boolean nowOn = !(mState == State.On); |
| 1229 | onToggle(nowOn); |
| 1230 | changeStateFromPress(nowOn); |
| 1231 | } |
| 1232 | |
| 1233 | public boolean isEnabled() { |
| 1234 | return !mState.inTransition(); |
| 1235 | } |
| 1236 | |
| 1237 | /** |
| 1238 | * Implementations may override this if their state can be in on of the intermediate |
| 1239 | * states until some notification is received (e.g airplane mode is 'turning off' until |
| 1240 | * we know the wireless connections are back online |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1241 | * |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1242 | * @param buttonOn Whether the button was turned on or off |
| 1243 | */ |
| 1244 | protected void changeStateFromPress(boolean buttonOn) { |
| 1245 | mState = buttonOn ? State.On : State.Off; |
| 1246 | } |
| 1247 | |
| 1248 | abstract void onToggle(boolean on); |
| 1249 | |
| 1250 | public void updateState(State state) { |
| 1251 | mState = state; |
| 1252 | } |
| 1253 | } |
| 1254 | |
| 1255 | private class SilentModeToggleAction extends ToggleAction { |
| 1256 | public SilentModeToggleAction() { |
| 1257 | super(R.drawable.ic_audio_vol_mute, |
| 1258 | R.drawable.ic_audio_vol, |
| 1259 | R.string.global_action_toggle_silent_mode, |
| 1260 | R.string.global_action_silent_mode_on_status, |
| 1261 | R.string.global_action_silent_mode_off_status); |
| 1262 | } |
| 1263 | |
| 1264 | void onToggle(boolean on) { |
| 1265 | if (on) { |
| 1266 | mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT); |
| 1267 | } else { |
| 1268 | mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL); |
| 1269 | } |
| 1270 | } |
| 1271 | |
| 1272 | public boolean showDuringKeyguard() { |
| 1273 | return true; |
| 1274 | } |
| 1275 | |
| 1276 | public boolean showBeforeProvisioning() { |
| 1277 | return false; |
| 1278 | } |
| 1279 | } |
| 1280 | |
| 1281 | private static class SilentModeTriStateAction implements Action, View.OnClickListener { |
| 1282 | |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1283 | 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] | 1284 | |
| 1285 | private final AudioManager mAudioManager; |
| 1286 | private final Handler mHandler; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1287 | |
Lucas Dupin | 40ec6b78 | 2018-06-05 19:07:16 -0700 | [diff] [blame] | 1288 | SilentModeTriStateAction(AudioManager audioManager, Handler handler) { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1289 | mAudioManager = audioManager; |
| 1290 | mHandler = handler; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1291 | } |
| 1292 | |
| 1293 | private int ringerModeToIndex(int ringerMode) { |
| 1294 | // They just happen to coincide |
| 1295 | return ringerMode; |
| 1296 | } |
| 1297 | |
| 1298 | private int indexToRingerMode(int index) { |
| 1299 | // They just happen to coincide |
| 1300 | return index; |
| 1301 | } |
| 1302 | |
| 1303 | @Override |
| 1304 | public CharSequence getLabelForAccessibility(Context context) { |
| 1305 | return null; |
| 1306 | } |
| 1307 | |
| 1308 | public View create(Context context, View convertView, ViewGroup parent, |
| 1309 | LayoutInflater inflater) { |
| 1310 | View v = inflater.inflate(R.layout.global_actions_silent_mode, parent, false); |
| 1311 | |
| 1312 | int selectedIndex = ringerModeToIndex(mAudioManager.getRingerMode()); |
| 1313 | for (int i = 0; i < 3; i++) { |
| 1314 | View itemView = v.findViewById(ITEM_IDS[i]); |
| 1315 | itemView.setSelected(selectedIndex == i); |
| 1316 | // Set up click handler |
| 1317 | itemView.setTag(i); |
| 1318 | itemView.setOnClickListener(this); |
| 1319 | } |
| 1320 | return v; |
| 1321 | } |
| 1322 | |
| 1323 | public void onPress() { |
| 1324 | } |
| 1325 | |
| 1326 | public boolean showDuringKeyguard() { |
| 1327 | return true; |
| 1328 | } |
| 1329 | |
| 1330 | public boolean showBeforeProvisioning() { |
| 1331 | return false; |
| 1332 | } |
| 1333 | |
| 1334 | public boolean isEnabled() { |
| 1335 | return true; |
| 1336 | } |
| 1337 | |
| 1338 | void willCreate() { |
| 1339 | } |
| 1340 | |
| 1341 | public void onClick(View v) { |
| 1342 | if (!(v.getTag() instanceof Integer)) return; |
| 1343 | |
| 1344 | int index = (Integer) v.getTag(); |
| 1345 | mAudioManager.setRingerMode(indexToRingerMode(index)); |
| 1346 | mHandler.sendEmptyMessageDelayed(MESSAGE_DISMISS, DIALOG_DISMISS_DELAY); |
| 1347 | } |
| 1348 | } |
| 1349 | |
| 1350 | private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 1351 | public void onReceive(Context context, Intent intent) { |
| 1352 | String action = intent.getAction(); |
| 1353 | if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action) |
| 1354 | || Intent.ACTION_SCREEN_OFF.equals(action)) { |
| 1355 | String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY); |
| 1356 | if (!SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS.equals(reason)) { |
Lucas Dupin | 1d4a579 | 2018-04-02 15:14:59 -0700 | [diff] [blame] | 1357 | mHandler.sendMessage(mHandler.obtainMessage(MESSAGE_DISMISS, reason)); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1358 | } |
| 1359 | } else if (TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED.equals(action)) { |
| 1360 | // Airplane mode can be changed after ECM exits if airplane toggle button |
| 1361 | // is pressed during ECM mode |
| 1362 | if (!(intent.getBooleanExtra("PHONE_IN_ECM_STATE", false)) && |
| 1363 | mIsWaitingForEcmExit) { |
| 1364 | mIsWaitingForEcmExit = false; |
| 1365 | changeAirplaneModeSystemSetting(true); |
| 1366 | } |
| 1367 | } |
| 1368 | } |
| 1369 | }; |
| 1370 | |
| 1371 | PhoneStateListener mPhoneStateListener = new PhoneStateListener() { |
| 1372 | @Override |
| 1373 | public void onServiceStateChanged(ServiceState serviceState) { |
| 1374 | if (!mHasTelephony) return; |
| 1375 | final boolean inAirplaneMode = serviceState.getState() == ServiceState.STATE_POWER_OFF; |
| 1376 | mAirplaneState = inAirplaneMode ? ToggleAction.State.On : ToggleAction.State.Off; |
| 1377 | mAirplaneModeOn.updateState(mAirplaneState); |
| 1378 | mAdapter.notifyDataSetChanged(); |
| 1379 | } |
| 1380 | }; |
| 1381 | |
| 1382 | private BroadcastReceiver mRingerModeReceiver = new BroadcastReceiver() { |
| 1383 | @Override |
| 1384 | public void onReceive(Context context, Intent intent) { |
| 1385 | if (intent.getAction().equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) { |
| 1386 | mHandler.sendEmptyMessage(MESSAGE_REFRESH); |
| 1387 | } |
| 1388 | } |
| 1389 | }; |
| 1390 | |
| 1391 | private ContentObserver mAirplaneModeObserver = new ContentObserver(new Handler()) { |
| 1392 | @Override |
| 1393 | public void onChange(boolean selfChange) { |
| 1394 | onAirplaneModeChanged(); |
| 1395 | } |
| 1396 | }; |
| 1397 | |
| 1398 | private static final int MESSAGE_DISMISS = 0; |
| 1399 | private static final int MESSAGE_REFRESH = 1; |
| 1400 | private static final int MESSAGE_SHOW = 2; |
| 1401 | private static final int DIALOG_DISMISS_DELAY = 300; // ms |
| 1402 | |
| 1403 | private Handler mHandler = new Handler() { |
| 1404 | public void handleMessage(Message msg) { |
| 1405 | switch (msg.what) { |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1406 | case MESSAGE_DISMISS: |
| 1407 | if (mDialog != null) { |
Lucas Dupin | 1d4a579 | 2018-04-02 15:14:59 -0700 | [diff] [blame] | 1408 | if (SYSTEM_DIALOG_REASON_DREAM.equals(msg.obj)) { |
| 1409 | mDialog.dismissImmediately(); |
| 1410 | } else { |
| 1411 | mDialog.dismiss(); |
| 1412 | } |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1413 | mDialog = null; |
| 1414 | } |
| 1415 | break; |
| 1416 | case MESSAGE_REFRESH: |
| 1417 | refreshSilentMode(); |
| 1418 | mAdapter.notifyDataSetChanged(); |
| 1419 | break; |
| 1420 | case MESSAGE_SHOW: |
| 1421 | handleShow(); |
| 1422 | break; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1423 | } |
| 1424 | } |
| 1425 | }; |
| 1426 | |
| 1427 | private void onAirplaneModeChanged() { |
| 1428 | // Let the service state callbacks handle the state. |
| 1429 | if (mHasTelephony) return; |
| 1430 | |
| 1431 | boolean airplaneModeOn = Settings.Global.getInt( |
| 1432 | mContext.getContentResolver(), |
| 1433 | Settings.Global.AIRPLANE_MODE_ON, |
| 1434 | 0) == 1; |
| 1435 | mAirplaneState = airplaneModeOn ? ToggleAction.State.On : ToggleAction.State.Off; |
| 1436 | mAirplaneModeOn.updateState(mAirplaneState); |
| 1437 | } |
| 1438 | |
| 1439 | /** |
| 1440 | * Change the airplane mode system setting |
| 1441 | */ |
| 1442 | private void changeAirplaneModeSystemSetting(boolean on) { |
| 1443 | Settings.Global.putInt( |
| 1444 | mContext.getContentResolver(), |
| 1445 | Settings.Global.AIRPLANE_MODE_ON, |
| 1446 | on ? 1 : 0); |
| 1447 | Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); |
| 1448 | intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); |
| 1449 | intent.putExtra("state", on); |
| 1450 | mContext.sendBroadcastAsUser(intent, UserHandle.ALL); |
| 1451 | if (!mHasTelephony) { |
| 1452 | mAirplaneState = on ? ToggleAction.State.On : ToggleAction.State.Off; |
| 1453 | } |
| 1454 | } |
| 1455 | |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1456 | private static final class ActionsDialog extends Dialog implements DialogInterface, |
| 1457 | ColorExtractor.OnColorsChangedListener { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1458 | |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1459 | private final Context mContext; |
| 1460 | private final MyAdapter mAdapter; |
Aaron Heuckroth | f708d47 | 2019-01-10 16:54:51 -0500 | [diff] [blame] | 1461 | private final MultiListLayout mGlobalActionsLayout; |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1462 | private final OnClickListener mClickListener; |
| 1463 | private final OnItemLongClickListener mLongClickListener; |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1464 | private final GradientDrawable mGradientDrawable; |
| 1465 | private final ColorExtractor mColorExtractor; |
| 1466 | private boolean mKeyguardShowing; |
Wesley.CW Wang | 3004fcb | 2018-06-15 16:24:57 +0800 | [diff] [blame] | 1467 | private boolean mShouldDisplaySeparatedButton; |
Beverly | 526d2d6 | 2018-08-15 12:55:33 -0400 | [diff] [blame] | 1468 | private boolean mShowing; |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1469 | |
| 1470 | public ActionsDialog(Context context, OnClickListener clickListener, MyAdapter adapter, |
Wesley.CW Wang | 3004fcb | 2018-06-15 16:24:57 +0800 | [diff] [blame] | 1471 | OnItemLongClickListener longClickListener, boolean shouldDisplaySeparatedButton) { |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1472 | super(context, com.android.systemui.R.style.Theme_SystemUI_Dialog_GlobalActions); |
Lucas Dupin | 448786c | 2017-07-24 17:44:25 -0700 | [diff] [blame] | 1473 | mContext = context; |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1474 | mAdapter = adapter; |
| 1475 | mClickListener = clickListener; |
| 1476 | mLongClickListener = longClickListener; |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1477 | mGradientDrawable = new GradientDrawable(mContext); |
Lucas Dupin | 1ead7fc | 2017-05-24 14:14:44 -0700 | [diff] [blame] | 1478 | mColorExtractor = Dependency.get(SysuiColorExtractor.class); |
Wesley.CW Wang | 3004fcb | 2018-06-15 16:24:57 +0800 | [diff] [blame] | 1479 | mShouldDisplaySeparatedButton = shouldDisplaySeparatedButton; |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1480 | |
| 1481 | // Window initialization |
| 1482 | Window window = getWindow(); |
| 1483 | window.requestFeature(Window.FEATURE_NO_TITLE); |
Adrian Roos | edfab3b | 2018-03-08 18:39:20 +0100 | [diff] [blame] | 1484 | // Inflate the decor view, so the attributes below are not overwritten by the theme. |
| 1485 | window.getDecorView(); |
| 1486 | window.getAttributes().systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| 1487 | | View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
| 1488 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; |
| 1489 | window.setLayout(MATCH_PARENT, MATCH_PARENT); |
| 1490 | window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
Alison Cichowlas | 4f19f4a | 2017-07-25 10:56:16 -0400 | [diff] [blame] | 1491 | window.addFlags( |
| 1492 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1493 | | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
Adrian Roos | edfab3b | 2018-03-08 18:39:20 +0100 | [diff] [blame] | 1494 | | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1495 | | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
| 1496 | | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH |
| 1497 | | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED); |
| 1498 | window.setBackgroundDrawable(mGradientDrawable); |
| 1499 | window.setType(WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY); |
| 1500 | |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1501 | setContentView(com.android.systemui.R.layout.global_actions_wrapped); |
Aaron Heuckroth | f708d47 | 2019-01-10 16:54:51 -0500 | [diff] [blame] | 1502 | mGlobalActionsLayout = (MultiListLayout) |
| 1503 | findViewById(com.android.systemui.R.id.global_actions_view); |
| 1504 | mGlobalActionsLayout.setOutsideTouchListener(view -> dismiss()); |
| 1505 | mGlobalActionsLayout.setHasSeparatedView(mShouldDisplaySeparatedButton); |
| 1506 | mGlobalActionsLayout.setListViewAccessibilityDelegate(new View.AccessibilityDelegate() { |
Phil Weaver | 9054e09 | 2018-04-27 16:28:50 -0700 | [diff] [blame] | 1507 | @Override |
| 1508 | public boolean dispatchPopulateAccessibilityEvent( |
| 1509 | View host, AccessibilityEvent event) { |
| 1510 | // Populate the title here, just as Activity does |
| 1511 | event.getText().add(mContext.getString(R.string.global_actions)); |
| 1512 | return true; |
| 1513 | } |
| 1514 | }); |
Aaron Heuckroth | f708d47 | 2019-01-10 16:54:51 -0500 | [diff] [blame] | 1515 | setTitle(R.string.global_actions); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1516 | } |
| 1517 | |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1518 | private void updateList() { |
Aaron Heuckroth | f708d47 | 2019-01-10 16:54:51 -0500 | [diff] [blame] | 1519 | mGlobalActionsLayout.removeAllItems(); |
| 1520 | ArrayList<Action> separatedActions = |
| 1521 | mAdapter.getSeparatedActions(mShouldDisplaySeparatedButton); |
| 1522 | ArrayList<Action> listActions = mAdapter.getListActions(mShouldDisplaySeparatedButton); |
| 1523 | mGlobalActionsLayout.setExpectedListItemCount(listActions.size()); |
| 1524 | mGlobalActionsLayout.setExpectedSeparatedItemCount(separatedActions.size()); |
| 1525 | |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1526 | for (int i = 0; i < mAdapter.getCount(); i++) { |
Aaron Heuckroth | f708d47 | 2019-01-10 16:54:51 -0500 | [diff] [blame] | 1527 | Action action = mAdapter.getItem(i); |
| 1528 | int separatedIndex = separatedActions.indexOf(action); |
| 1529 | ViewGroup parent; |
| 1530 | if (separatedIndex != -1) { |
| 1531 | parent = mGlobalActionsLayout.getParentView(true, separatedIndex); |
| 1532 | } else { |
| 1533 | int listIndex = listActions.indexOf(action); |
| 1534 | parent = mGlobalActionsLayout.getParentView(false, listIndex); |
| 1535 | } |
| 1536 | View v = mAdapter.getView(i, null, parent); |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1537 | final int pos = i; |
| 1538 | v.setOnClickListener(view -> mClickListener.onClick(this, pos)); |
| 1539 | v.setOnLongClickListener(view -> |
| 1540 | mLongClickListener.onItemLongClick(null, v, pos, 0)); |
Aaron Heuckroth | f708d47 | 2019-01-10 16:54:51 -0500 | [diff] [blame] | 1541 | parent.addView(v); |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1542 | } |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1543 | } |
| 1544 | |
| 1545 | @Override |
| 1546 | protected void onStart() { |
| 1547 | super.setCanceledOnTouchOutside(true); |
| 1548 | super.onStart(); |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1549 | updateList(); |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1550 | |
| 1551 | Point displaySize = new Point(); |
| 1552 | mContext.getDisplay().getRealSize(displaySize); |
| 1553 | mColorExtractor.addOnColorsChangedListener(this); |
| 1554 | mGradientDrawable.setScreenSize(displaySize.x, displaySize.y); |
| 1555 | GradientColors colors = mColorExtractor.getColors(mKeyguardShowing ? |
| 1556 | WallpaperManager.FLAG_LOCK : WallpaperManager.FLAG_SYSTEM); |
Lucas Dupin | b5f59fe | 2017-09-14 17:09:39 -0700 | [diff] [blame] | 1557 | updateColors(colors, false /* animate */); |
| 1558 | } |
| 1559 | |
| 1560 | /** |
| 1561 | * Updates background and system bars according to current GradientColors. |
| 1562 | * @param colors Colors and hints to use. |
| 1563 | * @param animate Interpolates gradient if true, just sets otherwise. |
| 1564 | */ |
| 1565 | private void updateColors(GradientColors colors, boolean animate) { |
| 1566 | mGradientDrawable.setColors(colors, animate); |
| 1567 | View decorView = getWindow().getDecorView(); |
| 1568 | if (colors.supportsDarkText()) { |
| 1569 | decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR | |
| 1570 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); |
| 1571 | } else { |
| 1572 | decorView.setSystemUiVisibility(0); |
| 1573 | } |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1574 | } |
| 1575 | |
| 1576 | @Override |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1577 | protected void onStop() { |
| 1578 | super.onStop(); |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1579 | mColorExtractor.removeOnColorsChangedListener(this); |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1580 | } |
| 1581 | |
| 1582 | @Override |
| 1583 | public void show() { |
| 1584 | super.show(); |
Beverly | 526d2d6 | 2018-08-15 12:55:33 -0400 | [diff] [blame] | 1585 | mShowing = true; |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1586 | mGradientDrawable.setAlpha(0); |
Aaron Heuckroth | f708d47 | 2019-01-10 16:54:51 -0500 | [diff] [blame] | 1587 | mGlobalActionsLayout.setTranslationX(getAnimTranslation()); |
| 1588 | mGlobalActionsLayout.setAlpha(0); |
| 1589 | mGlobalActionsLayout.animate() |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1590 | .alpha(1) |
| 1591 | .translationX(0) |
| 1592 | .setDuration(300) |
Lucas Dupin | de9db42 | 2017-07-19 17:15:41 -0700 | [diff] [blame] | 1593 | .setInterpolator(Interpolators.FAST_OUT_SLOW_IN) |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1594 | .setUpdateListener(animation -> { |
| 1595 | int alpha = (int) ((Float) animation.getAnimatedValue() |
| 1596 | * ScrimController.GRADIENT_SCRIM_ALPHA * 255); |
| 1597 | mGradientDrawable.setAlpha(alpha); |
| 1598 | }) |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1599 | .start(); |
| 1600 | } |
| 1601 | |
| 1602 | @Override |
| 1603 | public void dismiss() { |
Beverly | 526d2d6 | 2018-08-15 12:55:33 -0400 | [diff] [blame] | 1604 | if (!mShowing) { |
| 1605 | return; |
| 1606 | } |
| 1607 | mShowing = false; |
Aaron Heuckroth | f708d47 | 2019-01-10 16:54:51 -0500 | [diff] [blame] | 1608 | mGlobalActionsLayout.setTranslationX(0); |
| 1609 | mGlobalActionsLayout.setAlpha(1); |
| 1610 | mGlobalActionsLayout.animate() |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1611 | .alpha(0) |
| 1612 | .translationX(getAnimTranslation()) |
| 1613 | .setDuration(300) |
| 1614 | .withEndAction(() -> super.dismiss()) |
| 1615 | .setInterpolator(new LogAccelerateInterpolator()) |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1616 | .setUpdateListener(animation -> { |
| 1617 | int alpha = (int) ((1f - (Float) animation.getAnimatedValue()) |
| 1618 | * ScrimController.GRADIENT_SCRIM_ALPHA * 255); |
| 1619 | mGradientDrawable.setAlpha(alpha); |
| 1620 | }) |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1621 | .start(); |
| 1622 | } |
| 1623 | |
Lucas Dupin | 1d4a579 | 2018-04-02 15:14:59 -0700 | [diff] [blame] | 1624 | void dismissImmediately() { |
| 1625 | super.dismiss(); |
Beverly | 526d2d6 | 2018-08-15 12:55:33 -0400 | [diff] [blame] | 1626 | mShowing = false; |
Lucas Dupin | 1d4a579 | 2018-04-02 15:14:59 -0700 | [diff] [blame] | 1627 | } |
| 1628 | |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1629 | private float getAnimTranslation() { |
| 1630 | return getContext().getResources().getDimension( |
| 1631 | com.android.systemui.R.dimen.global_actions_panel_width) / 2; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1632 | } |
| 1633 | |
| 1634 | @Override |
Lucas Dupin | 7aaa353 | 2017-05-28 08:51:07 -0700 | [diff] [blame] | 1635 | public void onColorsChanged(ColorExtractor extractor, int which) { |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1636 | if (mKeyguardShowing) { |
| 1637 | if ((WallpaperManager.FLAG_LOCK & which) != 0) { |
Lucas Dupin | b5f59fe | 2017-09-14 17:09:39 -0700 | [diff] [blame] | 1638 | updateColors(extractor.getColors(WallpaperManager.FLAG_LOCK), |
| 1639 | true /* animate */); |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1640 | } |
| 1641 | } else { |
| 1642 | if ((WallpaperManager.FLAG_SYSTEM & which) != 0) { |
Lucas Dupin | b5f59fe | 2017-09-14 17:09:39 -0700 | [diff] [blame] | 1643 | updateColors(extractor.getColors(WallpaperManager.FLAG_SYSTEM), |
| 1644 | true /* animate */); |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1645 | } |
| 1646 | } |
| 1647 | } |
| 1648 | |
| 1649 | public void setKeyguardShowing(boolean keyguardShowing) { |
| 1650 | mKeyguardShowing = keyguardShowing; |
| 1651 | } |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1652 | } |
| 1653 | } |