blob: 36a4a10b8a3f8bc50badd4d7b9f21a27baddee95 [file] [log] [blame]
Jason Monk361915c2017-03-21 20:33:59 -04001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 * except in compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the
10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11 * KIND, either express or implied. See the License for the specific language governing
12 * permissions and limitations under the License.
13 */
14
15package com.android.systemui.globalactions;
16
Adrian Roosedfab3b2018-03-08 18:39:20 +010017import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
Adrian Roos2f05bb32018-02-19 16:42:27 +010018import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
19
Chad Brubakerf4075fe2018-01-03 13:23:22 -080020import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_USER_REQUEST;
21import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_NOT_REQUIRED;
Chad Brubaker4f28f0d2017-09-07 14:28:13 -070022import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN;
23
Dave Mankoffc88a2d72020-01-10 15:59:31 -050024import android.annotation.Nullable;
Jason Monk361915c2017-03-21 20:33:59 -040025import android.app.ActivityManager;
26import android.app.Dialog;
Dave Mankoffc88a2d72020-01-10 15:59:31 -050027import android.app.IActivityManager;
Chad Brubakerf4075fe2018-01-03 13:23:22 -080028import android.app.KeyguardManager;
Steve Elliott4c868852019-03-14 16:25:41 -040029import android.app.PendingIntent;
Steve Elliott53f12ae2019-05-13 17:14:15 -040030import android.app.StatusBarManager;
Lucas Dupinc1cc7592017-05-22 15:56:16 -070031import android.app.WallpaperManager;
Alex Chau04458852017-11-27 18:21:23 +000032import android.app.admin.DevicePolicyManager;
Pavel Grafov059021b2018-05-02 13:44:46 +010033import android.app.trust.TrustManager;
Jason Monk361915c2017-03-21 20:33:59 -040034import android.content.BroadcastReceiver;
Dave Mankoffc88a2d72020-01-10 15:59:31 -050035import android.content.ContentResolver;
Jason Monk361915c2017-03-21 20:33:59 -040036import android.content.Context;
37import android.content.DialogInterface;
38import android.content.Intent;
39import android.content.IntentFilter;
40import android.content.pm.UserInfo;
Dave Mankoffc88a2d72020-01-10 15:59:31 -050041import android.content.res.Resources;
Jason Monk361915c2017-03-21 20:33:59 -040042import android.database.ContentObserver;
43import android.graphics.drawable.Drawable;
44import android.media.AudioManager;
45import android.net.ConnectivityManager;
Steve Elliott53f12ae2019-05-13 17:14:15 -040046import android.os.Binder;
Jason Monk361915c2017-03-21 20:33:59 -040047import android.os.Handler;
Steve Elliott53f12ae2019-05-13 17:14:15 -040048import android.os.IBinder;
Jason Monk361915c2017-03-21 20:33:59 -040049import android.os.Message;
50import android.os.RemoteException;
Jason Monk361915c2017-03-21 20:33:59 -040051import android.os.SystemProperties;
52import android.os.UserHandle;
53import android.os.UserManager;
54import android.os.Vibrator;
55import android.provider.Settings;
Jason Monk361915c2017-03-21 20:33:59 -040056import android.service.dreams.IDreamManager;
Inseob Kim5e82f732019-11-08 15:08:38 +090057import android.sysprop.TelephonyProperties;
Fan Zhangf9914762019-11-01 15:58:38 -070058import android.telecom.TelecomManager;
Jason Monk361915c2017-03-21 20:33:59 -040059import android.telephony.PhoneStateListener;
60import android.telephony.ServiceState;
61import android.telephony.TelephonyManager;
Jason Monk361915c2017-03-21 20:33:59 -040062import android.util.ArraySet;
yuanjiahsu88363e92018-09-06 19:23:52 +080063import android.util.FeatureFlagUtils;
Jason Monk361915c2017-03-21 20:33:59 -040064import android.util.Log;
Lucas Dupin448786c2017-07-24 17:44:25 -070065import android.view.ContextThemeWrapper;
Jason Monk361915c2017-03-21 20:33:59 -040066import android.view.LayoutInflater;
67import android.view.View;
68import android.view.ViewGroup;
Lucas Dupinc1cc7592017-05-22 15:56:16 -070069import android.view.Window;
Jason Monk361915c2017-03-21 20:33:59 -040070import android.view.WindowManager;
71import android.view.WindowManagerGlobal;
72import android.view.accessibility.AccessibilityEvent;
Steve Elliott9b87a442019-03-05 10:24:16 -050073import android.widget.FrameLayout;
Jason Monk361915c2017-03-21 20:33:59 -040074import android.widget.ImageView;
75import android.widget.ImageView.ScaleType;
Jason Monk361915c2017-03-21 20:33:59 -040076import android.widget.TextView;
77
Charles He9851a8d2017-10-10 17:31:30 +010078import com.android.internal.R;
79import com.android.internal.colorextraction.ColorExtractor;
80import com.android.internal.colorextraction.ColorExtractor.GradientColors;
Lucas Dupin2bd3af62019-03-25 17:44:28 -070081import com.android.internal.colorextraction.drawable.ScrimDrawable;
Charles He9851a8d2017-10-10 17:31:30 +010082import com.android.internal.logging.MetricsLogger;
83import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Steve Elliott53f12ae2019-05-13 17:14:15 -040084import com.android.internal.statusbar.IStatusBarService;
Charles He9851a8d2017-10-10 17:31:30 +010085import com.android.internal.util.EmergencyAffordanceManager;
Beth Thibodeau5898ac42018-10-26 13:00:09 -040086import com.android.internal.util.ScreenRecordHelper;
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -050087import com.android.internal.util.ScreenshotHelper;
Steve Elliott48f75db2019-05-03 15:03:38 -040088import com.android.internal.view.RotationPolicy;
Charles He9851a8d2017-10-10 17:31:30 +010089import com.android.internal.widget.LockPatternUtils;
90import com.android.systemui.Dependency;
Charles He9851a8d2017-10-10 17:31:30 +010091import com.android.systemui.Interpolators;
Aaron Heuckrothf708d472019-01-10 16:54:51 -050092import com.android.systemui.MultiListLayout;
Aaron Heuckroth57d60d22019-03-05 14:00:12 -050093import com.android.systemui.MultiListLayout.MultiListAdapter;
Fabian Kozynskiff5e91f2019-09-24 15:38:08 -040094import com.android.systemui.broadcast.BroadcastDispatcher;
Charles He9851a8d2017-10-10 17:31:30 +010095import com.android.systemui.colorextraction.SysuiColorExtractor;
Dave Mankoffc88a2d72020-01-10 15:59:31 -050096import com.android.systemui.dagger.qualifiers.Main;
Steve Elliott4c868852019-03-14 16:25:41 -040097import com.android.systemui.plugins.ActivityStarter;
Charles He9851a8d2017-10-10 17:31:30 +010098import com.android.systemui.plugins.GlobalActions.GlobalActionsManager;
Steve Elliott9b87a442019-03-05 10:24:16 -050099import com.android.systemui.plugins.GlobalActionsPanelPlugin;
wilsonshihe8321942019-10-18 18:39:46 +0800100import com.android.systemui.statusbar.phone.NotificationShadeWindowController;
Steve Elliottbfa314a2019-03-06 13:53:19 -0500101import com.android.systemui.statusbar.phone.ScrimController;
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
Matt Pietalfd3b6cb2020-01-08 09:43:54 -0500446 ActionsDialog dialog = new ActionsDialog(
447 mContext, mAdapter, panelViewController, isControlsEnabled(mContext));
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() {
Matt Pietalfd3b6cb2020-01-08 09:43:54 -0500521 return !isControlsEnabled(mContext);
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400522 }
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) {
Matt Pietalfd3b6cb2020-01-08 09:43:54 -05001157 if (isControlsEnabled(context)) {
1158 return com.android.systemui.R.layout.global_actions_grid_item_v2;
1159 }
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001160 return com.android.systemui.R.layout.global_actions_grid_item;
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001161 }
1162
Jason Monk361915c2017-03-21 20:33:59 -04001163 public View create(
1164 Context context, View convertView, ViewGroup parent, LayoutInflater inflater) {
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001165 View v = inflater.inflate(getActionLayoutId(context), parent,
Jason Monk16fbd9d2017-04-27 14:28:49 -04001166 false);
Jason Monk361915c2017-03-21 20:33:59 -04001167
1168 ImageView icon = (ImageView) v.findViewById(R.id.icon);
1169 TextView messageView = (TextView) v.findViewById(R.id.message);
Aaron Heuckroth3f2d8b52019-04-05 13:27:51 -04001170 messageView.setSelected(true); // necessary for marquee to work
Jason Monk361915c2017-03-21 20:33:59 -04001171
Jason Monk361915c2017-03-21 20:33:59 -04001172 if (mIcon != null) {
1173 icon.setImageDrawable(mIcon);
1174 icon.setScaleType(ScaleType.CENTER_CROP);
1175 } else if (mIconResId != 0) {
1176 icon.setImageDrawable(context.getDrawable(mIconResId));
1177 }
1178 if (mMessage != null) {
1179 messageView.setText(mMessage);
1180 } else {
1181 messageView.setText(mMessageResId);
1182 }
1183
1184 return v;
1185 }
1186 }
1187
1188 /**
1189 * A toggle action knows whether it is on or off, and displays an icon
1190 * and status message accordingly.
1191 */
1192 private static abstract class ToggleAction implements Action {
1193
1194 enum State {
1195 Off(false),
1196 TurningOn(true),
1197 TurningOff(true),
1198 On(false);
1199
1200 private final boolean inTransition;
1201
1202 State(boolean intermediate) {
1203 inTransition = intermediate;
1204 }
1205
1206 public boolean inTransition() {
1207 return inTransition;
1208 }
1209 }
1210
1211 protected State mState = State.Off;
1212
1213 // prefs
1214 protected int mEnabledIconResId;
1215 protected int mDisabledIconResid;
1216 protected int mMessageResId;
1217 protected int mEnabledStatusMessageResId;
1218 protected int mDisabledStatusMessageResId;
1219
1220 /**
Jason Monk16fbd9d2017-04-27 14:28:49 -04001221 * @param enabledIconResId The icon for when this action is on.
1222 * @param disabledIconResid The icon for when this action is off.
1223 * @param message The general information message, e.g 'Silent Mode'
1224 * @param enabledStatusMessageResId The on status message, e.g 'sound disabled'
Jason Monk361915c2017-03-21 20:33:59 -04001225 * @param disabledStatusMessageResId The off status message, e.g. 'sound enabled'
1226 */
1227 public ToggleAction(int enabledIconResId,
1228 int disabledIconResid,
1229 int message,
1230 int enabledStatusMessageResId,
1231 int disabledStatusMessageResId) {
1232 mEnabledIconResId = enabledIconResId;
1233 mDisabledIconResid = disabledIconResid;
1234 mMessageResId = message;
1235 mEnabledStatusMessageResId = enabledStatusMessageResId;
1236 mDisabledStatusMessageResId = disabledStatusMessageResId;
1237 }
1238
1239 /**
1240 * Override to make changes to resource IDs just before creating the
1241 * View.
1242 */
1243 void willCreate() {
1244
1245 }
1246
1247 @Override
1248 public CharSequence getLabelForAccessibility(Context context) {
1249 return context.getString(mMessageResId);
1250 }
1251
1252 public View create(Context context, View convertView, ViewGroup parent,
1253 LayoutInflater inflater) {
1254 willCreate();
1255
Koji Fukui5c010ee2019-12-24 16:12:07 +09001256 View v = inflater.inflate(com.android.systemui.R
1257 .layout.global_actions_grid_item, parent, false);
Jason Monk361915c2017-03-21 20:33:59 -04001258
1259 ImageView icon = (ImageView) v.findViewById(R.id.icon);
1260 TextView messageView = (TextView) v.findViewById(R.id.message);
Jason Monk361915c2017-03-21 20:33:59 -04001261 final boolean enabled = isEnabled();
Koji Fukui5c010ee2019-12-24 16:12:07 +09001262 boolean on = ((mState == State.On) || (mState == State.TurningOn));
Jason Monk361915c2017-03-21 20:33:59 -04001263
1264 if (messageView != null) {
Koji Fukui5c010ee2019-12-24 16:12:07 +09001265 messageView.setText(on ? mEnabledStatusMessageResId : mDisabledStatusMessageResId);
Jason Monk361915c2017-03-21 20:33:59 -04001266 messageView.setEnabled(enabled);
Aaron Heuckroth3f2d8b52019-04-05 13:27:51 -04001267 messageView.setSelected(true); // necessary for marquee to work
Jason Monk361915c2017-03-21 20:33:59 -04001268 }
1269
Jason Monk361915c2017-03-21 20:33:59 -04001270 if (icon != null) {
1271 icon.setImageDrawable(context.getDrawable(
1272 (on ? mEnabledIconResId : mDisabledIconResid)));
1273 icon.setEnabled(enabled);
1274 }
1275
Jason Monk361915c2017-03-21 20:33:59 -04001276 v.setEnabled(enabled);
1277
1278 return v;
1279 }
1280
1281 public final void onPress() {
1282 if (mState.inTransition()) {
1283 Log.w(TAG, "shouldn't be able to toggle when in transition");
1284 return;
1285 }
1286
1287 final boolean nowOn = !(mState == State.On);
1288 onToggle(nowOn);
1289 changeStateFromPress(nowOn);
1290 }
1291
1292 public boolean isEnabled() {
1293 return !mState.inTransition();
1294 }
1295
1296 /**
1297 * Implementations may override this if their state can be in on of the intermediate
1298 * states until some notification is received (e.g airplane mode is 'turning off' until
1299 * we know the wireless connections are back online
Jason Monk16fbd9d2017-04-27 14:28:49 -04001300 *
Jason Monk361915c2017-03-21 20:33:59 -04001301 * @param buttonOn Whether the button was turned on or off
1302 */
1303 protected void changeStateFromPress(boolean buttonOn) {
1304 mState = buttonOn ? State.On : State.Off;
1305 }
1306
1307 abstract void onToggle(boolean on);
1308
1309 public void updateState(State state) {
1310 mState = state;
1311 }
1312 }
1313
1314 private class SilentModeToggleAction extends ToggleAction {
1315 public SilentModeToggleAction() {
1316 super(R.drawable.ic_audio_vol_mute,
1317 R.drawable.ic_audio_vol,
1318 R.string.global_action_toggle_silent_mode,
1319 R.string.global_action_silent_mode_on_status,
1320 R.string.global_action_silent_mode_off_status);
1321 }
1322
1323 void onToggle(boolean on) {
1324 if (on) {
1325 mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
1326 } else {
1327 mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
1328 }
1329 }
1330
1331 public boolean showDuringKeyguard() {
1332 return true;
1333 }
1334
1335 public boolean showBeforeProvisioning() {
1336 return false;
1337 }
1338 }
1339
1340 private static class SilentModeTriStateAction implements Action, View.OnClickListener {
1341
Jason Monk16fbd9d2017-04-27 14:28:49 -04001342 private final int[] ITEM_IDS = {R.id.option1, R.id.option2, R.id.option3};
Jason Monk361915c2017-03-21 20:33:59 -04001343
1344 private final AudioManager mAudioManager;
1345 private final Handler mHandler;
Jason Monk361915c2017-03-21 20:33:59 -04001346
Lucas Dupin40ec6b782018-06-05 19:07:16 -07001347 SilentModeTriStateAction(AudioManager audioManager, Handler handler) {
Jason Monk361915c2017-03-21 20:33:59 -04001348 mAudioManager = audioManager;
1349 mHandler = handler;
Jason Monk361915c2017-03-21 20:33:59 -04001350 }
1351
1352 private int ringerModeToIndex(int ringerMode) {
1353 // They just happen to coincide
1354 return ringerMode;
1355 }
1356
1357 private int indexToRingerMode(int index) {
1358 // They just happen to coincide
1359 return index;
1360 }
1361
1362 @Override
1363 public CharSequence getLabelForAccessibility(Context context) {
1364 return null;
1365 }
1366
1367 public View create(Context context, View convertView, ViewGroup parent,
1368 LayoutInflater inflater) {
1369 View v = inflater.inflate(R.layout.global_actions_silent_mode, parent, false);
1370
1371 int selectedIndex = ringerModeToIndex(mAudioManager.getRingerMode());
1372 for (int i = 0; i < 3; i++) {
1373 View itemView = v.findViewById(ITEM_IDS[i]);
1374 itemView.setSelected(selectedIndex == i);
1375 // Set up click handler
1376 itemView.setTag(i);
1377 itemView.setOnClickListener(this);
1378 }
1379 return v;
1380 }
1381
1382 public void onPress() {
1383 }
1384
1385 public boolean showDuringKeyguard() {
1386 return true;
1387 }
1388
1389 public boolean showBeforeProvisioning() {
1390 return false;
1391 }
1392
1393 public boolean isEnabled() {
1394 return true;
1395 }
1396
1397 void willCreate() {
1398 }
1399
1400 public void onClick(View v) {
1401 if (!(v.getTag() instanceof Integer)) return;
1402
1403 int index = (Integer) v.getTag();
1404 mAudioManager.setRingerMode(indexToRingerMode(index));
1405 mHandler.sendEmptyMessageDelayed(MESSAGE_DISMISS, DIALOG_DISMISS_DELAY);
1406 }
1407 }
1408
1409 private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
1410 public void onReceive(Context context, Intent intent) {
1411 String action = intent.getAction();
1412 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)
1413 || Intent.ACTION_SCREEN_OFF.equals(action)) {
1414 String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY);
1415 if (!SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS.equals(reason)) {
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001416 mHandler.sendMessage(mHandler.obtainMessage(MESSAGE_DISMISS, reason));
Jason Monk361915c2017-03-21 20:33:59 -04001417 }
Jayachandran C142eae02019-12-13 19:29:20 -08001418 } else if (TelephonyManager.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED.equals(action)) {
Jason Monk361915c2017-03-21 20:33:59 -04001419 // Airplane mode can be changed after ECM exits if airplane toggle button
1420 // is pressed during ECM mode
Daniel Bright4bcbfce2020-01-09 21:58:16 -08001421 if (!(intent.getBooleanExtra(TelephonyManager.EXTRA_PHONE_IN_ECM_STATE, false))
1422 && mIsWaitingForEcmExit) {
Jason Monk361915c2017-03-21 20:33:59 -04001423 mIsWaitingForEcmExit = false;
1424 changeAirplaneModeSystemSetting(true);
1425 }
1426 }
1427 }
1428 };
1429
1430 PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
1431 @Override
1432 public void onServiceStateChanged(ServiceState serviceState) {
1433 if (!mHasTelephony) return;
1434 final boolean inAirplaneMode = serviceState.getState() == ServiceState.STATE_POWER_OFF;
1435 mAirplaneState = inAirplaneMode ? ToggleAction.State.On : ToggleAction.State.Off;
1436 mAirplaneModeOn.updateState(mAirplaneState);
1437 mAdapter.notifyDataSetChanged();
1438 }
1439 };
1440
1441 private BroadcastReceiver mRingerModeReceiver = new BroadcastReceiver() {
1442 @Override
1443 public void onReceive(Context context, Intent intent) {
1444 if (intent.getAction().equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
1445 mHandler.sendEmptyMessage(MESSAGE_REFRESH);
1446 }
1447 }
1448 };
1449
1450 private ContentObserver mAirplaneModeObserver = new ContentObserver(new Handler()) {
1451 @Override
1452 public void onChange(boolean selfChange) {
1453 onAirplaneModeChanged();
1454 }
1455 };
1456
1457 private static final int MESSAGE_DISMISS = 0;
1458 private static final int MESSAGE_REFRESH = 1;
1459 private static final int MESSAGE_SHOW = 2;
1460 private static final int DIALOG_DISMISS_DELAY = 300; // ms
1461
1462 private Handler mHandler = new Handler() {
1463 public void handleMessage(Message msg) {
1464 switch (msg.what) {
Jason Monk16fbd9d2017-04-27 14:28:49 -04001465 case MESSAGE_DISMISS:
1466 if (mDialog != null) {
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001467 if (SYSTEM_DIALOG_REASON_DREAM.equals(msg.obj)) {
1468 mDialog.dismissImmediately();
1469 } else {
1470 mDialog.dismiss();
1471 }
Jason Monk16fbd9d2017-04-27 14:28:49 -04001472 mDialog = null;
1473 }
1474 break;
1475 case MESSAGE_REFRESH:
1476 refreshSilentMode();
1477 mAdapter.notifyDataSetChanged();
1478 break;
1479 case MESSAGE_SHOW:
1480 handleShow();
1481 break;
Jason Monk361915c2017-03-21 20:33:59 -04001482 }
1483 }
1484 };
1485
1486 private void onAirplaneModeChanged() {
1487 // Let the service state callbacks handle the state.
1488 if (mHasTelephony) return;
1489
1490 boolean airplaneModeOn = Settings.Global.getInt(
Dave Mankoffc88a2d72020-01-10 15:59:31 -05001491 mContentResolver,
Jason Monk361915c2017-03-21 20:33:59 -04001492 Settings.Global.AIRPLANE_MODE_ON,
1493 0) == 1;
1494 mAirplaneState = airplaneModeOn ? ToggleAction.State.On : ToggleAction.State.Off;
1495 mAirplaneModeOn.updateState(mAirplaneState);
1496 }
1497
1498 /**
1499 * Change the airplane mode system setting
1500 */
1501 private void changeAirplaneModeSystemSetting(boolean on) {
1502 Settings.Global.putInt(
Dave Mankoffc88a2d72020-01-10 15:59:31 -05001503 mContentResolver,
Jason Monk361915c2017-03-21 20:33:59 -04001504 Settings.Global.AIRPLANE_MODE_ON,
1505 on ? 1 : 0);
1506 Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
1507 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
1508 intent.putExtra("state", on);
1509 mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
1510 if (!mHasTelephony) {
1511 mAirplaneState = on ? ToggleAction.State.On : ToggleAction.State.Off;
1512 }
1513 }
1514
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001515 private static final class ActionsDialog extends Dialog implements DialogInterface,
1516 ColorExtractor.OnColorsChangedListener {
Jason Monk361915c2017-03-21 20:33:59 -04001517
Jason Monk16fbd9d2017-04-27 14:28:49 -04001518 private final Context mContext;
1519 private final MyAdapter mAdapter;
Steve Elliott53f12ae2019-05-13 17:14:15 -04001520 private final IStatusBarService mStatusBarService;
1521 private final IBinder mToken = new Binder();
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001522 private MultiListLayout mGlobalActionsLayout;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001523 private Drawable mBackgroundDrawable;
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001524 private final SysuiColorExtractor mColorExtractor;
Steve Elliott9b87a442019-03-05 10:24:16 -05001525 private final GlobalActionsPanelPlugin.PanelViewController mPanelController;
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001526 private boolean mKeyguardShowing;
Beverly526d2d62018-08-15 12:55:33 -04001527 private boolean mShowing;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001528 private float mScrimAlpha;
Steve Elliott48f75db2019-05-03 15:03:38 -04001529 private ResetOrientationData mResetOrientationData;
Steve Elliottff2c0d92019-07-30 15:09:54 -04001530 private boolean mHadTopUi;
wilsonshihe8321942019-10-18 18:39:46 +08001531 private final NotificationShadeWindowController mNotificationShadeWindowController;
Matt Pietalfd3b6cb2020-01-08 09:43:54 -05001532 private boolean mControlsEnabled;
Jason Monk16fbd9d2017-04-27 14:28:49 -04001533
Aaron Heuckrothf19d2722019-03-11 17:06:02 -04001534 ActionsDialog(Context context, MyAdapter adapter,
Matt Pietalfd3b6cb2020-01-08 09:43:54 -05001535 GlobalActionsPanelPlugin.PanelViewController plugin,
1536 boolean controlsEnabled) {
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001537 super(context, com.android.systemui.R.style.Theme_SystemUI_Dialog_GlobalActions);
Lucas Dupin448786c2017-07-24 17:44:25 -07001538 mContext = context;
Jason Monk16fbd9d2017-04-27 14:28:49 -04001539 mAdapter = adapter;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -07001540 mColorExtractor = Dependency.get(SysuiColorExtractor.class);
Steve Elliott53f12ae2019-05-13 17:14:15 -04001541 mStatusBarService = Dependency.get(IStatusBarService.class);
wilsonshihe8321942019-10-18 18:39:46 +08001542 mNotificationShadeWindowController =
1543 Dependency.get(NotificationShadeWindowController.class);
Matt Pietalfd3b6cb2020-01-08 09:43:54 -05001544 mControlsEnabled = controlsEnabled;
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001545
1546 // Window initialization
1547 Window window = getWindow();
1548 window.requestFeature(Window.FEATURE_NO_TITLE);
Adrian Roosedfab3b2018-03-08 18:39:20 +01001549 // Inflate the decor view, so the attributes below are not overwritten by the theme.
1550 window.getDecorView();
1551 window.getAttributes().systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1552 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1553 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1554 window.setLayout(MATCH_PARENT, MATCH_PARENT);
1555 window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
Alison Cichowlas4f19f4a2017-07-25 10:56:16 -04001556 window.addFlags(
1557 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001558 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
Adrian Roosedfab3b2018-03-08 18:39:20 +01001559 | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001560 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
1561 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
1562 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001563 window.setType(WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY);
Tiger Huang4a7835f2019-11-06 00:07:56 +08001564 window.setFitWindowInsetsTypes(0 /* types */);
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001565 setTitle(R.string.global_actions);
Steve Elliott9b87a442019-03-05 10:24:16 -05001566
1567 mPanelController = plugin;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001568 initializeLayout();
Steve Elliott9b87a442019-03-05 10:24:16 -05001569 }
1570
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001571 private boolean shouldUsePanel() {
Aran Ink3f594552019-05-13 14:29:35 -04001572 return mPanelController != null && mPanelController.getPanelContent() != null;
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001573 }
1574
1575 private void initializePanel() {
Steve Elliott48f75db2019-05-03 15:03:38 -04001576 int rotation = RotationUtils.getRotation(mContext);
1577 boolean rotationLocked = RotationPolicy.isRotationLocked(mContext);
1578 if (rotation != RotationUtils.ROTATION_NONE) {
1579 if (rotationLocked) {
1580 if (mResetOrientationData == null) {
1581 mResetOrientationData = new ResetOrientationData();
1582 mResetOrientationData.locked = true;
1583 mResetOrientationData.rotation = rotation;
1584 }
1585
1586 // Unlock rotation, so user can choose to rotate to portrait to see the panel.
Steve Elliotte05817f2019-05-17 14:39:53 -04001587 // This call is posted so that the rotation does not change until post-layout,
1588 // otherwise onConfigurationChanged() may not get invoked.
1589 mGlobalActionsLayout.post(() ->
1590 RotationPolicy.setRotationLockAtAngle(
1591 mContext, false, RotationUtils.ROTATION_NONE));
Steve Elliott48f75db2019-05-03 15:03:38 -04001592 }
1593 } else {
1594 if (!rotationLocked) {
1595 if (mResetOrientationData == null) {
1596 mResetOrientationData = new ResetOrientationData();
1597 mResetOrientationData.locked = false;
1598 }
1599
1600 // Lock to portrait, so the user doesn't accidentally hide the panel.
Steve Elliotte05817f2019-05-17 14:39:53 -04001601 // This call is posted so that the rotation does not change until post-layout,
1602 // otherwise onConfigurationChanged() may not get invoked.
1603 mGlobalActionsLayout.post(() ->
1604 RotationPolicy.setRotationLockAtAngle(
1605 mContext, true, RotationUtils.ROTATION_NONE));
Steve Elliott48f75db2019-05-03 15:03:38 -04001606 }
1607
Steve Elliott53f12ae2019-05-13 17:14:15 -04001608 // Disable rotation suggestions, if enabled
1609 setRotationSuggestionsEnabled(false);
1610
Steve Elliott300b48f2019-05-29 14:13:50 -04001611 FrameLayout panelContainer =
1612 findViewById(com.android.systemui.R.id.global_actions_panel_container);
Steve Elliott48f75db2019-05-03 15:03:38 -04001613 FrameLayout.LayoutParams panelParams =
1614 new FrameLayout.LayoutParams(
1615 FrameLayout.LayoutParams.MATCH_PARENT,
Steve Elliott300b48f2019-05-29 14:13:50 -04001616 FrameLayout.LayoutParams.MATCH_PARENT);
Steve Elliott48f75db2019-05-03 15:03:38 -04001617 panelContainer.addView(mPanelController.getPanelContent(), panelParams);
Steve Elliott86ef6282019-05-08 14:45:04 -04001618 mBackgroundDrawable = mPanelController.getBackgroundDrawable();
1619 mScrimAlpha = 1f;
Steve Elliott48f75db2019-05-03 15:03:38 -04001620 }
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001621 }
1622
1623 private void initializeLayout() {
1624 setContentView(getGlobalActionsLayoutId(mContext));
Steve Elliott300b48f2019-05-29 14:13:50 -04001625 fixNavBarClipping();
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001626 mGlobalActionsLayout = findViewById(com.android.systemui.R.id.global_actions_view);
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001627 mGlobalActionsLayout.setOutsideTouchListener(view -> dismiss());
Steve Elliott300b48f2019-05-29 14:13:50 -04001628 ((View) mGlobalActionsLayout.getParent()).setOnClickListener(view -> dismiss());
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001629 mGlobalActionsLayout.setListViewAccessibilityDelegate(new View.AccessibilityDelegate() {
Phil Weaver9054e092018-04-27 16:28:50 -07001630 @Override
1631 public boolean dispatchPopulateAccessibilityEvent(
1632 View host, AccessibilityEvent event) {
1633 // Populate the title here, just as Activity does
1634 event.getText().add(mContext.getString(R.string.global_actions));
1635 return true;
1636 }
1637 });
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001638 mGlobalActionsLayout.setRotationListener(this::onRotate);
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001639 mGlobalActionsLayout.setAdapter(mAdapter);
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001640
Steve Elliott86ef6282019-05-08 14:45:04 -04001641 if (shouldUsePanel()) {
Steve Elliottc59eb342019-04-23 16:59:06 -04001642 initializePanel();
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001643 }
Steve Elliott86ef6282019-05-08 14:45:04 -04001644 if (mBackgroundDrawable == null) {
1645 mBackgroundDrawable = new ScrimDrawable();
1646 mScrimAlpha = ScrimController.GRADIENT_SCRIM_ALPHA;
1647 }
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001648 getWindow().setBackgroundDrawable(mBackgroundDrawable);
Steve Elliott9b87a442019-03-05 10:24:16 -05001649 }
1650
Steve Elliott300b48f2019-05-29 14:13:50 -04001651 private void fixNavBarClipping() {
1652 ViewGroup content = findViewById(android.R.id.content);
1653 content.setClipChildren(false);
1654 content.setClipToPadding(false);
1655 ViewGroup contentParent = (ViewGroup) content.getParent();
1656 contentParent.setClipChildren(false);
1657 contentParent.setClipToPadding(false);
1658 }
1659
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001660 private int getGlobalActionsLayoutId(Context context) {
Matt Pietalfd3b6cb2020-01-08 09:43:54 -05001661 if (mControlsEnabled) {
1662 return com.android.systemui.R.layout.global_actions_grid_v2;
1663 }
1664
Steve Elliottdc165632019-05-23 14:26:31 -04001665 int rotation = RotationUtils.getRotation(context);
1666 boolean useGridLayout = isForceGridEnabled(context)
1667 || (shouldUsePanel() && rotation == RotationUtils.ROTATION_NONE);
1668 if (rotation == RotationUtils.ROTATION_SEASCAPE) {
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001669 if (useGridLayout) {
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001670 return com.android.systemui.R.layout.global_actions_grid_seascape;
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001671 } else {
1672 return com.android.systemui.R.layout.global_actions_column_seascape;
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001673 }
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001674 } else {
1675 if (useGridLayout) {
1676 return com.android.systemui.R.layout.global_actions_grid;
1677 } else {
1678 return com.android.systemui.R.layout.global_actions_column;
1679 }
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001680 }
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001681 }
1682
Jason Monk361915c2017-03-21 20:33:59 -04001683 @Override
1684 protected void onStart() {
1685 super.setCanceledOnTouchOutside(true);
1686 super.onStart();
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001687 mGlobalActionsLayout.updateList();
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001688
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001689 if (mBackgroundDrawable instanceof ScrimDrawable) {
Steve Elliott9b87a442019-03-05 10:24:16 -05001690 mColorExtractor.addOnColorsChangedListener(this);
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001691 GradientColors colors = mColorExtractor.getNeutralColors();
Steve Elliott9b87a442019-03-05 10:24:16 -05001692 updateColors(colors, false /* animate */);
1693 }
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001694 }
1695
1696 /**
1697 * Updates background and system bars according to current GradientColors.
1698 * @param colors Colors and hints to use.
1699 * @param animate Interpolates gradient if true, just sets otherwise.
1700 */
1701 private void updateColors(GradientColors colors, boolean animate) {
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001702 if (!(mBackgroundDrawable instanceof ScrimDrawable)) {
Steve Elliott9b87a442019-03-05 10:24:16 -05001703 return;
1704 }
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001705 ((ScrimDrawable) mBackgroundDrawable).setColor(colors.getMainColor(), animate);
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001706 View decorView = getWindow().getDecorView();
1707 if (colors.supportsDarkText()) {
1708 decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR |
Steve Elliott9b87a442019-03-05 10:24:16 -05001709 View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001710 } else {
1711 decorView.setSystemUiVisibility(0);
1712 }
Jason Monk361915c2017-03-21 20:33:59 -04001713 }
1714
1715 @Override
Jason Monk16fbd9d2017-04-27 14:28:49 -04001716 protected void onStop() {
1717 super.onStop();
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001718 mColorExtractor.removeOnColorsChangedListener(this);
Jason Monk16fbd9d2017-04-27 14:28:49 -04001719 }
1720
1721 @Override
1722 public void show() {
1723 super.show();
Beverly526d2d62018-08-15 12:55:33 -04001724 mShowing = true;
wilsonshihe8321942019-10-18 18:39:46 +08001725 mHadTopUi = mNotificationShadeWindowController.getForceHasTopUi();
1726 mNotificationShadeWindowController.setForceHasTopUi(true);
Steve Elliott9b87a442019-03-05 10:24:16 -05001727 mBackgroundDrawable.setAlpha(0);
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001728 mGlobalActionsLayout.setTranslationX(mGlobalActionsLayout.getAnimationOffsetX());
1729 mGlobalActionsLayout.setTranslationY(mGlobalActionsLayout.getAnimationOffsetY());
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001730 mGlobalActionsLayout.setAlpha(0);
1731 mGlobalActionsLayout.animate()
Jason Monk16fbd9d2017-04-27 14:28:49 -04001732 .alpha(1)
1733 .translationX(0)
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001734 .translationY(0)
Jason Monk16fbd9d2017-04-27 14:28:49 -04001735 .setDuration(300)
Lucas Dupinde9db422017-07-19 17:15:41 -07001736 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001737 .setUpdateListener(animation -> {
1738 int alpha = (int) ((Float) animation.getAnimatedValue()
Steve Elliott9b87a442019-03-05 10:24:16 -05001739 * mScrimAlpha * 255);
1740 mBackgroundDrawable.setAlpha(alpha);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001741 })
Jason Monk16fbd9d2017-04-27 14:28:49 -04001742 .start();
1743 }
1744
1745 @Override
1746 public void dismiss() {
Beverly526d2d62018-08-15 12:55:33 -04001747 if (!mShowing) {
1748 return;
1749 }
1750 mShowing = false;
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001751 mGlobalActionsLayout.setTranslationX(0);
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001752 mGlobalActionsLayout.setTranslationY(0);
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001753 mGlobalActionsLayout.setAlpha(1);
1754 mGlobalActionsLayout.animate()
Jason Monk16fbd9d2017-04-27 14:28:49 -04001755 .alpha(0)
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001756 .translationX(mGlobalActionsLayout.getAnimationOffsetX())
1757 .translationY(mGlobalActionsLayout.getAnimationOffsetY())
Jason Monk16fbd9d2017-04-27 14:28:49 -04001758 .setDuration(300)
Steve Elliottff2c0d92019-07-30 15:09:54 -04001759 .withEndAction(this::completeDismiss)
Jason Monk16fbd9d2017-04-27 14:28:49 -04001760 .setInterpolator(new LogAccelerateInterpolator())
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001761 .setUpdateListener(animation -> {
1762 int alpha = (int) ((1f - (Float) animation.getAnimatedValue())
Steve Elliott9b87a442019-03-05 10:24:16 -05001763 * mScrimAlpha * 255);
1764 mBackgroundDrawable.setAlpha(alpha);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001765 })
Jason Monk16fbd9d2017-04-27 14:28:49 -04001766 .start();
Steve Elliott48f75db2019-05-03 15:03:38 -04001767 dismissPanel();
1768 resetOrientation();
Jason Monk16fbd9d2017-04-27 14:28:49 -04001769 }
1770
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001771 void dismissImmediately() {
Beverly526d2d62018-08-15 12:55:33 -04001772 mShowing = false;
Steve Elliott48f75db2019-05-03 15:03:38 -04001773 dismissPanel();
1774 resetOrientation();
Steve Elliottff2c0d92019-07-30 15:09:54 -04001775 completeDismiss();
1776 }
1777
1778 private void completeDismiss() {
wilsonshihe8321942019-10-18 18:39:46 +08001779 mNotificationShadeWindowController.setForceHasTopUi(mHadTopUi);
Steve Elliottff2c0d92019-07-30 15:09:54 -04001780 super.dismiss();
Steve Elliott48f75db2019-05-03 15:03:38 -04001781 }
1782
1783 private void dismissPanel() {
Steve Elliott2d206d32019-03-14 16:30:33 -04001784 if (mPanelController != null) {
1785 mPanelController.onDismissed();
1786 }
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001787 }
1788
Steve Elliott53f12ae2019-05-13 17:14:15 -04001789 private void setRotationSuggestionsEnabled(boolean enabled) {
1790 try {
1791 final int userId = Binder.getCallingUserHandle().getIdentifier();
1792 final int what = enabled
1793 ? StatusBarManager.DISABLE2_NONE
1794 : StatusBarManager.DISABLE2_ROTATE_SUGGESTIONS;
1795 mStatusBarService.disable2ForUser(what, mToken, mContext.getPackageName(), userId);
1796 } catch (RemoteException ex) {
1797 throw ex.rethrowFromSystemServer();
1798 }
1799 }
1800
Steve Elliott48f75db2019-05-03 15:03:38 -04001801 private void resetOrientation() {
1802 if (mResetOrientationData != null) {
1803 RotationPolicy.setRotationLockAtAngle(mContext, mResetOrientationData.locked,
1804 mResetOrientationData.rotation);
1805 }
Steve Elliott53f12ae2019-05-13 17:14:15 -04001806 setRotationSuggestionsEnabled(true);
Steve Elliott48f75db2019-05-03 15:03:38 -04001807 }
1808
Jason Monk361915c2017-03-21 20:33:59 -04001809 @Override
Lucas Dupin7aaa3532017-05-28 08:51:07 -07001810 public void onColorsChanged(ColorExtractor extractor, int which) {
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001811 if (mKeyguardShowing) {
1812 if ((WallpaperManager.FLAG_LOCK & which) != 0) {
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001813 updateColors(extractor.getColors(WallpaperManager.FLAG_LOCK),
1814 true /* animate */);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001815 }
1816 } else {
1817 if ((WallpaperManager.FLAG_SYSTEM & which) != 0) {
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001818 updateColors(extractor.getColors(WallpaperManager.FLAG_SYSTEM),
1819 true /* animate */);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001820 }
1821 }
1822 }
1823
1824 public void setKeyguardShowing(boolean keyguardShowing) {
1825 mKeyguardShowing = keyguardShowing;
1826 }
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001827
Aaron Heuckroth4ef3a542019-04-01 14:17:23 -04001828 public void refreshDialog() {
1829 initializeLayout();
1830 mGlobalActionsLayout.updateList();
1831 }
1832
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001833 public void onRotate(int from, int to) {
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001834 if (mShowing) {
Aaron Heuckroth4ef3a542019-04-01 14:17:23 -04001835 refreshDialog();
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001836 }
1837 }
Steve Elliott48f75db2019-05-03 15:03:38 -04001838
1839 private static class ResetOrientationData {
1840 public boolean locked;
1841 public int rotation;
1842 }
Jason Monk361915c2017-03-21 20:33:59 -04001843 }
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001844
1845 /**
Aran Ink93dd25c2019-05-09 14:42:14 -04001846 * Determines whether or not debug mode has been activated for the Global Actions Panel.
1847 */
1848 private static boolean isPanelDebugModeEnabled(Context context) {
1849 return Settings.Secure.getInt(context.getContentResolver(),
1850 Settings.Secure.GLOBAL_ACTIONS_PANEL_DEBUG_ENABLED, 0) == 1;
1851 }
1852
1853 /**
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001854 * Determines whether or not the Global Actions menu should be forced to
1855 * use the newer grid-style layout.
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001856 */
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001857 private static boolean isForceGridEnabled(Context context) {
Aran Ink93dd25c2019-05-09 14:42:14 -04001858 return isPanelDebugModeEnabled(context);
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001859 }
Aaron Heuckrothf19d2722019-03-11 17:06:02 -04001860
Aaron Heuckrothf19d2722019-03-11 17:06:02 -04001861
1862 /**
1863 * Determines whether the Global Actions menu should use a separated view for emergency actions.
1864 */
1865 private static boolean shouldUseSeparatedView() {
1866 return true;
1867 }
Matt Pietalfd3b6cb2020-01-08 09:43:54 -05001868
1869 private static boolean isControlsEnabled(Context context) {
1870 return Settings.Secure.getInt(
1871 context.getContentResolver(), "systemui.controls_available", 0) == 1;
1872 }
Jason Monk361915c2017-03-21 20:33:59 -04001873}