blob: 8159567de66b18afe61bd5bac53b51700d08634c [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;
Steve Elliottbfa314a2019-03-06 13:53:19 -0500100import com.android.systemui.statusbar.phone.ScrimController;
Steve Elliottff2c0d92019-07-30 15:09:54 -0400101import com.android.systemui.statusbar.phone.StatusBarWindowController;
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700102import com.android.systemui.statusbar.policy.ConfigurationController;
Lucas Dupinc8f16e82019-09-17 18:24:50 -0400103import com.android.systemui.statusbar.policy.KeyguardStateController;
Shaotang Li5c422632018-07-04 14:18:40 +0800104import com.android.systemui.util.EmergencyDialerConstants;
Aaron Heuckroth75e249f2019-02-01 15:59:57 -0500105import com.android.systemui.util.leak.RotationUtils;
Julia Reynolds42411922017-11-08 11:19:09 -0500106import com.android.systemui.volume.SystemUIInterpolators.LogAccelerateInterpolator;
Lucas Dupinc1cc7592017-05-22 15:56:16 -0700107
Jason Monk361915c2017-03-21 20:33:59 -0400108import java.util.ArrayList;
109import java.util.List;
110
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500111import javax.inject.Inject;
112
Jason Monk361915c2017-03-21 20:33:59 -0400113/**
114 * Helper to show the global actions dialog. Each item is an {@link Action} that
115 * may show depending on whether the keyguard is showing, and whether the device
116 * is provisioned.
117 */
Aaron Heuckroth57d60d22019-03-05 14:00:12 -0500118public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
119 DialogInterface.OnShowListener, ConfigurationController.ConfigurationListener {
Jason Monk361915c2017-03-21 20:33:59 -0400120
121 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
122 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
Lucas Dupin1d4a5792018-04-02 15:14:59 -0700123 static public final String SYSTEM_DIALOG_REASON_DREAM = "dream";
Jason Monk361915c2017-03-21 20:33:59 -0400124
125 private static final String TAG = "GlobalActionsDialog";
126
127 private static final boolean SHOW_SILENT_TOGGLE = true;
128
129 /* Valid settings for global actions keys.
130 * see config.xml config_globalActionList */
131 private static final String GLOBAL_ACTION_KEY_POWER = "power";
132 private static final String GLOBAL_ACTION_KEY_AIRPLANE = "airplane";
133 private static final String GLOBAL_ACTION_KEY_BUGREPORT = "bugreport";
134 private static final String GLOBAL_ACTION_KEY_SILENT = "silent";
135 private static final String GLOBAL_ACTION_KEY_USERS = "users";
136 private static final String GLOBAL_ACTION_KEY_SETTINGS = "settings";
137 private static final String GLOBAL_ACTION_KEY_LOCKDOWN = "lockdown";
138 private static final String GLOBAL_ACTION_KEY_VOICEASSIST = "voiceassist";
139 private static final String GLOBAL_ACTION_KEY_ASSIST = "assist";
140 private static final String GLOBAL_ACTION_KEY_RESTART = "restart";
Alex Chau04458852017-11-27 18:21:23 +0000141 private static final String GLOBAL_ACTION_KEY_LOGOUT = "logout";
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800142 private static final String GLOBAL_ACTION_KEY_EMERGENCY = "emergency";
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500143 private static final String GLOBAL_ACTION_KEY_SCREENSHOT = "screenshot";
Jason Monk361915c2017-03-21 20:33:59 -0400144
145 private final Context mContext;
146 private final GlobalActionsManager mWindowManagerFuncs;
147 private final AudioManager mAudioManager;
148 private final IDreamManager mDreamManager;
Alex Chau04458852017-11-27 18:21:23 +0000149 private final DevicePolicyManager mDevicePolicyManager;
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800150 private final LockPatternUtils mLockPatternUtils;
151 private final KeyguardManager mKeyguardManager;
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000152 private final BroadcastDispatcher mBroadcastDispatcher;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500153 private final ContentResolver mContentResolver;
154 private final Resources mResources;
155 private final UserManager mUserManager;
156 private final TrustManager mTrustManager;
157 private final IActivityManager mIActivityManager;
158 private final TelecomManager mTelecomManager;
159 private final MetricsLogger mMetricsLogger;
Jason Monk361915c2017-03-21 20:33:59 -0400160
161 private ArrayList<Action> mItems;
162 private ActionsDialog mDialog;
163
164 private Action mSilentModeAction;
165 private ToggleAction mAirplaneModeOn;
166
167 private MyAdapter mAdapter;
168
169 private boolean mKeyguardShowing = false;
170 private boolean mDeviceProvisioned = false;
171 private ToggleAction.State mAirplaneState = ToggleAction.State.Off;
172 private boolean mIsWaitingForEcmExit = false;
173 private boolean mHasTelephony;
174 private boolean mHasVibrator;
175 private final boolean mShowSilentToggle;
176 private final EmergencyAffordanceManager mEmergencyAffordanceManager;
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500177 private final ScreenshotHelper mScreenshotHelper;
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400178 private final ScreenRecordHelper mScreenRecordHelper;
Steve Elliotta3f5207922019-03-18 13:37:22 -0400179 private final ActivityStarter mActivityStarter;
180 private GlobalActionsPanelPlugin mPanelPlugin;
Steve Elliott9b87a442019-03-05 10:24:16 -0500181
Jason Monk361915c2017-03-21 20:33:59 -0400182 /**
183 * @param context everything needs a context :(
184 */
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500185 @Inject
186 public GlobalActionsDialog(Context context, GlobalActionsManager windowManagerFuncs,
187 AudioManager audioManager, IDreamManager iDreamManager,
188 DevicePolicyManager devicePolicyManager, LockPatternUtils lockPatternUtils,
189 KeyguardManager keyguardManager, BroadcastDispatcher broadcastDispatcher,
190 ConnectivityManager connectivityManager, TelephonyManager telephonyManager,
191 ContentResolver contentResolver, @Nullable Vibrator vibrator, @Main Resources resources,
192 ConfigurationController configurationController, ActivityStarter activityStarter,
193 KeyguardStateController keyguardStateController, UserManager userManager,
194 TrustManager trustManager, IActivityManager iActivityManager,
195 TelecomManager telecomManager, MetricsLogger metricsLogger) {
Lucas Dupin448786c2017-07-24 17:44:25 -0700196 mContext = new ContextThemeWrapper(context, com.android.systemui.R.style.qs_theme);
Jason Monk361915c2017-03-21 20:33:59 -0400197 mWindowManagerFuncs = windowManagerFuncs;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500198 mAudioManager = audioManager;
199 mDreamManager = iDreamManager;
200 mDevicePolicyManager = devicePolicyManager;
201 mLockPatternUtils = lockPatternUtils;
202 mKeyguardManager = keyguardManager;
203 mBroadcastDispatcher = broadcastDispatcher;
204 mContentResolver = contentResolver;
205 mResources = resources;
206 mUserManager = userManager;
207 mTrustManager = trustManager;
208 mIActivityManager = iActivityManager;
209 mTelecomManager = telecomManager;
210 mMetricsLogger = metricsLogger;
Jason Monk361915c2017-03-21 20:33:59 -0400211
212 // receive broadcasts
213 IntentFilter filter = new IntentFilter();
214 filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
215 filter.addAction(Intent.ACTION_SCREEN_OFF);
Jayachandran C142eae02019-12-13 19:29:20 -0800216 filter.addAction(TelephonyManager.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000217 mBroadcastDispatcher.registerReceiver(mBroadcastReceiver, filter);
Jason Monk361915c2017-03-21 20:33:59 -0400218
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500219 mHasTelephony = connectivityManager.isNetworkSupported(ConnectivityManager.TYPE_MOBILE);
Jason Monk361915c2017-03-21 20:33:59 -0400220
221 // get notified of phone state changes
Jason Monk361915c2017-03-21 20:33:59 -0400222 telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE);
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500223 contentResolver.registerContentObserver(
Jason Monk361915c2017-03-21 20:33:59 -0400224 Settings.Global.getUriFor(Settings.Global.AIRPLANE_MODE_ON), true,
225 mAirplaneModeObserver);
Jason Monk361915c2017-03-21 20:33:59 -0400226 mHasVibrator = vibrator != null && vibrator.hasVibrator();
227
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500228 mShowSilentToggle = SHOW_SILENT_TOGGLE && !resources.getBoolean(
Jason Monk361915c2017-03-21 20:33:59 -0400229 R.bool.config_useFixedVolume);
230
231 mEmergencyAffordanceManager = new EmergencyAffordanceManager(context);
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500232 mScreenshotHelper = new ScreenshotHelper(context);
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400233 mScreenRecordHelper = new ScreenRecordHelper(context);
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700234
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500235 configurationController.addCallback(this);
Steve Elliott9b87a442019-03-05 10:24:16 -0500236
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500237 mActivityStarter = activityStarter;
Lucas Dupinc8f16e82019-09-17 18:24:50 -0400238 keyguardStateController.addCallback(new KeyguardStateController.Callback() {
239 @Override
240 public void onUnlockedChanged() {
241 if (mDialog != null && mDialog.mPanelController != null) {
242 boolean locked = !keyguardStateController.canDismissLockScreen();
243 mDialog.mPanelController.onDeviceLockStateChanged(locked);
244 }
245 }
246 });
Jason Monk361915c2017-03-21 20:33:59 -0400247 }
248
249 /**
250 * Show the global actions dialog (creating if necessary)
Jason Monk16fbd9d2017-04-27 14:28:49 -0400251 *
Jason Monk361915c2017-03-21 20:33:59 -0400252 * @param keyguardShowing True if keyguard is showing
253 */
Steve Elliotta3f5207922019-03-18 13:37:22 -0400254 public void showDialog(boolean keyguardShowing, boolean isDeviceProvisioned,
255 GlobalActionsPanelPlugin panelPlugin) {
Jason Monk361915c2017-03-21 20:33:59 -0400256 mKeyguardShowing = keyguardShowing;
257 mDeviceProvisioned = isDeviceProvisioned;
Steve Elliotta3f5207922019-03-18 13:37:22 -0400258 mPanelPlugin = panelPlugin;
Jason Monk361915c2017-03-21 20:33:59 -0400259 if (mDialog != null) {
260 mDialog.dismiss();
261 mDialog = null;
262 // Show delayed, so that the dismiss of the previous dialog completes
263 mHandler.sendEmptyMessage(MESSAGE_SHOW);
264 } else {
265 handleShow();
266 }
267 }
268
Charles He9851a8d2017-10-10 17:31:30 +0100269 /**
270 * Dismiss the global actions dialog, if it's currently shown
271 */
272 public void dismissDialog() {
273 mHandler.removeMessages(MESSAGE_DISMISS);
274 mHandler.sendEmptyMessage(MESSAGE_DISMISS);
275 }
276
Jason Monk361915c2017-03-21 20:33:59 -0400277 private void awakenIfNecessary() {
278 if (mDreamManager != null) {
279 try {
280 if (mDreamManager.isDreaming()) {
281 mDreamManager.awaken();
282 }
283 } catch (RemoteException e) {
284 // we tried
285 }
286 }
287 }
288
289 private void handleShow() {
290 awakenIfNecessary();
291 mDialog = createDialog();
292 prepareDialog();
293
294 // If we only have 1 item and it's a simple press action, just do this action.
295 if (mAdapter.getCount() == 1
296 && mAdapter.getItem(0) instanceof SinglePressAction
297 && !(mAdapter.getItem(0) instanceof LongPressAction)) {
298 ((SinglePressAction) mAdapter.getItem(0)).onPress();
299 } else {
300 WindowManager.LayoutParams attrs = mDialog.getWindow().getAttributes();
301 attrs.setTitle("ActionsDialog");
Adrian Roos2f05bb32018-02-19 16:42:27 +0100302 attrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
Jason Monk361915c2017-03-21 20:33:59 -0400303 mDialog.getWindow().setAttributes(attrs);
304 mDialog.show();
305 mWindowManagerFuncs.onGlobalActionsShown();
Jason Monk361915c2017-03-21 20:33:59 -0400306 }
307 }
308
309 /**
310 * Create the global actions dialog.
Jason Monk16fbd9d2017-04-27 14:28:49 -0400311 *
Jason Monk361915c2017-03-21 20:33:59 -0400312 * @return A new dialog.
313 */
314 private ActionsDialog createDialog() {
315 // Simple toggle style if there's no vibrator, otherwise use a tri-state
316 if (!mHasVibrator) {
317 mSilentModeAction = new SilentModeToggleAction();
318 } else {
Lucas Dupin40ec6b782018-06-05 19:07:16 -0700319 mSilentModeAction = new SilentModeTriStateAction(mAudioManager, mHandler);
Jason Monk361915c2017-03-21 20:33:59 -0400320 }
321 mAirplaneModeOn = new ToggleAction(
322 R.drawable.ic_lock_airplane_mode,
323 R.drawable.ic_lock_airplane_mode_off,
324 R.string.global_actions_toggle_airplane_mode,
325 R.string.global_actions_airplane_mode_on_status,
326 R.string.global_actions_airplane_mode_off_status) {
327
328 void onToggle(boolean on) {
Inseob Kim5e82f732019-11-08 15:08:38 +0900329 if (mHasTelephony && TelephonyProperties.in_ecm_mode().orElse(false)) {
Jason Monk361915c2017-03-21 20:33:59 -0400330 mIsWaitingForEcmExit = true;
331 // Launch ECM exit dialog
332 Intent ecmDialogIntent =
Jayachandran C142eae02019-12-13 19:29:20 -0800333 new Intent(TelephonyManager.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null);
Jason Monk361915c2017-03-21 20:33:59 -0400334 ecmDialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
335 mContext.startActivity(ecmDialogIntent);
336 } else {
337 changeAirplaneModeSystemSetting(on);
338 }
339 }
340
341 @Override
342 protected void changeStateFromPress(boolean buttonOn) {
343 if (!mHasTelephony) return;
344
345 // In ECM mode airplane state cannot be changed
Inseob Kim5e82f732019-11-08 15:08:38 +0900346 if (!TelephonyProperties.in_ecm_mode().orElse(false)) {
Jason Monk361915c2017-03-21 20:33:59 -0400347 mState = buttonOn ? State.TurningOn : State.TurningOff;
348 mAirplaneState = mState;
349 }
350 }
351
352 public boolean showDuringKeyguard() {
353 return true;
354 }
355
356 public boolean showBeforeProvisioning() {
357 return false;
358 }
359 };
360 onAirplaneModeChanged();
361
362 mItems = new ArrayList<Action>();
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500363 String[] defaultActions = mResources.getStringArray(R.array.config_globalActionsList);
Jason Monk361915c2017-03-21 20:33:59 -0400364
365 ArraySet<String> addedKeys = new ArraySet<String>();
366 for (int i = 0; i < defaultActions.length; i++) {
367 String actionKey = defaultActions[i];
368 if (addedKeys.contains(actionKey)) {
369 // If we already have added this, don't add it again.
370 continue;
371 }
372 if (GLOBAL_ACTION_KEY_POWER.equals(actionKey)) {
373 mItems.add(new PowerAction());
374 } else if (GLOBAL_ACTION_KEY_AIRPLANE.equals(actionKey)) {
375 mItems.add(mAirplaneModeOn);
376 } else if (GLOBAL_ACTION_KEY_BUGREPORT.equals(actionKey)) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500377 if (Settings.Global.getInt(mContentResolver,
Jason Monk361915c2017-03-21 20:33:59 -0400378 Settings.Global.BUGREPORT_IN_POWER_MENU, 0) != 0 && isCurrentUserOwner()) {
379 mItems.add(new BugReportAction());
380 }
381 } else if (GLOBAL_ACTION_KEY_SILENT.equals(actionKey)) {
382 if (mShowSilentToggle) {
383 mItems.add(mSilentModeAction);
384 }
385 } else if (GLOBAL_ACTION_KEY_USERS.equals(actionKey)) {
386 if (SystemProperties.getBoolean("fw.power_user_switcher", false)) {
387 addUsersToMenu(mItems);
388 }
389 } else if (GLOBAL_ACTION_KEY_SETTINGS.equals(actionKey)) {
390 mItems.add(getSettingsAction());
391 } else if (GLOBAL_ACTION_KEY_LOCKDOWN.equals(actionKey)) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500392 if (Settings.Secure.getIntForUser(mContentResolver,
Chad Brubaker02cd6cf2018-05-01 14:59:33 -0700393 Settings.Secure.LOCKDOWN_IN_POWER_MENU, 0, getCurrentUser().id) != 0
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800394 && shouldDisplayLockdown()) {
Chad Brubaker4f28f0d2017-09-07 14:28:13 -0700395 mItems.add(getLockdownAction());
396 }
Jason Monk361915c2017-03-21 20:33:59 -0400397 } else if (GLOBAL_ACTION_KEY_VOICEASSIST.equals(actionKey)) {
398 mItems.add(getVoiceAssistAction());
399 } else if (GLOBAL_ACTION_KEY_ASSIST.equals(actionKey)) {
400 mItems.add(getAssistAction());
401 } else if (GLOBAL_ACTION_KEY_RESTART.equals(actionKey)) {
402 mItems.add(new RestartAction());
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500403 } else if (GLOBAL_ACTION_KEY_SCREENSHOT.equals(actionKey)) {
404 mItems.add(new ScreenshotAction());
Alex Chau04458852017-11-27 18:21:23 +0000405 } else if (GLOBAL_ACTION_KEY_LOGOUT.equals(actionKey)) {
Alex Chaud7958272017-12-08 11:30:52 +0000406 if (mDevicePolicyManager.isLogoutEnabled()
Alex Chau04458852017-11-27 18:21:23 +0000407 && getCurrentUser().id != UserHandle.USER_SYSTEM) {
408 mItems.add(new LogoutAction());
Alex Chau04458852017-11-27 18:21:23 +0000409 }
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800410 } else if (GLOBAL_ACTION_KEY_EMERGENCY.equals(actionKey)) {
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400411 if (!mEmergencyAffordanceManager.needsEmergencyAffordance()) {
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800412 mItems.add(new EmergencyDialerAction());
413 }
Jason Monk361915c2017-03-21 20:33:59 -0400414 } else {
415 Log.e(TAG, "Invalid global action key " + actionKey);
416 }
417 // Add here so we don't add more than one.
418 addedKeys.add(actionKey);
419 }
420
421 if (mEmergencyAffordanceManager.needsEmergencyAffordance()) {
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400422 mItems.add(new EmergencyAffordanceAction());
Jason Monk361915c2017-03-21 20:33:59 -0400423 }
424
425 mAdapter = new MyAdapter();
426
Steve Elliott9b87a442019-03-05 10:24:16 -0500427 GlobalActionsPanelPlugin.PanelViewController panelViewController =
Steve Elliotta3f5207922019-03-18 13:37:22 -0400428 mPanelPlugin != null
429 ? mPanelPlugin.onPanelShown(
Steve Elliott4c868852019-03-14 16:25:41 -0400430 new GlobalActionsPanelPlugin.Callbacks() {
431 @Override
432 public void dismissGlobalActionsMenu() {
Steve Elliottc3147e22019-11-20 19:34:57 -0500433 dismissDialog();
Steve Elliott4c868852019-03-14 16:25:41 -0400434 }
435
436 @Override
437 public void startPendingIntentDismissingKeyguard(
438 PendingIntent intent) {
439 mActivityStarter
440 .startPendingIntentDismissingKeyguard(intent);
441 }
Steve Elliotte2a2e9b2019-04-30 21:31:03 -0400442 },
443 mKeyguardManager.isDeviceLocked())
Steve Elliott9b87a442019-03-05 10:24:16 -0500444 : null;
Steve Elliott02bbaaa2019-05-01 16:55:33 -0400445
Aaron Heuckrothf19d2722019-03-11 17:06:02 -0400446 ActionsDialog dialog = new ActionsDialog(mContext, mAdapter, panelViewController);
Jason Monk361915c2017-03-21 20:33:59 -0400447 dialog.setCanceledOnTouchOutside(false); // Handled by the custom class.
Lucas Dupinc1cc7592017-05-22 15:56:16 -0700448 dialog.setKeyguardShowing(mKeyguardShowing);
Jason Monk361915c2017-03-21 20:33:59 -0400449
450 dialog.setOnDismissListener(this);
Shaotang Li786da902018-08-02 11:18:00 +0800451 dialog.setOnShowListener(this);
Jason Monk361915c2017-03-21 20:33:59 -0400452
453 return dialog;
454 }
455
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800456 private boolean shouldDisplayLockdown() {
457 int userId = getCurrentUser().id;
458 // Lockdown is meaningless without a place to go.
459 if (!mKeyguardManager.isDeviceSecure(userId)) {
460 return false;
461 }
462
463 // Only show the lockdown button if the device isn't locked down (for whatever reason).
464 int state = mLockPatternUtils.getStrongAuthForUser(userId);
465 return (state == STRONG_AUTH_NOT_REQUIRED
466 || state == SOME_AUTH_REQUIRED_AFTER_USER_REQUEST);
467 }
468
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700469 @Override
470 public void onUiModeChanged() {
471 mContext.getTheme().applyStyle(mContext.getThemeResId(), true);
Lucas Dupina4e12ba2019-04-18 11:56:28 -0700472 if (mDialog != null && mDialog.isShowing()) {
Aaron Heuckroth4ef3a542019-04-01 14:17:23 -0400473 mDialog.refreshDialog();
474 }
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700475 }
476
477 public void destroy() {
478 Dependency.get(ConfigurationController.class).removeCallback(this);
479 }
480
Jason Monk361915c2017-03-21 20:33:59 -0400481 private final class PowerAction extends SinglePressAction implements LongPressAction {
482 private PowerAction() {
483 super(R.drawable.ic_lock_power_off,
Jason Monk16fbd9d2017-04-27 14:28:49 -0400484 R.string.global_action_power_off);
Jason Monk361915c2017-03-21 20:33:59 -0400485 }
486
487 @Override
488 public boolean onLongPress() {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500489 if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) {
Jason Monk361915c2017-03-21 20:33:59 -0400490 mWindowManagerFuncs.reboot(true);
491 return true;
492 }
493 return false;
494 }
495
496 @Override
497 public boolean showDuringKeyguard() {
498 return true;
499 }
500
501 @Override
502 public boolean showBeforeProvisioning() {
503 return true;
504 }
505
506 @Override
507 public void onPress() {
508 // shutdown by making sure radio and power are handled accordingly.
509 mWindowManagerFuncs.shutdown();
510 }
511 }
512
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400513 private abstract class EmergencyAction extends SinglePressAction {
514 EmergencyAction(int iconResId, int messageResId) {
515 super(iconResId, messageResId);
516 }
517
518 @Override
519 public boolean shouldBeSeparated() {
520 return shouldUseSeparatedView();
521 }
522
523 @Override
524 public View create(
525 Context context, View convertView, ViewGroup parent, LayoutInflater inflater) {
526 View v = super.create(context, convertView, parent, inflater);
527 int textColor;
528 if (shouldBeSeparated()) {
529 textColor = v.getResources().getColor(
530 com.android.systemui.R.color.global_actions_alert_text);
531 } else {
532 textColor = v.getResources().getColor(
533 com.android.systemui.R.color.global_actions_text);
534 }
535 TextView messageView = v.findViewById(R.id.message);
536 messageView.setTextColor(textColor);
Aaron Heuckroth3f2d8b52019-04-05 13:27:51 -0400537 messageView.setSelected(true); // necessary for marquee to work
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400538 ImageView icon = (ImageView) v.findViewById(R.id.icon);
539 icon.getDrawable().setTint(textColor);
540 return v;
541 }
542
543 @Override
544 public boolean showDuringKeyguard() {
545 return true;
546 }
547
548 @Override
549 public boolean showBeforeProvisioning() {
550 return true;
551 }
552 }
553
554 private class EmergencyAffordanceAction extends EmergencyAction {
555 EmergencyAffordanceAction() {
556 super(R.drawable.emergency_icon,
557 R.string.global_action_emergency);
558 }
559
560 @Override
561 public void onPress() {
562 mEmergencyAffordanceManager.performEmergencyCall();
563 }
564 }
565
566 private class EmergencyDialerAction extends EmergencyAction {
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800567 private EmergencyDialerAction() {
Aran Ink50195262019-05-30 10:55:37 -0400568 super(com.android.systemui.R.drawable.ic_emergency_star,
Wesley.CW Wang3004fcb2018-06-15 16:24:57 +0800569 R.string.global_action_emergency);
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800570 }
571
572 @Override
573 public void onPress() {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500574 mMetricsLogger.action(MetricsEvent.ACTION_EMERGENCY_DIALER_FROM_POWER_MENU);
575 Intent intent = mTelecomManager.createLaunchEmergencyDialerIntent(null /* number */);
Leo Hsue4cc3122019-03-06 15:25:28 +0800576 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
577 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
578 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
Shaotang Li5c422632018-07-04 14:18:40 +0800579 intent.putExtra(EmergencyDialerConstants.EXTRA_ENTRY_TYPE,
580 EmergencyDialerConstants.ENTRY_TYPE_POWER_MENU);
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800581 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
582 }
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800583 }
584
Jason Monk361915c2017-03-21 20:33:59 -0400585 private final class RestartAction extends SinglePressAction implements LongPressAction {
586 private RestartAction() {
587 super(R.drawable.ic_restart, R.string.global_action_restart);
588 }
589
590 @Override
591 public boolean onLongPress() {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500592 if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) {
Jason Monk361915c2017-03-21 20:33:59 -0400593 mWindowManagerFuncs.reboot(true);
594 return true;
595 }
596 return false;
597 }
598
599 @Override
600 public boolean showDuringKeyguard() {
601 return true;
602 }
603
604 @Override
605 public boolean showBeforeProvisioning() {
606 return true;
607 }
608
609 @Override
610 public void onPress() {
611 mWindowManagerFuncs.reboot(false);
612 }
613 }
614
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400615 private class ScreenshotAction extends SinglePressAction implements LongPressAction {
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500616 public ScreenshotAction() {
617 super(R.drawable.ic_screenshot, R.string.global_action_screenshot);
618 }
619
620 @Override
621 public void onPress() {
622 // Add a little delay before executing, to give the
623 // dialog a chance to go away before it takes a
624 // screenshot.
625 // TODO: instead, omit global action dialog layer
626 mHandler.postDelayed(new Runnable() {
627 @Override
628 public void run() {
James O'Learyfa5bb7a2019-09-05 13:43:29 -0400629 mScreenshotHelper.takeScreenshot(1, true, true, mHandler, null);
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500630 mMetricsLogger.action(MetricsEvent.ACTION_SCREENSHOT_POWER_MENU);
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500631 }
632 }, 500);
633 }
634
635 @Override
636 public boolean showDuringKeyguard() {
637 return true;
638 }
639
640 @Override
641 public boolean showBeforeProvisioning() {
642 return false;
643 }
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400644
645 @Override
646 public boolean onLongPress() {
647 if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SCREENRECORD_LONG_PRESS)) {
648 mScreenRecordHelper.launchRecordPrompt();
649 } else {
650 onPress();
651 }
652 return true;
653 }
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500654 }
655
Jason Monk361915c2017-03-21 20:33:59 -0400656 private class BugReportAction extends SinglePressAction implements LongPressAction {
657
658 public BugReportAction() {
659 super(R.drawable.ic_lock_bugreport, R.string.bugreport_title);
660 }
661
662 @Override
663 public void onPress() {
664 // don't actually trigger the bugreport if we are running stability
665 // tests via monkey
666 if (ActivityManager.isUserAMonkey()) {
667 return;
668 }
669 // Add a little delay before executing, to give the
670 // dialog a chance to go away before it takes a
671 // screenshot.
672 mHandler.postDelayed(new Runnable() {
673 @Override
674 public void run() {
675 try {
676 // Take an "interactive" bugreport.
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500677 mMetricsLogger.action(
Jason Monk361915c2017-03-21 20:33:59 -0400678 MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_INTERACTIVE);
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500679 if (!mIActivityManager.launchBugReportHandlerApp()) {
Paul Changc40f5782019-11-04 18:55:31 +0800680 Log.w(TAG, "Bugreport handler could not be launched");
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500681 mIActivityManager.requestInteractiveBugReport();
Paul Changc40f5782019-11-04 18:55:31 +0800682 }
Jason Monk361915c2017-03-21 20:33:59 -0400683 } catch (RemoteException e) {
684 }
685 }
686 }, 500);
687 }
688
689 @Override
690 public boolean onLongPress() {
691 // don't actually trigger the bugreport if we are running stability
692 // tests via monkey
693 if (ActivityManager.isUserAMonkey()) {
694 return false;
695 }
696 try {
697 // Take a "full" bugreport.
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500698 mMetricsLogger.action(MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_FULL);
699 mIActivityManager.requestFullBugReport();
Jason Monk361915c2017-03-21 20:33:59 -0400700 } catch (RemoteException e) {
701 }
702 return false;
703 }
704
705 public boolean showDuringKeyguard() {
706 return true;
707 }
708
709 @Override
710 public boolean showBeforeProvisioning() {
711 return false;
712 }
Jason Monk361915c2017-03-21 20:33:59 -0400713 }
714
Alex Chau04458852017-11-27 18:21:23 +0000715 private final class LogoutAction extends SinglePressAction {
716 private LogoutAction() {
717 super(R.drawable.ic_logout, R.string.global_action_logout);
718 }
719
720 @Override
721 public boolean showDuringKeyguard() {
722 return true;
723 }
724
725 @Override
726 public boolean showBeforeProvisioning() {
727 return false;
728 }
729
730 @Override
731 public void onPress() {
732 // Add a little delay before executing, to give the dialog a chance to go away before
733 // switching user
734 mHandler.postDelayed(() -> {
735 try {
Alex Chauedb6a012018-01-26 12:52:43 +0000736 int currentUserId = getCurrentUser().id;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500737 mIActivityManager.switchUser(UserHandle.USER_SYSTEM);
738 mIActivityManager.stopUser(currentUserId, true /*force*/, null);
Alex Chau04458852017-11-27 18:21:23 +0000739 } catch (RemoteException re) {
740 Log.e(TAG, "Couldn't logout user " + re);
741 }
742 }, 500);
743 }
744 }
745
Jason Monk361915c2017-03-21 20:33:59 -0400746 private Action getSettingsAction() {
747 return new SinglePressAction(R.drawable.ic_settings,
748 R.string.global_action_settings) {
749
750 @Override
751 public void onPress() {
752 Intent intent = new Intent(Settings.ACTION_SETTINGS);
753 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
754 mContext.startActivity(intent);
755 }
756
757 @Override
758 public boolean showDuringKeyguard() {
759 return true;
760 }
761
762 @Override
763 public boolean showBeforeProvisioning() {
764 return true;
765 }
766 };
767 }
768
Jason Monk361915c2017-03-21 20:33:59 -0400769 private Action getAssistAction() {
770 return new SinglePressAction(R.drawable.ic_action_assist_focused,
771 R.string.global_action_assist) {
772 @Override
773 public void onPress() {
774 Intent intent = new Intent(Intent.ACTION_ASSIST);
775 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
776 mContext.startActivity(intent);
777 }
778
779 @Override
780 public boolean showDuringKeyguard() {
781 return true;
782 }
783
784 @Override
785 public boolean showBeforeProvisioning() {
786 return true;
787 }
788 };
789 }
790
791 private Action getVoiceAssistAction() {
792 return new SinglePressAction(R.drawable.ic_voice_search,
793 R.string.global_action_voice_assist) {
794 @Override
795 public void onPress() {
796 Intent intent = new Intent(Intent.ACTION_VOICE_ASSIST);
797 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
798 mContext.startActivity(intent);
799 }
800
801 @Override
802 public boolean showDuringKeyguard() {
803 return true;
804 }
805
806 @Override
807 public boolean showBeforeProvisioning() {
808 return true;
809 }
810 };
811 }
812
813 private Action getLockdownAction() {
Alison Cichowlas21125432018-05-16 15:40:45 -0400814 return new SinglePressAction(R.drawable.ic_lock_lockdown,
Jason Monk361915c2017-03-21 20:33:59 -0400815 R.string.global_action_lockdown) {
816
817 @Override
818 public void onPress() {
Chad Brubaker4f28f0d2017-09-07 14:28:13 -0700819 new LockPatternUtils(mContext)
820 .requireStrongAuth(STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN,
821 UserHandle.USER_ALL);
Jason Monk361915c2017-03-21 20:33:59 -0400822 try {
823 WindowManagerGlobal.getWindowManagerService().lockNow(null);
Pavel Grafov059021b2018-05-02 13:44:46 +0100824 // Lock profiles (if any) on the background thread.
825 final Handler bgHandler = new Handler(Dependency.get(Dependency.BG_LOOPER));
826 bgHandler.post(() -> lockProfiles());
Jason Monk361915c2017-03-21 20:33:59 -0400827 } catch (RemoteException e) {
828 Log.e(TAG, "Error while trying to lock device.", e);
829 }
830 }
831
832 @Override
833 public boolean showDuringKeyguard() {
834 return true;
835 }
836
837 @Override
838 public boolean showBeforeProvisioning() {
839 return false;
840 }
841 };
842 }
843
Pavel Grafov059021b2018-05-02 13:44:46 +0100844 private void lockProfiles() {
Pavel Grafov059021b2018-05-02 13:44:46 +0100845 final int currentUserId = getCurrentUser().id;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500846 final int[] profileIds = mUserManager.getEnabledProfileIds(currentUserId);
Pavel Grafov059021b2018-05-02 13:44:46 +0100847 for (final int id : profileIds) {
848 if (id != currentUserId) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500849 mTrustManager.setDeviceLockedForUser(id, true);
Pavel Grafov059021b2018-05-02 13:44:46 +0100850 }
851 }
852 }
853
Jason Monk361915c2017-03-21 20:33:59 -0400854 private UserInfo getCurrentUser() {
855 try {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500856 return mIActivityManager.getCurrentUser();
Jason Monk361915c2017-03-21 20:33:59 -0400857 } catch (RemoteException re) {
858 return null;
859 }
860 }
861
862 private boolean isCurrentUserOwner() {
863 UserInfo currentUser = getCurrentUser();
864 return currentUser == null || currentUser.isPrimary();
865 }
866
867 private void addUsersToMenu(ArrayList<Action> items) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500868 if (mUserManager.isUserSwitcherEnabled()) {
869 List<UserInfo> users = mUserManager.getUsers();
Jason Monk361915c2017-03-21 20:33:59 -0400870 UserInfo currentUser = getCurrentUser();
871 for (final UserInfo user : users) {
872 if (user.supportsSwitchToByUser()) {
873 boolean isCurrentUser = currentUser == null
874 ? user.id == 0 : (currentUser.id == user.id);
875 Drawable icon = user.iconPath != null ? Drawable.createFromPath(user.iconPath)
876 : null;
877 SinglePressAction switchToUser = new SinglePressAction(
878 R.drawable.ic_menu_cc, icon,
879 (user.name != null ? user.name : "Primary")
Jason Monk16fbd9d2017-04-27 14:28:49 -0400880 + (isCurrentUser ? " \u2714" : "")) {
Jason Monk361915c2017-03-21 20:33:59 -0400881 public void onPress() {
882 try {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500883 mIActivityManager.switchUser(user.id);
Jason Monk361915c2017-03-21 20:33:59 -0400884 } catch (RemoteException re) {
885 Log.e(TAG, "Couldn't switch user " + re);
886 }
887 }
888
889 public boolean showDuringKeyguard() {
890 return true;
891 }
892
893 public boolean showBeforeProvisioning() {
894 return false;
895 }
896 };
897 items.add(switchToUser);
898 }
899 }
900 }
901 }
902
903 private void prepareDialog() {
904 refreshSilentMode();
905 mAirplaneModeOn.updateState(mAirplaneState);
906 mAdapter.notifyDataSetChanged();
Jason Monk361915c2017-03-21 20:33:59 -0400907 if (mShowSilentToggle) {
908 IntentFilter filter = new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION);
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000909 mBroadcastDispatcher.registerReceiver(mRingerModeReceiver, filter);
Jason Monk361915c2017-03-21 20:33:59 -0400910 }
911 }
912
913 private void refreshSilentMode() {
914 if (!mHasVibrator) {
915 final boolean silentModeOn =
916 mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL;
Jason Monk16fbd9d2017-04-27 14:28:49 -0400917 ((ToggleAction) mSilentModeAction).updateState(
Jason Monk361915c2017-03-21 20:33:59 -0400918 silentModeOn ? ToggleAction.State.On : ToggleAction.State.Off);
919 }
920 }
921
922 /** {@inheritDoc} */
923 public void onDismiss(DialogInterface dialog) {
Steve Elliottc3147e22019-11-20 19:34:57 -0500924 if (mDialog == dialog) {
925 mDialog = null;
926 }
Jason Monk361915c2017-03-21 20:33:59 -0400927 mWindowManagerFuncs.onGlobalActionsHidden();
928 if (mShowSilentToggle) {
929 try {
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000930 mBroadcastDispatcher.unregisterReceiver(mRingerModeReceiver);
Jason Monk361915c2017-03-21 20:33:59 -0400931 } catch (IllegalArgumentException ie) {
932 // ignore this
933 Log.w(TAG, ie);
934 }
935 }
936 }
937
938 /** {@inheritDoc} */
Shaotang Li786da902018-08-02 11:18:00 +0800939 public void onShow(DialogInterface dialog) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500940 mMetricsLogger.visible(MetricsEvent.POWER_MENU);
Shaotang Li786da902018-08-02 11:18:00 +0800941 }
942
Jason Monk361915c2017-03-21 20:33:59 -0400943 /**
944 * The adapter used for the list within the global actions dialog, taking
945 * into account whether the keyguard is showing via
Jason Monk16fbd9d2017-04-27 14:28:49 -0400946 * {@link com.android.systemui.globalactions.GlobalActionsDialog#mKeyguardShowing} and whether
947 * the device is provisioned
Jason Monk361915c2017-03-21 20:33:59 -0400948 * via {@link com.android.systemui.globalactions.GlobalActionsDialog#mDeviceProvisioned}.
949 */
Aaron Heuckroth57d60d22019-03-05 14:00:12 -0500950 public class MyAdapter extends MultiListAdapter {
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -0400951 private int countItems(boolean separated) {
Jason Monk361915c2017-03-21 20:33:59 -0400952 int count = 0;
Jason Monk361915c2017-03-21 20:33:59 -0400953 for (int i = 0; i < mItems.size(); i++) {
954 final Action action = mItems.get(i);
955
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -0400956 if (shouldBeShown(action) && action.shouldBeSeparated() == separated) {
957 count++;
Jason Monk361915c2017-03-21 20:33:59 -0400958 }
Jason Monk361915c2017-03-21 20:33:59 -0400959 }
960 return count;
961 }
962
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -0400963 private boolean shouldBeShown(Action action) {
964 if (mKeyguardShowing && !action.showDuringKeyguard()) {
965 return false;
966 }
967 if (!mDeviceProvisioned && !action.showBeforeProvisioning()) {
968 return false;
969 }
970 return true;
971 }
972
973 @Override
974 public int countSeparatedItems() {
975 return countItems(true);
976 }
977
978 @Override
979 public int countListItems() {
980 return countItems(false);
981 }
982
983 @Override
984 public int getCount() {
985 return countSeparatedItems() + countListItems();
986 }
987
Jason Monk361915c2017-03-21 20:33:59 -0400988 @Override
989 public boolean isEnabled(int position) {
990 return getItem(position).isEnabled();
991 }
992
Aaron Heuckroth57d60d22019-03-05 14:00:12 -0500993 @Override
Jason Monk361915c2017-03-21 20:33:59 -0400994 public boolean areAllItemsEnabled() {
995 return false;
996 }
997
Aaron Heuckroth57d60d22019-03-05 14:00:12 -0500998 @Override
Jason Monk361915c2017-03-21 20:33:59 -0400999 public Action getItem(int position) {
Jason Monk361915c2017-03-21 20:33:59 -04001000 int filteredPos = 0;
1001 for (int i = 0; i < mItems.size(); i++) {
1002 final Action action = mItems.get(i);
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -04001003 if (!shouldBeShown(action)) {
Jason Monk361915c2017-03-21 20:33:59 -04001004 continue;
1005 }
1006 if (filteredPos == position) {
1007 return action;
1008 }
1009 filteredPos++;
1010 }
1011
1012 throw new IllegalArgumentException("position " + position
1013 + " out of range of showable actions"
1014 + ", filtered count=" + getCount()
1015 + ", keyguardshowing=" + mKeyguardShowing
1016 + ", provisioned=" + mDeviceProvisioned);
1017 }
1018
1019
1020 public long getItemId(int position) {
1021 return position;
1022 }
1023
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001024 @Override
Jason Monk361915c2017-03-21 20:33:59 -04001025 public View getView(int position, View convertView, ViewGroup parent) {
1026 Action action = getItem(position);
Jason Monk16fbd9d2017-04-27 14:28:49 -04001027 View view = action.create(mContext, convertView, parent, LayoutInflater.from(mContext));
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -04001028 view.setOnClickListener(v -> onClickItem(position));
1029 view.setOnLongClickListener(v -> onLongClickItem(position));
Jason Monk16fbd9d2017-04-27 14:28:49 -04001030 return view;
Jason Monk361915c2017-03-21 20:33:59 -04001031 }
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001032
1033 @Override
1034 public boolean onLongClickItem(int position) {
1035 final Action action = mAdapter.getItem(position);
1036 if (action instanceof LongPressAction) {
Aran Inkbaa25862019-06-11 15:48:55 -04001037 if (mDialog != null) {
1038 mDialog.dismiss();
1039 } else {
1040 Log.w(TAG, "Action long-clicked while mDialog is null.");
1041 }
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001042 return ((LongPressAction) action).onLongPress();
1043 }
1044 return false;
1045 }
1046
1047 @Override
1048 public void onClickItem(int position) {
1049 Action item = mAdapter.getItem(position);
1050 if (!(item instanceof SilentModeTriStateAction)) {
Aran Inkbaa25862019-06-11 15:48:55 -04001051 if (mDialog != null) {
1052 mDialog.dismiss();
1053 } else {
1054 Log.w(TAG, "Action clicked while mDialog is null.");
1055 }
1056 item.onPress();
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001057 }
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001058 }
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -04001059
1060 @Override
1061 public boolean shouldBeSeparated(int position) {
1062 return getItem(position).shouldBeSeparated();
1063 }
Jason Monk361915c2017-03-21 20:33:59 -04001064 }
1065
1066 // note: the scheme below made more sense when we were planning on having
1067 // 8 different things in the global actions dialog. seems overkill with
1068 // only 3 items now, but may as well keep this flexible approach so it will
1069 // be easy should someone decide at the last minute to include something
1070 // else, such as 'enable wifi', or 'enable bluetooth'
1071
1072 /**
1073 * What each item in the global actions dialog must be able to support.
1074 */
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001075 public interface Action {
Jason Monk361915c2017-03-21 20:33:59 -04001076 /**
1077 * @return Text that will be announced when dialog is created. null
Jason Monk16fbd9d2017-04-27 14:28:49 -04001078 * for none.
Jason Monk361915c2017-03-21 20:33:59 -04001079 */
1080 CharSequence getLabelForAccessibility(Context context);
1081
1082 View create(Context context, View convertView, ViewGroup parent, LayoutInflater inflater);
1083
1084 void onPress();
1085
1086 /**
1087 * @return whether this action should appear in the dialog when the keygaurd
Jason Monk16fbd9d2017-04-27 14:28:49 -04001088 * is showing.
Jason Monk361915c2017-03-21 20:33:59 -04001089 */
1090 boolean showDuringKeyguard();
1091
1092 /**
1093 * @return whether this action should appear in the dialog before the
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001094 * device is provisioned.onlongpress
1095 *
Jason Monk361915c2017-03-21 20:33:59 -04001096 */
1097 boolean showBeforeProvisioning();
1098
1099 boolean isEnabled();
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001100
1101 default boolean shouldBeSeparated() {
1102 return false;
1103 }
Jason Monk361915c2017-03-21 20:33:59 -04001104 }
1105
1106 /**
1107 * An action that also supports long press.
1108 */
1109 private interface LongPressAction extends Action {
1110 boolean onLongPress();
1111 }
1112
1113 /**
1114 * A single press action maintains no state, just responds to a press
1115 * and takes an action.
1116 */
1117 private static abstract class SinglePressAction implements Action {
1118 private final int mIconResId;
1119 private final Drawable mIcon;
1120 private final int mMessageResId;
1121 private final CharSequence mMessage;
1122
1123 protected SinglePressAction(int iconResId, int messageResId) {
1124 mIconResId = iconResId;
1125 mMessageResId = messageResId;
1126 mMessage = null;
1127 mIcon = null;
1128 }
1129
1130 protected SinglePressAction(int iconResId, Drawable icon, CharSequence message) {
1131 mIconResId = iconResId;
1132 mMessageResId = 0;
1133 mMessage = message;
1134 mIcon = icon;
1135 }
1136
1137 public boolean isEnabled() {
1138 return true;
1139 }
1140
1141 public String getStatus() {
1142 return null;
1143 }
1144
1145 abstract public void onPress();
1146
1147 public CharSequence getLabelForAccessibility(Context context) {
1148 if (mMessage != null) {
1149 return mMessage;
1150 } else {
1151 return context.getString(mMessageResId);
1152 }
1153 }
1154
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001155 protected int getActionLayoutId(Context context) {
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001156 return com.android.systemui.R.layout.global_actions_grid_item;
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001157 }
1158
Jason Monk361915c2017-03-21 20:33:59 -04001159 public View create(
1160 Context context, View convertView, ViewGroup parent, LayoutInflater inflater) {
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001161 View v = inflater.inflate(getActionLayoutId(context), parent,
Jason Monk16fbd9d2017-04-27 14:28:49 -04001162 false);
Jason Monk361915c2017-03-21 20:33:59 -04001163
1164 ImageView icon = (ImageView) v.findViewById(R.id.icon);
1165 TextView messageView = (TextView) v.findViewById(R.id.message);
Aaron Heuckroth3f2d8b52019-04-05 13:27:51 -04001166 messageView.setSelected(true); // necessary for marquee to work
Jason Monk361915c2017-03-21 20:33:59 -04001167
Jason Monk361915c2017-03-21 20:33:59 -04001168 if (mIcon != null) {
1169 icon.setImageDrawable(mIcon);
1170 icon.setScaleType(ScaleType.CENTER_CROP);
1171 } else if (mIconResId != 0) {
1172 icon.setImageDrawable(context.getDrawable(mIconResId));
1173 }
1174 if (mMessage != null) {
1175 messageView.setText(mMessage);
1176 } else {
1177 messageView.setText(mMessageResId);
1178 }
1179
1180 return v;
1181 }
1182 }
1183
1184 /**
1185 * A toggle action knows whether it is on or off, and displays an icon
1186 * and status message accordingly.
1187 */
1188 private static abstract class ToggleAction implements Action {
1189
1190 enum State {
1191 Off(false),
1192 TurningOn(true),
1193 TurningOff(true),
1194 On(false);
1195
1196 private final boolean inTransition;
1197
1198 State(boolean intermediate) {
1199 inTransition = intermediate;
1200 }
1201
1202 public boolean inTransition() {
1203 return inTransition;
1204 }
1205 }
1206
1207 protected State mState = State.Off;
1208
1209 // prefs
1210 protected int mEnabledIconResId;
1211 protected int mDisabledIconResid;
1212 protected int mMessageResId;
1213 protected int mEnabledStatusMessageResId;
1214 protected int mDisabledStatusMessageResId;
1215
1216 /**
Jason Monk16fbd9d2017-04-27 14:28:49 -04001217 * @param enabledIconResId The icon for when this action is on.
1218 * @param disabledIconResid The icon for when this action is off.
1219 * @param message The general information message, e.g 'Silent Mode'
1220 * @param enabledStatusMessageResId The on status message, e.g 'sound disabled'
Jason Monk361915c2017-03-21 20:33:59 -04001221 * @param disabledStatusMessageResId The off status message, e.g. 'sound enabled'
1222 */
1223 public ToggleAction(int enabledIconResId,
1224 int disabledIconResid,
1225 int message,
1226 int enabledStatusMessageResId,
1227 int disabledStatusMessageResId) {
1228 mEnabledIconResId = enabledIconResId;
1229 mDisabledIconResid = disabledIconResid;
1230 mMessageResId = message;
1231 mEnabledStatusMessageResId = enabledStatusMessageResId;
1232 mDisabledStatusMessageResId = disabledStatusMessageResId;
1233 }
1234
1235 /**
1236 * Override to make changes to resource IDs just before creating the
1237 * View.
1238 */
1239 void willCreate() {
1240
1241 }
1242
1243 @Override
1244 public CharSequence getLabelForAccessibility(Context context) {
1245 return context.getString(mMessageResId);
1246 }
1247
1248 public View create(Context context, View convertView, ViewGroup parent,
1249 LayoutInflater inflater) {
1250 willCreate();
1251
Koji Fukui5c010ee2019-12-24 16:12:07 +09001252 View v = inflater.inflate(com.android.systemui.R
1253 .layout.global_actions_grid_item, parent, false);
Jason Monk361915c2017-03-21 20:33:59 -04001254
1255 ImageView icon = (ImageView) v.findViewById(R.id.icon);
1256 TextView messageView = (TextView) v.findViewById(R.id.message);
Jason Monk361915c2017-03-21 20:33:59 -04001257 final boolean enabled = isEnabled();
Koji Fukui5c010ee2019-12-24 16:12:07 +09001258 boolean on = ((mState == State.On) || (mState == State.TurningOn));
Jason Monk361915c2017-03-21 20:33:59 -04001259
1260 if (messageView != null) {
Koji Fukui5c010ee2019-12-24 16:12:07 +09001261 messageView.setText(on ? mEnabledStatusMessageResId : mDisabledStatusMessageResId);
Jason Monk361915c2017-03-21 20:33:59 -04001262 messageView.setEnabled(enabled);
Aaron Heuckroth3f2d8b52019-04-05 13:27:51 -04001263 messageView.setSelected(true); // necessary for marquee to work
Jason Monk361915c2017-03-21 20:33:59 -04001264 }
1265
Jason Monk361915c2017-03-21 20:33:59 -04001266 if (icon != null) {
1267 icon.setImageDrawable(context.getDrawable(
1268 (on ? mEnabledIconResId : mDisabledIconResid)));
1269 icon.setEnabled(enabled);
1270 }
1271
Jason Monk361915c2017-03-21 20:33:59 -04001272 v.setEnabled(enabled);
1273
1274 return v;
1275 }
1276
1277 public final void onPress() {
1278 if (mState.inTransition()) {
1279 Log.w(TAG, "shouldn't be able to toggle when in transition");
1280 return;
1281 }
1282
1283 final boolean nowOn = !(mState == State.On);
1284 onToggle(nowOn);
1285 changeStateFromPress(nowOn);
1286 }
1287
1288 public boolean isEnabled() {
1289 return !mState.inTransition();
1290 }
1291
1292 /**
1293 * Implementations may override this if their state can be in on of the intermediate
1294 * states until some notification is received (e.g airplane mode is 'turning off' until
1295 * we know the wireless connections are back online
Jason Monk16fbd9d2017-04-27 14:28:49 -04001296 *
Jason Monk361915c2017-03-21 20:33:59 -04001297 * @param buttonOn Whether the button was turned on or off
1298 */
1299 protected void changeStateFromPress(boolean buttonOn) {
1300 mState = buttonOn ? State.On : State.Off;
1301 }
1302
1303 abstract void onToggle(boolean on);
1304
1305 public void updateState(State state) {
1306 mState = state;
1307 }
1308 }
1309
1310 private class SilentModeToggleAction extends ToggleAction {
1311 public SilentModeToggleAction() {
1312 super(R.drawable.ic_audio_vol_mute,
1313 R.drawable.ic_audio_vol,
1314 R.string.global_action_toggle_silent_mode,
1315 R.string.global_action_silent_mode_on_status,
1316 R.string.global_action_silent_mode_off_status);
1317 }
1318
1319 void onToggle(boolean on) {
1320 if (on) {
1321 mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
1322 } else {
1323 mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
1324 }
1325 }
1326
1327 public boolean showDuringKeyguard() {
1328 return true;
1329 }
1330
1331 public boolean showBeforeProvisioning() {
1332 return false;
1333 }
1334 }
1335
1336 private static class SilentModeTriStateAction implements Action, View.OnClickListener {
1337
Jason Monk16fbd9d2017-04-27 14:28:49 -04001338 private final int[] ITEM_IDS = {R.id.option1, R.id.option2, R.id.option3};
Jason Monk361915c2017-03-21 20:33:59 -04001339
1340 private final AudioManager mAudioManager;
1341 private final Handler mHandler;
Jason Monk361915c2017-03-21 20:33:59 -04001342
Lucas Dupin40ec6b782018-06-05 19:07:16 -07001343 SilentModeTriStateAction(AudioManager audioManager, Handler handler) {
Jason Monk361915c2017-03-21 20:33:59 -04001344 mAudioManager = audioManager;
1345 mHandler = handler;
Jason Monk361915c2017-03-21 20:33:59 -04001346 }
1347
1348 private int ringerModeToIndex(int ringerMode) {
1349 // They just happen to coincide
1350 return ringerMode;
1351 }
1352
1353 private int indexToRingerMode(int index) {
1354 // They just happen to coincide
1355 return index;
1356 }
1357
1358 @Override
1359 public CharSequence getLabelForAccessibility(Context context) {
1360 return null;
1361 }
1362
1363 public View create(Context context, View convertView, ViewGroup parent,
1364 LayoutInflater inflater) {
1365 View v = inflater.inflate(R.layout.global_actions_silent_mode, parent, false);
1366
1367 int selectedIndex = ringerModeToIndex(mAudioManager.getRingerMode());
1368 for (int i = 0; i < 3; i++) {
1369 View itemView = v.findViewById(ITEM_IDS[i]);
1370 itemView.setSelected(selectedIndex == i);
1371 // Set up click handler
1372 itemView.setTag(i);
1373 itemView.setOnClickListener(this);
1374 }
1375 return v;
1376 }
1377
1378 public void onPress() {
1379 }
1380
1381 public boolean showDuringKeyguard() {
1382 return true;
1383 }
1384
1385 public boolean showBeforeProvisioning() {
1386 return false;
1387 }
1388
1389 public boolean isEnabled() {
1390 return true;
1391 }
1392
1393 void willCreate() {
1394 }
1395
1396 public void onClick(View v) {
1397 if (!(v.getTag() instanceof Integer)) return;
1398
1399 int index = (Integer) v.getTag();
1400 mAudioManager.setRingerMode(indexToRingerMode(index));
1401 mHandler.sendEmptyMessageDelayed(MESSAGE_DISMISS, DIALOG_DISMISS_DELAY);
1402 }
1403 }
1404
1405 private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
1406 public void onReceive(Context context, Intent intent) {
1407 String action = intent.getAction();
1408 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)
1409 || Intent.ACTION_SCREEN_OFF.equals(action)) {
1410 String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY);
1411 if (!SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS.equals(reason)) {
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001412 mHandler.sendMessage(mHandler.obtainMessage(MESSAGE_DISMISS, reason));
Jason Monk361915c2017-03-21 20:33:59 -04001413 }
Jayachandran C142eae02019-12-13 19:29:20 -08001414 } else if (TelephonyManager.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED.equals(action)) {
Jason Monk361915c2017-03-21 20:33:59 -04001415 // Airplane mode can be changed after ECM exits if airplane toggle button
1416 // is pressed during ECM mode
Daniel Bright4bcbfce2020-01-09 21:58:16 -08001417 if (!(intent.getBooleanExtra(TelephonyManager.EXTRA_PHONE_IN_ECM_STATE, false))
1418 && mIsWaitingForEcmExit) {
Jason Monk361915c2017-03-21 20:33:59 -04001419 mIsWaitingForEcmExit = false;
1420 changeAirplaneModeSystemSetting(true);
1421 }
1422 }
1423 }
1424 };
1425
1426 PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
1427 @Override
1428 public void onServiceStateChanged(ServiceState serviceState) {
1429 if (!mHasTelephony) return;
1430 final boolean inAirplaneMode = serviceState.getState() == ServiceState.STATE_POWER_OFF;
1431 mAirplaneState = inAirplaneMode ? ToggleAction.State.On : ToggleAction.State.Off;
1432 mAirplaneModeOn.updateState(mAirplaneState);
1433 mAdapter.notifyDataSetChanged();
1434 }
1435 };
1436
1437 private BroadcastReceiver mRingerModeReceiver = new BroadcastReceiver() {
1438 @Override
1439 public void onReceive(Context context, Intent intent) {
1440 if (intent.getAction().equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
1441 mHandler.sendEmptyMessage(MESSAGE_REFRESH);
1442 }
1443 }
1444 };
1445
1446 private ContentObserver mAirplaneModeObserver = new ContentObserver(new Handler()) {
1447 @Override
1448 public void onChange(boolean selfChange) {
1449 onAirplaneModeChanged();
1450 }
1451 };
1452
1453 private static final int MESSAGE_DISMISS = 0;
1454 private static final int MESSAGE_REFRESH = 1;
1455 private static final int MESSAGE_SHOW = 2;
1456 private static final int DIALOG_DISMISS_DELAY = 300; // ms
1457
1458 private Handler mHandler = new Handler() {
1459 public void handleMessage(Message msg) {
1460 switch (msg.what) {
Jason Monk16fbd9d2017-04-27 14:28:49 -04001461 case MESSAGE_DISMISS:
1462 if (mDialog != null) {
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001463 if (SYSTEM_DIALOG_REASON_DREAM.equals(msg.obj)) {
1464 mDialog.dismissImmediately();
1465 } else {
1466 mDialog.dismiss();
1467 }
Jason Monk16fbd9d2017-04-27 14:28:49 -04001468 mDialog = null;
1469 }
1470 break;
1471 case MESSAGE_REFRESH:
1472 refreshSilentMode();
1473 mAdapter.notifyDataSetChanged();
1474 break;
1475 case MESSAGE_SHOW:
1476 handleShow();
1477 break;
Jason Monk361915c2017-03-21 20:33:59 -04001478 }
1479 }
1480 };
1481
1482 private void onAirplaneModeChanged() {
1483 // Let the service state callbacks handle the state.
1484 if (mHasTelephony) return;
1485
1486 boolean airplaneModeOn = Settings.Global.getInt(
Dave Mankoffc88a2d72020-01-10 15:59:31 -05001487 mContentResolver,
Jason Monk361915c2017-03-21 20:33:59 -04001488 Settings.Global.AIRPLANE_MODE_ON,
1489 0) == 1;
1490 mAirplaneState = airplaneModeOn ? ToggleAction.State.On : ToggleAction.State.Off;
1491 mAirplaneModeOn.updateState(mAirplaneState);
1492 }
1493
1494 /**
1495 * Change the airplane mode system setting
1496 */
1497 private void changeAirplaneModeSystemSetting(boolean on) {
1498 Settings.Global.putInt(
Dave Mankoffc88a2d72020-01-10 15:59:31 -05001499 mContentResolver,
Jason Monk361915c2017-03-21 20:33:59 -04001500 Settings.Global.AIRPLANE_MODE_ON,
1501 on ? 1 : 0);
1502 Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
1503 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
1504 intent.putExtra("state", on);
1505 mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
1506 if (!mHasTelephony) {
1507 mAirplaneState = on ? ToggleAction.State.On : ToggleAction.State.Off;
1508 }
1509 }
1510
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001511 private static final class ActionsDialog extends Dialog implements DialogInterface,
1512 ColorExtractor.OnColorsChangedListener {
Jason Monk361915c2017-03-21 20:33:59 -04001513
Jason Monk16fbd9d2017-04-27 14:28:49 -04001514 private final Context mContext;
1515 private final MyAdapter mAdapter;
Steve Elliott53f12ae2019-05-13 17:14:15 -04001516 private final IStatusBarService mStatusBarService;
1517 private final IBinder mToken = new Binder();
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001518 private MultiListLayout mGlobalActionsLayout;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001519 private Drawable mBackgroundDrawable;
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001520 private final SysuiColorExtractor mColorExtractor;
Steve Elliott9b87a442019-03-05 10:24:16 -05001521 private final GlobalActionsPanelPlugin.PanelViewController mPanelController;
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001522 private boolean mKeyguardShowing;
Beverly526d2d62018-08-15 12:55:33 -04001523 private boolean mShowing;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001524 private float mScrimAlpha;
Steve Elliott48f75db2019-05-03 15:03:38 -04001525 private ResetOrientationData mResetOrientationData;
Steve Elliottff2c0d92019-07-30 15:09:54 -04001526 private boolean mHadTopUi;
1527 private final StatusBarWindowController mStatusBarWindowController;
Jason Monk16fbd9d2017-04-27 14:28:49 -04001528
Aaron Heuckrothf19d2722019-03-11 17:06:02 -04001529 ActionsDialog(Context context, MyAdapter adapter,
Steve Elliott9b87a442019-03-05 10:24:16 -05001530 GlobalActionsPanelPlugin.PanelViewController plugin) {
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001531 super(context, com.android.systemui.R.style.Theme_SystemUI_Dialog_GlobalActions);
Lucas Dupin448786c2017-07-24 17:44:25 -07001532 mContext = context;
Jason Monk16fbd9d2017-04-27 14:28:49 -04001533 mAdapter = adapter;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -07001534 mColorExtractor = Dependency.get(SysuiColorExtractor.class);
Steve Elliott53f12ae2019-05-13 17:14:15 -04001535 mStatusBarService = Dependency.get(IStatusBarService.class);
Steve Elliottff2c0d92019-07-30 15:09:54 -04001536 mStatusBarWindowController = Dependency.get(StatusBarWindowController.class);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001537
1538 // Window initialization
1539 Window window = getWindow();
1540 window.requestFeature(Window.FEATURE_NO_TITLE);
Adrian Roosedfab3b2018-03-08 18:39:20 +01001541 // Inflate the decor view, so the attributes below are not overwritten by the theme.
1542 window.getDecorView();
1543 window.getAttributes().systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1544 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1545 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1546 window.setLayout(MATCH_PARENT, MATCH_PARENT);
1547 window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
Alison Cichowlas4f19f4a2017-07-25 10:56:16 -04001548 window.addFlags(
1549 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001550 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
Adrian Roosedfab3b2018-03-08 18:39:20 +01001551 | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001552 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
1553 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
1554 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001555 window.setType(WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY);
Tiger Huang4a7835f2019-11-06 00:07:56 +08001556 window.setFitWindowInsetsTypes(0 /* types */);
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001557 setTitle(R.string.global_actions);
Steve Elliott9b87a442019-03-05 10:24:16 -05001558
1559 mPanelController = plugin;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001560 initializeLayout();
Steve Elliott9b87a442019-03-05 10:24:16 -05001561 }
1562
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001563 private boolean shouldUsePanel() {
Aran Ink3f594552019-05-13 14:29:35 -04001564 return mPanelController != null && mPanelController.getPanelContent() != null;
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001565 }
1566
1567 private void initializePanel() {
Steve Elliott48f75db2019-05-03 15:03:38 -04001568 int rotation = RotationUtils.getRotation(mContext);
1569 boolean rotationLocked = RotationPolicy.isRotationLocked(mContext);
1570 if (rotation != RotationUtils.ROTATION_NONE) {
1571 if (rotationLocked) {
1572 if (mResetOrientationData == null) {
1573 mResetOrientationData = new ResetOrientationData();
1574 mResetOrientationData.locked = true;
1575 mResetOrientationData.rotation = rotation;
1576 }
1577
1578 // Unlock rotation, so user can choose to rotate to portrait to see the panel.
Steve Elliotte05817f2019-05-17 14:39:53 -04001579 // This call is posted so that the rotation does not change until post-layout,
1580 // otherwise onConfigurationChanged() may not get invoked.
1581 mGlobalActionsLayout.post(() ->
1582 RotationPolicy.setRotationLockAtAngle(
1583 mContext, false, RotationUtils.ROTATION_NONE));
Steve Elliott48f75db2019-05-03 15:03:38 -04001584 }
1585 } else {
1586 if (!rotationLocked) {
1587 if (mResetOrientationData == null) {
1588 mResetOrientationData = new ResetOrientationData();
1589 mResetOrientationData.locked = false;
1590 }
1591
1592 // Lock to portrait, so the user doesn't accidentally hide 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, true, RotationUtils.ROTATION_NONE));
Steve Elliott48f75db2019-05-03 15:03:38 -04001598 }
1599
Steve Elliott53f12ae2019-05-13 17:14:15 -04001600 // Disable rotation suggestions, if enabled
1601 setRotationSuggestionsEnabled(false);
1602
Steve Elliott300b48f2019-05-29 14:13:50 -04001603 FrameLayout panelContainer =
1604 findViewById(com.android.systemui.R.id.global_actions_panel_container);
Steve Elliott48f75db2019-05-03 15:03:38 -04001605 FrameLayout.LayoutParams panelParams =
1606 new FrameLayout.LayoutParams(
1607 FrameLayout.LayoutParams.MATCH_PARENT,
Steve Elliott300b48f2019-05-29 14:13:50 -04001608 FrameLayout.LayoutParams.MATCH_PARENT);
Steve Elliott48f75db2019-05-03 15:03:38 -04001609 panelContainer.addView(mPanelController.getPanelContent(), panelParams);
Steve Elliott86ef6282019-05-08 14:45:04 -04001610 mBackgroundDrawable = mPanelController.getBackgroundDrawable();
1611 mScrimAlpha = 1f;
Steve Elliott48f75db2019-05-03 15:03:38 -04001612 }
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001613 }
1614
1615 private void initializeLayout() {
1616 setContentView(getGlobalActionsLayoutId(mContext));
Steve Elliott300b48f2019-05-29 14:13:50 -04001617 fixNavBarClipping();
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001618 mGlobalActionsLayout = findViewById(com.android.systemui.R.id.global_actions_view);
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001619 mGlobalActionsLayout.setOutsideTouchListener(view -> dismiss());
Steve Elliott300b48f2019-05-29 14:13:50 -04001620 ((View) mGlobalActionsLayout.getParent()).setOnClickListener(view -> dismiss());
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001621 mGlobalActionsLayout.setListViewAccessibilityDelegate(new View.AccessibilityDelegate() {
Phil Weaver9054e092018-04-27 16:28:50 -07001622 @Override
1623 public boolean dispatchPopulateAccessibilityEvent(
1624 View host, AccessibilityEvent event) {
1625 // Populate the title here, just as Activity does
1626 event.getText().add(mContext.getString(R.string.global_actions));
1627 return true;
1628 }
1629 });
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001630 mGlobalActionsLayout.setRotationListener(this::onRotate);
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001631 mGlobalActionsLayout.setAdapter(mAdapter);
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001632
Steve Elliott86ef6282019-05-08 14:45:04 -04001633 if (shouldUsePanel()) {
Steve Elliottc59eb342019-04-23 16:59:06 -04001634 initializePanel();
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001635 }
Steve Elliott86ef6282019-05-08 14:45:04 -04001636 if (mBackgroundDrawable == null) {
1637 mBackgroundDrawable = new ScrimDrawable();
1638 mScrimAlpha = ScrimController.GRADIENT_SCRIM_ALPHA;
1639 }
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001640 getWindow().setBackgroundDrawable(mBackgroundDrawable);
Steve Elliott9b87a442019-03-05 10:24:16 -05001641 }
1642
Steve Elliott300b48f2019-05-29 14:13:50 -04001643 private void fixNavBarClipping() {
1644 ViewGroup content = findViewById(android.R.id.content);
1645 content.setClipChildren(false);
1646 content.setClipToPadding(false);
1647 ViewGroup contentParent = (ViewGroup) content.getParent();
1648 contentParent.setClipChildren(false);
1649 contentParent.setClipToPadding(false);
1650 }
1651
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001652 private int getGlobalActionsLayoutId(Context context) {
Steve Elliottdc165632019-05-23 14:26:31 -04001653 int rotation = RotationUtils.getRotation(context);
1654 boolean useGridLayout = isForceGridEnabled(context)
1655 || (shouldUsePanel() && rotation == RotationUtils.ROTATION_NONE);
1656 if (rotation == RotationUtils.ROTATION_SEASCAPE) {
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001657 if (useGridLayout) {
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001658 return com.android.systemui.R.layout.global_actions_grid_seascape;
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001659 } else {
1660 return com.android.systemui.R.layout.global_actions_column_seascape;
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001661 }
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001662 } else {
1663 if (useGridLayout) {
1664 return com.android.systemui.R.layout.global_actions_grid;
1665 } else {
1666 return com.android.systemui.R.layout.global_actions_column;
1667 }
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001668 }
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001669 }
1670
Jason Monk361915c2017-03-21 20:33:59 -04001671 @Override
1672 protected void onStart() {
1673 super.setCanceledOnTouchOutside(true);
1674 super.onStart();
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001675 mGlobalActionsLayout.updateList();
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001676
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001677 if (mBackgroundDrawable instanceof ScrimDrawable) {
Steve Elliott9b87a442019-03-05 10:24:16 -05001678 mColorExtractor.addOnColorsChangedListener(this);
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001679 GradientColors colors = mColorExtractor.getNeutralColors();
Steve Elliott9b87a442019-03-05 10:24:16 -05001680 updateColors(colors, false /* animate */);
1681 }
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001682 }
1683
1684 /**
1685 * Updates background and system bars according to current GradientColors.
1686 * @param colors Colors and hints to use.
1687 * @param animate Interpolates gradient if true, just sets otherwise.
1688 */
1689 private void updateColors(GradientColors colors, boolean animate) {
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001690 if (!(mBackgroundDrawable instanceof ScrimDrawable)) {
Steve Elliott9b87a442019-03-05 10:24:16 -05001691 return;
1692 }
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001693 ((ScrimDrawable) mBackgroundDrawable).setColor(colors.getMainColor(), animate);
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001694 View decorView = getWindow().getDecorView();
1695 if (colors.supportsDarkText()) {
1696 decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR |
Steve Elliott9b87a442019-03-05 10:24:16 -05001697 View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001698 } else {
1699 decorView.setSystemUiVisibility(0);
1700 }
Jason Monk361915c2017-03-21 20:33:59 -04001701 }
1702
1703 @Override
Jason Monk16fbd9d2017-04-27 14:28:49 -04001704 protected void onStop() {
1705 super.onStop();
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001706 mColorExtractor.removeOnColorsChangedListener(this);
Jason Monk16fbd9d2017-04-27 14:28:49 -04001707 }
1708
1709 @Override
1710 public void show() {
1711 super.show();
Beverly526d2d62018-08-15 12:55:33 -04001712 mShowing = true;
Steve Elliottff2c0d92019-07-30 15:09:54 -04001713 mHadTopUi = mStatusBarWindowController.getForceHasTopUi();
1714 mStatusBarWindowController.setForceHasTopUi(true);
Steve Elliott9b87a442019-03-05 10:24:16 -05001715 mBackgroundDrawable.setAlpha(0);
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001716 mGlobalActionsLayout.setTranslationX(mGlobalActionsLayout.getAnimationOffsetX());
1717 mGlobalActionsLayout.setTranslationY(mGlobalActionsLayout.getAnimationOffsetY());
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001718 mGlobalActionsLayout.setAlpha(0);
1719 mGlobalActionsLayout.animate()
Jason Monk16fbd9d2017-04-27 14:28:49 -04001720 .alpha(1)
1721 .translationX(0)
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001722 .translationY(0)
Jason Monk16fbd9d2017-04-27 14:28:49 -04001723 .setDuration(300)
Lucas Dupinde9db422017-07-19 17:15:41 -07001724 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001725 .setUpdateListener(animation -> {
1726 int alpha = (int) ((Float) animation.getAnimatedValue()
Steve Elliott9b87a442019-03-05 10:24:16 -05001727 * mScrimAlpha * 255);
1728 mBackgroundDrawable.setAlpha(alpha);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001729 })
Jason Monk16fbd9d2017-04-27 14:28:49 -04001730 .start();
1731 }
1732
1733 @Override
1734 public void dismiss() {
Beverly526d2d62018-08-15 12:55:33 -04001735 if (!mShowing) {
1736 return;
1737 }
1738 mShowing = false;
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001739 mGlobalActionsLayout.setTranslationX(0);
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001740 mGlobalActionsLayout.setTranslationY(0);
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001741 mGlobalActionsLayout.setAlpha(1);
1742 mGlobalActionsLayout.animate()
Jason Monk16fbd9d2017-04-27 14:28:49 -04001743 .alpha(0)
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001744 .translationX(mGlobalActionsLayout.getAnimationOffsetX())
1745 .translationY(mGlobalActionsLayout.getAnimationOffsetY())
Jason Monk16fbd9d2017-04-27 14:28:49 -04001746 .setDuration(300)
Steve Elliottff2c0d92019-07-30 15:09:54 -04001747 .withEndAction(this::completeDismiss)
Jason Monk16fbd9d2017-04-27 14:28:49 -04001748 .setInterpolator(new LogAccelerateInterpolator())
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001749 .setUpdateListener(animation -> {
1750 int alpha = (int) ((1f - (Float) animation.getAnimatedValue())
Steve Elliott9b87a442019-03-05 10:24:16 -05001751 * mScrimAlpha * 255);
1752 mBackgroundDrawable.setAlpha(alpha);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001753 })
Jason Monk16fbd9d2017-04-27 14:28:49 -04001754 .start();
Steve Elliott48f75db2019-05-03 15:03:38 -04001755 dismissPanel();
1756 resetOrientation();
Jason Monk16fbd9d2017-04-27 14:28:49 -04001757 }
1758
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001759 void dismissImmediately() {
Beverly526d2d62018-08-15 12:55:33 -04001760 mShowing = false;
Steve Elliott48f75db2019-05-03 15:03:38 -04001761 dismissPanel();
1762 resetOrientation();
Steve Elliottff2c0d92019-07-30 15:09:54 -04001763 completeDismiss();
1764 }
1765
1766 private void completeDismiss() {
1767 mStatusBarWindowController.setForceHasTopUi(mHadTopUi);
1768 super.dismiss();
Steve Elliott48f75db2019-05-03 15:03:38 -04001769 }
1770
1771 private void dismissPanel() {
Steve Elliott2d206d32019-03-14 16:30:33 -04001772 if (mPanelController != null) {
1773 mPanelController.onDismissed();
1774 }
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001775 }
1776
Steve Elliott53f12ae2019-05-13 17:14:15 -04001777 private void setRotationSuggestionsEnabled(boolean enabled) {
1778 try {
1779 final int userId = Binder.getCallingUserHandle().getIdentifier();
1780 final int what = enabled
1781 ? StatusBarManager.DISABLE2_NONE
1782 : StatusBarManager.DISABLE2_ROTATE_SUGGESTIONS;
1783 mStatusBarService.disable2ForUser(what, mToken, mContext.getPackageName(), userId);
1784 } catch (RemoteException ex) {
1785 throw ex.rethrowFromSystemServer();
1786 }
1787 }
1788
Steve Elliott48f75db2019-05-03 15:03:38 -04001789 private void resetOrientation() {
1790 if (mResetOrientationData != null) {
1791 RotationPolicy.setRotationLockAtAngle(mContext, mResetOrientationData.locked,
1792 mResetOrientationData.rotation);
1793 }
Steve Elliott53f12ae2019-05-13 17:14:15 -04001794 setRotationSuggestionsEnabled(true);
Steve Elliott48f75db2019-05-03 15:03:38 -04001795 }
1796
Jason Monk361915c2017-03-21 20:33:59 -04001797 @Override
Lucas Dupin7aaa3532017-05-28 08:51:07 -07001798 public void onColorsChanged(ColorExtractor extractor, int which) {
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001799 if (mKeyguardShowing) {
1800 if ((WallpaperManager.FLAG_LOCK & which) != 0) {
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001801 updateColors(extractor.getColors(WallpaperManager.FLAG_LOCK),
1802 true /* animate */);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001803 }
1804 } else {
1805 if ((WallpaperManager.FLAG_SYSTEM & which) != 0) {
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001806 updateColors(extractor.getColors(WallpaperManager.FLAG_SYSTEM),
1807 true /* animate */);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001808 }
1809 }
1810 }
1811
1812 public void setKeyguardShowing(boolean keyguardShowing) {
1813 mKeyguardShowing = keyguardShowing;
1814 }
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001815
Aaron Heuckroth4ef3a542019-04-01 14:17:23 -04001816 public void refreshDialog() {
1817 initializeLayout();
1818 mGlobalActionsLayout.updateList();
1819 }
1820
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001821 public void onRotate(int from, int to) {
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001822 if (mShowing) {
Aaron Heuckroth4ef3a542019-04-01 14:17:23 -04001823 refreshDialog();
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001824 }
1825 }
Steve Elliott48f75db2019-05-03 15:03:38 -04001826
1827 private static class ResetOrientationData {
1828 public boolean locked;
1829 public int rotation;
1830 }
Jason Monk361915c2017-03-21 20:33:59 -04001831 }
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001832
1833 /**
Aran Ink93dd25c2019-05-09 14:42:14 -04001834 * Determines whether or not debug mode has been activated for the Global Actions Panel.
1835 */
1836 private static boolean isPanelDebugModeEnabled(Context context) {
1837 return Settings.Secure.getInt(context.getContentResolver(),
1838 Settings.Secure.GLOBAL_ACTIONS_PANEL_DEBUG_ENABLED, 0) == 1;
1839 }
1840
1841 /**
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001842 * Determines whether or not the Global Actions menu should be forced to
1843 * use the newer grid-style layout.
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001844 */
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001845 private static boolean isForceGridEnabled(Context context) {
Aran Ink93dd25c2019-05-09 14:42:14 -04001846 return isPanelDebugModeEnabled(context);
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001847 }
Aaron Heuckrothf19d2722019-03-11 17:06:02 -04001848
Aaron Heuckrothf19d2722019-03-11 17:06:02 -04001849
1850 /**
1851 * Determines whether the Global Actions menu should use a separated view for emergency actions.
1852 */
1853 private static boolean shouldUseSeparatedView() {
1854 return true;
1855 }
Jason Monk361915c2017-03-21 20:33:59 -04001856}