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