blob: fc19fa0c55fc21033878ec32a0c1f92a3dd73425 [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;
62import android.text.TextUtils;
63import android.util.ArraySet;
yuanjiahsu88363e92018-09-06 19:23:52 +080064import android.util.FeatureFlagUtils;
Jason Monk361915c2017-03-21 20:33:59 -040065import android.util.Log;
Lucas Dupin448786c2017-07-24 17:44:25 -070066import android.view.ContextThemeWrapper;
Jason Monk361915c2017-03-21 20:33:59 -040067import android.view.LayoutInflater;
68import android.view.View;
69import android.view.ViewGroup;
Lucas Dupinc1cc7592017-05-22 15:56:16 -070070import android.view.Window;
Jason Monk361915c2017-03-21 20:33:59 -040071import android.view.WindowManager;
72import android.view.WindowManagerGlobal;
73import android.view.accessibility.AccessibilityEvent;
Steve Elliott9b87a442019-03-05 10:24:16 -050074import android.widget.FrameLayout;
Jason Monk361915c2017-03-21 20:33:59 -040075import android.widget.ImageView;
76import android.widget.ImageView.ScaleType;
Jason Monk361915c2017-03-21 20:33:59 -040077import android.widget.TextView;
78
Charles He9851a8d2017-10-10 17:31:30 +010079import com.android.internal.R;
80import com.android.internal.colorextraction.ColorExtractor;
81import com.android.internal.colorextraction.ColorExtractor.GradientColors;
Lucas Dupin2bd3af62019-03-25 17:44:28 -070082import com.android.internal.colorextraction.drawable.ScrimDrawable;
Charles He9851a8d2017-10-10 17:31:30 +010083import com.android.internal.logging.MetricsLogger;
84import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Steve Elliott53f12ae2019-05-13 17:14:15 -040085import com.android.internal.statusbar.IStatusBarService;
Charles He9851a8d2017-10-10 17:31:30 +010086import com.android.internal.util.EmergencyAffordanceManager;
Beth Thibodeau5898ac42018-10-26 13:00:09 -040087import com.android.internal.util.ScreenRecordHelper;
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -050088import com.android.internal.util.ScreenshotHelper;
Steve Elliott48f75db2019-05-03 15:03:38 -040089import com.android.internal.view.RotationPolicy;
Charles He9851a8d2017-10-10 17:31:30 +010090import com.android.internal.widget.LockPatternUtils;
91import com.android.systemui.Dependency;
Charles He9851a8d2017-10-10 17:31:30 +010092import com.android.systemui.Interpolators;
Aaron Heuckrothf708d472019-01-10 16:54:51 -050093import com.android.systemui.MultiListLayout;
Aaron Heuckroth57d60d22019-03-05 14:00:12 -050094import com.android.systemui.MultiListLayout.MultiListAdapter;
Fabian Kozynskiff5e91f2019-09-24 15:38:08 -040095import com.android.systemui.broadcast.BroadcastDispatcher;
Charles He9851a8d2017-10-10 17:31:30 +010096import com.android.systemui.colorextraction.SysuiColorExtractor;
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;
Steve Elliottbfa314a2019-03-06 13:53:19 -0500101import com.android.systemui.statusbar.phone.ScrimController;
Steve Elliottff2c0d92019-07-30 15:09:54 -0400102import com.android.systemui.statusbar.phone.StatusBarWindowController;
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;
Jason Monk361915c2017-03-21 20:33:59 -0400161
162 private ArrayList<Action> mItems;
163 private ActionsDialog mDialog;
164
165 private Action mSilentModeAction;
166 private ToggleAction mAirplaneModeOn;
167
168 private MyAdapter mAdapter;
169
170 private boolean mKeyguardShowing = false;
171 private boolean mDeviceProvisioned = false;
172 private ToggleAction.State mAirplaneState = ToggleAction.State.Off;
173 private boolean mIsWaitingForEcmExit = false;
174 private boolean mHasTelephony;
175 private boolean mHasVibrator;
176 private final boolean mShowSilentToggle;
177 private final EmergencyAffordanceManager mEmergencyAffordanceManager;
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500178 private final ScreenshotHelper mScreenshotHelper;
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400179 private final ScreenRecordHelper mScreenRecordHelper;
Steve Elliotta3f5207922019-03-18 13:37:22 -0400180 private final ActivityStarter mActivityStarter;
181 private GlobalActionsPanelPlugin mPanelPlugin;
Steve Elliott9b87a442019-03-05 10:24:16 -0500182
Jason Monk361915c2017-03-21 20:33:59 -0400183 /**
184 * @param context everything needs a context :(
185 */
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500186 @Inject
187 public GlobalActionsDialog(Context context, GlobalActionsManager windowManagerFuncs,
188 AudioManager audioManager, IDreamManager iDreamManager,
189 DevicePolicyManager devicePolicyManager, LockPatternUtils lockPatternUtils,
190 KeyguardManager keyguardManager, BroadcastDispatcher broadcastDispatcher,
191 ConnectivityManager connectivityManager, TelephonyManager telephonyManager,
192 ContentResolver contentResolver, @Nullable Vibrator vibrator, @Main Resources resources,
193 ConfigurationController configurationController, ActivityStarter activityStarter,
194 KeyguardStateController keyguardStateController, UserManager userManager,
195 TrustManager trustManager, IActivityManager iActivityManager,
196 TelecomManager telecomManager, MetricsLogger metricsLogger) {
Lucas Dupin448786c2017-07-24 17:44:25 -0700197 mContext = new ContextThemeWrapper(context, com.android.systemui.R.style.qs_theme);
Jason Monk361915c2017-03-21 20:33:59 -0400198 mWindowManagerFuncs = windowManagerFuncs;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500199 mAudioManager = audioManager;
200 mDreamManager = iDreamManager;
201 mDevicePolicyManager = devicePolicyManager;
202 mLockPatternUtils = lockPatternUtils;
203 mKeyguardManager = keyguardManager;
204 mBroadcastDispatcher = broadcastDispatcher;
205 mContentResolver = contentResolver;
206 mResources = resources;
207 mUserManager = userManager;
208 mTrustManager = trustManager;
209 mIActivityManager = iActivityManager;
210 mTelecomManager = telecomManager;
211 mMetricsLogger = metricsLogger;
Jason Monk361915c2017-03-21 20:33:59 -0400212
213 // receive broadcasts
214 IntentFilter filter = new IntentFilter();
215 filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
216 filter.addAction(Intent.ACTION_SCREEN_OFF);
Jayachandran C142eae02019-12-13 19:29:20 -0800217 filter.addAction(TelephonyManager.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000218 mBroadcastDispatcher.registerReceiver(mBroadcastReceiver, filter);
Jason Monk361915c2017-03-21 20:33:59 -0400219
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500220 mHasTelephony = connectivityManager.isNetworkSupported(ConnectivityManager.TYPE_MOBILE);
Jason Monk361915c2017-03-21 20:33:59 -0400221
222 // get notified of phone state changes
Jason Monk361915c2017-03-21 20:33:59 -0400223 telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE);
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500224 contentResolver.registerContentObserver(
Jason Monk361915c2017-03-21 20:33:59 -0400225 Settings.Global.getUriFor(Settings.Global.AIRPLANE_MODE_ON), true,
226 mAirplaneModeObserver);
Jason Monk361915c2017-03-21 20:33:59 -0400227 mHasVibrator = vibrator != null && vibrator.hasVibrator();
228
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500229 mShowSilentToggle = SHOW_SILENT_TOGGLE && !resources.getBoolean(
Jason Monk361915c2017-03-21 20:33:59 -0400230 R.bool.config_useFixedVolume);
231
232 mEmergencyAffordanceManager = new EmergencyAffordanceManager(context);
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500233 mScreenshotHelper = new ScreenshotHelper(context);
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400234 mScreenRecordHelper = new ScreenRecordHelper(context);
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700235
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500236 configurationController.addCallback(this);
Steve Elliott9b87a442019-03-05 10:24:16 -0500237
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500238 mActivityStarter = activityStarter;
Lucas Dupinc8f16e82019-09-17 18:24:50 -0400239 keyguardStateController.addCallback(new KeyguardStateController.Callback() {
240 @Override
241 public void onUnlockedChanged() {
242 if (mDialog != null && mDialog.mPanelController != null) {
243 boolean locked = !keyguardStateController.canDismissLockScreen();
244 mDialog.mPanelController.onDeviceLockStateChanged(locked);
245 }
246 }
247 });
Jason Monk361915c2017-03-21 20:33:59 -0400248 }
249
250 /**
251 * Show the global actions dialog (creating if necessary)
Jason Monk16fbd9d2017-04-27 14:28:49 -0400252 *
Jason Monk361915c2017-03-21 20:33:59 -0400253 * @param keyguardShowing True if keyguard is showing
254 */
Steve Elliotta3f5207922019-03-18 13:37:22 -0400255 public void showDialog(boolean keyguardShowing, boolean isDeviceProvisioned,
256 GlobalActionsPanelPlugin panelPlugin) {
Jason Monk361915c2017-03-21 20:33:59 -0400257 mKeyguardShowing = keyguardShowing;
258 mDeviceProvisioned = isDeviceProvisioned;
Steve Elliotta3f5207922019-03-18 13:37:22 -0400259 mPanelPlugin = panelPlugin;
Jason Monk361915c2017-03-21 20:33:59 -0400260 if (mDialog != null) {
261 mDialog.dismiss();
262 mDialog = null;
263 // Show delayed, so that the dismiss of the previous dialog completes
264 mHandler.sendEmptyMessage(MESSAGE_SHOW);
265 } else {
266 handleShow();
267 }
268 }
269
Charles He9851a8d2017-10-10 17:31:30 +0100270 /**
271 * Dismiss the global actions dialog, if it's currently shown
272 */
273 public void dismissDialog() {
274 mHandler.removeMessages(MESSAGE_DISMISS);
275 mHandler.sendEmptyMessage(MESSAGE_DISMISS);
276 }
277
Jason Monk361915c2017-03-21 20:33:59 -0400278 private void awakenIfNecessary() {
279 if (mDreamManager != null) {
280 try {
281 if (mDreamManager.isDreaming()) {
282 mDreamManager.awaken();
283 }
284 } catch (RemoteException e) {
285 // we tried
286 }
287 }
288 }
289
290 private void handleShow() {
291 awakenIfNecessary();
292 mDialog = createDialog();
293 prepareDialog();
294
295 // If we only have 1 item and it's a simple press action, just do this action.
296 if (mAdapter.getCount() == 1
297 && mAdapter.getItem(0) instanceof SinglePressAction
298 && !(mAdapter.getItem(0) instanceof LongPressAction)) {
299 ((SinglePressAction) mAdapter.getItem(0)).onPress();
300 } else {
301 WindowManager.LayoutParams attrs = mDialog.getWindow().getAttributes();
302 attrs.setTitle("ActionsDialog");
Adrian Roos2f05bb32018-02-19 16:42:27 +0100303 attrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
Jason Monk361915c2017-03-21 20:33:59 -0400304 mDialog.getWindow().setAttributes(attrs);
305 mDialog.show();
306 mWindowManagerFuncs.onGlobalActionsShown();
Jason Monk361915c2017-03-21 20:33:59 -0400307 }
308 }
309
310 /**
311 * Create the global actions dialog.
Jason Monk16fbd9d2017-04-27 14:28:49 -0400312 *
Jason Monk361915c2017-03-21 20:33:59 -0400313 * @return A new dialog.
314 */
315 private ActionsDialog createDialog() {
316 // Simple toggle style if there's no vibrator, otherwise use a tri-state
317 if (!mHasVibrator) {
318 mSilentModeAction = new SilentModeToggleAction();
319 } else {
Lucas Dupin40ec6b782018-06-05 19:07:16 -0700320 mSilentModeAction = new SilentModeTriStateAction(mAudioManager, mHandler);
Jason Monk361915c2017-03-21 20:33:59 -0400321 }
322 mAirplaneModeOn = new ToggleAction(
323 R.drawable.ic_lock_airplane_mode,
324 R.drawable.ic_lock_airplane_mode_off,
325 R.string.global_actions_toggle_airplane_mode,
326 R.string.global_actions_airplane_mode_on_status,
327 R.string.global_actions_airplane_mode_off_status) {
328
329 void onToggle(boolean on) {
Inseob Kim5e82f732019-11-08 15:08:38 +0900330 if (mHasTelephony && TelephonyProperties.in_ecm_mode().orElse(false)) {
Jason Monk361915c2017-03-21 20:33:59 -0400331 mIsWaitingForEcmExit = true;
332 // Launch ECM exit dialog
333 Intent ecmDialogIntent =
Jayachandran C142eae02019-12-13 19:29:20 -0800334 new Intent(TelephonyManager.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null);
Jason Monk361915c2017-03-21 20:33:59 -0400335 ecmDialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
336 mContext.startActivity(ecmDialogIntent);
337 } else {
338 changeAirplaneModeSystemSetting(on);
339 }
340 }
341
342 @Override
343 protected void changeStateFromPress(boolean buttonOn) {
344 if (!mHasTelephony) return;
345
346 // In ECM mode airplane state cannot be changed
Inseob Kim5e82f732019-11-08 15:08:38 +0900347 if (!TelephonyProperties.in_ecm_mode().orElse(false)) {
Jason Monk361915c2017-03-21 20:33:59 -0400348 mState = buttonOn ? State.TurningOn : State.TurningOff;
349 mAirplaneState = mState;
350 }
351 }
352
353 public boolean showDuringKeyguard() {
354 return true;
355 }
356
357 public boolean showBeforeProvisioning() {
358 return false;
359 }
360 };
361 onAirplaneModeChanged();
362
363 mItems = new ArrayList<Action>();
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500364 String[] defaultActions = mResources.getStringArray(R.array.config_globalActionsList);
Jason Monk361915c2017-03-21 20:33:59 -0400365
366 ArraySet<String> addedKeys = new ArraySet<String>();
367 for (int i = 0; i < defaultActions.length; i++) {
368 String actionKey = defaultActions[i];
369 if (addedKeys.contains(actionKey)) {
370 // If we already have added this, don't add it again.
371 continue;
372 }
373 if (GLOBAL_ACTION_KEY_POWER.equals(actionKey)) {
374 mItems.add(new PowerAction());
375 } else if (GLOBAL_ACTION_KEY_AIRPLANE.equals(actionKey)) {
376 mItems.add(mAirplaneModeOn);
377 } else if (GLOBAL_ACTION_KEY_BUGREPORT.equals(actionKey)) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500378 if (Settings.Global.getInt(mContentResolver,
Jason Monk361915c2017-03-21 20:33:59 -0400379 Settings.Global.BUGREPORT_IN_POWER_MENU, 0) != 0 && isCurrentUserOwner()) {
380 mItems.add(new BugReportAction());
381 }
382 } else if (GLOBAL_ACTION_KEY_SILENT.equals(actionKey)) {
383 if (mShowSilentToggle) {
384 mItems.add(mSilentModeAction);
385 }
386 } else if (GLOBAL_ACTION_KEY_USERS.equals(actionKey)) {
387 if (SystemProperties.getBoolean("fw.power_user_switcher", false)) {
388 addUsersToMenu(mItems);
389 }
390 } else if (GLOBAL_ACTION_KEY_SETTINGS.equals(actionKey)) {
391 mItems.add(getSettingsAction());
392 } else if (GLOBAL_ACTION_KEY_LOCKDOWN.equals(actionKey)) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500393 if (Settings.Secure.getIntForUser(mContentResolver,
Chad Brubaker02cd6cf2018-05-01 14:59:33 -0700394 Settings.Secure.LOCKDOWN_IN_POWER_MENU, 0, getCurrentUser().id) != 0
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800395 && shouldDisplayLockdown()) {
Chad Brubaker4f28f0d2017-09-07 14:28:13 -0700396 mItems.add(getLockdownAction());
397 }
Jason Monk361915c2017-03-21 20:33:59 -0400398 } else if (GLOBAL_ACTION_KEY_VOICEASSIST.equals(actionKey)) {
399 mItems.add(getVoiceAssistAction());
400 } else if (GLOBAL_ACTION_KEY_ASSIST.equals(actionKey)) {
401 mItems.add(getAssistAction());
402 } else if (GLOBAL_ACTION_KEY_RESTART.equals(actionKey)) {
403 mItems.add(new RestartAction());
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500404 } else if (GLOBAL_ACTION_KEY_SCREENSHOT.equals(actionKey)) {
405 mItems.add(new ScreenshotAction());
Alex Chau04458852017-11-27 18:21:23 +0000406 } else if (GLOBAL_ACTION_KEY_LOGOUT.equals(actionKey)) {
Alex Chaud7958272017-12-08 11:30:52 +0000407 if (mDevicePolicyManager.isLogoutEnabled()
Alex Chau04458852017-11-27 18:21:23 +0000408 && getCurrentUser().id != UserHandle.USER_SYSTEM) {
409 mItems.add(new LogoutAction());
Alex Chau04458852017-11-27 18:21:23 +0000410 }
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800411 } else if (GLOBAL_ACTION_KEY_EMERGENCY.equals(actionKey)) {
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400412 if (!mEmergencyAffordanceManager.needsEmergencyAffordance()) {
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800413 mItems.add(new EmergencyDialerAction());
414 }
Jason Monk361915c2017-03-21 20:33:59 -0400415 } else {
416 Log.e(TAG, "Invalid global action key " + actionKey);
417 }
418 // Add here so we don't add more than one.
419 addedKeys.add(actionKey);
420 }
421
422 if (mEmergencyAffordanceManager.needsEmergencyAffordance()) {
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400423 mItems.add(new EmergencyAffordanceAction());
Jason Monk361915c2017-03-21 20:33:59 -0400424 }
425
426 mAdapter = new MyAdapter();
427
Steve Elliott9b87a442019-03-05 10:24:16 -0500428 GlobalActionsPanelPlugin.PanelViewController panelViewController =
Steve Elliotta3f5207922019-03-18 13:37:22 -0400429 mPanelPlugin != null
430 ? mPanelPlugin.onPanelShown(
Steve Elliott4c868852019-03-14 16:25:41 -0400431 new GlobalActionsPanelPlugin.Callbacks() {
432 @Override
433 public void dismissGlobalActionsMenu() {
Steve Elliottc3147e22019-11-20 19:34:57 -0500434 dismissDialog();
Steve Elliott4c868852019-03-14 16:25:41 -0400435 }
436
437 @Override
438 public void startPendingIntentDismissingKeyguard(
439 PendingIntent intent) {
440 mActivityStarter
441 .startPendingIntentDismissingKeyguard(intent);
442 }
Steve Elliotte2a2e9b2019-04-30 21:31:03 -0400443 },
444 mKeyguardManager.isDeviceLocked())
Steve Elliott9b87a442019-03-05 10:24:16 -0500445 : null;
Steve Elliott02bbaaa2019-05-01 16:55:33 -0400446
Aaron Heuckrothf19d2722019-03-11 17:06:02 -0400447 ActionsDialog dialog = new ActionsDialog(mContext, mAdapter, panelViewController);
Jason Monk361915c2017-03-21 20:33:59 -0400448 dialog.setCanceledOnTouchOutside(false); // Handled by the custom class.
Lucas Dupinc1cc7592017-05-22 15:56:16 -0700449 dialog.setKeyguardShowing(mKeyguardShowing);
Jason Monk361915c2017-03-21 20:33:59 -0400450
451 dialog.setOnDismissListener(this);
Shaotang Li786da902018-08-02 11:18:00 +0800452 dialog.setOnShowListener(this);
Jason Monk361915c2017-03-21 20:33:59 -0400453
454 return dialog;
455 }
456
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800457 private boolean shouldDisplayLockdown() {
458 int userId = getCurrentUser().id;
459 // Lockdown is meaningless without a place to go.
460 if (!mKeyguardManager.isDeviceSecure(userId)) {
461 return false;
462 }
463
464 // Only show the lockdown button if the device isn't locked down (for whatever reason).
465 int state = mLockPatternUtils.getStrongAuthForUser(userId);
466 return (state == STRONG_AUTH_NOT_REQUIRED
467 || state == SOME_AUTH_REQUIRED_AFTER_USER_REQUEST);
468 }
469
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700470 @Override
471 public void onUiModeChanged() {
472 mContext.getTheme().applyStyle(mContext.getThemeResId(), true);
Lucas Dupina4e12ba2019-04-18 11:56:28 -0700473 if (mDialog != null && mDialog.isShowing()) {
Aaron Heuckroth4ef3a542019-04-01 14:17:23 -0400474 mDialog.refreshDialog();
475 }
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700476 }
477
478 public void destroy() {
479 Dependency.get(ConfigurationController.class).removeCallback(this);
480 }
481
Jason Monk361915c2017-03-21 20:33:59 -0400482 private final class PowerAction extends SinglePressAction implements LongPressAction {
483 private PowerAction() {
484 super(R.drawable.ic_lock_power_off,
Jason Monk16fbd9d2017-04-27 14:28:49 -0400485 R.string.global_action_power_off);
Jason Monk361915c2017-03-21 20:33:59 -0400486 }
487
488 @Override
489 public boolean onLongPress() {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500490 if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) {
Jason Monk361915c2017-03-21 20:33:59 -0400491 mWindowManagerFuncs.reboot(true);
492 return true;
493 }
494 return false;
495 }
496
497 @Override
498 public boolean showDuringKeyguard() {
499 return true;
500 }
501
502 @Override
503 public boolean showBeforeProvisioning() {
504 return true;
505 }
506
507 @Override
508 public void onPress() {
509 // shutdown by making sure radio and power are handled accordingly.
510 mWindowManagerFuncs.shutdown();
511 }
512 }
513
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400514 private abstract class EmergencyAction extends SinglePressAction {
515 EmergencyAction(int iconResId, int messageResId) {
516 super(iconResId, messageResId);
517 }
518
519 @Override
520 public boolean shouldBeSeparated() {
521 return shouldUseSeparatedView();
522 }
523
524 @Override
525 public View create(
526 Context context, View convertView, ViewGroup parent, LayoutInflater inflater) {
527 View v = super.create(context, convertView, parent, inflater);
528 int textColor;
529 if (shouldBeSeparated()) {
530 textColor = v.getResources().getColor(
531 com.android.systemui.R.color.global_actions_alert_text);
532 } else {
533 textColor = v.getResources().getColor(
534 com.android.systemui.R.color.global_actions_text);
535 }
536 TextView messageView = v.findViewById(R.id.message);
537 messageView.setTextColor(textColor);
Aaron Heuckroth3f2d8b52019-04-05 13:27:51 -0400538 messageView.setSelected(true); // necessary for marquee to work
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400539 ImageView icon = (ImageView) v.findViewById(R.id.icon);
540 icon.getDrawable().setTint(textColor);
541 return v;
542 }
543
544 @Override
545 public boolean showDuringKeyguard() {
546 return true;
547 }
548
549 @Override
550 public boolean showBeforeProvisioning() {
551 return true;
552 }
553 }
554
555 private class EmergencyAffordanceAction extends EmergencyAction {
556 EmergencyAffordanceAction() {
557 super(R.drawable.emergency_icon,
558 R.string.global_action_emergency);
559 }
560
561 @Override
562 public void onPress() {
563 mEmergencyAffordanceManager.performEmergencyCall();
564 }
565 }
566
567 private class EmergencyDialerAction extends EmergencyAction {
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800568 private EmergencyDialerAction() {
Aran Ink50195262019-05-30 10:55:37 -0400569 super(com.android.systemui.R.drawable.ic_emergency_star,
Wesley.CW Wang3004fcb2018-06-15 16:24:57 +0800570 R.string.global_action_emergency);
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800571 }
572
573 @Override
574 public void onPress() {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500575 mMetricsLogger.action(MetricsEvent.ACTION_EMERGENCY_DIALER_FROM_POWER_MENU);
576 Intent intent = mTelecomManager.createLaunchEmergencyDialerIntent(null /* number */);
Leo Hsue4cc3122019-03-06 15:25:28 +0800577 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
578 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
579 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
Shaotang Li5c422632018-07-04 14:18:40 +0800580 intent.putExtra(EmergencyDialerConstants.EXTRA_ENTRY_TYPE,
581 EmergencyDialerConstants.ENTRY_TYPE_POWER_MENU);
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800582 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
583 }
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800584 }
585
Jason Monk361915c2017-03-21 20:33:59 -0400586 private final class RestartAction extends SinglePressAction implements LongPressAction {
587 private RestartAction() {
588 super(R.drawable.ic_restart, R.string.global_action_restart);
589 }
590
591 @Override
592 public boolean onLongPress() {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500593 if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) {
Jason Monk361915c2017-03-21 20:33:59 -0400594 mWindowManagerFuncs.reboot(true);
595 return true;
596 }
597 return false;
598 }
599
600 @Override
601 public boolean showDuringKeyguard() {
602 return true;
603 }
604
605 @Override
606 public boolean showBeforeProvisioning() {
607 return true;
608 }
609
610 @Override
611 public void onPress() {
612 mWindowManagerFuncs.reboot(false);
613 }
614 }
615
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400616 private class ScreenshotAction extends SinglePressAction implements LongPressAction {
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500617 public ScreenshotAction() {
618 super(R.drawable.ic_screenshot, R.string.global_action_screenshot);
619 }
620
621 @Override
622 public void onPress() {
623 // Add a little delay before executing, to give the
624 // dialog a chance to go away before it takes a
625 // screenshot.
626 // TODO: instead, omit global action dialog layer
627 mHandler.postDelayed(new Runnable() {
628 @Override
629 public void run() {
James O'Learyfa5bb7a2019-09-05 13:43:29 -0400630 mScreenshotHelper.takeScreenshot(1, true, true, mHandler, null);
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500631 mMetricsLogger.action(MetricsEvent.ACTION_SCREENSHOT_POWER_MENU);
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500632 }
633 }, 500);
634 }
635
636 @Override
637 public boolean showDuringKeyguard() {
638 return true;
639 }
640
641 @Override
642 public boolean showBeforeProvisioning() {
643 return false;
644 }
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400645
646 @Override
647 public boolean onLongPress() {
648 if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SCREENRECORD_LONG_PRESS)) {
649 mScreenRecordHelper.launchRecordPrompt();
650 } else {
651 onPress();
652 }
653 return true;
654 }
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500655 }
656
Jason Monk361915c2017-03-21 20:33:59 -0400657 private class BugReportAction extends SinglePressAction implements LongPressAction {
658
659 public BugReportAction() {
660 super(R.drawable.ic_lock_bugreport, R.string.bugreport_title);
661 }
662
663 @Override
664 public void onPress() {
665 // don't actually trigger the bugreport if we are running stability
666 // tests via monkey
667 if (ActivityManager.isUserAMonkey()) {
668 return;
669 }
670 // Add a little delay before executing, to give the
671 // dialog a chance to go away before it takes a
672 // screenshot.
673 mHandler.postDelayed(new Runnable() {
674 @Override
675 public void run() {
676 try {
677 // Take an "interactive" bugreport.
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500678 mMetricsLogger.action(
Jason Monk361915c2017-03-21 20:33:59 -0400679 MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_INTERACTIVE);
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500680 if (!mIActivityManager.launchBugReportHandlerApp()) {
Paul Changc40f5782019-11-04 18:55:31 +0800681 Log.w(TAG, "Bugreport handler could not be launched");
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500682 mIActivityManager.requestInteractiveBugReport();
Paul Changc40f5782019-11-04 18:55:31 +0800683 }
Jason Monk361915c2017-03-21 20:33:59 -0400684 } catch (RemoteException e) {
685 }
686 }
687 }, 500);
688 }
689
690 @Override
691 public boolean onLongPress() {
692 // don't actually trigger the bugreport if we are running stability
693 // tests via monkey
694 if (ActivityManager.isUserAMonkey()) {
695 return false;
696 }
697 try {
698 // Take a "full" bugreport.
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500699 mMetricsLogger.action(MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_FULL);
700 mIActivityManager.requestFullBugReport();
Jason Monk361915c2017-03-21 20:33:59 -0400701 } catch (RemoteException e) {
702 }
703 return false;
704 }
705
706 public boolean showDuringKeyguard() {
707 return true;
708 }
709
710 @Override
711 public boolean showBeforeProvisioning() {
712 return false;
713 }
Jason Monk361915c2017-03-21 20:33:59 -0400714 }
715
Alex Chau04458852017-11-27 18:21:23 +0000716 private final class LogoutAction extends SinglePressAction {
717 private LogoutAction() {
718 super(R.drawable.ic_logout, R.string.global_action_logout);
719 }
720
721 @Override
722 public boolean showDuringKeyguard() {
723 return true;
724 }
725
726 @Override
727 public boolean showBeforeProvisioning() {
728 return false;
729 }
730
731 @Override
732 public void onPress() {
733 // Add a little delay before executing, to give the dialog a chance to go away before
734 // switching user
735 mHandler.postDelayed(() -> {
736 try {
Alex Chauedb6a012018-01-26 12:52:43 +0000737 int currentUserId = getCurrentUser().id;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500738 mIActivityManager.switchUser(UserHandle.USER_SYSTEM);
739 mIActivityManager.stopUser(currentUserId, true /*force*/, null);
Alex Chau04458852017-11-27 18:21:23 +0000740 } catch (RemoteException re) {
741 Log.e(TAG, "Couldn't logout user " + re);
742 }
743 }, 500);
744 }
745 }
746
Jason Monk361915c2017-03-21 20:33:59 -0400747 private Action getSettingsAction() {
748 return new SinglePressAction(R.drawable.ic_settings,
749 R.string.global_action_settings) {
750
751 @Override
752 public void onPress() {
753 Intent intent = new Intent(Settings.ACTION_SETTINGS);
754 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
755 mContext.startActivity(intent);
756 }
757
758 @Override
759 public boolean showDuringKeyguard() {
760 return true;
761 }
762
763 @Override
764 public boolean showBeforeProvisioning() {
765 return true;
766 }
767 };
768 }
769
Jason Monk361915c2017-03-21 20:33:59 -0400770 private Action getAssistAction() {
771 return new SinglePressAction(R.drawable.ic_action_assist_focused,
772 R.string.global_action_assist) {
773 @Override
774 public void onPress() {
775 Intent intent = new Intent(Intent.ACTION_ASSIST);
776 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
777 mContext.startActivity(intent);
778 }
779
780 @Override
781 public boolean showDuringKeyguard() {
782 return true;
783 }
784
785 @Override
786 public boolean showBeforeProvisioning() {
787 return true;
788 }
789 };
790 }
791
792 private Action getVoiceAssistAction() {
793 return new SinglePressAction(R.drawable.ic_voice_search,
794 R.string.global_action_voice_assist) {
795 @Override
796 public void onPress() {
797 Intent intent = new Intent(Intent.ACTION_VOICE_ASSIST);
798 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
799 mContext.startActivity(intent);
800 }
801
802 @Override
803 public boolean showDuringKeyguard() {
804 return true;
805 }
806
807 @Override
808 public boolean showBeforeProvisioning() {
809 return true;
810 }
811 };
812 }
813
814 private Action getLockdownAction() {
Alison Cichowlas21125432018-05-16 15:40:45 -0400815 return new SinglePressAction(R.drawable.ic_lock_lockdown,
Jason Monk361915c2017-03-21 20:33:59 -0400816 R.string.global_action_lockdown) {
817
818 @Override
819 public void onPress() {
Chad Brubaker4f28f0d2017-09-07 14:28:13 -0700820 new LockPatternUtils(mContext)
821 .requireStrongAuth(STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN,
822 UserHandle.USER_ALL);
Jason Monk361915c2017-03-21 20:33:59 -0400823 try {
824 WindowManagerGlobal.getWindowManagerService().lockNow(null);
Pavel Grafov059021b2018-05-02 13:44:46 +0100825 // Lock profiles (if any) on the background thread.
826 final Handler bgHandler = new Handler(Dependency.get(Dependency.BG_LOOPER));
827 bgHandler.post(() -> lockProfiles());
Jason Monk361915c2017-03-21 20:33:59 -0400828 } catch (RemoteException e) {
829 Log.e(TAG, "Error while trying to lock device.", e);
830 }
831 }
832
833 @Override
834 public boolean showDuringKeyguard() {
835 return true;
836 }
837
838 @Override
839 public boolean showBeforeProvisioning() {
840 return false;
841 }
842 };
843 }
844
Pavel Grafov059021b2018-05-02 13:44:46 +0100845 private void lockProfiles() {
Pavel Grafov059021b2018-05-02 13:44:46 +0100846 final int currentUserId = getCurrentUser().id;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500847 final int[] profileIds = mUserManager.getEnabledProfileIds(currentUserId);
Pavel Grafov059021b2018-05-02 13:44:46 +0100848 for (final int id : profileIds) {
849 if (id != currentUserId) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500850 mTrustManager.setDeviceLockedForUser(id, true);
Pavel Grafov059021b2018-05-02 13:44:46 +0100851 }
852 }
853 }
854
Jason Monk361915c2017-03-21 20:33:59 -0400855 private UserInfo getCurrentUser() {
856 try {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500857 return mIActivityManager.getCurrentUser();
Jason Monk361915c2017-03-21 20:33:59 -0400858 } catch (RemoteException re) {
859 return null;
860 }
861 }
862
863 private boolean isCurrentUserOwner() {
864 UserInfo currentUser = getCurrentUser();
865 return currentUser == null || currentUser.isPrimary();
866 }
867
868 private void addUsersToMenu(ArrayList<Action> items) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500869 if (mUserManager.isUserSwitcherEnabled()) {
870 List<UserInfo> users = mUserManager.getUsers();
Jason Monk361915c2017-03-21 20:33:59 -0400871 UserInfo currentUser = getCurrentUser();
872 for (final UserInfo user : users) {
873 if (user.supportsSwitchToByUser()) {
874 boolean isCurrentUser = currentUser == null
875 ? user.id == 0 : (currentUser.id == user.id);
876 Drawable icon = user.iconPath != null ? Drawable.createFromPath(user.iconPath)
877 : null;
878 SinglePressAction switchToUser = new SinglePressAction(
879 R.drawable.ic_menu_cc, icon,
880 (user.name != null ? user.name : "Primary")
Jason Monk16fbd9d2017-04-27 14:28:49 -0400881 + (isCurrentUser ? " \u2714" : "")) {
Jason Monk361915c2017-03-21 20:33:59 -0400882 public void onPress() {
883 try {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500884 mIActivityManager.switchUser(user.id);
Jason Monk361915c2017-03-21 20:33:59 -0400885 } catch (RemoteException re) {
886 Log.e(TAG, "Couldn't switch user " + re);
887 }
888 }
889
890 public boolean showDuringKeyguard() {
891 return true;
892 }
893
894 public boolean showBeforeProvisioning() {
895 return false;
896 }
897 };
898 items.add(switchToUser);
899 }
900 }
901 }
902 }
903
904 private void prepareDialog() {
905 refreshSilentMode();
906 mAirplaneModeOn.updateState(mAirplaneState);
907 mAdapter.notifyDataSetChanged();
Jason Monk361915c2017-03-21 20:33:59 -0400908 if (mShowSilentToggle) {
909 IntentFilter filter = new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION);
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000910 mBroadcastDispatcher.registerReceiver(mRingerModeReceiver, filter);
Jason Monk361915c2017-03-21 20:33:59 -0400911 }
912 }
913
914 private void refreshSilentMode() {
915 if (!mHasVibrator) {
916 final boolean silentModeOn =
917 mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL;
Jason Monk16fbd9d2017-04-27 14:28:49 -0400918 ((ToggleAction) mSilentModeAction).updateState(
Jason Monk361915c2017-03-21 20:33:59 -0400919 silentModeOn ? ToggleAction.State.On : ToggleAction.State.Off);
920 }
921 }
922
923 /** {@inheritDoc} */
924 public void onDismiss(DialogInterface dialog) {
Steve Elliottc3147e22019-11-20 19:34:57 -0500925 if (mDialog == dialog) {
926 mDialog = null;
927 }
Jason Monk361915c2017-03-21 20:33:59 -0400928 mWindowManagerFuncs.onGlobalActionsHidden();
929 if (mShowSilentToggle) {
930 try {
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000931 mBroadcastDispatcher.unregisterReceiver(mRingerModeReceiver);
Jason Monk361915c2017-03-21 20:33:59 -0400932 } catch (IllegalArgumentException ie) {
933 // ignore this
934 Log.w(TAG, ie);
935 }
936 }
937 }
938
939 /** {@inheritDoc} */
Shaotang Li786da902018-08-02 11:18:00 +0800940 public void onShow(DialogInterface dialog) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500941 mMetricsLogger.visible(MetricsEvent.POWER_MENU);
Shaotang Li786da902018-08-02 11:18:00 +0800942 }
943
Jason Monk361915c2017-03-21 20:33:59 -0400944 /**
945 * The adapter used for the list within the global actions dialog, taking
946 * into account whether the keyguard is showing via
Jason Monk16fbd9d2017-04-27 14:28:49 -0400947 * {@link com.android.systemui.globalactions.GlobalActionsDialog#mKeyguardShowing} and whether
948 * the device is provisioned
Jason Monk361915c2017-03-21 20:33:59 -0400949 * via {@link com.android.systemui.globalactions.GlobalActionsDialog#mDeviceProvisioned}.
950 */
Aaron Heuckroth57d60d22019-03-05 14:00:12 -0500951 public class MyAdapter extends MultiListAdapter {
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -0400952 private int countItems(boolean separated) {
Jason Monk361915c2017-03-21 20:33:59 -0400953 int count = 0;
Jason Monk361915c2017-03-21 20:33:59 -0400954 for (int i = 0; i < mItems.size(); i++) {
955 final Action action = mItems.get(i);
956
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -0400957 if (shouldBeShown(action) && action.shouldBeSeparated() == separated) {
958 count++;
Jason Monk361915c2017-03-21 20:33:59 -0400959 }
Jason Monk361915c2017-03-21 20:33:59 -0400960 }
961 return count;
962 }
963
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -0400964 private boolean shouldBeShown(Action action) {
965 if (mKeyguardShowing && !action.showDuringKeyguard()) {
966 return false;
967 }
968 if (!mDeviceProvisioned && !action.showBeforeProvisioning()) {
969 return false;
970 }
971 return true;
972 }
973
974 @Override
975 public int countSeparatedItems() {
976 return countItems(true);
977 }
978
979 @Override
980 public int countListItems() {
981 return countItems(false);
982 }
983
984 @Override
985 public int getCount() {
986 return countSeparatedItems() + countListItems();
987 }
988
Jason Monk361915c2017-03-21 20:33:59 -0400989 @Override
990 public boolean isEnabled(int position) {
991 return getItem(position).isEnabled();
992 }
993
Aaron Heuckroth57d60d22019-03-05 14:00:12 -0500994 @Override
Jason Monk361915c2017-03-21 20:33:59 -0400995 public boolean areAllItemsEnabled() {
996 return false;
997 }
998
Aaron Heuckroth57d60d22019-03-05 14:00:12 -0500999 @Override
Jason Monk361915c2017-03-21 20:33:59 -04001000 public Action getItem(int position) {
Jason Monk361915c2017-03-21 20:33:59 -04001001 int filteredPos = 0;
1002 for (int i = 0; i < mItems.size(); i++) {
1003 final Action action = mItems.get(i);
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -04001004 if (!shouldBeShown(action)) {
Jason Monk361915c2017-03-21 20:33:59 -04001005 continue;
1006 }
1007 if (filteredPos == position) {
1008 return action;
1009 }
1010 filteredPos++;
1011 }
1012
1013 throw new IllegalArgumentException("position " + position
1014 + " out of range of showable actions"
1015 + ", filtered count=" + getCount()
1016 + ", keyguardshowing=" + mKeyguardShowing
1017 + ", provisioned=" + mDeviceProvisioned);
1018 }
1019
1020
1021 public long getItemId(int position) {
1022 return position;
1023 }
1024
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001025 @Override
Jason Monk361915c2017-03-21 20:33:59 -04001026 public View getView(int position, View convertView, ViewGroup parent) {
1027 Action action = getItem(position);
Jason Monk16fbd9d2017-04-27 14:28:49 -04001028 View view = action.create(mContext, convertView, parent, LayoutInflater.from(mContext));
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -04001029 view.setOnClickListener(v -> onClickItem(position));
1030 view.setOnLongClickListener(v -> onLongClickItem(position));
Jason Monk16fbd9d2017-04-27 14:28:49 -04001031 return view;
Jason Monk361915c2017-03-21 20:33:59 -04001032 }
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001033
1034 @Override
1035 public boolean onLongClickItem(int position) {
1036 final Action action = mAdapter.getItem(position);
1037 if (action instanceof LongPressAction) {
Aran Inkbaa25862019-06-11 15:48:55 -04001038 if (mDialog != null) {
1039 mDialog.dismiss();
1040 } else {
1041 Log.w(TAG, "Action long-clicked while mDialog is null.");
1042 }
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001043 return ((LongPressAction) action).onLongPress();
1044 }
1045 return false;
1046 }
1047
1048 @Override
1049 public void onClickItem(int position) {
1050 Action item = mAdapter.getItem(position);
1051 if (!(item instanceof SilentModeTriStateAction)) {
Aran Inkbaa25862019-06-11 15:48:55 -04001052 if (mDialog != null) {
1053 mDialog.dismiss();
1054 } else {
1055 Log.w(TAG, "Action clicked while mDialog is null.");
1056 }
1057 item.onPress();
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001058 }
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001059 }
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -04001060
1061 @Override
1062 public boolean shouldBeSeparated(int position) {
1063 return getItem(position).shouldBeSeparated();
1064 }
Jason Monk361915c2017-03-21 20:33:59 -04001065 }
1066
1067 // note: the scheme below made more sense when we were planning on having
1068 // 8 different things in the global actions dialog. seems overkill with
1069 // only 3 items now, but may as well keep this flexible approach so it will
1070 // be easy should someone decide at the last minute to include something
1071 // else, such as 'enable wifi', or 'enable bluetooth'
1072
1073 /**
1074 * What each item in the global actions dialog must be able to support.
1075 */
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001076 public interface Action {
Jason Monk361915c2017-03-21 20:33:59 -04001077 /**
1078 * @return Text that will be announced when dialog is created. null
Jason Monk16fbd9d2017-04-27 14:28:49 -04001079 * for none.
Jason Monk361915c2017-03-21 20:33:59 -04001080 */
1081 CharSequence getLabelForAccessibility(Context context);
1082
1083 View create(Context context, View convertView, ViewGroup parent, LayoutInflater inflater);
1084
1085 void onPress();
1086
1087 /**
1088 * @return whether this action should appear in the dialog when the keygaurd
Jason Monk16fbd9d2017-04-27 14:28:49 -04001089 * is showing.
Jason Monk361915c2017-03-21 20:33:59 -04001090 */
1091 boolean showDuringKeyguard();
1092
1093 /**
1094 * @return whether this action should appear in the dialog before the
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001095 * device is provisioned.onlongpress
1096 *
Jason Monk361915c2017-03-21 20:33:59 -04001097 */
1098 boolean showBeforeProvisioning();
1099
1100 boolean isEnabled();
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001101
1102 default boolean shouldBeSeparated() {
1103 return false;
1104 }
Jason Monk361915c2017-03-21 20:33:59 -04001105 }
1106
1107 /**
1108 * An action that also supports long press.
1109 */
1110 private interface LongPressAction extends Action {
1111 boolean onLongPress();
1112 }
1113
1114 /**
1115 * A single press action maintains no state, just responds to a press
1116 * and takes an action.
1117 */
1118 private static abstract class SinglePressAction implements Action {
1119 private final int mIconResId;
1120 private final Drawable mIcon;
1121 private final int mMessageResId;
1122 private final CharSequence mMessage;
1123
1124 protected SinglePressAction(int iconResId, int messageResId) {
1125 mIconResId = iconResId;
1126 mMessageResId = messageResId;
1127 mMessage = null;
1128 mIcon = null;
1129 }
1130
1131 protected SinglePressAction(int iconResId, Drawable icon, CharSequence message) {
1132 mIconResId = iconResId;
1133 mMessageResId = 0;
1134 mMessage = message;
1135 mIcon = icon;
1136 }
1137
1138 public boolean isEnabled() {
1139 return true;
1140 }
1141
1142 public String getStatus() {
1143 return null;
1144 }
1145
1146 abstract public void onPress();
1147
1148 public CharSequence getLabelForAccessibility(Context context) {
1149 if (mMessage != null) {
1150 return mMessage;
1151 } else {
1152 return context.getString(mMessageResId);
1153 }
1154 }
1155
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001156 protected int getActionLayoutId(Context context) {
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001157 return com.android.systemui.R.layout.global_actions_grid_item;
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001158 }
1159
Jason Monk361915c2017-03-21 20:33:59 -04001160 public View create(
1161 Context context, View convertView, ViewGroup parent, LayoutInflater inflater) {
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001162 View v = inflater.inflate(getActionLayoutId(context), parent,
Jason Monk16fbd9d2017-04-27 14:28:49 -04001163 false);
Jason Monk361915c2017-03-21 20:33:59 -04001164
1165 ImageView icon = (ImageView) v.findViewById(R.id.icon);
1166 TextView messageView = (TextView) v.findViewById(R.id.message);
Aaron Heuckroth3f2d8b52019-04-05 13:27:51 -04001167 messageView.setSelected(true); // necessary for marquee to work
Jason Monk361915c2017-03-21 20:33:59 -04001168
1169 TextView statusView = (TextView) v.findViewById(R.id.status);
1170 final String status = getStatus();
1171 if (!TextUtils.isEmpty(status)) {
1172 statusView.setText(status);
1173 } else {
1174 statusView.setVisibility(View.GONE);
1175 }
1176 if (mIcon != null) {
1177 icon.setImageDrawable(mIcon);
1178 icon.setScaleType(ScaleType.CENTER_CROP);
1179 } else if (mIconResId != 0) {
1180 icon.setImageDrawable(context.getDrawable(mIconResId));
1181 }
1182 if (mMessage != null) {
1183 messageView.setText(mMessage);
1184 } else {
1185 messageView.setText(mMessageResId);
1186 }
1187
1188 return v;
1189 }
1190 }
1191
1192 /**
1193 * A toggle action knows whether it is on or off, and displays an icon
1194 * and status message accordingly.
1195 */
1196 private static abstract class ToggleAction implements Action {
1197
1198 enum State {
1199 Off(false),
1200 TurningOn(true),
1201 TurningOff(true),
1202 On(false);
1203
1204 private final boolean inTransition;
1205
1206 State(boolean intermediate) {
1207 inTransition = intermediate;
1208 }
1209
1210 public boolean inTransition() {
1211 return inTransition;
1212 }
1213 }
1214
1215 protected State mState = State.Off;
1216
1217 // prefs
1218 protected int mEnabledIconResId;
1219 protected int mDisabledIconResid;
1220 protected int mMessageResId;
1221 protected int mEnabledStatusMessageResId;
1222 protected int mDisabledStatusMessageResId;
1223
1224 /**
Jason Monk16fbd9d2017-04-27 14:28:49 -04001225 * @param enabledIconResId The icon for when this action is on.
1226 * @param disabledIconResid The icon for when this action is off.
1227 * @param message The general information message, e.g 'Silent Mode'
1228 * @param enabledStatusMessageResId The on status message, e.g 'sound disabled'
Jason Monk361915c2017-03-21 20:33:59 -04001229 * @param disabledStatusMessageResId The off status message, e.g. 'sound enabled'
1230 */
1231 public ToggleAction(int enabledIconResId,
1232 int disabledIconResid,
1233 int message,
1234 int enabledStatusMessageResId,
1235 int disabledStatusMessageResId) {
1236 mEnabledIconResId = enabledIconResId;
1237 mDisabledIconResid = disabledIconResid;
1238 mMessageResId = message;
1239 mEnabledStatusMessageResId = enabledStatusMessageResId;
1240 mDisabledStatusMessageResId = disabledStatusMessageResId;
1241 }
1242
1243 /**
1244 * Override to make changes to resource IDs just before creating the
1245 * View.
1246 */
1247 void willCreate() {
1248
1249 }
1250
1251 @Override
1252 public CharSequence getLabelForAccessibility(Context context) {
1253 return context.getString(mMessageResId);
1254 }
1255
1256 public View create(Context context, View convertView, ViewGroup parent,
1257 LayoutInflater inflater) {
1258 willCreate();
1259
1260 View v = inflater.inflate(R
Jason Monk16fbd9d2017-04-27 14:28:49 -04001261 .layout.global_actions_item, parent, false);
Jason Monk361915c2017-03-21 20:33:59 -04001262
1263 ImageView icon = (ImageView) v.findViewById(R.id.icon);
1264 TextView messageView = (TextView) v.findViewById(R.id.message);
1265 TextView statusView = (TextView) v.findViewById(R.id.status);
1266 final boolean enabled = isEnabled();
1267
1268 if (messageView != null) {
1269 messageView.setText(mMessageResId);
1270 messageView.setEnabled(enabled);
Aaron Heuckroth3f2d8b52019-04-05 13:27:51 -04001271 messageView.setSelected(true); // necessary for marquee to work
Jason Monk361915c2017-03-21 20:33:59 -04001272 }
1273
1274 boolean on = ((mState == State.On) || (mState == State.TurningOn));
1275 if (icon != null) {
1276 icon.setImageDrawable(context.getDrawable(
1277 (on ? mEnabledIconResId : mDisabledIconResid)));
1278 icon.setEnabled(enabled);
1279 }
1280
1281 if (statusView != null) {
1282 statusView.setText(on ? mEnabledStatusMessageResId : mDisabledStatusMessageResId);
1283 statusView.setVisibility(View.VISIBLE);
1284 statusView.setEnabled(enabled);
1285 }
1286 v.setEnabled(enabled);
1287
1288 return v;
1289 }
1290
1291 public final void onPress() {
1292 if (mState.inTransition()) {
1293 Log.w(TAG, "shouldn't be able to toggle when in transition");
1294 return;
1295 }
1296
1297 final boolean nowOn = !(mState == State.On);
1298 onToggle(nowOn);
1299 changeStateFromPress(nowOn);
1300 }
1301
1302 public boolean isEnabled() {
1303 return !mState.inTransition();
1304 }
1305
1306 /**
1307 * Implementations may override this if their state can be in on of the intermediate
1308 * states until some notification is received (e.g airplane mode is 'turning off' until
1309 * we know the wireless connections are back online
Jason Monk16fbd9d2017-04-27 14:28:49 -04001310 *
Jason Monk361915c2017-03-21 20:33:59 -04001311 * @param buttonOn Whether the button was turned on or off
1312 */
1313 protected void changeStateFromPress(boolean buttonOn) {
1314 mState = buttonOn ? State.On : State.Off;
1315 }
1316
1317 abstract void onToggle(boolean on);
1318
1319 public void updateState(State state) {
1320 mState = state;
1321 }
1322 }
1323
1324 private class SilentModeToggleAction extends ToggleAction {
1325 public SilentModeToggleAction() {
1326 super(R.drawable.ic_audio_vol_mute,
1327 R.drawable.ic_audio_vol,
1328 R.string.global_action_toggle_silent_mode,
1329 R.string.global_action_silent_mode_on_status,
1330 R.string.global_action_silent_mode_off_status);
1331 }
1332
1333 void onToggle(boolean on) {
1334 if (on) {
1335 mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
1336 } else {
1337 mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
1338 }
1339 }
1340
1341 public boolean showDuringKeyguard() {
1342 return true;
1343 }
1344
1345 public boolean showBeforeProvisioning() {
1346 return false;
1347 }
1348 }
1349
1350 private static class SilentModeTriStateAction implements Action, View.OnClickListener {
1351
Jason Monk16fbd9d2017-04-27 14:28:49 -04001352 private final int[] ITEM_IDS = {R.id.option1, R.id.option2, R.id.option3};
Jason Monk361915c2017-03-21 20:33:59 -04001353
1354 private final AudioManager mAudioManager;
1355 private final Handler mHandler;
Jason Monk361915c2017-03-21 20:33:59 -04001356
Lucas Dupin40ec6b782018-06-05 19:07:16 -07001357 SilentModeTriStateAction(AudioManager audioManager, Handler handler) {
Jason Monk361915c2017-03-21 20:33:59 -04001358 mAudioManager = audioManager;
1359 mHandler = handler;
Jason Monk361915c2017-03-21 20:33:59 -04001360 }
1361
1362 private int ringerModeToIndex(int ringerMode) {
1363 // They just happen to coincide
1364 return ringerMode;
1365 }
1366
1367 private int indexToRingerMode(int index) {
1368 // They just happen to coincide
1369 return index;
1370 }
1371
1372 @Override
1373 public CharSequence getLabelForAccessibility(Context context) {
1374 return null;
1375 }
1376
1377 public View create(Context context, View convertView, ViewGroup parent,
1378 LayoutInflater inflater) {
1379 View v = inflater.inflate(R.layout.global_actions_silent_mode, parent, false);
1380
1381 int selectedIndex = ringerModeToIndex(mAudioManager.getRingerMode());
1382 for (int i = 0; i < 3; i++) {
1383 View itemView = v.findViewById(ITEM_IDS[i]);
1384 itemView.setSelected(selectedIndex == i);
1385 // Set up click handler
1386 itemView.setTag(i);
1387 itemView.setOnClickListener(this);
1388 }
1389 return v;
1390 }
1391
1392 public void onPress() {
1393 }
1394
1395 public boolean showDuringKeyguard() {
1396 return true;
1397 }
1398
1399 public boolean showBeforeProvisioning() {
1400 return false;
1401 }
1402
1403 public boolean isEnabled() {
1404 return true;
1405 }
1406
1407 void willCreate() {
1408 }
1409
1410 public void onClick(View v) {
1411 if (!(v.getTag() instanceof Integer)) return;
1412
1413 int index = (Integer) v.getTag();
1414 mAudioManager.setRingerMode(indexToRingerMode(index));
1415 mHandler.sendEmptyMessageDelayed(MESSAGE_DISMISS, DIALOG_DISMISS_DELAY);
1416 }
1417 }
1418
1419 private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
1420 public void onReceive(Context context, Intent intent) {
1421 String action = intent.getAction();
1422 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)
1423 || Intent.ACTION_SCREEN_OFF.equals(action)) {
1424 String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY);
1425 if (!SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS.equals(reason)) {
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001426 mHandler.sendMessage(mHandler.obtainMessage(MESSAGE_DISMISS, reason));
Jason Monk361915c2017-03-21 20:33:59 -04001427 }
Jayachandran C142eae02019-12-13 19:29:20 -08001428 } else if (TelephonyManager.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED.equals(action)) {
Jason Monk361915c2017-03-21 20:33:59 -04001429 // Airplane mode can be changed after ECM exits if airplane toggle button
1430 // is pressed during ECM mode
1431 if (!(intent.getBooleanExtra("PHONE_IN_ECM_STATE", false)) &&
1432 mIsWaitingForEcmExit) {
1433 mIsWaitingForEcmExit = false;
1434 changeAirplaneModeSystemSetting(true);
1435 }
1436 }
1437 }
1438 };
1439
1440 PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
1441 @Override
1442 public void onServiceStateChanged(ServiceState serviceState) {
1443 if (!mHasTelephony) return;
1444 final boolean inAirplaneMode = serviceState.getState() == ServiceState.STATE_POWER_OFF;
1445 mAirplaneState = inAirplaneMode ? ToggleAction.State.On : ToggleAction.State.Off;
1446 mAirplaneModeOn.updateState(mAirplaneState);
1447 mAdapter.notifyDataSetChanged();
1448 }
1449 };
1450
1451 private BroadcastReceiver mRingerModeReceiver = new BroadcastReceiver() {
1452 @Override
1453 public void onReceive(Context context, Intent intent) {
1454 if (intent.getAction().equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
1455 mHandler.sendEmptyMessage(MESSAGE_REFRESH);
1456 }
1457 }
1458 };
1459
1460 private ContentObserver mAirplaneModeObserver = new ContentObserver(new Handler()) {
1461 @Override
1462 public void onChange(boolean selfChange) {
1463 onAirplaneModeChanged();
1464 }
1465 };
1466
1467 private static final int MESSAGE_DISMISS = 0;
1468 private static final int MESSAGE_REFRESH = 1;
1469 private static final int MESSAGE_SHOW = 2;
1470 private static final int DIALOG_DISMISS_DELAY = 300; // ms
1471
1472 private Handler mHandler = new Handler() {
1473 public void handleMessage(Message msg) {
1474 switch (msg.what) {
Jason Monk16fbd9d2017-04-27 14:28:49 -04001475 case MESSAGE_DISMISS:
1476 if (mDialog != null) {
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001477 if (SYSTEM_DIALOG_REASON_DREAM.equals(msg.obj)) {
1478 mDialog.dismissImmediately();
1479 } else {
1480 mDialog.dismiss();
1481 }
Jason Monk16fbd9d2017-04-27 14:28:49 -04001482 mDialog = null;
1483 }
1484 break;
1485 case MESSAGE_REFRESH:
1486 refreshSilentMode();
1487 mAdapter.notifyDataSetChanged();
1488 break;
1489 case MESSAGE_SHOW:
1490 handleShow();
1491 break;
Jason Monk361915c2017-03-21 20:33:59 -04001492 }
1493 }
1494 };
1495
1496 private void onAirplaneModeChanged() {
1497 // Let the service state callbacks handle the state.
1498 if (mHasTelephony) return;
1499
1500 boolean airplaneModeOn = Settings.Global.getInt(
Dave Mankoffc88a2d72020-01-10 15:59:31 -05001501 mContentResolver,
Jason Monk361915c2017-03-21 20:33:59 -04001502 Settings.Global.AIRPLANE_MODE_ON,
1503 0) == 1;
1504 mAirplaneState = airplaneModeOn ? ToggleAction.State.On : ToggleAction.State.Off;
1505 mAirplaneModeOn.updateState(mAirplaneState);
1506 }
1507
1508 /**
1509 * Change the airplane mode system setting
1510 */
1511 private void changeAirplaneModeSystemSetting(boolean on) {
1512 Settings.Global.putInt(
Dave Mankoffc88a2d72020-01-10 15:59:31 -05001513 mContentResolver,
Jason Monk361915c2017-03-21 20:33:59 -04001514 Settings.Global.AIRPLANE_MODE_ON,
1515 on ? 1 : 0);
1516 Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
1517 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
1518 intent.putExtra("state", on);
1519 mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
1520 if (!mHasTelephony) {
1521 mAirplaneState = on ? ToggleAction.State.On : ToggleAction.State.Off;
1522 }
1523 }
1524
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001525 private static final class ActionsDialog extends Dialog implements DialogInterface,
1526 ColorExtractor.OnColorsChangedListener {
Jason Monk361915c2017-03-21 20:33:59 -04001527
Jason Monk16fbd9d2017-04-27 14:28:49 -04001528 private final Context mContext;
1529 private final MyAdapter mAdapter;
Steve Elliott53f12ae2019-05-13 17:14:15 -04001530 private final IStatusBarService mStatusBarService;
1531 private final IBinder mToken = new Binder();
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001532 private MultiListLayout mGlobalActionsLayout;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001533 private Drawable mBackgroundDrawable;
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001534 private final SysuiColorExtractor mColorExtractor;
Steve Elliott9b87a442019-03-05 10:24:16 -05001535 private final GlobalActionsPanelPlugin.PanelViewController mPanelController;
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001536 private boolean mKeyguardShowing;
Beverly526d2d62018-08-15 12:55:33 -04001537 private boolean mShowing;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001538 private float mScrimAlpha;
Steve Elliott48f75db2019-05-03 15:03:38 -04001539 private ResetOrientationData mResetOrientationData;
Steve Elliottff2c0d92019-07-30 15:09:54 -04001540 private boolean mHadTopUi;
1541 private final StatusBarWindowController mStatusBarWindowController;
Jason Monk16fbd9d2017-04-27 14:28:49 -04001542
Aaron Heuckrothf19d2722019-03-11 17:06:02 -04001543 ActionsDialog(Context context, MyAdapter adapter,
Steve Elliott9b87a442019-03-05 10:24:16 -05001544 GlobalActionsPanelPlugin.PanelViewController plugin) {
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001545 super(context, com.android.systemui.R.style.Theme_SystemUI_Dialog_GlobalActions);
Lucas Dupin448786c2017-07-24 17:44:25 -07001546 mContext = context;
Jason Monk16fbd9d2017-04-27 14:28:49 -04001547 mAdapter = adapter;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -07001548 mColorExtractor = Dependency.get(SysuiColorExtractor.class);
Steve Elliott53f12ae2019-05-13 17:14:15 -04001549 mStatusBarService = Dependency.get(IStatusBarService.class);
Steve Elliottff2c0d92019-07-30 15:09:54 -04001550 mStatusBarWindowController = Dependency.get(StatusBarWindowController.class);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001551
1552 // Window initialization
1553 Window window = getWindow();
1554 window.requestFeature(Window.FEATURE_NO_TITLE);
Adrian Roosedfab3b2018-03-08 18:39:20 +01001555 // Inflate the decor view, so the attributes below are not overwritten by the theme.
1556 window.getDecorView();
1557 window.getAttributes().systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1558 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1559 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1560 window.setLayout(MATCH_PARENT, MATCH_PARENT);
1561 window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
Alison Cichowlas4f19f4a2017-07-25 10:56:16 -04001562 window.addFlags(
1563 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001564 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
Adrian Roosedfab3b2018-03-08 18:39:20 +01001565 | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001566 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
1567 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
1568 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001569 window.setType(WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY);
Tiger Huang4a7835f2019-11-06 00:07:56 +08001570 window.setFitWindowInsetsTypes(0 /* types */);
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001571 setTitle(R.string.global_actions);
Steve Elliott9b87a442019-03-05 10:24:16 -05001572
1573 mPanelController = plugin;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001574 initializeLayout();
Steve Elliott9b87a442019-03-05 10:24:16 -05001575 }
1576
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001577 private boolean shouldUsePanel() {
Aran Ink3f594552019-05-13 14:29:35 -04001578 return mPanelController != null && mPanelController.getPanelContent() != null;
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001579 }
1580
1581 private void initializePanel() {
Steve Elliott48f75db2019-05-03 15:03:38 -04001582 int rotation = RotationUtils.getRotation(mContext);
1583 boolean rotationLocked = RotationPolicy.isRotationLocked(mContext);
1584 if (rotation != RotationUtils.ROTATION_NONE) {
1585 if (rotationLocked) {
1586 if (mResetOrientationData == null) {
1587 mResetOrientationData = new ResetOrientationData();
1588 mResetOrientationData.locked = true;
1589 mResetOrientationData.rotation = rotation;
1590 }
1591
1592 // Unlock rotation, so user can choose to rotate to portrait to see the panel.
Steve Elliotte05817f2019-05-17 14:39:53 -04001593 // This call is posted so that the rotation does not change until post-layout,
1594 // otherwise onConfigurationChanged() may not get invoked.
1595 mGlobalActionsLayout.post(() ->
1596 RotationPolicy.setRotationLockAtAngle(
1597 mContext, false, RotationUtils.ROTATION_NONE));
Steve Elliott48f75db2019-05-03 15:03:38 -04001598 }
1599 } else {
1600 if (!rotationLocked) {
1601 if (mResetOrientationData == null) {
1602 mResetOrientationData = new ResetOrientationData();
1603 mResetOrientationData.locked = false;
1604 }
1605
1606 // Lock to portrait, so the user doesn't accidentally hide the panel.
Steve Elliotte05817f2019-05-17 14:39:53 -04001607 // This call is posted so that the rotation does not change until post-layout,
1608 // otherwise onConfigurationChanged() may not get invoked.
1609 mGlobalActionsLayout.post(() ->
1610 RotationPolicy.setRotationLockAtAngle(
1611 mContext, true, RotationUtils.ROTATION_NONE));
Steve Elliott48f75db2019-05-03 15:03:38 -04001612 }
1613
Steve Elliott53f12ae2019-05-13 17:14:15 -04001614 // Disable rotation suggestions, if enabled
1615 setRotationSuggestionsEnabled(false);
1616
Steve Elliott300b48f2019-05-29 14:13:50 -04001617 FrameLayout panelContainer =
1618 findViewById(com.android.systemui.R.id.global_actions_panel_container);
Steve Elliott48f75db2019-05-03 15:03:38 -04001619 FrameLayout.LayoutParams panelParams =
1620 new FrameLayout.LayoutParams(
1621 FrameLayout.LayoutParams.MATCH_PARENT,
Steve Elliott300b48f2019-05-29 14:13:50 -04001622 FrameLayout.LayoutParams.MATCH_PARENT);
Steve Elliott48f75db2019-05-03 15:03:38 -04001623 panelContainer.addView(mPanelController.getPanelContent(), panelParams);
Steve Elliott86ef6282019-05-08 14:45:04 -04001624 mBackgroundDrawable = mPanelController.getBackgroundDrawable();
1625 mScrimAlpha = 1f;
Steve Elliott48f75db2019-05-03 15:03:38 -04001626 }
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001627 }
1628
1629 private void initializeLayout() {
1630 setContentView(getGlobalActionsLayoutId(mContext));
Steve Elliott300b48f2019-05-29 14:13:50 -04001631 fixNavBarClipping();
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001632 mGlobalActionsLayout = findViewById(com.android.systemui.R.id.global_actions_view);
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001633 mGlobalActionsLayout.setOutsideTouchListener(view -> dismiss());
Steve Elliott300b48f2019-05-29 14:13:50 -04001634 ((View) mGlobalActionsLayout.getParent()).setOnClickListener(view -> dismiss());
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001635 mGlobalActionsLayout.setListViewAccessibilityDelegate(new View.AccessibilityDelegate() {
Phil Weaver9054e092018-04-27 16:28:50 -07001636 @Override
1637 public boolean dispatchPopulateAccessibilityEvent(
1638 View host, AccessibilityEvent event) {
1639 // Populate the title here, just as Activity does
1640 event.getText().add(mContext.getString(R.string.global_actions));
1641 return true;
1642 }
1643 });
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001644 mGlobalActionsLayout.setRotationListener(this::onRotate);
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001645 mGlobalActionsLayout.setAdapter(mAdapter);
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001646
Steve Elliott86ef6282019-05-08 14:45:04 -04001647 if (shouldUsePanel()) {
Steve Elliottc59eb342019-04-23 16:59:06 -04001648 initializePanel();
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001649 }
Steve Elliott86ef6282019-05-08 14:45:04 -04001650 if (mBackgroundDrawable == null) {
1651 mBackgroundDrawable = new ScrimDrawable();
1652 mScrimAlpha = ScrimController.GRADIENT_SCRIM_ALPHA;
1653 }
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001654 getWindow().setBackgroundDrawable(mBackgroundDrawable);
Steve Elliott9b87a442019-03-05 10:24:16 -05001655 }
1656
Steve Elliott300b48f2019-05-29 14:13:50 -04001657 private void fixNavBarClipping() {
1658 ViewGroup content = findViewById(android.R.id.content);
1659 content.setClipChildren(false);
1660 content.setClipToPadding(false);
1661 ViewGroup contentParent = (ViewGroup) content.getParent();
1662 contentParent.setClipChildren(false);
1663 contentParent.setClipToPadding(false);
1664 }
1665
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001666 private int getGlobalActionsLayoutId(Context context) {
Steve Elliottdc165632019-05-23 14:26:31 -04001667 int rotation = RotationUtils.getRotation(context);
1668 boolean useGridLayout = isForceGridEnabled(context)
1669 || (shouldUsePanel() && rotation == RotationUtils.ROTATION_NONE);
1670 if (rotation == RotationUtils.ROTATION_SEASCAPE) {
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001671 if (useGridLayout) {
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001672 return com.android.systemui.R.layout.global_actions_grid_seascape;
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001673 } else {
1674 return com.android.systemui.R.layout.global_actions_column_seascape;
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001675 }
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001676 } else {
1677 if (useGridLayout) {
1678 return com.android.systemui.R.layout.global_actions_grid;
1679 } else {
1680 return com.android.systemui.R.layout.global_actions_column;
1681 }
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001682 }
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001683 }
1684
Jason Monk361915c2017-03-21 20:33:59 -04001685 @Override
1686 protected void onStart() {
1687 super.setCanceledOnTouchOutside(true);
1688 super.onStart();
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001689 mGlobalActionsLayout.updateList();
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001690
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001691 if (mBackgroundDrawable instanceof ScrimDrawable) {
Steve Elliott9b87a442019-03-05 10:24:16 -05001692 mColorExtractor.addOnColorsChangedListener(this);
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001693 GradientColors colors = mColorExtractor.getNeutralColors();
Steve Elliott9b87a442019-03-05 10:24:16 -05001694 updateColors(colors, false /* animate */);
1695 }
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001696 }
1697
1698 /**
1699 * Updates background and system bars according to current GradientColors.
1700 * @param colors Colors and hints to use.
1701 * @param animate Interpolates gradient if true, just sets otherwise.
1702 */
1703 private void updateColors(GradientColors colors, boolean animate) {
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001704 if (!(mBackgroundDrawable instanceof ScrimDrawable)) {
Steve Elliott9b87a442019-03-05 10:24:16 -05001705 return;
1706 }
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001707 ((ScrimDrawable) mBackgroundDrawable).setColor(colors.getMainColor(), animate);
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001708 View decorView = getWindow().getDecorView();
1709 if (colors.supportsDarkText()) {
1710 decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR |
Steve Elliott9b87a442019-03-05 10:24:16 -05001711 View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001712 } else {
1713 decorView.setSystemUiVisibility(0);
1714 }
Jason Monk361915c2017-03-21 20:33:59 -04001715 }
1716
1717 @Override
Jason Monk16fbd9d2017-04-27 14:28:49 -04001718 protected void onStop() {
1719 super.onStop();
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001720 mColorExtractor.removeOnColorsChangedListener(this);
Jason Monk16fbd9d2017-04-27 14:28:49 -04001721 }
1722
1723 @Override
1724 public void show() {
1725 super.show();
Beverly526d2d62018-08-15 12:55:33 -04001726 mShowing = true;
Steve Elliottff2c0d92019-07-30 15:09:54 -04001727 mHadTopUi = mStatusBarWindowController.getForceHasTopUi();
1728 mStatusBarWindowController.setForceHasTopUi(true);
Steve Elliott9b87a442019-03-05 10:24:16 -05001729 mBackgroundDrawable.setAlpha(0);
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001730 mGlobalActionsLayout.setTranslationX(mGlobalActionsLayout.getAnimationOffsetX());
1731 mGlobalActionsLayout.setTranslationY(mGlobalActionsLayout.getAnimationOffsetY());
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001732 mGlobalActionsLayout.setAlpha(0);
1733 mGlobalActionsLayout.animate()
Jason Monk16fbd9d2017-04-27 14:28:49 -04001734 .alpha(1)
1735 .translationX(0)
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001736 .translationY(0)
Jason Monk16fbd9d2017-04-27 14:28:49 -04001737 .setDuration(300)
Lucas Dupinde9db422017-07-19 17:15:41 -07001738 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001739 .setUpdateListener(animation -> {
1740 int alpha = (int) ((Float) animation.getAnimatedValue()
Steve Elliott9b87a442019-03-05 10:24:16 -05001741 * mScrimAlpha * 255);
1742 mBackgroundDrawable.setAlpha(alpha);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001743 })
Jason Monk16fbd9d2017-04-27 14:28:49 -04001744 .start();
1745 }
1746
1747 @Override
1748 public void dismiss() {
Beverly526d2d62018-08-15 12:55:33 -04001749 if (!mShowing) {
1750 return;
1751 }
1752 mShowing = false;
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001753 mGlobalActionsLayout.setTranslationX(0);
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001754 mGlobalActionsLayout.setTranslationY(0);
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001755 mGlobalActionsLayout.setAlpha(1);
1756 mGlobalActionsLayout.animate()
Jason Monk16fbd9d2017-04-27 14:28:49 -04001757 .alpha(0)
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001758 .translationX(mGlobalActionsLayout.getAnimationOffsetX())
1759 .translationY(mGlobalActionsLayout.getAnimationOffsetY())
Jason Monk16fbd9d2017-04-27 14:28:49 -04001760 .setDuration(300)
Steve Elliottff2c0d92019-07-30 15:09:54 -04001761 .withEndAction(this::completeDismiss)
Jason Monk16fbd9d2017-04-27 14:28:49 -04001762 .setInterpolator(new LogAccelerateInterpolator())
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001763 .setUpdateListener(animation -> {
1764 int alpha = (int) ((1f - (Float) animation.getAnimatedValue())
Steve Elliott9b87a442019-03-05 10:24:16 -05001765 * mScrimAlpha * 255);
1766 mBackgroundDrawable.setAlpha(alpha);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001767 })
Jason Monk16fbd9d2017-04-27 14:28:49 -04001768 .start();
Steve Elliott48f75db2019-05-03 15:03:38 -04001769 dismissPanel();
1770 resetOrientation();
Jason Monk16fbd9d2017-04-27 14:28:49 -04001771 }
1772
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001773 void dismissImmediately() {
Beverly526d2d62018-08-15 12:55:33 -04001774 mShowing = false;
Steve Elliott48f75db2019-05-03 15:03:38 -04001775 dismissPanel();
1776 resetOrientation();
Steve Elliottff2c0d92019-07-30 15:09:54 -04001777 completeDismiss();
1778 }
1779
1780 private void completeDismiss() {
1781 mStatusBarWindowController.setForceHasTopUi(mHadTopUi);
1782 super.dismiss();
Steve Elliott48f75db2019-05-03 15:03:38 -04001783 }
1784
1785 private void dismissPanel() {
Steve Elliott2d206d32019-03-14 16:30:33 -04001786 if (mPanelController != null) {
1787 mPanelController.onDismissed();
1788 }
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001789 }
1790
Steve Elliott53f12ae2019-05-13 17:14:15 -04001791 private void setRotationSuggestionsEnabled(boolean enabled) {
1792 try {
1793 final int userId = Binder.getCallingUserHandle().getIdentifier();
1794 final int what = enabled
1795 ? StatusBarManager.DISABLE2_NONE
1796 : StatusBarManager.DISABLE2_ROTATE_SUGGESTIONS;
1797 mStatusBarService.disable2ForUser(what, mToken, mContext.getPackageName(), userId);
1798 } catch (RemoteException ex) {
1799 throw ex.rethrowFromSystemServer();
1800 }
1801 }
1802
Steve Elliott48f75db2019-05-03 15:03:38 -04001803 private void resetOrientation() {
1804 if (mResetOrientationData != null) {
1805 RotationPolicy.setRotationLockAtAngle(mContext, mResetOrientationData.locked,
1806 mResetOrientationData.rotation);
1807 }
Steve Elliott53f12ae2019-05-13 17:14:15 -04001808 setRotationSuggestionsEnabled(true);
Steve Elliott48f75db2019-05-03 15:03:38 -04001809 }
1810
Jason Monk361915c2017-03-21 20:33:59 -04001811 @Override
Lucas Dupin7aaa3532017-05-28 08:51:07 -07001812 public void onColorsChanged(ColorExtractor extractor, int which) {
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001813 if (mKeyguardShowing) {
1814 if ((WallpaperManager.FLAG_LOCK & which) != 0) {
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001815 updateColors(extractor.getColors(WallpaperManager.FLAG_LOCK),
1816 true /* animate */);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001817 }
1818 } else {
1819 if ((WallpaperManager.FLAG_SYSTEM & which) != 0) {
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001820 updateColors(extractor.getColors(WallpaperManager.FLAG_SYSTEM),
1821 true /* animate */);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001822 }
1823 }
1824 }
1825
1826 public void setKeyguardShowing(boolean keyguardShowing) {
1827 mKeyguardShowing = keyguardShowing;
1828 }
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001829
Aaron Heuckroth4ef3a542019-04-01 14:17:23 -04001830 public void refreshDialog() {
1831 initializeLayout();
1832 mGlobalActionsLayout.updateList();
1833 }
1834
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001835 public void onRotate(int from, int to) {
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001836 if (mShowing) {
Aaron Heuckroth4ef3a542019-04-01 14:17:23 -04001837 refreshDialog();
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001838 }
1839 }
Steve Elliott48f75db2019-05-03 15:03:38 -04001840
1841 private static class ResetOrientationData {
1842 public boolean locked;
1843 public int rotation;
1844 }
Jason Monk361915c2017-03-21 20:33:59 -04001845 }
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001846
1847 /**
Aran Ink93dd25c2019-05-09 14:42:14 -04001848 * Determines whether or not debug mode has been activated for the Global Actions Panel.
1849 */
1850 private static boolean isPanelDebugModeEnabled(Context context) {
1851 return Settings.Secure.getInt(context.getContentResolver(),
1852 Settings.Secure.GLOBAL_ACTIONS_PANEL_DEBUG_ENABLED, 0) == 1;
1853 }
1854
1855 /**
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001856 * Determines whether or not the Global Actions menu should be forced to
1857 * use the newer grid-style layout.
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001858 */
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001859 private static boolean isForceGridEnabled(Context context) {
Aran Ink93dd25c2019-05-09 14:42:14 -04001860 return isPanelDebugModeEnabled(context);
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001861 }
Aaron Heuckrothf19d2722019-03-11 17:06:02 -04001862
Aaron Heuckrothf19d2722019-03-11 17:06:02 -04001863
1864 /**
1865 * Determines whether the Global Actions menu should use a separated view for emergency actions.
1866 */
1867 private static boolean shouldUseSeparatedView() {
1868 return true;
1869 }
Jason Monk361915c2017-03-21 20:33:59 -04001870}