blob: 5da02dc57242367bf0ffa5ddd6842c8025befb09 [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 Dupin991415e2019-11-25 17:48:58 -0800102import com.android.systemui.statusbar.BlurUtils;
Matt Pietal22231792020-01-23 09:51:09 -0500103import com.android.systemui.statusbar.phone.NotificationShadeWindowController;
Lucas Dupin43d01242020-02-03 11:58:33 -0800104import com.android.systemui.statusbar.phone.ScrimController;
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700105import com.android.systemui.statusbar.policy.ConfigurationController;
Lucas Dupinc8f16e82019-09-17 18:24:50 -0400106import com.android.systemui.statusbar.policy.KeyguardStateController;
Shaotang Li5c422632018-07-04 14:18:40 +0800107import com.android.systemui.util.EmergencyDialerConstants;
Aaron Heuckroth75e249f2019-02-01 15:59:57 -0500108import com.android.systemui.util.leak.RotationUtils;
Julia Reynolds42411922017-11-08 11:19:09 -0500109import com.android.systemui.volume.SystemUIInterpolators.LogAccelerateInterpolator;
Lucas Dupinc1cc7592017-05-22 15:56:16 -0700110
Jason Monk361915c2017-03-21 20:33:59 -0400111import java.util.ArrayList;
112import java.util.List;
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;
Lucas Dupin991415e2019-11-25 17:48:58 -0800165 private final BlurUtils mBlurUtils;
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,
Lucas Dupin991415e2019-11-25 17:48:58 -0800209 TelecomManager telecomManager, MetricsLogger metricsLogger,
210 BlurUtils blurUtils, SysuiColorExtractor colorExtractor,
211 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;
Lucas Dupin991415e2019-11-25 17:48:58 -0800232 mBlurUtils = blurUtils;
233 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,
440 mBlurUtils, 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);
571 Intent intent = mTelecomManager.createLaunchEmergencyDialerIntent(null /* number */);
Leo Hsue4cc3122019-03-06 15:25:28 +0800572 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
573 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
574 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
Shaotang Li5c422632018-07-04 14:18:40 +0800575 intent.putExtra(EmergencyDialerConstants.EXTRA_ENTRY_TYPE,
576 EmergencyDialerConstants.ENTRY_TYPE_POWER_MENU);
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800577 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
578 }
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800579 }
580
Jason Monk361915c2017-03-21 20:33:59 -0400581 private final class RestartAction extends SinglePressAction implements LongPressAction {
582 private RestartAction() {
583 super(R.drawable.ic_restart, R.string.global_action_restart);
584 }
585
586 @Override
587 public boolean onLongPress() {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500588 if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) {
Jason Monk361915c2017-03-21 20:33:59 -0400589 mWindowManagerFuncs.reboot(true);
590 return true;
591 }
592 return false;
593 }
594
595 @Override
596 public boolean showDuringKeyguard() {
597 return true;
598 }
599
600 @Override
601 public boolean showBeforeProvisioning() {
602 return true;
603 }
604
605 @Override
606 public void onPress() {
607 mWindowManagerFuncs.reboot(false);
608 }
609 }
610
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400611 private class ScreenshotAction extends SinglePressAction implements LongPressAction {
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500612 public ScreenshotAction() {
613 super(R.drawable.ic_screenshot, R.string.global_action_screenshot);
614 }
615
616 @Override
617 public void onPress() {
618 // Add a little delay before executing, to give the
619 // dialog a chance to go away before it takes a
620 // screenshot.
621 // TODO: instead, omit global action dialog layer
622 mHandler.postDelayed(new Runnable() {
623 @Override
624 public void run() {
James O'Learyfa5bb7a2019-09-05 13:43:29 -0400625 mScreenshotHelper.takeScreenshot(1, true, true, mHandler, null);
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500626 mMetricsLogger.action(MetricsEvent.ACTION_SCREENSHOT_POWER_MENU);
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500627 }
628 }, 500);
629 }
630
631 @Override
632 public boolean showDuringKeyguard() {
633 return true;
634 }
635
636 @Override
637 public boolean showBeforeProvisioning() {
638 return false;
639 }
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400640
641 @Override
642 public boolean onLongPress() {
643 if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SCREENRECORD_LONG_PRESS)) {
644 mScreenRecordHelper.launchRecordPrompt();
645 } else {
646 onPress();
647 }
648 return true;
649 }
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500650 }
651
Jason Monk361915c2017-03-21 20:33:59 -0400652 private class BugReportAction extends SinglePressAction implements LongPressAction {
653
654 public BugReportAction() {
655 super(R.drawable.ic_lock_bugreport, R.string.bugreport_title);
656 }
657
658 @Override
659 public void onPress() {
660 // don't actually trigger the bugreport if we are running stability
661 // tests via monkey
662 if (ActivityManager.isUserAMonkey()) {
663 return;
664 }
665 // Add a little delay before executing, to give the
666 // dialog a chance to go away before it takes a
667 // screenshot.
668 mHandler.postDelayed(new Runnable() {
669 @Override
670 public void run() {
671 try {
672 // Take an "interactive" bugreport.
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500673 mMetricsLogger.action(
Jason Monk361915c2017-03-21 20:33:59 -0400674 MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_INTERACTIVE);
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500675 if (!mIActivityManager.launchBugReportHandlerApp()) {
Paul Changc40f5782019-11-04 18:55:31 +0800676 Log.w(TAG, "Bugreport handler could not be launched");
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500677 mIActivityManager.requestInteractiveBugReport();
Paul Changc40f5782019-11-04 18:55:31 +0800678 }
Jason Monk361915c2017-03-21 20:33:59 -0400679 } catch (RemoteException e) {
680 }
681 }
682 }, 500);
683 }
684
685 @Override
686 public boolean onLongPress() {
687 // don't actually trigger the bugreport if we are running stability
688 // tests via monkey
689 if (ActivityManager.isUserAMonkey()) {
690 return false;
691 }
692 try {
693 // Take a "full" bugreport.
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500694 mMetricsLogger.action(MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_FULL);
695 mIActivityManager.requestFullBugReport();
Jason Monk361915c2017-03-21 20:33:59 -0400696 } catch (RemoteException e) {
697 }
698 return false;
699 }
700
701 public boolean showDuringKeyguard() {
702 return true;
703 }
704
705 @Override
706 public boolean showBeforeProvisioning() {
707 return false;
708 }
Jason Monk361915c2017-03-21 20:33:59 -0400709 }
710
Alex Chau04458852017-11-27 18:21:23 +0000711 private final class LogoutAction extends SinglePressAction {
712 private LogoutAction() {
713 super(R.drawable.ic_logout, R.string.global_action_logout);
714 }
715
716 @Override
717 public boolean showDuringKeyguard() {
718 return true;
719 }
720
721 @Override
722 public boolean showBeforeProvisioning() {
723 return false;
724 }
725
726 @Override
727 public void onPress() {
728 // Add a little delay before executing, to give the dialog a chance to go away before
729 // switching user
730 mHandler.postDelayed(() -> {
731 try {
Alex Chauedb6a012018-01-26 12:52:43 +0000732 int currentUserId = getCurrentUser().id;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500733 mIActivityManager.switchUser(UserHandle.USER_SYSTEM);
734 mIActivityManager.stopUser(currentUserId, true /*force*/, null);
Alex Chau04458852017-11-27 18:21:23 +0000735 } catch (RemoteException re) {
736 Log.e(TAG, "Couldn't logout user " + re);
737 }
738 }, 500);
739 }
740 }
741
Jason Monk361915c2017-03-21 20:33:59 -0400742 private Action getSettingsAction() {
743 return new SinglePressAction(R.drawable.ic_settings,
744 R.string.global_action_settings) {
745
746 @Override
747 public void onPress() {
748 Intent intent = new Intent(Settings.ACTION_SETTINGS);
749 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
750 mContext.startActivity(intent);
751 }
752
753 @Override
754 public boolean showDuringKeyguard() {
755 return true;
756 }
757
758 @Override
759 public boolean showBeforeProvisioning() {
760 return true;
761 }
762 };
763 }
764
Jason Monk361915c2017-03-21 20:33:59 -0400765 private Action getAssistAction() {
766 return new SinglePressAction(R.drawable.ic_action_assist_focused,
767 R.string.global_action_assist) {
768 @Override
769 public void onPress() {
770 Intent intent = new Intent(Intent.ACTION_ASSIST);
771 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
772 mContext.startActivity(intent);
773 }
774
775 @Override
776 public boolean showDuringKeyguard() {
777 return true;
778 }
779
780 @Override
781 public boolean showBeforeProvisioning() {
782 return true;
783 }
784 };
785 }
786
787 private Action getVoiceAssistAction() {
788 return new SinglePressAction(R.drawable.ic_voice_search,
789 R.string.global_action_voice_assist) {
790 @Override
791 public void onPress() {
792 Intent intent = new Intent(Intent.ACTION_VOICE_ASSIST);
793 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
794 mContext.startActivity(intent);
795 }
796
797 @Override
798 public boolean showDuringKeyguard() {
799 return true;
800 }
801
802 @Override
803 public boolean showBeforeProvisioning() {
804 return true;
805 }
806 };
807 }
808
809 private Action getLockdownAction() {
Alison Cichowlas21125432018-05-16 15:40:45 -0400810 return new SinglePressAction(R.drawable.ic_lock_lockdown,
Jason Monk361915c2017-03-21 20:33:59 -0400811 R.string.global_action_lockdown) {
812
813 @Override
814 public void onPress() {
Dave Mankoff8df818e2020-02-12 14:22:26 -0500815 mLockPatternUtils.requireStrongAuth(STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN,
816 UserHandle.USER_ALL);
Jason Monk361915c2017-03-21 20:33:59 -0400817 try {
Dave Mankoff8df818e2020-02-12 14:22:26 -0500818 mIWindowManager.lockNow(null);
Pavel Grafov059021b2018-05-02 13:44:46 +0100819 // Lock profiles (if any) on the background thread.
Dave Mankoff8df818e2020-02-12 14:22:26 -0500820 mBackgroundExecutor.execute(() -> lockProfiles());
Jason Monk361915c2017-03-21 20:33:59 -0400821 } catch (RemoteException e) {
822 Log.e(TAG, "Error while trying to lock device.", e);
823 }
824 }
825
826 @Override
827 public boolean showDuringKeyguard() {
828 return true;
829 }
830
831 @Override
832 public boolean showBeforeProvisioning() {
833 return false;
834 }
835 };
836 }
837
Pavel Grafov059021b2018-05-02 13:44:46 +0100838 private void lockProfiles() {
Pavel Grafov059021b2018-05-02 13:44:46 +0100839 final int currentUserId = getCurrentUser().id;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500840 final int[] profileIds = mUserManager.getEnabledProfileIds(currentUserId);
Pavel Grafov059021b2018-05-02 13:44:46 +0100841 for (final int id : profileIds) {
842 if (id != currentUserId) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500843 mTrustManager.setDeviceLockedForUser(id, true);
Pavel Grafov059021b2018-05-02 13:44:46 +0100844 }
845 }
846 }
847
Jason Monk361915c2017-03-21 20:33:59 -0400848 private UserInfo getCurrentUser() {
849 try {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500850 return mIActivityManager.getCurrentUser();
Jason Monk361915c2017-03-21 20:33:59 -0400851 } catch (RemoteException re) {
852 return null;
853 }
854 }
855
856 private boolean isCurrentUserOwner() {
857 UserInfo currentUser = getCurrentUser();
858 return currentUser == null || currentUser.isPrimary();
859 }
860
861 private void addUsersToMenu(ArrayList<Action> items) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500862 if (mUserManager.isUserSwitcherEnabled()) {
863 List<UserInfo> users = mUserManager.getUsers();
Jason Monk361915c2017-03-21 20:33:59 -0400864 UserInfo currentUser = getCurrentUser();
865 for (final UserInfo user : users) {
866 if (user.supportsSwitchToByUser()) {
867 boolean isCurrentUser = currentUser == null
868 ? user.id == 0 : (currentUser.id == user.id);
869 Drawable icon = user.iconPath != null ? Drawable.createFromPath(user.iconPath)
870 : null;
871 SinglePressAction switchToUser = new SinglePressAction(
872 R.drawable.ic_menu_cc, icon,
873 (user.name != null ? user.name : "Primary")
Jason Monk16fbd9d2017-04-27 14:28:49 -0400874 + (isCurrentUser ? " \u2714" : "")) {
Jason Monk361915c2017-03-21 20:33:59 -0400875 public void onPress() {
876 try {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500877 mIActivityManager.switchUser(user.id);
Jason Monk361915c2017-03-21 20:33:59 -0400878 } catch (RemoteException re) {
879 Log.e(TAG, "Couldn't switch user " + re);
880 }
881 }
882
883 public boolean showDuringKeyguard() {
884 return true;
885 }
886
887 public boolean showBeforeProvisioning() {
888 return false;
889 }
890 };
891 items.add(switchToUser);
892 }
893 }
894 }
895 }
896
897 private void prepareDialog() {
898 refreshSilentMode();
899 mAirplaneModeOn.updateState(mAirplaneState);
900 mAdapter.notifyDataSetChanged();
Jason Monk361915c2017-03-21 20:33:59 -0400901 if (mShowSilentToggle) {
902 IntentFilter filter = new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION);
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000903 mBroadcastDispatcher.registerReceiver(mRingerModeReceiver, filter);
Jason Monk361915c2017-03-21 20:33:59 -0400904 }
905 }
906
907 private void refreshSilentMode() {
908 if (!mHasVibrator) {
909 final boolean silentModeOn =
910 mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL;
Jason Monk16fbd9d2017-04-27 14:28:49 -0400911 ((ToggleAction) mSilentModeAction).updateState(
Jason Monk361915c2017-03-21 20:33:59 -0400912 silentModeOn ? ToggleAction.State.On : ToggleAction.State.Off);
913 }
914 }
915
916 /** {@inheritDoc} */
917 public void onDismiss(DialogInterface dialog) {
Steve Elliottc3147e22019-11-20 19:34:57 -0500918 if (mDialog == dialog) {
919 mDialog = null;
920 }
Jason Monk361915c2017-03-21 20:33:59 -0400921 mWindowManagerFuncs.onGlobalActionsHidden();
922 if (mShowSilentToggle) {
923 try {
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000924 mBroadcastDispatcher.unregisterReceiver(mRingerModeReceiver);
Jason Monk361915c2017-03-21 20:33:59 -0400925 } catch (IllegalArgumentException ie) {
926 // ignore this
927 Log.w(TAG, ie);
928 }
929 }
930 }
931
932 /** {@inheritDoc} */
Shaotang Li786da902018-08-02 11:18:00 +0800933 public void onShow(DialogInterface dialog) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500934 mMetricsLogger.visible(MetricsEvent.POWER_MENU);
Shaotang Li786da902018-08-02 11:18:00 +0800935 }
936
Jason Monk361915c2017-03-21 20:33:59 -0400937 /**
938 * The adapter used for the list within the global actions dialog, taking
939 * into account whether the keyguard is showing via
Jason Monk16fbd9d2017-04-27 14:28:49 -0400940 * {@link com.android.systemui.globalactions.GlobalActionsDialog#mKeyguardShowing} and whether
941 * the device is provisioned
Jason Monk361915c2017-03-21 20:33:59 -0400942 * via {@link com.android.systemui.globalactions.GlobalActionsDialog#mDeviceProvisioned}.
943 */
Aaron Heuckroth57d60d22019-03-05 14:00:12 -0500944 public class MyAdapter extends MultiListAdapter {
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -0400945 private int countItems(boolean separated) {
Jason Monk361915c2017-03-21 20:33:59 -0400946 int count = 0;
Jason Monk361915c2017-03-21 20:33:59 -0400947 for (int i = 0; i < mItems.size(); i++) {
948 final Action action = mItems.get(i);
949
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -0400950 if (shouldBeShown(action) && action.shouldBeSeparated() == separated) {
951 count++;
Jason Monk361915c2017-03-21 20:33:59 -0400952 }
Jason Monk361915c2017-03-21 20:33:59 -0400953 }
954 return count;
955 }
956
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -0400957 private boolean shouldBeShown(Action action) {
958 if (mKeyguardShowing && !action.showDuringKeyguard()) {
959 return false;
960 }
961 if (!mDeviceProvisioned && !action.showBeforeProvisioning()) {
962 return false;
963 }
964 return true;
965 }
966
967 @Override
968 public int countSeparatedItems() {
969 return countItems(true);
970 }
971
972 @Override
973 public int countListItems() {
974 return countItems(false);
975 }
976
977 @Override
978 public int getCount() {
979 return countSeparatedItems() + countListItems();
980 }
981
Jason Monk361915c2017-03-21 20:33:59 -0400982 @Override
983 public boolean isEnabled(int position) {
984 return getItem(position).isEnabled();
985 }
986
Aaron Heuckroth57d60d22019-03-05 14:00:12 -0500987 @Override
Jason Monk361915c2017-03-21 20:33:59 -0400988 public boolean areAllItemsEnabled() {
989 return false;
990 }
991
Aaron Heuckroth57d60d22019-03-05 14:00:12 -0500992 @Override
Jason Monk361915c2017-03-21 20:33:59 -0400993 public Action getItem(int position) {
Jason Monk361915c2017-03-21 20:33:59 -0400994 int filteredPos = 0;
995 for (int i = 0; i < mItems.size(); i++) {
996 final Action action = mItems.get(i);
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -0400997 if (!shouldBeShown(action)) {
Jason Monk361915c2017-03-21 20:33:59 -0400998 continue;
999 }
1000 if (filteredPos == position) {
1001 return action;
1002 }
1003 filteredPos++;
1004 }
1005
1006 throw new IllegalArgumentException("position " + position
1007 + " out of range of showable actions"
1008 + ", filtered count=" + getCount()
1009 + ", keyguardshowing=" + mKeyguardShowing
1010 + ", provisioned=" + mDeviceProvisioned);
1011 }
1012
1013
1014 public long getItemId(int position) {
1015 return position;
1016 }
1017
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001018 @Override
Jason Monk361915c2017-03-21 20:33:59 -04001019 public View getView(int position, View convertView, ViewGroup parent) {
1020 Action action = getItem(position);
Jason Monk16fbd9d2017-04-27 14:28:49 -04001021 View view = action.create(mContext, convertView, parent, LayoutInflater.from(mContext));
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -04001022 view.setOnClickListener(v -> onClickItem(position));
Aran Inkb4199d92020-02-07 13:25:21 -05001023 if (action instanceof LongPressAction) {
1024 view.setOnLongClickListener(v -> onLongClickItem(position));
1025 }
Jason Monk16fbd9d2017-04-27 14:28:49 -04001026 return view;
Jason Monk361915c2017-03-21 20:33:59 -04001027 }
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001028
1029 @Override
1030 public boolean onLongClickItem(int position) {
1031 final Action action = mAdapter.getItem(position);
1032 if (action instanceof LongPressAction) {
Aran Inkbaa25862019-06-11 15:48:55 -04001033 if (mDialog != null) {
1034 mDialog.dismiss();
1035 } else {
1036 Log.w(TAG, "Action long-clicked while mDialog is null.");
1037 }
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001038 return ((LongPressAction) action).onLongPress();
1039 }
1040 return false;
1041 }
1042
1043 @Override
1044 public void onClickItem(int position) {
1045 Action item = mAdapter.getItem(position);
1046 if (!(item instanceof SilentModeTriStateAction)) {
Aran Inkbaa25862019-06-11 15:48:55 -04001047 if (mDialog != null) {
1048 mDialog.dismiss();
1049 } else {
1050 Log.w(TAG, "Action clicked while mDialog is null.");
1051 }
1052 item.onPress();
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001053 }
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001054 }
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -04001055
1056 @Override
1057 public boolean shouldBeSeparated(int position) {
1058 return getItem(position).shouldBeSeparated();
1059 }
Jason Monk361915c2017-03-21 20:33:59 -04001060 }
1061
1062 // note: the scheme below made more sense when we were planning on having
1063 // 8 different things in the global actions dialog. seems overkill with
1064 // only 3 items now, but may as well keep this flexible approach so it will
1065 // be easy should someone decide at the last minute to include something
1066 // else, such as 'enable wifi', or 'enable bluetooth'
1067
1068 /**
1069 * What each item in the global actions dialog must be able to support.
1070 */
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001071 public interface Action {
Jason Monk361915c2017-03-21 20:33:59 -04001072 /**
1073 * @return Text that will be announced when dialog is created. null
Jason Monk16fbd9d2017-04-27 14:28:49 -04001074 * for none.
Jason Monk361915c2017-03-21 20:33:59 -04001075 */
1076 CharSequence getLabelForAccessibility(Context context);
1077
1078 View create(Context context, View convertView, ViewGroup parent, LayoutInflater inflater);
1079
1080 void onPress();
1081
1082 /**
1083 * @return whether this action should appear in the dialog when the keygaurd
Jason Monk16fbd9d2017-04-27 14:28:49 -04001084 * is showing.
Jason Monk361915c2017-03-21 20:33:59 -04001085 */
1086 boolean showDuringKeyguard();
1087
1088 /**
1089 * @return whether this action should appear in the dialog before the
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001090 * device is provisioned.onlongpress
1091 *
Jason Monk361915c2017-03-21 20:33:59 -04001092 */
1093 boolean showBeforeProvisioning();
1094
1095 boolean isEnabled();
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001096
1097 default boolean shouldBeSeparated() {
1098 return false;
1099 }
Jason Monk361915c2017-03-21 20:33:59 -04001100 }
1101
1102 /**
1103 * An action that also supports long press.
1104 */
1105 private interface LongPressAction extends Action {
1106 boolean onLongPress();
1107 }
1108
1109 /**
1110 * A single press action maintains no state, just responds to a press
1111 * and takes an action.
1112 */
Matt Pietale0661b62020-01-29 14:35:31 -05001113
1114 private abstract class SinglePressAction implements Action {
Jason Monk361915c2017-03-21 20:33:59 -04001115 private final int mIconResId;
1116 private final Drawable mIcon;
1117 private final int mMessageResId;
1118 private final CharSequence mMessage;
1119
1120 protected SinglePressAction(int iconResId, int messageResId) {
1121 mIconResId = iconResId;
1122 mMessageResId = messageResId;
1123 mMessage = null;
1124 mIcon = null;
1125 }
1126
1127 protected SinglePressAction(int iconResId, Drawable icon, CharSequence message) {
1128 mIconResId = iconResId;
1129 mMessageResId = 0;
1130 mMessage = message;
1131 mIcon = icon;
1132 }
1133
1134 public boolean isEnabled() {
1135 return true;
1136 }
1137
1138 public String getStatus() {
1139 return null;
1140 }
1141
1142 abstract public void onPress();
1143
1144 public CharSequence getLabelForAccessibility(Context context) {
1145 if (mMessage != null) {
1146 return mMessage;
1147 } else {
1148 return context.getString(mMessageResId);
1149 }
1150 }
1151
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001152 protected int getActionLayoutId(Context context) {
Matt Pietale0661b62020-01-29 14:35:31 -05001153 if (shouldShowControls()) {
Matt Pietalfd3b6cb2020-01-08 09:43:54 -05001154 return com.android.systemui.R.layout.global_actions_grid_item_v2;
1155 }
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001156 return com.android.systemui.R.layout.global_actions_grid_item;
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001157 }
1158
Jason Monk361915c2017-03-21 20:33:59 -04001159 public View create(
1160 Context context, View convertView, ViewGroup parent, LayoutInflater inflater) {
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001161 View v = inflater.inflate(getActionLayoutId(context), parent,
Jason Monk16fbd9d2017-04-27 14:28:49 -04001162 false);
Jason Monk361915c2017-03-21 20:33:59 -04001163
1164 ImageView icon = (ImageView) v.findViewById(R.id.icon);
1165 TextView messageView = (TextView) v.findViewById(R.id.message);
Aaron Heuckroth3f2d8b52019-04-05 13:27:51 -04001166 messageView.setSelected(true); // necessary for marquee to work
Jason Monk361915c2017-03-21 20:33:59 -04001167
Jason Monk361915c2017-03-21 20:33:59 -04001168 if (mIcon != null) {
1169 icon.setImageDrawable(mIcon);
1170 icon.setScaleType(ScaleType.CENTER_CROP);
1171 } else if (mIconResId != 0) {
1172 icon.setImageDrawable(context.getDrawable(mIconResId));
1173 }
1174 if (mMessage != null) {
1175 messageView.setText(mMessage);
1176 } else {
1177 messageView.setText(mMessageResId);
1178 }
1179
1180 return v;
1181 }
1182 }
1183
1184 /**
1185 * A toggle action knows whether it is on or off, and displays an icon
1186 * and status message accordingly.
1187 */
1188 private static abstract class ToggleAction implements Action {
1189
1190 enum State {
1191 Off(false),
1192 TurningOn(true),
1193 TurningOff(true),
1194 On(false);
1195
1196 private final boolean inTransition;
1197
1198 State(boolean intermediate) {
1199 inTransition = intermediate;
1200 }
1201
1202 public boolean inTransition() {
1203 return inTransition;
1204 }
1205 }
1206
1207 protected State mState = State.Off;
1208
1209 // prefs
1210 protected int mEnabledIconResId;
1211 protected int mDisabledIconResid;
1212 protected int mMessageResId;
1213 protected int mEnabledStatusMessageResId;
1214 protected int mDisabledStatusMessageResId;
1215
1216 /**
Jason Monk16fbd9d2017-04-27 14:28:49 -04001217 * @param enabledIconResId The icon for when this action is on.
1218 * @param disabledIconResid The icon for when this action is off.
1219 * @param message The general information message, e.g 'Silent Mode'
1220 * @param enabledStatusMessageResId The on status message, e.g 'sound disabled'
Jason Monk361915c2017-03-21 20:33:59 -04001221 * @param disabledStatusMessageResId The off status message, e.g. 'sound enabled'
1222 */
1223 public ToggleAction(int enabledIconResId,
1224 int disabledIconResid,
1225 int message,
1226 int enabledStatusMessageResId,
1227 int disabledStatusMessageResId) {
1228 mEnabledIconResId = enabledIconResId;
1229 mDisabledIconResid = disabledIconResid;
1230 mMessageResId = message;
1231 mEnabledStatusMessageResId = enabledStatusMessageResId;
1232 mDisabledStatusMessageResId = disabledStatusMessageResId;
1233 }
1234
1235 /**
1236 * Override to make changes to resource IDs just before creating the
1237 * View.
1238 */
1239 void willCreate() {
1240
1241 }
1242
1243 @Override
1244 public CharSequence getLabelForAccessibility(Context context) {
1245 return context.getString(mMessageResId);
1246 }
1247
1248 public View create(Context context, View convertView, ViewGroup parent,
1249 LayoutInflater inflater) {
1250 willCreate();
1251
Koji Fukui5c010ee2019-12-24 16:12:07 +09001252 View v = inflater.inflate(com.android.systemui.R
1253 .layout.global_actions_grid_item, parent, false);
Jason Monk361915c2017-03-21 20:33:59 -04001254
1255 ImageView icon = (ImageView) v.findViewById(R.id.icon);
1256 TextView messageView = (TextView) v.findViewById(R.id.message);
Jason Monk361915c2017-03-21 20:33:59 -04001257 final boolean enabled = isEnabled();
Koji Fukui5c010ee2019-12-24 16:12:07 +09001258 boolean on = ((mState == State.On) || (mState == State.TurningOn));
Jason Monk361915c2017-03-21 20:33:59 -04001259
1260 if (messageView != null) {
Koji Fukui5c010ee2019-12-24 16:12:07 +09001261 messageView.setText(on ? mEnabledStatusMessageResId : mDisabledStatusMessageResId);
Jason Monk361915c2017-03-21 20:33:59 -04001262 messageView.setEnabled(enabled);
Aaron Heuckroth3f2d8b52019-04-05 13:27:51 -04001263 messageView.setSelected(true); // necessary for marquee to work
Jason Monk361915c2017-03-21 20:33:59 -04001264 }
1265
Jason Monk361915c2017-03-21 20:33:59 -04001266 if (icon != null) {
1267 icon.setImageDrawable(context.getDrawable(
1268 (on ? mEnabledIconResId : mDisabledIconResid)));
1269 icon.setEnabled(enabled);
1270 }
1271
Jason Monk361915c2017-03-21 20:33:59 -04001272 v.setEnabled(enabled);
1273
1274 return v;
1275 }
1276
1277 public final void onPress() {
1278 if (mState.inTransition()) {
1279 Log.w(TAG, "shouldn't be able to toggle when in transition");
1280 return;
1281 }
1282
1283 final boolean nowOn = !(mState == State.On);
1284 onToggle(nowOn);
1285 changeStateFromPress(nowOn);
1286 }
1287
1288 public boolean isEnabled() {
1289 return !mState.inTransition();
1290 }
1291
1292 /**
1293 * Implementations may override this if their state can be in on of the intermediate
1294 * states until some notification is received (e.g airplane mode is 'turning off' until
1295 * we know the wireless connections are back online
Jason Monk16fbd9d2017-04-27 14:28:49 -04001296 *
Jason Monk361915c2017-03-21 20:33:59 -04001297 * @param buttonOn Whether the button was turned on or off
1298 */
1299 protected void changeStateFromPress(boolean buttonOn) {
1300 mState = buttonOn ? State.On : State.Off;
1301 }
1302
1303 abstract void onToggle(boolean on);
1304
1305 public void updateState(State state) {
1306 mState = state;
1307 }
1308 }
1309
Aran Ink780d4502020-02-14 10:39:58 -05001310 private class AirplaneModeAction extends ToggleAction {
1311 AirplaneModeAction() {
1312 super(
1313 R.drawable.ic_lock_airplane_mode,
1314 R.drawable.ic_lock_airplane_mode_off,
1315 R.string.global_actions_toggle_airplane_mode,
1316 R.string.global_actions_airplane_mode_on_status,
1317 R.string.global_actions_airplane_mode_off_status);
1318 }
1319 void onToggle(boolean on) {
1320 if (mHasTelephony && TelephonyProperties.in_ecm_mode().orElse(false)) {
1321 mIsWaitingForEcmExit = true;
1322 // Launch ECM exit dialog
1323 Intent ecmDialogIntent =
1324 new Intent(TelephonyManager.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null);
1325 ecmDialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1326 mContext.startActivity(ecmDialogIntent);
1327 } else {
1328 changeAirplaneModeSystemSetting(on);
1329 }
1330 }
1331
1332 @Override
1333 protected void changeStateFromPress(boolean buttonOn) {
1334 if (!mHasTelephony) return;
1335
1336 // In ECM mode airplane state cannot be changed
1337 if (!TelephonyProperties.in_ecm_mode().orElse(false)) {
1338 mState = buttonOn ? State.TurningOn : State.TurningOff;
1339 mAirplaneState = mState;
1340 }
1341 }
1342
1343 public boolean showDuringKeyguard() {
1344 return true;
1345 }
1346
1347 public boolean showBeforeProvisioning() {
1348 return false;
1349 }
1350 }
1351
Jason Monk361915c2017-03-21 20:33:59 -04001352 private class SilentModeToggleAction extends ToggleAction {
1353 public SilentModeToggleAction() {
1354 super(R.drawable.ic_audio_vol_mute,
1355 R.drawable.ic_audio_vol,
1356 R.string.global_action_toggle_silent_mode,
1357 R.string.global_action_silent_mode_on_status,
1358 R.string.global_action_silent_mode_off_status);
1359 }
1360
1361 void onToggle(boolean on) {
1362 if (on) {
1363 mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
1364 } else {
1365 mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
1366 }
1367 }
1368
1369 public boolean showDuringKeyguard() {
1370 return true;
1371 }
1372
1373 public boolean showBeforeProvisioning() {
1374 return false;
1375 }
1376 }
1377
1378 private static class SilentModeTriStateAction implements Action, View.OnClickListener {
1379
Jason Monk16fbd9d2017-04-27 14:28:49 -04001380 private final int[] ITEM_IDS = {R.id.option1, R.id.option2, R.id.option3};
Jason Monk361915c2017-03-21 20:33:59 -04001381
1382 private final AudioManager mAudioManager;
1383 private final Handler mHandler;
Jason Monk361915c2017-03-21 20:33:59 -04001384
Lucas Dupin40ec6b782018-06-05 19:07:16 -07001385 SilentModeTriStateAction(AudioManager audioManager, Handler handler) {
Jason Monk361915c2017-03-21 20:33:59 -04001386 mAudioManager = audioManager;
1387 mHandler = handler;
Jason Monk361915c2017-03-21 20:33:59 -04001388 }
1389
1390 private int ringerModeToIndex(int ringerMode) {
1391 // They just happen to coincide
1392 return ringerMode;
1393 }
1394
1395 private int indexToRingerMode(int index) {
1396 // They just happen to coincide
1397 return index;
1398 }
1399
1400 @Override
1401 public CharSequence getLabelForAccessibility(Context context) {
1402 return null;
1403 }
1404
1405 public View create(Context context, View convertView, ViewGroup parent,
1406 LayoutInflater inflater) {
1407 View v = inflater.inflate(R.layout.global_actions_silent_mode, parent, false);
1408
1409 int selectedIndex = ringerModeToIndex(mAudioManager.getRingerMode());
1410 for (int i = 0; i < 3; i++) {
1411 View itemView = v.findViewById(ITEM_IDS[i]);
1412 itemView.setSelected(selectedIndex == i);
1413 // Set up click handler
1414 itemView.setTag(i);
1415 itemView.setOnClickListener(this);
1416 }
1417 return v;
1418 }
1419
1420 public void onPress() {
1421 }
1422
1423 public boolean showDuringKeyguard() {
1424 return true;
1425 }
1426
1427 public boolean showBeforeProvisioning() {
1428 return false;
1429 }
1430
1431 public boolean isEnabled() {
1432 return true;
1433 }
1434
1435 void willCreate() {
1436 }
1437
1438 public void onClick(View v) {
1439 if (!(v.getTag() instanceof Integer)) return;
1440
1441 int index = (Integer) v.getTag();
1442 mAudioManager.setRingerMode(indexToRingerMode(index));
1443 mHandler.sendEmptyMessageDelayed(MESSAGE_DISMISS, DIALOG_DISMISS_DELAY);
1444 }
1445 }
1446
1447 private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
1448 public void onReceive(Context context, Intent intent) {
1449 String action = intent.getAction();
1450 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)
1451 || Intent.ACTION_SCREEN_OFF.equals(action)) {
1452 String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY);
1453 if (!SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS.equals(reason)) {
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001454 mHandler.sendMessage(mHandler.obtainMessage(MESSAGE_DISMISS, reason));
Jason Monk361915c2017-03-21 20:33:59 -04001455 }
Jayachandran C142eae02019-12-13 19:29:20 -08001456 } else if (TelephonyManager.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED.equals(action)) {
Jason Monk361915c2017-03-21 20:33:59 -04001457 // Airplane mode can be changed after ECM exits if airplane toggle button
1458 // is pressed during ECM mode
Daniel Bright4bcbfce2020-01-09 21:58:16 -08001459 if (!(intent.getBooleanExtra(TelephonyManager.EXTRA_PHONE_IN_ECM_STATE, false))
1460 && mIsWaitingForEcmExit) {
Jason Monk361915c2017-03-21 20:33:59 -04001461 mIsWaitingForEcmExit = false;
1462 changeAirplaneModeSystemSetting(true);
1463 }
1464 }
1465 }
1466 };
1467
1468 PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
1469 @Override
1470 public void onServiceStateChanged(ServiceState serviceState) {
1471 if (!mHasTelephony) return;
1472 final boolean inAirplaneMode = serviceState.getState() == ServiceState.STATE_POWER_OFF;
1473 mAirplaneState = inAirplaneMode ? ToggleAction.State.On : ToggleAction.State.Off;
1474 mAirplaneModeOn.updateState(mAirplaneState);
1475 mAdapter.notifyDataSetChanged();
1476 }
1477 };
1478
1479 private BroadcastReceiver mRingerModeReceiver = new BroadcastReceiver() {
1480 @Override
1481 public void onReceive(Context context, Intent intent) {
1482 if (intent.getAction().equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
1483 mHandler.sendEmptyMessage(MESSAGE_REFRESH);
1484 }
1485 }
1486 };
1487
1488 private ContentObserver mAirplaneModeObserver = new ContentObserver(new Handler()) {
1489 @Override
1490 public void onChange(boolean selfChange) {
1491 onAirplaneModeChanged();
1492 }
1493 };
1494
1495 private static final int MESSAGE_DISMISS = 0;
1496 private static final int MESSAGE_REFRESH = 1;
1497 private static final int MESSAGE_SHOW = 2;
1498 private static final int DIALOG_DISMISS_DELAY = 300; // ms
1499
1500 private Handler mHandler = new Handler() {
1501 public void handleMessage(Message msg) {
1502 switch (msg.what) {
Jason Monk16fbd9d2017-04-27 14:28:49 -04001503 case MESSAGE_DISMISS:
1504 if (mDialog != null) {
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001505 if (SYSTEM_DIALOG_REASON_DREAM.equals(msg.obj)) {
1506 mDialog.dismissImmediately();
1507 } else {
1508 mDialog.dismiss();
1509 }
Jason Monk16fbd9d2017-04-27 14:28:49 -04001510 mDialog = null;
1511 }
1512 break;
1513 case MESSAGE_REFRESH:
1514 refreshSilentMode();
1515 mAdapter.notifyDataSetChanged();
1516 break;
1517 case MESSAGE_SHOW:
1518 handleShow();
1519 break;
Jason Monk361915c2017-03-21 20:33:59 -04001520 }
1521 }
1522 };
1523
1524 private void onAirplaneModeChanged() {
1525 // Let the service state callbacks handle the state.
1526 if (mHasTelephony) return;
1527
1528 boolean airplaneModeOn = Settings.Global.getInt(
Dave Mankoffc88a2d72020-01-10 15:59:31 -05001529 mContentResolver,
Jason Monk361915c2017-03-21 20:33:59 -04001530 Settings.Global.AIRPLANE_MODE_ON,
1531 0) == 1;
1532 mAirplaneState = airplaneModeOn ? ToggleAction.State.On : ToggleAction.State.Off;
1533 mAirplaneModeOn.updateState(mAirplaneState);
1534 }
1535
1536 /**
1537 * Change the airplane mode system setting
1538 */
1539 private void changeAirplaneModeSystemSetting(boolean on) {
1540 Settings.Global.putInt(
Dave Mankoffc88a2d72020-01-10 15:59:31 -05001541 mContentResolver,
Jason Monk361915c2017-03-21 20:33:59 -04001542 Settings.Global.AIRPLANE_MODE_ON,
1543 on ? 1 : 0);
1544 Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
1545 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
1546 intent.putExtra("state", on);
1547 mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
1548 if (!mHasTelephony) {
1549 mAirplaneState = on ? ToggleAction.State.On : ToggleAction.State.Off;
1550 }
1551 }
1552
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001553 private static final class ActionsDialog extends Dialog implements DialogInterface,
1554 ColorExtractor.OnColorsChangedListener {
Jason Monk361915c2017-03-21 20:33:59 -04001555
Jason Monk16fbd9d2017-04-27 14:28:49 -04001556 private final Context mContext;
1557 private final MyAdapter mAdapter;
Steve Elliott53f12ae2019-05-13 17:14:15 -04001558 private final IStatusBarService mStatusBarService;
1559 private final IBinder mToken = new Binder();
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001560 private MultiListLayout mGlobalActionsLayout;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001561 private Drawable mBackgroundDrawable;
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001562 private final SysuiColorExtractor mColorExtractor;
Steve Elliott9b87a442019-03-05 10:24:16 -05001563 private final GlobalActionsPanelPlugin.PanelViewController mPanelController;
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001564 private boolean mKeyguardShowing;
Beverly526d2d62018-08-15 12:55:33 -04001565 private boolean mShowing;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001566 private float mScrimAlpha;
Steve Elliott48f75db2019-05-03 15:03:38 -04001567 private ResetOrientationData mResetOrientationData;
Steve Elliottff2c0d92019-07-30 15:09:54 -04001568 private boolean mHadTopUi;
wilsonshihe8321942019-10-18 18:39:46 +08001569 private final NotificationShadeWindowController mNotificationShadeWindowController;
Lucas Dupin991415e2019-11-25 17:48:58 -08001570 private final BlurUtils mBlurUtils;
Matt Pietal22231792020-01-23 09:51:09 -05001571
1572 private ControlsUiController mControlsUiController;
1573 private ViewGroup mControlsView;
Aran Ink780d4502020-02-14 10:39:58 -05001574 private ViewGroup mContainerView;
Jason Monk16fbd9d2017-04-27 14:28:49 -04001575
Aaron Heuckrothf19d2722019-03-11 17:06:02 -04001576 ActionsDialog(Context context, MyAdapter adapter,
Lucas Dupin991415e2019-11-25 17:48:58 -08001577 GlobalActionsPanelPlugin.PanelViewController plugin, BlurUtils blurUtils,
1578 SysuiColorExtractor sysuiColorExtractor, IStatusBarService statusBarService,
1579 NotificationShadeWindowController notificationShadeWindowController,
Matt Pietal22231792020-01-23 09:51:09 -05001580 ControlsUiController controlsUiController) {
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001581 super(context, com.android.systemui.R.style.Theme_SystemUI_Dialog_GlobalActions);
Lucas Dupin448786c2017-07-24 17:44:25 -07001582 mContext = context;
Jason Monk16fbd9d2017-04-27 14:28:49 -04001583 mAdapter = adapter;
Lucas Dupin991415e2019-11-25 17:48:58 -08001584 mBlurUtils = blurUtils;
1585 mColorExtractor = sysuiColorExtractor;
1586 mStatusBarService = statusBarService;
1587 mNotificationShadeWindowController = notificationShadeWindowController;
Matt Pietal22231792020-01-23 09:51:09 -05001588 mControlsUiController = controlsUiController;
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001589
1590 // Window initialization
1591 Window window = getWindow();
1592 window.requestFeature(Window.FEATURE_NO_TITLE);
Adrian Roosedfab3b2018-03-08 18:39:20 +01001593 // Inflate the decor view, so the attributes below are not overwritten by the theme.
1594 window.getDecorView();
1595 window.getAttributes().systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1596 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1597 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1598 window.setLayout(MATCH_PARENT, MATCH_PARENT);
1599 window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
Alison Cichowlas4f19f4a2017-07-25 10:56:16 -04001600 window.addFlags(
1601 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001602 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
Adrian Roosedfab3b2018-03-08 18:39:20 +01001603 | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001604 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
1605 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
1606 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001607 window.setType(WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY);
Tiger Huang52724442020-01-20 21:38:42 +08001608 window.getAttributes().setFitInsetsTypes(0 /* types */);
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001609 setTitle(R.string.global_actions);
Steve Elliott9b87a442019-03-05 10:24:16 -05001610
1611 mPanelController = plugin;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001612 initializeLayout();
Steve Elliott9b87a442019-03-05 10:24:16 -05001613 }
1614
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001615 private boolean shouldUsePanel() {
Aran Ink3f594552019-05-13 14:29:35 -04001616 return mPanelController != null && mPanelController.getPanelContent() != null;
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001617 }
1618
1619 private void initializePanel() {
Steve Elliott48f75db2019-05-03 15:03:38 -04001620 int rotation = RotationUtils.getRotation(mContext);
1621 boolean rotationLocked = RotationPolicy.isRotationLocked(mContext);
1622 if (rotation != RotationUtils.ROTATION_NONE) {
1623 if (rotationLocked) {
1624 if (mResetOrientationData == null) {
1625 mResetOrientationData = new ResetOrientationData();
1626 mResetOrientationData.locked = true;
1627 mResetOrientationData.rotation = rotation;
1628 }
1629
1630 // Unlock rotation, so user can choose to rotate to portrait to see the panel.
Steve Elliotte05817f2019-05-17 14:39:53 -04001631 // This call is posted so that the rotation does not change until post-layout,
1632 // otherwise onConfigurationChanged() may not get invoked.
1633 mGlobalActionsLayout.post(() ->
1634 RotationPolicy.setRotationLockAtAngle(
1635 mContext, false, RotationUtils.ROTATION_NONE));
Steve Elliott48f75db2019-05-03 15:03:38 -04001636 }
1637 } else {
1638 if (!rotationLocked) {
1639 if (mResetOrientationData == null) {
1640 mResetOrientationData = new ResetOrientationData();
1641 mResetOrientationData.locked = false;
1642 }
1643
1644 // Lock to portrait, so the user doesn't accidentally hide the panel.
Steve Elliotte05817f2019-05-17 14:39:53 -04001645 // This call is posted so that the rotation does not change until post-layout,
1646 // otherwise onConfigurationChanged() may not get invoked.
1647 mGlobalActionsLayout.post(() ->
1648 RotationPolicy.setRotationLockAtAngle(
1649 mContext, true, RotationUtils.ROTATION_NONE));
Steve Elliott48f75db2019-05-03 15:03:38 -04001650 }
1651
Steve Elliott53f12ae2019-05-13 17:14:15 -04001652 // Disable rotation suggestions, if enabled
1653 setRotationSuggestionsEnabled(false);
1654
Steve Elliott300b48f2019-05-29 14:13:50 -04001655 FrameLayout panelContainer =
1656 findViewById(com.android.systemui.R.id.global_actions_panel_container);
Steve Elliott48f75db2019-05-03 15:03:38 -04001657 FrameLayout.LayoutParams panelParams =
1658 new FrameLayout.LayoutParams(
1659 FrameLayout.LayoutParams.MATCH_PARENT,
Steve Elliott300b48f2019-05-29 14:13:50 -04001660 FrameLayout.LayoutParams.MATCH_PARENT);
Steve Elliott48f75db2019-05-03 15:03:38 -04001661 panelContainer.addView(mPanelController.getPanelContent(), panelParams);
Steve Elliott48f75db2019-05-03 15:03:38 -04001662 }
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001663 }
1664
1665 private void initializeLayout() {
1666 setContentView(getGlobalActionsLayoutId(mContext));
Steve Elliott300b48f2019-05-29 14:13:50 -04001667 fixNavBarClipping();
Matt Pietal22231792020-01-23 09:51:09 -05001668 mControlsView = findViewById(com.android.systemui.R.id.global_actions_controls);
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001669 mGlobalActionsLayout = findViewById(com.android.systemui.R.id.global_actions_view);
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001670 mGlobalActionsLayout.setOutsideTouchListener(view -> dismiss());
Steve Elliott300b48f2019-05-29 14:13:50 -04001671 ((View) mGlobalActionsLayout.getParent()).setOnClickListener(view -> dismiss());
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001672 mGlobalActionsLayout.setListViewAccessibilityDelegate(new View.AccessibilityDelegate() {
Phil Weaver9054e092018-04-27 16:28:50 -07001673 @Override
1674 public boolean dispatchPopulateAccessibilityEvent(
1675 View host, AccessibilityEvent event) {
1676 // Populate the title here, just as Activity does
1677 event.getText().add(mContext.getString(R.string.global_actions));
1678 return true;
1679 }
1680 });
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001681 mGlobalActionsLayout.setRotationListener(this::onRotate);
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001682 mGlobalActionsLayout.setAdapter(mAdapter);
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001683
Steve Elliott86ef6282019-05-08 14:45:04 -04001684 if (shouldUsePanel()) {
Steve Elliottc59eb342019-04-23 16:59:06 -04001685 initializePanel();
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001686 }
Steve Elliott86ef6282019-05-08 14:45:04 -04001687 if (mBackgroundDrawable == null) {
1688 mBackgroundDrawable = new ScrimDrawable();
Lucas Dupin43d01242020-02-03 11:58:33 -08001689 mScrimAlpha = ScrimController.BUSY_SCRIM_ALPHA;
Steve Elliott86ef6282019-05-08 14:45:04 -04001690 }
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001691 getWindow().setBackgroundDrawable(mBackgroundDrawable);
Aran Ink780d4502020-02-14 10:39:58 -05001692
1693 if (mControlsView != null) {
1694 mContainerView = findViewById(com.android.systemui.R.id.global_actions_container);
1695 mContainerView.setOnTouchListener((v, e) -> {
1696 dismiss();
1697 return true;
1698 });
1699 }
Steve Elliott9b87a442019-03-05 10:24:16 -05001700 }
1701
Steve Elliott300b48f2019-05-29 14:13:50 -04001702 private void fixNavBarClipping() {
1703 ViewGroup content = findViewById(android.R.id.content);
1704 content.setClipChildren(false);
1705 content.setClipToPadding(false);
1706 ViewGroup contentParent = (ViewGroup) content.getParent();
1707 contentParent.setClipChildren(false);
1708 contentParent.setClipToPadding(false);
1709 }
1710
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001711 private int getGlobalActionsLayoutId(Context context) {
Matt Pietal22231792020-01-23 09:51:09 -05001712 if (mControlsUiController != null) {
Matt Pietalfd3b6cb2020-01-08 09:43:54 -05001713 return com.android.systemui.R.layout.global_actions_grid_v2;
1714 }
1715
Steve Elliottdc165632019-05-23 14:26:31 -04001716 int rotation = RotationUtils.getRotation(context);
1717 boolean useGridLayout = isForceGridEnabled(context)
1718 || (shouldUsePanel() && rotation == RotationUtils.ROTATION_NONE);
1719 if (rotation == RotationUtils.ROTATION_SEASCAPE) {
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001720 if (useGridLayout) {
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001721 return com.android.systemui.R.layout.global_actions_grid_seascape;
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001722 } else {
1723 return com.android.systemui.R.layout.global_actions_column_seascape;
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001724 }
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001725 } else {
1726 if (useGridLayout) {
1727 return com.android.systemui.R.layout.global_actions_grid;
1728 } else {
1729 return com.android.systemui.R.layout.global_actions_column;
1730 }
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001731 }
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001732 }
1733
Jason Monk361915c2017-03-21 20:33:59 -04001734 @Override
1735 protected void onStart() {
1736 super.setCanceledOnTouchOutside(true);
1737 super.onStart();
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001738 mGlobalActionsLayout.updateList();
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001739
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001740 if (mBackgroundDrawable instanceof ScrimDrawable) {
Steve Elliott9b87a442019-03-05 10:24:16 -05001741 mColorExtractor.addOnColorsChangedListener(this);
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001742 GradientColors colors = mColorExtractor.getNeutralColors();
Steve Elliott9b87a442019-03-05 10:24:16 -05001743 updateColors(colors, false /* animate */);
1744 }
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001745 }
1746
1747 /**
1748 * Updates background and system bars according to current GradientColors.
1749 * @param colors Colors and hints to use.
1750 * @param animate Interpolates gradient if true, just sets otherwise.
1751 */
1752 private void updateColors(GradientColors colors, boolean animate) {
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001753 if (!(mBackgroundDrawable instanceof ScrimDrawable)) {
Steve Elliott9b87a442019-03-05 10:24:16 -05001754 return;
1755 }
Lucas Dupinba2b48a2020-02-06 09:28:06 -08001756 ((ScrimDrawable) mBackgroundDrawable).setColor(colors.supportsDarkText() ? Color.WHITE
1757 : Color.BLACK, animate);
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001758 View decorView = getWindow().getDecorView();
1759 if (colors.supportsDarkText()) {
1760 decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR |
Steve Elliott9b87a442019-03-05 10:24:16 -05001761 View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001762 } else {
1763 decorView.setSystemUiVisibility(0);
1764 }
Jason Monk361915c2017-03-21 20:33:59 -04001765 }
1766
1767 @Override
Jason Monk16fbd9d2017-04-27 14:28:49 -04001768 protected void onStop() {
1769 super.onStop();
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001770 mColorExtractor.removeOnColorsChangedListener(this);
Jason Monk16fbd9d2017-04-27 14:28:49 -04001771 }
1772
1773 @Override
1774 public void show() {
1775 super.show();
Beverly526d2d62018-08-15 12:55:33 -04001776 mShowing = true;
wilsonshihe8321942019-10-18 18:39:46 +08001777 mHadTopUi = mNotificationShadeWindowController.getForceHasTopUi();
1778 mNotificationShadeWindowController.setForceHasTopUi(true);
Steve Elliott9b87a442019-03-05 10:24:16 -05001779 mBackgroundDrawable.setAlpha(0);
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001780 mGlobalActionsLayout.setTranslationX(mGlobalActionsLayout.getAnimationOffsetX());
1781 mGlobalActionsLayout.setTranslationY(mGlobalActionsLayout.getAnimationOffsetY());
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001782 mGlobalActionsLayout.setAlpha(0);
1783 mGlobalActionsLayout.animate()
Jason Monk16fbd9d2017-04-27 14:28:49 -04001784 .alpha(1)
1785 .translationX(0)
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001786 .translationY(0)
Jason Monk16fbd9d2017-04-27 14:28:49 -04001787 .setDuration(300)
Lucas Dupinde9db422017-07-19 17:15:41 -07001788 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001789 .setUpdateListener(animation -> {
Lucas Dupin991415e2019-11-25 17:48:58 -08001790 float animatedValue = animation.getAnimatedFraction();
1791 int alpha = (int) (animatedValue * mScrimAlpha * 255);
Steve Elliott9b87a442019-03-05 10:24:16 -05001792 mBackgroundDrawable.setAlpha(alpha);
Lucas Dupin991415e2019-11-25 17:48:58 -08001793 mBlurUtils.applyBlur(mGlobalActionsLayout.getViewRootImpl(),
1794 mBlurUtils.radiusForRatio(animatedValue));
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001795 })
Jason Monk16fbd9d2017-04-27 14:28:49 -04001796 .start();
Matt Pietal22231792020-01-23 09:51:09 -05001797 if (mControlsUiController != null) {
1798 mControlsUiController.show(mControlsView);
1799 }
Jason Monk16fbd9d2017-04-27 14:28:49 -04001800 }
1801
1802 @Override
1803 public void dismiss() {
Beverly526d2d62018-08-15 12:55:33 -04001804 if (!mShowing) {
1805 return;
1806 }
1807 mShowing = false;
Matt Pietal22231792020-01-23 09:51:09 -05001808 if (mControlsUiController != null) mControlsUiController.hide();
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001809 mGlobalActionsLayout.setTranslationX(0);
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001810 mGlobalActionsLayout.setTranslationY(0);
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001811 mGlobalActionsLayout.setAlpha(1);
1812 mGlobalActionsLayout.animate()
Jason Monk16fbd9d2017-04-27 14:28:49 -04001813 .alpha(0)
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001814 .translationX(mGlobalActionsLayout.getAnimationOffsetX())
1815 .translationY(mGlobalActionsLayout.getAnimationOffsetY())
Jason Monk16fbd9d2017-04-27 14:28:49 -04001816 .setDuration(300)
Steve Elliottff2c0d92019-07-30 15:09:54 -04001817 .withEndAction(this::completeDismiss)
Jason Monk16fbd9d2017-04-27 14:28:49 -04001818 .setInterpolator(new LogAccelerateInterpolator())
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001819 .setUpdateListener(animation -> {
Lucas Dupin991415e2019-11-25 17:48:58 -08001820 float animatedValue = 1f - animation.getAnimatedFraction();
1821 int alpha = (int) (animatedValue * mScrimAlpha * 255);
Steve Elliott9b87a442019-03-05 10:24:16 -05001822 mBackgroundDrawable.setAlpha(alpha);
Lucas Dupin991415e2019-11-25 17:48:58 -08001823 mBlurUtils.applyBlur(mGlobalActionsLayout.getViewRootImpl(),
1824 mBlurUtils.radiusForRatio(animatedValue));
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001825 })
Jason Monk16fbd9d2017-04-27 14:28:49 -04001826 .start();
Steve Elliott48f75db2019-05-03 15:03:38 -04001827 dismissPanel();
1828 resetOrientation();
Jason Monk16fbd9d2017-04-27 14:28:49 -04001829 }
1830
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001831 void dismissImmediately() {
Beverly526d2d62018-08-15 12:55:33 -04001832 mShowing = false;
Matt Pietal019feaa2020-01-31 14:51:37 -05001833 if (mControlsUiController != null) mControlsUiController.hide();
Steve Elliott48f75db2019-05-03 15:03:38 -04001834 dismissPanel();
1835 resetOrientation();
Steve Elliottff2c0d92019-07-30 15:09:54 -04001836 completeDismiss();
1837 }
1838
1839 private void completeDismiss() {
wilsonshihe8321942019-10-18 18:39:46 +08001840 mNotificationShadeWindowController.setForceHasTopUi(mHadTopUi);
Steve Elliottff2c0d92019-07-30 15:09:54 -04001841 super.dismiss();
Steve Elliott48f75db2019-05-03 15:03:38 -04001842 }
1843
1844 private void dismissPanel() {
Steve Elliott2d206d32019-03-14 16:30:33 -04001845 if (mPanelController != null) {
1846 mPanelController.onDismissed();
1847 }
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001848 }
1849
Steve Elliott53f12ae2019-05-13 17:14:15 -04001850 private void setRotationSuggestionsEnabled(boolean enabled) {
1851 try {
1852 final int userId = Binder.getCallingUserHandle().getIdentifier();
1853 final int what = enabled
1854 ? StatusBarManager.DISABLE2_NONE
1855 : StatusBarManager.DISABLE2_ROTATE_SUGGESTIONS;
1856 mStatusBarService.disable2ForUser(what, mToken, mContext.getPackageName(), userId);
1857 } catch (RemoteException ex) {
1858 throw ex.rethrowFromSystemServer();
1859 }
1860 }
1861
Steve Elliott48f75db2019-05-03 15:03:38 -04001862 private void resetOrientation() {
1863 if (mResetOrientationData != null) {
1864 RotationPolicy.setRotationLockAtAngle(mContext, mResetOrientationData.locked,
1865 mResetOrientationData.rotation);
1866 }
Steve Elliott53f12ae2019-05-13 17:14:15 -04001867 setRotationSuggestionsEnabled(true);
Steve Elliott48f75db2019-05-03 15:03:38 -04001868 }
1869
Jason Monk361915c2017-03-21 20:33:59 -04001870 @Override
Lucas Dupin7aaa3532017-05-28 08:51:07 -07001871 public void onColorsChanged(ColorExtractor extractor, int which) {
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001872 if (mKeyguardShowing) {
1873 if ((WallpaperManager.FLAG_LOCK & which) != 0) {
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001874 updateColors(extractor.getColors(WallpaperManager.FLAG_LOCK),
1875 true /* animate */);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001876 }
1877 } else {
1878 if ((WallpaperManager.FLAG_SYSTEM & which) != 0) {
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001879 updateColors(extractor.getColors(WallpaperManager.FLAG_SYSTEM),
1880 true /* animate */);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001881 }
1882 }
1883 }
1884
1885 public void setKeyguardShowing(boolean keyguardShowing) {
1886 mKeyguardShowing = keyguardShowing;
1887 }
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001888
Aaron Heuckroth4ef3a542019-04-01 14:17:23 -04001889 public void refreshDialog() {
1890 initializeLayout();
1891 mGlobalActionsLayout.updateList();
1892 }
1893
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001894 public void onRotate(int from, int to) {
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001895 if (mShowing) {
Aaron Heuckroth4ef3a542019-04-01 14:17:23 -04001896 refreshDialog();
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001897 }
1898 }
Steve Elliott48f75db2019-05-03 15:03:38 -04001899
1900 private static class ResetOrientationData {
1901 public boolean locked;
1902 public int rotation;
1903 }
Jason Monk361915c2017-03-21 20:33:59 -04001904 }
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001905
1906 /**
Aran Ink93dd25c2019-05-09 14:42:14 -04001907 * Determines whether or not debug mode has been activated for the Global Actions Panel.
1908 */
1909 private static boolean isPanelDebugModeEnabled(Context context) {
1910 return Settings.Secure.getInt(context.getContentResolver(),
1911 Settings.Secure.GLOBAL_ACTIONS_PANEL_DEBUG_ENABLED, 0) == 1;
1912 }
1913
1914 /**
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001915 * Determines whether or not the Global Actions menu should be forced to
1916 * use the newer grid-style layout.
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001917 */
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001918 private static boolean isForceGridEnabled(Context context) {
Aran Ink93dd25c2019-05-09 14:42:14 -04001919 return isPanelDebugModeEnabled(context);
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001920 }
Aaron Heuckrothf19d2722019-03-11 17:06:02 -04001921
Matt Pietale0661b62020-01-29 14:35:31 -05001922 private boolean shouldShowControls() {
Fabian Kozynskif6063ae2020-02-24 16:14:35 -05001923 return mKeyguardStateController.isUnlocked()
Fabian Kozynski0424ab12020-02-21 12:09:17 -05001924 && mControlsUiController.getAvailable()
1925 && mAnyControlsProviders;
Matt Pietalfd3b6cb2020-01-08 09:43:54 -05001926 }
Jason Monk361915c2017-03-21 20:33:59 -04001927}