blob: c891bf6cb53ca62f3a9fdc4c0cd4ef319c65d5dd [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 Roos284b32d2020-05-08 14:26:13 +020018import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Adrian Roos2f05bb32018-02-19 16:42:27 +010019import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
Miranda Kephart7b2c3132020-03-27 09:54:14 -040020import static android.view.WindowManager.ScreenshotSource.SCREENSHOT_GLOBAL_ACTIONS;
21import static android.view.WindowManager.TAKE_SCREENSHOT_FULLSCREEN;
Adrian Roos2f05bb32018-02-19 16:42:27 +010022
Chad Brubakerf4075fe2018-01-03 13:23:22 -080023import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_USER_REQUEST;
24import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_NOT_REQUIRED;
Matt Pietal50b661a2020-06-17 11:01:54 -040025import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_BOOT;
Chad Brubaker4f28f0d2017-09-07 14:28:13 -070026import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN;
Winson Chung94674542020-05-15 10:35:55 -070027import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_GLOBAL_ACTIONS_SHOWING;
Chad Brubaker4f28f0d2017-09-07 14:28:13 -070028
Matt Pietale9440b72020-05-01 11:36:01 -040029import android.animation.Animator;
30import android.animation.AnimatorListenerAdapter;
31import android.animation.AnimatorSet;
32import android.animation.ObjectAnimator;
Dave Mankoffc88a2d72020-01-10 15:59:31 -050033import android.annotation.Nullable;
Jason Monk361915c2017-03-21 20:33:59 -040034import android.app.ActivityManager;
35import android.app.Dialog;
Dave Mankoffc88a2d72020-01-10 15:59:31 -050036import android.app.IActivityManager;
Steve Elliott4c868852019-03-14 16:25:41 -040037import android.app.PendingIntent;
Steve Elliott53f12ae2019-05-13 17:14:15 -040038import android.app.StatusBarManager;
Lucas Dupinc1cc7592017-05-22 15:56:16 -070039import android.app.WallpaperManager;
Alex Chau04458852017-11-27 18:21:23 +000040import android.app.admin.DevicePolicyManager;
Pavel Grafov059021b2018-05-02 13:44:46 +010041import android.app.trust.TrustManager;
Jason Monk361915c2017-03-21 20:33:59 -040042import android.content.BroadcastReceiver;
Matt Pietal61266442020-03-17 12:53:44 -040043import android.content.ComponentName;
Dave Mankoffc88a2d72020-01-10 15:59:31 -050044import android.content.ContentResolver;
Jason Monk361915c2017-03-21 20:33:59 -040045import android.content.Context;
46import android.content.DialogInterface;
47import android.content.Intent;
48import android.content.IntentFilter;
Matt Pietal61266442020-03-17 12:53:44 -040049import android.content.SharedPreferences;
Jason Monk361915c2017-03-21 20:33:59 -040050import android.content.pm.UserInfo;
Lucas Dupincb6726f2020-04-07 19:32:38 -070051import android.content.res.ColorStateList;
Dave Mankoffc88a2d72020-01-10 15:59:31 -050052import android.content.res.Resources;
Jason Monk361915c2017-03-21 20:33:59 -040053import android.database.ContentObserver;
Matt Pietale0661b62020-01-29 14:35:31 -050054import android.graphics.Color;
Jason Monk361915c2017-03-21 20:33:59 -040055import android.graphics.drawable.Drawable;
56import android.media.AudioManager;
57import android.net.ConnectivityManager;
Steve Elliott53f12ae2019-05-13 17:14:15 -040058import android.os.Binder;
Jason Monk361915c2017-03-21 20:33:59 -040059import android.os.Handler;
Steve Elliott53f12ae2019-05-13 17:14:15 -040060import android.os.IBinder;
Jason Monk361915c2017-03-21 20:33:59 -040061import android.os.Message;
62import android.os.RemoteException;
Jason Monk361915c2017-03-21 20:33:59 -040063import android.os.SystemProperties;
64import android.os.UserHandle;
65import android.os.UserManager;
66import android.os.Vibrator;
67import android.provider.Settings;
Jason Monk361915c2017-03-21 20:33:59 -040068import android.service.dreams.IDreamManager;
Inseob Kim5e82f732019-11-08 15:08:38 +090069import android.sysprop.TelephonyProperties;
Fan Zhangf9914762019-11-01 15:58:38 -070070import android.telecom.TelecomManager;
Jason Monk361915c2017-03-21 20:33:59 -040071import android.telephony.PhoneStateListener;
72import android.telephony.ServiceState;
73import android.telephony.TelephonyManager;
Sean Pontfd537a52020-05-14 10:04:24 -070074import android.transition.AutoTransition;
75import android.transition.TransitionManager;
76import android.transition.TransitionSet;
Jason Monk361915c2017-03-21 20:33:59 -040077import android.util.ArraySet;
yuanjiahsu88363e92018-09-06 19:23:52 +080078import android.util.FeatureFlagUtils;
Jason Monk361915c2017-03-21 20:33:59 -040079import android.util.Log;
Lucas Dupin448786c2017-07-24 17:44:25 -070080import android.view.ContextThemeWrapper;
Dave Mankoff8df818e2020-02-12 14:22:26 -050081import android.view.IWindowManager;
Jason Monk361915c2017-03-21 20:33:59 -040082import android.view.LayoutInflater;
83import android.view.View;
84import android.view.ViewGroup;
Lucas Dupinc1cc7592017-05-22 15:56:16 -070085import android.view.Window;
Lucas Dupin26571e92020-04-08 14:55:10 -070086import android.view.WindowInsets;
Jason Monk361915c2017-03-21 20:33:59 -040087import android.view.WindowManager;
Jason Monk361915c2017-03-21 20:33:59 -040088import android.view.accessibility.AccessibilityEvent;
Aran Inkcf038272020-03-31 17:48:37 -040089import android.widget.BaseAdapter;
Steve Elliott9b87a442019-03-05 10:24:16 -050090import android.widget.FrameLayout;
Jason Monk361915c2017-03-21 20:33:59 -040091import android.widget.ImageView;
92import android.widget.ImageView.ScaleType;
Aran Ink7c8fea92020-04-17 14:40:14 -040093import android.widget.LinearLayout;
Aran Inkcf038272020-03-31 17:48:37 -040094import android.widget.ListPopupWindow;
Jason Monk361915c2017-03-21 20:33:59 -040095import android.widget.TextView;
96
Fabian Kozynskib6a20372020-04-01 09:36:43 -040097import androidx.annotation.NonNull;
98import androidx.lifecycle.Lifecycle;
99import androidx.lifecycle.LifecycleOwner;
100import androidx.lifecycle.LifecycleRegistry;
101
Charles He9851a8d2017-10-10 17:31:30 +0100102import com.android.internal.R;
Chris Wren65a70c92020-04-02 10:43:46 -0400103import com.android.internal.annotations.VisibleForTesting;
Charles He9851a8d2017-10-10 17:31:30 +0100104import com.android.internal.colorextraction.ColorExtractor;
105import com.android.internal.colorextraction.ColorExtractor.GradientColors;
Lucas Dupin2bd3af62019-03-25 17:44:28 -0700106import com.android.internal.colorextraction.drawable.ScrimDrawable;
Charles He9851a8d2017-10-10 17:31:30 +0100107import com.android.internal.logging.MetricsLogger;
Chris Wren65a70c92020-04-02 10:43:46 -0400108import com.android.internal.logging.UiEvent;
109import com.android.internal.logging.UiEventLogger;
Charles He9851a8d2017-10-10 17:31:30 +0100110import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Steve Elliott53f12ae2019-05-13 17:14:15 -0400111import com.android.internal.statusbar.IStatusBarService;
Charles He9851a8d2017-10-10 17:31:30 +0100112import com.android.internal.util.EmergencyAffordanceManager;
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400113import com.android.internal.util.ScreenRecordHelper;
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500114import com.android.internal.util.ScreenshotHelper;
Steve Elliott48f75db2019-05-03 15:03:38 -0400115import com.android.internal.view.RotationPolicy;
Charles He9851a8d2017-10-10 17:31:30 +0100116import com.android.internal.widget.LockPatternUtils;
Charles He9851a8d2017-10-10 17:31:30 +0100117import com.android.systemui.Interpolators;
Aaron Heuckrothf708d472019-01-10 16:54:51 -0500118import com.android.systemui.MultiListLayout;
Aaron Heuckroth57d60d22019-03-05 14:00:12 -0500119import com.android.systemui.MultiListLayout.MultiListAdapter;
Fabian Kozynskiff5e91f2019-09-24 15:38:08 -0400120import com.android.systemui.broadcast.BroadcastDispatcher;
Charles He9851a8d2017-10-10 17:31:30 +0100121import com.android.systemui.colorextraction.SysuiColorExtractor;
Matt Pietal61266442020-03-17 12:53:44 -0400122import com.android.systemui.controls.ControlsServiceInfo;
123import com.android.systemui.controls.controller.ControlsController;
Fabian Kozynski137951c2020-05-26 15:13:52 -0400124import com.android.systemui.controls.dagger.ControlsComponent;
Matt Pietalf4b870b2020-04-17 17:11:36 -0400125import com.android.systemui.controls.management.ControlsAnimations;
Matt Pietal22231792020-01-23 09:51:09 -0500126import com.android.systemui.controls.ui.ControlsUiController;
Dave Mankoff8df818e2020-02-12 14:22:26 -0500127import com.android.systemui.dagger.qualifiers.Background;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500128import com.android.systemui.dagger.qualifiers.Main;
Winson Chung94674542020-05-15 10:35:55 -0700129import com.android.systemui.model.SysUiState;
Steve Elliott4c868852019-03-14 16:25:41 -0400130import com.android.systemui.plugins.ActivityStarter;
Charles He9851a8d2017-10-10 17:31:30 +0100131import com.android.systemui.plugins.GlobalActions.GlobalActionsManager;
Steve Elliott9b87a442019-03-05 10:24:16 -0500132import com.android.systemui.plugins.GlobalActionsPanelPlugin;
Matt Pietal96c36952020-05-26 11:14:37 -0400133import com.android.systemui.settings.CurrentUserContextTracker;
Santiago Etchebehere68eb53e2020-02-25 14:25:34 -0800134import com.android.systemui.statusbar.NotificationShadeDepthController;
Matt Pietal22231792020-01-23 09:51:09 -0500135import com.android.systemui.statusbar.phone.NotificationShadeWindowController;
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700136import com.android.systemui.statusbar.policy.ConfigurationController;
Lucas Dupinc8f16e82019-09-17 18:24:50 -0400137import com.android.systemui.statusbar.policy.KeyguardStateController;
Shaotang Li5c422632018-07-04 14:18:40 +0800138import com.android.systemui.util.EmergencyDialerConstants;
Fabian Kozynskib6a20372020-04-01 09:36:43 -0400139import com.android.systemui.util.RingerModeTracker;
Aaron Heuckroth75e249f2019-02-01 15:59:57 -0500140import com.android.systemui.util.leak.RotationUtils;
Lucas Dupinc1cc7592017-05-22 15:56:16 -0700141
Jason Monk361915c2017-03-21 20:33:59 -0400142import java.util.ArrayList;
Matt Pietal5459e772020-05-28 17:18:26 -0400143import java.util.Collections;
144import java.util.HashSet;
Jason Monk361915c2017-03-21 20:33:59 -0400145import java.util.List;
Fabian Kozynski137951c2020-05-26 15:13:52 -0400146import java.util.Optional;
Matt Pietal5459e772020-05-28 17:18:26 -0400147import java.util.Set;
Dave Mankoff8df818e2020-02-12 14:22:26 -0500148import java.util.concurrent.Executor;
Jason Monk361915c2017-03-21 20:33:59 -0400149
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500150import javax.inject.Inject;
151
Jason Monk361915c2017-03-21 20:33:59 -0400152/**
Sean Pont9d4fb032020-03-04 18:54:32 -0800153 * Helper to show the global actions dialog. Each item is an {@link Action} that may show depending
154 * on whether the keyguard is showing, and whether the device is provisioned.
Jason Monk361915c2017-03-21 20:33:59 -0400155 */
Aaron Heuckroth57d60d22019-03-05 14:00:12 -0500156public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
Sean Pont9d4fb032020-03-04 18:54:32 -0800157 DialogInterface.OnShowListener,
158 ConfigurationController.ConfigurationListener,
Fabian Kozynskib6a20372020-04-01 09:36:43 -0400159 GlobalActionsPanelPlugin.Callbacks,
160 LifecycleOwner {
Jason Monk361915c2017-03-21 20:33:59 -0400161
Sean Pont9d4fb032020-03-04 18:54:32 -0800162 public static final String SYSTEM_DIALOG_REASON_KEY = "reason";
163 public static final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
164 public static final String SYSTEM_DIALOG_REASON_DREAM = "dream";
Jason Monk361915c2017-03-21 20:33:59 -0400165
166 private static final String TAG = "GlobalActionsDialog";
167
168 private static final boolean SHOW_SILENT_TOGGLE = true;
169
170 /* Valid settings for global actions keys.
171 * see config.xml config_globalActionList */
Aran Inkcf038272020-03-31 17:48:37 -0400172 @VisibleForTesting
Sean Pontd7ff85a2020-05-18 21:47:08 -0700173 static final String GLOBAL_ACTION_KEY_POWER = "power";
174 private static final String GLOBAL_ACTION_KEY_AIRPLANE = "airplane";
175 private static final String GLOBAL_ACTION_KEY_BUGREPORT = "bugreport";
176 private static final String GLOBAL_ACTION_KEY_SILENT = "silent";
177 private static final String GLOBAL_ACTION_KEY_USERS = "users";
178 private static final String GLOBAL_ACTION_KEY_SETTINGS = "settings";
Aran Inkc58028b2020-06-04 15:33:22 -0400179 static final String GLOBAL_ACTION_KEY_LOCKDOWN = "lockdown";
Sean Pontd7ff85a2020-05-18 21:47:08 -0700180 private static final String GLOBAL_ACTION_KEY_VOICEASSIST = "voiceassist";
181 private static final String GLOBAL_ACTION_KEY_ASSIST = "assist";
182 static final String GLOBAL_ACTION_KEY_RESTART = "restart";
183 private static final String GLOBAL_ACTION_KEY_LOGOUT = "logout";
184 static final String GLOBAL_ACTION_KEY_EMERGENCY = "emergency";
185 static final String GLOBAL_ACTION_KEY_SCREENSHOT = "screenshot";
Jason Monk361915c2017-03-21 20:33:59 -0400186
Matt Pietal1b1f59b2020-06-02 15:58:20 -0400187 public static final String PREFS_CONTROLS_SEEDING_COMPLETED = "SeedingCompleted";
188 public static final String PREFS_CONTROLS_FILE = "controls_prefs";
Matt Pietal5459e772020-05-28 17:18:26 -0400189 private static final int SEEDING_MAX = 2;
Matt Pietal61266442020-03-17 12:53:44 -0400190
Jason Monk361915c2017-03-21 20:33:59 -0400191 private final Context mContext;
192 private final GlobalActionsManager mWindowManagerFuncs;
193 private final AudioManager mAudioManager;
194 private final IDreamManager mDreamManager;
Alex Chau04458852017-11-27 18:21:23 +0000195 private final DevicePolicyManager mDevicePolicyManager;
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800196 private final LockPatternUtils mLockPatternUtils;
Fabian Kozynskif6063ae2020-02-24 16:14:35 -0500197 private final KeyguardStateController mKeyguardStateController;
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000198 private final BroadcastDispatcher mBroadcastDispatcher;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500199 private final ContentResolver mContentResolver;
200 private final Resources mResources;
Dave Mankoff8df818e2020-02-12 14:22:26 -0500201 private final ConfigurationController mConfigurationController;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500202 private final UserManager mUserManager;
203 private final TrustManager mTrustManager;
204 private final IActivityManager mIActivityManager;
205 private final TelecomManager mTelecomManager;
206 private final MetricsLogger mMetricsLogger;
Chris Wren65a70c92020-04-02 10:43:46 -0400207 private final UiEventLogger mUiEventLogger;
Santiago Etchebehere68eb53e2020-02-25 14:25:34 -0800208 private final NotificationShadeDepthController mDepthController;
Winson Chung94674542020-05-15 10:35:55 -0700209 private final SysUiState mSysUiState;
Jason Monk361915c2017-03-21 20:33:59 -0400210
Fabian Kozynskib6a20372020-04-01 09:36:43 -0400211 // Used for RingerModeTracker
212 private final LifecycleRegistry mLifecycle = new LifecycleRegistry(this);
213
Aran Inkcf038272020-03-31 17:48:37 -0400214 @VisibleForTesting
Aran Inka65e68362020-04-14 15:23:24 -0400215 protected final ArrayList<Action> mItems = new ArrayList<>();
Aran Inkcf038272020-03-31 17:48:37 -0400216 @VisibleForTesting
Aran Inkc58028b2020-06-04 15:33:22 -0400217 protected final ArrayList<Action> mOverflowItems = new ArrayList<>();
218 @VisibleForTesting
219 protected final ArrayList<Action> mPowerItems = new ArrayList<>();
Aran Inkcf038272020-03-31 17:48:37 -0400220
Chris Wren9756a002020-05-12 16:46:27 -0400221 @VisibleForTesting
222 protected ActionsDialog mDialog;
Jason Monk361915c2017-03-21 20:33:59 -0400223
224 private Action mSilentModeAction;
225 private ToggleAction mAirplaneModeOn;
226
227 private MyAdapter mAdapter;
Aran Inkcf038272020-03-31 17:48:37 -0400228 private MyOverflowAdapter mOverflowAdapter;
Aran Inkc58028b2020-06-04 15:33:22 -0400229 private MyPowerOptionsAdapter mPowerAdapter;
Jason Monk361915c2017-03-21 20:33:59 -0400230
231 private boolean mKeyguardShowing = false;
232 private boolean mDeviceProvisioned = false;
Lucas Dupincb6726f2020-04-07 19:32:38 -0700233 private ToggleState mAirplaneState = ToggleState.Off;
Jason Monk361915c2017-03-21 20:33:59 -0400234 private boolean mIsWaitingForEcmExit = false;
235 private boolean mHasTelephony;
236 private boolean mHasVibrator;
237 private final boolean mShowSilentToggle;
238 private final EmergencyAffordanceManager mEmergencyAffordanceManager;
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500239 private final ScreenshotHelper mScreenshotHelper;
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400240 private final ScreenRecordHelper mScreenRecordHelper;
Steve Elliotta3f5207922019-03-18 13:37:22 -0400241 private final ActivityStarter mActivityStarter;
Lucas Dupin991415e2019-11-25 17:48:58 -0800242 private final SysuiColorExtractor mSysuiColorExtractor;
243 private final IStatusBarService mStatusBarService;
244 private final NotificationShadeWindowController mNotificationShadeWindowController;
Sean Pontd7ff85a2020-05-18 21:47:08 -0700245 private GlobalActionsPanelPlugin mWalletPlugin;
Fabian Kozynski137951c2020-05-26 15:13:52 -0400246 private Optional<ControlsUiController> mControlsUiControllerOptional;
Dave Mankoff8df818e2020-02-12 14:22:26 -0500247 private final IWindowManager mIWindowManager;
248 private final Executor mBackgroundExecutor;
Matt Pietalcd757c82020-04-08 10:20:48 -0400249 private List<ControlsServiceInfo> mControlsServiceInfos = new ArrayList<>();
Fabian Kozynski137951c2020-05-26 15:13:52 -0400250 private Optional<ControlsController> mControlsControllerOptional;
Fabian Kozynskib6a20372020-04-01 09:36:43 -0400251 private final RingerModeTracker mRingerModeTracker;
Chris Wrenaf4ce8462020-04-06 17:36:10 -0400252 private int mDialogPressDelay = DIALOG_PRESS_DELAY; // ms
Matt Pietal677981d2020-04-24 14:38:32 -0400253 private Handler mMainHandler;
Matt Pietal96c36952020-05-26 11:14:37 -0400254 private CurrentUserContextTracker mCurrentUserContextTracker;
Sean Pontd7ff85a2020-05-18 21:47:08 -0700255 @VisibleForTesting
256 boolean mShowLockScreenCardsAndControls = false;
Steve Elliott9b87a442019-03-05 10:24:16 -0500257
Chris Wren65a70c92020-04-02 10:43:46 -0400258 @VisibleForTesting
259 public enum GlobalActionsEvent implements UiEventLogger.UiEventEnum {
260 @UiEvent(doc = "The global actions / power menu surface became visible on the screen.")
Chris Wrenaf4ce8462020-04-06 17:36:10 -0400261 GA_POWER_MENU_OPEN(337),
262
Chris Wren9756a002020-05-12 16:46:27 -0400263 @UiEvent(doc = "The global actions / power menu surface was dismissed.")
264 GA_POWER_MENU_CLOSE(471),
265
Chris Wrenaf4ce8462020-04-06 17:36:10 -0400266 @UiEvent(doc = "The global actions bugreport button was pressed.")
267 GA_BUGREPORT_PRESS(344),
268
269 @UiEvent(doc = "The global actions bugreport button was long pressed.")
270 GA_BUGREPORT_LONG_PRESS(345),
271
272 @UiEvent(doc = "The global actions emergency button was pressed.")
273 GA_EMERGENCY_DIALER_PRESS(346),
274
275 @UiEvent(doc = "The global actions screenshot button was pressed.")
276 GA_SCREENSHOT_PRESS(347),
277
278 @UiEvent(doc = "The global actions screenshot button was long pressed.")
279 GA_SCREENSHOT_LONG_PRESS(348);
Chris Wren65a70c92020-04-02 10:43:46 -0400280
281 private final int mId;
282
283 GlobalActionsEvent(int id) {
284 mId = id;
285 }
286
287 @Override
288 public int getId() {
289 return mId;
290 }
291 }
292
Jason Monk361915c2017-03-21 20:33:59 -0400293 /**
294 * @param context everything needs a context :(
295 */
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500296 @Inject
297 public GlobalActionsDialog(Context context, GlobalActionsManager windowManagerFuncs,
298 AudioManager audioManager, IDreamManager iDreamManager,
299 DevicePolicyManager devicePolicyManager, LockPatternUtils lockPatternUtils,
Fabian Kozynskif6063ae2020-02-24 16:14:35 -0500300 BroadcastDispatcher broadcastDispatcher,
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500301 ConnectivityManager connectivityManager, TelephonyManager telephonyManager,
302 ContentResolver contentResolver, @Nullable Vibrator vibrator, @Main Resources resources,
303 ConfigurationController configurationController, ActivityStarter activityStarter,
304 KeyguardStateController keyguardStateController, UserManager userManager,
305 TrustManager trustManager, IActivityManager iActivityManager,
Dave Mankoff3c6aaab2020-01-10 17:50:34 -0500306 @Nullable TelecomManager telecomManager, MetricsLogger metricsLogger,
Santiago Etchebehere68eb53e2020-02-25 14:25:34 -0800307 NotificationShadeDepthController depthController, SysuiColorExtractor colorExtractor,
Sean Pontd7ff85a2020-05-18 21:47:08 -0700308 IStatusBarService statusBarService,
Matt Pietal22231792020-01-23 09:51:09 -0500309 NotificationShadeWindowController notificationShadeWindowController,
Fabian Kozynski137951c2020-05-26 15:13:52 -0400310 IWindowManager iWindowManager,
Fabian Kozynski0424ab12020-02-21 12:09:17 -0500311 @Background Executor backgroundExecutor,
Fabian Kozynski137951c2020-05-26 15:13:52 -0400312 UiEventLogger uiEventLogger,
Matt Pietal96c36952020-05-26 11:14:37 -0400313 RingerModeTracker ringerModeTracker, SysUiState sysUiState, @Main Handler handler,
Fabian Kozynski137951c2020-05-26 15:13:52 -0400314 ControlsComponent controlsComponent,
Matt Pietal96c36952020-05-26 11:14:37 -0400315 CurrentUserContextTracker currentUserContextTracker) {
Fabian Kozynski395aec92020-05-27 17:03:37 -0400316 mContext = context;
Jason Monk361915c2017-03-21 20:33:59 -0400317 mWindowManagerFuncs = windowManagerFuncs;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500318 mAudioManager = audioManager;
319 mDreamManager = iDreamManager;
320 mDevicePolicyManager = devicePolicyManager;
321 mLockPatternUtils = lockPatternUtils;
Fabian Kozynskif6063ae2020-02-24 16:14:35 -0500322 mKeyguardStateController = keyguardStateController;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500323 mBroadcastDispatcher = broadcastDispatcher;
324 mContentResolver = contentResolver;
325 mResources = resources;
Dave Mankoff8df818e2020-02-12 14:22:26 -0500326 mConfigurationController = configurationController;
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500327 mUserManager = userManager;
328 mTrustManager = trustManager;
329 mIActivityManager = iActivityManager;
330 mTelecomManager = telecomManager;
331 mMetricsLogger = metricsLogger;
Chris Wren65a70c92020-04-02 10:43:46 -0400332 mUiEventLogger = uiEventLogger;
Santiago Etchebehere68eb53e2020-02-25 14:25:34 -0800333 mDepthController = depthController;
Lucas Dupin991415e2019-11-25 17:48:58 -0800334 mSysuiColorExtractor = colorExtractor;
335 mStatusBarService = statusBarService;
336 mNotificationShadeWindowController = notificationShadeWindowController;
Fabian Kozynski137951c2020-05-26 15:13:52 -0400337 mControlsUiControllerOptional = controlsComponent.getControlsUiController();
Dave Mankoff8df818e2020-02-12 14:22:26 -0500338 mIWindowManager = iWindowManager;
339 mBackgroundExecutor = backgroundExecutor;
Fabian Kozynskib6a20372020-04-01 09:36:43 -0400340 mRingerModeTracker = ringerModeTracker;
Fabian Kozynski137951c2020-05-26 15:13:52 -0400341 mControlsControllerOptional = controlsComponent.getControlsController();
Winson Chung94674542020-05-15 10:35:55 -0700342 mSysUiState = sysUiState;
Matt Pietal677981d2020-04-24 14:38:32 -0400343 mMainHandler = handler;
Matt Pietal96c36952020-05-26 11:14:37 -0400344 mCurrentUserContextTracker = currentUserContextTracker;
Jason Monk361915c2017-03-21 20:33:59 -0400345
346 // receive broadcasts
347 IntentFilter filter = new IntentFilter();
348 filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
349 filter.addAction(Intent.ACTION_SCREEN_OFF);
Jayachandran C142eae02019-12-13 19:29:20 -0800350 filter.addAction(TelephonyManager.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000351 mBroadcastDispatcher.registerReceiver(mBroadcastReceiver, filter);
Jason Monk361915c2017-03-21 20:33:59 -0400352
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500353 mHasTelephony = connectivityManager.isNetworkSupported(ConnectivityManager.TYPE_MOBILE);
Jason Monk361915c2017-03-21 20:33:59 -0400354
355 // get notified of phone state changes
Jason Monk361915c2017-03-21 20:33:59 -0400356 telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE);
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500357 contentResolver.registerContentObserver(
Jason Monk361915c2017-03-21 20:33:59 -0400358 Settings.Global.getUriFor(Settings.Global.AIRPLANE_MODE_ON), true,
359 mAirplaneModeObserver);
Jason Monk361915c2017-03-21 20:33:59 -0400360 mHasVibrator = vibrator != null && vibrator.hasVibrator();
361
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500362 mShowSilentToggle = SHOW_SILENT_TOGGLE && !resources.getBoolean(
Jason Monk361915c2017-03-21 20:33:59 -0400363 R.bool.config_useFixedVolume);
Fabian Kozynskib6a20372020-04-01 09:36:43 -0400364 if (mShowSilentToggle) {
365 mRingerModeTracker.getRingerMode().observe(this, ringer ->
366 mHandler.sendEmptyMessage(MESSAGE_REFRESH)
367 );
368 }
Jason Monk361915c2017-03-21 20:33:59 -0400369
370 mEmergencyAffordanceManager = new EmergencyAffordanceManager(context);
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500371 mScreenshotHelper = new ScreenshotHelper(context);
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400372 mScreenRecordHelper = new ScreenRecordHelper(context);
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700373
Dave Mankoff8df818e2020-02-12 14:22:26 -0500374 mConfigurationController.addCallback(this);
Steve Elliott9b87a442019-03-05 10:24:16 -0500375
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500376 mActivityStarter = activityStarter;
Lucas Dupinc8f16e82019-09-17 18:24:50 -0400377 keyguardStateController.addCallback(new KeyguardStateController.Callback() {
378 @Override
379 public void onUnlockedChanged() {
Matt Pietal677981d2020-04-24 14:38:32 -0400380 if (mDialog != null) {
Sean Pontd7ff85a2020-05-18 21:47:08 -0700381 boolean unlocked = mKeyguardStateController.isUnlocked();
382 if (mDialog.mWalletViewController != null) {
383 mDialog.mWalletViewController.onDeviceLockStateChanged(!unlocked);
Matt Pietal677981d2020-04-24 14:38:32 -0400384 }
385 if (!mDialog.isShowingControls() && shouldShowControls()) {
Fabian Kozynski137951c2020-05-26 15:13:52 -0400386 mDialog.showControls(mControlsUiControllerOptional.get());
Matt Pietal677981d2020-04-24 14:38:32 -0400387 }
Sean Pontd7ff85a2020-05-18 21:47:08 -0700388 if (unlocked) {
389 mDialog.hideLockMessage();
390 }
Lucas Dupinc8f16e82019-09-17 18:24:50 -0400391 }
392 }
393 });
Fabian Kozynski0424ab12020-02-21 12:09:17 -0500394
Fabian Kozynski137951c2020-05-26 15:13:52 -0400395 if (controlsComponent.getControlsListingController().isPresent()) {
396 controlsComponent.getControlsListingController().get()
Matt Pietala33e0752020-06-02 16:27:38 -0400397 .addCallback(list -> {
398 mControlsServiceInfos = list;
Matt Pietal50b661a2020-06-17 11:01:54 -0400399 // This callback may occur after the dialog has been shown. If so, add
400 // controls into the already visible space or show the lock msg if needed.
401 if (mDialog != null) {
402 if (!mDialog.isShowingControls() && shouldShowControls()) {
403 mDialog.showControls(mControlsUiControllerOptional.get());
404 } else if (shouldShowLockMessage()) {
405 mDialog.showLockMessage();
406 }
Matt Pietala33e0752020-06-02 16:27:38 -0400407 }
408 });
Fabian Kozynski137951c2020-05-26 15:13:52 -0400409 }
410
Matt Pietal677981d2020-04-24 14:38:32 -0400411 // Listen for changes to show controls on the power menu while locked
412 onPowerMenuLockScreenSettingsChanged();
413 mContext.getContentResolver().registerContentObserver(
414 Settings.Secure.getUriFor(Settings.Secure.POWER_MENU_LOCKED_SHOW_CONTENT),
415 false /* notifyForDescendants */,
416 new ContentObserver(mMainHandler) {
417 @Override
418 public void onChange(boolean selfChange) {
419 onPowerMenuLockScreenSettingsChanged();
420 }
421 });
Jason Monk361915c2017-03-21 20:33:59 -0400422 }
423
Matt Pietal5459e772020-05-28 17:18:26 -0400424 /**
425 * See if any available control service providers match one of the preferred components. If
426 * they do, and there are no current favorites for that component, query the preferred
427 * component for a limited number of suggested controls.
428 */
Matt Pietalcd757c82020-04-08 10:20:48 -0400429 private void seedFavorites() {
Matt Pietal5459e772020-05-28 17:18:26 -0400430 if (!mControlsControllerOptional.isPresent()
431 || mControlsServiceInfos.isEmpty()) {
Matt Pietal96c36952020-05-26 11:14:37 -0400432 return;
433 }
434
Matt Pietal5459e772020-05-28 17:18:26 -0400435 String[] preferredControlsPackages = mContext.getResources()
436 .getStringArray(com.android.systemui.R.array.config_controlsPreferredPackages);
437
Matt Pietal96c36952020-05-26 11:14:37 -0400438 SharedPreferences prefs = mCurrentUserContextTracker.getCurrentUserContext()
439 .getSharedPreferences(PREFS_CONTROLS_FILE, Context.MODE_PRIVATE);
Matt Pietal5459e772020-05-28 17:18:26 -0400440 Set<String> seededPackages = prefs.getStringSet(PREFS_CONTROLS_SEEDING_COMPLETED,
441 Collections.emptySet());
Matt Pietal61266442020-03-17 12:53:44 -0400442
Matt Pietal5459e772020-05-28 17:18:26 -0400443 List<ComponentName> componentsToSeed = new ArrayList<>();
Matt Pietal9da55a72020-06-10 15:36:54 -0400444 for (int i = 0; i < Math.min(SEEDING_MAX, preferredControlsPackages.length); i++) {
445 String pkg = preferredControlsPackages[i];
446 for (ControlsServiceInfo info : mControlsServiceInfos) {
447 if (!pkg.equals(info.componentName.getPackageName())) continue;
448 if (seededPackages.contains(pkg)) {
449 break;
450 } else if (mControlsControllerOptional.get()
451 .countFavoritesForComponent(info.componentName) > 0) {
452 // When there are existing controls but no saved preference, assume it
453 // is out of sync, perhaps through a device restore, and update the
454 // preference
455 addPackageToSeededSet(prefs, pkg);
Matt Pietal5459e772020-05-28 17:18:26 -0400456 break;
457 }
Matt Pietal9da55a72020-06-10 15:36:54 -0400458 componentsToSeed.add(info.componentName);
459 break;
Matt Pietalcd757c82020-04-08 10:20:48 -0400460 }
461 }
462
Matt Pietal5459e772020-05-28 17:18:26 -0400463 if (componentsToSeed.isEmpty()) return;
Matt Pietalcd757c82020-04-08 10:20:48 -0400464
Matt Pietal5459e772020-05-28 17:18:26 -0400465 mControlsControllerOptional.get().seedFavoritesForComponents(
466 componentsToSeed,
467 (response) -> {
468 Log.d(TAG, "Controls seeded: " + response);
Matt Pietal5459e772020-05-28 17:18:26 -0400469 if (response.getAccepted()) {
Matt Pietal9da55a72020-06-10 15:36:54 -0400470 addPackageToSeededSet(prefs, response.getPackageName());
Matt Pietal5459e772020-05-28 17:18:26 -0400471 }
Matt Pietalcd757c82020-04-08 10:20:48 -0400472 });
473 }
Matt Pietal61266442020-03-17 12:53:44 -0400474
Matt Pietal9da55a72020-06-10 15:36:54 -0400475 private void addPackageToSeededSet(SharedPreferences prefs, String pkg) {
476 Set<String> seededPackages = prefs.getStringSet(PREFS_CONTROLS_SEEDING_COMPLETED,
477 Collections.emptySet());
478 Set<String> updatedPkgs = new HashSet<>(seededPackages);
479 updatedPkgs.add(pkg);
480 prefs.edit().putStringSet(PREFS_CONTROLS_SEEDING_COMPLETED, updatedPkgs).apply();
481 }
482
Jason Monk361915c2017-03-21 20:33:59 -0400483 /**
484 * Show the global actions dialog (creating if necessary)
Jason Monk16fbd9d2017-04-27 14:28:49 -0400485 *
Jason Monk361915c2017-03-21 20:33:59 -0400486 * @param keyguardShowing True if keyguard is showing
487 */
Matt Pietal6ce0a902020-04-24 10:30:57 -0400488 public void showOrHideDialog(boolean keyguardShowing, boolean isDeviceProvisioned,
Sean Pontd7ff85a2020-05-18 21:47:08 -0700489 GlobalActionsPanelPlugin walletPlugin) {
Jason Monk361915c2017-03-21 20:33:59 -0400490 mKeyguardShowing = keyguardShowing;
491 mDeviceProvisioned = isDeviceProvisioned;
Sean Pontd7ff85a2020-05-18 21:47:08 -0700492 mWalletPlugin = walletPlugin;
Matt Pietal6ce0a902020-04-24 10:30:57 -0400493 if (mDialog != null && mDialog.isShowing()) {
494 // In order to force global actions to hide on the same affordance press, we must
495 // register a call to onGlobalActionsShown() first to prevent the default actions
496 // menu from showing. This will be followed by a subsequent call to
497 // onGlobalActionsHidden() on dismiss()
498 mWindowManagerFuncs.onGlobalActionsShown();
Jason Monk361915c2017-03-21 20:33:59 -0400499 mDialog.dismiss();
500 mDialog = null;
Jason Monk361915c2017-03-21 20:33:59 -0400501 } else {
502 handleShow();
503 }
504 }
505
Charles He9851a8d2017-10-10 17:31:30 +0100506 /**
507 * Dismiss the global actions dialog, if it's currently shown
508 */
509 public void dismissDialog() {
510 mHandler.removeMessages(MESSAGE_DISMISS);
511 mHandler.sendEmptyMessage(MESSAGE_DISMISS);
512 }
513
Jason Monk361915c2017-03-21 20:33:59 -0400514 private void awakenIfNecessary() {
515 if (mDreamManager != null) {
516 try {
517 if (mDreamManager.isDreaming()) {
518 mDreamManager.awaken();
519 }
520 } catch (RemoteException e) {
521 // we tried
522 }
523 }
524 }
525
526 private void handleShow() {
527 awakenIfNecessary();
528 mDialog = createDialog();
529 prepareDialog();
Matt Pietalcd757c82020-04-08 10:20:48 -0400530 seedFavorites();
Jason Monk361915c2017-03-21 20:33:59 -0400531
Aran Inka65e68362020-04-14 15:23:24 -0400532 WindowManager.LayoutParams attrs = mDialog.getWindow().getAttributes();
533 attrs.setTitle("ActionsDialog");
534 attrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
535 mDialog.getWindow().setAttributes(attrs);
Adrian Roos284b32d2020-05-08 14:26:13 +0200536 // Don't acquire soft keyboard focus, to avoid destroying state when capturing bugreports
537 mDialog.getWindow().setFlags(FLAG_ALT_FOCUSABLE_IM, FLAG_ALT_FOCUSABLE_IM);
Aran Inka65e68362020-04-14 15:23:24 -0400538 mDialog.show();
539 mWindowManagerFuncs.onGlobalActionsShown();
Jason Monk361915c2017-03-21 20:33:59 -0400540 }
541
Aran Inkcf038272020-03-31 17:48:37 -0400542 @VisibleForTesting
543 protected boolean shouldShowAction(Action action) {
544 if (mKeyguardShowing && !action.showDuringKeyguard()) {
545 return false;
546 }
547 if (!mDeviceProvisioned && !action.showBeforeProvisioning()) {
548 return false;
549 }
550 return true;
551 }
552
Jason Monk361915c2017-03-21 20:33:59 -0400553 /**
Aran Inkcf038272020-03-31 17:48:37 -0400554 * Returns the maximum number of power menu items to show based on which GlobalActions
555 * layout is being used.
Jason Monk361915c2017-03-21 20:33:59 -0400556 */
Aran Inkcf038272020-03-31 17:48:37 -0400557 @VisibleForTesting
558 protected int getMaxShownPowerItems() {
Sean Pontd7ff85a2020-05-18 21:47:08 -0700559 return mResources.getInteger(com.android.systemui.R.integer.power_menu_max_columns);
Aran Inkcf038272020-03-31 17:48:37 -0400560 }
561
562 /**
563 * Add a power menu action item for to either the main or overflow items lists, depending on
564 * whether controls are enabled and whether the max number of shown items has been reached.
565 */
566 private void addActionItem(Action action) {
Aran Inka65e68362020-04-14 15:23:24 -0400567 if (shouldShowAction(action)) {
Aran Inkcf038272020-03-31 17:48:37 -0400568 if (mItems.size() < getMaxShownPowerItems()) {
569 mItems.add(action);
Aran Inka65e68362020-04-14 15:23:24 -0400570 } else {
Aran Inkcf038272020-03-31 17:48:37 -0400571 mOverflowItems.add(action);
572 }
573 }
574 }
575
576 @VisibleForTesting
577 protected String[] getDefaultActions() {
578 return mResources.getStringArray(R.array.config_globalActionsList);
579 }
580
581 @VisibleForTesting
582 protected void createActionItems() {
Jason Monk361915c2017-03-21 20:33:59 -0400583 // Simple toggle style if there's no vibrator, otherwise use a tri-state
584 if (!mHasVibrator) {
585 mSilentModeAction = new SilentModeToggleAction();
586 } else {
Lucas Dupin40ec6b782018-06-05 19:07:16 -0700587 mSilentModeAction = new SilentModeTriStateAction(mAudioManager, mHandler);
Jason Monk361915c2017-03-21 20:33:59 -0400588 }
Aran Ink780d4502020-02-14 10:39:58 -0500589 mAirplaneModeOn = new AirplaneModeAction();
Jason Monk361915c2017-03-21 20:33:59 -0400590 onAirplaneModeChanged();
591
Aran Inka65e68362020-04-14 15:23:24 -0400592 mItems.clear();
593 mOverflowItems.clear();
Aran Inkc58028b2020-06-04 15:33:22 -0400594 mPowerItems.clear();
Fabian Kozynski395aec92020-05-27 17:03:37 -0400595 String[] defaultActions = getDefaultActions();
Aran Inkc58028b2020-06-04 15:33:22 -0400596
597 ShutDownAction shutdownAction = new ShutDownAction();
598 RestartAction restartAction = new RestartAction();
599 ArraySet<String> addedKeys = new ArraySet<String>();
600
Aran Inkcf038272020-03-31 17:48:37 -0400601 // make sure emergency affordance action is first, if needed
602 if (mEmergencyAffordanceManager.needsEmergencyAffordance()) {
603 addActionItem(new EmergencyAffordanceAction());
Aran Inkc58028b2020-06-04 15:33:22 -0400604 addedKeys.add(GLOBAL_ACTION_KEY_EMERGENCY);
Aran Inkcf038272020-03-31 17:48:37 -0400605 }
Jason Monk361915c2017-03-21 20:33:59 -0400606
Jason Monk361915c2017-03-21 20:33:59 -0400607 for (int i = 0; i < defaultActions.length; i++) {
608 String actionKey = defaultActions[i];
609 if (addedKeys.contains(actionKey)) {
610 // If we already have added this, don't add it again.
611 continue;
612 }
613 if (GLOBAL_ACTION_KEY_POWER.equals(actionKey)) {
Aran Inkc58028b2020-06-04 15:33:22 -0400614 addActionItem(shutdownAction);
Jason Monk361915c2017-03-21 20:33:59 -0400615 } else if (GLOBAL_ACTION_KEY_AIRPLANE.equals(actionKey)) {
Aran Inkcf038272020-03-31 17:48:37 -0400616 addActionItem(mAirplaneModeOn);
Jason Monk361915c2017-03-21 20:33:59 -0400617 } else if (GLOBAL_ACTION_KEY_BUGREPORT.equals(actionKey)) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500618 if (Settings.Global.getInt(mContentResolver,
Jason Monk361915c2017-03-21 20:33:59 -0400619 Settings.Global.BUGREPORT_IN_POWER_MENU, 0) != 0 && isCurrentUserOwner()) {
Aran Inkcf038272020-03-31 17:48:37 -0400620 addActionItem(new BugReportAction());
Jason Monk361915c2017-03-21 20:33:59 -0400621 }
622 } else if (GLOBAL_ACTION_KEY_SILENT.equals(actionKey)) {
623 if (mShowSilentToggle) {
Aran Inkcf038272020-03-31 17:48:37 -0400624 addActionItem(mSilentModeAction);
Jason Monk361915c2017-03-21 20:33:59 -0400625 }
626 } else if (GLOBAL_ACTION_KEY_USERS.equals(actionKey)) {
627 if (SystemProperties.getBoolean("fw.power_user_switcher", false)) {
Aran Inkcf038272020-03-31 17:48:37 -0400628 addUsersToMenu();
Jason Monk361915c2017-03-21 20:33:59 -0400629 }
630 } else if (GLOBAL_ACTION_KEY_SETTINGS.equals(actionKey)) {
Aran Inkcf038272020-03-31 17:48:37 -0400631 addActionItem(getSettingsAction());
Jason Monk361915c2017-03-21 20:33:59 -0400632 } else if (GLOBAL_ACTION_KEY_LOCKDOWN.equals(actionKey)) {
Aran Inkc58028b2020-06-04 15:33:22 -0400633 if (shouldDisplayLockdown(getCurrentUser())) {
Aran Inkcf038272020-03-31 17:48:37 -0400634 addActionItem(getLockdownAction());
Chad Brubaker4f28f0d2017-09-07 14:28:13 -0700635 }
Jason Monk361915c2017-03-21 20:33:59 -0400636 } else if (GLOBAL_ACTION_KEY_VOICEASSIST.equals(actionKey)) {
Aran Inkcf038272020-03-31 17:48:37 -0400637 addActionItem(getVoiceAssistAction());
Jason Monk361915c2017-03-21 20:33:59 -0400638 } else if (GLOBAL_ACTION_KEY_ASSIST.equals(actionKey)) {
Aran Inkcf038272020-03-31 17:48:37 -0400639 addActionItem(getAssistAction());
Jason Monk361915c2017-03-21 20:33:59 -0400640 } else if (GLOBAL_ACTION_KEY_RESTART.equals(actionKey)) {
Aran Inkc58028b2020-06-04 15:33:22 -0400641 addActionItem(restartAction);
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500642 } else if (GLOBAL_ACTION_KEY_SCREENSHOT.equals(actionKey)) {
Aran Inkcf038272020-03-31 17:48:37 -0400643 addActionItem(new ScreenshotAction());
Alex Chau04458852017-11-27 18:21:23 +0000644 } else if (GLOBAL_ACTION_KEY_LOGOUT.equals(actionKey)) {
Alex Chaud7958272017-12-08 11:30:52 +0000645 if (mDevicePolicyManager.isLogoutEnabled()
Alex Chau04458852017-11-27 18:21:23 +0000646 && getCurrentUser().id != UserHandle.USER_SYSTEM) {
Aran Inkcf038272020-03-31 17:48:37 -0400647 addActionItem(new LogoutAction());
Alex Chau04458852017-11-27 18:21:23 +0000648 }
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800649 } else if (GLOBAL_ACTION_KEY_EMERGENCY.equals(actionKey)) {
Aran Inkc58028b2020-06-04 15:33:22 -0400650 addActionItem(new EmergencyDialerAction());
Jason Monk361915c2017-03-21 20:33:59 -0400651 } else {
652 Log.e(TAG, "Invalid global action key " + actionKey);
653 }
654 // Add here so we don't add more than one.
655 addedKeys.add(actionKey);
656 }
Aran Inkc58028b2020-06-04 15:33:22 -0400657
658 // replace power and restart with a single power options action, if needed
659 if (mItems.contains(shutdownAction) && mItems.contains(restartAction)
660 && mOverflowItems.size() > 0) {
661 // transfer shutdown and restart to their own list of power actions
662 mItems.remove(shutdownAction);
663 mItems.remove(restartAction);
664 mPowerItems.add(shutdownAction);
665 mPowerItems.add(restartAction);
666
667 // add the PowerOptionsAction after Emergency, if present
668 int powerIndex = addedKeys.contains(GLOBAL_ACTION_KEY_EMERGENCY) ? 1 : 0;
669 mItems.add(powerIndex, new PowerOptionsAction());
670
671 // transfer the first overflow action to the main set of items
672 Action firstOverflowAction = mOverflowItems.get(0);
673 mOverflowItems.remove(0);
674 mItems.add(firstOverflowAction);
675 }
Aran Inkcf038272020-03-31 17:48:37 -0400676 }
Jason Monk361915c2017-03-21 20:33:59 -0400677
Aran Inka65e68362020-04-14 15:23:24 -0400678 private void onRotate() {
679 // re-allocate actions between main and overflow lists
680 this.createActionItems();
681 }
682
Aran Inkcf038272020-03-31 17:48:37 -0400683 /**
684 * Create the global actions dialog.
685 *
686 * @return A new dialog.
687 */
688 private ActionsDialog createDialog() {
689 createActionItems();
Jason Monk361915c2017-03-21 20:33:59 -0400690
691 mAdapter = new MyAdapter();
Aran Inkcf038272020-03-31 17:48:37 -0400692 mOverflowAdapter = new MyOverflowAdapter();
Aran Inkc58028b2020-06-04 15:33:22 -0400693 mPowerAdapter = new MyPowerOptionsAdapter();
Jason Monk361915c2017-03-21 20:33:59 -0400694
Sean Pontd7ff85a2020-05-18 21:47:08 -0700695 mDepthController.setShowingHomeControls(true);
696 GlobalActionsPanelPlugin.PanelViewController walletViewController =
697 getWalletViewController();
Fabian Kozynski137951c2020-05-26 15:13:52 -0400698 ControlsUiController uiController = null;
699 if (mControlsUiControllerOptional.isPresent() && shouldShowControls()) {
700 uiController = mControlsUiControllerOptional.get();
701 }
Aran Inkcf038272020-03-31 17:48:37 -0400702 ActionsDialog dialog = new ActionsDialog(mContext, mAdapter, mOverflowAdapter,
Sean Pontd7ff85a2020-05-18 21:47:08 -0700703 walletViewController, mDepthController, mSysuiColorExtractor,
Aran Inkcf038272020-03-31 17:48:37 -0400704 mStatusBarService, mNotificationShadeWindowController,
Fabian Kozynski137951c2020-05-26 15:13:52 -0400705 controlsAvailable(), uiController,
Aran Inkc58028b2020-06-04 15:33:22 -0400706 mSysUiState, this::onRotate, mKeyguardShowing, mPowerAdapter);
Matt Pietal50b661a2020-06-17 11:01:54 -0400707
708 if (shouldShowLockMessage()) {
Sean Pontd7ff85a2020-05-18 21:47:08 -0700709 dialog.showLockMessage();
710 }
Jason Monk361915c2017-03-21 20:33:59 -0400711 dialog.setCanceledOnTouchOutside(false); // Handled by the custom class.
Jason Monk361915c2017-03-21 20:33:59 -0400712 dialog.setOnDismissListener(this);
Shaotang Li786da902018-08-02 11:18:00 +0800713 dialog.setOnShowListener(this);
Jason Monk361915c2017-03-21 20:33:59 -0400714
715 return dialog;
716 }
717
Aran Inkc58028b2020-06-04 15:33:22 -0400718 @VisibleForTesting
719 protected boolean shouldDisplayLockdown(UserInfo user) {
720 if (user == null) {
721 return false;
722 }
723
724 int userId = user.id;
725
726 // No lockdown option if it's not turned on in Settings
727 if (Settings.Secure.getIntForUser(mContentResolver,
728 Settings.Secure.LOCKDOWN_IN_POWER_MENU, 0, userId) == 0) {
729 return false;
730 }
731
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800732 // Lockdown is meaningless without a place to go.
Fabian Kozynskif6063ae2020-02-24 16:14:35 -0500733 if (!mKeyguardStateController.isMethodSecure()) {
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800734 return false;
735 }
736
737 // Only show the lockdown button if the device isn't locked down (for whatever reason).
738 int state = mLockPatternUtils.getStrongAuthForUser(userId);
739 return (state == STRONG_AUTH_NOT_REQUIRED
740 || state == SOME_AUTH_REQUIRED_AFTER_USER_REQUEST);
741 }
742
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700743 @Override
744 public void onUiModeChanged() {
745 mContext.getTheme().applyStyle(mContext.getThemeResId(), true);
Lucas Dupina4e12ba2019-04-18 11:56:28 -0700746 if (mDialog != null && mDialog.isShowing()) {
Aaron Heuckroth4ef3a542019-04-01 14:17:23 -0400747 mDialog.refreshDialog();
748 }
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700749 }
750
751 public void destroy() {
Dave Mankoff8df818e2020-02-12 14:22:26 -0500752 mConfigurationController.removeCallback(this);
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700753 }
754
Sean Pont9d4fb032020-03-04 18:54:32 -0800755 @Nullable
Sean Pontd7ff85a2020-05-18 21:47:08 -0700756 private GlobalActionsPanelPlugin.PanelViewController getWalletViewController() {
757 if (mWalletPlugin == null) {
Sean Pont9d4fb032020-03-04 18:54:32 -0800758 return null;
759 }
Sean Pontd7ff85a2020-05-18 21:47:08 -0700760 return mWalletPlugin.onPanelShown(this, !mKeyguardStateController.isUnlocked());
Sean Pont9d4fb032020-03-04 18:54:32 -0800761 }
762
763 /**
764 * Implements {@link GlobalActionsPanelPlugin.Callbacks#dismissGlobalActionsMenu()}, which is
765 * called when the quick access wallet requests dismissal.
766 */
767 @Override
768 public void dismissGlobalActionsMenu() {
769 dismissDialog();
770 }
771
772 /**
773 * Implements {@link GlobalActionsPanelPlugin.Callbacks#dismissGlobalActionsMenu()}, which is
774 * called when the quick access wallet requests that an intent be started (with lock screen
775 * shown first if needed).
776 */
777 @Override
778 public void startPendingIntentDismissingKeyguard(PendingIntent pendingIntent) {
779 mActivityStarter.startPendingIntentDismissingKeyguard(pendingIntent);
780 }
781
Aran Inkc58028b2020-06-04 15:33:22 -0400782 @VisibleForTesting
783 protected final class PowerOptionsAction extends SinglePressAction {
784 private PowerOptionsAction() {
Aran Inkb31fa572020-06-08 14:40:42 -0400785 super(com.android.systemui.R.drawable.ic_settings_power,
786 R.string.global_action_power_options);
Aran Inkc58028b2020-06-04 15:33:22 -0400787 }
788
789 @Override
790 public boolean showDuringKeyguard() {
791 return true;
792 }
793
794 @Override
795 public boolean showBeforeProvisioning() {
796 return true;
797 }
798
799 @Override
800 public void onPress() {
801 if (mDialog != null) {
802 mDialog.showPowerOptionsMenu();
803 }
804 }
805 }
806
807 private final class ShutDownAction extends SinglePressAction implements LongPressAction {
808 private ShutDownAction() {
Jason Monk361915c2017-03-21 20:33:59 -0400809 super(R.drawable.ic_lock_power_off,
Jason Monk16fbd9d2017-04-27 14:28:49 -0400810 R.string.global_action_power_off);
Jason Monk361915c2017-03-21 20:33:59 -0400811 }
812
813 @Override
814 public boolean onLongPress() {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500815 if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) {
Jason Monk361915c2017-03-21 20:33:59 -0400816 mWindowManagerFuncs.reboot(true);
817 return true;
818 }
819 return false;
820 }
821
822 @Override
823 public boolean showDuringKeyguard() {
824 return true;
825 }
826
827 @Override
828 public boolean showBeforeProvisioning() {
829 return true;
830 }
831
832 @Override
833 public void onPress() {
834 // shutdown by making sure radio and power are handled accordingly.
835 mWindowManagerFuncs.shutdown();
836 }
837 }
838
Aran Inkc58028b2020-06-04 15:33:22 -0400839 @VisibleForTesting
840 protected abstract class EmergencyAction extends SinglePressAction {
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400841 EmergencyAction(int iconResId, int messageResId) {
842 super(iconResId, messageResId);
843 }
844
845 @Override
846 public boolean shouldBeSeparated() {
Sean Pontd7ff85a2020-05-18 21:47:08 -0700847 return false;
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400848 }
849
850 @Override
851 public View create(
852 Context context, View convertView, ViewGroup parent, LayoutInflater inflater) {
853 View v = super.create(context, convertView, parent, inflater);
854 int textColor;
Sean Pontd7ff85a2020-05-18 21:47:08 -0700855 v.setBackgroundTintList(ColorStateList.valueOf(v.getResources().getColor(
856 com.android.systemui.R.color.global_actions_emergency_background)));
857 textColor = v.getResources().getColor(
858 com.android.systemui.R.color.global_actions_emergency_text);
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400859 TextView messageView = v.findViewById(R.id.message);
860 messageView.setTextColor(textColor);
Aaron Heuckroth3f2d8b52019-04-05 13:27:51 -0400861 messageView.setSelected(true); // necessary for marquee to work
Lucas Dupincb6726f2020-04-07 19:32:38 -0700862 ImageView icon = v.findViewById(R.id.icon);
Aaron Heuckrothc8343402019-03-13 16:27:15 -0400863 icon.getDrawable().setTint(textColor);
864 return v;
865 }
866
867 @Override
868 public boolean showDuringKeyguard() {
869 return true;
870 }
871
872 @Override
873 public boolean showBeforeProvisioning() {
874 return true;
875 }
876 }
877
878 private class EmergencyAffordanceAction extends EmergencyAction {
879 EmergencyAffordanceAction() {
880 super(R.drawable.emergency_icon,
881 R.string.global_action_emergency);
882 }
883
884 @Override
885 public void onPress() {
886 mEmergencyAffordanceManager.performEmergencyCall();
887 }
888 }
889
Chris Wrenaf4ce8462020-04-06 17:36:10 -0400890 @VisibleForTesting
891 class EmergencyDialerAction extends EmergencyAction {
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800892 private EmergencyDialerAction() {
Aran Ink50195262019-05-30 10:55:37 -0400893 super(com.android.systemui.R.drawable.ic_emergency_star,
Wesley.CW Wang3004fcb2018-06-15 16:24:57 +0800894 R.string.global_action_emergency);
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800895 }
896
897 @Override
898 public void onPress() {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500899 mMetricsLogger.action(MetricsEvent.ACTION_EMERGENCY_DIALER_FROM_POWER_MENU);
Chris Wrenaf4ce8462020-04-06 17:36:10 -0400900 mUiEventLogger.log(GlobalActionsEvent.GA_EMERGENCY_DIALER_PRESS);
Dave Mankoff3c6aaab2020-01-10 17:50:34 -0500901 if (mTelecomManager != null) {
902 Intent intent = mTelecomManager.createLaunchEmergencyDialerIntent(
903 null /* number */);
904 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
905 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
906 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
907 intent.putExtra(EmergencyDialerConstants.EXTRA_ENTRY_TYPE,
908 EmergencyDialerConstants.ENTRY_TYPE_POWER_MENU);
909 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
910 }
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800911 }
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800912 }
913
Chris Wrenaf4ce8462020-04-06 17:36:10 -0400914 @VisibleForTesting
915 EmergencyDialerAction makeEmergencyDialerActionForTesting() {
916 return new EmergencyDialerAction();
917 }
918
Jason Monk361915c2017-03-21 20:33:59 -0400919 private final class RestartAction extends SinglePressAction implements LongPressAction {
920 private RestartAction() {
921 super(R.drawable.ic_restart, R.string.global_action_restart);
922 }
923
924 @Override
925 public boolean onLongPress() {
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500926 if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) {
Jason Monk361915c2017-03-21 20:33:59 -0400927 mWindowManagerFuncs.reboot(true);
928 return true;
929 }
930 return false;
931 }
932
933 @Override
934 public boolean showDuringKeyguard() {
935 return true;
936 }
937
938 @Override
939 public boolean showBeforeProvisioning() {
940 return true;
941 }
942
943 @Override
944 public void onPress() {
945 mWindowManagerFuncs.reboot(false);
946 }
947 }
948
Chris Wrenaf4ce8462020-04-06 17:36:10 -0400949 @VisibleForTesting
950 class ScreenshotAction extends SinglePressAction implements LongPressAction {
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500951 public ScreenshotAction() {
952 super(R.drawable.ic_screenshot, R.string.global_action_screenshot);
953 }
954
955 @Override
956 public void onPress() {
957 // Add a little delay before executing, to give the
958 // dialog a chance to go away before it takes a
959 // screenshot.
960 // TODO: instead, omit global action dialog layer
961 mHandler.postDelayed(new Runnable() {
962 @Override
963 public void run() {
Miranda Kephart7b2c3132020-03-27 09:54:14 -0400964 mScreenshotHelper.takeScreenshot(TAKE_SCREENSHOT_FULLSCREEN, true, true,
965 SCREENSHOT_GLOBAL_ACTIONS, mHandler, null);
Dave Mankoffc88a2d72020-01-10 15:59:31 -0500966 mMetricsLogger.action(MetricsEvent.ACTION_SCREENSHOT_POWER_MENU);
Chris Wrenaf4ce8462020-04-06 17:36:10 -0400967 mUiEventLogger.log(GlobalActionsEvent.GA_SCREENSHOT_PRESS);
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500968 }
Chris Wrenaf4ce8462020-04-06 17:36:10 -0400969 }, mDialogPressDelay);
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500970 }
971
972 @Override
973 public boolean showDuringKeyguard() {
974 return true;
975 }
976
977 @Override
978 public boolean showBeforeProvisioning() {
979 return false;
980 }
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400981
982 @Override
983 public boolean onLongPress() {
984 if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SCREENRECORD_LONG_PRESS)) {
Chris Wrenaf4ce8462020-04-06 17:36:10 -0400985 mUiEventLogger.log(GlobalActionsEvent.GA_SCREENSHOT_LONG_PRESS);
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400986 mScreenRecordHelper.launchRecordPrompt();
987 } else {
988 onPress();
989 }
990 return true;
991 }
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500992 }
993
Chris Wrenaf4ce8462020-04-06 17:36:10 -0400994 @VisibleForTesting
995 ScreenshotAction makeScreenshotActionForTesting() {
996 return new ScreenshotAction();
997 }
998
999 @VisibleForTesting
1000 class BugReportAction extends SinglePressAction implements LongPressAction {
Jason Monk361915c2017-03-21 20:33:59 -04001001
1002 public BugReportAction() {
1003 super(R.drawable.ic_lock_bugreport, R.string.bugreport_title);
1004 }
1005
1006 @Override
1007 public void onPress() {
1008 // don't actually trigger the bugreport if we are running stability
1009 // tests via monkey
1010 if (ActivityManager.isUserAMonkey()) {
1011 return;
1012 }
1013 // Add a little delay before executing, to give the
1014 // dialog a chance to go away before it takes a
1015 // screenshot.
1016 mHandler.postDelayed(new Runnable() {
1017 @Override
1018 public void run() {
1019 try {
1020 // Take an "interactive" bugreport.
Dave Mankoffc88a2d72020-01-10 15:59:31 -05001021 mMetricsLogger.action(
Jason Monk361915c2017-03-21 20:33:59 -04001022 MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_INTERACTIVE);
Chris Wrenaf4ce8462020-04-06 17:36:10 -04001023 mUiEventLogger.log(GlobalActionsEvent.GA_BUGREPORT_PRESS);
Dave Mankoffc88a2d72020-01-10 15:59:31 -05001024 if (!mIActivityManager.launchBugReportHandlerApp()) {
Paul Changc40f5782019-11-04 18:55:31 +08001025 Log.w(TAG, "Bugreport handler could not be launched");
Dave Mankoffc88a2d72020-01-10 15:59:31 -05001026 mIActivityManager.requestInteractiveBugReport();
Paul Changc40f5782019-11-04 18:55:31 +08001027 }
Jason Monk361915c2017-03-21 20:33:59 -04001028 } catch (RemoteException e) {
1029 }
1030 }
Chris Wrenaf4ce8462020-04-06 17:36:10 -04001031 }, mDialogPressDelay);
Jason Monk361915c2017-03-21 20:33:59 -04001032 }
1033
1034 @Override
1035 public boolean onLongPress() {
1036 // don't actually trigger the bugreport if we are running stability
1037 // tests via monkey
1038 if (ActivityManager.isUserAMonkey()) {
1039 return false;
1040 }
1041 try {
1042 // Take a "full" bugreport.
Dave Mankoffc88a2d72020-01-10 15:59:31 -05001043 mMetricsLogger.action(MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_FULL);
Chris Wrenaf4ce8462020-04-06 17:36:10 -04001044 mUiEventLogger.log(GlobalActionsEvent.GA_BUGREPORT_LONG_PRESS);
Dave Mankoffc88a2d72020-01-10 15:59:31 -05001045 mIActivityManager.requestFullBugReport();
Jason Monk361915c2017-03-21 20:33:59 -04001046 } catch (RemoteException e) {
1047 }
1048 return false;
1049 }
1050
1051 public boolean showDuringKeyguard() {
1052 return true;
1053 }
1054
1055 @Override
1056 public boolean showBeforeProvisioning() {
1057 return false;
1058 }
Jason Monk361915c2017-03-21 20:33:59 -04001059 }
1060
Chris Wrenaf4ce8462020-04-06 17:36:10 -04001061 @VisibleForTesting
1062 BugReportAction makeBugReportActionForTesting() {
1063 return new BugReportAction();
1064 }
1065
Alex Chau04458852017-11-27 18:21:23 +00001066 private final class LogoutAction extends SinglePressAction {
1067 private LogoutAction() {
1068 super(R.drawable.ic_logout, R.string.global_action_logout);
1069 }
1070
1071 @Override
1072 public boolean showDuringKeyguard() {
1073 return true;
1074 }
1075
1076 @Override
1077 public boolean showBeforeProvisioning() {
1078 return false;
1079 }
1080
1081 @Override
1082 public void onPress() {
1083 // Add a little delay before executing, to give the dialog a chance to go away before
1084 // switching user
1085 mHandler.postDelayed(() -> {
1086 try {
Alex Chauedb6a012018-01-26 12:52:43 +00001087 int currentUserId = getCurrentUser().id;
Dave Mankoffc88a2d72020-01-10 15:59:31 -05001088 mIActivityManager.switchUser(UserHandle.USER_SYSTEM);
1089 mIActivityManager.stopUser(currentUserId, true /*force*/, null);
Alex Chau04458852017-11-27 18:21:23 +00001090 } catch (RemoteException re) {
1091 Log.e(TAG, "Couldn't logout user " + re);
1092 }
Chris Wrenaf4ce8462020-04-06 17:36:10 -04001093 }, mDialogPressDelay);
Alex Chau04458852017-11-27 18:21:23 +00001094 }
1095 }
1096
Jason Monk361915c2017-03-21 20:33:59 -04001097 private Action getSettingsAction() {
1098 return new SinglePressAction(R.drawable.ic_settings,
1099 R.string.global_action_settings) {
1100
1101 @Override
1102 public void onPress() {
1103 Intent intent = new Intent(Settings.ACTION_SETTINGS);
1104 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
1105 mContext.startActivity(intent);
1106 }
1107
1108 @Override
1109 public boolean showDuringKeyguard() {
1110 return true;
1111 }
1112
1113 @Override
1114 public boolean showBeforeProvisioning() {
1115 return true;
1116 }
1117 };
1118 }
1119
Jason Monk361915c2017-03-21 20:33:59 -04001120 private Action getAssistAction() {
1121 return new SinglePressAction(R.drawable.ic_action_assist_focused,
1122 R.string.global_action_assist) {
1123 @Override
1124 public void onPress() {
1125 Intent intent = new Intent(Intent.ACTION_ASSIST);
1126 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
1127 mContext.startActivity(intent);
1128 }
1129
1130 @Override
1131 public boolean showDuringKeyguard() {
1132 return true;
1133 }
1134
1135 @Override
1136 public boolean showBeforeProvisioning() {
1137 return true;
1138 }
1139 };
1140 }
1141
1142 private Action getVoiceAssistAction() {
1143 return new SinglePressAction(R.drawable.ic_voice_search,
1144 R.string.global_action_voice_assist) {
1145 @Override
1146 public void onPress() {
1147 Intent intent = new Intent(Intent.ACTION_VOICE_ASSIST);
1148 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
1149 mContext.startActivity(intent);
1150 }
1151
1152 @Override
1153 public boolean showDuringKeyguard() {
1154 return true;
1155 }
1156
1157 @Override
1158 public boolean showBeforeProvisioning() {
1159 return true;
1160 }
1161 };
1162 }
1163
1164 private Action getLockdownAction() {
Alison Cichowlas21125432018-05-16 15:40:45 -04001165 return new SinglePressAction(R.drawable.ic_lock_lockdown,
Jason Monk361915c2017-03-21 20:33:59 -04001166 R.string.global_action_lockdown) {
1167
1168 @Override
1169 public void onPress() {
Dave Mankoff8df818e2020-02-12 14:22:26 -05001170 mLockPatternUtils.requireStrongAuth(STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN,
1171 UserHandle.USER_ALL);
Jason Monk361915c2017-03-21 20:33:59 -04001172 try {
Dave Mankoff8df818e2020-02-12 14:22:26 -05001173 mIWindowManager.lockNow(null);
Pavel Grafov059021b2018-05-02 13:44:46 +01001174 // Lock profiles (if any) on the background thread.
Dave Mankoff8df818e2020-02-12 14:22:26 -05001175 mBackgroundExecutor.execute(() -> lockProfiles());
Jason Monk361915c2017-03-21 20:33:59 -04001176 } catch (RemoteException e) {
1177 Log.e(TAG, "Error while trying to lock device.", e);
1178 }
1179 }
1180
1181 @Override
1182 public boolean showDuringKeyguard() {
1183 return true;
1184 }
1185
1186 @Override
1187 public boolean showBeforeProvisioning() {
1188 return false;
1189 }
1190 };
1191 }
1192
Pavel Grafov059021b2018-05-02 13:44:46 +01001193 private void lockProfiles() {
Pavel Grafov059021b2018-05-02 13:44:46 +01001194 final int currentUserId = getCurrentUser().id;
Dave Mankoffc88a2d72020-01-10 15:59:31 -05001195 final int[] profileIds = mUserManager.getEnabledProfileIds(currentUserId);
Pavel Grafov059021b2018-05-02 13:44:46 +01001196 for (final int id : profileIds) {
1197 if (id != currentUserId) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -05001198 mTrustManager.setDeviceLockedForUser(id, true);
Pavel Grafov059021b2018-05-02 13:44:46 +01001199 }
1200 }
1201 }
1202
Jason Monk361915c2017-03-21 20:33:59 -04001203 private UserInfo getCurrentUser() {
1204 try {
Dave Mankoffc88a2d72020-01-10 15:59:31 -05001205 return mIActivityManager.getCurrentUser();
Jason Monk361915c2017-03-21 20:33:59 -04001206 } catch (RemoteException re) {
1207 return null;
1208 }
1209 }
1210
1211 private boolean isCurrentUserOwner() {
1212 UserInfo currentUser = getCurrentUser();
1213 return currentUser == null || currentUser.isPrimary();
1214 }
1215
Aran Inkcf038272020-03-31 17:48:37 -04001216 private void addUsersToMenu() {
Dave Mankoffc88a2d72020-01-10 15:59:31 -05001217 if (mUserManager.isUserSwitcherEnabled()) {
1218 List<UserInfo> users = mUserManager.getUsers();
Jason Monk361915c2017-03-21 20:33:59 -04001219 UserInfo currentUser = getCurrentUser();
1220 for (final UserInfo user : users) {
1221 if (user.supportsSwitchToByUser()) {
1222 boolean isCurrentUser = currentUser == null
1223 ? user.id == 0 : (currentUser.id == user.id);
1224 Drawable icon = user.iconPath != null ? Drawable.createFromPath(user.iconPath)
1225 : null;
1226 SinglePressAction switchToUser = new SinglePressAction(
1227 R.drawable.ic_menu_cc, icon,
1228 (user.name != null ? user.name : "Primary")
Jason Monk16fbd9d2017-04-27 14:28:49 -04001229 + (isCurrentUser ? " \u2714" : "")) {
Jason Monk361915c2017-03-21 20:33:59 -04001230 public void onPress() {
1231 try {
Dave Mankoffc88a2d72020-01-10 15:59:31 -05001232 mIActivityManager.switchUser(user.id);
Jason Monk361915c2017-03-21 20:33:59 -04001233 } catch (RemoteException re) {
1234 Log.e(TAG, "Couldn't switch user " + re);
1235 }
1236 }
1237
1238 public boolean showDuringKeyguard() {
1239 return true;
1240 }
1241
1242 public boolean showBeforeProvisioning() {
1243 return false;
1244 }
1245 };
Aran Inkcf038272020-03-31 17:48:37 -04001246 addActionItem(switchToUser);
Jason Monk361915c2017-03-21 20:33:59 -04001247 }
1248 }
1249 }
1250 }
1251
1252 private void prepareDialog() {
1253 refreshSilentMode();
1254 mAirplaneModeOn.updateState(mAirplaneState);
1255 mAdapter.notifyDataSetChanged();
Fabian Kozynskib6a20372020-04-01 09:36:43 -04001256 mLifecycle.setCurrentState(Lifecycle.State.RESUMED);
Jason Monk361915c2017-03-21 20:33:59 -04001257 }
1258
1259 private void refreshSilentMode() {
1260 if (!mHasVibrator) {
Fabian Kozynskib6a20372020-04-01 09:36:43 -04001261 Integer value = mRingerModeTracker.getRingerMode().getValue();
1262 final boolean silentModeOn = value != null && value != AudioManager.RINGER_MODE_NORMAL;
Jason Monk16fbd9d2017-04-27 14:28:49 -04001263 ((ToggleAction) mSilentModeAction).updateState(
Lucas Dupincb6726f2020-04-07 19:32:38 -07001264 silentModeOn ? ToggleState.On : ToggleState.Off);
Jason Monk361915c2017-03-21 20:33:59 -04001265 }
1266 }
1267
Sean Pont9d4fb032020-03-04 18:54:32 -08001268 /**
1269 * {@inheritDoc}
1270 */
Jason Monk361915c2017-03-21 20:33:59 -04001271 public void onDismiss(DialogInterface dialog) {
Steve Elliottc3147e22019-11-20 19:34:57 -05001272 if (mDialog == dialog) {
1273 mDialog = null;
1274 }
Chris Wren9756a002020-05-12 16:46:27 -04001275 mUiEventLogger.log(GlobalActionsEvent.GA_POWER_MENU_CLOSE);
Jason Monk361915c2017-03-21 20:33:59 -04001276 mWindowManagerFuncs.onGlobalActionsHidden();
Fabian Kozynskib5400882020-05-27 09:45:28 -04001277 mLifecycle.setCurrentState(Lifecycle.State.CREATED);
Jason Monk361915c2017-03-21 20:33:59 -04001278 }
1279
Sean Pont9d4fb032020-03-04 18:54:32 -08001280 /**
1281 * {@inheritDoc}
1282 */
Shaotang Li786da902018-08-02 11:18:00 +08001283 public void onShow(DialogInterface dialog) {
Dave Mankoffc88a2d72020-01-10 15:59:31 -05001284 mMetricsLogger.visible(MetricsEvent.POWER_MENU);
Chris Wren65a70c92020-04-02 10:43:46 -04001285 mUiEventLogger.log(GlobalActionsEvent.GA_POWER_MENU_OPEN);
Shaotang Li786da902018-08-02 11:18:00 +08001286 }
1287
Jason Monk361915c2017-03-21 20:33:59 -04001288 /**
Aran Inkcf038272020-03-31 17:48:37 -04001289 * The adapter used for power menu items shown in the global actions dialog.
Jason Monk361915c2017-03-21 20:33:59 -04001290 */
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001291 public class MyAdapter extends MultiListAdapter {
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -04001292 private int countItems(boolean separated) {
Jason Monk361915c2017-03-21 20:33:59 -04001293 int count = 0;
Jason Monk361915c2017-03-21 20:33:59 -04001294 for (int i = 0; i < mItems.size(); i++) {
1295 final Action action = mItems.get(i);
1296
Aran Inkcf038272020-03-31 17:48:37 -04001297 if (action.shouldBeSeparated() == separated) {
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -04001298 count++;
Jason Monk361915c2017-03-21 20:33:59 -04001299 }
Jason Monk361915c2017-03-21 20:33:59 -04001300 }
1301 return count;
1302 }
1303
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -04001304 @Override
1305 public int countSeparatedItems() {
1306 return countItems(true);
1307 }
1308
1309 @Override
1310 public int countListItems() {
1311 return countItems(false);
1312 }
1313
1314 @Override
1315 public int getCount() {
1316 return countSeparatedItems() + countListItems();
1317 }
1318
Jason Monk361915c2017-03-21 20:33:59 -04001319 @Override
1320 public boolean isEnabled(int position) {
1321 return getItem(position).isEnabled();
1322 }
1323
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001324 @Override
Jason Monk361915c2017-03-21 20:33:59 -04001325 public boolean areAllItemsEnabled() {
1326 return false;
1327 }
1328
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001329 @Override
Jason Monk361915c2017-03-21 20:33:59 -04001330 public Action getItem(int position) {
Jason Monk361915c2017-03-21 20:33:59 -04001331 int filteredPos = 0;
1332 for (int i = 0; i < mItems.size(); i++) {
1333 final Action action = mItems.get(i);
Aran Inkcf038272020-03-31 17:48:37 -04001334 if (!shouldShowAction(action)) {
Jason Monk361915c2017-03-21 20:33:59 -04001335 continue;
1336 }
1337 if (filteredPos == position) {
1338 return action;
1339 }
1340 filteredPos++;
1341 }
1342
1343 throw new IllegalArgumentException("position " + position
1344 + " out of range of showable actions"
1345 + ", filtered count=" + getCount()
1346 + ", keyguardshowing=" + mKeyguardShowing
1347 + ", provisioned=" + mDeviceProvisioned);
1348 }
1349
1350
1351 public long getItemId(int position) {
1352 return position;
1353 }
1354
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001355 @Override
Jason Monk361915c2017-03-21 20:33:59 -04001356 public View getView(int position, View convertView, ViewGroup parent) {
1357 Action action = getItem(position);
Jason Monk16fbd9d2017-04-27 14:28:49 -04001358 View view = action.create(mContext, convertView, parent, LayoutInflater.from(mContext));
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -04001359 view.setOnClickListener(v -> onClickItem(position));
Aran Inkb4199d92020-02-07 13:25:21 -05001360 if (action instanceof LongPressAction) {
1361 view.setOnLongClickListener(v -> onLongClickItem(position));
1362 }
Jason Monk16fbd9d2017-04-27 14:28:49 -04001363 return view;
Jason Monk361915c2017-03-21 20:33:59 -04001364 }
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001365
1366 @Override
1367 public boolean onLongClickItem(int position) {
1368 final Action action = mAdapter.getItem(position);
1369 if (action instanceof LongPressAction) {
Aran Inkbaa25862019-06-11 15:48:55 -04001370 if (mDialog != null) {
1371 mDialog.dismiss();
1372 } else {
1373 Log.w(TAG, "Action long-clicked while mDialog is null.");
1374 }
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001375 return ((LongPressAction) action).onLongPress();
1376 }
1377 return false;
1378 }
1379
1380 @Override
1381 public void onClickItem(int position) {
1382 Action item = mAdapter.getItem(position);
1383 if (!(item instanceof SilentModeTriStateAction)) {
Aran Inkbaa25862019-06-11 15:48:55 -04001384 if (mDialog != null) {
Aran Inkc58028b2020-06-04 15:33:22 -04001385 // don't dismiss the dialog if we're opening the power options menu
1386 if (!(item instanceof PowerOptionsAction)) {
1387 mDialog.dismiss();
1388 }
Aran Inkbaa25862019-06-11 15:48:55 -04001389 } else {
1390 Log.w(TAG, "Action clicked while mDialog is null.");
1391 }
1392 item.onPress();
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001393 }
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001394 }
Aaron Heuckroth5e28f8c82019-04-24 13:26:12 -04001395
1396 @Override
1397 public boolean shouldBeSeparated(int position) {
1398 return getItem(position).shouldBeSeparated();
1399 }
Jason Monk361915c2017-03-21 20:33:59 -04001400 }
1401
Aran Inkcf038272020-03-31 17:48:37 -04001402 /**
1403 * The adapter used for items in the overflow menu.
1404 */
Aran Inkc58028b2020-06-04 15:33:22 -04001405 public class MyPowerOptionsAdapter extends BaseAdapter {
1406 @Override
1407 public int getCount() {
1408 return mPowerItems.size();
1409 }
1410
1411 @Override
1412 public Action getItem(int position) {
1413 return mPowerItems.get(position);
1414 }
1415
1416 @Override
1417 public long getItemId(int position) {
1418 return position;
1419 }
1420
1421 @Override
1422 public View getView(int position, View convertView, ViewGroup parent) {
1423 Action action = getItem(position);
1424 if (action == null) {
1425 Log.w(TAG, "No power options action found at position: " + position);
1426 return null;
1427 }
Aran Ink143eea42020-06-16 19:18:49 -04001428 int viewLayoutResource = com.android.systemui.R.layout.global_actions_power_item;
Aran Inkc58028b2020-06-04 15:33:22 -04001429 View view = convertView != null ? convertView
1430 : LayoutInflater.from(mContext).inflate(viewLayoutResource, parent, false);
Aran Ink143eea42020-06-16 19:18:49 -04001431 view.setOnClickListener(v -> onClickItem(position));
1432 if (action instanceof LongPressAction) {
1433 view.setOnLongClickListener(v -> onLongClickItem(position));
Aran Inkc58028b2020-06-04 15:33:22 -04001434 }
Aran Ink143eea42020-06-16 19:18:49 -04001435 ImageView icon = view.findViewById(R.id.icon);
1436 TextView messageView = view.findViewById(R.id.message);
1437 messageView.setSelected(true); // necessary for marquee to work
1438
1439 icon.setImageDrawable(action.getIcon(mContext));
1440 icon.setScaleType(ScaleType.CENTER_CROP);
1441
1442 if (action.getMessage() != null) {
1443 messageView.setText(action.getMessage());
1444 } else {
1445 messageView.setText(action.getMessageResId());
1446 }
1447 return view;
Aran Inkc58028b2020-06-04 15:33:22 -04001448 }
1449
1450 private boolean onLongClickItem(int position) {
1451 final Action action = getItem(position);
1452 if (action instanceof LongPressAction) {
1453 if (mDialog != null) {
1454 mDialog.dismiss();
1455 } else {
1456 Log.w(TAG, "Action long-clicked while mDialog is null.");
1457 }
1458 return ((LongPressAction) action).onLongPress();
1459 }
1460 return false;
1461 }
1462
1463 private void onClickItem(int position) {
1464 Action item = getItem(position);
1465 if (!(item instanceof SilentModeTriStateAction)) {
1466 if (mDialog != null) {
1467 mDialog.dismiss();
1468 } else {
1469 Log.w(TAG, "Action clicked while mDialog is null.");
1470 }
1471 item.onPress();
1472 }
1473 }
1474 }
1475
1476 /**
1477 * The adapter used for items in the power options menu, triggered by the PowerOptionsAction.
1478 */
Aran Inkcf038272020-03-31 17:48:37 -04001479 public class MyOverflowAdapter extends BaseAdapter {
1480 @Override
1481 public int getCount() {
Aran Inka65e68362020-04-14 15:23:24 -04001482 return mOverflowItems.size();
Aran Inkcf038272020-03-31 17:48:37 -04001483 }
1484
1485 @Override
1486 public Action getItem(int position) {
Aran Inka65e68362020-04-14 15:23:24 -04001487 return mOverflowItems.get(position);
Aran Inkcf038272020-03-31 17:48:37 -04001488 }
1489
1490 @Override
1491 public long getItemId(int position) {
1492 return position;
1493 }
1494
1495 @Override
1496 public View getView(int position, View convertView, ViewGroup parent) {
1497 Action action = getItem(position);
1498 if (action == null) {
1499 Log.w(TAG, "No overflow action found at position: " + position);
1500 return null;
1501 }
1502 int viewLayoutResource = com.android.systemui.R.layout.controls_more_item;
1503 View view = convertView != null ? convertView
1504 : LayoutInflater.from(mContext).inflate(viewLayoutResource, parent, false);
1505 TextView textView = (TextView) view;
Aran Inkcf038272020-03-31 17:48:37 -04001506 if (action.getMessageResId() != 0) {
1507 textView.setText(action.getMessageResId());
1508 } else {
1509 textView.setText(action.getMessage());
1510 }
Aran Inkcf038272020-03-31 17:48:37 -04001511 return textView;
1512 }
1513
1514 private boolean onLongClickItem(int position) {
1515 final Action action = getItem(position);
1516 if (action instanceof LongPressAction) {
1517 if (mDialog != null) {
Aran Inkcf038272020-03-31 17:48:37 -04001518 mDialog.dismiss();
1519 } else {
1520 Log.w(TAG, "Action long-clicked while mDialog is null.");
1521 }
1522 return ((LongPressAction) action).onLongPress();
1523 }
1524 return false;
1525 }
1526
1527 private void onClickItem(int position) {
1528 Action item = getItem(position);
1529 if (!(item instanceof SilentModeTriStateAction)) {
1530 if (mDialog != null) {
Aran Inkcf038272020-03-31 17:48:37 -04001531 mDialog.dismiss();
1532 } else {
1533 Log.w(TAG, "Action clicked while mDialog is null.");
1534 }
1535 item.onPress();
1536 }
1537 }
1538 }
1539
Jason Monk361915c2017-03-21 20:33:59 -04001540 // note: the scheme below made more sense when we were planning on having
1541 // 8 different things in the global actions dialog. seems overkill with
1542 // only 3 items now, but may as well keep this flexible approach so it will
1543 // be easy should someone decide at the last minute to include something
1544 // else, such as 'enable wifi', or 'enable bluetooth'
1545
1546 /**
1547 * What each item in the global actions dialog must be able to support.
1548 */
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05001549 public interface Action {
Jason Monk361915c2017-03-21 20:33:59 -04001550 /**
Sean Pont9d4fb032020-03-04 18:54:32 -08001551 * @return Text that will be announced when dialog is created. null for none.
Jason Monk361915c2017-03-21 20:33:59 -04001552 */
1553 CharSequence getLabelForAccessibility(Context context);
1554
1555 View create(Context context, View convertView, ViewGroup parent, LayoutInflater inflater);
1556
1557 void onPress();
1558
1559 /**
Sean Pont9d4fb032020-03-04 18:54:32 -08001560 * @return whether this action should appear in the dialog when the keygaurd is showing.
Jason Monk361915c2017-03-21 20:33:59 -04001561 */
1562 boolean showDuringKeyguard();
1563
1564 /**
Aran Inkcf038272020-03-31 17:48:37 -04001565 * @return whether this action should appear in the dialog before the
1566 * device is provisioned.f
Jason Monk361915c2017-03-21 20:33:59 -04001567 */
1568 boolean showBeforeProvisioning();
1569
1570 boolean isEnabled();
Aaron Heuckrothf708d472019-01-10 16:54:51 -05001571
1572 default boolean shouldBeSeparated() {
1573 return false;
1574 }
Aran Inkcf038272020-03-31 17:48:37 -04001575
1576 /**
1577 * Return the id of the message associated with this action, or 0 if it doesn't have one.
1578 * @return
1579 */
1580 int getMessageResId();
1581
1582 /**
Aran Ink143eea42020-06-16 19:18:49 -04001583 * Return the icon drawable for this action.
1584 */
1585 Drawable getIcon(Context context);
1586
1587 /**
Aran Inkcf038272020-03-31 17:48:37 -04001588 * Return the message associated with this action, or null if it doesn't have one.
1589 * @return
1590 */
1591 CharSequence getMessage();
Jason Monk361915c2017-03-21 20:33:59 -04001592 }
1593
1594 /**
1595 * An action that also supports long press.
1596 */
1597 private interface LongPressAction extends Action {
1598 boolean onLongPress();
1599 }
1600
1601 /**
Sean Pont9d4fb032020-03-04 18:54:32 -08001602 * A single press action maintains no state, just responds to a press and takes an action.
Jason Monk361915c2017-03-21 20:33:59 -04001603 */
Matt Pietale0661b62020-01-29 14:35:31 -05001604
1605 private abstract class SinglePressAction implements Action {
Jason Monk361915c2017-03-21 20:33:59 -04001606 private final int mIconResId;
1607 private final Drawable mIcon;
1608 private final int mMessageResId;
1609 private final CharSequence mMessage;
1610
1611 protected SinglePressAction(int iconResId, int messageResId) {
1612 mIconResId = iconResId;
1613 mMessageResId = messageResId;
1614 mMessage = null;
1615 mIcon = null;
1616 }
1617
1618 protected SinglePressAction(int iconResId, Drawable icon, CharSequence message) {
1619 mIconResId = iconResId;
1620 mMessageResId = 0;
1621 mMessage = message;
1622 mIcon = icon;
1623 }
1624
1625 public boolean isEnabled() {
1626 return true;
1627 }
1628
1629 public String getStatus() {
1630 return null;
1631 }
1632
1633 abstract public void onPress();
1634
1635 public CharSequence getLabelForAccessibility(Context context) {
1636 if (mMessage != null) {
1637 return mMessage;
1638 } else {
1639 return context.getString(mMessageResId);
1640 }
1641 }
1642
Aran Inkcf038272020-03-31 17:48:37 -04001643 public int getMessageResId() {
1644 return mMessageResId;
1645 }
1646
1647 public CharSequence getMessage() {
1648 return mMessage;
1649 }
1650
Aran Ink143eea42020-06-16 19:18:49 -04001651 @Override
1652 public Drawable getIcon(Context context) {
1653 if (mIcon != null) {
1654 return mIcon;
1655 } else {
1656 return context.getDrawable(mIconResId);
1657 }
1658 }
1659
Jason Monk361915c2017-03-21 20:33:59 -04001660 public View create(
1661 Context context, View convertView, ViewGroup parent, LayoutInflater inflater) {
Sean Pontd7ff85a2020-05-18 21:47:08 -07001662 View v = inflater.inflate(com.android.systemui.R.layout.global_actions_grid_item_v2,
1663 parent, false /* attach */);
Jason Monk361915c2017-03-21 20:33:59 -04001664
Lucas Dupincb6726f2020-04-07 19:32:38 -07001665 ImageView icon = v.findViewById(R.id.icon);
1666 TextView messageView = v.findViewById(R.id.message);
Aaron Heuckroth3f2d8b52019-04-05 13:27:51 -04001667 messageView.setSelected(true); // necessary for marquee to work
Jason Monk361915c2017-03-21 20:33:59 -04001668
Aran Ink143eea42020-06-16 19:18:49 -04001669 icon.setImageDrawable(getIcon(context));
1670 icon.setScaleType(ScaleType.CENTER_CROP);
1671
Jason Monk361915c2017-03-21 20:33:59 -04001672 if (mMessage != null) {
1673 messageView.setText(mMessage);
1674 } else {
1675 messageView.setText(mMessageResId);
1676 }
1677
1678 return v;
1679 }
1680 }
1681
Lucas Dupincb6726f2020-04-07 19:32:38 -07001682 private enum ToggleState {
1683 Off(false),
1684 TurningOn(true),
1685 TurningOff(true),
1686 On(false);
1687
1688 private final boolean mInTransition;
1689
1690 ToggleState(boolean intermediate) {
1691 mInTransition = intermediate;
1692 }
1693
1694 public boolean inTransition() {
1695 return mInTransition;
1696 }
1697 }
1698
Jason Monk361915c2017-03-21 20:33:59 -04001699 /**
Sean Pont9d4fb032020-03-04 18:54:32 -08001700 * A toggle action knows whether it is on or off, and displays an icon and status message
1701 * accordingly.
Jason Monk361915c2017-03-21 20:33:59 -04001702 */
Lucas Dupincb6726f2020-04-07 19:32:38 -07001703 private abstract class ToggleAction implements Action {
Jason Monk361915c2017-03-21 20:33:59 -04001704
Lucas Dupincb6726f2020-04-07 19:32:38 -07001705 protected ToggleState mState = ToggleState.Off;
Jason Monk361915c2017-03-21 20:33:59 -04001706
1707 // prefs
1708 protected int mEnabledIconResId;
1709 protected int mDisabledIconResid;
1710 protected int mMessageResId;
1711 protected int mEnabledStatusMessageResId;
1712 protected int mDisabledStatusMessageResId;
1713
1714 /**
Jason Monk16fbd9d2017-04-27 14:28:49 -04001715 * @param enabledIconResId The icon for when this action is on.
1716 * @param disabledIconResid The icon for when this action is off.
1717 * @param message The general information message, e.g 'Silent Mode'
1718 * @param enabledStatusMessageResId The on status message, e.g 'sound disabled'
Jason Monk361915c2017-03-21 20:33:59 -04001719 * @param disabledStatusMessageResId The off status message, e.g. 'sound enabled'
1720 */
1721 public ToggleAction(int enabledIconResId,
1722 int disabledIconResid,
1723 int message,
1724 int enabledStatusMessageResId,
1725 int disabledStatusMessageResId) {
1726 mEnabledIconResId = enabledIconResId;
1727 mDisabledIconResid = disabledIconResid;
1728 mMessageResId = message;
1729 mEnabledStatusMessageResId = enabledStatusMessageResId;
1730 mDisabledStatusMessageResId = disabledStatusMessageResId;
1731 }
1732
1733 /**
Sean Pont9d4fb032020-03-04 18:54:32 -08001734 * Override to make changes to resource IDs just before creating the View.
Jason Monk361915c2017-03-21 20:33:59 -04001735 */
1736 void willCreate() {
1737
1738 }
1739
1740 @Override
1741 public CharSequence getLabelForAccessibility(Context context) {
1742 return context.getString(mMessageResId);
1743 }
1744
Aran Inkcf038272020-03-31 17:48:37 -04001745 private boolean isOn() {
1746 return mState == ToggleState.On || mState == ToggleState.TurningOn;
1747 }
1748
1749 @Override
1750 public CharSequence getMessage() {
1751 return null;
1752 }
1753 @Override
1754 public int getMessageResId() {
1755 return isOn() ? mEnabledStatusMessageResId : mDisabledStatusMessageResId;
1756 }
1757
1758 private int getIconResId() {
1759 return isOn() ? mEnabledIconResId : mDisabledIconResid;
1760 }
1761
Aran Ink143eea42020-06-16 19:18:49 -04001762 @Override
1763 public Drawable getIcon(Context context) {
1764 return context.getDrawable(getIconResId());
1765 }
1766
Jason Monk361915c2017-03-21 20:33:59 -04001767 public View create(Context context, View convertView, ViewGroup parent,
1768 LayoutInflater inflater) {
1769 willCreate();
1770
Sean Pontd7ff85a2020-05-18 21:47:08 -07001771 View v = inflater.inflate(com.android.systemui.R.layout.global_actions_grid_item_v2,
1772 parent, false /* attach */);
Jason Monk361915c2017-03-21 20:33:59 -04001773
1774 ImageView icon = (ImageView) v.findViewById(R.id.icon);
1775 TextView messageView = (TextView) v.findViewById(R.id.message);
Jason Monk361915c2017-03-21 20:33:59 -04001776 final boolean enabled = isEnabled();
1777
1778 if (messageView != null) {
Aran Inkcf038272020-03-31 17:48:37 -04001779 messageView.setText(getMessageResId());
Jason Monk361915c2017-03-21 20:33:59 -04001780 messageView.setEnabled(enabled);
Aaron Heuckroth3f2d8b52019-04-05 13:27:51 -04001781 messageView.setSelected(true); // necessary for marquee to work
Jason Monk361915c2017-03-21 20:33:59 -04001782 }
1783
Jason Monk361915c2017-03-21 20:33:59 -04001784 if (icon != null) {
Aran Inkcf038272020-03-31 17:48:37 -04001785 icon.setImageDrawable(context.getDrawable(getIconResId()));
Jason Monk361915c2017-03-21 20:33:59 -04001786 icon.setEnabled(enabled);
1787 }
1788
Jason Monk361915c2017-03-21 20:33:59 -04001789 v.setEnabled(enabled);
1790
1791 return v;
1792 }
1793
1794 public final void onPress() {
1795 if (mState.inTransition()) {
1796 Log.w(TAG, "shouldn't be able to toggle when in transition");
1797 return;
1798 }
1799
Lucas Dupincb6726f2020-04-07 19:32:38 -07001800 final boolean nowOn = !(mState == ToggleState.On);
Jason Monk361915c2017-03-21 20:33:59 -04001801 onToggle(nowOn);
1802 changeStateFromPress(nowOn);
1803 }
1804
1805 public boolean isEnabled() {
1806 return !mState.inTransition();
1807 }
1808
1809 /**
Sean Pont9d4fb032020-03-04 18:54:32 -08001810 * Implementations may override this if their state can be in on of the intermediate states
1811 * until some notification is received (e.g airplane mode is 'turning off' until we know the
1812 * wireless connections are back online
Jason Monk16fbd9d2017-04-27 14:28:49 -04001813 *
Jason Monk361915c2017-03-21 20:33:59 -04001814 * @param buttonOn Whether the button was turned on or off
1815 */
1816 protected void changeStateFromPress(boolean buttonOn) {
Lucas Dupincb6726f2020-04-07 19:32:38 -07001817 mState = buttonOn ? ToggleState.On : ToggleState.Off;
Jason Monk361915c2017-03-21 20:33:59 -04001818 }
1819
1820 abstract void onToggle(boolean on);
1821
Lucas Dupincb6726f2020-04-07 19:32:38 -07001822 public void updateState(ToggleState state) {
Jason Monk361915c2017-03-21 20:33:59 -04001823 mState = state;
1824 }
1825 }
1826
Aran Ink780d4502020-02-14 10:39:58 -05001827 private class AirplaneModeAction extends ToggleAction {
1828 AirplaneModeAction() {
1829 super(
Sean Pont9d4fb032020-03-04 18:54:32 -08001830 R.drawable.ic_lock_airplane_mode,
1831 R.drawable.ic_lock_airplane_mode_off,
1832 R.string.global_actions_toggle_airplane_mode,
1833 R.string.global_actions_airplane_mode_on_status,
1834 R.string.global_actions_airplane_mode_off_status);
Aran Ink780d4502020-02-14 10:39:58 -05001835 }
Sean Pont9d4fb032020-03-04 18:54:32 -08001836
Aran Ink780d4502020-02-14 10:39:58 -05001837 void onToggle(boolean on) {
1838 if (mHasTelephony && TelephonyProperties.in_ecm_mode().orElse(false)) {
1839 mIsWaitingForEcmExit = true;
1840 // Launch ECM exit dialog
1841 Intent ecmDialogIntent =
1842 new Intent(TelephonyManager.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null);
1843 ecmDialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1844 mContext.startActivity(ecmDialogIntent);
1845 } else {
1846 changeAirplaneModeSystemSetting(on);
1847 }
1848 }
1849
1850 @Override
1851 protected void changeStateFromPress(boolean buttonOn) {
1852 if (!mHasTelephony) return;
1853
1854 // In ECM mode airplane state cannot be changed
1855 if (!TelephonyProperties.in_ecm_mode().orElse(false)) {
Lucas Dupincb6726f2020-04-07 19:32:38 -07001856 mState = buttonOn ? ToggleState.TurningOn : ToggleState.TurningOff;
Aran Ink780d4502020-02-14 10:39:58 -05001857 mAirplaneState = mState;
1858 }
1859 }
1860
1861 public boolean showDuringKeyguard() {
1862 return true;
1863 }
1864
1865 public boolean showBeforeProvisioning() {
1866 return false;
1867 }
1868 }
1869
Jason Monk361915c2017-03-21 20:33:59 -04001870 private class SilentModeToggleAction extends ToggleAction {
1871 public SilentModeToggleAction() {
1872 super(R.drawable.ic_audio_vol_mute,
1873 R.drawable.ic_audio_vol,
1874 R.string.global_action_toggle_silent_mode,
1875 R.string.global_action_silent_mode_on_status,
1876 R.string.global_action_silent_mode_off_status);
1877 }
1878
1879 void onToggle(boolean on) {
1880 if (on) {
1881 mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
1882 } else {
1883 mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
1884 }
1885 }
1886
1887 public boolean showDuringKeyguard() {
1888 return true;
1889 }
1890
1891 public boolean showBeforeProvisioning() {
1892 return false;
1893 }
1894 }
1895
1896 private static class SilentModeTriStateAction implements Action, View.OnClickListener {
1897
Jason Monk16fbd9d2017-04-27 14:28:49 -04001898 private final int[] ITEM_IDS = {R.id.option1, R.id.option2, R.id.option3};
Jason Monk361915c2017-03-21 20:33:59 -04001899
1900 private final AudioManager mAudioManager;
1901 private final Handler mHandler;
Jason Monk361915c2017-03-21 20:33:59 -04001902
Lucas Dupin40ec6b782018-06-05 19:07:16 -07001903 SilentModeTriStateAction(AudioManager audioManager, Handler handler) {
Jason Monk361915c2017-03-21 20:33:59 -04001904 mAudioManager = audioManager;
1905 mHandler = handler;
Jason Monk361915c2017-03-21 20:33:59 -04001906 }
1907
1908 private int ringerModeToIndex(int ringerMode) {
1909 // They just happen to coincide
1910 return ringerMode;
1911 }
1912
1913 private int indexToRingerMode(int index) {
1914 // They just happen to coincide
1915 return index;
1916 }
1917
1918 @Override
1919 public CharSequence getLabelForAccessibility(Context context) {
1920 return null;
1921 }
1922
Aran Inkcf038272020-03-31 17:48:37 -04001923 @Override
1924 public int getMessageResId() {
1925 return 0;
1926 }
1927
1928 @Override
1929 public CharSequence getMessage() {
1930 return null;
1931 }
1932
Aran Ink143eea42020-06-16 19:18:49 -04001933 @Override
1934 public Drawable getIcon(Context context) {
1935 return null;
1936 }
1937
1938
Jason Monk361915c2017-03-21 20:33:59 -04001939 public View create(Context context, View convertView, ViewGroup parent,
1940 LayoutInflater inflater) {
1941 View v = inflater.inflate(R.layout.global_actions_silent_mode, parent, false);
1942
1943 int selectedIndex = ringerModeToIndex(mAudioManager.getRingerMode());
1944 for (int i = 0; i < 3; i++) {
1945 View itemView = v.findViewById(ITEM_IDS[i]);
1946 itemView.setSelected(selectedIndex == i);
1947 // Set up click handler
1948 itemView.setTag(i);
1949 itemView.setOnClickListener(this);
1950 }
1951 return v;
1952 }
1953
1954 public void onPress() {
1955 }
1956
1957 public boolean showDuringKeyguard() {
1958 return true;
1959 }
1960
1961 public boolean showBeforeProvisioning() {
1962 return false;
1963 }
1964
1965 public boolean isEnabled() {
1966 return true;
1967 }
1968
1969 void willCreate() {
1970 }
1971
1972 public void onClick(View v) {
1973 if (!(v.getTag() instanceof Integer)) return;
1974
1975 int index = (Integer) v.getTag();
1976 mAudioManager.setRingerMode(indexToRingerMode(index));
1977 mHandler.sendEmptyMessageDelayed(MESSAGE_DISMISS, DIALOG_DISMISS_DELAY);
1978 }
1979 }
1980
1981 private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
1982 public void onReceive(Context context, Intent intent) {
1983 String action = intent.getAction();
1984 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)
1985 || Intent.ACTION_SCREEN_OFF.equals(action)) {
1986 String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY);
1987 if (!SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS.equals(reason)) {
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001988 mHandler.sendMessage(mHandler.obtainMessage(MESSAGE_DISMISS, reason));
Jason Monk361915c2017-03-21 20:33:59 -04001989 }
Jayachandran C142eae02019-12-13 19:29:20 -08001990 } else if (TelephonyManager.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED.equals(action)) {
Jason Monk361915c2017-03-21 20:33:59 -04001991 // Airplane mode can be changed after ECM exits if airplane toggle button
1992 // is pressed during ECM mode
Daniel Bright4bcbfce2020-01-09 21:58:16 -08001993 if (!(intent.getBooleanExtra(TelephonyManager.EXTRA_PHONE_IN_ECM_STATE, false))
1994 && mIsWaitingForEcmExit) {
Jason Monk361915c2017-03-21 20:33:59 -04001995 mIsWaitingForEcmExit = false;
1996 changeAirplaneModeSystemSetting(true);
1997 }
1998 }
1999 }
2000 };
2001
2002 PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
2003 @Override
2004 public void onServiceStateChanged(ServiceState serviceState) {
2005 if (!mHasTelephony) return;
2006 final boolean inAirplaneMode = serviceState.getState() == ServiceState.STATE_POWER_OFF;
Lucas Dupincb6726f2020-04-07 19:32:38 -07002007 mAirplaneState = inAirplaneMode ? ToggleState.On : ToggleState.Off;
Jason Monk361915c2017-03-21 20:33:59 -04002008 mAirplaneModeOn.updateState(mAirplaneState);
2009 mAdapter.notifyDataSetChanged();
Aran Inkc58028b2020-06-04 15:33:22 -04002010 mOverflowAdapter.notifyDataSetChanged();
2011 mPowerAdapter.notifyDataSetChanged();
Jason Monk361915c2017-03-21 20:33:59 -04002012 }
2013 };
2014
Matt Pietal677981d2020-04-24 14:38:32 -04002015 private ContentObserver mAirplaneModeObserver = new ContentObserver(mMainHandler) {
Jason Monk361915c2017-03-21 20:33:59 -04002016 @Override
2017 public void onChange(boolean selfChange) {
2018 onAirplaneModeChanged();
2019 }
2020 };
2021
2022 private static final int MESSAGE_DISMISS = 0;
2023 private static final int MESSAGE_REFRESH = 1;
Jason Monk361915c2017-03-21 20:33:59 -04002024 private static final int DIALOG_DISMISS_DELAY = 300; // ms
Lucas Dupin7387a862020-04-13 10:15:29 -07002025 private static final int DIALOG_PRESS_DELAY = 850; // ms
Chris Wrenaf4ce8462020-04-06 17:36:10 -04002026
2027 @VisibleForTesting void setZeroDialogPressDelayForTesting() {
2028 mDialogPressDelay = 0; // ms
2029 }
Jason Monk361915c2017-03-21 20:33:59 -04002030
2031 private Handler mHandler = new Handler() {
2032 public void handleMessage(Message msg) {
2033 switch (msg.what) {
Jason Monk16fbd9d2017-04-27 14:28:49 -04002034 case MESSAGE_DISMISS:
2035 if (mDialog != null) {
Lucas Dupin1d4a5792018-04-02 15:14:59 -07002036 if (SYSTEM_DIALOG_REASON_DREAM.equals(msg.obj)) {
Matt Pietalf4b870b2020-04-17 17:11:36 -04002037 mDialog.completeDismiss();
Lucas Dupin1d4a5792018-04-02 15:14:59 -07002038 } else {
2039 mDialog.dismiss();
2040 }
Jason Monk16fbd9d2017-04-27 14:28:49 -04002041 mDialog = null;
2042 }
2043 break;
2044 case MESSAGE_REFRESH:
2045 refreshSilentMode();
2046 mAdapter.notifyDataSetChanged();
2047 break;
Jason Monk361915c2017-03-21 20:33:59 -04002048 }
2049 }
2050 };
2051
2052 private void onAirplaneModeChanged() {
2053 // Let the service state callbacks handle the state.
2054 if (mHasTelephony) return;
2055
2056 boolean airplaneModeOn = Settings.Global.getInt(
Dave Mankoffc88a2d72020-01-10 15:59:31 -05002057 mContentResolver,
Jason Monk361915c2017-03-21 20:33:59 -04002058 Settings.Global.AIRPLANE_MODE_ON,
2059 0) == 1;
Lucas Dupincb6726f2020-04-07 19:32:38 -07002060 mAirplaneState = airplaneModeOn ? ToggleState.On : ToggleState.Off;
Jason Monk361915c2017-03-21 20:33:59 -04002061 mAirplaneModeOn.updateState(mAirplaneState);
2062 }
2063
2064 /**
2065 * Change the airplane mode system setting
2066 */
2067 private void changeAirplaneModeSystemSetting(boolean on) {
2068 Settings.Global.putInt(
Dave Mankoffc88a2d72020-01-10 15:59:31 -05002069 mContentResolver,
Jason Monk361915c2017-03-21 20:33:59 -04002070 Settings.Global.AIRPLANE_MODE_ON,
2071 on ? 1 : 0);
2072 Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
2073 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
2074 intent.putExtra("state", on);
2075 mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
2076 if (!mHasTelephony) {
Lucas Dupincb6726f2020-04-07 19:32:38 -07002077 mAirplaneState = on ? ToggleState.On : ToggleState.Off;
Jason Monk361915c2017-03-21 20:33:59 -04002078 }
2079 }
2080
Fabian Kozynskib6a20372020-04-01 09:36:43 -04002081 @NonNull
2082 @Override
2083 public Lifecycle getLifecycle() {
2084 return mLifecycle;
2085 }
2086
Sean Pontd7ff85a2020-05-18 21:47:08 -07002087 @VisibleForTesting
2088 static final class ActionsDialog extends Dialog implements DialogInterface,
Lucas Dupinc1cc7592017-05-22 15:56:16 -07002089 ColorExtractor.OnColorsChangedListener {
Jason Monk361915c2017-03-21 20:33:59 -04002090
Jason Monk16fbd9d2017-04-27 14:28:49 -04002091 private final Context mContext;
2092 private final MyAdapter mAdapter;
Aran Inkcf038272020-03-31 17:48:37 -04002093 private final MyOverflowAdapter mOverflowAdapter;
Aran Inkc58028b2020-06-04 15:33:22 -04002094 private final MyPowerOptionsAdapter mPowerOptionsAdapter;
Steve Elliott53f12ae2019-05-13 17:14:15 -04002095 private final IStatusBarService mStatusBarService;
2096 private final IBinder mToken = new Binder();
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05002097 private MultiListLayout mGlobalActionsLayout;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04002098 private Drawable mBackgroundDrawable;
Lucas Dupin2bd3af62019-03-25 17:44:28 -07002099 private final SysuiColorExtractor mColorExtractor;
Sean Pontd7ff85a2020-05-18 21:47:08 -07002100 private final GlobalActionsPanelPlugin.PanelViewController mWalletViewController;
Lucas Dupinc1cc7592017-05-22 15:56:16 -07002101 private boolean mKeyguardShowing;
Beverly526d2d62018-08-15 12:55:33 -04002102 private boolean mShowing;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04002103 private float mScrimAlpha;
Steve Elliott48f75db2019-05-03 15:03:38 -04002104 private ResetOrientationData mResetOrientationData;
Steve Elliottff2c0d92019-07-30 15:09:54 -04002105 private boolean mHadTopUi;
wilsonshihe8321942019-10-18 18:39:46 +08002106 private final NotificationShadeWindowController mNotificationShadeWindowController;
Santiago Etchebehere68eb53e2020-02-25 14:25:34 -08002107 private final NotificationShadeDepthController mDepthController;
Winson Chung94674542020-05-15 10:35:55 -07002108 private final SysUiState mSysUiState;
Aran Inkcf038272020-03-31 17:48:37 -04002109 private ListPopupWindow mOverflowPopup;
Aran Ink143eea42020-06-16 19:18:49 -04002110 private Dialog mPowerOptionsDialog;
Aran Inka65e68362020-04-14 15:23:24 -04002111 private final Runnable mOnRotateCallback;
Sean Pontd7ff85a2020-05-18 21:47:08 -07002112 private final boolean mControlsAvailable;
Matt Pietal22231792020-01-23 09:51:09 -05002113
2114 private ControlsUiController mControlsUiController;
2115 private ViewGroup mControlsView;
Lucas Dupin5f9c8632020-04-20 14:47:43 -07002116 private ViewGroup mContainer;
Sean Pontd7ff85a2020-05-18 21:47:08 -07002117 @VisibleForTesting ViewGroup mLockMessageContainer;
2118 private TextView mLockMessage;
Jason Monk16fbd9d2017-04-27 14:28:49 -04002119
Aran Inkcf038272020-03-31 17:48:37 -04002120 ActionsDialog(Context context, MyAdapter adapter, MyOverflowAdapter overflowAdapter,
Sean Pontd7ff85a2020-05-18 21:47:08 -07002121 GlobalActionsPanelPlugin.PanelViewController walletViewController,
Santiago Etchebehere68eb53e2020-02-25 14:25:34 -08002122 NotificationShadeDepthController depthController,
Lucas Dupin991415e2019-11-25 17:48:58 -08002123 SysuiColorExtractor sysuiColorExtractor, IStatusBarService statusBarService,
2124 NotificationShadeWindowController notificationShadeWindowController,
Sean Pontd7ff85a2020-05-18 21:47:08 -07002125 boolean controlsAvailable, @Nullable ControlsUiController controlsUiController,
Aran Inkc58028b2020-06-04 15:33:22 -04002126 SysUiState sysuiState, Runnable onRotateCallback, boolean keyguardShowing,
2127 MyPowerOptionsAdapter powerAdapter) {
Lucas Dupinc1cc7592017-05-22 15:56:16 -07002128 super(context, com.android.systemui.R.style.Theme_SystemUI_Dialog_GlobalActions);
Lucas Dupin448786c2017-07-24 17:44:25 -07002129 mContext = context;
Jason Monk16fbd9d2017-04-27 14:28:49 -04002130 mAdapter = adapter;
Aran Inkcf038272020-03-31 17:48:37 -04002131 mOverflowAdapter = overflowAdapter;
Aran Inkc58028b2020-06-04 15:33:22 -04002132 mPowerOptionsAdapter = powerAdapter;
Santiago Etchebehere68eb53e2020-02-25 14:25:34 -08002133 mDepthController = depthController;
Lucas Dupin991415e2019-11-25 17:48:58 -08002134 mColorExtractor = sysuiColorExtractor;
2135 mStatusBarService = statusBarService;
2136 mNotificationShadeWindowController = notificationShadeWindowController;
Sean Pontd7ff85a2020-05-18 21:47:08 -07002137 mControlsAvailable = controlsAvailable;
Matt Pietal22231792020-01-23 09:51:09 -05002138 mControlsUiController = controlsUiController;
Winson Chung94674542020-05-15 10:35:55 -07002139 mSysUiState = sysuiState;
Aran Inka65e68362020-04-14 15:23:24 -04002140 mOnRotateCallback = onRotateCallback;
Aran Ink99c452d2020-04-28 14:23:13 -04002141 mKeyguardShowing = keyguardShowing;
Lucas Dupinc1cc7592017-05-22 15:56:16 -07002142
2143 // Window initialization
2144 Window window = getWindow();
2145 window.requestFeature(Window.FEATURE_NO_TITLE);
Adrian Roosedfab3b2018-03-08 18:39:20 +01002146 // Inflate the decor view, so the attributes below are not overwritten by the theme.
2147 window.getDecorView();
2148 window.getAttributes().systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
2149 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
2150 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
2151 window.setLayout(MATCH_PARENT, MATCH_PARENT);
2152 window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
Alison Cichowlas4f19f4a2017-07-25 10:56:16 -04002153 window.addFlags(
2154 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
Sean Pont9d4fb032020-03-04 18:54:32 -08002155 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
2156 | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
2157 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
2158 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
2159 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07002160 window.setType(WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY);
Tiger Huang52724442020-01-20 21:38:42 +08002161 window.getAttributes().setFitInsetsTypes(0 /* types */);
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05002162 setTitle(R.string.global_actions);
Steve Elliott9b87a442019-03-05 10:24:16 -05002163
Sean Pontd7ff85a2020-05-18 21:47:08 -07002164 mWalletViewController = walletViewController;
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04002165 initializeLayout();
Steve Elliott9b87a442019-03-05 10:24:16 -05002166 }
2167
Matt Pietal677981d2020-04-24 14:38:32 -04002168 private boolean isShowingControls() {
2169 return mControlsUiController != null;
2170 }
2171
2172 private void showControls(ControlsUiController controller) {
2173 mControlsUiController = controller;
2174 mControlsUiController.show(mControlsView, this::dismissForControlsActivity);
2175 }
2176
Sean Pontd7ff85a2020-05-18 21:47:08 -07002177 private void initializeWalletView() {
2178 if (mWalletViewController == null || mWalletViewController.getPanelContent() == null) {
2179 return;
2180 }
Aaron Heuckrothc7926612019-04-02 14:21:57 -04002181
Steve Elliott48f75db2019-05-03 15:03:38 -04002182 int rotation = RotationUtils.getRotation(mContext);
2183 boolean rotationLocked = RotationPolicy.isRotationLocked(mContext);
2184 if (rotation != RotationUtils.ROTATION_NONE) {
2185 if (rotationLocked) {
2186 if (mResetOrientationData == null) {
2187 mResetOrientationData = new ResetOrientationData();
2188 mResetOrientationData.locked = true;
2189 mResetOrientationData.rotation = rotation;
2190 }
2191
2192 // Unlock rotation, so user can choose to rotate to portrait to see the panel.
Steve Elliotte05817f2019-05-17 14:39:53 -04002193 // This call is posted so that the rotation does not change until post-layout,
2194 // otherwise onConfigurationChanged() may not get invoked.
2195 mGlobalActionsLayout.post(() ->
2196 RotationPolicy.setRotationLockAtAngle(
2197 mContext, false, RotationUtils.ROTATION_NONE));
Steve Elliott48f75db2019-05-03 15:03:38 -04002198 }
2199 } else {
2200 if (!rotationLocked) {
2201 if (mResetOrientationData == null) {
2202 mResetOrientationData = new ResetOrientationData();
2203 mResetOrientationData.locked = false;
2204 }
2205
2206 // Lock to portrait, so the user doesn't accidentally hide the panel.
Steve Elliotte05817f2019-05-17 14:39:53 -04002207 // This call is posted so that the rotation does not change until post-layout,
2208 // otherwise onConfigurationChanged() may not get invoked.
2209 mGlobalActionsLayout.post(() ->
2210 RotationPolicy.setRotationLockAtAngle(
2211 mContext, true, RotationUtils.ROTATION_NONE));
Steve Elliott48f75db2019-05-03 15:03:38 -04002212 }
2213
Steve Elliott53f12ae2019-05-13 17:14:15 -04002214 // Disable rotation suggestions, if enabled
2215 setRotationSuggestionsEnabled(false);
2216
Steve Elliott300b48f2019-05-29 14:13:50 -04002217 FrameLayout panelContainer =
Sean Pontd7ff85a2020-05-18 21:47:08 -07002218 findViewById(com.android.systemui.R.id.global_actions_wallet);
Steve Elliott48f75db2019-05-03 15:03:38 -04002219 FrameLayout.LayoutParams panelParams =
2220 new FrameLayout.LayoutParams(
2221 FrameLayout.LayoutParams.MATCH_PARENT,
Steve Elliott300b48f2019-05-29 14:13:50 -04002222 FrameLayout.LayoutParams.MATCH_PARENT);
Sean Pontd7ff85a2020-05-18 21:47:08 -07002223 if (!mControlsAvailable) {
2224 panelParams.topMargin = mContext.getResources().getDimensionPixelSize(
2225 com.android.systemui.R.dimen.global_actions_wallet_top_margin);
2226 }
2227 View walletView = mWalletViewController.getPanelContent();
Sean Pontfd537a52020-05-14 10:04:24 -07002228 panelContainer.addView(walletView, panelParams);
2229 // Smooth transitions when wallet is resized, which can happen when a card is added
2230 ViewGroup root = findViewById(com.android.systemui.R.id.global_actions_grid_root);
2231 if (root != null) {
2232 walletView.addOnLayoutChangeListener((v, l, t, r, b, ol, ot, or, ob) -> {
2233 int oldHeight = ob - ot;
2234 int newHeight = b - t;
2235 if (oldHeight > 0 && oldHeight != newHeight) {
2236 TransitionSet transition = new AutoTransition()
2237 .setDuration(250)
2238 .setOrdering(TransitionSet.ORDERING_TOGETHER);
2239 TransitionManager.beginDelayedTransition(root, transition);
2240 }
2241 });
2242 }
Steve Elliott48f75db2019-05-03 15:03:38 -04002243 }
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05002244 }
2245
Aran Inkcf038272020-03-31 17:48:37 -04002246 private ListPopupWindow createPowerOverflowPopup() {
Fabian Kozynski395aec92020-05-27 17:03:37 -04002247 GlobalActionsPopupMenu popup = new GlobalActionsPopupMenu(
Fabian Kozynski1144c972020-05-21 13:01:03 -04002248 new ContextThemeWrapper(
Fabian Kozynski395aec92020-05-27 17:03:37 -04002249 mContext,
2250 com.android.systemui.R.style.Control_ListPopupWindow
Fabian Kozynski1144c972020-05-21 13:01:03 -04002251 ), false /* isDropDownMode */);
Fabian Kozynski395aec92020-05-27 17:03:37 -04002252 popup.setOnItemClickListener(
2253 (parent, view, position, id) -> mOverflowAdapter.onClickItem(position));
2254 popup.setOnItemLongClickListener(
2255 (parent, view, position, id) -> mOverflowAdapter.onLongClickItem(position));
Aran Inkcf038272020-03-31 17:48:37 -04002256 View overflowButton =
2257 findViewById(com.android.systemui.R.id.global_actions_overflow_button);
2258 popup.setAnchorView(overflowButton);
Aran Inkcf038272020-03-31 17:48:37 -04002259 popup.setAdapter(mOverflowAdapter);
Aran Inkcf038272020-03-31 17:48:37 -04002260 return popup;
2261 }
2262
Aran Inkc58028b2020-06-04 15:33:22 -04002263 public void showPowerOptionsMenu() {
Aran Ink143eea42020-06-16 19:18:49 -04002264 mPowerOptionsDialog = GlobalActionsPowerDialog.create(mContext, mPowerOptionsAdapter);
2265 mPowerOptionsDialog.show();
Aran Inkc58028b2020-06-04 15:33:22 -04002266 }
2267
Aran Inkcf038272020-03-31 17:48:37 -04002268 private void showPowerOverflowMenu() {
Matt Pietalf74554f2020-04-29 13:43:55 -04002269 mOverflowPopup = createPowerOverflowPopup();
Aran Inkcf038272020-03-31 17:48:37 -04002270 mOverflowPopup.show();
2271 }
2272
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05002273 private void initializeLayout() {
Sean Pontd7ff85a2020-05-18 21:47:08 -07002274 setContentView(com.android.systemui.R.layout.global_actions_grid_v2);
Steve Elliott300b48f2019-05-29 14:13:50 -04002275 fixNavBarClipping();
Matt Pietal22231792020-01-23 09:51:09 -05002276 mControlsView = findViewById(com.android.systemui.R.id.global_actions_controls);
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04002277 mGlobalActionsLayout = findViewById(com.android.systemui.R.id.global_actions_view);
Aaron Heuckrothf708d472019-01-10 16:54:51 -05002278 mGlobalActionsLayout.setListViewAccessibilityDelegate(new View.AccessibilityDelegate() {
Phil Weaver9054e092018-04-27 16:28:50 -07002279 @Override
2280 public boolean dispatchPopulateAccessibilityEvent(
2281 View host, AccessibilityEvent event) {
2282 // Populate the title here, just as Activity does
2283 event.getText().add(mContext.getString(R.string.global_actions));
2284 return true;
2285 }
2286 });
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05002287 mGlobalActionsLayout.setRotationListener(this::onRotate);
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05002288 mGlobalActionsLayout.setAdapter(mAdapter);
Lucas Dupin5f9c8632020-04-20 14:47:43 -07002289 mContainer = findViewById(com.android.systemui.R.id.global_actions_container);
Sean Pontd7ff85a2020-05-18 21:47:08 -07002290 mLockMessageContainer = requireViewById(
2291 com.android.systemui.R.id.global_actions_lock_message_container);
2292 mLockMessage = requireViewById(com.android.systemui.R.id.global_actions_lock_message);
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04002293
Aran Inkcf038272020-03-31 17:48:37 -04002294 View overflowButton = findViewById(
2295 com.android.systemui.R.id.global_actions_overflow_button);
2296 if (overflowButton != null) {
Matt Pietal677981d2020-04-24 14:38:32 -04002297 if (mOverflowAdapter.getCount() > 0) {
Aran Inkcf038272020-03-31 17:48:37 -04002298 overflowButton.setOnClickListener((view) -> showPowerOverflowMenu());
Aran Ink7c8fea92020-04-17 14:40:14 -04002299 LinearLayout.LayoutParams params =
2300 (LinearLayout.LayoutParams) mGlobalActionsLayout.getLayoutParams();
2301 params.setMarginEnd(0);
2302 mGlobalActionsLayout.setLayoutParams(params);
Aran Inkcf038272020-03-31 17:48:37 -04002303 } else {
2304 overflowButton.setVisibility(View.GONE);
Aran Ink7c8fea92020-04-17 14:40:14 -04002305 LinearLayout.LayoutParams params =
2306 (LinearLayout.LayoutParams) mGlobalActionsLayout.getLayoutParams();
2307 params.setMarginEnd(mContext.getResources().getDimensionPixelSize(
2308 com.android.systemui.R.dimen.global_actions_side_margin));
2309 mGlobalActionsLayout.setLayoutParams(params);
Aran Inkcf038272020-03-31 17:48:37 -04002310 }
2311 }
2312
Sean Pontd7ff85a2020-05-18 21:47:08 -07002313 initializeWalletView();
Steve Elliott86ef6282019-05-08 14:45:04 -04002314 if (mBackgroundDrawable == null) {
2315 mBackgroundDrawable = new ScrimDrawable();
Sean Pontd7ff85a2020-05-18 21:47:08 -07002316 mScrimAlpha = 1.0f;
Steve Elliott86ef6282019-05-08 14:45:04 -04002317 }
Steve Elliotte9e7e1f2019-03-18 15:54:59 -04002318 getWindow().setBackgroundDrawable(mBackgroundDrawable);
Steve Elliott9b87a442019-03-05 10:24:16 -05002319 }
2320
Steve Elliott300b48f2019-05-29 14:13:50 -04002321 private void fixNavBarClipping() {
2322 ViewGroup content = findViewById(android.R.id.content);
2323 content.setClipChildren(false);
2324 content.setClipToPadding(false);
2325 ViewGroup contentParent = (ViewGroup) content.getParent();
2326 contentParent.setClipChildren(false);
2327 contentParent.setClipToPadding(false);
2328 }
2329
Jason Monk361915c2017-03-21 20:33:59 -04002330 @Override
2331 protected void onStart() {
2332 super.setCanceledOnTouchOutside(true);
2333 super.onStart();
Aaron Heuckroth57d60d22019-03-05 14:00:12 -05002334 mGlobalActionsLayout.updateList();
Lucas Dupinc1cc7592017-05-22 15:56:16 -07002335
Lucas Dupin2bd3af62019-03-25 17:44:28 -07002336 if (mBackgroundDrawable instanceof ScrimDrawable) {
Steve Elliott9b87a442019-03-05 10:24:16 -05002337 mColorExtractor.addOnColorsChangedListener(this);
Lucas Dupin2bd3af62019-03-25 17:44:28 -07002338 GradientColors colors = mColorExtractor.getNeutralColors();
Steve Elliott9b87a442019-03-05 10:24:16 -05002339 updateColors(colors, false /* animate */);
2340 }
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07002341 }
2342
2343 /**
2344 * Updates background and system bars according to current GradientColors.
Sean Pont9d4fb032020-03-04 18:54:32 -08002345 *
2346 * @param colors Colors and hints to use.
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07002347 * @param animate Interpolates gradient if true, just sets otherwise.
2348 */
2349 private void updateColors(GradientColors colors, boolean animate) {
Lucas Dupin2bd3af62019-03-25 17:44:28 -07002350 if (!(mBackgroundDrawable instanceof ScrimDrawable)) {
Steve Elliott9b87a442019-03-05 10:24:16 -05002351 return;
2352 }
Sean Pontd7ff85a2020-05-18 21:47:08 -07002353 ((ScrimDrawable) mBackgroundDrawable).setColor(Color.BLACK, animate);
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07002354 View decorView = getWindow().getDecorView();
2355 if (colors.supportsDarkText()) {
2356 decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR |
Steve Elliott9b87a442019-03-05 10:24:16 -05002357 View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07002358 } else {
2359 decorView.setSystemUiVisibility(0);
2360 }
Jason Monk361915c2017-03-21 20:33:59 -04002361 }
2362
2363 @Override
Jason Monk16fbd9d2017-04-27 14:28:49 -04002364 protected void onStop() {
2365 super.onStop();
Lucas Dupinc1cc7592017-05-22 15:56:16 -07002366 mColorExtractor.removeOnColorsChangedListener(this);
Jason Monk16fbd9d2017-04-27 14:28:49 -04002367 }
2368
2369 @Override
2370 public void show() {
2371 super.show();
Beverly526d2d62018-08-15 12:55:33 -04002372 mShowing = true;
wilsonshihe8321942019-10-18 18:39:46 +08002373 mHadTopUi = mNotificationShadeWindowController.getForceHasTopUi();
2374 mNotificationShadeWindowController.setForceHasTopUi(true);
Winson Chung94674542020-05-15 10:35:55 -07002375 mSysUiState.setFlag(SYSUI_STATE_GLOBAL_ACTIONS_SHOWING, true)
2376 .commitUpdate(mContext.getDisplayId());
Matt Pietale9440b72020-05-01 11:36:01 -04002377
Lucas Dupin26571e92020-04-08 14:55:10 -07002378 ViewGroup root = (ViewGroup) mGlobalActionsLayout.getRootView();
2379 root.setOnApplyWindowInsetsListener((v, windowInsets) -> {
Sean Pontd7ff85a2020-05-18 21:47:08 -07002380 root.setPadding(windowInsets.getStableInsetLeft(),
2381 windowInsets.getStableInsetTop(),
2382 windowInsets.getStableInsetRight(),
2383 windowInsets.getStableInsetBottom());
Lucas Dupin26571e92020-04-08 14:55:10 -07002384 return WindowInsets.CONSUMED;
2385 });
Matt Pietal22231792020-01-23 09:51:09 -05002386 if (mControlsUiController != null) {
Matt Pietalf4b870b2020-04-17 17:11:36 -04002387 mControlsUiController.show(mControlsView, this::dismissForControlsActivity);
Matt Pietal22231792020-01-23 09:51:09 -05002388 }
Matt Pietale9440b72020-05-01 11:36:01 -04002389
2390 mBackgroundDrawable.setAlpha(0);
2391 float xOffset = mGlobalActionsLayout.getAnimationOffsetX();
2392 ObjectAnimator alphaAnimator =
Matt Pietaldc6bb1d2020-05-14 13:33:41 -04002393 ObjectAnimator.ofFloat(mContainer, "alpha", 0f, 1f);
Matt Pietale9440b72020-05-01 11:36:01 -04002394 alphaAnimator.setInterpolator(Interpolators.LINEAR_OUT_SLOW_IN);
2395 alphaAnimator.setDuration(183);
2396 alphaAnimator.addUpdateListener((animation) -> {
2397 float animatedValue = animation.getAnimatedFraction();
2398 int alpha = (int) (animatedValue * mScrimAlpha * 255);
2399 mBackgroundDrawable.setAlpha(alpha);
2400 mDepthController.updateGlobalDialogVisibility(animatedValue,
2401 mGlobalActionsLayout);
2402 });
2403
2404 ObjectAnimator xAnimator =
2405 ObjectAnimator.ofFloat(mContainer, "translationX", xOffset, 0f);
Matt Pietaldc6bb1d2020-05-14 13:33:41 -04002406 xAnimator.setInterpolator(Interpolators.LINEAR_OUT_SLOW_IN);
2407 xAnimator.setDuration(350);
Matt Pietale9440b72020-05-01 11:36:01 -04002408
2409 AnimatorSet animatorSet = new AnimatorSet();
2410 animatorSet.playTogether(alphaAnimator, xAnimator);
2411 animatorSet.start();
Jason Monk16fbd9d2017-04-27 14:28:49 -04002412 }
2413
2414 @Override
2415 public void dismiss() {
Matt Pietalf4b870b2020-04-17 17:11:36 -04002416 dismissWithAnimation(() -> {
Lucas Dupin5f9c8632020-04-20 14:47:43 -07002417 mContainer.setTranslationX(0);
Matt Pietale9440b72020-05-01 11:36:01 -04002418 ObjectAnimator alphaAnimator =
Matt Pietaldc6bb1d2020-05-14 13:33:41 -04002419 ObjectAnimator.ofFloat(mContainer, "alpha", 1f, 0f);
Matt Pietale9440b72020-05-01 11:36:01 -04002420 alphaAnimator.setInterpolator(Interpolators.FAST_OUT_LINEAR_IN);
2421 alphaAnimator.setDuration(233);
2422 alphaAnimator.addUpdateListener((animation) -> {
2423 float animatedValue = 1f - animation.getAnimatedFraction();
2424 int alpha = (int) (animatedValue * mScrimAlpha * 255);
2425 mBackgroundDrawable.setAlpha(alpha);
2426 mDepthController.updateGlobalDialogVisibility(animatedValue,
2427 mGlobalActionsLayout);
2428 });
2429
2430 float xOffset = mGlobalActionsLayout.getAnimationOffsetX();
2431 ObjectAnimator xAnimator =
2432 ObjectAnimator.ofFloat(mContainer, "translationX", 0f, xOffset);
Matt Pietaldc6bb1d2020-05-14 13:33:41 -04002433 xAnimator.setInterpolator(Interpolators.FAST_OUT_LINEAR_IN);
2434 xAnimator.setDuration(350);
Matt Pietale9440b72020-05-01 11:36:01 -04002435
2436 AnimatorSet animatorSet = new AnimatorSet();
2437 animatorSet.playTogether(alphaAnimator, xAnimator);
2438 animatorSet.addListener(new AnimatorListenerAdapter() {
2439 public void onAnimationEnd(Animator animation) {
2440 completeDismiss();
2441 }
2442 });
2443
2444 animatorSet.start();
2445
2446 // close first, as popup windows will not fade during the animation
2447 dismissOverflow(false);
Aran Inkc58028b2020-06-04 15:33:22 -04002448 dismissPowerOptions(false);
Matt Pietale9440b72020-05-01 11:36:01 -04002449 if (mControlsUiController != null) mControlsUiController.closeDialogs(false);
Matt Pietalf4b870b2020-04-17 17:11:36 -04002450 });
2451 }
2452
2453 private void dismissForControlsActivity() {
2454 dismissWithAnimation(() -> {
Matt Pietald8a6ca62020-04-21 15:00:15 -04002455 ViewGroup root = (ViewGroup) mGlobalActionsLayout.getParent();
Matt Pietalf4b870b2020-04-17 17:11:36 -04002456 ControlsAnimations.exitAnimation(root, this::completeDismiss).start();
2457 });
2458 }
2459
2460 void dismissWithAnimation(Runnable animation) {
Beverly526d2d62018-08-15 12:55:33 -04002461 if (!mShowing) {
2462 return;
2463 }
2464 mShowing = false;
Matt Pietalf4b870b2020-04-17 17:11:36 -04002465 animation.run();
Steve Elliottff2c0d92019-07-30 15:09:54 -04002466 }
2467
2468 private void completeDismiss() {
Matt Pietalf4b870b2020-04-17 17:11:36 -04002469 mShowing = false;
2470 resetOrientation();
Sean Pontd7ff85a2020-05-18 21:47:08 -07002471 dismissWallet();
Aran Inkd397b902020-04-21 17:53:41 -04002472 dismissOverflow(true);
Aran Inkc58028b2020-06-04 15:33:22 -04002473 dismissPowerOptions(true);
Matt Pietalf4b870b2020-04-17 17:11:36 -04002474 if (mControlsUiController != null) mControlsUiController.hide();
wilsonshihe8321942019-10-18 18:39:46 +08002475 mNotificationShadeWindowController.setForceHasTopUi(mHadTopUi);
Lucas Dupin77198562020-03-31 14:16:16 -07002476 mDepthController.updateGlobalDialogVisibility(0, null /* view */);
Winson Chung94674542020-05-15 10:35:55 -07002477 mSysUiState.setFlag(SYSUI_STATE_GLOBAL_ACTIONS_SHOWING, false)
2478 .commitUpdate(mContext.getDisplayId());
Steve Elliottff2c0d92019-07-30 15:09:54 -04002479 super.dismiss();
Steve Elliott48f75db2019-05-03 15:03:38 -04002480 }
2481
Sean Pontd7ff85a2020-05-18 21:47:08 -07002482 private void dismissWallet() {
2483 if (mWalletViewController != null) {
2484 mWalletViewController.onDismissed();
Steve Elliott2d206d32019-03-14 16:30:33 -04002485 }
Lucas Dupin1d4a5792018-04-02 15:14:59 -07002486 }
2487
Aran Inkd397b902020-04-21 17:53:41 -04002488 private void dismissOverflow(boolean immediate) {
Aran Ink6560ab72020-04-20 16:04:29 -04002489 if (mOverflowPopup != null) {
Aran Inkd397b902020-04-21 17:53:41 -04002490 if (immediate) {
2491 mOverflowPopup.dismissImmediate();
2492 } else {
2493 mOverflowPopup.dismiss();
2494 }
Aran Ink6560ab72020-04-20 16:04:29 -04002495 }
2496 }
2497
Aran Inkc58028b2020-06-04 15:33:22 -04002498 private void dismissPowerOptions(boolean immediate) {
Aran Ink143eea42020-06-16 19:18:49 -04002499 if (mPowerOptionsDialog != null) {
Aran Inkc58028b2020-06-04 15:33:22 -04002500 if (immediate) {
Aran Ink143eea42020-06-16 19:18:49 -04002501 mPowerOptionsDialog.dismiss();
Aran Inkc58028b2020-06-04 15:33:22 -04002502 } else {
Aran Ink143eea42020-06-16 19:18:49 -04002503 mPowerOptionsDialog.dismiss();
Aran Inkc58028b2020-06-04 15:33:22 -04002504 }
2505 }
2506 }
2507
Steve Elliott53f12ae2019-05-13 17:14:15 -04002508 private void setRotationSuggestionsEnabled(boolean enabled) {
2509 try {
2510 final int userId = Binder.getCallingUserHandle().getIdentifier();
2511 final int what = enabled
2512 ? StatusBarManager.DISABLE2_NONE
2513 : StatusBarManager.DISABLE2_ROTATE_SUGGESTIONS;
2514 mStatusBarService.disable2ForUser(what, mToken, mContext.getPackageName(), userId);
2515 } catch (RemoteException ex) {
2516 throw ex.rethrowFromSystemServer();
2517 }
2518 }
2519
Steve Elliott48f75db2019-05-03 15:03:38 -04002520 private void resetOrientation() {
2521 if (mResetOrientationData != null) {
2522 RotationPolicy.setRotationLockAtAngle(mContext, mResetOrientationData.locked,
2523 mResetOrientationData.rotation);
2524 }
Steve Elliott53f12ae2019-05-13 17:14:15 -04002525 setRotationSuggestionsEnabled(true);
Steve Elliott48f75db2019-05-03 15:03:38 -04002526 }
2527
Jason Monk361915c2017-03-21 20:33:59 -04002528 @Override
Lucas Dupin7aaa3532017-05-28 08:51:07 -07002529 public void onColorsChanged(ColorExtractor extractor, int which) {
Lucas Dupinc1cc7592017-05-22 15:56:16 -07002530 if (mKeyguardShowing) {
2531 if ((WallpaperManager.FLAG_LOCK & which) != 0) {
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07002532 updateColors(extractor.getColors(WallpaperManager.FLAG_LOCK),
2533 true /* animate */);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07002534 }
2535 } else {
2536 if ((WallpaperManager.FLAG_SYSTEM & which) != 0) {
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07002537 updateColors(extractor.getColors(WallpaperManager.FLAG_SYSTEM),
2538 true /* animate */);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07002539 }
2540 }
2541 }
2542
2543 public void setKeyguardShowing(boolean keyguardShowing) {
2544 mKeyguardShowing = keyguardShowing;
2545 }
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05002546
Aaron Heuckroth4ef3a542019-04-01 14:17:23 -04002547 public void refreshDialog() {
Aran Ink00200c92020-05-12 14:15:43 -04002548 // ensure dropdown menus are dismissed before re-initializing the dialog
Sean Pontd7ff85a2020-05-18 21:47:08 -07002549 dismissWallet();
Aran Ink00200c92020-05-12 14:15:43 -04002550 dismissOverflow(true);
Aran Inkc58028b2020-06-04 15:33:22 -04002551 dismissPowerOptions(true);
Aran Ink00200c92020-05-12 14:15:43 -04002552 if (mControlsUiController != null) {
2553 mControlsUiController.hide();
2554 }
2555
2556 // re-create dialog
Aaron Heuckroth4ef3a542019-04-01 14:17:23 -04002557 initializeLayout();
2558 mGlobalActionsLayout.updateList();
Aran Inka65e68362020-04-14 15:23:24 -04002559 if (mControlsUiController != null) {
Matt Pietalf4b870b2020-04-17 17:11:36 -04002560 mControlsUiController.show(mControlsView, this::dismissForControlsActivity);
Aran Inka65e68362020-04-14 15:23:24 -04002561 }
Aaron Heuckroth4ef3a542019-04-01 14:17:23 -04002562 }
2563
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05002564 public void onRotate(int from, int to) {
Aaron Heuckrothe2d92ac2019-05-01 10:44:59 -04002565 if (mShowing) {
Aran Inka65e68362020-04-14 15:23:24 -04002566 mOnRotateCallback.run();
Aaron Heuckroth4ef3a542019-04-01 14:17:23 -04002567 refreshDialog();
Aaron Heuckroth4ea2fdb2019-02-14 16:28:35 -05002568 }
2569 }
Steve Elliott48f75db2019-05-03 15:03:38 -04002570
Sean Pontd7ff85a2020-05-18 21:47:08 -07002571 void hideLockMessage() {
2572 if (mLockMessageContainer.getVisibility() == View.VISIBLE) {
2573 mLockMessageContainer.animate().alpha(0).setDuration(150).setListener(
2574 new AnimatorListenerAdapter() {
2575 @Override
2576 public void onAnimationEnd(Animator animation) {
2577 mLockMessageContainer.setVisibility(View.GONE);
2578 }
2579 }).start();
2580 }
2581 }
2582
2583 void showLockMessage() {
2584 Drawable lockIcon = mContext.getDrawable(com.android.internal.R.drawable.ic_lock);
2585 lockIcon.setTint(mContext.getColor(com.android.systemui.R.color.control_primary_text));
2586 mLockMessage.setCompoundDrawablesWithIntrinsicBounds(null, lockIcon, null, null);
2587 mLockMessageContainer.setVisibility(View.VISIBLE);
2588 }
2589
Steve Elliott48f75db2019-05-03 15:03:38 -04002590 private static class ResetOrientationData {
2591 public boolean locked;
2592 public int rotation;
2593 }
Jason Monk361915c2017-03-21 20:33:59 -04002594 }
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05002595
2596 /**
Aran Ink93dd25c2019-05-09 14:42:14 -04002597 * Determines whether or not debug mode has been activated for the Global Actions Panel.
2598 */
2599 private static boolean isPanelDebugModeEnabled(Context context) {
2600 return Settings.Secure.getInt(context.getContentResolver(),
2601 Settings.Secure.GLOBAL_ACTIONS_PANEL_DEBUG_ENABLED, 0) == 1;
2602 }
2603
2604 /**
Sean Pont9d4fb032020-03-04 18:54:32 -08002605 * Determines whether or not the Global Actions menu should be forced to use the newer
2606 * grid-style layout.
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05002607 */
Aaron Heuckrothc7926612019-04-02 14:21:57 -04002608 private static boolean isForceGridEnabled(Context context) {
Aran Ink93dd25c2019-05-09 14:42:14 -04002609 return isPanelDebugModeEnabled(context);
Aaron Heuckroth75e249f2019-02-01 15:59:57 -05002610 }
Aaron Heuckrothf19d2722019-03-11 17:06:02 -04002611
Sean Pontd7ff85a2020-05-18 21:47:08 -07002612 private boolean shouldShowControls() {
Sean Pontae760072020-05-12 11:21:27 -07002613 return (mKeyguardStateController.isUnlocked() || mShowLockScreenCardsAndControls)
Matt Pietal50b661a2020-06-17 11:01:54 -04002614 && controlsAvailable()
2615 && mLockPatternUtils.getStrongAuthForUser(getCurrentUser().id)
2616 != STRONG_AUTH_REQUIRED_AFTER_BOOT;
Matt Pietalfd3b6cb2020-01-08 09:43:54 -05002617 }
Sean Pontd7ff85a2020-05-18 21:47:08 -07002618
2619 private boolean controlsAvailable() {
2620 return mDeviceProvisioned
Fabian Kozynski137951c2020-05-26 15:13:52 -04002621 && mControlsUiControllerOptional.isPresent()
2622 && mControlsUiControllerOptional.get().getAvailable()
Sean Pontd7ff85a2020-05-18 21:47:08 -07002623 && !mControlsServiceInfos.isEmpty();
2624 }
2625
Matt Pietal50b661a2020-06-17 11:01:54 -04002626 private boolean walletViewAvailable() {
2627 GlobalActionsPanelPlugin.PanelViewController walletViewController =
2628 getWalletViewController();
2629 return walletViewController != null && walletViewController.getPanelContent() != null;
2630 }
2631
2632 private boolean shouldShowLockMessage() {
2633 boolean isLockedAfterBoot = mLockPatternUtils.getStrongAuthForUser(getCurrentUser().id)
2634 == STRONG_AUTH_REQUIRED_AFTER_BOOT;
Sean Pontd7ff85a2020-05-18 21:47:08 -07002635 return !mKeyguardStateController.isUnlocked()
Matt Pietal50b661a2020-06-17 11:01:54 -04002636 && (!mShowLockScreenCardsAndControls || isLockedAfterBoot)
2637 && (controlsAvailable() || walletViewAvailable());
Aran Inka65e68362020-04-14 15:23:24 -04002638 }
Matt Pietal677981d2020-04-24 14:38:32 -04002639
2640 private void onPowerMenuLockScreenSettingsChanged() {
2641 mShowLockScreenCardsAndControls = Settings.Secure.getInt(mContentResolver,
2642 Settings.Secure.POWER_MENU_LOCKED_SHOW_CONTENT, 0) != 0;
2643 }
Matt Pietalf4b870b2020-04-17 17:11:36 -04002644}