blob: 45c07a3e4693996da1da3f764b8c984fba813fc8 [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));
1048 view.setOnLongClickListener(v -> onLongClickItem(position));
Jason Monk16fbd9d2017-04-27 14:28:49 -04001049 return view;
Jason Monk361915c2017-03-21 20:33:59 -04001050 }
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001051
1052 @Override
1053 public boolean onLongClickItem(int position) {
1054 final Action action = mAdapter.getItem(position);
1055 if (action instanceof LongPressAction) {
Aran Inkbaa25862019-06-11 15:48:55 -04001056 if (mDialog != null) {
1057 mDialog.dismiss();
1058 } else {
1059 Log.w(TAG, "Action long-clicked while mDialog is null.");
1060 }
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001061 return ((LongPressAction) action).onLongPress();
1062 }
1063 return false;
1064 }
1065
1066 @Override
1067 public void onClickItem(int position) {
1068 Action item = mAdapter.getItem(position);
1069 if (!(item instanceof SilentModeTriStateAction)) {
Aran Inkbaa25862019-06-11 15:48:55 -04001070 if (mDialog != null) {
1071 mDialog.dismiss();
1072 } else {
1073 Log.w(TAG, "Action clicked while mDialog is null.");
1074 }
1075 item.onPress();
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001076 }
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001077 }
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -04001078
1079 @Override
1080 public boolean shouldBeSeparated(int position) {
1081 return getItem(position).shouldBeSeparated();
1082 }
Jason Monk361915c2017-03-21 20:33:59 -04001083 }
1084
1085 // note: the scheme below made more sense when we were planning on having
1086 // 8 different things in the global actions dialog. seems overkill with
1087 // only 3 items now, but may as well keep this flexible approach so it will
1088 // be easy should someone decide at the last minute to include something
1089 // else, such as 'enable wifi', or 'enable bluetooth'
1090
1091 /**
1092 * What each item in the global actions dialog must be able to support.
1093 */
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001094 public interface Action {
Jason Monk361915c2017-03-21 20:33:59 -04001095 /**
1096 * @return Text that will be announced when dialog is created. null
Jason Monk16fbd9d2017-04-27 14:28:49 -04001097 * for none.
Jason Monk361915c2017-03-21 20:33:59 -04001098 */
1099 CharSequence getLabelForAccessibility(Context context);
1100
1101 View create(Context context, View convertView, ViewGroup parent, LayoutInflater inflater);
1102
1103 void onPress();
1104
1105 /**
1106 * @return whether this action should appear in the dialog when the keygaurd
Jason Monk16fbd9d2017-04-27 14:28:49 -04001107 * is showing.
Jason Monk361915c2017-03-21 20:33:59 -04001108 */
1109 boolean showDuringKeyguard();
1110
1111 /**
1112 * @return whether this action should appear in the dialog before the
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001113 * device is provisioned.onlongpress
1114 *
Jason Monk361915c2017-03-21 20:33:59 -04001115 */
1116 boolean showBeforeProvisioning();
1117
1118 boolean isEnabled();
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001119
1120 default boolean shouldBeSeparated() {
1121 return false;
1122 }
Jason Monk361915c2017-03-21 20:33:59 -04001123 }
1124
1125 /**
1126 * An action that also supports long press.
1127 */
1128 private interface LongPressAction extends Action {
1129 boolean onLongPress();
1130 }
1131
1132 /**
1133 * A single press action maintains no state, just responds to a press
1134 * and takes an action.
1135 */
Matt Pietale0661b62020-01-29 14:35:31 -05001136
1137 private abstract class SinglePressAction implements Action {
Jason Monk361915c2017-03-21 20:33:59 -04001138 private final int mIconResId;
1139 private final Drawable mIcon;
1140 private final int mMessageResId;
1141 private final CharSequence mMessage;
1142
1143 protected SinglePressAction(int iconResId, int messageResId) {
1144 mIconResId = iconResId;
1145 mMessageResId = messageResId;
1146 mMessage = null;
1147 mIcon = null;
1148 }
1149
1150 protected SinglePressAction(int iconResId, Drawable icon, CharSequence message) {
1151 mIconResId = iconResId;
1152 mMessageResId = 0;
1153 mMessage = message;
1154 mIcon = icon;
1155 }
1156
1157 public boolean isEnabled() {
1158 return true;
1159 }
1160
1161 public String getStatus() {
1162 return null;
1163 }
1164
1165 abstract public void onPress();
1166
1167 public CharSequence getLabelForAccessibility(Context context) {
1168 if (mMessage != null) {
1169 return mMessage;
1170 } else {
1171 return context.getString(mMessageResId);
1172 }
1173 }
1174
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001175 protected int getActionLayoutId(Context context) {
Matt Pietale0661b62020-01-29 14:35:31 -05001176 if (shouldShowControls()) {
Matt Pietalfd3b6cb2020-01-08 09:43:54 -05001177 return com.android.systemui.R.layout.global_actions_grid_item_v2;
1178 }
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001179 return com.android.systemui.R.layout.global_actions_grid_item;
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001180 }
1181
Jason Monk361915c2017-03-21 20:33:59 -04001182 public View create(
1183 Context context, View convertView, ViewGroup parent, LayoutInflater inflater) {
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001184 View v = inflater.inflate(getActionLayoutId(context), parent,
Jason Monk16fbd9d2017-04-27 14:28:49 -04001185 false);
Jason Monk361915c2017-03-21 20:33:59 -04001186
1187 ImageView icon = (ImageView) v.findViewById(R.id.icon);
1188 TextView messageView = (TextView) v.findViewById(R.id.message);
Aaron Heuckroth3f2d8b52019-04-05 13:27:51 -04001189 messageView.setSelected(true); // necessary for marquee to work
Jason Monk361915c2017-03-21 20:33:59 -04001190
Jason Monk361915c2017-03-21 20:33:59 -04001191 if (mIcon != null) {
1192 icon.setImageDrawable(mIcon);
1193 icon.setScaleType(ScaleType.CENTER_CROP);
1194 } else if (mIconResId != 0) {
1195 icon.setImageDrawable(context.getDrawable(mIconResId));
1196 }
1197 if (mMessage != null) {
1198 messageView.setText(mMessage);
1199 } else {
1200 messageView.setText(mMessageResId);
1201 }
1202
1203 return v;
1204 }
1205 }
1206
1207 /**
1208 * A toggle action knows whether it is on or off, and displays an icon
1209 * and status message accordingly.
1210 */
1211 private static abstract class ToggleAction implements Action {
1212
1213 enum State {
1214 Off(false),
1215 TurningOn(true),
1216 TurningOff(true),
1217 On(false);
1218
1219 private final boolean inTransition;
1220
1221 State(boolean intermediate) {
1222 inTransition = intermediate;
1223 }
1224
1225 public boolean inTransition() {
1226 return inTransition;
1227 }
1228 }
1229
1230 protected State mState = State.Off;
1231
1232 // prefs
1233 protected int mEnabledIconResId;
1234 protected int mDisabledIconResid;
1235 protected int mMessageResId;
1236 protected int mEnabledStatusMessageResId;
1237 protected int mDisabledStatusMessageResId;
1238
1239 /**
Jason Monk16fbd9d2017-04-27 14:28:49 -04001240 * @param enabledIconResId The icon for when this action is on.
1241 * @param disabledIconResid The icon for when this action is off.
1242 * @param message The general information message, e.g 'Silent Mode'
1243 * @param enabledStatusMessageResId The on status message, e.g 'sound disabled'
Jason Monk361915c2017-03-21 20:33:59 -04001244 * @param disabledStatusMessageResId The off status message, e.g. 'sound enabled'
1245 */
1246 public ToggleAction(int enabledIconResId,
1247 int disabledIconResid,
1248 int message,
1249 int enabledStatusMessageResId,
1250 int disabledStatusMessageResId) {
1251 mEnabledIconResId = enabledIconResId;
1252 mDisabledIconResid = disabledIconResid;
1253 mMessageResId = message;
1254 mEnabledStatusMessageResId = enabledStatusMessageResId;
1255 mDisabledStatusMessageResId = disabledStatusMessageResId;
1256 }
1257
1258 /**
1259 * Override to make changes to resource IDs just before creating the
1260 * View.
1261 */
1262 void willCreate() {
1263
1264 }
1265
1266 @Override
1267 public CharSequence getLabelForAccessibility(Context context) {
1268 return context.getString(mMessageResId);
1269 }
1270
1271 public View create(Context context, View convertView, ViewGroup parent,
1272 LayoutInflater inflater) {
1273 willCreate();
1274
Koji Fukui5c010ee2019-12-24 16:12:07 +09001275 View v = inflater.inflate(com.android.systemui.R
1276 .layout.global_actions_grid_item, parent, false);
Jason Monk361915c2017-03-21 20:33:59 -04001277
1278 ImageView icon = (ImageView) v.findViewById(R.id.icon);
1279 TextView messageView = (TextView) v.findViewById(R.id.message);
Jason Monk361915c2017-03-21 20:33:59 -04001280 final boolean enabled = isEnabled();
Koji Fukui5c010ee2019-12-24 16:12:07 +09001281 boolean on = ((mState == State.On) || (mState == State.TurningOn));
Jason Monk361915c2017-03-21 20:33:59 -04001282
1283 if (messageView != null) {
Koji Fukui5c010ee2019-12-24 16:12:07 +09001284 messageView.setText(on ? mEnabledStatusMessageResId : mDisabledStatusMessageResId);
Jason Monk361915c2017-03-21 20:33:59 -04001285 messageView.setEnabled(enabled);
Aaron Heuckroth3f2d8b52019-04-05 13:27:51 -04001286 messageView.setSelected(true); // necessary for marquee to work
Jason Monk361915c2017-03-21 20:33:59 -04001287 }
1288
Jason Monk361915c2017-03-21 20:33:59 -04001289 if (icon != null) {
1290 icon.setImageDrawable(context.getDrawable(
1291 (on ? mEnabledIconResId : mDisabledIconResid)));
1292 icon.setEnabled(enabled);
1293 }
1294
Jason Monk361915c2017-03-21 20:33:59 -04001295 v.setEnabled(enabled);
1296
1297 return v;
1298 }
1299
1300 public final void onPress() {
1301 if (mState.inTransition()) {
1302 Log.w(TAG, "shouldn't be able to toggle when in transition");
1303 return;
1304 }
1305
1306 final boolean nowOn = !(mState == State.On);
1307 onToggle(nowOn);
1308 changeStateFromPress(nowOn);
1309 }
1310
1311 public boolean isEnabled() {
1312 return !mState.inTransition();
1313 }
1314
1315 /**
1316 * Implementations may override this if their state can be in on of the intermediate
1317 * states until some notification is received (e.g airplane mode is 'turning off' until
1318 * we know the wireless connections are back online
Jason Monk16fbd9d2017-04-27 14:28:49 -04001319 *
Jason Monk361915c2017-03-21 20:33:59 -04001320 * @param buttonOn Whether the button was turned on or off
1321 */
1322 protected void changeStateFromPress(boolean buttonOn) {
1323 mState = buttonOn ? State.On : State.Off;
1324 }
1325
1326 abstract void onToggle(boolean on);
1327
1328 public void updateState(State state) {
1329 mState = state;
1330 }
1331 }
1332
1333 private class SilentModeToggleAction extends ToggleAction {
1334 public SilentModeToggleAction() {
1335 super(R.drawable.ic_audio_vol_mute,
1336 R.drawable.ic_audio_vol,
1337 R.string.global_action_toggle_silent_mode,
1338 R.string.global_action_silent_mode_on_status,
1339 R.string.global_action_silent_mode_off_status);
1340 }
1341
1342 void onToggle(boolean on) {
1343 if (on) {
1344 mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
1345 } else {
1346 mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
1347 }
1348 }
1349
1350 public boolean showDuringKeyguard() {
1351 return true;
1352 }
1353
1354 public boolean showBeforeProvisioning() {
1355 return false;
1356 }
1357 }
1358
1359 private static class SilentModeTriStateAction implements Action, View.OnClickListener {
1360
Jason Monk16fbd9d2017-04-27 14:28:49 -04001361 private final int[] ITEM_IDS = {R.id.option1, R.id.option2, R.id.option3};
Jason Monk361915c2017-03-21 20:33:59 -04001362
1363 private final AudioManager mAudioManager;
1364 private final Handler mHandler;
Jason Monk361915c2017-03-21 20:33:59 -04001365
Lucas Dupin40ec6b782018-06-05 19:07:16 -07001366 SilentModeTriStateAction(AudioManager audioManager, Handler handler) {
Jason Monk361915c2017-03-21 20:33:59 -04001367 mAudioManager = audioManager;
1368 mHandler = handler;
Jason Monk361915c2017-03-21 20:33:59 -04001369 }
1370
1371 private int ringerModeToIndex(int ringerMode) {
1372 // They just happen to coincide
1373 return ringerMode;
1374 }
1375
1376 private int indexToRingerMode(int index) {
1377 // They just happen to coincide
1378 return index;
1379 }
1380
1381 @Override
1382 public CharSequence getLabelForAccessibility(Context context) {
1383 return null;
1384 }
1385
1386 public View create(Context context, View convertView, ViewGroup parent,
1387 LayoutInflater inflater) {
1388 View v = inflater.inflate(R.layout.global_actions_silent_mode, parent, false);
1389
1390 int selectedIndex = ringerModeToIndex(mAudioManager.getRingerMode());
1391 for (int i = 0; i < 3; i++) {
1392 View itemView = v.findViewById(ITEM_IDS[i]);
1393 itemView.setSelected(selectedIndex == i);
1394 // Set up click handler
1395 itemView.setTag(i);
1396 itemView.setOnClickListener(this);
1397 }
1398 return v;
1399 }
1400
1401 public void onPress() {
1402 }
1403
1404 public boolean showDuringKeyguard() {
1405 return true;
1406 }
1407
1408 public boolean showBeforeProvisioning() {
1409 return false;
1410 }
1411
1412 public boolean isEnabled() {
1413 return true;
1414 }
1415
1416 void willCreate() {
1417 }
1418
1419 public void onClick(View v) {
1420 if (!(v.getTag() instanceof Integer)) return;
1421
1422 int index = (Integer) v.getTag();
1423 mAudioManager.setRingerMode(indexToRingerMode(index));
1424 mHandler.sendEmptyMessageDelayed(MESSAGE_DISMISS, DIALOG_DISMISS_DELAY);
1425 }
1426 }
1427
1428 private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
1429 public void onReceive(Context context, Intent intent) {
1430 String action = intent.getAction();
1431 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)
1432 || Intent.ACTION_SCREEN_OFF.equals(action)) {
1433 String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY);
1434 if (!SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS.equals(reason)) {
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001435 mHandler.sendMessage(mHandler.obtainMessage(MESSAGE_DISMISS, reason));
Jason Monk361915c2017-03-21 20:33:59 -04001436 }
Jayachandran C142eae02019-12-13 19:29:20 -08001437 } else if (TelephonyManager.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED.equals(action)) {
Jason Monk361915c2017-03-21 20:33:59 -04001438 // Airplane mode can be changed after ECM exits if airplane toggle button
1439 // is pressed during ECM mode
Daniel Bright4bcbfce2020-01-09 21:58:16 -08001440 if (!(intent.getBooleanExtra(TelephonyManager.EXTRA_PHONE_IN_ECM_STATE, false))
1441 && mIsWaitingForEcmExit) {
Jason Monk361915c2017-03-21 20:33:59 -04001442 mIsWaitingForEcmExit = false;
1443 changeAirplaneModeSystemSetting(true);
1444 }
1445 }
1446 }
1447 };
1448
1449 PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
1450 @Override
1451 public void onServiceStateChanged(ServiceState serviceState) {
1452 if (!mHasTelephony) return;
1453 final boolean inAirplaneMode = serviceState.getState() == ServiceState.STATE_POWER_OFF;
1454 mAirplaneState = inAirplaneMode ? ToggleAction.State.On : ToggleAction.State.Off;
1455 mAirplaneModeOn.updateState(mAirplaneState);
1456 mAdapter.notifyDataSetChanged();
1457 }
1458 };
1459
1460 private BroadcastReceiver mRingerModeReceiver = new BroadcastReceiver() {
1461 @Override
1462 public void onReceive(Context context, Intent intent) {
1463 if (intent.getAction().equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
1464 mHandler.sendEmptyMessage(MESSAGE_REFRESH);
1465 }
1466 }
1467 };
1468
1469 private ContentObserver mAirplaneModeObserver = new ContentObserver(new Handler()) {
1470 @Override
1471 public void onChange(boolean selfChange) {
1472 onAirplaneModeChanged();
1473 }
1474 };
1475
1476 private static final int MESSAGE_DISMISS = 0;
1477 private static final int MESSAGE_REFRESH = 1;
1478 private static final int MESSAGE_SHOW = 2;
1479 private static final int DIALOG_DISMISS_DELAY = 300; // ms
1480
1481 private Handler mHandler = new Handler() {
1482 public void handleMessage(Message msg) {
1483 switch (msg.what) {
Jason Monk16fbd9d2017-04-27 14:28:49 -04001484 case MESSAGE_DISMISS:
1485 if (mDialog != null) {
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001486 if (SYSTEM_DIALOG_REASON_DREAM.equals(msg.obj)) {
1487 mDialog.dismissImmediately();
1488 } else {
1489 mDialog.dismiss();
1490 }
Jason Monk16fbd9d2017-04-27 14:28:49 -04001491 mDialog = null;
1492 }
1493 break;
1494 case MESSAGE_REFRESH:
1495 refreshSilentMode();
1496 mAdapter.notifyDataSetChanged();
1497 break;
1498 case MESSAGE_SHOW:
1499 handleShow();
1500 break;
Jason Monk361915c2017-03-21 20:33:59 -04001501 }
1502 }
1503 };
1504
1505 private void onAirplaneModeChanged() {
1506 // Let the service state callbacks handle the state.
1507 if (mHasTelephony) return;
1508
1509 boolean airplaneModeOn = Settings.Global.getInt(
Dave Mankoffc88a2d72020-01-10 15:59:31 -05001510 mContentResolver,
Jason Monk361915c2017-03-21 20:33:59 -04001511 Settings.Global.AIRPLANE_MODE_ON,
1512 0) == 1;
1513 mAirplaneState = airplaneModeOn ? ToggleAction.State.On : ToggleAction.State.Off;
1514 mAirplaneModeOn.updateState(mAirplaneState);
1515 }
1516
1517 /**
1518 * Change the airplane mode system setting
1519 */
1520 private void changeAirplaneModeSystemSetting(boolean on) {
1521 Settings.Global.putInt(
Dave Mankoffc88a2d72020-01-10 15:59:31 -05001522 mContentResolver,
Jason Monk361915c2017-03-21 20:33:59 -04001523 Settings.Global.AIRPLANE_MODE_ON,
1524 on ? 1 : 0);
1525 Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
1526 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
1527 intent.putExtra("state", on);
1528 mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
1529 if (!mHasTelephony) {
1530 mAirplaneState = on ? ToggleAction.State.On : ToggleAction.State.Off;
1531 }
1532 }
1533
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001534 private static final class ActionsDialog extends Dialog implements DialogInterface,
1535 ColorExtractor.OnColorsChangedListener {
Jason Monk361915c2017-03-21 20:33:59 -04001536
Jason Monk16fbd9d2017-04-27 14:28:49 -04001537 private final Context mContext;
1538 private final MyAdapter mAdapter;
Steve Elliott53f12ae2019-05-13 17:14:15 -04001539 private final IStatusBarService mStatusBarService;
1540 private final IBinder mToken = new Binder();
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001541 private MultiListLayout mGlobalActionsLayout;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001542 private Drawable mBackgroundDrawable;
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001543 private final SysuiColorExtractor mColorExtractor;
Steve Elliott9b87a442019-03-05 10:24:16 -05001544 private final GlobalActionsPanelPlugin.PanelViewController mPanelController;
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001545 private boolean mKeyguardShowing;
Beverly526d2d62018-08-15 12:55:33 -04001546 private boolean mShowing;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001547 private float mScrimAlpha;
Steve Elliott48f75db2019-05-03 15:03:38 -04001548 private ResetOrientationData mResetOrientationData;
Steve Elliottff2c0d92019-07-30 15:09:54 -04001549 private boolean mHadTopUi;
wilsonshihe8321942019-10-18 18:39:46 +08001550 private final NotificationShadeWindowController mNotificationShadeWindowController;
Lucas Dupin991415e2019-11-25 17:48:58 -08001551 private final BlurUtils mBlurUtils;
Matt Pietal22231792020-01-23 09:51:09 -05001552
1553 private ControlsUiController mControlsUiController;
1554 private ViewGroup mControlsView;
Jason Monk16fbd9d2017-04-27 14:28:49 -04001555
Aaron Heuckrothf19d2722019-03-11 17:06:02 -04001556 ActionsDialog(Context context, MyAdapter adapter,
Lucas Dupin991415e2019-11-25 17:48:58 -08001557 GlobalActionsPanelPlugin.PanelViewController plugin, BlurUtils blurUtils,
1558 SysuiColorExtractor sysuiColorExtractor, IStatusBarService statusBarService,
1559 NotificationShadeWindowController notificationShadeWindowController,
Matt Pietal22231792020-01-23 09:51:09 -05001560 ControlsUiController controlsUiController) {
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001561 super(context, com.android.systemui.R.style.Theme_SystemUI_Dialog_GlobalActions);
Lucas Dupin448786c2017-07-24 17:44:25 -07001562 mContext = context;
Jason Monk16fbd9d2017-04-27 14:28:49 -04001563 mAdapter = adapter;
Lucas Dupin991415e2019-11-25 17:48:58 -08001564 mBlurUtils = blurUtils;
1565 mColorExtractor = sysuiColorExtractor;
1566 mStatusBarService = statusBarService;
1567 mNotificationShadeWindowController = notificationShadeWindowController;
Matt Pietal22231792020-01-23 09:51:09 -05001568 mControlsUiController = controlsUiController;
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001569
1570 // Window initialization
1571 Window window = getWindow();
1572 window.requestFeature(Window.FEATURE_NO_TITLE);
Adrian Roosedfab3b2018-03-08 18:39:20 +01001573 // Inflate the decor view, so the attributes below are not overwritten by the theme.
1574 window.getDecorView();
1575 window.getAttributes().systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1576 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1577 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1578 window.setLayout(MATCH_PARENT, MATCH_PARENT);
1579 window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
Alison Cichowlas4f19f4a2017-07-25 10:56:16 -04001580 window.addFlags(
1581 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001582 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
Adrian Roosedfab3b2018-03-08 18:39:20 +01001583 | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001584 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
1585 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
1586 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001587 window.setType(WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY);
Tiger Huang52724442020-01-20 21:38:42 +08001588 window.getAttributes().setFitInsetsTypes(0 /* types */);
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001589 setTitle(R.string.global_actions);
Steve Elliott9b87a442019-03-05 10:24:16 -05001590
1591 mPanelController = plugin;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001592 initializeLayout();
Steve Elliott9b87a442019-03-05 10:24:16 -05001593 }
1594
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001595 private boolean shouldUsePanel() {
Aran Ink3f594552019-05-13 14:29:35 -04001596 return mPanelController != null && mPanelController.getPanelContent() != null;
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001597 }
1598
1599 private void initializePanel() {
Steve Elliott48f75db2019-05-03 15:03:38 -04001600 int rotation = RotationUtils.getRotation(mContext);
1601 boolean rotationLocked = RotationPolicy.isRotationLocked(mContext);
1602 if (rotation != RotationUtils.ROTATION_NONE) {
1603 if (rotationLocked) {
1604 if (mResetOrientationData == null) {
1605 mResetOrientationData = new ResetOrientationData();
1606 mResetOrientationData.locked = true;
1607 mResetOrientationData.rotation = rotation;
1608 }
1609
1610 // Unlock rotation, so user can choose to rotate to portrait to see the panel.
Steve Elliotte05817f2019-05-17 14:39:53 -04001611 // This call is posted so that the rotation does not change until post-layout,
1612 // otherwise onConfigurationChanged() may not get invoked.
1613 mGlobalActionsLayout.post(() ->
1614 RotationPolicy.setRotationLockAtAngle(
1615 mContext, false, RotationUtils.ROTATION_NONE));
Steve Elliott48f75db2019-05-03 15:03:38 -04001616 }
1617 } else {
1618 if (!rotationLocked) {
1619 if (mResetOrientationData == null) {
1620 mResetOrientationData = new ResetOrientationData();
1621 mResetOrientationData.locked = false;
1622 }
1623
1624 // Lock to portrait, so the user doesn't accidentally hide the panel.
Steve Elliotte05817f2019-05-17 14:39:53 -04001625 // This call is posted so that the rotation does not change until post-layout,
1626 // otherwise onConfigurationChanged() may not get invoked.
1627 mGlobalActionsLayout.post(() ->
1628 RotationPolicy.setRotationLockAtAngle(
1629 mContext, true, RotationUtils.ROTATION_NONE));
Steve Elliott48f75db2019-05-03 15:03:38 -04001630 }
1631
Steve Elliott53f12ae2019-05-13 17:14:15 -04001632 // Disable rotation suggestions, if enabled
1633 setRotationSuggestionsEnabled(false);
1634
Steve Elliott300b48f2019-05-29 14:13:50 -04001635 FrameLayout panelContainer =
1636 findViewById(com.android.systemui.R.id.global_actions_panel_container);
Steve Elliott48f75db2019-05-03 15:03:38 -04001637 FrameLayout.LayoutParams panelParams =
1638 new FrameLayout.LayoutParams(
1639 FrameLayout.LayoutParams.MATCH_PARENT,
Steve Elliott300b48f2019-05-29 14:13:50 -04001640 FrameLayout.LayoutParams.MATCH_PARENT);
Steve Elliott48f75db2019-05-03 15:03:38 -04001641 panelContainer.addView(mPanelController.getPanelContent(), panelParams);
Steve Elliott48f75db2019-05-03 15:03:38 -04001642 }
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001643 }
1644
1645 private void initializeLayout() {
1646 setContentView(getGlobalActionsLayoutId(mContext));
Steve Elliott300b48f2019-05-29 14:13:50 -04001647 fixNavBarClipping();
Matt Pietal22231792020-01-23 09:51:09 -05001648 mControlsView = findViewById(com.android.systemui.R.id.global_actions_controls);
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001649 mGlobalActionsLayout = findViewById(com.android.systemui.R.id.global_actions_view);
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001650 mGlobalActionsLayout.setOutsideTouchListener(view -> dismiss());
Steve Elliott300b48f2019-05-29 14:13:50 -04001651 ((View) mGlobalActionsLayout.getParent()).setOnClickListener(view -> dismiss());
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001652 mGlobalActionsLayout.setListViewAccessibilityDelegate(new View.AccessibilityDelegate() {
Phil Weaver9054e092018-04-27 16:28:50 -07001653 @Override
1654 public boolean dispatchPopulateAccessibilityEvent(
1655 View host, AccessibilityEvent event) {
1656 // Populate the title here, just as Activity does
1657 event.getText().add(mContext.getString(R.string.global_actions));
1658 return true;
1659 }
1660 });
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001661 mGlobalActionsLayout.setRotationListener(this::onRotate);
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001662 mGlobalActionsLayout.setAdapter(mAdapter);
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001663
Steve Elliott86ef6282019-05-08 14:45:04 -04001664 if (shouldUsePanel()) {
Steve Elliottc59eb342019-04-23 16:59:06 -04001665 initializePanel();
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001666 }
Steve Elliott86ef6282019-05-08 14:45:04 -04001667 if (mBackgroundDrawable == null) {
1668 mBackgroundDrawable = new ScrimDrawable();
Matt Pietale0661b62020-01-29 14:35:31 -05001669 mScrimAlpha = 0.8f;
Steve Elliott86ef6282019-05-08 14:45:04 -04001670 }
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001671 getWindow().setBackgroundDrawable(mBackgroundDrawable);
Steve Elliott9b87a442019-03-05 10:24:16 -05001672 }
1673
Steve Elliott300b48f2019-05-29 14:13:50 -04001674 private void fixNavBarClipping() {
1675 ViewGroup content = findViewById(android.R.id.content);
1676 content.setClipChildren(false);
1677 content.setClipToPadding(false);
1678 ViewGroup contentParent = (ViewGroup) content.getParent();
1679 contentParent.setClipChildren(false);
1680 contentParent.setClipToPadding(false);
1681 }
1682
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001683 private int getGlobalActionsLayoutId(Context context) {
Matt Pietal22231792020-01-23 09:51:09 -05001684 if (mControlsUiController != null) {
Matt Pietalfd3b6cb2020-01-08 09:43:54 -05001685 return com.android.systemui.R.layout.global_actions_grid_v2;
1686 }
1687
Steve Elliottdc165632019-05-23 14:26:31 -04001688 int rotation = RotationUtils.getRotation(context);
1689 boolean useGridLayout = isForceGridEnabled(context)
1690 || (shouldUsePanel() && rotation == RotationUtils.ROTATION_NONE);
1691 if (rotation == RotationUtils.ROTATION_SEASCAPE) {
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001692 if (useGridLayout) {
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001693 return com.android.systemui.R.layout.global_actions_grid_seascape;
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001694 } else {
1695 return com.android.systemui.R.layout.global_actions_column_seascape;
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001696 }
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001697 } else {
1698 if (useGridLayout) {
1699 return com.android.systemui.R.layout.global_actions_grid;
1700 } else {
1701 return com.android.systemui.R.layout.global_actions_column;
1702 }
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001703 }
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001704 }
1705
Jason Monk361915c2017-03-21 20:33:59 -04001706 @Override
1707 protected void onStart() {
1708 super.setCanceledOnTouchOutside(true);
1709 super.onStart();
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001710 mGlobalActionsLayout.updateList();
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001711
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001712 if (mBackgroundDrawable instanceof ScrimDrawable) {
Steve Elliott9b87a442019-03-05 10:24:16 -05001713 mColorExtractor.addOnColorsChangedListener(this);
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001714 GradientColors colors = mColorExtractor.getNeutralColors();
Steve Elliott9b87a442019-03-05 10:24:16 -05001715 updateColors(colors, false /* animate */);
1716 }
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001717 }
1718
1719 /**
1720 * Updates background and system bars according to current GradientColors.
1721 * @param colors Colors and hints to use.
1722 * @param animate Interpolates gradient if true, just sets otherwise.
1723 */
1724 private void updateColors(GradientColors colors, boolean animate) {
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001725 if (!(mBackgroundDrawable instanceof ScrimDrawable)) {
Steve Elliott9b87a442019-03-05 10:24:16 -05001726 return;
1727 }
Matt Pietale0661b62020-01-29 14:35:31 -05001728 ((ScrimDrawable) mBackgroundDrawable).setColor(Color.BLACK, animate);
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001729 View decorView = getWindow().getDecorView();
1730 if (colors.supportsDarkText()) {
1731 decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR |
Steve Elliott9b87a442019-03-05 10:24:16 -05001732 View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001733 } else {
1734 decorView.setSystemUiVisibility(0);
1735 }
Jason Monk361915c2017-03-21 20:33:59 -04001736 }
1737
1738 @Override
Jason Monk16fbd9d2017-04-27 14:28:49 -04001739 protected void onStop() {
1740 super.onStop();
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001741 mColorExtractor.removeOnColorsChangedListener(this);
Jason Monk16fbd9d2017-04-27 14:28:49 -04001742 }
1743
1744 @Override
1745 public void show() {
1746 super.show();
Beverly526d2d62018-08-15 12:55:33 -04001747 mShowing = true;
wilsonshihe8321942019-10-18 18:39:46 +08001748 mHadTopUi = mNotificationShadeWindowController.getForceHasTopUi();
1749 mNotificationShadeWindowController.setForceHasTopUi(true);
Steve Elliott9b87a442019-03-05 10:24:16 -05001750 mBackgroundDrawable.setAlpha(0);
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001751 mGlobalActionsLayout.setTranslationX(mGlobalActionsLayout.getAnimationOffsetX());
1752 mGlobalActionsLayout.setTranslationY(mGlobalActionsLayout.getAnimationOffsetY());
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001753 mGlobalActionsLayout.setAlpha(0);
1754 mGlobalActionsLayout.animate()
Jason Monk16fbd9d2017-04-27 14:28:49 -04001755 .alpha(1)
1756 .translationX(0)
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001757 .translationY(0)
Jason Monk16fbd9d2017-04-27 14:28:49 -04001758 .setDuration(300)
Lucas Dupinde9db422017-07-19 17:15:41 -07001759 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001760 .setUpdateListener(animation -> {
Lucas Dupin991415e2019-11-25 17:48:58 -08001761 float animatedValue = animation.getAnimatedFraction();
1762 int alpha = (int) (animatedValue * mScrimAlpha * 255);
Steve Elliott9b87a442019-03-05 10:24:16 -05001763 mBackgroundDrawable.setAlpha(alpha);
Lucas Dupin991415e2019-11-25 17:48:58 -08001764 mBlurUtils.applyBlur(mGlobalActionsLayout.getViewRootImpl(),
1765 mBlurUtils.radiusForRatio(animatedValue));
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001766 })
Jason Monk16fbd9d2017-04-27 14:28:49 -04001767 .start();
Matt Pietal22231792020-01-23 09:51:09 -05001768 if (mControlsUiController != null) {
1769 mControlsUiController.show(mControlsView);
1770 }
Jason Monk16fbd9d2017-04-27 14:28:49 -04001771 }
1772
1773 @Override
1774 public void dismiss() {
Beverly526d2d62018-08-15 12:55:33 -04001775 if (!mShowing) {
1776 return;
1777 }
1778 mShowing = false;
Matt Pietal22231792020-01-23 09:51:09 -05001779 if (mControlsUiController != null) mControlsUiController.hide();
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001780 mGlobalActionsLayout.setTranslationX(0);
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001781 mGlobalActionsLayout.setTranslationY(0);
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001782 mGlobalActionsLayout.setAlpha(1);
1783 mGlobalActionsLayout.animate()
Jason Monk16fbd9d2017-04-27 14:28:49 -04001784 .alpha(0)
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001785 .translationX(mGlobalActionsLayout.getAnimationOffsetX())
1786 .translationY(mGlobalActionsLayout.getAnimationOffsetY())
Jason Monk16fbd9d2017-04-27 14:28:49 -04001787 .setDuration(300)
Steve Elliottff2c0d92019-07-30 15:09:54 -04001788 .withEndAction(this::completeDismiss)
Jason Monk16fbd9d2017-04-27 14:28:49 -04001789 .setInterpolator(new LogAccelerateInterpolator())
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001790 .setUpdateListener(animation -> {
Lucas Dupin991415e2019-11-25 17:48:58 -08001791 float animatedValue = 1f - animation.getAnimatedFraction();
1792 int alpha = (int) (animatedValue * mScrimAlpha * 255);
Steve Elliott9b87a442019-03-05 10:24:16 -05001793 mBackgroundDrawable.setAlpha(alpha);
Lucas Dupin991415e2019-11-25 17:48:58 -08001794 mBlurUtils.applyBlur(mGlobalActionsLayout.getViewRootImpl(),
1795 mBlurUtils.radiusForRatio(animatedValue));
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001796 })
Jason Monk16fbd9d2017-04-27 14:28:49 -04001797 .start();
Steve Elliott48f75db2019-05-03 15:03:38 -04001798 dismissPanel();
1799 resetOrientation();
Jason Monk16fbd9d2017-04-27 14:28:49 -04001800 }
1801
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001802 void dismissImmediately() {
Beverly526d2d62018-08-15 12:55:33 -04001803 mShowing = false;
Matt Pietal019feaa2020-01-31 14:51:37 -05001804 if (mControlsUiController != null) mControlsUiController.hide();
Steve Elliott48f75db2019-05-03 15:03:38 -04001805 dismissPanel();
1806 resetOrientation();
Steve Elliottff2c0d92019-07-30 15:09:54 -04001807 completeDismiss();
1808 }
1809
1810 private void completeDismiss() {
wilsonshihe8321942019-10-18 18:39:46 +08001811 mNotificationShadeWindowController.setForceHasTopUi(mHadTopUi);
Steve Elliottff2c0d92019-07-30 15:09:54 -04001812 super.dismiss();
Steve Elliott48f75db2019-05-03 15:03:38 -04001813 }
1814
1815 private void dismissPanel() {
Steve Elliott2d206d32019-03-14 16:30:33 -04001816 if (mPanelController != null) {
1817 mPanelController.onDismissed();
1818 }
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001819 }
1820
Steve Elliott53f12ae2019-05-13 17:14:15 -04001821 private void setRotationSuggestionsEnabled(boolean enabled) {
1822 try {
1823 final int userId = Binder.getCallingUserHandle().getIdentifier();
1824 final int what = enabled
1825 ? StatusBarManager.DISABLE2_NONE
1826 : StatusBarManager.DISABLE2_ROTATE_SUGGESTIONS;
1827 mStatusBarService.disable2ForUser(what, mToken, mContext.getPackageName(), userId);
1828 } catch (RemoteException ex) {
1829 throw ex.rethrowFromSystemServer();
1830 }
1831 }
1832
Steve Elliott48f75db2019-05-03 15:03:38 -04001833 private void resetOrientation() {
1834 if (mResetOrientationData != null) {
1835 RotationPolicy.setRotationLockAtAngle(mContext, mResetOrientationData.locked,
1836 mResetOrientationData.rotation);
1837 }
Steve Elliott53f12ae2019-05-13 17:14:15 -04001838 setRotationSuggestionsEnabled(true);
Steve Elliott48f75db2019-05-03 15:03:38 -04001839 }
1840
Jason Monk361915c2017-03-21 20:33:59 -04001841 @Override
Lucas Dupin7aaa3532017-05-28 08:51:07 -07001842 public void onColorsChanged(ColorExtractor extractor, int which) {
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001843 if (mKeyguardShowing) {
1844 if ((WallpaperManager.FLAG_LOCK & which) != 0) {
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001845 updateColors(extractor.getColors(WallpaperManager.FLAG_LOCK),
1846 true /* animate */);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001847 }
1848 } else {
1849 if ((WallpaperManager.FLAG_SYSTEM & which) != 0) {
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001850 updateColors(extractor.getColors(WallpaperManager.FLAG_SYSTEM),
1851 true /* animate */);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001852 }
1853 }
1854 }
1855
1856 public void setKeyguardShowing(boolean keyguardShowing) {
1857 mKeyguardShowing = keyguardShowing;
1858 }
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001859
Aaron Heuckroth4ef3a542019-04-01 14:17:23 -04001860 public void refreshDialog() {
1861 initializeLayout();
1862 mGlobalActionsLayout.updateList();
1863 }
1864
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001865 public void onRotate(int from, int to) {
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001866 if (mShowing) {
Aaron Heuckroth4ef3a542019-04-01 14:17:23 -04001867 refreshDialog();
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001868 }
1869 }
Steve Elliott48f75db2019-05-03 15:03:38 -04001870
1871 private static class ResetOrientationData {
1872 public boolean locked;
1873 public int rotation;
1874 }
Jason Monk361915c2017-03-21 20:33:59 -04001875 }
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001876
1877 /**
Aran Ink93dd25c2019-05-09 14:42:14 -04001878 * Determines whether or not debug mode has been activated for the Global Actions Panel.
1879 */
1880 private static boolean isPanelDebugModeEnabled(Context context) {
1881 return Settings.Secure.getInt(context.getContentResolver(),
1882 Settings.Secure.GLOBAL_ACTIONS_PANEL_DEBUG_ENABLED, 0) == 1;
1883 }
1884
1885 /**
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001886 * Determines whether or not the Global Actions menu should be forced to
1887 * use the newer grid-style layout.
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001888 */
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001889 private static boolean isForceGridEnabled(Context context) {
Aran Ink93dd25c2019-05-09 14:42:14 -04001890 return isPanelDebugModeEnabled(context);
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001891 }
Aaron Heuckrothf19d2722019-03-11 17:06:02 -04001892
Aaron Heuckrothf19d2722019-03-11 17:06:02 -04001893
1894 /**
1895 * Determines whether the Global Actions menu should use a separated view for emergency actions.
1896 */
1897 private static boolean shouldUseSeparatedView() {
1898 return true;
1899 }
Matt Pietalfd3b6cb2020-01-08 09:43:54 -05001900
Matt Pietale0661b62020-01-29 14:35:31 -05001901 private boolean shouldShowControls() {
1902 return isCurrentUserOwner()
1903 && !mKeyguardManager.isDeviceLocked()
1904 && Settings.Secure.getInt(mContext.getContentResolver(),
1905 "systemui.controls_available", 0) == 1;
Matt Pietalfd3b6cb2020-01-08 09:43:54 -05001906 }
Jason Monk361915c2017-03-21 20:33:59 -04001907}