Remove old power menu code
The new power menu lite replaces this version of the power menu, so we should clean up the unused code Bug: 179674461 Test: builds; atest com.android.systemui.globalactions Change-Id: I8e21edf45d87a87b8979fd8ee8b6bb13e277e0d8
This commit is contained in:
@@ -1,594 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the
|
||||
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the specific language governing
|
||||
* permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.systemui.globalactions;
|
||||
|
||||
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
|
||||
import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_BOOT;
|
||||
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_GLOBAL_ACTIONS_SHOWING;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.animation.AnimatorSet;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.annotation.Nullable;
|
||||
import android.app.IActivityManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.app.trust.TrustManager;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Resources;
|
||||
import android.database.ContentObserver;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.media.AudioManager;
|
||||
import android.os.Handler;
|
||||
import android.os.UserManager;
|
||||
import android.os.Vibrator;
|
||||
import android.provider.Settings;
|
||||
import android.service.dreams.IDreamManager;
|
||||
import android.telecom.TelecomManager;
|
||||
import android.transition.AutoTransition;
|
||||
import android.transition.TransitionManager;
|
||||
import android.transition.TransitionSet;
|
||||
import android.view.IWindowManager;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.view.WindowInsets;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
|
||||
import com.android.internal.R;
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.logging.MetricsLogger;
|
||||
import com.android.internal.logging.UiEventLogger;
|
||||
import com.android.internal.statusbar.IStatusBarService;
|
||||
import com.android.internal.view.RotationPolicy;
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.systemui.animation.Interpolators;
|
||||
import com.android.systemui.broadcast.BroadcastDispatcher;
|
||||
import com.android.systemui.colorextraction.SysuiColorExtractor;
|
||||
import com.android.systemui.dagger.qualifiers.Background;
|
||||
import com.android.systemui.dagger.qualifiers.Main;
|
||||
import com.android.systemui.model.SysUiState;
|
||||
import com.android.systemui.plugins.ActivityStarter;
|
||||
import com.android.systemui.plugins.GlobalActions.GlobalActionsManager;
|
||||
import com.android.systemui.plugins.GlobalActionsPanelPlugin;
|
||||
import com.android.systemui.statusbar.NotificationShadeWindowController;
|
||||
import com.android.systemui.statusbar.phone.StatusBar;
|
||||
import com.android.systemui.statusbar.policy.ConfigurationController;
|
||||
import com.android.systemui.statusbar.policy.KeyguardStateController;
|
||||
import com.android.systemui.telephony.TelephonyListenerManager;
|
||||
import com.android.systemui.util.RingerModeTracker;
|
||||
import com.android.systemui.util.leak.RotationUtils;
|
||||
import com.android.systemui.util.settings.GlobalSettings;
|
||||
import com.android.systemui.util.settings.SecureSettings;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Provider;
|
||||
|
||||
/**
|
||||
* Helper to show the global actions dialog. Each item is an {@link Action} that may show depending
|
||||
* on whether the keyguard is showing, and whether the device is provisioned.
|
||||
* This version includes wallet.
|
||||
*/
|
||||
public class GlobalActionsDialog extends GlobalActionsDialogLite
|
||||
implements DialogInterface.OnDismissListener,
|
||||
DialogInterface.OnShowListener,
|
||||
ConfigurationController.ConfigurationListener,
|
||||
GlobalActionsPanelPlugin.Callbacks,
|
||||
LifecycleOwner {
|
||||
|
||||
private static final String TAG = "GlobalActionsDialog";
|
||||
|
||||
private final LockPatternUtils mLockPatternUtils;
|
||||
private final KeyguardStateController mKeyguardStateController;
|
||||
private final SysUiState mSysUiState;
|
||||
private final ActivityStarter mActivityStarter;
|
||||
private final SysuiColorExtractor mSysuiColorExtractor;
|
||||
private final IStatusBarService mStatusBarService;
|
||||
private final NotificationShadeWindowController mNotificationShadeWindowController;
|
||||
private GlobalActionsPanelPlugin mWalletPlugin;
|
||||
|
||||
@VisibleForTesting
|
||||
boolean mShowLockScreenCards = false;
|
||||
|
||||
private final KeyguardStateController.Callback mKeyguardStateControllerListener =
|
||||
new KeyguardStateController.Callback() {
|
||||
@Override
|
||||
public void onUnlockedChanged() {
|
||||
if (mDialog != null) {
|
||||
ActionsDialog dialog = (ActionsDialog) mDialog;
|
||||
boolean unlocked = mKeyguardStateController.isUnlocked();
|
||||
if (dialog.mWalletViewController != null) {
|
||||
dialog.mWalletViewController.onDeviceLockStateChanged(!unlocked);
|
||||
}
|
||||
|
||||
if (unlocked) {
|
||||
dialog.hideLockMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private final ContentObserver mSettingsObserver = new ContentObserver(mMainHandler) {
|
||||
@Override
|
||||
public void onChange(boolean selfChange) {
|
||||
onPowerMenuLockScreenSettingsChanged();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param context everything needs a context :(
|
||||
*/
|
||||
@Inject
|
||||
public GlobalActionsDialog(
|
||||
Context context,
|
||||
GlobalActionsManager windowManagerFuncs,
|
||||
AudioManager audioManager,
|
||||
IDreamManager iDreamManager,
|
||||
DevicePolicyManager devicePolicyManager,
|
||||
LockPatternUtils lockPatternUtils,
|
||||
BroadcastDispatcher broadcastDispatcher,
|
||||
TelephonyListenerManager telephonyListenerManager,
|
||||
GlobalSettings globalSettings,
|
||||
SecureSettings secureSettings,
|
||||
@Nullable Vibrator vibrator,
|
||||
@Main Resources resources,
|
||||
ConfigurationController configurationController,
|
||||
ActivityStarter activityStarter,
|
||||
KeyguardStateController keyguardStateController,
|
||||
UserManager userManager,
|
||||
TrustManager trustManager,
|
||||
IActivityManager iActivityManager,
|
||||
@Nullable TelecomManager telecomManager,
|
||||
MetricsLogger metricsLogger,
|
||||
SysuiColorExtractor colorExtractor,
|
||||
IStatusBarService statusBarService,
|
||||
NotificationShadeWindowController notificationShadeWindowController,
|
||||
IWindowManager iWindowManager,
|
||||
@Background Executor backgroundExecutor,
|
||||
UiEventLogger uiEventLogger,
|
||||
RingerModeTracker ringerModeTracker,
|
||||
SysUiState sysUiState,
|
||||
@Main Handler handler,
|
||||
PackageManager packageManager,
|
||||
Optional<StatusBar> statusBarOptional) {
|
||||
|
||||
super(context,
|
||||
windowManagerFuncs,
|
||||
audioManager,
|
||||
iDreamManager,
|
||||
devicePolicyManager,
|
||||
lockPatternUtils,
|
||||
broadcastDispatcher,
|
||||
telephonyListenerManager,
|
||||
globalSettings,
|
||||
secureSettings,
|
||||
vibrator,
|
||||
resources,
|
||||
configurationController,
|
||||
keyguardStateController,
|
||||
userManager,
|
||||
trustManager,
|
||||
iActivityManager,
|
||||
telecomManager,
|
||||
metricsLogger,
|
||||
colorExtractor,
|
||||
statusBarService,
|
||||
notificationShadeWindowController,
|
||||
iWindowManager,
|
||||
backgroundExecutor,
|
||||
uiEventLogger,
|
||||
ringerModeTracker,
|
||||
sysUiState,
|
||||
handler,
|
||||
packageManager,
|
||||
statusBarOptional);
|
||||
|
||||
mLockPatternUtils = lockPatternUtils;
|
||||
mKeyguardStateController = keyguardStateController;
|
||||
mSysuiColorExtractor = colorExtractor;
|
||||
mStatusBarService = statusBarService;
|
||||
mNotificationShadeWindowController = notificationShadeWindowController;
|
||||
mSysUiState = sysUiState;
|
||||
mActivityStarter = activityStarter;
|
||||
|
||||
mKeyguardStateController.addCallback(mKeyguardStateControllerListener);
|
||||
|
||||
// Listen for changes to show pay on the power menu while locked
|
||||
onPowerMenuLockScreenSettingsChanged();
|
||||
mGlobalSettings.registerContentObserver(
|
||||
Settings.Secure.getUriFor(Settings.Secure.POWER_MENU_LOCKED_SHOW_CONTENT),
|
||||
false /* notifyForDescendants */,
|
||||
mSettingsObserver);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
super.destroy();
|
||||
mKeyguardStateController.removeCallback(mKeyguardStateControllerListener);
|
||||
mGlobalSettings.unregisterContentObserver(mSettingsObserver);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the global actions dialog (creating if necessary)
|
||||
*
|
||||
* @param keyguardShowing True if keyguard is showing
|
||||
*/
|
||||
public void showOrHideDialog(boolean keyguardShowing, boolean isDeviceProvisioned,
|
||||
GlobalActionsPanelPlugin walletPlugin) {
|
||||
mWalletPlugin = walletPlugin;
|
||||
super.showOrHideDialog(keyguardShowing, isDeviceProvisioned);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum number of power menu items to show based on which GlobalActions
|
||||
* layout is being used.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
@Override
|
||||
protected int getMaxShownPowerItems() {
|
||||
return getContext().getResources().getInteger(
|
||||
com.android.systemui.R.integer.power_menu_max_columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the global actions dialog.
|
||||
*
|
||||
* @return A new dialog.
|
||||
*/
|
||||
@Override
|
||||
protected ActionsDialogLite createDialog() {
|
||||
initDialogItems();
|
||||
|
||||
ActionsDialog dialog = new ActionsDialog(getContext(), mAdapter, mOverflowAdapter,
|
||||
this::getWalletViewController, mSysuiColorExtractor,
|
||||
mStatusBarService, mNotificationShadeWindowController,
|
||||
mSysUiState, this::onRotate, isKeyguardShowing(), mPowerAdapter, getEventLogger(),
|
||||
getStatusBar());
|
||||
|
||||
if (shouldShowLockMessage(dialog)) {
|
||||
dialog.showLockMessage();
|
||||
}
|
||||
dialog.setCanceledOnTouchOutside(false); // Handled by the custom class.
|
||||
dialog.setOnDismissListener(this);
|
||||
dialog.setOnShowListener(this);
|
||||
|
||||
return dialog;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private GlobalActionsPanelPlugin.PanelViewController getWalletViewController() {
|
||||
if (mWalletPlugin == null) {
|
||||
return null;
|
||||
}
|
||||
return mWalletPlugin.onPanelShown(this, !mKeyguardStateController.isUnlocked());
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements {@link GlobalActionsPanelPlugin.Callbacks#dismissGlobalActionsMenu()}, which is
|
||||
* called when the quick access wallet requests that an intent be started (with lock screen
|
||||
* shown first if needed).
|
||||
*/
|
||||
@Override
|
||||
public void startPendingIntentDismissingKeyguard(PendingIntent pendingIntent) {
|
||||
mActivityStarter.startPendingIntentDismissingKeyguard(pendingIntent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getEmergencyTextColor(Context context) {
|
||||
return context.getResources().getColor(
|
||||
com.android.systemui.R.color.global_actions_emergency_text);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getEmergencyIconColor(Context context) {
|
||||
return getContext().getResources().getColor(
|
||||
com.android.systemui.R.color.global_actions_emergency_text);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getEmergencyBackgroundColor(Context context) {
|
||||
return getContext().getResources().getColor(
|
||||
com.android.systemui.R.color.global_actions_emergency_background);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getGridItemLayoutResource() {
|
||||
return com.android.systemui.R.layout.global_actions_grid_item_v2;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static class ActionsDialog extends ActionsDialogLite {
|
||||
|
||||
private final Provider<GlobalActionsPanelPlugin.PanelViewController> mWalletFactory;
|
||||
@Nullable private GlobalActionsPanelPlugin.PanelViewController mWalletViewController;
|
||||
private ResetOrientationData mResetOrientationData;
|
||||
@VisibleForTesting ViewGroup mLockMessageContainer;
|
||||
private TextView mLockMessage;
|
||||
|
||||
ActionsDialog(Context context, MyAdapter adapter, MyOverflowAdapter overflowAdapter,
|
||||
Provider<GlobalActionsPanelPlugin.PanelViewController> walletFactory,
|
||||
SysuiColorExtractor sysuiColorExtractor, IStatusBarService statusBarService,
|
||||
NotificationShadeWindowController notificationShadeWindowController,
|
||||
SysUiState sysuiState, Runnable onRotateCallback, boolean keyguardShowing,
|
||||
MyPowerOptionsAdapter powerAdapter, UiEventLogger uiEventLogger,
|
||||
Optional<StatusBar> statusBarOptional) {
|
||||
super(context, com.android.systemui.R.style.Theme_SystemUI_Dialog_GlobalActions,
|
||||
adapter, overflowAdapter, sysuiColorExtractor, statusBarService,
|
||||
notificationShadeWindowController, sysuiState, onRotateCallback,
|
||||
keyguardShowing, powerAdapter, uiEventLogger, statusBarOptional);
|
||||
mWalletFactory = walletFactory;
|
||||
|
||||
// Update window attributes
|
||||
Window window = getWindow();
|
||||
window.getAttributes().systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
|
||||
window.setLayout(MATCH_PARENT, MATCH_PARENT);
|
||||
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
|
||||
window.addFlags(
|
||||
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
|
||||
| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
|
||||
| WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
|
||||
| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
|
||||
| WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
|
||||
| WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
|
||||
setTitle(R.string.global_actions);
|
||||
initializeLayout();
|
||||
}
|
||||
|
||||
private boolean isWalletViewAvailable() {
|
||||
return mWalletViewController != null && mWalletViewController.getPanelContent() != null;
|
||||
}
|
||||
|
||||
private void initializeWalletView() {
|
||||
if (mWalletFactory == null) {
|
||||
return;
|
||||
}
|
||||
mWalletViewController = mWalletFactory.get();
|
||||
if (!isWalletViewAvailable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean isLandscapeWalletViewShown = mContext.getResources().getBoolean(
|
||||
com.android.systemui.R.bool.global_actions_show_landscape_wallet_view);
|
||||
|
||||
int rotation = RotationUtils.getRotation(mContext);
|
||||
boolean rotationLocked = RotationPolicy.isRotationLocked(mContext);
|
||||
if (rotation != RotationUtils.ROTATION_NONE) {
|
||||
if (rotationLocked) {
|
||||
if (mResetOrientationData == null) {
|
||||
mResetOrientationData = new ResetOrientationData();
|
||||
mResetOrientationData.locked = true;
|
||||
mResetOrientationData.rotation = rotation;
|
||||
}
|
||||
|
||||
// Unlock rotation, so user can choose to rotate to portrait to see the panel.
|
||||
// This call is posted so that the rotation does not change until post-layout,
|
||||
// otherwise onConfigurationChanged() may not get invoked.
|
||||
mGlobalActionsLayout.post(() ->
|
||||
RotationPolicy.setRotationLockAtAngle(
|
||||
mContext, false, RotationUtils.ROTATION_NONE));
|
||||
|
||||
if (!isLandscapeWalletViewShown) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!rotationLocked) {
|
||||
if (mResetOrientationData == null) {
|
||||
mResetOrientationData = new ResetOrientationData();
|
||||
mResetOrientationData.locked = false;
|
||||
}
|
||||
}
|
||||
|
||||
boolean shouldLockRotation = !isLandscapeWalletViewShown;
|
||||
if (rotationLocked != shouldLockRotation) {
|
||||
// Locks the screen to portrait if the landscape / seascape orientation does not
|
||||
// show the wallet view, so the user doesn't accidentally hide the panel.
|
||||
// This call is posted so that the rotation does not change until post-layout,
|
||||
// otherwise onConfigurationChanged() may not get invoked.
|
||||
mGlobalActionsLayout.post(() ->
|
||||
RotationPolicy.setRotationLockAtAngle(
|
||||
mContext, shouldLockRotation, RotationUtils.ROTATION_NONE));
|
||||
}
|
||||
}
|
||||
|
||||
// Disable rotation suggestions, if enabled
|
||||
setRotationSuggestionsEnabled(false);
|
||||
|
||||
FrameLayout panelContainer =
|
||||
findViewById(com.android.systemui.R.id.global_actions_wallet);
|
||||
FrameLayout.LayoutParams panelParams =
|
||||
new FrameLayout.LayoutParams(
|
||||
FrameLayout.LayoutParams.MATCH_PARENT,
|
||||
FrameLayout.LayoutParams.MATCH_PARENT);
|
||||
panelParams.topMargin = mContext.getResources().getDimensionPixelSize(
|
||||
com.android.systemui.R.dimen.global_actions_wallet_top_margin);
|
||||
View walletView = mWalletViewController.getPanelContent();
|
||||
panelContainer.addView(walletView, panelParams);
|
||||
// Smooth transitions when wallet is resized, which can happen when a card is added
|
||||
ViewGroup root = findViewById(com.android.systemui.R.id.global_actions_grid_root);
|
||||
if (root != null) {
|
||||
walletView.addOnLayoutChangeListener((v, l, t, r, b, ol, ot, or, ob) -> {
|
||||
int oldHeight = ob - ot;
|
||||
int newHeight = b - t;
|
||||
if (oldHeight > 0 && oldHeight != newHeight) {
|
||||
TransitionSet transition = new AutoTransition()
|
||||
.setDuration(250)
|
||||
.setOrdering(TransitionSet.ORDERING_TOGETHER);
|
||||
TransitionManager.beginDelayedTransition(root, transition);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutResource() {
|
||||
return com.android.systemui.R.layout.global_actions_grid_v2;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initializeLayout() {
|
||||
super.initializeLayout();
|
||||
mLockMessageContainer = requireViewById(
|
||||
com.android.systemui.R.id.global_actions_lock_message_container);
|
||||
mLockMessage = requireViewById(com.android.systemui.R.id.global_actions_lock_message);
|
||||
initializeWalletView();
|
||||
getWindow().setBackgroundDrawable(mBackgroundDrawable);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void showDialog() {
|
||||
mShowing = true;
|
||||
mNotificationShadeWindowController.setRequestTopUi(true, TAG);
|
||||
mSysUiState.setFlag(SYSUI_STATE_GLOBAL_ACTIONS_SHOWING, true)
|
||||
.commitUpdate(mContext.getDisplayId());
|
||||
|
||||
ViewGroup root = (ViewGroup) mGlobalActionsLayout.getRootView();
|
||||
root.setOnApplyWindowInsetsListener((v, windowInsets) -> {
|
||||
root.setPadding(windowInsets.getStableInsetLeft(),
|
||||
windowInsets.getStableInsetTop(),
|
||||
windowInsets.getStableInsetRight(),
|
||||
windowInsets.getStableInsetBottom());
|
||||
return WindowInsets.CONSUMED;
|
||||
});
|
||||
|
||||
mBackgroundDrawable.setAlpha(0);
|
||||
float xOffset = mGlobalActionsLayout.getAnimationOffsetX();
|
||||
ObjectAnimator alphaAnimator =
|
||||
ObjectAnimator.ofFloat(mContainer, "alpha", 0f, 1f);
|
||||
alphaAnimator.setInterpolator(Interpolators.LINEAR_OUT_SLOW_IN);
|
||||
alphaAnimator.setDuration(183);
|
||||
alphaAnimator.addUpdateListener((animation) -> {
|
||||
float animatedValue = animation.getAnimatedFraction();
|
||||
int alpha = (int) (animatedValue * mScrimAlpha * 255);
|
||||
mBackgroundDrawable.setAlpha(alpha);
|
||||
});
|
||||
|
||||
ObjectAnimator xAnimator =
|
||||
ObjectAnimator.ofFloat(mContainer, "translationX", xOffset, 0f);
|
||||
xAnimator.setInterpolator(Interpolators.LINEAR_OUT_SLOW_IN);
|
||||
xAnimator.setDuration(350);
|
||||
|
||||
AnimatorSet animatorSet = new AnimatorSet();
|
||||
animatorSet.playTogether(alphaAnimator, xAnimator);
|
||||
animatorSet.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void dismissInternal() {
|
||||
super.dismissInternal();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void completeDismiss() {
|
||||
dismissWallet();
|
||||
resetOrientation();
|
||||
super.completeDismiss();
|
||||
}
|
||||
|
||||
private void dismissWallet() {
|
||||
if (mWalletViewController != null) {
|
||||
mWalletViewController.onDismissed();
|
||||
// The wallet controller should not be re-used after being dismissed.
|
||||
mWalletViewController = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void resetOrientation() {
|
||||
if (mResetOrientationData != null) {
|
||||
RotationPolicy.setRotationLockAtAngle(mContext, mResetOrientationData.locked,
|
||||
mResetOrientationData.rotation);
|
||||
}
|
||||
setRotationSuggestionsEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshDialog() {
|
||||
// ensure dropdown menus are dismissed before re-initializing the dialog
|
||||
dismissWallet();
|
||||
super.refreshDialog();
|
||||
}
|
||||
|
||||
void hideLockMessage() {
|
||||
if (mLockMessageContainer.getVisibility() == View.VISIBLE) {
|
||||
mLockMessageContainer.animate().alpha(0).setDuration(150).setListener(
|
||||
new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
mLockMessageContainer.setVisibility(View.GONE);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
}
|
||||
|
||||
void showLockMessage() {
|
||||
Drawable lockIcon = mContext.getDrawable(com.android.internal.R.drawable.ic_lock);
|
||||
lockIcon.setTint(mContext.getColor(com.android.systemui.R.color.control_primary_text));
|
||||
mLockMessage.setCompoundDrawablesWithIntrinsicBounds(null, lockIcon, null, null);
|
||||
mLockMessageContainer.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
private static class ResetOrientationData {
|
||||
public boolean locked;
|
||||
public int rotation;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not debug mode has been activated for the Global Actions Panel.
|
||||
*/
|
||||
private static boolean isPanelDebugModeEnabled(Context context) {
|
||||
return Settings.Secure.getInt(context.getContentResolver(),
|
||||
Settings.Secure.GLOBAL_ACTIONS_PANEL_DEBUG_ENABLED, 0) == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not the Global Actions menu should be forced to use the newer
|
||||
* grid-style layout.
|
||||
*/
|
||||
private static boolean isForceGridEnabled(Context context) {
|
||||
return isPanelDebugModeEnabled(context);
|
||||
}
|
||||
|
||||
private boolean shouldShowLockMessage(ActionsDialog dialog) {
|
||||
return isWalletAvailableAfterUnlock(dialog);
|
||||
}
|
||||
|
||||
// Temporary while we move items out of the power menu
|
||||
private boolean isWalletAvailableAfterUnlock(ActionsDialog dialog) {
|
||||
boolean isLockedAfterBoot = mLockPatternUtils.getStrongAuthForUser(getCurrentUser().id)
|
||||
== STRONG_AUTH_REQUIRED_AFTER_BOOT;
|
||||
return !mKeyguardStateController.isUnlocked()
|
||||
&& (!mShowLockScreenCards || isLockedAfterBoot)
|
||||
&& dialog.isWalletViewAvailable();
|
||||
}
|
||||
|
||||
private void onPowerMenuLockScreenSettingsChanged() {
|
||||
mShowLockScreenCards = mSecureSettings.getInt(
|
||||
Settings.Secure.POWER_MENU_LOCKED_SHOW_CONTENT, 0) != 0;
|
||||
}
|
||||
}
|
||||
@@ -169,14 +169,14 @@ public class GlobalActionsDialogLiteTest extends SysuiTestCase {
|
||||
public void testShouldLogShow() {
|
||||
mGlobalActionsDialogLite.onShow(null);
|
||||
mTestableLooper.processAllMessages();
|
||||
verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent.GA_POWER_MENU_OPEN);
|
||||
verifyLogPosted(GlobalActionsDialogLite.GlobalActionsEvent.GA_POWER_MENU_OPEN);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldLogDismiss() {
|
||||
mGlobalActionsDialogLite.onDismiss(mGlobalActionsDialogLite.mDialog);
|
||||
mTestableLooper.processAllMessages();
|
||||
verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent.GA_POWER_MENU_CLOSE);
|
||||
verifyLogPosted(GlobalActionsDialogLite.GlobalActionsEvent.GA_POWER_MENU_CLOSE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -186,16 +186,16 @@ public class GlobalActionsDialogLiteTest extends SysuiTestCase {
|
||||
doReturn(true).when(mGlobalActionsDialogLite).shouldDisplayLockdown(any());
|
||||
doReturn(true).when(mGlobalActionsDialogLite).shouldShowAction(any());
|
||||
String[] actions = {
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_EMERGENCY,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_LOCKDOWN,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_POWER,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_RESTART,
|
||||
GlobalActionsDialogLite.GLOBAL_ACTION_KEY_EMERGENCY,
|
||||
GlobalActionsDialogLite.GLOBAL_ACTION_KEY_LOCKDOWN,
|
||||
GlobalActionsDialogLite.GLOBAL_ACTION_KEY_POWER,
|
||||
GlobalActionsDialogLite.GLOBAL_ACTION_KEY_RESTART,
|
||||
};
|
||||
doReturn(actions).when(mGlobalActionsDialogLite).getDefaultActions();
|
||||
GlobalActionsDialogLite.ActionsDialogLite dialog = mGlobalActionsDialogLite.createDialog();
|
||||
dialog.onBackPressed();
|
||||
mTestableLooper.processAllMessages();
|
||||
verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent.GA_CLOSE_BACK);
|
||||
verifyLogPosted(GlobalActionsDialogLite.GlobalActionsEvent.GA_CLOSE_BACK);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -205,17 +205,17 @@ public class GlobalActionsDialogLiteTest extends SysuiTestCase {
|
||||
doReturn(true).when(mGlobalActionsDialogLite).shouldDisplayLockdown(any());
|
||||
doReturn(true).when(mGlobalActionsDialogLite).shouldShowAction(any());
|
||||
String[] actions = {
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_EMERGENCY,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_LOCKDOWN,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_POWER,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_RESTART,
|
||||
GlobalActionsDialogLite.GLOBAL_ACTION_KEY_EMERGENCY,
|
||||
GlobalActionsDialogLite.GLOBAL_ACTION_KEY_LOCKDOWN,
|
||||
GlobalActionsDialogLite.GLOBAL_ACTION_KEY_POWER,
|
||||
GlobalActionsDialogLite.GLOBAL_ACTION_KEY_RESTART,
|
||||
};
|
||||
doReturn(actions).when(mGlobalActionsDialogLite).getDefaultActions();
|
||||
GlobalActionsDialogLite.ActionsDialogLite dialog = mGlobalActionsDialogLite.createDialog();
|
||||
|
||||
GestureDetector.SimpleOnGestureListener gestureListener = spy(dialog.mGestureListener);
|
||||
gestureListener.onSingleTapConfirmed(null);
|
||||
verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent.GA_CLOSE_TAP_OUTSIDE);
|
||||
verifyLogPosted(GlobalActionsDialogLite.GlobalActionsEvent.GA_CLOSE_TAP_OUTSIDE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -226,10 +226,10 @@ public class GlobalActionsDialogLiteTest extends SysuiTestCase {
|
||||
doReturn(true).when(mGlobalActionsDialogLite).shouldShowAction(any());
|
||||
doReturn(true).when(mStatusBar).isKeyguardShowing();
|
||||
String[] actions = {
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_EMERGENCY,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_LOCKDOWN,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_POWER,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_RESTART,
|
||||
GlobalActionsDialogLite.GLOBAL_ACTION_KEY_EMERGENCY,
|
||||
GlobalActionsDialogLite.GLOBAL_ACTION_KEY_LOCKDOWN,
|
||||
GlobalActionsDialogLite.GLOBAL_ACTION_KEY_POWER,
|
||||
GlobalActionsDialogLite.GLOBAL_ACTION_KEY_RESTART,
|
||||
};
|
||||
doReturn(actions).when(mGlobalActionsDialogLite).getDefaultActions();
|
||||
GlobalActionsDialogLite.ActionsDialogLite dialog = mGlobalActionsDialogLite.createDialog();
|
||||
@@ -238,7 +238,7 @@ public class GlobalActionsDialogLiteTest extends SysuiTestCase {
|
||||
MotionEvent start = MotionEvent.obtain(0, 0, MotionEvent.ACTION_DOWN, 0, 0, 0);
|
||||
MotionEvent end = MotionEvent.obtain(0, 0, MotionEvent.ACTION_DOWN, 0, 500, 0);
|
||||
gestureListener.onFling(start, end, 0, 1000);
|
||||
verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent.GA_CLOSE_TAP_OUTSIDE);
|
||||
verifyLogPosted(GlobalActionsDialogLite.GlobalActionsEvent.GA_CLOSE_TAP_OUTSIDE);
|
||||
verify(mStatusBar).animateExpandSettingsPanel(null);
|
||||
}
|
||||
|
||||
@@ -250,10 +250,10 @@ public class GlobalActionsDialogLiteTest extends SysuiTestCase {
|
||||
doReturn(true).when(mGlobalActionsDialogLite).shouldShowAction(any());
|
||||
doReturn(false).when(mStatusBar).isKeyguardShowing();
|
||||
String[] actions = {
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_EMERGENCY,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_LOCKDOWN,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_POWER,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_RESTART,
|
||||
GlobalActionsDialogLite.GLOBAL_ACTION_KEY_EMERGENCY,
|
||||
GlobalActionsDialogLite.GLOBAL_ACTION_KEY_LOCKDOWN,
|
||||
GlobalActionsDialogLite.GLOBAL_ACTION_KEY_POWER,
|
||||
GlobalActionsDialogLite.GLOBAL_ACTION_KEY_RESTART,
|
||||
};
|
||||
doReturn(actions).when(mGlobalActionsDialogLite).getDefaultActions();
|
||||
GlobalActionsDialogLite.ActionsDialogLite dialog = mGlobalActionsDialogLite.createDialog();
|
||||
@@ -262,40 +262,40 @@ public class GlobalActionsDialogLiteTest extends SysuiTestCase {
|
||||
MotionEvent start = MotionEvent.obtain(0, 0, MotionEvent.ACTION_DOWN, 0, 0, 0);
|
||||
MotionEvent end = MotionEvent.obtain(0, 0, MotionEvent.ACTION_DOWN, 0, 500, 0);
|
||||
gestureListener.onFling(start, end, 0, 1000);
|
||||
verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent.GA_CLOSE_TAP_OUTSIDE);
|
||||
verifyLogPosted(GlobalActionsDialogLite.GlobalActionsEvent.GA_CLOSE_TAP_OUTSIDE);
|
||||
verify(mStatusBar).animateExpandNotificationsPanel();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldLogBugreportPress() throws InterruptedException {
|
||||
GlobalActionsDialog.BugReportAction bugReportAction =
|
||||
GlobalActionsDialogLite.BugReportAction bugReportAction =
|
||||
mGlobalActionsDialogLite.makeBugReportActionForTesting();
|
||||
bugReportAction.onPress();
|
||||
verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent.GA_BUGREPORT_PRESS);
|
||||
verifyLogPosted(GlobalActionsDialogLite.GlobalActionsEvent.GA_BUGREPORT_PRESS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldLogBugreportLongPress() {
|
||||
GlobalActionsDialog.BugReportAction bugReportAction =
|
||||
GlobalActionsDialogLite.BugReportAction bugReportAction =
|
||||
mGlobalActionsDialogLite.makeBugReportActionForTesting();
|
||||
bugReportAction.onLongPress();
|
||||
verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent.GA_BUGREPORT_LONG_PRESS);
|
||||
verifyLogPosted(GlobalActionsDialogLite.GlobalActionsEvent.GA_BUGREPORT_LONG_PRESS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldLogEmergencyDialerPress() {
|
||||
GlobalActionsDialog.EmergencyDialerAction emergencyDialerAction =
|
||||
GlobalActionsDialogLite.EmergencyDialerAction emergencyDialerAction =
|
||||
mGlobalActionsDialogLite.makeEmergencyDialerActionForTesting();
|
||||
emergencyDialerAction.onPress();
|
||||
verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent.GA_EMERGENCY_DIALER_PRESS);
|
||||
verifyLogPosted(GlobalActionsDialogLite.GlobalActionsEvent.GA_EMERGENCY_DIALER_PRESS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldLogScreenshotPress() {
|
||||
GlobalActionsDialog.ScreenshotAction screenshotAction =
|
||||
GlobalActionsDialogLite.ScreenshotAction screenshotAction =
|
||||
mGlobalActionsDialogLite.makeScreenshotActionForTesting();
|
||||
screenshotAction.onPress();
|
||||
verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent.GA_SCREENSHOT_PRESS);
|
||||
verifyLogPosted(GlobalActionsDialogLite.GlobalActionsEvent.GA_SCREENSHOT_PRESS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -304,7 +304,7 @@ public class GlobalActionsDialogLiteTest extends SysuiTestCase {
|
||||
com.android.internal.R.integer.config_navBarInteractionMode,
|
||||
WindowManagerPolicyConstants.NAV_BAR_MODE_2BUTTON);
|
||||
|
||||
GlobalActionsDialog.ScreenshotAction screenshotAction =
|
||||
GlobalActionsDialogLite.ScreenshotAction screenshotAction =
|
||||
mGlobalActionsDialogLite.makeScreenshotActionForTesting();
|
||||
assertThat(screenshotAction.shouldShow()).isTrue();
|
||||
}
|
||||
@@ -315,12 +315,12 @@ public class GlobalActionsDialogLiteTest extends SysuiTestCase {
|
||||
com.android.internal.R.integer.config_navBarInteractionMode,
|
||||
WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON);
|
||||
|
||||
GlobalActionsDialog.ScreenshotAction screenshotAction =
|
||||
GlobalActionsDialogLite.ScreenshotAction screenshotAction =
|
||||
mGlobalActionsDialogLite.makeScreenshotActionForTesting();
|
||||
assertThat(screenshotAction.shouldShow()).isFalse();
|
||||
}
|
||||
|
||||
private void verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent event) {
|
||||
private void verifyLogPosted(GlobalActionsDialogLite.GlobalActionsEvent event) {
|
||||
mTestableLooper.processAllMessages();
|
||||
verify(mUiEventLogger, times(1))
|
||||
.log(event);
|
||||
@@ -341,19 +341,19 @@ public class GlobalActionsDialogLiteTest extends SysuiTestCase {
|
||||
doReturn(true).when(mGlobalActionsDialogLite).shouldDisplayLockdown(any());
|
||||
doReturn(true).when(mGlobalActionsDialogLite).shouldShowAction(any());
|
||||
String[] actions = {
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_EMERGENCY,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_LOCKDOWN,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_POWER,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_RESTART,
|
||||
GlobalActionsDialogLite.GLOBAL_ACTION_KEY_EMERGENCY,
|
||||
GlobalActionsDialogLite.GLOBAL_ACTION_KEY_LOCKDOWN,
|
||||
GlobalActionsDialogLite.GLOBAL_ACTION_KEY_POWER,
|
||||
GlobalActionsDialogLite.GLOBAL_ACTION_KEY_RESTART,
|
||||
};
|
||||
doReturn(actions).when(mGlobalActionsDialogLite).getDefaultActions();
|
||||
mGlobalActionsDialogLite.createActionItems();
|
||||
|
||||
assertItemsOfType(mGlobalActionsDialogLite.mItems,
|
||||
GlobalActionsDialog.EmergencyAction.class,
|
||||
GlobalActionsDialog.LockDownAction.class,
|
||||
GlobalActionsDialog.ShutDownAction.class,
|
||||
GlobalActionsDialog.RestartAction.class);
|
||||
GlobalActionsDialogLite.EmergencyAction.class,
|
||||
GlobalActionsDialogLite.LockDownAction.class,
|
||||
GlobalActionsDialogLite.ShutDownAction.class,
|
||||
GlobalActionsDialogLite.RestartAction.class);
|
||||
assertThat(mGlobalActionsDialogLite.mOverflowItems).isEmpty();
|
||||
assertThat(mGlobalActionsDialogLite.mPowerItems).isEmpty();
|
||||
}
|
||||
@@ -365,19 +365,19 @@ public class GlobalActionsDialogLiteTest extends SysuiTestCase {
|
||||
// make sure lockdown action will NOT be shown
|
||||
doReturn(false).when(mGlobalActionsDialogLite).shouldDisplayLockdown(any());
|
||||
String[] actions = {
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_EMERGENCY,
|
||||
GlobalActionsDialogLite.GLOBAL_ACTION_KEY_EMERGENCY,
|
||||
// lockdown action not allowed
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_LOCKDOWN,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_POWER,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_RESTART,
|
||||
GlobalActionsDialogLite.GLOBAL_ACTION_KEY_LOCKDOWN,
|
||||
GlobalActionsDialogLite.GLOBAL_ACTION_KEY_POWER,
|
||||
GlobalActionsDialogLite.GLOBAL_ACTION_KEY_RESTART,
|
||||
};
|
||||
doReturn(actions).when(mGlobalActionsDialogLite).getDefaultActions();
|
||||
mGlobalActionsDialogLite.createActionItems();
|
||||
|
||||
assertItemsOfType(mGlobalActionsDialogLite.mItems,
|
||||
GlobalActionsDialog.EmergencyAction.class,
|
||||
GlobalActionsDialog.ShutDownAction.class,
|
||||
GlobalActionsDialog.RestartAction.class);
|
||||
GlobalActionsDialogLite.EmergencyAction.class,
|
||||
GlobalActionsDialogLite.ShutDownAction.class,
|
||||
GlobalActionsDialogLite.RestartAction.class);
|
||||
assertThat(mGlobalActionsDialogLite.mOverflowItems).isEmpty();
|
||||
assertThat(mGlobalActionsDialogLite.mPowerItems).isEmpty();
|
||||
}
|
||||
@@ -387,7 +387,7 @@ public class GlobalActionsDialogLiteTest extends SysuiTestCase {
|
||||
GlobalActionsDialogLite.LockDownAction lockDownAction =
|
||||
mGlobalActionsDialogLite.new LockDownAction();
|
||||
lockDownAction.onPress();
|
||||
verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent.GA_LOCKDOWN_PRESS);
|
||||
verifyLogPosted(GlobalActionsDialogLite.GlobalActionsEvent.GA_LOCKDOWN_PRESS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -395,7 +395,7 @@ public class GlobalActionsDialogLiteTest extends SysuiTestCase {
|
||||
GlobalActionsDialogLite.ShutDownAction shutDownAction =
|
||||
mGlobalActionsDialogLite.new ShutDownAction();
|
||||
shutDownAction.onPress();
|
||||
verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent.GA_SHUTDOWN_PRESS);
|
||||
verifyLogPosted(GlobalActionsDialogLite.GlobalActionsEvent.GA_SHUTDOWN_PRESS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -403,7 +403,7 @@ public class GlobalActionsDialogLiteTest extends SysuiTestCase {
|
||||
GlobalActionsDialogLite.ShutDownAction shutDownAction =
|
||||
mGlobalActionsDialogLite.new ShutDownAction();
|
||||
shutDownAction.onLongPress();
|
||||
verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent.GA_SHUTDOWN_LONG_PRESS);
|
||||
verifyLogPosted(GlobalActionsDialogLite.GlobalActionsEvent.GA_SHUTDOWN_LONG_PRESS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -411,7 +411,7 @@ public class GlobalActionsDialogLiteTest extends SysuiTestCase {
|
||||
GlobalActionsDialogLite.RestartAction restartAction =
|
||||
mGlobalActionsDialogLite.new RestartAction();
|
||||
restartAction.onPress();
|
||||
verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent.GA_REBOOT_PRESS);
|
||||
verifyLogPosted(GlobalActionsDialogLite.GlobalActionsEvent.GA_REBOOT_PRESS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -419,6 +419,6 @@ public class GlobalActionsDialogLiteTest extends SysuiTestCase {
|
||||
GlobalActionsDialogLite.RestartAction restartAction =
|
||||
mGlobalActionsDialogLite.new RestartAction();
|
||||
restartAction.onLongPress();
|
||||
verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent.GA_REBOOT_LONG_PRESS);
|
||||
verifyLogPosted(GlobalActionsDialogLite.GlobalActionsEvent.GA_REBOOT_LONG_PRESS);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,573 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.systemui.globalactions;
|
||||
|
||||
import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_NOT_REQUIRED;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.IActivityManager;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.app.trust.TrustManager;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
import android.media.AudioManager;
|
||||
import android.os.Handler;
|
||||
import android.os.RemoteException;
|
||||
import android.os.UserManager;
|
||||
import android.service.dreams.IDreamManager;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.testing.TestableLooper;
|
||||
import android.view.IWindowManager;
|
||||
import android.view.View;
|
||||
import android.view.WindowManagerPolicyConstants;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import com.android.internal.colorextraction.ColorExtractor;
|
||||
import com.android.internal.logging.MetricsLogger;
|
||||
import com.android.internal.logging.UiEventLogger;
|
||||
import com.android.internal.statusbar.IStatusBarService;
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
import com.android.systemui.broadcast.BroadcastDispatcher;
|
||||
import com.android.systemui.colorextraction.SysuiColorExtractor;
|
||||
import com.android.systemui.model.SysUiState;
|
||||
import com.android.systemui.plugins.ActivityStarter;
|
||||
import com.android.systemui.plugins.GlobalActions;
|
||||
import com.android.systemui.plugins.GlobalActionsPanelPlugin;
|
||||
import com.android.systemui.settings.UserTracker;
|
||||
import com.android.systemui.statusbar.NotificationShadeWindowController;
|
||||
import com.android.systemui.statusbar.phone.StatusBar;
|
||||
import com.android.systemui.statusbar.policy.ConfigurationController;
|
||||
import com.android.systemui.statusbar.policy.KeyguardStateController;
|
||||
import com.android.systemui.telephony.TelephonyListenerManager;
|
||||
import com.android.systemui.util.RingerModeLiveData;
|
||||
import com.android.systemui.util.RingerModeTracker;
|
||||
import com.android.systemui.util.settings.GlobalSettings;
|
||||
import com.android.systemui.util.settings.SecureSettings;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@SmallTest
|
||||
@RunWith(AndroidTestingRunner.class)
|
||||
@TestableLooper.RunWithLooper(setAsMainLooper = true)
|
||||
public class GlobalActionsDialogTest extends SysuiTestCase {
|
||||
private static final long UI_TIMEOUT_MILLIS = 5000; // 5 sec
|
||||
private static final Pattern CANCEL_BUTTON =
|
||||
Pattern.compile("cancel", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
private GlobalActionsDialog mGlobalActionsDialog;
|
||||
|
||||
@Mock private GlobalActions.GlobalActionsManager mWindowManagerFuncs;
|
||||
@Mock private AudioManager mAudioManager;
|
||||
@Mock private IDreamManager mDreamManager;
|
||||
@Mock private DevicePolicyManager mDevicePolicyManager;
|
||||
@Mock private LockPatternUtils mLockPatternUtils;
|
||||
@Mock private BroadcastDispatcher mBroadcastDispatcher;
|
||||
@Mock private TelephonyListenerManager mTelephonyListenerManager;
|
||||
@Mock private GlobalSettings mGlobalSettings;
|
||||
@Mock private Resources mResources;
|
||||
@Mock private ConfigurationController mConfigurationController;
|
||||
@Mock private ActivityStarter mActivityStarter;
|
||||
@Mock private KeyguardStateController mKeyguardStateController;
|
||||
@Mock private UserManager mUserManager;
|
||||
@Mock private TrustManager mTrustManager;
|
||||
@Mock private IActivityManager mActivityManager;
|
||||
@Mock private MetricsLogger mMetricsLogger;
|
||||
@Mock private SysuiColorExtractor mColorExtractor;
|
||||
@Mock private IStatusBarService mStatusBarService;
|
||||
@Mock private NotificationShadeWindowController mNotificationShadeWindowController;
|
||||
@Mock private IWindowManager mWindowManager;
|
||||
@Mock private Executor mBackgroundExecutor;
|
||||
@Mock private UiEventLogger mUiEventLogger;
|
||||
@Mock private RingerModeTracker mRingerModeTracker;
|
||||
@Mock private RingerModeLiveData mRingerModeLiveData;
|
||||
@Mock private SysUiState mSysUiState;
|
||||
@Mock GlobalActionsPanelPlugin mWalletPlugin;
|
||||
@Mock GlobalActionsPanelPlugin.PanelViewController mWalletController;
|
||||
@Mock private Handler mHandler;
|
||||
@Mock private UserTracker mUserTracker;
|
||||
@Mock private PackageManager mPackageManager;
|
||||
@Mock private SecureSettings mSecureSettings;
|
||||
@Mock private StatusBar mStatusBar;
|
||||
|
||||
private TestableLooper mTestableLooper;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mTestableLooper = TestableLooper.get(this);
|
||||
allowTestableLooperAsMainThread();
|
||||
|
||||
when(mRingerModeTracker.getRingerMode()).thenReturn(mRingerModeLiveData);
|
||||
when(mResources.getConfiguration()).thenReturn(
|
||||
getContext().getResources().getConfiguration());
|
||||
|
||||
mGlobalActionsDialog = new GlobalActionsDialog(mContext,
|
||||
mWindowManagerFuncs,
|
||||
mAudioManager,
|
||||
mDreamManager,
|
||||
mDevicePolicyManager,
|
||||
mLockPatternUtils,
|
||||
mBroadcastDispatcher,
|
||||
mTelephonyListenerManager,
|
||||
mGlobalSettings,
|
||||
mSecureSettings,
|
||||
null,
|
||||
mResources,
|
||||
mConfigurationController,
|
||||
mActivityStarter,
|
||||
mKeyguardStateController,
|
||||
mUserManager,
|
||||
mTrustManager,
|
||||
mActivityManager,
|
||||
null,
|
||||
mMetricsLogger,
|
||||
mColorExtractor,
|
||||
mStatusBarService,
|
||||
mNotificationShadeWindowController,
|
||||
mWindowManager,
|
||||
mBackgroundExecutor,
|
||||
mUiEventLogger,
|
||||
mRingerModeTracker,
|
||||
mSysUiState,
|
||||
mHandler,
|
||||
mPackageManager,
|
||||
Optional.of(mStatusBar)
|
||||
);
|
||||
mGlobalActionsDialog.setZeroDialogPressDelayForTesting();
|
||||
|
||||
ColorExtractor.GradientColors backdropColors = new ColorExtractor.GradientColors();
|
||||
backdropColors.setMainColor(Color.BLACK);
|
||||
when(mColorExtractor.getNeutralColors()).thenReturn(backdropColors);
|
||||
when(mSysUiState.setFlag(anyInt(), anyBoolean())).thenReturn(mSysUiState);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldLogShow() {
|
||||
mGlobalActionsDialog.onShow(null);
|
||||
mTestableLooper.processAllMessages();
|
||||
verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent.GA_POWER_MENU_OPEN);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldLogDismiss() {
|
||||
mGlobalActionsDialog.onDismiss(mGlobalActionsDialog.mDialog);
|
||||
mTestableLooper.processAllMessages();
|
||||
verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent.GA_POWER_MENU_CLOSE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldLogBugreportPress() throws InterruptedException {
|
||||
GlobalActionsDialog.BugReportAction bugReportAction =
|
||||
mGlobalActionsDialog.makeBugReportActionForTesting();
|
||||
bugReportAction.onPress();
|
||||
verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent.GA_BUGREPORT_PRESS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldLogBugreportLongPress() {
|
||||
GlobalActionsDialog.BugReportAction bugReportAction =
|
||||
mGlobalActionsDialog.makeBugReportActionForTesting();
|
||||
bugReportAction.onLongPress();
|
||||
verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent.GA_BUGREPORT_LONG_PRESS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldLogEmergencyDialerPress() {
|
||||
GlobalActionsDialog.EmergencyDialerAction emergencyDialerAction =
|
||||
mGlobalActionsDialog.makeEmergencyDialerActionForTesting();
|
||||
emergencyDialerAction.onPress();
|
||||
verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent.GA_EMERGENCY_DIALER_PRESS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldLogScreenshotPress() {
|
||||
GlobalActionsDialog.ScreenshotAction screenshotAction =
|
||||
mGlobalActionsDialog.makeScreenshotActionForTesting();
|
||||
screenshotAction.onPress();
|
||||
verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent.GA_SCREENSHOT_PRESS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldShowScreenshot() {
|
||||
mContext.getOrCreateTestableResources().addOverride(
|
||||
com.android.internal.R.integer.config_navBarInteractionMode,
|
||||
WindowManagerPolicyConstants.NAV_BAR_MODE_2BUTTON);
|
||||
|
||||
GlobalActionsDialog.ScreenshotAction screenshotAction =
|
||||
mGlobalActionsDialog.makeScreenshotActionForTesting();
|
||||
assertThat(screenshotAction.shouldShow()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldNotShowScreenshot() {
|
||||
mContext.getOrCreateTestableResources().addOverride(
|
||||
com.android.internal.R.integer.config_navBarInteractionMode,
|
||||
WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON);
|
||||
|
||||
GlobalActionsDialog.ScreenshotAction screenshotAction =
|
||||
mGlobalActionsDialog.makeScreenshotActionForTesting();
|
||||
assertThat(screenshotAction.shouldShow()).isFalse();
|
||||
}
|
||||
|
||||
private void verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent event) {
|
||||
mTestableLooper.processAllMessages();
|
||||
verify(mUiEventLogger, times(1))
|
||||
.log(event);
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
private static <T> void assertItemsOfType(List<T> stuff, Class<? extends T>... classes) {
|
||||
assertThat(stuff).hasSize(classes.length);
|
||||
for (int i = 0; i < stuff.size(); i++) {
|
||||
assertThat(stuff.get(i)).isInstanceOf(classes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateActionItems_maxThree_noOverflow() {
|
||||
mGlobalActionsDialog = spy(mGlobalActionsDialog);
|
||||
// allow 3 items to be shown
|
||||
doReturn(3).when(mGlobalActionsDialog).getMaxShownPowerItems();
|
||||
// ensure items are not blocked by keyguard or device provisioning
|
||||
doReturn(true).when(mGlobalActionsDialog).shouldShowAction(any());
|
||||
String[] actions = {
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_EMERGENCY,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_POWER,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_RESTART,
|
||||
};
|
||||
doReturn(actions).when(mGlobalActionsDialog).getDefaultActions();
|
||||
mGlobalActionsDialog.createActionItems();
|
||||
|
||||
assertItemsOfType(mGlobalActionsDialog.mItems,
|
||||
GlobalActionsDialog.EmergencyAction.class,
|
||||
GlobalActionsDialog.ShutDownAction.class,
|
||||
GlobalActionsDialog.RestartAction.class);
|
||||
assertThat(mGlobalActionsDialog.mOverflowItems).isEmpty();
|
||||
assertThat(mGlobalActionsDialog.mPowerItems).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateActionItems_maxThree_condensePower() {
|
||||
mGlobalActionsDialog = spy(mGlobalActionsDialog);
|
||||
// allow 3 items to be shown
|
||||
doReturn(3).when(mGlobalActionsDialog).getMaxShownPowerItems();
|
||||
// ensure items are not blocked by keyguard or device provisioning
|
||||
doReturn(true).when(mGlobalActionsDialog).shouldShowAction(any());
|
||||
// make sure lockdown action will be shown
|
||||
doReturn(true).when(mGlobalActionsDialog).shouldDisplayLockdown(any());
|
||||
String[] actions = {
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_EMERGENCY,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_LOCKDOWN,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_POWER,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_RESTART,
|
||||
};
|
||||
doReturn(actions).when(mGlobalActionsDialog).getDefaultActions();
|
||||
mGlobalActionsDialog.createActionItems();
|
||||
|
||||
assertItemsOfType(mGlobalActionsDialog.mItems,
|
||||
GlobalActionsDialog.EmergencyAction.class,
|
||||
GlobalActionsDialog.LockDownAction.class,
|
||||
GlobalActionsDialog.PowerOptionsAction.class);
|
||||
assertThat(mGlobalActionsDialog.mOverflowItems).isEmpty();
|
||||
assertItemsOfType(mGlobalActionsDialog.mPowerItems,
|
||||
GlobalActionsDialog.ShutDownAction.class,
|
||||
GlobalActionsDialog.RestartAction.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateActionItems_maxThree_condensePower_splitPower() {
|
||||
mGlobalActionsDialog = spy(mGlobalActionsDialog);
|
||||
// allow 3 items to be shown
|
||||
doReturn(3).when(mGlobalActionsDialog).getMaxShownPowerItems();
|
||||
// make sure lockdown action will be shown
|
||||
doReturn(true).when(mGlobalActionsDialog).shouldDisplayLockdown(any());
|
||||
// make sure bugreport also shown
|
||||
doReturn(true).when(mGlobalActionsDialog).shouldDisplayBugReport(any());
|
||||
// ensure items are not blocked by keyguard or device provisioning
|
||||
doReturn(true).when(mGlobalActionsDialog).shouldShowAction(any());
|
||||
String[] actions = {
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_EMERGENCY,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_LOCKDOWN,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_POWER,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_BUGREPORT,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_RESTART,
|
||||
};
|
||||
doReturn(actions).when(mGlobalActionsDialog).getDefaultActions();
|
||||
mGlobalActionsDialog.createActionItems();
|
||||
|
||||
assertItemsOfType(mGlobalActionsDialog.mItems,
|
||||
GlobalActionsDialog.EmergencyAction.class,
|
||||
GlobalActionsDialog.LockDownAction.class,
|
||||
GlobalActionsDialog.PowerOptionsAction.class);
|
||||
assertItemsOfType(mGlobalActionsDialog.mOverflowItems,
|
||||
GlobalActionsDialog.BugReportAction.class);
|
||||
assertItemsOfType(mGlobalActionsDialog.mPowerItems,
|
||||
GlobalActionsDialog.ShutDownAction.class,
|
||||
GlobalActionsDialog.RestartAction.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateActionItems_maxFour_condensePower() {
|
||||
mGlobalActionsDialog = spy(mGlobalActionsDialog);
|
||||
// allow 3 items to be shown
|
||||
doReturn(4).when(mGlobalActionsDialog).getMaxShownPowerItems();
|
||||
// make sure lockdown action will be shown
|
||||
doReturn(true).when(mGlobalActionsDialog).shouldDisplayLockdown(any());
|
||||
// ensure items are not blocked by keyguard or device provisioning
|
||||
doReturn(true).when(mGlobalActionsDialog).shouldShowAction(any());
|
||||
String[] actions = {
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_EMERGENCY,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_LOCKDOWN,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_POWER,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_RESTART,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_SCREENSHOT
|
||||
};
|
||||
doReturn(actions).when(mGlobalActionsDialog).getDefaultActions();
|
||||
mGlobalActionsDialog.createActionItems();
|
||||
|
||||
assertItemsOfType(mGlobalActionsDialog.mItems,
|
||||
GlobalActionsDialog.EmergencyAction.class,
|
||||
GlobalActionsDialog.LockDownAction.class,
|
||||
GlobalActionsDialog.PowerOptionsAction.class,
|
||||
GlobalActionsDialog.ScreenshotAction.class);
|
||||
assertThat(mGlobalActionsDialog.mOverflowItems).isEmpty();
|
||||
assertItemsOfType(mGlobalActionsDialog.mPowerItems,
|
||||
GlobalActionsDialog.ShutDownAction.class,
|
||||
GlobalActionsDialog.RestartAction.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateActionItems_maxThree_doNotCondensePower() {
|
||||
mGlobalActionsDialog = spy(mGlobalActionsDialog);
|
||||
// allow 3 items to be shown
|
||||
doReturn(3).when(mGlobalActionsDialog).getMaxShownPowerItems();
|
||||
// make sure lockdown action will be shown
|
||||
doReturn(true).when(mGlobalActionsDialog).shouldDisplayLockdown(any());
|
||||
// make sure bugreport is also shown
|
||||
doReturn(true).when(mGlobalActionsDialog).shouldDisplayBugReport(any());
|
||||
// ensure items are not blocked by keyguard or device provisioning
|
||||
doReturn(true).when(mGlobalActionsDialog).shouldShowAction(any());
|
||||
String[] actions = {
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_EMERGENCY,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_POWER,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_BUGREPORT,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_LOCKDOWN,
|
||||
};
|
||||
doReturn(actions).when(mGlobalActionsDialog).getDefaultActions();
|
||||
mGlobalActionsDialog.createActionItems();
|
||||
|
||||
assertItemsOfType(mGlobalActionsDialog.mItems,
|
||||
GlobalActionsDialog.EmergencyAction.class,
|
||||
GlobalActionsDialog.ShutDownAction.class,
|
||||
GlobalActionsDialog.BugReportAction.class);
|
||||
assertItemsOfType(mGlobalActionsDialog.mOverflowItems,
|
||||
GlobalActionsDialog.LockDownAction.class);
|
||||
assertThat(mGlobalActionsDialog.mPowerItems).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateActionItems_maxAny() {
|
||||
mGlobalActionsDialog = spy(mGlobalActionsDialog);
|
||||
// allow any number of power menu items to be shown
|
||||
doReturn(Integer.MAX_VALUE).when(mGlobalActionsDialog).getMaxShownPowerItems();
|
||||
// ensure items are not blocked by keyguard or device provisioning
|
||||
doReturn(true).when(mGlobalActionsDialog).shouldShowAction(any());
|
||||
// make sure lockdown action will be shown
|
||||
doReturn(true).when(mGlobalActionsDialog).shouldDisplayLockdown(any());
|
||||
String[] actions = {
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_EMERGENCY,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_POWER,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_RESTART,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_LOCKDOWN,
|
||||
};
|
||||
doReturn(actions).when(mGlobalActionsDialog).getDefaultActions();
|
||||
mGlobalActionsDialog.createActionItems();
|
||||
|
||||
assertItemsOfType(mGlobalActionsDialog.mItems,
|
||||
GlobalActionsDialog.EmergencyAction.class,
|
||||
GlobalActionsDialog.ShutDownAction.class,
|
||||
GlobalActionsDialog.RestartAction.class,
|
||||
GlobalActionsDialog.LockDownAction.class);
|
||||
assertThat(mGlobalActionsDialog.mOverflowItems).isEmpty();
|
||||
assertThat(mGlobalActionsDialog.mPowerItems).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateActionItems_maxThree_lockdownDisabled_doesNotShowLockdown() {
|
||||
mGlobalActionsDialog = spy(mGlobalActionsDialog);
|
||||
// allow only 3 items to be shown
|
||||
doReturn(3).when(mGlobalActionsDialog).getMaxShownPowerItems();
|
||||
// make sure lockdown action will NOT be shown
|
||||
doReturn(false).when(mGlobalActionsDialog).shouldDisplayLockdown(any());
|
||||
String[] actions = {
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_EMERGENCY,
|
||||
// lockdown action not allowed
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_LOCKDOWN,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_POWER,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_RESTART,
|
||||
};
|
||||
doReturn(actions).when(mGlobalActionsDialog).getDefaultActions();
|
||||
mGlobalActionsDialog.createActionItems();
|
||||
|
||||
assertItemsOfType(mGlobalActionsDialog.mItems,
|
||||
GlobalActionsDialog.EmergencyAction.class,
|
||||
GlobalActionsDialog.ShutDownAction.class,
|
||||
GlobalActionsDialog.RestartAction.class);
|
||||
assertThat(mGlobalActionsDialog.mOverflowItems).isEmpty();
|
||||
assertThat(mGlobalActionsDialog.mPowerItems).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateActionItems_shouldShowAction_excludeBugReport() {
|
||||
mGlobalActionsDialog = spy(mGlobalActionsDialog);
|
||||
// allow only 3 items to be shown
|
||||
doReturn(3).when(mGlobalActionsDialog).getMaxShownPowerItems();
|
||||
doReturn(true).when(mGlobalActionsDialog).shouldDisplayBugReport(any());
|
||||
// exclude bugreport in shouldShowAction to demonstrate how any button can be removed
|
||||
doAnswer(
|
||||
invocation -> !(invocation.getArgument(0)
|
||||
instanceof GlobalActionsDialog.BugReportAction))
|
||||
.when(mGlobalActionsDialog).shouldShowAction(any());
|
||||
|
||||
String[] actions = {
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_EMERGENCY,
|
||||
// bugreport action not allowed
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_BUGREPORT,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_POWER,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_RESTART,
|
||||
};
|
||||
doReturn(actions).when(mGlobalActionsDialog).getDefaultActions();
|
||||
mGlobalActionsDialog.createActionItems();
|
||||
|
||||
assertItemsOfType(mGlobalActionsDialog.mItems,
|
||||
GlobalActionsDialog.EmergencyAction.class,
|
||||
GlobalActionsDialog.ShutDownAction.class,
|
||||
GlobalActionsDialog.RestartAction.class);
|
||||
assertThat(mGlobalActionsDialog.mOverflowItems).isEmpty();
|
||||
assertThat(mGlobalActionsDialog.mPowerItems).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldShowLockScreenMessage() throws RemoteException {
|
||||
mGlobalActionsDialog = spy(mGlobalActionsDialog);
|
||||
mGlobalActionsDialog.mDialog = null;
|
||||
when(mKeyguardStateController.isUnlocked()).thenReturn(false);
|
||||
when(mActivityManager.getCurrentUser()).thenReturn(newUserInfo());
|
||||
when(mLockPatternUtils.getStrongAuthForUser(anyInt())).thenReturn(STRONG_AUTH_NOT_REQUIRED);
|
||||
mGlobalActionsDialog.mShowLockScreenCards = false;
|
||||
setupDefaultActions();
|
||||
when(mWalletPlugin.onPanelShown(any(), anyBoolean())).thenReturn(mWalletController);
|
||||
when(mWalletController.getPanelContent()).thenReturn(new FrameLayout(mContext));
|
||||
|
||||
mGlobalActionsDialog.showOrHideDialog(false, true, mWalletPlugin);
|
||||
|
||||
GlobalActionsDialog.ActionsDialog dialog =
|
||||
(GlobalActionsDialog.ActionsDialog) mGlobalActionsDialog.mDialog;
|
||||
assertThat(dialog).isNotNull();
|
||||
assertThat(dialog.mLockMessageContainer.getVisibility()).isEqualTo(View.VISIBLE);
|
||||
|
||||
// Dismiss the dialog so that it does not pollute other tests
|
||||
mGlobalActionsDialog.showOrHideDialog(false, true, mWalletPlugin);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldNotShowLockScreenMessage_whenWalletShownOnLockScreen()
|
||||
throws RemoteException {
|
||||
mGlobalActionsDialog = spy(mGlobalActionsDialog);
|
||||
mGlobalActionsDialog.mDialog = null;
|
||||
when(mKeyguardStateController.isUnlocked()).thenReturn(false);
|
||||
when(mActivityManager.getCurrentUser()).thenReturn(newUserInfo());
|
||||
when(mLockPatternUtils.getStrongAuthForUser(anyInt())).thenReturn(STRONG_AUTH_NOT_REQUIRED);
|
||||
mGlobalActionsDialog.mShowLockScreenCards = true;
|
||||
setupDefaultActions();
|
||||
when(mWalletPlugin.onPanelShown(any(), anyBoolean())).thenReturn(mWalletController);
|
||||
when(mWalletController.getPanelContent()).thenReturn(new FrameLayout(mContext));
|
||||
|
||||
mGlobalActionsDialog.showOrHideDialog(false, true, mWalletPlugin);
|
||||
|
||||
GlobalActionsDialog.ActionsDialog dialog =
|
||||
(GlobalActionsDialog.ActionsDialog) mGlobalActionsDialog.mDialog;
|
||||
assertThat(dialog).isNotNull();
|
||||
assertThat(dialog.mLockMessageContainer.getVisibility()).isEqualTo(View.GONE);
|
||||
|
||||
// Dismiss the dialog so that it does not pollute other tests
|
||||
mGlobalActionsDialog.showOrHideDialog(false, true, mWalletPlugin);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldNotShowLockScreenMessage_whenWalletBothDisabled()
|
||||
throws RemoteException {
|
||||
mGlobalActionsDialog = spy(mGlobalActionsDialog);
|
||||
mGlobalActionsDialog.mDialog = null;
|
||||
when(mKeyguardStateController.isUnlocked()).thenReturn(false);
|
||||
|
||||
when(mActivityManager.getCurrentUser()).thenReturn(newUserInfo());
|
||||
when(mLockPatternUtils.getStrongAuthForUser(anyInt())).thenReturn(STRONG_AUTH_NOT_REQUIRED);
|
||||
mGlobalActionsDialog.mShowLockScreenCards = true;
|
||||
setupDefaultActions();
|
||||
when(mWalletPlugin.onPanelShown(any(), anyBoolean())).thenReturn(mWalletController);
|
||||
when(mWalletController.getPanelContent()).thenReturn(null);
|
||||
|
||||
mGlobalActionsDialog.showOrHideDialog(false, true, mWalletPlugin);
|
||||
|
||||
GlobalActionsDialog.ActionsDialog dialog =
|
||||
(GlobalActionsDialog.ActionsDialog) mGlobalActionsDialog.mDialog;
|
||||
assertThat(dialog).isNotNull();
|
||||
assertThat(dialog.mLockMessageContainer.getVisibility()).isEqualTo(View.GONE);
|
||||
|
||||
// Dismiss the dialog so that it does not pollute other tests
|
||||
mGlobalActionsDialog.showOrHideDialog(false, true, mWalletPlugin);
|
||||
}
|
||||
|
||||
private UserInfo newUserInfo() {
|
||||
return new UserInfo(0, null, null, UserInfo.FLAG_PRIMARY, null);
|
||||
}
|
||||
|
||||
private void setupDefaultActions() {
|
||||
String[] actions = {
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_EMERGENCY,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_POWER,
|
||||
GlobalActionsDialog.GLOBAL_ACTION_KEY_RESTART,
|
||||
};
|
||||
doReturn(actions).when(mGlobalActionsDialog).getDefaultActions();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user