blob: 6d16253b61efe4d59f0fff4e16040253360e5826 [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;
Steve Elliott4c868852019-03-14 16:25:41 -040028import android.app.PendingIntent;
Steve Elliott53f12ae2019-05-13 17:14:15 -040029import android.app.StatusBarManager;
Lucas Dupinc1cc7592017-05-22 15:56:16 -070030import android.app.WallpaperManager;
Alex Chau04458852017-11-27 18:21:23 +000031import android.app.admin.DevicePolicyManager;
Pavel Grafov059021b2018-05-02 13:44:46 +010032import android.app.trust.TrustManager;
Jason Monk361915c2017-03-21 20:33:59 -040033import android.content.BroadcastReceiver;
Dave Mankoffc88a2d72020-01-10 15:59:31 -050034import android.content.ContentResolver;
Jason Monk361915c2017-03-21 20:33:59 -040035import android.content.Context;
36import android.content.DialogInterface;
37import android.content.Intent;
38import android.content.IntentFilter;
39import android.content.pm.UserInfo;
Dave Mankoffc88a2d72020-01-10 15:59:31 -050040import android.content.res.Resources;
Jason Monk361915c2017-03-21 20:33:59 -040041import android.database.ContentObserver;
Matt Pietale0661b62020-01-29 14:35:31 -050042import android.graphics.Color;
Jason Monk361915c2017-03-21 20:33:59 -040043import 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;
Dave Mankoff8df818e2020-02-12 14:22:26 -050066import android.view.IWindowManager;
Jason Monk361915c2017-03-21 20:33:59 -040067import android.view.LayoutInflater;
68import android.view.View;
69import android.view.ViewGroup;
Lucas Dupinc1cc7592017-05-22 15:56:16 -070070import android.view.Window;
Jason Monk361915c2017-03-21 20:33:59 -040071import android.view.WindowManager;
Jason Monk361915c2017-03-21 20:33:59 -040072import 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;
Charles He9851a8d2017-10-10 17:31:30 +010090import com.android.systemui.Interpolators;
Aaron Heuckrothf708d472019-01-10 16:54:51 -050091import com.android.systemui.MultiListLayout;
Aaron Heuckroth57d60d22019-03-05 14:00:12 -050092import com.android.systemui.MultiListLayout.MultiListAdapter;
Fabian Kozynskiff5e91f2019-09-24 15:38:08 -040093import com.android.systemui.broadcast.BroadcastDispatcher;
Charles He9851a8d2017-10-10 17:31:30 +010094import com.android.systemui.colorextraction.SysuiColorExtractor;
Fabian Kozynski0424ab12020-02-21 12:09:17 -050095import com.android.systemui.controls.management.ControlsListingController;
Matt Pietal22231792020-01-23 09:51:09 -050096import com.android.systemui.controls.ui.ControlsUiController;
Dave Mankoff8df818e2020-02-12 14:22:26 -050097import com.android.systemui.dagger.qualifiers.Background;
Dave Mankoffc88a2d72020-01-10 15:59:31 -050098import com.android.systemui.dagger.qualifiers.Main;
Steve Elliott4c868852019-03-14 16:25:41 -040099import com.android.systemui.plugins.ActivityStarter;
Charles He9851a8d2017-10-10 17:31:30 +0100100import com.android.systemui.plugins.GlobalActions.GlobalActionsManager;
Steve Elliott9b87a442019-03-05 10:24:16 -0500101import com.android.systemui.plugins.GlobalActionsPanelPlugin;
Lucas Dupin99f5fba2020-03-12 12:59:18 -0700102import com.android.systemui.statusbar.BlurUtils;
Santiago Etchebehere68eb53e2020-02-25 14:25:34 -0800103import com.android.systemui.statusbar.NotificationShadeDepthController;
Matt Pietal22231792020-01-23 09:51:09 -0500104import com.android.systemui.statusbar.phone.NotificationShadeWindowController;
Lucas Dupin43d01242020-02-03 11:58:33 -0800105import com.android.systemui.statusbar.phone.ScrimController;
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700106import com.android.systemui.statusbar.policy.ConfigurationController;
Lucas Dupinc8f16e82019-09-17 18:24:50 -0400107import com.android.systemui.statusbar.policy.KeyguardStateController;
Shaotang Li5c422632018-07-04 14:18:40 +0800108import com.android.systemui.util.EmergencyDialerConstants;
Aaron Heuckroth75e249f2019-02-01 15:59:57 -0500109import com.android.systemui.util.leak.RotationUtils;
Julia Reynolds42411922017-11-08 11:19:09 -0500110import com.android.systemui.volume.SystemUIInterpolators.LogAccelerateInterpolator;
Lucas Dupinc1cc7592017-05-22 15:56:16 -0700111
Jason Monk361915c2017-03-21 20:33:59 -0400112import java.util.ArrayList;
113import java.util.List;
Dave Mankoff8df818e2020-02-12 14:22:26 -0500114import java.util.concurrent.Executor;
Jason Monk361915c2017-03-21 20:33:59 -0400115
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500116import javax.inject.Inject;
117
Jason Monk361915c2017-03-21 20:33:59 -0400118/**
119 * Helper to show the global actions dialog. Each item is an {@link Action} that
120 * may show depending on whether the keyguard is showing, and whether the device
121 * is provisioned.
122 */
Aaron Heuckroth57d60d22019-03-05 14:00:12 -0500123public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
124 DialogInterface.OnShowListener, ConfigurationController.ConfigurationListener {
Jason Monk361915c2017-03-21 20:33:59 -0400125
126 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
127 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
Lucas Dupin1d4a5792018-04-02 15:14:59 -0700128 static public final String SYSTEM_DIALOG_REASON_DREAM = "dream";
Jason Monk361915c2017-03-21 20:33:59 -0400129
130 private static final String TAG = "GlobalActionsDialog";
131
132 private static final boolean SHOW_SILENT_TOGGLE = true;
133
134 /* Valid settings for global actions keys.
135 * see config.xml config_globalActionList */
136 private static final String GLOBAL_ACTION_KEY_POWER = "power";
137 private static final String GLOBAL_ACTION_KEY_AIRPLANE = "airplane";
138 private static final String GLOBAL_ACTION_KEY_BUGREPORT = "bugreport";
139 private static final String GLOBAL_ACTION_KEY_SILENT = "silent";
140 private static final String GLOBAL_ACTION_KEY_USERS = "users";
141 private static final String GLOBAL_ACTION_KEY_SETTINGS = "settings";
142 private static final String GLOBAL_ACTION_KEY_LOCKDOWN = "lockdown";
143 private static final String GLOBAL_ACTION_KEY_VOICEASSIST = "voiceassist";
144 private static final String GLOBAL_ACTION_KEY_ASSIST = "assist";
145 private static final String GLOBAL_ACTION_KEY_RESTART = "restart";
Alex Chau04458852017-11-27 18:21:23 +0000146 private static final String GLOBAL_ACTION_KEY_LOGOUT = "logout";
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800147 private static final String GLOBAL_ACTION_KEY_EMERGENCY = "emergency";
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500148 private static final String GLOBAL_ACTION_KEY_SCREENSHOT = "screenshot";
Jason Monk361915c2017-03-21 20:33:59 -0400149
150 private final Context mContext;
151 private final GlobalActionsManager mWindowManagerFuncs;
152 private final AudioManager mAudioManager;
153 private final IDreamManager mDreamManager;
Alex Chau04458852017-11-27 18:21:23 +0000154 private final DevicePolicyManager mDevicePolicyManager;
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800155 private final LockPatternUtils mLockPatternUtils;
Fabian Kozynskif6063ae2020-02-24 16:14:35 -0500156 private final KeyguardStateController mKeyguardStateController;
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000157 private final BroadcastDispatcher mBroadcastDispatcher;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500158 private final ContentResolver mContentResolver;
159 private final Resources mResources;
Dave Mankoff8df818e2020-02-12 14:22:26 -0500160 private final ConfigurationController mConfigurationController;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500161 private final UserManager mUserManager;
162 private final TrustManager mTrustManager;
163 private final IActivityManager mIActivityManager;
164 private final TelecomManager mTelecomManager;
165 private final MetricsLogger mMetricsLogger;
Santiago Etchebehere68eb53e2020-02-25 14:25:34 -0800166 private final NotificationShadeDepthController mDepthController;
Lucas Dupin99f5fba2020-03-12 12:59:18 -0700167 private final BlurUtils mBlurUtils;
Jason Monk361915c2017-03-21 20:33:59 -0400168
169 private ArrayList<Action> mItems;
170 private ActionsDialog mDialog;
171
172 private Action mSilentModeAction;
173 private ToggleAction mAirplaneModeOn;
174
175 private MyAdapter mAdapter;
176
177 private boolean mKeyguardShowing = false;
178 private boolean mDeviceProvisioned = false;
179 private ToggleAction.State mAirplaneState = ToggleAction.State.Off;
180 private boolean mIsWaitingForEcmExit = false;
181 private boolean mHasTelephony;
182 private boolean mHasVibrator;
183 private final boolean mShowSilentToggle;
184 private final EmergencyAffordanceManager mEmergencyAffordanceManager;
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500185 private final ScreenshotHelper mScreenshotHelper;
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400186 private final ScreenRecordHelper mScreenRecordHelper;
Steve Elliotta3f5207922019-03-18 13:37:22 -0400187 private final ActivityStarter mActivityStarter;
Lucas Dupin991415e2019-11-25 17:48:58 -0800188 private final SysuiColorExtractor mSysuiColorExtractor;
189 private final IStatusBarService mStatusBarService;
190 private final NotificationShadeWindowController mNotificationShadeWindowController;
Steve Elliotta3f5207922019-03-18 13:37:22 -0400191 private GlobalActionsPanelPlugin mPanelPlugin;
Matt Pietal22231792020-01-23 09:51:09 -0500192 private ControlsUiController mControlsUiController;
Dave Mankoff8df818e2020-02-12 14:22:26 -0500193 private final IWindowManager mIWindowManager;
194 private final Executor mBackgroundExecutor;
Fabian Kozynski0424ab12020-02-21 12:09:17 -0500195 private final ControlsListingController mControlsListingController;
196 private boolean mAnyControlsProviders = false;
Steve Elliott9b87a442019-03-05 10:24:16 -0500197
Jason Monk361915c2017-03-21 20:33:59 -0400198 /**
199 * @param context everything needs a context :(
200 */
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500201 @Inject
202 public GlobalActionsDialog(Context context, GlobalActionsManager windowManagerFuncs,
203 AudioManager audioManager, IDreamManager iDreamManager,
204 DevicePolicyManager devicePolicyManager, LockPatternUtils lockPatternUtils,
Fabian Kozynskif6063ae2020-02-24 16:14:35 -0500205 BroadcastDispatcher broadcastDispatcher,
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500206 ConnectivityManager connectivityManager, TelephonyManager telephonyManager,
207 ContentResolver contentResolver, @Nullable Vibrator vibrator, @Main Resources resources,
208 ConfigurationController configurationController, ActivityStarter activityStarter,
209 KeyguardStateController keyguardStateController, UserManager userManager,
210 TrustManager trustManager, IActivityManager iActivityManager,
Dave Mankoff3c6aaab2020-01-10 17:50:34 -0500211 @Nullable TelecomManager telecomManager, MetricsLogger metricsLogger,
Santiago Etchebehere68eb53e2020-02-25 14:25:34 -0800212 NotificationShadeDepthController depthController, SysuiColorExtractor colorExtractor,
Lucas Dupin99f5fba2020-03-12 12:59:18 -0700213 IStatusBarService statusBarService, BlurUtils blurUtils,
Matt Pietal22231792020-01-23 09:51:09 -0500214 NotificationShadeWindowController notificationShadeWindowController,
Dave Mankoff8df818e2020-02-12 14:22:26 -0500215 ControlsUiController controlsUiController, IWindowManager iWindowManager,
Fabian Kozynski0424ab12020-02-21 12:09:17 -0500216 @Background Executor backgroundExecutor,
217 ControlsListingController controlsListingController) {
Lucas Dupin448786c2017-07-24 17:44:25 -0700218 mContext = new ContextThemeWrapper(context, com.android.systemui.R.style.qs_theme);
Jason Monk361915c2017-03-21 20:33:59 -0400219 mWindowManagerFuncs = windowManagerFuncs;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500220 mAudioManager = audioManager;
221 mDreamManager = iDreamManager;
222 mDevicePolicyManager = devicePolicyManager;
223 mLockPatternUtils = lockPatternUtils;
Fabian Kozynskif6063ae2020-02-24 16:14:35 -0500224 mKeyguardStateController = keyguardStateController;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500225 mBroadcastDispatcher = broadcastDispatcher;
226 mContentResolver = contentResolver;
227 mResources = resources;
Dave Mankoff8df818e2020-02-12 14:22:26 -0500228 mConfigurationController = configurationController;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500229 mUserManager = userManager;
230 mTrustManager = trustManager;
231 mIActivityManager = iActivityManager;
232 mTelecomManager = telecomManager;
233 mMetricsLogger = metricsLogger;
Santiago Etchebehere68eb53e2020-02-25 14:25:34 -0800234 mDepthController = depthController;
Lucas Dupin991415e2019-11-25 17:48:58 -0800235 mSysuiColorExtractor = colorExtractor;
236 mStatusBarService = statusBarService;
237 mNotificationShadeWindowController = notificationShadeWindowController;
Matt Pietal22231792020-01-23 09:51:09 -0500238 mControlsUiController = controlsUiController;
Dave Mankoff8df818e2020-02-12 14:22:26 -0500239 mIWindowManager = iWindowManager;
240 mBackgroundExecutor = backgroundExecutor;
Fabian Kozynski0424ab12020-02-21 12:09:17 -0500241 mControlsListingController = controlsListingController;
Lucas Dupin99f5fba2020-03-12 12:59:18 -0700242 mBlurUtils = blurUtils;
Jason Monk361915c2017-03-21 20:33:59 -0400243
244 // receive broadcasts
245 IntentFilter filter = new IntentFilter();
246 filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
247 filter.addAction(Intent.ACTION_SCREEN_OFF);
Jayachandran C142eae02019-12-13 19:29:20 -0800248 filter.addAction(TelephonyManager.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000249 mBroadcastDispatcher.registerReceiver(mBroadcastReceiver, filter);
Jason Monk361915c2017-03-21 20:33:59 -0400250
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500251 mHasTelephony = connectivityManager.isNetworkSupported(ConnectivityManager.TYPE_MOBILE);
Jason Monk361915c2017-03-21 20:33:59 -0400252
253 // get notified of phone state changes
Jason Monk361915c2017-03-21 20:33:59 -0400254 telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE);
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500255 contentResolver.registerContentObserver(
Jason Monk361915c2017-03-21 20:33:59 -0400256 Settings.Global.getUriFor(Settings.Global.AIRPLANE_MODE_ON), true,
257 mAirplaneModeObserver);
Jason Monk361915c2017-03-21 20:33:59 -0400258 mHasVibrator = vibrator != null && vibrator.hasVibrator();
259
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500260 mShowSilentToggle = SHOW_SILENT_TOGGLE && !resources.getBoolean(
Jason Monk361915c2017-03-21 20:33:59 -0400261 R.bool.config_useFixedVolume);
262
263 mEmergencyAffordanceManager = new EmergencyAffordanceManager(context);
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500264 mScreenshotHelper = new ScreenshotHelper(context);
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400265 mScreenRecordHelper = new ScreenRecordHelper(context);
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700266
Dave Mankoff8df818e2020-02-12 14:22:26 -0500267 mConfigurationController.addCallback(this);
Steve Elliott9b87a442019-03-05 10:24:16 -0500268
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500269 mActivityStarter = activityStarter;
Lucas Dupinc8f16e82019-09-17 18:24:50 -0400270 keyguardStateController.addCallback(new KeyguardStateController.Callback() {
271 @Override
272 public void onUnlockedChanged() {
273 if (mDialog != null && mDialog.mPanelController != null) {
274 boolean locked = !keyguardStateController.canDismissLockScreen();
275 mDialog.mPanelController.onDeviceLockStateChanged(locked);
276 }
277 }
278 });
Fabian Kozynski0424ab12020-02-21 12:09:17 -0500279
280 mControlsListingController.addCallback(list -> mAnyControlsProviders = !list.isEmpty());
Jason Monk361915c2017-03-21 20:33:59 -0400281 }
282
283 /**
284 * Show the global actions dialog (creating if necessary)
Jason Monk16fbd9d2017-04-27 14:28:49 -0400285 *
Jason Monk361915c2017-03-21 20:33:59 -0400286 * @param keyguardShowing True if keyguard is showing
287 */
Steve Elliotta3f5207922019-03-18 13:37:22 -0400288 public void showDialog(boolean keyguardShowing, boolean isDeviceProvisioned,
289 GlobalActionsPanelPlugin panelPlugin) {
Jason Monk361915c2017-03-21 20:33:59 -0400290 mKeyguardShowing = keyguardShowing;
291 mDeviceProvisioned = isDeviceProvisioned;
Steve Elliotta3f5207922019-03-18 13:37:22 -0400292 mPanelPlugin = panelPlugin;
Jason Monk361915c2017-03-21 20:33:59 -0400293 if (mDialog != null) {
294 mDialog.dismiss();
295 mDialog = null;
296 // Show delayed, so that the dismiss of the previous dialog completes
297 mHandler.sendEmptyMessage(MESSAGE_SHOW);
298 } else {
299 handleShow();
300 }
301 }
302
Charles He9851a8d2017-10-10 17:31:30 +0100303 /**
304 * Dismiss the global actions dialog, if it's currently shown
305 */
306 public void dismissDialog() {
307 mHandler.removeMessages(MESSAGE_DISMISS);
308 mHandler.sendEmptyMessage(MESSAGE_DISMISS);
309 }
310
Jason Monk361915c2017-03-21 20:33:59 -0400311 private void awakenIfNecessary() {
312 if (mDreamManager != null) {
313 try {
314 if (mDreamManager.isDreaming()) {
315 mDreamManager.awaken();
316 }
317 } catch (RemoteException e) {
318 // we tried
319 }
320 }
321 }
322
323 private void handleShow() {
324 awakenIfNecessary();
325 mDialog = createDialog();
326 prepareDialog();
327
328 // If we only have 1 item and it's a simple press action, just do this action.
329 if (mAdapter.getCount() == 1
330 && mAdapter.getItem(0) instanceof SinglePressAction
331 && !(mAdapter.getItem(0) instanceof LongPressAction)) {
332 ((SinglePressAction) mAdapter.getItem(0)).onPress();
333 } else {
334 WindowManager.LayoutParams attrs = mDialog.getWindow().getAttributes();
335 attrs.setTitle("ActionsDialog");
Adrian Roos2f05bb32018-02-19 16:42:27 +0100336 attrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
Jason Monk361915c2017-03-21 20:33:59 -0400337 mDialog.getWindow().setAttributes(attrs);
338 mDialog.show();
339 mWindowManagerFuncs.onGlobalActionsShown();
Jason Monk361915c2017-03-21 20:33:59 -0400340 }
341 }
342
343 /**
344 * Create the global actions dialog.
Jason Monk16fbd9d2017-04-27 14:28:49 -0400345 *
Jason Monk361915c2017-03-21 20:33:59 -0400346 * @return A new dialog.
347 */
348 private ActionsDialog createDialog() {
349 // Simple toggle style if there's no vibrator, otherwise use a tri-state
350 if (!mHasVibrator) {
351 mSilentModeAction = new SilentModeToggleAction();
352 } else {
Lucas Dupin40ec6b782018-06-05 19:07:16 -0700353 mSilentModeAction = new SilentModeTriStateAction(mAudioManager, mHandler);
Jason Monk361915c2017-03-21 20:33:59 -0400354 }
Aran Ink780d4502020-02-14 10:39:58 -0500355 mAirplaneModeOn = new AirplaneModeAction();
Jason Monk361915c2017-03-21 20:33:59 -0400356 onAirplaneModeChanged();
357
358 mItems = new ArrayList<Action>();
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500359 String[] defaultActions = mResources.getStringArray(R.array.config_globalActionsList);
Jason Monk361915c2017-03-21 20:33:59 -0400360
361 ArraySet<String> addedKeys = new ArraySet<String>();
362 for (int i = 0; i < defaultActions.length; i++) {
363 String actionKey = defaultActions[i];
364 if (addedKeys.contains(actionKey)) {
365 // If we already have added this, don't add it again.
366 continue;
367 }
368 if (GLOBAL_ACTION_KEY_POWER.equals(actionKey)) {
369 mItems.add(new PowerAction());
370 } else if (GLOBAL_ACTION_KEY_AIRPLANE.equals(actionKey)) {
371 mItems.add(mAirplaneModeOn);
372 } else if (GLOBAL_ACTION_KEY_BUGREPORT.equals(actionKey)) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500373 if (Settings.Global.getInt(mContentResolver,
Jason Monk361915c2017-03-21 20:33:59 -0400374 Settings.Global.BUGREPORT_IN_POWER_MENU, 0) != 0 && isCurrentUserOwner()) {
375 mItems.add(new BugReportAction());
376 }
377 } else if (GLOBAL_ACTION_KEY_SILENT.equals(actionKey)) {
378 if (mShowSilentToggle) {
379 mItems.add(mSilentModeAction);
380 }
381 } else if (GLOBAL_ACTION_KEY_USERS.equals(actionKey)) {
382 if (SystemProperties.getBoolean("fw.power_user_switcher", false)) {
383 addUsersToMenu(mItems);
384 }
385 } else if (GLOBAL_ACTION_KEY_SETTINGS.equals(actionKey)) {
386 mItems.add(getSettingsAction());
387 } else if (GLOBAL_ACTION_KEY_LOCKDOWN.equals(actionKey)) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500388 if (Settings.Secure.getIntForUser(mContentResolver,
Chad Brubaker02cd6cf2018-05-01 14:59:33 -0700389 Settings.Secure.LOCKDOWN_IN_POWER_MENU, 0, getCurrentUser().id) != 0
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800390 && shouldDisplayLockdown()) {
Chad Brubaker4f28f0d2017-09-07 14:28:13 -0700391 mItems.add(getLockdownAction());
392 }
Jason Monk361915c2017-03-21 20:33:59 -0400393 } else if (GLOBAL_ACTION_KEY_VOICEASSIST.equals(actionKey)) {
394 mItems.add(getVoiceAssistAction());
395 } else if (GLOBAL_ACTION_KEY_ASSIST.equals(actionKey)) {
396 mItems.add(getAssistAction());
397 } else if (GLOBAL_ACTION_KEY_RESTART.equals(actionKey)) {
398 mItems.add(new RestartAction());
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500399 } else if (GLOBAL_ACTION_KEY_SCREENSHOT.equals(actionKey)) {
400 mItems.add(new ScreenshotAction());
Alex Chau04458852017-11-27 18:21:23 +0000401 } else if (GLOBAL_ACTION_KEY_LOGOUT.equals(actionKey)) {
Alex Chaud7958272017-12-08 11:30:52 +0000402 if (mDevicePolicyManager.isLogoutEnabled()
Alex Chau04458852017-11-27 18:21:23 +0000403 && getCurrentUser().id != UserHandle.USER_SYSTEM) {
404 mItems.add(new LogoutAction());
Alex Chau04458852017-11-27 18:21:23 +0000405 }
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800406 } else if (GLOBAL_ACTION_KEY_EMERGENCY.equals(actionKey)) {
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400407 if (!mEmergencyAffordanceManager.needsEmergencyAffordance()) {
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800408 mItems.add(new EmergencyDialerAction());
409 }
Jason Monk361915c2017-03-21 20:33:59 -0400410 } else {
411 Log.e(TAG, "Invalid global action key " + actionKey);
412 }
413 // Add here so we don't add more than one.
414 addedKeys.add(actionKey);
415 }
416
417 if (mEmergencyAffordanceManager.needsEmergencyAffordance()) {
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400418 mItems.add(new EmergencyAffordanceAction());
Jason Monk361915c2017-03-21 20:33:59 -0400419 }
420
421 mAdapter = new MyAdapter();
422
Steve Elliott9b87a442019-03-05 10:24:16 -0500423 GlobalActionsPanelPlugin.PanelViewController panelViewController =
Steve Elliotta3f5207922019-03-18 13:37:22 -0400424 mPanelPlugin != null
425 ? mPanelPlugin.onPanelShown(
Steve Elliott4c868852019-03-14 16:25:41 -0400426 new GlobalActionsPanelPlugin.Callbacks() {
427 @Override
428 public void dismissGlobalActionsMenu() {
Steve Elliottc3147e22019-11-20 19:34:57 -0500429 dismissDialog();
Steve Elliott4c868852019-03-14 16:25:41 -0400430 }
431
432 @Override
433 public void startPendingIntentDismissingKeyguard(
434 PendingIntent intent) {
435 mActivityStarter
436 .startPendingIntentDismissingKeyguard(intent);
437 }
Steve Elliotte2a2e9b2019-04-30 21:31:03 -0400438 },
Fabian Kozynskif6063ae2020-02-24 16:14:35 -0500439 !mKeyguardStateController.isUnlocked())
Steve Elliott9b87a442019-03-05 10:24:16 -0500440 : null;
Steve Elliott02bbaaa2019-05-01 16:55:33 -0400441
Lucas Dupin991415e2019-11-25 17:48:58 -0800442 ActionsDialog dialog = new ActionsDialog(mContext, mAdapter, panelViewController,
Santiago Etchebehere68eb53e2020-02-25 14:25:34 -0800443 mDepthController, mSysuiColorExtractor, mStatusBarService,
Matt Pietal22231792020-01-23 09:51:09 -0500444 mNotificationShadeWindowController,
Lucas Dupin99f5fba2020-03-12 12:59:18 -0700445 shouldShowControls() ? mControlsUiController : null, mBlurUtils);
Jason Monk361915c2017-03-21 20:33:59 -0400446 dialog.setCanceledOnTouchOutside(false); // Handled by the custom class.
Lucas Dupinc1cc7592017-05-22 15:56:16 -0700447 dialog.setKeyguardShowing(mKeyguardShowing);
Jason Monk361915c2017-03-21 20:33:59 -0400448
449 dialog.setOnDismissListener(this);
Shaotang Li786da902018-08-02 11:18:00 +0800450 dialog.setOnShowListener(this);
Jason Monk361915c2017-03-21 20:33:59 -0400451
452 return dialog;
453 }
454
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800455 private boolean shouldDisplayLockdown() {
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800456 // Lockdown is meaningless without a place to go.
Fabian Kozynskif6063ae2020-02-24 16:14:35 -0500457 if (!mKeyguardStateController.isMethodSecure()) {
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800458 return false;
459 }
460
Fabian Kozynskif6063ae2020-02-24 16:14:35 -0500461 int userId = getCurrentUser().id;
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800462 // Only show the lockdown button if the device isn't locked down (for whatever reason).
463 int state = mLockPatternUtils.getStrongAuthForUser(userId);
464 return (state == STRONG_AUTH_NOT_REQUIRED
465 || state == SOME_AUTH_REQUIRED_AFTER_USER_REQUEST);
466 }
467
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700468 @Override
469 public void onUiModeChanged() {
470 mContext.getTheme().applyStyle(mContext.getThemeResId(), true);
Lucas Dupina4e12ba2019-04-18 11:56:28 -0700471 if (mDialog != null && mDialog.isShowing()) {
Aaron Heuckroth4ef3a542019-04-01 14:17:23 -0400472 mDialog.refreshDialog();
473 }
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700474 }
475
476 public void destroy() {
Dave Mankoff8df818e2020-02-12 14:22:26 -0500477 mConfigurationController.removeCallback(this);
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700478 }
479
Jason Monk361915c2017-03-21 20:33:59 -0400480 private final class PowerAction extends SinglePressAction implements LongPressAction {
481 private PowerAction() {
482 super(R.drawable.ic_lock_power_off,
Jason Monk16fbd9d2017-04-27 14:28:49 -0400483 R.string.global_action_power_off);
Jason Monk361915c2017-03-21 20:33:59 -0400484 }
485
486 @Override
487 public boolean onLongPress() {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500488 if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) {
Jason Monk361915c2017-03-21 20:33:59 -0400489 mWindowManagerFuncs.reboot(true);
490 return true;
491 }
492 return false;
493 }
494
495 @Override
496 public boolean showDuringKeyguard() {
497 return true;
498 }
499
500 @Override
501 public boolean showBeforeProvisioning() {
502 return true;
503 }
504
505 @Override
506 public void onPress() {
507 // shutdown by making sure radio and power are handled accordingly.
508 mWindowManagerFuncs.shutdown();
509 }
510 }
511
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400512 private abstract class EmergencyAction extends SinglePressAction {
513 EmergencyAction(int iconResId, int messageResId) {
514 super(iconResId, messageResId);
515 }
516
517 @Override
518 public boolean shouldBeSeparated() {
Aran Ink780d4502020-02-14 10:39:58 -0500519 return true;
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400520 }
521
522 @Override
523 public View create(
524 Context context, View convertView, ViewGroup parent, LayoutInflater inflater) {
525 View v = super.create(context, convertView, parent, inflater);
526 int textColor;
527 if (shouldBeSeparated()) {
528 textColor = v.getResources().getColor(
529 com.android.systemui.R.color.global_actions_alert_text);
530 } else {
531 textColor = v.getResources().getColor(
532 com.android.systemui.R.color.global_actions_text);
533 }
534 TextView messageView = v.findViewById(R.id.message);
535 messageView.setTextColor(textColor);
Aaron Heuckroth3f2d8b52019-04-05 13:27:51 -0400536 messageView.setSelected(true); // necessary for marquee to work
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400537 ImageView icon = (ImageView) v.findViewById(R.id.icon);
538 icon.getDrawable().setTint(textColor);
539 return v;
540 }
541
542 @Override
543 public boolean showDuringKeyguard() {
544 return true;
545 }
546
547 @Override
548 public boolean showBeforeProvisioning() {
549 return true;
550 }
551 }
552
553 private class EmergencyAffordanceAction extends EmergencyAction {
554 EmergencyAffordanceAction() {
555 super(R.drawable.emergency_icon,
556 R.string.global_action_emergency);
557 }
558
559 @Override
560 public void onPress() {
561 mEmergencyAffordanceManager.performEmergencyCall();
562 }
563 }
564
565 private class EmergencyDialerAction extends EmergencyAction {
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800566 private EmergencyDialerAction() {
Aran Ink50195262019-05-30 10:55:37 -0400567 super(com.android.systemui.R.drawable.ic_emergency_star,
Wesley.CW Wang3004fcb2018-06-15 16:24:57 +0800568 R.string.global_action_emergency);
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800569 }
570
571 @Override
572 public void onPress() {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500573 mMetricsLogger.action(MetricsEvent.ACTION_EMERGENCY_DIALER_FROM_POWER_MENU);
Dave Mankoff3c6aaab2020-01-10 17:50:34 -0500574 if (mTelecomManager != null) {
575 Intent intent = mTelecomManager.createLaunchEmergencyDialerIntent(
576 null /* number */);
577 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
578 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
579 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
580 intent.putExtra(EmergencyDialerConstants.EXTRA_ENTRY_TYPE,
581 EmergencyDialerConstants.ENTRY_TYPE_POWER_MENU);
582 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
583 }
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800584 }
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800585 }
586
Jason Monk361915c2017-03-21 20:33:59 -0400587 private final class RestartAction extends SinglePressAction implements LongPressAction {
588 private RestartAction() {
589 super(R.drawable.ic_restart, R.string.global_action_restart);
590 }
591
592 @Override
593 public boolean onLongPress() {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500594 if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) {
Jason Monk361915c2017-03-21 20:33:59 -0400595 mWindowManagerFuncs.reboot(true);
596 return true;
597 }
598 return false;
599 }
600
601 @Override
602 public boolean showDuringKeyguard() {
603 return true;
604 }
605
606 @Override
607 public boolean showBeforeProvisioning() {
608 return true;
609 }
610
611 @Override
612 public void onPress() {
613 mWindowManagerFuncs.reboot(false);
614 }
615 }
616
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400617 private class ScreenshotAction extends SinglePressAction implements LongPressAction {
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500618 public ScreenshotAction() {
619 super(R.drawable.ic_screenshot, R.string.global_action_screenshot);
620 }
621
622 @Override
623 public void onPress() {
624 // Add a little delay before executing, to give the
625 // dialog a chance to go away before it takes a
626 // screenshot.
627 // TODO: instead, omit global action dialog layer
628 mHandler.postDelayed(new Runnable() {
629 @Override
630 public void run() {
James O'Learyfa5bb7a2019-09-05 13:43:29 -0400631 mScreenshotHelper.takeScreenshot(1, true, true, mHandler, null);
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500632 mMetricsLogger.action(MetricsEvent.ACTION_SCREENSHOT_POWER_MENU);
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500633 }
634 }, 500);
635 }
636
637 @Override
638 public boolean showDuringKeyguard() {
639 return true;
640 }
641
642 @Override
643 public boolean showBeforeProvisioning() {
644 return false;
645 }
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400646
647 @Override
648 public boolean onLongPress() {
649 if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SCREENRECORD_LONG_PRESS)) {
650 mScreenRecordHelper.launchRecordPrompt();
651 } else {
652 onPress();
653 }
654 return true;
655 }
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500656 }
657
Jason Monk361915c2017-03-21 20:33:59 -0400658 private class BugReportAction extends SinglePressAction implements LongPressAction {
659
660 public BugReportAction() {
661 super(R.drawable.ic_lock_bugreport, R.string.bugreport_title);
662 }
663
664 @Override
665 public void onPress() {
666 // don't actually trigger the bugreport if we are running stability
667 // tests via monkey
668 if (ActivityManager.isUserAMonkey()) {
669 return;
670 }
671 // Add a little delay before executing, to give the
672 // dialog a chance to go away before it takes a
673 // screenshot.
674 mHandler.postDelayed(new Runnable() {
675 @Override
676 public void run() {
677 try {
678 // Take an "interactive" bugreport.
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500679 mMetricsLogger.action(
Jason Monk361915c2017-03-21 20:33:59 -0400680 MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_INTERACTIVE);
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500681 if (!mIActivityManager.launchBugReportHandlerApp()) {
Paul Changc40f5782019-11-04 18:55:31 +0800682 Log.w(TAG, "Bugreport handler could not be launched");
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500683 mIActivityManager.requestInteractiveBugReport();
Paul Changc40f5782019-11-04 18:55:31 +0800684 }
Jason Monk361915c2017-03-21 20:33:59 -0400685 } catch (RemoteException e) {
686 }
687 }
688 }, 500);
689 }
690
691 @Override
692 public boolean onLongPress() {
693 // don't actually trigger the bugreport if we are running stability
694 // tests via monkey
695 if (ActivityManager.isUserAMonkey()) {
696 return false;
697 }
698 try {
699 // Take a "full" bugreport.
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500700 mMetricsLogger.action(MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_FULL);
701 mIActivityManager.requestFullBugReport();
Jason Monk361915c2017-03-21 20:33:59 -0400702 } catch (RemoteException e) {
703 }
704 return false;
705 }
706
707 public boolean showDuringKeyguard() {
708 return true;
709 }
710
711 @Override
712 public boolean showBeforeProvisioning() {
713 return false;
714 }
Jason Monk361915c2017-03-21 20:33:59 -0400715 }
716
Alex Chau04458852017-11-27 18:21:23 +0000717 private final class LogoutAction extends SinglePressAction {
718 private LogoutAction() {
719 super(R.drawable.ic_logout, R.string.global_action_logout);
720 }
721
722 @Override
723 public boolean showDuringKeyguard() {
724 return true;
725 }
726
727 @Override
728 public boolean showBeforeProvisioning() {
729 return false;
730 }
731
732 @Override
733 public void onPress() {
734 // Add a little delay before executing, to give the dialog a chance to go away before
735 // switching user
736 mHandler.postDelayed(() -> {
737 try {
Alex Chauedb6a012018-01-26 12:52:43 +0000738 int currentUserId = getCurrentUser().id;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500739 mIActivityManager.switchUser(UserHandle.USER_SYSTEM);
740 mIActivityManager.stopUser(currentUserId, true /*force*/, null);
Alex Chau04458852017-11-27 18:21:23 +0000741 } catch (RemoteException re) {
742 Log.e(TAG, "Couldn't logout user " + re);
743 }
744 }, 500);
745 }
746 }
747
Jason Monk361915c2017-03-21 20:33:59 -0400748 private Action getSettingsAction() {
749 return new SinglePressAction(R.drawable.ic_settings,
750 R.string.global_action_settings) {
751
752 @Override
753 public void onPress() {
754 Intent intent = new Intent(Settings.ACTION_SETTINGS);
755 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
756 mContext.startActivity(intent);
757 }
758
759 @Override
760 public boolean showDuringKeyguard() {
761 return true;
762 }
763
764 @Override
765 public boolean showBeforeProvisioning() {
766 return true;
767 }
768 };
769 }
770
Jason Monk361915c2017-03-21 20:33:59 -0400771 private Action getAssistAction() {
772 return new SinglePressAction(R.drawable.ic_action_assist_focused,
773 R.string.global_action_assist) {
774 @Override
775 public void onPress() {
776 Intent intent = new Intent(Intent.ACTION_ASSIST);
777 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
778 mContext.startActivity(intent);
779 }
780
781 @Override
782 public boolean showDuringKeyguard() {
783 return true;
784 }
785
786 @Override
787 public boolean showBeforeProvisioning() {
788 return true;
789 }
790 };
791 }
792
793 private Action getVoiceAssistAction() {
794 return new SinglePressAction(R.drawable.ic_voice_search,
795 R.string.global_action_voice_assist) {
796 @Override
797 public void onPress() {
798 Intent intent = new Intent(Intent.ACTION_VOICE_ASSIST);
799 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
800 mContext.startActivity(intent);
801 }
802
803 @Override
804 public boolean showDuringKeyguard() {
805 return true;
806 }
807
808 @Override
809 public boolean showBeforeProvisioning() {
810 return true;
811 }
812 };
813 }
814
815 private Action getLockdownAction() {
Alison Cichowlas21125432018-05-16 15:40:45 -0400816 return new SinglePressAction(R.drawable.ic_lock_lockdown,
Jason Monk361915c2017-03-21 20:33:59 -0400817 R.string.global_action_lockdown) {
818
819 @Override
820 public void onPress() {
Dave Mankoff8df818e2020-02-12 14:22:26 -0500821 mLockPatternUtils.requireStrongAuth(STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN,
822 UserHandle.USER_ALL);
Jason Monk361915c2017-03-21 20:33:59 -0400823 try {
Dave Mankoff8df818e2020-02-12 14:22:26 -0500824 mIWindowManager.lockNow(null);
Pavel Grafov059021b2018-05-02 13:44:46 +0100825 // Lock profiles (if any) on the background thread.
Dave Mankoff8df818e2020-02-12 14:22:26 -0500826 mBackgroundExecutor.execute(() -> 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));
Aran Inkb4199d92020-02-07 13:25:21 -05001029 if (action instanceof LongPressAction) {
1030 view.setOnLongClickListener(v -> onLongClickItem(position));
1031 }
Jason Monk16fbd9d2017-04-27 14:28:49 -04001032 return view;
Jason Monk361915c2017-03-21 20:33:59 -04001033 }
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001034
1035 @Override
1036 public boolean onLongClickItem(int position) {
1037 final Action action = mAdapter.getItem(position);
1038 if (action instanceof LongPressAction) {
Aran Inkbaa25862019-06-11 15:48:55 -04001039 if (mDialog != null) {
1040 mDialog.dismiss();
1041 } else {
1042 Log.w(TAG, "Action long-clicked while mDialog is null.");
1043 }
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001044 return ((LongPressAction) action).onLongPress();
1045 }
1046 return false;
1047 }
1048
1049 @Override
1050 public void onClickItem(int position) {
1051 Action item = mAdapter.getItem(position);
1052 if (!(item instanceof SilentModeTriStateAction)) {
Aran Inkbaa25862019-06-11 15:48:55 -04001053 if (mDialog != null) {
1054 mDialog.dismiss();
1055 } else {
1056 Log.w(TAG, "Action clicked while mDialog is null.");
1057 }
1058 item.onPress();
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001059 }
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001060 }
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -04001061
1062 @Override
1063 public boolean shouldBeSeparated(int position) {
1064 return getItem(position).shouldBeSeparated();
1065 }
Jason Monk361915c2017-03-21 20:33:59 -04001066 }
1067
1068 // note: the scheme below made more sense when we were planning on having
1069 // 8 different things in the global actions dialog. seems overkill with
1070 // only 3 items now, but may as well keep this flexible approach so it will
1071 // be easy should someone decide at the last minute to include something
1072 // else, such as 'enable wifi', or 'enable bluetooth'
1073
1074 /**
1075 * What each item in the global actions dialog must be able to support.
1076 */
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001077 public interface Action {
Jason Monk361915c2017-03-21 20:33:59 -04001078 /**
1079 * @return Text that will be announced when dialog is created. null
Jason Monk16fbd9d2017-04-27 14:28:49 -04001080 * for none.
Jason Monk361915c2017-03-21 20:33:59 -04001081 */
1082 CharSequence getLabelForAccessibility(Context context);
1083
1084 View create(Context context, View convertView, ViewGroup parent, LayoutInflater inflater);
1085
1086 void onPress();
1087
1088 /**
1089 * @return whether this action should appear in the dialog when the keygaurd
Jason Monk16fbd9d2017-04-27 14:28:49 -04001090 * is showing.
Jason Monk361915c2017-03-21 20:33:59 -04001091 */
1092 boolean showDuringKeyguard();
1093
1094 /**
1095 * @return whether this action should appear in the dialog before the
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001096 * device is provisioned.onlongpress
1097 *
Jason Monk361915c2017-03-21 20:33:59 -04001098 */
1099 boolean showBeforeProvisioning();
1100
1101 boolean isEnabled();
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001102
1103 default boolean shouldBeSeparated() {
1104 return false;
1105 }
Jason Monk361915c2017-03-21 20:33:59 -04001106 }
1107
1108 /**
1109 * An action that also supports long press.
1110 */
1111 private interface LongPressAction extends Action {
1112 boolean onLongPress();
1113 }
1114
1115 /**
1116 * A single press action maintains no state, just responds to a press
1117 * and takes an action.
1118 */
Matt Pietale0661b62020-01-29 14:35:31 -05001119
1120 private abstract class SinglePressAction implements Action {
Jason Monk361915c2017-03-21 20:33:59 -04001121 private final int mIconResId;
1122 private final Drawable mIcon;
1123 private final int mMessageResId;
1124 private final CharSequence mMessage;
1125
1126 protected SinglePressAction(int iconResId, int messageResId) {
1127 mIconResId = iconResId;
1128 mMessageResId = messageResId;
1129 mMessage = null;
1130 mIcon = null;
1131 }
1132
1133 protected SinglePressAction(int iconResId, Drawable icon, CharSequence message) {
1134 mIconResId = iconResId;
1135 mMessageResId = 0;
1136 mMessage = message;
1137 mIcon = icon;
1138 }
1139
1140 public boolean isEnabled() {
1141 return true;
1142 }
1143
1144 public String getStatus() {
1145 return null;
1146 }
1147
1148 abstract public void onPress();
1149
1150 public CharSequence getLabelForAccessibility(Context context) {
1151 if (mMessage != null) {
1152 return mMessage;
1153 } else {
1154 return context.getString(mMessageResId);
1155 }
1156 }
1157
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001158 protected int getActionLayoutId(Context context) {
Matt Pietale0661b62020-01-29 14:35:31 -05001159 if (shouldShowControls()) {
Matt Pietalfd3b6cb2020-01-08 09:43:54 -05001160 return com.android.systemui.R.layout.global_actions_grid_item_v2;
1161 }
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001162 return com.android.systemui.R.layout.global_actions_grid_item;
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001163 }
1164
Jason Monk361915c2017-03-21 20:33:59 -04001165 public View create(
1166 Context context, View convertView, ViewGroup parent, LayoutInflater inflater) {
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001167 View v = inflater.inflate(getActionLayoutId(context), parent,
Jason Monk16fbd9d2017-04-27 14:28:49 -04001168 false);
Jason Monk361915c2017-03-21 20:33:59 -04001169
1170 ImageView icon = (ImageView) v.findViewById(R.id.icon);
1171 TextView messageView = (TextView) v.findViewById(R.id.message);
Aaron Heuckroth3f2d8b52019-04-05 13:27:51 -04001172 messageView.setSelected(true); // necessary for marquee to work
Jason Monk361915c2017-03-21 20:33:59 -04001173
Jason Monk361915c2017-03-21 20:33:59 -04001174 if (mIcon != null) {
1175 icon.setImageDrawable(mIcon);
1176 icon.setScaleType(ScaleType.CENTER_CROP);
1177 } else if (mIconResId != 0) {
1178 icon.setImageDrawable(context.getDrawable(mIconResId));
1179 }
1180 if (mMessage != null) {
1181 messageView.setText(mMessage);
1182 } else {
1183 messageView.setText(mMessageResId);
1184 }
1185
1186 return v;
1187 }
1188 }
1189
1190 /**
1191 * A toggle action knows whether it is on or off, and displays an icon
1192 * and status message accordingly.
1193 */
1194 private static abstract class ToggleAction implements Action {
1195
1196 enum State {
1197 Off(false),
1198 TurningOn(true),
1199 TurningOff(true),
1200 On(false);
1201
1202 private final boolean inTransition;
1203
1204 State(boolean intermediate) {
1205 inTransition = intermediate;
1206 }
1207
1208 public boolean inTransition() {
1209 return inTransition;
1210 }
1211 }
1212
1213 protected State mState = State.Off;
1214
1215 // prefs
1216 protected int mEnabledIconResId;
1217 protected int mDisabledIconResid;
1218 protected int mMessageResId;
1219 protected int mEnabledStatusMessageResId;
1220 protected int mDisabledStatusMessageResId;
1221
1222 /**
Jason Monk16fbd9d2017-04-27 14:28:49 -04001223 * @param enabledIconResId The icon for when this action is on.
1224 * @param disabledIconResid The icon for when this action is off.
1225 * @param message The general information message, e.g 'Silent Mode'
1226 * @param enabledStatusMessageResId The on status message, e.g 'sound disabled'
Jason Monk361915c2017-03-21 20:33:59 -04001227 * @param disabledStatusMessageResId The off status message, e.g. 'sound enabled'
1228 */
1229 public ToggleAction(int enabledIconResId,
1230 int disabledIconResid,
1231 int message,
1232 int enabledStatusMessageResId,
1233 int disabledStatusMessageResId) {
1234 mEnabledIconResId = enabledIconResId;
1235 mDisabledIconResid = disabledIconResid;
1236 mMessageResId = message;
1237 mEnabledStatusMessageResId = enabledStatusMessageResId;
1238 mDisabledStatusMessageResId = disabledStatusMessageResId;
1239 }
1240
1241 /**
1242 * Override to make changes to resource IDs just before creating the
1243 * View.
1244 */
1245 void willCreate() {
1246
1247 }
1248
1249 @Override
1250 public CharSequence getLabelForAccessibility(Context context) {
1251 return context.getString(mMessageResId);
1252 }
1253
1254 public View create(Context context, View convertView, ViewGroup parent,
1255 LayoutInflater inflater) {
1256 willCreate();
1257
Koji Fukui5c010ee2019-12-24 16:12:07 +09001258 View v = inflater.inflate(com.android.systemui.R
1259 .layout.global_actions_grid_item, parent, false);
Jason Monk361915c2017-03-21 20:33:59 -04001260
1261 ImageView icon = (ImageView) v.findViewById(R.id.icon);
1262 TextView messageView = (TextView) v.findViewById(R.id.message);
Jason Monk361915c2017-03-21 20:33:59 -04001263 final boolean enabled = isEnabled();
Koji Fukui5c010ee2019-12-24 16:12:07 +09001264 boolean on = ((mState == State.On) || (mState == State.TurningOn));
Jason Monk361915c2017-03-21 20:33:59 -04001265
1266 if (messageView != null) {
Koji Fukui5c010ee2019-12-24 16:12:07 +09001267 messageView.setText(on ? mEnabledStatusMessageResId : mDisabledStatusMessageResId);
Jason Monk361915c2017-03-21 20:33:59 -04001268 messageView.setEnabled(enabled);
Aaron Heuckroth3f2d8b52019-04-05 13:27:51 -04001269 messageView.setSelected(true); // necessary for marquee to work
Jason Monk361915c2017-03-21 20:33:59 -04001270 }
1271
Jason Monk361915c2017-03-21 20:33:59 -04001272 if (icon != null) {
1273 icon.setImageDrawable(context.getDrawable(
1274 (on ? mEnabledIconResId : mDisabledIconResid)));
1275 icon.setEnabled(enabled);
1276 }
1277
Jason Monk361915c2017-03-21 20:33:59 -04001278 v.setEnabled(enabled);
1279
1280 return v;
1281 }
1282
1283 public final void onPress() {
1284 if (mState.inTransition()) {
1285 Log.w(TAG, "shouldn't be able to toggle when in transition");
1286 return;
1287 }
1288
1289 final boolean nowOn = !(mState == State.On);
1290 onToggle(nowOn);
1291 changeStateFromPress(nowOn);
1292 }
1293
1294 public boolean isEnabled() {
1295 return !mState.inTransition();
1296 }
1297
1298 /**
1299 * Implementations may override this if their state can be in on of the intermediate
1300 * states until some notification is received (e.g airplane mode is 'turning off' until
1301 * we know the wireless connections are back online
Jason Monk16fbd9d2017-04-27 14:28:49 -04001302 *
Jason Monk361915c2017-03-21 20:33:59 -04001303 * @param buttonOn Whether the button was turned on or off
1304 */
1305 protected void changeStateFromPress(boolean buttonOn) {
1306 mState = buttonOn ? State.On : State.Off;
1307 }
1308
1309 abstract void onToggle(boolean on);
1310
1311 public void updateState(State state) {
1312 mState = state;
1313 }
1314 }
1315
Aran Ink780d4502020-02-14 10:39:58 -05001316 private class AirplaneModeAction extends ToggleAction {
1317 AirplaneModeAction() {
1318 super(
1319 R.drawable.ic_lock_airplane_mode,
1320 R.drawable.ic_lock_airplane_mode_off,
1321 R.string.global_actions_toggle_airplane_mode,
1322 R.string.global_actions_airplane_mode_on_status,
1323 R.string.global_actions_airplane_mode_off_status);
1324 }
1325 void onToggle(boolean on) {
1326 if (mHasTelephony && TelephonyProperties.in_ecm_mode().orElse(false)) {
1327 mIsWaitingForEcmExit = true;
1328 // Launch ECM exit dialog
1329 Intent ecmDialogIntent =
1330 new Intent(TelephonyManager.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null);
1331 ecmDialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1332 mContext.startActivity(ecmDialogIntent);
1333 } else {
1334 changeAirplaneModeSystemSetting(on);
1335 }
1336 }
1337
1338 @Override
1339 protected void changeStateFromPress(boolean buttonOn) {
1340 if (!mHasTelephony) return;
1341
1342 // In ECM mode airplane state cannot be changed
1343 if (!TelephonyProperties.in_ecm_mode().orElse(false)) {
1344 mState = buttonOn ? State.TurningOn : State.TurningOff;
1345 mAirplaneState = mState;
1346 }
1347 }
1348
1349 public boolean showDuringKeyguard() {
1350 return true;
1351 }
1352
1353 public boolean showBeforeProvisioning() {
1354 return false;
1355 }
1356 }
1357
Jason Monk361915c2017-03-21 20:33:59 -04001358 private class SilentModeToggleAction extends ToggleAction {
1359 public SilentModeToggleAction() {
1360 super(R.drawable.ic_audio_vol_mute,
1361 R.drawable.ic_audio_vol,
1362 R.string.global_action_toggle_silent_mode,
1363 R.string.global_action_silent_mode_on_status,
1364 R.string.global_action_silent_mode_off_status);
1365 }
1366
1367 void onToggle(boolean on) {
1368 if (on) {
1369 mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
1370 } else {
1371 mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
1372 }
1373 }
1374
1375 public boolean showDuringKeyguard() {
1376 return true;
1377 }
1378
1379 public boolean showBeforeProvisioning() {
1380 return false;
1381 }
1382 }
1383
1384 private static class SilentModeTriStateAction implements Action, View.OnClickListener {
1385
Jason Monk16fbd9d2017-04-27 14:28:49 -04001386 private final int[] ITEM_IDS = {R.id.option1, R.id.option2, R.id.option3};
Jason Monk361915c2017-03-21 20:33:59 -04001387
1388 private final AudioManager mAudioManager;
1389 private final Handler mHandler;
Jason Monk361915c2017-03-21 20:33:59 -04001390
Lucas Dupin40ec6b782018-06-05 19:07:16 -07001391 SilentModeTriStateAction(AudioManager audioManager, Handler handler) {
Jason Monk361915c2017-03-21 20:33:59 -04001392 mAudioManager = audioManager;
1393 mHandler = handler;
Jason Monk361915c2017-03-21 20:33:59 -04001394 }
1395
1396 private int ringerModeToIndex(int ringerMode) {
1397 // They just happen to coincide
1398 return ringerMode;
1399 }
1400
1401 private int indexToRingerMode(int index) {
1402 // They just happen to coincide
1403 return index;
1404 }
1405
1406 @Override
1407 public CharSequence getLabelForAccessibility(Context context) {
1408 return null;
1409 }
1410
1411 public View create(Context context, View convertView, ViewGroup parent,
1412 LayoutInflater inflater) {
1413 View v = inflater.inflate(R.layout.global_actions_silent_mode, parent, false);
1414
1415 int selectedIndex = ringerModeToIndex(mAudioManager.getRingerMode());
1416 for (int i = 0; i < 3; i++) {
1417 View itemView = v.findViewById(ITEM_IDS[i]);
1418 itemView.setSelected(selectedIndex == i);
1419 // Set up click handler
1420 itemView.setTag(i);
1421 itemView.setOnClickListener(this);
1422 }
1423 return v;
1424 }
1425
1426 public void onPress() {
1427 }
1428
1429 public boolean showDuringKeyguard() {
1430 return true;
1431 }
1432
1433 public boolean showBeforeProvisioning() {
1434 return false;
1435 }
1436
1437 public boolean isEnabled() {
1438 return true;
1439 }
1440
1441 void willCreate() {
1442 }
1443
1444 public void onClick(View v) {
1445 if (!(v.getTag() instanceof Integer)) return;
1446
1447 int index = (Integer) v.getTag();
1448 mAudioManager.setRingerMode(indexToRingerMode(index));
1449 mHandler.sendEmptyMessageDelayed(MESSAGE_DISMISS, DIALOG_DISMISS_DELAY);
1450 }
1451 }
1452
1453 private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
1454 public void onReceive(Context context, Intent intent) {
1455 String action = intent.getAction();
1456 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)
1457 || Intent.ACTION_SCREEN_OFF.equals(action)) {
1458 String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY);
1459 if (!SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS.equals(reason)) {
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001460 mHandler.sendMessage(mHandler.obtainMessage(MESSAGE_DISMISS, reason));
Jason Monk361915c2017-03-21 20:33:59 -04001461 }
Jayachandran C142eae02019-12-13 19:29:20 -08001462 } else if (TelephonyManager.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED.equals(action)) {
Jason Monk361915c2017-03-21 20:33:59 -04001463 // Airplane mode can be changed after ECM exits if airplane toggle button
1464 // is pressed during ECM mode
Daniel Bright4bcbfce2020-01-09 21:58:16 -08001465 if (!(intent.getBooleanExtra(TelephonyManager.EXTRA_PHONE_IN_ECM_STATE, false))
1466 && mIsWaitingForEcmExit) {
Jason Monk361915c2017-03-21 20:33:59 -04001467 mIsWaitingForEcmExit = false;
1468 changeAirplaneModeSystemSetting(true);
1469 }
1470 }
1471 }
1472 };
1473
1474 PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
1475 @Override
1476 public void onServiceStateChanged(ServiceState serviceState) {
1477 if (!mHasTelephony) return;
1478 final boolean inAirplaneMode = serviceState.getState() == ServiceState.STATE_POWER_OFF;
1479 mAirplaneState = inAirplaneMode ? ToggleAction.State.On : ToggleAction.State.Off;
1480 mAirplaneModeOn.updateState(mAirplaneState);
1481 mAdapter.notifyDataSetChanged();
1482 }
1483 };
1484
1485 private BroadcastReceiver mRingerModeReceiver = new BroadcastReceiver() {
1486 @Override
1487 public void onReceive(Context context, Intent intent) {
1488 if (intent.getAction().equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
1489 mHandler.sendEmptyMessage(MESSAGE_REFRESH);
1490 }
1491 }
1492 };
1493
1494 private ContentObserver mAirplaneModeObserver = new ContentObserver(new Handler()) {
1495 @Override
1496 public void onChange(boolean selfChange) {
1497 onAirplaneModeChanged();
1498 }
1499 };
1500
1501 private static final int MESSAGE_DISMISS = 0;
1502 private static final int MESSAGE_REFRESH = 1;
1503 private static final int MESSAGE_SHOW = 2;
1504 private static final int DIALOG_DISMISS_DELAY = 300; // ms
1505
1506 private Handler mHandler = new Handler() {
1507 public void handleMessage(Message msg) {
1508 switch (msg.what) {
Jason Monk16fbd9d2017-04-27 14:28:49 -04001509 case MESSAGE_DISMISS:
1510 if (mDialog != null) {
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001511 if (SYSTEM_DIALOG_REASON_DREAM.equals(msg.obj)) {
1512 mDialog.dismissImmediately();
1513 } else {
1514 mDialog.dismiss();
1515 }
Jason Monk16fbd9d2017-04-27 14:28:49 -04001516 mDialog = null;
1517 }
1518 break;
1519 case MESSAGE_REFRESH:
1520 refreshSilentMode();
1521 mAdapter.notifyDataSetChanged();
1522 break;
1523 case MESSAGE_SHOW:
1524 handleShow();
1525 break;
Jason Monk361915c2017-03-21 20:33:59 -04001526 }
1527 }
1528 };
1529
1530 private void onAirplaneModeChanged() {
1531 // Let the service state callbacks handle the state.
1532 if (mHasTelephony) return;
1533
1534 boolean airplaneModeOn = Settings.Global.getInt(
Dave Mankoffc88a2d72020-01-10 15:59:31 -05001535 mContentResolver,
Jason Monk361915c2017-03-21 20:33:59 -04001536 Settings.Global.AIRPLANE_MODE_ON,
1537 0) == 1;
1538 mAirplaneState = airplaneModeOn ? ToggleAction.State.On : ToggleAction.State.Off;
1539 mAirplaneModeOn.updateState(mAirplaneState);
1540 }
1541
1542 /**
1543 * Change the airplane mode system setting
1544 */
1545 private void changeAirplaneModeSystemSetting(boolean on) {
1546 Settings.Global.putInt(
Dave Mankoffc88a2d72020-01-10 15:59:31 -05001547 mContentResolver,
Jason Monk361915c2017-03-21 20:33:59 -04001548 Settings.Global.AIRPLANE_MODE_ON,
1549 on ? 1 : 0);
1550 Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
1551 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
1552 intent.putExtra("state", on);
1553 mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
1554 if (!mHasTelephony) {
1555 mAirplaneState = on ? ToggleAction.State.On : ToggleAction.State.Off;
1556 }
1557 }
1558
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001559 private static final class ActionsDialog extends Dialog implements DialogInterface,
1560 ColorExtractor.OnColorsChangedListener {
Jason Monk361915c2017-03-21 20:33:59 -04001561
Jason Monk16fbd9d2017-04-27 14:28:49 -04001562 private final Context mContext;
1563 private final MyAdapter mAdapter;
Steve Elliott53f12ae2019-05-13 17:14:15 -04001564 private final IStatusBarService mStatusBarService;
1565 private final IBinder mToken = new Binder();
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001566 private MultiListLayout mGlobalActionsLayout;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001567 private Drawable mBackgroundDrawable;
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001568 private final SysuiColorExtractor mColorExtractor;
Steve Elliott9b87a442019-03-05 10:24:16 -05001569 private final GlobalActionsPanelPlugin.PanelViewController mPanelController;
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001570 private boolean mKeyguardShowing;
Beverly526d2d62018-08-15 12:55:33 -04001571 private boolean mShowing;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001572 private float mScrimAlpha;
Steve Elliott48f75db2019-05-03 15:03:38 -04001573 private ResetOrientationData mResetOrientationData;
Steve Elliottff2c0d92019-07-30 15:09:54 -04001574 private boolean mHadTopUi;
wilsonshihe8321942019-10-18 18:39:46 +08001575 private final NotificationShadeWindowController mNotificationShadeWindowController;
Santiago Etchebehere68eb53e2020-02-25 14:25:34 -08001576 private final NotificationShadeDepthController mDepthController;
Lucas Dupin99f5fba2020-03-12 12:59:18 -07001577 private final BlurUtils mBlurUtils;
Matt Pietal22231792020-01-23 09:51:09 -05001578
1579 private ControlsUiController mControlsUiController;
1580 private ViewGroup mControlsView;
Jason Monk16fbd9d2017-04-27 14:28:49 -04001581
Aaron Heuckrothf19d2722019-03-11 17:06:02 -04001582 ActionsDialog(Context context, MyAdapter adapter,
Santiago Etchebehere68eb53e2020-02-25 14:25:34 -08001583 GlobalActionsPanelPlugin.PanelViewController plugin,
1584 NotificationShadeDepthController depthController,
Lucas Dupin991415e2019-11-25 17:48:58 -08001585 SysuiColorExtractor sysuiColorExtractor, IStatusBarService statusBarService,
1586 NotificationShadeWindowController notificationShadeWindowController,
Lucas Dupin99f5fba2020-03-12 12:59:18 -07001587 ControlsUiController controlsUiController, BlurUtils blurUtils) {
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001588 super(context, com.android.systemui.R.style.Theme_SystemUI_Dialog_GlobalActions);
Lucas Dupin448786c2017-07-24 17:44:25 -07001589 mContext = context;
Jason Monk16fbd9d2017-04-27 14:28:49 -04001590 mAdapter = adapter;
Santiago Etchebehere68eb53e2020-02-25 14:25:34 -08001591 mDepthController = depthController;
Lucas Dupin991415e2019-11-25 17:48:58 -08001592 mColorExtractor = sysuiColorExtractor;
1593 mStatusBarService = statusBarService;
1594 mNotificationShadeWindowController = notificationShadeWindowController;
Matt Pietal22231792020-01-23 09:51:09 -05001595 mControlsUiController = controlsUiController;
Lucas Dupin99f5fba2020-03-12 12:59:18 -07001596 mBlurUtils = blurUtils;
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001597
1598 // Window initialization
1599 Window window = getWindow();
1600 window.requestFeature(Window.FEATURE_NO_TITLE);
Adrian Roosedfab3b2018-03-08 18:39:20 +01001601 // Inflate the decor view, so the attributes below are not overwritten by the theme.
1602 window.getDecorView();
1603 window.getAttributes().systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1604 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1605 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1606 window.setLayout(MATCH_PARENT, MATCH_PARENT);
1607 window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
Alison Cichowlas4f19f4a2017-07-25 10:56:16 -04001608 window.addFlags(
1609 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001610 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
Adrian Roosedfab3b2018-03-08 18:39:20 +01001611 | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001612 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
1613 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
1614 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001615 window.setType(WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY);
Tiger Huang52724442020-01-20 21:38:42 +08001616 window.getAttributes().setFitInsetsTypes(0 /* types */);
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001617 setTitle(R.string.global_actions);
Steve Elliott9b87a442019-03-05 10:24:16 -05001618
1619 mPanelController = plugin;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001620 initializeLayout();
Steve Elliott9b87a442019-03-05 10:24:16 -05001621 }
1622
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001623 private boolean shouldUsePanel() {
Aran Ink3f594552019-05-13 14:29:35 -04001624 return mPanelController != null && mPanelController.getPanelContent() != null;
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001625 }
1626
1627 private void initializePanel() {
Steve Elliott48f75db2019-05-03 15:03:38 -04001628 int rotation = RotationUtils.getRotation(mContext);
1629 boolean rotationLocked = RotationPolicy.isRotationLocked(mContext);
1630 if (rotation != RotationUtils.ROTATION_NONE) {
1631 if (rotationLocked) {
1632 if (mResetOrientationData == null) {
1633 mResetOrientationData = new ResetOrientationData();
1634 mResetOrientationData.locked = true;
1635 mResetOrientationData.rotation = rotation;
1636 }
1637
1638 // Unlock rotation, so user can choose to rotate to portrait to see the panel.
Steve Elliotte05817f2019-05-17 14:39:53 -04001639 // This call is posted so that the rotation does not change until post-layout,
1640 // otherwise onConfigurationChanged() may not get invoked.
1641 mGlobalActionsLayout.post(() ->
1642 RotationPolicy.setRotationLockAtAngle(
1643 mContext, false, RotationUtils.ROTATION_NONE));
Steve Elliott48f75db2019-05-03 15:03:38 -04001644 }
1645 } else {
1646 if (!rotationLocked) {
1647 if (mResetOrientationData == null) {
1648 mResetOrientationData = new ResetOrientationData();
1649 mResetOrientationData.locked = false;
1650 }
1651
1652 // Lock to portrait, so the user doesn't accidentally hide the panel.
Steve Elliotte05817f2019-05-17 14:39:53 -04001653 // This call is posted so that the rotation does not change until post-layout,
1654 // otherwise onConfigurationChanged() may not get invoked.
1655 mGlobalActionsLayout.post(() ->
1656 RotationPolicy.setRotationLockAtAngle(
1657 mContext, true, RotationUtils.ROTATION_NONE));
Steve Elliott48f75db2019-05-03 15:03:38 -04001658 }
1659
Steve Elliott53f12ae2019-05-13 17:14:15 -04001660 // Disable rotation suggestions, if enabled
1661 setRotationSuggestionsEnabled(false);
1662
Steve Elliott300b48f2019-05-29 14:13:50 -04001663 FrameLayout panelContainer =
1664 findViewById(com.android.systemui.R.id.global_actions_panel_container);
Steve Elliott48f75db2019-05-03 15:03:38 -04001665 FrameLayout.LayoutParams panelParams =
1666 new FrameLayout.LayoutParams(
1667 FrameLayout.LayoutParams.MATCH_PARENT,
Steve Elliott300b48f2019-05-29 14:13:50 -04001668 FrameLayout.LayoutParams.MATCH_PARENT);
Steve Elliott48f75db2019-05-03 15:03:38 -04001669 panelContainer.addView(mPanelController.getPanelContent(), panelParams);
Steve Elliott48f75db2019-05-03 15:03:38 -04001670 }
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001671 }
1672
1673 private void initializeLayout() {
1674 setContentView(getGlobalActionsLayoutId(mContext));
Steve Elliott300b48f2019-05-29 14:13:50 -04001675 fixNavBarClipping();
Matt Pietal22231792020-01-23 09:51:09 -05001676 mControlsView = findViewById(com.android.systemui.R.id.global_actions_controls);
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001677 mGlobalActionsLayout = findViewById(com.android.systemui.R.id.global_actions_view);
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001678 mGlobalActionsLayout.setOutsideTouchListener(view -> dismiss());
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001679 mGlobalActionsLayout.setListViewAccessibilityDelegate(new View.AccessibilityDelegate() {
Phil Weaver9054e092018-04-27 16:28:50 -07001680 @Override
1681 public boolean dispatchPopulateAccessibilityEvent(
1682 View host, AccessibilityEvent event) {
1683 // Populate the title here, just as Activity does
1684 event.getText().add(mContext.getString(R.string.global_actions));
1685 return true;
1686 }
1687 });
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001688 mGlobalActionsLayout.setRotationListener(this::onRotate);
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001689 mGlobalActionsLayout.setAdapter(mAdapter);
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001690
Aran Ink06090262020-03-03 13:23:17 -05001691 View globalActionsParent = (View) mGlobalActionsLayout.getParent();
1692 globalActionsParent.setOnClickListener(v -> dismiss());
1693
1694 // add fall-through dismiss handling to root view
1695 View rootView = findViewById(com.android.systemui.R.id.global_actions_grid_root);
1696 if (rootView != null) {
1697 rootView.setOnClickListener(v -> dismiss());
1698 }
1699
Steve Elliott86ef6282019-05-08 14:45:04 -04001700 if (shouldUsePanel()) {
Steve Elliottc59eb342019-04-23 16:59:06 -04001701 initializePanel();
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001702 }
Steve Elliott86ef6282019-05-08 14:45:04 -04001703 if (mBackgroundDrawable == null) {
1704 mBackgroundDrawable = new ScrimDrawable();
Lucas Dupin99f5fba2020-03-12 12:59:18 -07001705 mScrimAlpha = mBlurUtils.supportsBlursOnWindows()
1706 ? ScrimController.BLUR_SCRIM_ALPHA : ScrimController.BUSY_SCRIM_ALPHA;
Steve Elliott86ef6282019-05-08 14:45:04 -04001707 }
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04001708 getWindow().setBackgroundDrawable(mBackgroundDrawable);
Steve Elliott9b87a442019-03-05 10:24:16 -05001709 }
1710
Steve Elliott300b48f2019-05-29 14:13:50 -04001711 private void fixNavBarClipping() {
1712 ViewGroup content = findViewById(android.R.id.content);
1713 content.setClipChildren(false);
1714 content.setClipToPadding(false);
1715 ViewGroup contentParent = (ViewGroup) content.getParent();
1716 contentParent.setClipChildren(false);
1717 contentParent.setClipToPadding(false);
1718 }
1719
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001720 private int getGlobalActionsLayoutId(Context context) {
Matt Pietal22231792020-01-23 09:51:09 -05001721 if (mControlsUiController != null) {
Matt Pietalfd3b6cb2020-01-08 09:43:54 -05001722 return com.android.systemui.R.layout.global_actions_grid_v2;
1723 }
1724
Steve Elliottdc165632019-05-23 14:26:31 -04001725 int rotation = RotationUtils.getRotation(context);
1726 boolean useGridLayout = isForceGridEnabled(context)
1727 || (shouldUsePanel() && rotation == RotationUtils.ROTATION_NONE);
1728 if (rotation == RotationUtils.ROTATION_SEASCAPE) {
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001729 if (useGridLayout) {
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001730 return com.android.systemui.R.layout.global_actions_grid_seascape;
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001731 } else {
1732 return com.android.systemui.R.layout.global_actions_column_seascape;
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001733 }
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001734 } else {
1735 if (useGridLayout) {
1736 return com.android.systemui.R.layout.global_actions_grid;
1737 } else {
1738 return com.android.systemui.R.layout.global_actions_column;
1739 }
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001740 }
Aaron Heuckroth166392f2019-01-17 16:50:59 -05001741 }
1742
Jason Monk361915c2017-03-21 20:33:59 -04001743 @Override
1744 protected void onStart() {
1745 super.setCanceledOnTouchOutside(true);
1746 super.onStart();
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001747 mGlobalActionsLayout.updateList();
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001748
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001749 if (mBackgroundDrawable instanceof ScrimDrawable) {
Steve Elliott9b87a442019-03-05 10:24:16 -05001750 mColorExtractor.addOnColorsChangedListener(this);
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001751 GradientColors colors = mColorExtractor.getNeutralColors();
Steve Elliott9b87a442019-03-05 10:24:16 -05001752 updateColors(colors, false /* animate */);
1753 }
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001754 }
1755
1756 /**
1757 * Updates background and system bars according to current GradientColors.
1758 * @param colors Colors and hints to use.
1759 * @param animate Interpolates gradient if true, just sets otherwise.
1760 */
1761 private void updateColors(GradientColors colors, boolean animate) {
Lucas Dupin2bd3af62019-03-25 17:44:28 -07001762 if (!(mBackgroundDrawable instanceof ScrimDrawable)) {
Steve Elliott9b87a442019-03-05 10:24:16 -05001763 return;
1764 }
Lucas Dupinba2b48a2020-02-06 09:28:06 -08001765 ((ScrimDrawable) mBackgroundDrawable).setColor(colors.supportsDarkText() ? Color.WHITE
1766 : Color.BLACK, animate);
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001767 View decorView = getWindow().getDecorView();
1768 if (colors.supportsDarkText()) {
1769 decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR |
Steve Elliott9b87a442019-03-05 10:24:16 -05001770 View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001771 } else {
1772 decorView.setSystemUiVisibility(0);
1773 }
Jason Monk361915c2017-03-21 20:33:59 -04001774 }
1775
1776 @Override
Jason Monk16fbd9d2017-04-27 14:28:49 -04001777 protected void onStop() {
1778 super.onStop();
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001779 mColorExtractor.removeOnColorsChangedListener(this);
Jason Monk16fbd9d2017-04-27 14:28:49 -04001780 }
1781
1782 @Override
1783 public void show() {
1784 super.show();
Beverly526d2d62018-08-15 12:55:33 -04001785 mShowing = true;
wilsonshihe8321942019-10-18 18:39:46 +08001786 mHadTopUi = mNotificationShadeWindowController.getForceHasTopUi();
1787 mNotificationShadeWindowController.setForceHasTopUi(true);
Steve Elliott9b87a442019-03-05 10:24:16 -05001788 mBackgroundDrawable.setAlpha(0);
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001789 mGlobalActionsLayout.setTranslationX(mGlobalActionsLayout.getAnimationOffsetX());
1790 mGlobalActionsLayout.setTranslationY(mGlobalActionsLayout.getAnimationOffsetY());
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001791 mGlobalActionsLayout.setAlpha(0);
1792 mGlobalActionsLayout.animate()
Jason Monk16fbd9d2017-04-27 14:28:49 -04001793 .alpha(1)
1794 .translationX(0)
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001795 .translationY(0)
Jason Monk16fbd9d2017-04-27 14:28:49 -04001796 .setDuration(300)
Lucas Dupinde9db422017-07-19 17:15:41 -07001797 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001798 .setUpdateListener(animation -> {
Lucas Dupin991415e2019-11-25 17:48:58 -08001799 float animatedValue = animation.getAnimatedFraction();
1800 int alpha = (int) (animatedValue * mScrimAlpha * 255);
Steve Elliott9b87a442019-03-05 10:24:16 -05001801 mBackgroundDrawable.setAlpha(alpha);
Santiago Etchebehere68eb53e2020-02-25 14:25:34 -08001802 mDepthController.updateGlobalDialogVisibility(animatedValue,
1803 mGlobalActionsLayout);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001804 })
Jason Monk16fbd9d2017-04-27 14:28:49 -04001805 .start();
Matt Pietal22231792020-01-23 09:51:09 -05001806 if (mControlsUiController != null) {
1807 mControlsUiController.show(mControlsView);
1808 }
Jason Monk16fbd9d2017-04-27 14:28:49 -04001809 }
1810
1811 @Override
1812 public void dismiss() {
Beverly526d2d62018-08-15 12:55:33 -04001813 if (!mShowing) {
1814 return;
1815 }
1816 mShowing = false;
Matt Pietal22231792020-01-23 09:51:09 -05001817 if (mControlsUiController != null) mControlsUiController.hide();
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001818 mGlobalActionsLayout.setTranslationX(0);
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001819 mGlobalActionsLayout.setTranslationY(0);
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001820 mGlobalActionsLayout.setAlpha(1);
1821 mGlobalActionsLayout.animate()
Jason Monk16fbd9d2017-04-27 14:28:49 -04001822 .alpha(0)
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001823 .translationX(mGlobalActionsLayout.getAnimationOffsetX())
1824 .translationY(mGlobalActionsLayout.getAnimationOffsetY())
Jason Monk16fbd9d2017-04-27 14:28:49 -04001825 .setDuration(300)
Steve Elliottff2c0d92019-07-30 15:09:54 -04001826 .withEndAction(this::completeDismiss)
Jason Monk16fbd9d2017-04-27 14:28:49 -04001827 .setInterpolator(new LogAccelerateInterpolator())
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001828 .setUpdateListener(animation -> {
Lucas Dupin991415e2019-11-25 17:48:58 -08001829 float animatedValue = 1f - animation.getAnimatedFraction();
1830 int alpha = (int) (animatedValue * mScrimAlpha * 255);
Steve Elliott9b87a442019-03-05 10:24:16 -05001831 mBackgroundDrawable.setAlpha(alpha);
Santiago Etchebehere68eb53e2020-02-25 14:25:34 -08001832 mDepthController.updateGlobalDialogVisibility(animatedValue,
1833 mGlobalActionsLayout);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001834 })
Jason Monk16fbd9d2017-04-27 14:28:49 -04001835 .start();
Steve Elliott48f75db2019-05-03 15:03:38 -04001836 dismissPanel();
1837 resetOrientation();
Jason Monk16fbd9d2017-04-27 14:28:49 -04001838 }
1839
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001840 void dismissImmediately() {
Beverly526d2d62018-08-15 12:55:33 -04001841 mShowing = false;
Matt Pietal019feaa2020-01-31 14:51:37 -05001842 if (mControlsUiController != null) mControlsUiController.hide();
Steve Elliott48f75db2019-05-03 15:03:38 -04001843 dismissPanel();
1844 resetOrientation();
Steve Elliottff2c0d92019-07-30 15:09:54 -04001845 completeDismiss();
1846 }
1847
1848 private void completeDismiss() {
wilsonshihe8321942019-10-18 18:39:46 +08001849 mNotificationShadeWindowController.setForceHasTopUi(mHadTopUi);
Steve Elliottff2c0d92019-07-30 15:09:54 -04001850 super.dismiss();
Steve Elliott48f75db2019-05-03 15:03:38 -04001851 }
1852
1853 private void dismissPanel() {
Steve Elliott2d206d32019-03-14 16:30:33 -04001854 if (mPanelController != null) {
1855 mPanelController.onDismissed();
1856 }
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001857 }
1858
Steve Elliott53f12ae2019-05-13 17:14:15 -04001859 private void setRotationSuggestionsEnabled(boolean enabled) {
1860 try {
1861 final int userId = Binder.getCallingUserHandle().getIdentifier();
1862 final int what = enabled
1863 ? StatusBarManager.DISABLE2_NONE
1864 : StatusBarManager.DISABLE2_ROTATE_SUGGESTIONS;
1865 mStatusBarService.disable2ForUser(what, mToken, mContext.getPackageName(), userId);
1866 } catch (RemoteException ex) {
1867 throw ex.rethrowFromSystemServer();
1868 }
1869 }
1870
Steve Elliott48f75db2019-05-03 15:03:38 -04001871 private void resetOrientation() {
1872 if (mResetOrientationData != null) {
1873 RotationPolicy.setRotationLockAtAngle(mContext, mResetOrientationData.locked,
1874 mResetOrientationData.rotation);
1875 }
Steve Elliott53f12ae2019-05-13 17:14:15 -04001876 setRotationSuggestionsEnabled(true);
Steve Elliott48f75db2019-05-03 15:03:38 -04001877 }
1878
Jason Monk361915c2017-03-21 20:33:59 -04001879 @Override
Lucas Dupin7aaa3532017-05-28 08:51:07 -07001880 public void onColorsChanged(ColorExtractor extractor, int which) {
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001881 if (mKeyguardShowing) {
1882 if ((WallpaperManager.FLAG_LOCK & which) != 0) {
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001883 updateColors(extractor.getColors(WallpaperManager.FLAG_LOCK),
1884 true /* animate */);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001885 }
1886 } else {
1887 if ((WallpaperManager.FLAG_SYSTEM & which) != 0) {
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001888 updateColors(extractor.getColors(WallpaperManager.FLAG_SYSTEM),
1889 true /* animate */);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001890 }
1891 }
1892 }
1893
1894 public void setKeyguardShowing(boolean keyguardShowing) {
1895 mKeyguardShowing = keyguardShowing;
1896 }
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001897
Aaron Heuckroth4ef3a542019-04-01 14:17:23 -04001898 public void refreshDialog() {
1899 initializeLayout();
1900 mGlobalActionsLayout.updateList();
1901 }
1902
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001903 public void onRotate(int from, int to) {
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04001904 if (mShowing) {
Aaron Heuckroth4ef3a542019-04-01 14:17:23 -04001905 refreshDialog();
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05001906 }
1907 }
Steve Elliott48f75db2019-05-03 15:03:38 -04001908
1909 private static class ResetOrientationData {
1910 public boolean locked;
1911 public int rotation;
1912 }
Jason Monk361915c2017-03-21 20:33:59 -04001913 }
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001914
1915 /**
Aran Ink93dd25c2019-05-09 14:42:14 -04001916 * Determines whether or not debug mode has been activated for the Global Actions Panel.
1917 */
1918 private static boolean isPanelDebugModeEnabled(Context context) {
1919 return Settings.Secure.getInt(context.getContentResolver(),
1920 Settings.Secure.GLOBAL_ACTIONS_PANEL_DEBUG_ENABLED, 0) == 1;
1921 }
1922
1923 /**
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001924 * Determines whether or not the Global Actions menu should be forced to
1925 * use the newer grid-style layout.
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001926 */
Aaron Heuckrothc7926612019-04-02 14:21:57 -04001927 private static boolean isForceGridEnabled(Context context) {
Aran Ink93dd25c2019-05-09 14:42:14 -04001928 return isPanelDebugModeEnabled(context);
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05001929 }
Aaron Heuckrothf19d2722019-03-11 17:06:02 -04001930
Matt Pietale0661b62020-01-29 14:35:31 -05001931 private boolean shouldShowControls() {
Fabian Kozynskif6063ae2020-02-24 16:14:35 -05001932 return mKeyguardStateController.isUnlocked()
Fabian Kozynski0424ab12020-02-21 12:09:17 -05001933 && mControlsUiController.getAvailable()
1934 && mAnyControlsProviders;
Matt Pietalfd3b6cb2020-01-08 09:43:54 -05001935 }
Jason Monk361915c2017-03-21 20:33:59 -04001936}