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

Commit 45b6edf9 authored by Ethan Chen's avatar Ethan Chen
Browse files

Detect whether overflow button should be shown based on menu key state

Some devices may have hardware keys but not contain a hardware menu key.
Hardware keys are also able to remapped. The overflow button detection logic
currently does not take that into account. This change allows detects
whether any key is capable of emitting the MENU_ACTION keystroke in
order to determine whether the overflow button should be shown or not.

Change-Id: I8699bd0242560314f8eadc54b187c69c992cf875
parent 4ed6fd0c
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -210,6 +210,11 @@ interface IWindowManager
     */
    boolean hasNavigationBar();

    /**
     * Device can generate KEY_ACTION_MENU keypress
     */
    boolean hasMenuKeyEnabled();

    /**
     * Lock the device immediately with the specified options (can be null).
     */
+23 −23
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.view;

import android.app.AppGlobals;
import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
@@ -220,9 +221,6 @@ public class ViewConfiguration {
    private final int mOverflingDistance;
    private final boolean mFadingMarqueeEnabled;

    private boolean sHasPermanentMenuKey;
    private boolean sHasPermanentMenuKeySet;

    private Context mContext;

    static final SparseArray<ViewConfiguration> sConfigurations =
@@ -292,16 +290,6 @@ public class ViewConfiguration {
        mOverscrollDistance = (int) (sizeAndDensity * OVERSCROLL_DISTANCE + 0.5f);
        mOverflingDistance = (int) (sizeAndDensity * OVERFLING_DISTANCE + 0.5f);

        if (!sHasPermanentMenuKeySet) {
            IWindowManager wm = WindowManagerGlobal.getWindowManagerService();
            try {
                sHasPermanentMenuKey = !wm.hasSystemNavBar() && !wm.hasNavigationBar();
                sHasPermanentMenuKeySet = true;
            } catch (RemoteException ex) {
                sHasPermanentMenuKey = false;
            }
        }

        mFadingMarqueeEnabled = res.getBoolean(
                com.android.internal.R.bool.config_ui_enableFadingMarquee);
        mTouchSlop = res.getDimensionPixelSize(
@@ -682,17 +670,29 @@ public class ViewConfiguration {
     * @return true if a permanent menu key is present, false otherwise.
     */
    public boolean hasPermanentMenuKey() {
        // The action overflow button within app UI can
        // be controlled with a system setting
        int showOverflowButton = Settings.System.getInt(
                mContext.getContentResolver(),
                Settings.System.UI_FORCE_OVERFLOW_BUTTON, 0);
        if (showOverflowButton == 1) {
            // Force overflow button on by reporting that
            // the device has no permanent menu key
        IWindowManager wm = WindowManagerGlobal.getWindowManagerService();
        // Report no menu key if device has soft buttons
        try {
            if (wm.hasSystemNavBar() || wm.hasNavigationBar()) {
                return false;
        } else {
            return sHasPermanentMenuKey;
            }
        } catch (RemoteException ex) {
            // do nothing, continue trying to guess
        }

        // Report no menu key if overflow button is forced to enabled
        ContentResolver res = mContext.getContentResolver();
        boolean forceOverflowButton = Settings.System.getInt(res,
                Settings.System.UI_FORCE_OVERFLOW_BUTTON, 0) == 1;
        if (forceOverflowButton) {
            return false;
        }

        // Report menu key presence based on hardware key rebinding
        try {
            return wm.hasMenuKeyEnabled();
        } catch (RemoteException ex) {
            return true;
        }
    }

+5 −0
Original line number Diff line number Diff line
@@ -1100,6 +1100,11 @@ public interface WindowManagerPolicy {
     */
    public boolean hasNavigationBar();

    /**
     * Specifies whether device can generate KEY_ACTION_MENU keypress
     */
    public boolean hasMenuKeyEnabled();

    /**
     * Lock the device now.
     */
+16 −0
Original line number Diff line number Diff line
@@ -374,6 +374,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    boolean mHasMenuKey;
    boolean mHasAssistKey;
    boolean mHasAppSwitchKey;
    boolean mHasMenuKeyEnabled;

    // The last window we were told about in focusChanged.
    WindowState mFocusedWindow;
@@ -1334,6 +1335,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            boolean keyRebindingEnabled = Settings.System.getInt(resolver,
                    Settings.System.HARDWARE_KEY_REBINDING, 0) == 1;

            mHasMenuKeyEnabled = false;

            if (!keyRebindingEnabled) {
                if (mHasHomeKey) {
                    if (mHasAppSwitchKey) {
@@ -1349,6 +1352,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    } else {
                        mLongPressOnMenuBehavior = KEY_ACTION_SEARCH;
                    }
                    mHasMenuKeyEnabled = true;
                }
                if (mHasAssistKey) {
                    mPressOnAssistBehavior = KEY_ACTION_SEARCH;
@@ -1367,6 +1371,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                        mLongPressOnHomeBehavior = Settings.System.getInt(resolver,
                                Settings.System.KEY_HOME_LONG_PRESS_ACTION, KEY_ACTION_APP_SWITCH);
                    }
                    mHasMenuKeyEnabled = (mLongPressOnHomeBehavior == KEY_ACTION_MENU);
                }
                if (mHasMenuKey) {
                    mPressOnMenuBehavior = Settings.System.getInt(resolver,
@@ -1378,18 +1383,24 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                        mLongPressOnMenuBehavior = Settings.System.getInt(resolver,
                                Settings.System.KEY_MENU_LONG_PRESS_ACTION, KEY_ACTION_SEARCH);
                    }
                    mHasMenuKeyEnabled |= (mPressOnMenuBehavior == KEY_ACTION_MENU) ||
                        (mLongPressOnMenuBehavior == KEY_ACTION_MENU);
                }
                if (mHasAssistKey) {
                    mPressOnAssistBehavior = Settings.System.getInt(resolver,
                            Settings.System.KEY_ASSIST_ACTION, KEY_ACTION_SEARCH);
                    mLongPressOnAssistBehavior = Settings.System.getInt(resolver,
                            Settings.System.KEY_ASSIST_LONG_PRESS_ACTION, KEY_ACTION_VOICE_SEARCH);
                    mHasMenuKeyEnabled |= (mPressOnAssistBehavior == KEY_ACTION_MENU) ||
                        (mLongPressOnAssistBehavior == KEY_ACTION_MENU);
                }
                if (mHasAppSwitchKey) {
                    mPressOnAppSwitchBehavior = Settings.System.getInt(resolver,
                            Settings.System.KEY_APP_SWITCH_ACTION, KEY_ACTION_APP_SWITCH);
                    mLongPressOnAppSwitchBehavior = Settings.System.getInt(resolver,
                            Settings.System.KEY_APP_SWITCH_LONG_PRESS_ACTION, KEY_ACTION_NOTHING);
                    mHasMenuKeyEnabled |= (mPressOnAppSwitchBehavior == KEY_ACTION_MENU) ||
                        (mLongPressOnAppSwitchBehavior == KEY_ACTION_MENU);
                }
            }

@@ -5176,6 +5187,11 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        return mHasNavigationBar;
    }

    @Override
    public boolean hasMenuKeyEnabled() {
        return mHasMenuKeyEnabled;
    }

    @Override
    public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
        mLastInputMethodWindow = ime;
+5 −0
Original line number Diff line number Diff line
@@ -10484,6 +10484,11 @@ public class WindowManagerService extends IWindowManager.Stub
        return mPolicy.hasNavigationBar();
    }

    @Override
    public boolean hasMenuKeyEnabled() {
        return mPolicy.hasMenuKeyEnabled();
    }

    public void lockNow(Bundle options) {
        mPolicy.lockNow(options);
    }
Loading