Support the ability to force-show navigation for GKS

GKS requested to force show nav bar except for Launcher apps.

Returns null in InsetsPolicy.getNavControlTarget() to forcibly
show the nav bar when:
  - The feature is enabled.
  - The activity type of the focus window is ACTIVITY_TYPE_STANDARD.

Bug: 161689887
Test: manual:
      1. adb shell settings put secure "nav_bar_kids_mode" "1"
      2. choose 3-buttons navigation mode in
         Settings>System>Gestures>System navigation
      2. open an app that hides nav bar and check if the nav bar is
         still visible.
Change-Id: I7679da7d8b0892317d04cdc3553fe9a8fcdb2292
This commit is contained in:
shawnlin
2022-01-26 13:15:40 +08:00
parent 1bad646ddd
commit e4c6ca77c9
3 changed files with 115 additions and 0 deletions

View File

@@ -0,0 +1,83 @@
/*
* 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;
}
}

View File

@@ -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();
}

View File

@@ -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;
@@ -424,6 +425,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);