blob: 80d776a59235c2dece0c2b6072aeb86f7c7fdf52 [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;
43import android.graphics.drawable.Drawable;
44import android.media.AudioManager;
45import android.net.ConnectivityManager;
Steve Elliott53f12ae2019-05-13 17:14:15 -040046import android.os.Binder;
Jason Monk361915c2017-03-21 20:33:59 -040047import android.os.Handler;
Steve Elliott53f12ae2019-05-13 17:14:15 -040048import android.os.IBinder;
Jason Monk361915c2017-03-21 20:33:59 -040049import android.os.Message;
50import android.os.RemoteException;
Jason Monk361915c2017-03-21 20:33:59 -040051import android.os.SystemProperties;
52import android.os.UserHandle;
53import android.os.UserManager;
54import android.os.Vibrator;
55import android.provider.Settings;
Jason Monk361915c2017-03-21 20:33:59 -040056import android.service.dreams.IDreamManager;
Inseob Kim5e82f732019-11-08 15:08:38 +090057import android.sysprop.TelephonyProperties;
Fan Zhangf9914762019-11-01 15:58:38 -070058import android.telecom.TelecomManager;
Jason Monk361915c2017-03-21 20:33:59 -040059import android.telephony.PhoneStateListener;
60import android.telephony.ServiceState;
61import android.telephony.TelephonyManager;
Jason Monk361915c2017-03-21 20:33:59 -040062import android.util.ArraySet;
yuanjiahsu88363e92018-09-06 19:23:52 +080063import android.util.FeatureFlagUtils;
Jason Monk361915c2017-03-21 20:33:59 -040064import android.util.Log;
Lucas Dupin448786c2017-07-24 17:44:25 -070065import android.view.ContextThemeWrapper;
Jason Monk361915c2017-03-21 20:33:59 -040066import android.view.LayoutInflater;
67import android.view.View;
68import android.view.ViewGroup;
Lucas Dupinc1cc7592017-05-22 15:56:16 -070069import android.view.Window;
Jason Monk361915c2017-03-21 20:33:59 -040070import android.view.WindowManager;
71import android.view.WindowManagerGlobal;
72import android.view.accessibility.AccessibilityEvent;
Steve Elliott9b87a442019-03-05 10:24:16 -050073import android.widget.FrameLayout;
Jason Monk361915c2017-03-21 20:33:59 -040074import android.widget.ImageView;
75import android.widget.ImageView.ScaleType;
Jason Monk361915c2017-03-21 20:33:59 -040076import android.widget.TextView;
77
Charles He9851a8d2017-10-10 17:31:30 +010078import com.android.internal.R;
79import com.android.internal.colorextraction.ColorExtractor;
80import com.android.internal.colorextraction.ColorExtractor.GradientColors;
Lucas Dupin2bd3af62019-03-25 17:44:28 -070081import com.android.internal.colorextraction.drawable.ScrimDrawable;
Charles He9851a8d2017-10-10 17:31:30 +010082import com.android.internal.logging.MetricsLogger;
83import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Steve Elliott53f12ae2019-05-13 17:14:15 -040084import com.android.internal.statusbar.IStatusBarService;
Charles He9851a8d2017-10-10 17:31:30 +010085import com.android.internal.util.EmergencyAffordanceManager;
Beth Thibodeau5898ac42018-10-26 13:00:09 -040086import com.android.internal.util.ScreenRecordHelper;
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -050087import com.android.internal.util.ScreenshotHelper;
Steve Elliott48f75db2019-05-03 15:03:38 -040088import com.android.internal.view.RotationPolicy;
Charles He9851a8d2017-10-10 17:31:30 +010089import com.android.internal.widget.LockPatternUtils;
90import com.android.systemui.Dependency;
Charles He9851a8d2017-10-10 17:31:30 +010091import com.android.systemui.Interpolators;
Aaron Heuckrothf708d472019-01-10 16:54:51 -050092import com.android.systemui.MultiListLayout;
Aaron Heuckroth57d60d22019-03-05 14:00:12 -050093import com.android.systemui.MultiListLayout.MultiListAdapter;
Fabian Kozynskiff5e91f2019-09-24 15:38:08 -040094import com.android.systemui.broadcast.BroadcastDispatcher;
Charles He9851a8d2017-10-10 17:31:30 +010095import com.android.systemui.colorextraction.SysuiColorExtractor;
Matt Pietal22231792020-01-23 09:51:09 -050096import com.android.systemui.controls.ui.ControlsUiController;
Dave Mankoffc88a2d72020-01-10 15:59:31 -050097import com.android.systemui.dagger.qualifiers.Main;
Steve Elliott4c868852019-03-14 16:25:41 -040098import com.android.systemui.plugins.ActivityStarter;
Charles He9851a8d2017-10-10 17:31:30 +010099import com.android.systemui.plugins.GlobalActions.GlobalActionsManager;
Steve Elliott9b87a442019-03-05 10:24:16 -0500100import com.android.systemui.plugins.GlobalActionsPanelPlugin;
Lucas Dupin991415e2019-11-25 17:48:58 -0800101import com.android.systemui.statusbar.BlurUtils;
Matt Pietal22231792020-01-23 09:51:09 -0500102import com.android.systemui.statusbar.phone.NotificationShadeWindowController;
Steve Elliottbfa314a2019-03-06 13:53:19 -0500103import com.android.systemui.statusbar.phone.ScrimController;
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
Matt Pietal22231792020-01-23 09:51:09 -0500462 boolean showControls = !mKeyguardManager.isDeviceLocked() && isControlsEnabled(mContext);
463
Lucas Dupin991415e2019-11-25 17:48:58 -0800464 ActionsDialog dialog = new ActionsDialog(mContext, mAdapter, panelViewController,
465 mBlurUtils, mSysuiColorExtractor, mStatusBarService,
Matt Pietal22231792020-01-23 09:51:09 -0500466 mNotificationShadeWindowController,
467 showControls ? mControlsUiController : null);
Jason Monk361915c2017-03-21 20:33:59 -0400468 dialog.setCanceledOnTouchOutside(false); // Handled by the custom class.
Lucas Dupinc1cc7592017-05-22 15:56:16 -0700469 dialog.setKeyguardShowing(mKeyguardShowing);
Jason Monk361915c2017-03-21 20:33:59 -0400470
471 dialog.setOnDismissListener(this);
Shaotang Li786da902018-08-02 11:18:00 +0800472 dialog.setOnShowListener(this);
Jason Monk361915c2017-03-21 20:33:59 -0400473
474 return dialog;
475 }
476
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800477 private boolean shouldDisplayLockdown() {
478 int userId = getCurrentUser().id;
479 // Lockdown is meaningless without a place to go.
480 if (!mKeyguardManager.isDeviceSecure(userId)) {
481 return false;
482 }
483
484 // Only show the lockdown button if the device isn't locked down (for whatever reason).
485 int state = mLockPatternUtils.getStrongAuthForUser(userId);
486 return (state == STRONG_AUTH_NOT_REQUIRED
487 || state == SOME_AUTH_REQUIRED_AFTER_USER_REQUEST);
488 }
489
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700490 @Override
491 public void onUiModeChanged() {
492 mContext.getTheme().applyStyle(mContext.getThemeResId(), true);
Lucas Dupina4e12ba2019-04-18 11:56:28 -0700493 if (mDialog != null && mDialog.isShowing()) {
Aaron Heuckroth4ef3a542019-04-01 14:17:23 -0400494 mDialog.refreshDialog();
495 }
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700496 }
497
498 public void destroy() {
499 Dependency.get(ConfigurationController.class).removeCallback(this);
500 }
501
Jason Monk361915c2017-03-21 20:33:59 -0400502 private final class PowerAction extends SinglePressAction implements LongPressAction {
503 private PowerAction() {
504 super(R.drawable.ic_lock_power_off,
Jason Monk16fbd9d2017-04-27 14:28:49 -0400505 R.string.global_action_power_off);
Jason Monk361915c2017-03-21 20:33:59 -0400506 }
507
508 @Override
509 public boolean onLongPress() {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500510 if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) {
Jason Monk361915c2017-03-21 20:33:59 -0400511 mWindowManagerFuncs.reboot(true);
512 return true;
513 }
514 return false;
515 }
516
517 @Override
518 public boolean showDuringKeyguard() {
519 return true;
520 }
521
522 @Override
523 public boolean showBeforeProvisioning() {
524 return true;
525 }
526
527 @Override
528 public void onPress() {
529 // shutdown by making sure radio and power are handled accordingly.
530 mWindowManagerFuncs.shutdown();
531 }
532 }
533
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400534 private abstract class EmergencyAction extends SinglePressAction {
535 EmergencyAction(int iconResId, int messageResId) {
536 super(iconResId, messageResId);
537 }
538
539 @Override
540 public boolean shouldBeSeparated() {
Matt Pietalfd3b6cb2020-01-08 09:43:54 -0500541 return !isControlsEnabled(mContext);
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400542 }
543
544 @Override
545 public View create(
546 Context context, View convertView, ViewGroup parent, LayoutInflater inflater) {
547 View v = super.create(context, convertView, parent, inflater);
548 int textColor;
549 if (shouldBeSeparated()) {
550 textColor = v.getResources().getColor(
551 com.android.systemui.R.color.global_actions_alert_text);
552 } else {
553 textColor = v.getResources().getColor(
554 com.android.systemui.R.color.global_actions_text);
555 }
556 TextView messageView = v.findViewById(R.id.message);
557 messageView.setTextColor(textColor);
Aaron Heuckroth3f2d8b52019-04-05 13:27:51 -0400558 messageView.setSelected(true); // necessary for marquee to work
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400559 ImageView icon = (ImageView) v.findViewById(R.id.icon);
560 icon.getDrawable().setTint(textColor);
561 return v;
562 }
563
564 @Override
565 public boolean showDuringKeyguard() {
566 return true;
567 }
568
569 @Override
570 public boolean showBeforeProvisioning() {
571 return true;
572 }
573 }
574
575 private class EmergencyAffordanceAction extends EmergencyAction {
576 EmergencyAffordanceAction() {
577 super(R.drawable.emergency_icon,
578 R.string.global_action_emergency);
579 }
580
581 @Override
582 public void onPress() {
583 mEmergencyAffordanceManager.performEmergencyCall();
584 }
585 }
586
587 private class EmergencyDialerAction extends EmergencyAction {
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800588 private EmergencyDialerAction() {
Aran Ink50195262019-05-30 10:55:37 -0400589 super(com.android.systemui.R.drawable.ic_emergency_star,
Wesley.CW Wang3004fcb2018-06-15 16:24:57 +0800590 R.string.global_action_emergency);
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800591 }
592
593 @Override
594 public void onPress() {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500595 mMetricsLogger.action(MetricsEvent.ACTION_EMERGENCY_DIALER_FROM_POWER_MENU);
596 Intent intent = mTelecomManager.createLaunchEmergencyDialerIntent(null /* number */);
Leo Hsue4cc3122019-03-06 15:25:28 +0800597 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
598 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
599 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
Shaotang Li5c422632018-07-04 14:18:40 +0800600 intent.putExtra(EmergencyDialerConstants.EXTRA_ENTRY_TYPE,
601 EmergencyDialerConstants.ENTRY_TYPE_POWER_MENU);
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800602 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
603 }
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800604 }
605
Jason Monk361915c2017-03-21 20:33:59 -0400606 private final class RestartAction extends SinglePressAction implements LongPressAction {
607 private RestartAction() {
608 super(R.drawable.ic_restart, R.string.global_action_restart);
609 }
610
611 @Override
612 public boolean onLongPress() {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500613 if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) {
Jason Monk361915c2017-03-21 20:33:59 -0400614 mWindowManagerFuncs.reboot(true);
615 return true;
616 }
617 return false;
618 }
619
620 @Override
621 public boolean showDuringKeyguard() {
622 return true;
623 }
624
625 @Override
626 public boolean showBeforeProvisioning() {
627 return true;
628 }
629
630 @Override
631 public void onPress() {
632 mWindowManagerFuncs.reboot(false);
633 }
634 }
635
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400636 private class ScreenshotAction extends SinglePressAction implements LongPressAction {
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500637 public ScreenshotAction() {
638 super(R.drawable.ic_screenshot, R.string.global_action_screenshot);
639 }
640
641 @Override
642 public void onPress() {
643 // Add a little delay before executing, to give the
644 // dialog a chance to go away before it takes a
645 // screenshot.
646 // TODO: instead, omit global action dialog layer
647 mHandler.postDelayed(new Runnable() {
648 @Override
649 public void run() {
James O'Learyfa5bb7a2019-09-05 13:43:29 -0400650 mScreenshotHelper.takeScreenshot(1, true, true, mHandler, null);
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500651 mMetricsLogger.action(MetricsEvent.ACTION_SCREENSHOT_POWER_MENU);
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500652 }
653 }, 500);
654 }
655
656 @Override
657 public boolean showDuringKeyguard() {
658 return true;
659 }
660
661 @Override
662 public boolean showBeforeProvisioning() {
663 return false;
664 }
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400665
666 @Override
667 public boolean onLongPress() {
668 if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SCREENRECORD_LONG_PRESS)) {
669 mScreenRecordHelper.launchRecordPrompt();
670 } else {
671 onPress();
672 }
673 return true;
674 }
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500675 }
676
Jason Monk361915c2017-03-21 20:33:59 -0400677 private class BugReportAction extends SinglePressAction implements LongPressAction {
678
679 public BugReportAction() {
680 super(R.drawable.ic_lock_bugreport, R.string.bugreport_title);
681 }
682
683 @Override
684 public void onPress() {
685 // don't actually trigger the bugreport if we are running stability
686 // tests via monkey
687 if (ActivityManager.isUserAMonkey()) {
688 return;
689 }
690 // Add a little delay before executing, to give the
691 // dialog a chance to go away before it takes a
692 // screenshot.
693 mHandler.postDelayed(new Runnable() {
694 @Override
695 public void run() {
696 try {
697 // Take an "interactive" bugreport.
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500698 mMetricsLogger.action(
Jason Monk361915c2017-03-21 20:33:59 -0400699 MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_INTERACTIVE);
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500700 if (!mIActivityManager.launchBugReportHandlerApp()) {
Paul Changc40f5782019-11-04 18:55:31 +0800701 Log.w(TAG, "Bugreport handler could not be launched");
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500702 mIActivityManager.requestInteractiveBugReport();
Paul Changc40f5782019-11-04 18:55:31 +0800703 }
Jason Monk361915c2017-03-21 20:33:59 -0400704 } catch (RemoteException e) {
705 }
706 }
707 }, 500);
708 }
709
710 @Override
711 public boolean onLongPress() {
712 // don't actually trigger the bugreport if we are running stability
713 // tests via monkey
714 if (ActivityManager.isUserAMonkey()) {
715 return false;
716 }
717 try {
718 // Take a "full" bugreport.
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500719 mMetricsLogger.action(MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_FULL);
720 mIActivityManager.requestFullBugReport();
Jason Monk361915c2017-03-21 20:33:59 -0400721 } catch (RemoteException e) {
722 }
723 return false;
724 }
725
726 public boolean showDuringKeyguard() {
727 return true;
728 }
729
730 @Override
731 public boolean showBeforeProvisioning() {
732 return false;
733 }
Jason Monk361915c2017-03-21 20:33:59 -0400734 }
735
Alex Chau04458852017-11-27 18:21:23 +0000736 private final class LogoutAction extends SinglePressAction {
737 private LogoutAction() {
738 super(R.drawable.ic_logout, R.string.global_action_logout);
739 }
740
741 @Override
742 public boolean showDuringKeyguard() {
743 return true;
744 }
745
746 @Override
747 public boolean showBeforeProvisioning() {
748 return false;
749 }
750
751 @Override
752 public void onPress() {
753 // Add a little delay before executing, to give the dialog a chance to go away before
754 // switching user
755 mHandler.postDelayed(() -> {
756 try {
Alex Chauedb6a012018-01-26 12:52:43 +0000757 int currentUserId = getCurrentUser().id;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500758 mIActivityManager.switchUser(UserHandle.USER_SYSTEM);
759 mIActivityManager.stopUser(currentUserId, true /*force*/, null);
Alex Chau04458852017-11-27 18:21:23 +0000760 } catch (RemoteException re) {
761 Log.e(TAG, "Couldn't logout user " + re);
762 }
763 }, 500);
764 }
765 }
766
Jason Monk361915c2017-03-21 20:33:59 -0400767 private Action getSettingsAction() {
768 return new SinglePressAction(R.drawable.ic_settings,
769 R.string.global_action_settings) {
770
771 @Override
772 public void onPress() {
773 Intent intent = new Intent(Settings.ACTION_SETTINGS);
774 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
775 mContext.startActivity(intent);
776 }
777
778 @Override
779 public boolean showDuringKeyguard() {
780 return true;
781 }
782
783 @Override
784 public boolean showBeforeProvisioning() {
785 return true;
786 }
787 };
788 }
789
Jason Monk361915c2017-03-21 20:33:59 -0400790 private Action getAssistAction() {
791 return new SinglePressAction(R.drawable.ic_action_assist_focused,
792 R.string.global_action_assist) {
793 @Override
794 public void onPress() {
795 Intent intent = new Intent(Intent.ACTION_ASSIST);
796 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
797 mContext.startActivity(intent);
798 }
799
800 @Override
801 public boolean showDuringKeyguard() {
802 return true;
803 }
804
805 @Override
806 public boolean showBeforeProvisioning() {
807 return true;
808 }
809 };
810 }
811
812 private Action getVoiceAssistAction() {
813 return new SinglePressAction(R.drawable.ic_voice_search,
814 R.string.global_action_voice_assist) {
815 @Override
816 public void onPress() {
817 Intent intent = new Intent(Intent.ACTION_VOICE_ASSIST);
818 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
819 mContext.startActivity(intent);
820 }
821
822 @Override
823 public boolean showDuringKeyguard() {
824 return true;
825 }
826
827 @Override
828 public boolean showBeforeProvisioning() {
829 return true;
830 }
831 };
832 }
833
834 private Action getLockdownAction() {
Alison Cichowlas21125432018-05-16 15:40:45 -0400835 return new SinglePressAction(R.drawable.ic_lock_lockdown,
Jason Monk361915c2017-03-21 20:33:59 -0400836 R.string.global_action_lockdown) {
837
838 @Override
839 public void onPress() {
Chad Brubaker4f28f0d2017-09-07 14:28:13 -0700840 new LockPatternUtils(mContext)
841 .requireStrongAuth(STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN,
842 UserHandle.USER_ALL);
Jason Monk361915c2017-03-21 20:33:59 -0400843 try {
844 WindowManagerGlobal.getWindowManagerService().lockNow(null);
Pavel Grafov059021b2018-05-02 13:44:46 +0100845 // Lock profiles (if any) on the background thread.
846 final Handler bgHandler = new Handler(Dependency.get(Dependency.BG_LOOPER));
847 bgHandler.post(() -> lockProfiles());
Jason Monk361915c2017-03-21 20:33:59 -0400848 } catch (RemoteException e) {
849 Log.e(TAG, "Error while trying to lock device.", e);
850 }
851 }
852
853 @Override
854 public boolean showDuringKeyguard() {
855 return true;
856 }
857
858 @Override
859 public boolean showBeforeProvisioning() {
860 return false;
861 }
862 };
863 }
864
Pavel Grafov059021b2018-05-02 13:44:46 +0100865 private void lockProfiles() {
Pavel Grafov059021b2018-05-02 13:44:46 +0100866 final int currentUserId = getCurrentUser().id;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500867 final int[] profileIds = mUserManager.getEnabledProfileIds(currentUserId);
Pavel Grafov059021b2018-05-02 13:44:46 +0100868 for (final int id : profileIds) {
869 if (id != currentUserId) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500870 mTrustManager.setDeviceLockedForUser(id, true);
Pavel Grafov059021b2018-05-02 13:44:46 +0100871 }
872 }
873 }
874
Jason Monk361915c2017-03-21 20:33:59 -0400875 private UserInfo getCurrentUser() {
876 try {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500877 return mIActivityManager.getCurrentUser();
Jason Monk361915c2017-03-21 20:33:59 -0400878 } catch (RemoteException re) {
879 return null;
880 }
881 }
882
883 private boolean isCurrentUserOwner() {
884 UserInfo currentUser = getCurrentUser();
885 return currentUser == null || currentUser.isPrimary();
886 }
887
888 private void addUsersToMenu(ArrayList<Action> items) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500889 if (mUserManager.isUserSwitcherEnabled()) {
890 List<UserInfo> users = mUserManager.getUsers();
Jason Monk361915c2017-03-21 20:33:59 -0400891 UserInfo currentUser = getCurrentUser();
892 for (final UserInfo user : users) {
893 if (user.supportsSwitchToByUser()) {
894 boolean isCurrentUser = currentUser == null
895 ? user.id == 0 : (currentUser.id == user.id);
896 Drawable icon = user.iconPath != null ? Drawable.createFromPath(user.iconPath)
897 : null;
898 SinglePressAction switchToUser = new SinglePressAction(
899 R.drawable.ic_menu_cc, icon,
900 (user.name != null ? user.name : "Primary")
Jason Monk16fbd9d2017-04-27 14:28:49 -0400901 + (isCurrentUser ? " \u2714" : "")) {
Jason Monk361915c2017-03-21 20:33:59 -0400902 public void onPress() {
903 try {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500904 mIActivityManager.switchUser(user.id);
Jason Monk361915c2017-03-21 20:33:59 -0400905 } catch (RemoteException re) {
906 Log.e(TAG, "Couldn't switch user " + re);
907 }
908 }
909
910 public boolean showDuringKeyguard() {
911 return true;
912 }
913
914 public boolean showBeforeProvisioning() {
915 return false;
916 }
917 };
918 items.add(switchToUser);
919 }
920 }
921 }
922 }
923
924 private void prepareDialog() {
925 refreshSilentMode();
926 mAirplaneModeOn.updateState(mAirplaneState);
927 mAdapter.notifyDataSetChanged();
Jason Monk361915c2017-03-21 20:33:59 -0400928 if (mShowSilentToggle) {
929 IntentFilter filter = new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION);
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000930 mBroadcastDispatcher.registerReceiver(mRingerModeReceiver, filter);
Jason Monk361915c2017-03-21 20:33:59 -0400931 }
932 }
933
934 private void refreshSilentMode() {
935 if (!mHasVibrator) {
936 final boolean silentModeOn =
937 mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL;
Jason Monk16fbd9d2017-04-27 14:28:49 -0400938 ((ToggleAction) mSilentModeAction).updateState(
Jason Monk361915c2017-03-21 20:33:59 -0400939 silentModeOn ? ToggleAction.State.On : ToggleAction.State.Off);
940 }
941 }
942
943 /** {@inheritDoc} */
944 public void onDismiss(DialogInterface dialog) {
Steve Elliottc3147e22019-11-20 19:34:57 -0500945 if (mDialog == dialog) {
946 mDialog = null;
947 }
Jason Monk361915c2017-03-21 20:33:59 -0400948 mWindowManagerFuncs.onGlobalActionsHidden();
949 if (mShowSilentToggle) {
950 try {
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000951 mBroadcastDispatcher.unregisterReceiver(mRingerModeReceiver);
Jason Monk361915c2017-03-21 20:33:59 -0400952 } catch (IllegalArgumentException ie) {
953 // ignore this
954 Log.w(TAG, ie);
955 }
956 }
957 }
958
959 /** {@inheritDoc} */
Shaotang Li786da902018-08-02 11:18:00 +0800960 public void onShow(DialogInterface dialog) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500961 mMetricsLogger.visible(MetricsEvent.POWER_MENU);
Shaotang Li786da902018-08-02 11:18:00 +0800962 }
963
Jason Monk361915c2017-03-21 20:33:59 -0400964 /**
965 * The adapter used for the list within the global actions dialog, taking
966 * into account whether the keyguard is showing via
Jason Monk16fbd9d2017-04-27 14:28:49 -0400967 * {@link com.android.systemui.globalactions.GlobalActionsDialog#mKeyguardShowing} and whether
968 * the device is provisioned
Jason Monk361915c2017-03-21 20:33:59 -0400969 * via {@link com.android.systemui.globalactions.GlobalActionsDialog#mDeviceProvisioned}.
970 */
Aaron Heuckroth57d60d22019-03-05 14:00:12 -0500971 public class MyAdapter extends MultiListAdapter {
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -0400972 private int countItems(boolean separated) {
Jason Monk361915c2017-03-21 20:33:59 -0400973 int count = 0;
Jason Monk361915c2017-03-21 20:33:59 -0400974 for (int i = 0; i < mItems.size(); i++) {
975 final Action action = mItems.get(i);
976
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -0400977 if (shouldBeShown(action) && action.shouldBeSeparated() == separated) {
978 count++;
Jason Monk361915c2017-03-21 20:33:59 -0400979 }
Jason Monk361915c2017-03-21 20:33:59 -0400980 }
981 return count;
982 }
983
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -0400984 private boolean shouldBeShown(Action action) {
985 if (mKeyguardShowing && !action.showDuringKeyguard()) {
986 return false;
987 }
988 if (!mDeviceProvisioned && !action.showBeforeProvisioning()) {
989 return false;
990 }
991 return true;
992 }
993
994 @Override
995 public int countSeparatedItems() {
996 return countItems(true);
997 }
998
999 @Override
1000 public int countListItems() {
1001 return countItems(false);
1002 }
1003
1004 @Override
1005 public int getCount() {
1006 return countSeparatedItems() + countListItems();
1007 }
1008
Jason Monk361915c2017-03-21 20:33:59 -04001009 @Override
1010 public boolean isEnabled(int position) {
1011 return getItem(position).isEnabled();
1012 }
1013
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001014 @Override
Jason Monk361915c2017-03-21 20:33:59 -04001015 public boolean areAllItemsEnabled() {
1016 return false;
1017 }
1018
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001019 @Override
Jason Monk361915c2017-03-21 20:33:59 -04001020 public Action getItem(int position) {
Jason Monk361915c2017-03-21 20:33:59 -04001021 int filteredPos = 0;
1022 for (int i = 0; i < mItems.size(); i++) {
1023 final Action action = mItems.get(i);
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -04001024 if (!shouldBeShown(action)) {
Jason Monk361915c2017-03-21 20:33:59 -04001025 continue;
1026 }
1027 if (filteredPos == position) {
1028 return action;
1029 }
1030 filteredPos++;
1031 }
1032
1033 throw new IllegalArgumentException("position " + position
1034 + " out of range of showable actions"
1035 + ", filtered count=" + getCount()
1036 + ", keyguardshowing=" + mKeyguardShowing
1037 + ", provisioned=" + mDeviceProvisioned);
1038 }
1039
1040
1041 public long getItemId(int position) {
1042 return position;
1043 }
1044
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001045 @Override
Jason Monk361915c2017-03-21 20:33:59 -04001046 public View getView(int position, View convertView, ViewGroup parent) {
1047 Action action = getItem(position);
Jason Monk16fbd9d2017-04-27 14:28:49 -04001048 View view = action.create(mContext, convertView, parent, LayoutInflater.from(mContext));
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -04001049 view.setOnClickListener(v -> onClickItem(position));
1050 view.setOnLongClickListener(v -> onLongClickItem(position));
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 */
1138 private static abstract class SinglePressAction implements Action {
1139 private final int mIconResId;
1140 private final Drawable mIcon;
1141 private final int mMessageResId;
1142 private final CharSequence mMessage;
1143
1144 protected SinglePressAction(int iconResId, int messageResId) {
1145 mIconResId = iconResId;
1146 mMessageResId = messageResId;
1147 mMessage = null;
1148 mIcon = null;
1149 }
1150
1151 protected SinglePressAction(int iconResId, Drawable icon, CharSequence message) {
1152 mIconResId = iconResId;
1153 mMessageResId = 0;
1154 mMessage = message;
1155 mIcon = icon;
1156 }
1157
1158 public boolean isEnabled() {
1159 return true;
1160 }
1161
1162 public String getStatus() {
1163 return null;
1164 }
1165
1166 abstract public void onPress();
1167
1168 public CharSequence getLabelForAccessibility(Context context) {
1169 if (mMessage != null) {
1170 return mMessage;
1171 } else {
1172 return context.getString(mMessageResId);
1173 }
1174 }
1175
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001176 protected int getActionLayoutId(Context context) {
Matt Pietalfd3b6cb2020-01-08 09:43:54 -05001177 if (isControlsEnabled(context)) {
1178 return com.android.systemui.R.layout.global_actions_grid_item_v2;
1179 }
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001180 return com.android.systemui.R.layout.global_actions_grid_item;
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001181 }
1182
Jason Monk361915c2017-03-21 20:33:59 -04001183 public View create(
1184 Context context, View convertView, ViewGroup parent, LayoutInflater inflater) {
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001185 View v = inflater.inflate(getActionLayoutId(context), parent,
Jason Monk16fbd9d2017-04-27 14:28:49 -04001186 false);
Jason Monk361915c2017-03-21 20:33:59 -04001187
1188 ImageView icon = (ImageView) v.findViewById(R.id.icon);
1189 TextView messageView = (TextView) v.findViewById(R.id.message);
Aaron Heuckroth3f2d8b52019-04-05 13:27:51 -04001190 messageView.setSelected(true); // necessary for marquee to work
Jason Monk361915c2017-03-21 20:33:59 -04001191
Jason Monk361915c2017-03-21 20:33:59 -04001192 if (mIcon != null) {
1193 icon.setImageDrawable(mIcon);
1194 icon.setScaleType(ScaleType.CENTER_CROP);
1195 } else if (mIconResId != 0) {
1196 icon.setImageDrawable(context.getDrawable(mIconResId));
1197 }
1198 if (mMessage != null) {
1199 messageView.setText(mMessage);
1200 } else {
1201 messageView.setText(mMessageResId);
1202 }
1203
1204 return v;
1205 }
1206 }
1207
1208 /**
1209 * A toggle action knows whether it is on or off, and displays an icon
1210 * and status message accordingly.
1211 */
1212 private static abstract class ToggleAction implements Action {
1213
1214 enum State {
1215 Off(false),
1216 TurningOn(true),
1217 TurningOff(true),
1218 On(false);
1219
1220 private final boolean inTransition;
1221
1222 State(boolean intermediate) {
1223 inTransition = intermediate;
1224 }
1225
1226 public boolean inTransition() {
1227 return inTransition;
1228 }
1229 }
1230
1231 protected State mState = State.Off;
1232
1233 // prefs
1234 protected int mEnabledIconResId;
1235 protected int mDisabledIconResid;
1236 protected int mMessageResId;
1237 protected int mEnabledStatusMessageResId;
1238 protected int mDisabledStatusMessageResId;
1239
1240 /**
Jason Monk16fbd9d2017-04-27 14:28:49 -04001241 * @param enabledIconResId The icon for when this action is on.
1242 * @param disabledIconResid The icon for when this action is off.
1243 * @param message The general information message, e.g 'Silent Mode'
1244 * @param enabledStatusMessageResId The on status message, e.g 'sound disabled'
Jason Monk361915c2017-03-21 20:33:59 -04001245 * @param disabledStatusMessageResId The off status message, e.g. 'sound enabled'
1246 */
1247 public ToggleAction(int enabledIconResId,
1248 int disabledIconResid,
1249 int message,
1250 int enabledStatusMessageResId,
1251 int disabledStatusMessageResId) {
1252 mEnabledIconResId = enabledIconResId;
1253 mDisabledIconResid = disabledIconResid;
1254 mMessageResId = message;
1255 mEnabledStatusMessageResId = enabledStatusMessageResId;
1256 mDisabledStatusMessageResId = disabledStatusMessageResId;
1257 }
1258
1259 /**
1260 * Override to make changes to resource IDs just before creating the
1261 * View.
1262 */
1263 void willCreate() {
1264
1265 }
1266
1267 @Override
1268 public CharSequence getLabelForAccessibility(Context context) {
1269 return context.getString(mMessageResId);
1270 }
1271
1272 public View create(Context context, View convertView, ViewGroup parent,
1273 LayoutInflater inflater) {
1274 willCreate();
1275
Koji Fukui5c010ee2019-12-24 16:12:07 +09001276 View v = inflater.inflate(com.android.systemui.R
1277 .layout.global_actions_grid_item, parent, false);
Jason Monk361915c2017-03-21 20:33:59 -04001278
1279 ImageView icon = (ImageView) v.findViewById(R.id.icon);
1280 TextView messageView = (TextView) v.findViewById(R.id.message);
Jason Monk361915c2017-03-21 20:33:59 -04001281 final boolean enabled = isEnabled();
Koji Fukui5c010ee2019-12-24 16:12:07 +09001282 boolean on = ((mState == State.On) || (mState == State.TurningOn));
Jason Monk361915c2017-03-21 20:33:59 -04001283
1284 if (messageView != null) {
Koji Fukui5c010ee2019-12-24 16:12:07 +09001285 messageView.setText(on ? mEnabledStatusMessageResId : mDisabledStatusMessageResId);
Jason Monk361915c2017-03-21 20:33:59 -04001286 messageView.setEnabled(enabled);
Aaron Heuckroth3f2d8b52019-04-05 13:27:51 -04001287 messageView.setSelected(true); // necessary for marquee to work
Jason Monk361915c2017-03-21 20:33:59 -04001288 }
1289
Jason Monk361915c2017-03-21 20:33:59 -04001290 if (icon != null) {
1291 icon.setImageDrawable(context.getDrawable(
1292 (on ? mEnabledIconResId : mDisabledIconResid)));
1293 icon.setEnabled(enabled);
1294 }
1295
Jason Monk361915c2017-03-21 20:33:59 -04001296 v.setEnabled(enabled);
1297
1298 return v;
1299 }
1300
1301 public final void onPress() {
1302 if (mState.inTransition()) {
1303 Log.w(TAG, "shouldn't be able to toggle when in transition");
1304 return;
1305 }
1306
1307 final boolean nowOn = !(mState == State.On);
1308 onToggle(nowOn);
1309 changeStateFromPress(nowOn);
1310 }
1311
1312 public boolean isEnabled() {
1313 return !mState.inTransition();
1314 }
1315
1316 /**
1317 * Implementations may override this if their state can be in on of the intermediate
1318 * states until some notification is received (e.g airplane mode is 'turning off' until
1319 * we know the wireless connections are back online
Jason Monk16fbd9d2017-04-27 14:28:49 -04001320 *
Jason Monk361915c2017-03-21 20:33:59 -04001321 * @param buttonOn Whether the button was turned on or off
1322 */
1323 protected void changeStateFromPress(boolean buttonOn) {
1324 mState = buttonOn ? State.On : State.Off;
1325 }
1326
1327 abstract void onToggle(boolean on);
1328
1329 public void updateState(State state) {
1330 mState = state;
1331 }
1332 }
1333
1334 private class SilentModeToggleAction extends ToggleAction {
1335 public SilentModeToggleAction() {
1336 super(R.drawable.ic_audio_vol_mute,
1337 R.drawable.ic_audio_vol,
1338 R.string.global_action_toggle_silent_mode,
1339 R.string.global_action_silent_mode_on_status,
1340 R.string.global_action_silent_mode_off_status);
1341 }
1342
1343 void onToggle(boolean on) {
1344 if (on) {
1345 mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
1346 } else {
1347 mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
1348 }
1349 }
1350
1351 public boolean showDuringKeyguard() {
1352 return true;
1353 }
1354
1355 public boolean showBeforeProvisioning() {
1356 return false;
1357 }
1358 }
1359
1360 private static class SilentModeTriStateAction implements Action, View.OnClickListener {
1361
Jason Monk16fbd9d2017-04-27 14:28:49 -04001362 private final int[] ITEM_IDS = {R.id.option1, R.id.option2, R.id.option3};
Jason Monk361915c2017-03-21 20:33:59 -04001363
1364 private final AudioManager mAudioManager;
1365 private final Handler mHandler;
Jason Monk361915c2017-03-21 20:33:59 -04001366
Lucas Dupin40ec6b782018-06-05 19:07:16 -07001367 SilentModeTriStateAction(AudioManager audioManager, Handler handler) {
Jason Monk361915c2017-03-21 20:33:59 -04001368 mAudioManager = audioManager;
1369 mHandler = handler;
Jason Monk361915c2017-03-21 20:33:59 -04001370 }
1371
1372 private int ringerModeToIndex(int ringerMode) {
1373 // They just happen to coincide
1374 return ringerMode;
1375 }
1376
1377 private int indexToRingerMode(int index) {
1378 // They just happen to coincide
1379 return index;
1380 }
1381
1382 @Override
1383 public CharSequence getLabelForAccessibility(Context context) {
1384 return null;
1385 }
1386
1387 public View create(Context context, View convertView, ViewGroup parent,
1388 LayoutInflater inflater) {
1389 View v = inflater.inflate(R.layout.global_actions_silent_mode, parent, false);
1390
1391 int selectedIndex = ringerModeToIndex(mAudioManager.getRingerMode());
1392 for (int i = 0; i < 3; i++) {
1393 View itemView = v.findViewById(ITEM_IDS[i]);
1394 itemView.setSelected(selectedIndex == i);
1395 // Set up click handler
1396 itemView.setTag(i);
1397 itemView.setOnClickListener(this);
1398 }
1399 return v;
1400 }
1401
1402 public void onPress() {
1403 }
1404
1405 public boolean showDuringKeyguard() {
1406 return true;
1407 }
1408
1409 public boolean showBeforeProvisioning() {
1410 return false;
1411 }
1412
1413 public boolean isEnabled() {
1414 return true;
1415 }
1416
1417 void willCreate() {
1418 }
1419
1420 public void onClick(View v) {
1421 if (!(v.getTag() instanceof Integer)) return;
1422
1423 int index = (Integer) v.getTag();
1424 mAudioManager.setRingerMode(indexToRingerMode(index));
1425 mHandler.sendEmptyMessageDelayed(MESSAGE_DISMISS, DIALOG_DISMISS_DELAY);
1426 }
1427 }
1428
1429 private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
1430 public void onReceive(Context context, Intent intent) {
1431 String action = intent.getAction();
1432 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)
1433 || Intent.ACTION_SCREEN_OFF.equals(action)) {
1434 String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY);
1435 if (!SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS.equals(reason)) {
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001436 mHandler.sendMessage(mHandler.obtainMessage(MESSAGE_DISMISS, reason));
Jason Monk361915c2017-03-21 20:33:59 -04001437 }
Jayachandran C142eae02019-12-13 19:29:20 -08001438 } else if (TelephonyManager.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED.equals(action)) {
Jason Monk361915c2017-03-21 20:33:59 -04001439 // Airplane mode can be changed after ECM exits if airplane toggle button
1440 // is pressed during ECM mode
Daniel Bright4bcbfce2020-01-09 21:58:16 -08001441 if (!(intent.getBooleanExtra(TelephonyManager.EXTRA_PHONE_IN_ECM_STATE, false))
1442 && mIsWaitingForEcmExit) {
Jason Monk361915c2017-03-21 20:33:59 -04001443 mIsWaitingForEcmExit = false;
1444 changeAirplaneModeSystemSetting(true);
1445 }
1446 }
1447 }
1448 };
1449
1450 PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
1451 @Override
1452 public void onServiceStateChanged(ServiceState serviceState) {
1453 if (!mHasTelephony) return;
1454 final boolean inAirplaneMode = serviceState.getState() == ServiceState.STATE_POWER_OFF;
1455 mAirplaneState = inAirplaneMode ? ToggleAction.State.On : ToggleAction.State.Off;
1456 mAirplaneModeOn.updateState(mAirplaneState);
1457 mAdapter.notifyDataSetChanged();
1458 }
1459 };
1460
1461 private BroadcastReceiver mRingerModeReceiver = new BroadcastReceiver() {
1462 @Override
1463 public void onReceive(Context context, Intent intent) {
1464 if (intent.getAction().equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
1465 mHandler.sendEmptyMessage(MESSAGE_REFRESH);
1466 }
1467 }
1468 };
1469
1470 private ContentObserver mAirplaneModeObserver = new ContentObserver(new Handler()) {
1471 @Override
1472 public void onChange(boolean selfChange) {
1473 onAirplaneModeChanged();
1474 }
1475 };
1476
1477 private static final int MESSAGE_DISMISS = 0;
1478 private static final int MESSAGE_REFRESH = 1;
1479 private static final int MESSAGE_SHOW = 2;
1480 private static final int DIALOG_DISMISS_DELAY = 300; // ms
1481
1482 private Handler mHandler = new Handler() {
1483 public void handleMessage(Message msg) {
1484 switch (msg.what) {
Jason Monk16fbd9d2017-04-27 14:28:49 -04001485 case MESSAGE_DISMISS:
1486 if (mDialog != null) {
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001487 if (SYSTEM_DIALOG_REASON_DREAM.equals(msg.obj)) {
1488 mDialog.dismissImmediately();
1489 } else {
1490 mDialog.dismiss();
1491 }
Jason Monk16fbd9d2017-04-27 14:28:49 -04001492 mDialog = null;
1493 }
1494 break;
1495 case MESSAGE_REFRESH:
1496 refreshSilentMode();
1497 mAdapter.notifyDataSetChanged();
1498 break;
1499 case MESSAGE_SHOW:
1500 handleShow();
1501 break;
Jason Monk361915c2017-03-21 20:33:59 -04001502 }
1503 }
1504 };
1505
1506 private void onAirplaneModeChanged() {
1507 // Let the service state callbacks handle the state.
1508 if (mHasTelephony) return;
1509
1510 boolean airplaneModeOn = Settings.Global.getInt(
Dave Mankoffc88a2d72020-01-10 15:59:31 -05001511 mContentResolver,
Jason Monk361915c2017-03-21 20:33:59 -04001512 Settings.Global.AIRPLANE_MODE_ON,
1513 0) == 1;
1514 mAirplaneState = airplaneModeOn ? ToggleAction.State.On : ToggleAction.State.Off;
1515 mAirplaneModeOn.updateState(mAirplaneState);
1516 }
1517
1518 /**
1519 * Change the airplane mode system setting
1520 */
1521 private void changeAirplaneModeSystemSetting(boolean on) {
1522 Settings.Global.putInt(
Dave Mankoffc88a2d72020-01-10 15:59:31 -05001523 mContentResolver,
Jason Monk361915c2017-03-21 20:33:59 -04001524 Settings.Global.AIRPLANE_MODE_ON,
1525 on ? 1 : 0);
1526 Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
1527 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
1528 intent.putExtra("state", on);
1529 mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
1530 if (!mHasTelephony) {
1531 mAirplaneState = on ? ToggleAction.State.On : ToggleAction.State.Off;
1532 }
1533 }
1534
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001535 private static final class ActionsDialog extends Dialog implements DialogInterface,
1536 ColorExtractor.OnColorsChangedListener {
Jason Monk361915c2017-03-21 20:33:59 -04001537
Jason Monk16fbd9d2017-04-27 14:28:49 -04001538 private final Context mContext;
1539 private final MyAdapter mAdapter;
Steve Elliott53f12ae2019-05-13 17:14:15 -04001540 private final IStatusBarService mStatusBarService;
1541 private final IBinder mToken = new Binder();
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001542 private MultiListLayout mGlobalActionsLayout;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001543 private Drawable mBackgroundDrawable;
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001544 private final SysuiColorExtractor mColorExtractor;
Steve Elliott9b87a442019-03-05 10:24:16 -05001545 private final GlobalActionsPanelPlugin.PanelViewController mPanelController;
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001546 private boolean mKeyguardShowing;
Beverly526d2d62018-08-15 12:55:33 -04001547 private boolean mShowing;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001548 private float mScrimAlpha;
Steve Elliott48f75db2019-05-03 15:03:38 -04001549 private ResetOrientationData mResetOrientationData;
Steve Elliottff2c0d92019-07-30 15:09:54 -04001550 private boolean mHadTopUi;
wilsonshihe8321942019-10-18 18:39:46 +08001551 private final NotificationShadeWindowController mNotificationShadeWindowController;
Lucas Dupin991415e2019-11-25 17:48:58 -08001552 private final BlurUtils mBlurUtils;
Matt Pietal22231792020-01-23 09:51:09 -05001553
1554 private ControlsUiController mControlsUiController;
1555 private ViewGroup mControlsView;
Jason Monk16fbd9d2017-04-27 14:28:49 -04001556
Aaron Heuckrothf19d2722019-03-11 17:06:02 -04001557 ActionsDialog(Context context, MyAdapter adapter,
Lucas Dupin991415e2019-11-25 17:48:58 -08001558 GlobalActionsPanelPlugin.PanelViewController plugin, BlurUtils blurUtils,
1559 SysuiColorExtractor sysuiColorExtractor, IStatusBarService statusBarService,
1560 NotificationShadeWindowController notificationShadeWindowController,
Matt Pietal22231792020-01-23 09:51:09 -05001561 ControlsUiController controlsUiController) {
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001562 super(context, com.android.systemui.R.style.Theme_SystemUI_Dialog_GlobalActions);
Lucas Dupin448786c2017-07-24 17:44:25 -07001563 mContext = context;
Jason Monk16fbd9d2017-04-27 14:28:49 -04001564 mAdapter = adapter;
Lucas Dupin991415e2019-11-25 17:48:58 -08001565 mBlurUtils = blurUtils;
1566 mColorExtractor = sysuiColorExtractor;
1567 mStatusBarService = statusBarService;
1568 mNotificationShadeWindowController = notificationShadeWindowController;
Matt Pietal22231792020-01-23 09:51:09 -05001569 mControlsUiController = controlsUiController;
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001570
1571 // Window initialization
1572 Window window = getWindow();
1573 window.requestFeature(Window.FEATURE_NO_TITLE);
Adrian Roosedfab3b2018-03-08 18:39:20 +01001574 // Inflate the decor view, so the attributes below are not overwritten by the theme.
1575 window.getDecorView();
1576 window.getAttributes().systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1577 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1578 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1579 window.setLayout(MATCH_PARENT, MATCH_PARENT);
1580 window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
Alison Cichowlas4f19f4a2017-07-25 10:56:16 -04001581 window.addFlags(
1582 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001583 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
Adrian Roosedfab3b2018-03-08 18:39:20 +01001584 | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001585 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
1586 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
1587 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001588 window.setType(WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY);
Tiger Huang52724442020-01-20 21:38:42 +08001589 window.getAttributes().setFitInsetsTypes(0 /* types */);
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001590 setTitle(R.string.global_actions);
Steve Elliott9b87a442019-03-05 10:24:16 -05001591
1592 mPanelController = plugin;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001593 initializeLayout();
Steve Elliott9b87a442019-03-05 10:24:16 -05001594 }
1595
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001596 private boolean shouldUsePanel() {
Aran Ink3f594552019-05-13 14:29:35 -04001597 return mPanelController != null && mPanelController.getPanelContent() != null;
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001598 }
1599
1600 private void initializePanel() {
Steve Elliott48f75db2019-05-03 15:03:38 -04001601 int rotation = RotationUtils.getRotation(mContext);
1602 boolean rotationLocked = RotationPolicy.isRotationLocked(mContext);
1603 if (rotation != RotationUtils.ROTATION_NONE) {
1604 if (rotationLocked) {
1605 if (mResetOrientationData == null) {
1606 mResetOrientationData = new ResetOrientationData();
1607 mResetOrientationData.locked = true;
1608 mResetOrientationData.rotation = rotation;
1609 }
1610
1611 // Unlock rotation, so user can choose to rotate to portrait to see the panel.
Steve Elliotte05817f2019-05-17 14:39:53 -04001612 // This call is posted so that the rotation does not change until post-layout,
1613 // otherwise onConfigurationChanged() may not get invoked.
1614 mGlobalActionsLayout.post(() ->
1615 RotationPolicy.setRotationLockAtAngle(
1616 mContext, false, RotationUtils.ROTATION_NONE));
Steve Elliott48f75db2019-05-03 15:03:38 -04001617 }
1618 } else {
1619 if (!rotationLocked) {
1620 if (mResetOrientationData == null) {
1621 mResetOrientationData = new ResetOrientationData();
1622 mResetOrientationData.locked = false;
1623 }
1624
1625 // Lock to portrait, so the user doesn't accidentally hide the panel.
Steve Elliotte05817f2019-05-17 14:39:53 -04001626 // This call is posted so that the rotation does not change until post-layout,
1627 // otherwise onConfigurationChanged() may not get invoked.
1628 mGlobalActionsLayout.post(() ->
1629 RotationPolicy.setRotationLockAtAngle(
1630 mContext, true, RotationUtils.ROTATION_NONE));
Steve Elliott48f75db2019-05-03 15:03:38 -04001631 }
1632
Steve Elliott53f12ae2019-05-13 17:14:15 -04001633 // Disable rotation suggestions, if enabled
1634 setRotationSuggestionsEnabled(false);
1635
Steve Elliott300b48f2019-05-29 14:13:50 -04001636 FrameLayout panelContainer =
1637 findViewById(com.android.systemui.R.id.global_actions_panel_container);
Steve Elliott48f75db2019-05-03 15:03:38 -04001638 FrameLayout.LayoutParams panelParams =
1639 new FrameLayout.LayoutParams(
1640 FrameLayout.LayoutParams.MATCH_PARENT,
Steve Elliott300b48f2019-05-29 14:13:50 -04001641 FrameLayout.LayoutParams.MATCH_PARENT);
Steve Elliott48f75db2019-05-03 15:03:38 -04001642 panelContainer.addView(mPanelController.getPanelContent(), panelParams);
Steve Elliott86ef6282019-05-08 14:45:04 -04001643 mBackgroundDrawable = mPanelController.getBackgroundDrawable();
1644 mScrimAlpha = 1f;
Steve Elliott48f75db2019-05-03 15:03:38 -04001645 }
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001646 }
1647
1648 private void initializeLayout() {
1649 setContentView(getGlobalActionsLayoutId(mContext));
Steve Elliott300b48f2019-05-29 14:13:50 -04001650 fixNavBarClipping();
Matt Pietal22231792020-01-23 09:51:09 -05001651 mControlsView = findViewById(com.android.systemui.R.id.global_actions_controls);
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001652 mGlobalActionsLayout = findViewById(com.android.systemui.R.id.global_actions_view);
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001653 mGlobalActionsLayout.setOutsideTouchListener(view -> dismiss());
Steve Elliott300b48f2019-05-29 14:13:50 -04001654 ((View) mGlobalActionsLayout.getParent()).setOnClickListener(view -> dismiss());
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001655 mGlobalActionsLayout.setListViewAccessibilityDelegate(new View.AccessibilityDelegate() {
Phil Weaver9054e092018-04-27 16:28:50 -07001656 @Override
1657 public boolean dispatchPopulateAccessibilityEvent(
1658 View host, AccessibilityEvent event) {
1659 // Populate the title here, just as Activity does
1660 event.getText().add(mContext.getString(R.string.global_actions));
1661 return true;
1662 }
1663 });
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001664 mGlobalActionsLayout.setRotationListener(this::onRotate);
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001665 mGlobalActionsLayout.setAdapter(mAdapter);
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001666
Steve Elliott86ef6282019-05-08 14:45:04 -04001667 if (shouldUsePanel()) {
Steve Elliottc59eb342019-04-23 16:59:06 -04001668 initializePanel();
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001669 }
Steve Elliott86ef6282019-05-08 14:45:04 -04001670 if (mBackgroundDrawable == null) {
1671 mBackgroundDrawable = new ScrimDrawable();
1672 mScrimAlpha = ScrimController.GRADIENT_SCRIM_ALPHA;
1673 }
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001674 getWindow().setBackgroundDrawable(mBackgroundDrawable);
Steve Elliott9b87a442019-03-05 10:24:16 -05001675 }
1676
Steve Elliott300b48f2019-05-29 14:13:50 -04001677 private void fixNavBarClipping() {
1678 ViewGroup content = findViewById(android.R.id.content);
1679 content.setClipChildren(false);
1680 content.setClipToPadding(false);
1681 ViewGroup contentParent = (ViewGroup) content.getParent();
1682 contentParent.setClipChildren(false);
1683 contentParent.setClipToPadding(false);
1684 }
1685
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001686 private int getGlobalActionsLayoutId(Context context) {
Matt Pietal22231792020-01-23 09:51:09 -05001687 if (mControlsUiController != null) {
Matt Pietalfd3b6cb2020-01-08 09:43:54 -05001688 return com.android.systemui.R.layout.global_actions_grid_v2;
1689 }
1690
Steve Elliottdc165632019-05-23 14:26:31 -04001691 int rotation = RotationUtils.getRotation(context);
1692 boolean useGridLayout = isForceGridEnabled(context)
1693 || (shouldUsePanel() && rotation == RotationUtils.ROTATION_NONE);
1694 if (rotation == RotationUtils.ROTATION_SEASCAPE) {
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001695 if (useGridLayout) {
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001696 return com.android.systemui.R.layout.global_actions_grid_seascape;
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001697 } else {
1698 return com.android.systemui.R.layout.global_actions_column_seascape;
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001699 }
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001700 } else {
1701 if (useGridLayout) {
1702 return com.android.systemui.R.layout.global_actions_grid;
1703 } else {
1704 return com.android.systemui.R.layout.global_actions_column;
1705 }
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001706 }
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001707 }
1708
Jason Monk361915c2017-03-21 20:33:59 -04001709 @Override
1710 protected void onStart() {
1711 super.setCanceledOnTouchOutside(true);
1712 super.onStart();
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001713 mGlobalActionsLayout.updateList();
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001714
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001715 if (mBackgroundDrawable instanceof ScrimDrawable) {
Steve Elliott9b87a442019-03-05 10:24:16 -05001716 mColorExtractor.addOnColorsChangedListener(this);
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001717 GradientColors colors = mColorExtractor.getNeutralColors();
Steve Elliott9b87a442019-03-05 10:24:16 -05001718 updateColors(colors, false /* animate */);
1719 }
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001720 }
1721
1722 /**
1723 * Updates background and system bars according to current GradientColors.
1724 * @param colors Colors and hints to use.
1725 * @param animate Interpolates gradient if true, just sets otherwise.
1726 */
1727 private void updateColors(GradientColors colors, boolean animate) {
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001728 if (!(mBackgroundDrawable instanceof ScrimDrawable)) {
Steve Elliott9b87a442019-03-05 10:24:16 -05001729 return;
1730 }
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001731 ((ScrimDrawable) mBackgroundDrawable).setColor(colors.getMainColor(), animate);
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001732 View decorView = getWindow().getDecorView();
1733 if (colors.supportsDarkText()) {
1734 decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR |
Steve Elliott9b87a442019-03-05 10:24:16 -05001735 View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001736 } else {
1737 decorView.setSystemUiVisibility(0);
1738 }
Jason Monk361915c2017-03-21 20:33:59 -04001739 }
1740
1741 @Override
Jason Monk16fbd9d2017-04-27 14:28:49 -04001742 protected void onStop() {
1743 super.onStop();
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001744 mColorExtractor.removeOnColorsChangedListener(this);
Jason Monk16fbd9d2017-04-27 14:28:49 -04001745 }
1746
1747 @Override
1748 public void show() {
1749 super.show();
Beverly526d2d62018-08-15 12:55:33 -04001750 mShowing = true;
wilsonshihe8321942019-10-18 18:39:46 +08001751 mHadTopUi = mNotificationShadeWindowController.getForceHasTopUi();
1752 mNotificationShadeWindowController.setForceHasTopUi(true);
Steve Elliott9b87a442019-03-05 10:24:16 -05001753 mBackgroundDrawable.setAlpha(0);
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001754 mGlobalActionsLayout.setTranslationX(mGlobalActionsLayout.getAnimationOffsetX());
1755 mGlobalActionsLayout.setTranslationY(mGlobalActionsLayout.getAnimationOffsetY());
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001756 mGlobalActionsLayout.setAlpha(0);
1757 mGlobalActionsLayout.animate()
Jason Monk16fbd9d2017-04-27 14:28:49 -04001758 .alpha(1)
1759 .translationX(0)
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001760 .translationY(0)
Jason Monk16fbd9d2017-04-27 14:28:49 -04001761 .setDuration(300)
Lucas Dupinde9db422017-07-19 17:15:41 -07001762 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001763 .setUpdateListener(animation -> {
Lucas Dupin991415e2019-11-25 17:48:58 -08001764 float animatedValue = animation.getAnimatedFraction();
1765 int alpha = (int) (animatedValue * mScrimAlpha * 255);
Steve Elliott9b87a442019-03-05 10:24:16 -05001766 mBackgroundDrawable.setAlpha(alpha);
Lucas Dupin991415e2019-11-25 17:48:58 -08001767 mBlurUtils.applyBlur(mGlobalActionsLayout.getViewRootImpl(),
1768 mBlurUtils.radiusForRatio(animatedValue));
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001769 })
Jason Monk16fbd9d2017-04-27 14:28:49 -04001770 .start();
Matt Pietal22231792020-01-23 09:51:09 -05001771 if (mControlsUiController != null) {
1772 mControlsUiController.show(mControlsView);
1773 }
Jason Monk16fbd9d2017-04-27 14:28:49 -04001774 }
1775
1776 @Override
1777 public void dismiss() {
Beverly526d2d62018-08-15 12:55:33 -04001778 if (!mShowing) {
1779 return;
1780 }
1781 mShowing = false;
Matt Pietal22231792020-01-23 09:51:09 -05001782 if (mControlsUiController != null) mControlsUiController.hide();
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001783 mGlobalActionsLayout.setTranslationX(0);
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001784 mGlobalActionsLayout.setTranslationY(0);
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001785 mGlobalActionsLayout.setAlpha(1);
1786 mGlobalActionsLayout.animate()
Jason Monk16fbd9d2017-04-27 14:28:49 -04001787 .alpha(0)
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001788 .translationX(mGlobalActionsLayout.getAnimationOffsetX())
1789 .translationY(mGlobalActionsLayout.getAnimationOffsetY())
Jason Monk16fbd9d2017-04-27 14:28:49 -04001790 .setDuration(300)
Steve Elliottff2c0d92019-07-30 15:09:54 -04001791 .withEndAction(this::completeDismiss)
Jason Monk16fbd9d2017-04-27 14:28:49 -04001792 .setInterpolator(new LogAccelerateInterpolator())
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001793 .setUpdateListener(animation -> {
Lucas Dupin991415e2019-11-25 17:48:58 -08001794 float animatedValue = 1f - animation.getAnimatedFraction();
1795 int alpha = (int) (animatedValue * mScrimAlpha * 255);
Steve Elliott9b87a442019-03-05 10:24:16 -05001796 mBackgroundDrawable.setAlpha(alpha);
Lucas Dupin991415e2019-11-25 17:48:58 -08001797 mBlurUtils.applyBlur(mGlobalActionsLayout.getViewRootImpl(),
1798 mBlurUtils.radiusForRatio(animatedValue));
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001799 })
Jason Monk16fbd9d2017-04-27 14:28:49 -04001800 .start();
Steve Elliott48f75db2019-05-03 15:03:38 -04001801 dismissPanel();
1802 resetOrientation();
Jason Monk16fbd9d2017-04-27 14:28:49 -04001803 }
1804
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001805 void dismissImmediately() {
Beverly526d2d62018-08-15 12:55:33 -04001806 mShowing = false;
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
1903 private static boolean isControlsEnabled(Context context) {
1904 return Settings.Secure.getInt(
1905 context.getContentResolver(), "systemui.controls_available", 0) == 1;
1906 }
Jason Monk361915c2017-03-21 20:33:59 -04001907}