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

Commit 9701d6b4 authored by Vinit Nayak's avatar Vinit Nayak
Browse files

Cache call to WM#hasNavigationBar

Bug: 307714378
Test: Added logs to ensure first time call to
WM is made and subsequent ones hit cache.
Tested on foldable.
Flag: None

Change-Id: I41b3e0df3e78bba2cccaa7fc1c2a4aaee116618d
parent 1e03b984
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.os.UserHandle;
import android.provider.Settings;
import android.util.Log;
import android.util.SparseArray;
import android.util.SparseBooleanArray;
import android.view.Display;
import android.view.IWindowManager;
import android.view.View;
@@ -94,6 +95,9 @@ public class NavigationBarControllerImpl implements
    @VisibleForTesting
    SparseArray<NavigationBar> mNavigationBars = new SparseArray<>();

    /** Local cache for {@link IWindowManager#hasNavigationBar(int)}. */
    private SparseBooleanArray mHasNavBar = new SparseBooleanArray();

    // Tracks config changes that will actually recreate the nav bar
    private final InterestingConfigChanges mConfigChanges = new InterestingConfigChanges(
            ActivityInfo.CONFIG_FONT_SCALE
@@ -221,10 +225,16 @@ public class NavigationBarControllerImpl implements
    }

    private boolean shouldCreateNavBarAndTaskBar(int displayId) {
        if (mHasNavBar.indexOfKey(displayId) > -1) {
            return mHasNavBar.get(displayId);
        }

        final IWindowManager wms = WindowManagerGlobal.getWindowManagerService();

        try {
            return wms.hasNavigationBar(displayId);
            boolean hasNavigationBar = wms.hasNavigationBar(displayId);
            mHasNavBar.put(displayId, hasNavigationBar);
            return hasNavigationBar;
        } catch (RemoteException e) {
            // Cannot get wms, just return false with warning message.
            Log.w(TAG, "Cannot get WindowManager.");