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

Commit 6a201acd authored by Shawn Lin's avatar Shawn Lin Committed by Android (Google) Code Review
Browse files

Merge "Support the ability to force-show navigation for GKS"

parents c271def0 e4c6ca77
Loading
Loading
Loading
Loading
+83 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.internal.policy;

import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
import android.os.Handler;
import android.os.UserHandle;
import android.provider.Settings;

/**
 * A ContentObserver for listening force show navigation bar relative setting keys:
 *  - {@link Settings.Secure#NAVIGATION_MODE}
 *  - {@link Settings.Secure#NAV_BAR_KIDS_MODE}
 *
 * @hide
 */
public class ForceShowNavigationBarSettingsObserver extends ContentObserver {
    private Context mContext;
    private Runnable mOnChangeRunnable;

    public ForceShowNavigationBarSettingsObserver(Handler handler, Context context) {
        super(handler);
        mContext = context;
    }

    public void setOnChangeRunnable(Runnable r) {
        mOnChangeRunnable = r;
    }

    /**
     * Registers the observer.
     */
    public void register() {
        final ContentResolver r = mContext.getContentResolver();
        r.registerContentObserver(
                Settings.Secure.getUriFor(Settings.Secure.NAVIGATION_MODE),
                false, this, UserHandle.USER_ALL);
        r.registerContentObserver(
                Settings.Secure.getUriFor(Settings.Secure.NAV_BAR_KIDS_MODE),
                false, this, UserHandle.USER_ALL);
    }

    /**
     * Unregisters the observer.
     */
    public void unregister() {
        mContext.getContentResolver().unregisterContentObserver(this);
    }

    @Override
    public void onChange(boolean selfChange) {
        if (mOnChangeRunnable != null) {
            mOnChangeRunnable.run();
        }
    }

    /**
     * Returns true only when it's in three button nav mode and the kid nav bar mode is enabled.
     * Otherwise, return false.
     */
    public boolean isEnabled() {
        return Settings.Secure.getIntForUser(mContext.getContentResolver(),
                Settings.Secure.NAVIGATION_MODE, 0, UserHandle.USER_CURRENT) == 0
                && Settings.Secure.getIntForUser(mContext.getContentResolver(),
                Settings.Secure.NAV_BAR_KIDS_MODE, 0, UserHandle.USER_CURRENT) == 1;
    }
}
+23 −0
Original line number Diff line number Diff line
@@ -139,6 +139,7 @@ import android.view.accessibility.AccessibilityManager;

import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.policy.ForceShowNavigationBarSettingsObserver;
import com.android.internal.policy.GestureNavigationSettingsObserver;
import com.android.internal.policy.ScreenDecorationsUtils;
import com.android.internal.policy.SystemBarUtils;
@@ -381,6 +382,9 @@ public class DisplayPolicy {

    private final WindowManagerInternal.AppTransitionListener mAppTransitionListener;

    private final ForceShowNavigationBarSettingsObserver mForceShowNavigationBarSettingsObserver;
    private boolean mForceShowNavigationBarEnabled;

    private class PolicyHandler extends Handler {

        PolicyHandler(Looper looper) {
@@ -652,6 +656,18 @@ public class DisplayPolicy {
            }
        });
        mHandler.post(mGestureNavigationSettingsObserver::register);

        mForceShowNavigationBarSettingsObserver = new ForceShowNavigationBarSettingsObserver(
                mHandler, mContext);
        mForceShowNavigationBarSettingsObserver.setOnChangeRunnable(() -> {
            synchronized (mLock) {
                mForceShowNavigationBarEnabled =
                        mForceShowNavigationBarSettingsObserver.isEnabled();
                updateSystemBarAttributes();
            }
        });
        mForceShowNavigationBarEnabled = mForceShowNavigationBarSettingsObserver.isEnabled();
        mHandler.post(mForceShowNavigationBarSettingsObserver::register);
    }

    /**
@@ -791,6 +807,10 @@ public class DisplayPolicy {
        return mWindowManagerDrawComplete;
    }

    public boolean isForceShowNavigationBarEnabled() {
        return mForceShowNavigationBarEnabled;
    }

    public ScreenOnListener getScreenOnListener() {
        return mScreenOnListener;
    }
@@ -2755,6 +2775,8 @@ public class DisplayPolicy {
        }
        pw.print(prefix); pw.print("mTopIsFullscreen="); pw.println(mTopIsFullscreen);
        pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
        pw.print(prefix); pw.print("mForceShowNavigationBarEnabled=");
        pw.print(mForceShowNavigationBarEnabled);
        pw.print(" mAllowLockscreenWhenOn="); pw.println(mAllowLockscreenWhenOn);
        pw.print(prefix); pw.print("mRemoteInsetsControllerControlsSystemBars=");
        pw.println(mDisplayContent.getInsetsPolicy().getRemoteInsetsControllerControlsSystemBars());
@@ -2832,6 +2854,7 @@ public class DisplayPolicy {
    void release() {
        mDisplayContent.mTransitionController.unregisterLegacyListener(mAppTransitionListener);
        mHandler.post(mGestureNavigationSettingsObserver::unregister);
        mHandler.post(mForceShowNavigationBarSettingsObserver::unregister);
        mImmersiveModeConfirmation.release();
    }

+9 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.server.wm;

import static android.app.StatusBarManager.WINDOW_STATE_HIDDEN;
import static android.app.StatusBarManager.WINDOW_STATE_SHOWING;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
import static android.view.InsetsController.ANIMATION_TYPE_HIDE;
import static android.view.InsetsController.ANIMATION_TYPE_SHOW;
import static android.view.InsetsController.LAYOUT_INSETS_DURING_ANIMATION_HIDDEN;
@@ -450,6 +451,14 @@ class InsetsPolicy {
            // Notification shade has control anyways, no reason to force anything.
            return focusedWin;
        }
        if (mPolicy.isForceShowNavigationBarEnabled()
                && focusedWin.getActivityType() == ACTIVITY_TYPE_STANDARD) {
            // When "force show navigation bar" is enabled, it means we are in kid navigation bar
            // and 3-button navigation bar mode. In this mode, the navigation bar is forcibly shown
            // when activity type is ACTIVITY_TYPE_STANDARD which means Launcher or Recent could
            // still control the navigation bar in this mode.
            return null;
        }
        if (remoteInsetsControllerControlsSystemBars(focusedWin)) {
            mDisplayContent.mRemoteInsetsControlTarget.topFocusedWindowChanged(
                    focusedWin.mAttrs.packageName);