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