diff options
| author | 2019-04-25 06:14:57 +0000 | |
|---|---|---|
| committer | 2019-04-25 06:14:57 +0000 | |
| commit | 05500a36514fecdb15374ccf3839adda4a2c024b (patch) | |
| tree | 52bc707481f7e14843244d791289d3f5faae5bbe | |
| parent | 671a62fffbe02f2717a7e59c40989745af08718b (diff) | |
| parent | 1aa24b9b5e9ea80016de60c40afe0ebb61c2ce84 (diff) | |
Merge "Ensure we get the right nav bar mode for the current user in sysui" into qt-dev
14 files changed, 256 insertions, 114 deletions
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 3e70badaa78c..b89b9ef3cad7 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_3BUTTON; 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; @@ -95,13 +94,6 @@ public class QuickStepContract { } /** - * @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) { @@ -109,13 +101,6 @@ public class QuickStepContract { } /** - * @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) { @@ -123,37 +108,6 @@ public class QuickStepContract { } /** - * @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 4b338f79e9c6..1feb63d884fd 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.KeyguardDismissUtil; 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 @@ public class Dependency extends SystemUI { @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 @@ public class Dependency extends SystemUI { 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 ee729555747c..3ace7050c743 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.content.pm.PackageManager.MATCH_SYSTEM_ONLY; 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; @@ -70,6 +71,7 @@ import com.android.systemui.shared.system.QuickStepContract.SystemUiStateFlags; 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; @@ -87,7 +89,8 @@ import javax.inject.Singleton; * 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"; @@ -124,6 +127,7 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis private MotionEvent mStatusBarGestureDownEvent; private float mWindowCornerRadius; private boolean mSupportsRoundedCornersOnWindows; + private int mNavBarMode = NAV_BAR_MODE_3BUTTON; private ISystemUiProxy mSysUiProxy = new ISystemUiProxy.Stub() { @@ -427,16 +431,6 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis 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()) { @@ -474,6 +468,8 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis // 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(); @@ -483,6 +479,7 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis filter.addDataSchemeSpecificPart(mRecentsComponentName.getPackageName(), PatternMatcher.PATTERN_LITERAL); filter.addAction(Intent.ACTION_PACKAGE_CHANGED); + // TODO: Shouldn't this be per-user? mContext.registerReceiver(mLauncherStateChangedReceiver, filter); } } @@ -678,7 +675,7 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis 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; } @@ -736,6 +733,11 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis } @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); @@ -747,8 +749,6 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis 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 33a2acfe9521..d0c47345a83a 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 @@ package com.android.systemui.recents; 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 @@ public class RecentsOnboarding { 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 @@ public class RecentsOnboarding { } 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 a964849864d2..9b3f05e3e8d3 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 @@ public class EdgeBackGestureHandler implements DisplayListener { 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 class EdgeBackGestureHandler implements DisplayListener { */ public void onNavBarAttached() { mIsAttached = true; - onOverlaysChanged(); + updateIsEnabled(); } /** @@ -179,11 +181,8 @@ public class EdgeBackGestureHandler implements DisplayListener { 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 bf5b60a9437b..2f245fff1824 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 @@ public class NavBarTintController implements View.OnAttachStateChangeListener, 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 @@ public class NavBarTintController implements View.OnAttachStateChangeListener, } void start() { - if (!isEnabled(mNavigationBarView.getContext())) { + if (!isEnabled(mNavigationBarView.getContext(), mNavBarMode)) { return; } mSamplingEnabled = true; @@ -178,6 +180,10 @@ public class NavBarTintController implements View.OnAttachStateChangeListener, } } + public void onNavigationModeChanged(int mode) { + mNavBarMode = mode; + } + void dump(PrintWriter pw) { pw.println("NavBarTintController:"); pw.println(" navBar isAttached: " + mNavigationBarView.isAttachedToWindow()); @@ -190,8 +196,8 @@ public class NavBarTintController implements View.OnAttachStateChangeListener, 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 c96c6d7237b1..de57066d80ba 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.WINDOW_STATE_SHOWING; 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; @@ -119,7 +120,8 @@ import javax.inject.Inject; * 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; @@ -160,6 +162,7 @@ public class NavigationBarFragment extends LifecycleFragment implements Callback private int mLayoutDirection; private int mSystemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE; + private int mNavBarMode = NAV_BAR_MODE_3BUTTON; private LightBarController mLightBarController; private AutoHideController mAutoHideController; @@ -209,7 +212,7 @@ public class NavigationBarFragment extends LifecycleFragment implements Callback 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); @@ -246,13 +249,15 @@ public class NavigationBarFragment extends LifecycleFragment implements Callback @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 ----- @@ -928,7 +933,7 @@ public class NavigationBarFragment extends LifecycleFragment implements Callback 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"); } @@ -984,6 +989,11 @@ public class NavigationBarFragment extends LifecycleFragment implements Callback 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), @@ -1040,7 +1050,7 @@ public class NavigationBarFragment extends LifecycleFragment implements Callback 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 a522ed1ced74..404c07b807e5 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.List; 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 @@ public class NavigationBarInflaterView extends FrameLayout 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 @@ public class NavigationBarInflaterView extends FrameLayout } 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 @@ public class NavigationBarInflaterView extends FrameLayout } @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 @@ public class NavigationBarInflaterView extends FrameLayout 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 8ff6cc9b3d93..4e4a6aec57b5 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 @@ public final class NavigationBarTransitions extends BarTransitions implements 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 @@ public final class NavigationBarTransitions extends BarTransitions implements @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 411378f1bf07..6f1e161cf237 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.TimeInterpolator; 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.FileDescriptor; 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 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav 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 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav } }; - 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 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav mEdgeBackGestureHandler = new EdgeBackGestureHandler(context, mOverviewProxyService); mTintController = new NavBarTintController(this, getLightTransitionsController()); - } public NavBarTintController getTintController() { @@ -470,7 +461,7 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav return; } - if (QuickStepContract.isGesturalMode(getContext())) { + if (QuickStepContract.isGesturalMode(mNavBarMode)) { drawable.setRotation(degrees); return; } @@ -578,7 +569,7 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav 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 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav // 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 class NavigationBarView extends FrameLayout implements PluginListener<Nav } 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 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav 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 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav "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 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav 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 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav 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 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav 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 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav 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 000000000000..a00feeb6c116 --- /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 47a10547688b..9988c85361bb 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 @@ public class NavigationPrototypeController extends ContentObserver implements Co 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 @@ public class NavigationPrototypeController extends ContentObserver implements Co * @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 cc159b4aaea5..002313c227c6 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 @@ import java.util.ArrayList; */ 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 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb 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 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb } @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 3ae57e391005..ad9c7299f8ed 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 @@ public class NavigationBarFragmentTest extends SysuiBaseFragmentTest { deviceProvisionedController, new MetricsLogger(), mock(AssistManager.class), - mOverviewProxyService); + mOverviewProxyService, + mock(NavigationModeController.class)); } private class HostCallbacksForExternalDisplay extends |