blob: 59b28b4372b41f6f75b617fe5b2ec9536fe50fbe [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;
Santiago Etchebehere68eb53e2020-02-25 14:25:34 -0800102import com.android.systemui.statusbar.NotificationShadeDepthController;
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;
Dave Mankoff8df818e2020-02-12 14:22:26 -0500113import java.util.concurrent.Executor;
Jason Monk361915c2017-03-21 20:33:59 -0400114
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500115import javax.inject.Inject;
116
Jason Monk361915c2017-03-21 20:33:59 -0400117/**
118 * Helper to show the global actions dialog. Each item is an {@link Action} that
119 * may show depending on whether the keyguard is showing, and whether the device
120 * is provisioned.
121 */
Aaron Heuckroth57d60d22019-03-05 14:00:12 -0500122public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
123 DialogInterface.OnShowListener, ConfigurationController.ConfigurationListener {
Jason Monk361915c2017-03-21 20:33:59 -0400124
125 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
126 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
Lucas Dupin1d4a5792018-04-02 15:14:59 -0700127 static public final String SYSTEM_DIALOG_REASON_DREAM = "dream";
Jason Monk361915c2017-03-21 20:33:59 -0400128
129 private static final String TAG = "GlobalActionsDialog";
130
131 private static final boolean SHOW_SILENT_TOGGLE = true;
132
133 /* Valid settings for global actions keys.
134 * see config.xml config_globalActionList */
135 private static final String GLOBAL_ACTION_KEY_POWER = "power";
136 private static final String GLOBAL_ACTION_KEY_AIRPLANE = "airplane";
137 private static final String GLOBAL_ACTION_KEY_BUGREPORT = "bugreport";
138 private static final String GLOBAL_ACTION_KEY_SILENT = "silent";
139 private static final String GLOBAL_ACTION_KEY_USERS = "users";
140 private static final String GLOBAL_ACTION_KEY_SETTINGS = "settings";
141 private static final String GLOBAL_ACTION_KEY_LOCKDOWN = "lockdown";
142 private static final String GLOBAL_ACTION_KEY_VOICEASSIST = "voiceassist";
143 private static final String GLOBAL_ACTION_KEY_ASSIST = "assist";
144 private static final String GLOBAL_ACTION_KEY_RESTART = "restart";
Alex Chau04458852017-11-27 18:21:23 +0000145 private static final String GLOBAL_ACTION_KEY_LOGOUT = "logout";
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800146 private static final String GLOBAL_ACTION_KEY_EMERGENCY = "emergency";
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500147 private static final String GLOBAL_ACTION_KEY_SCREENSHOT = "screenshot";
Jason Monk361915c2017-03-21 20:33:59 -0400148
149 private final Context mContext;
150 private final GlobalActionsManager mWindowManagerFuncs;
151 private final AudioManager mAudioManager;
152 private final IDreamManager mDreamManager;
Alex Chau04458852017-11-27 18:21:23 +0000153 private final DevicePolicyManager mDevicePolicyManager;
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800154 private final LockPatternUtils mLockPatternUtils;
Fabian Kozynskif6063ae2020-02-24 16:14:35 -0500155 private final KeyguardStateController mKeyguardStateController;
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000156 private final BroadcastDispatcher mBroadcastDispatcher;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500157 private final ContentResolver mContentResolver;
158 private final Resources mResources;
Dave Mankoff8df818e2020-02-12 14:22:26 -0500159 private final ConfigurationController mConfigurationController;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500160 private final UserManager mUserManager;
161 private final TrustManager mTrustManager;
162 private final IActivityManager mIActivityManager;
163 private final TelecomManager mTelecomManager;
164 private final MetricsLogger mMetricsLogger;
Santiago Etchebehere68eb53e2020-02-25 14:25:34 -0800165 private final NotificationShadeDepthController mDepthController;
Jason Monk361915c2017-03-21 20:33:59 -0400166
167 private ArrayList<Action> mItems;
168 private ActionsDialog mDialog;
169
170 private Action mSilentModeAction;
171 private ToggleAction mAirplaneModeOn;
172
173 private MyAdapter mAdapter;
174
175 private boolean mKeyguardShowing = false;
176 private boolean mDeviceProvisioned = false;
177 private ToggleAction.State mAirplaneState = ToggleAction.State.Off;
178 private boolean mIsWaitingForEcmExit = false;
179 private boolean mHasTelephony;
180 private boolean mHasVibrator;
181 private final boolean mShowSilentToggle;
182 private final EmergencyAffordanceManager mEmergencyAffordanceManager;
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500183 private final ScreenshotHelper mScreenshotHelper;
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400184 private final ScreenRecordHelper mScreenRecordHelper;
Steve Elliotta3f5207922019-03-18 13:37:22 -0400185 private final ActivityStarter mActivityStarter;
Lucas Dupin991415e2019-11-25 17:48:58 -0800186 private final SysuiColorExtractor mSysuiColorExtractor;
187 private final IStatusBarService mStatusBarService;
188 private final NotificationShadeWindowController mNotificationShadeWindowController;
Steve Elliotta3f5207922019-03-18 13:37:22 -0400189 private GlobalActionsPanelPlugin mPanelPlugin;
Matt Pietal22231792020-01-23 09:51:09 -0500190 private ControlsUiController mControlsUiController;
Dave Mankoff8df818e2020-02-12 14:22:26 -0500191 private final IWindowManager mIWindowManager;
192 private final Executor mBackgroundExecutor;
Fabian Kozynski0424ab12020-02-21 12:09:17 -0500193 private final ControlsListingController mControlsListingController;
194 private boolean mAnyControlsProviders = false;
Steve Elliott9b87a442019-03-05 10:24:16 -0500195
Jason Monk361915c2017-03-21 20:33:59 -0400196 /**
197 * @param context everything needs a context :(
198 */
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500199 @Inject
200 public GlobalActionsDialog(Context context, GlobalActionsManager windowManagerFuncs,
201 AudioManager audioManager, IDreamManager iDreamManager,
202 DevicePolicyManager devicePolicyManager, LockPatternUtils lockPatternUtils,
Fabian Kozynskif6063ae2020-02-24 16:14:35 -0500203 BroadcastDispatcher broadcastDispatcher,
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500204 ConnectivityManager connectivityManager, TelephonyManager telephonyManager,
205 ContentResolver contentResolver, @Nullable Vibrator vibrator, @Main Resources resources,
206 ConfigurationController configurationController, ActivityStarter activityStarter,
207 KeyguardStateController keyguardStateController, UserManager userManager,
208 TrustManager trustManager, IActivityManager iActivityManager,
Dave Mankoff3c6aaab2020-01-10 17:50:34 -0500209 @Nullable TelecomManager telecomManager, MetricsLogger metricsLogger,
Santiago Etchebehere68eb53e2020-02-25 14:25:34 -0800210 NotificationShadeDepthController depthController, SysuiColorExtractor colorExtractor,
Lucas Dupin991415e2019-11-25 17:48:58 -0800211 IStatusBarService statusBarService,
Matt Pietal22231792020-01-23 09:51:09 -0500212 NotificationShadeWindowController notificationShadeWindowController,
Dave Mankoff8df818e2020-02-12 14:22:26 -0500213 ControlsUiController controlsUiController, IWindowManager iWindowManager,
Fabian Kozynski0424ab12020-02-21 12:09:17 -0500214 @Background Executor backgroundExecutor,
215 ControlsListingController controlsListingController) {
Lucas Dupin448786c2017-07-24 17:44:25 -0700216 mContext = new ContextThemeWrapper(context, com.android.systemui.R.style.qs_theme);
Jason Monk361915c2017-03-21 20:33:59 -0400217 mWindowManagerFuncs = windowManagerFuncs;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500218 mAudioManager = audioManager;
219 mDreamManager = iDreamManager;
220 mDevicePolicyManager = devicePolicyManager;
221 mLockPatternUtils = lockPatternUtils;
Fabian Kozynskif6063ae2020-02-24 16:14:35 -0500222 mKeyguardStateController = keyguardStateController;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500223 mBroadcastDispatcher = broadcastDispatcher;
224 mContentResolver = contentResolver;
225 mResources = resources;
Dave Mankoff8df818e2020-02-12 14:22:26 -0500226 mConfigurationController = configurationController;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500227 mUserManager = userManager;
228 mTrustManager = trustManager;
229 mIActivityManager = iActivityManager;
230 mTelecomManager = telecomManager;
231 mMetricsLogger = metricsLogger;
Santiago Etchebehere68eb53e2020-02-25 14:25:34 -0800232 mDepthController = depthController;
Lucas Dupin991415e2019-11-25 17:48:58 -0800233 mSysuiColorExtractor = colorExtractor;
234 mStatusBarService = statusBarService;
235 mNotificationShadeWindowController = notificationShadeWindowController;
Matt Pietal22231792020-01-23 09:51:09 -0500236 mControlsUiController = controlsUiController;
Dave Mankoff8df818e2020-02-12 14:22:26 -0500237 mIWindowManager = iWindowManager;
238 mBackgroundExecutor = backgroundExecutor;
Fabian Kozynski0424ab12020-02-21 12:09:17 -0500239 mControlsListingController = controlsListingController;
Jason Monk361915c2017-03-21 20:33:59 -0400240
241 // receive broadcasts
242 IntentFilter filter = new IntentFilter();
243 filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
244 filter.addAction(Intent.ACTION_SCREEN_OFF);
Jayachandran C142eae02019-12-13 19:29:20 -0800245 filter.addAction(TelephonyManager.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000246 mBroadcastDispatcher.registerReceiver(mBroadcastReceiver, filter);
Jason Monk361915c2017-03-21 20:33:59 -0400247
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500248 mHasTelephony = connectivityManager.isNetworkSupported(ConnectivityManager.TYPE_MOBILE);
Jason Monk361915c2017-03-21 20:33:59 -0400249
250 // get notified of phone state changes
Jason Monk361915c2017-03-21 20:33:59 -0400251 telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE);
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500252 contentResolver.registerContentObserver(
Jason Monk361915c2017-03-21 20:33:59 -0400253 Settings.Global.getUriFor(Settings.Global.AIRPLANE_MODE_ON), true,
254 mAirplaneModeObserver);
Jason Monk361915c2017-03-21 20:33:59 -0400255 mHasVibrator = vibrator != null && vibrator.hasVibrator();
256
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500257 mShowSilentToggle = SHOW_SILENT_TOGGLE && !resources.getBoolean(
Jason Monk361915c2017-03-21 20:33:59 -0400258 R.bool.config_useFixedVolume);
259
260 mEmergencyAffordanceManager = new EmergencyAffordanceManager(context);
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500261 mScreenshotHelper = new ScreenshotHelper(context);
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400262 mScreenRecordHelper = new ScreenRecordHelper(context);
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700263
Dave Mankoff8df818e2020-02-12 14:22:26 -0500264 mConfigurationController.addCallback(this);
Steve Elliott9b87a442019-03-05 10:24:16 -0500265
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500266 mActivityStarter = activityStarter;
Lucas Dupinc8f16e82019-09-17 18:24:50 -0400267 keyguardStateController.addCallback(new KeyguardStateController.Callback() {
268 @Override
269 public void onUnlockedChanged() {
270 if (mDialog != null && mDialog.mPanelController != null) {
271 boolean locked = !keyguardStateController.canDismissLockScreen();
272 mDialog.mPanelController.onDeviceLockStateChanged(locked);
273 }
274 }
275 });
Fabian Kozynski0424ab12020-02-21 12:09:17 -0500276
277 mControlsListingController.addCallback(list -> mAnyControlsProviders = !list.isEmpty());
Jason Monk361915c2017-03-21 20:33:59 -0400278 }
279
280 /**
281 * Show the global actions dialog (creating if necessary)
Jason Monk16fbd9d2017-04-27 14:28:49 -0400282 *
Jason Monk361915c2017-03-21 20:33:59 -0400283 * @param keyguardShowing True if keyguard is showing
284 */
Steve Elliotta3f5207922019-03-18 13:37:22 -0400285 public void showDialog(boolean keyguardShowing, boolean isDeviceProvisioned,
286 GlobalActionsPanelPlugin panelPlugin) {
Jason Monk361915c2017-03-21 20:33:59 -0400287 mKeyguardShowing = keyguardShowing;
288 mDeviceProvisioned = isDeviceProvisioned;
Steve Elliotta3f5207922019-03-18 13:37:22 -0400289 mPanelPlugin = panelPlugin;
Jason Monk361915c2017-03-21 20:33:59 -0400290 if (mDialog != null) {
291 mDialog.dismiss();
292 mDialog = null;
293 // Show delayed, so that the dismiss of the previous dialog completes
294 mHandler.sendEmptyMessage(MESSAGE_SHOW);
295 } else {
296 handleShow();
297 }
298 }
299
Charles He9851a8d2017-10-10 17:31:30 +0100300 /**
301 * Dismiss the global actions dialog, if it's currently shown
302 */
303 public void dismissDialog() {
304 mHandler.removeMessages(MESSAGE_DISMISS);
305 mHandler.sendEmptyMessage(MESSAGE_DISMISS);
306 }
307
Jason Monk361915c2017-03-21 20:33:59 -0400308 private void awakenIfNecessary() {
309 if (mDreamManager != null) {
310 try {
311 if (mDreamManager.isDreaming()) {
312 mDreamManager.awaken();
313 }
314 } catch (RemoteException e) {
315 // we tried
316 }
317 }
318 }
319
320 private void handleShow() {
321 awakenIfNecessary();
322 mDialog = createDialog();
323 prepareDialog();
324
325 // If we only have 1 item and it's a simple press action, just do this action.
326 if (mAdapter.getCount() == 1
327 && mAdapter.getItem(0) instanceof SinglePressAction
328 && !(mAdapter.getItem(0) instanceof LongPressAction)) {
329 ((SinglePressAction) mAdapter.getItem(0)).onPress();
330 } else {
331 WindowManager.LayoutParams attrs = mDialog.getWindow().getAttributes();
332 attrs.setTitle("ActionsDialog");
Adrian Roos2f05bb32018-02-19 16:42:27 +0100333 attrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
Jason Monk361915c2017-03-21 20:33:59 -0400334 mDialog.getWindow().setAttributes(attrs);
335 mDialog.show();
336 mWindowManagerFuncs.onGlobalActionsShown();
Jason Monk361915c2017-03-21 20:33:59 -0400337 }
338 }
339
340 /**
341 * Create the global actions dialog.
Jason Monk16fbd9d2017-04-27 14:28:49 -0400342 *
Jason Monk361915c2017-03-21 20:33:59 -0400343 * @return A new dialog.
344 */
345 private ActionsDialog createDialog() {
346 // Simple toggle style if there's no vibrator, otherwise use a tri-state
347 if (!mHasVibrator) {
348 mSilentModeAction = new SilentModeToggleAction();
349 } else {
Lucas Dupin40ec6b782018-06-05 19:07:16 -0700350 mSilentModeAction = new SilentModeTriStateAction(mAudioManager, mHandler);
Jason Monk361915c2017-03-21 20:33:59 -0400351 }
Aran Ink780d4502020-02-14 10:39:58 -0500352 mAirplaneModeOn = new AirplaneModeAction();
Jason Monk361915c2017-03-21 20:33:59 -0400353 onAirplaneModeChanged();
354
355 mItems = new ArrayList<Action>();
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500356 String[] defaultActions = mResources.getStringArray(R.array.config_globalActionsList);
Jason Monk361915c2017-03-21 20:33:59 -0400357
358 ArraySet<String> addedKeys = new ArraySet<String>();
359 for (int i = 0; i < defaultActions.length; i++) {
360 String actionKey = defaultActions[i];
361 if (addedKeys.contains(actionKey)) {
362 // If we already have added this, don't add it again.
363 continue;
364 }
365 if (GLOBAL_ACTION_KEY_POWER.equals(actionKey)) {
366 mItems.add(new PowerAction());
367 } else if (GLOBAL_ACTION_KEY_AIRPLANE.equals(actionKey)) {
368 mItems.add(mAirplaneModeOn);
369 } else if (GLOBAL_ACTION_KEY_BUGREPORT.equals(actionKey)) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500370 if (Settings.Global.getInt(mContentResolver,
Jason Monk361915c2017-03-21 20:33:59 -0400371 Settings.Global.BUGREPORT_IN_POWER_MENU, 0) != 0 && isCurrentUserOwner()) {
372 mItems.add(new BugReportAction());
373 }
374 } else if (GLOBAL_ACTION_KEY_SILENT.equals(actionKey)) {
375 if (mShowSilentToggle) {
376 mItems.add(mSilentModeAction);
377 }
378 } else if (GLOBAL_ACTION_KEY_USERS.equals(actionKey)) {
379 if (SystemProperties.getBoolean("fw.power_user_switcher", false)) {
380 addUsersToMenu(mItems);
381 }
382 } else if (GLOBAL_ACTION_KEY_SETTINGS.equals(actionKey)) {
383 mItems.add(getSettingsAction());
384 } else if (GLOBAL_ACTION_KEY_LOCKDOWN.equals(actionKey)) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500385 if (Settings.Secure.getIntForUser(mContentResolver,
Chad Brubaker02cd6cf2018-05-01 14:59:33 -0700386 Settings.Secure.LOCKDOWN_IN_POWER_MENU, 0, getCurrentUser().id) != 0
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800387 && shouldDisplayLockdown()) {
Chad Brubaker4f28f0d2017-09-07 14:28:13 -0700388 mItems.add(getLockdownAction());
389 }
Jason Monk361915c2017-03-21 20:33:59 -0400390 } else if (GLOBAL_ACTION_KEY_VOICEASSIST.equals(actionKey)) {
391 mItems.add(getVoiceAssistAction());
392 } else if (GLOBAL_ACTION_KEY_ASSIST.equals(actionKey)) {
393 mItems.add(getAssistAction());
394 } else if (GLOBAL_ACTION_KEY_RESTART.equals(actionKey)) {
395 mItems.add(new RestartAction());
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500396 } else if (GLOBAL_ACTION_KEY_SCREENSHOT.equals(actionKey)) {
397 mItems.add(new ScreenshotAction());
Alex Chau04458852017-11-27 18:21:23 +0000398 } else if (GLOBAL_ACTION_KEY_LOGOUT.equals(actionKey)) {
Alex Chaud7958272017-12-08 11:30:52 +0000399 if (mDevicePolicyManager.isLogoutEnabled()
Alex Chau04458852017-11-27 18:21:23 +0000400 && getCurrentUser().id != UserHandle.USER_SYSTEM) {
401 mItems.add(new LogoutAction());
Alex Chau04458852017-11-27 18:21:23 +0000402 }
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800403 } else if (GLOBAL_ACTION_KEY_EMERGENCY.equals(actionKey)) {
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400404 if (!mEmergencyAffordanceManager.needsEmergencyAffordance()) {
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800405 mItems.add(new EmergencyDialerAction());
406 }
Jason Monk361915c2017-03-21 20:33:59 -0400407 } else {
408 Log.e(TAG, "Invalid global action key " + actionKey);
409 }
410 // Add here so we don't add more than one.
411 addedKeys.add(actionKey);
412 }
413
414 if (mEmergencyAffordanceManager.needsEmergencyAffordance()) {
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400415 mItems.add(new EmergencyAffordanceAction());
Jason Monk361915c2017-03-21 20:33:59 -0400416 }
417
418 mAdapter = new MyAdapter();
419
Steve Elliott9b87a442019-03-05 10:24:16 -0500420 GlobalActionsPanelPlugin.PanelViewController panelViewController =
Steve Elliotta3f5207922019-03-18 13:37:22 -0400421 mPanelPlugin != null
422 ? mPanelPlugin.onPanelShown(
Steve Elliott4c868852019-03-14 16:25:41 -0400423 new GlobalActionsPanelPlugin.Callbacks() {
424 @Override
425 public void dismissGlobalActionsMenu() {
Steve Elliottc3147e22019-11-20 19:34:57 -0500426 dismissDialog();
Steve Elliott4c868852019-03-14 16:25:41 -0400427 }
428
429 @Override
430 public void startPendingIntentDismissingKeyguard(
431 PendingIntent intent) {
432 mActivityStarter
433 .startPendingIntentDismissingKeyguard(intent);
434 }
Steve Elliotte2a2e9b2019-04-30 21:31:03 -0400435 },
Fabian Kozynskif6063ae2020-02-24 16:14:35 -0500436 !mKeyguardStateController.isUnlocked())
Steve Elliott9b87a442019-03-05 10:24:16 -0500437 : null;
Steve Elliott02bbaaa2019-05-01 16:55:33 -0400438
Lucas Dupin991415e2019-11-25 17:48:58 -0800439 ActionsDialog dialog = new ActionsDialog(mContext, mAdapter, panelViewController,
Santiago Etchebehere68eb53e2020-02-25 14:25:34 -0800440 mDepthController, mSysuiColorExtractor, mStatusBarService,
Matt Pietal22231792020-01-23 09:51:09 -0500441 mNotificationShadeWindowController,
Matt Pietale0661b62020-01-29 14:35:31 -0500442 shouldShowControls() ? mControlsUiController : null);
Jason Monk361915c2017-03-21 20:33:59 -0400443 dialog.setCanceledOnTouchOutside(false); // Handled by the custom class.
Lucas Dupinc1cc7592017-05-22 15:56:16 -0700444 dialog.setKeyguardShowing(mKeyguardShowing);
Jason Monk361915c2017-03-21 20:33:59 -0400445
446 dialog.setOnDismissListener(this);
Shaotang Li786da902018-08-02 11:18:00 +0800447 dialog.setOnShowListener(this);
Jason Monk361915c2017-03-21 20:33:59 -0400448
449 return dialog;
450 }
451
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800452 private boolean shouldDisplayLockdown() {
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800453 // Lockdown is meaningless without a place to go.
Fabian Kozynskif6063ae2020-02-24 16:14:35 -0500454 if (!mKeyguardStateController.isMethodSecure()) {
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800455 return false;
456 }
457
Fabian Kozynskif6063ae2020-02-24 16:14:35 -0500458 int userId = getCurrentUser().id;
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800459 // Only show the lockdown button if the device isn't locked down (for whatever reason).
460 int state = mLockPatternUtils.getStrongAuthForUser(userId);
461 return (state == STRONG_AUTH_NOT_REQUIRED
462 || state == SOME_AUTH_REQUIRED_AFTER_USER_REQUEST);
463 }
464
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700465 @Override
466 public void onUiModeChanged() {
467 mContext.getTheme().applyStyle(mContext.getThemeResId(), true);
Lucas Dupina4e12ba2019-04-18 11:56:28 -0700468 if (mDialog != null && mDialog.isShowing()) {
Aaron Heuckroth4ef3a542019-04-01 14:17:23 -0400469 mDialog.refreshDialog();
470 }
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700471 }
472
473 public void destroy() {
Dave Mankoff8df818e2020-02-12 14:22:26 -0500474 mConfigurationController.removeCallback(this);
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700475 }
476
Jason Monk361915c2017-03-21 20:33:59 -0400477 private final class PowerAction extends SinglePressAction implements LongPressAction {
478 private PowerAction() {
479 super(R.drawable.ic_lock_power_off,
Jason Monk16fbd9d2017-04-27 14:28:49 -0400480 R.string.global_action_power_off);
Jason Monk361915c2017-03-21 20:33:59 -0400481 }
482
483 @Override
484 public boolean onLongPress() {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500485 if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) {
Jason Monk361915c2017-03-21 20:33:59 -0400486 mWindowManagerFuncs.reboot(true);
487 return true;
488 }
489 return false;
490 }
491
492 @Override
493 public boolean showDuringKeyguard() {
494 return true;
495 }
496
497 @Override
498 public boolean showBeforeProvisioning() {
499 return true;
500 }
501
502 @Override
503 public void onPress() {
504 // shutdown by making sure radio and power are handled accordingly.
505 mWindowManagerFuncs.shutdown();
506 }
507 }
508
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400509 private abstract class EmergencyAction extends SinglePressAction {
510 EmergencyAction(int iconResId, int messageResId) {
511 super(iconResId, messageResId);
512 }
513
514 @Override
515 public boolean shouldBeSeparated() {
Aran Ink780d4502020-02-14 10:39:58 -0500516 return true;
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400517 }
518
519 @Override
520 public View create(
521 Context context, View convertView, ViewGroup parent, LayoutInflater inflater) {
522 View v = super.create(context, convertView, parent, inflater);
523 int textColor;
524 if (shouldBeSeparated()) {
525 textColor = v.getResources().getColor(
526 com.android.systemui.R.color.global_actions_alert_text);
527 } else {
528 textColor = v.getResources().getColor(
529 com.android.systemui.R.color.global_actions_text);
530 }
531 TextView messageView = v.findViewById(R.id.message);
532 messageView.setTextColor(textColor);
Aaron Heuckroth3f2d8b52019-04-05 13:27:51 -0400533 messageView.setSelected(true); // necessary for marquee to work
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400534 ImageView icon = (ImageView) v.findViewById(R.id.icon);
535 icon.getDrawable().setTint(textColor);
536 return v;
537 }
538
539 @Override
540 public boolean showDuringKeyguard() {
541 return true;
542 }
543
544 @Override
545 public boolean showBeforeProvisioning() {
546 return true;
547 }
548 }
549
550 private class EmergencyAffordanceAction extends EmergencyAction {
551 EmergencyAffordanceAction() {
552 super(R.drawable.emergency_icon,
553 R.string.global_action_emergency);
554 }
555
556 @Override
557 public void onPress() {
558 mEmergencyAffordanceManager.performEmergencyCall();
559 }
560 }
561
562 private class EmergencyDialerAction extends EmergencyAction {
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800563 private EmergencyDialerAction() {
Aran Ink50195262019-05-30 10:55:37 -0400564 super(com.android.systemui.R.drawable.ic_emergency_star,
Wesley.CW Wang3004fcb2018-06-15 16:24:57 +0800565 R.string.global_action_emergency);
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800566 }
567
568 @Override
569 public void onPress() {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500570 mMetricsLogger.action(MetricsEvent.ACTION_EMERGENCY_DIALER_FROM_POWER_MENU);
Dave Mankoff3c6aaab2020-01-10 17:50:34 -0500571 if (mTelecomManager != null) {
572 Intent intent = mTelecomManager.createLaunchEmergencyDialerIntent(
573 null /* number */);
574 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
575 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
576 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
577 intent.putExtra(EmergencyDialerConstants.EXTRA_ENTRY_TYPE,
578 EmergencyDialerConstants.ENTRY_TYPE_POWER_MENU);
579 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
580 }
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800581 }
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800582 }
583
Jason Monk361915c2017-03-21 20:33:59 -0400584 private final class RestartAction extends SinglePressAction implements LongPressAction {
585 private RestartAction() {
586 super(R.drawable.ic_restart, R.string.global_action_restart);
587 }
588
589 @Override
590 public boolean onLongPress() {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500591 if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) {
Jason Monk361915c2017-03-21 20:33:59 -0400592 mWindowManagerFuncs.reboot(true);
593 return true;
594 }
595 return false;
596 }
597
598 @Override
599 public boolean showDuringKeyguard() {
600 return true;
601 }
602
603 @Override
604 public boolean showBeforeProvisioning() {
605 return true;
606 }
607
608 @Override
609 public void onPress() {
610 mWindowManagerFuncs.reboot(false);
611 }
612 }
613
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400614 private class ScreenshotAction extends SinglePressAction implements LongPressAction {
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500615 public ScreenshotAction() {
616 super(R.drawable.ic_screenshot, R.string.global_action_screenshot);
617 }
618
619 @Override
620 public void onPress() {
621 // Add a little delay before executing, to give the
622 // dialog a chance to go away before it takes a
623 // screenshot.
624 // TODO: instead, omit global action dialog layer
625 mHandler.postDelayed(new Runnable() {
626 @Override
627 public void run() {
James O'Learyfa5bb7a2019-09-05 13:43:29 -0400628 mScreenshotHelper.takeScreenshot(1, true, true, mHandler, null);
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500629 mMetricsLogger.action(MetricsEvent.ACTION_SCREENSHOT_POWER_MENU);
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500630 }
631 }, 500);
632 }
633
634 @Override
635 public boolean showDuringKeyguard() {
636 return true;
637 }
638
639 @Override
640 public boolean showBeforeProvisioning() {
641 return false;
642 }
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400643
644 @Override
645 public boolean onLongPress() {
646 if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SCREENRECORD_LONG_PRESS)) {
647 mScreenRecordHelper.launchRecordPrompt();
648 } else {
649 onPress();
650 }
651 return true;
652 }
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500653 }
654
Jason Monk361915c2017-03-21 20:33:59 -0400655 private class BugReportAction extends SinglePressAction implements LongPressAction {
656
657 public BugReportAction() {
658 super(R.drawable.ic_lock_bugreport, R.string.bugreport_title);
659 }
660
661 @Override
662 public void onPress() {
663 // don't actually trigger the bugreport if we are running stability
664 // tests via monkey
665 if (ActivityManager.isUserAMonkey()) {
666 return;
667 }
668 // Add a little delay before executing, to give the
669 // dialog a chance to go away before it takes a
670 // screenshot.
671 mHandler.postDelayed(new Runnable() {
672 @Override
673 public void run() {
674 try {
675 // Take an "interactive" bugreport.
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500676 mMetricsLogger.action(
Jason Monk361915c2017-03-21 20:33:59 -0400677 MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_INTERACTIVE);
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500678 if (!mIActivityManager.launchBugReportHandlerApp()) {
Paul Changc40f5782019-11-04 18:55:31 +0800679 Log.w(TAG, "Bugreport handler could not be launched");
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500680 mIActivityManager.requestInteractiveBugReport();
Paul Changc40f5782019-11-04 18:55:31 +0800681 }
Jason Monk361915c2017-03-21 20:33:59 -0400682 } catch (RemoteException e) {
683 }
684 }
685 }, 500);
686 }
687
688 @Override
689 public boolean onLongPress() {
690 // don't actually trigger the bugreport if we are running stability
691 // tests via monkey
692 if (ActivityManager.isUserAMonkey()) {
693 return false;
694 }
695 try {
696 // Take a "full" bugreport.
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500697 mMetricsLogger.action(MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_FULL);
698 mIActivityManager.requestFullBugReport();
Jason Monk361915c2017-03-21 20:33:59 -0400699 } catch (RemoteException e) {
700 }
701 return false;
702 }
703
704 public boolean showDuringKeyguard() {
705 return true;
706 }
707
708 @Override
709 public boolean showBeforeProvisioning() {
710 return false;
711 }
Jason Monk361915c2017-03-21 20:33:59 -0400712 }
713
Alex Chau04458852017-11-27 18:21:23 +0000714 private final class LogoutAction extends SinglePressAction {
715 private LogoutAction() {
716 super(R.drawable.ic_logout, R.string.global_action_logout);
717 }
718
719 @Override
720 public boolean showDuringKeyguard() {
721 return true;
722 }
723
724 @Override
725 public boolean showBeforeProvisioning() {
726 return false;
727 }
728
729 @Override
730 public void onPress() {
731 // Add a little delay before executing, to give the dialog a chance to go away before
732 // switching user
733 mHandler.postDelayed(() -> {
734 try {
Alex Chauedb6a012018-01-26 12:52:43 +0000735 int currentUserId = getCurrentUser().id;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500736 mIActivityManager.switchUser(UserHandle.USER_SYSTEM);
737 mIActivityManager.stopUser(currentUserId, true /*force*/, null);
Alex Chau04458852017-11-27 18:21:23 +0000738 } catch (RemoteException re) {
739 Log.e(TAG, "Couldn't logout user " + re);
740 }
741 }, 500);
742 }
743 }
744
Jason Monk361915c2017-03-21 20:33:59 -0400745 private Action getSettingsAction() {
746 return new SinglePressAction(R.drawable.ic_settings,
747 R.string.global_action_settings) {
748
749 @Override
750 public void onPress() {
751 Intent intent = new Intent(Settings.ACTION_SETTINGS);
752 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
753 mContext.startActivity(intent);
754 }
755
756 @Override
757 public boolean showDuringKeyguard() {
758 return true;
759 }
760
761 @Override
762 public boolean showBeforeProvisioning() {
763 return true;
764 }
765 };
766 }
767
Jason Monk361915c2017-03-21 20:33:59 -0400768 private Action getAssistAction() {
769 return new SinglePressAction(R.drawable.ic_action_assist_focused,
770 R.string.global_action_assist) {
771 @Override
772 public void onPress() {
773 Intent intent = new Intent(Intent.ACTION_ASSIST);
774 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
775 mContext.startActivity(intent);
776 }
777
778 @Override
779 public boolean showDuringKeyguard() {
780 return true;
781 }
782
783 @Override
784 public boolean showBeforeProvisioning() {
785 return true;
786 }
787 };
788 }
789
790 private Action getVoiceAssistAction() {
791 return new SinglePressAction(R.drawable.ic_voice_search,
792 R.string.global_action_voice_assist) {
793 @Override
794 public void onPress() {
795 Intent intent = new Intent(Intent.ACTION_VOICE_ASSIST);
796 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
797 mContext.startActivity(intent);
798 }
799
800 @Override
801 public boolean showDuringKeyguard() {
802 return true;
803 }
804
805 @Override
806 public boolean showBeforeProvisioning() {
807 return true;
808 }
809 };
810 }
811
812 private Action getLockdownAction() {
Alison Cichowlas21125432018-05-16 15:40:45 -0400813 return new SinglePressAction(R.drawable.ic_lock_lockdown,
Jason Monk361915c2017-03-21 20:33:59 -0400814 R.string.global_action_lockdown) {
815
816 @Override
817 public void onPress() {
Dave Mankoff8df818e2020-02-12 14:22:26 -0500818 mLockPatternUtils.requireStrongAuth(STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN,
819 UserHandle.USER_ALL);
Jason Monk361915c2017-03-21 20:33:59 -0400820 try {
Dave Mankoff8df818e2020-02-12 14:22:26 -0500821 mIWindowManager.lockNow(null);
Pavel Grafov059021b2018-05-02 13:44:46 +0100822 // Lock profiles (if any) on the background thread.
Dave Mankoff8df818e2020-02-12 14:22:26 -0500823 mBackgroundExecutor.execute(() -> lockProfiles());
Jason Monk361915c2017-03-21 20:33:59 -0400824 } catch (RemoteException e) {
825 Log.e(TAG, "Error while trying to lock device.", e);
826 }
827 }
828
829 @Override
830 public boolean showDuringKeyguard() {
831 return true;
832 }
833
834 @Override
835 public boolean showBeforeProvisioning() {
836 return false;
837 }
838 };
839 }
840
Pavel Grafov059021b2018-05-02 13:44:46 +0100841 private void lockProfiles() {
Pavel Grafov059021b2018-05-02 13:44:46 +0100842 final int currentUserId = getCurrentUser().id;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500843 final int[] profileIds = mUserManager.getEnabledProfileIds(currentUserId);
Pavel Grafov059021b2018-05-02 13:44:46 +0100844 for (final int id : profileIds) {
845 if (id != currentUserId) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500846 mTrustManager.setDeviceLockedForUser(id, true);
Pavel Grafov059021b2018-05-02 13:44:46 +0100847 }
848 }
849 }
850
Jason Monk361915c2017-03-21 20:33:59 -0400851 private UserInfo getCurrentUser() {
852 try {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500853 return mIActivityManager.getCurrentUser();
Jason Monk361915c2017-03-21 20:33:59 -0400854 } catch (RemoteException re) {
855 return null;
856 }
857 }
858
859 private boolean isCurrentUserOwner() {
860 UserInfo currentUser = getCurrentUser();
861 return currentUser == null || currentUser.isPrimary();
862 }
863
864 private void addUsersToMenu(ArrayList<Action> items) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500865 if (mUserManager.isUserSwitcherEnabled()) {
866 List<UserInfo> users = mUserManager.getUsers();
Jason Monk361915c2017-03-21 20:33:59 -0400867 UserInfo currentUser = getCurrentUser();
868 for (final UserInfo user : users) {
869 if (user.supportsSwitchToByUser()) {
870 boolean isCurrentUser = currentUser == null
871 ? user.id == 0 : (currentUser.id == user.id);
872 Drawable icon = user.iconPath != null ? Drawable.createFromPath(user.iconPath)
873 : null;
874 SinglePressAction switchToUser = new SinglePressAction(
875 R.drawable.ic_menu_cc, icon,
876 (user.name != null ? user.name : "Primary")
Jason Monk16fbd9d2017-04-27 14:28:49 -0400877 + (isCurrentUser ? " \u2714" : "")) {
Jason Monk361915c2017-03-21 20:33:59 -0400878 public void onPress() {
879 try {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500880 mIActivityManager.switchUser(user.id);
Jason Monk361915c2017-03-21 20:33:59 -0400881 } catch (RemoteException re) {
882 Log.e(TAG, "Couldn't switch user " + re);
883 }
884 }
885
886 public boolean showDuringKeyguard() {
887 return true;
888 }
889
890 public boolean showBeforeProvisioning() {
891 return false;
892 }
893 };
894 items.add(switchToUser);
895 }
896 }
897 }
898 }
899
900 private void prepareDialog() {
901 refreshSilentMode();
902 mAirplaneModeOn.updateState(mAirplaneState);
903 mAdapter.notifyDataSetChanged();
Jason Monk361915c2017-03-21 20:33:59 -0400904 if (mShowSilentToggle) {
905 IntentFilter filter = new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION);
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000906 mBroadcastDispatcher.registerReceiver(mRingerModeReceiver, filter);
Jason Monk361915c2017-03-21 20:33:59 -0400907 }
908 }
909
910 private void refreshSilentMode() {
911 if (!mHasVibrator) {
912 final boolean silentModeOn =
913 mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL;
Jason Monk16fbd9d2017-04-27 14:28:49 -0400914 ((ToggleAction) mSilentModeAction).updateState(
Jason Monk361915c2017-03-21 20:33:59 -0400915 silentModeOn ? ToggleAction.State.On : ToggleAction.State.Off);
916 }
917 }
918
919 /** {@inheritDoc} */
920 public void onDismiss(DialogInterface dialog) {
Steve Elliottc3147e22019-11-20 19:34:57 -0500921 if (mDialog == dialog) {
922 mDialog = null;
923 }
Jason Monk361915c2017-03-21 20:33:59 -0400924 mWindowManagerFuncs.onGlobalActionsHidden();
925 if (mShowSilentToggle) {
926 try {
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000927 mBroadcastDispatcher.unregisterReceiver(mRingerModeReceiver);
Jason Monk361915c2017-03-21 20:33:59 -0400928 } catch (IllegalArgumentException ie) {
929 // ignore this
930 Log.w(TAG, ie);
931 }
932 }
933 }
934
935 /** {@inheritDoc} */
Shaotang Li786da902018-08-02 11:18:00 +0800936 public void onShow(DialogInterface dialog) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500937 mMetricsLogger.visible(MetricsEvent.POWER_MENU);
Shaotang Li786da902018-08-02 11:18:00 +0800938 }
939
Jason Monk361915c2017-03-21 20:33:59 -0400940 /**
941 * The adapter used for the list within the global actions dialog, taking
942 * into account whether the keyguard is showing via
Jason Monk16fbd9d2017-04-27 14:28:49 -0400943 * {@link com.android.systemui.globalactions.GlobalActionsDialog#mKeyguardShowing} and whether
944 * the device is provisioned
Jason Monk361915c2017-03-21 20:33:59 -0400945 * via {@link com.android.systemui.globalactions.GlobalActionsDialog#mDeviceProvisioned}.
946 */
Aaron Heuckroth57d60d22019-03-05 14:00:12 -0500947 public class MyAdapter extends MultiListAdapter {
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -0400948 private int countItems(boolean separated) {
Jason Monk361915c2017-03-21 20:33:59 -0400949 int count = 0;
Jason Monk361915c2017-03-21 20:33:59 -0400950 for (int i = 0; i < mItems.size(); i++) {
951 final Action action = mItems.get(i);
952
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -0400953 if (shouldBeShown(action) && action.shouldBeSeparated() == separated) {
954 count++;
Jason Monk361915c2017-03-21 20:33:59 -0400955 }
Jason Monk361915c2017-03-21 20:33:59 -0400956 }
957 return count;
958 }
959
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -0400960 private boolean shouldBeShown(Action action) {
961 if (mKeyguardShowing && !action.showDuringKeyguard()) {
962 return false;
963 }
964 if (!mDeviceProvisioned && !action.showBeforeProvisioning()) {
965 return false;
966 }
967 return true;
968 }
969
970 @Override
971 public int countSeparatedItems() {
972 return countItems(true);
973 }
974
975 @Override
976 public int countListItems() {
977 return countItems(false);
978 }
979
980 @Override
981 public int getCount() {
982 return countSeparatedItems() + countListItems();
983 }
984
Jason Monk361915c2017-03-21 20:33:59 -0400985 @Override
986 public boolean isEnabled(int position) {
987 return getItem(position).isEnabled();
988 }
989
Aaron Heuckroth57d60d22019-03-05 14:00:12 -0500990 @Override
Jason Monk361915c2017-03-21 20:33:59 -0400991 public boolean areAllItemsEnabled() {
992 return false;
993 }
994
Aaron Heuckroth57d60d22019-03-05 14:00:12 -0500995 @Override
Jason Monk361915c2017-03-21 20:33:59 -0400996 public Action getItem(int position) {
Jason Monk361915c2017-03-21 20:33:59 -0400997 int filteredPos = 0;
998 for (int i = 0; i < mItems.size(); i++) {
999 final Action action = mItems.get(i);
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -04001000 if (!shouldBeShown(action)) {
Jason Monk361915c2017-03-21 20:33:59 -04001001 continue;
1002 }
1003 if (filteredPos == position) {
1004 return action;
1005 }
1006 filteredPos++;
1007 }
1008
1009 throw new IllegalArgumentException("position " + position
1010 + " out of range of showable actions"
1011 + ", filtered count=" + getCount()
1012 + ", keyguardshowing=" + mKeyguardShowing
1013 + ", provisioned=" + mDeviceProvisioned);
1014 }
1015
1016
1017 public long getItemId(int position) {
1018 return position;
1019 }
1020
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001021 @Override
Jason Monk361915c2017-03-21 20:33:59 -04001022 public View getView(int position, View convertView, ViewGroup parent) {
1023 Action action = getItem(position);
Jason Monk16fbd9d2017-04-27 14:28:49 -04001024 View view = action.create(mContext, convertView, parent, LayoutInflater.from(mContext));
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -04001025 view.setOnClickListener(v -> onClickItem(position));
Aran Inkb4199d92020-02-07 13:25:21 -05001026 if (action instanceof LongPressAction) {
1027 view.setOnLongClickListener(v -> onLongClickItem(position));
1028 }
Jason Monk16fbd9d2017-04-27 14:28:49 -04001029 return view;
Jason Monk361915c2017-03-21 20:33:59 -04001030 }
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001031
1032 @Override
1033 public boolean onLongClickItem(int position) {
1034 final Action action = mAdapter.getItem(position);
1035 if (action instanceof LongPressAction) {
Aran Inkbaa25862019-06-11 15:48:55 -04001036 if (mDialog != null) {
1037 mDialog.dismiss();
1038 } else {
1039 Log.w(TAG, "Action long-clicked while mDialog is null.");
1040 }
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001041 return ((LongPressAction) action).onLongPress();
1042 }
1043 return false;
1044 }
1045
1046 @Override
1047 public void onClickItem(int position) {
1048 Action item = mAdapter.getItem(position);
1049 if (!(item instanceof SilentModeTriStateAction)) {
Aran Inkbaa25862019-06-11 15:48:55 -04001050 if (mDialog != null) {
1051 mDialog.dismiss();
1052 } else {
1053 Log.w(TAG, "Action clicked while mDialog is null.");
1054 }
1055 item.onPress();
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001056 }
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001057 }
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -04001058
1059 @Override
1060 public boolean shouldBeSeparated(int position) {
1061 return getItem(position).shouldBeSeparated();
1062 }
Jason Monk361915c2017-03-21 20:33:59 -04001063 }
1064
1065 // note: the scheme below made more sense when we were planning on having
1066 // 8 different things in the global actions dialog. seems overkill with
1067 // only 3 items now, but may as well keep this flexible approach so it will
1068 // be easy should someone decide at the last minute to include something
1069 // else, such as 'enable wifi', or 'enable bluetooth'
1070
1071 /**
1072 * What each item in the global actions dialog must be able to support.
1073 */
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001074 public interface Action {
Jason Monk361915c2017-03-21 20:33:59 -04001075 /**
1076 * @return Text that will be announced when dialog is created. null
Jason Monk16fbd9d2017-04-27 14:28:49 -04001077 * for none.
Jason Monk361915c2017-03-21 20:33:59 -04001078 */
1079 CharSequence getLabelForAccessibility(Context context);
1080
1081 View create(Context context, View convertView, ViewGroup parent, LayoutInflater inflater);
1082
1083 void onPress();
1084
1085 /**
1086 * @return whether this action should appear in the dialog when the keygaurd
Jason Monk16fbd9d2017-04-27 14:28:49 -04001087 * is showing.
Jason Monk361915c2017-03-21 20:33:59 -04001088 */
1089 boolean showDuringKeyguard();
1090
1091 /**
1092 * @return whether this action should appear in the dialog before the
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001093 * device is provisioned.onlongpress
1094 *
Jason Monk361915c2017-03-21 20:33:59 -04001095 */
1096 boolean showBeforeProvisioning();
1097
1098 boolean isEnabled();
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001099
1100 default boolean shouldBeSeparated() {
1101 return false;
1102 }
Jason Monk361915c2017-03-21 20:33:59 -04001103 }
1104
1105 /**
1106 * An action that also supports long press.
1107 */
1108 private interface LongPressAction extends Action {
1109 boolean onLongPress();
1110 }
1111
1112 /**
1113 * A single press action maintains no state, just responds to a press
1114 * and takes an action.
1115 */
Matt Pietale0661b62020-01-29 14:35:31 -05001116
1117 private abstract class SinglePressAction implements Action {
Jason Monk361915c2017-03-21 20:33:59 -04001118 private final int mIconResId;
1119 private final Drawable mIcon;
1120 private final int mMessageResId;
1121 private final CharSequence mMessage;
1122
1123 protected SinglePressAction(int iconResId, int messageResId) {
1124 mIconResId = iconResId;
1125 mMessageResId = messageResId;
1126 mMessage = null;
1127 mIcon = null;
1128 }
1129
1130 protected SinglePressAction(int iconResId, Drawable icon, CharSequence message) {
1131 mIconResId = iconResId;
1132 mMessageResId = 0;
1133 mMessage = message;
1134 mIcon = icon;
1135 }
1136
1137 public boolean isEnabled() {
1138 return true;
1139 }
1140
1141 public String getStatus() {
1142 return null;
1143 }
1144
1145 abstract public void onPress();
1146
1147 public CharSequence getLabelForAccessibility(Context context) {
1148 if (mMessage != null) {
1149 return mMessage;
1150 } else {
1151 return context.getString(mMessageResId);
1152 }
1153 }
1154
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001155 protected int getActionLayoutId(Context context) {
Matt Pietale0661b62020-01-29 14:35:31 -05001156 if (shouldShowControls()) {
Matt Pietalfd3b6cb2020-01-08 09:43:54 -05001157 return com.android.systemui.R.layout.global_actions_grid_item_v2;
1158 }
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001159 return com.android.systemui.R.layout.global_actions_grid_item;
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001160 }
1161
Jason Monk361915c2017-03-21 20:33:59 -04001162 public View create(
1163 Context context, View convertView, ViewGroup parent, LayoutInflater inflater) {
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001164 View v = inflater.inflate(getActionLayoutId(context), parent,
Jason Monk16fbd9d2017-04-27 14:28:49 -04001165 false);
Jason Monk361915c2017-03-21 20:33:59 -04001166
1167 ImageView icon = (ImageView) v.findViewById(R.id.icon);
1168 TextView messageView = (TextView) v.findViewById(R.id.message);
Aaron Heuckroth3f2d8b52019-04-05 13:27:51 -04001169 messageView.setSelected(true); // necessary for marquee to work
Jason Monk361915c2017-03-21 20:33:59 -04001170
Jason Monk361915c2017-03-21 20:33:59 -04001171 if (mIcon != null) {
1172 icon.setImageDrawable(mIcon);
1173 icon.setScaleType(ScaleType.CENTER_CROP);
1174 } else if (mIconResId != 0) {
1175 icon.setImageDrawable(context.getDrawable(mIconResId));
1176 }
1177 if (mMessage != null) {
1178 messageView.setText(mMessage);
1179 } else {
1180 messageView.setText(mMessageResId);
1181 }
1182
1183 return v;
1184 }
1185 }
1186
1187 /**
1188 * A toggle action knows whether it is on or off, and displays an icon
1189 * and status message accordingly.
1190 */
1191 private static abstract class ToggleAction implements Action {
1192
1193 enum State {
1194 Off(false),
1195 TurningOn(true),
1196 TurningOff(true),
1197 On(false);
1198
1199 private final boolean inTransition;
1200
1201 State(boolean intermediate) {
1202 inTransition = intermediate;
1203 }
1204
1205 public boolean inTransition() {
1206 return inTransition;
1207 }
1208 }
1209
1210 protected State mState = State.Off;
1211
1212 // prefs
1213 protected int mEnabledIconResId;
1214 protected int mDisabledIconResid;
1215 protected int mMessageResId;
1216 protected int mEnabledStatusMessageResId;
1217 protected int mDisabledStatusMessageResId;
1218
1219 /**
Jason Monk16fbd9d2017-04-27 14:28:49 -04001220 * @param enabledIconResId The icon for when this action is on.
1221 * @param disabledIconResid The icon for when this action is off.
1222 * @param message The general information message, e.g 'Silent Mode'
1223 * @param enabledStatusMessageResId The on status message, e.g 'sound disabled'
Jason Monk361915c2017-03-21 20:33:59 -04001224 * @param disabledStatusMessageResId The off status message, e.g. 'sound enabled'
1225 */
1226 public ToggleAction(int enabledIconResId,
1227 int disabledIconResid,
1228 int message,
1229 int enabledStatusMessageResId,
1230 int disabledStatusMessageResId) {
1231 mEnabledIconResId = enabledIconResId;
1232 mDisabledIconResid = disabledIconResid;
1233 mMessageResId = message;
1234 mEnabledStatusMessageResId = enabledStatusMessageResId;
1235 mDisabledStatusMessageResId = disabledStatusMessageResId;
1236 }
1237
1238 /**
1239 * Override to make changes to resource IDs just before creating the
1240 * View.
1241 */
1242 void willCreate() {
1243
1244 }
1245
1246 @Override
1247 public CharSequence getLabelForAccessibility(Context context) {
1248 return context.getString(mMessageResId);
1249 }
1250
1251 public View create(Context context, View convertView, ViewGroup parent,
1252 LayoutInflater inflater) {
1253 willCreate();
1254
Koji Fukui5c010ee2019-12-24 16:12:07 +09001255 View v = inflater.inflate(com.android.systemui.R
1256 .layout.global_actions_grid_item, parent, false);
Jason Monk361915c2017-03-21 20:33:59 -04001257
1258 ImageView icon = (ImageView) v.findViewById(R.id.icon);
1259 TextView messageView = (TextView) v.findViewById(R.id.message);
Jason Monk361915c2017-03-21 20:33:59 -04001260 final boolean enabled = isEnabled();
Koji Fukui5c010ee2019-12-24 16:12:07 +09001261 boolean on = ((mState == State.On) || (mState == State.TurningOn));
Jason Monk361915c2017-03-21 20:33:59 -04001262
1263 if (messageView != null) {
Koji Fukui5c010ee2019-12-24 16:12:07 +09001264 messageView.setText(on ? mEnabledStatusMessageResId : mDisabledStatusMessageResId);
Jason Monk361915c2017-03-21 20:33:59 -04001265 messageView.setEnabled(enabled);
Aaron Heuckroth3f2d8b52019-04-05 13:27:51 -04001266 messageView.setSelected(true); // necessary for marquee to work
Jason Monk361915c2017-03-21 20:33:59 -04001267 }
1268
Jason Monk361915c2017-03-21 20:33:59 -04001269 if (icon != null) {
1270 icon.setImageDrawable(context.getDrawable(
1271 (on ? mEnabledIconResId : mDisabledIconResid)));
1272 icon.setEnabled(enabled);
1273 }
1274
Jason Monk361915c2017-03-21 20:33:59 -04001275 v.setEnabled(enabled);
1276
1277 return v;
1278 }
1279
1280 public final void onPress() {
1281 if (mState.inTransition()) {
1282 Log.w(TAG, "shouldn't be able to toggle when in transition");
1283 return;
1284 }
1285
1286 final boolean nowOn = !(mState == State.On);
1287 onToggle(nowOn);
1288 changeStateFromPress(nowOn);
1289 }
1290
1291 public boolean isEnabled() {
1292 return !mState.inTransition();
1293 }
1294
1295 /**
1296 * Implementations may override this if their state can be in on of the intermediate
1297 * states until some notification is received (e.g airplane mode is 'turning off' until
1298 * we know the wireless connections are back online
Jason Monk16fbd9d2017-04-27 14:28:49 -04001299 *
Jason Monk361915c2017-03-21 20:33:59 -04001300 * @param buttonOn Whether the button was turned on or off
1301 */
1302 protected void changeStateFromPress(boolean buttonOn) {
1303 mState = buttonOn ? State.On : State.Off;
1304 }
1305
1306 abstract void onToggle(boolean on);
1307
1308 public void updateState(State state) {
1309 mState = state;
1310 }
1311 }
1312
Aran Ink780d4502020-02-14 10:39:58 -05001313 private class AirplaneModeAction extends ToggleAction {
1314 AirplaneModeAction() {
1315 super(
1316 R.drawable.ic_lock_airplane_mode,
1317 R.drawable.ic_lock_airplane_mode_off,
1318 R.string.global_actions_toggle_airplane_mode,
1319 R.string.global_actions_airplane_mode_on_status,
1320 R.string.global_actions_airplane_mode_off_status);
1321 }
1322 void onToggle(boolean on) {
1323 if (mHasTelephony && TelephonyProperties.in_ecm_mode().orElse(false)) {
1324 mIsWaitingForEcmExit = true;
1325 // Launch ECM exit dialog
1326 Intent ecmDialogIntent =
1327 new Intent(TelephonyManager.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null);
1328 ecmDialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1329 mContext.startActivity(ecmDialogIntent);
1330 } else {
1331 changeAirplaneModeSystemSetting(on);
1332 }
1333 }
1334
1335 @Override
1336 protected void changeStateFromPress(boolean buttonOn) {
1337 if (!mHasTelephony) return;
1338
1339 // In ECM mode airplane state cannot be changed
1340 if (!TelephonyProperties.in_ecm_mode().orElse(false)) {
1341 mState = buttonOn ? State.TurningOn : State.TurningOff;
1342 mAirplaneState = mState;
1343 }
1344 }
1345
1346 public boolean showDuringKeyguard() {
1347 return true;
1348 }
1349
1350 public boolean showBeforeProvisioning() {
1351 return false;
1352 }
1353 }
1354
Jason Monk361915c2017-03-21 20:33:59 -04001355 private class SilentModeToggleAction extends ToggleAction {
1356 public SilentModeToggleAction() {
1357 super(R.drawable.ic_audio_vol_mute,
1358 R.drawable.ic_audio_vol,
1359 R.string.global_action_toggle_silent_mode,
1360 R.string.global_action_silent_mode_on_status,
1361 R.string.global_action_silent_mode_off_status);
1362 }
1363
1364 void onToggle(boolean on) {
1365 if (on) {
1366 mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
1367 } else {
1368 mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
1369 }
1370 }
1371
1372 public boolean showDuringKeyguard() {
1373 return true;
1374 }
1375
1376 public boolean showBeforeProvisioning() {
1377 return false;
1378 }
1379 }
1380
1381 private static class SilentModeTriStateAction implements Action, View.OnClickListener {
1382
Jason Monk16fbd9d2017-04-27 14:28:49 -04001383 private final int[] ITEM_IDS = {R.id.option1, R.id.option2, R.id.option3};
Jason Monk361915c2017-03-21 20:33:59 -04001384
1385 private final AudioManager mAudioManager;
1386 private final Handler mHandler;
Jason Monk361915c2017-03-21 20:33:59 -04001387
Lucas Dupin40ec6b782018-06-05 19:07:16 -07001388 SilentModeTriStateAction(AudioManager audioManager, Handler handler) {
Jason Monk361915c2017-03-21 20:33:59 -04001389 mAudioManager = audioManager;
1390 mHandler = handler;
Jason Monk361915c2017-03-21 20:33:59 -04001391 }
1392
1393 private int ringerModeToIndex(int ringerMode) {
1394 // They just happen to coincide
1395 return ringerMode;
1396 }
1397
1398 private int indexToRingerMode(int index) {
1399 // They just happen to coincide
1400 return index;
1401 }
1402
1403 @Override
1404 public CharSequence getLabelForAccessibility(Context context) {
1405 return null;
1406 }
1407
1408 public View create(Context context, View convertView, ViewGroup parent,
1409 LayoutInflater inflater) {
1410 View v = inflater.inflate(R.layout.global_actions_silent_mode, parent, false);
1411
1412 int selectedIndex = ringerModeToIndex(mAudioManager.getRingerMode());
1413 for (int i = 0; i < 3; i++) {
1414 View itemView = v.findViewById(ITEM_IDS[i]);
1415 itemView.setSelected(selectedIndex == i);
1416 // Set up click handler
1417 itemView.setTag(i);
1418 itemView.setOnClickListener(this);
1419 }
1420 return v;
1421 }
1422
1423 public void onPress() {
1424 }
1425
1426 public boolean showDuringKeyguard() {
1427 return true;
1428 }
1429
1430 public boolean showBeforeProvisioning() {
1431 return false;
1432 }
1433
1434 public boolean isEnabled() {
1435 return true;
1436 }
1437
1438 void willCreate() {
1439 }
1440
1441 public void onClick(View v) {
1442 if (!(v.getTag() instanceof Integer)) return;
1443
1444 int index = (Integer) v.getTag();
1445 mAudioManager.setRingerMode(indexToRingerMode(index));
1446 mHandler.sendEmptyMessageDelayed(MESSAGE_DISMISS, DIALOG_DISMISS_DELAY);
1447 }
1448 }
1449
1450 private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
1451 public void onReceive(Context context, Intent intent) {
1452 String action = intent.getAction();
1453 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)
1454 || Intent.ACTION_SCREEN_OFF.equals(action)) {
1455 String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY);
1456 if (!SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS.equals(reason)) {
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001457 mHandler.sendMessage(mHandler.obtainMessage(MESSAGE_DISMISS, reason));
Jason Monk361915c2017-03-21 20:33:59 -04001458 }
Jayachandran C142eae02019-12-13 19:29:20 -08001459 } else if (TelephonyManager.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED.equals(action)) {
Jason Monk361915c2017-03-21 20:33:59 -04001460 // Airplane mode can be changed after ECM exits if airplane toggle button
1461 // is pressed during ECM mode
Daniel Bright4bcbfce2020-01-09 21:58:16 -08001462 if (!(intent.getBooleanExtra(TelephonyManager.EXTRA_PHONE_IN_ECM_STATE, false))
1463 && mIsWaitingForEcmExit) {
Jason Monk361915c2017-03-21 20:33:59 -04001464 mIsWaitingForEcmExit = false;
1465 changeAirplaneModeSystemSetting(true);
1466 }
1467 }
1468 }
1469 };
1470
1471 PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
1472 @Override
1473 public void onServiceStateChanged(ServiceState serviceState) {
1474 if (!mHasTelephony) return;
1475 final boolean inAirplaneMode = serviceState.getState() == ServiceState.STATE_POWER_OFF;
1476 mAirplaneState = inAirplaneMode ? ToggleAction.State.On : ToggleAction.State.Off;
1477 mAirplaneModeOn.updateState(mAirplaneState);
1478 mAdapter.notifyDataSetChanged();
1479 }
1480 };
1481
1482 private BroadcastReceiver mRingerModeReceiver = new BroadcastReceiver() {
1483 @Override
1484 public void onReceive(Context context, Intent intent) {
1485 if (intent.getAction().equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
1486 mHandler.sendEmptyMessage(MESSAGE_REFRESH);
1487 }
1488 }
1489 };
1490
1491 private ContentObserver mAirplaneModeObserver = new ContentObserver(new Handler()) {
1492 @Override
1493 public void onChange(boolean selfChange) {
1494 onAirplaneModeChanged();
1495 }
1496 };
1497
1498 private static final int MESSAGE_DISMISS = 0;
1499 private static final int MESSAGE_REFRESH = 1;
1500 private static final int MESSAGE_SHOW = 2;
1501 private static final int DIALOG_DISMISS_DELAY = 300; // ms
1502
1503 private Handler mHandler = new Handler() {
1504 public void handleMessage(Message msg) {
1505 switch (msg.what) {
Jason Monk16fbd9d2017-04-27 14:28:49 -04001506 case MESSAGE_DISMISS:
1507 if (mDialog != null) {
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001508 if (SYSTEM_DIALOG_REASON_DREAM.equals(msg.obj)) {
1509 mDialog.dismissImmediately();
1510 } else {
1511 mDialog.dismiss();
1512 }
Jason Monk16fbd9d2017-04-27 14:28:49 -04001513 mDialog = null;
1514 }
1515 break;
1516 case MESSAGE_REFRESH:
1517 refreshSilentMode();
1518 mAdapter.notifyDataSetChanged();
1519 break;
1520 case MESSAGE_SHOW:
1521 handleShow();
1522 break;
Jason Monk361915c2017-03-21 20:33:59 -04001523 }
1524 }
1525 };
1526
1527 private void onAirplaneModeChanged() {
1528 // Let the service state callbacks handle the state.
1529 if (mHasTelephony) return;
1530
1531 boolean airplaneModeOn = Settings.Global.getInt(
Dave Mankoffc88a2d72020-01-10 15:59:31 -05001532 mContentResolver,
Jason Monk361915c2017-03-21 20:33:59 -04001533 Settings.Global.AIRPLANE_MODE_ON,
1534 0) == 1;
1535 mAirplaneState = airplaneModeOn ? ToggleAction.State.On : ToggleAction.State.Off;
1536 mAirplaneModeOn.updateState(mAirplaneState);
1537 }
1538
1539 /**
1540 * Change the airplane mode system setting
1541 */
1542 private void changeAirplaneModeSystemSetting(boolean on) {
1543 Settings.Global.putInt(
Dave Mankoffc88a2d72020-01-10 15:59:31 -05001544 mContentResolver,
Jason Monk361915c2017-03-21 20:33:59 -04001545 Settings.Global.AIRPLANE_MODE_ON,
1546 on ? 1 : 0);
1547 Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
1548 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
1549 intent.putExtra("state", on);
1550 mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
1551 if (!mHasTelephony) {
1552 mAirplaneState = on ? ToggleAction.State.On : ToggleAction.State.Off;
1553 }
1554 }
1555
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001556 private static final class ActionsDialog extends Dialog implements DialogInterface,
1557 ColorExtractor.OnColorsChangedListener {
Jason Monk361915c2017-03-21 20:33:59 -04001558
Jason Monk16fbd9d2017-04-27 14:28:49 -04001559 private final Context mContext;
1560 private final MyAdapter mAdapter;
Steve Elliott53f12ae2019-05-13 17:14:15 -04001561 private final IStatusBarService mStatusBarService;
1562 private final IBinder mToken = new Binder();
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001563 private MultiListLayout mGlobalActionsLayout;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001564 private Drawable mBackgroundDrawable;
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001565 private final SysuiColorExtractor mColorExtractor;
Steve Elliott9b87a442019-03-05 10:24:16 -05001566 private final GlobalActionsPanelPlugin.PanelViewController mPanelController;
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001567 private boolean mKeyguardShowing;
Beverly526d2d62018-08-15 12:55:33 -04001568 private boolean mShowing;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001569 private float mScrimAlpha;
Steve Elliott48f75db2019-05-03 15:03:38 -04001570 private ResetOrientationData mResetOrientationData;
Steve Elliottff2c0d92019-07-30 15:09:54 -04001571 private boolean mHadTopUi;
wilsonshihe8321942019-10-18 18:39:46 +08001572 private final NotificationShadeWindowController mNotificationShadeWindowController;
Santiago Etchebehere68eb53e2020-02-25 14:25:34 -08001573 private final NotificationShadeDepthController mDepthController;
Matt Pietal22231792020-01-23 09:51:09 -05001574
1575 private ControlsUiController mControlsUiController;
1576 private ViewGroup mControlsView;
Jason Monk16fbd9d2017-04-27 14:28:49 -04001577
Aaron Heuckrothf19d2722019-03-11 17:06:02 -04001578 ActionsDialog(Context context, MyAdapter adapter,
Santiago Etchebehere68eb53e2020-02-25 14:25:34 -08001579 GlobalActionsPanelPlugin.PanelViewController plugin,
1580 NotificationShadeDepthController depthController,
Lucas Dupin991415e2019-11-25 17:48:58 -08001581 SysuiColorExtractor sysuiColorExtractor, IStatusBarService statusBarService,
1582 NotificationShadeWindowController notificationShadeWindowController,
Matt Pietal22231792020-01-23 09:51:09 -05001583 ControlsUiController controlsUiController) {
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001584 super(context, com.android.systemui.R.style.Theme_SystemUI_Dialog_GlobalActions);
Lucas Dupin448786c2017-07-24 17:44:25 -07001585 mContext = context;
Jason Monk16fbd9d2017-04-27 14:28:49 -04001586 mAdapter = adapter;
Santiago Etchebehere68eb53e2020-02-25 14:25:34 -08001587 mDepthController = depthController;
Lucas Dupin991415e2019-11-25 17:48:58 -08001588 mColorExtractor = sysuiColorExtractor;
1589 mStatusBarService = statusBarService;
1590 mNotificationShadeWindowController = notificationShadeWindowController;
Matt Pietal22231792020-01-23 09:51:09 -05001591 mControlsUiController = controlsUiController;
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001592
1593 // Window initialization
1594 Window window = getWindow();
1595 window.requestFeature(Window.FEATURE_NO_TITLE);
Adrian Roosedfab3b2018-03-08 18:39:20 +01001596 // Inflate the decor view, so the attributes below are not overwritten by the theme.
1597 window.getDecorView();
1598 window.getAttributes().systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1599 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1600 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1601 window.setLayout(MATCH_PARENT, MATCH_PARENT);
1602 window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
Alison Cichowlas4f19f4a2017-07-25 10:56:16 -04001603 window.addFlags(
1604 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001605 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
Adrian Roosedfab3b2018-03-08 18:39:20 +01001606 | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001607 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
1608 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
1609 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001610 window.setType(WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY);
Tiger Huang52724442020-01-20 21:38:42 +08001611 window.getAttributes().setFitInsetsTypes(0 /* types */);
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001612 setTitle(R.string.global_actions);
Steve Elliott9b87a442019-03-05 10:24:16 -05001613
1614 mPanelController = plugin;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001615 initializeLayout();
Steve Elliott9b87a442019-03-05 10:24:16 -05001616 }
1617
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001618 private boolean shouldUsePanel() {
Aran Ink3f594552019-05-13 14:29:35 -04001619 return mPanelController != null && mPanelController.getPanelContent() != null;
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001620 }
1621
1622 private void initializePanel() {
Steve Elliott48f75db2019-05-03 15:03:38 -04001623 int rotation = RotationUtils.getRotation(mContext);
1624 boolean rotationLocked = RotationPolicy.isRotationLocked(mContext);
1625 if (rotation != RotationUtils.ROTATION_NONE) {
1626 if (rotationLocked) {
1627 if (mResetOrientationData == null) {
1628 mResetOrientationData = new ResetOrientationData();
1629 mResetOrientationData.locked = true;
1630 mResetOrientationData.rotation = rotation;
1631 }
1632
1633 // Unlock rotation, so user can choose to rotate to portrait to see the panel.
Steve Elliotte05817f2019-05-17 14:39:53 -04001634 // This call is posted so that the rotation does not change until post-layout,
1635 // otherwise onConfigurationChanged() may not get invoked.
1636 mGlobalActionsLayout.post(() ->
1637 RotationPolicy.setRotationLockAtAngle(
1638 mContext, false, RotationUtils.ROTATION_NONE));
Steve Elliott48f75db2019-05-03 15:03:38 -04001639 }
1640 } else {
1641 if (!rotationLocked) {
1642 if (mResetOrientationData == null) {
1643 mResetOrientationData = new ResetOrientationData();
1644 mResetOrientationData.locked = false;
1645 }
1646
1647 // Lock to portrait, so the user doesn't accidentally hide the panel.
Steve Elliotte05817f2019-05-17 14:39:53 -04001648 // This call is posted so that the rotation does not change until post-layout,
1649 // otherwise onConfigurationChanged() may not get invoked.
1650 mGlobalActionsLayout.post(() ->
1651 RotationPolicy.setRotationLockAtAngle(
1652 mContext, true, RotationUtils.ROTATION_NONE));
Steve Elliott48f75db2019-05-03 15:03:38 -04001653 }
1654
Steve Elliott53f12ae2019-05-13 17:14:15 -04001655 // Disable rotation suggestions, if enabled
1656 setRotationSuggestionsEnabled(false);
1657
Steve Elliott300b48f2019-05-29 14:13:50 -04001658 FrameLayout panelContainer =
1659 findViewById(com.android.systemui.R.id.global_actions_panel_container);
Steve Elliott48f75db2019-05-03 15:03:38 -04001660 FrameLayout.LayoutParams panelParams =
1661 new FrameLayout.LayoutParams(
1662 FrameLayout.LayoutParams.MATCH_PARENT,
Steve Elliott300b48f2019-05-29 14:13:50 -04001663 FrameLayout.LayoutParams.MATCH_PARENT);
Steve Elliott48f75db2019-05-03 15:03:38 -04001664 panelContainer.addView(mPanelController.getPanelContent(), panelParams);
Steve Elliott48f75db2019-05-03 15:03:38 -04001665 }
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001666 }
1667
1668 private void initializeLayout() {
1669 setContentView(getGlobalActionsLayoutId(mContext));
Steve Elliott300b48f2019-05-29 14:13:50 -04001670 fixNavBarClipping();
Matt Pietal22231792020-01-23 09:51:09 -05001671 mControlsView = findViewById(com.android.systemui.R.id.global_actions_controls);
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001672 mGlobalActionsLayout = findViewById(com.android.systemui.R.id.global_actions_view);
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001673 mGlobalActionsLayout.setOutsideTouchListener(view -> dismiss());
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001674 mGlobalActionsLayout.setListViewAccessibilityDelegate(new View.AccessibilityDelegate() {
Phil Weaver9054e092018-04-27 16:28:50 -07001675 @Override
1676 public boolean dispatchPopulateAccessibilityEvent(
1677 View host, AccessibilityEvent event) {
1678 // Populate the title here, just as Activity does
1679 event.getText().add(mContext.getString(R.string.global_actions));
1680 return true;
1681 }
1682 });
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001683 mGlobalActionsLayout.setRotationListener(this::onRotate);
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001684 mGlobalActionsLayout.setAdapter(mAdapter);
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001685
Aran Ink06090262020-03-03 13:23:17 -05001686 View globalActionsParent = (View) mGlobalActionsLayout.getParent();
1687 globalActionsParent.setOnClickListener(v -> dismiss());
1688
1689 // add fall-through dismiss handling to root view
1690 View rootView = findViewById(com.android.systemui.R.id.global_actions_grid_root);
1691 if (rootView != null) {
1692 rootView.setOnClickListener(v -> dismiss());
1693 }
1694
Steve Elliott86ef6282019-05-08 14:45:04 -04001695 if (shouldUsePanel()) {
Steve Elliottc59eb342019-04-23 16:59:06 -04001696 initializePanel();
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001697 }
Steve Elliott86ef6282019-05-08 14:45:04 -04001698 if (mBackgroundDrawable == null) {
1699 mBackgroundDrawable = new ScrimDrawable();
Lucas Dupin43d01242020-02-03 11:58:33 -08001700 mScrimAlpha = ScrimController.BUSY_SCRIM_ALPHA;
Steve Elliott86ef6282019-05-08 14:45:04 -04001701 }
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001702 getWindow().setBackgroundDrawable(mBackgroundDrawable);
Steve Elliott9b87a442019-03-05 10:24:16 -05001703 }
1704
Steve Elliott300b48f2019-05-29 14:13:50 -04001705 private void fixNavBarClipping() {
1706 ViewGroup content = findViewById(android.R.id.content);
1707 content.setClipChildren(false);
1708 content.setClipToPadding(false);
1709 ViewGroup contentParent = (ViewGroup) content.getParent();
1710 contentParent.setClipChildren(false);
1711 contentParent.setClipToPadding(false);
1712 }
1713
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001714 private int getGlobalActionsLayoutId(Context context) {
Matt Pietal22231792020-01-23 09:51:09 -05001715 if (mControlsUiController != null) {
Matt Pietalfd3b6cb2020-01-08 09:43:54 -05001716 return com.android.systemui.R.layout.global_actions_grid_v2;
1717 }
1718
Steve Elliottdc165632019-05-23 14:26:31 -04001719 int rotation = RotationUtils.getRotation(context);
1720 boolean useGridLayout = isForceGridEnabled(context)
1721 || (shouldUsePanel() && rotation == RotationUtils.ROTATION_NONE);
1722 if (rotation == RotationUtils.ROTATION_SEASCAPE) {
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001723 if (useGridLayout) {
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001724 return com.android.systemui.R.layout.global_actions_grid_seascape;
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001725 } else {
1726 return com.android.systemui.R.layout.global_actions_column_seascape;
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001727 }
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001728 } else {
1729 if (useGridLayout) {
1730 return com.android.systemui.R.layout.global_actions_grid;
1731 } else {
1732 return com.android.systemui.R.layout.global_actions_column;
1733 }
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001734 }
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001735 }
1736
Jason Monk361915c2017-03-21 20:33:59 -04001737 @Override
1738 protected void onStart() {
1739 super.setCanceledOnTouchOutside(true);
1740 super.onStart();
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001741 mGlobalActionsLayout.updateList();
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001742
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001743 if (mBackgroundDrawable instanceof ScrimDrawable) {
Steve Elliott9b87a442019-03-05 10:24:16 -05001744 mColorExtractor.addOnColorsChangedListener(this);
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001745 GradientColors colors = mColorExtractor.getNeutralColors();
Steve Elliott9b87a442019-03-05 10:24:16 -05001746 updateColors(colors, false /* animate */);
1747 }
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001748 }
1749
1750 /**
1751 * Updates background and system bars according to current GradientColors.
1752 * @param colors Colors and hints to use.
1753 * @param animate Interpolates gradient if true, just sets otherwise.
1754 */
1755 private void updateColors(GradientColors colors, boolean animate) {
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001756 if (!(mBackgroundDrawable instanceof ScrimDrawable)) {
Steve Elliott9b87a442019-03-05 10:24:16 -05001757 return;
1758 }
Lucas Dupinba2b48a2020-02-06 09:28:06 -08001759 ((ScrimDrawable) mBackgroundDrawable).setColor(colors.supportsDarkText() ? Color.WHITE
1760 : Color.BLACK, animate);
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001761 View decorView = getWindow().getDecorView();
1762 if (colors.supportsDarkText()) {
1763 decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR |
Steve Elliott9b87a442019-03-05 10:24:16 -05001764 View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001765 } else {
1766 decorView.setSystemUiVisibility(0);
1767 }
Jason Monk361915c2017-03-21 20:33:59 -04001768 }
1769
1770 @Override
Jason Monk16fbd9d2017-04-27 14:28:49 -04001771 protected void onStop() {
1772 super.onStop();
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001773 mColorExtractor.removeOnColorsChangedListener(this);
Jason Monk16fbd9d2017-04-27 14:28:49 -04001774 }
1775
1776 @Override
1777 public void show() {
1778 super.show();
Beverly526d2d62018-08-15 12:55:33 -04001779 mShowing = true;
wilsonshihe8321942019-10-18 18:39:46 +08001780 mHadTopUi = mNotificationShadeWindowController.getForceHasTopUi();
1781 mNotificationShadeWindowController.setForceHasTopUi(true);
Steve Elliott9b87a442019-03-05 10:24:16 -05001782 mBackgroundDrawable.setAlpha(0);
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001783 mGlobalActionsLayout.setTranslationX(mGlobalActionsLayout.getAnimationOffsetX());
1784 mGlobalActionsLayout.setTranslationY(mGlobalActionsLayout.getAnimationOffsetY());
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001785 mGlobalActionsLayout.setAlpha(0);
1786 mGlobalActionsLayout.animate()
Jason Monk16fbd9d2017-04-27 14:28:49 -04001787 .alpha(1)
1788 .translationX(0)
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001789 .translationY(0)
Jason Monk16fbd9d2017-04-27 14:28:49 -04001790 .setDuration(300)
Lucas Dupinde9db422017-07-19 17:15:41 -07001791 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001792 .setUpdateListener(animation -> {
Lucas Dupin991415e2019-11-25 17:48:58 -08001793 float animatedValue = animation.getAnimatedFraction();
1794 int alpha = (int) (animatedValue * mScrimAlpha * 255);
Steve Elliott9b87a442019-03-05 10:24:16 -05001795 mBackgroundDrawable.setAlpha(alpha);
Santiago Etchebehere68eb53e2020-02-25 14:25:34 -08001796 mDepthController.updateGlobalDialogVisibility(animatedValue,
1797 mGlobalActionsLayout);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001798 })
Jason Monk16fbd9d2017-04-27 14:28:49 -04001799 .start();
Matt Pietal22231792020-01-23 09:51:09 -05001800 if (mControlsUiController != null) {
1801 mControlsUiController.show(mControlsView);
1802 }
Jason Monk16fbd9d2017-04-27 14:28:49 -04001803 }
1804
1805 @Override
1806 public void dismiss() {
Beverly526d2d62018-08-15 12:55:33 -04001807 if (!mShowing) {
1808 return;
1809 }
1810 mShowing = false;
Matt Pietal22231792020-01-23 09:51:09 -05001811 if (mControlsUiController != null) mControlsUiController.hide();
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001812 mGlobalActionsLayout.setTranslationX(0);
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001813 mGlobalActionsLayout.setTranslationY(0);
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001814 mGlobalActionsLayout.setAlpha(1);
1815 mGlobalActionsLayout.animate()
Jason Monk16fbd9d2017-04-27 14:28:49 -04001816 .alpha(0)
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001817 .translationX(mGlobalActionsLayout.getAnimationOffsetX())
1818 .translationY(mGlobalActionsLayout.getAnimationOffsetY())
Jason Monk16fbd9d2017-04-27 14:28:49 -04001819 .setDuration(300)
Steve Elliottff2c0d92019-07-30 15:09:54 -04001820 .withEndAction(this::completeDismiss)
Jason Monk16fbd9d2017-04-27 14:28:49 -04001821 .setInterpolator(new LogAccelerateInterpolator())
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001822 .setUpdateListener(animation -> {
Lucas Dupin991415e2019-11-25 17:48:58 -08001823 float animatedValue = 1f - animation.getAnimatedFraction();
1824 int alpha = (int) (animatedValue * mScrimAlpha * 255);
Steve Elliott9b87a442019-03-05 10:24:16 -05001825 mBackgroundDrawable.setAlpha(alpha);
Santiago Etchebehere68eb53e2020-02-25 14:25:34 -08001826 mDepthController.updateGlobalDialogVisibility(animatedValue,
1827 mGlobalActionsLayout);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001828 })
Jason Monk16fbd9d2017-04-27 14:28:49 -04001829 .start();
Steve Elliott48f75db2019-05-03 15:03:38 -04001830 dismissPanel();
1831 resetOrientation();
Jason Monk16fbd9d2017-04-27 14:28:49 -04001832 }
1833
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001834 void dismissImmediately() {
Beverly526d2d62018-08-15 12:55:33 -04001835 mShowing = false;
Matt Pietal019feaa2020-01-31 14:51:37 -05001836 if (mControlsUiController != null) mControlsUiController.hide();
Steve Elliott48f75db2019-05-03 15:03:38 -04001837 dismissPanel();
1838 resetOrientation();
Steve Elliottff2c0d92019-07-30 15:09:54 -04001839 completeDismiss();
1840 }
1841
1842 private void completeDismiss() {
wilsonshihe8321942019-10-18 18:39:46 +08001843 mNotificationShadeWindowController.setForceHasTopUi(mHadTopUi);
Steve Elliottff2c0d92019-07-30 15:09:54 -04001844 super.dismiss();
Steve Elliott48f75db2019-05-03 15:03:38 -04001845 }
1846
1847 private void dismissPanel() {
Steve Elliott2d206d32019-03-14 16:30:33 -04001848 if (mPanelController != null) {
1849 mPanelController.onDismissed();
1850 }
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001851 }
1852
Steve Elliott53f12ae2019-05-13 17:14:15 -04001853 private void setRotationSuggestionsEnabled(boolean enabled) {
1854 try {
1855 final int userId = Binder.getCallingUserHandle().getIdentifier();
1856 final int what = enabled
1857 ? StatusBarManager.DISABLE2_NONE
1858 : StatusBarManager.DISABLE2_ROTATE_SUGGESTIONS;
1859 mStatusBarService.disable2ForUser(what, mToken, mContext.getPackageName(), userId);
1860 } catch (RemoteException ex) {
1861 throw ex.rethrowFromSystemServer();
1862 }
1863 }
1864
Steve Elliott48f75db2019-05-03 15:03:38 -04001865 private void resetOrientation() {
1866 if (mResetOrientationData != null) {
1867 RotationPolicy.setRotationLockAtAngle(mContext, mResetOrientationData.locked,
1868 mResetOrientationData.rotation);
1869 }
Steve Elliott53f12ae2019-05-13 17:14:15 -04001870 setRotationSuggestionsEnabled(true);
Steve Elliott48f75db2019-05-03 15:03:38 -04001871 }
1872
Jason Monk361915c2017-03-21 20:33:59 -04001873 @Override
Lucas Dupin7aaa3532017-05-28 08:51:07 -07001874 public void onColorsChanged(ColorExtractor extractor, int which) {
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001875 if (mKeyguardShowing) {
1876 if ((WallpaperManager.FLAG_LOCK & which) != 0) {
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001877 updateColors(extractor.getColors(WallpaperManager.FLAG_LOCK),
1878 true /* animate */);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001879 }
1880 } else {
1881 if ((WallpaperManager.FLAG_SYSTEM & which) != 0) {
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001882 updateColors(extractor.getColors(WallpaperManager.FLAG_SYSTEM),
1883 true /* animate */);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001884 }
1885 }
1886 }
1887
1888 public void setKeyguardShowing(boolean keyguardShowing) {
1889 mKeyguardShowing = keyguardShowing;
1890 }
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001891
Aaron Heuckroth4ef3a542019-04-01 14:17:23 -04001892 public void refreshDialog() {
1893 initializeLayout();
1894 mGlobalActionsLayout.updateList();
1895 }
1896
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001897 public void onRotate(int from, int to) {
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001898 if (mShowing) {
Aaron Heuckroth4ef3a542019-04-01 14:17:23 -04001899 refreshDialog();
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001900 }
1901 }
Steve Elliott48f75db2019-05-03 15:03:38 -04001902
1903 private static class ResetOrientationData {
1904 public boolean locked;
1905 public int rotation;
1906 }
Jason Monk361915c2017-03-21 20:33:59 -04001907 }
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001908
1909 /**
Aran Ink93dd25c2019-05-09 14:42:14 -04001910 * Determines whether or not debug mode has been activated for the Global Actions Panel.
1911 */
1912 private static boolean isPanelDebugModeEnabled(Context context) {
1913 return Settings.Secure.getInt(context.getContentResolver(),
1914 Settings.Secure.GLOBAL_ACTIONS_PANEL_DEBUG_ENABLED, 0) == 1;
1915 }
1916
1917 /**
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001918 * Determines whether or not the Global Actions menu should be forced to
1919 * use the newer grid-style layout.
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001920 */
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001921 private static boolean isForceGridEnabled(Context context) {
Aran Ink93dd25c2019-05-09 14:42:14 -04001922 return isPanelDebugModeEnabled(context);
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001923 }
Aaron Heuckrothf19d2722019-03-11 17:06:02 -04001924
Matt Pietale0661b62020-01-29 14:35:31 -05001925 private boolean shouldShowControls() {
Fabian Kozynskif6063ae2020-02-24 16:14:35 -05001926 return mKeyguardStateController.isUnlocked()
Fabian Kozynski0424ab12020-02-21 12:09:17 -05001927 && mControlsUiController.getAvailable()
1928 && mAnyControlsProviders;
Matt Pietalfd3b6cb2020-01-08 09:43:54 -05001929 }
Jason Monk361915c2017-03-21 20:33:59 -04001930}