Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e5298681 authored by Winson Chung's avatar Winson Chung Committed by android-build-merger
Browse files

Merge "Ensure we get the right nav bar mode for the current user in the system" into qt-dev

am: fdd2a8d5

Change-Id: Ic213c4c42d696c59286d8b7dfc94602c81520dbe
parents cf99104e fdd2a8d5
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -2462,6 +2462,7 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
    void switchUser() {
        super.switchUser();
        mWmService.mWindowsChanged = true;
        mDisplayPolicy.switchUser();
    }

    private void resetAnimationBackgroundAnimator() {
+51 −5
Original line number Diff line number Diff line
@@ -112,7 +112,10 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Px;
import android.app.ActivityManager;
import android.app.ActivityManagerInternal;
import android.app.ActivityThread;
import android.app.LoadedApk;
import android.app.ResourcesManager;
import android.app.StatusBarManager;
import android.content.Context;
import android.content.Intent;
@@ -210,6 +213,8 @@ public class DisplayPolicy {
    private final Object mLock;
    private final Handler mHandler;

    private Resources mCurrentUserResources;

    private final boolean mCarDockEnablesAccelerometer;
    private final boolean mDeskDockEnablesAccelerometer;
    private final AccessibilityManager mAccessibilityManager;
@@ -2603,10 +2608,18 @@ public class DisplayPolicy {
                || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
    }

    /**
     * Called when the user is switched.
     */
    public void switchUser() {
        updateCurrentUserResources();
    }

    /**
     * Called when the resource overlays change.
     */
    public void onOverlayChangedLw() {
        updateCurrentUserResources();
        onConfigurationChanged();
        mSystemGestures.onConfigurationChanged();
    }
@@ -2617,8 +2630,7 @@ public class DisplayPolicy {
    public void onConfigurationChanged() {
        final DisplayRotation displayRotation = mDisplayContent.getDisplayRotation();

        final Context uiContext = getSystemUiContext();
        final Resources res = uiContext.getResources();
        final Resources res = getCurrentUserResources();
        final int portraitRotation = displayRotation.getPortraitRotation();
        final int upsideDownRotation = displayRotation.getUpsideDownRotation();
        final int landscapeRotation = displayRotation.getLandscapeRotation();
@@ -2693,15 +2705,49 @@ public class DisplayPolicy {
    }

    void updateConfigurationAndScreenSizeDependentBehaviors() {
        final Context uiContext = getSystemUiContext();
        final Resources res = uiContext.getResources();
        final Resources res = getCurrentUserResources();
        mNavigationBarCanMove =
                mDisplayContent.mBaseDisplayWidth != mDisplayContent.mBaseDisplayHeight
                        && res.getBoolean(R.bool.config_navBarCanMove);
    }

    /**
     * Updates the current user's resources to pick up any changes for the current user (including
     * overlay paths)
     */
    private void updateCurrentUserResources() {
        final int userId = mService.mAmInternal.getCurrentUserId();
        final Context uiContext = getSystemUiContext();
        final LoadedApk pi = ActivityThread.currentActivityThread().getPackageInfo(
                uiContext.getPackageName(), null, 0, userId);

        // Create the resources from the current-user package info
        // (see ContextImpl.createDisplayContext)
        mCurrentUserResources = ResourcesManager.getInstance().getResources(null,
                pi.getResDir(),
                null /* splitResDirs */,
                pi.getOverlayDirs(),
                pi.getApplicationInfo().sharedLibraryFiles,
                mDisplayContent.getDisplayId(),
                null /* overrideConfig */,
                uiContext.getResources().getCompatibilityInfo(),
                null /* classLoader */);
    }

    @VisibleForTesting
    Context getSystemUiContext() {
    Resources getCurrentUserResources() {
        if (mCurrentUserResources == null) {
            updateCurrentUserResources();
        }
        return mCurrentUserResources;
    }

    @VisibleForTesting
    Context getContext() {
        return mContext;
    }

    private Context getSystemUiContext() {
        final Context uiContext = ActivityThread.currentActivityThread().getSystemUiContext();
        return mDisplayContent.isDefaultDisplay
                ? uiContext : uiContext.createDisplayContext(mDisplayContent.getDisplay());
+5 −5
Original line number Diff line number Diff line
@@ -69,15 +69,15 @@ public class DisplayPolicyTestsBase extends WindowTestsBase {
    public void setUpDisplayPolicy() {
        mDisplayPolicy = spy(mDisplayContent.getDisplayPolicy());

        final TestContextWrapper context =
                new TestContextWrapper(mDisplayPolicy.getSystemUiContext());
        final TestContextWrapper context = new TestContextWrapper(
                mDisplayPolicy.getContext(), mDisplayPolicy.getCurrentUserResources());
        final TestableResources resources = context.getResourceMocker();
        resources.addOverride(R.dimen.status_bar_height_portrait, STATUS_BAR_HEIGHT);
        resources.addOverride(R.dimen.status_bar_height_landscape, STATUS_BAR_HEIGHT);
        resources.addOverride(R.dimen.navigation_bar_height, NAV_BAR_HEIGHT);
        resources.addOverride(R.dimen.navigation_bar_height_landscape, NAV_BAR_HEIGHT);
        resources.addOverride(R.dimen.navigation_bar_width, NAV_BAR_HEIGHT);
        doReturn(context).when(mDisplayPolicy).getSystemUiContext();
        doReturn(resources.getResources()).when(mDisplayPolicy).getCurrentUserResources();
        doReturn(true).when(mDisplayPolicy).hasNavigationBar();
        doReturn(true).when(mDisplayPolicy).hasStatusBar();

@@ -157,9 +157,9 @@ public class DisplayPolicyTestsBase extends WindowTestsBase {
    static class TestContextWrapper extends ContextWrapper {
        private final TestableResources mResourceMocker;

        TestContextWrapper(Context targetContext) {
        TestContextWrapper(Context targetContext, Resources targetResources) {
            super(targetContext);
            mResourceMocker = new TestableResources(targetContext.getResources());
            mResourceMocker = new TestableResources(targetResources);
        }

        @Override