Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
| 15 | package com.android.systemui.globalactions; |
| 16 | |
Adrian Roos | edfab3b | 2018-03-08 18:39:20 +0100 | [diff] [blame] | 17 | import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; |
Adrian Roos | 2f05bb3 | 2018-02-19 16:42:27 +0100 | [diff] [blame] | 18 | import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; |
| 19 | |
Chad Brubaker | f4075fe | 2018-01-03 13:23:22 -0800 | [diff] [blame] | 20 | import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_USER_REQUEST; |
| 21 | import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_NOT_REQUIRED; |
Chad Brubaker | 4f28f0d | 2017-09-07 14:28:13 -0700 | [diff] [blame] | 22 | import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN; |
| 23 | |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 24 | import android.annotation.Nullable; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 25 | import android.app.ActivityManager; |
| 26 | import android.app.Dialog; |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 27 | import android.app.IActivityManager; |
Steve Elliott | 4c86885 | 2019-03-14 16:25:41 -0400 | [diff] [blame] | 28 | import android.app.PendingIntent; |
Steve Elliott | 53f12ae | 2019-05-13 17:14:15 -0400 | [diff] [blame] | 29 | import android.app.StatusBarManager; |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 30 | import android.app.WallpaperManager; |
Alex Chau | 0445885 | 2017-11-27 18:21:23 +0000 | [diff] [blame] | 31 | import android.app.admin.DevicePolicyManager; |
Pavel Grafov | 059021b | 2018-05-02 13:44:46 +0100 | [diff] [blame] | 32 | import android.app.trust.TrustManager; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 33 | import android.content.BroadcastReceiver; |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 34 | import android.content.ContentResolver; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 35 | import android.content.Context; |
| 36 | import android.content.DialogInterface; |
| 37 | import android.content.Intent; |
| 38 | import android.content.IntentFilter; |
| 39 | import android.content.pm.UserInfo; |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 40 | import android.content.res.Resources; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 41 | import android.database.ContentObserver; |
Matt Pietal | e0661b6 | 2020-01-29 14:35:31 -0500 | [diff] [blame] | 42 | import android.graphics.Color; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 43 | import android.graphics.drawable.Drawable; |
| 44 | import android.media.AudioManager; |
| 45 | import android.net.ConnectivityManager; |
Steve Elliott | 53f12ae | 2019-05-13 17:14:15 -0400 | [diff] [blame] | 46 | import android.os.Binder; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 47 | import android.os.Handler; |
Steve Elliott | 53f12ae | 2019-05-13 17:14:15 -0400 | [diff] [blame] | 48 | import android.os.IBinder; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 49 | import android.os.Message; |
| 50 | import android.os.RemoteException; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 51 | import android.os.SystemProperties; |
| 52 | import android.os.UserHandle; |
| 53 | import android.os.UserManager; |
| 54 | import android.os.Vibrator; |
| 55 | import android.provider.Settings; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 56 | import android.service.dreams.IDreamManager; |
Inseob Kim | 5e82f73 | 2019-11-08 15:08:38 +0900 | [diff] [blame] | 57 | import android.sysprop.TelephonyProperties; |
Fan Zhang | f991476 | 2019-11-01 15:58:38 -0700 | [diff] [blame] | 58 | import android.telecom.TelecomManager; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 59 | import android.telephony.PhoneStateListener; |
| 60 | import android.telephony.ServiceState; |
| 61 | import android.telephony.TelephonyManager; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 62 | import android.util.ArraySet; |
yuanjiahsu | 88363e9 | 2018-09-06 19:23:52 +0800 | [diff] [blame] | 63 | import android.util.FeatureFlagUtils; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 64 | import android.util.Log; |
Lucas Dupin | 448786c | 2017-07-24 17:44:25 -0700 | [diff] [blame] | 65 | import android.view.ContextThemeWrapper; |
Dave Mankoff | 8df818e | 2020-02-12 14:22:26 -0500 | [diff] [blame] | 66 | import android.view.IWindowManager; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 67 | import android.view.LayoutInflater; |
| 68 | import android.view.View; |
| 69 | import android.view.ViewGroup; |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 70 | import android.view.Window; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 71 | import android.view.WindowManager; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 72 | import android.view.accessibility.AccessibilityEvent; |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 73 | import android.widget.FrameLayout; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 74 | import android.widget.ImageView; |
| 75 | import android.widget.ImageView.ScaleType; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 76 | import android.widget.TextView; |
| 77 | |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 78 | import com.android.internal.R; |
| 79 | import com.android.internal.colorextraction.ColorExtractor; |
| 80 | import com.android.internal.colorextraction.ColorExtractor.GradientColors; |
Lucas Dupin | 2bd3af6 | 2019-03-25 17:44:28 -0700 | [diff] [blame] | 81 | import com.android.internal.colorextraction.drawable.ScrimDrawable; |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 82 | import com.android.internal.logging.MetricsLogger; |
| 83 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Steve Elliott | 53f12ae | 2019-05-13 17:14:15 -0400 | [diff] [blame] | 84 | import com.android.internal.statusbar.IStatusBarService; |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 85 | import com.android.internal.util.EmergencyAffordanceManager; |
Beth Thibodeau | 5898ac4 | 2018-10-26 13:00:09 -0400 | [diff] [blame] | 86 | import com.android.internal.util.ScreenRecordHelper; |
Alison Cichowlas | a2cd19e | 2017-12-06 10:51:21 -0500 | [diff] [blame] | 87 | import com.android.internal.util.ScreenshotHelper; |
Steve Elliott | 48f75db | 2019-05-03 15:03:38 -0400 | [diff] [blame] | 88 | import com.android.internal.view.RotationPolicy; |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 89 | import com.android.internal.widget.LockPatternUtils; |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 90 | import com.android.systemui.Interpolators; |
Aaron Heuckroth | f708d47 | 2019-01-10 16:54:51 -0500 | [diff] [blame] | 91 | import com.android.systemui.MultiListLayout; |
Aaron Heuckroth | 57d60d2 | 2019-03-05 14:00:12 -0500 | [diff] [blame] | 92 | import com.android.systemui.MultiListLayout.MultiListAdapter; |
Fabian Kozynski | ff5e91f | 2019-09-24 15:38:08 -0400 | [diff] [blame] | 93 | import com.android.systemui.broadcast.BroadcastDispatcher; |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 94 | import com.android.systemui.colorextraction.SysuiColorExtractor; |
Fabian Kozynski | 0424ab1 | 2020-02-21 12:09:17 -0500 | [diff] [blame] | 95 | import com.android.systemui.controls.management.ControlsListingController; |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 96 | import com.android.systemui.controls.ui.ControlsUiController; |
Dave Mankoff | 8df818e | 2020-02-12 14:22:26 -0500 | [diff] [blame] | 97 | import com.android.systemui.dagger.qualifiers.Background; |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 98 | import com.android.systemui.dagger.qualifiers.Main; |
Steve Elliott | 4c86885 | 2019-03-14 16:25:41 -0400 | [diff] [blame] | 99 | import com.android.systemui.plugins.ActivityStarter; |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 100 | import com.android.systemui.plugins.GlobalActions.GlobalActionsManager; |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 101 | import com.android.systemui.plugins.GlobalActionsPanelPlugin; |
Lucas Dupin | 99f5fba | 2020-03-12 12:59:18 -0700 | [diff] [blame^] | 102 | import com.android.systemui.statusbar.BlurUtils; |
Santiago Etchebehere | 68eb53e | 2020-02-25 14:25:34 -0800 | [diff] [blame] | 103 | import com.android.systemui.statusbar.NotificationShadeDepthController; |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 104 | import com.android.systemui.statusbar.phone.NotificationShadeWindowController; |
Lucas Dupin | 43d0124 | 2020-02-03 11:58:33 -0800 | [diff] [blame] | 105 | import com.android.systemui.statusbar.phone.ScrimController; |
Lucas Dupin | e5b7dc7 | 2018-10-02 15:18:05 -0700 | [diff] [blame] | 106 | import com.android.systemui.statusbar.policy.ConfigurationController; |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 107 | import com.android.systemui.statusbar.policy.KeyguardStateController; |
Shaotang Li | 5c42263 | 2018-07-04 14:18:40 +0800 | [diff] [blame] | 108 | import com.android.systemui.util.EmergencyDialerConstants; |
Aaron Heuckroth | 75e249f | 2019-02-01 15:59:57 -0500 | [diff] [blame] | 109 | import com.android.systemui.util.leak.RotationUtils; |
Julia Reynolds | 4241192 | 2017-11-08 11:19:09 -0500 | [diff] [blame] | 110 | import com.android.systemui.volume.SystemUIInterpolators.LogAccelerateInterpolator; |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 111 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 112 | import java.util.ArrayList; |
| 113 | import java.util.List; |
Dave Mankoff | 8df818e | 2020-02-12 14:22:26 -0500 | [diff] [blame] | 114 | import java.util.concurrent.Executor; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 115 | |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 116 | import javax.inject.Inject; |
| 117 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 118 | /** |
| 119 | * Helper to show the global actions dialog. Each item is an {@link Action} that |
| 120 | * may show depending on whether the keyguard is showing, and whether the device |
| 121 | * is provisioned. |
| 122 | */ |
Aaron Heuckroth | 57d60d2 | 2019-03-05 14:00:12 -0500 | [diff] [blame] | 123 | public class GlobalActionsDialog implements DialogInterface.OnDismissListener, |
| 124 | DialogInterface.OnShowListener, ConfigurationController.ConfigurationListener { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 125 | |
| 126 | static public final String SYSTEM_DIALOG_REASON_KEY = "reason"; |
| 127 | static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions"; |
Lucas Dupin | 1d4a579 | 2018-04-02 15:14:59 -0700 | [diff] [blame] | 128 | static public final String SYSTEM_DIALOG_REASON_DREAM = "dream"; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 129 | |
| 130 | private static final String TAG = "GlobalActionsDialog"; |
| 131 | |
| 132 | private static final boolean SHOW_SILENT_TOGGLE = true; |
| 133 | |
| 134 | /* Valid settings for global actions keys. |
| 135 | * see config.xml config_globalActionList */ |
| 136 | private static final String GLOBAL_ACTION_KEY_POWER = "power"; |
| 137 | private static final String GLOBAL_ACTION_KEY_AIRPLANE = "airplane"; |
| 138 | private static final String GLOBAL_ACTION_KEY_BUGREPORT = "bugreport"; |
| 139 | private static final String GLOBAL_ACTION_KEY_SILENT = "silent"; |
| 140 | private static final String GLOBAL_ACTION_KEY_USERS = "users"; |
| 141 | private static final String GLOBAL_ACTION_KEY_SETTINGS = "settings"; |
| 142 | private static final String GLOBAL_ACTION_KEY_LOCKDOWN = "lockdown"; |
| 143 | private static final String GLOBAL_ACTION_KEY_VOICEASSIST = "voiceassist"; |
| 144 | private static final String GLOBAL_ACTION_KEY_ASSIST = "assist"; |
| 145 | private static final String GLOBAL_ACTION_KEY_RESTART = "restart"; |
Alex Chau | 0445885 | 2017-11-27 18:21:23 +0000 | [diff] [blame] | 146 | private static final String GLOBAL_ACTION_KEY_LOGOUT = "logout"; |
Wesley.CW Wang | 8d07276 | 2018-05-28 16:39:27 +0800 | [diff] [blame] | 147 | private static final String GLOBAL_ACTION_KEY_EMERGENCY = "emergency"; |
Alison Cichowlas | a2cd19e | 2017-12-06 10:51:21 -0500 | [diff] [blame] | 148 | private static final String GLOBAL_ACTION_KEY_SCREENSHOT = "screenshot"; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 149 | |
| 150 | private final Context mContext; |
| 151 | private final GlobalActionsManager mWindowManagerFuncs; |
| 152 | private final AudioManager mAudioManager; |
| 153 | private final IDreamManager mDreamManager; |
Alex Chau | 0445885 | 2017-11-27 18:21:23 +0000 | [diff] [blame] | 154 | private final DevicePolicyManager mDevicePolicyManager; |
Chad Brubaker | f4075fe | 2018-01-03 13:23:22 -0800 | [diff] [blame] | 155 | private final LockPatternUtils mLockPatternUtils; |
Fabian Kozynski | f6063ae | 2020-02-24 16:14:35 -0500 | [diff] [blame] | 156 | private final KeyguardStateController mKeyguardStateController; |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 157 | private final BroadcastDispatcher mBroadcastDispatcher; |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 158 | private final ContentResolver mContentResolver; |
| 159 | private final Resources mResources; |
Dave Mankoff | 8df818e | 2020-02-12 14:22:26 -0500 | [diff] [blame] | 160 | private final ConfigurationController mConfigurationController; |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 161 | private final UserManager mUserManager; |
| 162 | private final TrustManager mTrustManager; |
| 163 | private final IActivityManager mIActivityManager; |
| 164 | private final TelecomManager mTelecomManager; |
| 165 | private final MetricsLogger mMetricsLogger; |
Santiago Etchebehere | 68eb53e | 2020-02-25 14:25:34 -0800 | [diff] [blame] | 166 | private final NotificationShadeDepthController mDepthController; |
Lucas Dupin | 99f5fba | 2020-03-12 12:59:18 -0700 | [diff] [blame^] | 167 | private final BlurUtils mBlurUtils; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 168 | |
| 169 | private ArrayList<Action> mItems; |
| 170 | private ActionsDialog mDialog; |
| 171 | |
| 172 | private Action mSilentModeAction; |
| 173 | private ToggleAction mAirplaneModeOn; |
| 174 | |
| 175 | private MyAdapter mAdapter; |
| 176 | |
| 177 | private boolean mKeyguardShowing = false; |
| 178 | private boolean mDeviceProvisioned = false; |
| 179 | private ToggleAction.State mAirplaneState = ToggleAction.State.Off; |
| 180 | private boolean mIsWaitingForEcmExit = false; |
| 181 | private boolean mHasTelephony; |
| 182 | private boolean mHasVibrator; |
| 183 | private final boolean mShowSilentToggle; |
| 184 | private final EmergencyAffordanceManager mEmergencyAffordanceManager; |
Alison Cichowlas | a2cd19e | 2017-12-06 10:51:21 -0500 | [diff] [blame] | 185 | private final ScreenshotHelper mScreenshotHelper; |
Beth Thibodeau | 5898ac4 | 2018-10-26 13:00:09 -0400 | [diff] [blame] | 186 | private final ScreenRecordHelper mScreenRecordHelper; |
Steve Elliott | a3f520792 | 2019-03-18 13:37:22 -0400 | [diff] [blame] | 187 | private final ActivityStarter mActivityStarter; |
Lucas Dupin | 991415e | 2019-11-25 17:48:58 -0800 | [diff] [blame] | 188 | private final SysuiColorExtractor mSysuiColorExtractor; |
| 189 | private final IStatusBarService mStatusBarService; |
| 190 | private final NotificationShadeWindowController mNotificationShadeWindowController; |
Steve Elliott | a3f520792 | 2019-03-18 13:37:22 -0400 | [diff] [blame] | 191 | private GlobalActionsPanelPlugin mPanelPlugin; |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 192 | private ControlsUiController mControlsUiController; |
Dave Mankoff | 8df818e | 2020-02-12 14:22:26 -0500 | [diff] [blame] | 193 | private final IWindowManager mIWindowManager; |
| 194 | private final Executor mBackgroundExecutor; |
Fabian Kozynski | 0424ab1 | 2020-02-21 12:09:17 -0500 | [diff] [blame] | 195 | private final ControlsListingController mControlsListingController; |
| 196 | private boolean mAnyControlsProviders = false; |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 197 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 198 | /** |
| 199 | * @param context everything needs a context :( |
| 200 | */ |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 201 | @Inject |
| 202 | public GlobalActionsDialog(Context context, GlobalActionsManager windowManagerFuncs, |
| 203 | AudioManager audioManager, IDreamManager iDreamManager, |
| 204 | DevicePolicyManager devicePolicyManager, LockPatternUtils lockPatternUtils, |
Fabian Kozynski | f6063ae | 2020-02-24 16:14:35 -0500 | [diff] [blame] | 205 | BroadcastDispatcher broadcastDispatcher, |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 206 | ConnectivityManager connectivityManager, TelephonyManager telephonyManager, |
| 207 | ContentResolver contentResolver, @Nullable Vibrator vibrator, @Main Resources resources, |
| 208 | ConfigurationController configurationController, ActivityStarter activityStarter, |
| 209 | KeyguardStateController keyguardStateController, UserManager userManager, |
| 210 | TrustManager trustManager, IActivityManager iActivityManager, |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 211 | @Nullable TelecomManager telecomManager, MetricsLogger metricsLogger, |
Santiago Etchebehere | 68eb53e | 2020-02-25 14:25:34 -0800 | [diff] [blame] | 212 | NotificationShadeDepthController depthController, SysuiColorExtractor colorExtractor, |
Lucas Dupin | 99f5fba | 2020-03-12 12:59:18 -0700 | [diff] [blame^] | 213 | IStatusBarService statusBarService, BlurUtils blurUtils, |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 214 | NotificationShadeWindowController notificationShadeWindowController, |
Dave Mankoff | 8df818e | 2020-02-12 14:22:26 -0500 | [diff] [blame] | 215 | ControlsUiController controlsUiController, IWindowManager iWindowManager, |
Fabian Kozynski | 0424ab1 | 2020-02-21 12:09:17 -0500 | [diff] [blame] | 216 | @Background Executor backgroundExecutor, |
| 217 | ControlsListingController controlsListingController) { |
Lucas Dupin | 448786c | 2017-07-24 17:44:25 -0700 | [diff] [blame] | 218 | mContext = new ContextThemeWrapper(context, com.android.systemui.R.style.qs_theme); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 219 | mWindowManagerFuncs = windowManagerFuncs; |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 220 | mAudioManager = audioManager; |
| 221 | mDreamManager = iDreamManager; |
| 222 | mDevicePolicyManager = devicePolicyManager; |
| 223 | mLockPatternUtils = lockPatternUtils; |
Fabian Kozynski | f6063ae | 2020-02-24 16:14:35 -0500 | [diff] [blame] | 224 | mKeyguardStateController = keyguardStateController; |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 225 | mBroadcastDispatcher = broadcastDispatcher; |
| 226 | mContentResolver = contentResolver; |
| 227 | mResources = resources; |
Dave Mankoff | 8df818e | 2020-02-12 14:22:26 -0500 | [diff] [blame] | 228 | mConfigurationController = configurationController; |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 229 | mUserManager = userManager; |
| 230 | mTrustManager = trustManager; |
| 231 | mIActivityManager = iActivityManager; |
| 232 | mTelecomManager = telecomManager; |
| 233 | mMetricsLogger = metricsLogger; |
Santiago Etchebehere | 68eb53e | 2020-02-25 14:25:34 -0800 | [diff] [blame] | 234 | mDepthController = depthController; |
Lucas Dupin | 991415e | 2019-11-25 17:48:58 -0800 | [diff] [blame] | 235 | mSysuiColorExtractor = colorExtractor; |
| 236 | mStatusBarService = statusBarService; |
| 237 | mNotificationShadeWindowController = notificationShadeWindowController; |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 238 | mControlsUiController = controlsUiController; |
Dave Mankoff | 8df818e | 2020-02-12 14:22:26 -0500 | [diff] [blame] | 239 | mIWindowManager = iWindowManager; |
| 240 | mBackgroundExecutor = backgroundExecutor; |
Fabian Kozynski | 0424ab1 | 2020-02-21 12:09:17 -0500 | [diff] [blame] | 241 | mControlsListingController = controlsListingController; |
Lucas Dupin | 99f5fba | 2020-03-12 12:59:18 -0700 | [diff] [blame^] | 242 | mBlurUtils = blurUtils; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 243 | |
| 244 | // receive broadcasts |
| 245 | IntentFilter filter = new IntentFilter(); |
| 246 | filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); |
| 247 | filter.addAction(Intent.ACTION_SCREEN_OFF); |
Jayachandran C | 142eae0 | 2019-12-13 19:29:20 -0800 | [diff] [blame] | 248 | filter.addAction(TelephonyManager.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED); |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 249 | mBroadcastDispatcher.registerReceiver(mBroadcastReceiver, filter); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 250 | |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 251 | mHasTelephony = connectivityManager.isNetworkSupported(ConnectivityManager.TYPE_MOBILE); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 252 | |
| 253 | // get notified of phone state changes |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 254 | telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE); |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 255 | contentResolver.registerContentObserver( |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 256 | Settings.Global.getUriFor(Settings.Global.AIRPLANE_MODE_ON), true, |
| 257 | mAirplaneModeObserver); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 258 | mHasVibrator = vibrator != null && vibrator.hasVibrator(); |
| 259 | |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 260 | mShowSilentToggle = SHOW_SILENT_TOGGLE && !resources.getBoolean( |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 261 | R.bool.config_useFixedVolume); |
| 262 | |
| 263 | mEmergencyAffordanceManager = new EmergencyAffordanceManager(context); |
Alison Cichowlas | a2cd19e | 2017-12-06 10:51:21 -0500 | [diff] [blame] | 264 | mScreenshotHelper = new ScreenshotHelper(context); |
Beth Thibodeau | 5898ac4 | 2018-10-26 13:00:09 -0400 | [diff] [blame] | 265 | mScreenRecordHelper = new ScreenRecordHelper(context); |
Lucas Dupin | e5b7dc7 | 2018-10-02 15:18:05 -0700 | [diff] [blame] | 266 | |
Dave Mankoff | 8df818e | 2020-02-12 14:22:26 -0500 | [diff] [blame] | 267 | mConfigurationController.addCallback(this); |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 268 | |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 269 | mActivityStarter = activityStarter; |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 270 | keyguardStateController.addCallback(new KeyguardStateController.Callback() { |
| 271 | @Override |
| 272 | public void onUnlockedChanged() { |
| 273 | if (mDialog != null && mDialog.mPanelController != null) { |
| 274 | boolean locked = !keyguardStateController.canDismissLockScreen(); |
| 275 | mDialog.mPanelController.onDeviceLockStateChanged(locked); |
| 276 | } |
| 277 | } |
| 278 | }); |
Fabian Kozynski | 0424ab1 | 2020-02-21 12:09:17 -0500 | [diff] [blame] | 279 | |
| 280 | mControlsListingController.addCallback(list -> mAnyControlsProviders = !list.isEmpty()); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | /** |
| 284 | * Show the global actions dialog (creating if necessary) |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 285 | * |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 286 | * @param keyguardShowing True if keyguard is showing |
| 287 | */ |
Steve Elliott | a3f520792 | 2019-03-18 13:37:22 -0400 | [diff] [blame] | 288 | public void showDialog(boolean keyguardShowing, boolean isDeviceProvisioned, |
| 289 | GlobalActionsPanelPlugin panelPlugin) { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 290 | mKeyguardShowing = keyguardShowing; |
| 291 | mDeviceProvisioned = isDeviceProvisioned; |
Steve Elliott | a3f520792 | 2019-03-18 13:37:22 -0400 | [diff] [blame] | 292 | mPanelPlugin = panelPlugin; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 293 | if (mDialog != null) { |
| 294 | mDialog.dismiss(); |
| 295 | mDialog = null; |
| 296 | // Show delayed, so that the dismiss of the previous dialog completes |
| 297 | mHandler.sendEmptyMessage(MESSAGE_SHOW); |
| 298 | } else { |
| 299 | handleShow(); |
| 300 | } |
| 301 | } |
| 302 | |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 303 | /** |
| 304 | * Dismiss the global actions dialog, if it's currently shown |
| 305 | */ |
| 306 | public void dismissDialog() { |
| 307 | mHandler.removeMessages(MESSAGE_DISMISS); |
| 308 | mHandler.sendEmptyMessage(MESSAGE_DISMISS); |
| 309 | } |
| 310 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 311 | private void awakenIfNecessary() { |
| 312 | if (mDreamManager != null) { |
| 313 | try { |
| 314 | if (mDreamManager.isDreaming()) { |
| 315 | mDreamManager.awaken(); |
| 316 | } |
| 317 | } catch (RemoteException e) { |
| 318 | // we tried |
| 319 | } |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | private void handleShow() { |
| 324 | awakenIfNecessary(); |
| 325 | mDialog = createDialog(); |
| 326 | prepareDialog(); |
| 327 | |
| 328 | // If we only have 1 item and it's a simple press action, just do this action. |
| 329 | if (mAdapter.getCount() == 1 |
| 330 | && mAdapter.getItem(0) instanceof SinglePressAction |
| 331 | && !(mAdapter.getItem(0) instanceof LongPressAction)) { |
| 332 | ((SinglePressAction) mAdapter.getItem(0)).onPress(); |
| 333 | } else { |
| 334 | WindowManager.LayoutParams attrs = mDialog.getWindow().getAttributes(); |
| 335 | attrs.setTitle("ActionsDialog"); |
Adrian Roos | 2f05bb3 | 2018-02-19 16:42:27 +0100 | [diff] [blame] | 336 | attrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 337 | mDialog.getWindow().setAttributes(attrs); |
| 338 | mDialog.show(); |
| 339 | mWindowManagerFuncs.onGlobalActionsShown(); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 340 | } |
| 341 | } |
| 342 | |
| 343 | /** |
| 344 | * Create the global actions dialog. |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 345 | * |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 346 | * @return A new dialog. |
| 347 | */ |
| 348 | private ActionsDialog createDialog() { |
| 349 | // Simple toggle style if there's no vibrator, otherwise use a tri-state |
| 350 | if (!mHasVibrator) { |
| 351 | mSilentModeAction = new SilentModeToggleAction(); |
| 352 | } else { |
Lucas Dupin | 40ec6b78 | 2018-06-05 19:07:16 -0700 | [diff] [blame] | 353 | mSilentModeAction = new SilentModeTriStateAction(mAudioManager, mHandler); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 354 | } |
Aran Ink | 780d450 | 2020-02-14 10:39:58 -0500 | [diff] [blame] | 355 | mAirplaneModeOn = new AirplaneModeAction(); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 356 | onAirplaneModeChanged(); |
| 357 | |
| 358 | mItems = new ArrayList<Action>(); |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 359 | String[] defaultActions = mResources.getStringArray(R.array.config_globalActionsList); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 360 | |
| 361 | ArraySet<String> addedKeys = new ArraySet<String>(); |
| 362 | for (int i = 0; i < defaultActions.length; i++) { |
| 363 | String actionKey = defaultActions[i]; |
| 364 | if (addedKeys.contains(actionKey)) { |
| 365 | // If we already have added this, don't add it again. |
| 366 | continue; |
| 367 | } |
| 368 | if (GLOBAL_ACTION_KEY_POWER.equals(actionKey)) { |
| 369 | mItems.add(new PowerAction()); |
| 370 | } else if (GLOBAL_ACTION_KEY_AIRPLANE.equals(actionKey)) { |
| 371 | mItems.add(mAirplaneModeOn); |
| 372 | } else if (GLOBAL_ACTION_KEY_BUGREPORT.equals(actionKey)) { |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 373 | if (Settings.Global.getInt(mContentResolver, |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 374 | Settings.Global.BUGREPORT_IN_POWER_MENU, 0) != 0 && isCurrentUserOwner()) { |
| 375 | mItems.add(new BugReportAction()); |
| 376 | } |
| 377 | } else if (GLOBAL_ACTION_KEY_SILENT.equals(actionKey)) { |
| 378 | if (mShowSilentToggle) { |
| 379 | mItems.add(mSilentModeAction); |
| 380 | } |
| 381 | } else if (GLOBAL_ACTION_KEY_USERS.equals(actionKey)) { |
| 382 | if (SystemProperties.getBoolean("fw.power_user_switcher", false)) { |
| 383 | addUsersToMenu(mItems); |
| 384 | } |
| 385 | } else if (GLOBAL_ACTION_KEY_SETTINGS.equals(actionKey)) { |
| 386 | mItems.add(getSettingsAction()); |
| 387 | } else if (GLOBAL_ACTION_KEY_LOCKDOWN.equals(actionKey)) { |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 388 | if (Settings.Secure.getIntForUser(mContentResolver, |
Chad Brubaker | 02cd6cf | 2018-05-01 14:59:33 -0700 | [diff] [blame] | 389 | Settings.Secure.LOCKDOWN_IN_POWER_MENU, 0, getCurrentUser().id) != 0 |
Chad Brubaker | f4075fe | 2018-01-03 13:23:22 -0800 | [diff] [blame] | 390 | && shouldDisplayLockdown()) { |
Chad Brubaker | 4f28f0d | 2017-09-07 14:28:13 -0700 | [diff] [blame] | 391 | mItems.add(getLockdownAction()); |
| 392 | } |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 393 | } else if (GLOBAL_ACTION_KEY_VOICEASSIST.equals(actionKey)) { |
| 394 | mItems.add(getVoiceAssistAction()); |
| 395 | } else if (GLOBAL_ACTION_KEY_ASSIST.equals(actionKey)) { |
| 396 | mItems.add(getAssistAction()); |
| 397 | } else if (GLOBAL_ACTION_KEY_RESTART.equals(actionKey)) { |
| 398 | mItems.add(new RestartAction()); |
Alison Cichowlas | a2cd19e | 2017-12-06 10:51:21 -0500 | [diff] [blame] | 399 | } else if (GLOBAL_ACTION_KEY_SCREENSHOT.equals(actionKey)) { |
| 400 | mItems.add(new ScreenshotAction()); |
Alex Chau | 0445885 | 2017-11-27 18:21:23 +0000 | [diff] [blame] | 401 | } else if (GLOBAL_ACTION_KEY_LOGOUT.equals(actionKey)) { |
Alex Chau | d795827 | 2017-12-08 11:30:52 +0000 | [diff] [blame] | 402 | if (mDevicePolicyManager.isLogoutEnabled() |
Alex Chau | 0445885 | 2017-11-27 18:21:23 +0000 | [diff] [blame] | 403 | && getCurrentUser().id != UserHandle.USER_SYSTEM) { |
| 404 | mItems.add(new LogoutAction()); |
Alex Chau | 0445885 | 2017-11-27 18:21:23 +0000 | [diff] [blame] | 405 | } |
Wesley.CW Wang | a9de792 | 2018-07-06 15:26:21 +0800 | [diff] [blame] | 406 | } else if (GLOBAL_ACTION_KEY_EMERGENCY.equals(actionKey)) { |
Aaron Heuckroth | c834340 | 2019-03-13 16:27:15 -0400 | [diff] [blame] | 407 | if (!mEmergencyAffordanceManager.needsEmergencyAffordance()) { |
Wesley.CW Wang | a9de792 | 2018-07-06 15:26:21 +0800 | [diff] [blame] | 408 | mItems.add(new EmergencyDialerAction()); |
| 409 | } |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 410 | } else { |
| 411 | Log.e(TAG, "Invalid global action key " + actionKey); |
| 412 | } |
| 413 | // Add here so we don't add more than one. |
| 414 | addedKeys.add(actionKey); |
| 415 | } |
| 416 | |
| 417 | if (mEmergencyAffordanceManager.needsEmergencyAffordance()) { |
Aaron Heuckroth | c834340 | 2019-03-13 16:27:15 -0400 | [diff] [blame] | 418 | mItems.add(new EmergencyAffordanceAction()); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | mAdapter = new MyAdapter(); |
| 422 | |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 423 | GlobalActionsPanelPlugin.PanelViewController panelViewController = |
Steve Elliott | a3f520792 | 2019-03-18 13:37:22 -0400 | [diff] [blame] | 424 | mPanelPlugin != null |
| 425 | ? mPanelPlugin.onPanelShown( |
Steve Elliott | 4c86885 | 2019-03-14 16:25:41 -0400 | [diff] [blame] | 426 | new GlobalActionsPanelPlugin.Callbacks() { |
| 427 | @Override |
| 428 | public void dismissGlobalActionsMenu() { |
Steve Elliott | c3147e2 | 2019-11-20 19:34:57 -0500 | [diff] [blame] | 429 | dismissDialog(); |
Steve Elliott | 4c86885 | 2019-03-14 16:25:41 -0400 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | @Override |
| 433 | public void startPendingIntentDismissingKeyguard( |
| 434 | PendingIntent intent) { |
| 435 | mActivityStarter |
| 436 | .startPendingIntentDismissingKeyguard(intent); |
| 437 | } |
Steve Elliott | e2a2e9b | 2019-04-30 21:31:03 -0400 | [diff] [blame] | 438 | }, |
Fabian Kozynski | f6063ae | 2020-02-24 16:14:35 -0500 | [diff] [blame] | 439 | !mKeyguardStateController.isUnlocked()) |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 440 | : null; |
Steve Elliott | 02bbaaa | 2019-05-01 16:55:33 -0400 | [diff] [blame] | 441 | |
Lucas Dupin | 991415e | 2019-11-25 17:48:58 -0800 | [diff] [blame] | 442 | ActionsDialog dialog = new ActionsDialog(mContext, mAdapter, panelViewController, |
Santiago Etchebehere | 68eb53e | 2020-02-25 14:25:34 -0800 | [diff] [blame] | 443 | mDepthController, mSysuiColorExtractor, mStatusBarService, |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 444 | mNotificationShadeWindowController, |
Lucas Dupin | 99f5fba | 2020-03-12 12:59:18 -0700 | [diff] [blame^] | 445 | shouldShowControls() ? mControlsUiController : null, mBlurUtils); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 446 | dialog.setCanceledOnTouchOutside(false); // Handled by the custom class. |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 447 | dialog.setKeyguardShowing(mKeyguardShowing); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 448 | |
| 449 | dialog.setOnDismissListener(this); |
Shaotang Li | 786da90 | 2018-08-02 11:18:00 +0800 | [diff] [blame] | 450 | dialog.setOnShowListener(this); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 451 | |
| 452 | return dialog; |
| 453 | } |
| 454 | |
Chad Brubaker | f4075fe | 2018-01-03 13:23:22 -0800 | [diff] [blame] | 455 | private boolean shouldDisplayLockdown() { |
Chad Brubaker | f4075fe | 2018-01-03 13:23:22 -0800 | [diff] [blame] | 456 | // Lockdown is meaningless without a place to go. |
Fabian Kozynski | f6063ae | 2020-02-24 16:14:35 -0500 | [diff] [blame] | 457 | if (!mKeyguardStateController.isMethodSecure()) { |
Chad Brubaker | f4075fe | 2018-01-03 13:23:22 -0800 | [diff] [blame] | 458 | return false; |
| 459 | } |
| 460 | |
Fabian Kozynski | f6063ae | 2020-02-24 16:14:35 -0500 | [diff] [blame] | 461 | int userId = getCurrentUser().id; |
Chad Brubaker | f4075fe | 2018-01-03 13:23:22 -0800 | [diff] [blame] | 462 | // Only show the lockdown button if the device isn't locked down (for whatever reason). |
| 463 | int state = mLockPatternUtils.getStrongAuthForUser(userId); |
| 464 | return (state == STRONG_AUTH_NOT_REQUIRED |
| 465 | || state == SOME_AUTH_REQUIRED_AFTER_USER_REQUEST); |
| 466 | } |
| 467 | |
Lucas Dupin | e5b7dc7 | 2018-10-02 15:18:05 -0700 | [diff] [blame] | 468 | @Override |
| 469 | public void onUiModeChanged() { |
| 470 | mContext.getTheme().applyStyle(mContext.getThemeResId(), true); |
Lucas Dupin | a4e12ba | 2019-04-18 11:56:28 -0700 | [diff] [blame] | 471 | if (mDialog != null && mDialog.isShowing()) { |
Aaron Heuckroth | 4ef3a54 | 2019-04-01 14:17:23 -0400 | [diff] [blame] | 472 | mDialog.refreshDialog(); |
| 473 | } |
Lucas Dupin | e5b7dc7 | 2018-10-02 15:18:05 -0700 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | public void destroy() { |
Dave Mankoff | 8df818e | 2020-02-12 14:22:26 -0500 | [diff] [blame] | 477 | mConfigurationController.removeCallback(this); |
Lucas Dupin | e5b7dc7 | 2018-10-02 15:18:05 -0700 | [diff] [blame] | 478 | } |
| 479 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 480 | private final class PowerAction extends SinglePressAction implements LongPressAction { |
| 481 | private PowerAction() { |
| 482 | super(R.drawable.ic_lock_power_off, |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 483 | R.string.global_action_power_off); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | @Override |
| 487 | public boolean onLongPress() { |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 488 | if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 489 | mWindowManagerFuncs.reboot(true); |
| 490 | return true; |
| 491 | } |
| 492 | return false; |
| 493 | } |
| 494 | |
| 495 | @Override |
| 496 | public boolean showDuringKeyguard() { |
| 497 | return true; |
| 498 | } |
| 499 | |
| 500 | @Override |
| 501 | public boolean showBeforeProvisioning() { |
| 502 | return true; |
| 503 | } |
| 504 | |
| 505 | @Override |
| 506 | public void onPress() { |
| 507 | // shutdown by making sure radio and power are handled accordingly. |
| 508 | mWindowManagerFuncs.shutdown(); |
| 509 | } |
| 510 | } |
| 511 | |
Aaron Heuckroth | c834340 | 2019-03-13 16:27:15 -0400 | [diff] [blame] | 512 | private abstract class EmergencyAction extends SinglePressAction { |
| 513 | EmergencyAction(int iconResId, int messageResId) { |
| 514 | super(iconResId, messageResId); |
| 515 | } |
| 516 | |
| 517 | @Override |
| 518 | public boolean shouldBeSeparated() { |
Aran Ink | 780d450 | 2020-02-14 10:39:58 -0500 | [diff] [blame] | 519 | return true; |
Aaron Heuckroth | c834340 | 2019-03-13 16:27:15 -0400 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | @Override |
| 523 | public View create( |
| 524 | Context context, View convertView, ViewGroup parent, LayoutInflater inflater) { |
| 525 | View v = super.create(context, convertView, parent, inflater); |
| 526 | int textColor; |
| 527 | if (shouldBeSeparated()) { |
| 528 | textColor = v.getResources().getColor( |
| 529 | com.android.systemui.R.color.global_actions_alert_text); |
| 530 | } else { |
| 531 | textColor = v.getResources().getColor( |
| 532 | com.android.systemui.R.color.global_actions_text); |
| 533 | } |
| 534 | TextView messageView = v.findViewById(R.id.message); |
| 535 | messageView.setTextColor(textColor); |
Aaron Heuckroth | 3f2d8b5 | 2019-04-05 13:27:51 -0400 | [diff] [blame] | 536 | messageView.setSelected(true); // necessary for marquee to work |
Aaron Heuckroth | c834340 | 2019-03-13 16:27:15 -0400 | [diff] [blame] | 537 | ImageView icon = (ImageView) v.findViewById(R.id.icon); |
| 538 | icon.getDrawable().setTint(textColor); |
| 539 | return v; |
| 540 | } |
| 541 | |
| 542 | @Override |
| 543 | public boolean showDuringKeyguard() { |
| 544 | return true; |
| 545 | } |
| 546 | |
| 547 | @Override |
| 548 | public boolean showBeforeProvisioning() { |
| 549 | return true; |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | private class EmergencyAffordanceAction extends EmergencyAction { |
| 554 | EmergencyAffordanceAction() { |
| 555 | super(R.drawable.emergency_icon, |
| 556 | R.string.global_action_emergency); |
| 557 | } |
| 558 | |
| 559 | @Override |
| 560 | public void onPress() { |
| 561 | mEmergencyAffordanceManager.performEmergencyCall(); |
| 562 | } |
| 563 | } |
| 564 | |
| 565 | private class EmergencyDialerAction extends EmergencyAction { |
Wesley.CW Wang | a9de792 | 2018-07-06 15:26:21 +0800 | [diff] [blame] | 566 | private EmergencyDialerAction() { |
Aran Ink | 5019526 | 2019-05-30 10:55:37 -0400 | [diff] [blame] | 567 | super(com.android.systemui.R.drawable.ic_emergency_star, |
Wesley.CW Wang | 3004fcb | 2018-06-15 16:24:57 +0800 | [diff] [blame] | 568 | R.string.global_action_emergency); |
Wesley.CW Wang | 8d07276 | 2018-05-28 16:39:27 +0800 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | @Override |
| 572 | public void onPress() { |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 573 | mMetricsLogger.action(MetricsEvent.ACTION_EMERGENCY_DIALER_FROM_POWER_MENU); |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 574 | if (mTelecomManager != null) { |
| 575 | Intent intent = mTelecomManager.createLaunchEmergencyDialerIntent( |
| 576 | null /* number */); |
| 577 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 578 | | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS |
| 579 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 580 | intent.putExtra(EmergencyDialerConstants.EXTRA_ENTRY_TYPE, |
| 581 | EmergencyDialerConstants.ENTRY_TYPE_POWER_MENU); |
| 582 | mContext.startActivityAsUser(intent, UserHandle.CURRENT); |
| 583 | } |
Wesley.CW Wang | 8d07276 | 2018-05-28 16:39:27 +0800 | [diff] [blame] | 584 | } |
Wesley.CW Wang | 8d07276 | 2018-05-28 16:39:27 +0800 | [diff] [blame] | 585 | } |
| 586 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 587 | private final class RestartAction extends SinglePressAction implements LongPressAction { |
| 588 | private RestartAction() { |
| 589 | super(R.drawable.ic_restart, R.string.global_action_restart); |
| 590 | } |
| 591 | |
| 592 | @Override |
| 593 | public boolean onLongPress() { |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 594 | if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 595 | mWindowManagerFuncs.reboot(true); |
| 596 | return true; |
| 597 | } |
| 598 | return false; |
| 599 | } |
| 600 | |
| 601 | @Override |
| 602 | public boolean showDuringKeyguard() { |
| 603 | return true; |
| 604 | } |
| 605 | |
| 606 | @Override |
| 607 | public boolean showBeforeProvisioning() { |
| 608 | return true; |
| 609 | } |
| 610 | |
| 611 | @Override |
| 612 | public void onPress() { |
| 613 | mWindowManagerFuncs.reboot(false); |
| 614 | } |
| 615 | } |
| 616 | |
Beth Thibodeau | 5898ac4 | 2018-10-26 13:00:09 -0400 | [diff] [blame] | 617 | private class ScreenshotAction extends SinglePressAction implements LongPressAction { |
Alison Cichowlas | a2cd19e | 2017-12-06 10:51:21 -0500 | [diff] [blame] | 618 | public ScreenshotAction() { |
| 619 | super(R.drawable.ic_screenshot, R.string.global_action_screenshot); |
| 620 | } |
| 621 | |
| 622 | @Override |
| 623 | public void onPress() { |
| 624 | // Add a little delay before executing, to give the |
| 625 | // dialog a chance to go away before it takes a |
| 626 | // screenshot. |
| 627 | // TODO: instead, omit global action dialog layer |
| 628 | mHandler.postDelayed(new Runnable() { |
| 629 | @Override |
| 630 | public void run() { |
James O'Leary | fa5bb7a | 2019-09-05 13:43:29 -0400 | [diff] [blame] | 631 | mScreenshotHelper.takeScreenshot(1, true, true, mHandler, null); |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 632 | mMetricsLogger.action(MetricsEvent.ACTION_SCREENSHOT_POWER_MENU); |
Alison Cichowlas | a2cd19e | 2017-12-06 10:51:21 -0500 | [diff] [blame] | 633 | } |
| 634 | }, 500); |
| 635 | } |
| 636 | |
| 637 | @Override |
| 638 | public boolean showDuringKeyguard() { |
| 639 | return true; |
| 640 | } |
| 641 | |
| 642 | @Override |
| 643 | public boolean showBeforeProvisioning() { |
| 644 | return false; |
| 645 | } |
Beth Thibodeau | 5898ac4 | 2018-10-26 13:00:09 -0400 | [diff] [blame] | 646 | |
| 647 | @Override |
| 648 | public boolean onLongPress() { |
| 649 | if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SCREENRECORD_LONG_PRESS)) { |
| 650 | mScreenRecordHelper.launchRecordPrompt(); |
| 651 | } else { |
| 652 | onPress(); |
| 653 | } |
| 654 | return true; |
| 655 | } |
Alison Cichowlas | a2cd19e | 2017-12-06 10:51:21 -0500 | [diff] [blame] | 656 | } |
| 657 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 658 | private class BugReportAction extends SinglePressAction implements LongPressAction { |
| 659 | |
| 660 | public BugReportAction() { |
| 661 | super(R.drawable.ic_lock_bugreport, R.string.bugreport_title); |
| 662 | } |
| 663 | |
| 664 | @Override |
| 665 | public void onPress() { |
| 666 | // don't actually trigger the bugreport if we are running stability |
| 667 | // tests via monkey |
| 668 | if (ActivityManager.isUserAMonkey()) { |
| 669 | return; |
| 670 | } |
| 671 | // Add a little delay before executing, to give the |
| 672 | // dialog a chance to go away before it takes a |
| 673 | // screenshot. |
| 674 | mHandler.postDelayed(new Runnable() { |
| 675 | @Override |
| 676 | public void run() { |
| 677 | try { |
| 678 | // Take an "interactive" bugreport. |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 679 | mMetricsLogger.action( |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 680 | MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_INTERACTIVE); |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 681 | if (!mIActivityManager.launchBugReportHandlerApp()) { |
Paul Chang | c40f578 | 2019-11-04 18:55:31 +0800 | [diff] [blame] | 682 | Log.w(TAG, "Bugreport handler could not be launched"); |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 683 | mIActivityManager.requestInteractiveBugReport(); |
Paul Chang | c40f578 | 2019-11-04 18:55:31 +0800 | [diff] [blame] | 684 | } |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 685 | } catch (RemoteException e) { |
| 686 | } |
| 687 | } |
| 688 | }, 500); |
| 689 | } |
| 690 | |
| 691 | @Override |
| 692 | public boolean onLongPress() { |
| 693 | // don't actually trigger the bugreport if we are running stability |
| 694 | // tests via monkey |
| 695 | if (ActivityManager.isUserAMonkey()) { |
| 696 | return false; |
| 697 | } |
| 698 | try { |
| 699 | // Take a "full" bugreport. |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 700 | mMetricsLogger.action(MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_FULL); |
| 701 | mIActivityManager.requestFullBugReport(); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 702 | } catch (RemoteException e) { |
| 703 | } |
| 704 | return false; |
| 705 | } |
| 706 | |
| 707 | public boolean showDuringKeyguard() { |
| 708 | return true; |
| 709 | } |
| 710 | |
| 711 | @Override |
| 712 | public boolean showBeforeProvisioning() { |
| 713 | return false; |
| 714 | } |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 715 | } |
| 716 | |
Alex Chau | 0445885 | 2017-11-27 18:21:23 +0000 | [diff] [blame] | 717 | private final class LogoutAction extends SinglePressAction { |
| 718 | private LogoutAction() { |
| 719 | super(R.drawable.ic_logout, R.string.global_action_logout); |
| 720 | } |
| 721 | |
| 722 | @Override |
| 723 | public boolean showDuringKeyguard() { |
| 724 | return true; |
| 725 | } |
| 726 | |
| 727 | @Override |
| 728 | public boolean showBeforeProvisioning() { |
| 729 | return false; |
| 730 | } |
| 731 | |
| 732 | @Override |
| 733 | public void onPress() { |
| 734 | // Add a little delay before executing, to give the dialog a chance to go away before |
| 735 | // switching user |
| 736 | mHandler.postDelayed(() -> { |
| 737 | try { |
Alex Chau | edb6a01 | 2018-01-26 12:52:43 +0000 | [diff] [blame] | 738 | int currentUserId = getCurrentUser().id; |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 739 | mIActivityManager.switchUser(UserHandle.USER_SYSTEM); |
| 740 | mIActivityManager.stopUser(currentUserId, true /*force*/, null); |
Alex Chau | 0445885 | 2017-11-27 18:21:23 +0000 | [diff] [blame] | 741 | } catch (RemoteException re) { |
| 742 | Log.e(TAG, "Couldn't logout user " + re); |
| 743 | } |
| 744 | }, 500); |
| 745 | } |
| 746 | } |
| 747 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 748 | private Action getSettingsAction() { |
| 749 | return new SinglePressAction(R.drawable.ic_settings, |
| 750 | R.string.global_action_settings) { |
| 751 | |
| 752 | @Override |
| 753 | public void onPress() { |
| 754 | Intent intent = new Intent(Settings.ACTION_SETTINGS); |
| 755 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 756 | mContext.startActivity(intent); |
| 757 | } |
| 758 | |
| 759 | @Override |
| 760 | public boolean showDuringKeyguard() { |
| 761 | return true; |
| 762 | } |
| 763 | |
| 764 | @Override |
| 765 | public boolean showBeforeProvisioning() { |
| 766 | return true; |
| 767 | } |
| 768 | }; |
| 769 | } |
| 770 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 771 | private Action getAssistAction() { |
| 772 | return new SinglePressAction(R.drawable.ic_action_assist_focused, |
| 773 | R.string.global_action_assist) { |
| 774 | @Override |
| 775 | public void onPress() { |
| 776 | Intent intent = new Intent(Intent.ACTION_ASSIST); |
| 777 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 778 | mContext.startActivity(intent); |
| 779 | } |
| 780 | |
| 781 | @Override |
| 782 | public boolean showDuringKeyguard() { |
| 783 | return true; |
| 784 | } |
| 785 | |
| 786 | @Override |
| 787 | public boolean showBeforeProvisioning() { |
| 788 | return true; |
| 789 | } |
| 790 | }; |
| 791 | } |
| 792 | |
| 793 | private Action getVoiceAssistAction() { |
| 794 | return new SinglePressAction(R.drawable.ic_voice_search, |
| 795 | R.string.global_action_voice_assist) { |
| 796 | @Override |
| 797 | public void onPress() { |
| 798 | Intent intent = new Intent(Intent.ACTION_VOICE_ASSIST); |
| 799 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 800 | mContext.startActivity(intent); |
| 801 | } |
| 802 | |
| 803 | @Override |
| 804 | public boolean showDuringKeyguard() { |
| 805 | return true; |
| 806 | } |
| 807 | |
| 808 | @Override |
| 809 | public boolean showBeforeProvisioning() { |
| 810 | return true; |
| 811 | } |
| 812 | }; |
| 813 | } |
| 814 | |
| 815 | private Action getLockdownAction() { |
Alison Cichowlas | 2112543 | 2018-05-16 15:40:45 -0400 | [diff] [blame] | 816 | return new SinglePressAction(R.drawable.ic_lock_lockdown, |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 817 | R.string.global_action_lockdown) { |
| 818 | |
| 819 | @Override |
| 820 | public void onPress() { |
Dave Mankoff | 8df818e | 2020-02-12 14:22:26 -0500 | [diff] [blame] | 821 | mLockPatternUtils.requireStrongAuth(STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN, |
| 822 | UserHandle.USER_ALL); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 823 | try { |
Dave Mankoff | 8df818e | 2020-02-12 14:22:26 -0500 | [diff] [blame] | 824 | mIWindowManager.lockNow(null); |
Pavel Grafov | 059021b | 2018-05-02 13:44:46 +0100 | [diff] [blame] | 825 | // Lock profiles (if any) on the background thread. |
Dave Mankoff | 8df818e | 2020-02-12 14:22:26 -0500 | [diff] [blame] | 826 | mBackgroundExecutor.execute(() -> lockProfiles()); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 827 | } catch (RemoteException e) { |
| 828 | Log.e(TAG, "Error while trying to lock device.", e); |
| 829 | } |
| 830 | } |
| 831 | |
| 832 | @Override |
| 833 | public boolean showDuringKeyguard() { |
| 834 | return true; |
| 835 | } |
| 836 | |
| 837 | @Override |
| 838 | public boolean showBeforeProvisioning() { |
| 839 | return false; |
| 840 | } |
| 841 | }; |
| 842 | } |
| 843 | |
Pavel Grafov | 059021b | 2018-05-02 13:44:46 +0100 | [diff] [blame] | 844 | private void lockProfiles() { |
Pavel Grafov | 059021b | 2018-05-02 13:44:46 +0100 | [diff] [blame] | 845 | final int currentUserId = getCurrentUser().id; |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 846 | final int[] profileIds = mUserManager.getEnabledProfileIds(currentUserId); |
Pavel Grafov | 059021b | 2018-05-02 13:44:46 +0100 | [diff] [blame] | 847 | for (final int id : profileIds) { |
| 848 | if (id != currentUserId) { |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 849 | mTrustManager.setDeviceLockedForUser(id, true); |
Pavel Grafov | 059021b | 2018-05-02 13:44:46 +0100 | [diff] [blame] | 850 | } |
| 851 | } |
| 852 | } |
| 853 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 854 | private UserInfo getCurrentUser() { |
| 855 | try { |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 856 | return mIActivityManager.getCurrentUser(); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 857 | } catch (RemoteException re) { |
| 858 | return null; |
| 859 | } |
| 860 | } |
| 861 | |
| 862 | private boolean isCurrentUserOwner() { |
| 863 | UserInfo currentUser = getCurrentUser(); |
| 864 | return currentUser == null || currentUser.isPrimary(); |
| 865 | } |
| 866 | |
| 867 | private void addUsersToMenu(ArrayList<Action> items) { |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 868 | if (mUserManager.isUserSwitcherEnabled()) { |
| 869 | List<UserInfo> users = mUserManager.getUsers(); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 870 | UserInfo currentUser = getCurrentUser(); |
| 871 | for (final UserInfo user : users) { |
| 872 | if (user.supportsSwitchToByUser()) { |
| 873 | boolean isCurrentUser = currentUser == null |
| 874 | ? user.id == 0 : (currentUser.id == user.id); |
| 875 | Drawable icon = user.iconPath != null ? Drawable.createFromPath(user.iconPath) |
| 876 | : null; |
| 877 | SinglePressAction switchToUser = new SinglePressAction( |
| 878 | R.drawable.ic_menu_cc, icon, |
| 879 | (user.name != null ? user.name : "Primary") |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 880 | + (isCurrentUser ? " \u2714" : "")) { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 881 | public void onPress() { |
| 882 | try { |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 883 | mIActivityManager.switchUser(user.id); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 884 | } catch (RemoteException re) { |
| 885 | Log.e(TAG, "Couldn't switch user " + re); |
| 886 | } |
| 887 | } |
| 888 | |
| 889 | public boolean showDuringKeyguard() { |
| 890 | return true; |
| 891 | } |
| 892 | |
| 893 | public boolean showBeforeProvisioning() { |
| 894 | return false; |
| 895 | } |
| 896 | }; |
| 897 | items.add(switchToUser); |
| 898 | } |
| 899 | } |
| 900 | } |
| 901 | } |
| 902 | |
| 903 | private void prepareDialog() { |
| 904 | refreshSilentMode(); |
| 905 | mAirplaneModeOn.updateState(mAirplaneState); |
| 906 | mAdapter.notifyDataSetChanged(); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 907 | if (mShowSilentToggle) { |
| 908 | IntentFilter filter = new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION); |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 909 | mBroadcastDispatcher.registerReceiver(mRingerModeReceiver, filter); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 910 | } |
| 911 | } |
| 912 | |
| 913 | private void refreshSilentMode() { |
| 914 | if (!mHasVibrator) { |
| 915 | final boolean silentModeOn = |
| 916 | mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL; |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 917 | ((ToggleAction) mSilentModeAction).updateState( |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 918 | silentModeOn ? ToggleAction.State.On : ToggleAction.State.Off); |
| 919 | } |
| 920 | } |
| 921 | |
| 922 | /** {@inheritDoc} */ |
| 923 | public void onDismiss(DialogInterface dialog) { |
Steve Elliott | c3147e2 | 2019-11-20 19:34:57 -0500 | [diff] [blame] | 924 | if (mDialog == dialog) { |
| 925 | mDialog = null; |
| 926 | } |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 927 | mWindowManagerFuncs.onGlobalActionsHidden(); |
| 928 | if (mShowSilentToggle) { |
| 929 | try { |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 930 | mBroadcastDispatcher.unregisterReceiver(mRingerModeReceiver); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 931 | } catch (IllegalArgumentException ie) { |
| 932 | // ignore this |
| 933 | Log.w(TAG, ie); |
| 934 | } |
| 935 | } |
| 936 | } |
| 937 | |
| 938 | /** {@inheritDoc} */ |
Shaotang Li | 786da90 | 2018-08-02 11:18:00 +0800 | [diff] [blame] | 939 | public void onShow(DialogInterface dialog) { |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 940 | mMetricsLogger.visible(MetricsEvent.POWER_MENU); |
Shaotang Li | 786da90 | 2018-08-02 11:18:00 +0800 | [diff] [blame] | 941 | } |
| 942 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 943 | /** |
| 944 | * The adapter used for the list within the global actions dialog, taking |
| 945 | * into account whether the keyguard is showing via |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 946 | * {@link com.android.systemui.globalactions.GlobalActionsDialog#mKeyguardShowing} and whether |
| 947 | * the device is provisioned |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 948 | * via {@link com.android.systemui.globalactions.GlobalActionsDialog#mDeviceProvisioned}. |
| 949 | */ |
Aaron Heuckroth | 57d60d2 | 2019-03-05 14:00:12 -0500 | [diff] [blame] | 950 | public class MyAdapter extends MultiListAdapter { |
Aaron Heuckroth | 5e28f8c8 | 2019-04-24 13:26:12 -0400 | [diff] [blame] | 951 | private int countItems(boolean separated) { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 952 | int count = 0; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 953 | for (int i = 0; i < mItems.size(); i++) { |
| 954 | final Action action = mItems.get(i); |
| 955 | |
Aaron Heuckroth | 5e28f8c8 | 2019-04-24 13:26:12 -0400 | [diff] [blame] | 956 | if (shouldBeShown(action) && action.shouldBeSeparated() == separated) { |
| 957 | count++; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 958 | } |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 959 | } |
| 960 | return count; |
| 961 | } |
| 962 | |
Aaron Heuckroth | 5e28f8c8 | 2019-04-24 13:26:12 -0400 | [diff] [blame] | 963 | private boolean shouldBeShown(Action action) { |
| 964 | if (mKeyguardShowing && !action.showDuringKeyguard()) { |
| 965 | return false; |
| 966 | } |
| 967 | if (!mDeviceProvisioned && !action.showBeforeProvisioning()) { |
| 968 | return false; |
| 969 | } |
| 970 | return true; |
| 971 | } |
| 972 | |
| 973 | @Override |
| 974 | public int countSeparatedItems() { |
| 975 | return countItems(true); |
| 976 | } |
| 977 | |
| 978 | @Override |
| 979 | public int countListItems() { |
| 980 | return countItems(false); |
| 981 | } |
| 982 | |
| 983 | @Override |
| 984 | public int getCount() { |
| 985 | return countSeparatedItems() + countListItems(); |
| 986 | } |
| 987 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 988 | @Override |
| 989 | public boolean isEnabled(int position) { |
| 990 | return getItem(position).isEnabled(); |
| 991 | } |
| 992 | |
Aaron Heuckroth | 57d60d2 | 2019-03-05 14:00:12 -0500 | [diff] [blame] | 993 | @Override |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 994 | public boolean areAllItemsEnabled() { |
| 995 | return false; |
| 996 | } |
| 997 | |
Aaron Heuckroth | 57d60d2 | 2019-03-05 14:00:12 -0500 | [diff] [blame] | 998 | @Override |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 999 | public Action getItem(int position) { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1000 | int filteredPos = 0; |
| 1001 | for (int i = 0; i < mItems.size(); i++) { |
| 1002 | final Action action = mItems.get(i); |
Aaron Heuckroth | 5e28f8c8 | 2019-04-24 13:26:12 -0400 | [diff] [blame] | 1003 | if (!shouldBeShown(action)) { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1004 | continue; |
| 1005 | } |
| 1006 | if (filteredPos == position) { |
| 1007 | return action; |
| 1008 | } |
| 1009 | filteredPos++; |
| 1010 | } |
| 1011 | |
| 1012 | throw new IllegalArgumentException("position " + position |
| 1013 | + " out of range of showable actions" |
| 1014 | + ", filtered count=" + getCount() |
| 1015 | + ", keyguardshowing=" + mKeyguardShowing |
| 1016 | + ", provisioned=" + mDeviceProvisioned); |
| 1017 | } |
| 1018 | |
| 1019 | |
| 1020 | public long getItemId(int position) { |
| 1021 | return position; |
| 1022 | } |
| 1023 | |
Aaron Heuckroth | 57d60d2 | 2019-03-05 14:00:12 -0500 | [diff] [blame] | 1024 | @Override |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1025 | public View getView(int position, View convertView, ViewGroup parent) { |
| 1026 | Action action = getItem(position); |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1027 | View view = action.create(mContext, convertView, parent, LayoutInflater.from(mContext)); |
Aaron Heuckroth | 5e28f8c8 | 2019-04-24 13:26:12 -0400 | [diff] [blame] | 1028 | view.setOnClickListener(v -> onClickItem(position)); |
Aran Ink | b4199d9 | 2020-02-07 13:25:21 -0500 | [diff] [blame] | 1029 | if (action instanceof LongPressAction) { |
| 1030 | view.setOnLongClickListener(v -> onLongClickItem(position)); |
| 1031 | } |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1032 | return view; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1033 | } |
Aaron Heuckroth | 57d60d2 | 2019-03-05 14:00:12 -0500 | [diff] [blame] | 1034 | |
| 1035 | @Override |
| 1036 | public boolean onLongClickItem(int position) { |
| 1037 | final Action action = mAdapter.getItem(position); |
| 1038 | if (action instanceof LongPressAction) { |
Aran Ink | baa2586 | 2019-06-11 15:48:55 -0400 | [diff] [blame] | 1039 | if (mDialog != null) { |
| 1040 | mDialog.dismiss(); |
| 1041 | } else { |
| 1042 | Log.w(TAG, "Action long-clicked while mDialog is null."); |
| 1043 | } |
Aaron Heuckroth | 57d60d2 | 2019-03-05 14:00:12 -0500 | [diff] [blame] | 1044 | return ((LongPressAction) action).onLongPress(); |
| 1045 | } |
| 1046 | return false; |
| 1047 | } |
| 1048 | |
| 1049 | @Override |
| 1050 | public void onClickItem(int position) { |
| 1051 | Action item = mAdapter.getItem(position); |
| 1052 | if (!(item instanceof SilentModeTriStateAction)) { |
Aran Ink | baa2586 | 2019-06-11 15:48:55 -0400 | [diff] [blame] | 1053 | if (mDialog != null) { |
| 1054 | mDialog.dismiss(); |
| 1055 | } else { |
| 1056 | Log.w(TAG, "Action clicked while mDialog is null."); |
| 1057 | } |
| 1058 | item.onPress(); |
Aaron Heuckroth | 57d60d2 | 2019-03-05 14:00:12 -0500 | [diff] [blame] | 1059 | } |
Aaron Heuckroth | 57d60d2 | 2019-03-05 14:00:12 -0500 | [diff] [blame] | 1060 | } |
Aaron Heuckroth | 5e28f8c8 | 2019-04-24 13:26:12 -0400 | [diff] [blame] | 1061 | |
| 1062 | @Override |
| 1063 | public boolean shouldBeSeparated(int position) { |
| 1064 | return getItem(position).shouldBeSeparated(); |
| 1065 | } |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1066 | } |
| 1067 | |
| 1068 | // note: the scheme below made more sense when we were planning on having |
| 1069 | // 8 different things in the global actions dialog. seems overkill with |
| 1070 | // only 3 items now, but may as well keep this flexible approach so it will |
| 1071 | // be easy should someone decide at the last minute to include something |
| 1072 | // else, such as 'enable wifi', or 'enable bluetooth' |
| 1073 | |
| 1074 | /** |
| 1075 | * What each item in the global actions dialog must be able to support. |
| 1076 | */ |
Aaron Heuckroth | 57d60d2 | 2019-03-05 14:00:12 -0500 | [diff] [blame] | 1077 | public interface Action { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1078 | /** |
| 1079 | * @return Text that will be announced when dialog is created. null |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1080 | * for none. |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1081 | */ |
| 1082 | CharSequence getLabelForAccessibility(Context context); |
| 1083 | |
| 1084 | View create(Context context, View convertView, ViewGroup parent, LayoutInflater inflater); |
| 1085 | |
| 1086 | void onPress(); |
| 1087 | |
| 1088 | /** |
| 1089 | * @return whether this action should appear in the dialog when the keygaurd |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1090 | * is showing. |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1091 | */ |
| 1092 | boolean showDuringKeyguard(); |
| 1093 | |
| 1094 | /** |
| 1095 | * @return whether this action should appear in the dialog before the |
Aaron Heuckroth | 57d60d2 | 2019-03-05 14:00:12 -0500 | [diff] [blame] | 1096 | * device is provisioned.onlongpress |
| 1097 | * |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1098 | */ |
| 1099 | boolean showBeforeProvisioning(); |
| 1100 | |
| 1101 | boolean isEnabled(); |
Aaron Heuckroth | f708d47 | 2019-01-10 16:54:51 -0500 | [diff] [blame] | 1102 | |
| 1103 | default boolean shouldBeSeparated() { |
| 1104 | return false; |
| 1105 | } |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1106 | } |
| 1107 | |
| 1108 | /** |
| 1109 | * An action that also supports long press. |
| 1110 | */ |
| 1111 | private interface LongPressAction extends Action { |
| 1112 | boolean onLongPress(); |
| 1113 | } |
| 1114 | |
| 1115 | /** |
| 1116 | * A single press action maintains no state, just responds to a press |
| 1117 | * and takes an action. |
| 1118 | */ |
Matt Pietal | e0661b6 | 2020-01-29 14:35:31 -0500 | [diff] [blame] | 1119 | |
| 1120 | private abstract class SinglePressAction implements Action { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1121 | private final int mIconResId; |
| 1122 | private final Drawable mIcon; |
| 1123 | private final int mMessageResId; |
| 1124 | private final CharSequence mMessage; |
| 1125 | |
| 1126 | protected SinglePressAction(int iconResId, int messageResId) { |
| 1127 | mIconResId = iconResId; |
| 1128 | mMessageResId = messageResId; |
| 1129 | mMessage = null; |
| 1130 | mIcon = null; |
| 1131 | } |
| 1132 | |
| 1133 | protected SinglePressAction(int iconResId, Drawable icon, CharSequence message) { |
| 1134 | mIconResId = iconResId; |
| 1135 | mMessageResId = 0; |
| 1136 | mMessage = message; |
| 1137 | mIcon = icon; |
| 1138 | } |
| 1139 | |
| 1140 | public boolean isEnabled() { |
| 1141 | return true; |
| 1142 | } |
| 1143 | |
| 1144 | public String getStatus() { |
| 1145 | return null; |
| 1146 | } |
| 1147 | |
| 1148 | abstract public void onPress(); |
| 1149 | |
| 1150 | public CharSequence getLabelForAccessibility(Context context) { |
| 1151 | if (mMessage != null) { |
| 1152 | return mMessage; |
| 1153 | } else { |
| 1154 | return context.getString(mMessageResId); |
| 1155 | } |
| 1156 | } |
| 1157 | |
Aaron Heuckroth | 166392f | 2019-01-17 16:50:59 -0500 | [diff] [blame] | 1158 | protected int getActionLayoutId(Context context) { |
Matt Pietal | e0661b6 | 2020-01-29 14:35:31 -0500 | [diff] [blame] | 1159 | if (shouldShowControls()) { |
Matt Pietal | fd3b6cb | 2020-01-08 09:43:54 -0500 | [diff] [blame] | 1160 | return com.android.systemui.R.layout.global_actions_grid_item_v2; |
| 1161 | } |
Aaron Heuckroth | c792661 | 2019-04-02 14:21:57 -0400 | [diff] [blame] | 1162 | return com.android.systemui.R.layout.global_actions_grid_item; |
Aaron Heuckroth | 166392f | 2019-01-17 16:50:59 -0500 | [diff] [blame] | 1163 | } |
| 1164 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1165 | public View create( |
| 1166 | Context context, View convertView, ViewGroup parent, LayoutInflater inflater) { |
Aaron Heuckroth | 166392f | 2019-01-17 16:50:59 -0500 | [diff] [blame] | 1167 | View v = inflater.inflate(getActionLayoutId(context), parent, |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1168 | false); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1169 | |
| 1170 | ImageView icon = (ImageView) v.findViewById(R.id.icon); |
| 1171 | TextView messageView = (TextView) v.findViewById(R.id.message); |
Aaron Heuckroth | 3f2d8b5 | 2019-04-05 13:27:51 -0400 | [diff] [blame] | 1172 | messageView.setSelected(true); // necessary for marquee to work |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1173 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1174 | if (mIcon != null) { |
| 1175 | icon.setImageDrawable(mIcon); |
| 1176 | icon.setScaleType(ScaleType.CENTER_CROP); |
| 1177 | } else if (mIconResId != 0) { |
| 1178 | icon.setImageDrawable(context.getDrawable(mIconResId)); |
| 1179 | } |
| 1180 | if (mMessage != null) { |
| 1181 | messageView.setText(mMessage); |
| 1182 | } else { |
| 1183 | messageView.setText(mMessageResId); |
| 1184 | } |
| 1185 | |
| 1186 | return v; |
| 1187 | } |
| 1188 | } |
| 1189 | |
| 1190 | /** |
| 1191 | * A toggle action knows whether it is on or off, and displays an icon |
| 1192 | * and status message accordingly. |
| 1193 | */ |
| 1194 | private static abstract class ToggleAction implements Action { |
| 1195 | |
| 1196 | enum State { |
| 1197 | Off(false), |
| 1198 | TurningOn(true), |
| 1199 | TurningOff(true), |
| 1200 | On(false); |
| 1201 | |
| 1202 | private final boolean inTransition; |
| 1203 | |
| 1204 | State(boolean intermediate) { |
| 1205 | inTransition = intermediate; |
| 1206 | } |
| 1207 | |
| 1208 | public boolean inTransition() { |
| 1209 | return inTransition; |
| 1210 | } |
| 1211 | } |
| 1212 | |
| 1213 | protected State mState = State.Off; |
| 1214 | |
| 1215 | // prefs |
| 1216 | protected int mEnabledIconResId; |
| 1217 | protected int mDisabledIconResid; |
| 1218 | protected int mMessageResId; |
| 1219 | protected int mEnabledStatusMessageResId; |
| 1220 | protected int mDisabledStatusMessageResId; |
| 1221 | |
| 1222 | /** |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1223 | * @param enabledIconResId The icon for when this action is on. |
| 1224 | * @param disabledIconResid The icon for when this action is off. |
| 1225 | * @param message The general information message, e.g 'Silent Mode' |
| 1226 | * @param enabledStatusMessageResId The on status message, e.g 'sound disabled' |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1227 | * @param disabledStatusMessageResId The off status message, e.g. 'sound enabled' |
| 1228 | */ |
| 1229 | public ToggleAction(int enabledIconResId, |
| 1230 | int disabledIconResid, |
| 1231 | int message, |
| 1232 | int enabledStatusMessageResId, |
| 1233 | int disabledStatusMessageResId) { |
| 1234 | mEnabledIconResId = enabledIconResId; |
| 1235 | mDisabledIconResid = disabledIconResid; |
| 1236 | mMessageResId = message; |
| 1237 | mEnabledStatusMessageResId = enabledStatusMessageResId; |
| 1238 | mDisabledStatusMessageResId = disabledStatusMessageResId; |
| 1239 | } |
| 1240 | |
| 1241 | /** |
| 1242 | * Override to make changes to resource IDs just before creating the |
| 1243 | * View. |
| 1244 | */ |
| 1245 | void willCreate() { |
| 1246 | |
| 1247 | } |
| 1248 | |
| 1249 | @Override |
| 1250 | public CharSequence getLabelForAccessibility(Context context) { |
| 1251 | return context.getString(mMessageResId); |
| 1252 | } |
| 1253 | |
| 1254 | public View create(Context context, View convertView, ViewGroup parent, |
| 1255 | LayoutInflater inflater) { |
| 1256 | willCreate(); |
| 1257 | |
Koji Fukui | 5c010ee | 2019-12-24 16:12:07 +0900 | [diff] [blame] | 1258 | View v = inflater.inflate(com.android.systemui.R |
| 1259 | .layout.global_actions_grid_item, parent, false); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1260 | |
| 1261 | ImageView icon = (ImageView) v.findViewById(R.id.icon); |
| 1262 | TextView messageView = (TextView) v.findViewById(R.id.message); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1263 | final boolean enabled = isEnabled(); |
Koji Fukui | 5c010ee | 2019-12-24 16:12:07 +0900 | [diff] [blame] | 1264 | boolean on = ((mState == State.On) || (mState == State.TurningOn)); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1265 | |
| 1266 | if (messageView != null) { |
Koji Fukui | 5c010ee | 2019-12-24 16:12:07 +0900 | [diff] [blame] | 1267 | messageView.setText(on ? mEnabledStatusMessageResId : mDisabledStatusMessageResId); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1268 | messageView.setEnabled(enabled); |
Aaron Heuckroth | 3f2d8b5 | 2019-04-05 13:27:51 -0400 | [diff] [blame] | 1269 | messageView.setSelected(true); // necessary for marquee to work |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1270 | } |
| 1271 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1272 | if (icon != null) { |
| 1273 | icon.setImageDrawable(context.getDrawable( |
| 1274 | (on ? mEnabledIconResId : mDisabledIconResid))); |
| 1275 | icon.setEnabled(enabled); |
| 1276 | } |
| 1277 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1278 | v.setEnabled(enabled); |
| 1279 | |
| 1280 | return v; |
| 1281 | } |
| 1282 | |
| 1283 | public final void onPress() { |
| 1284 | if (mState.inTransition()) { |
| 1285 | Log.w(TAG, "shouldn't be able to toggle when in transition"); |
| 1286 | return; |
| 1287 | } |
| 1288 | |
| 1289 | final boolean nowOn = !(mState == State.On); |
| 1290 | onToggle(nowOn); |
| 1291 | changeStateFromPress(nowOn); |
| 1292 | } |
| 1293 | |
| 1294 | public boolean isEnabled() { |
| 1295 | return !mState.inTransition(); |
| 1296 | } |
| 1297 | |
| 1298 | /** |
| 1299 | * Implementations may override this if their state can be in on of the intermediate |
| 1300 | * states until some notification is received (e.g airplane mode is 'turning off' until |
| 1301 | * we know the wireless connections are back online |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1302 | * |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1303 | * @param buttonOn Whether the button was turned on or off |
| 1304 | */ |
| 1305 | protected void changeStateFromPress(boolean buttonOn) { |
| 1306 | mState = buttonOn ? State.On : State.Off; |
| 1307 | } |
| 1308 | |
| 1309 | abstract void onToggle(boolean on); |
| 1310 | |
| 1311 | public void updateState(State state) { |
| 1312 | mState = state; |
| 1313 | } |
| 1314 | } |
| 1315 | |
Aran Ink | 780d450 | 2020-02-14 10:39:58 -0500 | [diff] [blame] | 1316 | private class AirplaneModeAction extends ToggleAction { |
| 1317 | AirplaneModeAction() { |
| 1318 | super( |
| 1319 | R.drawable.ic_lock_airplane_mode, |
| 1320 | R.drawable.ic_lock_airplane_mode_off, |
| 1321 | R.string.global_actions_toggle_airplane_mode, |
| 1322 | R.string.global_actions_airplane_mode_on_status, |
| 1323 | R.string.global_actions_airplane_mode_off_status); |
| 1324 | } |
| 1325 | void onToggle(boolean on) { |
| 1326 | if (mHasTelephony && TelephonyProperties.in_ecm_mode().orElse(false)) { |
| 1327 | mIsWaitingForEcmExit = true; |
| 1328 | // Launch ECM exit dialog |
| 1329 | Intent ecmDialogIntent = |
| 1330 | new Intent(TelephonyManager.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null); |
| 1331 | ecmDialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1332 | mContext.startActivity(ecmDialogIntent); |
| 1333 | } else { |
| 1334 | changeAirplaneModeSystemSetting(on); |
| 1335 | } |
| 1336 | } |
| 1337 | |
| 1338 | @Override |
| 1339 | protected void changeStateFromPress(boolean buttonOn) { |
| 1340 | if (!mHasTelephony) return; |
| 1341 | |
| 1342 | // In ECM mode airplane state cannot be changed |
| 1343 | if (!TelephonyProperties.in_ecm_mode().orElse(false)) { |
| 1344 | mState = buttonOn ? State.TurningOn : State.TurningOff; |
| 1345 | mAirplaneState = mState; |
| 1346 | } |
| 1347 | } |
| 1348 | |
| 1349 | public boolean showDuringKeyguard() { |
| 1350 | return true; |
| 1351 | } |
| 1352 | |
| 1353 | public boolean showBeforeProvisioning() { |
| 1354 | return false; |
| 1355 | } |
| 1356 | } |
| 1357 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1358 | private class SilentModeToggleAction extends ToggleAction { |
| 1359 | public SilentModeToggleAction() { |
| 1360 | super(R.drawable.ic_audio_vol_mute, |
| 1361 | R.drawable.ic_audio_vol, |
| 1362 | R.string.global_action_toggle_silent_mode, |
| 1363 | R.string.global_action_silent_mode_on_status, |
| 1364 | R.string.global_action_silent_mode_off_status); |
| 1365 | } |
| 1366 | |
| 1367 | void onToggle(boolean on) { |
| 1368 | if (on) { |
| 1369 | mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT); |
| 1370 | } else { |
| 1371 | mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL); |
| 1372 | } |
| 1373 | } |
| 1374 | |
| 1375 | public boolean showDuringKeyguard() { |
| 1376 | return true; |
| 1377 | } |
| 1378 | |
| 1379 | public boolean showBeforeProvisioning() { |
| 1380 | return false; |
| 1381 | } |
| 1382 | } |
| 1383 | |
| 1384 | private static class SilentModeTriStateAction implements Action, View.OnClickListener { |
| 1385 | |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1386 | private final int[] ITEM_IDS = {R.id.option1, R.id.option2, R.id.option3}; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1387 | |
| 1388 | private final AudioManager mAudioManager; |
| 1389 | private final Handler mHandler; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1390 | |
Lucas Dupin | 40ec6b78 | 2018-06-05 19:07:16 -0700 | [diff] [blame] | 1391 | SilentModeTriStateAction(AudioManager audioManager, Handler handler) { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1392 | mAudioManager = audioManager; |
| 1393 | mHandler = handler; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1394 | } |
| 1395 | |
| 1396 | private int ringerModeToIndex(int ringerMode) { |
| 1397 | // They just happen to coincide |
| 1398 | return ringerMode; |
| 1399 | } |
| 1400 | |
| 1401 | private int indexToRingerMode(int index) { |
| 1402 | // They just happen to coincide |
| 1403 | return index; |
| 1404 | } |
| 1405 | |
| 1406 | @Override |
| 1407 | public CharSequence getLabelForAccessibility(Context context) { |
| 1408 | return null; |
| 1409 | } |
| 1410 | |
| 1411 | public View create(Context context, View convertView, ViewGroup parent, |
| 1412 | LayoutInflater inflater) { |
| 1413 | View v = inflater.inflate(R.layout.global_actions_silent_mode, parent, false); |
| 1414 | |
| 1415 | int selectedIndex = ringerModeToIndex(mAudioManager.getRingerMode()); |
| 1416 | for (int i = 0; i < 3; i++) { |
| 1417 | View itemView = v.findViewById(ITEM_IDS[i]); |
| 1418 | itemView.setSelected(selectedIndex == i); |
| 1419 | // Set up click handler |
| 1420 | itemView.setTag(i); |
| 1421 | itemView.setOnClickListener(this); |
| 1422 | } |
| 1423 | return v; |
| 1424 | } |
| 1425 | |
| 1426 | public void onPress() { |
| 1427 | } |
| 1428 | |
| 1429 | public boolean showDuringKeyguard() { |
| 1430 | return true; |
| 1431 | } |
| 1432 | |
| 1433 | public boolean showBeforeProvisioning() { |
| 1434 | return false; |
| 1435 | } |
| 1436 | |
| 1437 | public boolean isEnabled() { |
| 1438 | return true; |
| 1439 | } |
| 1440 | |
| 1441 | void willCreate() { |
| 1442 | } |
| 1443 | |
| 1444 | public void onClick(View v) { |
| 1445 | if (!(v.getTag() instanceof Integer)) return; |
| 1446 | |
| 1447 | int index = (Integer) v.getTag(); |
| 1448 | mAudioManager.setRingerMode(indexToRingerMode(index)); |
| 1449 | mHandler.sendEmptyMessageDelayed(MESSAGE_DISMISS, DIALOG_DISMISS_DELAY); |
| 1450 | } |
| 1451 | } |
| 1452 | |
| 1453 | private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 1454 | public void onReceive(Context context, Intent intent) { |
| 1455 | String action = intent.getAction(); |
| 1456 | if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action) |
| 1457 | || Intent.ACTION_SCREEN_OFF.equals(action)) { |
| 1458 | String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY); |
| 1459 | if (!SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS.equals(reason)) { |
Lucas Dupin | 1d4a579 | 2018-04-02 15:14:59 -0700 | [diff] [blame] | 1460 | mHandler.sendMessage(mHandler.obtainMessage(MESSAGE_DISMISS, reason)); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1461 | } |
Jayachandran C | 142eae0 | 2019-12-13 19:29:20 -0800 | [diff] [blame] | 1462 | } else if (TelephonyManager.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED.equals(action)) { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1463 | // Airplane mode can be changed after ECM exits if airplane toggle button |
| 1464 | // is pressed during ECM mode |
Daniel Bright | 4bcbfce | 2020-01-09 21:58:16 -0800 | [diff] [blame] | 1465 | if (!(intent.getBooleanExtra(TelephonyManager.EXTRA_PHONE_IN_ECM_STATE, false)) |
| 1466 | && mIsWaitingForEcmExit) { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1467 | mIsWaitingForEcmExit = false; |
| 1468 | changeAirplaneModeSystemSetting(true); |
| 1469 | } |
| 1470 | } |
| 1471 | } |
| 1472 | }; |
| 1473 | |
| 1474 | PhoneStateListener mPhoneStateListener = new PhoneStateListener() { |
| 1475 | @Override |
| 1476 | public void onServiceStateChanged(ServiceState serviceState) { |
| 1477 | if (!mHasTelephony) return; |
| 1478 | final boolean inAirplaneMode = serviceState.getState() == ServiceState.STATE_POWER_OFF; |
| 1479 | mAirplaneState = inAirplaneMode ? ToggleAction.State.On : ToggleAction.State.Off; |
| 1480 | mAirplaneModeOn.updateState(mAirplaneState); |
| 1481 | mAdapter.notifyDataSetChanged(); |
| 1482 | } |
| 1483 | }; |
| 1484 | |
| 1485 | private BroadcastReceiver mRingerModeReceiver = new BroadcastReceiver() { |
| 1486 | @Override |
| 1487 | public void onReceive(Context context, Intent intent) { |
| 1488 | if (intent.getAction().equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) { |
| 1489 | mHandler.sendEmptyMessage(MESSAGE_REFRESH); |
| 1490 | } |
| 1491 | } |
| 1492 | }; |
| 1493 | |
| 1494 | private ContentObserver mAirplaneModeObserver = new ContentObserver(new Handler()) { |
| 1495 | @Override |
| 1496 | public void onChange(boolean selfChange) { |
| 1497 | onAirplaneModeChanged(); |
| 1498 | } |
| 1499 | }; |
| 1500 | |
| 1501 | private static final int MESSAGE_DISMISS = 0; |
| 1502 | private static final int MESSAGE_REFRESH = 1; |
| 1503 | private static final int MESSAGE_SHOW = 2; |
| 1504 | private static final int DIALOG_DISMISS_DELAY = 300; // ms |
| 1505 | |
| 1506 | private Handler mHandler = new Handler() { |
| 1507 | public void handleMessage(Message msg) { |
| 1508 | switch (msg.what) { |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1509 | case MESSAGE_DISMISS: |
| 1510 | if (mDialog != null) { |
Lucas Dupin | 1d4a579 | 2018-04-02 15:14:59 -0700 | [diff] [blame] | 1511 | if (SYSTEM_DIALOG_REASON_DREAM.equals(msg.obj)) { |
| 1512 | mDialog.dismissImmediately(); |
| 1513 | } else { |
| 1514 | mDialog.dismiss(); |
| 1515 | } |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1516 | mDialog = null; |
| 1517 | } |
| 1518 | break; |
| 1519 | case MESSAGE_REFRESH: |
| 1520 | refreshSilentMode(); |
| 1521 | mAdapter.notifyDataSetChanged(); |
| 1522 | break; |
| 1523 | case MESSAGE_SHOW: |
| 1524 | handleShow(); |
| 1525 | break; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1526 | } |
| 1527 | } |
| 1528 | }; |
| 1529 | |
| 1530 | private void onAirplaneModeChanged() { |
| 1531 | // Let the service state callbacks handle the state. |
| 1532 | if (mHasTelephony) return; |
| 1533 | |
| 1534 | boolean airplaneModeOn = Settings.Global.getInt( |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 1535 | mContentResolver, |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1536 | Settings.Global.AIRPLANE_MODE_ON, |
| 1537 | 0) == 1; |
| 1538 | mAirplaneState = airplaneModeOn ? ToggleAction.State.On : ToggleAction.State.Off; |
| 1539 | mAirplaneModeOn.updateState(mAirplaneState); |
| 1540 | } |
| 1541 | |
| 1542 | /** |
| 1543 | * Change the airplane mode system setting |
| 1544 | */ |
| 1545 | private void changeAirplaneModeSystemSetting(boolean on) { |
| 1546 | Settings.Global.putInt( |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 1547 | mContentResolver, |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1548 | Settings.Global.AIRPLANE_MODE_ON, |
| 1549 | on ? 1 : 0); |
| 1550 | Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); |
| 1551 | intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); |
| 1552 | intent.putExtra("state", on); |
| 1553 | mContext.sendBroadcastAsUser(intent, UserHandle.ALL); |
| 1554 | if (!mHasTelephony) { |
| 1555 | mAirplaneState = on ? ToggleAction.State.On : ToggleAction.State.Off; |
| 1556 | } |
| 1557 | } |
| 1558 | |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1559 | private static final class ActionsDialog extends Dialog implements DialogInterface, |
| 1560 | ColorExtractor.OnColorsChangedListener { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1561 | |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1562 | private final Context mContext; |
| 1563 | private final MyAdapter mAdapter; |
Steve Elliott | 53f12ae | 2019-05-13 17:14:15 -0400 | [diff] [blame] | 1564 | private final IStatusBarService mStatusBarService; |
| 1565 | private final IBinder mToken = new Binder(); |
Aaron Heuckroth | 75e249f | 2019-02-01 15:59:57 -0500 | [diff] [blame] | 1566 | private MultiListLayout mGlobalActionsLayout; |
Steve Elliott | e9e7e1f | 2019-03-18 15:54:59 -0400 | [diff] [blame] | 1567 | private Drawable mBackgroundDrawable; |
Lucas Dupin | 2bd3af6 | 2019-03-25 17:44:28 -0700 | [diff] [blame] | 1568 | private final SysuiColorExtractor mColorExtractor; |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 1569 | private final GlobalActionsPanelPlugin.PanelViewController mPanelController; |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1570 | private boolean mKeyguardShowing; |
Beverly | 526d2d6 | 2018-08-15 12:55:33 -0400 | [diff] [blame] | 1571 | private boolean mShowing; |
Steve Elliott | e9e7e1f | 2019-03-18 15:54:59 -0400 | [diff] [blame] | 1572 | private float mScrimAlpha; |
Steve Elliott | 48f75db | 2019-05-03 15:03:38 -0400 | [diff] [blame] | 1573 | private ResetOrientationData mResetOrientationData; |
Steve Elliott | ff2c0d9 | 2019-07-30 15:09:54 -0400 | [diff] [blame] | 1574 | private boolean mHadTopUi; |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 1575 | private final NotificationShadeWindowController mNotificationShadeWindowController; |
Santiago Etchebehere | 68eb53e | 2020-02-25 14:25:34 -0800 | [diff] [blame] | 1576 | private final NotificationShadeDepthController mDepthController; |
Lucas Dupin | 99f5fba | 2020-03-12 12:59:18 -0700 | [diff] [blame^] | 1577 | private final BlurUtils mBlurUtils; |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 1578 | |
| 1579 | private ControlsUiController mControlsUiController; |
| 1580 | private ViewGroup mControlsView; |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1581 | |
Aaron Heuckroth | f19d272 | 2019-03-11 17:06:02 -0400 | [diff] [blame] | 1582 | ActionsDialog(Context context, MyAdapter adapter, |
Santiago Etchebehere | 68eb53e | 2020-02-25 14:25:34 -0800 | [diff] [blame] | 1583 | GlobalActionsPanelPlugin.PanelViewController plugin, |
| 1584 | NotificationShadeDepthController depthController, |
Lucas Dupin | 991415e | 2019-11-25 17:48:58 -0800 | [diff] [blame] | 1585 | SysuiColorExtractor sysuiColorExtractor, IStatusBarService statusBarService, |
| 1586 | NotificationShadeWindowController notificationShadeWindowController, |
Lucas Dupin | 99f5fba | 2020-03-12 12:59:18 -0700 | [diff] [blame^] | 1587 | ControlsUiController controlsUiController, BlurUtils blurUtils) { |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1588 | super(context, com.android.systemui.R.style.Theme_SystemUI_Dialog_GlobalActions); |
Lucas Dupin | 448786c | 2017-07-24 17:44:25 -0700 | [diff] [blame] | 1589 | mContext = context; |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1590 | mAdapter = adapter; |
Santiago Etchebehere | 68eb53e | 2020-02-25 14:25:34 -0800 | [diff] [blame] | 1591 | mDepthController = depthController; |
Lucas Dupin | 991415e | 2019-11-25 17:48:58 -0800 | [diff] [blame] | 1592 | mColorExtractor = sysuiColorExtractor; |
| 1593 | mStatusBarService = statusBarService; |
| 1594 | mNotificationShadeWindowController = notificationShadeWindowController; |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 1595 | mControlsUiController = controlsUiController; |
Lucas Dupin | 99f5fba | 2020-03-12 12:59:18 -0700 | [diff] [blame^] | 1596 | mBlurUtils = blurUtils; |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1597 | |
| 1598 | // Window initialization |
| 1599 | Window window = getWindow(); |
| 1600 | window.requestFeature(Window.FEATURE_NO_TITLE); |
Adrian Roos | edfab3b | 2018-03-08 18:39:20 +0100 | [diff] [blame] | 1601 | // Inflate the decor view, so the attributes below are not overwritten by the theme. |
| 1602 | window.getDecorView(); |
| 1603 | window.getAttributes().systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| 1604 | | View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
| 1605 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; |
| 1606 | window.setLayout(MATCH_PARENT, MATCH_PARENT); |
| 1607 | window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
Alison Cichowlas | 4f19f4a | 2017-07-25 10:56:16 -0400 | [diff] [blame] | 1608 | window.addFlags( |
| 1609 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1610 | | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
Adrian Roos | edfab3b | 2018-03-08 18:39:20 +0100 | [diff] [blame] | 1611 | | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1612 | | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
| 1613 | | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH |
| 1614 | | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED); |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1615 | window.setType(WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY); |
Tiger Huang | 5272444 | 2020-01-20 21:38:42 +0800 | [diff] [blame] | 1616 | window.getAttributes().setFitInsetsTypes(0 /* types */); |
Aaron Heuckroth | 75e249f | 2019-02-01 15:59:57 -0500 | [diff] [blame] | 1617 | setTitle(R.string.global_actions); |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 1618 | |
| 1619 | mPanelController = plugin; |
Steve Elliott | e9e7e1f | 2019-03-18 15:54:59 -0400 | [diff] [blame] | 1620 | initializeLayout(); |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 1621 | } |
| 1622 | |
Aaron Heuckroth | c792661 | 2019-04-02 14:21:57 -0400 | [diff] [blame] | 1623 | private boolean shouldUsePanel() { |
Aran Ink | 3f59455 | 2019-05-13 14:29:35 -0400 | [diff] [blame] | 1624 | return mPanelController != null && mPanelController.getPanelContent() != null; |
Aaron Heuckroth | c792661 | 2019-04-02 14:21:57 -0400 | [diff] [blame] | 1625 | } |
| 1626 | |
| 1627 | private void initializePanel() { |
Steve Elliott | 48f75db | 2019-05-03 15:03:38 -0400 | [diff] [blame] | 1628 | int rotation = RotationUtils.getRotation(mContext); |
| 1629 | boolean rotationLocked = RotationPolicy.isRotationLocked(mContext); |
| 1630 | if (rotation != RotationUtils.ROTATION_NONE) { |
| 1631 | if (rotationLocked) { |
| 1632 | if (mResetOrientationData == null) { |
| 1633 | mResetOrientationData = new ResetOrientationData(); |
| 1634 | mResetOrientationData.locked = true; |
| 1635 | mResetOrientationData.rotation = rotation; |
| 1636 | } |
| 1637 | |
| 1638 | // Unlock rotation, so user can choose to rotate to portrait to see the panel. |
Steve Elliott | e05817f | 2019-05-17 14:39:53 -0400 | [diff] [blame] | 1639 | // This call is posted so that the rotation does not change until post-layout, |
| 1640 | // otherwise onConfigurationChanged() may not get invoked. |
| 1641 | mGlobalActionsLayout.post(() -> |
| 1642 | RotationPolicy.setRotationLockAtAngle( |
| 1643 | mContext, false, RotationUtils.ROTATION_NONE)); |
Steve Elliott | 48f75db | 2019-05-03 15:03:38 -0400 | [diff] [blame] | 1644 | } |
| 1645 | } else { |
| 1646 | if (!rotationLocked) { |
| 1647 | if (mResetOrientationData == null) { |
| 1648 | mResetOrientationData = new ResetOrientationData(); |
| 1649 | mResetOrientationData.locked = false; |
| 1650 | } |
| 1651 | |
| 1652 | // Lock to portrait, so the user doesn't accidentally hide the panel. |
Steve Elliott | e05817f | 2019-05-17 14:39:53 -0400 | [diff] [blame] | 1653 | // This call is posted so that the rotation does not change until post-layout, |
| 1654 | // otherwise onConfigurationChanged() may not get invoked. |
| 1655 | mGlobalActionsLayout.post(() -> |
| 1656 | RotationPolicy.setRotationLockAtAngle( |
| 1657 | mContext, true, RotationUtils.ROTATION_NONE)); |
Steve Elliott | 48f75db | 2019-05-03 15:03:38 -0400 | [diff] [blame] | 1658 | } |
| 1659 | |
Steve Elliott | 53f12ae | 2019-05-13 17:14:15 -0400 | [diff] [blame] | 1660 | // Disable rotation suggestions, if enabled |
| 1661 | setRotationSuggestionsEnabled(false); |
| 1662 | |
Steve Elliott | 300b48f | 2019-05-29 14:13:50 -0400 | [diff] [blame] | 1663 | FrameLayout panelContainer = |
| 1664 | findViewById(com.android.systemui.R.id.global_actions_panel_container); |
Steve Elliott | 48f75db | 2019-05-03 15:03:38 -0400 | [diff] [blame] | 1665 | FrameLayout.LayoutParams panelParams = |
| 1666 | new FrameLayout.LayoutParams( |
| 1667 | FrameLayout.LayoutParams.MATCH_PARENT, |
Steve Elliott | 300b48f | 2019-05-29 14:13:50 -0400 | [diff] [blame] | 1668 | FrameLayout.LayoutParams.MATCH_PARENT); |
Steve Elliott | 48f75db | 2019-05-03 15:03:38 -0400 | [diff] [blame] | 1669 | panelContainer.addView(mPanelController.getPanelContent(), panelParams); |
Steve Elliott | 48f75db | 2019-05-03 15:03:38 -0400 | [diff] [blame] | 1670 | } |
Aaron Heuckroth | 75e249f | 2019-02-01 15:59:57 -0500 | [diff] [blame] | 1671 | } |
| 1672 | |
| 1673 | private void initializeLayout() { |
| 1674 | setContentView(getGlobalActionsLayoutId(mContext)); |
Steve Elliott | 300b48f | 2019-05-29 14:13:50 -0400 | [diff] [blame] | 1675 | fixNavBarClipping(); |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 1676 | mControlsView = findViewById(com.android.systemui.R.id.global_actions_controls); |
Steve Elliott | e9e7e1f | 2019-03-18 15:54:59 -0400 | [diff] [blame] | 1677 | mGlobalActionsLayout = findViewById(com.android.systemui.R.id.global_actions_view); |
Aaron Heuckroth | f708d47 | 2019-01-10 16:54:51 -0500 | [diff] [blame] | 1678 | mGlobalActionsLayout.setOutsideTouchListener(view -> dismiss()); |
Aaron Heuckroth | f708d47 | 2019-01-10 16:54:51 -0500 | [diff] [blame] | 1679 | mGlobalActionsLayout.setListViewAccessibilityDelegate(new View.AccessibilityDelegate() { |
Phil Weaver | 9054e09 | 2018-04-27 16:28:50 -0700 | [diff] [blame] | 1680 | @Override |
| 1681 | public boolean dispatchPopulateAccessibilityEvent( |
| 1682 | View host, AccessibilityEvent event) { |
| 1683 | // Populate the title here, just as Activity does |
| 1684 | event.getText().add(mContext.getString(R.string.global_actions)); |
| 1685 | return true; |
| 1686 | } |
| 1687 | }); |
Aaron Heuckroth | 4ea2fdb | 2019-02-14 16:28:35 -0500 | [diff] [blame] | 1688 | mGlobalActionsLayout.setRotationListener(this::onRotate); |
Aaron Heuckroth | 57d60d2 | 2019-03-05 14:00:12 -0500 | [diff] [blame] | 1689 | mGlobalActionsLayout.setAdapter(mAdapter); |
Steve Elliott | e9e7e1f | 2019-03-18 15:54:59 -0400 | [diff] [blame] | 1690 | |
Aran Ink | 0609026 | 2020-03-03 13:23:17 -0500 | [diff] [blame] | 1691 | View globalActionsParent = (View) mGlobalActionsLayout.getParent(); |
| 1692 | globalActionsParent.setOnClickListener(v -> dismiss()); |
| 1693 | |
| 1694 | // add fall-through dismiss handling to root view |
| 1695 | View rootView = findViewById(com.android.systemui.R.id.global_actions_grid_root); |
| 1696 | if (rootView != null) { |
| 1697 | rootView.setOnClickListener(v -> dismiss()); |
| 1698 | } |
| 1699 | |
Steve Elliott | 86ef628 | 2019-05-08 14:45:04 -0400 | [diff] [blame] | 1700 | if (shouldUsePanel()) { |
Steve Elliott | c59eb34 | 2019-04-23 16:59:06 -0400 | [diff] [blame] | 1701 | initializePanel(); |
Steve Elliott | e9e7e1f | 2019-03-18 15:54:59 -0400 | [diff] [blame] | 1702 | } |
Steve Elliott | 86ef628 | 2019-05-08 14:45:04 -0400 | [diff] [blame] | 1703 | if (mBackgroundDrawable == null) { |
| 1704 | mBackgroundDrawable = new ScrimDrawable(); |
Lucas Dupin | 99f5fba | 2020-03-12 12:59:18 -0700 | [diff] [blame^] | 1705 | mScrimAlpha = mBlurUtils.supportsBlursOnWindows() |
| 1706 | ? ScrimController.BLUR_SCRIM_ALPHA : ScrimController.BUSY_SCRIM_ALPHA; |
Steve Elliott | 86ef628 | 2019-05-08 14:45:04 -0400 | [diff] [blame] | 1707 | } |
Steve Elliott | e9e7e1f | 2019-03-18 15:54:59 -0400 | [diff] [blame] | 1708 | getWindow().setBackgroundDrawable(mBackgroundDrawable); |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 1709 | } |
| 1710 | |
Steve Elliott | 300b48f | 2019-05-29 14:13:50 -0400 | [diff] [blame] | 1711 | private void fixNavBarClipping() { |
| 1712 | ViewGroup content = findViewById(android.R.id.content); |
| 1713 | content.setClipChildren(false); |
| 1714 | content.setClipToPadding(false); |
| 1715 | ViewGroup contentParent = (ViewGroup) content.getParent(); |
| 1716 | contentParent.setClipChildren(false); |
| 1717 | contentParent.setClipToPadding(false); |
| 1718 | } |
| 1719 | |
Aaron Heuckroth | 166392f | 2019-01-17 16:50:59 -0500 | [diff] [blame] | 1720 | private int getGlobalActionsLayoutId(Context context) { |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 1721 | if (mControlsUiController != null) { |
Matt Pietal | fd3b6cb | 2020-01-08 09:43:54 -0500 | [diff] [blame] | 1722 | return com.android.systemui.R.layout.global_actions_grid_v2; |
| 1723 | } |
| 1724 | |
Steve Elliott | dc16563 | 2019-05-23 14:26:31 -0400 | [diff] [blame] | 1725 | int rotation = RotationUtils.getRotation(context); |
| 1726 | boolean useGridLayout = isForceGridEnabled(context) |
| 1727 | || (shouldUsePanel() && rotation == RotationUtils.ROTATION_NONE); |
| 1728 | if (rotation == RotationUtils.ROTATION_SEASCAPE) { |
Aaron Heuckroth | e2d92ac | 2019-05-01 10:44:59 -0400 | [diff] [blame] | 1729 | if (useGridLayout) { |
Aaron Heuckroth | 75e249f | 2019-02-01 15:59:57 -0500 | [diff] [blame] | 1730 | return com.android.systemui.R.layout.global_actions_grid_seascape; |
Aaron Heuckroth | e2d92ac | 2019-05-01 10:44:59 -0400 | [diff] [blame] | 1731 | } else { |
| 1732 | return com.android.systemui.R.layout.global_actions_column_seascape; |
Aaron Heuckroth | 75e249f | 2019-02-01 15:59:57 -0500 | [diff] [blame] | 1733 | } |
Aaron Heuckroth | e2d92ac | 2019-05-01 10:44:59 -0400 | [diff] [blame] | 1734 | } else { |
| 1735 | if (useGridLayout) { |
| 1736 | return com.android.systemui.R.layout.global_actions_grid; |
| 1737 | } else { |
| 1738 | return com.android.systemui.R.layout.global_actions_column; |
| 1739 | } |
Aaron Heuckroth | 166392f | 2019-01-17 16:50:59 -0500 | [diff] [blame] | 1740 | } |
Aaron Heuckroth | 166392f | 2019-01-17 16:50:59 -0500 | [diff] [blame] | 1741 | } |
| 1742 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1743 | @Override |
| 1744 | protected void onStart() { |
| 1745 | super.setCanceledOnTouchOutside(true); |
| 1746 | super.onStart(); |
Aaron Heuckroth | 57d60d2 | 2019-03-05 14:00:12 -0500 | [diff] [blame] | 1747 | mGlobalActionsLayout.updateList(); |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1748 | |
Lucas Dupin | 2bd3af6 | 2019-03-25 17:44:28 -0700 | [diff] [blame] | 1749 | if (mBackgroundDrawable instanceof ScrimDrawable) { |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 1750 | mColorExtractor.addOnColorsChangedListener(this); |
Lucas Dupin | 2bd3af6 | 2019-03-25 17:44:28 -0700 | [diff] [blame] | 1751 | GradientColors colors = mColorExtractor.getNeutralColors(); |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 1752 | updateColors(colors, false /* animate */); |
| 1753 | } |
Lucas Dupin | b5f59fe | 2017-09-14 17:09:39 -0700 | [diff] [blame] | 1754 | } |
| 1755 | |
| 1756 | /** |
| 1757 | * Updates background and system bars according to current GradientColors. |
| 1758 | * @param colors Colors and hints to use. |
| 1759 | * @param animate Interpolates gradient if true, just sets otherwise. |
| 1760 | */ |
| 1761 | private void updateColors(GradientColors colors, boolean animate) { |
Lucas Dupin | 2bd3af6 | 2019-03-25 17:44:28 -0700 | [diff] [blame] | 1762 | if (!(mBackgroundDrawable instanceof ScrimDrawable)) { |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 1763 | return; |
| 1764 | } |
Lucas Dupin | ba2b48a | 2020-02-06 09:28:06 -0800 | [diff] [blame] | 1765 | ((ScrimDrawable) mBackgroundDrawable).setColor(colors.supportsDarkText() ? Color.WHITE |
| 1766 | : Color.BLACK, animate); |
Lucas Dupin | b5f59fe | 2017-09-14 17:09:39 -0700 | [diff] [blame] | 1767 | View decorView = getWindow().getDecorView(); |
| 1768 | if (colors.supportsDarkText()) { |
| 1769 | decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR | |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 1770 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); |
Lucas Dupin | b5f59fe | 2017-09-14 17:09:39 -0700 | [diff] [blame] | 1771 | } else { |
| 1772 | decorView.setSystemUiVisibility(0); |
| 1773 | } |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1774 | } |
| 1775 | |
| 1776 | @Override |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1777 | protected void onStop() { |
| 1778 | super.onStop(); |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1779 | mColorExtractor.removeOnColorsChangedListener(this); |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1780 | } |
| 1781 | |
| 1782 | @Override |
| 1783 | public void show() { |
| 1784 | super.show(); |
Beverly | 526d2d6 | 2018-08-15 12:55:33 -0400 | [diff] [blame] | 1785 | mShowing = true; |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 1786 | mHadTopUi = mNotificationShadeWindowController.getForceHasTopUi(); |
| 1787 | mNotificationShadeWindowController.setForceHasTopUi(true); |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 1788 | mBackgroundDrawable.setAlpha(0); |
Aaron Heuckroth | c792661 | 2019-04-02 14:21:57 -0400 | [diff] [blame] | 1789 | mGlobalActionsLayout.setTranslationX(mGlobalActionsLayout.getAnimationOffsetX()); |
| 1790 | mGlobalActionsLayout.setTranslationY(mGlobalActionsLayout.getAnimationOffsetY()); |
Aaron Heuckroth | f708d47 | 2019-01-10 16:54:51 -0500 | [diff] [blame] | 1791 | mGlobalActionsLayout.setAlpha(0); |
| 1792 | mGlobalActionsLayout.animate() |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1793 | .alpha(1) |
| 1794 | .translationX(0) |
Aaron Heuckroth | c792661 | 2019-04-02 14:21:57 -0400 | [diff] [blame] | 1795 | .translationY(0) |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1796 | .setDuration(300) |
Lucas Dupin | de9db42 | 2017-07-19 17:15:41 -0700 | [diff] [blame] | 1797 | .setInterpolator(Interpolators.FAST_OUT_SLOW_IN) |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1798 | .setUpdateListener(animation -> { |
Lucas Dupin | 991415e | 2019-11-25 17:48:58 -0800 | [diff] [blame] | 1799 | float animatedValue = animation.getAnimatedFraction(); |
| 1800 | int alpha = (int) (animatedValue * mScrimAlpha * 255); |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 1801 | mBackgroundDrawable.setAlpha(alpha); |
Santiago Etchebehere | 68eb53e | 2020-02-25 14:25:34 -0800 | [diff] [blame] | 1802 | mDepthController.updateGlobalDialogVisibility(animatedValue, |
| 1803 | mGlobalActionsLayout); |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1804 | }) |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1805 | .start(); |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 1806 | if (mControlsUiController != null) { |
| 1807 | mControlsUiController.show(mControlsView); |
| 1808 | } |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1809 | } |
| 1810 | |
| 1811 | @Override |
| 1812 | public void dismiss() { |
Beverly | 526d2d6 | 2018-08-15 12:55:33 -0400 | [diff] [blame] | 1813 | if (!mShowing) { |
| 1814 | return; |
| 1815 | } |
| 1816 | mShowing = false; |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 1817 | if (mControlsUiController != null) mControlsUiController.hide(); |
Aaron Heuckroth | f708d47 | 2019-01-10 16:54:51 -0500 | [diff] [blame] | 1818 | mGlobalActionsLayout.setTranslationX(0); |
Aaron Heuckroth | c792661 | 2019-04-02 14:21:57 -0400 | [diff] [blame] | 1819 | mGlobalActionsLayout.setTranslationY(0); |
Aaron Heuckroth | f708d47 | 2019-01-10 16:54:51 -0500 | [diff] [blame] | 1820 | mGlobalActionsLayout.setAlpha(1); |
| 1821 | mGlobalActionsLayout.animate() |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1822 | .alpha(0) |
Aaron Heuckroth | c792661 | 2019-04-02 14:21:57 -0400 | [diff] [blame] | 1823 | .translationX(mGlobalActionsLayout.getAnimationOffsetX()) |
| 1824 | .translationY(mGlobalActionsLayout.getAnimationOffsetY()) |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1825 | .setDuration(300) |
Steve Elliott | ff2c0d9 | 2019-07-30 15:09:54 -0400 | [diff] [blame] | 1826 | .withEndAction(this::completeDismiss) |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1827 | .setInterpolator(new LogAccelerateInterpolator()) |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1828 | .setUpdateListener(animation -> { |
Lucas Dupin | 991415e | 2019-11-25 17:48:58 -0800 | [diff] [blame] | 1829 | float animatedValue = 1f - animation.getAnimatedFraction(); |
| 1830 | int alpha = (int) (animatedValue * mScrimAlpha * 255); |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 1831 | mBackgroundDrawable.setAlpha(alpha); |
Santiago Etchebehere | 68eb53e | 2020-02-25 14:25:34 -0800 | [diff] [blame] | 1832 | mDepthController.updateGlobalDialogVisibility(animatedValue, |
| 1833 | mGlobalActionsLayout); |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1834 | }) |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1835 | .start(); |
Steve Elliott | 48f75db | 2019-05-03 15:03:38 -0400 | [diff] [blame] | 1836 | dismissPanel(); |
| 1837 | resetOrientation(); |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1838 | } |
| 1839 | |
Lucas Dupin | 1d4a579 | 2018-04-02 15:14:59 -0700 | [diff] [blame] | 1840 | void dismissImmediately() { |
Beverly | 526d2d6 | 2018-08-15 12:55:33 -0400 | [diff] [blame] | 1841 | mShowing = false; |
Matt Pietal | 019feaa | 2020-01-31 14:51:37 -0500 | [diff] [blame] | 1842 | if (mControlsUiController != null) mControlsUiController.hide(); |
Steve Elliott | 48f75db | 2019-05-03 15:03:38 -0400 | [diff] [blame] | 1843 | dismissPanel(); |
| 1844 | resetOrientation(); |
Steve Elliott | ff2c0d9 | 2019-07-30 15:09:54 -0400 | [diff] [blame] | 1845 | completeDismiss(); |
| 1846 | } |
| 1847 | |
| 1848 | private void completeDismiss() { |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 1849 | mNotificationShadeWindowController.setForceHasTopUi(mHadTopUi); |
Steve Elliott | ff2c0d9 | 2019-07-30 15:09:54 -0400 | [diff] [blame] | 1850 | super.dismiss(); |
Steve Elliott | 48f75db | 2019-05-03 15:03:38 -0400 | [diff] [blame] | 1851 | } |
| 1852 | |
| 1853 | private void dismissPanel() { |
Steve Elliott | 2d206d3 | 2019-03-14 16:30:33 -0400 | [diff] [blame] | 1854 | if (mPanelController != null) { |
| 1855 | mPanelController.onDismissed(); |
| 1856 | } |
Lucas Dupin | 1d4a579 | 2018-04-02 15:14:59 -0700 | [diff] [blame] | 1857 | } |
| 1858 | |
Steve Elliott | 53f12ae | 2019-05-13 17:14:15 -0400 | [diff] [blame] | 1859 | private void setRotationSuggestionsEnabled(boolean enabled) { |
| 1860 | try { |
| 1861 | final int userId = Binder.getCallingUserHandle().getIdentifier(); |
| 1862 | final int what = enabled |
| 1863 | ? StatusBarManager.DISABLE2_NONE |
| 1864 | : StatusBarManager.DISABLE2_ROTATE_SUGGESTIONS; |
| 1865 | mStatusBarService.disable2ForUser(what, mToken, mContext.getPackageName(), userId); |
| 1866 | } catch (RemoteException ex) { |
| 1867 | throw ex.rethrowFromSystemServer(); |
| 1868 | } |
| 1869 | } |
| 1870 | |
Steve Elliott | 48f75db | 2019-05-03 15:03:38 -0400 | [diff] [blame] | 1871 | private void resetOrientation() { |
| 1872 | if (mResetOrientationData != null) { |
| 1873 | RotationPolicy.setRotationLockAtAngle(mContext, mResetOrientationData.locked, |
| 1874 | mResetOrientationData.rotation); |
| 1875 | } |
Steve Elliott | 53f12ae | 2019-05-13 17:14:15 -0400 | [diff] [blame] | 1876 | setRotationSuggestionsEnabled(true); |
Steve Elliott | 48f75db | 2019-05-03 15:03:38 -0400 | [diff] [blame] | 1877 | } |
| 1878 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1879 | @Override |
Lucas Dupin | 7aaa353 | 2017-05-28 08:51:07 -0700 | [diff] [blame] | 1880 | public void onColorsChanged(ColorExtractor extractor, int which) { |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1881 | if (mKeyguardShowing) { |
| 1882 | if ((WallpaperManager.FLAG_LOCK & which) != 0) { |
Lucas Dupin | b5f59fe | 2017-09-14 17:09:39 -0700 | [diff] [blame] | 1883 | updateColors(extractor.getColors(WallpaperManager.FLAG_LOCK), |
| 1884 | true /* animate */); |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1885 | } |
| 1886 | } else { |
| 1887 | if ((WallpaperManager.FLAG_SYSTEM & which) != 0) { |
Lucas Dupin | b5f59fe | 2017-09-14 17:09:39 -0700 | [diff] [blame] | 1888 | updateColors(extractor.getColors(WallpaperManager.FLAG_SYSTEM), |
| 1889 | true /* animate */); |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1890 | } |
| 1891 | } |
| 1892 | } |
| 1893 | |
| 1894 | public void setKeyguardShowing(boolean keyguardShowing) { |
| 1895 | mKeyguardShowing = keyguardShowing; |
| 1896 | } |
Aaron Heuckroth | 4ea2fdb | 2019-02-14 16:28:35 -0500 | [diff] [blame] | 1897 | |
Aaron Heuckroth | 4ef3a54 | 2019-04-01 14:17:23 -0400 | [diff] [blame] | 1898 | public void refreshDialog() { |
| 1899 | initializeLayout(); |
| 1900 | mGlobalActionsLayout.updateList(); |
| 1901 | } |
| 1902 | |
Aaron Heuckroth | 4ea2fdb | 2019-02-14 16:28:35 -0500 | [diff] [blame] | 1903 | public void onRotate(int from, int to) { |
Aaron Heuckroth | e2d92ac | 2019-05-01 10:44:59 -0400 | [diff] [blame] | 1904 | if (mShowing) { |
Aaron Heuckroth | 4ef3a54 | 2019-04-01 14:17:23 -0400 | [diff] [blame] | 1905 | refreshDialog(); |
Aaron Heuckroth | 4ea2fdb | 2019-02-14 16:28:35 -0500 | [diff] [blame] | 1906 | } |
| 1907 | } |
Steve Elliott | 48f75db | 2019-05-03 15:03:38 -0400 | [diff] [blame] | 1908 | |
| 1909 | private static class ResetOrientationData { |
| 1910 | public boolean locked; |
| 1911 | public int rotation; |
| 1912 | } |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1913 | } |
Aaron Heuckroth | 75e249f | 2019-02-01 15:59:57 -0500 | [diff] [blame] | 1914 | |
| 1915 | /** |
Aran Ink | 93dd25c | 2019-05-09 14:42:14 -0400 | [diff] [blame] | 1916 | * Determines whether or not debug mode has been activated for the Global Actions Panel. |
| 1917 | */ |
| 1918 | private static boolean isPanelDebugModeEnabled(Context context) { |
| 1919 | return Settings.Secure.getInt(context.getContentResolver(), |
| 1920 | Settings.Secure.GLOBAL_ACTIONS_PANEL_DEBUG_ENABLED, 0) == 1; |
| 1921 | } |
| 1922 | |
| 1923 | /** |
Aaron Heuckroth | c792661 | 2019-04-02 14:21:57 -0400 | [diff] [blame] | 1924 | * Determines whether or not the Global Actions menu should be forced to |
| 1925 | * use the newer grid-style layout. |
Aaron Heuckroth | 75e249f | 2019-02-01 15:59:57 -0500 | [diff] [blame] | 1926 | */ |
Aaron Heuckroth | c792661 | 2019-04-02 14:21:57 -0400 | [diff] [blame] | 1927 | private static boolean isForceGridEnabled(Context context) { |
Aran Ink | 93dd25c | 2019-05-09 14:42:14 -0400 | [diff] [blame] | 1928 | return isPanelDebugModeEnabled(context); |
Aaron Heuckroth | 75e249f | 2019-02-01 15:59:57 -0500 | [diff] [blame] | 1929 | } |
Aaron Heuckroth | f19d272 | 2019-03-11 17:06:02 -0400 | [diff] [blame] | 1930 | |
Matt Pietal | e0661b6 | 2020-01-29 14:35:31 -0500 | [diff] [blame] | 1931 | private boolean shouldShowControls() { |
Fabian Kozynski | f6063ae | 2020-02-24 16:14:35 -0500 | [diff] [blame] | 1932 | return mKeyguardStateController.isUnlocked() |
Fabian Kozynski | 0424ab1 | 2020-02-21 12:09:17 -0500 | [diff] [blame] | 1933 | && mControlsUiController.getAvailable() |
| 1934 | && mAnyControlsProviders; |
Matt Pietal | fd3b6cb | 2020-01-08 09:43:54 -0500 | [diff] [blame] | 1935 | } |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1936 | } |