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