blob: b99d7655c425f5951ba37b62ffcf55bbe4d5ec45 [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;
Steve Elliott4c868852019-03-14 16:25:41 -040028import android.app.PendingIntent;
Steve Elliott53f12ae2019-05-13 17:14:15 -040029import android.app.StatusBarManager;
Lucas Dupinc1cc7592017-05-22 15:56:16 -070030import android.app.WallpaperManager;
Alex Chau04458852017-11-27 18:21:23 +000031import android.app.admin.DevicePolicyManager;
Pavel Grafov059021b2018-05-02 13:44:46 +010032import android.app.trust.TrustManager;
Jason Monk361915c2017-03-21 20:33:59 -040033import android.content.BroadcastReceiver;
Dave Mankoffc88a2d72020-01-10 15:59:31 -050034import android.content.ContentResolver;
Jason Monk361915c2017-03-21 20:33:59 -040035import android.content.Context;
36import android.content.DialogInterface;
37import android.content.Intent;
38import android.content.IntentFilter;
39import android.content.pm.UserInfo;
Dave Mankoffc88a2d72020-01-10 15:59:31 -050040import android.content.res.Resources;
Jason Monk361915c2017-03-21 20:33:59 -040041import android.database.ContentObserver;
Matt Pietale0661b62020-01-29 14:35:31 -050042import android.graphics.Color;
Jason Monk361915c2017-03-21 20:33:59 -040043import android.graphics.drawable.Drawable;
44import android.media.AudioManager;
45import android.net.ConnectivityManager;
Steve Elliott53f12ae2019-05-13 17:14:15 -040046import android.os.Binder;
Jason Monk361915c2017-03-21 20:33:59 -040047import android.os.Handler;
Steve Elliott53f12ae2019-05-13 17:14:15 -040048import android.os.IBinder;
Jason Monk361915c2017-03-21 20:33:59 -040049import android.os.Message;
50import android.os.RemoteException;
Jason Monk361915c2017-03-21 20:33:59 -040051import android.os.SystemProperties;
52import android.os.UserHandle;
53import android.os.UserManager;
54import android.os.Vibrator;
55import android.provider.Settings;
Jason Monk361915c2017-03-21 20:33:59 -040056import android.service.dreams.IDreamManager;
Inseob Kim5e82f732019-11-08 15:08:38 +090057import android.sysprop.TelephonyProperties;
Fan Zhangf9914762019-11-01 15:58:38 -070058import android.telecom.TelecomManager;
Jason Monk361915c2017-03-21 20:33:59 -040059import android.telephony.PhoneStateListener;
60import android.telephony.ServiceState;
61import android.telephony.TelephonyManager;
Jason Monk361915c2017-03-21 20:33:59 -040062import android.util.ArraySet;
yuanjiahsu88363e92018-09-06 19:23:52 +080063import android.util.FeatureFlagUtils;
Jason Monk361915c2017-03-21 20:33:59 -040064import android.util.Log;
Lucas Dupin448786c2017-07-24 17:44:25 -070065import android.view.ContextThemeWrapper;
Dave Mankoff8df818e2020-02-12 14:22:26 -050066import android.view.IWindowManager;
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;
Jason Monk361915c2017-03-21 20:33:59 -040072import android.view.accessibility.AccessibilityEvent;
Steve Elliott9b87a442019-03-05 10:24:16 -050073import android.widget.FrameLayout;
Jason Monk361915c2017-03-21 20:33:59 -040074import android.widget.ImageView;
75import android.widget.ImageView.ScaleType;
Jason Monk361915c2017-03-21 20:33:59 -040076import android.widget.TextView;
77
Charles He9851a8d2017-10-10 17:31:30 +010078import com.android.internal.R;
79import com.android.internal.colorextraction.ColorExtractor;
80import com.android.internal.colorextraction.ColorExtractor.GradientColors;
Lucas Dupin2bd3af62019-03-25 17:44:28 -070081import com.android.internal.colorextraction.drawable.ScrimDrawable;
Charles He9851a8d2017-10-10 17:31:30 +010082import com.android.internal.logging.MetricsLogger;
83import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Steve Elliott53f12ae2019-05-13 17:14:15 -040084import com.android.internal.statusbar.IStatusBarService;
Charles He9851a8d2017-10-10 17:31:30 +010085import com.android.internal.util.EmergencyAffordanceManager;
Beth Thibodeau5898ac42018-10-26 13:00:09 -040086import com.android.internal.util.ScreenRecordHelper;
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -050087import com.android.internal.util.ScreenshotHelper;
Steve Elliott48f75db2019-05-03 15:03:38 -040088import com.android.internal.view.RotationPolicy;
Charles He9851a8d2017-10-10 17:31:30 +010089import com.android.internal.widget.LockPatternUtils;
Charles He9851a8d2017-10-10 17:31:30 +010090import com.android.systemui.Interpolators;
Aaron Heuckrothf708d472019-01-10 16:54:51 -050091import com.android.systemui.MultiListLayout;
Aaron Heuckroth57d60d22019-03-05 14:00:12 -050092import com.android.systemui.MultiListLayout.MultiListAdapter;
Fabian Kozynskiff5e91f2019-09-24 15:38:08 -040093import com.android.systemui.broadcast.BroadcastDispatcher;
Charles He9851a8d2017-10-10 17:31:30 +010094import com.android.systemui.colorextraction.SysuiColorExtractor;
Fabian Kozynski0424ab12020-02-21 12:09:17 -050095import com.android.systemui.controls.management.ControlsListingController;
Matt Pietal22231792020-01-23 09:51:09 -050096import com.android.systemui.controls.ui.ControlsUiController;
Dave Mankoff8df818e2020-02-12 14:22:26 -050097import com.android.systemui.dagger.qualifiers.Background;
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 Dupin99f5fba2020-03-12 12:59:18 -0700102import com.android.systemui.statusbar.BlurUtils;
Santiago Etchebehere68eb53e2020-02-25 14:25:34 -0800103import com.android.systemui.statusbar.NotificationShadeDepthController;
Matt Pietal22231792020-01-23 09:51:09 -0500104import com.android.systemui.statusbar.phone.NotificationShadeWindowController;
Lucas Dupin43d01242020-02-03 11:58:33 -0800105import com.android.systemui.statusbar.phone.ScrimController;
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700106import com.android.systemui.statusbar.policy.ConfigurationController;
Lucas Dupinc8f16e82019-09-17 18:24:50 -0400107import com.android.systemui.statusbar.policy.KeyguardStateController;
Shaotang Li5c422632018-07-04 14:18:40 +0800108import com.android.systemui.util.EmergencyDialerConstants;
Aaron Heuckroth75e249f2019-02-01 15:59:57 -0500109import com.android.systemui.util.leak.RotationUtils;
Julia Reynolds42411922017-11-08 11:19:09 -0500110import com.android.systemui.volume.SystemUIInterpolators.LogAccelerateInterpolator;
Lucas Dupinc1cc7592017-05-22 15:56:16 -0700111
Jason Monk361915c2017-03-21 20:33:59 -0400112import java.util.ArrayList;
113import java.util.List;
Dave Mankoff8df818e2020-02-12 14:22:26 -0500114import java.util.concurrent.Executor;
Jason Monk361915c2017-03-21 20:33:59 -0400115
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500116import javax.inject.Inject;
117
Jason Monk361915c2017-03-21 20:33:59 -0400118/**
Sean Pont9d4fb032020-03-04 18:54:32 -0800119 * Helper to show the global actions dialog. Each item is an {@link Action} that may show depending
120 * on whether the keyguard is showing, and whether the device is provisioned.
Jason Monk361915c2017-03-21 20:33:59 -0400121 */
Aaron Heuckroth57d60d22019-03-05 14:00:12 -0500122public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
Sean Pont9d4fb032020-03-04 18:54:32 -0800123 DialogInterface.OnShowListener,
124 ConfigurationController.ConfigurationListener,
125 GlobalActionsPanelPlugin.Callbacks {
Jason Monk361915c2017-03-21 20:33:59 -0400126
Sean Pont9d4fb032020-03-04 18:54:32 -0800127 public static final String SYSTEM_DIALOG_REASON_KEY = "reason";
128 public static final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
129 public static final String SYSTEM_DIALOG_REASON_DREAM = "dream";
Jason Monk361915c2017-03-21 20:33:59 -0400130
131 private static final String TAG = "GlobalActionsDialog";
132
133 private static final boolean SHOW_SILENT_TOGGLE = true;
134
135 /* Valid settings for global actions keys.
136 * see config.xml config_globalActionList */
137 private static final String GLOBAL_ACTION_KEY_POWER = "power";
138 private static final String GLOBAL_ACTION_KEY_AIRPLANE = "airplane";
139 private static final String GLOBAL_ACTION_KEY_BUGREPORT = "bugreport";
140 private static final String GLOBAL_ACTION_KEY_SILENT = "silent";
141 private static final String GLOBAL_ACTION_KEY_USERS = "users";
142 private static final String GLOBAL_ACTION_KEY_SETTINGS = "settings";
143 private static final String GLOBAL_ACTION_KEY_LOCKDOWN = "lockdown";
144 private static final String GLOBAL_ACTION_KEY_VOICEASSIST = "voiceassist";
145 private static final String GLOBAL_ACTION_KEY_ASSIST = "assist";
146 private static final String GLOBAL_ACTION_KEY_RESTART = "restart";
Alex Chau04458852017-11-27 18:21:23 +0000147 private static final String GLOBAL_ACTION_KEY_LOGOUT = "logout";
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800148 private static final String GLOBAL_ACTION_KEY_EMERGENCY = "emergency";
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500149 private static final String GLOBAL_ACTION_KEY_SCREENSHOT = "screenshot";
Jason Monk361915c2017-03-21 20:33:59 -0400150
151 private final Context mContext;
152 private final GlobalActionsManager mWindowManagerFuncs;
153 private final AudioManager mAudioManager;
154 private final IDreamManager mDreamManager;
Alex Chau04458852017-11-27 18:21:23 +0000155 private final DevicePolicyManager mDevicePolicyManager;
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800156 private final LockPatternUtils mLockPatternUtils;
Fabian Kozynskif6063ae2020-02-24 16:14:35 -0500157 private final KeyguardStateController mKeyguardStateController;
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000158 private final BroadcastDispatcher mBroadcastDispatcher;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500159 private final ContentResolver mContentResolver;
160 private final Resources mResources;
Dave Mankoff8df818e2020-02-12 14:22:26 -0500161 private final ConfigurationController mConfigurationController;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500162 private final UserManager mUserManager;
163 private final TrustManager mTrustManager;
164 private final IActivityManager mIActivityManager;
165 private final TelecomManager mTelecomManager;
166 private final MetricsLogger mMetricsLogger;
Santiago Etchebehere68eb53e2020-02-25 14:25:34 -0800167 private final NotificationShadeDepthController mDepthController;
Lucas Dupin99f5fba2020-03-12 12:59:18 -0700168 private final BlurUtils mBlurUtils;
Jason Monk361915c2017-03-21 20:33:59 -0400169
170 private ArrayList<Action> mItems;
171 private ActionsDialog mDialog;
172
173 private Action mSilentModeAction;
174 private ToggleAction mAirplaneModeOn;
175
176 private MyAdapter mAdapter;
177
178 private boolean mKeyguardShowing = false;
179 private boolean mDeviceProvisioned = false;
180 private ToggleAction.State mAirplaneState = ToggleAction.State.Off;
181 private boolean mIsWaitingForEcmExit = false;
182 private boolean mHasTelephony;
183 private boolean mHasVibrator;
184 private final boolean mShowSilentToggle;
185 private final EmergencyAffordanceManager mEmergencyAffordanceManager;
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500186 private final ScreenshotHelper mScreenshotHelper;
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400187 private final ScreenRecordHelper mScreenRecordHelper;
Steve Elliotta3f5207922019-03-18 13:37:22 -0400188 private final ActivityStarter mActivityStarter;
Lucas Dupin991415e2019-11-25 17:48:58 -0800189 private final SysuiColorExtractor mSysuiColorExtractor;
190 private final IStatusBarService mStatusBarService;
191 private final NotificationShadeWindowController mNotificationShadeWindowController;
Steve Elliotta3f5207922019-03-18 13:37:22 -0400192 private GlobalActionsPanelPlugin mPanelPlugin;
Matt Pietal22231792020-01-23 09:51:09 -0500193 private ControlsUiController mControlsUiController;
Dave Mankoff8df818e2020-02-12 14:22:26 -0500194 private final IWindowManager mIWindowManager;
195 private final Executor mBackgroundExecutor;
Fabian Kozynski0424ab12020-02-21 12:09:17 -0500196 private final ControlsListingController mControlsListingController;
197 private boolean mAnyControlsProviders = false;
Steve Elliott9b87a442019-03-05 10:24:16 -0500198
Jason Monk361915c2017-03-21 20:33:59 -0400199 /**
200 * @param context everything needs a context :(
201 */
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500202 @Inject
203 public GlobalActionsDialog(Context context, GlobalActionsManager windowManagerFuncs,
204 AudioManager audioManager, IDreamManager iDreamManager,
205 DevicePolicyManager devicePolicyManager, LockPatternUtils lockPatternUtils,
Fabian Kozynskif6063ae2020-02-24 16:14:35 -0500206 BroadcastDispatcher broadcastDispatcher,
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500207 ConnectivityManager connectivityManager, TelephonyManager telephonyManager,
208 ContentResolver contentResolver, @Nullable Vibrator vibrator, @Main Resources resources,
209 ConfigurationController configurationController, ActivityStarter activityStarter,
210 KeyguardStateController keyguardStateController, UserManager userManager,
211 TrustManager trustManager, IActivityManager iActivityManager,
Dave Mankoff3c6aaab2020-01-10 17:50:34 -0500212 @Nullable TelecomManager telecomManager, MetricsLogger metricsLogger,
Santiago Etchebehere68eb53e2020-02-25 14:25:34 -0800213 NotificationShadeDepthController depthController, SysuiColorExtractor colorExtractor,
Lucas Dupin99f5fba2020-03-12 12:59:18 -0700214 IStatusBarService statusBarService, BlurUtils blurUtils,
Matt Pietal22231792020-01-23 09:51:09 -0500215 NotificationShadeWindowController notificationShadeWindowController,
Dave Mankoff8df818e2020-02-12 14:22:26 -0500216 ControlsUiController controlsUiController, IWindowManager iWindowManager,
Fabian Kozynski0424ab12020-02-21 12:09:17 -0500217 @Background Executor backgroundExecutor,
218 ControlsListingController controlsListingController) {
Lucas Dupin448786c2017-07-24 17:44:25 -0700219 mContext = new ContextThemeWrapper(context, com.android.systemui.R.style.qs_theme);
Jason Monk361915c2017-03-21 20:33:59 -0400220 mWindowManagerFuncs = windowManagerFuncs;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500221 mAudioManager = audioManager;
222 mDreamManager = iDreamManager;
223 mDevicePolicyManager = devicePolicyManager;
224 mLockPatternUtils = lockPatternUtils;
Fabian Kozynskif6063ae2020-02-24 16:14:35 -0500225 mKeyguardStateController = keyguardStateController;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500226 mBroadcastDispatcher = broadcastDispatcher;
227 mContentResolver = contentResolver;
228 mResources = resources;
Dave Mankoff8df818e2020-02-12 14:22:26 -0500229 mConfigurationController = configurationController;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500230 mUserManager = userManager;
231 mTrustManager = trustManager;
232 mIActivityManager = iActivityManager;
233 mTelecomManager = telecomManager;
234 mMetricsLogger = metricsLogger;
Santiago Etchebehere68eb53e2020-02-25 14:25:34 -0800235 mDepthController = depthController;
Lucas Dupin991415e2019-11-25 17:48:58 -0800236 mSysuiColorExtractor = colorExtractor;
237 mStatusBarService = statusBarService;
238 mNotificationShadeWindowController = notificationShadeWindowController;
Matt Pietal22231792020-01-23 09:51:09 -0500239 mControlsUiController = controlsUiController;
Dave Mankoff8df818e2020-02-12 14:22:26 -0500240 mIWindowManager = iWindowManager;
241 mBackgroundExecutor = backgroundExecutor;
Fabian Kozynski0424ab12020-02-21 12:09:17 -0500242 mControlsListingController = controlsListingController;
Lucas Dupin99f5fba2020-03-12 12:59:18 -0700243 mBlurUtils = blurUtils;
Jason Monk361915c2017-03-21 20:33:59 -0400244
245 // receive broadcasts
246 IntentFilter filter = new IntentFilter();
247 filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
248 filter.addAction(Intent.ACTION_SCREEN_OFF);
Jayachandran C142eae02019-12-13 19:29:20 -0800249 filter.addAction(TelephonyManager.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000250 mBroadcastDispatcher.registerReceiver(mBroadcastReceiver, filter);
Jason Monk361915c2017-03-21 20:33:59 -0400251
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500252 mHasTelephony = connectivityManager.isNetworkSupported(ConnectivityManager.TYPE_MOBILE);
Jason Monk361915c2017-03-21 20:33:59 -0400253
254 // get notified of phone state changes
Jason Monk361915c2017-03-21 20:33:59 -0400255 telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE);
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500256 contentResolver.registerContentObserver(
Jason Monk361915c2017-03-21 20:33:59 -0400257 Settings.Global.getUriFor(Settings.Global.AIRPLANE_MODE_ON), true,
258 mAirplaneModeObserver);
Jason Monk361915c2017-03-21 20:33:59 -0400259 mHasVibrator = vibrator != null && vibrator.hasVibrator();
260
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500261 mShowSilentToggle = SHOW_SILENT_TOGGLE && !resources.getBoolean(
Jason Monk361915c2017-03-21 20:33:59 -0400262 R.bool.config_useFixedVolume);
263
264 mEmergencyAffordanceManager = new EmergencyAffordanceManager(context);
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500265 mScreenshotHelper = new ScreenshotHelper(context);
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400266 mScreenRecordHelper = new ScreenRecordHelper(context);
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700267
Dave Mankoff8df818e2020-02-12 14:22:26 -0500268 mConfigurationController.addCallback(this);
Steve Elliott9b87a442019-03-05 10:24:16 -0500269
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500270 mActivityStarter = activityStarter;
Lucas Dupinc8f16e82019-09-17 18:24:50 -0400271 keyguardStateController.addCallback(new KeyguardStateController.Callback() {
272 @Override
273 public void onUnlockedChanged() {
274 if (mDialog != null && mDialog.mPanelController != null) {
Sean Pont9d4fb032020-03-04 18:54:32 -0800275 boolean unlocked = keyguardStateController.isUnlocked()
276 || keyguardStateController.canDismissLockScreen();
277 mDialog.mPanelController.onDeviceLockStateChanged(unlocked);
Lucas Dupinc8f16e82019-09-17 18:24:50 -0400278 }
279 }
280 });
Fabian Kozynski0424ab12020-02-21 12:09:17 -0500281
282 mControlsListingController.addCallback(list -> mAnyControlsProviders = !list.isEmpty());
Jason Monk361915c2017-03-21 20:33:59 -0400283 }
284
285 /**
286 * Show the global actions dialog (creating if necessary)
Jason Monk16fbd9d2017-04-27 14:28:49 -0400287 *
Jason Monk361915c2017-03-21 20:33:59 -0400288 * @param keyguardShowing True if keyguard is showing
289 */
Steve Elliotta3f5207922019-03-18 13:37:22 -0400290 public void showDialog(boolean keyguardShowing, boolean isDeviceProvisioned,
291 GlobalActionsPanelPlugin panelPlugin) {
Jason Monk361915c2017-03-21 20:33:59 -0400292 mKeyguardShowing = keyguardShowing;
293 mDeviceProvisioned = isDeviceProvisioned;
Steve Elliotta3f5207922019-03-18 13:37:22 -0400294 mPanelPlugin = panelPlugin;
Jason Monk361915c2017-03-21 20:33:59 -0400295 if (mDialog != null) {
296 mDialog.dismiss();
297 mDialog = null;
298 // Show delayed, so that the dismiss of the previous dialog completes
299 mHandler.sendEmptyMessage(MESSAGE_SHOW);
300 } else {
301 handleShow();
302 }
303 }
304
Charles He9851a8d2017-10-10 17:31:30 +0100305 /**
306 * Dismiss the global actions dialog, if it's currently shown
307 */
308 public void dismissDialog() {
309 mHandler.removeMessages(MESSAGE_DISMISS);
310 mHandler.sendEmptyMessage(MESSAGE_DISMISS);
311 }
312
Jason Monk361915c2017-03-21 20:33:59 -0400313 private void awakenIfNecessary() {
314 if (mDreamManager != null) {
315 try {
316 if (mDreamManager.isDreaming()) {
317 mDreamManager.awaken();
318 }
319 } catch (RemoteException e) {
320 // we tried
321 }
322 }
323 }
324
325 private void handleShow() {
326 awakenIfNecessary();
327 mDialog = createDialog();
328 prepareDialog();
329
330 // If we only have 1 item and it's a simple press action, just do this action.
331 if (mAdapter.getCount() == 1
332 && mAdapter.getItem(0) instanceof SinglePressAction
333 && !(mAdapter.getItem(0) instanceof LongPressAction)) {
334 ((SinglePressAction) mAdapter.getItem(0)).onPress();
335 } else {
336 WindowManager.LayoutParams attrs = mDialog.getWindow().getAttributes();
337 attrs.setTitle("ActionsDialog");
Adrian Roos2f05bb32018-02-19 16:42:27 +0100338 attrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
Jason Monk361915c2017-03-21 20:33:59 -0400339 mDialog.getWindow().setAttributes(attrs);
340 mDialog.show();
341 mWindowManagerFuncs.onGlobalActionsShown();
Jason Monk361915c2017-03-21 20:33:59 -0400342 }
343 }
344
345 /**
346 * Create the global actions dialog.
Jason Monk16fbd9d2017-04-27 14:28:49 -0400347 *
Jason Monk361915c2017-03-21 20:33:59 -0400348 * @return A new dialog.
349 */
350 private ActionsDialog createDialog() {
351 // Simple toggle style if there's no vibrator, otherwise use a tri-state
352 if (!mHasVibrator) {
353 mSilentModeAction = new SilentModeToggleAction();
354 } else {
Lucas Dupin40ec6b782018-06-05 19:07:16 -0700355 mSilentModeAction = new SilentModeTriStateAction(mAudioManager, mHandler);
Jason Monk361915c2017-03-21 20:33:59 -0400356 }
Aran Ink780d4502020-02-14 10:39:58 -0500357 mAirplaneModeOn = new AirplaneModeAction();
Jason Monk361915c2017-03-21 20:33:59 -0400358 onAirplaneModeChanged();
359
360 mItems = new ArrayList<Action>();
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500361 String[] defaultActions = mResources.getStringArray(R.array.config_globalActionsList);
Jason Monk361915c2017-03-21 20:33:59 -0400362
363 ArraySet<String> addedKeys = new ArraySet<String>();
364 for (int i = 0; i < defaultActions.length; i++) {
365 String actionKey = defaultActions[i];
366 if (addedKeys.contains(actionKey)) {
367 // If we already have added this, don't add it again.
368 continue;
369 }
370 if (GLOBAL_ACTION_KEY_POWER.equals(actionKey)) {
371 mItems.add(new PowerAction());
372 } else if (GLOBAL_ACTION_KEY_AIRPLANE.equals(actionKey)) {
373 mItems.add(mAirplaneModeOn);
374 } else if (GLOBAL_ACTION_KEY_BUGREPORT.equals(actionKey)) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500375 if (Settings.Global.getInt(mContentResolver,
Jason Monk361915c2017-03-21 20:33:59 -0400376 Settings.Global.BUGREPORT_IN_POWER_MENU, 0) != 0 && isCurrentUserOwner()) {
377 mItems.add(new BugReportAction());
378 }
379 } else if (GLOBAL_ACTION_KEY_SILENT.equals(actionKey)) {
380 if (mShowSilentToggle) {
381 mItems.add(mSilentModeAction);
382 }
383 } else if (GLOBAL_ACTION_KEY_USERS.equals(actionKey)) {
384 if (SystemProperties.getBoolean("fw.power_user_switcher", false)) {
385 addUsersToMenu(mItems);
386 }
387 } else if (GLOBAL_ACTION_KEY_SETTINGS.equals(actionKey)) {
388 mItems.add(getSettingsAction());
389 } else if (GLOBAL_ACTION_KEY_LOCKDOWN.equals(actionKey)) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500390 if (Settings.Secure.getIntForUser(mContentResolver,
Sean Pont9d4fb032020-03-04 18:54:32 -0800391 Settings.Secure.LOCKDOWN_IN_POWER_MENU, 0, getCurrentUser().id) != 0
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800392 && shouldDisplayLockdown()) {
Chad Brubaker4f28f0d2017-09-07 14:28:13 -0700393 mItems.add(getLockdownAction());
394 }
Jason Monk361915c2017-03-21 20:33:59 -0400395 } else if (GLOBAL_ACTION_KEY_VOICEASSIST.equals(actionKey)) {
396 mItems.add(getVoiceAssistAction());
397 } else if (GLOBAL_ACTION_KEY_ASSIST.equals(actionKey)) {
398 mItems.add(getAssistAction());
399 } else if (GLOBAL_ACTION_KEY_RESTART.equals(actionKey)) {
400 mItems.add(new RestartAction());
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500401 } else if (GLOBAL_ACTION_KEY_SCREENSHOT.equals(actionKey)) {
402 mItems.add(new ScreenshotAction());
Alex Chau04458852017-11-27 18:21:23 +0000403 } else if (GLOBAL_ACTION_KEY_LOGOUT.equals(actionKey)) {
Alex Chaud7958272017-12-08 11:30:52 +0000404 if (mDevicePolicyManager.isLogoutEnabled()
Alex Chau04458852017-11-27 18:21:23 +0000405 && getCurrentUser().id != UserHandle.USER_SYSTEM) {
406 mItems.add(new LogoutAction());
Alex Chau04458852017-11-27 18:21:23 +0000407 }
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800408 } else if (GLOBAL_ACTION_KEY_EMERGENCY.equals(actionKey)) {
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400409 if (!mEmergencyAffordanceManager.needsEmergencyAffordance()) {
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800410 mItems.add(new EmergencyDialerAction());
411 }
Jason Monk361915c2017-03-21 20:33:59 -0400412 } else {
413 Log.e(TAG, "Invalid global action key " + actionKey);
414 }
415 // Add here so we don't add more than one.
416 addedKeys.add(actionKey);
417 }
418
419 if (mEmergencyAffordanceManager.needsEmergencyAffordance()) {
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400420 mItems.add(new EmergencyAffordanceAction());
Jason Monk361915c2017-03-21 20:33:59 -0400421 }
422
423 mAdapter = new MyAdapter();
424
Sean Pont9d4fb032020-03-04 18:54:32 -0800425 ActionsDialog dialog = new ActionsDialog(mContext, mAdapter, getWalletPanelViewController(),
Santiago Etchebehere68eb53e2020-02-25 14:25:34 -0800426 mDepthController, mSysuiColorExtractor, mStatusBarService,
Matt Pietal22231792020-01-23 09:51:09 -0500427 mNotificationShadeWindowController,
Lucas Dupin99f5fba2020-03-12 12:59:18 -0700428 shouldShowControls() ? mControlsUiController : null, mBlurUtils);
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() {
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800439 // Lockdown is meaningless without a place to go.
Fabian Kozynskif6063ae2020-02-24 16:14:35 -0500440 if (!mKeyguardStateController.isMethodSecure()) {
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800441 return false;
442 }
443
Fabian Kozynskif6063ae2020-02-24 16:14:35 -0500444 int userId = getCurrentUser().id;
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800445 // 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() {
Dave Mankoff8df818e2020-02-12 14:22:26 -0500460 mConfigurationController.removeCallback(this);
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700461 }
462
Sean Pont9d4fb032020-03-04 18:54:32 -0800463 @Nullable
464 private GlobalActionsPanelPlugin.PanelViewController getWalletPanelViewController() {
465 if (mPanelPlugin == null) {
466 return null;
467 }
468 return mPanelPlugin.onPanelShown(this, !mKeyguardStateController.isUnlocked());
469 }
470
471 /**
472 * Implements {@link GlobalActionsPanelPlugin.Callbacks#dismissGlobalActionsMenu()}, which is
473 * called when the quick access wallet requests dismissal.
474 */
475 @Override
476 public void dismissGlobalActionsMenu() {
477 dismissDialog();
478 }
479
480 /**
481 * Implements {@link GlobalActionsPanelPlugin.Callbacks#dismissGlobalActionsMenu()}, which is
482 * called when the quick access wallet requests that an intent be started (with lock screen
483 * shown first if needed).
484 */
485 @Override
486 public void startPendingIntentDismissingKeyguard(PendingIntent pendingIntent) {
487 mActivityStarter.startPendingIntentDismissingKeyguard(pendingIntent);
488 }
489
Jason Monk361915c2017-03-21 20:33:59 -0400490 private final class PowerAction extends SinglePressAction implements LongPressAction {
491 private PowerAction() {
492 super(R.drawable.ic_lock_power_off,
Jason Monk16fbd9d2017-04-27 14:28:49 -0400493 R.string.global_action_power_off);
Jason Monk361915c2017-03-21 20:33:59 -0400494 }
495
496 @Override
497 public boolean onLongPress() {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500498 if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) {
Jason Monk361915c2017-03-21 20:33:59 -0400499 mWindowManagerFuncs.reboot(true);
500 return true;
501 }
502 return false;
503 }
504
505 @Override
506 public boolean showDuringKeyguard() {
507 return true;
508 }
509
510 @Override
511 public boolean showBeforeProvisioning() {
512 return true;
513 }
514
515 @Override
516 public void onPress() {
517 // shutdown by making sure radio and power are handled accordingly.
518 mWindowManagerFuncs.shutdown();
519 }
520 }
521
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400522 private abstract class EmergencyAction extends SinglePressAction {
523 EmergencyAction(int iconResId, int messageResId) {
524 super(iconResId, messageResId);
525 }
526
527 @Override
528 public boolean shouldBeSeparated() {
Aran Ink780d4502020-02-14 10:39:58 -0500529 return true;
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400530 }
531
532 @Override
533 public View create(
534 Context context, View convertView, ViewGroup parent, LayoutInflater inflater) {
535 View v = super.create(context, convertView, parent, inflater);
536 int textColor;
537 if (shouldBeSeparated()) {
538 textColor = v.getResources().getColor(
539 com.android.systemui.R.color.global_actions_alert_text);
540 } else {
541 textColor = v.getResources().getColor(
542 com.android.systemui.R.color.global_actions_text);
543 }
544 TextView messageView = v.findViewById(R.id.message);
545 messageView.setTextColor(textColor);
Aaron Heuckroth3f2d8b52019-04-05 13:27:51 -0400546 messageView.setSelected(true); // necessary for marquee to work
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400547 ImageView icon = (ImageView) v.findViewById(R.id.icon);
548 icon.getDrawable().setTint(textColor);
549 return v;
550 }
551
552 @Override
553 public boolean showDuringKeyguard() {
554 return true;
555 }
556
557 @Override
558 public boolean showBeforeProvisioning() {
559 return true;
560 }
561 }
562
563 private class EmergencyAffordanceAction extends EmergencyAction {
564 EmergencyAffordanceAction() {
565 super(R.drawable.emergency_icon,
566 R.string.global_action_emergency);
567 }
568
569 @Override
570 public void onPress() {
571 mEmergencyAffordanceManager.performEmergencyCall();
572 }
573 }
574
575 private class EmergencyDialerAction extends EmergencyAction {
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800576 private EmergencyDialerAction() {
Aran Ink50195262019-05-30 10:55:37 -0400577 super(com.android.systemui.R.drawable.ic_emergency_star,
Wesley.CW Wang3004fcb2018-06-15 16:24:57 +0800578 R.string.global_action_emergency);
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800579 }
580
581 @Override
582 public void onPress() {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500583 mMetricsLogger.action(MetricsEvent.ACTION_EMERGENCY_DIALER_FROM_POWER_MENU);
Dave Mankoff3c6aaab2020-01-10 17:50:34 -0500584 if (mTelecomManager != null) {
585 Intent intent = mTelecomManager.createLaunchEmergencyDialerIntent(
586 null /* number */);
587 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
588 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
589 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
590 intent.putExtra(EmergencyDialerConstants.EXTRA_ENTRY_TYPE,
591 EmergencyDialerConstants.ENTRY_TYPE_POWER_MENU);
592 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
593 }
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800594 }
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800595 }
596
Jason Monk361915c2017-03-21 20:33:59 -0400597 private final class RestartAction extends SinglePressAction implements LongPressAction {
598 private RestartAction() {
599 super(R.drawable.ic_restart, R.string.global_action_restart);
600 }
601
602 @Override
603 public boolean onLongPress() {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500604 if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) {
Jason Monk361915c2017-03-21 20:33:59 -0400605 mWindowManagerFuncs.reboot(true);
606 return true;
607 }
608 return false;
609 }
610
611 @Override
612 public boolean showDuringKeyguard() {
613 return true;
614 }
615
616 @Override
617 public boolean showBeforeProvisioning() {
618 return true;
619 }
620
621 @Override
622 public void onPress() {
623 mWindowManagerFuncs.reboot(false);
624 }
625 }
626
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400627 private class ScreenshotAction extends SinglePressAction implements LongPressAction {
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500628 public ScreenshotAction() {
629 super(R.drawable.ic_screenshot, R.string.global_action_screenshot);
630 }
631
632 @Override
633 public void onPress() {
634 // Add a little delay before executing, to give the
635 // dialog a chance to go away before it takes a
636 // screenshot.
637 // TODO: instead, omit global action dialog layer
638 mHandler.postDelayed(new Runnable() {
639 @Override
640 public void run() {
James O'Learyfa5bb7a2019-09-05 13:43:29 -0400641 mScreenshotHelper.takeScreenshot(1, true, true, mHandler, null);
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500642 mMetricsLogger.action(MetricsEvent.ACTION_SCREENSHOT_POWER_MENU);
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500643 }
644 }, 500);
645 }
646
647 @Override
648 public boolean showDuringKeyguard() {
649 return true;
650 }
651
652 @Override
653 public boolean showBeforeProvisioning() {
654 return false;
655 }
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400656
657 @Override
658 public boolean onLongPress() {
659 if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SCREENRECORD_LONG_PRESS)) {
660 mScreenRecordHelper.launchRecordPrompt();
661 } else {
662 onPress();
663 }
664 return true;
665 }
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500666 }
667
Jason Monk361915c2017-03-21 20:33:59 -0400668 private class BugReportAction extends SinglePressAction implements LongPressAction {
669
670 public BugReportAction() {
671 super(R.drawable.ic_lock_bugreport, R.string.bugreport_title);
672 }
673
674 @Override
675 public void onPress() {
676 // don't actually trigger the bugreport if we are running stability
677 // tests via monkey
678 if (ActivityManager.isUserAMonkey()) {
679 return;
680 }
681 // Add a little delay before executing, to give the
682 // dialog a chance to go away before it takes a
683 // screenshot.
684 mHandler.postDelayed(new Runnable() {
685 @Override
686 public void run() {
687 try {
688 // Take an "interactive" bugreport.
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500689 mMetricsLogger.action(
Jason Monk361915c2017-03-21 20:33:59 -0400690 MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_INTERACTIVE);
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500691 if (!mIActivityManager.launchBugReportHandlerApp()) {
Paul Changc40f5782019-11-04 18:55:31 +0800692 Log.w(TAG, "Bugreport handler could not be launched");
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500693 mIActivityManager.requestInteractiveBugReport();
Paul Changc40f5782019-11-04 18:55:31 +0800694 }
Jason Monk361915c2017-03-21 20:33:59 -0400695 } catch (RemoteException e) {
696 }
697 }
698 }, 500);
699 }
700
701 @Override
702 public boolean onLongPress() {
703 // don't actually trigger the bugreport if we are running stability
704 // tests via monkey
705 if (ActivityManager.isUserAMonkey()) {
706 return false;
707 }
708 try {
709 // Take a "full" bugreport.
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500710 mMetricsLogger.action(MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_FULL);
711 mIActivityManager.requestFullBugReport();
Jason Monk361915c2017-03-21 20:33:59 -0400712 } catch (RemoteException e) {
713 }
714 return false;
715 }
716
717 public boolean showDuringKeyguard() {
718 return true;
719 }
720
721 @Override
722 public boolean showBeforeProvisioning() {
723 return false;
724 }
Jason Monk361915c2017-03-21 20:33:59 -0400725 }
726
Alex Chau04458852017-11-27 18:21:23 +0000727 private final class LogoutAction extends SinglePressAction {
728 private LogoutAction() {
729 super(R.drawable.ic_logout, R.string.global_action_logout);
730 }
731
732 @Override
733 public boolean showDuringKeyguard() {
734 return true;
735 }
736
737 @Override
738 public boolean showBeforeProvisioning() {
739 return false;
740 }
741
742 @Override
743 public void onPress() {
744 // Add a little delay before executing, to give the dialog a chance to go away before
745 // switching user
746 mHandler.postDelayed(() -> {
747 try {
Alex Chauedb6a012018-01-26 12:52:43 +0000748 int currentUserId = getCurrentUser().id;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500749 mIActivityManager.switchUser(UserHandle.USER_SYSTEM);
750 mIActivityManager.stopUser(currentUserId, true /*force*/, null);
Alex Chau04458852017-11-27 18:21:23 +0000751 } catch (RemoteException re) {
752 Log.e(TAG, "Couldn't logout user " + re);
753 }
754 }, 500);
755 }
756 }
757
Jason Monk361915c2017-03-21 20:33:59 -0400758 private Action getSettingsAction() {
759 return new SinglePressAction(R.drawable.ic_settings,
760 R.string.global_action_settings) {
761
762 @Override
763 public void onPress() {
764 Intent intent = new Intent(Settings.ACTION_SETTINGS);
765 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
766 mContext.startActivity(intent);
767 }
768
769 @Override
770 public boolean showDuringKeyguard() {
771 return true;
772 }
773
774 @Override
775 public boolean showBeforeProvisioning() {
776 return true;
777 }
778 };
779 }
780
Jason Monk361915c2017-03-21 20:33:59 -0400781 private Action getAssistAction() {
782 return new SinglePressAction(R.drawable.ic_action_assist_focused,
783 R.string.global_action_assist) {
784 @Override
785 public void onPress() {
786 Intent intent = new Intent(Intent.ACTION_ASSIST);
787 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
788 mContext.startActivity(intent);
789 }
790
791 @Override
792 public boolean showDuringKeyguard() {
793 return true;
794 }
795
796 @Override
797 public boolean showBeforeProvisioning() {
798 return true;
799 }
800 };
801 }
802
803 private Action getVoiceAssistAction() {
804 return new SinglePressAction(R.drawable.ic_voice_search,
805 R.string.global_action_voice_assist) {
806 @Override
807 public void onPress() {
808 Intent intent = new Intent(Intent.ACTION_VOICE_ASSIST);
809 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
810 mContext.startActivity(intent);
811 }
812
813 @Override
814 public boolean showDuringKeyguard() {
815 return true;
816 }
817
818 @Override
819 public boolean showBeforeProvisioning() {
820 return true;
821 }
822 };
823 }
824
825 private Action getLockdownAction() {
Alison Cichowlas21125432018-05-16 15:40:45 -0400826 return new SinglePressAction(R.drawable.ic_lock_lockdown,
Jason Monk361915c2017-03-21 20:33:59 -0400827 R.string.global_action_lockdown) {
828
829 @Override
830 public void onPress() {
Dave Mankoff8df818e2020-02-12 14:22:26 -0500831 mLockPatternUtils.requireStrongAuth(STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN,
832 UserHandle.USER_ALL);
Jason Monk361915c2017-03-21 20:33:59 -0400833 try {
Dave Mankoff8df818e2020-02-12 14:22:26 -0500834 mIWindowManager.lockNow(null);
Pavel Grafov059021b2018-05-02 13:44:46 +0100835 // Lock profiles (if any) on the background thread.
Dave Mankoff8df818e2020-02-12 14:22:26 -0500836 mBackgroundExecutor.execute(() -> lockProfiles());
Jason Monk361915c2017-03-21 20:33:59 -0400837 } catch (RemoteException e) {
838 Log.e(TAG, "Error while trying to lock device.", e);
839 }
840 }
841
842 @Override
843 public boolean showDuringKeyguard() {
844 return true;
845 }
846
847 @Override
848 public boolean showBeforeProvisioning() {
849 return false;
850 }
851 };
852 }
853
Pavel Grafov059021b2018-05-02 13:44:46 +0100854 private void lockProfiles() {
Pavel Grafov059021b2018-05-02 13:44:46 +0100855 final int currentUserId = getCurrentUser().id;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500856 final int[] profileIds = mUserManager.getEnabledProfileIds(currentUserId);
Pavel Grafov059021b2018-05-02 13:44:46 +0100857 for (final int id : profileIds) {
858 if (id != currentUserId) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500859 mTrustManager.setDeviceLockedForUser(id, true);
Pavel Grafov059021b2018-05-02 13:44:46 +0100860 }
861 }
862 }
863
Jason Monk361915c2017-03-21 20:33:59 -0400864 private UserInfo getCurrentUser() {
865 try {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500866 return mIActivityManager.getCurrentUser();
Jason Monk361915c2017-03-21 20:33:59 -0400867 } catch (RemoteException re) {
868 return null;
869 }
870 }
871
872 private boolean isCurrentUserOwner() {
873 UserInfo currentUser = getCurrentUser();
874 return currentUser == null || currentUser.isPrimary();
875 }
876
877 private void addUsersToMenu(ArrayList<Action> items) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500878 if (mUserManager.isUserSwitcherEnabled()) {
879 List<UserInfo> users = mUserManager.getUsers();
Jason Monk361915c2017-03-21 20:33:59 -0400880 UserInfo currentUser = getCurrentUser();
881 for (final UserInfo user : users) {
882 if (user.supportsSwitchToByUser()) {
883 boolean isCurrentUser = currentUser == null
884 ? user.id == 0 : (currentUser.id == user.id);
885 Drawable icon = user.iconPath != null ? Drawable.createFromPath(user.iconPath)
886 : null;
887 SinglePressAction switchToUser = new SinglePressAction(
888 R.drawable.ic_menu_cc, icon,
889 (user.name != null ? user.name : "Primary")
Jason Monk16fbd9d2017-04-27 14:28:49 -0400890 + (isCurrentUser ? " \u2714" : "")) {
Jason Monk361915c2017-03-21 20:33:59 -0400891 public void onPress() {
892 try {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500893 mIActivityManager.switchUser(user.id);
Jason Monk361915c2017-03-21 20:33:59 -0400894 } catch (RemoteException re) {
895 Log.e(TAG, "Couldn't switch user " + re);
896 }
897 }
898
899 public boolean showDuringKeyguard() {
900 return true;
901 }
902
903 public boolean showBeforeProvisioning() {
904 return false;
905 }
906 };
907 items.add(switchToUser);
908 }
909 }
910 }
911 }
912
913 private void prepareDialog() {
914 refreshSilentMode();
915 mAirplaneModeOn.updateState(mAirplaneState);
916 mAdapter.notifyDataSetChanged();
Jason Monk361915c2017-03-21 20:33:59 -0400917 if (mShowSilentToggle) {
918 IntentFilter filter = new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION);
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000919 mBroadcastDispatcher.registerReceiver(mRingerModeReceiver, filter);
Jason Monk361915c2017-03-21 20:33:59 -0400920 }
921 }
922
923 private void refreshSilentMode() {
924 if (!mHasVibrator) {
925 final boolean silentModeOn =
926 mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL;
Jason Monk16fbd9d2017-04-27 14:28:49 -0400927 ((ToggleAction) mSilentModeAction).updateState(
Jason Monk361915c2017-03-21 20:33:59 -0400928 silentModeOn ? ToggleAction.State.On : ToggleAction.State.Off);
929 }
930 }
931
Sean Pont9d4fb032020-03-04 18:54:32 -0800932 /**
933 * {@inheritDoc}
934 */
Jason Monk361915c2017-03-21 20:33:59 -0400935 public void onDismiss(DialogInterface dialog) {
Steve Elliottc3147e22019-11-20 19:34:57 -0500936 if (mDialog == dialog) {
937 mDialog = null;
938 }
Jason Monk361915c2017-03-21 20:33:59 -0400939 mWindowManagerFuncs.onGlobalActionsHidden();
940 if (mShowSilentToggle) {
941 try {
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000942 mBroadcastDispatcher.unregisterReceiver(mRingerModeReceiver);
Jason Monk361915c2017-03-21 20:33:59 -0400943 } catch (IllegalArgumentException ie) {
944 // ignore this
945 Log.w(TAG, ie);
946 }
947 }
948 }
949
Sean Pont9d4fb032020-03-04 18:54:32 -0800950 /**
951 * {@inheritDoc}
952 */
Shaotang Li786da902018-08-02 11:18:00 +0800953 public void onShow(DialogInterface dialog) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500954 mMetricsLogger.visible(MetricsEvent.POWER_MENU);
Shaotang Li786da902018-08-02 11:18:00 +0800955 }
956
Jason Monk361915c2017-03-21 20:33:59 -0400957 /**
Sean Pont9d4fb032020-03-04 18:54:32 -0800958 * The adapter used for the list within the global actions dialog, taking into account whether
959 * the keyguard is showing via
960 * {@link com.android.systemui.globalactions.GlobalActionsDialog#mKeyguardShowing}
961 * and whether the device is provisioned via
962 * {@link com.android.systemui.globalactions.GlobalActionsDialog#mDeviceProvisioned}.
Jason Monk361915c2017-03-21 20:33:59 -0400963 */
Aaron Heuckroth57d60d22019-03-05 14:00:12 -0500964 public class MyAdapter extends MultiListAdapter {
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -0400965 private int countItems(boolean separated) {
Jason Monk361915c2017-03-21 20:33:59 -0400966 int count = 0;
Jason Monk361915c2017-03-21 20:33:59 -0400967 for (int i = 0; i < mItems.size(); i++) {
968 final Action action = mItems.get(i);
969
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -0400970 if (shouldBeShown(action) && action.shouldBeSeparated() == separated) {
971 count++;
Jason Monk361915c2017-03-21 20:33:59 -0400972 }
Jason Monk361915c2017-03-21 20:33:59 -0400973 }
974 return count;
975 }
976
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -0400977 private boolean shouldBeShown(Action action) {
978 if (mKeyguardShowing && !action.showDuringKeyguard()) {
979 return false;
980 }
981 if (!mDeviceProvisioned && !action.showBeforeProvisioning()) {
982 return false;
983 }
984 return true;
985 }
986
987 @Override
988 public int countSeparatedItems() {
989 return countItems(true);
990 }
991
992 @Override
993 public int countListItems() {
994 return countItems(false);
995 }
996
997 @Override
998 public int getCount() {
999 return countSeparatedItems() + countListItems();
1000 }
1001
Jason Monk361915c2017-03-21 20:33:59 -04001002 @Override
1003 public boolean isEnabled(int position) {
1004 return getItem(position).isEnabled();
1005 }
1006
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001007 @Override
Jason Monk361915c2017-03-21 20:33:59 -04001008 public boolean areAllItemsEnabled() {
1009 return false;
1010 }
1011
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001012 @Override
Jason Monk361915c2017-03-21 20:33:59 -04001013 public Action getItem(int position) {
Jason Monk361915c2017-03-21 20:33:59 -04001014 int filteredPos = 0;
1015 for (int i = 0; i < mItems.size(); i++) {
1016 final Action action = mItems.get(i);
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -04001017 if (!shouldBeShown(action)) {
Jason Monk361915c2017-03-21 20:33:59 -04001018 continue;
1019 }
1020 if (filteredPos == position) {
1021 return action;
1022 }
1023 filteredPos++;
1024 }
1025
1026 throw new IllegalArgumentException("position " + position
1027 + " out of range of showable actions"
1028 + ", filtered count=" + getCount()
1029 + ", keyguardshowing=" + mKeyguardShowing
1030 + ", provisioned=" + mDeviceProvisioned);
1031 }
1032
1033
1034 public long getItemId(int position) {
1035 return position;
1036 }
1037
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001038 @Override
Jason Monk361915c2017-03-21 20:33:59 -04001039 public View getView(int position, View convertView, ViewGroup parent) {
1040 Action action = getItem(position);
Jason Monk16fbd9d2017-04-27 14:28:49 -04001041 View view = action.create(mContext, convertView, parent, LayoutInflater.from(mContext));
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -04001042 view.setOnClickListener(v -> onClickItem(position));
Aran Inkb4199d92020-02-07 13:25:21 -05001043 if (action instanceof LongPressAction) {
1044 view.setOnLongClickListener(v -> onLongClickItem(position));
1045 }
Jason Monk16fbd9d2017-04-27 14:28:49 -04001046 return view;
Jason Monk361915c2017-03-21 20:33:59 -04001047 }
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001048
1049 @Override
1050 public boolean onLongClickItem(int position) {
1051 final Action action = mAdapter.getItem(position);
1052 if (action instanceof LongPressAction) {
Aran Inkbaa25862019-06-11 15:48:55 -04001053 if (mDialog != null) {
1054 mDialog.dismiss();
1055 } else {
1056 Log.w(TAG, "Action long-clicked while mDialog is null.");
1057 }
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001058 return ((LongPressAction) action).onLongPress();
1059 }
1060 return false;
1061 }
1062
1063 @Override
1064 public void onClickItem(int position) {
1065 Action item = mAdapter.getItem(position);
1066 if (!(item instanceof SilentModeTriStateAction)) {
Aran Inkbaa25862019-06-11 15:48:55 -04001067 if (mDialog != null) {
1068 mDialog.dismiss();
1069 } else {
1070 Log.w(TAG, "Action clicked while mDialog is null.");
1071 }
1072 item.onPress();
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001073 }
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001074 }
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -04001075
1076 @Override
1077 public boolean shouldBeSeparated(int position) {
1078 return getItem(position).shouldBeSeparated();
1079 }
Jason Monk361915c2017-03-21 20:33:59 -04001080 }
1081
1082 // note: the scheme below made more sense when we were planning on having
1083 // 8 different things in the global actions dialog. seems overkill with
1084 // only 3 items now, but may as well keep this flexible approach so it will
1085 // be easy should someone decide at the last minute to include something
1086 // else, such as 'enable wifi', or 'enable bluetooth'
1087
1088 /**
1089 * What each item in the global actions dialog must be able to support.
1090 */
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001091 public interface Action {
Jason Monk361915c2017-03-21 20:33:59 -04001092 /**
Sean Pont9d4fb032020-03-04 18:54:32 -08001093 * @return Text that will be announced when dialog is created. null for none.
Jason Monk361915c2017-03-21 20:33:59 -04001094 */
1095 CharSequence getLabelForAccessibility(Context context);
1096
1097 View create(Context context, View convertView, ViewGroup parent, LayoutInflater inflater);
1098
1099 void onPress();
1100
1101 /**
Sean Pont9d4fb032020-03-04 18:54:32 -08001102 * @return whether this action should appear in the dialog when the keygaurd is showing.
Jason Monk361915c2017-03-21 20:33:59 -04001103 */
1104 boolean showDuringKeyguard();
1105
1106 /**
Sean Pont9d4fb032020-03-04 18:54:32 -08001107 * @return whether this action should appear in the dialog before the device is
1108 * provisioned.onlongpress
Jason Monk361915c2017-03-21 20:33:59 -04001109 */
1110 boolean showBeforeProvisioning();
1111
1112 boolean isEnabled();
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001113
1114 default boolean shouldBeSeparated() {
1115 return false;
1116 }
Jason Monk361915c2017-03-21 20:33:59 -04001117 }
1118
1119 /**
1120 * An action that also supports long press.
1121 */
1122 private interface LongPressAction extends Action {
1123 boolean onLongPress();
1124 }
1125
1126 /**
Sean Pont9d4fb032020-03-04 18:54:32 -08001127 * A single press action maintains no state, just responds to a press and takes an action.
Jason Monk361915c2017-03-21 20:33:59 -04001128 */
Matt Pietale0661b62020-01-29 14:35:31 -05001129
1130 private abstract class SinglePressAction implements Action {
Jason Monk361915c2017-03-21 20:33:59 -04001131 private final int mIconResId;
1132 private final Drawable mIcon;
1133 private final int mMessageResId;
1134 private final CharSequence mMessage;
1135
1136 protected SinglePressAction(int iconResId, int messageResId) {
1137 mIconResId = iconResId;
1138 mMessageResId = messageResId;
1139 mMessage = null;
1140 mIcon = null;
1141 }
1142
1143 protected SinglePressAction(int iconResId, Drawable icon, CharSequence message) {
1144 mIconResId = iconResId;
1145 mMessageResId = 0;
1146 mMessage = message;
1147 mIcon = icon;
1148 }
1149
1150 public boolean isEnabled() {
1151 return true;
1152 }
1153
1154 public String getStatus() {
1155 return null;
1156 }
1157
1158 abstract public void onPress();
1159
1160 public CharSequence getLabelForAccessibility(Context context) {
1161 if (mMessage != null) {
1162 return mMessage;
1163 } else {
1164 return context.getString(mMessageResId);
1165 }
1166 }
1167
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001168 protected int getActionLayoutId(Context context) {
Matt Pietale0661b62020-01-29 14:35:31 -05001169 if (shouldShowControls()) {
Matt Pietalfd3b6cb2020-01-08 09:43:54 -05001170 return com.android.systemui.R.layout.global_actions_grid_item_v2;
1171 }
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001172 return com.android.systemui.R.layout.global_actions_grid_item;
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001173 }
1174
Jason Monk361915c2017-03-21 20:33:59 -04001175 public View create(
1176 Context context, View convertView, ViewGroup parent, LayoutInflater inflater) {
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001177 View v = inflater.inflate(getActionLayoutId(context), parent,
Jason Monk16fbd9d2017-04-27 14:28:49 -04001178 false);
Jason Monk361915c2017-03-21 20:33:59 -04001179
1180 ImageView icon = (ImageView) v.findViewById(R.id.icon);
1181 TextView messageView = (TextView) v.findViewById(R.id.message);
Aaron Heuckroth3f2d8b52019-04-05 13:27:51 -04001182 messageView.setSelected(true); // necessary for marquee to work
Jason Monk361915c2017-03-21 20:33:59 -04001183
Jason Monk361915c2017-03-21 20:33:59 -04001184 if (mIcon != null) {
1185 icon.setImageDrawable(mIcon);
1186 icon.setScaleType(ScaleType.CENTER_CROP);
1187 } else if (mIconResId != 0) {
1188 icon.setImageDrawable(context.getDrawable(mIconResId));
1189 }
1190 if (mMessage != null) {
1191 messageView.setText(mMessage);
1192 } else {
1193 messageView.setText(mMessageResId);
1194 }
1195
1196 return v;
1197 }
1198 }
1199
1200 /**
Sean Pont9d4fb032020-03-04 18:54:32 -08001201 * A toggle action knows whether it is on or off, and displays an icon and status message
1202 * accordingly.
Jason Monk361915c2017-03-21 20:33:59 -04001203 */
1204 private static abstract class ToggleAction implements Action {
1205
1206 enum State {
1207 Off(false),
1208 TurningOn(true),
1209 TurningOff(true),
1210 On(false);
1211
1212 private final boolean inTransition;
1213
1214 State(boolean intermediate) {
1215 inTransition = intermediate;
1216 }
1217
1218 public boolean inTransition() {
1219 return inTransition;
1220 }
1221 }
1222
1223 protected State mState = State.Off;
1224
1225 // prefs
1226 protected int mEnabledIconResId;
1227 protected int mDisabledIconResid;
1228 protected int mMessageResId;
1229 protected int mEnabledStatusMessageResId;
1230 protected int mDisabledStatusMessageResId;
1231
1232 /**
Jason Monk16fbd9d2017-04-27 14:28:49 -04001233 * @param enabledIconResId The icon for when this action is on.
1234 * @param disabledIconResid The icon for when this action is off.
1235 * @param message The general information message, e.g 'Silent Mode'
1236 * @param enabledStatusMessageResId The on status message, e.g 'sound disabled'
Jason Monk361915c2017-03-21 20:33:59 -04001237 * @param disabledStatusMessageResId The off status message, e.g. 'sound enabled'
1238 */
1239 public ToggleAction(int enabledIconResId,
1240 int disabledIconResid,
1241 int message,
1242 int enabledStatusMessageResId,
1243 int disabledStatusMessageResId) {
1244 mEnabledIconResId = enabledIconResId;
1245 mDisabledIconResid = disabledIconResid;
1246 mMessageResId = message;
1247 mEnabledStatusMessageResId = enabledStatusMessageResId;
1248 mDisabledStatusMessageResId = disabledStatusMessageResId;
1249 }
1250
1251 /**
Sean Pont9d4fb032020-03-04 18:54:32 -08001252 * Override to make changes to resource IDs just before creating the View.
Jason Monk361915c2017-03-21 20:33:59 -04001253 */
1254 void willCreate() {
1255
1256 }
1257
1258 @Override
1259 public CharSequence getLabelForAccessibility(Context context) {
1260 return context.getString(mMessageResId);
1261 }
1262
1263 public View create(Context context, View convertView, ViewGroup parent,
1264 LayoutInflater inflater) {
1265 willCreate();
1266
Koji Fukui5c010ee2019-12-24 16:12:07 +09001267 View v = inflater.inflate(com.android.systemui.R
1268 .layout.global_actions_grid_item, parent, false);
Jason Monk361915c2017-03-21 20:33:59 -04001269
1270 ImageView icon = (ImageView) v.findViewById(R.id.icon);
1271 TextView messageView = (TextView) v.findViewById(R.id.message);
Jason Monk361915c2017-03-21 20:33:59 -04001272 final boolean enabled = isEnabled();
Koji Fukui5c010ee2019-12-24 16:12:07 +09001273 boolean on = ((mState == State.On) || (mState == State.TurningOn));
Jason Monk361915c2017-03-21 20:33:59 -04001274
1275 if (messageView != null) {
Koji Fukui5c010ee2019-12-24 16:12:07 +09001276 messageView.setText(on ? mEnabledStatusMessageResId : mDisabledStatusMessageResId);
Jason Monk361915c2017-03-21 20:33:59 -04001277 messageView.setEnabled(enabled);
Aaron Heuckroth3f2d8b52019-04-05 13:27:51 -04001278 messageView.setSelected(true); // necessary for marquee to work
Jason Monk361915c2017-03-21 20:33:59 -04001279 }
1280
Jason Monk361915c2017-03-21 20:33:59 -04001281 if (icon != null) {
1282 icon.setImageDrawable(context.getDrawable(
1283 (on ? mEnabledIconResId : mDisabledIconResid)));
1284 icon.setEnabled(enabled);
1285 }
1286
Jason Monk361915c2017-03-21 20:33:59 -04001287 v.setEnabled(enabled);
1288
1289 return v;
1290 }
1291
1292 public final void onPress() {
1293 if (mState.inTransition()) {
1294 Log.w(TAG, "shouldn't be able to toggle when in transition");
1295 return;
1296 }
1297
1298 final boolean nowOn = !(mState == State.On);
1299 onToggle(nowOn);
1300 changeStateFromPress(nowOn);
1301 }
1302
1303 public boolean isEnabled() {
1304 return !mState.inTransition();
1305 }
1306
1307 /**
Sean Pont9d4fb032020-03-04 18:54:32 -08001308 * Implementations may override this if their state can be in on of the intermediate states
1309 * until some notification is received (e.g airplane mode is 'turning off' until we know the
1310 * wireless connections are back online
Jason Monk16fbd9d2017-04-27 14:28:49 -04001311 *
Jason Monk361915c2017-03-21 20:33:59 -04001312 * @param buttonOn Whether the button was turned on or off
1313 */
1314 protected void changeStateFromPress(boolean buttonOn) {
1315 mState = buttonOn ? State.On : State.Off;
1316 }
1317
1318 abstract void onToggle(boolean on);
1319
1320 public void updateState(State state) {
1321 mState = state;
1322 }
1323 }
1324
Aran Ink780d4502020-02-14 10:39:58 -05001325 private class AirplaneModeAction extends ToggleAction {
1326 AirplaneModeAction() {
1327 super(
Sean Pont9d4fb032020-03-04 18:54:32 -08001328 R.drawable.ic_lock_airplane_mode,
1329 R.drawable.ic_lock_airplane_mode_off,
1330 R.string.global_actions_toggle_airplane_mode,
1331 R.string.global_actions_airplane_mode_on_status,
1332 R.string.global_actions_airplane_mode_off_status);
Aran Ink780d4502020-02-14 10:39:58 -05001333 }
Sean Pont9d4fb032020-03-04 18:54:32 -08001334
Aran Ink780d4502020-02-14 10:39:58 -05001335 void onToggle(boolean on) {
1336 if (mHasTelephony && TelephonyProperties.in_ecm_mode().orElse(false)) {
1337 mIsWaitingForEcmExit = true;
1338 // Launch ECM exit dialog
1339 Intent ecmDialogIntent =
1340 new Intent(TelephonyManager.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null);
1341 ecmDialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1342 mContext.startActivity(ecmDialogIntent);
1343 } else {
1344 changeAirplaneModeSystemSetting(on);
1345 }
1346 }
1347
1348 @Override
1349 protected void changeStateFromPress(boolean buttonOn) {
1350 if (!mHasTelephony) return;
1351
1352 // In ECM mode airplane state cannot be changed
1353 if (!TelephonyProperties.in_ecm_mode().orElse(false)) {
1354 mState = buttonOn ? State.TurningOn : State.TurningOff;
1355 mAirplaneState = mState;
1356 }
1357 }
1358
1359 public boolean showDuringKeyguard() {
1360 return true;
1361 }
1362
1363 public boolean showBeforeProvisioning() {
1364 return false;
1365 }
1366 }
1367
Jason Monk361915c2017-03-21 20:33:59 -04001368 private class SilentModeToggleAction extends ToggleAction {
1369 public SilentModeToggleAction() {
1370 super(R.drawable.ic_audio_vol_mute,
1371 R.drawable.ic_audio_vol,
1372 R.string.global_action_toggle_silent_mode,
1373 R.string.global_action_silent_mode_on_status,
1374 R.string.global_action_silent_mode_off_status);
1375 }
1376
1377 void onToggle(boolean on) {
1378 if (on) {
1379 mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
1380 } else {
1381 mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
1382 }
1383 }
1384
1385 public boolean showDuringKeyguard() {
1386 return true;
1387 }
1388
1389 public boolean showBeforeProvisioning() {
1390 return false;
1391 }
1392 }
1393
1394 private static class SilentModeTriStateAction implements Action, View.OnClickListener {
1395
Jason Monk16fbd9d2017-04-27 14:28:49 -04001396 private final int[] ITEM_IDS = {R.id.option1, R.id.option2, R.id.option3};
Jason Monk361915c2017-03-21 20:33:59 -04001397
1398 private final AudioManager mAudioManager;
1399 private final Handler mHandler;
Jason Monk361915c2017-03-21 20:33:59 -04001400
Lucas Dupin40ec6b782018-06-05 19:07:16 -07001401 SilentModeTriStateAction(AudioManager audioManager, Handler handler) {
Jason Monk361915c2017-03-21 20:33:59 -04001402 mAudioManager = audioManager;
1403 mHandler = handler;
Jason Monk361915c2017-03-21 20:33:59 -04001404 }
1405
1406 private int ringerModeToIndex(int ringerMode) {
1407 // They just happen to coincide
1408 return ringerMode;
1409 }
1410
1411 private int indexToRingerMode(int index) {
1412 // They just happen to coincide
1413 return index;
1414 }
1415
1416 @Override
1417 public CharSequence getLabelForAccessibility(Context context) {
1418 return null;
1419 }
1420
1421 public View create(Context context, View convertView, ViewGroup parent,
1422 LayoutInflater inflater) {
1423 View v = inflater.inflate(R.layout.global_actions_silent_mode, parent, false);
1424
1425 int selectedIndex = ringerModeToIndex(mAudioManager.getRingerMode());
1426 for (int i = 0; i < 3; i++) {
1427 View itemView = v.findViewById(ITEM_IDS[i]);
1428 itemView.setSelected(selectedIndex == i);
1429 // Set up click handler
1430 itemView.setTag(i);
1431 itemView.setOnClickListener(this);
1432 }
1433 return v;
1434 }
1435
1436 public void onPress() {
1437 }
1438
1439 public boolean showDuringKeyguard() {
1440 return true;
1441 }
1442
1443 public boolean showBeforeProvisioning() {
1444 return false;
1445 }
1446
1447 public boolean isEnabled() {
1448 return true;
1449 }
1450
1451 void willCreate() {
1452 }
1453
1454 public void onClick(View v) {
1455 if (!(v.getTag() instanceof Integer)) return;
1456
1457 int index = (Integer) v.getTag();
1458 mAudioManager.setRingerMode(indexToRingerMode(index));
1459 mHandler.sendEmptyMessageDelayed(MESSAGE_DISMISS, DIALOG_DISMISS_DELAY);
1460 }
1461 }
1462
1463 private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
1464 public void onReceive(Context context, Intent intent) {
1465 String action = intent.getAction();
1466 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)
1467 || Intent.ACTION_SCREEN_OFF.equals(action)) {
1468 String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY);
1469 if (!SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS.equals(reason)) {
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001470 mHandler.sendMessage(mHandler.obtainMessage(MESSAGE_DISMISS, reason));
Jason Monk361915c2017-03-21 20:33:59 -04001471 }
Jayachandran C142eae02019-12-13 19:29:20 -08001472 } else if (TelephonyManager.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED.equals(action)) {
Jason Monk361915c2017-03-21 20:33:59 -04001473 // Airplane mode can be changed after ECM exits if airplane toggle button
1474 // is pressed during ECM mode
Daniel Bright4bcbfce2020-01-09 21:58:16 -08001475 if (!(intent.getBooleanExtra(TelephonyManager.EXTRA_PHONE_IN_ECM_STATE, false))
1476 && mIsWaitingForEcmExit) {
Jason Monk361915c2017-03-21 20:33:59 -04001477 mIsWaitingForEcmExit = false;
1478 changeAirplaneModeSystemSetting(true);
1479 }
1480 }
1481 }
1482 };
1483
1484 PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
1485 @Override
1486 public void onServiceStateChanged(ServiceState serviceState) {
1487 if (!mHasTelephony) return;
1488 final boolean inAirplaneMode = serviceState.getState() == ServiceState.STATE_POWER_OFF;
1489 mAirplaneState = inAirplaneMode ? ToggleAction.State.On : ToggleAction.State.Off;
1490 mAirplaneModeOn.updateState(mAirplaneState);
1491 mAdapter.notifyDataSetChanged();
1492 }
1493 };
1494
1495 private BroadcastReceiver mRingerModeReceiver = new BroadcastReceiver() {
1496 @Override
1497 public void onReceive(Context context, Intent intent) {
1498 if (intent.getAction().equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
1499 mHandler.sendEmptyMessage(MESSAGE_REFRESH);
1500 }
1501 }
1502 };
1503
1504 private ContentObserver mAirplaneModeObserver = new ContentObserver(new Handler()) {
1505 @Override
1506 public void onChange(boolean selfChange) {
1507 onAirplaneModeChanged();
1508 }
1509 };
1510
1511 private static final int MESSAGE_DISMISS = 0;
1512 private static final int MESSAGE_REFRESH = 1;
1513 private static final int MESSAGE_SHOW = 2;
1514 private static final int DIALOG_DISMISS_DELAY = 300; // ms
1515
1516 private Handler mHandler = new Handler() {
1517 public void handleMessage(Message msg) {
1518 switch (msg.what) {
Jason Monk16fbd9d2017-04-27 14:28:49 -04001519 case MESSAGE_DISMISS:
1520 if (mDialog != null) {
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001521 if (SYSTEM_DIALOG_REASON_DREAM.equals(msg.obj)) {
1522 mDialog.dismissImmediately();
1523 } else {
1524 mDialog.dismiss();
1525 }
Jason Monk16fbd9d2017-04-27 14:28:49 -04001526 mDialog = null;
1527 }
1528 break;
1529 case MESSAGE_REFRESH:
1530 refreshSilentMode();
1531 mAdapter.notifyDataSetChanged();
1532 break;
1533 case MESSAGE_SHOW:
1534 handleShow();
1535 break;
Jason Monk361915c2017-03-21 20:33:59 -04001536 }
1537 }
1538 };
1539
1540 private void onAirplaneModeChanged() {
1541 // Let the service state callbacks handle the state.
1542 if (mHasTelephony) return;
1543
1544 boolean airplaneModeOn = Settings.Global.getInt(
Dave Mankoffc88a2d72020-01-10 15:59:31 -05001545 mContentResolver,
Jason Monk361915c2017-03-21 20:33:59 -04001546 Settings.Global.AIRPLANE_MODE_ON,
1547 0) == 1;
1548 mAirplaneState = airplaneModeOn ? ToggleAction.State.On : ToggleAction.State.Off;
1549 mAirplaneModeOn.updateState(mAirplaneState);
1550 }
1551
1552 /**
1553 * Change the airplane mode system setting
1554 */
1555 private void changeAirplaneModeSystemSetting(boolean on) {
1556 Settings.Global.putInt(
Dave Mankoffc88a2d72020-01-10 15:59:31 -05001557 mContentResolver,
Jason Monk361915c2017-03-21 20:33:59 -04001558 Settings.Global.AIRPLANE_MODE_ON,
1559 on ? 1 : 0);
1560 Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
1561 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
1562 intent.putExtra("state", on);
1563 mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
1564 if (!mHasTelephony) {
1565 mAirplaneState = on ? ToggleAction.State.On : ToggleAction.State.Off;
1566 }
1567 }
1568
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001569 private static final class ActionsDialog extends Dialog implements DialogInterface,
1570 ColorExtractor.OnColorsChangedListener {
Jason Monk361915c2017-03-21 20:33:59 -04001571
Jason Monk16fbd9d2017-04-27 14:28:49 -04001572 private final Context mContext;
1573 private final MyAdapter mAdapter;
Steve Elliott53f12ae2019-05-13 17:14:15 -04001574 private final IStatusBarService mStatusBarService;
1575 private final IBinder mToken = new Binder();
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001576 private MultiListLayout mGlobalActionsLayout;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001577 private Drawable mBackgroundDrawable;
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001578 private final SysuiColorExtractor mColorExtractor;
Steve Elliott9b87a442019-03-05 10:24:16 -05001579 private final GlobalActionsPanelPlugin.PanelViewController mPanelController;
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001580 private boolean mKeyguardShowing;
Beverly526d2d62018-08-15 12:55:33 -04001581 private boolean mShowing;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001582 private float mScrimAlpha;
Steve Elliott48f75db2019-05-03 15:03:38 -04001583 private ResetOrientationData mResetOrientationData;
Steve Elliottff2c0d92019-07-30 15:09:54 -04001584 private boolean mHadTopUi;
wilsonshihe8321942019-10-18 18:39:46 +08001585 private final NotificationShadeWindowController mNotificationShadeWindowController;
Santiago Etchebehere68eb53e2020-02-25 14:25:34 -08001586 private final NotificationShadeDepthController mDepthController;
Lucas Dupin99f5fba2020-03-12 12:59:18 -07001587 private final BlurUtils mBlurUtils;
Matt Pietal22231792020-01-23 09:51:09 -05001588
1589 private ControlsUiController mControlsUiController;
1590 private ViewGroup mControlsView;
Jason Monk16fbd9d2017-04-27 14:28:49 -04001591
Aaron Heuckrothf19d2722019-03-11 17:06:02 -04001592 ActionsDialog(Context context, MyAdapter adapter,
Santiago Etchebehere68eb53e2020-02-25 14:25:34 -08001593 GlobalActionsPanelPlugin.PanelViewController plugin,
1594 NotificationShadeDepthController depthController,
Lucas Dupin991415e2019-11-25 17:48:58 -08001595 SysuiColorExtractor sysuiColorExtractor, IStatusBarService statusBarService,
1596 NotificationShadeWindowController notificationShadeWindowController,
Lucas Dupin99f5fba2020-03-12 12:59:18 -07001597 ControlsUiController controlsUiController, BlurUtils blurUtils) {
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001598 super(context, com.android.systemui.R.style.Theme_SystemUI_Dialog_GlobalActions);
Lucas Dupin448786c2017-07-24 17:44:25 -07001599 mContext = context;
Jason Monk16fbd9d2017-04-27 14:28:49 -04001600 mAdapter = adapter;
Santiago Etchebehere68eb53e2020-02-25 14:25:34 -08001601 mDepthController = depthController;
Lucas Dupin991415e2019-11-25 17:48:58 -08001602 mColorExtractor = sysuiColorExtractor;
1603 mStatusBarService = statusBarService;
1604 mNotificationShadeWindowController = notificationShadeWindowController;
Matt Pietal22231792020-01-23 09:51:09 -05001605 mControlsUiController = controlsUiController;
Lucas Dupin99f5fba2020-03-12 12:59:18 -07001606 mBlurUtils = blurUtils;
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001607
1608 // Window initialization
1609 Window window = getWindow();
1610 window.requestFeature(Window.FEATURE_NO_TITLE);
Adrian Roosedfab3b2018-03-08 18:39:20 +01001611 // Inflate the decor view, so the attributes below are not overwritten by the theme.
1612 window.getDecorView();
1613 window.getAttributes().systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1614 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1615 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1616 window.setLayout(MATCH_PARENT, MATCH_PARENT);
1617 window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
Alison Cichowlas4f19f4a2017-07-25 10:56:16 -04001618 window.addFlags(
1619 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
Sean Pont9d4fb032020-03-04 18:54:32 -08001620 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
1621 | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
1622 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
1623 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
1624 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001625 window.setType(WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY);
Tiger Huang52724442020-01-20 21:38:42 +08001626 window.getAttributes().setFitInsetsTypes(0 /* types */);
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001627 setTitle(R.string.global_actions);
Steve Elliott9b87a442019-03-05 10:24:16 -05001628
1629 mPanelController = plugin;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001630 initializeLayout();
Steve Elliott9b87a442019-03-05 10:24:16 -05001631 }
1632
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001633 private boolean shouldUsePanel() {
Aran Ink3f594552019-05-13 14:29:35 -04001634 return mPanelController != null && mPanelController.getPanelContent() != null;
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001635 }
1636
1637 private void initializePanel() {
Steve Elliott48f75db2019-05-03 15:03:38 -04001638 int rotation = RotationUtils.getRotation(mContext);
1639 boolean rotationLocked = RotationPolicy.isRotationLocked(mContext);
1640 if (rotation != RotationUtils.ROTATION_NONE) {
1641 if (rotationLocked) {
1642 if (mResetOrientationData == null) {
1643 mResetOrientationData = new ResetOrientationData();
1644 mResetOrientationData.locked = true;
1645 mResetOrientationData.rotation = rotation;
1646 }
1647
1648 // Unlock rotation, so user can choose to rotate to portrait to see the panel.
Steve Elliotte05817f2019-05-17 14:39:53 -04001649 // This call is posted so that the rotation does not change until post-layout,
1650 // otherwise onConfigurationChanged() may not get invoked.
1651 mGlobalActionsLayout.post(() ->
1652 RotationPolicy.setRotationLockAtAngle(
1653 mContext, false, RotationUtils.ROTATION_NONE));
Steve Elliott48f75db2019-05-03 15:03:38 -04001654 }
1655 } else {
1656 if (!rotationLocked) {
1657 if (mResetOrientationData == null) {
1658 mResetOrientationData = new ResetOrientationData();
1659 mResetOrientationData.locked = false;
1660 }
1661
1662 // Lock to portrait, so the user doesn't accidentally hide the panel.
Steve Elliotte05817f2019-05-17 14:39:53 -04001663 // This call is posted so that the rotation does not change until post-layout,
1664 // otherwise onConfigurationChanged() may not get invoked.
1665 mGlobalActionsLayout.post(() ->
1666 RotationPolicy.setRotationLockAtAngle(
1667 mContext, true, RotationUtils.ROTATION_NONE));
Steve Elliott48f75db2019-05-03 15:03:38 -04001668 }
1669
Steve Elliott53f12ae2019-05-13 17:14:15 -04001670 // Disable rotation suggestions, if enabled
1671 setRotationSuggestionsEnabled(false);
1672
Steve Elliott300b48f2019-05-29 14:13:50 -04001673 FrameLayout panelContainer =
1674 findViewById(com.android.systemui.R.id.global_actions_panel_container);
Steve Elliott48f75db2019-05-03 15:03:38 -04001675 FrameLayout.LayoutParams panelParams =
1676 new FrameLayout.LayoutParams(
1677 FrameLayout.LayoutParams.MATCH_PARENT,
Steve Elliott300b48f2019-05-29 14:13:50 -04001678 FrameLayout.LayoutParams.MATCH_PARENT);
Steve Elliott48f75db2019-05-03 15:03:38 -04001679 panelContainer.addView(mPanelController.getPanelContent(), panelParams);
Steve Elliott48f75db2019-05-03 15:03:38 -04001680 }
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001681 }
1682
1683 private void initializeLayout() {
1684 setContentView(getGlobalActionsLayoutId(mContext));
Steve Elliott300b48f2019-05-29 14:13:50 -04001685 fixNavBarClipping();
Matt Pietal22231792020-01-23 09:51:09 -05001686 mControlsView = findViewById(com.android.systemui.R.id.global_actions_controls);
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001687 mGlobalActionsLayout = findViewById(com.android.systemui.R.id.global_actions_view);
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001688 mGlobalActionsLayout.setOutsideTouchListener(view -> dismiss());
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001689 mGlobalActionsLayout.setListViewAccessibilityDelegate(new View.AccessibilityDelegate() {
Phil Weaver9054e092018-04-27 16:28:50 -07001690 @Override
1691 public boolean dispatchPopulateAccessibilityEvent(
1692 View host, AccessibilityEvent event) {
1693 // Populate the title here, just as Activity does
1694 event.getText().add(mContext.getString(R.string.global_actions));
1695 return true;
1696 }
1697 });
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001698 mGlobalActionsLayout.setRotationListener(this::onRotate);
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001699 mGlobalActionsLayout.setAdapter(mAdapter);
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001700
Aran Ink06090262020-03-03 13:23:17 -05001701 View globalActionsParent = (View) mGlobalActionsLayout.getParent();
1702 globalActionsParent.setOnClickListener(v -> dismiss());
1703
1704 // add fall-through dismiss handling to root view
1705 View rootView = findViewById(com.android.systemui.R.id.global_actions_grid_root);
1706 if (rootView != null) {
1707 rootView.setOnClickListener(v -> dismiss());
1708 }
1709
Steve Elliott86ef6282019-05-08 14:45:04 -04001710 if (shouldUsePanel()) {
Steve Elliottc59eb342019-04-23 16:59:06 -04001711 initializePanel();
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001712 }
Steve Elliott86ef6282019-05-08 14:45:04 -04001713 if (mBackgroundDrawable == null) {
1714 mBackgroundDrawable = new ScrimDrawable();
Lucas Dupin99f5fba2020-03-12 12:59:18 -07001715 mScrimAlpha = mBlurUtils.supportsBlursOnWindows()
1716 ? ScrimController.BLUR_SCRIM_ALPHA : ScrimController.BUSY_SCRIM_ALPHA;
Steve Elliott86ef6282019-05-08 14:45:04 -04001717 }
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001718 getWindow().setBackgroundDrawable(mBackgroundDrawable);
Steve Elliott9b87a442019-03-05 10:24:16 -05001719 }
1720
Steve Elliott300b48f2019-05-29 14:13:50 -04001721 private void fixNavBarClipping() {
1722 ViewGroup content = findViewById(android.R.id.content);
1723 content.setClipChildren(false);
1724 content.setClipToPadding(false);
1725 ViewGroup contentParent = (ViewGroup) content.getParent();
1726 contentParent.setClipChildren(false);
1727 contentParent.setClipToPadding(false);
1728 }
1729
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001730 private int getGlobalActionsLayoutId(Context context) {
Matt Pietal22231792020-01-23 09:51:09 -05001731 if (mControlsUiController != null) {
Matt Pietalfd3b6cb2020-01-08 09:43:54 -05001732 return com.android.systemui.R.layout.global_actions_grid_v2;
1733 }
1734
Steve Elliottdc165632019-05-23 14:26:31 -04001735 int rotation = RotationUtils.getRotation(context);
1736 boolean useGridLayout = isForceGridEnabled(context)
1737 || (shouldUsePanel() && rotation == RotationUtils.ROTATION_NONE);
1738 if (rotation == RotationUtils.ROTATION_SEASCAPE) {
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001739 if (useGridLayout) {
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001740 return com.android.systemui.R.layout.global_actions_grid_seascape;
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001741 } else {
1742 return com.android.systemui.R.layout.global_actions_column_seascape;
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001743 }
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001744 } else {
1745 if (useGridLayout) {
1746 return com.android.systemui.R.layout.global_actions_grid;
1747 } else {
1748 return com.android.systemui.R.layout.global_actions_column;
1749 }
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001750 }
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001751 }
1752
Jason Monk361915c2017-03-21 20:33:59 -04001753 @Override
1754 protected void onStart() {
1755 super.setCanceledOnTouchOutside(true);
1756 super.onStart();
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001757 mGlobalActionsLayout.updateList();
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001758
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001759 if (mBackgroundDrawable instanceof ScrimDrawable) {
Steve Elliott9b87a442019-03-05 10:24:16 -05001760 mColorExtractor.addOnColorsChangedListener(this);
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001761 GradientColors colors = mColorExtractor.getNeutralColors();
Steve Elliott9b87a442019-03-05 10:24:16 -05001762 updateColors(colors, false /* animate */);
1763 }
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001764 }
1765
1766 /**
1767 * Updates background and system bars according to current GradientColors.
Sean Pont9d4fb032020-03-04 18:54:32 -08001768 *
1769 * @param colors Colors and hints to use.
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001770 * @param animate Interpolates gradient if true, just sets otherwise.
1771 */
1772 private void updateColors(GradientColors colors, boolean animate) {
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001773 if (!(mBackgroundDrawable instanceof ScrimDrawable)) {
Steve Elliott9b87a442019-03-05 10:24:16 -05001774 return;
1775 }
Lucas Dupinba2b48a2020-02-06 09:28:06 -08001776 ((ScrimDrawable) mBackgroundDrawable).setColor(colors.supportsDarkText() ? Color.WHITE
1777 : Color.BLACK, animate);
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001778 View decorView = getWindow().getDecorView();
1779 if (colors.supportsDarkText()) {
1780 decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR |
Steve Elliott9b87a442019-03-05 10:24:16 -05001781 View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001782 } else {
1783 decorView.setSystemUiVisibility(0);
1784 }
Jason Monk361915c2017-03-21 20:33:59 -04001785 }
1786
1787 @Override
Jason Monk16fbd9d2017-04-27 14:28:49 -04001788 protected void onStop() {
1789 super.onStop();
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001790 mColorExtractor.removeOnColorsChangedListener(this);
Jason Monk16fbd9d2017-04-27 14:28:49 -04001791 }
1792
1793 @Override
1794 public void show() {
1795 super.show();
Beverly526d2d62018-08-15 12:55:33 -04001796 mShowing = true;
wilsonshihe8321942019-10-18 18:39:46 +08001797 mHadTopUi = mNotificationShadeWindowController.getForceHasTopUi();
1798 mNotificationShadeWindowController.setForceHasTopUi(true);
Steve Elliott9b87a442019-03-05 10:24:16 -05001799 mBackgroundDrawable.setAlpha(0);
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001800 mGlobalActionsLayout.setTranslationX(mGlobalActionsLayout.getAnimationOffsetX());
1801 mGlobalActionsLayout.setTranslationY(mGlobalActionsLayout.getAnimationOffsetY());
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001802 mGlobalActionsLayout.setAlpha(0);
1803 mGlobalActionsLayout.animate()
Jason Monk16fbd9d2017-04-27 14:28:49 -04001804 .alpha(1)
1805 .translationX(0)
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001806 .translationY(0)
Jason Monk16fbd9d2017-04-27 14:28:49 -04001807 .setDuration(300)
Lucas Dupinde9db422017-07-19 17:15:41 -07001808 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001809 .setUpdateListener(animation -> {
Lucas Dupin991415e2019-11-25 17:48:58 -08001810 float animatedValue = animation.getAnimatedFraction();
1811 int alpha = (int) (animatedValue * mScrimAlpha * 255);
Steve Elliott9b87a442019-03-05 10:24:16 -05001812 mBackgroundDrawable.setAlpha(alpha);
Santiago Etchebehere68eb53e2020-02-25 14:25:34 -08001813 mDepthController.updateGlobalDialogVisibility(animatedValue,
1814 mGlobalActionsLayout);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001815 })
Jason Monk16fbd9d2017-04-27 14:28:49 -04001816 .start();
Matt Pietal22231792020-01-23 09:51:09 -05001817 if (mControlsUiController != null) {
1818 mControlsUiController.show(mControlsView);
1819 }
Jason Monk16fbd9d2017-04-27 14:28:49 -04001820 }
1821
1822 @Override
1823 public void dismiss() {
Beverly526d2d62018-08-15 12:55:33 -04001824 if (!mShowing) {
1825 return;
1826 }
1827 mShowing = false;
Matt Pietal22231792020-01-23 09:51:09 -05001828 if (mControlsUiController != null) mControlsUiController.hide();
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001829 mGlobalActionsLayout.setTranslationX(0);
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001830 mGlobalActionsLayout.setTranslationY(0);
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001831 mGlobalActionsLayout.setAlpha(1);
1832 mGlobalActionsLayout.animate()
Jason Monk16fbd9d2017-04-27 14:28:49 -04001833 .alpha(0)
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001834 .translationX(mGlobalActionsLayout.getAnimationOffsetX())
1835 .translationY(mGlobalActionsLayout.getAnimationOffsetY())
Jason Monk16fbd9d2017-04-27 14:28:49 -04001836 .setDuration(300)
Steve Elliottff2c0d92019-07-30 15:09:54 -04001837 .withEndAction(this::completeDismiss)
Jason Monk16fbd9d2017-04-27 14:28:49 -04001838 .setInterpolator(new LogAccelerateInterpolator())
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001839 .setUpdateListener(animation -> {
Lucas Dupin991415e2019-11-25 17:48:58 -08001840 float animatedValue = 1f - animation.getAnimatedFraction();
1841 int alpha = (int) (animatedValue * mScrimAlpha * 255);
Steve Elliott9b87a442019-03-05 10:24:16 -05001842 mBackgroundDrawable.setAlpha(alpha);
Santiago Etchebehere68eb53e2020-02-25 14:25:34 -08001843 mDepthController.updateGlobalDialogVisibility(animatedValue,
1844 mGlobalActionsLayout);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001845 })
Jason Monk16fbd9d2017-04-27 14:28:49 -04001846 .start();
Steve Elliott48f75db2019-05-03 15:03:38 -04001847 dismissPanel();
1848 resetOrientation();
Jason Monk16fbd9d2017-04-27 14:28:49 -04001849 }
1850
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001851 void dismissImmediately() {
Beverly526d2d62018-08-15 12:55:33 -04001852 mShowing = false;
Matt Pietal019feaa2020-01-31 14:51:37 -05001853 if (mControlsUiController != null) mControlsUiController.hide();
Steve Elliott48f75db2019-05-03 15:03:38 -04001854 dismissPanel();
1855 resetOrientation();
Steve Elliottff2c0d92019-07-30 15:09:54 -04001856 completeDismiss();
1857 }
1858
1859 private void completeDismiss() {
wilsonshihe8321942019-10-18 18:39:46 +08001860 mNotificationShadeWindowController.setForceHasTopUi(mHadTopUi);
Steve Elliottff2c0d92019-07-30 15:09:54 -04001861 super.dismiss();
Steve Elliott48f75db2019-05-03 15:03:38 -04001862 }
1863
1864 private void dismissPanel() {
Steve Elliott2d206d32019-03-14 16:30:33 -04001865 if (mPanelController != null) {
1866 mPanelController.onDismissed();
1867 }
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001868 }
1869
Steve Elliott53f12ae2019-05-13 17:14:15 -04001870 private void setRotationSuggestionsEnabled(boolean enabled) {
1871 try {
1872 final int userId = Binder.getCallingUserHandle().getIdentifier();
1873 final int what = enabled
1874 ? StatusBarManager.DISABLE2_NONE
1875 : StatusBarManager.DISABLE2_ROTATE_SUGGESTIONS;
1876 mStatusBarService.disable2ForUser(what, mToken, mContext.getPackageName(), userId);
1877 } catch (RemoteException ex) {
1878 throw ex.rethrowFromSystemServer();
1879 }
1880 }
1881
Steve Elliott48f75db2019-05-03 15:03:38 -04001882 private void resetOrientation() {
1883 if (mResetOrientationData != null) {
1884 RotationPolicy.setRotationLockAtAngle(mContext, mResetOrientationData.locked,
1885 mResetOrientationData.rotation);
1886 }
Steve Elliott53f12ae2019-05-13 17:14:15 -04001887 setRotationSuggestionsEnabled(true);
Steve Elliott48f75db2019-05-03 15:03:38 -04001888 }
1889
Jason Monk361915c2017-03-21 20:33:59 -04001890 @Override
Lucas Dupin7aaa3532017-05-28 08:51:07 -07001891 public void onColorsChanged(ColorExtractor extractor, int which) {
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001892 if (mKeyguardShowing) {
1893 if ((WallpaperManager.FLAG_LOCK & which) != 0) {
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001894 updateColors(extractor.getColors(WallpaperManager.FLAG_LOCK),
1895 true /* animate */);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001896 }
1897 } else {
1898 if ((WallpaperManager.FLAG_SYSTEM & which) != 0) {
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001899 updateColors(extractor.getColors(WallpaperManager.FLAG_SYSTEM),
1900 true /* animate */);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001901 }
1902 }
1903 }
1904
1905 public void setKeyguardShowing(boolean keyguardShowing) {
1906 mKeyguardShowing = keyguardShowing;
1907 }
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001908
Aaron Heuckroth4ef3a542019-04-01 14:17:23 -04001909 public void refreshDialog() {
1910 initializeLayout();
1911 mGlobalActionsLayout.updateList();
1912 }
1913
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001914 public void onRotate(int from, int to) {
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001915 if (mShowing) {
Aaron Heuckroth4ef3a542019-04-01 14:17:23 -04001916 refreshDialog();
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001917 }
1918 }
Steve Elliott48f75db2019-05-03 15:03:38 -04001919
1920 private static class ResetOrientationData {
1921 public boolean locked;
1922 public int rotation;
1923 }
Jason Monk361915c2017-03-21 20:33:59 -04001924 }
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001925
1926 /**
Aran Ink93dd25c2019-05-09 14:42:14 -04001927 * Determines whether or not debug mode has been activated for the Global Actions Panel.
1928 */
1929 private static boolean isPanelDebugModeEnabled(Context context) {
1930 return Settings.Secure.getInt(context.getContentResolver(),
1931 Settings.Secure.GLOBAL_ACTIONS_PANEL_DEBUG_ENABLED, 0) == 1;
1932 }
1933
1934 /**
Sean Pont9d4fb032020-03-04 18:54:32 -08001935 * Determines whether or not the Global Actions menu should be forced to use the newer
1936 * grid-style layout.
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001937 */
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001938 private static boolean isForceGridEnabled(Context context) {
Aran Ink93dd25c2019-05-09 14:42:14 -04001939 return isPanelDebugModeEnabled(context);
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001940 }
Aaron Heuckrothf19d2722019-03-11 17:06:02 -04001941
Matt Pietale0661b62020-01-29 14:35:31 -05001942 private boolean shouldShowControls() {
Fabian Kozynskif6063ae2020-02-24 16:14:35 -05001943 return mKeyguardStateController.isUnlocked()
Fabian Kozynski0424ab12020-02-21 12:09:17 -05001944 && mControlsUiController.getAvailable()
1945 && mAnyControlsProviders;
Matt Pietalfd3b6cb2020-01-08 09:43:54 -05001946 }
Jason Monk361915c2017-03-21 20:33:59 -04001947}