blob: ef0be88bfd4ef57f0af6966cf03d04411236b9ac [file] [log] [blame]
Jason Monk361915c2017-03-21 20:33:59 -04001/*
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
15package com.android.systemui.globalactions;
16
Adrian Roosedfab3b2018-03-08 18:39:20 +010017import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
Adrian Roos2f05bb32018-02-19 16:42:27 +010018import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
19
Chad Brubakerf4075fe2018-01-03 13:23:22 -080020import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_USER_REQUEST;
21import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_NOT_REQUIRED;
Chad Brubaker4f28f0d2017-09-07 14:28:13 -070022import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN;
23
Dave Mankoffc88a2d72020-01-10 15:59:31 -050024import android.annotation.Nullable;
Jason Monk361915c2017-03-21 20:33:59 -040025import android.app.ActivityManager;
26import android.app.Dialog;
Dave Mankoffc88a2d72020-01-10 15:59:31 -050027import android.app.IActivityManager;
Chad Brubakerf4075fe2018-01-03 13:23:22 -080028import android.app.KeyguardManager;
Steve Elliott4c868852019-03-14 16:25:41 -040029import android.app.PendingIntent;
Steve Elliott53f12ae2019-05-13 17:14:15 -040030import android.app.StatusBarManager;
Lucas Dupinc1cc7592017-05-22 15:56:16 -070031import android.app.WallpaperManager;
Alex Chau04458852017-11-27 18:21:23 +000032import android.app.admin.DevicePolicyManager;
Pavel Grafov059021b2018-05-02 13:44:46 +010033import android.app.trust.TrustManager;
Jason Monk361915c2017-03-21 20:33:59 -040034import android.content.BroadcastReceiver;
Dave Mankoffc88a2d72020-01-10 15:59:31 -050035import android.content.ContentResolver;
Jason Monk361915c2017-03-21 20:33:59 -040036import android.content.Context;
37import android.content.DialogInterface;
38import android.content.Intent;
39import android.content.IntentFilter;
40import android.content.pm.UserInfo;
Dave Mankoffc88a2d72020-01-10 15:59:31 -050041import android.content.res.Resources;
Jason Monk361915c2017-03-21 20:33:59 -040042import android.database.ContentObserver;
Matt Pietale0661b62020-01-29 14:35:31 -050043import android.graphics.Color;
Jason Monk361915c2017-03-21 20:33:59 -040044import android.graphics.drawable.Drawable;
45import android.media.AudioManager;
46import android.net.ConnectivityManager;
Steve Elliott53f12ae2019-05-13 17:14:15 -040047import android.os.Binder;
Jason Monk361915c2017-03-21 20:33:59 -040048import android.os.Handler;
Steve Elliott53f12ae2019-05-13 17:14:15 -040049import android.os.IBinder;
Jason Monk361915c2017-03-21 20:33:59 -040050import android.os.Message;
51import android.os.RemoteException;
Jason Monk361915c2017-03-21 20:33:59 -040052import android.os.SystemProperties;
53import android.os.UserHandle;
54import android.os.UserManager;
55import android.os.Vibrator;
56import android.provider.Settings;
Jason Monk361915c2017-03-21 20:33:59 -040057import android.service.dreams.IDreamManager;
Inseob Kim5e82f732019-11-08 15:08:38 +090058import android.sysprop.TelephonyProperties;
Fan Zhangf9914762019-11-01 15:58:38 -070059import android.telecom.TelecomManager;
Jason Monk361915c2017-03-21 20:33:59 -040060import android.telephony.PhoneStateListener;
61import android.telephony.ServiceState;
62import android.telephony.TelephonyManager;
Jason Monk361915c2017-03-21 20:33:59 -040063import android.util.ArraySet;
yuanjiahsu88363e92018-09-06 19:23:52 +080064import android.util.FeatureFlagUtils;
Jason Monk361915c2017-03-21 20:33:59 -040065import android.util.Log;
Lucas Dupin448786c2017-07-24 17:44:25 -070066import android.view.ContextThemeWrapper;
Jason Monk361915c2017-03-21 20:33:59 -040067import android.view.LayoutInflater;
68import android.view.View;
69import android.view.ViewGroup;
Lucas Dupinc1cc7592017-05-22 15:56:16 -070070import android.view.Window;
Jason Monk361915c2017-03-21 20:33:59 -040071import android.view.WindowManager;
72import android.view.WindowManagerGlobal;
73import android.view.accessibility.AccessibilityEvent;
Steve Elliott9b87a442019-03-05 10:24:16 -050074import android.widget.FrameLayout;
Jason Monk361915c2017-03-21 20:33:59 -040075import android.widget.ImageView;
76import android.widget.ImageView.ScaleType;
Jason Monk361915c2017-03-21 20:33:59 -040077import android.widget.TextView;
78
Charles He9851a8d2017-10-10 17:31:30 +010079import com.android.internal.R;
80import com.android.internal.colorextraction.ColorExtractor;
81import com.android.internal.colorextraction.ColorExtractor.GradientColors;
Lucas Dupin2bd3af62019-03-25 17:44:28 -070082import com.android.internal.colorextraction.drawable.ScrimDrawable;
Charles He9851a8d2017-10-10 17:31:30 +010083import com.android.internal.logging.MetricsLogger;
84import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Steve Elliott53f12ae2019-05-13 17:14:15 -040085import com.android.internal.statusbar.IStatusBarService;
Charles He9851a8d2017-10-10 17:31:30 +010086import com.android.internal.util.EmergencyAffordanceManager;
Beth Thibodeau5898ac42018-10-26 13:00:09 -040087import com.android.internal.util.ScreenRecordHelper;
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -050088import com.android.internal.util.ScreenshotHelper;
Steve Elliott48f75db2019-05-03 15:03:38 -040089import com.android.internal.view.RotationPolicy;
Charles He9851a8d2017-10-10 17:31:30 +010090import com.android.internal.widget.LockPatternUtils;
91import com.android.systemui.Dependency;
Charles He9851a8d2017-10-10 17:31:30 +010092import com.android.systemui.Interpolators;
Aaron Heuckrothf708d472019-01-10 16:54:51 -050093import com.android.systemui.MultiListLayout;
Aaron Heuckroth57d60d22019-03-05 14:00:12 -050094import com.android.systemui.MultiListLayout.MultiListAdapter;
Fabian Kozynskiff5e91f2019-09-24 15:38:08 -040095import com.android.systemui.broadcast.BroadcastDispatcher;
Charles He9851a8d2017-10-10 17:31:30 +010096import com.android.systemui.colorextraction.SysuiColorExtractor;
Matt Pietal22231792020-01-23 09:51:09 -050097import com.android.systemui.controls.ui.ControlsUiController;
Dave Mankoffc88a2d72020-01-10 15:59:31 -050098import com.android.systemui.dagger.qualifiers.Main;
Steve Elliott4c868852019-03-14 16:25:41 -040099import com.android.systemui.plugins.ActivityStarter;
Charles He9851a8d2017-10-10 17:31:30 +0100100import com.android.systemui.plugins.GlobalActions.GlobalActionsManager;
Steve Elliott9b87a442019-03-05 10:24:16 -0500101import com.android.systemui.plugins.GlobalActionsPanelPlugin;
Lucas Dupin991415e2019-11-25 17:48:58 -0800102import com.android.systemui.statusbar.BlurUtils;
Matt Pietal22231792020-01-23 09:51:09 -0500103import com.android.systemui.statusbar.phone.NotificationShadeWindowController;
Lucas Dupin43d01242020-02-03 11:58:33 -0800104import com.android.systemui.statusbar.phone.ScrimController;
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700105import com.android.systemui.statusbar.policy.ConfigurationController;
Lucas Dupinc8f16e82019-09-17 18:24:50 -0400106import com.android.systemui.statusbar.policy.KeyguardStateController;
Shaotang Li5c422632018-07-04 14:18:40 +0800107import com.android.systemui.util.EmergencyDialerConstants;
Aaron Heuckroth75e249f2019-02-01 15:59:57 -0500108import com.android.systemui.util.leak.RotationUtils;
Julia Reynolds42411922017-11-08 11:19:09 -0500109import com.android.systemui.volume.SystemUIInterpolators.LogAccelerateInterpolator;
Lucas Dupinc1cc7592017-05-22 15:56:16 -0700110
Jason Monk361915c2017-03-21 20:33:59 -0400111import java.util.ArrayList;
112import java.util.List;
113
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500114import javax.inject.Inject;
115
Jason Monk361915c2017-03-21 20:33:59 -0400116/**
117 * Helper to show the global actions dialog. Each item is an {@link Action} that
118 * may show depending on whether the keyguard is showing, and whether the device
119 * is provisioned.
120 */
Aaron Heuckroth57d60d22019-03-05 14:00:12 -0500121public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
122 DialogInterface.OnShowListener, ConfigurationController.ConfigurationListener {
Jason Monk361915c2017-03-21 20:33:59 -0400123
124 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
125 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
Lucas Dupin1d4a5792018-04-02 15:14:59 -0700126 static public final String SYSTEM_DIALOG_REASON_DREAM = "dream";
Jason Monk361915c2017-03-21 20:33:59 -0400127
128 private static final String TAG = "GlobalActionsDialog";
129
130 private static final boolean SHOW_SILENT_TOGGLE = true;
131
132 /* Valid settings for global actions keys.
133 * see config.xml config_globalActionList */
134 private static final String GLOBAL_ACTION_KEY_POWER = "power";
135 private static final String GLOBAL_ACTION_KEY_AIRPLANE = "airplane";
136 private static final String GLOBAL_ACTION_KEY_BUGREPORT = "bugreport";
137 private static final String GLOBAL_ACTION_KEY_SILENT = "silent";
138 private static final String GLOBAL_ACTION_KEY_USERS = "users";
139 private static final String GLOBAL_ACTION_KEY_SETTINGS = "settings";
140 private static final String GLOBAL_ACTION_KEY_LOCKDOWN = "lockdown";
141 private static final String GLOBAL_ACTION_KEY_VOICEASSIST = "voiceassist";
142 private static final String GLOBAL_ACTION_KEY_ASSIST = "assist";
143 private static final String GLOBAL_ACTION_KEY_RESTART = "restart";
Alex Chau04458852017-11-27 18:21:23 +0000144 private static final String GLOBAL_ACTION_KEY_LOGOUT = "logout";
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800145 private static final String GLOBAL_ACTION_KEY_EMERGENCY = "emergency";
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500146 private static final String GLOBAL_ACTION_KEY_SCREENSHOT = "screenshot";
Jason Monk361915c2017-03-21 20:33:59 -0400147
148 private final Context mContext;
149 private final GlobalActionsManager mWindowManagerFuncs;
150 private final AudioManager mAudioManager;
151 private final IDreamManager mDreamManager;
Alex Chau04458852017-11-27 18:21:23 +0000152 private final DevicePolicyManager mDevicePolicyManager;
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800153 private final LockPatternUtils mLockPatternUtils;
154 private final KeyguardManager mKeyguardManager;
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000155 private final BroadcastDispatcher mBroadcastDispatcher;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500156 private final ContentResolver mContentResolver;
157 private final Resources mResources;
158 private final UserManager mUserManager;
159 private final TrustManager mTrustManager;
160 private final IActivityManager mIActivityManager;
161 private final TelecomManager mTelecomManager;
162 private final MetricsLogger mMetricsLogger;
Lucas Dupin991415e2019-11-25 17:48:58 -0800163 private final BlurUtils mBlurUtils;
Jason Monk361915c2017-03-21 20:33:59 -0400164
165 private ArrayList<Action> mItems;
166 private ActionsDialog mDialog;
167
168 private Action mSilentModeAction;
169 private ToggleAction mAirplaneModeOn;
170
171 private MyAdapter mAdapter;
172
173 private boolean mKeyguardShowing = false;
174 private boolean mDeviceProvisioned = false;
175 private ToggleAction.State mAirplaneState = ToggleAction.State.Off;
176 private boolean mIsWaitingForEcmExit = false;
177 private boolean mHasTelephony;
178 private boolean mHasVibrator;
179 private final boolean mShowSilentToggle;
180 private final EmergencyAffordanceManager mEmergencyAffordanceManager;
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500181 private final ScreenshotHelper mScreenshotHelper;
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400182 private final ScreenRecordHelper mScreenRecordHelper;
Steve Elliotta3f5207922019-03-18 13:37:22 -0400183 private final ActivityStarter mActivityStarter;
Lucas Dupin991415e2019-11-25 17:48:58 -0800184 private final SysuiColorExtractor mSysuiColorExtractor;
185 private final IStatusBarService mStatusBarService;
186 private final NotificationShadeWindowController mNotificationShadeWindowController;
Steve Elliotta3f5207922019-03-18 13:37:22 -0400187 private GlobalActionsPanelPlugin mPanelPlugin;
Matt Pietal22231792020-01-23 09:51:09 -0500188 private ControlsUiController mControlsUiController;
Steve Elliott9b87a442019-03-05 10:24:16 -0500189
Jason Monk361915c2017-03-21 20:33:59 -0400190 /**
191 * @param context everything needs a context :(
192 */
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500193 @Inject
194 public GlobalActionsDialog(Context context, GlobalActionsManager windowManagerFuncs,
195 AudioManager audioManager, IDreamManager iDreamManager,
196 DevicePolicyManager devicePolicyManager, LockPatternUtils lockPatternUtils,
197 KeyguardManager keyguardManager, BroadcastDispatcher broadcastDispatcher,
198 ConnectivityManager connectivityManager, TelephonyManager telephonyManager,
199 ContentResolver contentResolver, @Nullable Vibrator vibrator, @Main Resources resources,
200 ConfigurationController configurationController, ActivityStarter activityStarter,
201 KeyguardStateController keyguardStateController, UserManager userManager,
202 TrustManager trustManager, IActivityManager iActivityManager,
Lucas Dupin991415e2019-11-25 17:48:58 -0800203 TelecomManager telecomManager, MetricsLogger metricsLogger,
204 BlurUtils blurUtils, SysuiColorExtractor colorExtractor,
205 IStatusBarService statusBarService,
Matt Pietal22231792020-01-23 09:51:09 -0500206 NotificationShadeWindowController notificationShadeWindowController,
207 ControlsUiController controlsUiController) {
Lucas Dupin448786c2017-07-24 17:44:25 -0700208 mContext = new ContextThemeWrapper(context, com.android.systemui.R.style.qs_theme);
Jason Monk361915c2017-03-21 20:33:59 -0400209 mWindowManagerFuncs = windowManagerFuncs;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500210 mAudioManager = audioManager;
211 mDreamManager = iDreamManager;
212 mDevicePolicyManager = devicePolicyManager;
213 mLockPatternUtils = lockPatternUtils;
214 mKeyguardManager = keyguardManager;
215 mBroadcastDispatcher = broadcastDispatcher;
216 mContentResolver = contentResolver;
217 mResources = resources;
218 mUserManager = userManager;
219 mTrustManager = trustManager;
220 mIActivityManager = iActivityManager;
221 mTelecomManager = telecomManager;
222 mMetricsLogger = metricsLogger;
Lucas Dupin991415e2019-11-25 17:48:58 -0800223 mBlurUtils = blurUtils;
224 mSysuiColorExtractor = colorExtractor;
225 mStatusBarService = statusBarService;
226 mNotificationShadeWindowController = notificationShadeWindowController;
Matt Pietal22231792020-01-23 09:51:09 -0500227 mControlsUiController = controlsUiController;
Jason Monk361915c2017-03-21 20:33:59 -0400228
229 // receive broadcasts
230 IntentFilter filter = new IntentFilter();
231 filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
232 filter.addAction(Intent.ACTION_SCREEN_OFF);
Jayachandran C142eae02019-12-13 19:29:20 -0800233 filter.addAction(TelephonyManager.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000234 mBroadcastDispatcher.registerReceiver(mBroadcastReceiver, filter);
Jason Monk361915c2017-03-21 20:33:59 -0400235
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500236 mHasTelephony = connectivityManager.isNetworkSupported(ConnectivityManager.TYPE_MOBILE);
Jason Monk361915c2017-03-21 20:33:59 -0400237
238 // get notified of phone state changes
Jason Monk361915c2017-03-21 20:33:59 -0400239 telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE);
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500240 contentResolver.registerContentObserver(
Jason Monk361915c2017-03-21 20:33:59 -0400241 Settings.Global.getUriFor(Settings.Global.AIRPLANE_MODE_ON), true,
242 mAirplaneModeObserver);
Jason Monk361915c2017-03-21 20:33:59 -0400243 mHasVibrator = vibrator != null && vibrator.hasVibrator();
244
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500245 mShowSilentToggle = SHOW_SILENT_TOGGLE && !resources.getBoolean(
Jason Monk361915c2017-03-21 20:33:59 -0400246 R.bool.config_useFixedVolume);
247
248 mEmergencyAffordanceManager = new EmergencyAffordanceManager(context);
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500249 mScreenshotHelper = new ScreenshotHelper(context);
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400250 mScreenRecordHelper = new ScreenRecordHelper(context);
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700251
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500252 configurationController.addCallback(this);
Steve Elliott9b87a442019-03-05 10:24:16 -0500253
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500254 mActivityStarter = activityStarter;
Lucas Dupinc8f16e82019-09-17 18:24:50 -0400255 keyguardStateController.addCallback(new KeyguardStateController.Callback() {
256 @Override
257 public void onUnlockedChanged() {
258 if (mDialog != null && mDialog.mPanelController != null) {
259 boolean locked = !keyguardStateController.canDismissLockScreen();
260 mDialog.mPanelController.onDeviceLockStateChanged(locked);
261 }
262 }
263 });
Jason Monk361915c2017-03-21 20:33:59 -0400264 }
265
266 /**
267 * Show the global actions dialog (creating if necessary)
Jason Monk16fbd9d2017-04-27 14:28:49 -0400268 *
Jason Monk361915c2017-03-21 20:33:59 -0400269 * @param keyguardShowing True if keyguard is showing
270 */
Steve Elliotta3f5207922019-03-18 13:37:22 -0400271 public void showDialog(boolean keyguardShowing, boolean isDeviceProvisioned,
272 GlobalActionsPanelPlugin panelPlugin) {
Jason Monk361915c2017-03-21 20:33:59 -0400273 mKeyguardShowing = keyguardShowing;
274 mDeviceProvisioned = isDeviceProvisioned;
Steve Elliotta3f5207922019-03-18 13:37:22 -0400275 mPanelPlugin = panelPlugin;
Jason Monk361915c2017-03-21 20:33:59 -0400276 if (mDialog != null) {
277 mDialog.dismiss();
278 mDialog = null;
279 // Show delayed, so that the dismiss of the previous dialog completes
280 mHandler.sendEmptyMessage(MESSAGE_SHOW);
281 } else {
282 handleShow();
283 }
284 }
285
Charles He9851a8d2017-10-10 17:31:30 +0100286 /**
287 * Dismiss the global actions dialog, if it's currently shown
288 */
289 public void dismissDialog() {
290 mHandler.removeMessages(MESSAGE_DISMISS);
291 mHandler.sendEmptyMessage(MESSAGE_DISMISS);
292 }
293
Jason Monk361915c2017-03-21 20:33:59 -0400294 private void awakenIfNecessary() {
295 if (mDreamManager != null) {
296 try {
297 if (mDreamManager.isDreaming()) {
298 mDreamManager.awaken();
299 }
300 } catch (RemoteException e) {
301 // we tried
302 }
303 }
304 }
305
306 private void handleShow() {
307 awakenIfNecessary();
308 mDialog = createDialog();
309 prepareDialog();
310
311 // If we only have 1 item and it's a simple press action, just do this action.
312 if (mAdapter.getCount() == 1
313 && mAdapter.getItem(0) instanceof SinglePressAction
314 && !(mAdapter.getItem(0) instanceof LongPressAction)) {
315 ((SinglePressAction) mAdapter.getItem(0)).onPress();
316 } else {
317 WindowManager.LayoutParams attrs = mDialog.getWindow().getAttributes();
318 attrs.setTitle("ActionsDialog");
Adrian Roos2f05bb32018-02-19 16:42:27 +0100319 attrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
Jason Monk361915c2017-03-21 20:33:59 -0400320 mDialog.getWindow().setAttributes(attrs);
321 mDialog.show();
322 mWindowManagerFuncs.onGlobalActionsShown();
Jason Monk361915c2017-03-21 20:33:59 -0400323 }
324 }
325
326 /**
327 * Create the global actions dialog.
Jason Monk16fbd9d2017-04-27 14:28:49 -0400328 *
Jason Monk361915c2017-03-21 20:33:59 -0400329 * @return A new dialog.
330 */
331 private ActionsDialog createDialog() {
332 // Simple toggle style if there's no vibrator, otherwise use a tri-state
333 if (!mHasVibrator) {
334 mSilentModeAction = new SilentModeToggleAction();
335 } else {
Lucas Dupin40ec6b782018-06-05 19:07:16 -0700336 mSilentModeAction = new SilentModeTriStateAction(mAudioManager, mHandler);
Jason Monk361915c2017-03-21 20:33:59 -0400337 }
Aran Ink780d4502020-02-14 10:39:58 -0500338 mAirplaneModeOn = new AirplaneModeAction();
Jason Monk361915c2017-03-21 20:33:59 -0400339 onAirplaneModeChanged();
340
341 mItems = new ArrayList<Action>();
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500342 String[] defaultActions = mResources.getStringArray(R.array.config_globalActionsList);
Jason Monk361915c2017-03-21 20:33:59 -0400343
344 ArraySet<String> addedKeys = new ArraySet<String>();
345 for (int i = 0; i < defaultActions.length; i++) {
346 String actionKey = defaultActions[i];
347 if (addedKeys.contains(actionKey)) {
348 // If we already have added this, don't add it again.
349 continue;
350 }
351 if (GLOBAL_ACTION_KEY_POWER.equals(actionKey)) {
352 mItems.add(new PowerAction());
353 } else if (GLOBAL_ACTION_KEY_AIRPLANE.equals(actionKey)) {
354 mItems.add(mAirplaneModeOn);
355 } else if (GLOBAL_ACTION_KEY_BUGREPORT.equals(actionKey)) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500356 if (Settings.Global.getInt(mContentResolver,
Jason Monk361915c2017-03-21 20:33:59 -0400357 Settings.Global.BUGREPORT_IN_POWER_MENU, 0) != 0 && isCurrentUserOwner()) {
358 mItems.add(new BugReportAction());
359 }
360 } else if (GLOBAL_ACTION_KEY_SILENT.equals(actionKey)) {
361 if (mShowSilentToggle) {
362 mItems.add(mSilentModeAction);
363 }
364 } else if (GLOBAL_ACTION_KEY_USERS.equals(actionKey)) {
365 if (SystemProperties.getBoolean("fw.power_user_switcher", false)) {
366 addUsersToMenu(mItems);
367 }
368 } else if (GLOBAL_ACTION_KEY_SETTINGS.equals(actionKey)) {
369 mItems.add(getSettingsAction());
370 } else if (GLOBAL_ACTION_KEY_LOCKDOWN.equals(actionKey)) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500371 if (Settings.Secure.getIntForUser(mContentResolver,
Chad Brubaker02cd6cf2018-05-01 14:59:33 -0700372 Settings.Secure.LOCKDOWN_IN_POWER_MENU, 0, getCurrentUser().id) != 0
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800373 && shouldDisplayLockdown()) {
Chad Brubaker4f28f0d2017-09-07 14:28:13 -0700374 mItems.add(getLockdownAction());
375 }
Jason Monk361915c2017-03-21 20:33:59 -0400376 } else if (GLOBAL_ACTION_KEY_VOICEASSIST.equals(actionKey)) {
377 mItems.add(getVoiceAssistAction());
378 } else if (GLOBAL_ACTION_KEY_ASSIST.equals(actionKey)) {
379 mItems.add(getAssistAction());
380 } else if (GLOBAL_ACTION_KEY_RESTART.equals(actionKey)) {
381 mItems.add(new RestartAction());
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500382 } else if (GLOBAL_ACTION_KEY_SCREENSHOT.equals(actionKey)) {
383 mItems.add(new ScreenshotAction());
Alex Chau04458852017-11-27 18:21:23 +0000384 } else if (GLOBAL_ACTION_KEY_LOGOUT.equals(actionKey)) {
Alex Chaud7958272017-12-08 11:30:52 +0000385 if (mDevicePolicyManager.isLogoutEnabled()
Alex Chau04458852017-11-27 18:21:23 +0000386 && getCurrentUser().id != UserHandle.USER_SYSTEM) {
387 mItems.add(new LogoutAction());
Alex Chau04458852017-11-27 18:21:23 +0000388 }
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800389 } else if (GLOBAL_ACTION_KEY_EMERGENCY.equals(actionKey)) {
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400390 if (!mEmergencyAffordanceManager.needsEmergencyAffordance()) {
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800391 mItems.add(new EmergencyDialerAction());
392 }
Jason Monk361915c2017-03-21 20:33:59 -0400393 } else {
394 Log.e(TAG, "Invalid global action key " + actionKey);
395 }
396 // Add here so we don't add more than one.
397 addedKeys.add(actionKey);
398 }
399
400 if (mEmergencyAffordanceManager.needsEmergencyAffordance()) {
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400401 mItems.add(new EmergencyAffordanceAction());
Jason Monk361915c2017-03-21 20:33:59 -0400402 }
403
404 mAdapter = new MyAdapter();
405
Steve Elliott9b87a442019-03-05 10:24:16 -0500406 GlobalActionsPanelPlugin.PanelViewController panelViewController =
Steve Elliotta3f5207922019-03-18 13:37:22 -0400407 mPanelPlugin != null
408 ? mPanelPlugin.onPanelShown(
Steve Elliott4c868852019-03-14 16:25:41 -0400409 new GlobalActionsPanelPlugin.Callbacks() {
410 @Override
411 public void dismissGlobalActionsMenu() {
Steve Elliottc3147e22019-11-20 19:34:57 -0500412 dismissDialog();
Steve Elliott4c868852019-03-14 16:25:41 -0400413 }
414
415 @Override
416 public void startPendingIntentDismissingKeyguard(
417 PendingIntent intent) {
418 mActivityStarter
419 .startPendingIntentDismissingKeyguard(intent);
420 }
Steve Elliotte2a2e9b2019-04-30 21:31:03 -0400421 },
422 mKeyguardManager.isDeviceLocked())
Steve Elliott9b87a442019-03-05 10:24:16 -0500423 : null;
Steve Elliott02bbaaa2019-05-01 16:55:33 -0400424
Lucas Dupin991415e2019-11-25 17:48:58 -0800425 ActionsDialog dialog = new ActionsDialog(mContext, mAdapter, panelViewController,
426 mBlurUtils, mSysuiColorExtractor, mStatusBarService,
Matt Pietal22231792020-01-23 09:51:09 -0500427 mNotificationShadeWindowController,
Matt Pietale0661b62020-01-29 14:35:31 -0500428 shouldShowControls() ? mControlsUiController : null);
Jason Monk361915c2017-03-21 20:33:59 -0400429 dialog.setCanceledOnTouchOutside(false); // Handled by the custom class.
Lucas Dupinc1cc7592017-05-22 15:56:16 -0700430 dialog.setKeyguardShowing(mKeyguardShowing);
Jason Monk361915c2017-03-21 20:33:59 -0400431
432 dialog.setOnDismissListener(this);
Shaotang Li786da902018-08-02 11:18:00 +0800433 dialog.setOnShowListener(this);
Jason Monk361915c2017-03-21 20:33:59 -0400434
435 return dialog;
436 }
437
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800438 private boolean shouldDisplayLockdown() {
439 int userId = getCurrentUser().id;
440 // Lockdown is meaningless without a place to go.
441 if (!mKeyguardManager.isDeviceSecure(userId)) {
442 return false;
443 }
444
445 // Only show the lockdown button if the device isn't locked down (for whatever reason).
446 int state = mLockPatternUtils.getStrongAuthForUser(userId);
447 return (state == STRONG_AUTH_NOT_REQUIRED
448 || state == SOME_AUTH_REQUIRED_AFTER_USER_REQUEST);
449 }
450
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700451 @Override
452 public void onUiModeChanged() {
453 mContext.getTheme().applyStyle(mContext.getThemeResId(), true);
Lucas Dupina4e12ba2019-04-18 11:56:28 -0700454 if (mDialog != null && mDialog.isShowing()) {
Aaron Heuckroth4ef3a542019-04-01 14:17:23 -0400455 mDialog.refreshDialog();
456 }
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700457 }
458
459 public void destroy() {
460 Dependency.get(ConfigurationController.class).removeCallback(this);
461 }
462
Jason Monk361915c2017-03-21 20:33:59 -0400463 private final class PowerAction extends SinglePressAction implements LongPressAction {
464 private PowerAction() {
465 super(R.drawable.ic_lock_power_off,
Jason Monk16fbd9d2017-04-27 14:28:49 -0400466 R.string.global_action_power_off);
Jason Monk361915c2017-03-21 20:33:59 -0400467 }
468
469 @Override
470 public boolean onLongPress() {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500471 if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) {
Jason Monk361915c2017-03-21 20:33:59 -0400472 mWindowManagerFuncs.reboot(true);
473 return true;
474 }
475 return false;
476 }
477
478 @Override
479 public boolean showDuringKeyguard() {
480 return true;
481 }
482
483 @Override
484 public boolean showBeforeProvisioning() {
485 return true;
486 }
487
488 @Override
489 public void onPress() {
490 // shutdown by making sure radio and power are handled accordingly.
491 mWindowManagerFuncs.shutdown();
492 }
493 }
494
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400495 private abstract class EmergencyAction extends SinglePressAction {
496 EmergencyAction(int iconResId, int messageResId) {
497 super(iconResId, messageResId);
498 }
499
500 @Override
501 public boolean shouldBeSeparated() {
Aran Ink780d4502020-02-14 10:39:58 -0500502 return true;
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400503 }
504
505 @Override
506 public View create(
507 Context context, View convertView, ViewGroup parent, LayoutInflater inflater) {
508 View v = super.create(context, convertView, parent, inflater);
509 int textColor;
510 if (shouldBeSeparated()) {
511 textColor = v.getResources().getColor(
512 com.android.systemui.R.color.global_actions_alert_text);
513 } else {
514 textColor = v.getResources().getColor(
515 com.android.systemui.R.color.global_actions_text);
516 }
517 TextView messageView = v.findViewById(R.id.message);
518 messageView.setTextColor(textColor);
Aaron Heuckroth3f2d8b52019-04-05 13:27:51 -0400519 messageView.setSelected(true); // necessary for marquee to work
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400520 ImageView icon = (ImageView) v.findViewById(R.id.icon);
521 icon.getDrawable().setTint(textColor);
522 return v;
523 }
524
525 @Override
526 public boolean showDuringKeyguard() {
527 return true;
528 }
529
530 @Override
531 public boolean showBeforeProvisioning() {
532 return true;
533 }
534 }
535
536 private class EmergencyAffordanceAction extends EmergencyAction {
537 EmergencyAffordanceAction() {
538 super(R.drawable.emergency_icon,
539 R.string.global_action_emergency);
540 }
541
542 @Override
543 public void onPress() {
544 mEmergencyAffordanceManager.performEmergencyCall();
545 }
546 }
547
548 private class EmergencyDialerAction extends EmergencyAction {
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800549 private EmergencyDialerAction() {
Aran Ink50195262019-05-30 10:55:37 -0400550 super(com.android.systemui.R.drawable.ic_emergency_star,
Wesley.CW Wang3004fcb2018-06-15 16:24:57 +0800551 R.string.global_action_emergency);
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800552 }
553
554 @Override
555 public void onPress() {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500556 mMetricsLogger.action(MetricsEvent.ACTION_EMERGENCY_DIALER_FROM_POWER_MENU);
557 Intent intent = mTelecomManager.createLaunchEmergencyDialerIntent(null /* number */);
Leo Hsue4cc3122019-03-06 15:25:28 +0800558 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
559 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
560 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
Shaotang Li5c422632018-07-04 14:18:40 +0800561 intent.putExtra(EmergencyDialerConstants.EXTRA_ENTRY_TYPE,
562 EmergencyDialerConstants.ENTRY_TYPE_POWER_MENU);
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800563 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
564 }
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800565 }
566
Jason Monk361915c2017-03-21 20:33:59 -0400567 private final class RestartAction extends SinglePressAction implements LongPressAction {
568 private RestartAction() {
569 super(R.drawable.ic_restart, R.string.global_action_restart);
570 }
571
572 @Override
573 public boolean onLongPress() {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500574 if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) {
Jason Monk361915c2017-03-21 20:33:59 -0400575 mWindowManagerFuncs.reboot(true);
576 return true;
577 }
578 return false;
579 }
580
581 @Override
582 public boolean showDuringKeyguard() {
583 return true;
584 }
585
586 @Override
587 public boolean showBeforeProvisioning() {
588 return true;
589 }
590
591 @Override
592 public void onPress() {
593 mWindowManagerFuncs.reboot(false);
594 }
595 }
596
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400597 private class ScreenshotAction extends SinglePressAction implements LongPressAction {
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500598 public ScreenshotAction() {
599 super(R.drawable.ic_screenshot, R.string.global_action_screenshot);
600 }
601
602 @Override
603 public void onPress() {
604 // Add a little delay before executing, to give the
605 // dialog a chance to go away before it takes a
606 // screenshot.
607 // TODO: instead, omit global action dialog layer
608 mHandler.postDelayed(new Runnable() {
609 @Override
610 public void run() {
James O'Learyfa5bb7a2019-09-05 13:43:29 -0400611 mScreenshotHelper.takeScreenshot(1, true, true, mHandler, null);
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500612 mMetricsLogger.action(MetricsEvent.ACTION_SCREENSHOT_POWER_MENU);
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500613 }
614 }, 500);
615 }
616
617 @Override
618 public boolean showDuringKeyguard() {
619 return true;
620 }
621
622 @Override
623 public boolean showBeforeProvisioning() {
624 return false;
625 }
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400626
627 @Override
628 public boolean onLongPress() {
629 if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SCREENRECORD_LONG_PRESS)) {
630 mScreenRecordHelper.launchRecordPrompt();
631 } else {
632 onPress();
633 }
634 return true;
635 }
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500636 }
637
Jason Monk361915c2017-03-21 20:33:59 -0400638 private class BugReportAction extends SinglePressAction implements LongPressAction {
639
640 public BugReportAction() {
641 super(R.drawable.ic_lock_bugreport, R.string.bugreport_title);
642 }
643
644 @Override
645 public void onPress() {
646 // don't actually trigger the bugreport if we are running stability
647 // tests via monkey
648 if (ActivityManager.isUserAMonkey()) {
649 return;
650 }
651 // Add a little delay before executing, to give the
652 // dialog a chance to go away before it takes a
653 // screenshot.
654 mHandler.postDelayed(new Runnable() {
655 @Override
656 public void run() {
657 try {
658 // Take an "interactive" bugreport.
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500659 mMetricsLogger.action(
Jason Monk361915c2017-03-21 20:33:59 -0400660 MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_INTERACTIVE);
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500661 if (!mIActivityManager.launchBugReportHandlerApp()) {
Paul Changc40f5782019-11-04 18:55:31 +0800662 Log.w(TAG, "Bugreport handler could not be launched");
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500663 mIActivityManager.requestInteractiveBugReport();
Paul Changc40f5782019-11-04 18:55:31 +0800664 }
Jason Monk361915c2017-03-21 20:33:59 -0400665 } catch (RemoteException e) {
666 }
667 }
668 }, 500);
669 }
670
671 @Override
672 public boolean onLongPress() {
673 // don't actually trigger the bugreport if we are running stability
674 // tests via monkey
675 if (ActivityManager.isUserAMonkey()) {
676 return false;
677 }
678 try {
679 // Take a "full" bugreport.
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500680 mMetricsLogger.action(MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_FULL);
681 mIActivityManager.requestFullBugReport();
Jason Monk361915c2017-03-21 20:33:59 -0400682 } catch (RemoteException e) {
683 }
684 return false;
685 }
686
687 public boolean showDuringKeyguard() {
688 return true;
689 }
690
691 @Override
692 public boolean showBeforeProvisioning() {
693 return false;
694 }
Jason Monk361915c2017-03-21 20:33:59 -0400695 }
696
Alex Chau04458852017-11-27 18:21:23 +0000697 private final class LogoutAction extends SinglePressAction {
698 private LogoutAction() {
699 super(R.drawable.ic_logout, R.string.global_action_logout);
700 }
701
702 @Override
703 public boolean showDuringKeyguard() {
704 return true;
705 }
706
707 @Override
708 public boolean showBeforeProvisioning() {
709 return false;
710 }
711
712 @Override
713 public void onPress() {
714 // Add a little delay before executing, to give the dialog a chance to go away before
715 // switching user
716 mHandler.postDelayed(() -> {
717 try {
Alex Chauedb6a012018-01-26 12:52:43 +0000718 int currentUserId = getCurrentUser().id;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500719 mIActivityManager.switchUser(UserHandle.USER_SYSTEM);
720 mIActivityManager.stopUser(currentUserId, true /*force*/, null);
Alex Chau04458852017-11-27 18:21:23 +0000721 } catch (RemoteException re) {
722 Log.e(TAG, "Couldn't logout user " + re);
723 }
724 }, 500);
725 }
726 }
727
Jason Monk361915c2017-03-21 20:33:59 -0400728 private Action getSettingsAction() {
729 return new SinglePressAction(R.drawable.ic_settings,
730 R.string.global_action_settings) {
731
732 @Override
733 public void onPress() {
734 Intent intent = new Intent(Settings.ACTION_SETTINGS);
735 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
736 mContext.startActivity(intent);
737 }
738
739 @Override
740 public boolean showDuringKeyguard() {
741 return true;
742 }
743
744 @Override
745 public boolean showBeforeProvisioning() {
746 return true;
747 }
748 };
749 }
750
Jason Monk361915c2017-03-21 20:33:59 -0400751 private Action getAssistAction() {
752 return new SinglePressAction(R.drawable.ic_action_assist_focused,
753 R.string.global_action_assist) {
754 @Override
755 public void onPress() {
756 Intent intent = new Intent(Intent.ACTION_ASSIST);
757 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
758 mContext.startActivity(intent);
759 }
760
761 @Override
762 public boolean showDuringKeyguard() {
763 return true;
764 }
765
766 @Override
767 public boolean showBeforeProvisioning() {
768 return true;
769 }
770 };
771 }
772
773 private Action getVoiceAssistAction() {
774 return new SinglePressAction(R.drawable.ic_voice_search,
775 R.string.global_action_voice_assist) {
776 @Override
777 public void onPress() {
778 Intent intent = new Intent(Intent.ACTION_VOICE_ASSIST);
779 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
780 mContext.startActivity(intent);
781 }
782
783 @Override
784 public boolean showDuringKeyguard() {
785 return true;
786 }
787
788 @Override
789 public boolean showBeforeProvisioning() {
790 return true;
791 }
792 };
793 }
794
795 private Action getLockdownAction() {
Alison Cichowlas21125432018-05-16 15:40:45 -0400796 return new SinglePressAction(R.drawable.ic_lock_lockdown,
Jason Monk361915c2017-03-21 20:33:59 -0400797 R.string.global_action_lockdown) {
798
799 @Override
800 public void onPress() {
Chad Brubaker4f28f0d2017-09-07 14:28:13 -0700801 new LockPatternUtils(mContext)
802 .requireStrongAuth(STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN,
803 UserHandle.USER_ALL);
Jason Monk361915c2017-03-21 20:33:59 -0400804 try {
805 WindowManagerGlobal.getWindowManagerService().lockNow(null);
Pavel Grafov059021b2018-05-02 13:44:46 +0100806 // Lock profiles (if any) on the background thread.
807 final Handler bgHandler = new Handler(Dependency.get(Dependency.BG_LOOPER));
808 bgHandler.post(() -> lockProfiles());
Jason Monk361915c2017-03-21 20:33:59 -0400809 } catch (RemoteException e) {
810 Log.e(TAG, "Error while trying to lock device.", e);
811 }
812 }
813
814 @Override
815 public boolean showDuringKeyguard() {
816 return true;
817 }
818
819 @Override
820 public boolean showBeforeProvisioning() {
821 return false;
822 }
823 };
824 }
825
Pavel Grafov059021b2018-05-02 13:44:46 +0100826 private void lockProfiles() {
Pavel Grafov059021b2018-05-02 13:44:46 +0100827 final int currentUserId = getCurrentUser().id;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500828 final int[] profileIds = mUserManager.getEnabledProfileIds(currentUserId);
Pavel Grafov059021b2018-05-02 13:44:46 +0100829 for (final int id : profileIds) {
830 if (id != currentUserId) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500831 mTrustManager.setDeviceLockedForUser(id, true);
Pavel Grafov059021b2018-05-02 13:44:46 +0100832 }
833 }
834 }
835
Jason Monk361915c2017-03-21 20:33:59 -0400836 private UserInfo getCurrentUser() {
837 try {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500838 return mIActivityManager.getCurrentUser();
Jason Monk361915c2017-03-21 20:33:59 -0400839 } catch (RemoteException re) {
840 return null;
841 }
842 }
843
844 private boolean isCurrentUserOwner() {
845 UserInfo currentUser = getCurrentUser();
846 return currentUser == null || currentUser.isPrimary();
847 }
848
849 private void addUsersToMenu(ArrayList<Action> items) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500850 if (mUserManager.isUserSwitcherEnabled()) {
851 List<UserInfo> users = mUserManager.getUsers();
Jason Monk361915c2017-03-21 20:33:59 -0400852 UserInfo currentUser = getCurrentUser();
853 for (final UserInfo user : users) {
854 if (user.supportsSwitchToByUser()) {
855 boolean isCurrentUser = currentUser == null
856 ? user.id == 0 : (currentUser.id == user.id);
857 Drawable icon = user.iconPath != null ? Drawable.createFromPath(user.iconPath)
858 : null;
859 SinglePressAction switchToUser = new SinglePressAction(
860 R.drawable.ic_menu_cc, icon,
861 (user.name != null ? user.name : "Primary")
Jason Monk16fbd9d2017-04-27 14:28:49 -0400862 + (isCurrentUser ? " \u2714" : "")) {
Jason Monk361915c2017-03-21 20:33:59 -0400863 public void onPress() {
864 try {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500865 mIActivityManager.switchUser(user.id);
Jason Monk361915c2017-03-21 20:33:59 -0400866 } catch (RemoteException re) {
867 Log.e(TAG, "Couldn't switch user " + re);
868 }
869 }
870
871 public boolean showDuringKeyguard() {
872 return true;
873 }
874
875 public boolean showBeforeProvisioning() {
876 return false;
877 }
878 };
879 items.add(switchToUser);
880 }
881 }
882 }
883 }
884
885 private void prepareDialog() {
886 refreshSilentMode();
887 mAirplaneModeOn.updateState(mAirplaneState);
888 mAdapter.notifyDataSetChanged();
Jason Monk361915c2017-03-21 20:33:59 -0400889 if (mShowSilentToggle) {
890 IntentFilter filter = new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION);
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000891 mBroadcastDispatcher.registerReceiver(mRingerModeReceiver, filter);
Jason Monk361915c2017-03-21 20:33:59 -0400892 }
893 }
894
895 private void refreshSilentMode() {
896 if (!mHasVibrator) {
897 final boolean silentModeOn =
898 mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL;
Jason Monk16fbd9d2017-04-27 14:28:49 -0400899 ((ToggleAction) mSilentModeAction).updateState(
Jason Monk361915c2017-03-21 20:33:59 -0400900 silentModeOn ? ToggleAction.State.On : ToggleAction.State.Off);
901 }
902 }
903
904 /** {@inheritDoc} */
905 public void onDismiss(DialogInterface dialog) {
Steve Elliottc3147e22019-11-20 19:34:57 -0500906 if (mDialog == dialog) {
907 mDialog = null;
908 }
Jason Monk361915c2017-03-21 20:33:59 -0400909 mWindowManagerFuncs.onGlobalActionsHidden();
910 if (mShowSilentToggle) {
911 try {
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000912 mBroadcastDispatcher.unregisterReceiver(mRingerModeReceiver);
Jason Monk361915c2017-03-21 20:33:59 -0400913 } catch (IllegalArgumentException ie) {
914 // ignore this
915 Log.w(TAG, ie);
916 }
917 }
918 }
919
920 /** {@inheritDoc} */
Shaotang Li786da902018-08-02 11:18:00 +0800921 public void onShow(DialogInterface dialog) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500922 mMetricsLogger.visible(MetricsEvent.POWER_MENU);
Shaotang Li786da902018-08-02 11:18:00 +0800923 }
924
Jason Monk361915c2017-03-21 20:33:59 -0400925 /**
926 * The adapter used for the list within the global actions dialog, taking
927 * into account whether the keyguard is showing via
Jason Monk16fbd9d2017-04-27 14:28:49 -0400928 * {@link com.android.systemui.globalactions.GlobalActionsDialog#mKeyguardShowing} and whether
929 * the device is provisioned
Jason Monk361915c2017-03-21 20:33:59 -0400930 * via {@link com.android.systemui.globalactions.GlobalActionsDialog#mDeviceProvisioned}.
931 */
Aaron Heuckroth57d60d22019-03-05 14:00:12 -0500932 public class MyAdapter extends MultiListAdapter {
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -0400933 private int countItems(boolean separated) {
Jason Monk361915c2017-03-21 20:33:59 -0400934 int count = 0;
Jason Monk361915c2017-03-21 20:33:59 -0400935 for (int i = 0; i < mItems.size(); i++) {
936 final Action action = mItems.get(i);
937
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -0400938 if (shouldBeShown(action) && action.shouldBeSeparated() == separated) {
939 count++;
Jason Monk361915c2017-03-21 20:33:59 -0400940 }
Jason Monk361915c2017-03-21 20:33:59 -0400941 }
942 return count;
943 }
944
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -0400945 private boolean shouldBeShown(Action action) {
946 if (mKeyguardShowing && !action.showDuringKeyguard()) {
947 return false;
948 }
949 if (!mDeviceProvisioned && !action.showBeforeProvisioning()) {
950 return false;
951 }
952 return true;
953 }
954
955 @Override
956 public int countSeparatedItems() {
957 return countItems(true);
958 }
959
960 @Override
961 public int countListItems() {
962 return countItems(false);
963 }
964
965 @Override
966 public int getCount() {
967 return countSeparatedItems() + countListItems();
968 }
969
Jason Monk361915c2017-03-21 20:33:59 -0400970 @Override
971 public boolean isEnabled(int position) {
972 return getItem(position).isEnabled();
973 }
974
Aaron Heuckroth57d60d22019-03-05 14:00:12 -0500975 @Override
Jason Monk361915c2017-03-21 20:33:59 -0400976 public boolean areAllItemsEnabled() {
977 return false;
978 }
979
Aaron Heuckroth57d60d22019-03-05 14:00:12 -0500980 @Override
Jason Monk361915c2017-03-21 20:33:59 -0400981 public Action getItem(int position) {
Jason Monk361915c2017-03-21 20:33:59 -0400982 int filteredPos = 0;
983 for (int i = 0; i < mItems.size(); i++) {
984 final Action action = mItems.get(i);
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -0400985 if (!shouldBeShown(action)) {
Jason Monk361915c2017-03-21 20:33:59 -0400986 continue;
987 }
988 if (filteredPos == position) {
989 return action;
990 }
991 filteredPos++;
992 }
993
994 throw new IllegalArgumentException("position " + position
995 + " out of range of showable actions"
996 + ", filtered count=" + getCount()
997 + ", keyguardshowing=" + mKeyguardShowing
998 + ", provisioned=" + mDeviceProvisioned);
999 }
1000
1001
1002 public long getItemId(int position) {
1003 return position;
1004 }
1005
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001006 @Override
Jason Monk361915c2017-03-21 20:33:59 -04001007 public View getView(int position, View convertView, ViewGroup parent) {
1008 Action action = getItem(position);
Jason Monk16fbd9d2017-04-27 14:28:49 -04001009 View view = action.create(mContext, convertView, parent, LayoutInflater.from(mContext));
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -04001010 view.setOnClickListener(v -> onClickItem(position));
Aran Inkb4199d92020-02-07 13:25:21 -05001011 if (action instanceof LongPressAction) {
1012 view.setOnLongClickListener(v -> onLongClickItem(position));
1013 }
Jason Monk16fbd9d2017-04-27 14:28:49 -04001014 return view;
Jason Monk361915c2017-03-21 20:33:59 -04001015 }
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001016
1017 @Override
1018 public boolean onLongClickItem(int position) {
1019 final Action action = mAdapter.getItem(position);
1020 if (action instanceof LongPressAction) {
Aran Inkbaa25862019-06-11 15:48:55 -04001021 if (mDialog != null) {
1022 mDialog.dismiss();
1023 } else {
1024 Log.w(TAG, "Action long-clicked while mDialog is null.");
1025 }
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001026 return ((LongPressAction) action).onLongPress();
1027 }
1028 return false;
1029 }
1030
1031 @Override
1032 public void onClickItem(int position) {
1033 Action item = mAdapter.getItem(position);
1034 if (!(item instanceof SilentModeTriStateAction)) {
Aran Inkbaa25862019-06-11 15:48:55 -04001035 if (mDialog != null) {
1036 mDialog.dismiss();
1037 } else {
1038 Log.w(TAG, "Action clicked while mDialog is null.");
1039 }
1040 item.onPress();
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001041 }
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001042 }
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -04001043
1044 @Override
1045 public boolean shouldBeSeparated(int position) {
1046 return getItem(position).shouldBeSeparated();
1047 }
Jason Monk361915c2017-03-21 20:33:59 -04001048 }
1049
1050 // note: the scheme below made more sense when we were planning on having
1051 // 8 different things in the global actions dialog. seems overkill with
1052 // only 3 items now, but may as well keep this flexible approach so it will
1053 // be easy should someone decide at the last minute to include something
1054 // else, such as 'enable wifi', or 'enable bluetooth'
1055
1056 /**
1057 * What each item in the global actions dialog must be able to support.
1058 */
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001059 public interface Action {
Jason Monk361915c2017-03-21 20:33:59 -04001060 /**
1061 * @return Text that will be announced when dialog is created. null
Jason Monk16fbd9d2017-04-27 14:28:49 -04001062 * for none.
Jason Monk361915c2017-03-21 20:33:59 -04001063 */
1064 CharSequence getLabelForAccessibility(Context context);
1065
1066 View create(Context context, View convertView, ViewGroup parent, LayoutInflater inflater);
1067
1068 void onPress();
1069
1070 /**
1071 * @return whether this action should appear in the dialog when the keygaurd
Jason Monk16fbd9d2017-04-27 14:28:49 -04001072 * is showing.
Jason Monk361915c2017-03-21 20:33:59 -04001073 */
1074 boolean showDuringKeyguard();
1075
1076 /**
1077 * @return whether this action should appear in the dialog before the
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001078 * device is provisioned.onlongpress
1079 *
Jason Monk361915c2017-03-21 20:33:59 -04001080 */
1081 boolean showBeforeProvisioning();
1082
1083 boolean isEnabled();
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001084
1085 default boolean shouldBeSeparated() {
1086 return false;
1087 }
Jason Monk361915c2017-03-21 20:33:59 -04001088 }
1089
1090 /**
1091 * An action that also supports long press.
1092 */
1093 private interface LongPressAction extends Action {
1094 boolean onLongPress();
1095 }
1096
1097 /**
1098 * A single press action maintains no state, just responds to a press
1099 * and takes an action.
1100 */
Matt Pietale0661b62020-01-29 14:35:31 -05001101
1102 private abstract class SinglePressAction implements Action {
Jason Monk361915c2017-03-21 20:33:59 -04001103 private final int mIconResId;
1104 private final Drawable mIcon;
1105 private final int mMessageResId;
1106 private final CharSequence mMessage;
1107
1108 protected SinglePressAction(int iconResId, int messageResId) {
1109 mIconResId = iconResId;
1110 mMessageResId = messageResId;
1111 mMessage = null;
1112 mIcon = null;
1113 }
1114
1115 protected SinglePressAction(int iconResId, Drawable icon, CharSequence message) {
1116 mIconResId = iconResId;
1117 mMessageResId = 0;
1118 mMessage = message;
1119 mIcon = icon;
1120 }
1121
1122 public boolean isEnabled() {
1123 return true;
1124 }
1125
1126 public String getStatus() {
1127 return null;
1128 }
1129
1130 abstract public void onPress();
1131
1132 public CharSequence getLabelForAccessibility(Context context) {
1133 if (mMessage != null) {
1134 return mMessage;
1135 } else {
1136 return context.getString(mMessageResId);
1137 }
1138 }
1139
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001140 protected int getActionLayoutId(Context context) {
Matt Pietale0661b62020-01-29 14:35:31 -05001141 if (shouldShowControls()) {
Matt Pietalfd3b6cb2020-01-08 09:43:54 -05001142 return com.android.systemui.R.layout.global_actions_grid_item_v2;
1143 }
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001144 return com.android.systemui.R.layout.global_actions_grid_item;
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001145 }
1146
Jason Monk361915c2017-03-21 20:33:59 -04001147 public View create(
1148 Context context, View convertView, ViewGroup parent, LayoutInflater inflater) {
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001149 View v = inflater.inflate(getActionLayoutId(context), parent,
Jason Monk16fbd9d2017-04-27 14:28:49 -04001150 false);
Jason Monk361915c2017-03-21 20:33:59 -04001151
1152 ImageView icon = (ImageView) v.findViewById(R.id.icon);
1153 TextView messageView = (TextView) v.findViewById(R.id.message);
Aaron Heuckroth3f2d8b52019-04-05 13:27:51 -04001154 messageView.setSelected(true); // necessary for marquee to work
Jason Monk361915c2017-03-21 20:33:59 -04001155
Jason Monk361915c2017-03-21 20:33:59 -04001156 if (mIcon != null) {
1157 icon.setImageDrawable(mIcon);
1158 icon.setScaleType(ScaleType.CENTER_CROP);
1159 } else if (mIconResId != 0) {
1160 icon.setImageDrawable(context.getDrawable(mIconResId));
1161 }
1162 if (mMessage != null) {
1163 messageView.setText(mMessage);
1164 } else {
1165 messageView.setText(mMessageResId);
1166 }
1167
1168 return v;
1169 }
1170 }
1171
1172 /**
1173 * A toggle action knows whether it is on or off, and displays an icon
1174 * and status message accordingly.
1175 */
1176 private static abstract class ToggleAction implements Action {
1177
1178 enum State {
1179 Off(false),
1180 TurningOn(true),
1181 TurningOff(true),
1182 On(false);
1183
1184 private final boolean inTransition;
1185
1186 State(boolean intermediate) {
1187 inTransition = intermediate;
1188 }
1189
1190 public boolean inTransition() {
1191 return inTransition;
1192 }
1193 }
1194
1195 protected State mState = State.Off;
1196
1197 // prefs
1198 protected int mEnabledIconResId;
1199 protected int mDisabledIconResid;
1200 protected int mMessageResId;
1201 protected int mEnabledStatusMessageResId;
1202 protected int mDisabledStatusMessageResId;
1203
1204 /**
Jason Monk16fbd9d2017-04-27 14:28:49 -04001205 * @param enabledIconResId The icon for when this action is on.
1206 * @param disabledIconResid The icon for when this action is off.
1207 * @param message The general information message, e.g 'Silent Mode'
1208 * @param enabledStatusMessageResId The on status message, e.g 'sound disabled'
Jason Monk361915c2017-03-21 20:33:59 -04001209 * @param disabledStatusMessageResId The off status message, e.g. 'sound enabled'
1210 */
1211 public ToggleAction(int enabledIconResId,
1212 int disabledIconResid,
1213 int message,
1214 int enabledStatusMessageResId,
1215 int disabledStatusMessageResId) {
1216 mEnabledIconResId = enabledIconResId;
1217 mDisabledIconResid = disabledIconResid;
1218 mMessageResId = message;
1219 mEnabledStatusMessageResId = enabledStatusMessageResId;
1220 mDisabledStatusMessageResId = disabledStatusMessageResId;
1221 }
1222
1223 /**
1224 * Override to make changes to resource IDs just before creating the
1225 * View.
1226 */
1227 void willCreate() {
1228
1229 }
1230
1231 @Override
1232 public CharSequence getLabelForAccessibility(Context context) {
1233 return context.getString(mMessageResId);
1234 }
1235
1236 public View create(Context context, View convertView, ViewGroup parent,
1237 LayoutInflater inflater) {
1238 willCreate();
1239
Koji Fukui5c010ee2019-12-24 16:12:07 +09001240 View v = inflater.inflate(com.android.systemui.R
1241 .layout.global_actions_grid_item, parent, false);
Jason Monk361915c2017-03-21 20:33:59 -04001242
1243 ImageView icon = (ImageView) v.findViewById(R.id.icon);
1244 TextView messageView = (TextView) v.findViewById(R.id.message);
Jason Monk361915c2017-03-21 20:33:59 -04001245 final boolean enabled = isEnabled();
Koji Fukui5c010ee2019-12-24 16:12:07 +09001246 boolean on = ((mState == State.On) || (mState == State.TurningOn));
Jason Monk361915c2017-03-21 20:33:59 -04001247
1248 if (messageView != null) {
Koji Fukui5c010ee2019-12-24 16:12:07 +09001249 messageView.setText(on ? mEnabledStatusMessageResId : mDisabledStatusMessageResId);
Jason Monk361915c2017-03-21 20:33:59 -04001250 messageView.setEnabled(enabled);
Aaron Heuckroth3f2d8b52019-04-05 13:27:51 -04001251 messageView.setSelected(true); // necessary for marquee to work
Jason Monk361915c2017-03-21 20:33:59 -04001252 }
1253
Jason Monk361915c2017-03-21 20:33:59 -04001254 if (icon != null) {
1255 icon.setImageDrawable(context.getDrawable(
1256 (on ? mEnabledIconResId : mDisabledIconResid)));
1257 icon.setEnabled(enabled);
1258 }
1259
Jason Monk361915c2017-03-21 20:33:59 -04001260 v.setEnabled(enabled);
1261
1262 return v;
1263 }
1264
1265 public final void onPress() {
1266 if (mState.inTransition()) {
1267 Log.w(TAG, "shouldn't be able to toggle when in transition");
1268 return;
1269 }
1270
1271 final boolean nowOn = !(mState == State.On);
1272 onToggle(nowOn);
1273 changeStateFromPress(nowOn);
1274 }
1275
1276 public boolean isEnabled() {
1277 return !mState.inTransition();
1278 }
1279
1280 /**
1281 * Implementations may override this if their state can be in on of the intermediate
1282 * states until some notification is received (e.g airplane mode is 'turning off' until
1283 * we know the wireless connections are back online
Jason Monk16fbd9d2017-04-27 14:28:49 -04001284 *
Jason Monk361915c2017-03-21 20:33:59 -04001285 * @param buttonOn Whether the button was turned on or off
1286 */
1287 protected void changeStateFromPress(boolean buttonOn) {
1288 mState = buttonOn ? State.On : State.Off;
1289 }
1290
1291 abstract void onToggle(boolean on);
1292
1293 public void updateState(State state) {
1294 mState = state;
1295 }
1296 }
1297
Aran Ink780d4502020-02-14 10:39:58 -05001298 private class AirplaneModeAction extends ToggleAction {
1299 AirplaneModeAction() {
1300 super(
1301 R.drawable.ic_lock_airplane_mode,
1302 R.drawable.ic_lock_airplane_mode_off,
1303 R.string.global_actions_toggle_airplane_mode,
1304 R.string.global_actions_airplane_mode_on_status,
1305 R.string.global_actions_airplane_mode_off_status);
1306 }
1307 void onToggle(boolean on) {
1308 if (mHasTelephony && TelephonyProperties.in_ecm_mode().orElse(false)) {
1309 mIsWaitingForEcmExit = true;
1310 // Launch ECM exit dialog
1311 Intent ecmDialogIntent =
1312 new Intent(TelephonyManager.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null);
1313 ecmDialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1314 mContext.startActivity(ecmDialogIntent);
1315 } else {
1316 changeAirplaneModeSystemSetting(on);
1317 }
1318 }
1319
1320 @Override
1321 protected void changeStateFromPress(boolean buttonOn) {
1322 if (!mHasTelephony) return;
1323
1324 // In ECM mode airplane state cannot be changed
1325 if (!TelephonyProperties.in_ecm_mode().orElse(false)) {
1326 mState = buttonOn ? State.TurningOn : State.TurningOff;
1327 mAirplaneState = mState;
1328 }
1329 }
1330
1331 public boolean showDuringKeyguard() {
1332 return true;
1333 }
1334
1335 public boolean showBeforeProvisioning() {
1336 return false;
1337 }
1338 }
1339
Jason Monk361915c2017-03-21 20:33:59 -04001340 private class SilentModeToggleAction extends ToggleAction {
1341 public SilentModeToggleAction() {
1342 super(R.drawable.ic_audio_vol_mute,
1343 R.drawable.ic_audio_vol,
1344 R.string.global_action_toggle_silent_mode,
1345 R.string.global_action_silent_mode_on_status,
1346 R.string.global_action_silent_mode_off_status);
1347 }
1348
1349 void onToggle(boolean on) {
1350 if (on) {
1351 mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
1352 } else {
1353 mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
1354 }
1355 }
1356
1357 public boolean showDuringKeyguard() {
1358 return true;
1359 }
1360
1361 public boolean showBeforeProvisioning() {
1362 return false;
1363 }
1364 }
1365
1366 private static class SilentModeTriStateAction implements Action, View.OnClickListener {
1367
Jason Monk16fbd9d2017-04-27 14:28:49 -04001368 private final int[] ITEM_IDS = {R.id.option1, R.id.option2, R.id.option3};
Jason Monk361915c2017-03-21 20:33:59 -04001369
1370 private final AudioManager mAudioManager;
1371 private final Handler mHandler;
Jason Monk361915c2017-03-21 20:33:59 -04001372
Lucas Dupin40ec6b782018-06-05 19:07:16 -07001373 SilentModeTriStateAction(AudioManager audioManager, Handler handler) {
Jason Monk361915c2017-03-21 20:33:59 -04001374 mAudioManager = audioManager;
1375 mHandler = handler;
Jason Monk361915c2017-03-21 20:33:59 -04001376 }
1377
1378 private int ringerModeToIndex(int ringerMode) {
1379 // They just happen to coincide
1380 return ringerMode;
1381 }
1382
1383 private int indexToRingerMode(int index) {
1384 // They just happen to coincide
1385 return index;
1386 }
1387
1388 @Override
1389 public CharSequence getLabelForAccessibility(Context context) {
1390 return null;
1391 }
1392
1393 public View create(Context context, View convertView, ViewGroup parent,
1394 LayoutInflater inflater) {
1395 View v = inflater.inflate(R.layout.global_actions_silent_mode, parent, false);
1396
1397 int selectedIndex = ringerModeToIndex(mAudioManager.getRingerMode());
1398 for (int i = 0; i < 3; i++) {
1399 View itemView = v.findViewById(ITEM_IDS[i]);
1400 itemView.setSelected(selectedIndex == i);
1401 // Set up click handler
1402 itemView.setTag(i);
1403 itemView.setOnClickListener(this);
1404 }
1405 return v;
1406 }
1407
1408 public void onPress() {
1409 }
1410
1411 public boolean showDuringKeyguard() {
1412 return true;
1413 }
1414
1415 public boolean showBeforeProvisioning() {
1416 return false;
1417 }
1418
1419 public boolean isEnabled() {
1420 return true;
1421 }
1422
1423 void willCreate() {
1424 }
1425
1426 public void onClick(View v) {
1427 if (!(v.getTag() instanceof Integer)) return;
1428
1429 int index = (Integer) v.getTag();
1430 mAudioManager.setRingerMode(indexToRingerMode(index));
1431 mHandler.sendEmptyMessageDelayed(MESSAGE_DISMISS, DIALOG_DISMISS_DELAY);
1432 }
1433 }
1434
1435 private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
1436 public void onReceive(Context context, Intent intent) {
1437 String action = intent.getAction();
1438 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)
1439 || Intent.ACTION_SCREEN_OFF.equals(action)) {
1440 String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY);
1441 if (!SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS.equals(reason)) {
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001442 mHandler.sendMessage(mHandler.obtainMessage(MESSAGE_DISMISS, reason));
Jason Monk361915c2017-03-21 20:33:59 -04001443 }
Jayachandran C142eae02019-12-13 19:29:20 -08001444 } else if (TelephonyManager.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED.equals(action)) {
Jason Monk361915c2017-03-21 20:33:59 -04001445 // Airplane mode can be changed after ECM exits if airplane toggle button
1446 // is pressed during ECM mode
Daniel Bright4bcbfce2020-01-09 21:58:16 -08001447 if (!(intent.getBooleanExtra(TelephonyManager.EXTRA_PHONE_IN_ECM_STATE, false))
1448 && mIsWaitingForEcmExit) {
Jason Monk361915c2017-03-21 20:33:59 -04001449 mIsWaitingForEcmExit = false;
1450 changeAirplaneModeSystemSetting(true);
1451 }
1452 }
1453 }
1454 };
1455
1456 PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
1457 @Override
1458 public void onServiceStateChanged(ServiceState serviceState) {
1459 if (!mHasTelephony) return;
1460 final boolean inAirplaneMode = serviceState.getState() == ServiceState.STATE_POWER_OFF;
1461 mAirplaneState = inAirplaneMode ? ToggleAction.State.On : ToggleAction.State.Off;
1462 mAirplaneModeOn.updateState(mAirplaneState);
1463 mAdapter.notifyDataSetChanged();
1464 }
1465 };
1466
1467 private BroadcastReceiver mRingerModeReceiver = new BroadcastReceiver() {
1468 @Override
1469 public void onReceive(Context context, Intent intent) {
1470 if (intent.getAction().equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
1471 mHandler.sendEmptyMessage(MESSAGE_REFRESH);
1472 }
1473 }
1474 };
1475
1476 private ContentObserver mAirplaneModeObserver = new ContentObserver(new Handler()) {
1477 @Override
1478 public void onChange(boolean selfChange) {
1479 onAirplaneModeChanged();
1480 }
1481 };
1482
1483 private static final int MESSAGE_DISMISS = 0;
1484 private static final int MESSAGE_REFRESH = 1;
1485 private static final int MESSAGE_SHOW = 2;
1486 private static final int DIALOG_DISMISS_DELAY = 300; // ms
1487
1488 private Handler mHandler = new Handler() {
1489 public void handleMessage(Message msg) {
1490 switch (msg.what) {
Jason Monk16fbd9d2017-04-27 14:28:49 -04001491 case MESSAGE_DISMISS:
1492 if (mDialog != null) {
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001493 if (SYSTEM_DIALOG_REASON_DREAM.equals(msg.obj)) {
1494 mDialog.dismissImmediately();
1495 } else {
1496 mDialog.dismiss();
1497 }
Jason Monk16fbd9d2017-04-27 14:28:49 -04001498 mDialog = null;
1499 }
1500 break;
1501 case MESSAGE_REFRESH:
1502 refreshSilentMode();
1503 mAdapter.notifyDataSetChanged();
1504 break;
1505 case MESSAGE_SHOW:
1506 handleShow();
1507 break;
Jason Monk361915c2017-03-21 20:33:59 -04001508 }
1509 }
1510 };
1511
1512 private void onAirplaneModeChanged() {
1513 // Let the service state callbacks handle the state.
1514 if (mHasTelephony) return;
1515
1516 boolean airplaneModeOn = Settings.Global.getInt(
Dave Mankoffc88a2d72020-01-10 15:59:31 -05001517 mContentResolver,
Jason Monk361915c2017-03-21 20:33:59 -04001518 Settings.Global.AIRPLANE_MODE_ON,
1519 0) == 1;
1520 mAirplaneState = airplaneModeOn ? ToggleAction.State.On : ToggleAction.State.Off;
1521 mAirplaneModeOn.updateState(mAirplaneState);
1522 }
1523
1524 /**
1525 * Change the airplane mode system setting
1526 */
1527 private void changeAirplaneModeSystemSetting(boolean on) {
1528 Settings.Global.putInt(
Dave Mankoffc88a2d72020-01-10 15:59:31 -05001529 mContentResolver,
Jason Monk361915c2017-03-21 20:33:59 -04001530 Settings.Global.AIRPLANE_MODE_ON,
1531 on ? 1 : 0);
1532 Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
1533 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
1534 intent.putExtra("state", on);
1535 mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
1536 if (!mHasTelephony) {
1537 mAirplaneState = on ? ToggleAction.State.On : ToggleAction.State.Off;
1538 }
1539 }
1540
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001541 private static final class ActionsDialog extends Dialog implements DialogInterface,
1542 ColorExtractor.OnColorsChangedListener {
Jason Monk361915c2017-03-21 20:33:59 -04001543
Jason Monk16fbd9d2017-04-27 14:28:49 -04001544 private final Context mContext;
1545 private final MyAdapter mAdapter;
Steve Elliott53f12ae2019-05-13 17:14:15 -04001546 private final IStatusBarService mStatusBarService;
1547 private final IBinder mToken = new Binder();
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001548 private MultiListLayout mGlobalActionsLayout;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001549 private Drawable mBackgroundDrawable;
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001550 private final SysuiColorExtractor mColorExtractor;
Steve Elliott9b87a442019-03-05 10:24:16 -05001551 private final GlobalActionsPanelPlugin.PanelViewController mPanelController;
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001552 private boolean mKeyguardShowing;
Beverly526d2d62018-08-15 12:55:33 -04001553 private boolean mShowing;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001554 private float mScrimAlpha;
Steve Elliott48f75db2019-05-03 15:03:38 -04001555 private ResetOrientationData mResetOrientationData;
Steve Elliottff2c0d92019-07-30 15:09:54 -04001556 private boolean mHadTopUi;
wilsonshihe8321942019-10-18 18:39:46 +08001557 private final NotificationShadeWindowController mNotificationShadeWindowController;
Lucas Dupin991415e2019-11-25 17:48:58 -08001558 private final BlurUtils mBlurUtils;
Matt Pietal22231792020-01-23 09:51:09 -05001559
1560 private ControlsUiController mControlsUiController;
1561 private ViewGroup mControlsView;
Aran Ink780d4502020-02-14 10:39:58 -05001562 private ViewGroup mContainerView;
Jason Monk16fbd9d2017-04-27 14:28:49 -04001563
Aaron Heuckrothf19d2722019-03-11 17:06:02 -04001564 ActionsDialog(Context context, MyAdapter adapter,
Lucas Dupin991415e2019-11-25 17:48:58 -08001565 GlobalActionsPanelPlugin.PanelViewController plugin, BlurUtils blurUtils,
1566 SysuiColorExtractor sysuiColorExtractor, IStatusBarService statusBarService,
1567 NotificationShadeWindowController notificationShadeWindowController,
Matt Pietal22231792020-01-23 09:51:09 -05001568 ControlsUiController controlsUiController) {
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001569 super(context, com.android.systemui.R.style.Theme_SystemUI_Dialog_GlobalActions);
Lucas Dupin448786c2017-07-24 17:44:25 -07001570 mContext = context;
Jason Monk16fbd9d2017-04-27 14:28:49 -04001571 mAdapter = adapter;
Lucas Dupin991415e2019-11-25 17:48:58 -08001572 mBlurUtils = blurUtils;
1573 mColorExtractor = sysuiColorExtractor;
1574 mStatusBarService = statusBarService;
1575 mNotificationShadeWindowController = notificationShadeWindowController;
Matt Pietal22231792020-01-23 09:51:09 -05001576 mControlsUiController = controlsUiController;
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001577
1578 // Window initialization
1579 Window window = getWindow();
1580 window.requestFeature(Window.FEATURE_NO_TITLE);
Adrian Roosedfab3b2018-03-08 18:39:20 +01001581 // Inflate the decor view, so the attributes below are not overwritten by the theme.
1582 window.getDecorView();
1583 window.getAttributes().systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1584 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1585 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1586 window.setLayout(MATCH_PARENT, MATCH_PARENT);
1587 window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
Alison Cichowlas4f19f4a2017-07-25 10:56:16 -04001588 window.addFlags(
1589 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001590 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
Adrian Roosedfab3b2018-03-08 18:39:20 +01001591 | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001592 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
1593 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
1594 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001595 window.setType(WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY);
Tiger Huang52724442020-01-20 21:38:42 +08001596 window.getAttributes().setFitInsetsTypes(0 /* types */);
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001597 setTitle(R.string.global_actions);
Steve Elliott9b87a442019-03-05 10:24:16 -05001598
1599 mPanelController = plugin;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001600 initializeLayout();
Steve Elliott9b87a442019-03-05 10:24:16 -05001601 }
1602
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001603 private boolean shouldUsePanel() {
Aran Ink3f594552019-05-13 14:29:35 -04001604 return mPanelController != null && mPanelController.getPanelContent() != null;
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001605 }
1606
1607 private void initializePanel() {
Steve Elliott48f75db2019-05-03 15:03:38 -04001608 int rotation = RotationUtils.getRotation(mContext);
1609 boolean rotationLocked = RotationPolicy.isRotationLocked(mContext);
1610 if (rotation != RotationUtils.ROTATION_NONE) {
1611 if (rotationLocked) {
1612 if (mResetOrientationData == null) {
1613 mResetOrientationData = new ResetOrientationData();
1614 mResetOrientationData.locked = true;
1615 mResetOrientationData.rotation = rotation;
1616 }
1617
1618 // Unlock rotation, so user can choose to rotate to portrait to see the panel.
Steve Elliotte05817f2019-05-17 14:39:53 -04001619 // This call is posted so that the rotation does not change until post-layout,
1620 // otherwise onConfigurationChanged() may not get invoked.
1621 mGlobalActionsLayout.post(() ->
1622 RotationPolicy.setRotationLockAtAngle(
1623 mContext, false, RotationUtils.ROTATION_NONE));
Steve Elliott48f75db2019-05-03 15:03:38 -04001624 }
1625 } else {
1626 if (!rotationLocked) {
1627 if (mResetOrientationData == null) {
1628 mResetOrientationData = new ResetOrientationData();
1629 mResetOrientationData.locked = false;
1630 }
1631
1632 // Lock to portrait, so the user doesn't accidentally hide the panel.
Steve Elliotte05817f2019-05-17 14:39:53 -04001633 // This call is posted so that the rotation does not change until post-layout,
1634 // otherwise onConfigurationChanged() may not get invoked.
1635 mGlobalActionsLayout.post(() ->
1636 RotationPolicy.setRotationLockAtAngle(
1637 mContext, true, RotationUtils.ROTATION_NONE));
Steve Elliott48f75db2019-05-03 15:03:38 -04001638 }
1639
Steve Elliott53f12ae2019-05-13 17:14:15 -04001640 // Disable rotation suggestions, if enabled
1641 setRotationSuggestionsEnabled(false);
1642
Steve Elliott300b48f2019-05-29 14:13:50 -04001643 FrameLayout panelContainer =
1644 findViewById(com.android.systemui.R.id.global_actions_panel_container);
Steve Elliott48f75db2019-05-03 15:03:38 -04001645 FrameLayout.LayoutParams panelParams =
1646 new FrameLayout.LayoutParams(
1647 FrameLayout.LayoutParams.MATCH_PARENT,
Steve Elliott300b48f2019-05-29 14:13:50 -04001648 FrameLayout.LayoutParams.MATCH_PARENT);
Steve Elliott48f75db2019-05-03 15:03:38 -04001649 panelContainer.addView(mPanelController.getPanelContent(), panelParams);
Steve Elliott48f75db2019-05-03 15:03:38 -04001650 }
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001651 }
1652
1653 private void initializeLayout() {
1654 setContentView(getGlobalActionsLayoutId(mContext));
Steve Elliott300b48f2019-05-29 14:13:50 -04001655 fixNavBarClipping();
Matt Pietal22231792020-01-23 09:51:09 -05001656 mControlsView = findViewById(com.android.systemui.R.id.global_actions_controls);
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001657 mGlobalActionsLayout = findViewById(com.android.systemui.R.id.global_actions_view);
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001658 mGlobalActionsLayout.setOutsideTouchListener(view -> dismiss());
Steve Elliott300b48f2019-05-29 14:13:50 -04001659 ((View) mGlobalActionsLayout.getParent()).setOnClickListener(view -> dismiss());
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001660 mGlobalActionsLayout.setListViewAccessibilityDelegate(new View.AccessibilityDelegate() {
Phil Weaver9054e092018-04-27 16:28:50 -07001661 @Override
1662 public boolean dispatchPopulateAccessibilityEvent(
1663 View host, AccessibilityEvent event) {
1664 // Populate the title here, just as Activity does
1665 event.getText().add(mContext.getString(R.string.global_actions));
1666 return true;
1667 }
1668 });
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001669 mGlobalActionsLayout.setRotationListener(this::onRotate);
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001670 mGlobalActionsLayout.setAdapter(mAdapter);
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001671
Steve Elliott86ef6282019-05-08 14:45:04 -04001672 if (shouldUsePanel()) {
Steve Elliottc59eb342019-04-23 16:59:06 -04001673 initializePanel();
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001674 }
Steve Elliott86ef6282019-05-08 14:45:04 -04001675 if (mBackgroundDrawable == null) {
1676 mBackgroundDrawable = new ScrimDrawable();
Lucas Dupin43d01242020-02-03 11:58:33 -08001677 mScrimAlpha = ScrimController.BUSY_SCRIM_ALPHA;
Steve Elliott86ef6282019-05-08 14:45:04 -04001678 }
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001679 getWindow().setBackgroundDrawable(mBackgroundDrawable);
Aran Ink780d4502020-02-14 10:39:58 -05001680
1681 if (mControlsView != null) {
1682 mContainerView = findViewById(com.android.systemui.R.id.global_actions_container);
1683 mContainerView.setOnTouchListener((v, e) -> {
1684 dismiss();
1685 return true;
1686 });
1687 }
Steve Elliott9b87a442019-03-05 10:24:16 -05001688 }
1689
Steve Elliott300b48f2019-05-29 14:13:50 -04001690 private void fixNavBarClipping() {
1691 ViewGroup content = findViewById(android.R.id.content);
1692 content.setClipChildren(false);
1693 content.setClipToPadding(false);
1694 ViewGroup contentParent = (ViewGroup) content.getParent();
1695 contentParent.setClipChildren(false);
1696 contentParent.setClipToPadding(false);
1697 }
1698
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001699 private int getGlobalActionsLayoutId(Context context) {
Matt Pietal22231792020-01-23 09:51:09 -05001700 if (mControlsUiController != null) {
Matt Pietalfd3b6cb2020-01-08 09:43:54 -05001701 return com.android.systemui.R.layout.global_actions_grid_v2;
1702 }
1703
Steve Elliottdc165632019-05-23 14:26:31 -04001704 int rotation = RotationUtils.getRotation(context);
1705 boolean useGridLayout = isForceGridEnabled(context)
1706 || (shouldUsePanel() && rotation == RotationUtils.ROTATION_NONE);
1707 if (rotation == RotationUtils.ROTATION_SEASCAPE) {
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001708 if (useGridLayout) {
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001709 return com.android.systemui.R.layout.global_actions_grid_seascape;
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001710 } else {
1711 return com.android.systemui.R.layout.global_actions_column_seascape;
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001712 }
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001713 } else {
1714 if (useGridLayout) {
1715 return com.android.systemui.R.layout.global_actions_grid;
1716 } else {
1717 return com.android.systemui.R.layout.global_actions_column;
1718 }
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001719 }
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001720 }
1721
Jason Monk361915c2017-03-21 20:33:59 -04001722 @Override
1723 protected void onStart() {
1724 super.setCanceledOnTouchOutside(true);
1725 super.onStart();
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001726 mGlobalActionsLayout.updateList();
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001727
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001728 if (mBackgroundDrawable instanceof ScrimDrawable) {
Steve Elliott9b87a442019-03-05 10:24:16 -05001729 mColorExtractor.addOnColorsChangedListener(this);
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001730 GradientColors colors = mColorExtractor.getNeutralColors();
Steve Elliott9b87a442019-03-05 10:24:16 -05001731 updateColors(colors, false /* animate */);
1732 }
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001733 }
1734
1735 /**
1736 * Updates background and system bars according to current GradientColors.
1737 * @param colors Colors and hints to use.
1738 * @param animate Interpolates gradient if true, just sets otherwise.
1739 */
1740 private void updateColors(GradientColors colors, boolean animate) {
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001741 if (!(mBackgroundDrawable instanceof ScrimDrawable)) {
Steve Elliott9b87a442019-03-05 10:24:16 -05001742 return;
1743 }
Lucas Dupinba2b48a2020-02-06 09:28:06 -08001744 ((ScrimDrawable) mBackgroundDrawable).setColor(colors.supportsDarkText() ? Color.WHITE
1745 : Color.BLACK, animate);
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001746 View decorView = getWindow().getDecorView();
1747 if (colors.supportsDarkText()) {
1748 decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR |
Steve Elliott9b87a442019-03-05 10:24:16 -05001749 View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001750 } else {
1751 decorView.setSystemUiVisibility(0);
1752 }
Jason Monk361915c2017-03-21 20:33:59 -04001753 }
1754
1755 @Override
Jason Monk16fbd9d2017-04-27 14:28:49 -04001756 protected void onStop() {
1757 super.onStop();
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001758 mColorExtractor.removeOnColorsChangedListener(this);
Jason Monk16fbd9d2017-04-27 14:28:49 -04001759 }
1760
1761 @Override
1762 public void show() {
1763 super.show();
Beverly526d2d62018-08-15 12:55:33 -04001764 mShowing = true;
wilsonshihe8321942019-10-18 18:39:46 +08001765 mHadTopUi = mNotificationShadeWindowController.getForceHasTopUi();
1766 mNotificationShadeWindowController.setForceHasTopUi(true);
Steve Elliott9b87a442019-03-05 10:24:16 -05001767 mBackgroundDrawable.setAlpha(0);
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001768 mGlobalActionsLayout.setTranslationX(mGlobalActionsLayout.getAnimationOffsetX());
1769 mGlobalActionsLayout.setTranslationY(mGlobalActionsLayout.getAnimationOffsetY());
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001770 mGlobalActionsLayout.setAlpha(0);
1771 mGlobalActionsLayout.animate()
Jason Monk16fbd9d2017-04-27 14:28:49 -04001772 .alpha(1)
1773 .translationX(0)
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001774 .translationY(0)
Jason Monk16fbd9d2017-04-27 14:28:49 -04001775 .setDuration(300)
Lucas Dupinde9db422017-07-19 17:15:41 -07001776 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001777 .setUpdateListener(animation -> {
Lucas Dupin991415e2019-11-25 17:48:58 -08001778 float animatedValue = animation.getAnimatedFraction();
1779 int alpha = (int) (animatedValue * mScrimAlpha * 255);
Steve Elliott9b87a442019-03-05 10:24:16 -05001780 mBackgroundDrawable.setAlpha(alpha);
Lucas Dupin991415e2019-11-25 17:48:58 -08001781 mBlurUtils.applyBlur(mGlobalActionsLayout.getViewRootImpl(),
1782 mBlurUtils.radiusForRatio(animatedValue));
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001783 })
Jason Monk16fbd9d2017-04-27 14:28:49 -04001784 .start();
Matt Pietal22231792020-01-23 09:51:09 -05001785 if (mControlsUiController != null) {
1786 mControlsUiController.show(mControlsView);
1787 }
Jason Monk16fbd9d2017-04-27 14:28:49 -04001788 }
1789
1790 @Override
1791 public void dismiss() {
Beverly526d2d62018-08-15 12:55:33 -04001792 if (!mShowing) {
1793 return;
1794 }
1795 mShowing = false;
Matt Pietal22231792020-01-23 09:51:09 -05001796 if (mControlsUiController != null) mControlsUiController.hide();
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001797 mGlobalActionsLayout.setTranslationX(0);
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001798 mGlobalActionsLayout.setTranslationY(0);
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001799 mGlobalActionsLayout.setAlpha(1);
1800 mGlobalActionsLayout.animate()
Jason Monk16fbd9d2017-04-27 14:28:49 -04001801 .alpha(0)
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001802 .translationX(mGlobalActionsLayout.getAnimationOffsetX())
1803 .translationY(mGlobalActionsLayout.getAnimationOffsetY())
Jason Monk16fbd9d2017-04-27 14:28:49 -04001804 .setDuration(300)
Steve Elliottff2c0d92019-07-30 15:09:54 -04001805 .withEndAction(this::completeDismiss)
Jason Monk16fbd9d2017-04-27 14:28:49 -04001806 .setInterpolator(new LogAccelerateInterpolator())
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001807 .setUpdateListener(animation -> {
Lucas Dupin991415e2019-11-25 17:48:58 -08001808 float animatedValue = 1f - animation.getAnimatedFraction();
1809 int alpha = (int) (animatedValue * mScrimAlpha * 255);
Steve Elliott9b87a442019-03-05 10:24:16 -05001810 mBackgroundDrawable.setAlpha(alpha);
Lucas Dupin991415e2019-11-25 17:48:58 -08001811 mBlurUtils.applyBlur(mGlobalActionsLayout.getViewRootImpl(),
1812 mBlurUtils.radiusForRatio(animatedValue));
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001813 })
Jason Monk16fbd9d2017-04-27 14:28:49 -04001814 .start();
Steve Elliott48f75db2019-05-03 15:03:38 -04001815 dismissPanel();
1816 resetOrientation();
Jason Monk16fbd9d2017-04-27 14:28:49 -04001817 }
1818
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001819 void dismissImmediately() {
Beverly526d2d62018-08-15 12:55:33 -04001820 mShowing = false;
Matt Pietal019feaa2020-01-31 14:51:37 -05001821 if (mControlsUiController != null) mControlsUiController.hide();
Steve Elliott48f75db2019-05-03 15:03:38 -04001822 dismissPanel();
1823 resetOrientation();
Steve Elliottff2c0d92019-07-30 15:09:54 -04001824 completeDismiss();
1825 }
1826
1827 private void completeDismiss() {
wilsonshihe8321942019-10-18 18:39:46 +08001828 mNotificationShadeWindowController.setForceHasTopUi(mHadTopUi);
Steve Elliottff2c0d92019-07-30 15:09:54 -04001829 super.dismiss();
Steve Elliott48f75db2019-05-03 15:03:38 -04001830 }
1831
1832 private void dismissPanel() {
Steve Elliott2d206d32019-03-14 16:30:33 -04001833 if (mPanelController != null) {
1834 mPanelController.onDismissed();
1835 }
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001836 }
1837
Steve Elliott53f12ae2019-05-13 17:14:15 -04001838 private void setRotationSuggestionsEnabled(boolean enabled) {
1839 try {
1840 final int userId = Binder.getCallingUserHandle().getIdentifier();
1841 final int what = enabled
1842 ? StatusBarManager.DISABLE2_NONE
1843 : StatusBarManager.DISABLE2_ROTATE_SUGGESTIONS;
1844 mStatusBarService.disable2ForUser(what, mToken, mContext.getPackageName(), userId);
1845 } catch (RemoteException ex) {
1846 throw ex.rethrowFromSystemServer();
1847 }
1848 }
1849
Steve Elliott48f75db2019-05-03 15:03:38 -04001850 private void resetOrientation() {
1851 if (mResetOrientationData != null) {
1852 RotationPolicy.setRotationLockAtAngle(mContext, mResetOrientationData.locked,
1853 mResetOrientationData.rotation);
1854 }
Steve Elliott53f12ae2019-05-13 17:14:15 -04001855 setRotationSuggestionsEnabled(true);
Steve Elliott48f75db2019-05-03 15:03:38 -04001856 }
1857
Jason Monk361915c2017-03-21 20:33:59 -04001858 @Override
Lucas Dupin7aaa3532017-05-28 08:51:07 -07001859 public void onColorsChanged(ColorExtractor extractor, int which) {
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001860 if (mKeyguardShowing) {
1861 if ((WallpaperManager.FLAG_LOCK & which) != 0) {
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001862 updateColors(extractor.getColors(WallpaperManager.FLAG_LOCK),
1863 true /* animate */);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001864 }
1865 } else {
1866 if ((WallpaperManager.FLAG_SYSTEM & which) != 0) {
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001867 updateColors(extractor.getColors(WallpaperManager.FLAG_SYSTEM),
1868 true /* animate */);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001869 }
1870 }
1871 }
1872
1873 public void setKeyguardShowing(boolean keyguardShowing) {
1874 mKeyguardShowing = keyguardShowing;
1875 }
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001876
Aaron Heuckroth4ef3a542019-04-01 14:17:23 -04001877 public void refreshDialog() {
1878 initializeLayout();
1879 mGlobalActionsLayout.updateList();
1880 }
1881
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001882 public void onRotate(int from, int to) {
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001883 if (mShowing) {
Aaron Heuckroth4ef3a542019-04-01 14:17:23 -04001884 refreshDialog();
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001885 }
1886 }
Steve Elliott48f75db2019-05-03 15:03:38 -04001887
1888 private static class ResetOrientationData {
1889 public boolean locked;
1890 public int rotation;
1891 }
Jason Monk361915c2017-03-21 20:33:59 -04001892 }
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001893
1894 /**
Aran Ink93dd25c2019-05-09 14:42:14 -04001895 * Determines whether or not debug mode has been activated for the Global Actions Panel.
1896 */
1897 private static boolean isPanelDebugModeEnabled(Context context) {
1898 return Settings.Secure.getInt(context.getContentResolver(),
1899 Settings.Secure.GLOBAL_ACTIONS_PANEL_DEBUG_ENABLED, 0) == 1;
1900 }
1901
1902 /**
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001903 * Determines whether or not the Global Actions menu should be forced to
1904 * use the newer grid-style layout.
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001905 */
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001906 private static boolean isForceGridEnabled(Context context) {
Aran Ink93dd25c2019-05-09 14:42:14 -04001907 return isPanelDebugModeEnabled(context);
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001908 }
Aaron Heuckrothf19d2722019-03-11 17:06:02 -04001909
Matt Pietale0661b62020-01-29 14:35:31 -05001910 private boolean shouldShowControls() {
Fabian Kozynski8b540452020-02-04 15:16:30 -05001911 return !mKeyguardManager.isDeviceLocked()
1912 && mControlsUiController.getAvailable();
Matt Pietalfd3b6cb2020-01-08 09:43:54 -05001913 }
Jason Monk361915c2017-03-21 20:33:59 -04001914}