blob: 37351985b3bd24d860dea4211734dda55da83b2a [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;
Dave Mankoffc88a2d72020-01-10 15:59:31 -050096import com.android.systemui.dagger.qualifiers.Main;
Steve Elliott4c868852019-03-14 16:25:41 -040097import com.android.systemui.plugins.ActivityStarter;
Charles He9851a8d2017-10-10 17:31:30 +010098import com.android.systemui.plugins.GlobalActions.GlobalActionsManager;
Steve Elliott9b87a442019-03-05 10:24:16 -050099import com.android.systemui.plugins.GlobalActionsPanelPlugin;
wilsonshihe8321942019-10-18 18:39:46 +0800100import com.android.systemui.statusbar.phone.NotificationShadeWindowController;
Lucas Dupin991415e2019-11-25 17:48:58 -0800101import com.android.systemui.statusbar.BlurUtils;
Steve Elliottbfa314a2019-03-06 13:53:19 -0500102import com.android.systemui.statusbar.phone.ScrimController;
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700103import com.android.systemui.statusbar.policy.ConfigurationController;
Lucas Dupinc8f16e82019-09-17 18:24:50 -0400104import com.android.systemui.statusbar.policy.KeyguardStateController;
Shaotang Li5c422632018-07-04 14:18:40 +0800105import com.android.systemui.util.EmergencyDialerConstants;
Aaron Heuckroth75e249f2019-02-01 15:59:57 -0500106import com.android.systemui.util.leak.RotationUtils;
Julia Reynolds42411922017-11-08 11:19:09 -0500107import com.android.systemui.volume.SystemUIInterpolators.LogAccelerateInterpolator;
Lucas Dupinc1cc7592017-05-22 15:56:16 -0700108
Jason Monk361915c2017-03-21 20:33:59 -0400109import java.util.ArrayList;
110import java.util.List;
111
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500112import javax.inject.Inject;
113
Jason Monk361915c2017-03-21 20:33:59 -0400114/**
115 * Helper to show the global actions dialog. Each item is an {@link Action} that
116 * may show depending on whether the keyguard is showing, and whether the device
117 * is provisioned.
118 */
Aaron Heuckroth57d60d22019-03-05 14:00:12 -0500119public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
120 DialogInterface.OnShowListener, ConfigurationController.ConfigurationListener {
Jason Monk361915c2017-03-21 20:33:59 -0400121
122 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
123 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
Lucas Dupin1d4a5792018-04-02 15:14:59 -0700124 static public final String SYSTEM_DIALOG_REASON_DREAM = "dream";
Jason Monk361915c2017-03-21 20:33:59 -0400125
126 private static final String TAG = "GlobalActionsDialog";
127
128 private static final boolean SHOW_SILENT_TOGGLE = true;
129
130 /* Valid settings for global actions keys.
131 * see config.xml config_globalActionList */
132 private static final String GLOBAL_ACTION_KEY_POWER = "power";
133 private static final String GLOBAL_ACTION_KEY_AIRPLANE = "airplane";
134 private static final String GLOBAL_ACTION_KEY_BUGREPORT = "bugreport";
135 private static final String GLOBAL_ACTION_KEY_SILENT = "silent";
136 private static final String GLOBAL_ACTION_KEY_USERS = "users";
137 private static final String GLOBAL_ACTION_KEY_SETTINGS = "settings";
138 private static final String GLOBAL_ACTION_KEY_LOCKDOWN = "lockdown";
139 private static final String GLOBAL_ACTION_KEY_VOICEASSIST = "voiceassist";
140 private static final String GLOBAL_ACTION_KEY_ASSIST = "assist";
141 private static final String GLOBAL_ACTION_KEY_RESTART = "restart";
Alex Chau04458852017-11-27 18:21:23 +0000142 private static final String GLOBAL_ACTION_KEY_LOGOUT = "logout";
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800143 private static final String GLOBAL_ACTION_KEY_EMERGENCY = "emergency";
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500144 private static final String GLOBAL_ACTION_KEY_SCREENSHOT = "screenshot";
Jason Monk361915c2017-03-21 20:33:59 -0400145
146 private final Context mContext;
147 private final GlobalActionsManager mWindowManagerFuncs;
148 private final AudioManager mAudioManager;
149 private final IDreamManager mDreamManager;
Alex Chau04458852017-11-27 18:21:23 +0000150 private final DevicePolicyManager mDevicePolicyManager;
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800151 private final LockPatternUtils mLockPatternUtils;
152 private final KeyguardManager mKeyguardManager;
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000153 private final BroadcastDispatcher mBroadcastDispatcher;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500154 private final ContentResolver mContentResolver;
155 private final Resources mResources;
156 private final UserManager mUserManager;
157 private final TrustManager mTrustManager;
158 private final IActivityManager mIActivityManager;
159 private final TelecomManager mTelecomManager;
160 private final MetricsLogger mMetricsLogger;
Lucas Dupin991415e2019-11-25 17:48:58 -0800161 private final BlurUtils mBlurUtils;
Jason Monk361915c2017-03-21 20:33:59 -0400162
163 private ArrayList<Action> mItems;
164 private ActionsDialog mDialog;
165
166 private Action mSilentModeAction;
167 private ToggleAction mAirplaneModeOn;
168
169 private MyAdapter mAdapter;
170
171 private boolean mKeyguardShowing = false;
172 private boolean mDeviceProvisioned = false;
173 private ToggleAction.State mAirplaneState = ToggleAction.State.Off;
174 private boolean mIsWaitingForEcmExit = false;
175 private boolean mHasTelephony;
176 private boolean mHasVibrator;
177 private final boolean mShowSilentToggle;
178 private final EmergencyAffordanceManager mEmergencyAffordanceManager;
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500179 private final ScreenshotHelper mScreenshotHelper;
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400180 private final ScreenRecordHelper mScreenRecordHelper;
Steve Elliotta3f5207922019-03-18 13:37:22 -0400181 private final ActivityStarter mActivityStarter;
Lucas Dupin991415e2019-11-25 17:48:58 -0800182 private final SysuiColorExtractor mSysuiColorExtractor;
183 private final IStatusBarService mStatusBarService;
184 private final NotificationShadeWindowController mNotificationShadeWindowController;
Steve Elliotta3f5207922019-03-18 13:37:22 -0400185 private GlobalActionsPanelPlugin mPanelPlugin;
Steve Elliott9b87a442019-03-05 10:24:16 -0500186
Jason Monk361915c2017-03-21 20:33:59 -0400187 /**
188 * @param context everything needs a context :(
189 */
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500190 @Inject
191 public GlobalActionsDialog(Context context, GlobalActionsManager windowManagerFuncs,
192 AudioManager audioManager, IDreamManager iDreamManager,
193 DevicePolicyManager devicePolicyManager, LockPatternUtils lockPatternUtils,
194 KeyguardManager keyguardManager, BroadcastDispatcher broadcastDispatcher,
195 ConnectivityManager connectivityManager, TelephonyManager telephonyManager,
196 ContentResolver contentResolver, @Nullable Vibrator vibrator, @Main Resources resources,
197 ConfigurationController configurationController, ActivityStarter activityStarter,
198 KeyguardStateController keyguardStateController, UserManager userManager,
199 TrustManager trustManager, IActivityManager iActivityManager,
Lucas Dupin991415e2019-11-25 17:48:58 -0800200 TelecomManager telecomManager, MetricsLogger metricsLogger,
201 BlurUtils blurUtils, SysuiColorExtractor colorExtractor,
202 IStatusBarService statusBarService,
203 NotificationShadeWindowController notificationShadeWindowController) {
Lucas Dupin448786c2017-07-24 17:44:25 -0700204 mContext = new ContextThemeWrapper(context, com.android.systemui.R.style.qs_theme);
Jason Monk361915c2017-03-21 20:33:59 -0400205 mWindowManagerFuncs = windowManagerFuncs;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500206 mAudioManager = audioManager;
207 mDreamManager = iDreamManager;
208 mDevicePolicyManager = devicePolicyManager;
209 mLockPatternUtils = lockPatternUtils;
210 mKeyguardManager = keyguardManager;
211 mBroadcastDispatcher = broadcastDispatcher;
212 mContentResolver = contentResolver;
213 mResources = resources;
214 mUserManager = userManager;
215 mTrustManager = trustManager;
216 mIActivityManager = iActivityManager;
217 mTelecomManager = telecomManager;
218 mMetricsLogger = metricsLogger;
Lucas Dupin991415e2019-11-25 17:48:58 -0800219 mBlurUtils = blurUtils;
220 mSysuiColorExtractor = colorExtractor;
221 mStatusBarService = statusBarService;
222 mNotificationShadeWindowController = notificationShadeWindowController;
Jason Monk361915c2017-03-21 20:33:59 -0400223
224 // receive broadcasts
225 IntentFilter filter = new IntentFilter();
226 filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
227 filter.addAction(Intent.ACTION_SCREEN_OFF);
Jayachandran C142eae02019-12-13 19:29:20 -0800228 filter.addAction(TelephonyManager.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000229 mBroadcastDispatcher.registerReceiver(mBroadcastReceiver, filter);
Jason Monk361915c2017-03-21 20:33:59 -0400230
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500231 mHasTelephony = connectivityManager.isNetworkSupported(ConnectivityManager.TYPE_MOBILE);
Jason Monk361915c2017-03-21 20:33:59 -0400232
233 // get notified of phone state changes
Jason Monk361915c2017-03-21 20:33:59 -0400234 telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE);
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500235 contentResolver.registerContentObserver(
Jason Monk361915c2017-03-21 20:33:59 -0400236 Settings.Global.getUriFor(Settings.Global.AIRPLANE_MODE_ON), true,
237 mAirplaneModeObserver);
Jason Monk361915c2017-03-21 20:33:59 -0400238 mHasVibrator = vibrator != null && vibrator.hasVibrator();
239
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500240 mShowSilentToggle = SHOW_SILENT_TOGGLE && !resources.getBoolean(
Jason Monk361915c2017-03-21 20:33:59 -0400241 R.bool.config_useFixedVolume);
242
243 mEmergencyAffordanceManager = new EmergencyAffordanceManager(context);
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500244 mScreenshotHelper = new ScreenshotHelper(context);
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400245 mScreenRecordHelper = new ScreenRecordHelper(context);
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700246
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500247 configurationController.addCallback(this);
Steve Elliott9b87a442019-03-05 10:24:16 -0500248
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500249 mActivityStarter = activityStarter;
Lucas Dupinc8f16e82019-09-17 18:24:50 -0400250 keyguardStateController.addCallback(new KeyguardStateController.Callback() {
251 @Override
252 public void onUnlockedChanged() {
253 if (mDialog != null && mDialog.mPanelController != null) {
254 boolean locked = !keyguardStateController.canDismissLockScreen();
255 mDialog.mPanelController.onDeviceLockStateChanged(locked);
256 }
257 }
258 });
Jason Monk361915c2017-03-21 20:33:59 -0400259 }
260
261 /**
262 * Show the global actions dialog (creating if necessary)
Jason Monk16fbd9d2017-04-27 14:28:49 -0400263 *
Jason Monk361915c2017-03-21 20:33:59 -0400264 * @param keyguardShowing True if keyguard is showing
265 */
Steve Elliotta3f5207922019-03-18 13:37:22 -0400266 public void showDialog(boolean keyguardShowing, boolean isDeviceProvisioned,
267 GlobalActionsPanelPlugin panelPlugin) {
Jason Monk361915c2017-03-21 20:33:59 -0400268 mKeyguardShowing = keyguardShowing;
269 mDeviceProvisioned = isDeviceProvisioned;
Steve Elliotta3f5207922019-03-18 13:37:22 -0400270 mPanelPlugin = panelPlugin;
Jason Monk361915c2017-03-21 20:33:59 -0400271 if (mDialog != null) {
272 mDialog.dismiss();
273 mDialog = null;
274 // Show delayed, so that the dismiss of the previous dialog completes
275 mHandler.sendEmptyMessage(MESSAGE_SHOW);
276 } else {
277 handleShow();
278 }
279 }
280
Charles He9851a8d2017-10-10 17:31:30 +0100281 /**
282 * Dismiss the global actions dialog, if it's currently shown
283 */
284 public void dismissDialog() {
285 mHandler.removeMessages(MESSAGE_DISMISS);
286 mHandler.sendEmptyMessage(MESSAGE_DISMISS);
287 }
288
Jason Monk361915c2017-03-21 20:33:59 -0400289 private void awakenIfNecessary() {
290 if (mDreamManager != null) {
291 try {
292 if (mDreamManager.isDreaming()) {
293 mDreamManager.awaken();
294 }
295 } catch (RemoteException e) {
296 // we tried
297 }
298 }
299 }
300
301 private void handleShow() {
302 awakenIfNecessary();
303 mDialog = createDialog();
304 prepareDialog();
305
306 // If we only have 1 item and it's a simple press action, just do this action.
307 if (mAdapter.getCount() == 1
308 && mAdapter.getItem(0) instanceof SinglePressAction
309 && !(mAdapter.getItem(0) instanceof LongPressAction)) {
310 ((SinglePressAction) mAdapter.getItem(0)).onPress();
311 } else {
312 WindowManager.LayoutParams attrs = mDialog.getWindow().getAttributes();
313 attrs.setTitle("ActionsDialog");
Adrian Roos2f05bb32018-02-19 16:42:27 +0100314 attrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
Jason Monk361915c2017-03-21 20:33:59 -0400315 mDialog.getWindow().setAttributes(attrs);
316 mDialog.show();
317 mWindowManagerFuncs.onGlobalActionsShown();
Jason Monk361915c2017-03-21 20:33:59 -0400318 }
319 }
320
321 /**
322 * Create the global actions dialog.
Jason Monk16fbd9d2017-04-27 14:28:49 -0400323 *
Jason Monk361915c2017-03-21 20:33:59 -0400324 * @return A new dialog.
325 */
326 private ActionsDialog createDialog() {
327 // Simple toggle style if there's no vibrator, otherwise use a tri-state
328 if (!mHasVibrator) {
329 mSilentModeAction = new SilentModeToggleAction();
330 } else {
Lucas Dupin40ec6b782018-06-05 19:07:16 -0700331 mSilentModeAction = new SilentModeTriStateAction(mAudioManager, mHandler);
Jason Monk361915c2017-03-21 20:33:59 -0400332 }
333 mAirplaneModeOn = new ToggleAction(
334 R.drawable.ic_lock_airplane_mode,
335 R.drawable.ic_lock_airplane_mode_off,
336 R.string.global_actions_toggle_airplane_mode,
337 R.string.global_actions_airplane_mode_on_status,
338 R.string.global_actions_airplane_mode_off_status) {
339
340 void onToggle(boolean on) {
Inseob Kim5e82f732019-11-08 15:08:38 +0900341 if (mHasTelephony && TelephonyProperties.in_ecm_mode().orElse(false)) {
Jason Monk361915c2017-03-21 20:33:59 -0400342 mIsWaitingForEcmExit = true;
343 // Launch ECM exit dialog
344 Intent ecmDialogIntent =
Jayachandran C142eae02019-12-13 19:29:20 -0800345 new Intent(TelephonyManager.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null);
Jason Monk361915c2017-03-21 20:33:59 -0400346 ecmDialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
347 mContext.startActivity(ecmDialogIntent);
348 } else {
349 changeAirplaneModeSystemSetting(on);
350 }
351 }
352
353 @Override
354 protected void changeStateFromPress(boolean buttonOn) {
355 if (!mHasTelephony) return;
356
357 // In ECM mode airplane state cannot be changed
Inseob Kim5e82f732019-11-08 15:08:38 +0900358 if (!TelephonyProperties.in_ecm_mode().orElse(false)) {
Jason Monk361915c2017-03-21 20:33:59 -0400359 mState = buttonOn ? State.TurningOn : State.TurningOff;
360 mAirplaneState = mState;
361 }
362 }
363
364 public boolean showDuringKeyguard() {
365 return true;
366 }
367
368 public boolean showBeforeProvisioning() {
369 return false;
370 }
371 };
372 onAirplaneModeChanged();
373
374 mItems = new ArrayList<Action>();
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500375 String[] defaultActions = mResources.getStringArray(R.array.config_globalActionsList);
Jason Monk361915c2017-03-21 20:33:59 -0400376
377 ArraySet<String> addedKeys = new ArraySet<String>();
378 for (int i = 0; i < defaultActions.length; i++) {
379 String actionKey = defaultActions[i];
380 if (addedKeys.contains(actionKey)) {
381 // If we already have added this, don't add it again.
382 continue;
383 }
384 if (GLOBAL_ACTION_KEY_POWER.equals(actionKey)) {
385 mItems.add(new PowerAction());
386 } else if (GLOBAL_ACTION_KEY_AIRPLANE.equals(actionKey)) {
387 mItems.add(mAirplaneModeOn);
388 } else if (GLOBAL_ACTION_KEY_BUGREPORT.equals(actionKey)) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500389 if (Settings.Global.getInt(mContentResolver,
Jason Monk361915c2017-03-21 20:33:59 -0400390 Settings.Global.BUGREPORT_IN_POWER_MENU, 0) != 0 && isCurrentUserOwner()) {
391 mItems.add(new BugReportAction());
392 }
393 } else if (GLOBAL_ACTION_KEY_SILENT.equals(actionKey)) {
394 if (mShowSilentToggle) {
395 mItems.add(mSilentModeAction);
396 }
397 } else if (GLOBAL_ACTION_KEY_USERS.equals(actionKey)) {
398 if (SystemProperties.getBoolean("fw.power_user_switcher", false)) {
399 addUsersToMenu(mItems);
400 }
401 } else if (GLOBAL_ACTION_KEY_SETTINGS.equals(actionKey)) {
402 mItems.add(getSettingsAction());
403 } else if (GLOBAL_ACTION_KEY_LOCKDOWN.equals(actionKey)) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500404 if (Settings.Secure.getIntForUser(mContentResolver,
Chad Brubaker02cd6cf2018-05-01 14:59:33 -0700405 Settings.Secure.LOCKDOWN_IN_POWER_MENU, 0, getCurrentUser().id) != 0
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800406 && shouldDisplayLockdown()) {
Chad Brubaker4f28f0d2017-09-07 14:28:13 -0700407 mItems.add(getLockdownAction());
408 }
Jason Monk361915c2017-03-21 20:33:59 -0400409 } else if (GLOBAL_ACTION_KEY_VOICEASSIST.equals(actionKey)) {
410 mItems.add(getVoiceAssistAction());
411 } else if (GLOBAL_ACTION_KEY_ASSIST.equals(actionKey)) {
412 mItems.add(getAssistAction());
413 } else if (GLOBAL_ACTION_KEY_RESTART.equals(actionKey)) {
414 mItems.add(new RestartAction());
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500415 } else if (GLOBAL_ACTION_KEY_SCREENSHOT.equals(actionKey)) {
416 mItems.add(new ScreenshotAction());
Alex Chau04458852017-11-27 18:21:23 +0000417 } else if (GLOBAL_ACTION_KEY_LOGOUT.equals(actionKey)) {
Alex Chaud7958272017-12-08 11:30:52 +0000418 if (mDevicePolicyManager.isLogoutEnabled()
Alex Chau04458852017-11-27 18:21:23 +0000419 && getCurrentUser().id != UserHandle.USER_SYSTEM) {
420 mItems.add(new LogoutAction());
Alex Chau04458852017-11-27 18:21:23 +0000421 }
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800422 } else if (GLOBAL_ACTION_KEY_EMERGENCY.equals(actionKey)) {
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400423 if (!mEmergencyAffordanceManager.needsEmergencyAffordance()) {
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800424 mItems.add(new EmergencyDialerAction());
425 }
Jason Monk361915c2017-03-21 20:33:59 -0400426 } else {
427 Log.e(TAG, "Invalid global action key " + actionKey);
428 }
429 // Add here so we don't add more than one.
430 addedKeys.add(actionKey);
431 }
432
433 if (mEmergencyAffordanceManager.needsEmergencyAffordance()) {
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400434 mItems.add(new EmergencyAffordanceAction());
Jason Monk361915c2017-03-21 20:33:59 -0400435 }
436
437 mAdapter = new MyAdapter();
438
Steve Elliott9b87a442019-03-05 10:24:16 -0500439 GlobalActionsPanelPlugin.PanelViewController panelViewController =
Steve Elliotta3f5207922019-03-18 13:37:22 -0400440 mPanelPlugin != null
441 ? mPanelPlugin.onPanelShown(
Steve Elliott4c868852019-03-14 16:25:41 -0400442 new GlobalActionsPanelPlugin.Callbacks() {
443 @Override
444 public void dismissGlobalActionsMenu() {
Steve Elliottc3147e22019-11-20 19:34:57 -0500445 dismissDialog();
Steve Elliott4c868852019-03-14 16:25:41 -0400446 }
447
448 @Override
449 public void startPendingIntentDismissingKeyguard(
450 PendingIntent intent) {
451 mActivityStarter
452 .startPendingIntentDismissingKeyguard(intent);
453 }
Steve Elliotte2a2e9b2019-04-30 21:31:03 -0400454 },
455 mKeyguardManager.isDeviceLocked())
Steve Elliott9b87a442019-03-05 10:24:16 -0500456 : null;
Steve Elliott02bbaaa2019-05-01 16:55:33 -0400457
Lucas Dupin991415e2019-11-25 17:48:58 -0800458 ActionsDialog dialog = new ActionsDialog(mContext, mAdapter, panelViewController,
459 mBlurUtils, mSysuiColorExtractor, mStatusBarService,
460 mNotificationShadeWindowController, isControlsEnabled(mContext));
Jason Monk361915c2017-03-21 20:33:59 -0400461 dialog.setCanceledOnTouchOutside(false); // Handled by the custom class.
Lucas Dupinc1cc7592017-05-22 15:56:16 -0700462 dialog.setKeyguardShowing(mKeyguardShowing);
Jason Monk361915c2017-03-21 20:33:59 -0400463
464 dialog.setOnDismissListener(this);
Shaotang Li786da902018-08-02 11:18:00 +0800465 dialog.setOnShowListener(this);
Jason Monk361915c2017-03-21 20:33:59 -0400466
467 return dialog;
468 }
469
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800470 private boolean shouldDisplayLockdown() {
471 int userId = getCurrentUser().id;
472 // Lockdown is meaningless without a place to go.
473 if (!mKeyguardManager.isDeviceSecure(userId)) {
474 return false;
475 }
476
477 // Only show the lockdown button if the device isn't locked down (for whatever reason).
478 int state = mLockPatternUtils.getStrongAuthForUser(userId);
479 return (state == STRONG_AUTH_NOT_REQUIRED
480 || state == SOME_AUTH_REQUIRED_AFTER_USER_REQUEST);
481 }
482
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700483 @Override
484 public void onUiModeChanged() {
485 mContext.getTheme().applyStyle(mContext.getThemeResId(), true);
Lucas Dupina4e12ba2019-04-18 11:56:28 -0700486 if (mDialog != null && mDialog.isShowing()) {
Aaron Heuckroth4ef3a542019-04-01 14:17:23 -0400487 mDialog.refreshDialog();
488 }
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700489 }
490
491 public void destroy() {
492 Dependency.get(ConfigurationController.class).removeCallback(this);
493 }
494
Jason Monk361915c2017-03-21 20:33:59 -0400495 private final class PowerAction extends SinglePressAction implements LongPressAction {
496 private PowerAction() {
497 super(R.drawable.ic_lock_power_off,
Jason Monk16fbd9d2017-04-27 14:28:49 -0400498 R.string.global_action_power_off);
Jason Monk361915c2017-03-21 20:33:59 -0400499 }
500
501 @Override
502 public boolean onLongPress() {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500503 if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) {
Jason Monk361915c2017-03-21 20:33:59 -0400504 mWindowManagerFuncs.reboot(true);
505 return true;
506 }
507 return false;
508 }
509
510 @Override
511 public boolean showDuringKeyguard() {
512 return true;
513 }
514
515 @Override
516 public boolean showBeforeProvisioning() {
517 return true;
518 }
519
520 @Override
521 public void onPress() {
522 // shutdown by making sure radio and power are handled accordingly.
523 mWindowManagerFuncs.shutdown();
524 }
525 }
526
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400527 private abstract class EmergencyAction extends SinglePressAction {
528 EmergencyAction(int iconResId, int messageResId) {
529 super(iconResId, messageResId);
530 }
531
532 @Override
533 public boolean shouldBeSeparated() {
Matt Pietalfd3b6cb2020-01-08 09:43:54 -0500534 return !isControlsEnabled(mContext);
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400535 }
536
537 @Override
538 public View create(
539 Context context, View convertView, ViewGroup parent, LayoutInflater inflater) {
540 View v = super.create(context, convertView, parent, inflater);
541 int textColor;
542 if (shouldBeSeparated()) {
543 textColor = v.getResources().getColor(
544 com.android.systemui.R.color.global_actions_alert_text);
545 } else {
546 textColor = v.getResources().getColor(
547 com.android.systemui.R.color.global_actions_text);
548 }
549 TextView messageView = v.findViewById(R.id.message);
550 messageView.setTextColor(textColor);
Aaron Heuckroth3f2d8b52019-04-05 13:27:51 -0400551 messageView.setSelected(true); // necessary for marquee to work
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400552 ImageView icon = (ImageView) v.findViewById(R.id.icon);
553 icon.getDrawable().setTint(textColor);
554 return v;
555 }
556
557 @Override
558 public boolean showDuringKeyguard() {
559 return true;
560 }
561
562 @Override
563 public boolean showBeforeProvisioning() {
564 return true;
565 }
566 }
567
568 private class EmergencyAffordanceAction extends EmergencyAction {
569 EmergencyAffordanceAction() {
570 super(R.drawable.emergency_icon,
571 R.string.global_action_emergency);
572 }
573
574 @Override
575 public void onPress() {
576 mEmergencyAffordanceManager.performEmergencyCall();
577 }
578 }
579
580 private class EmergencyDialerAction extends EmergencyAction {
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800581 private EmergencyDialerAction() {
Aran Ink50195262019-05-30 10:55:37 -0400582 super(com.android.systemui.R.drawable.ic_emergency_star,
Wesley.CW Wang3004fcb2018-06-15 16:24:57 +0800583 R.string.global_action_emergency);
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800584 }
585
586 @Override
587 public void onPress() {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500588 mMetricsLogger.action(MetricsEvent.ACTION_EMERGENCY_DIALER_FROM_POWER_MENU);
589 Intent intent = mTelecomManager.createLaunchEmergencyDialerIntent(null /* number */);
Leo Hsue4cc3122019-03-06 15:25:28 +0800590 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
591 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
592 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
Shaotang Li5c422632018-07-04 14:18:40 +0800593 intent.putExtra(EmergencyDialerConstants.EXTRA_ENTRY_TYPE,
594 EmergencyDialerConstants.ENTRY_TYPE_POWER_MENU);
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800595 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
596 }
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800597 }
598
Jason Monk361915c2017-03-21 20:33:59 -0400599 private final class RestartAction extends SinglePressAction implements LongPressAction {
600 private RestartAction() {
601 super(R.drawable.ic_restart, R.string.global_action_restart);
602 }
603
604 @Override
605 public boolean onLongPress() {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500606 if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) {
Jason Monk361915c2017-03-21 20:33:59 -0400607 mWindowManagerFuncs.reboot(true);
608 return true;
609 }
610 return false;
611 }
612
613 @Override
614 public boolean showDuringKeyguard() {
615 return true;
616 }
617
618 @Override
619 public boolean showBeforeProvisioning() {
620 return true;
621 }
622
623 @Override
624 public void onPress() {
625 mWindowManagerFuncs.reboot(false);
626 }
627 }
628
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400629 private class ScreenshotAction extends SinglePressAction implements LongPressAction {
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500630 public ScreenshotAction() {
631 super(R.drawable.ic_screenshot, R.string.global_action_screenshot);
632 }
633
634 @Override
635 public void onPress() {
636 // Add a little delay before executing, to give the
637 // dialog a chance to go away before it takes a
638 // screenshot.
639 // TODO: instead, omit global action dialog layer
640 mHandler.postDelayed(new Runnable() {
641 @Override
642 public void run() {
James O'Learyfa5bb7a2019-09-05 13:43:29 -0400643 mScreenshotHelper.takeScreenshot(1, true, true, mHandler, null);
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500644 mMetricsLogger.action(MetricsEvent.ACTION_SCREENSHOT_POWER_MENU);
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500645 }
646 }, 500);
647 }
648
649 @Override
650 public boolean showDuringKeyguard() {
651 return true;
652 }
653
654 @Override
655 public boolean showBeforeProvisioning() {
656 return false;
657 }
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400658
659 @Override
660 public boolean onLongPress() {
661 if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SCREENRECORD_LONG_PRESS)) {
662 mScreenRecordHelper.launchRecordPrompt();
663 } else {
664 onPress();
665 }
666 return true;
667 }
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500668 }
669
Jason Monk361915c2017-03-21 20:33:59 -0400670 private class BugReportAction extends SinglePressAction implements LongPressAction {
671
672 public BugReportAction() {
673 super(R.drawable.ic_lock_bugreport, R.string.bugreport_title);
674 }
675
676 @Override
677 public void onPress() {
678 // don't actually trigger the bugreport if we are running stability
679 // tests via monkey
680 if (ActivityManager.isUserAMonkey()) {
681 return;
682 }
683 // Add a little delay before executing, to give the
684 // dialog a chance to go away before it takes a
685 // screenshot.
686 mHandler.postDelayed(new Runnable() {
687 @Override
688 public void run() {
689 try {
690 // Take an "interactive" bugreport.
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500691 mMetricsLogger.action(
Jason Monk361915c2017-03-21 20:33:59 -0400692 MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_INTERACTIVE);
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500693 if (!mIActivityManager.launchBugReportHandlerApp()) {
Paul Changc40f5782019-11-04 18:55:31 +0800694 Log.w(TAG, "Bugreport handler could not be launched");
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500695 mIActivityManager.requestInteractiveBugReport();
Paul Changc40f5782019-11-04 18:55:31 +0800696 }
Jason Monk361915c2017-03-21 20:33:59 -0400697 } catch (RemoteException e) {
698 }
699 }
700 }, 500);
701 }
702
703 @Override
704 public boolean onLongPress() {
705 // don't actually trigger the bugreport if we are running stability
706 // tests via monkey
707 if (ActivityManager.isUserAMonkey()) {
708 return false;
709 }
710 try {
711 // Take a "full" bugreport.
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500712 mMetricsLogger.action(MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_FULL);
713 mIActivityManager.requestFullBugReport();
Jason Monk361915c2017-03-21 20:33:59 -0400714 } catch (RemoteException e) {
715 }
716 return false;
717 }
718
719 public boolean showDuringKeyguard() {
720 return true;
721 }
722
723 @Override
724 public boolean showBeforeProvisioning() {
725 return false;
726 }
Jason Monk361915c2017-03-21 20:33:59 -0400727 }
728
Alex Chau04458852017-11-27 18:21:23 +0000729 private final class LogoutAction extends SinglePressAction {
730 private LogoutAction() {
731 super(R.drawable.ic_logout, R.string.global_action_logout);
732 }
733
734 @Override
735 public boolean showDuringKeyguard() {
736 return true;
737 }
738
739 @Override
740 public boolean showBeforeProvisioning() {
741 return false;
742 }
743
744 @Override
745 public void onPress() {
746 // Add a little delay before executing, to give the dialog a chance to go away before
747 // switching user
748 mHandler.postDelayed(() -> {
749 try {
Alex Chauedb6a012018-01-26 12:52:43 +0000750 int currentUserId = getCurrentUser().id;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500751 mIActivityManager.switchUser(UserHandle.USER_SYSTEM);
752 mIActivityManager.stopUser(currentUserId, true /*force*/, null);
Alex Chau04458852017-11-27 18:21:23 +0000753 } catch (RemoteException re) {
754 Log.e(TAG, "Couldn't logout user " + re);
755 }
756 }, 500);
757 }
758 }
759
Jason Monk361915c2017-03-21 20:33:59 -0400760 private Action getSettingsAction() {
761 return new SinglePressAction(R.drawable.ic_settings,
762 R.string.global_action_settings) {
763
764 @Override
765 public void onPress() {
766 Intent intent = new Intent(Settings.ACTION_SETTINGS);
767 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
768 mContext.startActivity(intent);
769 }
770
771 @Override
772 public boolean showDuringKeyguard() {
773 return true;
774 }
775
776 @Override
777 public boolean showBeforeProvisioning() {
778 return true;
779 }
780 };
781 }
782
Jason Monk361915c2017-03-21 20:33:59 -0400783 private Action getAssistAction() {
784 return new SinglePressAction(R.drawable.ic_action_assist_focused,
785 R.string.global_action_assist) {
786 @Override
787 public void onPress() {
788 Intent intent = new Intent(Intent.ACTION_ASSIST);
789 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
790 mContext.startActivity(intent);
791 }
792
793 @Override
794 public boolean showDuringKeyguard() {
795 return true;
796 }
797
798 @Override
799 public boolean showBeforeProvisioning() {
800 return true;
801 }
802 };
803 }
804
805 private Action getVoiceAssistAction() {
806 return new SinglePressAction(R.drawable.ic_voice_search,
807 R.string.global_action_voice_assist) {
808 @Override
809 public void onPress() {
810 Intent intent = new Intent(Intent.ACTION_VOICE_ASSIST);
811 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
812 mContext.startActivity(intent);
813 }
814
815 @Override
816 public boolean showDuringKeyguard() {
817 return true;
818 }
819
820 @Override
821 public boolean showBeforeProvisioning() {
822 return true;
823 }
824 };
825 }
826
827 private Action getLockdownAction() {
Alison Cichowlas21125432018-05-16 15:40:45 -0400828 return new SinglePressAction(R.drawable.ic_lock_lockdown,
Jason Monk361915c2017-03-21 20:33:59 -0400829 R.string.global_action_lockdown) {
830
831 @Override
832 public void onPress() {
Chad Brubaker4f28f0d2017-09-07 14:28:13 -0700833 new LockPatternUtils(mContext)
834 .requireStrongAuth(STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN,
835 UserHandle.USER_ALL);
Jason Monk361915c2017-03-21 20:33:59 -0400836 try {
837 WindowManagerGlobal.getWindowManagerService().lockNow(null);
Pavel Grafov059021b2018-05-02 13:44:46 +0100838 // Lock profiles (if any) on the background thread.
839 final Handler bgHandler = new Handler(Dependency.get(Dependency.BG_LOOPER));
840 bgHandler.post(() -> lockProfiles());
Jason Monk361915c2017-03-21 20:33:59 -0400841 } catch (RemoteException e) {
842 Log.e(TAG, "Error while trying to lock device.", e);
843 }
844 }
845
846 @Override
847 public boolean showDuringKeyguard() {
848 return true;
849 }
850
851 @Override
852 public boolean showBeforeProvisioning() {
853 return false;
854 }
855 };
856 }
857
Pavel Grafov059021b2018-05-02 13:44:46 +0100858 private void lockProfiles() {
Pavel Grafov059021b2018-05-02 13:44:46 +0100859 final int currentUserId = getCurrentUser().id;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500860 final int[] profileIds = mUserManager.getEnabledProfileIds(currentUserId);
Pavel Grafov059021b2018-05-02 13:44:46 +0100861 for (final int id : profileIds) {
862 if (id != currentUserId) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500863 mTrustManager.setDeviceLockedForUser(id, true);
Pavel Grafov059021b2018-05-02 13:44:46 +0100864 }
865 }
866 }
867
Jason Monk361915c2017-03-21 20:33:59 -0400868 private UserInfo getCurrentUser() {
869 try {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500870 return mIActivityManager.getCurrentUser();
Jason Monk361915c2017-03-21 20:33:59 -0400871 } catch (RemoteException re) {
872 return null;
873 }
874 }
875
876 private boolean isCurrentUserOwner() {
877 UserInfo currentUser = getCurrentUser();
878 return currentUser == null || currentUser.isPrimary();
879 }
880
881 private void addUsersToMenu(ArrayList<Action> items) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500882 if (mUserManager.isUserSwitcherEnabled()) {
883 List<UserInfo> users = mUserManager.getUsers();
Jason Monk361915c2017-03-21 20:33:59 -0400884 UserInfo currentUser = getCurrentUser();
885 for (final UserInfo user : users) {
886 if (user.supportsSwitchToByUser()) {
887 boolean isCurrentUser = currentUser == null
888 ? user.id == 0 : (currentUser.id == user.id);
889 Drawable icon = user.iconPath != null ? Drawable.createFromPath(user.iconPath)
890 : null;
891 SinglePressAction switchToUser = new SinglePressAction(
892 R.drawable.ic_menu_cc, icon,
893 (user.name != null ? user.name : "Primary")
Jason Monk16fbd9d2017-04-27 14:28:49 -0400894 + (isCurrentUser ? " \u2714" : "")) {
Jason Monk361915c2017-03-21 20:33:59 -0400895 public void onPress() {
896 try {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500897 mIActivityManager.switchUser(user.id);
Jason Monk361915c2017-03-21 20:33:59 -0400898 } catch (RemoteException re) {
899 Log.e(TAG, "Couldn't switch user " + re);
900 }
901 }
902
903 public boolean showDuringKeyguard() {
904 return true;
905 }
906
907 public boolean showBeforeProvisioning() {
908 return false;
909 }
910 };
911 items.add(switchToUser);
912 }
913 }
914 }
915 }
916
917 private void prepareDialog() {
918 refreshSilentMode();
919 mAirplaneModeOn.updateState(mAirplaneState);
920 mAdapter.notifyDataSetChanged();
Jason Monk361915c2017-03-21 20:33:59 -0400921 if (mShowSilentToggle) {
922 IntentFilter filter = new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION);
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000923 mBroadcastDispatcher.registerReceiver(mRingerModeReceiver, filter);
Jason Monk361915c2017-03-21 20:33:59 -0400924 }
925 }
926
927 private void refreshSilentMode() {
928 if (!mHasVibrator) {
929 final boolean silentModeOn =
930 mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL;
Jason Monk16fbd9d2017-04-27 14:28:49 -0400931 ((ToggleAction) mSilentModeAction).updateState(
Jason Monk361915c2017-03-21 20:33:59 -0400932 silentModeOn ? ToggleAction.State.On : ToggleAction.State.Off);
933 }
934 }
935
936 /** {@inheritDoc} */
937 public void onDismiss(DialogInterface dialog) {
Steve Elliottc3147e22019-11-20 19:34:57 -0500938 if (mDialog == dialog) {
939 mDialog = null;
940 }
Jason Monk361915c2017-03-21 20:33:59 -0400941 mWindowManagerFuncs.onGlobalActionsHidden();
942 if (mShowSilentToggle) {
943 try {
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000944 mBroadcastDispatcher.unregisterReceiver(mRingerModeReceiver);
Jason Monk361915c2017-03-21 20:33:59 -0400945 } catch (IllegalArgumentException ie) {
946 // ignore this
947 Log.w(TAG, ie);
948 }
949 }
950 }
951
952 /** {@inheritDoc} */
Shaotang Li786da902018-08-02 11:18:00 +0800953 public void onShow(DialogInterface dialog) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500954 mMetricsLogger.visible(MetricsEvent.POWER_MENU);
Shaotang Li786da902018-08-02 11:18:00 +0800955 }
956
Jason Monk361915c2017-03-21 20:33:59 -0400957 /**
958 * The adapter used for the list within the global actions dialog, taking
959 * into account whether the keyguard is showing via
Jason Monk16fbd9d2017-04-27 14:28:49 -0400960 * {@link com.android.systemui.globalactions.GlobalActionsDialog#mKeyguardShowing} and whether
961 * the device is provisioned
Jason Monk361915c2017-03-21 20:33:59 -0400962 * via {@link com.android.systemui.globalactions.GlobalActionsDialog#mDeviceProvisioned}.
963 */
Aaron Heuckroth57d60d22019-03-05 14:00:12 -0500964 public class MyAdapter extends MultiListAdapter {
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -0400965 private int countItems(boolean separated) {
Jason Monk361915c2017-03-21 20:33:59 -0400966 int count = 0;
Jason Monk361915c2017-03-21 20:33:59 -0400967 for (int i = 0; i < mItems.size(); i++) {
968 final Action action = mItems.get(i);
969
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -0400970 if (shouldBeShown(action) && action.shouldBeSeparated() == separated) {
971 count++;
Jason Monk361915c2017-03-21 20:33:59 -0400972 }
Jason Monk361915c2017-03-21 20:33:59 -0400973 }
974 return count;
975 }
976
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -0400977 private boolean shouldBeShown(Action action) {
978 if (mKeyguardShowing && !action.showDuringKeyguard()) {
979 return false;
980 }
981 if (!mDeviceProvisioned && !action.showBeforeProvisioning()) {
982 return false;
983 }
984 return true;
985 }
986
987 @Override
988 public int countSeparatedItems() {
989 return countItems(true);
990 }
991
992 @Override
993 public int countListItems() {
994 return countItems(false);
995 }
996
997 @Override
998 public int getCount() {
999 return countSeparatedItems() + countListItems();
1000 }
1001
Jason Monk361915c2017-03-21 20:33:59 -04001002 @Override
1003 public boolean isEnabled(int position) {
1004 return getItem(position).isEnabled();
1005 }
1006
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001007 @Override
Jason Monk361915c2017-03-21 20:33:59 -04001008 public boolean areAllItemsEnabled() {
1009 return false;
1010 }
1011
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001012 @Override
Jason Monk361915c2017-03-21 20:33:59 -04001013 public Action getItem(int position) {
Jason Monk361915c2017-03-21 20:33:59 -04001014 int filteredPos = 0;
1015 for (int i = 0; i < mItems.size(); i++) {
1016 final Action action = mItems.get(i);
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -04001017 if (!shouldBeShown(action)) {
Jason Monk361915c2017-03-21 20:33:59 -04001018 continue;
1019 }
1020 if (filteredPos == position) {
1021 return action;
1022 }
1023 filteredPos++;
1024 }
1025
1026 throw new IllegalArgumentException("position " + position
1027 + " out of range of showable actions"
1028 + ", filtered count=" + getCount()
1029 + ", keyguardshowing=" + mKeyguardShowing
1030 + ", provisioned=" + mDeviceProvisioned);
1031 }
1032
1033
1034 public long getItemId(int position) {
1035 return position;
1036 }
1037
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001038 @Override
Jason Monk361915c2017-03-21 20:33:59 -04001039 public View getView(int position, View convertView, ViewGroup parent) {
1040 Action action = getItem(position);
Jason Monk16fbd9d2017-04-27 14:28:49 -04001041 View view = action.create(mContext, convertView, parent, LayoutInflater.from(mContext));
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -04001042 view.setOnClickListener(v -> onClickItem(position));
1043 view.setOnLongClickListener(v -> onLongClickItem(position));
Jason Monk16fbd9d2017-04-27 14:28:49 -04001044 return view;
Jason Monk361915c2017-03-21 20:33:59 -04001045 }
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001046
1047 @Override
1048 public boolean onLongClickItem(int position) {
1049 final Action action = mAdapter.getItem(position);
1050 if (action instanceof LongPressAction) {
Aran Inkbaa25862019-06-11 15:48:55 -04001051 if (mDialog != null) {
1052 mDialog.dismiss();
1053 } else {
1054 Log.w(TAG, "Action long-clicked while mDialog is null.");
1055 }
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001056 return ((LongPressAction) action).onLongPress();
1057 }
1058 return false;
1059 }
1060
1061 @Override
1062 public void onClickItem(int position) {
1063 Action item = mAdapter.getItem(position);
1064 if (!(item instanceof SilentModeTriStateAction)) {
Aran Inkbaa25862019-06-11 15:48:55 -04001065 if (mDialog != null) {
1066 mDialog.dismiss();
1067 } else {
1068 Log.w(TAG, "Action clicked while mDialog is null.");
1069 }
1070 item.onPress();
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001071 }
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001072 }
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -04001073
1074 @Override
1075 public boolean shouldBeSeparated(int position) {
1076 return getItem(position).shouldBeSeparated();
1077 }
Jason Monk361915c2017-03-21 20:33:59 -04001078 }
1079
1080 // note: the scheme below made more sense when we were planning on having
1081 // 8 different things in the global actions dialog. seems overkill with
1082 // only 3 items now, but may as well keep this flexible approach so it will
1083 // be easy should someone decide at the last minute to include something
1084 // else, such as 'enable wifi', or 'enable bluetooth'
1085
1086 /**
1087 * What each item in the global actions dialog must be able to support.
1088 */
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001089 public interface Action {
Jason Monk361915c2017-03-21 20:33:59 -04001090 /**
1091 * @return Text that will be announced when dialog is created. null
Jason Monk16fbd9d2017-04-27 14:28:49 -04001092 * for none.
Jason Monk361915c2017-03-21 20:33:59 -04001093 */
1094 CharSequence getLabelForAccessibility(Context context);
1095
1096 View create(Context context, View convertView, ViewGroup parent, LayoutInflater inflater);
1097
1098 void onPress();
1099
1100 /**
1101 * @return whether this action should appear in the dialog when the keygaurd
Jason Monk16fbd9d2017-04-27 14:28:49 -04001102 * is showing.
Jason Monk361915c2017-03-21 20:33:59 -04001103 */
1104 boolean showDuringKeyguard();
1105
1106 /**
1107 * @return whether this action should appear in the dialog before the
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001108 * device is provisioned.onlongpress
1109 *
Jason Monk361915c2017-03-21 20:33:59 -04001110 */
1111 boolean showBeforeProvisioning();
1112
1113 boolean isEnabled();
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001114
1115 default boolean shouldBeSeparated() {
1116 return false;
1117 }
Jason Monk361915c2017-03-21 20:33:59 -04001118 }
1119
1120 /**
1121 * An action that also supports long press.
1122 */
1123 private interface LongPressAction extends Action {
1124 boolean onLongPress();
1125 }
1126
1127 /**
1128 * A single press action maintains no state, just responds to a press
1129 * and takes an action.
1130 */
1131 private static abstract class SinglePressAction implements Action {
1132 private final int mIconResId;
1133 private final Drawable mIcon;
1134 private final int mMessageResId;
1135 private final CharSequence mMessage;
1136
1137 protected SinglePressAction(int iconResId, int messageResId) {
1138 mIconResId = iconResId;
1139 mMessageResId = messageResId;
1140 mMessage = null;
1141 mIcon = null;
1142 }
1143
1144 protected SinglePressAction(int iconResId, Drawable icon, CharSequence message) {
1145 mIconResId = iconResId;
1146 mMessageResId = 0;
1147 mMessage = message;
1148 mIcon = icon;
1149 }
1150
1151 public boolean isEnabled() {
1152 return true;
1153 }
1154
1155 public String getStatus() {
1156 return null;
1157 }
1158
1159 abstract public void onPress();
1160
1161 public CharSequence getLabelForAccessibility(Context context) {
1162 if (mMessage != null) {
1163 return mMessage;
1164 } else {
1165 return context.getString(mMessageResId);
1166 }
1167 }
1168
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001169 protected int getActionLayoutId(Context context) {
Matt Pietalfd3b6cb2020-01-08 09:43:54 -05001170 if (isControlsEnabled(context)) {
1171 return com.android.systemui.R.layout.global_actions_grid_item_v2;
1172 }
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001173 return com.android.systemui.R.layout.global_actions_grid_item;
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001174 }
1175
Jason Monk361915c2017-03-21 20:33:59 -04001176 public View create(
1177 Context context, View convertView, ViewGroup parent, LayoutInflater inflater) {
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001178 View v = inflater.inflate(getActionLayoutId(context), parent,
Jason Monk16fbd9d2017-04-27 14:28:49 -04001179 false);
Jason Monk361915c2017-03-21 20:33:59 -04001180
1181 ImageView icon = (ImageView) v.findViewById(R.id.icon);
1182 TextView messageView = (TextView) v.findViewById(R.id.message);
Aaron Heuckroth3f2d8b52019-04-05 13:27:51 -04001183 messageView.setSelected(true); // necessary for marquee to work
Jason Monk361915c2017-03-21 20:33:59 -04001184
Jason Monk361915c2017-03-21 20:33:59 -04001185 if (mIcon != null) {
1186 icon.setImageDrawable(mIcon);
1187 icon.setScaleType(ScaleType.CENTER_CROP);
1188 } else if (mIconResId != 0) {
1189 icon.setImageDrawable(context.getDrawable(mIconResId));
1190 }
1191 if (mMessage != null) {
1192 messageView.setText(mMessage);
1193 } else {
1194 messageView.setText(mMessageResId);
1195 }
1196
1197 return v;
1198 }
1199 }
1200
1201 /**
1202 * A toggle action knows whether it is on or off, and displays an icon
1203 * and status message accordingly.
1204 */
1205 private static abstract class ToggleAction implements Action {
1206
1207 enum State {
1208 Off(false),
1209 TurningOn(true),
1210 TurningOff(true),
1211 On(false);
1212
1213 private final boolean inTransition;
1214
1215 State(boolean intermediate) {
1216 inTransition = intermediate;
1217 }
1218
1219 public boolean inTransition() {
1220 return inTransition;
1221 }
1222 }
1223
1224 protected State mState = State.Off;
1225
1226 // prefs
1227 protected int mEnabledIconResId;
1228 protected int mDisabledIconResid;
1229 protected int mMessageResId;
1230 protected int mEnabledStatusMessageResId;
1231 protected int mDisabledStatusMessageResId;
1232
1233 /**
Jason Monk16fbd9d2017-04-27 14:28:49 -04001234 * @param enabledIconResId The icon for when this action is on.
1235 * @param disabledIconResid The icon for when this action is off.
1236 * @param message The general information message, e.g 'Silent Mode'
1237 * @param enabledStatusMessageResId The on status message, e.g 'sound disabled'
Jason Monk361915c2017-03-21 20:33:59 -04001238 * @param disabledStatusMessageResId The off status message, e.g. 'sound enabled'
1239 */
1240 public ToggleAction(int enabledIconResId,
1241 int disabledIconResid,
1242 int message,
1243 int enabledStatusMessageResId,
1244 int disabledStatusMessageResId) {
1245 mEnabledIconResId = enabledIconResId;
1246 mDisabledIconResid = disabledIconResid;
1247 mMessageResId = message;
1248 mEnabledStatusMessageResId = enabledStatusMessageResId;
1249 mDisabledStatusMessageResId = disabledStatusMessageResId;
1250 }
1251
1252 /**
1253 * Override to make changes to resource IDs just before creating the
1254 * View.
1255 */
1256 void willCreate() {
1257
1258 }
1259
1260 @Override
1261 public CharSequence getLabelForAccessibility(Context context) {
1262 return context.getString(mMessageResId);
1263 }
1264
1265 public View create(Context context, View convertView, ViewGroup parent,
1266 LayoutInflater inflater) {
1267 willCreate();
1268
Koji Fukui5c010ee2019-12-24 16:12:07 +09001269 View v = inflater.inflate(com.android.systemui.R
1270 .layout.global_actions_grid_item, parent, false);
Jason Monk361915c2017-03-21 20:33:59 -04001271
1272 ImageView icon = (ImageView) v.findViewById(R.id.icon);
1273 TextView messageView = (TextView) v.findViewById(R.id.message);
Jason Monk361915c2017-03-21 20:33:59 -04001274 final boolean enabled = isEnabled();
Koji Fukui5c010ee2019-12-24 16:12:07 +09001275 boolean on = ((mState == State.On) || (mState == State.TurningOn));
Jason Monk361915c2017-03-21 20:33:59 -04001276
1277 if (messageView != null) {
Koji Fukui5c010ee2019-12-24 16:12:07 +09001278 messageView.setText(on ? mEnabledStatusMessageResId : mDisabledStatusMessageResId);
Jason Monk361915c2017-03-21 20:33:59 -04001279 messageView.setEnabled(enabled);
Aaron Heuckroth3f2d8b52019-04-05 13:27:51 -04001280 messageView.setSelected(true); // necessary for marquee to work
Jason Monk361915c2017-03-21 20:33:59 -04001281 }
1282
Jason Monk361915c2017-03-21 20:33:59 -04001283 if (icon != null) {
1284 icon.setImageDrawable(context.getDrawable(
1285 (on ? mEnabledIconResId : mDisabledIconResid)));
1286 icon.setEnabled(enabled);
1287 }
1288
Jason Monk361915c2017-03-21 20:33:59 -04001289 v.setEnabled(enabled);
1290
1291 return v;
1292 }
1293
1294 public final void onPress() {
1295 if (mState.inTransition()) {
1296 Log.w(TAG, "shouldn't be able to toggle when in transition");
1297 return;
1298 }
1299
1300 final boolean nowOn = !(mState == State.On);
1301 onToggle(nowOn);
1302 changeStateFromPress(nowOn);
1303 }
1304
1305 public boolean isEnabled() {
1306 return !mState.inTransition();
1307 }
1308
1309 /**
1310 * Implementations may override this if their state can be in on of the intermediate
1311 * states until some notification is received (e.g airplane mode is 'turning off' until
1312 * we know the wireless connections are back online
Jason Monk16fbd9d2017-04-27 14:28:49 -04001313 *
Jason Monk361915c2017-03-21 20:33:59 -04001314 * @param buttonOn Whether the button was turned on or off
1315 */
1316 protected void changeStateFromPress(boolean buttonOn) {
1317 mState = buttonOn ? State.On : State.Off;
1318 }
1319
1320 abstract void onToggle(boolean on);
1321
1322 public void updateState(State state) {
1323 mState = state;
1324 }
1325 }
1326
1327 private class SilentModeToggleAction extends ToggleAction {
1328 public SilentModeToggleAction() {
1329 super(R.drawable.ic_audio_vol_mute,
1330 R.drawable.ic_audio_vol,
1331 R.string.global_action_toggle_silent_mode,
1332 R.string.global_action_silent_mode_on_status,
1333 R.string.global_action_silent_mode_off_status);
1334 }
1335
1336 void onToggle(boolean on) {
1337 if (on) {
1338 mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
1339 } else {
1340 mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
1341 }
1342 }
1343
1344 public boolean showDuringKeyguard() {
1345 return true;
1346 }
1347
1348 public boolean showBeforeProvisioning() {
1349 return false;
1350 }
1351 }
1352
1353 private static class SilentModeTriStateAction implements Action, View.OnClickListener {
1354
Jason Monk16fbd9d2017-04-27 14:28:49 -04001355 private final int[] ITEM_IDS = {R.id.option1, R.id.option2, R.id.option3};
Jason Monk361915c2017-03-21 20:33:59 -04001356
1357 private final AudioManager mAudioManager;
1358 private final Handler mHandler;
Jason Monk361915c2017-03-21 20:33:59 -04001359
Lucas Dupin40ec6b782018-06-05 19:07:16 -07001360 SilentModeTriStateAction(AudioManager audioManager, Handler handler) {
Jason Monk361915c2017-03-21 20:33:59 -04001361 mAudioManager = audioManager;
1362 mHandler = handler;
Jason Monk361915c2017-03-21 20:33:59 -04001363 }
1364
1365 private int ringerModeToIndex(int ringerMode) {
1366 // They just happen to coincide
1367 return ringerMode;
1368 }
1369
1370 private int indexToRingerMode(int index) {
1371 // They just happen to coincide
1372 return index;
1373 }
1374
1375 @Override
1376 public CharSequence getLabelForAccessibility(Context context) {
1377 return null;
1378 }
1379
1380 public View create(Context context, View convertView, ViewGroup parent,
1381 LayoutInflater inflater) {
1382 View v = inflater.inflate(R.layout.global_actions_silent_mode, parent, false);
1383
1384 int selectedIndex = ringerModeToIndex(mAudioManager.getRingerMode());
1385 for (int i = 0; i < 3; i++) {
1386 View itemView = v.findViewById(ITEM_IDS[i]);
1387 itemView.setSelected(selectedIndex == i);
1388 // Set up click handler
1389 itemView.setTag(i);
1390 itemView.setOnClickListener(this);
1391 }
1392 return v;
1393 }
1394
1395 public void onPress() {
1396 }
1397
1398 public boolean showDuringKeyguard() {
1399 return true;
1400 }
1401
1402 public boolean showBeforeProvisioning() {
1403 return false;
1404 }
1405
1406 public boolean isEnabled() {
1407 return true;
1408 }
1409
1410 void willCreate() {
1411 }
1412
1413 public void onClick(View v) {
1414 if (!(v.getTag() instanceof Integer)) return;
1415
1416 int index = (Integer) v.getTag();
1417 mAudioManager.setRingerMode(indexToRingerMode(index));
1418 mHandler.sendEmptyMessageDelayed(MESSAGE_DISMISS, DIALOG_DISMISS_DELAY);
1419 }
1420 }
1421
1422 private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
1423 public void onReceive(Context context, Intent intent) {
1424 String action = intent.getAction();
1425 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)
1426 || Intent.ACTION_SCREEN_OFF.equals(action)) {
1427 String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY);
1428 if (!SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS.equals(reason)) {
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001429 mHandler.sendMessage(mHandler.obtainMessage(MESSAGE_DISMISS, reason));
Jason Monk361915c2017-03-21 20:33:59 -04001430 }
Jayachandran C142eae02019-12-13 19:29:20 -08001431 } else if (TelephonyManager.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED.equals(action)) {
Jason Monk361915c2017-03-21 20:33:59 -04001432 // Airplane mode can be changed after ECM exits if airplane toggle button
1433 // is pressed during ECM mode
Daniel Bright4bcbfce2020-01-09 21:58:16 -08001434 if (!(intent.getBooleanExtra(TelephonyManager.EXTRA_PHONE_IN_ECM_STATE, false))
1435 && mIsWaitingForEcmExit) {
Jason Monk361915c2017-03-21 20:33:59 -04001436 mIsWaitingForEcmExit = false;
1437 changeAirplaneModeSystemSetting(true);
1438 }
1439 }
1440 }
1441 };
1442
1443 PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
1444 @Override
1445 public void onServiceStateChanged(ServiceState serviceState) {
1446 if (!mHasTelephony) return;
1447 final boolean inAirplaneMode = serviceState.getState() == ServiceState.STATE_POWER_OFF;
1448 mAirplaneState = inAirplaneMode ? ToggleAction.State.On : ToggleAction.State.Off;
1449 mAirplaneModeOn.updateState(mAirplaneState);
1450 mAdapter.notifyDataSetChanged();
1451 }
1452 };
1453
1454 private BroadcastReceiver mRingerModeReceiver = new BroadcastReceiver() {
1455 @Override
1456 public void onReceive(Context context, Intent intent) {
1457 if (intent.getAction().equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
1458 mHandler.sendEmptyMessage(MESSAGE_REFRESH);
1459 }
1460 }
1461 };
1462
1463 private ContentObserver mAirplaneModeObserver = new ContentObserver(new Handler()) {
1464 @Override
1465 public void onChange(boolean selfChange) {
1466 onAirplaneModeChanged();
1467 }
1468 };
1469
1470 private static final int MESSAGE_DISMISS = 0;
1471 private static final int MESSAGE_REFRESH = 1;
1472 private static final int MESSAGE_SHOW = 2;
1473 private static final int DIALOG_DISMISS_DELAY = 300; // ms
1474
1475 private Handler mHandler = new Handler() {
1476 public void handleMessage(Message msg) {
1477 switch (msg.what) {
Jason Monk16fbd9d2017-04-27 14:28:49 -04001478 case MESSAGE_DISMISS:
1479 if (mDialog != null) {
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001480 if (SYSTEM_DIALOG_REASON_DREAM.equals(msg.obj)) {
1481 mDialog.dismissImmediately();
1482 } else {
1483 mDialog.dismiss();
1484 }
Jason Monk16fbd9d2017-04-27 14:28:49 -04001485 mDialog = null;
1486 }
1487 break;
1488 case MESSAGE_REFRESH:
1489 refreshSilentMode();
1490 mAdapter.notifyDataSetChanged();
1491 break;
1492 case MESSAGE_SHOW:
1493 handleShow();
1494 break;
Jason Monk361915c2017-03-21 20:33:59 -04001495 }
1496 }
1497 };
1498
1499 private void onAirplaneModeChanged() {
1500 // Let the service state callbacks handle the state.
1501 if (mHasTelephony) return;
1502
1503 boolean airplaneModeOn = Settings.Global.getInt(
Dave Mankoffc88a2d72020-01-10 15:59:31 -05001504 mContentResolver,
Jason Monk361915c2017-03-21 20:33:59 -04001505 Settings.Global.AIRPLANE_MODE_ON,
1506 0) == 1;
1507 mAirplaneState = airplaneModeOn ? ToggleAction.State.On : ToggleAction.State.Off;
1508 mAirplaneModeOn.updateState(mAirplaneState);
1509 }
1510
1511 /**
1512 * Change the airplane mode system setting
1513 */
1514 private void changeAirplaneModeSystemSetting(boolean on) {
1515 Settings.Global.putInt(
Dave Mankoffc88a2d72020-01-10 15:59:31 -05001516 mContentResolver,
Jason Monk361915c2017-03-21 20:33:59 -04001517 Settings.Global.AIRPLANE_MODE_ON,
1518 on ? 1 : 0);
1519 Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
1520 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
1521 intent.putExtra("state", on);
1522 mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
1523 if (!mHasTelephony) {
1524 mAirplaneState = on ? ToggleAction.State.On : ToggleAction.State.Off;
1525 }
1526 }
1527
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001528 private static final class ActionsDialog extends Dialog implements DialogInterface,
1529 ColorExtractor.OnColorsChangedListener {
Jason Monk361915c2017-03-21 20:33:59 -04001530
Jason Monk16fbd9d2017-04-27 14:28:49 -04001531 private final Context mContext;
1532 private final MyAdapter mAdapter;
Steve Elliott53f12ae2019-05-13 17:14:15 -04001533 private final IStatusBarService mStatusBarService;
1534 private final IBinder mToken = new Binder();
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001535 private MultiListLayout mGlobalActionsLayout;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001536 private Drawable mBackgroundDrawable;
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001537 private final SysuiColorExtractor mColorExtractor;
Steve Elliott9b87a442019-03-05 10:24:16 -05001538 private final GlobalActionsPanelPlugin.PanelViewController mPanelController;
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001539 private boolean mKeyguardShowing;
Beverly526d2d62018-08-15 12:55:33 -04001540 private boolean mShowing;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001541 private float mScrimAlpha;
Steve Elliott48f75db2019-05-03 15:03:38 -04001542 private ResetOrientationData mResetOrientationData;
Steve Elliottff2c0d92019-07-30 15:09:54 -04001543 private boolean mHadTopUi;
wilsonshihe8321942019-10-18 18:39:46 +08001544 private final NotificationShadeWindowController mNotificationShadeWindowController;
Lucas Dupin991415e2019-11-25 17:48:58 -08001545 private final BlurUtils mBlurUtils;
1546 private final boolean mControlsEnabled;
Jason Monk16fbd9d2017-04-27 14:28:49 -04001547
Aaron Heuckrothf19d2722019-03-11 17:06:02 -04001548 ActionsDialog(Context context, MyAdapter adapter,
Lucas Dupin991415e2019-11-25 17:48:58 -08001549 GlobalActionsPanelPlugin.PanelViewController plugin, BlurUtils blurUtils,
1550 SysuiColorExtractor sysuiColorExtractor, IStatusBarService statusBarService,
1551 NotificationShadeWindowController notificationShadeWindowController,
Matt Pietalfd3b6cb2020-01-08 09:43:54 -05001552 boolean controlsEnabled) {
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001553 super(context, com.android.systemui.R.style.Theme_SystemUI_Dialog_GlobalActions);
Lucas Dupin448786c2017-07-24 17:44:25 -07001554 mContext = context;
Jason Monk16fbd9d2017-04-27 14:28:49 -04001555 mAdapter = adapter;
Lucas Dupin991415e2019-11-25 17:48:58 -08001556 mBlurUtils = blurUtils;
1557 mColorExtractor = sysuiColorExtractor;
1558 mStatusBarService = statusBarService;
1559 mNotificationShadeWindowController = notificationShadeWindowController;
Matt Pietalfd3b6cb2020-01-08 09:43:54 -05001560 mControlsEnabled = controlsEnabled;
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001561
1562 // Window initialization
1563 Window window = getWindow();
1564 window.requestFeature(Window.FEATURE_NO_TITLE);
Adrian Roosedfab3b2018-03-08 18:39:20 +01001565 // Inflate the decor view, so the attributes below are not overwritten by the theme.
1566 window.getDecorView();
1567 window.getAttributes().systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1568 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1569 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1570 window.setLayout(MATCH_PARENT, MATCH_PARENT);
1571 window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
Alison Cichowlas4f19f4a2017-07-25 10:56:16 -04001572 window.addFlags(
1573 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001574 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
Adrian Roosedfab3b2018-03-08 18:39:20 +01001575 | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001576 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
1577 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
1578 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001579 window.setType(WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY);
Tiger Huang4a7835f2019-11-06 00:07:56 +08001580 window.setFitWindowInsetsTypes(0 /* types */);
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001581 setTitle(R.string.global_actions);
Steve Elliott9b87a442019-03-05 10:24:16 -05001582
1583 mPanelController = plugin;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001584 initializeLayout();
Steve Elliott9b87a442019-03-05 10:24:16 -05001585 }
1586
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001587 private boolean shouldUsePanel() {
Aran Ink3f594552019-05-13 14:29:35 -04001588 return mPanelController != null && mPanelController.getPanelContent() != null;
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001589 }
1590
1591 private void initializePanel() {
Steve Elliott48f75db2019-05-03 15:03:38 -04001592 int rotation = RotationUtils.getRotation(mContext);
1593 boolean rotationLocked = RotationPolicy.isRotationLocked(mContext);
1594 if (rotation != RotationUtils.ROTATION_NONE) {
1595 if (rotationLocked) {
1596 if (mResetOrientationData == null) {
1597 mResetOrientationData = new ResetOrientationData();
1598 mResetOrientationData.locked = true;
1599 mResetOrientationData.rotation = rotation;
1600 }
1601
1602 // Unlock rotation, so user can choose to rotate to portrait to see the panel.
Steve Elliotte05817f2019-05-17 14:39:53 -04001603 // This call is posted so that the rotation does not change until post-layout,
1604 // otherwise onConfigurationChanged() may not get invoked.
1605 mGlobalActionsLayout.post(() ->
1606 RotationPolicy.setRotationLockAtAngle(
1607 mContext, false, RotationUtils.ROTATION_NONE));
Steve Elliott48f75db2019-05-03 15:03:38 -04001608 }
1609 } else {
1610 if (!rotationLocked) {
1611 if (mResetOrientationData == null) {
1612 mResetOrientationData = new ResetOrientationData();
1613 mResetOrientationData.locked = false;
1614 }
1615
1616 // Lock to portrait, so the user doesn't accidentally hide the panel.
Steve Elliotte05817f2019-05-17 14:39:53 -04001617 // This call is posted so that the rotation does not change until post-layout,
1618 // otherwise onConfigurationChanged() may not get invoked.
1619 mGlobalActionsLayout.post(() ->
1620 RotationPolicy.setRotationLockAtAngle(
1621 mContext, true, RotationUtils.ROTATION_NONE));
Steve Elliott48f75db2019-05-03 15:03:38 -04001622 }
1623
Steve Elliott53f12ae2019-05-13 17:14:15 -04001624 // Disable rotation suggestions, if enabled
1625 setRotationSuggestionsEnabled(false);
1626
Steve Elliott300b48f2019-05-29 14:13:50 -04001627 FrameLayout panelContainer =
1628 findViewById(com.android.systemui.R.id.global_actions_panel_container);
Steve Elliott48f75db2019-05-03 15:03:38 -04001629 FrameLayout.LayoutParams panelParams =
1630 new FrameLayout.LayoutParams(
1631 FrameLayout.LayoutParams.MATCH_PARENT,
Steve Elliott300b48f2019-05-29 14:13:50 -04001632 FrameLayout.LayoutParams.MATCH_PARENT);
Steve Elliott48f75db2019-05-03 15:03:38 -04001633 panelContainer.addView(mPanelController.getPanelContent(), panelParams);
Steve Elliott86ef6282019-05-08 14:45:04 -04001634 mBackgroundDrawable = mPanelController.getBackgroundDrawable();
1635 mScrimAlpha = 1f;
Steve Elliott48f75db2019-05-03 15:03:38 -04001636 }
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001637 }
1638
1639 private void initializeLayout() {
1640 setContentView(getGlobalActionsLayoutId(mContext));
Steve Elliott300b48f2019-05-29 14:13:50 -04001641 fixNavBarClipping();
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001642 mGlobalActionsLayout = findViewById(com.android.systemui.R.id.global_actions_view);
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001643 mGlobalActionsLayout.setOutsideTouchListener(view -> dismiss());
Steve Elliott300b48f2019-05-29 14:13:50 -04001644 ((View) mGlobalActionsLayout.getParent()).setOnClickListener(view -> dismiss());
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001645 mGlobalActionsLayout.setListViewAccessibilityDelegate(new View.AccessibilityDelegate() {
Phil Weaver9054e092018-04-27 16:28:50 -07001646 @Override
1647 public boolean dispatchPopulateAccessibilityEvent(
1648 View host, AccessibilityEvent event) {
1649 // Populate the title here, just as Activity does
1650 event.getText().add(mContext.getString(R.string.global_actions));
1651 return true;
1652 }
1653 });
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001654 mGlobalActionsLayout.setRotationListener(this::onRotate);
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001655 mGlobalActionsLayout.setAdapter(mAdapter);
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001656
Steve Elliott86ef6282019-05-08 14:45:04 -04001657 if (shouldUsePanel()) {
Steve Elliottc59eb342019-04-23 16:59:06 -04001658 initializePanel();
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001659 }
Steve Elliott86ef6282019-05-08 14:45:04 -04001660 if (mBackgroundDrawable == null) {
1661 mBackgroundDrawable = new ScrimDrawable();
1662 mScrimAlpha = ScrimController.GRADIENT_SCRIM_ALPHA;
1663 }
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001664 getWindow().setBackgroundDrawable(mBackgroundDrawable);
Steve Elliott9b87a442019-03-05 10:24:16 -05001665 }
1666
Steve Elliott300b48f2019-05-29 14:13:50 -04001667 private void fixNavBarClipping() {
1668 ViewGroup content = findViewById(android.R.id.content);
1669 content.setClipChildren(false);
1670 content.setClipToPadding(false);
1671 ViewGroup contentParent = (ViewGroup) content.getParent();
1672 contentParent.setClipChildren(false);
1673 contentParent.setClipToPadding(false);
1674 }
1675
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001676 private int getGlobalActionsLayoutId(Context context) {
Matt Pietalfd3b6cb2020-01-08 09:43:54 -05001677 if (mControlsEnabled) {
1678 return com.android.systemui.R.layout.global_actions_grid_v2;
1679 }
1680
Steve Elliottdc165632019-05-23 14:26:31 -04001681 int rotation = RotationUtils.getRotation(context);
1682 boolean useGridLayout = isForceGridEnabled(context)
1683 || (shouldUsePanel() && rotation == RotationUtils.ROTATION_NONE);
1684 if (rotation == RotationUtils.ROTATION_SEASCAPE) {
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001685 if (useGridLayout) {
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001686 return com.android.systemui.R.layout.global_actions_grid_seascape;
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001687 } else {
1688 return com.android.systemui.R.layout.global_actions_column_seascape;
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001689 }
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001690 } else {
1691 if (useGridLayout) {
1692 return com.android.systemui.R.layout.global_actions_grid;
1693 } else {
1694 return com.android.systemui.R.layout.global_actions_column;
1695 }
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001696 }
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001697 }
1698
Jason Monk361915c2017-03-21 20:33:59 -04001699 @Override
1700 protected void onStart() {
1701 super.setCanceledOnTouchOutside(true);
1702 super.onStart();
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001703 mGlobalActionsLayout.updateList();
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001704
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001705 if (mBackgroundDrawable instanceof ScrimDrawable) {
Steve Elliott9b87a442019-03-05 10:24:16 -05001706 mColorExtractor.addOnColorsChangedListener(this);
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001707 GradientColors colors = mColorExtractor.getNeutralColors();
Steve Elliott9b87a442019-03-05 10:24:16 -05001708 updateColors(colors, false /* animate */);
1709 }
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001710 }
1711
1712 /**
1713 * Updates background and system bars according to current GradientColors.
1714 * @param colors Colors and hints to use.
1715 * @param animate Interpolates gradient if true, just sets otherwise.
1716 */
1717 private void updateColors(GradientColors colors, boolean animate) {
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001718 if (!(mBackgroundDrawable instanceof ScrimDrawable)) {
Steve Elliott9b87a442019-03-05 10:24:16 -05001719 return;
1720 }
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001721 ((ScrimDrawable) mBackgroundDrawable).setColor(colors.getMainColor(), animate);
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001722 View decorView = getWindow().getDecorView();
1723 if (colors.supportsDarkText()) {
1724 decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR |
Steve Elliott9b87a442019-03-05 10:24:16 -05001725 View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001726 } else {
1727 decorView.setSystemUiVisibility(0);
1728 }
Jason Monk361915c2017-03-21 20:33:59 -04001729 }
1730
1731 @Override
Jason Monk16fbd9d2017-04-27 14:28:49 -04001732 protected void onStop() {
1733 super.onStop();
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001734 mColorExtractor.removeOnColorsChangedListener(this);
Jason Monk16fbd9d2017-04-27 14:28:49 -04001735 }
1736
1737 @Override
1738 public void show() {
1739 super.show();
Beverly526d2d62018-08-15 12:55:33 -04001740 mShowing = true;
wilsonshihe8321942019-10-18 18:39:46 +08001741 mHadTopUi = mNotificationShadeWindowController.getForceHasTopUi();
1742 mNotificationShadeWindowController.setForceHasTopUi(true);
Steve Elliott9b87a442019-03-05 10:24:16 -05001743 mBackgroundDrawable.setAlpha(0);
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001744 mGlobalActionsLayout.setTranslationX(mGlobalActionsLayout.getAnimationOffsetX());
1745 mGlobalActionsLayout.setTranslationY(mGlobalActionsLayout.getAnimationOffsetY());
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001746 mGlobalActionsLayout.setAlpha(0);
1747 mGlobalActionsLayout.animate()
Jason Monk16fbd9d2017-04-27 14:28:49 -04001748 .alpha(1)
1749 .translationX(0)
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001750 .translationY(0)
Jason Monk16fbd9d2017-04-27 14:28:49 -04001751 .setDuration(300)
Lucas Dupinde9db422017-07-19 17:15:41 -07001752 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001753 .setUpdateListener(animation -> {
Lucas Dupin991415e2019-11-25 17:48:58 -08001754 float animatedValue = animation.getAnimatedFraction();
1755 int alpha = (int) (animatedValue * mScrimAlpha * 255);
Steve Elliott9b87a442019-03-05 10:24:16 -05001756 mBackgroundDrawable.setAlpha(alpha);
Lucas Dupin991415e2019-11-25 17:48:58 -08001757 mBlurUtils.applyBlur(mGlobalActionsLayout.getViewRootImpl(),
1758 mBlurUtils.radiusForRatio(animatedValue));
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001759 })
Jason Monk16fbd9d2017-04-27 14:28:49 -04001760 .start();
1761 }
1762
1763 @Override
1764 public void dismiss() {
Beverly526d2d62018-08-15 12:55:33 -04001765 if (!mShowing) {
1766 return;
1767 }
1768 mShowing = false;
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001769 mGlobalActionsLayout.setTranslationX(0);
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001770 mGlobalActionsLayout.setTranslationY(0);
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001771 mGlobalActionsLayout.setAlpha(1);
1772 mGlobalActionsLayout.animate()
Jason Monk16fbd9d2017-04-27 14:28:49 -04001773 .alpha(0)
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001774 .translationX(mGlobalActionsLayout.getAnimationOffsetX())
1775 .translationY(mGlobalActionsLayout.getAnimationOffsetY())
Jason Monk16fbd9d2017-04-27 14:28:49 -04001776 .setDuration(300)
Steve Elliottff2c0d92019-07-30 15:09:54 -04001777 .withEndAction(this::completeDismiss)
Jason Monk16fbd9d2017-04-27 14:28:49 -04001778 .setInterpolator(new LogAccelerateInterpolator())
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001779 .setUpdateListener(animation -> {
Lucas Dupin991415e2019-11-25 17:48:58 -08001780 float animatedValue = 1f - animation.getAnimatedFraction();
1781 int alpha = (int) (animatedValue * mScrimAlpha * 255);
Steve Elliott9b87a442019-03-05 10:24:16 -05001782 mBackgroundDrawable.setAlpha(alpha);
Lucas Dupin991415e2019-11-25 17:48:58 -08001783 mBlurUtils.applyBlur(mGlobalActionsLayout.getViewRootImpl(),
1784 mBlurUtils.radiusForRatio(animatedValue));
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001785 })
Jason Monk16fbd9d2017-04-27 14:28:49 -04001786 .start();
Steve Elliott48f75db2019-05-03 15:03:38 -04001787 dismissPanel();
1788 resetOrientation();
Jason Monk16fbd9d2017-04-27 14:28:49 -04001789 }
1790
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001791 void dismissImmediately() {
Beverly526d2d62018-08-15 12:55:33 -04001792 mShowing = false;
Steve Elliott48f75db2019-05-03 15:03:38 -04001793 dismissPanel();
1794 resetOrientation();
Steve Elliottff2c0d92019-07-30 15:09:54 -04001795 completeDismiss();
1796 }
1797
1798 private void completeDismiss() {
wilsonshihe8321942019-10-18 18:39:46 +08001799 mNotificationShadeWindowController.setForceHasTopUi(mHadTopUi);
Steve Elliottff2c0d92019-07-30 15:09:54 -04001800 super.dismiss();
Steve Elliott48f75db2019-05-03 15:03:38 -04001801 }
1802
1803 private void dismissPanel() {
Steve Elliott2d206d32019-03-14 16:30:33 -04001804 if (mPanelController != null) {
1805 mPanelController.onDismissed();
1806 }
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001807 }
1808
Steve Elliott53f12ae2019-05-13 17:14:15 -04001809 private void setRotationSuggestionsEnabled(boolean enabled) {
1810 try {
1811 final int userId = Binder.getCallingUserHandle().getIdentifier();
1812 final int what = enabled
1813 ? StatusBarManager.DISABLE2_NONE
1814 : StatusBarManager.DISABLE2_ROTATE_SUGGESTIONS;
1815 mStatusBarService.disable2ForUser(what, mToken, mContext.getPackageName(), userId);
1816 } catch (RemoteException ex) {
1817 throw ex.rethrowFromSystemServer();
1818 }
1819 }
1820
Steve Elliott48f75db2019-05-03 15:03:38 -04001821 private void resetOrientation() {
1822 if (mResetOrientationData != null) {
1823 RotationPolicy.setRotationLockAtAngle(mContext, mResetOrientationData.locked,
1824 mResetOrientationData.rotation);
1825 }
Steve Elliott53f12ae2019-05-13 17:14:15 -04001826 setRotationSuggestionsEnabled(true);
Steve Elliott48f75db2019-05-03 15:03:38 -04001827 }
1828
Jason Monk361915c2017-03-21 20:33:59 -04001829 @Override
Lucas Dupin7aaa3532017-05-28 08:51:07 -07001830 public void onColorsChanged(ColorExtractor extractor, int which) {
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001831 if (mKeyguardShowing) {
1832 if ((WallpaperManager.FLAG_LOCK & which) != 0) {
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001833 updateColors(extractor.getColors(WallpaperManager.FLAG_LOCK),
1834 true /* animate */);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001835 }
1836 } else {
1837 if ((WallpaperManager.FLAG_SYSTEM & which) != 0) {
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001838 updateColors(extractor.getColors(WallpaperManager.FLAG_SYSTEM),
1839 true /* animate */);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001840 }
1841 }
1842 }
1843
1844 public void setKeyguardShowing(boolean keyguardShowing) {
1845 mKeyguardShowing = keyguardShowing;
1846 }
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001847
Aaron Heuckroth4ef3a542019-04-01 14:17:23 -04001848 public void refreshDialog() {
1849 initializeLayout();
1850 mGlobalActionsLayout.updateList();
1851 }
1852
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001853 public void onRotate(int from, int to) {
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001854 if (mShowing) {
Aaron Heuckroth4ef3a542019-04-01 14:17:23 -04001855 refreshDialog();
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001856 }
1857 }
Steve Elliott48f75db2019-05-03 15:03:38 -04001858
1859 private static class ResetOrientationData {
1860 public boolean locked;
1861 public int rotation;
1862 }
Jason Monk361915c2017-03-21 20:33:59 -04001863 }
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001864
1865 /**
Aran Ink93dd25c2019-05-09 14:42:14 -04001866 * Determines whether or not debug mode has been activated for the Global Actions Panel.
1867 */
1868 private static boolean isPanelDebugModeEnabled(Context context) {
1869 return Settings.Secure.getInt(context.getContentResolver(),
1870 Settings.Secure.GLOBAL_ACTIONS_PANEL_DEBUG_ENABLED, 0) == 1;
1871 }
1872
1873 /**
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001874 * Determines whether or not the Global Actions menu should be forced to
1875 * use the newer grid-style layout.
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001876 */
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001877 private static boolean isForceGridEnabled(Context context) {
Aran Ink93dd25c2019-05-09 14:42:14 -04001878 return isPanelDebugModeEnabled(context);
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001879 }
Aaron Heuckrothf19d2722019-03-11 17:06:02 -04001880
Aaron Heuckrothf19d2722019-03-11 17:06:02 -04001881
1882 /**
1883 * Determines whether the Global Actions menu should use a separated view for emergency actions.
1884 */
1885 private static boolean shouldUseSeparatedView() {
1886 return true;
1887 }
Matt Pietalfd3b6cb2020-01-08 09:43:54 -05001888
1889 private static boolean isControlsEnabled(Context context) {
1890 return Settings.Secure.getInt(
1891 context.getContentResolver(), "systemui.controls_available", 0) == 1;
1892 }
Jason Monk361915c2017-03-21 20:33:59 -04001893}