blob: 92f7e1f953f1865e9d201d1954d6f397c88405b0 [file] [log] [blame]
Jason Monk361915c2017-03-21 20:33:59 -04001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 * except in compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the
10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11 * KIND, either express or implied. See the License for the specific language governing
12 * permissions and limitations under the License.
13 */
14
15package com.android.systemui.globalactions;
16
Adrian Roosedfab3b2018-03-08 18:39:20 +010017import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
Adrian Roos2f05bb32018-02-19 16:42:27 +010018import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
19
Chad Brubakerf4075fe2018-01-03 13:23:22 -080020import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_USER_REQUEST;
21import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_NOT_REQUIRED;
Chad Brubaker4f28f0d2017-09-07 14:28:13 -070022import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN;
23
Dave Mankoffc88a2d72020-01-10 15:59:31 -050024import android.annotation.Nullable;
Jason Monk361915c2017-03-21 20:33:59 -040025import android.app.ActivityManager;
26import android.app.Dialog;
Dave Mankoffc88a2d72020-01-10 15:59:31 -050027import android.app.IActivityManager;
Chad Brubakerf4075fe2018-01-03 13:23:22 -080028import android.app.KeyguardManager;
Steve Elliott4c868852019-03-14 16:25:41 -040029import android.app.PendingIntent;
Steve Elliott53f12ae2019-05-13 17:14:15 -040030import android.app.StatusBarManager;
Lucas Dupinc1cc7592017-05-22 15:56:16 -070031import android.app.WallpaperManager;
Alex Chau04458852017-11-27 18:21:23 +000032import android.app.admin.DevicePolicyManager;
Pavel Grafov059021b2018-05-02 13:44:46 +010033import android.app.trust.TrustManager;
Jason Monk361915c2017-03-21 20:33:59 -040034import android.content.BroadcastReceiver;
Dave Mankoffc88a2d72020-01-10 15:59:31 -050035import android.content.ContentResolver;
Jason Monk361915c2017-03-21 20:33:59 -040036import android.content.Context;
37import android.content.DialogInterface;
38import android.content.Intent;
39import android.content.IntentFilter;
40import android.content.pm.UserInfo;
Dave Mankoffc88a2d72020-01-10 15:59:31 -050041import android.content.res.Resources;
Jason Monk361915c2017-03-21 20:33:59 -040042import android.database.ContentObserver;
Matt Pietale0661b62020-01-29 14:35:31 -050043import android.graphics.Color;
Jason Monk361915c2017-03-21 20:33:59 -040044import android.graphics.drawable.Drawable;
45import android.media.AudioManager;
46import android.net.ConnectivityManager;
Steve Elliott53f12ae2019-05-13 17:14:15 -040047import android.os.Binder;
Jason Monk361915c2017-03-21 20:33:59 -040048import android.os.Handler;
Steve Elliott53f12ae2019-05-13 17:14:15 -040049import android.os.IBinder;
Jason Monk361915c2017-03-21 20:33:59 -040050import android.os.Message;
51import android.os.RemoteException;
Jason Monk361915c2017-03-21 20:33:59 -040052import android.os.SystemProperties;
53import android.os.UserHandle;
54import android.os.UserManager;
55import android.os.Vibrator;
56import android.provider.Settings;
Jason Monk361915c2017-03-21 20:33:59 -040057import android.service.dreams.IDreamManager;
Inseob Kim5e82f732019-11-08 15:08:38 +090058import android.sysprop.TelephonyProperties;
Fan Zhangf9914762019-11-01 15:58:38 -070059import android.telecom.TelecomManager;
Jason Monk361915c2017-03-21 20:33:59 -040060import android.telephony.PhoneStateListener;
61import android.telephony.ServiceState;
62import android.telephony.TelephonyManager;
Jason Monk361915c2017-03-21 20:33:59 -040063import android.util.ArraySet;
yuanjiahsu88363e92018-09-06 19:23:52 +080064import android.util.FeatureFlagUtils;
Jason Monk361915c2017-03-21 20:33:59 -040065import android.util.Log;
Lucas Dupin448786c2017-07-24 17:44:25 -070066import android.view.ContextThemeWrapper;
Jason Monk361915c2017-03-21 20:33:59 -040067import android.view.LayoutInflater;
68import android.view.View;
69import android.view.ViewGroup;
Lucas Dupinc1cc7592017-05-22 15:56:16 -070070import android.view.Window;
Jason Monk361915c2017-03-21 20:33:59 -040071import android.view.WindowManager;
72import android.view.WindowManagerGlobal;
73import android.view.accessibility.AccessibilityEvent;
Steve Elliott9b87a442019-03-05 10:24:16 -050074import android.widget.FrameLayout;
Jason Monk361915c2017-03-21 20:33:59 -040075import android.widget.ImageView;
76import android.widget.ImageView.ScaleType;
Jason Monk361915c2017-03-21 20:33:59 -040077import android.widget.TextView;
78
Charles He9851a8d2017-10-10 17:31:30 +010079import com.android.internal.R;
80import com.android.internal.colorextraction.ColorExtractor;
81import com.android.internal.colorextraction.ColorExtractor.GradientColors;
Lucas Dupin2bd3af62019-03-25 17:44:28 -070082import com.android.internal.colorextraction.drawable.ScrimDrawable;
Charles He9851a8d2017-10-10 17:31:30 +010083import com.android.internal.logging.MetricsLogger;
84import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Steve Elliott53f12ae2019-05-13 17:14:15 -040085import com.android.internal.statusbar.IStatusBarService;
Charles He9851a8d2017-10-10 17:31:30 +010086import com.android.internal.util.EmergencyAffordanceManager;
Beth Thibodeau5898ac42018-10-26 13:00:09 -040087import com.android.internal.util.ScreenRecordHelper;
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -050088import com.android.internal.util.ScreenshotHelper;
Steve Elliott48f75db2019-05-03 15:03:38 -040089import com.android.internal.view.RotationPolicy;
Charles He9851a8d2017-10-10 17:31:30 +010090import com.android.internal.widget.LockPatternUtils;
91import com.android.systemui.Dependency;
Charles He9851a8d2017-10-10 17:31:30 +010092import com.android.systemui.Interpolators;
Aaron Heuckrothf708d472019-01-10 16:54:51 -050093import com.android.systemui.MultiListLayout;
Aaron Heuckroth57d60d22019-03-05 14:00:12 -050094import com.android.systemui.MultiListLayout.MultiListAdapter;
Fabian Kozynskiff5e91f2019-09-24 15:38:08 -040095import com.android.systemui.broadcast.BroadcastDispatcher;
Charles He9851a8d2017-10-10 17:31:30 +010096import com.android.systemui.colorextraction.SysuiColorExtractor;
Matt Pietal22231792020-01-23 09:51:09 -050097import com.android.systemui.controls.ui.ControlsUiController;
Dave Mankoffc88a2d72020-01-10 15:59:31 -050098import com.android.systemui.dagger.qualifiers.Main;
Steve Elliott4c868852019-03-14 16:25:41 -040099import com.android.systemui.plugins.ActivityStarter;
Charles He9851a8d2017-10-10 17:31:30 +0100100import com.android.systemui.plugins.GlobalActions.GlobalActionsManager;
Steve Elliott9b87a442019-03-05 10:24:16 -0500101import com.android.systemui.plugins.GlobalActionsPanelPlugin;
Lucas Dupin991415e2019-11-25 17:48:58 -0800102import com.android.systemui.statusbar.BlurUtils;
Matt Pietal22231792020-01-23 09:51:09 -0500103import com.android.systemui.statusbar.phone.NotificationShadeWindowController;
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700104import com.android.systemui.statusbar.policy.ConfigurationController;
Lucas Dupinc8f16e82019-09-17 18:24:50 -0400105import com.android.systemui.statusbar.policy.KeyguardStateController;
Shaotang Li5c422632018-07-04 14:18:40 +0800106import com.android.systemui.util.EmergencyDialerConstants;
Aaron Heuckroth75e249f2019-02-01 15:59:57 -0500107import com.android.systemui.util.leak.RotationUtils;
Julia Reynolds42411922017-11-08 11:19:09 -0500108import com.android.systemui.volume.SystemUIInterpolators.LogAccelerateInterpolator;
Lucas Dupinc1cc7592017-05-22 15:56:16 -0700109
Jason Monk361915c2017-03-21 20:33:59 -0400110import java.util.ArrayList;
111import java.util.List;
112
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500113import javax.inject.Inject;
114
Jason Monk361915c2017-03-21 20:33:59 -0400115/**
116 * Helper to show the global actions dialog. Each item is an {@link Action} that
117 * may show depending on whether the keyguard is showing, and whether the device
118 * is provisioned.
119 */
Aaron Heuckroth57d60d22019-03-05 14:00:12 -0500120public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
121 DialogInterface.OnShowListener, ConfigurationController.ConfigurationListener {
Jason Monk361915c2017-03-21 20:33:59 -0400122
123 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
124 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
Lucas Dupin1d4a5792018-04-02 15:14:59 -0700125 static public final String SYSTEM_DIALOG_REASON_DREAM = "dream";
Jason Monk361915c2017-03-21 20:33:59 -0400126
127 private static final String TAG = "GlobalActionsDialog";
128
129 private static final boolean SHOW_SILENT_TOGGLE = true;
130
131 /* Valid settings for global actions keys.
132 * see config.xml config_globalActionList */
133 private static final String GLOBAL_ACTION_KEY_POWER = "power";
134 private static final String GLOBAL_ACTION_KEY_AIRPLANE = "airplane";
135 private static final String GLOBAL_ACTION_KEY_BUGREPORT = "bugreport";
136 private static final String GLOBAL_ACTION_KEY_SILENT = "silent";
137 private static final String GLOBAL_ACTION_KEY_USERS = "users";
138 private static final String GLOBAL_ACTION_KEY_SETTINGS = "settings";
139 private static final String GLOBAL_ACTION_KEY_LOCKDOWN = "lockdown";
140 private static final String GLOBAL_ACTION_KEY_VOICEASSIST = "voiceassist";
141 private static final String GLOBAL_ACTION_KEY_ASSIST = "assist";
142 private static final String GLOBAL_ACTION_KEY_RESTART = "restart";
Alex Chau04458852017-11-27 18:21:23 +0000143 private static final String GLOBAL_ACTION_KEY_LOGOUT = "logout";
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800144 private static final String GLOBAL_ACTION_KEY_EMERGENCY = "emergency";
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500145 private static final String GLOBAL_ACTION_KEY_SCREENSHOT = "screenshot";
Jason Monk361915c2017-03-21 20:33:59 -0400146
147 private final Context mContext;
148 private final GlobalActionsManager mWindowManagerFuncs;
149 private final AudioManager mAudioManager;
150 private final IDreamManager mDreamManager;
Alex Chau04458852017-11-27 18:21:23 +0000151 private final DevicePolicyManager mDevicePolicyManager;
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800152 private final LockPatternUtils mLockPatternUtils;
153 private final KeyguardManager mKeyguardManager;
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000154 private final BroadcastDispatcher mBroadcastDispatcher;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500155 private final ContentResolver mContentResolver;
156 private final Resources mResources;
157 private final UserManager mUserManager;
158 private final TrustManager mTrustManager;
159 private final IActivityManager mIActivityManager;
160 private final TelecomManager mTelecomManager;
161 private final MetricsLogger mMetricsLogger;
Lucas Dupin991415e2019-11-25 17:48:58 -0800162 private final BlurUtils mBlurUtils;
Jason Monk361915c2017-03-21 20:33:59 -0400163
164 private ArrayList<Action> mItems;
165 private ActionsDialog mDialog;
166
167 private Action mSilentModeAction;
168 private ToggleAction mAirplaneModeOn;
169
170 private MyAdapter mAdapter;
171
172 private boolean mKeyguardShowing = false;
173 private boolean mDeviceProvisioned = false;
174 private ToggleAction.State mAirplaneState = ToggleAction.State.Off;
175 private boolean mIsWaitingForEcmExit = false;
176 private boolean mHasTelephony;
177 private boolean mHasVibrator;
178 private final boolean mShowSilentToggle;
179 private final EmergencyAffordanceManager mEmergencyAffordanceManager;
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500180 private final ScreenshotHelper mScreenshotHelper;
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400181 private final ScreenRecordHelper mScreenRecordHelper;
Steve Elliotta3f5207922019-03-18 13:37:22 -0400182 private final ActivityStarter mActivityStarter;
Lucas Dupin991415e2019-11-25 17:48:58 -0800183 private final SysuiColorExtractor mSysuiColorExtractor;
184 private final IStatusBarService mStatusBarService;
185 private final NotificationShadeWindowController mNotificationShadeWindowController;
Steve Elliotta3f5207922019-03-18 13:37:22 -0400186 private GlobalActionsPanelPlugin mPanelPlugin;
Matt Pietal22231792020-01-23 09:51:09 -0500187 private ControlsUiController mControlsUiController;
Steve Elliott9b87a442019-03-05 10:24:16 -0500188
Jason Monk361915c2017-03-21 20:33:59 -0400189 /**
190 * @param context everything needs a context :(
191 */
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500192 @Inject
193 public GlobalActionsDialog(Context context, GlobalActionsManager windowManagerFuncs,
194 AudioManager audioManager, IDreamManager iDreamManager,
195 DevicePolicyManager devicePolicyManager, LockPatternUtils lockPatternUtils,
196 KeyguardManager keyguardManager, BroadcastDispatcher broadcastDispatcher,
197 ConnectivityManager connectivityManager, TelephonyManager telephonyManager,
198 ContentResolver contentResolver, @Nullable Vibrator vibrator, @Main Resources resources,
199 ConfigurationController configurationController, ActivityStarter activityStarter,
200 KeyguardStateController keyguardStateController, UserManager userManager,
201 TrustManager trustManager, IActivityManager iActivityManager,
Lucas Dupin991415e2019-11-25 17:48:58 -0800202 TelecomManager telecomManager, MetricsLogger metricsLogger,
203 BlurUtils blurUtils, SysuiColorExtractor colorExtractor,
204 IStatusBarService statusBarService,
Matt Pietal22231792020-01-23 09:51:09 -0500205 NotificationShadeWindowController notificationShadeWindowController,
206 ControlsUiController controlsUiController) {
Lucas Dupin448786c2017-07-24 17:44:25 -0700207 mContext = new ContextThemeWrapper(context, com.android.systemui.R.style.qs_theme);
Jason Monk361915c2017-03-21 20:33:59 -0400208 mWindowManagerFuncs = windowManagerFuncs;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500209 mAudioManager = audioManager;
210 mDreamManager = iDreamManager;
211 mDevicePolicyManager = devicePolicyManager;
212 mLockPatternUtils = lockPatternUtils;
213 mKeyguardManager = keyguardManager;
214 mBroadcastDispatcher = broadcastDispatcher;
215 mContentResolver = contentResolver;
216 mResources = resources;
217 mUserManager = userManager;
218 mTrustManager = trustManager;
219 mIActivityManager = iActivityManager;
220 mTelecomManager = telecomManager;
221 mMetricsLogger = metricsLogger;
Lucas Dupin991415e2019-11-25 17:48:58 -0800222 mBlurUtils = blurUtils;
223 mSysuiColorExtractor = colorExtractor;
224 mStatusBarService = statusBarService;
225 mNotificationShadeWindowController = notificationShadeWindowController;
Matt Pietal22231792020-01-23 09:51:09 -0500226 mControlsUiController = controlsUiController;
Jason Monk361915c2017-03-21 20:33:59 -0400227
228 // receive broadcasts
229 IntentFilter filter = new IntentFilter();
230 filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
231 filter.addAction(Intent.ACTION_SCREEN_OFF);
Jayachandran C142eae02019-12-13 19:29:20 -0800232 filter.addAction(TelephonyManager.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000233 mBroadcastDispatcher.registerReceiver(mBroadcastReceiver, filter);
Jason Monk361915c2017-03-21 20:33:59 -0400234
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500235 mHasTelephony = connectivityManager.isNetworkSupported(ConnectivityManager.TYPE_MOBILE);
Jason Monk361915c2017-03-21 20:33:59 -0400236
237 // get notified of phone state changes
Jason Monk361915c2017-03-21 20:33:59 -0400238 telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE);
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500239 contentResolver.registerContentObserver(
Jason Monk361915c2017-03-21 20:33:59 -0400240 Settings.Global.getUriFor(Settings.Global.AIRPLANE_MODE_ON), true,
241 mAirplaneModeObserver);
Jason Monk361915c2017-03-21 20:33:59 -0400242 mHasVibrator = vibrator != null && vibrator.hasVibrator();
243
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500244 mShowSilentToggle = SHOW_SILENT_TOGGLE && !resources.getBoolean(
Jason Monk361915c2017-03-21 20:33:59 -0400245 R.bool.config_useFixedVolume);
246
247 mEmergencyAffordanceManager = new EmergencyAffordanceManager(context);
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500248 mScreenshotHelper = new ScreenshotHelper(context);
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400249 mScreenRecordHelper = new ScreenRecordHelper(context);
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700250
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500251 configurationController.addCallback(this);
Steve Elliott9b87a442019-03-05 10:24:16 -0500252
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500253 mActivityStarter = activityStarter;
Lucas Dupinc8f16e82019-09-17 18:24:50 -0400254 keyguardStateController.addCallback(new KeyguardStateController.Callback() {
255 @Override
256 public void onUnlockedChanged() {
257 if (mDialog != null && mDialog.mPanelController != null) {
258 boolean locked = !keyguardStateController.canDismissLockScreen();
259 mDialog.mPanelController.onDeviceLockStateChanged(locked);
260 }
261 }
262 });
Jason Monk361915c2017-03-21 20:33:59 -0400263 }
264
265 /**
266 * Show the global actions dialog (creating if necessary)
Jason Monk16fbd9d2017-04-27 14:28:49 -0400267 *
Jason Monk361915c2017-03-21 20:33:59 -0400268 * @param keyguardShowing True if keyguard is showing
269 */
Steve Elliotta3f5207922019-03-18 13:37:22 -0400270 public void showDialog(boolean keyguardShowing, boolean isDeviceProvisioned,
271 GlobalActionsPanelPlugin panelPlugin) {
Jason Monk361915c2017-03-21 20:33:59 -0400272 mKeyguardShowing = keyguardShowing;
273 mDeviceProvisioned = isDeviceProvisioned;
Steve Elliotta3f5207922019-03-18 13:37:22 -0400274 mPanelPlugin = panelPlugin;
Jason Monk361915c2017-03-21 20:33:59 -0400275 if (mDialog != null) {
276 mDialog.dismiss();
277 mDialog = null;
278 // Show delayed, so that the dismiss of the previous dialog completes
279 mHandler.sendEmptyMessage(MESSAGE_SHOW);
280 } else {
281 handleShow();
282 }
283 }
284
Charles He9851a8d2017-10-10 17:31:30 +0100285 /**
286 * Dismiss the global actions dialog, if it's currently shown
287 */
288 public void dismissDialog() {
289 mHandler.removeMessages(MESSAGE_DISMISS);
290 mHandler.sendEmptyMessage(MESSAGE_DISMISS);
291 }
292
Jason Monk361915c2017-03-21 20:33:59 -0400293 private void awakenIfNecessary() {
294 if (mDreamManager != null) {
295 try {
296 if (mDreamManager.isDreaming()) {
297 mDreamManager.awaken();
298 }
299 } catch (RemoteException e) {
300 // we tried
301 }
302 }
303 }
304
305 private void handleShow() {
306 awakenIfNecessary();
307 mDialog = createDialog();
308 prepareDialog();
309
310 // If we only have 1 item and it's a simple press action, just do this action.
311 if (mAdapter.getCount() == 1
312 && mAdapter.getItem(0) instanceof SinglePressAction
313 && !(mAdapter.getItem(0) instanceof LongPressAction)) {
314 ((SinglePressAction) mAdapter.getItem(0)).onPress();
315 } else {
316 WindowManager.LayoutParams attrs = mDialog.getWindow().getAttributes();
317 attrs.setTitle("ActionsDialog");
Adrian Roos2f05bb32018-02-19 16:42:27 +0100318 attrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
Jason Monk361915c2017-03-21 20:33:59 -0400319 mDialog.getWindow().setAttributes(attrs);
320 mDialog.show();
321 mWindowManagerFuncs.onGlobalActionsShown();
Jason Monk361915c2017-03-21 20:33:59 -0400322 }
323 }
324
325 /**
326 * Create the global actions dialog.
Jason Monk16fbd9d2017-04-27 14:28:49 -0400327 *
Jason Monk361915c2017-03-21 20:33:59 -0400328 * @return A new dialog.
329 */
330 private ActionsDialog createDialog() {
331 // Simple toggle style if there's no vibrator, otherwise use a tri-state
332 if (!mHasVibrator) {
333 mSilentModeAction = new SilentModeToggleAction();
334 } else {
Lucas Dupin40ec6b782018-06-05 19:07:16 -0700335 mSilentModeAction = new SilentModeTriStateAction(mAudioManager, mHandler);
Jason Monk361915c2017-03-21 20:33:59 -0400336 }
337 mAirplaneModeOn = new ToggleAction(
338 R.drawable.ic_lock_airplane_mode,
339 R.drawable.ic_lock_airplane_mode_off,
340 R.string.global_actions_toggle_airplane_mode,
341 R.string.global_actions_airplane_mode_on_status,
342 R.string.global_actions_airplane_mode_off_status) {
343
344 void onToggle(boolean on) {
Inseob Kim5e82f732019-11-08 15:08:38 +0900345 if (mHasTelephony && TelephonyProperties.in_ecm_mode().orElse(false)) {
Jason Monk361915c2017-03-21 20:33:59 -0400346 mIsWaitingForEcmExit = true;
347 // Launch ECM exit dialog
348 Intent ecmDialogIntent =
Jayachandran C142eae02019-12-13 19:29:20 -0800349 new Intent(TelephonyManager.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null);
Jason Monk361915c2017-03-21 20:33:59 -0400350 ecmDialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
351 mContext.startActivity(ecmDialogIntent);
352 } else {
353 changeAirplaneModeSystemSetting(on);
354 }
355 }
356
357 @Override
358 protected void changeStateFromPress(boolean buttonOn) {
359 if (!mHasTelephony) return;
360
361 // In ECM mode airplane state cannot be changed
Inseob Kim5e82f732019-11-08 15:08:38 +0900362 if (!TelephonyProperties.in_ecm_mode().orElse(false)) {
Jason Monk361915c2017-03-21 20:33:59 -0400363 mState = buttonOn ? State.TurningOn : State.TurningOff;
364 mAirplaneState = mState;
365 }
366 }
367
368 public boolean showDuringKeyguard() {
369 return true;
370 }
371
372 public boolean showBeforeProvisioning() {
373 return false;
374 }
375 };
376 onAirplaneModeChanged();
377
378 mItems = new ArrayList<Action>();
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500379 String[] defaultActions = mResources.getStringArray(R.array.config_globalActionsList);
Jason Monk361915c2017-03-21 20:33:59 -0400380
381 ArraySet<String> addedKeys = new ArraySet<String>();
382 for (int i = 0; i < defaultActions.length; i++) {
383 String actionKey = defaultActions[i];
384 if (addedKeys.contains(actionKey)) {
385 // If we already have added this, don't add it again.
386 continue;
387 }
388 if (GLOBAL_ACTION_KEY_POWER.equals(actionKey)) {
389 mItems.add(new PowerAction());
390 } else if (GLOBAL_ACTION_KEY_AIRPLANE.equals(actionKey)) {
391 mItems.add(mAirplaneModeOn);
392 } else if (GLOBAL_ACTION_KEY_BUGREPORT.equals(actionKey)) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500393 if (Settings.Global.getInt(mContentResolver,
Jason Monk361915c2017-03-21 20:33:59 -0400394 Settings.Global.BUGREPORT_IN_POWER_MENU, 0) != 0 && isCurrentUserOwner()) {
395 mItems.add(new BugReportAction());
396 }
397 } else if (GLOBAL_ACTION_KEY_SILENT.equals(actionKey)) {
398 if (mShowSilentToggle) {
399 mItems.add(mSilentModeAction);
400 }
401 } else if (GLOBAL_ACTION_KEY_USERS.equals(actionKey)) {
402 if (SystemProperties.getBoolean("fw.power_user_switcher", false)) {
403 addUsersToMenu(mItems);
404 }
405 } else if (GLOBAL_ACTION_KEY_SETTINGS.equals(actionKey)) {
406 mItems.add(getSettingsAction());
407 } else if (GLOBAL_ACTION_KEY_LOCKDOWN.equals(actionKey)) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500408 if (Settings.Secure.getIntForUser(mContentResolver,
Chad Brubaker02cd6cf2018-05-01 14:59:33 -0700409 Settings.Secure.LOCKDOWN_IN_POWER_MENU, 0, getCurrentUser().id) != 0
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800410 && shouldDisplayLockdown()) {
Chad Brubaker4f28f0d2017-09-07 14:28:13 -0700411 mItems.add(getLockdownAction());
412 }
Jason Monk361915c2017-03-21 20:33:59 -0400413 } else if (GLOBAL_ACTION_KEY_VOICEASSIST.equals(actionKey)) {
414 mItems.add(getVoiceAssistAction());
415 } else if (GLOBAL_ACTION_KEY_ASSIST.equals(actionKey)) {
416 mItems.add(getAssistAction());
417 } else if (GLOBAL_ACTION_KEY_RESTART.equals(actionKey)) {
418 mItems.add(new RestartAction());
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500419 } else if (GLOBAL_ACTION_KEY_SCREENSHOT.equals(actionKey)) {
420 mItems.add(new ScreenshotAction());
Alex Chau04458852017-11-27 18:21:23 +0000421 } else if (GLOBAL_ACTION_KEY_LOGOUT.equals(actionKey)) {
Alex Chaud7958272017-12-08 11:30:52 +0000422 if (mDevicePolicyManager.isLogoutEnabled()
Alex Chau04458852017-11-27 18:21:23 +0000423 && getCurrentUser().id != UserHandle.USER_SYSTEM) {
424 mItems.add(new LogoutAction());
Alex Chau04458852017-11-27 18:21:23 +0000425 }
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800426 } else if (GLOBAL_ACTION_KEY_EMERGENCY.equals(actionKey)) {
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400427 if (!mEmergencyAffordanceManager.needsEmergencyAffordance()) {
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800428 mItems.add(new EmergencyDialerAction());
429 }
Jason Monk361915c2017-03-21 20:33:59 -0400430 } else {
431 Log.e(TAG, "Invalid global action key " + actionKey);
432 }
433 // Add here so we don't add more than one.
434 addedKeys.add(actionKey);
435 }
436
437 if (mEmergencyAffordanceManager.needsEmergencyAffordance()) {
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400438 mItems.add(new EmergencyAffordanceAction());
Jason Monk361915c2017-03-21 20:33:59 -0400439 }
440
441 mAdapter = new MyAdapter();
442
Steve Elliott9b87a442019-03-05 10:24:16 -0500443 GlobalActionsPanelPlugin.PanelViewController panelViewController =
Steve Elliotta3f5207922019-03-18 13:37:22 -0400444 mPanelPlugin != null
445 ? mPanelPlugin.onPanelShown(
Steve Elliott4c868852019-03-14 16:25:41 -0400446 new GlobalActionsPanelPlugin.Callbacks() {
447 @Override
448 public void dismissGlobalActionsMenu() {
Steve Elliottc3147e22019-11-20 19:34:57 -0500449 dismissDialog();
Steve Elliott4c868852019-03-14 16:25:41 -0400450 }
451
452 @Override
453 public void startPendingIntentDismissingKeyguard(
454 PendingIntent intent) {
455 mActivityStarter
456 .startPendingIntentDismissingKeyguard(intent);
457 }
Steve Elliotte2a2e9b2019-04-30 21:31:03 -0400458 },
459 mKeyguardManager.isDeviceLocked())
Steve Elliott9b87a442019-03-05 10:24:16 -0500460 : null;
Steve Elliott02bbaaa2019-05-01 16:55:33 -0400461
Lucas Dupin991415e2019-11-25 17:48:58 -0800462 ActionsDialog dialog = new ActionsDialog(mContext, mAdapter, panelViewController,
463 mBlurUtils, mSysuiColorExtractor, mStatusBarService,
Matt Pietal22231792020-01-23 09:51:09 -0500464 mNotificationShadeWindowController,
Matt Pietale0661b62020-01-29 14:35:31 -0500465 shouldShowControls() ? mControlsUiController : null);
Jason Monk361915c2017-03-21 20:33:59 -0400466 dialog.setCanceledOnTouchOutside(false); // Handled by the custom class.
Lucas Dupinc1cc7592017-05-22 15:56:16 -0700467 dialog.setKeyguardShowing(mKeyguardShowing);
Jason Monk361915c2017-03-21 20:33:59 -0400468
469 dialog.setOnDismissListener(this);
Shaotang Li786da902018-08-02 11:18:00 +0800470 dialog.setOnShowListener(this);
Jason Monk361915c2017-03-21 20:33:59 -0400471
472 return dialog;
473 }
474
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800475 private boolean shouldDisplayLockdown() {
476 int userId = getCurrentUser().id;
477 // Lockdown is meaningless without a place to go.
478 if (!mKeyguardManager.isDeviceSecure(userId)) {
479 return false;
480 }
481
482 // Only show the lockdown button if the device isn't locked down (for whatever reason).
483 int state = mLockPatternUtils.getStrongAuthForUser(userId);
484 return (state == STRONG_AUTH_NOT_REQUIRED
485 || state == SOME_AUTH_REQUIRED_AFTER_USER_REQUEST);
486 }
487
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700488 @Override
489 public void onUiModeChanged() {
490 mContext.getTheme().applyStyle(mContext.getThemeResId(), true);
Lucas Dupina4e12ba2019-04-18 11:56:28 -0700491 if (mDialog != null && mDialog.isShowing()) {
Aaron Heuckroth4ef3a542019-04-01 14:17:23 -0400492 mDialog.refreshDialog();
493 }
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700494 }
495
496 public void destroy() {
497 Dependency.get(ConfigurationController.class).removeCallback(this);
498 }
499
Jason Monk361915c2017-03-21 20:33:59 -0400500 private final class PowerAction extends SinglePressAction implements LongPressAction {
501 private PowerAction() {
502 super(R.drawable.ic_lock_power_off,
Jason Monk16fbd9d2017-04-27 14:28:49 -0400503 R.string.global_action_power_off);
Jason Monk361915c2017-03-21 20:33:59 -0400504 }
505
506 @Override
507 public boolean onLongPress() {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500508 if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) {
Jason Monk361915c2017-03-21 20:33:59 -0400509 mWindowManagerFuncs.reboot(true);
510 return true;
511 }
512 return false;
513 }
514
515 @Override
516 public boolean showDuringKeyguard() {
517 return true;
518 }
519
520 @Override
521 public boolean showBeforeProvisioning() {
522 return true;
523 }
524
525 @Override
526 public void onPress() {
527 // shutdown by making sure radio and power are handled accordingly.
528 mWindowManagerFuncs.shutdown();
529 }
530 }
531
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400532 private abstract class EmergencyAction extends SinglePressAction {
533 EmergencyAction(int iconResId, int messageResId) {
534 super(iconResId, messageResId);
535 }
536
537 @Override
538 public boolean shouldBeSeparated() {
Matt Pietale0661b62020-01-29 14:35:31 -0500539 return !shouldShowControls();
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400540 }
541
542 @Override
543 public View create(
544 Context context, View convertView, ViewGroup parent, LayoutInflater inflater) {
545 View v = super.create(context, convertView, parent, inflater);
546 int textColor;
547 if (shouldBeSeparated()) {
548 textColor = v.getResources().getColor(
549 com.android.systemui.R.color.global_actions_alert_text);
550 } else {
551 textColor = v.getResources().getColor(
552 com.android.systemui.R.color.global_actions_text);
553 }
554 TextView messageView = v.findViewById(R.id.message);
555 messageView.setTextColor(textColor);
Aaron Heuckroth3f2d8b52019-04-05 13:27:51 -0400556 messageView.setSelected(true); // necessary for marquee to work
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400557 ImageView icon = (ImageView) v.findViewById(R.id.icon);
558 icon.getDrawable().setTint(textColor);
559 return v;
560 }
561
562 @Override
563 public boolean showDuringKeyguard() {
564 return true;
565 }
566
567 @Override
568 public boolean showBeforeProvisioning() {
569 return true;
570 }
571 }
572
573 private class EmergencyAffordanceAction extends EmergencyAction {
574 EmergencyAffordanceAction() {
575 super(R.drawable.emergency_icon,
576 R.string.global_action_emergency);
577 }
578
579 @Override
580 public void onPress() {
581 mEmergencyAffordanceManager.performEmergencyCall();
582 }
583 }
584
585 private class EmergencyDialerAction extends EmergencyAction {
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800586 private EmergencyDialerAction() {
Aran Ink50195262019-05-30 10:55:37 -0400587 super(com.android.systemui.R.drawable.ic_emergency_star,
Wesley.CW Wang3004fcb2018-06-15 16:24:57 +0800588 R.string.global_action_emergency);
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800589 }
590
591 @Override
592 public void onPress() {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500593 mMetricsLogger.action(MetricsEvent.ACTION_EMERGENCY_DIALER_FROM_POWER_MENU);
594 Intent intent = mTelecomManager.createLaunchEmergencyDialerIntent(null /* number */);
Leo Hsue4cc3122019-03-06 15:25:28 +0800595 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
596 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
597 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
Shaotang Li5c422632018-07-04 14:18:40 +0800598 intent.putExtra(EmergencyDialerConstants.EXTRA_ENTRY_TYPE,
599 EmergencyDialerConstants.ENTRY_TYPE_POWER_MENU);
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800600 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
601 }
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800602 }
603
Jason Monk361915c2017-03-21 20:33:59 -0400604 private final class RestartAction extends SinglePressAction implements LongPressAction {
605 private RestartAction() {
606 super(R.drawable.ic_restart, R.string.global_action_restart);
607 }
608
609 @Override
610 public boolean onLongPress() {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500611 if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) {
Jason Monk361915c2017-03-21 20:33:59 -0400612 mWindowManagerFuncs.reboot(true);
613 return true;
614 }
615 return false;
616 }
617
618 @Override
619 public boolean showDuringKeyguard() {
620 return true;
621 }
622
623 @Override
624 public boolean showBeforeProvisioning() {
625 return true;
626 }
627
628 @Override
629 public void onPress() {
630 mWindowManagerFuncs.reboot(false);
631 }
632 }
633
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400634 private class ScreenshotAction extends SinglePressAction implements LongPressAction {
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500635 public ScreenshotAction() {
636 super(R.drawable.ic_screenshot, R.string.global_action_screenshot);
637 }
638
639 @Override
640 public void onPress() {
641 // Add a little delay before executing, to give the
642 // dialog a chance to go away before it takes a
643 // screenshot.
644 // TODO: instead, omit global action dialog layer
645 mHandler.postDelayed(new Runnable() {
646 @Override
647 public void run() {
James O'Learyfa5bb7a2019-09-05 13:43:29 -0400648 mScreenshotHelper.takeScreenshot(1, true, true, mHandler, null);
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500649 mMetricsLogger.action(MetricsEvent.ACTION_SCREENSHOT_POWER_MENU);
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500650 }
651 }, 500);
652 }
653
654 @Override
655 public boolean showDuringKeyguard() {
656 return true;
657 }
658
659 @Override
660 public boolean showBeforeProvisioning() {
661 return false;
662 }
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400663
664 @Override
665 public boolean onLongPress() {
666 if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SCREENRECORD_LONG_PRESS)) {
667 mScreenRecordHelper.launchRecordPrompt();
668 } else {
669 onPress();
670 }
671 return true;
672 }
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500673 }
674
Jason Monk361915c2017-03-21 20:33:59 -0400675 private class BugReportAction extends SinglePressAction implements LongPressAction {
676
677 public BugReportAction() {
678 super(R.drawable.ic_lock_bugreport, R.string.bugreport_title);
679 }
680
681 @Override
682 public void onPress() {
683 // don't actually trigger the bugreport if we are running stability
684 // tests via monkey
685 if (ActivityManager.isUserAMonkey()) {
686 return;
687 }
688 // Add a little delay before executing, to give the
689 // dialog a chance to go away before it takes a
690 // screenshot.
691 mHandler.postDelayed(new Runnable() {
692 @Override
693 public void run() {
694 try {
695 // Take an "interactive" bugreport.
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500696 mMetricsLogger.action(
Jason Monk361915c2017-03-21 20:33:59 -0400697 MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_INTERACTIVE);
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500698 if (!mIActivityManager.launchBugReportHandlerApp()) {
Paul Changc40f5782019-11-04 18:55:31 +0800699 Log.w(TAG, "Bugreport handler could not be launched");
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500700 mIActivityManager.requestInteractiveBugReport();
Paul Changc40f5782019-11-04 18:55:31 +0800701 }
Jason Monk361915c2017-03-21 20:33:59 -0400702 } catch (RemoteException e) {
703 }
704 }
705 }, 500);
706 }
707
708 @Override
709 public boolean onLongPress() {
710 // don't actually trigger the bugreport if we are running stability
711 // tests via monkey
712 if (ActivityManager.isUserAMonkey()) {
713 return false;
714 }
715 try {
716 // Take a "full" bugreport.
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500717 mMetricsLogger.action(MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_FULL);
718 mIActivityManager.requestFullBugReport();
Jason Monk361915c2017-03-21 20:33:59 -0400719 } catch (RemoteException e) {
720 }
721 return false;
722 }
723
724 public boolean showDuringKeyguard() {
725 return true;
726 }
727
728 @Override
729 public boolean showBeforeProvisioning() {
730 return false;
731 }
Jason Monk361915c2017-03-21 20:33:59 -0400732 }
733
Alex Chau04458852017-11-27 18:21:23 +0000734 private final class LogoutAction extends SinglePressAction {
735 private LogoutAction() {
736 super(R.drawable.ic_logout, R.string.global_action_logout);
737 }
738
739 @Override
740 public boolean showDuringKeyguard() {
741 return true;
742 }
743
744 @Override
745 public boolean showBeforeProvisioning() {
746 return false;
747 }
748
749 @Override
750 public void onPress() {
751 // Add a little delay before executing, to give the dialog a chance to go away before
752 // switching user
753 mHandler.postDelayed(() -> {
754 try {
Alex Chauedb6a012018-01-26 12:52:43 +0000755 int currentUserId = getCurrentUser().id;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500756 mIActivityManager.switchUser(UserHandle.USER_SYSTEM);
757 mIActivityManager.stopUser(currentUserId, true /*force*/, null);
Alex Chau04458852017-11-27 18:21:23 +0000758 } catch (RemoteException re) {
759 Log.e(TAG, "Couldn't logout user " + re);
760 }
761 }, 500);
762 }
763 }
764
Jason Monk361915c2017-03-21 20:33:59 -0400765 private Action getSettingsAction() {
766 return new SinglePressAction(R.drawable.ic_settings,
767 R.string.global_action_settings) {
768
769 @Override
770 public void onPress() {
771 Intent intent = new Intent(Settings.ACTION_SETTINGS);
772 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
773 mContext.startActivity(intent);
774 }
775
776 @Override
777 public boolean showDuringKeyguard() {
778 return true;
779 }
780
781 @Override
782 public boolean showBeforeProvisioning() {
783 return true;
784 }
785 };
786 }
787
Jason Monk361915c2017-03-21 20:33:59 -0400788 private Action getAssistAction() {
789 return new SinglePressAction(R.drawable.ic_action_assist_focused,
790 R.string.global_action_assist) {
791 @Override
792 public void onPress() {
793 Intent intent = new Intent(Intent.ACTION_ASSIST);
794 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
795 mContext.startActivity(intent);
796 }
797
798 @Override
799 public boolean showDuringKeyguard() {
800 return true;
801 }
802
803 @Override
804 public boolean showBeforeProvisioning() {
805 return true;
806 }
807 };
808 }
809
810 private Action getVoiceAssistAction() {
811 return new SinglePressAction(R.drawable.ic_voice_search,
812 R.string.global_action_voice_assist) {
813 @Override
814 public void onPress() {
815 Intent intent = new Intent(Intent.ACTION_VOICE_ASSIST);
816 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
817 mContext.startActivity(intent);
818 }
819
820 @Override
821 public boolean showDuringKeyguard() {
822 return true;
823 }
824
825 @Override
826 public boolean showBeforeProvisioning() {
827 return true;
828 }
829 };
830 }
831
832 private Action getLockdownAction() {
Alison Cichowlas21125432018-05-16 15:40:45 -0400833 return new SinglePressAction(R.drawable.ic_lock_lockdown,
Jason Monk361915c2017-03-21 20:33:59 -0400834 R.string.global_action_lockdown) {
835
836 @Override
837 public void onPress() {
Chad Brubaker4f28f0d2017-09-07 14:28:13 -0700838 new LockPatternUtils(mContext)
839 .requireStrongAuth(STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN,
840 UserHandle.USER_ALL);
Jason Monk361915c2017-03-21 20:33:59 -0400841 try {
842 WindowManagerGlobal.getWindowManagerService().lockNow(null);
Pavel Grafov059021b2018-05-02 13:44:46 +0100843 // Lock profiles (if any) on the background thread.
844 final Handler bgHandler = new Handler(Dependency.get(Dependency.BG_LOOPER));
845 bgHandler.post(() -> lockProfiles());
Jason Monk361915c2017-03-21 20:33:59 -0400846 } catch (RemoteException e) {
847 Log.e(TAG, "Error while trying to lock device.", e);
848 }
849 }
850
851 @Override
852 public boolean showDuringKeyguard() {
853 return true;
854 }
855
856 @Override
857 public boolean showBeforeProvisioning() {
858 return false;
859 }
860 };
861 }
862
Pavel Grafov059021b2018-05-02 13:44:46 +0100863 private void lockProfiles() {
Pavel Grafov059021b2018-05-02 13:44:46 +0100864 final int currentUserId = getCurrentUser().id;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500865 final int[] profileIds = mUserManager.getEnabledProfileIds(currentUserId);
Pavel Grafov059021b2018-05-02 13:44:46 +0100866 for (final int id : profileIds) {
867 if (id != currentUserId) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500868 mTrustManager.setDeviceLockedForUser(id, true);
Pavel Grafov059021b2018-05-02 13:44:46 +0100869 }
870 }
871 }
872
Jason Monk361915c2017-03-21 20:33:59 -0400873 private UserInfo getCurrentUser() {
874 try {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500875 return mIActivityManager.getCurrentUser();
Jason Monk361915c2017-03-21 20:33:59 -0400876 } catch (RemoteException re) {
877 return null;
878 }
879 }
880
881 private boolean isCurrentUserOwner() {
882 UserInfo currentUser = getCurrentUser();
883 return currentUser == null || currentUser.isPrimary();
884 }
885
886 private void addUsersToMenu(ArrayList<Action> items) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500887 if (mUserManager.isUserSwitcherEnabled()) {
888 List<UserInfo> users = mUserManager.getUsers();
Jason Monk361915c2017-03-21 20:33:59 -0400889 UserInfo currentUser = getCurrentUser();
890 for (final UserInfo user : users) {
891 if (user.supportsSwitchToByUser()) {
892 boolean isCurrentUser = currentUser == null
893 ? user.id == 0 : (currentUser.id == user.id);
894 Drawable icon = user.iconPath != null ? Drawable.createFromPath(user.iconPath)
895 : null;
896 SinglePressAction switchToUser = new SinglePressAction(
897 R.drawable.ic_menu_cc, icon,
898 (user.name != null ? user.name : "Primary")
Jason Monk16fbd9d2017-04-27 14:28:49 -0400899 + (isCurrentUser ? " \u2714" : "")) {
Jason Monk361915c2017-03-21 20:33:59 -0400900 public void onPress() {
901 try {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500902 mIActivityManager.switchUser(user.id);
Jason Monk361915c2017-03-21 20:33:59 -0400903 } catch (RemoteException re) {
904 Log.e(TAG, "Couldn't switch user " + re);
905 }
906 }
907
908 public boolean showDuringKeyguard() {
909 return true;
910 }
911
912 public boolean showBeforeProvisioning() {
913 return false;
914 }
915 };
916 items.add(switchToUser);
917 }
918 }
919 }
920 }
921
922 private void prepareDialog() {
923 refreshSilentMode();
924 mAirplaneModeOn.updateState(mAirplaneState);
925 mAdapter.notifyDataSetChanged();
Jason Monk361915c2017-03-21 20:33:59 -0400926 if (mShowSilentToggle) {
927 IntentFilter filter = new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION);
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000928 mBroadcastDispatcher.registerReceiver(mRingerModeReceiver, filter);
Jason Monk361915c2017-03-21 20:33:59 -0400929 }
930 }
931
932 private void refreshSilentMode() {
933 if (!mHasVibrator) {
934 final boolean silentModeOn =
935 mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL;
Jason Monk16fbd9d2017-04-27 14:28:49 -0400936 ((ToggleAction) mSilentModeAction).updateState(
Jason Monk361915c2017-03-21 20:33:59 -0400937 silentModeOn ? ToggleAction.State.On : ToggleAction.State.Off);
938 }
939 }
940
941 /** {@inheritDoc} */
942 public void onDismiss(DialogInterface dialog) {
Steve Elliottc3147e22019-11-20 19:34:57 -0500943 if (mDialog == dialog) {
944 mDialog = null;
945 }
Jason Monk361915c2017-03-21 20:33:59 -0400946 mWindowManagerFuncs.onGlobalActionsHidden();
947 if (mShowSilentToggle) {
948 try {
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000949 mBroadcastDispatcher.unregisterReceiver(mRingerModeReceiver);
Jason Monk361915c2017-03-21 20:33:59 -0400950 } catch (IllegalArgumentException ie) {
951 // ignore this
952 Log.w(TAG, ie);
953 }
954 }
955 }
956
957 /** {@inheritDoc} */
Shaotang Li786da902018-08-02 11:18:00 +0800958 public void onShow(DialogInterface dialog) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500959 mMetricsLogger.visible(MetricsEvent.POWER_MENU);
Shaotang Li786da902018-08-02 11:18:00 +0800960 }
961
Jason Monk361915c2017-03-21 20:33:59 -0400962 /**
963 * The adapter used for the list within the global actions dialog, taking
964 * into account whether the keyguard is showing via
Jason Monk16fbd9d2017-04-27 14:28:49 -0400965 * {@link com.android.systemui.globalactions.GlobalActionsDialog#mKeyguardShowing} and whether
966 * the device is provisioned
Jason Monk361915c2017-03-21 20:33:59 -0400967 * via {@link com.android.systemui.globalactions.GlobalActionsDialog#mDeviceProvisioned}.
968 */
Aaron Heuckroth57d60d22019-03-05 14:00:12 -0500969 public class MyAdapter extends MultiListAdapter {
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -0400970 private int countItems(boolean separated) {
Jason Monk361915c2017-03-21 20:33:59 -0400971 int count = 0;
Jason Monk361915c2017-03-21 20:33:59 -0400972 for (int i = 0; i < mItems.size(); i++) {
973 final Action action = mItems.get(i);
974
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -0400975 if (shouldBeShown(action) && action.shouldBeSeparated() == separated) {
976 count++;
Jason Monk361915c2017-03-21 20:33:59 -0400977 }
Jason Monk361915c2017-03-21 20:33:59 -0400978 }
979 return count;
980 }
981
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -0400982 private boolean shouldBeShown(Action action) {
983 if (mKeyguardShowing && !action.showDuringKeyguard()) {
984 return false;
985 }
986 if (!mDeviceProvisioned && !action.showBeforeProvisioning()) {
987 return false;
988 }
989 return true;
990 }
991
992 @Override
993 public int countSeparatedItems() {
994 return countItems(true);
995 }
996
997 @Override
998 public int countListItems() {
999 return countItems(false);
1000 }
1001
1002 @Override
1003 public int getCount() {
1004 return countSeparatedItems() + countListItems();
1005 }
1006
Jason Monk361915c2017-03-21 20:33:59 -04001007 @Override
1008 public boolean isEnabled(int position) {
1009 return getItem(position).isEnabled();
1010 }
1011
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001012 @Override
Jason Monk361915c2017-03-21 20:33:59 -04001013 public boolean areAllItemsEnabled() {
1014 return false;
1015 }
1016
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001017 @Override
Jason Monk361915c2017-03-21 20:33:59 -04001018 public Action getItem(int position) {
Jason Monk361915c2017-03-21 20:33:59 -04001019 int filteredPos = 0;
1020 for (int i = 0; i < mItems.size(); i++) {
1021 final Action action = mItems.get(i);
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -04001022 if (!shouldBeShown(action)) {
Jason Monk361915c2017-03-21 20:33:59 -04001023 continue;
1024 }
1025 if (filteredPos == position) {
1026 return action;
1027 }
1028 filteredPos++;
1029 }
1030
1031 throw new IllegalArgumentException("position " + position
1032 + " out of range of showable actions"
1033 + ", filtered count=" + getCount()
1034 + ", keyguardshowing=" + mKeyguardShowing
1035 + ", provisioned=" + mDeviceProvisioned);
1036 }
1037
1038
1039 public long getItemId(int position) {
1040 return position;
1041 }
1042
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001043 @Override
Jason Monk361915c2017-03-21 20:33:59 -04001044 public View getView(int position, View convertView, ViewGroup parent) {
1045 Action action = getItem(position);
Jason Monk16fbd9d2017-04-27 14:28:49 -04001046 View view = action.create(mContext, convertView, parent, LayoutInflater.from(mContext));
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -04001047 view.setOnClickListener(v -> onClickItem(position));
Aran Inkb4199d92020-02-07 13:25:21 -05001048 if (action instanceof LongPressAction) {
1049 view.setOnLongClickListener(v -> onLongClickItem(position));
1050 }
Jason Monk16fbd9d2017-04-27 14:28:49 -04001051 return view;
Jason Monk361915c2017-03-21 20:33:59 -04001052 }
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001053
1054 @Override
1055 public boolean onLongClickItem(int position) {
1056 final Action action = mAdapter.getItem(position);
1057 if (action instanceof LongPressAction) {
Aran Inkbaa25862019-06-11 15:48:55 -04001058 if (mDialog != null) {
1059 mDialog.dismiss();
1060 } else {
1061 Log.w(TAG, "Action long-clicked while mDialog is null.");
1062 }
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001063 return ((LongPressAction) action).onLongPress();
1064 }
1065 return false;
1066 }
1067
1068 @Override
1069 public void onClickItem(int position) {
1070 Action item = mAdapter.getItem(position);
1071 if (!(item instanceof SilentModeTriStateAction)) {
Aran Inkbaa25862019-06-11 15:48:55 -04001072 if (mDialog != null) {
1073 mDialog.dismiss();
1074 } else {
1075 Log.w(TAG, "Action clicked while mDialog is null.");
1076 }
1077 item.onPress();
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001078 }
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001079 }
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -04001080
1081 @Override
1082 public boolean shouldBeSeparated(int position) {
1083 return getItem(position).shouldBeSeparated();
1084 }
Jason Monk361915c2017-03-21 20:33:59 -04001085 }
1086
1087 // note: the scheme below made more sense when we were planning on having
1088 // 8 different things in the global actions dialog. seems overkill with
1089 // only 3 items now, but may as well keep this flexible approach so it will
1090 // be easy should someone decide at the last minute to include something
1091 // else, such as 'enable wifi', or 'enable bluetooth'
1092
1093 /**
1094 * What each item in the global actions dialog must be able to support.
1095 */
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001096 public interface Action {
Jason Monk361915c2017-03-21 20:33:59 -04001097 /**
1098 * @return Text that will be announced when dialog is created. null
Jason Monk16fbd9d2017-04-27 14:28:49 -04001099 * for none.
Jason Monk361915c2017-03-21 20:33:59 -04001100 */
1101 CharSequence getLabelForAccessibility(Context context);
1102
1103 View create(Context context, View convertView, ViewGroup parent, LayoutInflater inflater);
1104
1105 void onPress();
1106
1107 /**
1108 * @return whether this action should appear in the dialog when the keygaurd
Jason Monk16fbd9d2017-04-27 14:28:49 -04001109 * is showing.
Jason Monk361915c2017-03-21 20:33:59 -04001110 */
1111 boolean showDuringKeyguard();
1112
1113 /**
1114 * @return whether this action should appear in the dialog before the
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001115 * device is provisioned.onlongpress
1116 *
Jason Monk361915c2017-03-21 20:33:59 -04001117 */
1118 boolean showBeforeProvisioning();
1119
1120 boolean isEnabled();
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001121
1122 default boolean shouldBeSeparated() {
1123 return false;
1124 }
Jason Monk361915c2017-03-21 20:33:59 -04001125 }
1126
1127 /**
1128 * An action that also supports long press.
1129 */
1130 private interface LongPressAction extends Action {
1131 boolean onLongPress();
1132 }
1133
1134 /**
1135 * A single press action maintains no state, just responds to a press
1136 * and takes an action.
1137 */
Matt Pietale0661b62020-01-29 14:35:31 -05001138
1139 private abstract class SinglePressAction implements Action {
Jason Monk361915c2017-03-21 20:33:59 -04001140 private final int mIconResId;
1141 private final Drawable mIcon;
1142 private final int mMessageResId;
1143 private final CharSequence mMessage;
1144
1145 protected SinglePressAction(int iconResId, int messageResId) {
1146 mIconResId = iconResId;
1147 mMessageResId = messageResId;
1148 mMessage = null;
1149 mIcon = null;
1150 }
1151
1152 protected SinglePressAction(int iconResId, Drawable icon, CharSequence message) {
1153 mIconResId = iconResId;
1154 mMessageResId = 0;
1155 mMessage = message;
1156 mIcon = icon;
1157 }
1158
1159 public boolean isEnabled() {
1160 return true;
1161 }
1162
1163 public String getStatus() {
1164 return null;
1165 }
1166
1167 abstract public void onPress();
1168
1169 public CharSequence getLabelForAccessibility(Context context) {
1170 if (mMessage != null) {
1171 return mMessage;
1172 } else {
1173 return context.getString(mMessageResId);
1174 }
1175 }
1176
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001177 protected int getActionLayoutId(Context context) {
Matt Pietale0661b62020-01-29 14:35:31 -05001178 if (shouldShowControls()) {
Matt Pietalfd3b6cb2020-01-08 09:43:54 -05001179 return com.android.systemui.R.layout.global_actions_grid_item_v2;
1180 }
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001181 return com.android.systemui.R.layout.global_actions_grid_item;
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001182 }
1183
Jason Monk361915c2017-03-21 20:33:59 -04001184 public View create(
1185 Context context, View convertView, ViewGroup parent, LayoutInflater inflater) {
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001186 View v = inflater.inflate(getActionLayoutId(context), parent,
Jason Monk16fbd9d2017-04-27 14:28:49 -04001187 false);
Jason Monk361915c2017-03-21 20:33:59 -04001188
1189 ImageView icon = (ImageView) v.findViewById(R.id.icon);
1190 TextView messageView = (TextView) v.findViewById(R.id.message);
Aaron Heuckroth3f2d8b52019-04-05 13:27:51 -04001191 messageView.setSelected(true); // necessary for marquee to work
Jason Monk361915c2017-03-21 20:33:59 -04001192
Jason Monk361915c2017-03-21 20:33:59 -04001193 if (mIcon != null) {
1194 icon.setImageDrawable(mIcon);
1195 icon.setScaleType(ScaleType.CENTER_CROP);
1196 } else if (mIconResId != 0) {
1197 icon.setImageDrawable(context.getDrawable(mIconResId));
1198 }
1199 if (mMessage != null) {
1200 messageView.setText(mMessage);
1201 } else {
1202 messageView.setText(mMessageResId);
1203 }
1204
1205 return v;
1206 }
1207 }
1208
1209 /**
1210 * A toggle action knows whether it is on or off, and displays an icon
1211 * and status message accordingly.
1212 */
1213 private static abstract class ToggleAction implements Action {
1214
1215 enum State {
1216 Off(false),
1217 TurningOn(true),
1218 TurningOff(true),
1219 On(false);
1220
1221 private final boolean inTransition;
1222
1223 State(boolean intermediate) {
1224 inTransition = intermediate;
1225 }
1226
1227 public boolean inTransition() {
1228 return inTransition;
1229 }
1230 }
1231
1232 protected State mState = State.Off;
1233
1234 // prefs
1235 protected int mEnabledIconResId;
1236 protected int mDisabledIconResid;
1237 protected int mMessageResId;
1238 protected int mEnabledStatusMessageResId;
1239 protected int mDisabledStatusMessageResId;
1240
1241 /**
Jason Monk16fbd9d2017-04-27 14:28:49 -04001242 * @param enabledIconResId The icon for when this action is on.
1243 * @param disabledIconResid The icon for when this action is off.
1244 * @param message The general information message, e.g 'Silent Mode'
1245 * @param enabledStatusMessageResId The on status message, e.g 'sound disabled'
Jason Monk361915c2017-03-21 20:33:59 -04001246 * @param disabledStatusMessageResId The off status message, e.g. 'sound enabled'
1247 */
1248 public ToggleAction(int enabledIconResId,
1249 int disabledIconResid,
1250 int message,
1251 int enabledStatusMessageResId,
1252 int disabledStatusMessageResId) {
1253 mEnabledIconResId = enabledIconResId;
1254 mDisabledIconResid = disabledIconResid;
1255 mMessageResId = message;
1256 mEnabledStatusMessageResId = enabledStatusMessageResId;
1257 mDisabledStatusMessageResId = disabledStatusMessageResId;
1258 }
1259
1260 /**
1261 * Override to make changes to resource IDs just before creating the
1262 * View.
1263 */
1264 void willCreate() {
1265
1266 }
1267
1268 @Override
1269 public CharSequence getLabelForAccessibility(Context context) {
1270 return context.getString(mMessageResId);
1271 }
1272
1273 public View create(Context context, View convertView, ViewGroup parent,
1274 LayoutInflater inflater) {
1275 willCreate();
1276
Koji Fukui5c010ee2019-12-24 16:12:07 +09001277 View v = inflater.inflate(com.android.systemui.R
1278 .layout.global_actions_grid_item, parent, false);
Jason Monk361915c2017-03-21 20:33:59 -04001279
1280 ImageView icon = (ImageView) v.findViewById(R.id.icon);
1281 TextView messageView = (TextView) v.findViewById(R.id.message);
Jason Monk361915c2017-03-21 20:33:59 -04001282 final boolean enabled = isEnabled();
Koji Fukui5c010ee2019-12-24 16:12:07 +09001283 boolean on = ((mState == State.On) || (mState == State.TurningOn));
Jason Monk361915c2017-03-21 20:33:59 -04001284
1285 if (messageView != null) {
Koji Fukui5c010ee2019-12-24 16:12:07 +09001286 messageView.setText(on ? mEnabledStatusMessageResId : mDisabledStatusMessageResId);
Jason Monk361915c2017-03-21 20:33:59 -04001287 messageView.setEnabled(enabled);
Aaron Heuckroth3f2d8b52019-04-05 13:27:51 -04001288 messageView.setSelected(true); // necessary for marquee to work
Jason Monk361915c2017-03-21 20:33:59 -04001289 }
1290
Jason Monk361915c2017-03-21 20:33:59 -04001291 if (icon != null) {
1292 icon.setImageDrawable(context.getDrawable(
1293 (on ? mEnabledIconResId : mDisabledIconResid)));
1294 icon.setEnabled(enabled);
1295 }
1296
Jason Monk361915c2017-03-21 20:33:59 -04001297 v.setEnabled(enabled);
1298
1299 return v;
1300 }
1301
1302 public final void onPress() {
1303 if (mState.inTransition()) {
1304 Log.w(TAG, "shouldn't be able to toggle when in transition");
1305 return;
1306 }
1307
1308 final boolean nowOn = !(mState == State.On);
1309 onToggle(nowOn);
1310 changeStateFromPress(nowOn);
1311 }
1312
1313 public boolean isEnabled() {
1314 return !mState.inTransition();
1315 }
1316
1317 /**
1318 * Implementations may override this if their state can be in on of the intermediate
1319 * states until some notification is received (e.g airplane mode is 'turning off' until
1320 * we know the wireless connections are back online
Jason Monk16fbd9d2017-04-27 14:28:49 -04001321 *
Jason Monk361915c2017-03-21 20:33:59 -04001322 * @param buttonOn Whether the button was turned on or off
1323 */
1324 protected void changeStateFromPress(boolean buttonOn) {
1325 mState = buttonOn ? State.On : State.Off;
1326 }
1327
1328 abstract void onToggle(boolean on);
1329
1330 public void updateState(State state) {
1331 mState = state;
1332 }
1333 }
1334
1335 private class SilentModeToggleAction extends ToggleAction {
1336 public SilentModeToggleAction() {
1337 super(R.drawable.ic_audio_vol_mute,
1338 R.drawable.ic_audio_vol,
1339 R.string.global_action_toggle_silent_mode,
1340 R.string.global_action_silent_mode_on_status,
1341 R.string.global_action_silent_mode_off_status);
1342 }
1343
1344 void onToggle(boolean on) {
1345 if (on) {
1346 mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
1347 } else {
1348 mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
1349 }
1350 }
1351
1352 public boolean showDuringKeyguard() {
1353 return true;
1354 }
1355
1356 public boolean showBeforeProvisioning() {
1357 return false;
1358 }
1359 }
1360
1361 private static class SilentModeTriStateAction implements Action, View.OnClickListener {
1362
Jason Monk16fbd9d2017-04-27 14:28:49 -04001363 private final int[] ITEM_IDS = {R.id.option1, R.id.option2, R.id.option3};
Jason Monk361915c2017-03-21 20:33:59 -04001364
1365 private final AudioManager mAudioManager;
1366 private final Handler mHandler;
Jason Monk361915c2017-03-21 20:33:59 -04001367
Lucas Dupin40ec6b782018-06-05 19:07:16 -07001368 SilentModeTriStateAction(AudioManager audioManager, Handler handler) {
Jason Monk361915c2017-03-21 20:33:59 -04001369 mAudioManager = audioManager;
1370 mHandler = handler;
Jason Monk361915c2017-03-21 20:33:59 -04001371 }
1372
1373 private int ringerModeToIndex(int ringerMode) {
1374 // They just happen to coincide
1375 return ringerMode;
1376 }
1377
1378 private int indexToRingerMode(int index) {
1379 // They just happen to coincide
1380 return index;
1381 }
1382
1383 @Override
1384 public CharSequence getLabelForAccessibility(Context context) {
1385 return null;
1386 }
1387
1388 public View create(Context context, View convertView, ViewGroup parent,
1389 LayoutInflater inflater) {
1390 View v = inflater.inflate(R.layout.global_actions_silent_mode, parent, false);
1391
1392 int selectedIndex = ringerModeToIndex(mAudioManager.getRingerMode());
1393 for (int i = 0; i < 3; i++) {
1394 View itemView = v.findViewById(ITEM_IDS[i]);
1395 itemView.setSelected(selectedIndex == i);
1396 // Set up click handler
1397 itemView.setTag(i);
1398 itemView.setOnClickListener(this);
1399 }
1400 return v;
1401 }
1402
1403 public void onPress() {
1404 }
1405
1406 public boolean showDuringKeyguard() {
1407 return true;
1408 }
1409
1410 public boolean showBeforeProvisioning() {
1411 return false;
1412 }
1413
1414 public boolean isEnabled() {
1415 return true;
1416 }
1417
1418 void willCreate() {
1419 }
1420
1421 public void onClick(View v) {
1422 if (!(v.getTag() instanceof Integer)) return;
1423
1424 int index = (Integer) v.getTag();
1425 mAudioManager.setRingerMode(indexToRingerMode(index));
1426 mHandler.sendEmptyMessageDelayed(MESSAGE_DISMISS, DIALOG_DISMISS_DELAY);
1427 }
1428 }
1429
1430 private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
1431 public void onReceive(Context context, Intent intent) {
1432 String action = intent.getAction();
1433 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)
1434 || Intent.ACTION_SCREEN_OFF.equals(action)) {
1435 String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY);
1436 if (!SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS.equals(reason)) {
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001437 mHandler.sendMessage(mHandler.obtainMessage(MESSAGE_DISMISS, reason));
Jason Monk361915c2017-03-21 20:33:59 -04001438 }
Jayachandran C142eae02019-12-13 19:29:20 -08001439 } else if (TelephonyManager.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED.equals(action)) {
Jason Monk361915c2017-03-21 20:33:59 -04001440 // Airplane mode can be changed after ECM exits if airplane toggle button
1441 // is pressed during ECM mode
Daniel Bright4bcbfce2020-01-09 21:58:16 -08001442 if (!(intent.getBooleanExtra(TelephonyManager.EXTRA_PHONE_IN_ECM_STATE, false))
1443 && mIsWaitingForEcmExit) {
Jason Monk361915c2017-03-21 20:33:59 -04001444 mIsWaitingForEcmExit = false;
1445 changeAirplaneModeSystemSetting(true);
1446 }
1447 }
1448 }
1449 };
1450
1451 PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
1452 @Override
1453 public void onServiceStateChanged(ServiceState serviceState) {
1454 if (!mHasTelephony) return;
1455 final boolean inAirplaneMode = serviceState.getState() == ServiceState.STATE_POWER_OFF;
1456 mAirplaneState = inAirplaneMode ? ToggleAction.State.On : ToggleAction.State.Off;
1457 mAirplaneModeOn.updateState(mAirplaneState);
1458 mAdapter.notifyDataSetChanged();
1459 }
1460 };
1461
1462 private BroadcastReceiver mRingerModeReceiver = new BroadcastReceiver() {
1463 @Override
1464 public void onReceive(Context context, Intent intent) {
1465 if (intent.getAction().equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
1466 mHandler.sendEmptyMessage(MESSAGE_REFRESH);
1467 }
1468 }
1469 };
1470
1471 private ContentObserver mAirplaneModeObserver = new ContentObserver(new Handler()) {
1472 @Override
1473 public void onChange(boolean selfChange) {
1474 onAirplaneModeChanged();
1475 }
1476 };
1477
1478 private static final int MESSAGE_DISMISS = 0;
1479 private static final int MESSAGE_REFRESH = 1;
1480 private static final int MESSAGE_SHOW = 2;
1481 private static final int DIALOG_DISMISS_DELAY = 300; // ms
1482
1483 private Handler mHandler = new Handler() {
1484 public void handleMessage(Message msg) {
1485 switch (msg.what) {
Jason Monk16fbd9d2017-04-27 14:28:49 -04001486 case MESSAGE_DISMISS:
1487 if (mDialog != null) {
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001488 if (SYSTEM_DIALOG_REASON_DREAM.equals(msg.obj)) {
1489 mDialog.dismissImmediately();
1490 } else {
1491 mDialog.dismiss();
1492 }
Jason Monk16fbd9d2017-04-27 14:28:49 -04001493 mDialog = null;
1494 }
1495 break;
1496 case MESSAGE_REFRESH:
1497 refreshSilentMode();
1498 mAdapter.notifyDataSetChanged();
1499 break;
1500 case MESSAGE_SHOW:
1501 handleShow();
1502 break;
Jason Monk361915c2017-03-21 20:33:59 -04001503 }
1504 }
1505 };
1506
1507 private void onAirplaneModeChanged() {
1508 // Let the service state callbacks handle the state.
1509 if (mHasTelephony) return;
1510
1511 boolean airplaneModeOn = Settings.Global.getInt(
Dave Mankoffc88a2d72020-01-10 15:59:31 -05001512 mContentResolver,
Jason Monk361915c2017-03-21 20:33:59 -04001513 Settings.Global.AIRPLANE_MODE_ON,
1514 0) == 1;
1515 mAirplaneState = airplaneModeOn ? ToggleAction.State.On : ToggleAction.State.Off;
1516 mAirplaneModeOn.updateState(mAirplaneState);
1517 }
1518
1519 /**
1520 * Change the airplane mode system setting
1521 */
1522 private void changeAirplaneModeSystemSetting(boolean on) {
1523 Settings.Global.putInt(
Dave Mankoffc88a2d72020-01-10 15:59:31 -05001524 mContentResolver,
Jason Monk361915c2017-03-21 20:33:59 -04001525 Settings.Global.AIRPLANE_MODE_ON,
1526 on ? 1 : 0);
1527 Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
1528 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
1529 intent.putExtra("state", on);
1530 mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
1531 if (!mHasTelephony) {
1532 mAirplaneState = on ? ToggleAction.State.On : ToggleAction.State.Off;
1533 }
1534 }
1535
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001536 private static final class ActionsDialog extends Dialog implements DialogInterface,
1537 ColorExtractor.OnColorsChangedListener {
Jason Monk361915c2017-03-21 20:33:59 -04001538
Jason Monk16fbd9d2017-04-27 14:28:49 -04001539 private final Context mContext;
1540 private final MyAdapter mAdapter;
Steve Elliott53f12ae2019-05-13 17:14:15 -04001541 private final IStatusBarService mStatusBarService;
1542 private final IBinder mToken = new Binder();
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001543 private MultiListLayout mGlobalActionsLayout;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001544 private Drawable mBackgroundDrawable;
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001545 private final SysuiColorExtractor mColorExtractor;
Steve Elliott9b87a442019-03-05 10:24:16 -05001546 private final GlobalActionsPanelPlugin.PanelViewController mPanelController;
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001547 private boolean mKeyguardShowing;
Beverly526d2d62018-08-15 12:55:33 -04001548 private boolean mShowing;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001549 private float mScrimAlpha;
Steve Elliott48f75db2019-05-03 15:03:38 -04001550 private ResetOrientationData mResetOrientationData;
Steve Elliottff2c0d92019-07-30 15:09:54 -04001551 private boolean mHadTopUi;
wilsonshihe8321942019-10-18 18:39:46 +08001552 private final NotificationShadeWindowController mNotificationShadeWindowController;
Lucas Dupin991415e2019-11-25 17:48:58 -08001553 private final BlurUtils mBlurUtils;
Matt Pietal22231792020-01-23 09:51:09 -05001554
1555 private ControlsUiController mControlsUiController;
1556 private ViewGroup mControlsView;
Jason Monk16fbd9d2017-04-27 14:28:49 -04001557
Aaron Heuckrothf19d2722019-03-11 17:06:02 -04001558 ActionsDialog(Context context, MyAdapter adapter,
Lucas Dupin991415e2019-11-25 17:48:58 -08001559 GlobalActionsPanelPlugin.PanelViewController plugin, BlurUtils blurUtils,
1560 SysuiColorExtractor sysuiColorExtractor, IStatusBarService statusBarService,
1561 NotificationShadeWindowController notificationShadeWindowController,
Matt Pietal22231792020-01-23 09:51:09 -05001562 ControlsUiController controlsUiController) {
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001563 super(context, com.android.systemui.R.style.Theme_SystemUI_Dialog_GlobalActions);
Lucas Dupin448786c2017-07-24 17:44:25 -07001564 mContext = context;
Jason Monk16fbd9d2017-04-27 14:28:49 -04001565 mAdapter = adapter;
Lucas Dupin991415e2019-11-25 17:48:58 -08001566 mBlurUtils = blurUtils;
1567 mColorExtractor = sysuiColorExtractor;
1568 mStatusBarService = statusBarService;
1569 mNotificationShadeWindowController = notificationShadeWindowController;
Matt Pietal22231792020-01-23 09:51:09 -05001570 mControlsUiController = controlsUiController;
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001571
1572 // Window initialization
1573 Window window = getWindow();
1574 window.requestFeature(Window.FEATURE_NO_TITLE);
Adrian Roosedfab3b2018-03-08 18:39:20 +01001575 // Inflate the decor view, so the attributes below are not overwritten by the theme.
1576 window.getDecorView();
1577 window.getAttributes().systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1578 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1579 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1580 window.setLayout(MATCH_PARENT, MATCH_PARENT);
1581 window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
Alison Cichowlas4f19f4a2017-07-25 10:56:16 -04001582 window.addFlags(
1583 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001584 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
Adrian Roosedfab3b2018-03-08 18:39:20 +01001585 | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001586 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
1587 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
1588 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001589 window.setType(WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY);
Tiger Huang52724442020-01-20 21:38:42 +08001590 window.getAttributes().setFitInsetsTypes(0 /* types */);
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001591 setTitle(R.string.global_actions);
Steve Elliott9b87a442019-03-05 10:24:16 -05001592
1593 mPanelController = plugin;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001594 initializeLayout();
Steve Elliott9b87a442019-03-05 10:24:16 -05001595 }
1596
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001597 private boolean shouldUsePanel() {
Aran Ink3f594552019-05-13 14:29:35 -04001598 return mPanelController != null && mPanelController.getPanelContent() != null;
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001599 }
1600
1601 private void initializePanel() {
Steve Elliott48f75db2019-05-03 15:03:38 -04001602 int rotation = RotationUtils.getRotation(mContext);
1603 boolean rotationLocked = RotationPolicy.isRotationLocked(mContext);
1604 if (rotation != RotationUtils.ROTATION_NONE) {
1605 if (rotationLocked) {
1606 if (mResetOrientationData == null) {
1607 mResetOrientationData = new ResetOrientationData();
1608 mResetOrientationData.locked = true;
1609 mResetOrientationData.rotation = rotation;
1610 }
1611
1612 // Unlock rotation, so user can choose to rotate to portrait to see the panel.
Steve Elliotte05817f2019-05-17 14:39:53 -04001613 // This call is posted so that the rotation does not change until post-layout,
1614 // otherwise onConfigurationChanged() may not get invoked.
1615 mGlobalActionsLayout.post(() ->
1616 RotationPolicy.setRotationLockAtAngle(
1617 mContext, false, RotationUtils.ROTATION_NONE));
Steve Elliott48f75db2019-05-03 15:03:38 -04001618 }
1619 } else {
1620 if (!rotationLocked) {
1621 if (mResetOrientationData == null) {
1622 mResetOrientationData = new ResetOrientationData();
1623 mResetOrientationData.locked = false;
1624 }
1625
1626 // Lock to portrait, so the user doesn't accidentally hide the panel.
Steve Elliotte05817f2019-05-17 14:39:53 -04001627 // This call is posted so that the rotation does not change until post-layout,
1628 // otherwise onConfigurationChanged() may not get invoked.
1629 mGlobalActionsLayout.post(() ->
1630 RotationPolicy.setRotationLockAtAngle(
1631 mContext, true, RotationUtils.ROTATION_NONE));
Steve Elliott48f75db2019-05-03 15:03:38 -04001632 }
1633
Steve Elliott53f12ae2019-05-13 17:14:15 -04001634 // Disable rotation suggestions, if enabled
1635 setRotationSuggestionsEnabled(false);
1636
Steve Elliott300b48f2019-05-29 14:13:50 -04001637 FrameLayout panelContainer =
1638 findViewById(com.android.systemui.R.id.global_actions_panel_container);
Steve Elliott48f75db2019-05-03 15:03:38 -04001639 FrameLayout.LayoutParams panelParams =
1640 new FrameLayout.LayoutParams(
1641 FrameLayout.LayoutParams.MATCH_PARENT,
Steve Elliott300b48f2019-05-29 14:13:50 -04001642 FrameLayout.LayoutParams.MATCH_PARENT);
Steve Elliott48f75db2019-05-03 15:03:38 -04001643 panelContainer.addView(mPanelController.getPanelContent(), panelParams);
Steve Elliott48f75db2019-05-03 15:03:38 -04001644 }
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001645 }
1646
1647 private void initializeLayout() {
1648 setContentView(getGlobalActionsLayoutId(mContext));
Steve Elliott300b48f2019-05-29 14:13:50 -04001649 fixNavBarClipping();
Matt Pietal22231792020-01-23 09:51:09 -05001650 mControlsView = findViewById(com.android.systemui.R.id.global_actions_controls);
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001651 mGlobalActionsLayout = findViewById(com.android.systemui.R.id.global_actions_view);
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001652 mGlobalActionsLayout.setOutsideTouchListener(view -> dismiss());
Steve Elliott300b48f2019-05-29 14:13:50 -04001653 ((View) mGlobalActionsLayout.getParent()).setOnClickListener(view -> dismiss());
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001654 mGlobalActionsLayout.setListViewAccessibilityDelegate(new View.AccessibilityDelegate() {
Phil Weaver9054e092018-04-27 16:28:50 -07001655 @Override
1656 public boolean dispatchPopulateAccessibilityEvent(
1657 View host, AccessibilityEvent event) {
1658 // Populate the title here, just as Activity does
1659 event.getText().add(mContext.getString(R.string.global_actions));
1660 return true;
1661 }
1662 });
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001663 mGlobalActionsLayout.setRotationListener(this::onRotate);
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001664 mGlobalActionsLayout.setAdapter(mAdapter);
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001665
Steve Elliott86ef6282019-05-08 14:45:04 -04001666 if (shouldUsePanel()) {
Steve Elliottc59eb342019-04-23 16:59:06 -04001667 initializePanel();
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001668 }
Steve Elliott86ef6282019-05-08 14:45:04 -04001669 if (mBackgroundDrawable == null) {
1670 mBackgroundDrawable = new ScrimDrawable();
Matt Pietale0661b62020-01-29 14:35:31 -05001671 mScrimAlpha = 0.8f;
Steve Elliott86ef6282019-05-08 14:45:04 -04001672 }
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001673 getWindow().setBackgroundDrawable(mBackgroundDrawable);
Steve Elliott9b87a442019-03-05 10:24:16 -05001674 }
1675
Steve Elliott300b48f2019-05-29 14:13:50 -04001676 private void fixNavBarClipping() {
1677 ViewGroup content = findViewById(android.R.id.content);
1678 content.setClipChildren(false);
1679 content.setClipToPadding(false);
1680 ViewGroup contentParent = (ViewGroup) content.getParent();
1681 contentParent.setClipChildren(false);
1682 contentParent.setClipToPadding(false);
1683 }
1684
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001685 private int getGlobalActionsLayoutId(Context context) {
Matt Pietal22231792020-01-23 09:51:09 -05001686 if (mControlsUiController != null) {
Matt Pietalfd3b6cb2020-01-08 09:43:54 -05001687 return com.android.systemui.R.layout.global_actions_grid_v2;
1688 }
1689
Steve Elliottdc165632019-05-23 14:26:31 -04001690 int rotation = RotationUtils.getRotation(context);
1691 boolean useGridLayout = isForceGridEnabled(context)
1692 || (shouldUsePanel() && rotation == RotationUtils.ROTATION_NONE);
1693 if (rotation == RotationUtils.ROTATION_SEASCAPE) {
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001694 if (useGridLayout) {
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001695 return com.android.systemui.R.layout.global_actions_grid_seascape;
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001696 } else {
1697 return com.android.systemui.R.layout.global_actions_column_seascape;
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001698 }
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001699 } else {
1700 if (useGridLayout) {
1701 return com.android.systemui.R.layout.global_actions_grid;
1702 } else {
1703 return com.android.systemui.R.layout.global_actions_column;
1704 }
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001705 }
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001706 }
1707
Jason Monk361915c2017-03-21 20:33:59 -04001708 @Override
1709 protected void onStart() {
1710 super.setCanceledOnTouchOutside(true);
1711 super.onStart();
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001712 mGlobalActionsLayout.updateList();
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001713
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001714 if (mBackgroundDrawable instanceof ScrimDrawable) {
Steve Elliott9b87a442019-03-05 10:24:16 -05001715 mColorExtractor.addOnColorsChangedListener(this);
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001716 GradientColors colors = mColorExtractor.getNeutralColors();
Steve Elliott9b87a442019-03-05 10:24:16 -05001717 updateColors(colors, false /* animate */);
1718 }
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001719 }
1720
1721 /**
1722 * Updates background and system bars according to current GradientColors.
1723 * @param colors Colors and hints to use.
1724 * @param animate Interpolates gradient if true, just sets otherwise.
1725 */
1726 private void updateColors(GradientColors colors, boolean animate) {
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001727 if (!(mBackgroundDrawable instanceof ScrimDrawable)) {
Steve Elliott9b87a442019-03-05 10:24:16 -05001728 return;
1729 }
Matt Pietale0661b62020-01-29 14:35:31 -05001730 ((ScrimDrawable) mBackgroundDrawable).setColor(Color.BLACK, animate);
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001731 View decorView = getWindow().getDecorView();
1732 if (colors.supportsDarkText()) {
1733 decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR |
Steve Elliott9b87a442019-03-05 10:24:16 -05001734 View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001735 } else {
1736 decorView.setSystemUiVisibility(0);
1737 }
Jason Monk361915c2017-03-21 20:33:59 -04001738 }
1739
1740 @Override
Jason Monk16fbd9d2017-04-27 14:28:49 -04001741 protected void onStop() {
1742 super.onStop();
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001743 mColorExtractor.removeOnColorsChangedListener(this);
Jason Monk16fbd9d2017-04-27 14:28:49 -04001744 }
1745
1746 @Override
1747 public void show() {
1748 super.show();
Beverly526d2d62018-08-15 12:55:33 -04001749 mShowing = true;
wilsonshihe8321942019-10-18 18:39:46 +08001750 mHadTopUi = mNotificationShadeWindowController.getForceHasTopUi();
1751 mNotificationShadeWindowController.setForceHasTopUi(true);
Steve Elliott9b87a442019-03-05 10:24:16 -05001752 mBackgroundDrawable.setAlpha(0);
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001753 mGlobalActionsLayout.setTranslationX(mGlobalActionsLayout.getAnimationOffsetX());
1754 mGlobalActionsLayout.setTranslationY(mGlobalActionsLayout.getAnimationOffsetY());
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001755 mGlobalActionsLayout.setAlpha(0);
1756 mGlobalActionsLayout.animate()
Jason Monk16fbd9d2017-04-27 14:28:49 -04001757 .alpha(1)
1758 .translationX(0)
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001759 .translationY(0)
Jason Monk16fbd9d2017-04-27 14:28:49 -04001760 .setDuration(300)
Lucas Dupinde9db422017-07-19 17:15:41 -07001761 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001762 .setUpdateListener(animation -> {
Lucas Dupin991415e2019-11-25 17:48:58 -08001763 float animatedValue = animation.getAnimatedFraction();
1764 int alpha = (int) (animatedValue * mScrimAlpha * 255);
Steve Elliott9b87a442019-03-05 10:24:16 -05001765 mBackgroundDrawable.setAlpha(alpha);
Lucas Dupin991415e2019-11-25 17:48:58 -08001766 mBlurUtils.applyBlur(mGlobalActionsLayout.getViewRootImpl(),
1767 mBlurUtils.radiusForRatio(animatedValue));
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001768 })
Jason Monk16fbd9d2017-04-27 14:28:49 -04001769 .start();
Matt Pietal22231792020-01-23 09:51:09 -05001770 if (mControlsUiController != null) {
1771 mControlsUiController.show(mControlsView);
1772 }
Jason Monk16fbd9d2017-04-27 14:28:49 -04001773 }
1774
1775 @Override
1776 public void dismiss() {
Beverly526d2d62018-08-15 12:55:33 -04001777 if (!mShowing) {
1778 return;
1779 }
1780 mShowing = false;
Matt Pietal22231792020-01-23 09:51:09 -05001781 if (mControlsUiController != null) mControlsUiController.hide();
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001782 mGlobalActionsLayout.setTranslationX(0);
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001783 mGlobalActionsLayout.setTranslationY(0);
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001784 mGlobalActionsLayout.setAlpha(1);
1785 mGlobalActionsLayout.animate()
Jason Monk16fbd9d2017-04-27 14:28:49 -04001786 .alpha(0)
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001787 .translationX(mGlobalActionsLayout.getAnimationOffsetX())
1788 .translationY(mGlobalActionsLayout.getAnimationOffsetY())
Jason Monk16fbd9d2017-04-27 14:28:49 -04001789 .setDuration(300)
Steve Elliottff2c0d92019-07-30 15:09:54 -04001790 .withEndAction(this::completeDismiss)
Jason Monk16fbd9d2017-04-27 14:28:49 -04001791 .setInterpolator(new LogAccelerateInterpolator())
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001792 .setUpdateListener(animation -> {
Lucas Dupin991415e2019-11-25 17:48:58 -08001793 float animatedValue = 1f - animation.getAnimatedFraction();
1794 int alpha = (int) (animatedValue * mScrimAlpha * 255);
Steve Elliott9b87a442019-03-05 10:24:16 -05001795 mBackgroundDrawable.setAlpha(alpha);
Lucas Dupin991415e2019-11-25 17:48:58 -08001796 mBlurUtils.applyBlur(mGlobalActionsLayout.getViewRootImpl(),
1797 mBlurUtils.radiusForRatio(animatedValue));
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001798 })
Jason Monk16fbd9d2017-04-27 14:28:49 -04001799 .start();
Steve Elliott48f75db2019-05-03 15:03:38 -04001800 dismissPanel();
1801 resetOrientation();
Jason Monk16fbd9d2017-04-27 14:28:49 -04001802 }
1803
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001804 void dismissImmediately() {
Beverly526d2d62018-08-15 12:55:33 -04001805 mShowing = false;
Matt Pietal019feaa2020-01-31 14:51:37 -05001806 if (mControlsUiController != null) mControlsUiController.hide();
Steve Elliott48f75db2019-05-03 15:03:38 -04001807 dismissPanel();
1808 resetOrientation();
Steve Elliottff2c0d92019-07-30 15:09:54 -04001809 completeDismiss();
1810 }
1811
1812 private void completeDismiss() {
wilsonshihe8321942019-10-18 18:39:46 +08001813 mNotificationShadeWindowController.setForceHasTopUi(mHadTopUi);
Steve Elliottff2c0d92019-07-30 15:09:54 -04001814 super.dismiss();
Steve Elliott48f75db2019-05-03 15:03:38 -04001815 }
1816
1817 private void dismissPanel() {
Steve Elliott2d206d32019-03-14 16:30:33 -04001818 if (mPanelController != null) {
1819 mPanelController.onDismissed();
1820 }
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001821 }
1822
Steve Elliott53f12ae2019-05-13 17:14:15 -04001823 private void setRotationSuggestionsEnabled(boolean enabled) {
1824 try {
1825 final int userId = Binder.getCallingUserHandle().getIdentifier();
1826 final int what = enabled
1827 ? StatusBarManager.DISABLE2_NONE
1828 : StatusBarManager.DISABLE2_ROTATE_SUGGESTIONS;
1829 mStatusBarService.disable2ForUser(what, mToken, mContext.getPackageName(), userId);
1830 } catch (RemoteException ex) {
1831 throw ex.rethrowFromSystemServer();
1832 }
1833 }
1834
Steve Elliott48f75db2019-05-03 15:03:38 -04001835 private void resetOrientation() {
1836 if (mResetOrientationData != null) {
1837 RotationPolicy.setRotationLockAtAngle(mContext, mResetOrientationData.locked,
1838 mResetOrientationData.rotation);
1839 }
Steve Elliott53f12ae2019-05-13 17:14:15 -04001840 setRotationSuggestionsEnabled(true);
Steve Elliott48f75db2019-05-03 15:03:38 -04001841 }
1842
Jason Monk361915c2017-03-21 20:33:59 -04001843 @Override
Lucas Dupin7aaa3532017-05-28 08:51:07 -07001844 public void onColorsChanged(ColorExtractor extractor, int which) {
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001845 if (mKeyguardShowing) {
1846 if ((WallpaperManager.FLAG_LOCK & which) != 0) {
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001847 updateColors(extractor.getColors(WallpaperManager.FLAG_LOCK),
1848 true /* animate */);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001849 }
1850 } else {
1851 if ((WallpaperManager.FLAG_SYSTEM & which) != 0) {
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001852 updateColors(extractor.getColors(WallpaperManager.FLAG_SYSTEM),
1853 true /* animate */);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001854 }
1855 }
1856 }
1857
1858 public void setKeyguardShowing(boolean keyguardShowing) {
1859 mKeyguardShowing = keyguardShowing;
1860 }
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001861
Aaron Heuckroth4ef3a542019-04-01 14:17:23 -04001862 public void refreshDialog() {
1863 initializeLayout();
1864 mGlobalActionsLayout.updateList();
1865 }
1866
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001867 public void onRotate(int from, int to) {
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001868 if (mShowing) {
Aaron Heuckroth4ef3a542019-04-01 14:17:23 -04001869 refreshDialog();
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001870 }
1871 }
Steve Elliott48f75db2019-05-03 15:03:38 -04001872
1873 private static class ResetOrientationData {
1874 public boolean locked;
1875 public int rotation;
1876 }
Jason Monk361915c2017-03-21 20:33:59 -04001877 }
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001878
1879 /**
Aran Ink93dd25c2019-05-09 14:42:14 -04001880 * Determines whether or not debug mode has been activated for the Global Actions Panel.
1881 */
1882 private static boolean isPanelDebugModeEnabled(Context context) {
1883 return Settings.Secure.getInt(context.getContentResolver(),
1884 Settings.Secure.GLOBAL_ACTIONS_PANEL_DEBUG_ENABLED, 0) == 1;
1885 }
1886
1887 /**
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001888 * Determines whether or not the Global Actions menu should be forced to
1889 * use the newer grid-style layout.
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001890 */
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001891 private static boolean isForceGridEnabled(Context context) {
Aran Ink93dd25c2019-05-09 14:42:14 -04001892 return isPanelDebugModeEnabled(context);
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001893 }
Aaron Heuckrothf19d2722019-03-11 17:06:02 -04001894
Aaron Heuckrothf19d2722019-03-11 17:06:02 -04001895
1896 /**
1897 * Determines whether the Global Actions menu should use a separated view for emergency actions.
1898 */
1899 private static boolean shouldUseSeparatedView() {
1900 return true;
1901 }
Matt Pietalfd3b6cb2020-01-08 09:43:54 -05001902
Matt Pietale0661b62020-01-29 14:35:31 -05001903 private boolean shouldShowControls() {
Fabian Kozynski8b540452020-02-04 15:16:30 -05001904 return !mKeyguardManager.isDeviceLocked()
1905 && mControlsUiController.getAvailable();
Matt Pietalfd3b6cb2020-01-08 09:43:54 -05001906 }
Jason Monk361915c2017-03-21 20:33:59 -04001907}