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

Commit 3829f4b3 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 7659088 from 7931ff7a to sc-qpr1-release

Change-Id: Ibb305330e6ee8cabd314d8d3350d4be41cd48eda
parents b2eb822e 7931ff7a
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -37,9 +37,18 @@
        android:textAppearance="?android:attr/textAppearanceListItem"
        android:textColor="?android:attr/textColorPrimary" />

    <TextView
        android:id="@android:id/summary"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@android:id/title"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textAlignment="viewStart"
        android:textColor="?android:attr/textColorSecondary" />

    <SeekBar
        android:id="@*android:id/seekbar"
        android:layout_below="@android:id/title"
        android:layout_below="@android:id/summary"
        android:layout_gravity="center_vertical"
        android:layout_width="match_parent"
        android:layout_height="48dp"
+9 −0
Original line number Diff line number Diff line
@@ -13220,6 +13220,15 @@
    <!-- Power menu explanation where to find prevent ringing option. [CHAR LIMIT=NONE] -->
    <string name="power_menu_power_prevent_ringing_hint">Prevent ringing:\nShortcut available in the volume menu.</string>
    <!-- Power menu title of the seekbar setting controlling duration of how long the power button must be held to invoke assistant. [CHAR LIMIT=NONE]-->
    <string name="power_menu_long_press_for_assist_sensitivity_title">Press &amp; hold duration</string>
    <!-- Power menu summary of the seekbar setting controlling duration of how long the power button must be held to invoke assistant. [CHAR LIMIT=NONE]-->
    <string name="power_menu_long_press_for_assist_sensitivity_summary">Adjust sensitivity by choosing how long to press &amp; hold the power button</string>
    <!-- Label at the lowest end of duration slider for long press power invocation of assistant. [CHAR LIMIT=30] -->
    <string name="power_menu_long_press_for_assist_sensitivity_low_label">Short</string>
    <!-- Label at the highest end of duration slider for long press power invocation of assistant. [CHAR LIMIT=30] -->
    <string name="power_menu_long_press_for_assist_sensitivity_high_label">Long</string>
    <!-- Wallet (formerly Cards and passes) toggle name [CHAR LIMIT=60] -->
    <string name="lockscreen_privacy_wallet_setting_toggle">Show wallet</string>
    <!-- Wallet (formerly Cards and passes) summary [CHAR LIMIT=NONE] -->
+12 −2
Original line number Diff line number Diff line
@@ -24,6 +24,16 @@
        settings:controller="com.android.settings.gestures.LongPressPowerButtonPreferenceController"
    />

    <com.android.settings.widget.LabeledSeekBarPreference
        android:key="gesture_power_menu_long_press_for_assist_sensitivity"
        android:title="@string/power_menu_long_press_for_assist_sensitivity_title"
        android:summary="@string/power_menu_long_press_for_assist_sensitivity_summary"
        android:selectable="true"
        settings:textStart="@string/power_menu_long_press_for_assist_sensitivity_low_label"
        settings:textEnd="@string/power_menu_long_press_for_assist_sensitivity_high_label"
        settings:controller="com.android.settings.gestures.LongPressPowerSensitivityPreferenceController"
    />

    <com.android.settingslib.widget.FooterPreference
        android:key="power_menu_power_volume_up_hint"
        android:title="@string/power_menu_power_volume_up_hint"
+7 −32
Original line number Diff line number Diff line
@@ -16,6 +16,11 @@

package com.android.settings.gestures;

import static com.android.settings.gestures.PowerMenuSettingsUtils.LONG_PRESS_POWER_ASSISTANT_VALUE;
import static com.android.settings.gestures.PowerMenuSettingsUtils.LONG_PRESS_POWER_GLOBAL_ACTIONS;
import static com.android.settings.gestures.PowerMenuSettingsUtils.POWER_BUTTON_LONG_PRESS_DEFAULT_VALUE_RESOURCE;
import static com.android.settings.gestures.PowerMenuSettingsUtils.POWER_BUTTON_LONG_PRESS_SETTING;

import android.content.Context;
import android.provider.Settings;

@@ -33,27 +38,12 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
 */
public class LongPressPowerButtonPreferenceController extends TogglePreferenceController {

    private static final String POWER_BUTTON_LONG_PRESS_SETTING =
            Settings.Global.POWER_BUTTON_LONG_PRESS;
    private static final String KEY_CHORD_POWER_VOLUME_UP_SETTING =
            Settings.Global.KEY_CHORD_POWER_VOLUME_UP;

    private static final String FOOTER_HINT_KEY = "power_menu_power_volume_up_hint";
    private static final String ASSIST_SWITCH_KEY = "gesture_power_menu_long_press_for_assist";

    /**
     * Values used for long press power button behaviour when Assist setting is enabled.
     *
     * {@link com.android.server.policy.PhoneWindowManager#LONG_PRESS_POWER_GLOBAL_ACTIONS} for
     * source of the value.
     */
    @VisibleForTesting
    static final int LONG_PRESS_POWER_NO_ACTION = 0;
    @VisibleForTesting
    static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
    @VisibleForTesting
    static final int LONG_PRESS_POWER_ASSISTANT_VALUE = 5; // Settings.Secure.ASSISTANT

    /**
     * Values used for volume key chord behaviour when Assist setting is enabled.
     *
@@ -67,15 +57,6 @@ public class LongPressPowerButtonPreferenceController extends TogglePreferenceCo
    @VisibleForTesting
    static final int KEY_CHORD_POWER_VOLUME_UP_GLOBAL_ACTIONS = 2;

    /**
     * Value used for long press power button behaviour when the Assist setting is disabled.
     *
     * If this value matches Assist setting, then it falls back to Global Actions panel or
     * power menu, depending on their respective settings.
     */
    private static final int POWER_BUTTON_LONG_PRESS_DEFAULT_VALUE_RESOURCE =
            com.android.internal.R.integer.config_longPressOnPowerBehavior;

    private static final int KEY_CHORD_POWER_VOLUME_UP_DEFAULT_VALUE_RESOURCE =
            com.android.internal.R.integer.config_keyChordPowerVolumeUp;

@@ -101,7 +82,7 @@ public class LongPressPowerButtonPreferenceController extends TogglePreferenceCo

    @Override
    public CharSequence getSummary() {
        final int powerButtonValue = getPowerButtonValue();
        final int powerButtonValue = PowerMenuSettingsUtils.getPowerButtonSettingValue(mContext);
        if (powerButtonValue == LONG_PRESS_POWER_ASSISTANT_VALUE) {
            return mContext.getString(R.string.power_menu_summary_long_press_for_assist_enabled);
        } else if (powerButtonValue == LONG_PRESS_POWER_GLOBAL_ACTIONS) {
@@ -122,7 +103,7 @@ public class LongPressPowerButtonPreferenceController extends TogglePreferenceCo

    @Override
    public boolean isChecked() {
        return getPowerButtonValue() == LONG_PRESS_POWER_ASSISTANT_VALUE;
        return PowerMenuSettingsUtils.isLongPressPowerForAssistEnabled(mContext);
    }

    @Override
@@ -159,12 +140,6 @@ public class LongPressPowerButtonPreferenceController extends TogglePreferenceCo
        }
    }

    private int getPowerButtonValue() {
        return Settings.Global.getInt(mContext.getContentResolver(),
                POWER_BUTTON_LONG_PRESS_SETTING,
                mContext.getResources().getInteger(POWER_BUTTON_LONG_PRESS_DEFAULT_VALUE_RESOURCE));
    }

    private static boolean isPowerMenuKeyChordEnabled(Context context) {
        return Settings.Global.getInt(context.getContentResolver(),
                KEY_CHORD_POWER_VOLUME_UP_SETTING,
+155 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings.gestures;

import android.content.Context;
import android.database.ContentObserver;
import android.os.Handler;
import android.provider.Settings;

import androidx.annotation.Nullable;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;

import com.android.settings.core.SliderPreferenceController;
import com.android.settings.widget.LabeledSeekBarPreference;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop;

/** Handles changes to the long press power button sensitivity slider. */
public class LongPressPowerSensitivityPreferenceController extends
        SliderPreferenceController implements
        LifecycleObserver, OnStart, OnStop {

    private final ContentObserver mPowerButtonObserver = new ContentObserver(Handler.getMain()) {
        @Override
        public void onChange(boolean selfChange) {
            if (mPreference != null) {
                updateState(mPreference);
            }
        }
    };

    @Nullable
    private final int[] mSensitivityValues;

    @Nullable
    private LabeledSeekBarPreference mPreference;

    public LongPressPowerSensitivityPreferenceController(Context context, String preferenceKey) {
        super(context, preferenceKey);
        mSensitivityValues = context.getResources().getIntArray(
                com.android.internal.R.array.config_longPressOnPowerDurationSettings);
    }

    @Override
    public void onStart() {
        mContext.getContentResolver().registerContentObserver(
                Settings.Global.getUriFor(PowerMenuSettingsUtils.POWER_BUTTON_LONG_PRESS_SETTING),
                false, mPowerButtonObserver);
    }

    @Override
    public void onStop() {
        mContext.getContentResolver().unregisterContentObserver(mPowerButtonObserver);
    }

    @Override
    public void displayPreference(PreferenceScreen screen) {
        super.displayPreference(screen);
        mPreference = screen.findPreference(getPreferenceKey());
        if (mPreference != null) {
            mPreference.setContinuousUpdates(false);
            mPreference.setHapticFeedbackMode(
                    LabeledSeekBarPreference.HAPTIC_FEEDBACK_MODE_ON_TICKS);
            mPreference.setMin(getMin());
            mPreference.setMax(getMax());
        }
    }

    @Override
    public void updateState(Preference preference) {
        super.updateState(preference);
        final LabeledSeekBarPreference pref = (LabeledSeekBarPreference) preference;
        pref.setEnabled(
                isAvailable() && PowerMenuSettingsUtils.isLongPressPowerForAssistEnabled(mContext));
        pref.setProgress(getSliderPosition());
    }

    @Override
    public int getAvailabilityStatus() {
        if (mSensitivityValues == null || mSensitivityValues.length < 2) {
            return UNSUPPORTED_ON_DEVICE;
        }

        if (!PowerMenuSettingsUtils.isLongPressPowerForAssistEnabled(mContext)) {
            return DISABLED_DEPENDENT_SETTING;
        }

        return AVAILABLE;
    }

    @Override
    public int getSliderPosition() {
        return mSensitivityValues == null ? 0 : closestValueIndex(mSensitivityValues,
                getCurrentSensitivityValue());
    }

    @Override
    public boolean setSliderPosition(int position) {
        if (mSensitivityValues == null || position < 0 || position >= mSensitivityValues.length) {
            return false;
        }
        return Settings.Global.putInt(mContext.getContentResolver(),
                Settings.Global.POWER_BUTTON_LONG_PRESS_DURATION_MS,
                mSensitivityValues[position]);
    }

    @Override
    public int getMax() {
        if (mSensitivityValues == null || mSensitivityValues.length == 0) {
            return 0;
        }
        return mSensitivityValues.length - 1;
    }

    @Override
    public int getMin() {
        return 0;
    }

    private int getCurrentSensitivityValue() {
        return Settings.Global.getInt(mContext.getContentResolver(),
                Settings.Global.POWER_BUTTON_LONG_PRESS_DURATION_MS,
                mContext.getResources().getInteger(
                        com.android.internal.R.integer.config_longPressOnPowerDurationMs));
    }

    private static int closestValueIndex(int[] values, int needle) {
        int minDistance = Integer.MAX_VALUE;
        int valueIndex = 0;
        for (int i = 0; i < values.length; i++) {
            int diff = Math.abs(values[i] - needle);
            if (diff < minDistance) {
                minDistance = diff;
                valueIndex = i;
            }
        }
        return valueIndex;
    }
}
Loading