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

Commit d53c355c authored by Ming-Shin Lu's avatar Ming-Shin Lu
Browse files

Introduce USAGE_IME_FEEDBACK & default keyboard vibration intensity config

The CL is to prepare clean-up FLAG_BYPASS_USER_VIBRATION_INTENSITY_SCALE
check for keyboard vibration in VibratorManagerService (VMS).

With USAGE_IME_FEEDBACK hint, the keyboard vibration can be allowed to get
the current / default vibration intensity in VMS more natually through
config_defaultKeyboardVibrationIntensity in config.xml.

Note that in VibrationSettings#{getDefaultIntensity, getCurrentIntensity}
will apply the default keyboard vibration intensity when enabling keyboard
vibration settings support, otherwise will fallback to USAGE_TOUCH default
intensity.

Also ensure in VibrationAttriribute#getAudioUsage(usageHint) to return
the corresponding audio attribute USAGE_ASSISTANCE_SONIFICATION as
usage_touch for IME feedback hint.

In the next CL, we will apply this new usage hint so keyboard vibrations
can be handled by the scale logic in VibratorScaler vs. bypassing it.

Flag: android.os.vibrator.vibration_attribute_ime_usage_api
Bug: 332661766
Test: atest VibratorManagerServiceTest
Test: atest VibrationSettingsTest
Change-Id: I6256c4f47a8bbee4b649d35eabfbc0c94215c0d7
parent 12fd7706
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -34161,6 +34161,7 @@ package android.os {
    field public static final int USAGE_CLASS_UNKNOWN = 0; // 0x0
    field public static final int USAGE_COMMUNICATION_REQUEST = 65; // 0x41
    field public static final int USAGE_HARDWARE_FEEDBACK = 50; // 0x32
    field @FlaggedApi("android.os.vibrator.vibration_attribute_ime_usage_api") public static final int USAGE_IME_FEEDBACK = 82; // 0x52
    field public static final int USAGE_MEDIA = 19; // 0x13
    field public static final int USAGE_NOTIFICATION = 49; // 0x31
    field public static final int USAGE_PHYSICAL_EMULATION = 34; // 0x22
+13 −0
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

package android.os;

import static android.os.vibrator.Flags.FLAG_VIBRATION_ATTRIBUTE_IME_USAGE_API;

import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -55,6 +58,7 @@ public final class VibrationAttributes implements Parcelable {
            USAGE_PHYSICAL_EMULATION,
            USAGE_RINGTONE,
            USAGE_TOUCH,
            USAGE_IME_FEEDBACK,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface Usage {}
@@ -135,6 +139,12 @@ public final class VibrationAttributes implements Parcelable {
     * Usage value to use for accessibility vibrations, such as with a screen reader.
     */
    public static final int USAGE_ACCESSIBILITY = 0x40 | USAGE_CLASS_FEEDBACK;
    /**
     * Usage value to use for input method editor (IME) haptic feedback.
     */
    @FlaggedApi(FLAG_VIBRATION_ATTRIBUTE_IME_USAGE_API)
    public static final int USAGE_IME_FEEDBACK = 0x50 | USAGE_CLASS_FEEDBACK;

    /**
     * Usage value to use for media vibrations, such as music, movie, soundtrack, animations, games,
     * or any interactive media that isn't for touch feedback specifically.
@@ -349,6 +359,7 @@ public final class VibrationAttributes implements Parcelable {
            case USAGE_RINGTONE:
                return AudioAttributes.USAGE_NOTIFICATION_RINGTONE;
            case USAGE_TOUCH:
            case USAGE_IME_FEEDBACK:
                return AudioAttributes.USAGE_ASSISTANCE_SONIFICATION;
            case USAGE_ALARM:
                return AudioAttributes.USAGE_ALARM;
@@ -447,6 +458,8 @@ public final class VibrationAttributes implements Parcelable {
                return "PHYSICAL_EMULATION";
            case USAGE_HARDWARE_FEEDBACK:
                return "HARDWARE_FEEDBACK";
            case USAGE_IME_FEEDBACK:
                return "IME";
            default:
                return "unknown usage " + usage;
        }
+9 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.os.VibrationAttributes.USAGE_ACCESSIBILITY;
import static android.os.VibrationAttributes.USAGE_ALARM;
import static android.os.VibrationAttributes.USAGE_COMMUNICATION_REQUEST;
import static android.os.VibrationAttributes.USAGE_HARDWARE_FEEDBACK;
import static android.os.VibrationAttributes.USAGE_IME_FEEDBACK;
import static android.os.VibrationAttributes.USAGE_MEDIA;
import static android.os.VibrationAttributes.USAGE_NOTIFICATION;
import static android.os.VibrationAttributes.USAGE_PHYSICAL_EMULATION;
@@ -67,6 +68,8 @@ public class VibrationConfig {
    private final int mDefaultNotificationVibrationIntensity;
    @VibrationIntensity
    private final int mDefaultRingVibrationIntensity;
    @VibrationIntensity
    private final int mDefaultKeyboardVibrationIntensity;

    private final boolean mKeyboardVibrationSettingsSupported;

@@ -98,6 +101,8 @@ public class VibrationConfig {
                com.android.internal.R.integer.config_defaultNotificationVibrationIntensity);
        mDefaultRingVibrationIntensity = loadDefaultIntensity(resources,
                com.android.internal.R.integer.config_defaultRingVibrationIntensity);
        mDefaultKeyboardVibrationIntensity = loadDefaultIntensity(resources,
                com.android.internal.R.integer.config_defaultKeyboardVibrationIntensity);
    }

    @VibrationIntensity
@@ -213,6 +218,9 @@ public class VibrationConfig {
            case USAGE_PHYSICAL_EMULATION:
            case USAGE_ACCESSIBILITY:
                return mDefaultHapticFeedbackIntensity;
            case USAGE_IME_FEEDBACK:
                return isKeyboardVibrationSettingsSupported()
                        ? mDefaultKeyboardVibrationIntensity : mDefaultHapticFeedbackIntensity;
            case USAGE_MEDIA:
            case USAGE_UNKNOWN:
                // fall through
@@ -236,6 +244,7 @@ public class VibrationConfig {
                + ", mDefaultMediaIntensity=" + mDefaultMediaVibrationIntensity
                + ", mDefaultNotificationIntensity=" + mDefaultNotificationVibrationIntensity
                + ", mDefaultRingIntensity=" + mDefaultRingVibrationIntensity
                + ", mDefaultKeyboardIntensity=" + mDefaultKeyboardVibrationIntensity
                + ", mKeyboardVibrationSettingsSupported=" + mKeyboardVibrationSettingsSupported
                + "}";
    }
+11 −0
Original line number Diff line number Diff line
@@ -74,3 +74,14 @@ flag {
      purpose: PURPOSE_BUGFIX
    }
}

flag {
    namespace: "haptics"
    name: "vibration_attribute_ime_usage_api"
    is_exported: true
    description: "A public API for IME usage vibration attribute"
    bug: "332661766"
    metadata {
        purpose: PURPOSE_FEATURE
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -1399,6 +1399,10 @@
         Settings.System.RING_VIBRATION_INTENSITY more details on the constant values and
         meanings. -->
    <integer name="config_defaultRingVibrationIntensity">2</integer>
    <!-- The default intensity level for keyboard vibrations. Note that this will only be applied
         on devices where config_keyboardVibrationSettingsSupported is true, otherwise the
         keyboard vibration will follow config_defaultHapticFeedbackIntensity -->
    <integer name="config_defaultKeyboardVibrationIntensity">2</integer>

    <!-- Whether to use the strict phone number matcher by default. -->
    <bool name="config_use_strict_phone_number_comparation">false</bool>
Loading