blob: dc7b1ef9a092dbdbe2e1c6103538894d1cb9f653 [file] [log] [blame]
Jason Monk361915c2017-03-21 20:33:59 -04001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 * except in compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the
10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11 * KIND, either express or implied. See the License for the specific language governing
12 * permissions and limitations under the License.
13 */
14
15package com.android.systemui.globalactions;
16
Adrian Roosedfab3b2018-03-08 18:39:20 +010017import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
Adrian Roos2f05bb32018-02-19 16:42:27 +010018import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
19
Chad Brubakerf4075fe2018-01-03 13:23:22 -080020import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_USER_REQUEST;
21import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_NOT_REQUIRED;
Chad Brubaker4f28f0d2017-09-07 14:28:13 -070022import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN;
23
Jason Monk361915c2017-03-21 20:33:59 -040024import android.app.ActivityManager;
25import android.app.Dialog;
Chad Brubakerf4075fe2018-01-03 13:23:22 -080026import android.app.KeyguardManager;
Lucas Dupinc1cc7592017-05-22 15:56:16 -070027import android.app.WallpaperManager;
Alex Chau04458852017-11-27 18:21:23 +000028import android.app.admin.DevicePolicyManager;
Pavel Grafov059021b2018-05-02 13:44:46 +010029import android.app.trust.TrustManager;
Jason Monk361915c2017-03-21 20:33:59 -040030import android.content.BroadcastReceiver;
31import android.content.Context;
32import android.content.DialogInterface;
33import android.content.Intent;
34import android.content.IntentFilter;
35import android.content.pm.UserInfo;
36import android.database.ContentObserver;
Lucas Dupinc1cc7592017-05-22 15:56:16 -070037import android.graphics.Point;
Jason Monk361915c2017-03-21 20:33:59 -040038import android.graphics.drawable.Drawable;
39import android.media.AudioManager;
40import android.net.ConnectivityManager;
41import android.os.Build;
Jason Monk361915c2017-03-21 20:33:59 -040042import android.os.Handler;
43import android.os.Message;
44import android.os.RemoteException;
45import android.os.ServiceManager;
46import android.os.SystemProperties;
47import android.os.UserHandle;
48import android.os.UserManager;
49import android.os.Vibrator;
50import android.provider.Settings;
51import android.service.dreams.DreamService;
52import android.service.dreams.IDreamManager;
53import android.telephony.PhoneStateListener;
54import android.telephony.ServiceState;
55import android.telephony.TelephonyManager;
56import android.text.TextUtils;
57import android.util.ArraySet;
yuanjiahsu88363e92018-09-06 19:23:52 +080058import android.util.FeatureFlagUtils;
Jason Monk361915c2017-03-21 20:33:59 -040059import android.util.Log;
Lucas Dupin448786c2017-07-24 17:44:25 -070060import android.view.ContextThemeWrapper;
Jason Monk361915c2017-03-21 20:33:59 -040061import android.view.LayoutInflater;
62import android.view.View;
63import android.view.ViewGroup;
Lucas Dupinc1cc7592017-05-22 15:56:16 -070064import android.view.Window;
Jason Monk361915c2017-03-21 20:33:59 -040065import android.view.WindowManager;
66import android.view.WindowManagerGlobal;
67import android.view.accessibility.AccessibilityEvent;
Jason Monk16fbd9d2017-04-27 14:28:49 -040068import android.widget.AdapterView.OnItemLongClickListener;
Jason Monk361915c2017-03-21 20:33:59 -040069import android.widget.BaseAdapter;
Wesley.CW Wang3004fcb2018-06-15 16:24:57 +080070import android.widget.FrameLayout;
Jason Monk361915c2017-03-21 20:33:59 -040071import android.widget.ImageView;
72import android.widget.ImageView.ScaleType;
Jason Monk16fbd9d2017-04-27 14:28:49 -040073import android.widget.LinearLayout;
Jason Monk361915c2017-03-21 20:33:59 -040074import android.widget.TextView;
75
Charles He9851a8d2017-10-10 17:31:30 +010076import com.android.internal.R;
77import com.android.internal.colorextraction.ColorExtractor;
78import com.android.internal.colorextraction.ColorExtractor.GradientColors;
Lucas Dupine2292a92017-07-06 14:35:30 -070079import com.android.internal.colorextraction.drawable.GradientDrawable;
Charles He9851a8d2017-10-10 17:31:30 +010080import com.android.internal.logging.MetricsLogger;
81import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
82import com.android.internal.telephony.TelephonyIntents;
83import com.android.internal.telephony.TelephonyProperties;
84import com.android.internal.util.EmergencyAffordanceManager;
Beth Thibodeau5898ac42018-10-26 13:00:09 -040085import com.android.internal.util.ScreenRecordHelper;
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -050086import com.android.internal.util.ScreenshotHelper;
Charles He9851a8d2017-10-10 17:31:30 +010087import com.android.internal.widget.LockPatternUtils;
88import com.android.systemui.Dependency;
89import com.android.systemui.HardwareUiLayout;
90import com.android.systemui.Interpolators;
91import com.android.systemui.colorextraction.SysuiColorExtractor;
92import com.android.systemui.plugins.GlobalActions.GlobalActionsManager;
93import com.android.systemui.statusbar.phone.ScrimController;
Lucas Dupine5b7dc72018-10-02 15:18:05 -070094import com.android.systemui.statusbar.policy.ConfigurationController;
Shaotang Li5c422632018-07-04 14:18:40 +080095import com.android.systemui.util.EmergencyDialerConstants;
Julia Reynolds42411922017-11-08 11:19:09 -050096import com.android.systemui.volume.SystemUIInterpolators.LogAccelerateInterpolator;
Lucas Dupinc1cc7592017-05-22 15:56:16 -070097
Jason Monk361915c2017-03-21 20:33:59 -040098import java.util.ArrayList;
99import java.util.List;
100
101/**
102 * Helper to show the global actions dialog. Each item is an {@link Action} that
103 * may show depending on whether the keyguard is showing, and whether the device
104 * is provisioned.
105 */
Charles He9851a8d2017-10-10 17:31:30 +0100106class GlobalActionsDialog implements DialogInterface.OnDismissListener,
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700107 DialogInterface.OnClickListener, DialogInterface.OnShowListener,
108 ConfigurationController.ConfigurationListener {
Jason Monk361915c2017-03-21 20:33:59 -0400109
110 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
111 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
Lucas Dupin1d4a5792018-04-02 15:14:59 -0700112 static public final String SYSTEM_DIALOG_REASON_DREAM = "dream";
Jason Monk361915c2017-03-21 20:33:59 -0400113
114 private static final String TAG = "GlobalActionsDialog";
115
116 private static final boolean SHOW_SILENT_TOGGLE = true;
117
118 /* Valid settings for global actions keys.
119 * see config.xml config_globalActionList */
120 private static final String GLOBAL_ACTION_KEY_POWER = "power";
121 private static final String GLOBAL_ACTION_KEY_AIRPLANE = "airplane";
122 private static final String GLOBAL_ACTION_KEY_BUGREPORT = "bugreport";
123 private static final String GLOBAL_ACTION_KEY_SILENT = "silent";
124 private static final String GLOBAL_ACTION_KEY_USERS = "users";
125 private static final String GLOBAL_ACTION_KEY_SETTINGS = "settings";
126 private static final String GLOBAL_ACTION_KEY_LOCKDOWN = "lockdown";
127 private static final String GLOBAL_ACTION_KEY_VOICEASSIST = "voiceassist";
128 private static final String GLOBAL_ACTION_KEY_ASSIST = "assist";
129 private static final String GLOBAL_ACTION_KEY_RESTART = "restart";
Alex Chau04458852017-11-27 18:21:23 +0000130 private static final String GLOBAL_ACTION_KEY_LOGOUT = "logout";
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800131 private static final String GLOBAL_ACTION_KEY_EMERGENCY = "emergency";
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500132 private static final String GLOBAL_ACTION_KEY_SCREENSHOT = "screenshot";
Jason Monk361915c2017-03-21 20:33:59 -0400133
134 private final Context mContext;
135 private final GlobalActionsManager mWindowManagerFuncs;
136 private final AudioManager mAudioManager;
137 private final IDreamManager mDreamManager;
Alex Chau04458852017-11-27 18:21:23 +0000138 private final DevicePolicyManager mDevicePolicyManager;
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800139 private final LockPatternUtils mLockPatternUtils;
140 private final KeyguardManager mKeyguardManager;
Jason Monk361915c2017-03-21 20:33:59 -0400141
142 private ArrayList<Action> mItems;
143 private ActionsDialog mDialog;
144
145 private Action mSilentModeAction;
146 private ToggleAction mAirplaneModeOn;
147
148 private MyAdapter mAdapter;
149
150 private boolean mKeyguardShowing = false;
151 private boolean mDeviceProvisioned = false;
152 private ToggleAction.State mAirplaneState = ToggleAction.State.Off;
153 private boolean mIsWaitingForEcmExit = false;
154 private boolean mHasTelephony;
155 private boolean mHasVibrator;
Alex Chau04458852017-11-27 18:21:23 +0000156 private boolean mHasLogoutButton;
Chad Brubaker72a73ea2018-01-26 15:56:55 -0800157 private boolean mHasLockdownButton;
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800158 private boolean mSeparatedEmergencyButtonEnabled;
Jason Monk361915c2017-03-21 20:33:59 -0400159 private final boolean mShowSilentToggle;
160 private final EmergencyAffordanceManager mEmergencyAffordanceManager;
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500161 private final ScreenshotHelper mScreenshotHelper;
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400162 private final ScreenRecordHelper mScreenRecordHelper;
Jason Monk361915c2017-03-21 20:33:59 -0400163
164 /**
165 * @param context everything needs a context :(
166 */
167 public GlobalActionsDialog(Context context, GlobalActionsManager windowManagerFuncs) {
Lucas Dupin448786c2017-07-24 17:44:25 -0700168 mContext = new ContextThemeWrapper(context, com.android.systemui.R.style.qs_theme);
Jason Monk361915c2017-03-21 20:33:59 -0400169 mWindowManagerFuncs = windowManagerFuncs;
170 mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
171 mDreamManager = IDreamManager.Stub.asInterface(
172 ServiceManager.getService(DreamService.DREAM_SERVICE));
Alex Chau04458852017-11-27 18:21:23 +0000173 mDevicePolicyManager = (DevicePolicyManager) mContext.getSystemService(
174 Context.DEVICE_POLICY_SERVICE);
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800175 mLockPatternUtils = new LockPatternUtils(mContext);
176 mKeyguardManager = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE);
Jason Monk361915c2017-03-21 20:33:59 -0400177
178 // receive broadcasts
179 IntentFilter filter = new IntentFilter();
180 filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
181 filter.addAction(Intent.ACTION_SCREEN_OFF);
182 filter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
183 context.registerReceiver(mBroadcastReceiver, filter);
184
185 ConnectivityManager cm = (ConnectivityManager)
186 context.getSystemService(Context.CONNECTIVITY_SERVICE);
187 mHasTelephony = cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE);
188
189 // get notified of phone state changes
190 TelephonyManager telephonyManager =
191 (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
192 telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE);
193 mContext.getContentResolver().registerContentObserver(
194 Settings.Global.getUriFor(Settings.Global.AIRPLANE_MODE_ON), true,
195 mAirplaneModeObserver);
196 Vibrator vibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
197 mHasVibrator = vibrator != null && vibrator.hasVibrator();
198
199 mShowSilentToggle = SHOW_SILENT_TOGGLE && !mContext.getResources().getBoolean(
200 R.bool.config_useFixedVolume);
201
202 mEmergencyAffordanceManager = new EmergencyAffordanceManager(context);
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500203 mScreenshotHelper = new ScreenshotHelper(context);
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400204 mScreenRecordHelper = new ScreenRecordHelper(context);
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700205
206 Dependency.get(ConfigurationController.class).addCallback(this);
Jason Monk361915c2017-03-21 20:33:59 -0400207 }
208
209 /**
210 * Show the global actions dialog (creating if necessary)
Jason Monk16fbd9d2017-04-27 14:28:49 -0400211 *
Jason Monk361915c2017-03-21 20:33:59 -0400212 * @param keyguardShowing True if keyguard is showing
213 */
214 public void showDialog(boolean keyguardShowing, boolean isDeviceProvisioned) {
215 mKeyguardShowing = keyguardShowing;
216 mDeviceProvisioned = isDeviceProvisioned;
217 if (mDialog != null) {
218 mDialog.dismiss();
219 mDialog = null;
220 // Show delayed, so that the dismiss of the previous dialog completes
221 mHandler.sendEmptyMessage(MESSAGE_SHOW);
222 } else {
223 handleShow();
224 }
225 }
226
Charles He9851a8d2017-10-10 17:31:30 +0100227 /**
228 * Dismiss the global actions dialog, if it's currently shown
229 */
230 public void dismissDialog() {
231 mHandler.removeMessages(MESSAGE_DISMISS);
232 mHandler.sendEmptyMessage(MESSAGE_DISMISS);
233 }
234
Jason Monk361915c2017-03-21 20:33:59 -0400235 private void awakenIfNecessary() {
236 if (mDreamManager != null) {
237 try {
238 if (mDreamManager.isDreaming()) {
239 mDreamManager.awaken();
240 }
241 } catch (RemoteException e) {
242 // we tried
243 }
244 }
245 }
246
247 private void handleShow() {
248 awakenIfNecessary();
249 mDialog = createDialog();
250 prepareDialog();
251
252 // If we only have 1 item and it's a simple press action, just do this action.
253 if (mAdapter.getCount() == 1
254 && mAdapter.getItem(0) instanceof SinglePressAction
255 && !(mAdapter.getItem(0) instanceof LongPressAction)) {
256 ((SinglePressAction) mAdapter.getItem(0)).onPress();
257 } else {
258 WindowManager.LayoutParams attrs = mDialog.getWindow().getAttributes();
259 attrs.setTitle("ActionsDialog");
Adrian Roos2f05bb32018-02-19 16:42:27 +0100260 attrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
Jason Monk361915c2017-03-21 20:33:59 -0400261 mDialog.getWindow().setAttributes(attrs);
262 mDialog.show();
263 mWindowManagerFuncs.onGlobalActionsShown();
Jason Monk361915c2017-03-21 20:33:59 -0400264 }
265 }
266
267 /**
268 * Create the global actions dialog.
Jason Monk16fbd9d2017-04-27 14:28:49 -0400269 *
Jason Monk361915c2017-03-21 20:33:59 -0400270 * @return A new dialog.
271 */
272 private ActionsDialog createDialog() {
273 // Simple toggle style if there's no vibrator, otherwise use a tri-state
274 if (!mHasVibrator) {
275 mSilentModeAction = new SilentModeToggleAction();
276 } else {
Lucas Dupin40ec6b782018-06-05 19:07:16 -0700277 mSilentModeAction = new SilentModeTriStateAction(mAudioManager, mHandler);
Jason Monk361915c2017-03-21 20:33:59 -0400278 }
279 mAirplaneModeOn = new ToggleAction(
280 R.drawable.ic_lock_airplane_mode,
281 R.drawable.ic_lock_airplane_mode_off,
282 R.string.global_actions_toggle_airplane_mode,
283 R.string.global_actions_airplane_mode_on_status,
284 R.string.global_actions_airplane_mode_off_status) {
285
286 void onToggle(boolean on) {
287 if (mHasTelephony && Boolean.parseBoolean(
288 SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) {
289 mIsWaitingForEcmExit = true;
290 // Launch ECM exit dialog
291 Intent ecmDialogIntent =
292 new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null);
293 ecmDialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
294 mContext.startActivity(ecmDialogIntent);
295 } else {
296 changeAirplaneModeSystemSetting(on);
297 }
298 }
299
300 @Override
301 protected void changeStateFromPress(boolean buttonOn) {
302 if (!mHasTelephony) return;
303
304 // In ECM mode airplane state cannot be changed
305 if (!(Boolean.parseBoolean(
306 SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE)))) {
307 mState = buttonOn ? State.TurningOn : State.TurningOff;
308 mAirplaneState = mState;
309 }
310 }
311
312 public boolean showDuringKeyguard() {
313 return true;
314 }
315
316 public boolean showBeforeProvisioning() {
317 return false;
318 }
319 };
320 onAirplaneModeChanged();
321
322 mItems = new ArrayList<Action>();
323 String[] defaultActions = mContext.getResources().getStringArray(
324 R.array.config_globalActionsList);
325
326 ArraySet<String> addedKeys = new ArraySet<String>();
Alex Chau04458852017-11-27 18:21:23 +0000327 mHasLogoutButton = false;
Chad Brubaker72a73ea2018-01-26 15:56:55 -0800328 mHasLockdownButton = false;
yuanjiahsu88363e92018-09-06 19:23:52 +0800329 mSeparatedEmergencyButtonEnabled = FeatureFlagUtils
330 .isEnabled(mContext, FeatureFlagUtils.EMERGENCY_DIAL_SHORTCUTS);
Jason Monk361915c2017-03-21 20:33:59 -0400331 for (int i = 0; i < defaultActions.length; i++) {
332 String actionKey = defaultActions[i];
333 if (addedKeys.contains(actionKey)) {
334 // If we already have added this, don't add it again.
335 continue;
336 }
337 if (GLOBAL_ACTION_KEY_POWER.equals(actionKey)) {
338 mItems.add(new PowerAction());
339 } else if (GLOBAL_ACTION_KEY_AIRPLANE.equals(actionKey)) {
340 mItems.add(mAirplaneModeOn);
341 } else if (GLOBAL_ACTION_KEY_BUGREPORT.equals(actionKey)) {
342 if (Settings.Global.getInt(mContext.getContentResolver(),
343 Settings.Global.BUGREPORT_IN_POWER_MENU, 0) != 0 && isCurrentUserOwner()) {
344 mItems.add(new BugReportAction());
345 }
346 } else if (GLOBAL_ACTION_KEY_SILENT.equals(actionKey)) {
347 if (mShowSilentToggle) {
348 mItems.add(mSilentModeAction);
349 }
350 } else if (GLOBAL_ACTION_KEY_USERS.equals(actionKey)) {
351 if (SystemProperties.getBoolean("fw.power_user_switcher", false)) {
352 addUsersToMenu(mItems);
353 }
354 } else if (GLOBAL_ACTION_KEY_SETTINGS.equals(actionKey)) {
355 mItems.add(getSettingsAction());
356 } else if (GLOBAL_ACTION_KEY_LOCKDOWN.equals(actionKey)) {
Chad Brubaker02cd6cf2018-05-01 14:59:33 -0700357 if (Settings.Secure.getIntForUser(mContext.getContentResolver(),
358 Settings.Secure.LOCKDOWN_IN_POWER_MENU, 0, getCurrentUser().id) != 0
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800359 && shouldDisplayLockdown()) {
Chad Brubaker4f28f0d2017-09-07 14:28:13 -0700360 mItems.add(getLockdownAction());
Chad Brubaker72a73ea2018-01-26 15:56:55 -0800361 mHasLockdownButton = true;
Chad Brubaker4f28f0d2017-09-07 14:28:13 -0700362 }
Jason Monk361915c2017-03-21 20:33:59 -0400363 } else if (GLOBAL_ACTION_KEY_VOICEASSIST.equals(actionKey)) {
364 mItems.add(getVoiceAssistAction());
365 } else if (GLOBAL_ACTION_KEY_ASSIST.equals(actionKey)) {
366 mItems.add(getAssistAction());
367 } else if (GLOBAL_ACTION_KEY_RESTART.equals(actionKey)) {
368 mItems.add(new RestartAction());
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500369 } else if (GLOBAL_ACTION_KEY_SCREENSHOT.equals(actionKey)) {
370 mItems.add(new ScreenshotAction());
Alex Chau04458852017-11-27 18:21:23 +0000371 } else if (GLOBAL_ACTION_KEY_LOGOUT.equals(actionKey)) {
Alex Chaud7958272017-12-08 11:30:52 +0000372 if (mDevicePolicyManager.isLogoutEnabled()
Alex Chau04458852017-11-27 18:21:23 +0000373 && getCurrentUser().id != UserHandle.USER_SYSTEM) {
374 mItems.add(new LogoutAction());
375 mHasLogoutButton = true;
376 }
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800377 } else if (GLOBAL_ACTION_KEY_EMERGENCY.equals(actionKey)) {
378 if (mSeparatedEmergencyButtonEnabled
379 && !mEmergencyAffordanceManager.needsEmergencyAffordance()) {
380 mItems.add(new EmergencyDialerAction());
381 }
Jason Monk361915c2017-03-21 20:33:59 -0400382 } else {
383 Log.e(TAG, "Invalid global action key " + actionKey);
384 }
385 // Add here so we don't add more than one.
386 addedKeys.add(actionKey);
387 }
388
389 if (mEmergencyAffordanceManager.needsEmergencyAffordance()) {
390 mItems.add(getEmergencyAction());
391 }
392
393 mAdapter = new MyAdapter();
394
Lucas Dupin1d4a5792018-04-02 15:14:59 -0700395 OnItemLongClickListener onItemLongClickListener = (parent, view, position, id) -> {
396 final Action action = mAdapter.getItem(position);
397 if (action instanceof LongPressAction) {
398 mDialog.dismiss();
399 return ((LongPressAction) action).onLongPress();
Jason Monk16fbd9d2017-04-27 14:28:49 -0400400 }
Lucas Dupin1d4a5792018-04-02 15:14:59 -0700401 return false;
Jason Monk16fbd9d2017-04-27 14:28:49 -0400402 };
Wesley.CW Wang3004fcb2018-06-15 16:24:57 +0800403 ActionsDialog dialog = new ActionsDialog(mContext, this, mAdapter, onItemLongClickListener,
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800404 mSeparatedEmergencyButtonEnabled);
Jason Monk361915c2017-03-21 20:33:59 -0400405 dialog.setCanceledOnTouchOutside(false); // Handled by the custom class.
Lucas Dupinc1cc7592017-05-22 15:56:16 -0700406 dialog.setKeyguardShowing(mKeyguardShowing);
Jason Monk361915c2017-03-21 20:33:59 -0400407
408 dialog.setOnDismissListener(this);
Shaotang Li786da902018-08-02 11:18:00 +0800409 dialog.setOnShowListener(this);
Jason Monk361915c2017-03-21 20:33:59 -0400410
411 return dialog;
412 }
413
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800414 private boolean shouldDisplayLockdown() {
415 int userId = getCurrentUser().id;
416 // Lockdown is meaningless without a place to go.
417 if (!mKeyguardManager.isDeviceSecure(userId)) {
418 return false;
419 }
420
421 // Only show the lockdown button if the device isn't locked down (for whatever reason).
422 int state = mLockPatternUtils.getStrongAuthForUser(userId);
423 return (state == STRONG_AUTH_NOT_REQUIRED
424 || state == SOME_AUTH_REQUIRED_AFTER_USER_REQUEST);
425 }
426
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700427 @Override
428 public void onUiModeChanged() {
429 mContext.getTheme().applyStyle(mContext.getThemeResId(), true);
430 }
431
432 public void destroy() {
433 Dependency.get(ConfigurationController.class).removeCallback(this);
434 }
435
Jason Monk361915c2017-03-21 20:33:59 -0400436 private final class PowerAction extends SinglePressAction implements LongPressAction {
437 private PowerAction() {
438 super(R.drawable.ic_lock_power_off,
Jason Monk16fbd9d2017-04-27 14:28:49 -0400439 R.string.global_action_power_off);
Jason Monk361915c2017-03-21 20:33:59 -0400440 }
441
442 @Override
443 public boolean onLongPress() {
444 UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
445 if (!um.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) {
446 mWindowManagerFuncs.reboot(true);
447 return true;
448 }
449 return false;
450 }
451
452 @Override
453 public boolean showDuringKeyguard() {
454 return true;
455 }
456
457 @Override
458 public boolean showBeforeProvisioning() {
459 return true;
460 }
461
462 @Override
463 public void onPress() {
464 // shutdown by making sure radio and power are handled accordingly.
465 mWindowManagerFuncs.shutdown();
466 }
467 }
468
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800469 private class EmergencyDialerAction extends SinglePressAction {
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800470 private EmergencyDialerAction() {
471 super(R.drawable.ic_faster_emergency,
Wesley.CW Wang3004fcb2018-06-15 16:24:57 +0800472 R.string.global_action_emergency);
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800473 }
474
475 @Override
476 public void onPress() {
Shaotang Li786da902018-08-02 11:18:00 +0800477 MetricsLogger.action(mContext, MetricsEvent.ACTION_EMERGENCY_DIALER_FROM_POWER_MENU);
Shaotang Li5c422632018-07-04 14:18:40 +0800478 Intent intent = new Intent(EmergencyDialerConstants.ACTION_DIAL);
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800479 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
Shaotang Li5c422632018-07-04 14:18:40 +0800480 intent.putExtra(EmergencyDialerConstants.EXTRA_ENTRY_TYPE,
481 EmergencyDialerConstants.ENTRY_TYPE_POWER_MENU);
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800482 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
483 }
484
485 @Override
486 public boolean showDuringKeyguard() {
487 return true;
488 }
489
490 @Override
491 public boolean showBeforeProvisioning() {
492 return true;
493 }
494 }
495
Jason Monk361915c2017-03-21 20:33:59 -0400496 private final class RestartAction extends SinglePressAction implements LongPressAction {
497 private RestartAction() {
498 super(R.drawable.ic_restart, R.string.global_action_restart);
499 }
500
501 @Override
502 public boolean onLongPress() {
503 UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
504 if (!um.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) {
505 mWindowManagerFuncs.reboot(true);
506 return true;
507 }
508 return false;
509 }
510
511 @Override
512 public boolean showDuringKeyguard() {
513 return true;
514 }
515
516 @Override
517 public boolean showBeforeProvisioning() {
518 return true;
519 }
520
521 @Override
522 public void onPress() {
523 mWindowManagerFuncs.reboot(false);
524 }
525 }
526
527
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400528 private class ScreenshotAction extends SinglePressAction implements LongPressAction {
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500529 public ScreenshotAction() {
530 super(R.drawable.ic_screenshot, R.string.global_action_screenshot);
531 }
532
533 @Override
534 public void onPress() {
535 // Add a little delay before executing, to give the
536 // dialog a chance to go away before it takes a
537 // screenshot.
538 // TODO: instead, omit global action dialog layer
539 mHandler.postDelayed(new Runnable() {
540 @Override
541 public void run() {
542 mScreenshotHelper.takeScreenshot(1, true, true, mHandler);
543 MetricsLogger.action(mContext,
544 MetricsEvent.ACTION_SCREENSHOT_POWER_MENU);
545 }
546 }, 500);
547 }
548
549 @Override
550 public boolean showDuringKeyguard() {
551 return true;
552 }
553
554 @Override
555 public boolean showBeforeProvisioning() {
556 return false;
557 }
Beth Thibodeau5898ac42018-10-26 13:00:09 -0400558
559 @Override
560 public boolean onLongPress() {
561 if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SCREENRECORD_LONG_PRESS)) {
562 mScreenRecordHelper.launchRecordPrompt();
563 } else {
564 onPress();
565 }
566 return true;
567 }
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500568 }
569
Jason Monk361915c2017-03-21 20:33:59 -0400570 private class BugReportAction extends SinglePressAction implements LongPressAction {
571
572 public BugReportAction() {
573 super(R.drawable.ic_lock_bugreport, R.string.bugreport_title);
574 }
575
576 @Override
577 public void onPress() {
578 // don't actually trigger the bugreport if we are running stability
579 // tests via monkey
580 if (ActivityManager.isUserAMonkey()) {
581 return;
582 }
583 // Add a little delay before executing, to give the
584 // dialog a chance to go away before it takes a
585 // screenshot.
586 mHandler.postDelayed(new Runnable() {
587 @Override
588 public void run() {
589 try {
590 // Take an "interactive" bugreport.
591 MetricsLogger.action(mContext,
592 MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_INTERACTIVE);
593 ActivityManager.getService().requestBugReport(
594 ActivityManager.BUGREPORT_OPTION_INTERACTIVE);
595 } catch (RemoteException e) {
596 }
597 }
598 }, 500);
599 }
600
601 @Override
602 public boolean onLongPress() {
603 // don't actually trigger the bugreport if we are running stability
604 // tests via monkey
605 if (ActivityManager.isUserAMonkey()) {
606 return false;
607 }
608 try {
609 // Take a "full" bugreport.
610 MetricsLogger.action(mContext, MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_FULL);
611 ActivityManager.getService().requestBugReport(
612 ActivityManager.BUGREPORT_OPTION_FULL);
613 } catch (RemoteException e) {
614 }
615 return false;
616 }
617
618 public boolean showDuringKeyguard() {
619 return true;
620 }
621
622 @Override
623 public boolean showBeforeProvisioning() {
624 return false;
625 }
626
627 @Override
628 public String getStatus() {
629 return mContext.getString(
630 R.string.bugreport_status,
631 Build.VERSION.RELEASE,
632 Build.ID);
633 }
634 }
635
Alex Chau04458852017-11-27 18:21:23 +0000636 private final class LogoutAction extends SinglePressAction {
637 private LogoutAction() {
638 super(R.drawable.ic_logout, R.string.global_action_logout);
639 }
640
641 @Override
642 public boolean showDuringKeyguard() {
643 return true;
644 }
645
646 @Override
647 public boolean showBeforeProvisioning() {
648 return false;
649 }
650
651 @Override
652 public void onPress() {
653 // Add a little delay before executing, to give the dialog a chance to go away before
654 // switching user
655 mHandler.postDelayed(() -> {
656 try {
Alex Chauedb6a012018-01-26 12:52:43 +0000657 int currentUserId = getCurrentUser().id;
Alex Chau04458852017-11-27 18:21:23 +0000658 ActivityManager.getService().switchUser(UserHandle.USER_SYSTEM);
Alex Chauedb6a012018-01-26 12:52:43 +0000659 ActivityManager.getService().stopUser(currentUserId, true /*force*/, null);
Alex Chau04458852017-11-27 18:21:23 +0000660 } catch (RemoteException re) {
661 Log.e(TAG, "Couldn't logout user " + re);
662 }
663 }, 500);
664 }
665 }
666
Jason Monk361915c2017-03-21 20:33:59 -0400667 private Action getSettingsAction() {
668 return new SinglePressAction(R.drawable.ic_settings,
669 R.string.global_action_settings) {
670
671 @Override
672 public void onPress() {
673 Intent intent = new Intent(Settings.ACTION_SETTINGS);
674 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
675 mContext.startActivity(intent);
676 }
677
678 @Override
679 public boolean showDuringKeyguard() {
680 return true;
681 }
682
683 @Override
684 public boolean showBeforeProvisioning() {
685 return true;
686 }
687 };
688 }
689
690 private Action getEmergencyAction() {
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800691 Drawable emergencyIcon = mContext.getDrawable(R.drawable.emergency_icon);
692 if(!mSeparatedEmergencyButtonEnabled) {
693 // use un-colored legacy treatment
694 emergencyIcon.setTintList(null);
695 }
696
Jason Monk361915c2017-03-21 20:33:59 -0400697 return new SinglePressAction(R.drawable.emergency_icon,
698 R.string.global_action_emergency) {
699 @Override
700 public void onPress() {
701 mEmergencyAffordanceManager.performEmergencyCall();
702 }
703
704 @Override
705 public boolean showDuringKeyguard() {
706 return true;
707 }
708
709 @Override
710 public boolean showBeforeProvisioning() {
711 return true;
712 }
713 };
714 }
715
716 private Action getAssistAction() {
717 return new SinglePressAction(R.drawable.ic_action_assist_focused,
718 R.string.global_action_assist) {
719 @Override
720 public void onPress() {
721 Intent intent = new Intent(Intent.ACTION_ASSIST);
722 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
723 mContext.startActivity(intent);
724 }
725
726 @Override
727 public boolean showDuringKeyguard() {
728 return true;
729 }
730
731 @Override
732 public boolean showBeforeProvisioning() {
733 return true;
734 }
735 };
736 }
737
738 private Action getVoiceAssistAction() {
739 return new SinglePressAction(R.drawable.ic_voice_search,
740 R.string.global_action_voice_assist) {
741 @Override
742 public void onPress() {
743 Intent intent = new Intent(Intent.ACTION_VOICE_ASSIST);
744 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
745 mContext.startActivity(intent);
746 }
747
748 @Override
749 public boolean showDuringKeyguard() {
750 return true;
751 }
752
753 @Override
754 public boolean showBeforeProvisioning() {
755 return true;
756 }
757 };
758 }
759
760 private Action getLockdownAction() {
Alison Cichowlas21125432018-05-16 15:40:45 -0400761 return new SinglePressAction(R.drawable.ic_lock_lockdown,
Jason Monk361915c2017-03-21 20:33:59 -0400762 R.string.global_action_lockdown) {
763
764 @Override
765 public void onPress() {
Chad Brubaker4f28f0d2017-09-07 14:28:13 -0700766 new LockPatternUtils(mContext)
767 .requireStrongAuth(STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN,
768 UserHandle.USER_ALL);
Jason Monk361915c2017-03-21 20:33:59 -0400769 try {
770 WindowManagerGlobal.getWindowManagerService().lockNow(null);
Pavel Grafov059021b2018-05-02 13:44:46 +0100771 // Lock profiles (if any) on the background thread.
772 final Handler bgHandler = new Handler(Dependency.get(Dependency.BG_LOOPER));
773 bgHandler.post(() -> lockProfiles());
Jason Monk361915c2017-03-21 20:33:59 -0400774 } catch (RemoteException e) {
775 Log.e(TAG, "Error while trying to lock device.", e);
776 }
777 }
778
779 @Override
780 public boolean showDuringKeyguard() {
781 return true;
782 }
783
784 @Override
785 public boolean showBeforeProvisioning() {
786 return false;
787 }
788 };
789 }
790
Pavel Grafov059021b2018-05-02 13:44:46 +0100791 private void lockProfiles() {
792 final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
793 final TrustManager tm = (TrustManager) mContext.getSystemService(Context.TRUST_SERVICE);
794 final int currentUserId = getCurrentUser().id;
795 final int[] profileIds = um.getEnabledProfileIds(currentUserId);
796 for (final int id : profileIds) {
797 if (id != currentUserId) {
798 tm.setDeviceLockedForUser(id, true);
799 }
800 }
801 }
802
Jason Monk361915c2017-03-21 20:33:59 -0400803 private UserInfo getCurrentUser() {
804 try {
805 return ActivityManager.getService().getCurrentUser();
806 } catch (RemoteException re) {
807 return null;
808 }
809 }
810
811 private boolean isCurrentUserOwner() {
812 UserInfo currentUser = getCurrentUser();
813 return currentUser == null || currentUser.isPrimary();
814 }
815
816 private void addUsersToMenu(ArrayList<Action> items) {
817 UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
818 if (um.isUserSwitcherEnabled()) {
819 List<UserInfo> users = um.getUsers();
820 UserInfo currentUser = getCurrentUser();
821 for (final UserInfo user : users) {
822 if (user.supportsSwitchToByUser()) {
823 boolean isCurrentUser = currentUser == null
824 ? user.id == 0 : (currentUser.id == user.id);
825 Drawable icon = user.iconPath != null ? Drawable.createFromPath(user.iconPath)
826 : null;
827 SinglePressAction switchToUser = new SinglePressAction(
828 R.drawable.ic_menu_cc, icon,
829 (user.name != null ? user.name : "Primary")
Jason Monk16fbd9d2017-04-27 14:28:49 -0400830 + (isCurrentUser ? " \u2714" : "")) {
Jason Monk361915c2017-03-21 20:33:59 -0400831 public void onPress() {
832 try {
833 ActivityManager.getService().switchUser(user.id);
834 } catch (RemoteException re) {
835 Log.e(TAG, "Couldn't switch user " + re);
836 }
837 }
838
839 public boolean showDuringKeyguard() {
840 return true;
841 }
842
843 public boolean showBeforeProvisioning() {
844 return false;
845 }
846 };
847 items.add(switchToUser);
848 }
849 }
850 }
851 }
852
853 private void prepareDialog() {
854 refreshSilentMode();
855 mAirplaneModeOn.updateState(mAirplaneState);
856 mAdapter.notifyDataSetChanged();
Jason Monk361915c2017-03-21 20:33:59 -0400857 if (mShowSilentToggle) {
858 IntentFilter filter = new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION);
859 mContext.registerReceiver(mRingerModeReceiver, filter);
860 }
861 }
862
863 private void refreshSilentMode() {
864 if (!mHasVibrator) {
865 final boolean silentModeOn =
866 mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL;
Jason Monk16fbd9d2017-04-27 14:28:49 -0400867 ((ToggleAction) mSilentModeAction).updateState(
Jason Monk361915c2017-03-21 20:33:59 -0400868 silentModeOn ? ToggleAction.State.On : ToggleAction.State.Off);
869 }
870 }
871
872 /** {@inheritDoc} */
873 public void onDismiss(DialogInterface dialog) {
874 mWindowManagerFuncs.onGlobalActionsHidden();
875 if (mShowSilentToggle) {
876 try {
877 mContext.unregisterReceiver(mRingerModeReceiver);
878 } catch (IllegalArgumentException ie) {
879 // ignore this
880 Log.w(TAG, ie);
881 }
882 }
883 }
884
885 /** {@inheritDoc} */
886 public void onClick(DialogInterface dialog, int which) {
Jason Monkfd279662017-06-29 19:37:48 -0400887 Action item = mAdapter.getItem(which);
Jason Monkb4302182017-08-04 13:39:17 -0400888 if (!(item instanceof SilentModeTriStateAction)) {
Jason Monk361915c2017-03-21 20:33:59 -0400889 dialog.dismiss();
890 }
Jason Monkfd279662017-06-29 19:37:48 -0400891 item.onPress();
Jason Monk361915c2017-03-21 20:33:59 -0400892 }
893
Shaotang Li786da902018-08-02 11:18:00 +0800894 /** {@inheritDoc} */
895 public void onShow(DialogInterface dialog) {
896 MetricsLogger.visible(mContext, MetricsEvent.POWER_MENU);
897 }
898
Jason Monk361915c2017-03-21 20:33:59 -0400899 /**
900 * The adapter used for the list within the global actions dialog, taking
901 * into account whether the keyguard is showing via
Jason Monk16fbd9d2017-04-27 14:28:49 -0400902 * {@link com.android.systemui.globalactions.GlobalActionsDialog#mKeyguardShowing} and whether
903 * the device is provisioned
Jason Monk361915c2017-03-21 20:33:59 -0400904 * via {@link com.android.systemui.globalactions.GlobalActionsDialog#mDeviceProvisioned}.
905 */
906 private class MyAdapter extends BaseAdapter {
907
908 public int getCount() {
909 int count = 0;
910
911 for (int i = 0; i < mItems.size(); i++) {
912 final Action action = mItems.get(i);
913
914 if (mKeyguardShowing && !action.showDuringKeyguard()) {
915 continue;
916 }
917 if (!mDeviceProvisioned && !action.showBeforeProvisioning()) {
918 continue;
919 }
920 count++;
921 }
922 return count;
923 }
924
925 @Override
926 public boolean isEnabled(int position) {
927 return getItem(position).isEnabled();
928 }
929
930 @Override
931 public boolean areAllItemsEnabled() {
932 return false;
933 }
934
935 public Action getItem(int position) {
936
937 int filteredPos = 0;
938 for (int i = 0; i < mItems.size(); i++) {
939 final Action action = mItems.get(i);
940 if (mKeyguardShowing && !action.showDuringKeyguard()) {
941 continue;
942 }
943 if (!mDeviceProvisioned && !action.showBeforeProvisioning()) {
944 continue;
945 }
946 if (filteredPos == position) {
947 return action;
948 }
949 filteredPos++;
950 }
951
952 throw new IllegalArgumentException("position " + position
953 + " out of range of showable actions"
954 + ", filtered count=" + getCount()
955 + ", keyguardshowing=" + mKeyguardShowing
956 + ", provisioned=" + mDeviceProvisioned);
957 }
958
959
960 public long getItemId(int position) {
961 return position;
962 }
963
964 public View getView(int position, View convertView, ViewGroup parent) {
965 Action action = getItem(position);
Jason Monk16fbd9d2017-04-27 14:28:49 -0400966 View view = action.create(mContext, convertView, parent, LayoutInflater.from(mContext));
Alison Cichowlas3be52db2018-03-06 19:48:06 -0500967 // Everything but screenshot, the last item, gets white background.
968 if (position == getCount() - 1) {
Jason Monk16fbd9d2017-04-27 14:28:49 -0400969 HardwareUiLayout.get(parent).setDivisionView(view);
970 }
971 return view;
Jason Monk361915c2017-03-21 20:33:59 -0400972 }
973 }
974
975 // note: the scheme below made more sense when we were planning on having
976 // 8 different things in the global actions dialog. seems overkill with
977 // only 3 items now, but may as well keep this flexible approach so it will
978 // be easy should someone decide at the last minute to include something
979 // else, such as 'enable wifi', or 'enable bluetooth'
980
981 /**
982 * What each item in the global actions dialog must be able to support.
983 */
984 private interface Action {
985 /**
986 * @return Text that will be announced when dialog is created. null
Jason Monk16fbd9d2017-04-27 14:28:49 -0400987 * for none.
Jason Monk361915c2017-03-21 20:33:59 -0400988 */
989 CharSequence getLabelForAccessibility(Context context);
990
991 View create(Context context, View convertView, ViewGroup parent, LayoutInflater inflater);
992
993 void onPress();
994
995 /**
996 * @return whether this action should appear in the dialog when the keygaurd
Jason Monk16fbd9d2017-04-27 14:28:49 -0400997 * is showing.
Jason Monk361915c2017-03-21 20:33:59 -0400998 */
999 boolean showDuringKeyguard();
1000
1001 /**
1002 * @return whether this action should appear in the dialog before the
Jason Monk16fbd9d2017-04-27 14:28:49 -04001003 * device is provisioned.
Jason Monk361915c2017-03-21 20:33:59 -04001004 */
1005 boolean showBeforeProvisioning();
1006
1007 boolean isEnabled();
1008 }
1009
1010 /**
1011 * An action that also supports long press.
1012 */
1013 private interface LongPressAction extends Action {
1014 boolean onLongPress();
1015 }
1016
1017 /**
1018 * A single press action maintains no state, just responds to a press
1019 * and takes an action.
1020 */
1021 private static abstract class SinglePressAction implements Action {
1022 private final int mIconResId;
1023 private final Drawable mIcon;
1024 private final int mMessageResId;
1025 private final CharSequence mMessage;
1026
1027 protected SinglePressAction(int iconResId, int messageResId) {
1028 mIconResId = iconResId;
1029 mMessageResId = messageResId;
1030 mMessage = null;
1031 mIcon = null;
1032 }
1033
1034 protected SinglePressAction(int iconResId, Drawable icon, CharSequence message) {
1035 mIconResId = iconResId;
1036 mMessageResId = 0;
1037 mMessage = message;
1038 mIcon = icon;
1039 }
1040
1041 public boolean isEnabled() {
1042 return true;
1043 }
1044
1045 public String getStatus() {
1046 return null;
1047 }
1048
1049 abstract public void onPress();
1050
1051 public CharSequence getLabelForAccessibility(Context context) {
1052 if (mMessage != null) {
1053 return mMessage;
1054 } else {
1055 return context.getString(mMessageResId);
1056 }
1057 }
1058
1059 public View create(
1060 Context context, View convertView, ViewGroup parent, LayoutInflater inflater) {
Jason Monk16fbd9d2017-04-27 14:28:49 -04001061 View v = inflater.inflate(com.android.systemui.R.layout.global_actions_item, parent,
1062 false);
Jason Monk361915c2017-03-21 20:33:59 -04001063
1064 ImageView icon = (ImageView) v.findViewById(R.id.icon);
1065 TextView messageView = (TextView) v.findViewById(R.id.message);
1066
1067 TextView statusView = (TextView) v.findViewById(R.id.status);
1068 final String status = getStatus();
1069 if (!TextUtils.isEmpty(status)) {
1070 statusView.setText(status);
1071 } else {
1072 statusView.setVisibility(View.GONE);
1073 }
1074 if (mIcon != null) {
1075 icon.setImageDrawable(mIcon);
1076 icon.setScaleType(ScaleType.CENTER_CROP);
1077 } else if (mIconResId != 0) {
1078 icon.setImageDrawable(context.getDrawable(mIconResId));
1079 }
1080 if (mMessage != null) {
1081 messageView.setText(mMessage);
1082 } else {
1083 messageView.setText(mMessageResId);
1084 }
1085
1086 return v;
1087 }
1088 }
1089
1090 /**
1091 * A toggle action knows whether it is on or off, and displays an icon
1092 * and status message accordingly.
1093 */
1094 private static abstract class ToggleAction implements Action {
1095
1096 enum State {
1097 Off(false),
1098 TurningOn(true),
1099 TurningOff(true),
1100 On(false);
1101
1102 private final boolean inTransition;
1103
1104 State(boolean intermediate) {
1105 inTransition = intermediate;
1106 }
1107
1108 public boolean inTransition() {
1109 return inTransition;
1110 }
1111 }
1112
1113 protected State mState = State.Off;
1114
1115 // prefs
1116 protected int mEnabledIconResId;
1117 protected int mDisabledIconResid;
1118 protected int mMessageResId;
1119 protected int mEnabledStatusMessageResId;
1120 protected int mDisabledStatusMessageResId;
1121
1122 /**
Jason Monk16fbd9d2017-04-27 14:28:49 -04001123 * @param enabledIconResId The icon for when this action is on.
1124 * @param disabledIconResid The icon for when this action is off.
1125 * @param message The general information message, e.g 'Silent Mode'
1126 * @param enabledStatusMessageResId The on status message, e.g 'sound disabled'
Jason Monk361915c2017-03-21 20:33:59 -04001127 * @param disabledStatusMessageResId The off status message, e.g. 'sound enabled'
1128 */
1129 public ToggleAction(int enabledIconResId,
1130 int disabledIconResid,
1131 int message,
1132 int enabledStatusMessageResId,
1133 int disabledStatusMessageResId) {
1134 mEnabledIconResId = enabledIconResId;
1135 mDisabledIconResid = disabledIconResid;
1136 mMessageResId = message;
1137 mEnabledStatusMessageResId = enabledStatusMessageResId;
1138 mDisabledStatusMessageResId = disabledStatusMessageResId;
1139 }
1140
1141 /**
1142 * Override to make changes to resource IDs just before creating the
1143 * View.
1144 */
1145 void willCreate() {
1146
1147 }
1148
1149 @Override
1150 public CharSequence getLabelForAccessibility(Context context) {
1151 return context.getString(mMessageResId);
1152 }
1153
1154 public View create(Context context, View convertView, ViewGroup parent,
1155 LayoutInflater inflater) {
1156 willCreate();
1157
1158 View v = inflater.inflate(R
Jason Monk16fbd9d2017-04-27 14:28:49 -04001159 .layout.global_actions_item, parent, false);
Jason Monk361915c2017-03-21 20:33:59 -04001160
1161 ImageView icon = (ImageView) v.findViewById(R.id.icon);
1162 TextView messageView = (TextView) v.findViewById(R.id.message);
1163 TextView statusView = (TextView) v.findViewById(R.id.status);
1164 final boolean enabled = isEnabled();
1165
1166 if (messageView != null) {
1167 messageView.setText(mMessageResId);
1168 messageView.setEnabled(enabled);
1169 }
1170
1171 boolean on = ((mState == State.On) || (mState == State.TurningOn));
1172 if (icon != null) {
1173 icon.setImageDrawable(context.getDrawable(
1174 (on ? mEnabledIconResId : mDisabledIconResid)));
1175 icon.setEnabled(enabled);
1176 }
1177
1178 if (statusView != null) {
1179 statusView.setText(on ? mEnabledStatusMessageResId : mDisabledStatusMessageResId);
1180 statusView.setVisibility(View.VISIBLE);
1181 statusView.setEnabled(enabled);
1182 }
1183 v.setEnabled(enabled);
1184
1185 return v;
1186 }
1187
1188 public final void onPress() {
1189 if (mState.inTransition()) {
1190 Log.w(TAG, "shouldn't be able to toggle when in transition");
1191 return;
1192 }
1193
1194 final boolean nowOn = !(mState == State.On);
1195 onToggle(nowOn);
1196 changeStateFromPress(nowOn);
1197 }
1198
1199 public boolean isEnabled() {
1200 return !mState.inTransition();
1201 }
1202
1203 /**
1204 * Implementations may override this if their state can be in on of the intermediate
1205 * states until some notification is received (e.g airplane mode is 'turning off' until
1206 * we know the wireless connections are back online
Jason Monk16fbd9d2017-04-27 14:28:49 -04001207 *
Jason Monk361915c2017-03-21 20:33:59 -04001208 * @param buttonOn Whether the button was turned on or off
1209 */
1210 protected void changeStateFromPress(boolean buttonOn) {
1211 mState = buttonOn ? State.On : State.Off;
1212 }
1213
1214 abstract void onToggle(boolean on);
1215
1216 public void updateState(State state) {
1217 mState = state;
1218 }
1219 }
1220
1221 private class SilentModeToggleAction extends ToggleAction {
1222 public SilentModeToggleAction() {
1223 super(R.drawable.ic_audio_vol_mute,
1224 R.drawable.ic_audio_vol,
1225 R.string.global_action_toggle_silent_mode,
1226 R.string.global_action_silent_mode_on_status,
1227 R.string.global_action_silent_mode_off_status);
1228 }
1229
1230 void onToggle(boolean on) {
1231 if (on) {
1232 mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
1233 } else {
1234 mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
1235 }
1236 }
1237
1238 public boolean showDuringKeyguard() {
1239 return true;
1240 }
1241
1242 public boolean showBeforeProvisioning() {
1243 return false;
1244 }
1245 }
1246
1247 private static class SilentModeTriStateAction implements Action, View.OnClickListener {
1248
Jason Monk16fbd9d2017-04-27 14:28:49 -04001249 private final int[] ITEM_IDS = {R.id.option1, R.id.option2, R.id.option3};
Jason Monk361915c2017-03-21 20:33:59 -04001250
1251 private final AudioManager mAudioManager;
1252 private final Handler mHandler;
Jason Monk361915c2017-03-21 20:33:59 -04001253
Lucas Dupin40ec6b782018-06-05 19:07:16 -07001254 SilentModeTriStateAction(AudioManager audioManager, Handler handler) {
Jason Monk361915c2017-03-21 20:33:59 -04001255 mAudioManager = audioManager;
1256 mHandler = handler;
Jason Monk361915c2017-03-21 20:33:59 -04001257 }
1258
1259 private int ringerModeToIndex(int ringerMode) {
1260 // They just happen to coincide
1261 return ringerMode;
1262 }
1263
1264 private int indexToRingerMode(int index) {
1265 // They just happen to coincide
1266 return index;
1267 }
1268
1269 @Override
1270 public CharSequence getLabelForAccessibility(Context context) {
1271 return null;
1272 }
1273
1274 public View create(Context context, View convertView, ViewGroup parent,
1275 LayoutInflater inflater) {
1276 View v = inflater.inflate(R.layout.global_actions_silent_mode, parent, false);
1277
1278 int selectedIndex = ringerModeToIndex(mAudioManager.getRingerMode());
1279 for (int i = 0; i < 3; i++) {
1280 View itemView = v.findViewById(ITEM_IDS[i]);
1281 itemView.setSelected(selectedIndex == i);
1282 // Set up click handler
1283 itemView.setTag(i);
1284 itemView.setOnClickListener(this);
1285 }
1286 return v;
1287 }
1288
1289 public void onPress() {
1290 }
1291
1292 public boolean showDuringKeyguard() {
1293 return true;
1294 }
1295
1296 public boolean showBeforeProvisioning() {
1297 return false;
1298 }
1299
1300 public boolean isEnabled() {
1301 return true;
1302 }
1303
1304 void willCreate() {
1305 }
1306
1307 public void onClick(View v) {
1308 if (!(v.getTag() instanceof Integer)) return;
1309
1310 int index = (Integer) v.getTag();
1311 mAudioManager.setRingerMode(indexToRingerMode(index));
1312 mHandler.sendEmptyMessageDelayed(MESSAGE_DISMISS, DIALOG_DISMISS_DELAY);
1313 }
1314 }
1315
1316 private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
1317 public void onReceive(Context context, Intent intent) {
1318 String action = intent.getAction();
1319 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)
1320 || Intent.ACTION_SCREEN_OFF.equals(action)) {
1321 String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY);
1322 if (!SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS.equals(reason)) {
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001323 mHandler.sendMessage(mHandler.obtainMessage(MESSAGE_DISMISS, reason));
Jason Monk361915c2017-03-21 20:33:59 -04001324 }
1325 } else if (TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED.equals(action)) {
1326 // Airplane mode can be changed after ECM exits if airplane toggle button
1327 // is pressed during ECM mode
1328 if (!(intent.getBooleanExtra("PHONE_IN_ECM_STATE", false)) &&
1329 mIsWaitingForEcmExit) {
1330 mIsWaitingForEcmExit = false;
1331 changeAirplaneModeSystemSetting(true);
1332 }
1333 }
1334 }
1335 };
1336
1337 PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
1338 @Override
1339 public void onServiceStateChanged(ServiceState serviceState) {
1340 if (!mHasTelephony) return;
1341 final boolean inAirplaneMode = serviceState.getState() == ServiceState.STATE_POWER_OFF;
1342 mAirplaneState = inAirplaneMode ? ToggleAction.State.On : ToggleAction.State.Off;
1343 mAirplaneModeOn.updateState(mAirplaneState);
1344 mAdapter.notifyDataSetChanged();
1345 }
1346 };
1347
1348 private BroadcastReceiver mRingerModeReceiver = new BroadcastReceiver() {
1349 @Override
1350 public void onReceive(Context context, Intent intent) {
1351 if (intent.getAction().equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
1352 mHandler.sendEmptyMessage(MESSAGE_REFRESH);
1353 }
1354 }
1355 };
1356
1357 private ContentObserver mAirplaneModeObserver = new ContentObserver(new Handler()) {
1358 @Override
1359 public void onChange(boolean selfChange) {
1360 onAirplaneModeChanged();
1361 }
1362 };
1363
1364 private static final int MESSAGE_DISMISS = 0;
1365 private static final int MESSAGE_REFRESH = 1;
1366 private static final int MESSAGE_SHOW = 2;
1367 private static final int DIALOG_DISMISS_DELAY = 300; // ms
1368
1369 private Handler mHandler = new Handler() {
1370 public void handleMessage(Message msg) {
1371 switch (msg.what) {
Jason Monk16fbd9d2017-04-27 14:28:49 -04001372 case MESSAGE_DISMISS:
1373 if (mDialog != null) {
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001374 if (SYSTEM_DIALOG_REASON_DREAM.equals(msg.obj)) {
1375 mDialog.dismissImmediately();
1376 } else {
1377 mDialog.dismiss();
1378 }
Jason Monk16fbd9d2017-04-27 14:28:49 -04001379 mDialog = null;
1380 }
1381 break;
1382 case MESSAGE_REFRESH:
1383 refreshSilentMode();
1384 mAdapter.notifyDataSetChanged();
1385 break;
1386 case MESSAGE_SHOW:
1387 handleShow();
1388 break;
Jason Monk361915c2017-03-21 20:33:59 -04001389 }
1390 }
1391 };
1392
1393 private void onAirplaneModeChanged() {
1394 // Let the service state callbacks handle the state.
1395 if (mHasTelephony) return;
1396
1397 boolean airplaneModeOn = Settings.Global.getInt(
1398 mContext.getContentResolver(),
1399 Settings.Global.AIRPLANE_MODE_ON,
1400 0) == 1;
1401 mAirplaneState = airplaneModeOn ? ToggleAction.State.On : ToggleAction.State.Off;
1402 mAirplaneModeOn.updateState(mAirplaneState);
1403 }
1404
1405 /**
1406 * Change the airplane mode system setting
1407 */
1408 private void changeAirplaneModeSystemSetting(boolean on) {
1409 Settings.Global.putInt(
1410 mContext.getContentResolver(),
1411 Settings.Global.AIRPLANE_MODE_ON,
1412 on ? 1 : 0);
1413 Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
1414 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
1415 intent.putExtra("state", on);
1416 mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
1417 if (!mHasTelephony) {
1418 mAirplaneState = on ? ToggleAction.State.On : ToggleAction.State.Off;
1419 }
1420 }
1421
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001422 private static final class ActionsDialog extends Dialog implements DialogInterface,
1423 ColorExtractor.OnColorsChangedListener {
Jason Monk361915c2017-03-21 20:33:59 -04001424
Jason Monk16fbd9d2017-04-27 14:28:49 -04001425 private final Context mContext;
1426 private final MyAdapter mAdapter;
1427 private final LinearLayout mListView;
Wesley.CW Wang3004fcb2018-06-15 16:24:57 +08001428 private final FrameLayout mSeparatedView;
Jason Monk16fbd9d2017-04-27 14:28:49 -04001429 private final HardwareUiLayout mHardwareLayout;
1430 private final OnClickListener mClickListener;
1431 private final OnItemLongClickListener mLongClickListener;
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001432 private final GradientDrawable mGradientDrawable;
1433 private final ColorExtractor mColorExtractor;
1434 private boolean mKeyguardShowing;
Wesley.CW Wang3004fcb2018-06-15 16:24:57 +08001435 private boolean mShouldDisplaySeparatedButton;
Beverly526d2d62018-08-15 12:55:33 -04001436 private boolean mShowing;
Jason Monk16fbd9d2017-04-27 14:28:49 -04001437
1438 public ActionsDialog(Context context, OnClickListener clickListener, MyAdapter adapter,
Wesley.CW Wang3004fcb2018-06-15 16:24:57 +08001439 OnItemLongClickListener longClickListener, boolean shouldDisplaySeparatedButton) {
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001440 super(context, com.android.systemui.R.style.Theme_SystemUI_Dialog_GlobalActions);
Lucas Dupin448786c2017-07-24 17:44:25 -07001441 mContext = context;
Jason Monk16fbd9d2017-04-27 14:28:49 -04001442 mAdapter = adapter;
1443 mClickListener = clickListener;
1444 mLongClickListener = longClickListener;
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001445 mGradientDrawable = new GradientDrawable(mContext);
Lucas Dupin1ead7fc2017-05-24 14:14:44 -07001446 mColorExtractor = Dependency.get(SysuiColorExtractor.class);
Wesley.CW Wang3004fcb2018-06-15 16:24:57 +08001447 mShouldDisplaySeparatedButton = shouldDisplaySeparatedButton;
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001448
1449 // Window initialization
1450 Window window = getWindow();
1451 window.requestFeature(Window.FEATURE_NO_TITLE);
Adrian Roosedfab3b2018-03-08 18:39:20 +01001452 // Inflate the decor view, so the attributes below are not overwritten by the theme.
1453 window.getDecorView();
1454 window.getAttributes().systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1455 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1456 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1457 window.setLayout(MATCH_PARENT, MATCH_PARENT);
1458 window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
Alison Cichowlas4f19f4a2017-07-25 10:56:16 -04001459 window.addFlags(
1460 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001461 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
Adrian Roosedfab3b2018-03-08 18:39:20 +01001462 | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001463 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
1464 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
1465 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
1466 window.setBackgroundDrawable(mGradientDrawable);
1467 window.setType(WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY);
1468
Jason Monk16fbd9d2017-04-27 14:28:49 -04001469 setContentView(com.android.systemui.R.layout.global_actions_wrapped);
Jason Monk16fbd9d2017-04-27 14:28:49 -04001470 mListView = findViewById(android.R.id.list);
Wesley.CW Wang3004fcb2018-06-15 16:24:57 +08001471 mSeparatedView = findViewById(com.android.systemui.R.id.separated_button);
1472 if (!mShouldDisplaySeparatedButton) {
1473 mSeparatedView.setVisibility(View.GONE);
1474 }
Jason Monk16fbd9d2017-04-27 14:28:49 -04001475 mHardwareLayout = HardwareUiLayout.get(mListView);
1476 mHardwareLayout.setOutsideTouchListener(view -> dismiss());
Wesley.CW Wang3004fcb2018-06-15 16:24:57 +08001477 mHardwareLayout.setHasSeparatedButton(mShouldDisplaySeparatedButton);
Phil Weaver8583ae82018-02-13 11:01:24 -08001478 setTitle(R.string.global_actions);
Phil Weaver9054e092018-04-27 16:28:50 -07001479 mListView.setAccessibilityDelegate(new View.AccessibilityDelegate() {
1480 @Override
1481 public boolean dispatchPopulateAccessibilityEvent(
1482 View host, AccessibilityEvent event) {
1483 // Populate the title here, just as Activity does
1484 event.getText().add(mContext.getString(R.string.global_actions));
1485 return true;
1486 }
1487 });
Jason Monk361915c2017-03-21 20:33:59 -04001488 }
1489
Jason Monk16fbd9d2017-04-27 14:28:49 -04001490 private void updateList() {
1491 mListView.removeAllViews();
Wesley.CW Wang3004fcb2018-06-15 16:24:57 +08001492 mSeparatedView.removeAllViews();
Jason Monk16fbd9d2017-04-27 14:28:49 -04001493 for (int i = 0; i < mAdapter.getCount(); i++) {
Wesley.CW Wang3004fcb2018-06-15 16:24:57 +08001494 ViewGroup parentView = mShouldDisplaySeparatedButton && i == mAdapter.getCount() - 1
1495 ? mSeparatedView : mListView;
1496 View v = mAdapter.getView(i, null, parentView);
Jason Monk16fbd9d2017-04-27 14:28:49 -04001497 final int pos = i;
1498 v.setOnClickListener(view -> mClickListener.onClick(this, pos));
1499 v.setOnLongClickListener(view ->
1500 mLongClickListener.onItemLongClick(null, v, pos, 0));
Wesley.CW Wang3004fcb2018-06-15 16:24:57 +08001501 parentView.addView(v);
Jason Monk16fbd9d2017-04-27 14:28:49 -04001502 }
Jason Monk361915c2017-03-21 20:33:59 -04001503 }
1504
1505 @Override
1506 protected void onStart() {
1507 super.setCanceledOnTouchOutside(true);
1508 super.onStart();
Jason Monk16fbd9d2017-04-27 14:28:49 -04001509 updateList();
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001510
1511 Point displaySize = new Point();
1512 mContext.getDisplay().getRealSize(displaySize);
1513 mColorExtractor.addOnColorsChangedListener(this);
1514 mGradientDrawable.setScreenSize(displaySize.x, displaySize.y);
1515 GradientColors colors = mColorExtractor.getColors(mKeyguardShowing ?
1516 WallpaperManager.FLAG_LOCK : WallpaperManager.FLAG_SYSTEM);
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001517 updateColors(colors, false /* animate */);
1518 }
1519
1520 /**
1521 * Updates background and system bars according to current GradientColors.
1522 * @param colors Colors and hints to use.
1523 * @param animate Interpolates gradient if true, just sets otherwise.
1524 */
1525 private void updateColors(GradientColors colors, boolean animate) {
1526 mGradientDrawable.setColors(colors, animate);
1527 View decorView = getWindow().getDecorView();
1528 if (colors.supportsDarkText()) {
1529 decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR |
1530 View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
1531 } else {
1532 decorView.setSystemUiVisibility(0);
1533 }
Jason Monk361915c2017-03-21 20:33:59 -04001534 }
1535
1536 @Override
Jason Monk16fbd9d2017-04-27 14:28:49 -04001537 protected void onStop() {
1538 super.onStop();
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001539 mColorExtractor.removeOnColorsChangedListener(this);
Jason Monk16fbd9d2017-04-27 14:28:49 -04001540 }
1541
1542 @Override
1543 public void show() {
1544 super.show();
Beverly526d2d62018-08-15 12:55:33 -04001545 mShowing = true;
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001546 mGradientDrawable.setAlpha(0);
Jason Monk16fbd9d2017-04-27 14:28:49 -04001547 mHardwareLayout.setTranslationX(getAnimTranslation());
1548 mHardwareLayout.setAlpha(0);
1549 mHardwareLayout.animate()
1550 .alpha(1)
1551 .translationX(0)
1552 .setDuration(300)
Lucas Dupinde9db422017-07-19 17:15:41 -07001553 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001554 .setUpdateListener(animation -> {
1555 int alpha = (int) ((Float) animation.getAnimatedValue()
1556 * ScrimController.GRADIENT_SCRIM_ALPHA * 255);
1557 mGradientDrawable.setAlpha(alpha);
1558 })
Jason Monk16fbd9d2017-04-27 14:28:49 -04001559 .start();
1560 }
1561
1562 @Override
1563 public void dismiss() {
Beverly526d2d62018-08-15 12:55:33 -04001564 if (!mShowing) {
1565 return;
1566 }
1567 mShowing = false;
Jason Monk16fbd9d2017-04-27 14:28:49 -04001568 mHardwareLayout.setTranslationX(0);
1569 mHardwareLayout.setAlpha(1);
1570 mHardwareLayout.animate()
1571 .alpha(0)
1572 .translationX(getAnimTranslation())
1573 .setDuration(300)
1574 .withEndAction(() -> super.dismiss())
1575 .setInterpolator(new LogAccelerateInterpolator())
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001576 .setUpdateListener(animation -> {
1577 int alpha = (int) ((1f - (Float) animation.getAnimatedValue())
1578 * ScrimController.GRADIENT_SCRIM_ALPHA * 255);
1579 mGradientDrawable.setAlpha(alpha);
1580 })
Jason Monk16fbd9d2017-04-27 14:28:49 -04001581 .start();
1582 }
1583
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001584 void dismissImmediately() {
1585 super.dismiss();
Beverly526d2d62018-08-15 12:55:33 -04001586 mShowing = false;
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001587 }
1588
Jason Monk16fbd9d2017-04-27 14:28:49 -04001589 private float getAnimTranslation() {
1590 return getContext().getResources().getDimension(
1591 com.android.systemui.R.dimen.global_actions_panel_width) / 2;
Jason Monk361915c2017-03-21 20:33:59 -04001592 }
1593
1594 @Override
Lucas Dupin7aaa3532017-05-28 08:51:07 -07001595 public void onColorsChanged(ColorExtractor extractor, int which) {
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001596 if (mKeyguardShowing) {
1597 if ((WallpaperManager.FLAG_LOCK & which) != 0) {
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001598 updateColors(extractor.getColors(WallpaperManager.FLAG_LOCK),
1599 true /* animate */);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001600 }
1601 } else {
1602 if ((WallpaperManager.FLAG_SYSTEM & which) != 0) {
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001603 updateColors(extractor.getColors(WallpaperManager.FLAG_SYSTEM),
1604 true /* animate */);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001605 }
1606 }
1607 }
1608
1609 public void setKeyguardShowing(boolean keyguardShowing) {
1610 mKeyguardShowing = keyguardShowing;
1611 }
Jason Monk361915c2017-03-21 20:33:59 -04001612 }
1613}