Skip to content

Commit

Permalink
Always show status bars in full screen in automotive
Browse files Browse the repository at this point in the history
Some OEMs like Volvo and Polestar do not respect the flags we set to
hide the status bars in full screen mode. As a result, status bars are
drawn over the content, rendering some critical areas unclickable.

Volvo: https://hsv.googleplex.com/4734281294282752
Generic auto device: https://hsv.googleplex.com/5018858311122944

Note: with the refactor slated for crbug/1449311, showing the system
bars in full screen in automotive devices may be possible

Change-Id: I65986ff3627920aa9f33ff38519143dc1cdf1aa9
Fixed: b/284213593, b/284205285, b/284212069, b/283871513
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4569720
Commit-Queue: Geoff Huang <geoffhuang@google.com>
Reviewed-by: Theresa Sullivan <twellington@chromium.org>
Code-Coverage: Findit <findit-for-me@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/heads/main@{#1150425}
  • Loading branch information
Geoff Huang authored and Chromium LUCI CQ committed May 30, 2023
1 parent 20707da commit 15dba28
Showing 1 changed file with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import static android.view.View.SYSTEM_UI_FLAG_FULLSCREEN;
import static android.view.View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
import static android.view.View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
import static android.view.View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
import static android.view.View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
import static android.view.View.SYSTEM_UI_FLAG_LOW_PROFILE;
Expand All @@ -26,6 +27,7 @@
import org.chromium.base.ApplicationStatus;
import org.chromium.base.ApplicationStatus.ActivityStateListener;
import org.chromium.base.ApplicationStatus.WindowFocusChangedListener;
import org.chromium.base.BuildInfo;
import org.chromium.base.Log;
import org.chromium.base.ObserverList;
import org.chromium.base.supplier.ObservableSupplier;
Expand Down Expand Up @@ -115,8 +117,8 @@ private static class FullscreenHandler extends Handler {
private final WeakReference<FullscreenHtmlApiHandler> mFullscreenHtmlApiHandler;

public FullscreenHandler(FullscreenHtmlApiHandler fullscreenHtmlApiHandler) {
mFullscreenHtmlApiHandler = new WeakReference<FullscreenHtmlApiHandler>(
fullscreenHtmlApiHandler);
mFullscreenHtmlApiHandler =
new WeakReference<FullscreenHtmlApiHandler>(fullscreenHtmlApiHandler);
}

@Override
Expand Down Expand Up @@ -147,7 +149,7 @@ public void handleMessage(Message msg) {
"handleMessage set flags, systemUiVisibility="
+ systemUiVisibility);
}
contentView.setSystemUiVisibility(systemUiVisibility);
setSystemUiVisibility(contentView, systemUiVisibility);
}

if ((systemUiVisibility & SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) == 0) {
Expand All @@ -161,9 +163,8 @@ public void handleMessage(Message msg) {
// renderer.
contentView.addOnLayoutChangeListener(new OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right,
int bottom, int oldLeft, int oldTop, int oldRight,
int oldBottom) {
public void onLayoutChange(View v, int left, int top, int right, int bottom,
int oldLeft, int oldTop, int oldRight, int oldBottom) {
sendEmptyMessageDelayed(MSG_ID_CLEAR_LAYOUT_FULLSCREEN_FLAG,
CLEAR_LAYOUT_FULLSCREEN_DELAY_MS);
contentView.removeOnLayoutChangeListener(this);
Expand All @@ -187,7 +188,7 @@ public void onLayoutChange(View v, int left, int top, int right,
"handleMessage clear fullscreen flag, systemUiVisibility="
+ systemUiVisibility);
}
contentView.setSystemUiVisibility(systemUiVisibility);
setSystemUiVisibility(contentView, systemUiVisibility);
fullscreenHtmlApiHandler.clearWindowFlags(
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
break;
Expand Down Expand Up @@ -469,7 +470,7 @@ private void exitFullscreen(WebContents webContents, View contentView, Tab tab)
systemUiVisibility = applyExitFullscreenUIFlags(systemUiVisibility);
clearWindowFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
if (DEBUG_LOGS) Log.i(TAG, "exitFullscreen, systemUiVisibility=" + systemUiVisibility);
contentView.setSystemUiVisibility(systemUiVisibility);
setSystemUiVisibility(contentView, systemUiVisibility);
if (mFullscreenOnLayoutChangeListener != null) {
contentView.removeOnLayoutChangeListener(mFullscreenOnLayoutChangeListener);
}
Expand Down Expand Up @@ -551,10 +552,11 @@ public void enterFullscreen(final Tab tab, FullscreenOptions options) {

// To avoid a double layout that is caused by the system when just hiding
// the status bar set the status bar as translucent immediately. This causes
// it not to take up space so the layout is stable. (See https://crbug.com/935015). Do
// not do this in multi-window mode since that mode forces the status bar
// to always be visible.
if (!mFullscreenOptions.showStatusBar && !isMultiWindow) {
// it not to take up space so the layout is stable. (See https://crbug.com/935015).
// Do not do this in multi-window mode or automotive devices since the status bar is
// forced to always be visible.
if (!mFullscreenOptions.showStatusBar && !isMultiWindow
&& !BuildInfo.getInstance().isAutomotive) {
setWindowFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}

Expand Down Expand Up @@ -594,7 +596,7 @@ public void onLayoutChange(View v, int left, int top, int right, int bottom,

contentView.addOnLayoutChangeListener(mFullscreenOnLayoutChangeListener);
if (DEBUG_LOGS) Log.i(TAG, "enterFullscreen, systemUiVisibility=" + systemUiVisibility);
contentView.setSystemUiVisibility(systemUiVisibility);
setSystemUiVisibility(contentView, systemUiVisibility);

// Request a layout so the updated system visibility takes affect.
// The flow will continue in the handler of MSG_ID_SET_FULLSCREEN_SYSTEM_UI_FLAGS message.
Expand Down Expand Up @@ -657,7 +659,7 @@ private int applyEnterFullscreenUIFlags(int systemUiVisibility) {
boolean showStatusBar =
mFullscreenOptions != null ? mFullscreenOptions.showStatusBar : false;

int flags = View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
int flags = SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
if (!showStatusBar && !showNavigationBar) {
flags |= SYSTEM_UI_FLAG_LOW_PROFILE;
}
Expand All @@ -682,9 +684,8 @@ private int applyEnterFullscreenUIFlags(int systemUiVisibility) {
*/
private static int applyExitFullscreenUIFlags(int systemUiVisibility) {
int maskOffFlags = SYSTEM_UI_FLAG_LOW_PROFILE | SYSTEM_UI_FLAG_FULLSCREEN
| SYSTEM_UI_FLAG_HIDE_NAVIGATION;
maskOffFlags |= SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
maskOffFlags |= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
| SYSTEM_UI_FLAG_HIDE_NAVIGATION | SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | SYSTEM_UI_FLAG_IMMERSIVE_STICKY;

return systemUiVisibility & ~maskOffFlags;
}
Expand Down Expand Up @@ -753,4 +754,10 @@ void setVersionCompatForTesting(DimensionCompat compat) {
void triggerWindowLayoutChangeForTesting() {
((CustomViewToast) getToast()).triggerWindowLayoutForTesting();
}

private static void setSystemUiVisibility(View contentView, int systemUiVisibility) {
if (!BuildInfo.getInstance().isAutomotive) {
contentView.setSystemUiVisibility(systemUiVisibility);
}
}
}

0 comments on commit 15dba28

Please sign in to comment.