blob: 56cfe8010fef42094f0a9794aa909d5bcfab9806 [file] [log] [blame]
Jason Monk361915c2017-03-21 20:33:59 -04001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 * except in compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the
10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11 * KIND, either express or implied. See the License for the specific language governing
12 * permissions and limitations under the License.
13 */
14
15package com.android.systemui.globalactions;
16
Adrian Roosedfab3b2018-03-08 18:39:20 +010017import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
Adrian Roos2f05bb32018-02-19 16:42:27 +010018import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
19
Chad Brubakerf4075fe2018-01-03 13:23:22 -080020import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_USER_REQUEST;
21import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_NOT_REQUIRED;
Chad Brubaker4f28f0d2017-09-07 14:28:13 -070022import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN;
23
Dave Mankoffc88a2d72020-01-10 15:59:31 -050024import android.annotation.Nullable;
Jason Monk361915c2017-03-21 20:33:59 -040025import android.app.ActivityManager;
26import android.app.Dialog;
Dave Mankoffc88a2d72020-01-10 15:59:31 -050027import android.app.IActivityManager;
Chad Brubakerf4075fe2018-01-03 13:23:22 -080028import android.app.KeyguardManager;
Steve Elliott4c868852019-03-14 16:25:41 -040029import android.app.PendingIntent;
Steve Elliott53f12ae2019-05-13 17:14:15 -040030import android.app.StatusBarManager;
Lucas Dupinc1cc7592017-05-22 15:56:16 -070031import android.app.WallpaperManager;
Alex Chau04458852017-11-27 18:21:23 +000032import android.app.admin.DevicePolicyManager;
Pavel Grafov059021b2018-05-02 13:44:46 +010033import android.app.trust.TrustManager;
Jason Monk361915c2017-03-21 20:33:59 -040034import android.content.BroadcastReceiver;
Dave Mankoffc88a2d72020-01-10 15:59:31 -050035import android.content.ContentResolver;
Jason Monk361915c2017-03-21 20:33:59 -040036import android.content.Context;
37import android.content.DialogInterface;
38import android.content.Intent;
39import android.content.IntentFilter;
40import android.content.pm.UserInfo;
Dave Mankoffc88a2d72020-01-10 15:59:31 -050041import android.content.res.Resources;
Jason Monk361915c2017-03-21 20:33:59 -040042import android.database.ContentObserver;
Matt Pietale0661b62020-01-29 14:35:31 -050043import android.graphics.Color;
Jason Monk361915c2017-03-21 20:33:59 -040044import android.graphics.drawable.Drawable;
45import android.media.AudioManager;
46import android.net.ConnectivityManager;
Steve Elliott53f12ae2019-05-13 17:14:15 -040047import android.os.Binder;
Jason Monk361915c2017-03-21 20:33:59 -040048import android.os.Handler;
Steve Elliott53f12ae2019-05-13 17:14:15 -040049import android.os.IBinder;
Jason Monk361915c2017-03-21 20:33:59 -040050import android.os.Message;
51import android.os.RemoteException;
Jason Monk361915c2017-03-21 20:33:59 -040052import android.os.SystemProperties;
53import android.os.UserHandle;
54import android.os.UserManager;
55import android.os.Vibrator;
56import android.provider.Settings;
Jason Monk361915c2017-03-21 20:33:59 -040057import android.service.dreams.IDreamManager;
Inseob Kim5e82f732019-11-08 15:08:38 +090058import android.sysprop.TelephonyProperties;
Fan Zhangf9914762019-11-01 15:58:38 -070059import android.telecom.TelecomManager;
Jason Monk361915c2017-03-21 20:33:59 -040060import android.telephony.PhoneStateListener;
61import android.telephony.ServiceState;
62import android.telephony.TelephonyManager;
Jason Monk361915c2017-03-21 20:33:59 -040063import android.util.ArraySet;
yuanjiahsu88363e92018-09-06 19:23:52 +080064import android.util.FeatureFlagUtils;
Jason Monk361915c2017-03-21 20:33:59 -040065import android.util.Log;
Lucas Dupin448786c2017-07-24 17:44:25 -070066import android.view.ContextThemeWrapper;
Dave Mankoff8df818e2020-02-12 14:22:26 -050067import android.view.IWindowManager;
Jason Monk361915c2017-03-21 20:33:59 -040068import android.view.LayoutInflater;
69import android.view.View;
70import android.view.ViewGroup;
Lucas Dupinc1cc7592017-05-22 15:56:16 -070071import android.view.Window;
Jason Monk361915c2017-03-21 20:33:59 -040072import android.view.WindowManager;
Jason Monk361915c2017-03-21 20:33:59 -040073import android.view.accessibility.AccessibilityEvent;
Steve Elliott9b87a442019-03-05 10:24:16 -050074import android.widget.FrameLayout;
Jason Monk361915c2017-03-21 20:33:59 -040075import android.widget.ImageView;
76import android.widget.ImageView.ScaleType;
Jason Monk361915c2017-03-21 20:33:59 -040077import android.widget.TextView;
78
Charles He9851a8d2017-10-10 17:31:30 +010079import com.android.internal.R;
80import com.android.internal.colorextraction.ColorExtractor;
81import com.android.internal.colorextraction.ColorExtractor.GradientColors;
Lucas Dupin2bd3af62019-03-25 17:44:28 -070082import com.android.internal.colorextraction.drawable.ScrimDrawable;
Charles He9851a8d2017-10-10 17:31:30 +010083import com.android.internal.logging.MetricsLogger;
84import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Steve Elliott53f12ae2019-05-13 17:14:15 -040085import com.android.internal.statusbar.IStatusBarService;
Charles He9851a8d2017-10-10 17:31:30 +010086import com.android.internal.util.EmergencyAffordanceManager;
Beth Thibodeau5898ac42018-10-26 13:00:09 -040087import com.android.internal.util.ScreenRecordHelper;
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -050088import com.android.internal.util.ScreenshotHelper;
Steve Elliott48f75db2019-05-03 15:03:38 -040089import com.android.internal.view.RotationPolicy;
Charles He9851a8d2017-10-10 17:31:30 +010090import com.android.internal.widget.LockPatternUtils;
Charles He9851a8d2017-10-10 17:31:30 +010091import com.android.systemui.Interpolators;
Aaron Heuckrothf708d472019-01-10 16:54:51 -050092import com.android.systemui.MultiListLayout;
Aaron Heuckroth57d60d22019-03-05 14:00:12 -050093import com.android.systemui.MultiListLayout.MultiListAdapter;
Fabian Kozynskiff5e91f2019-09-24 15:38:08 -040094import com.android.systemui.broadcast.BroadcastDispatcher;
Charles He9851a8d2017-10-10 17:31:30 +010095import com.android.systemui.colorextraction.SysuiColorExtractor;
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;
155 private final KeyguardManager mKeyguardManager;
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;
Steve Elliott9b87a442019-03-05 10:24:16 -0500193
Jason Monk361915c2017-03-21 20:33:59 -0400194 /**
195 * @param context everything needs a context :(
196 */
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500197 @Inject
198 public GlobalActionsDialog(Context context, GlobalActionsManager windowManagerFuncs,
199 AudioManager audioManager, IDreamManager iDreamManager,
200 DevicePolicyManager devicePolicyManager, LockPatternUtils lockPatternUtils,
201 KeyguardManager keyguardManager, BroadcastDispatcher broadcastDispatcher,
202 ConnectivityManager connectivityManager, TelephonyManager telephonyManager,
203 ContentResolver contentResolver, @Nullable Vibrator vibrator, @Main Resources resources,
204 ConfigurationController configurationController, ActivityStarter activityStarter,
205 KeyguardStateController keyguardStateController, UserManager userManager,
206 TrustManager trustManager, IActivityManager iActivityManager,
Lucas Dupin991415e2019-11-25 17:48:58 -0800207 TelecomManager telecomManager, MetricsLogger metricsLogger,
208 BlurUtils blurUtils, SysuiColorExtractor colorExtractor,
209 IStatusBarService statusBarService,
Matt Pietal22231792020-01-23 09:51:09 -0500210 NotificationShadeWindowController notificationShadeWindowController,
Dave Mankoff8df818e2020-02-12 14:22:26 -0500211 ControlsUiController controlsUiController, IWindowManager iWindowManager,
212 @Background Executor backgroundExecutor) {
Lucas Dupin448786c2017-07-24 17:44:25 -0700213 mContext = new ContextThemeWrapper(context, com.android.systemui.R.style.qs_theme);
Jason Monk361915c2017-03-21 20:33:59 -0400214 mWindowManagerFuncs = windowManagerFuncs;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500215 mAudioManager = audioManager;
216 mDreamManager = iDreamManager;
217 mDevicePolicyManager = devicePolicyManager;
218 mLockPatternUtils = lockPatternUtils;
219 mKeyguardManager = keyguardManager;
220 mBroadcastDispatcher = broadcastDispatcher;
221 mContentResolver = contentResolver;
222 mResources = resources;
Dave Mankoff8df818e2020-02-12 14:22:26 -0500223 mConfigurationController = configurationController;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500224 mUserManager = userManager;
225 mTrustManager = trustManager;
226 mIActivityManager = iActivityManager;
227 mTelecomManager = telecomManager;
228 mMetricsLogger = metricsLogger;
Lucas Dupin991415e2019-11-25 17:48:58 -0800229 mBlurUtils = blurUtils;
230 mSysuiColorExtractor = colorExtractor;
231 mStatusBarService = statusBarService;
232 mNotificationShadeWindowController = notificationShadeWindowController;
Matt Pietal22231792020-01-23 09:51:09 -0500233 mControlsUiController = controlsUiController;
Dave Mankoff8df818e2020-02-12 14:22:26 -0500234 mIWindowManager = iWindowManager;
235 mBackgroundExecutor = backgroundExecutor;
Jason Monk361915c2017-03-21 20:33:59 -0400236
237 // receive broadcasts
238 IntentFilter filter = new IntentFilter();
239 filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
240 filter.addAction(Intent.ACTION_SCREEN_OFF);
Jayachandran C142eae02019-12-13 19:29:20 -0800241 filter.addAction(TelephonyManager.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000242 mBroadcastDispatcher.registerReceiver(mBroadcastReceiver, filter);
Jason Monk361915c2017-03-21 20:33:59 -0400243
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500244 mHasTelephony = connectivityManager.isNetworkSupported(ConnectivityManager.TYPE_MOBILE);
Jason Monk361915c2017-03-21 20:33:59 -0400245
246 // get notified of phone state changes
Jason Monk361915c2017-03-21 20:33:59 -0400247 telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE);
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500248 contentResolver.registerContentObserver(
Jason Monk361915c2017-03-21 20:33:59 -0400249 Settings.Global.getUriFor(Settings.Global.AIRPLANE_MODE_ON), true,
250 mAirplaneModeObserver);
Jason Monk361915c2017-03-21 20:33:59 -0400251 mHasVibrator = vibrator != null && vibrator.hasVibrator();
252
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500253 mShowSilentToggle = SHOW_SILENT_TOGGLE && !resources.getBoolean(
Jason Monk361915c2017-03-21 20:33:59 -0400254 R.bool.config_useFixedVolume);
255
256 mEmergencyAffordanceManager = new EmergencyAffordanceManager(context);
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500257 mScreenshotHelper = new ScreenshotHelper(context);
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400258 mScreenRecordHelper = new ScreenRecordHelper(context);
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700259
Dave Mankoff8df818e2020-02-12 14:22:26 -0500260 mConfigurationController.addCallback(this);
Steve Elliott9b87a442019-03-05 10:24:16 -0500261
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500262 mActivityStarter = activityStarter;
Lucas Dupinc8f16e82019-09-17 18:24:50 -0400263 keyguardStateController.addCallback(new KeyguardStateController.Callback() {
264 @Override
265 public void onUnlockedChanged() {
266 if (mDialog != null && mDialog.mPanelController != null) {
267 boolean locked = !keyguardStateController.canDismissLockScreen();
268 mDialog.mPanelController.onDeviceLockStateChanged(locked);
269 }
270 }
271 });
Jason Monk361915c2017-03-21 20:33:59 -0400272 }
273
274 /**
275 * Show the global actions dialog (creating if necessary)
Jason Monk16fbd9d2017-04-27 14:28:49 -0400276 *
Jason Monk361915c2017-03-21 20:33:59 -0400277 * @param keyguardShowing True if keyguard is showing
278 */
Steve Elliotta3f5207922019-03-18 13:37:22 -0400279 public void showDialog(boolean keyguardShowing, boolean isDeviceProvisioned,
280 GlobalActionsPanelPlugin panelPlugin) {
Jason Monk361915c2017-03-21 20:33:59 -0400281 mKeyguardShowing = keyguardShowing;
282 mDeviceProvisioned = isDeviceProvisioned;
Steve Elliotta3f5207922019-03-18 13:37:22 -0400283 mPanelPlugin = panelPlugin;
Jason Monk361915c2017-03-21 20:33:59 -0400284 if (mDialog != null) {
285 mDialog.dismiss();
286 mDialog = null;
287 // Show delayed, so that the dismiss of the previous dialog completes
288 mHandler.sendEmptyMessage(MESSAGE_SHOW);
289 } else {
290 handleShow();
291 }
292 }
293
Charles He9851a8d2017-10-10 17:31:30 +0100294 /**
295 * Dismiss the global actions dialog, if it's currently shown
296 */
297 public void dismissDialog() {
298 mHandler.removeMessages(MESSAGE_DISMISS);
299 mHandler.sendEmptyMessage(MESSAGE_DISMISS);
300 }
301
Jason Monk361915c2017-03-21 20:33:59 -0400302 private void awakenIfNecessary() {
303 if (mDreamManager != null) {
304 try {
305 if (mDreamManager.isDreaming()) {
306 mDreamManager.awaken();
307 }
308 } catch (RemoteException e) {
309 // we tried
310 }
311 }
312 }
313
314 private void handleShow() {
315 awakenIfNecessary();
316 mDialog = createDialog();
317 prepareDialog();
318
319 // If we only have 1 item and it's a simple press action, just do this action.
320 if (mAdapter.getCount() == 1
321 && mAdapter.getItem(0) instanceof SinglePressAction
322 && !(mAdapter.getItem(0) instanceof LongPressAction)) {
323 ((SinglePressAction) mAdapter.getItem(0)).onPress();
324 } else {
325 WindowManager.LayoutParams attrs = mDialog.getWindow().getAttributes();
326 attrs.setTitle("ActionsDialog");
Adrian Roos2f05bb32018-02-19 16:42:27 +0100327 attrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
Jason Monk361915c2017-03-21 20:33:59 -0400328 mDialog.getWindow().setAttributes(attrs);
329 mDialog.show();
330 mWindowManagerFuncs.onGlobalActionsShown();
Jason Monk361915c2017-03-21 20:33:59 -0400331 }
332 }
333
334 /**
335 * Create the global actions dialog.
Jason Monk16fbd9d2017-04-27 14:28:49 -0400336 *
Jason Monk361915c2017-03-21 20:33:59 -0400337 * @return A new dialog.
338 */
339 private ActionsDialog createDialog() {
340 // Simple toggle style if there's no vibrator, otherwise use a tri-state
341 if (!mHasVibrator) {
342 mSilentModeAction = new SilentModeToggleAction();
343 } else {
Lucas Dupin40ec6b782018-06-05 19:07:16 -0700344 mSilentModeAction = new SilentModeTriStateAction(mAudioManager, mHandler);
Jason Monk361915c2017-03-21 20:33:59 -0400345 }
346 mAirplaneModeOn = new ToggleAction(
347 R.drawable.ic_lock_airplane_mode,
348 R.drawable.ic_lock_airplane_mode_off,
349 R.string.global_actions_toggle_airplane_mode,
350 R.string.global_actions_airplane_mode_on_status,
351 R.string.global_actions_airplane_mode_off_status) {
352
353 void onToggle(boolean on) {
Inseob Kim5e82f732019-11-08 15:08:38 +0900354 if (mHasTelephony && TelephonyProperties.in_ecm_mode().orElse(false)) {
Jason Monk361915c2017-03-21 20:33:59 -0400355 mIsWaitingForEcmExit = true;
356 // Launch ECM exit dialog
357 Intent ecmDialogIntent =
Jayachandran C142eae02019-12-13 19:29:20 -0800358 new Intent(TelephonyManager.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null);
Jason Monk361915c2017-03-21 20:33:59 -0400359 ecmDialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
360 mContext.startActivity(ecmDialogIntent);
361 } else {
362 changeAirplaneModeSystemSetting(on);
363 }
364 }
365
366 @Override
367 protected void changeStateFromPress(boolean buttonOn) {
368 if (!mHasTelephony) return;
369
370 // In ECM mode airplane state cannot be changed
Inseob Kim5e82f732019-11-08 15:08:38 +0900371 if (!TelephonyProperties.in_ecm_mode().orElse(false)) {
Jason Monk361915c2017-03-21 20:33:59 -0400372 mState = buttonOn ? State.TurningOn : State.TurningOff;
373 mAirplaneState = mState;
374 }
375 }
376
377 public boolean showDuringKeyguard() {
378 return true;
379 }
380
381 public boolean showBeforeProvisioning() {
382 return false;
383 }
384 };
385 onAirplaneModeChanged();
386
387 mItems = new ArrayList<Action>();
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500388 String[] defaultActions = mResources.getStringArray(R.array.config_globalActionsList);
Jason Monk361915c2017-03-21 20:33:59 -0400389
390 ArraySet<String> addedKeys = new ArraySet<String>();
391 for (int i = 0; i < defaultActions.length; i++) {
392 String actionKey = defaultActions[i];
393 if (addedKeys.contains(actionKey)) {
394 // If we already have added this, don't add it again.
395 continue;
396 }
397 if (GLOBAL_ACTION_KEY_POWER.equals(actionKey)) {
398 mItems.add(new PowerAction());
399 } else if (GLOBAL_ACTION_KEY_AIRPLANE.equals(actionKey)) {
400 mItems.add(mAirplaneModeOn);
401 } else if (GLOBAL_ACTION_KEY_BUGREPORT.equals(actionKey)) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500402 if (Settings.Global.getInt(mContentResolver,
Jason Monk361915c2017-03-21 20:33:59 -0400403 Settings.Global.BUGREPORT_IN_POWER_MENU, 0) != 0 && isCurrentUserOwner()) {
404 mItems.add(new BugReportAction());
405 }
406 } else if (GLOBAL_ACTION_KEY_SILENT.equals(actionKey)) {
407 if (mShowSilentToggle) {
408 mItems.add(mSilentModeAction);
409 }
410 } else if (GLOBAL_ACTION_KEY_USERS.equals(actionKey)) {
411 if (SystemProperties.getBoolean("fw.power_user_switcher", false)) {
412 addUsersToMenu(mItems);
413 }
414 } else if (GLOBAL_ACTION_KEY_SETTINGS.equals(actionKey)) {
415 mItems.add(getSettingsAction());
416 } else if (GLOBAL_ACTION_KEY_LOCKDOWN.equals(actionKey)) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500417 if (Settings.Secure.getIntForUser(mContentResolver,
Chad Brubaker02cd6cf2018-05-01 14:59:33 -0700418 Settings.Secure.LOCKDOWN_IN_POWER_MENU, 0, getCurrentUser().id) != 0
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800419 && shouldDisplayLockdown()) {
Chad Brubaker4f28f0d2017-09-07 14:28:13 -0700420 mItems.add(getLockdownAction());
421 }
Jason Monk361915c2017-03-21 20:33:59 -0400422 } else if (GLOBAL_ACTION_KEY_VOICEASSIST.equals(actionKey)) {
423 mItems.add(getVoiceAssistAction());
424 } else if (GLOBAL_ACTION_KEY_ASSIST.equals(actionKey)) {
425 mItems.add(getAssistAction());
426 } else if (GLOBAL_ACTION_KEY_RESTART.equals(actionKey)) {
427 mItems.add(new RestartAction());
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500428 } else if (GLOBAL_ACTION_KEY_SCREENSHOT.equals(actionKey)) {
429 mItems.add(new ScreenshotAction());
Alex Chau04458852017-11-27 18:21:23 +0000430 } else if (GLOBAL_ACTION_KEY_LOGOUT.equals(actionKey)) {
Alex Chaud7958272017-12-08 11:30:52 +0000431 if (mDevicePolicyManager.isLogoutEnabled()
Alex Chau04458852017-11-27 18:21:23 +0000432 && getCurrentUser().id != UserHandle.USER_SYSTEM) {
433 mItems.add(new LogoutAction());
Alex Chau04458852017-11-27 18:21:23 +0000434 }
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800435 } else if (GLOBAL_ACTION_KEY_EMERGENCY.equals(actionKey)) {
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400436 if (!mEmergencyAffordanceManager.needsEmergencyAffordance()) {
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800437 mItems.add(new EmergencyDialerAction());
438 }
Jason Monk361915c2017-03-21 20:33:59 -0400439 } else {
440 Log.e(TAG, "Invalid global action key " + actionKey);
441 }
442 // Add here so we don't add more than one.
443 addedKeys.add(actionKey);
444 }
445
446 if (mEmergencyAffordanceManager.needsEmergencyAffordance()) {
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400447 mItems.add(new EmergencyAffordanceAction());
Jason Monk361915c2017-03-21 20:33:59 -0400448 }
449
450 mAdapter = new MyAdapter();
451
Steve Elliott9b87a442019-03-05 10:24:16 -0500452 GlobalActionsPanelPlugin.PanelViewController panelViewController =
Steve Elliotta3f5207922019-03-18 13:37:22 -0400453 mPanelPlugin != null
454 ? mPanelPlugin.onPanelShown(
Steve Elliott4c868852019-03-14 16:25:41 -0400455 new GlobalActionsPanelPlugin.Callbacks() {
456 @Override
457 public void dismissGlobalActionsMenu() {
Steve Elliottc3147e22019-11-20 19:34:57 -0500458 dismissDialog();
Steve Elliott4c868852019-03-14 16:25:41 -0400459 }
460
461 @Override
462 public void startPendingIntentDismissingKeyguard(
463 PendingIntent intent) {
464 mActivityStarter
465 .startPendingIntentDismissingKeyguard(intent);
466 }
Steve Elliotte2a2e9b2019-04-30 21:31:03 -0400467 },
468 mKeyguardManager.isDeviceLocked())
Steve Elliott9b87a442019-03-05 10:24:16 -0500469 : null;
Steve Elliott02bbaaa2019-05-01 16:55:33 -0400470
Lucas Dupin991415e2019-11-25 17:48:58 -0800471 ActionsDialog dialog = new ActionsDialog(mContext, mAdapter, panelViewController,
472 mBlurUtils, mSysuiColorExtractor, mStatusBarService,
Matt Pietal22231792020-01-23 09:51:09 -0500473 mNotificationShadeWindowController,
Matt Pietale0661b62020-01-29 14:35:31 -0500474 shouldShowControls() ? mControlsUiController : null);
Jason Monk361915c2017-03-21 20:33:59 -0400475 dialog.setCanceledOnTouchOutside(false); // Handled by the custom class.
Lucas Dupinc1cc7592017-05-22 15:56:16 -0700476 dialog.setKeyguardShowing(mKeyguardShowing);
Jason Monk361915c2017-03-21 20:33:59 -0400477
478 dialog.setOnDismissListener(this);
Shaotang Li786da902018-08-02 11:18:00 +0800479 dialog.setOnShowListener(this);
Jason Monk361915c2017-03-21 20:33:59 -0400480
481 return dialog;
482 }
483
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800484 private boolean shouldDisplayLockdown() {
485 int userId = getCurrentUser().id;
486 // Lockdown is meaningless without a place to go.
487 if (!mKeyguardManager.isDeviceSecure(userId)) {
488 return false;
489 }
490
491 // Only show the lockdown button if the device isn't locked down (for whatever reason).
492 int state = mLockPatternUtils.getStrongAuthForUser(userId);
493 return (state == STRONG_AUTH_NOT_REQUIRED
494 || state == SOME_AUTH_REQUIRED_AFTER_USER_REQUEST);
495 }
496
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700497 @Override
498 public void onUiModeChanged() {
499 mContext.getTheme().applyStyle(mContext.getThemeResId(), true);
Lucas Dupina4e12ba2019-04-18 11:56:28 -0700500 if (mDialog != null && mDialog.isShowing()) {
Aaron Heuckroth4ef3a542019-04-01 14:17:23 -0400501 mDialog.refreshDialog();
502 }
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700503 }
504
505 public void destroy() {
Dave Mankoff8df818e2020-02-12 14:22:26 -0500506 mConfigurationController.removeCallback(this);
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700507 }
508
Jason Monk361915c2017-03-21 20:33:59 -0400509 private final class PowerAction extends SinglePressAction implements LongPressAction {
510 private PowerAction() {
511 super(R.drawable.ic_lock_power_off,
Jason Monk16fbd9d2017-04-27 14:28:49 -0400512 R.string.global_action_power_off);
Jason Monk361915c2017-03-21 20:33:59 -0400513 }
514
515 @Override
516 public boolean onLongPress() {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500517 if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) {
Jason Monk361915c2017-03-21 20:33:59 -0400518 mWindowManagerFuncs.reboot(true);
519 return true;
520 }
521 return false;
522 }
523
524 @Override
525 public boolean showDuringKeyguard() {
526 return true;
527 }
528
529 @Override
530 public boolean showBeforeProvisioning() {
531 return true;
532 }
533
534 @Override
535 public void onPress() {
536 // shutdown by making sure radio and power are handled accordingly.
537 mWindowManagerFuncs.shutdown();
538 }
539 }
540
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400541 private abstract class EmergencyAction extends SinglePressAction {
542 EmergencyAction(int iconResId, int messageResId) {
543 super(iconResId, messageResId);
544 }
545
546 @Override
547 public boolean shouldBeSeparated() {
Matt Pietale0661b62020-01-29 14:35:31 -0500548 return !shouldShowControls();
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400549 }
550
551 @Override
552 public View create(
553 Context context, View convertView, ViewGroup parent, LayoutInflater inflater) {
554 View v = super.create(context, convertView, parent, inflater);
555 int textColor;
556 if (shouldBeSeparated()) {
557 textColor = v.getResources().getColor(
558 com.android.systemui.R.color.global_actions_alert_text);
559 } else {
560 textColor = v.getResources().getColor(
561 com.android.systemui.R.color.global_actions_text);
562 }
563 TextView messageView = v.findViewById(R.id.message);
564 messageView.setTextColor(textColor);
Aaron Heuckroth3f2d8b52019-04-05 13:27:51 -0400565 messageView.setSelected(true); // necessary for marquee to work
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400566 ImageView icon = (ImageView) v.findViewById(R.id.icon);
567 icon.getDrawable().setTint(textColor);
568 return v;
569 }
570
571 @Override
572 public boolean showDuringKeyguard() {
573 return true;
574 }
575
576 @Override
577 public boolean showBeforeProvisioning() {
578 return true;
579 }
580 }
581
582 private class EmergencyAffordanceAction extends EmergencyAction {
583 EmergencyAffordanceAction() {
584 super(R.drawable.emergency_icon,
585 R.string.global_action_emergency);
586 }
587
588 @Override
589 public void onPress() {
590 mEmergencyAffordanceManager.performEmergencyCall();
591 }
592 }
593
594 private class EmergencyDialerAction extends EmergencyAction {
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800595 private EmergencyDialerAction() {
Aran Ink50195262019-05-30 10:55:37 -0400596 super(com.android.systemui.R.drawable.ic_emergency_star,
Wesley.CW Wang3004fcb2018-06-15 16:24:57 +0800597 R.string.global_action_emergency);
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800598 }
599
600 @Override
601 public void onPress() {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500602 mMetricsLogger.action(MetricsEvent.ACTION_EMERGENCY_DIALER_FROM_POWER_MENU);
603 Intent intent = mTelecomManager.createLaunchEmergencyDialerIntent(null /* number */);
Leo Hsue4cc3122019-03-06 15:25:28 +0800604 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
605 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
606 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
Shaotang Li5c422632018-07-04 14:18:40 +0800607 intent.putExtra(EmergencyDialerConstants.EXTRA_ENTRY_TYPE,
608 EmergencyDialerConstants.ENTRY_TYPE_POWER_MENU);
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800609 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
610 }
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800611 }
612
Jason Monk361915c2017-03-21 20:33:59 -0400613 private final class RestartAction extends SinglePressAction implements LongPressAction {
614 private RestartAction() {
615 super(R.drawable.ic_restart, R.string.global_action_restart);
616 }
617
618 @Override
619 public boolean onLongPress() {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500620 if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) {
Jason Monk361915c2017-03-21 20:33:59 -0400621 mWindowManagerFuncs.reboot(true);
622 return true;
623 }
624 return false;
625 }
626
627 @Override
628 public boolean showDuringKeyguard() {
629 return true;
630 }
631
632 @Override
633 public boolean showBeforeProvisioning() {
634 return true;
635 }
636
637 @Override
638 public void onPress() {
639 mWindowManagerFuncs.reboot(false);
640 }
641 }
642
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400643 private class ScreenshotAction extends SinglePressAction implements LongPressAction {
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500644 public ScreenshotAction() {
645 super(R.drawable.ic_screenshot, R.string.global_action_screenshot);
646 }
647
648 @Override
649 public void onPress() {
650 // Add a little delay before executing, to give the
651 // dialog a chance to go away before it takes a
652 // screenshot.
653 // TODO: instead, omit global action dialog layer
654 mHandler.postDelayed(new Runnable() {
655 @Override
656 public void run() {
James O'Learyfa5bb7a2019-09-05 13:43:29 -0400657 mScreenshotHelper.takeScreenshot(1, true, true, mHandler, null);
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500658 mMetricsLogger.action(MetricsEvent.ACTION_SCREENSHOT_POWER_MENU);
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500659 }
660 }, 500);
661 }
662
663 @Override
664 public boolean showDuringKeyguard() {
665 return true;
666 }
667
668 @Override
669 public boolean showBeforeProvisioning() {
670 return false;
671 }
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400672
673 @Override
674 public boolean onLongPress() {
675 if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SCREENRECORD_LONG_PRESS)) {
676 mScreenRecordHelper.launchRecordPrompt();
677 } else {
678 onPress();
679 }
680 return true;
681 }
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500682 }
683
Jason Monk361915c2017-03-21 20:33:59 -0400684 private class BugReportAction extends SinglePressAction implements LongPressAction {
685
686 public BugReportAction() {
687 super(R.drawable.ic_lock_bugreport, R.string.bugreport_title);
688 }
689
690 @Override
691 public void onPress() {
692 // don't actually trigger the bugreport if we are running stability
693 // tests via monkey
694 if (ActivityManager.isUserAMonkey()) {
695 return;
696 }
697 // Add a little delay before executing, to give the
698 // dialog a chance to go away before it takes a
699 // screenshot.
700 mHandler.postDelayed(new Runnable() {
701 @Override
702 public void run() {
703 try {
704 // Take an "interactive" bugreport.
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500705 mMetricsLogger.action(
Jason Monk361915c2017-03-21 20:33:59 -0400706 MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_INTERACTIVE);
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500707 if (!mIActivityManager.launchBugReportHandlerApp()) {
Paul Changc40f5782019-11-04 18:55:31 +0800708 Log.w(TAG, "Bugreport handler could not be launched");
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500709 mIActivityManager.requestInteractiveBugReport();
Paul Changc40f5782019-11-04 18:55:31 +0800710 }
Jason Monk361915c2017-03-21 20:33:59 -0400711 } catch (RemoteException e) {
712 }
713 }
714 }, 500);
715 }
716
717 @Override
718 public boolean onLongPress() {
719 // don't actually trigger the bugreport if we are running stability
720 // tests via monkey
721 if (ActivityManager.isUserAMonkey()) {
722 return false;
723 }
724 try {
725 // Take a "full" bugreport.
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500726 mMetricsLogger.action(MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_FULL);
727 mIActivityManager.requestFullBugReport();
Jason Monk361915c2017-03-21 20:33:59 -0400728 } catch (RemoteException e) {
729 }
730 return false;
731 }
732
733 public boolean showDuringKeyguard() {
734 return true;
735 }
736
737 @Override
738 public boolean showBeforeProvisioning() {
739 return false;
740 }
Jason Monk361915c2017-03-21 20:33:59 -0400741 }
742
Alex Chau04458852017-11-27 18:21:23 +0000743 private final class LogoutAction extends SinglePressAction {
744 private LogoutAction() {
745 super(R.drawable.ic_logout, R.string.global_action_logout);
746 }
747
748 @Override
749 public boolean showDuringKeyguard() {
750 return true;
751 }
752
753 @Override
754 public boolean showBeforeProvisioning() {
755 return false;
756 }
757
758 @Override
759 public void onPress() {
760 // Add a little delay before executing, to give the dialog a chance to go away before
761 // switching user
762 mHandler.postDelayed(() -> {
763 try {
Alex Chauedb6a012018-01-26 12:52:43 +0000764 int currentUserId = getCurrentUser().id;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500765 mIActivityManager.switchUser(UserHandle.USER_SYSTEM);
766 mIActivityManager.stopUser(currentUserId, true /*force*/, null);
Alex Chau04458852017-11-27 18:21:23 +0000767 } catch (RemoteException re) {
768 Log.e(TAG, "Couldn't logout user " + re);
769 }
770 }, 500);
771 }
772 }
773
Jason Monk361915c2017-03-21 20:33:59 -0400774 private Action getSettingsAction() {
775 return new SinglePressAction(R.drawable.ic_settings,
776 R.string.global_action_settings) {
777
778 @Override
779 public void onPress() {
780 Intent intent = new Intent(Settings.ACTION_SETTINGS);
781 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
782 mContext.startActivity(intent);
783 }
784
785 @Override
786 public boolean showDuringKeyguard() {
787 return true;
788 }
789
790 @Override
791 public boolean showBeforeProvisioning() {
792 return true;
793 }
794 };
795 }
796
Jason Monk361915c2017-03-21 20:33:59 -0400797 private Action getAssistAction() {
798 return new SinglePressAction(R.drawable.ic_action_assist_focused,
799 R.string.global_action_assist) {
800 @Override
801 public void onPress() {
802 Intent intent = new Intent(Intent.ACTION_ASSIST);
803 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
804 mContext.startActivity(intent);
805 }
806
807 @Override
808 public boolean showDuringKeyguard() {
809 return true;
810 }
811
812 @Override
813 public boolean showBeforeProvisioning() {
814 return true;
815 }
816 };
817 }
818
819 private Action getVoiceAssistAction() {
820 return new SinglePressAction(R.drawable.ic_voice_search,
821 R.string.global_action_voice_assist) {
822 @Override
823 public void onPress() {
824 Intent intent = new Intent(Intent.ACTION_VOICE_ASSIST);
825 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
826 mContext.startActivity(intent);
827 }
828
829 @Override
830 public boolean showDuringKeyguard() {
831 return true;
832 }
833
834 @Override
835 public boolean showBeforeProvisioning() {
836 return true;
837 }
838 };
839 }
840
841 private Action getLockdownAction() {
Alison Cichowlas21125432018-05-16 15:40:45 -0400842 return new SinglePressAction(R.drawable.ic_lock_lockdown,
Jason Monk361915c2017-03-21 20:33:59 -0400843 R.string.global_action_lockdown) {
844
845 @Override
846 public void onPress() {
Dave Mankoff8df818e2020-02-12 14:22:26 -0500847 mLockPatternUtils.requireStrongAuth(STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN,
848 UserHandle.USER_ALL);
Jason Monk361915c2017-03-21 20:33:59 -0400849 try {
Dave Mankoff8df818e2020-02-12 14:22:26 -0500850 mIWindowManager.lockNow(null);
Pavel Grafov059021b2018-05-02 13:44:46 +0100851 // Lock profiles (if any) on the background thread.
Dave Mankoff8df818e2020-02-12 14:22:26 -0500852 mBackgroundExecutor.execute(() -> lockProfiles());
Jason Monk361915c2017-03-21 20:33:59 -0400853 } catch (RemoteException e) {
854 Log.e(TAG, "Error while trying to lock device.", e);
855 }
856 }
857
858 @Override
859 public boolean showDuringKeyguard() {
860 return true;
861 }
862
863 @Override
864 public boolean showBeforeProvisioning() {
865 return false;
866 }
867 };
868 }
869
Pavel Grafov059021b2018-05-02 13:44:46 +0100870 private void lockProfiles() {
Pavel Grafov059021b2018-05-02 13:44:46 +0100871 final int currentUserId = getCurrentUser().id;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500872 final int[] profileIds = mUserManager.getEnabledProfileIds(currentUserId);
Pavel Grafov059021b2018-05-02 13:44:46 +0100873 for (final int id : profileIds) {
874 if (id != currentUserId) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500875 mTrustManager.setDeviceLockedForUser(id, true);
Pavel Grafov059021b2018-05-02 13:44:46 +0100876 }
877 }
878 }
879
Jason Monk361915c2017-03-21 20:33:59 -0400880 private UserInfo getCurrentUser() {
881 try {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500882 return mIActivityManager.getCurrentUser();
Jason Monk361915c2017-03-21 20:33:59 -0400883 } catch (RemoteException re) {
884 return null;
885 }
886 }
887
888 private boolean isCurrentUserOwner() {
889 UserInfo currentUser = getCurrentUser();
890 return currentUser == null || currentUser.isPrimary();
891 }
892
893 private void addUsersToMenu(ArrayList<Action> items) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500894 if (mUserManager.isUserSwitcherEnabled()) {
895 List<UserInfo> users = mUserManager.getUsers();
Jason Monk361915c2017-03-21 20:33:59 -0400896 UserInfo currentUser = getCurrentUser();
897 for (final UserInfo user : users) {
898 if (user.supportsSwitchToByUser()) {
899 boolean isCurrentUser = currentUser == null
900 ? user.id == 0 : (currentUser.id == user.id);
901 Drawable icon = user.iconPath != null ? Drawable.createFromPath(user.iconPath)
902 : null;
903 SinglePressAction switchToUser = new SinglePressAction(
904 R.drawable.ic_menu_cc, icon,
905 (user.name != null ? user.name : "Primary")
Jason Monk16fbd9d2017-04-27 14:28:49 -0400906 + (isCurrentUser ? " \u2714" : "")) {
Jason Monk361915c2017-03-21 20:33:59 -0400907 public void onPress() {
908 try {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500909 mIActivityManager.switchUser(user.id);
Jason Monk361915c2017-03-21 20:33:59 -0400910 } catch (RemoteException re) {
911 Log.e(TAG, "Couldn't switch user " + re);
912 }
913 }
914
915 public boolean showDuringKeyguard() {
916 return true;
917 }
918
919 public boolean showBeforeProvisioning() {
920 return false;
921 }
922 };
923 items.add(switchToUser);
924 }
925 }
926 }
927 }
928
929 private void prepareDialog() {
930 refreshSilentMode();
931 mAirplaneModeOn.updateState(mAirplaneState);
932 mAdapter.notifyDataSetChanged();
Jason Monk361915c2017-03-21 20:33:59 -0400933 if (mShowSilentToggle) {
934 IntentFilter filter = new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION);
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000935 mBroadcastDispatcher.registerReceiver(mRingerModeReceiver, filter);
Jason Monk361915c2017-03-21 20:33:59 -0400936 }
937 }
938
939 private void refreshSilentMode() {
940 if (!mHasVibrator) {
941 final boolean silentModeOn =
942 mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL;
Jason Monk16fbd9d2017-04-27 14:28:49 -0400943 ((ToggleAction) mSilentModeAction).updateState(
Jason Monk361915c2017-03-21 20:33:59 -0400944 silentModeOn ? ToggleAction.State.On : ToggleAction.State.Off);
945 }
946 }
947
948 /** {@inheritDoc} */
949 public void onDismiss(DialogInterface dialog) {
Steve Elliottc3147e22019-11-20 19:34:57 -0500950 if (mDialog == dialog) {
951 mDialog = null;
952 }
Jason Monk361915c2017-03-21 20:33:59 -0400953 mWindowManagerFuncs.onGlobalActionsHidden();
954 if (mShowSilentToggle) {
955 try {
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000956 mBroadcastDispatcher.unregisterReceiver(mRingerModeReceiver);
Jason Monk361915c2017-03-21 20:33:59 -0400957 } catch (IllegalArgumentException ie) {
958 // ignore this
959 Log.w(TAG, ie);
960 }
961 }
962 }
963
964 /** {@inheritDoc} */
Shaotang Li786da902018-08-02 11:18:00 +0800965 public void onShow(DialogInterface dialog) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500966 mMetricsLogger.visible(MetricsEvent.POWER_MENU);
Shaotang Li786da902018-08-02 11:18:00 +0800967 }
968
Jason Monk361915c2017-03-21 20:33:59 -0400969 /**
970 * The adapter used for the list within the global actions dialog, taking
971 * into account whether the keyguard is showing via
Jason Monk16fbd9d2017-04-27 14:28:49 -0400972 * {@link com.android.systemui.globalactions.GlobalActionsDialog#mKeyguardShowing} and whether
973 * the device is provisioned
Jason Monk361915c2017-03-21 20:33:59 -0400974 * via {@link com.android.systemui.globalactions.GlobalActionsDialog#mDeviceProvisioned}.
975 */
Aaron Heuckroth57d60d22019-03-05 14:00:12 -0500976 public class MyAdapter extends MultiListAdapter {
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -0400977 private int countItems(boolean separated) {
Jason Monk361915c2017-03-21 20:33:59 -0400978 int count = 0;
Jason Monk361915c2017-03-21 20:33:59 -0400979 for (int i = 0; i < mItems.size(); i++) {
980 final Action action = mItems.get(i);
981
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -0400982 if (shouldBeShown(action) && action.shouldBeSeparated() == separated) {
983 count++;
Jason Monk361915c2017-03-21 20:33:59 -0400984 }
Jason Monk361915c2017-03-21 20:33:59 -0400985 }
986 return count;
987 }
988
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -0400989 private boolean shouldBeShown(Action action) {
990 if (mKeyguardShowing && !action.showDuringKeyguard()) {
991 return false;
992 }
993 if (!mDeviceProvisioned && !action.showBeforeProvisioning()) {
994 return false;
995 }
996 return true;
997 }
998
999 @Override
1000 public int countSeparatedItems() {
1001 return countItems(true);
1002 }
1003
1004 @Override
1005 public int countListItems() {
1006 return countItems(false);
1007 }
1008
1009 @Override
1010 public int getCount() {
1011 return countSeparatedItems() + countListItems();
1012 }
1013
Jason Monk361915c2017-03-21 20:33:59 -04001014 @Override
1015 public boolean isEnabled(int position) {
1016 return getItem(position).isEnabled();
1017 }
1018
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001019 @Override
Jason Monk361915c2017-03-21 20:33:59 -04001020 public boolean areAllItemsEnabled() {
1021 return false;
1022 }
1023
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001024 @Override
Jason Monk361915c2017-03-21 20:33:59 -04001025 public Action getItem(int position) {
Jason Monk361915c2017-03-21 20:33:59 -04001026 int filteredPos = 0;
1027 for (int i = 0; i < mItems.size(); i++) {
1028 final Action action = mItems.get(i);
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -04001029 if (!shouldBeShown(action)) {
Jason Monk361915c2017-03-21 20:33:59 -04001030 continue;
1031 }
1032 if (filteredPos == position) {
1033 return action;
1034 }
1035 filteredPos++;
1036 }
1037
1038 throw new IllegalArgumentException("position " + position
1039 + " out of range of showable actions"
1040 + ", filtered count=" + getCount()
1041 + ", keyguardshowing=" + mKeyguardShowing
1042 + ", provisioned=" + mDeviceProvisioned);
1043 }
1044
1045
1046 public long getItemId(int position) {
1047 return position;
1048 }
1049
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001050 @Override
Jason Monk361915c2017-03-21 20:33:59 -04001051 public View getView(int position, View convertView, ViewGroup parent) {
1052 Action action = getItem(position);
Jason Monk16fbd9d2017-04-27 14:28:49 -04001053 View view = action.create(mContext, convertView, parent, LayoutInflater.from(mContext));
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -04001054 view.setOnClickListener(v -> onClickItem(position));
Aran Inkb4199d92020-02-07 13:25:21 -05001055 if (action instanceof LongPressAction) {
1056 view.setOnLongClickListener(v -> onLongClickItem(position));
1057 }
Jason Monk16fbd9d2017-04-27 14:28:49 -04001058 return view;
Jason Monk361915c2017-03-21 20:33:59 -04001059 }
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001060
1061 @Override
1062 public boolean onLongClickItem(int position) {
1063 final Action action = mAdapter.getItem(position);
1064 if (action instanceof LongPressAction) {
Aran Inkbaa25862019-06-11 15:48:55 -04001065 if (mDialog != null) {
1066 mDialog.dismiss();
1067 } else {
1068 Log.w(TAG, "Action long-clicked while mDialog is null.");
1069 }
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001070 return ((LongPressAction) action).onLongPress();
1071 }
1072 return false;
1073 }
1074
1075 @Override
1076 public void onClickItem(int position) {
1077 Action item = mAdapter.getItem(position);
1078 if (!(item instanceof SilentModeTriStateAction)) {
Aran Inkbaa25862019-06-11 15:48:55 -04001079 if (mDialog != null) {
1080 mDialog.dismiss();
1081 } else {
1082 Log.w(TAG, "Action clicked while mDialog is null.");
1083 }
1084 item.onPress();
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001085 }
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001086 }
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -04001087
1088 @Override
1089 public boolean shouldBeSeparated(int position) {
1090 return getItem(position).shouldBeSeparated();
1091 }
Jason Monk361915c2017-03-21 20:33:59 -04001092 }
1093
1094 // note: the scheme below made more sense when we were planning on having
1095 // 8 different things in the global actions dialog. seems overkill with
1096 // only 3 items now, but may as well keep this flexible approach so it will
1097 // be easy should someone decide at the last minute to include something
1098 // else, such as 'enable wifi', or 'enable bluetooth'
1099
1100 /**
1101 * What each item in the global actions dialog must be able to support.
1102 */
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001103 public interface Action {
Jason Monk361915c2017-03-21 20:33:59 -04001104 /**
1105 * @return Text that will be announced when dialog is created. null
Jason Monk16fbd9d2017-04-27 14:28:49 -04001106 * for none.
Jason Monk361915c2017-03-21 20:33:59 -04001107 */
1108 CharSequence getLabelForAccessibility(Context context);
1109
1110 View create(Context context, View convertView, ViewGroup parent, LayoutInflater inflater);
1111
1112 void onPress();
1113
1114 /**
1115 * @return whether this action should appear in the dialog when the keygaurd
Jason Monk16fbd9d2017-04-27 14:28:49 -04001116 * is showing.
Jason Monk361915c2017-03-21 20:33:59 -04001117 */
1118 boolean showDuringKeyguard();
1119
1120 /**
1121 * @return whether this action should appear in the dialog before the
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001122 * device is provisioned.onlongpress
1123 *
Jason Monk361915c2017-03-21 20:33:59 -04001124 */
1125 boolean showBeforeProvisioning();
1126
1127 boolean isEnabled();
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001128
1129 default boolean shouldBeSeparated() {
1130 return false;
1131 }
Jason Monk361915c2017-03-21 20:33:59 -04001132 }
1133
1134 /**
1135 * An action that also supports long press.
1136 */
1137 private interface LongPressAction extends Action {
1138 boolean onLongPress();
1139 }
1140
1141 /**
1142 * A single press action maintains no state, just responds to a press
1143 * and takes an action.
1144 */
Matt Pietale0661b62020-01-29 14:35:31 -05001145
1146 private abstract class SinglePressAction implements Action {
Jason Monk361915c2017-03-21 20:33:59 -04001147 private final int mIconResId;
1148 private final Drawable mIcon;
1149 private final int mMessageResId;
1150 private final CharSequence mMessage;
1151
1152 protected SinglePressAction(int iconResId, int messageResId) {
1153 mIconResId = iconResId;
1154 mMessageResId = messageResId;
1155 mMessage = null;
1156 mIcon = null;
1157 }
1158
1159 protected SinglePressAction(int iconResId, Drawable icon, CharSequence message) {
1160 mIconResId = iconResId;
1161 mMessageResId = 0;
1162 mMessage = message;
1163 mIcon = icon;
1164 }
1165
1166 public boolean isEnabled() {
1167 return true;
1168 }
1169
1170 public String getStatus() {
1171 return null;
1172 }
1173
1174 abstract public void onPress();
1175
1176 public CharSequence getLabelForAccessibility(Context context) {
1177 if (mMessage != null) {
1178 return mMessage;
1179 } else {
1180 return context.getString(mMessageResId);
1181 }
1182 }
1183
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001184 protected int getActionLayoutId(Context context) {
Matt Pietale0661b62020-01-29 14:35:31 -05001185 if (shouldShowControls()) {
Matt Pietalfd3b6cb2020-01-08 09:43:54 -05001186 return com.android.systemui.R.layout.global_actions_grid_item_v2;
1187 }
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001188 return com.android.systemui.R.layout.global_actions_grid_item;
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001189 }
1190
Jason Monk361915c2017-03-21 20:33:59 -04001191 public View create(
1192 Context context, View convertView, ViewGroup parent, LayoutInflater inflater) {
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001193 View v = inflater.inflate(getActionLayoutId(context), parent,
Jason Monk16fbd9d2017-04-27 14:28:49 -04001194 false);
Jason Monk361915c2017-03-21 20:33:59 -04001195
1196 ImageView icon = (ImageView) v.findViewById(R.id.icon);
1197 TextView messageView = (TextView) v.findViewById(R.id.message);
Aaron Heuckroth3f2d8b52019-04-05 13:27:51 -04001198 messageView.setSelected(true); // necessary for marquee to work
Jason Monk361915c2017-03-21 20:33:59 -04001199
Jason Monk361915c2017-03-21 20:33:59 -04001200 if (mIcon != null) {
1201 icon.setImageDrawable(mIcon);
1202 icon.setScaleType(ScaleType.CENTER_CROP);
1203 } else if (mIconResId != 0) {
1204 icon.setImageDrawable(context.getDrawable(mIconResId));
1205 }
1206 if (mMessage != null) {
1207 messageView.setText(mMessage);
1208 } else {
1209 messageView.setText(mMessageResId);
1210 }
1211
1212 return v;
1213 }
1214 }
1215
1216 /**
1217 * A toggle action knows whether it is on or off, and displays an icon
1218 * and status message accordingly.
1219 */
1220 private static abstract class ToggleAction implements Action {
1221
1222 enum State {
1223 Off(false),
1224 TurningOn(true),
1225 TurningOff(true),
1226 On(false);
1227
1228 private final boolean inTransition;
1229
1230 State(boolean intermediate) {
1231 inTransition = intermediate;
1232 }
1233
1234 public boolean inTransition() {
1235 return inTransition;
1236 }
1237 }
1238
1239 protected State mState = State.Off;
1240
1241 // prefs
1242 protected int mEnabledIconResId;
1243 protected int mDisabledIconResid;
1244 protected int mMessageResId;
1245 protected int mEnabledStatusMessageResId;
1246 protected int mDisabledStatusMessageResId;
1247
1248 /**
Jason Monk16fbd9d2017-04-27 14:28:49 -04001249 * @param enabledIconResId The icon for when this action is on.
1250 * @param disabledIconResid The icon for when this action is off.
1251 * @param message The general information message, e.g 'Silent Mode'
1252 * @param enabledStatusMessageResId The on status message, e.g 'sound disabled'
Jason Monk361915c2017-03-21 20:33:59 -04001253 * @param disabledStatusMessageResId The off status message, e.g. 'sound enabled'
1254 */
1255 public ToggleAction(int enabledIconResId,
1256 int disabledIconResid,
1257 int message,
1258 int enabledStatusMessageResId,
1259 int disabledStatusMessageResId) {
1260 mEnabledIconResId = enabledIconResId;
1261 mDisabledIconResid = disabledIconResid;
1262 mMessageResId = message;
1263 mEnabledStatusMessageResId = enabledStatusMessageResId;
1264 mDisabledStatusMessageResId = disabledStatusMessageResId;
1265 }
1266
1267 /**
1268 * Override to make changes to resource IDs just before creating the
1269 * View.
1270 */
1271 void willCreate() {
1272
1273 }
1274
1275 @Override
1276 public CharSequence getLabelForAccessibility(Context context) {
1277 return context.getString(mMessageResId);
1278 }
1279
1280 public View create(Context context, View convertView, ViewGroup parent,
1281 LayoutInflater inflater) {
1282 willCreate();
1283
Koji Fukui5c010ee2019-12-24 16:12:07 +09001284 View v = inflater.inflate(com.android.systemui.R
1285 .layout.global_actions_grid_item, parent, false);
Jason Monk361915c2017-03-21 20:33:59 -04001286
1287 ImageView icon = (ImageView) v.findViewById(R.id.icon);
1288 TextView messageView = (TextView) v.findViewById(R.id.message);
Jason Monk361915c2017-03-21 20:33:59 -04001289 final boolean enabled = isEnabled();
Koji Fukui5c010ee2019-12-24 16:12:07 +09001290 boolean on = ((mState == State.On) || (mState == State.TurningOn));
Jason Monk361915c2017-03-21 20:33:59 -04001291
1292 if (messageView != null) {
Koji Fukui5c010ee2019-12-24 16:12:07 +09001293 messageView.setText(on ? mEnabledStatusMessageResId : mDisabledStatusMessageResId);
Jason Monk361915c2017-03-21 20:33:59 -04001294 messageView.setEnabled(enabled);
Aaron Heuckroth3f2d8b52019-04-05 13:27:51 -04001295 messageView.setSelected(true); // necessary for marquee to work
Jason Monk361915c2017-03-21 20:33:59 -04001296 }
1297
Jason Monk361915c2017-03-21 20:33:59 -04001298 if (icon != null) {
1299 icon.setImageDrawable(context.getDrawable(
1300 (on ? mEnabledIconResId : mDisabledIconResid)));
1301 icon.setEnabled(enabled);
1302 }
1303
Jason Monk361915c2017-03-21 20:33:59 -04001304 v.setEnabled(enabled);
1305
1306 return v;
1307 }
1308
1309 public final void onPress() {
1310 if (mState.inTransition()) {
1311 Log.w(TAG, "shouldn't be able to toggle when in transition");
1312 return;
1313 }
1314
1315 final boolean nowOn = !(mState == State.On);
1316 onToggle(nowOn);
1317 changeStateFromPress(nowOn);
1318 }
1319
1320 public boolean isEnabled() {
1321 return !mState.inTransition();
1322 }
1323
1324 /**
1325 * Implementations may override this if their state can be in on of the intermediate
1326 * states until some notification is received (e.g airplane mode is 'turning off' until
1327 * we know the wireless connections are back online
Jason Monk16fbd9d2017-04-27 14:28:49 -04001328 *
Jason Monk361915c2017-03-21 20:33:59 -04001329 * @param buttonOn Whether the button was turned on or off
1330 */
1331 protected void changeStateFromPress(boolean buttonOn) {
1332 mState = buttonOn ? State.On : State.Off;
1333 }
1334
1335 abstract void onToggle(boolean on);
1336
1337 public void updateState(State state) {
1338 mState = state;
1339 }
1340 }
1341
1342 private class SilentModeToggleAction extends ToggleAction {
1343 public SilentModeToggleAction() {
1344 super(R.drawable.ic_audio_vol_mute,
1345 R.drawable.ic_audio_vol,
1346 R.string.global_action_toggle_silent_mode,
1347 R.string.global_action_silent_mode_on_status,
1348 R.string.global_action_silent_mode_off_status);
1349 }
1350
1351 void onToggle(boolean on) {
1352 if (on) {
1353 mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
1354 } else {
1355 mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
1356 }
1357 }
1358
1359 public boolean showDuringKeyguard() {
1360 return true;
1361 }
1362
1363 public boolean showBeforeProvisioning() {
1364 return false;
1365 }
1366 }
1367
1368 private static class SilentModeTriStateAction implements Action, View.OnClickListener {
1369
Jason Monk16fbd9d2017-04-27 14:28:49 -04001370 private final int[] ITEM_IDS = {R.id.option1, R.id.option2, R.id.option3};
Jason Monk361915c2017-03-21 20:33:59 -04001371
1372 private final AudioManager mAudioManager;
1373 private final Handler mHandler;
Jason Monk361915c2017-03-21 20:33:59 -04001374
Lucas Dupin40ec6b782018-06-05 19:07:16 -07001375 SilentModeTriStateAction(AudioManager audioManager, Handler handler) {
Jason Monk361915c2017-03-21 20:33:59 -04001376 mAudioManager = audioManager;
1377 mHandler = handler;
Jason Monk361915c2017-03-21 20:33:59 -04001378 }
1379
1380 private int ringerModeToIndex(int ringerMode) {
1381 // They just happen to coincide
1382 return ringerMode;
1383 }
1384
1385 private int indexToRingerMode(int index) {
1386 // They just happen to coincide
1387 return index;
1388 }
1389
1390 @Override
1391 public CharSequence getLabelForAccessibility(Context context) {
1392 return null;
1393 }
1394
1395 public View create(Context context, View convertView, ViewGroup parent,
1396 LayoutInflater inflater) {
1397 View v = inflater.inflate(R.layout.global_actions_silent_mode, parent, false);
1398
1399 int selectedIndex = ringerModeToIndex(mAudioManager.getRingerMode());
1400 for (int i = 0; i < 3; i++) {
1401 View itemView = v.findViewById(ITEM_IDS[i]);
1402 itemView.setSelected(selectedIndex == i);
1403 // Set up click handler
1404 itemView.setTag(i);
1405 itemView.setOnClickListener(this);
1406 }
1407 return v;
1408 }
1409
1410 public void onPress() {
1411 }
1412
1413 public boolean showDuringKeyguard() {
1414 return true;
1415 }
1416
1417 public boolean showBeforeProvisioning() {
1418 return false;
1419 }
1420
1421 public boolean isEnabled() {
1422 return true;
1423 }
1424
1425 void willCreate() {
1426 }
1427
1428 public void onClick(View v) {
1429 if (!(v.getTag() instanceof Integer)) return;
1430
1431 int index = (Integer) v.getTag();
1432 mAudioManager.setRingerMode(indexToRingerMode(index));
1433 mHandler.sendEmptyMessageDelayed(MESSAGE_DISMISS, DIALOG_DISMISS_DELAY);
1434 }
1435 }
1436
1437 private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
1438 public void onReceive(Context context, Intent intent) {
1439 String action = intent.getAction();
1440 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)
1441 || Intent.ACTION_SCREEN_OFF.equals(action)) {
1442 String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY);
1443 if (!SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS.equals(reason)) {
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001444 mHandler.sendMessage(mHandler.obtainMessage(MESSAGE_DISMISS, reason));
Jason Monk361915c2017-03-21 20:33:59 -04001445 }
Jayachandran C142eae02019-12-13 19:29:20 -08001446 } else if (TelephonyManager.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED.equals(action)) {
Jason Monk361915c2017-03-21 20:33:59 -04001447 // Airplane mode can be changed after ECM exits if airplane toggle button
1448 // is pressed during ECM mode
Daniel Bright4bcbfce2020-01-09 21:58:16 -08001449 if (!(intent.getBooleanExtra(TelephonyManager.EXTRA_PHONE_IN_ECM_STATE, false))
1450 && mIsWaitingForEcmExit) {
Jason Monk361915c2017-03-21 20:33:59 -04001451 mIsWaitingForEcmExit = false;
1452 changeAirplaneModeSystemSetting(true);
1453 }
1454 }
1455 }
1456 };
1457
1458 PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
1459 @Override
1460 public void onServiceStateChanged(ServiceState serviceState) {
1461 if (!mHasTelephony) return;
1462 final boolean inAirplaneMode = serviceState.getState() == ServiceState.STATE_POWER_OFF;
1463 mAirplaneState = inAirplaneMode ? ToggleAction.State.On : ToggleAction.State.Off;
1464 mAirplaneModeOn.updateState(mAirplaneState);
1465 mAdapter.notifyDataSetChanged();
1466 }
1467 };
1468
1469 private BroadcastReceiver mRingerModeReceiver = new BroadcastReceiver() {
1470 @Override
1471 public void onReceive(Context context, Intent intent) {
1472 if (intent.getAction().equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
1473 mHandler.sendEmptyMessage(MESSAGE_REFRESH);
1474 }
1475 }
1476 };
1477
1478 private ContentObserver mAirplaneModeObserver = new ContentObserver(new Handler()) {
1479 @Override
1480 public void onChange(boolean selfChange) {
1481 onAirplaneModeChanged();
1482 }
1483 };
1484
1485 private static final int MESSAGE_DISMISS = 0;
1486 private static final int MESSAGE_REFRESH = 1;
1487 private static final int MESSAGE_SHOW = 2;
1488 private static final int DIALOG_DISMISS_DELAY = 300; // ms
1489
1490 private Handler mHandler = new Handler() {
1491 public void handleMessage(Message msg) {
1492 switch (msg.what) {
Jason Monk16fbd9d2017-04-27 14:28:49 -04001493 case MESSAGE_DISMISS:
1494 if (mDialog != null) {
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001495 if (SYSTEM_DIALOG_REASON_DREAM.equals(msg.obj)) {
1496 mDialog.dismissImmediately();
1497 } else {
1498 mDialog.dismiss();
1499 }
Jason Monk16fbd9d2017-04-27 14:28:49 -04001500 mDialog = null;
1501 }
1502 break;
1503 case MESSAGE_REFRESH:
1504 refreshSilentMode();
1505 mAdapter.notifyDataSetChanged();
1506 break;
1507 case MESSAGE_SHOW:
1508 handleShow();
1509 break;
Jason Monk361915c2017-03-21 20:33:59 -04001510 }
1511 }
1512 };
1513
1514 private void onAirplaneModeChanged() {
1515 // Let the service state callbacks handle the state.
1516 if (mHasTelephony) return;
1517
1518 boolean airplaneModeOn = Settings.Global.getInt(
Dave Mankoffc88a2d72020-01-10 15:59:31 -05001519 mContentResolver,
Jason Monk361915c2017-03-21 20:33:59 -04001520 Settings.Global.AIRPLANE_MODE_ON,
1521 0) == 1;
1522 mAirplaneState = airplaneModeOn ? ToggleAction.State.On : ToggleAction.State.Off;
1523 mAirplaneModeOn.updateState(mAirplaneState);
1524 }
1525
1526 /**
1527 * Change the airplane mode system setting
1528 */
1529 private void changeAirplaneModeSystemSetting(boolean on) {
1530 Settings.Global.putInt(
Dave Mankoffc88a2d72020-01-10 15:59:31 -05001531 mContentResolver,
Jason Monk361915c2017-03-21 20:33:59 -04001532 Settings.Global.AIRPLANE_MODE_ON,
1533 on ? 1 : 0);
1534 Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
1535 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
1536 intent.putExtra("state", on);
1537 mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
1538 if (!mHasTelephony) {
1539 mAirplaneState = on ? ToggleAction.State.On : ToggleAction.State.Off;
1540 }
1541 }
1542
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001543 private static final class ActionsDialog extends Dialog implements DialogInterface,
1544 ColorExtractor.OnColorsChangedListener {
Jason Monk361915c2017-03-21 20:33:59 -04001545
Jason Monk16fbd9d2017-04-27 14:28:49 -04001546 private final Context mContext;
1547 private final MyAdapter mAdapter;
Steve Elliott53f12ae2019-05-13 17:14:15 -04001548 private final IStatusBarService mStatusBarService;
1549 private final IBinder mToken = new Binder();
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001550 private MultiListLayout mGlobalActionsLayout;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001551 private Drawable mBackgroundDrawable;
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001552 private final SysuiColorExtractor mColorExtractor;
Steve Elliott9b87a442019-03-05 10:24:16 -05001553 private final GlobalActionsPanelPlugin.PanelViewController mPanelController;
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001554 private boolean mKeyguardShowing;
Beverly526d2d62018-08-15 12:55:33 -04001555 private boolean mShowing;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001556 private float mScrimAlpha;
Steve Elliott48f75db2019-05-03 15:03:38 -04001557 private ResetOrientationData mResetOrientationData;
Steve Elliottff2c0d92019-07-30 15:09:54 -04001558 private boolean mHadTopUi;
wilsonshihe8321942019-10-18 18:39:46 +08001559 private final NotificationShadeWindowController mNotificationShadeWindowController;
Lucas Dupin991415e2019-11-25 17:48:58 -08001560 private final BlurUtils mBlurUtils;
Matt Pietal22231792020-01-23 09:51:09 -05001561
1562 private ControlsUiController mControlsUiController;
1563 private ViewGroup mControlsView;
Jason Monk16fbd9d2017-04-27 14:28:49 -04001564
Aaron Heuckrothf19d2722019-03-11 17:06:02 -04001565 ActionsDialog(Context context, MyAdapter adapter,
Lucas Dupin991415e2019-11-25 17:48:58 -08001566 GlobalActionsPanelPlugin.PanelViewController plugin, BlurUtils blurUtils,
1567 SysuiColorExtractor sysuiColorExtractor, IStatusBarService statusBarService,
1568 NotificationShadeWindowController notificationShadeWindowController,
Matt Pietal22231792020-01-23 09:51:09 -05001569 ControlsUiController controlsUiController) {
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001570 super(context, com.android.systemui.R.style.Theme_SystemUI_Dialog_GlobalActions);
Lucas Dupin448786c2017-07-24 17:44:25 -07001571 mContext = context;
Jason Monk16fbd9d2017-04-27 14:28:49 -04001572 mAdapter = adapter;
Lucas Dupin991415e2019-11-25 17:48:58 -08001573 mBlurUtils = blurUtils;
1574 mColorExtractor = sysuiColorExtractor;
1575 mStatusBarService = statusBarService;
1576 mNotificationShadeWindowController = notificationShadeWindowController;
Matt Pietal22231792020-01-23 09:51:09 -05001577 mControlsUiController = controlsUiController;
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001578
1579 // Window initialization
1580 Window window = getWindow();
1581 window.requestFeature(Window.FEATURE_NO_TITLE);
Adrian Roosedfab3b2018-03-08 18:39:20 +01001582 // Inflate the decor view, so the attributes below are not overwritten by the theme.
1583 window.getDecorView();
1584 window.getAttributes().systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1585 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1586 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1587 window.setLayout(MATCH_PARENT, MATCH_PARENT);
1588 window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
Alison Cichowlas4f19f4a2017-07-25 10:56:16 -04001589 window.addFlags(
1590 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001591 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
Adrian Roosedfab3b2018-03-08 18:39:20 +01001592 | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001593 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
1594 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
1595 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001596 window.setType(WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY);
Tiger Huang52724442020-01-20 21:38:42 +08001597 window.getAttributes().setFitInsetsTypes(0 /* types */);
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001598 setTitle(R.string.global_actions);
Steve Elliott9b87a442019-03-05 10:24:16 -05001599
1600 mPanelController = plugin;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001601 initializeLayout();
Steve Elliott9b87a442019-03-05 10:24:16 -05001602 }
1603
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001604 private boolean shouldUsePanel() {
Aran Ink3f594552019-05-13 14:29:35 -04001605 return mPanelController != null && mPanelController.getPanelContent() != null;
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001606 }
1607
1608 private void initializePanel() {
Steve Elliott48f75db2019-05-03 15:03:38 -04001609 int rotation = RotationUtils.getRotation(mContext);
1610 boolean rotationLocked = RotationPolicy.isRotationLocked(mContext);
1611 if (rotation != RotationUtils.ROTATION_NONE) {
1612 if (rotationLocked) {
1613 if (mResetOrientationData == null) {
1614 mResetOrientationData = new ResetOrientationData();
1615 mResetOrientationData.locked = true;
1616 mResetOrientationData.rotation = rotation;
1617 }
1618
1619 // Unlock rotation, so user can choose to rotate to portrait to see the panel.
Steve Elliotte05817f2019-05-17 14:39:53 -04001620 // This call is posted so that the rotation does not change until post-layout,
1621 // otherwise onConfigurationChanged() may not get invoked.
1622 mGlobalActionsLayout.post(() ->
1623 RotationPolicy.setRotationLockAtAngle(
1624 mContext, false, RotationUtils.ROTATION_NONE));
Steve Elliott48f75db2019-05-03 15:03:38 -04001625 }
1626 } else {
1627 if (!rotationLocked) {
1628 if (mResetOrientationData == null) {
1629 mResetOrientationData = new ResetOrientationData();
1630 mResetOrientationData.locked = false;
1631 }
1632
1633 // Lock to portrait, so the user doesn't accidentally hide 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, true, RotationUtils.ROTATION_NONE));
Steve Elliott48f75db2019-05-03 15:03:38 -04001639 }
1640
Steve Elliott53f12ae2019-05-13 17:14:15 -04001641 // Disable rotation suggestions, if enabled
1642 setRotationSuggestionsEnabled(false);
1643
Steve Elliott300b48f2019-05-29 14:13:50 -04001644 FrameLayout panelContainer =
1645 findViewById(com.android.systemui.R.id.global_actions_panel_container);
Steve Elliott48f75db2019-05-03 15:03:38 -04001646 FrameLayout.LayoutParams panelParams =
1647 new FrameLayout.LayoutParams(
1648 FrameLayout.LayoutParams.MATCH_PARENT,
Steve Elliott300b48f2019-05-29 14:13:50 -04001649 FrameLayout.LayoutParams.MATCH_PARENT);
Steve Elliott48f75db2019-05-03 15:03:38 -04001650 panelContainer.addView(mPanelController.getPanelContent(), panelParams);
Steve Elliott48f75db2019-05-03 15:03:38 -04001651 }
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001652 }
1653
1654 private void initializeLayout() {
1655 setContentView(getGlobalActionsLayoutId(mContext));
Steve Elliott300b48f2019-05-29 14:13:50 -04001656 fixNavBarClipping();
Matt Pietal22231792020-01-23 09:51:09 -05001657 mControlsView = findViewById(com.android.systemui.R.id.global_actions_controls);
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001658 mGlobalActionsLayout = findViewById(com.android.systemui.R.id.global_actions_view);
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001659 mGlobalActionsLayout.setOutsideTouchListener(view -> dismiss());
Steve Elliott300b48f2019-05-29 14:13:50 -04001660 ((View) mGlobalActionsLayout.getParent()).setOnClickListener(view -> dismiss());
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001661 mGlobalActionsLayout.setListViewAccessibilityDelegate(new View.AccessibilityDelegate() {
Phil Weaver9054e092018-04-27 16:28:50 -07001662 @Override
1663 public boolean dispatchPopulateAccessibilityEvent(
1664 View host, AccessibilityEvent event) {
1665 // Populate the title here, just as Activity does
1666 event.getText().add(mContext.getString(R.string.global_actions));
1667 return true;
1668 }
1669 });
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001670 mGlobalActionsLayout.setRotationListener(this::onRotate);
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001671 mGlobalActionsLayout.setAdapter(mAdapter);
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001672
Steve Elliott86ef6282019-05-08 14:45:04 -04001673 if (shouldUsePanel()) {
Steve Elliottc59eb342019-04-23 16:59:06 -04001674 initializePanel();
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001675 }
Steve Elliott86ef6282019-05-08 14:45:04 -04001676 if (mBackgroundDrawable == null) {
1677 mBackgroundDrawable = new ScrimDrawable();
Lucas Dupin43d01242020-02-03 11:58:33 -08001678 mScrimAlpha = ScrimController.BUSY_SCRIM_ALPHA;
Steve Elliott86ef6282019-05-08 14:45:04 -04001679 }
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001680 getWindow().setBackgroundDrawable(mBackgroundDrawable);
Steve Elliott9b87a442019-03-05 10:24:16 -05001681 }
1682
Steve Elliott300b48f2019-05-29 14:13:50 -04001683 private void fixNavBarClipping() {
1684 ViewGroup content = findViewById(android.R.id.content);
1685 content.setClipChildren(false);
1686 content.setClipToPadding(false);
1687 ViewGroup contentParent = (ViewGroup) content.getParent();
1688 contentParent.setClipChildren(false);
1689 contentParent.setClipToPadding(false);
1690 }
1691
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001692 private int getGlobalActionsLayoutId(Context context) {
Matt Pietal22231792020-01-23 09:51:09 -05001693 if (mControlsUiController != null) {
Matt Pietalfd3b6cb2020-01-08 09:43:54 -05001694 return com.android.systemui.R.layout.global_actions_grid_v2;
1695 }
1696
Steve Elliottdc165632019-05-23 14:26:31 -04001697 int rotation = RotationUtils.getRotation(context);
1698 boolean useGridLayout = isForceGridEnabled(context)
1699 || (shouldUsePanel() && rotation == RotationUtils.ROTATION_NONE);
1700 if (rotation == RotationUtils.ROTATION_SEASCAPE) {
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001701 if (useGridLayout) {
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001702 return com.android.systemui.R.layout.global_actions_grid_seascape;
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001703 } else {
1704 return com.android.systemui.R.layout.global_actions_column_seascape;
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001705 }
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001706 } else {
1707 if (useGridLayout) {
1708 return com.android.systemui.R.layout.global_actions_grid;
1709 } else {
1710 return com.android.systemui.R.layout.global_actions_column;
1711 }
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001712 }
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001713 }
1714
Jason Monk361915c2017-03-21 20:33:59 -04001715 @Override
1716 protected void onStart() {
1717 super.setCanceledOnTouchOutside(true);
1718 super.onStart();
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001719 mGlobalActionsLayout.updateList();
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001720
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001721 if (mBackgroundDrawable instanceof ScrimDrawable) {
Steve Elliott9b87a442019-03-05 10:24:16 -05001722 mColorExtractor.addOnColorsChangedListener(this);
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001723 GradientColors colors = mColorExtractor.getNeutralColors();
Steve Elliott9b87a442019-03-05 10:24:16 -05001724 updateColors(colors, false /* animate */);
1725 }
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001726 }
1727
1728 /**
1729 * Updates background and system bars according to current GradientColors.
1730 * @param colors Colors and hints to use.
1731 * @param animate Interpolates gradient if true, just sets otherwise.
1732 */
1733 private void updateColors(GradientColors colors, boolean animate) {
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001734 if (!(mBackgroundDrawable instanceof ScrimDrawable)) {
Steve Elliott9b87a442019-03-05 10:24:16 -05001735 return;
1736 }
Lucas Dupinba2b48a2020-02-06 09:28:06 -08001737 ((ScrimDrawable) mBackgroundDrawable).setColor(colors.supportsDarkText() ? Color.WHITE
1738 : Color.BLACK, animate);
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001739 View decorView = getWindow().getDecorView();
1740 if (colors.supportsDarkText()) {
1741 decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR |
Steve Elliott9b87a442019-03-05 10:24:16 -05001742 View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001743 } else {
1744 decorView.setSystemUiVisibility(0);
1745 }
Jason Monk361915c2017-03-21 20:33:59 -04001746 }
1747
1748 @Override
Jason Monk16fbd9d2017-04-27 14:28:49 -04001749 protected void onStop() {
1750 super.onStop();
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001751 mColorExtractor.removeOnColorsChangedListener(this);
Jason Monk16fbd9d2017-04-27 14:28:49 -04001752 }
1753
1754 @Override
1755 public void show() {
1756 super.show();
Beverly526d2d62018-08-15 12:55:33 -04001757 mShowing = true;
wilsonshihe8321942019-10-18 18:39:46 +08001758 mHadTopUi = mNotificationShadeWindowController.getForceHasTopUi();
1759 mNotificationShadeWindowController.setForceHasTopUi(true);
Steve Elliott9b87a442019-03-05 10:24:16 -05001760 mBackgroundDrawable.setAlpha(0);
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001761 mGlobalActionsLayout.setTranslationX(mGlobalActionsLayout.getAnimationOffsetX());
1762 mGlobalActionsLayout.setTranslationY(mGlobalActionsLayout.getAnimationOffsetY());
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001763 mGlobalActionsLayout.setAlpha(0);
1764 mGlobalActionsLayout.animate()
Jason Monk16fbd9d2017-04-27 14:28:49 -04001765 .alpha(1)
1766 .translationX(0)
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001767 .translationY(0)
Jason Monk16fbd9d2017-04-27 14:28:49 -04001768 .setDuration(300)
Lucas Dupinde9db422017-07-19 17:15:41 -07001769 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001770 .setUpdateListener(animation -> {
Lucas Dupin991415e2019-11-25 17:48:58 -08001771 float animatedValue = animation.getAnimatedFraction();
1772 int alpha = (int) (animatedValue * mScrimAlpha * 255);
Steve Elliott9b87a442019-03-05 10:24:16 -05001773 mBackgroundDrawable.setAlpha(alpha);
Lucas Dupin991415e2019-11-25 17:48:58 -08001774 mBlurUtils.applyBlur(mGlobalActionsLayout.getViewRootImpl(),
1775 mBlurUtils.radiusForRatio(animatedValue));
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001776 })
Jason Monk16fbd9d2017-04-27 14:28:49 -04001777 .start();
Matt Pietal22231792020-01-23 09:51:09 -05001778 if (mControlsUiController != null) {
1779 mControlsUiController.show(mControlsView);
1780 }
Jason Monk16fbd9d2017-04-27 14:28:49 -04001781 }
1782
1783 @Override
1784 public void dismiss() {
Beverly526d2d62018-08-15 12:55:33 -04001785 if (!mShowing) {
1786 return;
1787 }
1788 mShowing = false;
Matt Pietal22231792020-01-23 09:51:09 -05001789 if (mControlsUiController != null) mControlsUiController.hide();
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001790 mGlobalActionsLayout.setTranslationX(0);
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001791 mGlobalActionsLayout.setTranslationY(0);
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001792 mGlobalActionsLayout.setAlpha(1);
1793 mGlobalActionsLayout.animate()
Jason Monk16fbd9d2017-04-27 14:28:49 -04001794 .alpha(0)
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001795 .translationX(mGlobalActionsLayout.getAnimationOffsetX())
1796 .translationY(mGlobalActionsLayout.getAnimationOffsetY())
Jason Monk16fbd9d2017-04-27 14:28:49 -04001797 .setDuration(300)
Steve Elliottff2c0d92019-07-30 15:09:54 -04001798 .withEndAction(this::completeDismiss)
Jason Monk16fbd9d2017-04-27 14:28:49 -04001799 .setInterpolator(new LogAccelerateInterpolator())
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001800 .setUpdateListener(animation -> {
Lucas Dupin991415e2019-11-25 17:48:58 -08001801 float animatedValue = 1f - animation.getAnimatedFraction();
1802 int alpha = (int) (animatedValue * mScrimAlpha * 255);
Steve Elliott9b87a442019-03-05 10:24:16 -05001803 mBackgroundDrawable.setAlpha(alpha);
Lucas Dupin991415e2019-11-25 17:48:58 -08001804 mBlurUtils.applyBlur(mGlobalActionsLayout.getViewRootImpl(),
1805 mBlurUtils.radiusForRatio(animatedValue));
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001806 })
Jason Monk16fbd9d2017-04-27 14:28:49 -04001807 .start();
Steve Elliott48f75db2019-05-03 15:03:38 -04001808 dismissPanel();
1809 resetOrientation();
Jason Monk16fbd9d2017-04-27 14:28:49 -04001810 }
1811
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001812 void dismissImmediately() {
Beverly526d2d62018-08-15 12:55:33 -04001813 mShowing = false;
Matt Pietal019feaa2020-01-31 14:51:37 -05001814 if (mControlsUiController != null) mControlsUiController.hide();
Steve Elliott48f75db2019-05-03 15:03:38 -04001815 dismissPanel();
1816 resetOrientation();
Steve Elliottff2c0d92019-07-30 15:09:54 -04001817 completeDismiss();
1818 }
1819
1820 private void completeDismiss() {
wilsonshihe8321942019-10-18 18:39:46 +08001821 mNotificationShadeWindowController.setForceHasTopUi(mHadTopUi);
Steve Elliottff2c0d92019-07-30 15:09:54 -04001822 super.dismiss();
Steve Elliott48f75db2019-05-03 15:03:38 -04001823 }
1824
1825 private void dismissPanel() {
Steve Elliott2d206d32019-03-14 16:30:33 -04001826 if (mPanelController != null) {
1827 mPanelController.onDismissed();
1828 }
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001829 }
1830
Steve Elliott53f12ae2019-05-13 17:14:15 -04001831 private void setRotationSuggestionsEnabled(boolean enabled) {
1832 try {
1833 final int userId = Binder.getCallingUserHandle().getIdentifier();
1834 final int what = enabled
1835 ? StatusBarManager.DISABLE2_NONE
1836 : StatusBarManager.DISABLE2_ROTATE_SUGGESTIONS;
1837 mStatusBarService.disable2ForUser(what, mToken, mContext.getPackageName(), userId);
1838 } catch (RemoteException ex) {
1839 throw ex.rethrowFromSystemServer();
1840 }
1841 }
1842
Steve Elliott48f75db2019-05-03 15:03:38 -04001843 private void resetOrientation() {
1844 if (mResetOrientationData != null) {
1845 RotationPolicy.setRotationLockAtAngle(mContext, mResetOrientationData.locked,
1846 mResetOrientationData.rotation);
1847 }
Steve Elliott53f12ae2019-05-13 17:14:15 -04001848 setRotationSuggestionsEnabled(true);
Steve Elliott48f75db2019-05-03 15:03:38 -04001849 }
1850
Jason Monk361915c2017-03-21 20:33:59 -04001851 @Override
Lucas Dupin7aaa3532017-05-28 08:51:07 -07001852 public void onColorsChanged(ColorExtractor extractor, int which) {
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001853 if (mKeyguardShowing) {
1854 if ((WallpaperManager.FLAG_LOCK & which) != 0) {
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001855 updateColors(extractor.getColors(WallpaperManager.FLAG_LOCK),
1856 true /* animate */);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001857 }
1858 } else {
1859 if ((WallpaperManager.FLAG_SYSTEM & which) != 0) {
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001860 updateColors(extractor.getColors(WallpaperManager.FLAG_SYSTEM),
1861 true /* animate */);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001862 }
1863 }
1864 }
1865
1866 public void setKeyguardShowing(boolean keyguardShowing) {
1867 mKeyguardShowing = keyguardShowing;
1868 }
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001869
Aaron Heuckroth4ef3a542019-04-01 14:17:23 -04001870 public void refreshDialog() {
1871 initializeLayout();
1872 mGlobalActionsLayout.updateList();
1873 }
1874
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001875 public void onRotate(int from, int to) {
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001876 if (mShowing) {
Aaron Heuckroth4ef3a542019-04-01 14:17:23 -04001877 refreshDialog();
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001878 }
1879 }
Steve Elliott48f75db2019-05-03 15:03:38 -04001880
1881 private static class ResetOrientationData {
1882 public boolean locked;
1883 public int rotation;
1884 }
Jason Monk361915c2017-03-21 20:33:59 -04001885 }
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001886
1887 /**
Aran Ink93dd25c2019-05-09 14:42:14 -04001888 * Determines whether or not debug mode has been activated for the Global Actions Panel.
1889 */
1890 private static boolean isPanelDebugModeEnabled(Context context) {
1891 return Settings.Secure.getInt(context.getContentResolver(),
1892 Settings.Secure.GLOBAL_ACTIONS_PANEL_DEBUG_ENABLED, 0) == 1;
1893 }
1894
1895 /**
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001896 * Determines whether or not the Global Actions menu should be forced to
1897 * use the newer grid-style layout.
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001898 */
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001899 private static boolean isForceGridEnabled(Context context) {
Aran Ink93dd25c2019-05-09 14:42:14 -04001900 return isPanelDebugModeEnabled(context);
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001901 }
Aaron Heuckrothf19d2722019-03-11 17:06:02 -04001902
Aaron Heuckrothf19d2722019-03-11 17:06:02 -04001903
1904 /**
1905 * Determines whether the Global Actions menu should use a separated view for emergency actions.
1906 */
1907 private static boolean shouldUseSeparatedView() {
1908 return true;
1909 }
Matt Pietalfd3b6cb2020-01-08 09:43:54 -05001910
Matt Pietale0661b62020-01-29 14:35:31 -05001911 private boolean shouldShowControls() {
Fabian Kozynski8b540452020-02-04 15:16:30 -05001912 return !mKeyguardManager.isDeviceLocked()
1913 && mControlsUiController.getAvailable();
Matt Pietalfd3b6cb2020-01-08 09:43:54 -05001914 }
Jason Monk361915c2017-03-21 20:33:59 -04001915}