Skip to content

Commit 0c4ccff

Browse files
committed
Add hasNavigationBar() to the window manager.
It is no longer sufficient to check the value of internal.R.bool.config_showNavigationBar to determine if a navigation bar (separate from the status bar) is shown on a device, because the emulator needs to be able to override this value (now possible by setting qemu.hw.mainkeys to "1" or "0", for navbar or no navbar, respectively). This logic is now contained in PhoneWindowManager, and any clients wishing to know whether the system has a software nav bar should consult the new hasNavigationBar() method. Bug: 5404945 Change-Id: I119d32a8c84b88b2ef46f63244e7f11dc5de0359
1 parent 70ac412 commit 0c4ccff

File tree

8 files changed

+45
-10
lines changed

8 files changed

+45
-10
lines changed

core/java/android/view/IWindowManager.aidl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,4 +224,9 @@ interface IWindowManager
224224
* Block until the given window has been drawn to the screen.
225225
*/
226226
void waitForWindowDrawn(IBinder token, in IRemoteCallback callback);
227+
228+
/**
229+
* Device has a software navigation bar (separate from the status bar).
230+
*/
231+
boolean hasNavigationBar();
227232
}

core/java/android/view/ViewConfiguration.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,7 @@ private ViewConfiguration(Context context) {
292292
if (!sHasPermanentMenuKeySet) {
293293
IWindowManager wm = Display.getWindowManager();
294294
try {
295-
sHasPermanentMenuKey = wm.canStatusBarHide() && !res.getBoolean(
296-
com.android.internal.R.bool.config_showNavigationBar);
295+
sHasPermanentMenuKey = wm.canStatusBarHide() && !wm.hasNavigationBar();
297296
sHasPermanentMenuKeySet = true;
298297
} catch (RemoteException ex) {
299298
sHasPermanentMenuKey = false;

core/java/android/view/WindowManagerPolicy.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,11 @@ interface OnKeyguardExitResult {
10091009
*/
10101010
public int adjustSystemUiVisibilityLw(int visibility);
10111011

1012+
/**
1013+
* Specifies whether there is an on-screen navigation bar separate from the status bar.
1014+
*/
1015+
public boolean hasNavigationBar();
1016+
10121017
/**
10131018
* Print the WindowManagerPolicy's state into the given stream.
10141019
*

packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,15 +295,15 @@ protected View makeStatusBarView() {
295295
mStatusBarView = sb;
296296

297297
try {
298-
boolean showNav = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
298+
boolean showNav = mWindowManager.hasNavigationBar();
299299
if (showNav) {
300300
mNavigationBarView =
301301
(NavigationBarView) View.inflate(context, R.layout.navigation_bar, null);
302302

303303
mNavigationBarView.setDisabledFlags(mDisabled);
304304
}
305-
} catch (Resources.NotFoundException ex) {
306-
// no nav bar for you
305+
} catch (RemoteException ex) {
306+
// no window manager? good luck with that
307307
}
308308

309309
// figure out which pixel-format to use for the status bar.

packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBar.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -444,11 +444,14 @@ protected View makeStatusBarView() {
444444

445445
sb.setHandler(mHandler);
446446

447-
// Sanity-check that someone hasn't set up the config wrong and asked for a navigation bar
448-
// on a tablet that has only the system bar
449-
if (mContext.getResources().getBoolean(
450-
com.android.internal.R.bool.config_showNavigationBar)) {
451-
throw new RuntimeException("Tablet device cannot show navigation bar and system bar");
447+
try {
448+
// Sanity-check that someone hasn't set up the config wrong and asked for a navigation
449+
// bar on a tablet that has only the system bar
450+
if (mWindowManager.hasNavigationBar()) {
451+
throw new RuntimeException(
452+
"Tablet device cannot show navigation bar and system bar");
453+
}
454+
} catch (RemoteException ex) {
452455
}
453456

454457
mBarContents = (ViewGroup) sb.findViewById(R.id.bar_contents);

policy/src/com/android/internal/policy/impl/PhoneWindowManager.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,14 @@ public void setInitialDisplaySize(int width, int height) {
823823

824824
mHasNavigationBar = mContext.getResources().getBoolean(
825825
com.android.internal.R.bool.config_showNavigationBar);
826+
// Allow a system property to override this. Used by the emulator.
827+
// See also hasNavigationBar().
828+
String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
829+
if (! "".equals(navBarOverride)) {
830+
if (navBarOverride.equals("1")) mHasNavigationBar = true;
831+
else if (navBarOverride.equals("0")) mHasNavigationBar = false;
832+
}
833+
826834
mNavigationBarHeight = mHasNavigationBar
827835
? mContext.getResources().getDimensionPixelSize(
828836
com.android.internal.R.dimen.navigation_bar_height)
@@ -3725,6 +3733,12 @@ public void run() {
37253733
return diff;
37263734
}
37273735

3736+
// Use this instead of checking config_showNavigationBar so that it can be consistently
3737+
// overridden by qemu.hw.mainkeys in the emulator.
3738+
public boolean hasNavigationBar() {
3739+
return mHasNavigationBar;
3740+
}
3741+
37283742
public void dump(String prefix, FileDescriptor fd, PrintWriter pw, String[] args) {
37293743
pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
37303744
pw.print(" mSystemReady="); pw.print(mSystemReady);

services/java/com/android/server/wm/WindowManagerService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9263,6 +9263,11 @@ boolean removeFakeWindowLocked(FakeWindow window) {
92639263
}
92649264
}
92659265

9266+
@Override
9267+
public boolean hasNavigationBar() {
9268+
return mPolicy.hasNavigationBar();
9269+
}
9270+
92669271
void dumpInput(FileDescriptor fd, PrintWriter pw, boolean dumpAll) {
92679272
pw.println("WINDOW MANAGER INPUT (dumpsys window input)");
92689273
mInputManager.dump(pw);

tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeWindowManager.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,4 +467,8 @@ public int getPreferredOptionsPanelGravity() throws RemoteException {
467467

468468
public void dismissKeyguard() {
469469
}
470+
471+
public boolean hasNavigationBar() {
472+
return false; // should this return something else?
473+
}
470474
}

0 commit comments

Comments
 (0)