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

Commit 2c570c17 authored by Steve Elliott's avatar Steve Elliott Committed by Android (Google) Code Review
Browse files

Merge "Power key behavior tweaks." into qt-dev

parents d6aa4d3e b458f4ee
Loading
Loading
Loading
Loading
+25 −0
Original line number Original line Diff line number Diff line
@@ -13569,6 +13569,28 @@ public final class Settings {
        private static final Validator AWARE_ALLOWED_VALIDATOR = BOOLEAN_VALIDATOR;
        private static final Validator AWARE_ALLOWED_VALIDATOR = BOOLEAN_VALIDATOR;
        /**
         * Overrides internal R.integer.config_longPressOnPowerBehavior.
         * Allowable values detailed in frameworks/base/core/res/res/values/config.xml.
         * Used by PhoneWindowManager.
         * @hide
         */
        public static final String POWER_BUTTON_LONG_PRESS =
                "power_button_long_press";
        private static final Validator POWER_BUTTON_LONG_PRESS_VALIDATOR =
                new SettingsValidators.InclusiveIntegerRangeValidator(0, 5);
        /**
         * Overrides internal R.integer.config_veryLongPressOnPowerBehavior.
         * Allowable values detailed in frameworks/base/core/res/res/values/config.xml.
         * Used by PhoneWindowManager.
         * @hide
         */
        public static final String POWER_BUTTON_VERY_LONG_PRESS =
                "power_button_very_long_press";
        private static final Validator POWER_BUTTON_VERY_LONG_PRESS_VALIDATOR =
                new SettingsValidators.InclusiveIntegerRangeValidator(0, 1);
        /**
        /**
         * Settings to backup. This is here so that it's in the same place as the settings
         * Settings to backup. This is here so that it's in the same place as the settings
         * keys and easy to update.
         * keys and easy to update.
@@ -13682,6 +13704,8 @@ public final class Settings {
                    WIFI_PNO_RECENCY_SORTING_ENABLED_VALIDATOR);
                    WIFI_PNO_RECENCY_SORTING_ENABLED_VALIDATOR);
            VALIDATORS.put(WIFI_LINK_PROBING_ENABLED, WIFI_LINK_PROBING_ENABLED_VALIDATOR);
            VALIDATORS.put(WIFI_LINK_PROBING_ENABLED, WIFI_LINK_PROBING_ENABLED_VALIDATOR);
            VALIDATORS.put(AWARE_ALLOWED, AWARE_ALLOWED_VALIDATOR);
            VALIDATORS.put(AWARE_ALLOWED, AWARE_ALLOWED_VALIDATOR);
            VALIDATORS.put(POWER_BUTTON_LONG_PRESS, POWER_BUTTON_LONG_PRESS_VALIDATOR);
            VALIDATORS.put(POWER_BUTTON_VERY_LONG_PRESS, POWER_BUTTON_VERY_LONG_PRESS_VALIDATOR);
        }
        }
        /**
        /**
@@ -14687,6 +14711,7 @@ public final class Settings {
         */
         */
        public static final String TEXT_CLASSIFIER_ACTION_MODEL_PARAMS =
        public static final String TEXT_CLASSIFIER_ACTION_MODEL_PARAMS =
                "text_classifier_action_model_params";
                "text_classifier_action_model_params";
    }
    }
    /**
    /**
+1 −0
Original line number Original line Diff line number Diff line
@@ -1098,6 +1098,7 @@
            2 - Power off (with confirmation)
            2 - Power off (with confirmation)
            3 - Power off (without confirmation)
            3 - Power off (without confirmation)
            4 - Go to voice assist
            4 - Go to voice assist
            5 - Go to assistant (Settings.Secure.ASSISTANT)
    -->
    -->
    <integer name="config_longPressOnPowerBehavior">1</integer>
    <integer name="config_longPressOnPowerBehavior">1</integer>


+4 −1
Original line number Original line Diff line number Diff line
@@ -577,7 +577,10 @@ public class SettingsBackupTest {
                    Settings.Global.RADIO_BUG_WAKELOCK_TIMEOUT_COUNT_THRESHOLD,
                    Settings.Global.RADIO_BUG_WAKELOCK_TIMEOUT_COUNT_THRESHOLD,
                    Settings.Global.RADIO_BUG_SYSTEM_ERROR_COUNT_THRESHOLD,
                    Settings.Global.RADIO_BUG_SYSTEM_ERROR_COUNT_THRESHOLD,
                    Settings.Global.ENABLED_SUBSCRIPTION_FOR_SLOT,
                    Settings.Global.ENABLED_SUBSCRIPTION_FOR_SLOT,
                    Settings.Global.MODEM_STACK_ENABLED_FOR_SLOT);
                    Settings.Global.MODEM_STACK_ENABLED_FOR_SLOT,
                    Settings.Global.POWER_BUTTON_LONG_PRESS,
                    Settings.Global.POWER_BUTTON_VERY_LONG_PRESS);

    private static final Set<String> BACKUP_BLACKLISTED_SECURE_SETTINGS =
    private static final Set<String> BACKUP_BLACKLISTED_SECURE_SETTINGS =
             newHashSet(
             newHashSet(
                 Settings.Secure.ACCESSIBILITY_SOFT_KEYBOARD_MODE,
                 Settings.Secure.ACCESSIBILITY_SOFT_KEYBOARD_MODE,
+84 −42
Original line number Original line Diff line number Diff line
@@ -256,6 +256,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    // Whether to allow devices placed in vr headset viewers to have an alternative Home intent.
    // Whether to allow devices placed in vr headset viewers to have an alternative Home intent.
    static final boolean ENABLE_VR_HEADSET_HOME_CAPTURE = true;
    static final boolean ENABLE_VR_HEADSET_HOME_CAPTURE = true;


    // must match: config_shortPressOnPowerBehavior in config.xml
    static final int SHORT_PRESS_POWER_NOTHING = 0;
    static final int SHORT_PRESS_POWER_NOTHING = 0;
    static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
    static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
    static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
    static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
@@ -263,29 +264,34 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    static final int SHORT_PRESS_POWER_GO_HOME = 4;
    static final int SHORT_PRESS_POWER_GO_HOME = 4;
    static final int SHORT_PRESS_POWER_CLOSE_IME_OR_GO_HOME = 5;
    static final int SHORT_PRESS_POWER_CLOSE_IME_OR_GO_HOME = 5;


    // must match: config_LongPressOnPowerBehavior in config.xml
    static final int LONG_PRESS_POWER_NOTHING = 0;
    static final int LONG_PRESS_POWER_NOTHING = 0;
    static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
    static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
    static final int LONG_PRESS_POWER_SHUT_OFF = 2;
    static final int LONG_PRESS_POWER_SHUT_OFF = 2;
    static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
    static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
    static final int LONG_PRESS_POWER_GO_TO_VOICE_ASSIST = 4;
    static final int LONG_PRESS_POWER_GO_TO_VOICE_ASSIST = 4;
    static final int LONG_PRESS_POWER_ASSISTANT = 5; // Settings.Secure.ASSISTANT


    // must match: config_veryLongPresOnPowerBehavior in config.xml
    static final int VERY_LONG_PRESS_POWER_NOTHING = 0;
    static final int VERY_LONG_PRESS_POWER_NOTHING = 0;
    static final int VERY_LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
    static final int VERY_LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;


    // must match: config_doublePressOnPowerBehavior in config.xml
    static final int MULTI_PRESS_POWER_NOTHING = 0;
    static final int MULTI_PRESS_POWER_NOTHING = 0;
    static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
    static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
    static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
    static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;


    // must match: config_longPressOnBackBehavior in config.xml
    static final int LONG_PRESS_BACK_NOTHING = 0;
    static final int LONG_PRESS_BACK_NOTHING = 0;
    static final int LONG_PRESS_BACK_GO_TO_VOICE_ASSIST = 1;
    static final int LONG_PRESS_BACK_GO_TO_VOICE_ASSIST = 1;


    // These need to match the documentation/constant in
    // must match: config_longPressOnHomeBehavior in config.xml
    // core/res/res/values/config.xml
    static final int LONG_PRESS_HOME_NOTHING = 0;
    static final int LONG_PRESS_HOME_NOTHING = 0;
    static final int LONG_PRESS_HOME_ALL_APPS = 1;
    static final int LONG_PRESS_HOME_ALL_APPS = 1;
    static final int LONG_PRESS_HOME_ASSIST = 2;
    static final int LONG_PRESS_HOME_ASSIST = 2;
    static final int LAST_LONG_PRESS_HOME_BEHAVIOR = LONG_PRESS_HOME_ASSIST;
    static final int LAST_LONG_PRESS_HOME_BEHAVIOR = LONG_PRESS_HOME_ASSIST;


    // must match: config_doubleTapOnHomeBehavior in config.xml
    static final int DOUBLE_TAP_HOME_NOTHING = 0;
    static final int DOUBLE_TAP_HOME_NOTHING = 0;
    static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
    static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;


@@ -770,6 +776,12 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            resolver.registerContentObserver(Settings.Secure.getUriFor(
            resolver.registerContentObserver(Settings.Secure.getUriFor(
                    Settings.Secure.SYSTEM_NAVIGATION_KEYS_ENABLED), false, this,
                    Settings.Secure.SYSTEM_NAVIGATION_KEYS_ENABLED), false, this,
                    UserHandle.USER_ALL);
                    UserHandle.USER_ALL);
            resolver.registerContentObserver(Settings.Global.getUriFor(
                    Settings.Global.POWER_BUTTON_LONG_PRESS), false, this,
                    UserHandle.USER_ALL);
            resolver.registerContentObserver(Settings.Global.getUriFor(
                    Settings.Global.POWER_BUTTON_VERY_LONG_PRESS), false, this,
                    UserHandle.USER_ALL);
            updateSettings();
            updateSettings();
        }
        }


@@ -1215,17 +1227,17 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                mPowerKeyHandled = true;
                mPowerKeyHandled = true;
                performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, false,
                performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, false,
                        "Power - Long Press - Go To Voice Assist");
                        "Power - Long Press - Go To Voice Assist");
            final boolean keyguardActive = mKeyguardDelegate == null
                // Some devices allow the voice assistant intent during setup (and use that intent
                    ? false
                // to launch something else, like Settings). So we explicitly allow that via the
                    : mKeyguardDelegate.isShowing();
                // config_allowStartActivityForLongPressOnPowerInSetup resource in config.xml.
            if (!keyguardActive) {
                launchVoiceAssist(mAllowStartActivityForLongPressOnPowerDuringSetup);
                Intent intent = new Intent(Intent.ACTION_VOICE_ASSIST);
                break;
                if (mAllowStartActivityForLongPressOnPowerDuringSetup) {
            case LONG_PRESS_POWER_ASSISTANT:
                    mContext.startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
                mPowerKeyHandled = true;
                } else {
                performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, false,
                    startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
                        "Power - Long Press - Go To Assistant");
                }
                final int powerKeyDeviceId = Integer.MIN_VALUE;
            }
                launchAssistAction(null, powerKeyDeviceId);
                break;
                break;
        }
        }
    }
    }
@@ -1250,13 +1262,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            case LONG_PRESS_BACK_NOTHING:
            case LONG_PRESS_BACK_NOTHING:
                break;
                break;
            case LONG_PRESS_BACK_GO_TO_VOICE_ASSIST:
            case LONG_PRESS_BACK_GO_TO_VOICE_ASSIST:
                final boolean keyguardActive = mKeyguardDelegate == null
                launchVoiceAssist(false /* allowDuringSetup */);
                        ? false
                        : mKeyguardDelegate.isShowing();
                if (!keyguardActive) {
                    Intent intent = new Intent(Intent.ACTION_VOICE_ASSIST);
                    startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
                }
                break;
                break;
        }
        }
    }
    }
@@ -1999,6 +2005,15 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                mHasSoftInput = hasSoftInput;
                mHasSoftInput = hasSoftInput;
                updateRotation = true;
                updateRotation = true;
            }
            }

            mLongPressOnPowerBehavior = Settings.Global.getInt(resolver,
                    Settings.Global.POWER_BUTTON_LONG_PRESS,
                    mContext.getResources().getInteger(
                            com.android.internal.R.integer.config_longPressOnPowerBehavior));
            mVeryLongPressOnPowerBehavior = Settings.Global.getInt(resolver,
                    Settings.Global.POWER_BUTTON_VERY_LONG_PRESS,
                    mContext.getResources().getInteger(
                            com.android.internal.R.integer.config_veryLongPressOnPowerBehavior));
        }
        }
        if (updateRotation) {
        if (updateRotation) {
            updateRotation(true);
            updateRotation(true);
@@ -3225,6 +3240,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        return 0;
        return 0;
    }
    }


    // There are several different flavors of "assistant" that can be launched from
    // various parts of the UI.

    /** starts ACTION_SEARCH_LONG_PRESS, usually a voice search prompt */
    private void launchAssistLongPressAction() {
    private void launchAssistLongPressAction() {
        performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, false,
        performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, false,
                "Assist - Long Press");
                "Assist - Long Press");
@@ -3246,6 +3265,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        }
        }
    }
    }


    /** Asks the status bar to startAssist(), usually a full "assistant" interface */
    private void launchAssistAction(String hint, int deviceId) {
    private void launchAssistAction(String hint, int deviceId) {
        sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
        sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
        if (!isUserSetupComplete()) {
        if (!isUserSetupComplete()) {
@@ -3276,12 +3296,30 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        }
        }
    }
    }


    /** Launches ACTION_VOICE_ASSIST. Does nothing on keyguard. */
    private void launchVoiceAssist(boolean allowDuringSetup) {
        final boolean keyguardActive = mKeyguardDelegate == null
                ? false
                : mKeyguardDelegate.isShowing();
        if (!keyguardActive) {
            Intent intent = new Intent(Intent.ACTION_VOICE_ASSIST);
            startActivityAsUser(intent, null, UserHandle.CURRENT_OR_SELF,
                    allowDuringSetup);
        }

    }

    private void startActivityAsUser(Intent intent, UserHandle handle) {
    private void startActivityAsUser(Intent intent, UserHandle handle) {
        startActivityAsUser(intent, null, handle);
        startActivityAsUser(intent, null, handle);
    }
    }


    private void startActivityAsUser(Intent intent, Bundle bundle, UserHandle handle) {
    private void startActivityAsUser(Intent intent, Bundle bundle, UserHandle handle) {
        if (isUserSetupComplete()) {
        startActivityAsUser(intent, bundle, handle, false /* allowDuringSetup */);
    }

    private void startActivityAsUser(Intent intent, Bundle bundle, UserHandle handle,
            boolean allowDuringSetup) {
        if (allowDuringSetup || isUserSetupComplete()) {
            mContext.startActivityAsUser(intent, bundle, handle);
            mContext.startActivityAsUser(intent, bundle, handle);
        } else {
        } else {
            Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
            Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
@@ -5541,6 +5579,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                return "LONG_PRESS_POWER_SHUT_OFF";
                return "LONG_PRESS_POWER_SHUT_OFF";
            case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
            case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
                return "LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM";
                return "LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM";
            case LONG_PRESS_POWER_GO_TO_VOICE_ASSIST:
                return "LONG_PRESS_POWER_GO_TO_VOICE_ASSIST";
            case LONG_PRESS_POWER_ASSISTANT:
                return "LONG_PRESS_POWER_ASSISTANT";
            default:
            default:
                return Integer.toString(behavior);
                return Integer.toString(behavior);
        }
        }