Loading core/java/android/os/ExternalVibrationScale.aidl +1 −0 Original line number Original line Diff line number Diff line Loading @@ -23,6 +23,7 @@ package android.os; * @hide * @hide */ */ parcelable ExternalVibrationScale { parcelable ExternalVibrationScale { // TODO(b/345186129): remove this once we finish migrating to scale factor. @Backing(type="int") @Backing(type="int") enum ScaleLevel { enum ScaleLevel { SCALE_MUTE = -100, SCALE_MUTE = -100, Loading core/java/android/os/VibrationEffect.java +27 −0 Original line number Original line Diff line number Diff line Loading @@ -644,6 +644,19 @@ public abstract class VibrationEffect implements Parcelable { * scale down the intensity, values larger than 1 will scale up * scale down the intensity, values larger than 1 will scale up * @return this if there is no scaling to be done, or a copy of this effect with scaled * @return this if there is no scaling to be done, or a copy of this effect with scaled * vibration intensity otherwise * vibration intensity otherwise * * @hide */ @NonNull public abstract VibrationEffect scaleLinearly(float scaleFactor); /** * Applies given scale factor as adaptive scale. * * @param scaleFactor scale factor to be applied to the intensity. Values within [0,1) will * scale down the intensity, values larger than 1 will scale up * @return this if there is no scaling to be done, or a copy of this effect with scaled * vibration intensity otherwise * @hide * @hide */ */ @NonNull @NonNull Loading Loading @@ -1003,6 +1016,13 @@ public abstract class VibrationEffect implements Parcelable { return applyToSegments(VibrationEffectSegment::scale, scaleFactor); return applyToSegments(VibrationEffectSegment::scale, scaleFactor); } } /** @hide */ @NonNull @Override public Composed scaleLinearly(float scaleFactor) { return applyToSegments(VibrationEffectSegment::scaleLinearly, scaleFactor); } /** @hide */ /** @hide */ @NonNull @NonNull @Override @Override Loading Loading @@ -1265,6 +1285,13 @@ public abstract class VibrationEffect implements Parcelable { return updated; return updated; } } /** @hide */ @NonNull @Override public VibrationEffect scaleLinearly(float scaleFactor) { return scale(scaleFactor); } /** @hide */ /** @hide */ @NonNull @NonNull @Override @Override Loading core/java/android/os/vibrator/VibrationConfig.java +81 −2 Original line number Original line Diff line number Diff line Loading @@ -63,13 +63,14 @@ public class VibrationConfig { */ */ private static final int DEFAULT_AMPLITUDE = 255; private static final int DEFAULT_AMPLITUDE = 255; // TODO(b/191150049): move these to vibrator static config file private final float mHapticChannelMaxVibrationAmplitude; private final float mHapticChannelMaxVibrationAmplitude; private final int mDefaultVibrationAmplitude; private final int mDefaultVibrationAmplitude; private final int mRampStepDurationMs; private final int mRampStepDurationMs; private final int mRampDownDurationMs; private final int mRampDownDurationMs; private final int mRequestVibrationParamsTimeoutMs; private final int mRequestVibrationParamsTimeoutMs; private final int[] mRequestVibrationParamsForUsages; private final int[] mRequestVibrationParamsForUsages; private final float[] mVibrationScaleFactors; private final float[] mExternalVibrationScaleFactors; private final boolean mIgnoreVibrationsOnWirelessCharger; private final boolean mIgnoreVibrationsOnWirelessCharger; Loading Loading @@ -123,6 +124,11 @@ public class VibrationConfig { com.android.internal.R.integer.config_defaultRingVibrationIntensity); com.android.internal.R.integer.config_defaultRingVibrationIntensity); mDefaultKeyboardVibrationIntensity = loadDefaultIntensity(resources, mDefaultKeyboardVibrationIntensity = loadDefaultIntensity(resources, com.android.internal.R.integer.config_defaultKeyboardVibrationIntensity); com.android.internal.R.integer.config_defaultKeyboardVibrationIntensity); mVibrationScaleFactors = loadIntensityScaleFactors(resources, com.android.internal.R.array.config_vibrationIntensityScaleFactors); mExternalVibrationScaleFactors = loadIntensityScaleFactors(resources, com.android.internal.R.array.config_externalVibrationIntensityScaleFactors); } } @VibrationIntensity @VibrationIntensity Loading @@ -135,6 +141,22 @@ public class VibrationConfig { return value; return value; } } @Nullable private static float[] loadIntensityScaleFactors(@Nullable Resources res, int resId) { float[] scales = loadFloatArray(res, resId); if (scales == null || scales.length != Vibrator.VIBRATION_INTENSITY_HIGH) { // Missing or bad config, ignore it. return null; } for (float scale : scales) { if (scale <= 0) { // Bad scale value, ignore config. return null; } } return scales; } private static float loadFloat(@Nullable Resources res, int resId) { private static float loadFloat(@Nullable Resources res, int resId) { return res != null ? res.getFloat(resId) : 0f; return res != null ? res.getFloat(resId) : 0f; } } Loading @@ -151,6 +173,22 @@ public class VibrationConfig { return res != null ? res.getIntArray(resId) : new int[0]; return res != null ? res.getIntArray(resId) : new int[0]; } } private static float[] loadFloatArray(@Nullable Resources res, int resId) { String[] values = res != null ? res.getStringArray(resId) : null; if (values == null) { return null; } float[] parsedValues = new float[values.length]; for (int i = 0; i < values.length; i++) { try { parsedValues[i] = Float.parseFloat(values[i]); } catch (Exception e) { return null; } } return parsedValues; } /** /** * Return the maximum amplitude the vibrator can play using the audio haptic channels. * Return the maximum amplitude the vibrator can play using the audio haptic channels. * * Loading Loading @@ -180,10 +218,45 @@ public class VibrationConfig { * for each level. * for each level. */ */ public float getDefaultVibrationScaleLevelGain() { public float getDefaultVibrationScaleLevelGain() { // TODO(b/356407380): add device config for this return DEFAULT_SCALE_LEVEL_GAIN; return DEFAULT_SCALE_LEVEL_GAIN; } } /** Return true if device has vibration scale factors config. */ public boolean hasVibrationScaleFactors() { return mVibrationScaleFactors != null; } /** * Return the scale factor configured for given intensity, or the default value if no * configuration is in place. */ public float getVibrationScaleFactor(@VibrationIntensity int intensity, float defaultValue) { if (mVibrationScaleFactors == null || mVibrationScaleFactors.length < intensity) { return defaultValue; } return mVibrationScaleFactors[intensity - 1]; } /** Return true if device has vibration scale factors config. */ public boolean hasExternalVibrationScaleFactors() { return mExternalVibrationScaleFactors != null; } /** * Return the scale factor configured for given intensity for external vibrations. * * <p>This will return {@link #getVibrationScaleFactor} if no configuration is in place * specifically for external vibrations. */ public float getExternalVibrationScaleFactor(@VibrationIntensity int intensity, float defaultValue) { if (mExternalVibrationScaleFactors == null || mExternalVibrationScaleFactors.length < intensity) { return getVibrationScaleFactor(intensity, defaultValue); } return mExternalVibrationScaleFactors[intensity - 1]; } /** /** * The duration, in milliseconds, that should be applied to the ramp to turn off the vibrator * The duration, in milliseconds, that should be applied to the ramp to turn off the vibrator * when a vibration is cancelled or finished at non-zero amplitude. * when a vibration is cancelled or finished at non-zero amplitude. Loading Loading @@ -305,6 +378,9 @@ public class VibrationConfig { + ", mDefaultRingIntensity=" + mDefaultRingVibrationIntensity + ", mDefaultRingIntensity=" + mDefaultRingVibrationIntensity + ", mDefaultKeyboardIntensity=" + mDefaultKeyboardVibrationIntensity + ", mDefaultKeyboardIntensity=" + mDefaultKeyboardVibrationIntensity + ", mKeyboardVibrationSettingsSupported=" + mKeyboardVibrationSettingsSupported + ", mKeyboardVibrationSettingsSupported=" + mKeyboardVibrationSettingsSupported + ", mVibrationScaleFactors=" + Arrays.toString(mVibrationScaleFactors) + ", mExternalVibrationScaleFactors=" + Arrays.toString(mExternalVibrationScaleFactors) + "}"; + "}"; } } Loading @@ -319,6 +395,9 @@ public class VibrationConfig { pw.println("ignoreVibrationsOnWirelessCharger = " + mIgnoreVibrationsOnWirelessCharger); pw.println("ignoreVibrationsOnWirelessCharger = " + mIgnoreVibrationsOnWirelessCharger); pw.println("defaultVibrationAmplitude = " + mDefaultVibrationAmplitude); pw.println("defaultVibrationAmplitude = " + mDefaultVibrationAmplitude); pw.println("hapticChannelMaxAmplitude = " + mHapticChannelMaxVibrationAmplitude); pw.println("hapticChannelMaxAmplitude = " + mHapticChannelMaxVibrationAmplitude); pw.println("vibrationScaleFactors = " + Arrays.toString(mVibrationScaleFactors)); pw.println("externalVibrationScaleFactors = " + Arrays.toString(mExternalVibrationScaleFactors)); pw.println("rampStepDurationMs = " + mRampStepDurationMs); pw.println("rampStepDurationMs = " + mRampStepDurationMs); pw.println("rampDownDurationMs = " + mRampDownDurationMs); pw.println("rampDownDurationMs = " + mRampDownDurationMs); pw.println("requestVibrationParamsForUsages = " pw.println("requestVibrationParamsForUsages = " Loading core/java/android/os/vibrator/flags.aconfig +10 −0 Original line number Original line Diff line number Diff line Loading @@ -146,3 +146,13 @@ flag { purpose: PURPOSE_BUGFIX purpose: PURPOSE_BUGFIX } } } } flag { namespace: "haptics" name: "vibration_scale_device_config_enabled" description: "Enables device-configurable vibration scale factors" bug: "427503922" metadata { purpose: PURPOSE_BUGFIX } } core/res/res/values/config.xml +25 −0 Original line number Original line Diff line number Diff line Loading @@ -4390,6 +4390,31 @@ <!-- The default vibration strength, must be between 1 and 255 inclusive. --> <!-- The default vibration strength, must be between 1 and 255 inclusive. --> <integer name="config_defaultVibrationAmplitude">255</integer> <integer name="config_defaultVibrationAmplitude">255</integer> <!-- The scale factor to be applied at each vibration intensity level supported by the device, defined by a positive float value. The default framework scaling will be applied if this is not set, based on the user and the default scales for each usage. The number of entries here must be the device supported scale levels for LOW/MEDIUM/HIGH. Example: <string-array name="config_vibrationIntensityScaleFactors" translatable="false"> <item>0.5</item> -> Vibrator.VIBRATION_INTENSITY_LOW <item>0.7</item> -> Vibrator.VIBRATION_INTENSITY_MEDIUM <item>1.0</item> -> Vibrator.VIBRATION_INTENSITY_HIGH </string-array> --> <string-array name="config_vibrationIntensityScaleFactors" translatable="false" /> <!-- The scale factor to be applied for external vibrations only (i.e. audio-coupled haptics), defined by a positive float value. The values from config_vibrationIntensityScaleFactors will be used if this is not set. The number of entries here must be the device supported scale levels for LOW/MEDIUM/HIGH. Example: <string-array name="config_externalVibrationIntensityScaleFactors" translatable="false"> <item>0.3</item> -> Vibrator.VIBRATION_INTENSITY_LOW <item>0.5</item> -> Vibrator.VIBRATION_INTENSITY_MEDIUM <item>1.0</item> -> Vibrator.VIBRATION_INTENSITY_HIGH </string-array> --> <string-array name="config_externalVibrationIntensityScaleFactors" translatable="false" /> <!-- The max vibration strength allowed in audio haptic channels, must be positive or zero if <!-- The max vibration strength allowed in audio haptic channels, must be positive or zero if limit is unknown. --> limit is unknown. --> <item name="config_hapticChannelMaxVibrationAmplitude" format="float" type="dimen">0</item> <item name="config_hapticChannelMaxVibrationAmplitude" format="float" type="dimen">0</item> Loading Loading
core/java/android/os/ExternalVibrationScale.aidl +1 −0 Original line number Original line Diff line number Diff line Loading @@ -23,6 +23,7 @@ package android.os; * @hide * @hide */ */ parcelable ExternalVibrationScale { parcelable ExternalVibrationScale { // TODO(b/345186129): remove this once we finish migrating to scale factor. @Backing(type="int") @Backing(type="int") enum ScaleLevel { enum ScaleLevel { SCALE_MUTE = -100, SCALE_MUTE = -100, Loading
core/java/android/os/VibrationEffect.java +27 −0 Original line number Original line Diff line number Diff line Loading @@ -644,6 +644,19 @@ public abstract class VibrationEffect implements Parcelable { * scale down the intensity, values larger than 1 will scale up * scale down the intensity, values larger than 1 will scale up * @return this if there is no scaling to be done, or a copy of this effect with scaled * @return this if there is no scaling to be done, or a copy of this effect with scaled * vibration intensity otherwise * vibration intensity otherwise * * @hide */ @NonNull public abstract VibrationEffect scaleLinearly(float scaleFactor); /** * Applies given scale factor as adaptive scale. * * @param scaleFactor scale factor to be applied to the intensity. Values within [0,1) will * scale down the intensity, values larger than 1 will scale up * @return this if there is no scaling to be done, or a copy of this effect with scaled * vibration intensity otherwise * @hide * @hide */ */ @NonNull @NonNull Loading Loading @@ -1003,6 +1016,13 @@ public abstract class VibrationEffect implements Parcelable { return applyToSegments(VibrationEffectSegment::scale, scaleFactor); return applyToSegments(VibrationEffectSegment::scale, scaleFactor); } } /** @hide */ @NonNull @Override public Composed scaleLinearly(float scaleFactor) { return applyToSegments(VibrationEffectSegment::scaleLinearly, scaleFactor); } /** @hide */ /** @hide */ @NonNull @NonNull @Override @Override Loading Loading @@ -1265,6 +1285,13 @@ public abstract class VibrationEffect implements Parcelable { return updated; return updated; } } /** @hide */ @NonNull @Override public VibrationEffect scaleLinearly(float scaleFactor) { return scale(scaleFactor); } /** @hide */ /** @hide */ @NonNull @NonNull @Override @Override Loading
core/java/android/os/vibrator/VibrationConfig.java +81 −2 Original line number Original line Diff line number Diff line Loading @@ -63,13 +63,14 @@ public class VibrationConfig { */ */ private static final int DEFAULT_AMPLITUDE = 255; private static final int DEFAULT_AMPLITUDE = 255; // TODO(b/191150049): move these to vibrator static config file private final float mHapticChannelMaxVibrationAmplitude; private final float mHapticChannelMaxVibrationAmplitude; private final int mDefaultVibrationAmplitude; private final int mDefaultVibrationAmplitude; private final int mRampStepDurationMs; private final int mRampStepDurationMs; private final int mRampDownDurationMs; private final int mRampDownDurationMs; private final int mRequestVibrationParamsTimeoutMs; private final int mRequestVibrationParamsTimeoutMs; private final int[] mRequestVibrationParamsForUsages; private final int[] mRequestVibrationParamsForUsages; private final float[] mVibrationScaleFactors; private final float[] mExternalVibrationScaleFactors; private final boolean mIgnoreVibrationsOnWirelessCharger; private final boolean mIgnoreVibrationsOnWirelessCharger; Loading Loading @@ -123,6 +124,11 @@ public class VibrationConfig { com.android.internal.R.integer.config_defaultRingVibrationIntensity); com.android.internal.R.integer.config_defaultRingVibrationIntensity); mDefaultKeyboardVibrationIntensity = loadDefaultIntensity(resources, mDefaultKeyboardVibrationIntensity = loadDefaultIntensity(resources, com.android.internal.R.integer.config_defaultKeyboardVibrationIntensity); com.android.internal.R.integer.config_defaultKeyboardVibrationIntensity); mVibrationScaleFactors = loadIntensityScaleFactors(resources, com.android.internal.R.array.config_vibrationIntensityScaleFactors); mExternalVibrationScaleFactors = loadIntensityScaleFactors(resources, com.android.internal.R.array.config_externalVibrationIntensityScaleFactors); } } @VibrationIntensity @VibrationIntensity Loading @@ -135,6 +141,22 @@ public class VibrationConfig { return value; return value; } } @Nullable private static float[] loadIntensityScaleFactors(@Nullable Resources res, int resId) { float[] scales = loadFloatArray(res, resId); if (scales == null || scales.length != Vibrator.VIBRATION_INTENSITY_HIGH) { // Missing or bad config, ignore it. return null; } for (float scale : scales) { if (scale <= 0) { // Bad scale value, ignore config. return null; } } return scales; } private static float loadFloat(@Nullable Resources res, int resId) { private static float loadFloat(@Nullable Resources res, int resId) { return res != null ? res.getFloat(resId) : 0f; return res != null ? res.getFloat(resId) : 0f; } } Loading @@ -151,6 +173,22 @@ public class VibrationConfig { return res != null ? res.getIntArray(resId) : new int[0]; return res != null ? res.getIntArray(resId) : new int[0]; } } private static float[] loadFloatArray(@Nullable Resources res, int resId) { String[] values = res != null ? res.getStringArray(resId) : null; if (values == null) { return null; } float[] parsedValues = new float[values.length]; for (int i = 0; i < values.length; i++) { try { parsedValues[i] = Float.parseFloat(values[i]); } catch (Exception e) { return null; } } return parsedValues; } /** /** * Return the maximum amplitude the vibrator can play using the audio haptic channels. * Return the maximum amplitude the vibrator can play using the audio haptic channels. * * Loading Loading @@ -180,10 +218,45 @@ public class VibrationConfig { * for each level. * for each level. */ */ public float getDefaultVibrationScaleLevelGain() { public float getDefaultVibrationScaleLevelGain() { // TODO(b/356407380): add device config for this return DEFAULT_SCALE_LEVEL_GAIN; return DEFAULT_SCALE_LEVEL_GAIN; } } /** Return true if device has vibration scale factors config. */ public boolean hasVibrationScaleFactors() { return mVibrationScaleFactors != null; } /** * Return the scale factor configured for given intensity, or the default value if no * configuration is in place. */ public float getVibrationScaleFactor(@VibrationIntensity int intensity, float defaultValue) { if (mVibrationScaleFactors == null || mVibrationScaleFactors.length < intensity) { return defaultValue; } return mVibrationScaleFactors[intensity - 1]; } /** Return true if device has vibration scale factors config. */ public boolean hasExternalVibrationScaleFactors() { return mExternalVibrationScaleFactors != null; } /** * Return the scale factor configured for given intensity for external vibrations. * * <p>This will return {@link #getVibrationScaleFactor} if no configuration is in place * specifically for external vibrations. */ public float getExternalVibrationScaleFactor(@VibrationIntensity int intensity, float defaultValue) { if (mExternalVibrationScaleFactors == null || mExternalVibrationScaleFactors.length < intensity) { return getVibrationScaleFactor(intensity, defaultValue); } return mExternalVibrationScaleFactors[intensity - 1]; } /** /** * The duration, in milliseconds, that should be applied to the ramp to turn off the vibrator * The duration, in milliseconds, that should be applied to the ramp to turn off the vibrator * when a vibration is cancelled or finished at non-zero amplitude. * when a vibration is cancelled or finished at non-zero amplitude. Loading Loading @@ -305,6 +378,9 @@ public class VibrationConfig { + ", mDefaultRingIntensity=" + mDefaultRingVibrationIntensity + ", mDefaultRingIntensity=" + mDefaultRingVibrationIntensity + ", mDefaultKeyboardIntensity=" + mDefaultKeyboardVibrationIntensity + ", mDefaultKeyboardIntensity=" + mDefaultKeyboardVibrationIntensity + ", mKeyboardVibrationSettingsSupported=" + mKeyboardVibrationSettingsSupported + ", mKeyboardVibrationSettingsSupported=" + mKeyboardVibrationSettingsSupported + ", mVibrationScaleFactors=" + Arrays.toString(mVibrationScaleFactors) + ", mExternalVibrationScaleFactors=" + Arrays.toString(mExternalVibrationScaleFactors) + "}"; + "}"; } } Loading @@ -319,6 +395,9 @@ public class VibrationConfig { pw.println("ignoreVibrationsOnWirelessCharger = " + mIgnoreVibrationsOnWirelessCharger); pw.println("ignoreVibrationsOnWirelessCharger = " + mIgnoreVibrationsOnWirelessCharger); pw.println("defaultVibrationAmplitude = " + mDefaultVibrationAmplitude); pw.println("defaultVibrationAmplitude = " + mDefaultVibrationAmplitude); pw.println("hapticChannelMaxAmplitude = " + mHapticChannelMaxVibrationAmplitude); pw.println("hapticChannelMaxAmplitude = " + mHapticChannelMaxVibrationAmplitude); pw.println("vibrationScaleFactors = " + Arrays.toString(mVibrationScaleFactors)); pw.println("externalVibrationScaleFactors = " + Arrays.toString(mExternalVibrationScaleFactors)); pw.println("rampStepDurationMs = " + mRampStepDurationMs); pw.println("rampStepDurationMs = " + mRampStepDurationMs); pw.println("rampDownDurationMs = " + mRampDownDurationMs); pw.println("rampDownDurationMs = " + mRampDownDurationMs); pw.println("requestVibrationParamsForUsages = " pw.println("requestVibrationParamsForUsages = " Loading
core/java/android/os/vibrator/flags.aconfig +10 −0 Original line number Original line Diff line number Diff line Loading @@ -146,3 +146,13 @@ flag { purpose: PURPOSE_BUGFIX purpose: PURPOSE_BUGFIX } } } } flag { namespace: "haptics" name: "vibration_scale_device_config_enabled" description: "Enables device-configurable vibration scale factors" bug: "427503922" metadata { purpose: PURPOSE_BUGFIX } }
core/res/res/values/config.xml +25 −0 Original line number Original line Diff line number Diff line Loading @@ -4390,6 +4390,31 @@ <!-- The default vibration strength, must be between 1 and 255 inclusive. --> <!-- The default vibration strength, must be between 1 and 255 inclusive. --> <integer name="config_defaultVibrationAmplitude">255</integer> <integer name="config_defaultVibrationAmplitude">255</integer> <!-- The scale factor to be applied at each vibration intensity level supported by the device, defined by a positive float value. The default framework scaling will be applied if this is not set, based on the user and the default scales for each usage. The number of entries here must be the device supported scale levels for LOW/MEDIUM/HIGH. Example: <string-array name="config_vibrationIntensityScaleFactors" translatable="false"> <item>0.5</item> -> Vibrator.VIBRATION_INTENSITY_LOW <item>0.7</item> -> Vibrator.VIBRATION_INTENSITY_MEDIUM <item>1.0</item> -> Vibrator.VIBRATION_INTENSITY_HIGH </string-array> --> <string-array name="config_vibrationIntensityScaleFactors" translatable="false" /> <!-- The scale factor to be applied for external vibrations only (i.e. audio-coupled haptics), defined by a positive float value. The values from config_vibrationIntensityScaleFactors will be used if this is not set. The number of entries here must be the device supported scale levels for LOW/MEDIUM/HIGH. Example: <string-array name="config_externalVibrationIntensityScaleFactors" translatable="false"> <item>0.3</item> -> Vibrator.VIBRATION_INTENSITY_LOW <item>0.5</item> -> Vibrator.VIBRATION_INTENSITY_MEDIUM <item>1.0</item> -> Vibrator.VIBRATION_INTENSITY_HIGH </string-array> --> <string-array name="config_externalVibrationIntensityScaleFactors" translatable="false" /> <!-- The max vibration strength allowed in audio haptic channels, must be positive or zero if <!-- The max vibration strength allowed in audio haptic channels, must be positive or zero if limit is unknown. --> limit is unknown. --> <item name="config_hapticChannelMaxVibrationAmplitude" format="float" type="dimen">0</item> <item name="config_hapticChannelMaxVibrationAmplitude" format="float" type="dimen">0</item> Loading