Ensure we get the right nav bar mode for the current user in sysui
- Load resources from the current user's context to ensure the right
overlays are read
- Create a controller in sysui to dispatch mode change to prevent callers
from calling with the wrong user's context
- Clean up the quickstep contract to prevent launcher from calling methods
using the baked in fw resource ids
Bug: 130185871
Test: Switch to secondary user, ensure the mode is read correctly
Change-Id: I00d9276185777e340b3e758345a00d2e9b3e3e64
diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/QuickStepContract.java b/packages/SystemUI/shared/src/com/android/systemui/shared/system/QuickStepContract.java
index 4054784..56aabc2a 100644
--- a/packages/SystemUI/shared/src/com/android/systemui/shared/system/QuickStepContract.java
+++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/QuickStepContract.java
@@ -21,7 +21,6 @@
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL;
import android.annotation.IntDef;
-import android.content.Context;
import android.content.res.Resources;
import android.view.WindowManagerPolicyConstants;
@@ -90,13 +89,6 @@
}
/**
- * @return whether the current nav bar mode is gestural
- */
- public static boolean isGesturalMode(Context context) {
- return isGesturalMode(getCurrentInteractionMode(context));
- }
-
- /**
* @return whether this nav bar mode is swipe up
*/
public static boolean isSwipeUpMode(int mode) {
@@ -104,13 +96,6 @@
}
/**
- * @return whether the current nav bar mode is swipe up
- */
- public static boolean isSwipeUpMode(Context context) {
- return isSwipeUpMode(getCurrentInteractionMode(context));
- }
-
- /**
* @return whether this nav bar mode is 3 button
*/
public static boolean isLegacyMode(int mode) {
@@ -118,37 +103,6 @@
}
/**
- * @return whether this nav bar mode is 3 button
- */
- public static boolean isLegacyMode(Context context) {
- return isLegacyMode(getCurrentInteractionMode(context));
- }
-
- /**
- * @return the current nav bar interaction mode
- */
- public static int getCurrentInteractionMode(Context context) {
- return context.getResources().getInteger(
- com.android.internal.R.integer.config_navBarInteractionMode);
- }
-
- /**
- * @return {@code true} if the navbar can be clicked through
- */
- public static boolean isNavBarClickThrough(Context context) {
- return context.getResources().getBoolean(
- com.android.internal.R.bool.config_navBarTapThrough);
- }
-
- /**
- * @return the edge sensitivity width in px
- */
- public static int getEdgeSensitivityWidth(Context context) {
- return context.getResources().getDimensionPixelSize(
- com.android.internal.R.dimen.config_backGestureInset);
- }
-
- /**
* Corner radius that should be used on windows in order to cover the display.
* These values are expressed in pixels because they should not respect display or font
* scaling, this means that we don't have to reload them on config changes.
diff --git a/packages/SystemUI/src/com/android/systemui/Dependency.java b/packages/SystemUI/src/com/android/systemui/Dependency.java
index 4b338f7..1feb63d 100644
--- a/packages/SystemUI/src/com/android/systemui/Dependency.java
+++ b/packages/SystemUI/src/com/android/systemui/Dependency.java
@@ -74,6 +74,7 @@
import com.android.systemui.statusbar.phone.LightBarController;
import com.android.systemui.statusbar.phone.LockscreenGestureLogger;
import com.android.systemui.statusbar.phone.ManagedProfileController;
+import com.android.systemui.statusbar.phone.NavigationModeController;
import com.android.systemui.statusbar.phone.NotificationGroupAlertTransferHelper;
import com.android.systemui.statusbar.phone.NotificationGroupManager;
import com.android.systemui.statusbar.phone.ShadeController;
@@ -244,6 +245,7 @@
@Inject Lazy<LightBarController> mLightBarController;
@Inject Lazy<IWindowManager> mIWindowManager;
@Inject Lazy<OverviewProxyService> mOverviewProxyService;
+ @Inject Lazy<NavigationModeController> mNavBarModeController;
@Inject Lazy<EnhancedEstimates> mEnhancedEstimates;
@Inject Lazy<VibratorHelper> mVibratorHelper;
@Inject Lazy<IStatusBarService> mIStatusBarService;
@@ -407,6 +409,8 @@
mProviders.put(OverviewProxyService.class, mOverviewProxyService::get);
+ mProviders.put(NavigationModeController.class, mNavBarModeController::get);
+
mProviders.put(EnhancedEstimates.class, mEnhancedEstimates::get);
mProviders.put(VibratorHelper.class, mVibratorHelper::get);
diff --git a/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java b/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java
index 898f64b..09a5e6f 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java
@@ -20,6 +20,7 @@
import static android.view.MotionEvent.ACTION_CANCEL;
import static android.view.MotionEvent.ACTION_DOWN;
import static android.view.MotionEvent.ACTION_UP;
+import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON;
import static com.android.systemui.shared.system.NavigationBarCompat.FLAG_DISABLE_SWIPE_UP;
import static com.android.systemui.shared.system.NavigationBarCompat.FLAG_SHOW_OVERVIEW_BUTTON;
@@ -69,6 +70,7 @@
import com.android.systemui.stackdivider.Divider;
import com.android.systemui.statusbar.NavigationBarController;
import com.android.systemui.statusbar.phone.NavigationBarFragment;
+import com.android.systemui.statusbar.phone.NavigationModeController;
import com.android.systemui.statusbar.phone.StatusBar;
import com.android.systemui.statusbar.policy.CallbackController;
import com.android.systemui.statusbar.policy.DeviceProvisionedController;
@@ -86,7 +88,8 @@
* Class to send information from overview to launcher with a binder.
*/
@Singleton
-public class OverviewProxyService implements CallbackController<OverviewProxyListener>, Dumpable {
+public class OverviewProxyService implements CallbackController<OverviewProxyListener>,
+ NavigationModeController.ModeChangedListener, Dumpable {
private static final String ACTION_QUICKSTEP = "android.intent.action.QUICKSTEP_SERVICE";
@@ -123,6 +126,7 @@
private MotionEvent mStatusBarGestureDownEvent;
private float mWindowCornerRadius;
private boolean mSupportsRoundedCornersOnWindows;
+ private int mNavBarMode = NAV_BAR_MODE_3BUTTON;
private ISystemUiProxy mSysUiProxy = new ISystemUiProxy.Stub() {
@@ -411,16 +415,6 @@
private final DeviceProvisionedListener mDeviceProvisionedCallback =
new DeviceProvisionedListener() {
-
- @Override
- public void onDeviceProvisionedChanged() {
- /*
- on initialize, keep track of the previous gestural state (nothing is enabled by default)
- restore to a non gestural state if device is not provisioned
- once the device is provisioned, restore to the original state
- */
- }
-
@Override
public void onUserSetupChanged() {
if (mDeviceProvisionedController.isCurrentUserSetup()) {
@@ -458,6 +452,8 @@
// Assumes device always starts with back button until launcher tells it that it does not
mBackButtonAlpha = 1.0f;
+ mNavBarMode = Dependency.get(NavigationModeController.class).addListener(this);
+
// Listen for the package update changes.
if (mDeviceProvisionedController.getCurrentUser() == UserHandle.USER_SYSTEM) {
updateEnabledState();
@@ -467,6 +463,7 @@
filter.addDataSchemeSpecificPart(mRecentsComponentName.getPackageName(),
PatternMatcher.PATTERN_LITERAL);
filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
+ // TODO: Shouldn't this be per-user?
mContext.registerReceiver(mLauncherStateChangedReceiver, filter);
}
}
@@ -661,7 +658,7 @@
private int getDefaultInteractionFlags() {
// If there is no settings available use device default or get it from settings
- return QuickStepContract.isLegacyMode(mContext)
+ return QuickStepContract.isLegacyMode(mNavBarMode)
? DEFAULT_DISABLE_SWIPE_UP_STATE
: 0;
}
@@ -719,6 +716,11 @@
}
@Override
+ public void onNavigationModeChanged(int mode) {
+ mNavBarMode = mode;
+ }
+
+ @Override
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
pw.println(TAG_OPS + " state:");
pw.print(" recentsComponentName="); pw.println(mRecentsComponentName);
@@ -730,8 +732,6 @@
pw.print(" quickStepIntent="); pw.println(mQuickStepIntent);
pw.print(" quickStepIntentResolved="); pw.println(isEnabled());
- pw.print(" navBarMode=");
- pw.println(QuickStepContract.getCurrentInteractionMode(mContext));
pw.print(" mSysUiStateFlags="); pw.println(mSysUiStateFlags);
}
diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsOnboarding.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsOnboarding.java
index 33a2acf..d0c4734 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/RecentsOnboarding.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsOnboarding.java
@@ -18,6 +18,7 @@
import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
+import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON;
import static com.android.systemui.Prefs.Key.DISMISSED_RECENTS_SWIPE_UP_ONBOARDING_COUNT;
import static com.android.systemui.Prefs.Key.HAS_DISMISSED_RECENTS_QUICK_SCRUB_ONBOARDING_ONCE;
@@ -111,6 +112,7 @@
private final int mOnboardingToastColor;
private final int mOnboardingToastArrowRadius;
private int mNavBarHeight;
+ private int mNavBarMode = NAV_BAR_MODE_3BUTTON;
private boolean mOverviewProxyListenerRegistered;
private boolean mTaskListenerRegistered;
@@ -339,8 +341,12 @@
} catch (RemoteException e) {}
}
+ public void onNavigationModeChanged(int mode) {
+ mNavBarMode = mode;
+ }
+
public void onConnectedToLauncher() {
- if (!ONBOARDING_ENABLED || QuickStepContract.isGesturalMode(mContext)) {
+ if (!ONBOARDING_ENABLED || QuickStepContract.isGesturalMode(mNavBarMode)) {
return;
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/EdgeBackGestureHandler.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/EdgeBackGestureHandler.java
index 8028200..ad8d40b 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/EdgeBackGestureHandler.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/EdgeBackGestureHandler.java
@@ -156,7 +156,9 @@
mWm = context.getSystemService(WindowManager.class);
mOverviewProxyService = overviewProxyService;
- mEdgeWidth = QuickStepContract.getEdgeSensitivityWidth(context);
+ // TODO: Get this for the current user
+ mEdgeWidth = res.getDimensionPixelSize(
+ com.android.internal.R.dimen.config_backGestureInset);
mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
mSwipeThreshold = res.getDimension(R.dimen.navigation_edge_action_drag_threshold);
@@ -168,7 +170,7 @@
*/
public void onNavBarAttached() {
mIsAttached = true;
- onOverlaysChanged();
+ updateIsEnabled();
}
/**
@@ -179,11 +181,8 @@
updateIsEnabled();
}
- /**
- * Called when system overlays has changed
- */
- public void onOverlaysChanged() {
- mIsGesturalModeEnabled = QuickStepContract.isGesturalMode(mContext);
+ public void onNavigationModeChanged(int mode) {
+ mIsGesturalModeEnabled = QuickStepContract.isGesturalMode(mode);
updateIsEnabled();
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavBarTintController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavBarTintController.java
index bf5b60a..2f245ff 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavBarTintController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavBarTintController.java
@@ -17,6 +17,7 @@
package com.android.systemui.statusbar.phone;
import static android.view.Display.DEFAULT_DISPLAY;
+import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON;
import android.content.Context;
import android.content.res.Resources;
@@ -43,6 +44,7 @@
private final Handler mHandler = new Handler();
private final NavigationBarView mNavigationBarView;
private final LightBarTransitionsController mLightBarController;
+ private int mNavBarMode = NAV_BAR_MODE_3BUTTON;
private final CompositionSamplingListener mSamplingListener;
private final Runnable mUpdateSamplingListener = this::updateSamplingListener;
@@ -91,7 +93,7 @@
}
void start() {
- if (!isEnabled(mNavigationBarView.getContext())) {
+ if (!isEnabled(mNavigationBarView.getContext(), mNavBarMode)) {
return;
}
mSamplingEnabled = true;
@@ -178,6 +180,10 @@
}
}
+ public void onNavigationModeChanged(int mode) {
+ mNavBarMode = mode;
+ }
+
void dump(PrintWriter pw) {
pw.println("NavBarTintController:");
pw.println(" navBar isAttached: " + mNavigationBarView.isAttachedToWindow());
@@ -190,8 +196,8 @@
pw.println(" mCurrentMedianLuma: " + mCurrentMedianLuma);
}
- public static boolean isEnabled(Context context) {
+ public static boolean isEnabled(Context context, int navBarMode) {
return context.getDisplayId() == DEFAULT_DISPLAY
- && QuickStepContract.isGesturalMode(context);
+ && QuickStepContract.isGesturalMode(navBarMode);
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java
index 742fdda..e6c3170 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java
@@ -21,6 +21,7 @@
import static android.app.StatusBarManager.WindowType;
import static android.app.StatusBarManager.WindowVisibleState;
import static android.app.StatusBarManager.windowStateToString;
+import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON;
import static com.android.systemui.recents.OverviewProxyService.OverviewProxyListener;
import static com.android.systemui.shared.system.NavigationBarCompat.InteractionType;
@@ -117,7 +118,8 @@
* Fragment containing the NavigationBarFragment. Contains logic for what happens
* on clicks and view states of the nav bar.
*/
-public class NavigationBarFragment extends LifecycleFragment implements Callbacks {
+public class NavigationBarFragment extends LifecycleFragment implements Callbacks,
+ NavigationModeController.ModeChangedListener {
public static final String TAG = "NavigationBar";
private static final boolean DEBUG = false;
@@ -158,6 +160,7 @@
private int mLayoutDirection;
private int mSystemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE;
+ private int mNavBarMode = NAV_BAR_MODE_3BUTTON;
private LightBarController mLightBarController;
private AutoHideController mAutoHideController;
@@ -207,7 +210,7 @@
final ButtonDispatcher backButton = mNavigationBarView.getBackButton();
final boolean useAltBack =
(mNavigationIconHints & StatusBarManager.NAVIGATION_HINT_BACK_ALT) != 0;
- if (QuickStepContract.isGesturalMode(getContext()) && !useAltBack) {
+ if (QuickStepContract.isGesturalMode(mNavBarMode) && !useAltBack) {
// If property was changed to hide/show back button, going home will trigger
// launcher to to change the back button alpha to reflect property change
backButton.setVisibility(View.GONE);
@@ -244,13 +247,15 @@
@Inject
public NavigationBarFragment(AccessibilityManagerWrapper accessibilityManagerWrapper,
DeviceProvisionedController deviceProvisionedController, MetricsLogger metricsLogger,
- AssistManager assistManager, OverviewProxyService overviewProxyService) {
+ AssistManager assistManager, OverviewProxyService overviewProxyService,
+ NavigationModeController navigationModeController) {
mAccessibilityManagerWrapper = accessibilityManagerWrapper;
mDeviceProvisionedController = deviceProvisionedController;
mMetricsLogger = metricsLogger;
mAssistManager = assistManager;
mAssistantAvailable = mAssistManager.getAssistInfoForUser(UserHandle.USER_CURRENT) != null;
mOverviewProxyService = overviewProxyService;
+ mNavBarMode = navigationModeController.addListener(this);
}
// ----- Fragment Lifecycle Callbacks -----
@@ -907,7 +912,7 @@
if (mOverviewProxyService.getProxy() != null) {
try {
mOverviewProxyService.getProxy().onAssistantAvailable(available
- && QuickStepContract.isGesturalMode(getContext()));
+ && QuickStepContract.isGesturalMode(mNavBarMode));
} catch (RemoteException e) {
Log.w(TAG, "Unable to send assistant availability data to launcher");
}
@@ -963,6 +968,11 @@
mNavigationBarView.getBarTransitions().transitionTo(mNavigationBarMode, anim);
}
+ @Override
+ public void onNavigationModeChanged(int mode) {
+ mNavBarMode = mode;
+ }
+
public void disableAnimationsDuringHide(long delay) {
mNavigationBarView.setLayoutTransitionsEnabled(false);
mNavigationBarView.postDelayed(() -> mNavigationBarView.setLayoutTransitionsEnabled(true),
@@ -1019,7 +1029,7 @@
if (Intent.ACTION_SCREEN_ON.equals(action)) {
// Enabled and screen is on, start it again if enabled
- if (NavBarTintController.isEnabled(getContext())) {
+ if (NavBarTintController.isEnabled(getContext(), mNavBarMode)) {
mNavigationBarView.getTintController().start();
}
} else {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarInflaterView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarInflaterView.java
index a522ed1c..404c07b 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarInflaterView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarInflaterView.java
@@ -15,6 +15,7 @@
package com.android.systemui.statusbar.phone;
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
+import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON;
import android.annotation.Nullable;
import android.content.Context;
@@ -49,7 +50,8 @@
import java.util.Objects;
public class NavigationBarInflaterView extends FrameLayout
- implements Tunable, PluginListener<NavBarButtonProvider> {
+ implements Tunable, PluginListener<NavBarButtonProvider>,
+ NavigationModeController.ModeChangedListener {
private static final String TAG = "NavBarInflater";
@@ -102,11 +104,13 @@
private boolean mUsingCustomLayout;
private OverviewProxyService mOverviewProxyService;
+ private int mNavBarMode = NAV_BAR_MODE_3BUTTON;
public NavigationBarInflaterView(Context context, AttributeSet attrs) {
super(context, attrs);
createInflaters();
mOverviewProxyService = Dependency.get(OverviewProxyService.class);
+ mNavBarMode = Dependency.get(NavigationModeController.class).addListener(this);
}
@VisibleForTesting
@@ -138,7 +142,7 @@
}
protected String getDefaultLayout() {
- final int defaultResource = QuickStepContract.isGesturalMode(getContext())
+ final int defaultResource = QuickStepContract.isGesturalMode(mNavBarMode)
? R.string.config_navBarLayoutHandle
: mOverviewProxyService.shouldShowSwipeUpUI()
? R.string.config_navBarLayoutQuickstep
@@ -147,6 +151,12 @@
}
@Override
+ public void onNavigationModeChanged(int mode) {
+ mNavBarMode = mode;
+ onLikelyDefaultLayoutChange();
+ }
+
+ @Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
Dependency.get(TunerService.class).addTunable(this, NAV_BAR_VIEWS, NAV_BAR_LEFT,
@@ -159,6 +169,7 @@
protected void onDetachedFromWindow() {
Dependency.get(TunerService.class).removeTunable(this);
Dependency.get(PluginManager.class).removePluginListener(this);
+ Dependency.get(NavigationModeController.class).removeListener(this);
super.onDetachedFromWindow();
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarTransitions.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarTransitions.java
index 8ff6cc9..4e4a6aec 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarTransitions.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarTransitions.java
@@ -16,6 +16,8 @@
package com.android.systemui.statusbar.phone;
+import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON;
+
import static com.android.systemui.statusbar.phone.NavBarTintController.DEFAULT_COLOR_ADAPT_TRANSITION_TIME;
import static com.android.systemui.statusbar.phone.NavBarTintController.MIN_COLOR_ADAPT_TRANSITION_TIME;
@@ -46,6 +48,7 @@
private boolean mLightsOut;
private boolean mAutoDim;
private View mNavButtons;
+ private int mNavBarMode = NAV_BAR_MODE_3BUTTON;
private final Handler mHandler = Handler.getMain();
private final IWallpaperVisibilityListener mWallpaperVisibilityListener =
@@ -176,9 +179,13 @@
@Override
public int getTintAnimationDuration() {
- if (NavBarTintController.isEnabled(mView.getContext())) {
+ if (NavBarTintController.isEnabled(mView.getContext(), mNavBarMode)) {
return Math.max(DEFAULT_COLOR_ADAPT_TRANSITION_TIME, MIN_COLOR_ADAPT_TRANSITION_TIME);
}
return LightBarTransitionsController.DEFAULT_TINT_ANIMATION_DURATION;
}
+
+ public void onNavigationModeChanged(int mode) {
+ mNavBarMode = mode;
+ }
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
index 411378f..6f1e161 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
@@ -16,8 +16,8 @@
package com.android.systemui.statusbar.phone;
-import static android.content.Intent.ACTION_OVERLAY_CHANGED;
import static android.view.WindowManagerPolicyConstants.NAV_BAR_INVALID;
+import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON;
import static com.android.systemui.shared.system.NavigationBarCompat.FLAG_SHOW_OVERVIEW_BUTTON;
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_NOTIFICATION_PANEL_EXPANDED;
@@ -31,10 +31,7 @@
import android.animation.ValueAnimator;
import android.annotation.DrawableRes;
import android.app.StatusBarManager;
-import android.content.BroadcastReceiver;
import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
import android.content.res.Configuration;
import android.graphics.Canvas;
import android.graphics.Point;
@@ -84,7 +81,8 @@
import java.io.PrintWriter;
import java.util.function.Consumer;
-public class NavigationBarView extends FrameLayout implements PluginListener<NavGesture> {
+public class NavigationBarView extends FrameLayout implements PluginListener<NavGesture>,
+ NavigationModeController.ModeChangedListener {
final static boolean DEBUG = false;
final static String TAG = "StatusBar/NavBarView";
@@ -104,6 +102,7 @@
boolean mLongClickableAccessibilityButton;
int mDisabledFlags = 0;
int mNavigationIconHints = 0;
+ private int mNavBarMode = NAV_BAR_MODE_3BUTTON;
private Rect mHomeButtonBounds = new Rect();
private Rect mBackButtonBounds = new Rect();
@@ -234,13 +233,6 @@
}
};
- private BroadcastReceiver mOverlaysChangedReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- onOverlaysChanged();
- }
- };
-
public NavigationBarView(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -287,7 +279,6 @@
mEdgeBackGestureHandler = new EdgeBackGestureHandler(context, mOverviewProxyService);
mTintController = new NavBarTintController(this, getLightTransitionsController());
-
}
public NavBarTintController getTintController() {
@@ -470,7 +461,7 @@
return;
}
- if (QuickStepContract.isGesturalMode(getContext())) {
+ if (QuickStepContract.isGesturalMode(mNavBarMode)) {
drawable.setRotation(degrees);
return;
}
@@ -578,7 +569,7 @@
mBarTransitions.reapplyDarkIntensity();
- boolean disableHome = QuickStepContract.isGesturalMode(getContext())
+ boolean disableHome = QuickStepContract.isGesturalMode(mNavBarMode)
|| ((mDisabledFlags & View.STATUS_BAR_DISABLE_HOME) != 0);
// TODO(b/113914868): investigation log for disappearing home button
@@ -588,7 +579,7 @@
// Always disable recents when alternate car mode UI is active and for secondary displays.
boolean disableRecent = isRecentsButtonDisabled();
- boolean disableBack = !useAltBack && (QuickStepContract.isGesturalMode(getContext())
+ boolean disableBack = !useAltBack && (QuickStepContract.isGesturalMode(mNavBarMode)
|| ((mDisabledFlags & View.STATUS_BAR_DISABLE_BACK) != 0));
// When screen pinning, don't hide back and home when connected service or back and
@@ -724,7 +715,7 @@
}
public void updateWindowTouchable() {
- boolean touchable = mImeVisible || !QuickStepContract.isGesturalMode(getContext());
+ boolean touchable = mImeVisible || !QuickStepContract.isGesturalMode(mNavBarMode);
setWindowFlag(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, !touchable);
}
@@ -746,16 +737,21 @@
wm.updateViewLayout(navbarView, lp);
}
- private void onOverlaysChanged() {
- mNavigationInflaterView.setNavigationBarLayout(null);
+ @Override
+ public void onNavigationModeChanged(int mode) {
+ mNavBarMode = mode;
+ mBarTransitions.onNavigationModeChanged(mNavBarMode);
+ mEdgeBackGestureHandler.onNavigationModeChanged(mNavBarMode);
+ mRecentsOnboarding.onNavigationModeChanged(mNavBarMode);
// Color adaption is tied with showing home handle, only avaliable if visible
- if (QuickStepContract.isGesturalMode(getContext())) {
+ mTintController.onNavigationModeChanged(mNavBarMode);
+ if (QuickStepContract.isGesturalMode(mNavBarMode)) {
mTintController.start();
} else {
mTintController.stop();
}
- mEdgeBackGestureHandler.onOverlaysChanged();
+ updateWindowTouchable();
}
public void setMenuVisibility(final boolean show) {
@@ -938,7 +934,7 @@
"onMeasure: (%dx%d) old: (%dx%d)", w, h, getMeasuredWidth(), getMeasuredHeight()));
final boolean newVertical = w > 0 && h > w
- && !QuickStepContract.isGesturalMode(getContext());
+ && !QuickStepContract.isGesturalMode(mNavBarMode);
if (newVertical != mIsVertical) {
mIsVertical = newVertical;
if (DEBUG) {
@@ -949,7 +945,7 @@
notifyVerticalChangedListener(newVertical);
}
- if (QuickStepContract.isGesturalMode(getContext())) {
+ if (QuickStepContract.isGesturalMode(mNavBarMode)) {
// Update the nav bar background to match the height of the visible nav bar
int height = mIsVertical
? getResources().getDimensionPixelSize(
@@ -1048,11 +1044,10 @@
onPluginDisconnected(null); // Create default gesture helper
Dependency.get(PluginManager.class).addPluginListener(this,
NavGesture.class, false /* Only one */);
+ int navBarMode = Dependency.get(NavigationModeController.class).addListener(this);
+ onNavigationModeChanged(navBarMode);
setUpSwipeUpOnboarding(isQuickStepSwipeUpEnabled());
- IntentFilter filter = new IntentFilter(ACTION_OVERLAY_CHANGED);
- filter.addDataScheme("package");
- getContext().registerReceiver(mOverlaysChangedReceiver, filter);
mEdgeBackGestureHandler.onNavBarAttached();
updateWindowTouchable();
}
@@ -1061,6 +1056,7 @@
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
Dependency.get(PluginManager.class).removePluginListener(this);
+ Dependency.get(NavigationModeController.class).removeListener(this);
if (mGestureHelper != null) {
mGestureHelper.destroy();
}
@@ -1068,8 +1064,6 @@
for (int i = 0; i < mButtonDispatchers.size(); ++i) {
mButtonDispatchers.valueAt(i).onDestroy();
}
-
- getContext().unregisterReceiver(mOverlaysChangedReceiver);
mEdgeBackGestureHandler.onNavBarDetached();
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationModeController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationModeController.java
new file mode 100644
index 0000000..a00feeb
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationModeController.java
@@ -0,0 +1,146 @@
+/*
+ * Copyright (C) 2019 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.statusbar.phone;
+
+import static android.content.Intent.ACTION_OVERLAY_CHANGED;
+import static android.content.Intent.ACTION_USER_SWITCHED;
+import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.om.IOverlayManager;
+import android.content.pm.PackageManager;
+import android.content.res.ApkAssets;
+import android.os.PatternMatcher;
+import android.os.ServiceManager;
+import android.os.UserHandle;
+import android.util.Log;
+
+import com.android.systemui.Dumpable;
+import com.android.systemui.shared.system.ActivityManagerWrapper;
+
+import java.io.FileDescriptor;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+/**
+ * Controller for tracking the current navigation bar mode.
+ */
+@Singleton
+public class NavigationModeController implements Dumpable {
+
+ private static final String TAG = NavigationModeController.class.getName();
+ private static final boolean DEBUG = true;
+
+ public interface ModeChangedListener {
+ void onNavigationModeChanged(int mode);
+ }
+
+ private final Context mContext;
+ private final IOverlayManager mOverlayManager;
+
+ private int mMode = NAV_BAR_MODE_3BUTTON;
+ private ArrayList<ModeChangedListener> mListeners = new ArrayList<>();
+
+ private BroadcastReceiver mReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ context = getCurrentUserContext();
+ int mode = getCurrentInteractionMode(context);
+ mMode = mode;
+ if (DEBUG) {
+ Log.e(TAG, "ACTION_OVERLAY_CHANGED: mode=" + mMode
+ + " contextUser=" + context.getUserId());
+ dumpAssetPaths(context);
+ }
+
+ for (int i = 0; i < mListeners.size(); i++) {
+ mListeners.get(i).onNavigationModeChanged(mode);
+ }
+ }
+ };
+
+ @Inject
+ public NavigationModeController(Context context) {
+ mContext = context;
+ mOverlayManager = IOverlayManager.Stub.asInterface(
+ ServiceManager.getService(Context.OVERLAY_SERVICE));
+
+ IntentFilter overlayFilter = new IntentFilter(ACTION_OVERLAY_CHANGED);
+ overlayFilter.addDataScheme("package");
+ overlayFilter.addDataSchemeSpecificPart("android", PatternMatcher.PATTERN_LITERAL);
+ mContext.registerReceiverAsUser(mReceiver, UserHandle.ALL, overlayFilter, null, null);
+
+ IntentFilter userFilter = new IntentFilter(ACTION_USER_SWITCHED);
+ mContext.registerReceiverAsUser(mReceiver, UserHandle.ALL, userFilter, null, null);
+
+ mMode = getCurrentInteractionMode(getCurrentUserContext());
+ }
+
+ public int addListener(ModeChangedListener listener) {
+ mListeners.add(listener);
+ return getCurrentInteractionMode(mContext);
+ }
+
+ public void removeListener(ModeChangedListener listener) {
+ mListeners.remove(listener);
+ }
+
+ private int getCurrentInteractionMode(Context context) {
+ int mode = context.getResources().getInteger(
+ com.android.internal.R.integer.config_navBarInteractionMode);
+ return mode;
+ }
+
+ private Context getCurrentUserContext() {
+ int userId = ActivityManagerWrapper.getInstance().getCurrentUserId();
+ if (DEBUG) {
+ Log.d(TAG, "getCurrentUserContext: contextUser=" + mContext.getUserId()
+ + " currentUser=" + userId);
+ }
+ if (mContext.getUserId() == userId) {
+ return mContext;
+ }
+ try {
+ return mContext.createPackageContextAsUser(mContext.getPackageName(),
+ 0 /* flags */, UserHandle.of(userId));
+ } catch (PackageManager.NameNotFoundException e) {
+ // Never happens for the sysui package
+ return null;
+ }
+ }
+
+ @Override
+ public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+ pw.println("NavigationModeController:");
+ pw.println(" mode=" + mMode);
+ dumpAssetPaths(getCurrentUserContext());
+ }
+
+ private void dumpAssetPaths(Context context) {
+ Log.d(TAG, "assetPaths=");
+ ApkAssets[] assets = context.getResources().getAssets().getApkAssets();
+ for (ApkAssets a : assets) {
+ Log.d(TAG, " " + a.getAssetPath());
+ }
+ }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationPrototypeController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationPrototypeController.java
index 47a1054..9988c85 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationPrototypeController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationPrototypeController.java
@@ -16,6 +16,8 @@
package com.android.systemui.statusbar.phone;
+import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL;
+
import android.annotation.IntDef;
import android.content.ComponentCallbacks;
import android.content.Context;
@@ -119,7 +121,7 @@
mListener.onHomeButtonVisibilityChanged(!hideHomeButton());
} else if (path.endsWith(NAV_COLOR_ADAPT_ENABLE_SETTING)) {
mListener.onColorAdaptChanged(
- NavBarTintController.isEnabled(mContext));
+ NavBarTintController.isEnabled(mContext, NAV_BAR_MODE_GESTURAL));
} else if (path.endsWith(SHOW_HOME_HANDLE_SETTING)) {
mListener.onHomeHandleVisiblilityChanged(showHomeHandle());
} else if (path.endsWith(ENABLE_ASSISTANT_GESTURE)) {
@@ -132,7 +134,8 @@
* @return the width for edge swipe
*/
public int getEdgeSensitivityWidth() {
- return QuickStepContract.getEdgeSensitivityWidth(mContext);
+ return mContext.getResources().getDimensionPixelSize(
+ com.android.internal.R.dimen.config_backGestureInset);
}
/**
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java
index cc159b4..002313c 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java
@@ -71,7 +71,7 @@
*/
public class StatusBarKeyguardViewManager implements RemoteInputController.Callback,
StatusBarStateController.StateListener, ConfigurationController.ConfigurationListener,
- NotificationPanelView.PanelExpansionListener {
+ NotificationPanelView.PanelExpansionListener, NavigationModeController.ModeChangedListener {
// When hiding the Keyguard with timing supplied from WindowManager, better be early than late.
private static final long HIDE_TIMING_CORRECTION_MS = - 16 * 3;
@@ -192,10 +192,11 @@
mViewMediatorCallback = callback;
mLockPatternUtils = lockPatternUtils;
mStatusBarWindowController = Dependency.get(StatusBarWindowController.class);
- mGesturalNav = QuickStepContract.isGesturalMode(context);
KeyguardUpdateMonitor.getInstance(context).registerCallback(mUpdateMonitorCallback);
mStatusBarStateController.addCallback(this);
Dependency.get(ConfigurationController.class).addCallback(this);
+ mLastGesturalNav = QuickStepContract.isGesturalMode(
+ Dependency.get(NavigationModeController.class).addListener(this));
mDockManager = SysUiServiceProvider.getComponent(context, DockManager.class);
if (mDockManager != null) {
mDockManager.addListener(mDockEventListener);
@@ -587,8 +588,8 @@
}
@Override
- public void onOverlayChanged() {
- boolean gesturalNav = QuickStepContract.isGesturalMode(mContext);
+ public void onNavigationModeChanged(int mode) {
+ boolean gesturalNav = QuickStepContract.isGesturalMode(mode);
if (gesturalNav != mGesturalNav) {
mGesturalNav = gesturalNav;
updateStates();
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NavigationBarFragmentTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NavigationBarFragmentTest.java
index 3ae57e3..ad9c729 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NavigationBarFragmentTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NavigationBarFragmentTest.java
@@ -214,7 +214,8 @@
deviceProvisionedController,
new MetricsLogger(),
mock(AssistManager.class),
- mOverviewProxyService);
+ mOverviewProxyService,
+ mock(NavigationModeController.class));
}
private class HostCallbacksForExternalDisplay extends