Loading core/java/android/os/Vibrator.java +28 −3 Original line number Diff line number Diff line Loading @@ -126,6 +126,7 @@ public abstract class Vibrator { // The default vibration intensity level for ringtones. @VibrationIntensity private int mDefaultRingVibrationIntensity; private float mHapticChannelMaxVibrationAmplitude; /** * @hide to prevent subclassing from outside of the framework Loading @@ -134,7 +135,7 @@ public abstract class Vibrator { public Vibrator() { mPackageName = ActivityThread.currentPackageName(); final Context ctx = ActivityThread.currentActivityThread().getSystemContext(); loadVibrationIntensities(ctx); loadVibrationConfig(ctx); } /** Loading @@ -142,22 +143,28 @@ public abstract class Vibrator { */ protected Vibrator(Context context) { mPackageName = context.getOpPackageName(); loadVibrationIntensities(context); loadVibrationConfig(context); } private void loadVibrationIntensities(Context context) { private void loadVibrationConfig(Context context) { mDefaultHapticFeedbackIntensity = loadDefaultIntensity(context, com.android.internal.R.integer.config_defaultHapticFeedbackIntensity); mDefaultNotificationVibrationIntensity = loadDefaultIntensity(context, com.android.internal.R.integer.config_defaultNotificationVibrationIntensity); mDefaultRingVibrationIntensity = loadDefaultIntensity(context, com.android.internal.R.integer.config_defaultRingVibrationIntensity); mHapticChannelMaxVibrationAmplitude = loadFloat(context, com.android.internal.R.dimen.config_hapticChannelMaxVibrationAmplitude, 0); } private int loadDefaultIntensity(Context ctx, int resId) { return ctx != null ? ctx.getResources().getInteger(resId) : VIBRATION_INTENSITY_MEDIUM; } private float loadFloat(Context ctx, int resId, float defaultValue) { return ctx != null ? ctx.getResources().getFloat(resId) : defaultValue; } /** @hide */ protected VibratorInfo getInfo() { return VibratorInfo.EMPTY_VIBRATOR_INFO; Loading Loading @@ -296,6 +303,24 @@ public abstract class Vibrator { return getInfo().getMaxAmplitude(relativeFrequency); } /** * Return the maximum amplitude the vibrator can play using the audio haptic channels. * * <p>This is a positive value, or {@link Float#NaN NaN} if it's unknown. If this returns a * positive value <code>maxAmplitude</code>, then the signals from the haptic channels of audio * tracks should be in the range <code>[-maxAmplitude, maxAmplitude]</code>. * * @return a positive value representing the maximum absolute value the device can play signals * from audio haptic channels, or {@link Float#NaN NaN} if it's unknown. * @hide */ public float getHapticChannelMaximumAmplitude() { if (mHapticChannelMaxVibrationAmplitude <= 0) { return Float.NaN; } return mHapticChannelMaxVibrationAmplitude; } /** * Configure an always-on haptics effect. * Loading core/res/res/values/config.xml +4 −0 Original line number Diff line number Diff line Loading @@ -3350,6 +3350,10 @@ <!-- The default vibration strength, must be between 1 and 255 inclusive. --> <integer name="config_defaultVibrationAmplitude">255</integer> <!-- The max vibration strength allowed in audio haptic channels, must be positive or zero if limit is unknown. --> <item name="config_hapticChannelMaxVibrationAmplitude" format="float" type="dimen">0</item> <!-- If the device should still vibrate even in low power mode, for certain priority vibrations (e.g. accessibility, alarms). This is mainly for Wear devices that don't have speakers. --> <bool name="config_allowPriorityVibrationsInLowPowerMode">false</bool> Loading core/res/res/values/symbols.xml +1 −0 Original line number Diff line number Diff line Loading @@ -2013,6 +2013,7 @@ <java-symbol type="integer" name="config_notificationServiceArchiveSize" /> <java-symbol type="integer" name="config_previousVibrationsDumpLimit" /> <java-symbol type="integer" name="config_defaultVibrationAmplitude" /> <java-symbol type="dimen" name="config_hapticChannelMaxVibrationAmplitude" /> <java-symbol type="integer" name="config_vibrationWaveformRampStepDuration" /> <java-symbol type="integer" name="config_vibrationWaveformRampDownDuration" /> <java-symbol type="integer" name="config_radioScanningTimeout" /> Loading services/core/java/com/android/server/vibrator/VibrationSettings.java +7 −0 Original line number Diff line number Diff line Loading @@ -353,6 +353,7 @@ final class VibrationSettings { + ", mLowPowerMode=" + mLowPowerMode + ", mZenMode=" + Settings.Global.zenModeToString(mZenMode) + ", mProcStatesCache=" + mUidObserver.mProcStatesCache + ", mHapticChannelMaxVibrationAmplitude=" + getHapticChannelMaxVibrationAmplitude() + ", mHapticFeedbackIntensity=" + intensityToString(getCurrentIntensity(VibrationAttributes.USAGE_TOUCH)) + ", mHapticFeedbackDefaultIntensity=" Loading Loading @@ -411,6 +412,12 @@ final class VibrationSettings { } } private float getHapticChannelMaxVibrationAmplitude() { synchronized (mLock) { return mVibrator == null ? Float.NaN : mVibrator.getHapticChannelMaximumAmplitude(); } } private int getSystemSetting(String settingName, int defaultValue) { return Settings.System.getIntForUser(mContext.getContentResolver(), settingName, defaultValue, UserHandle.USER_CURRENT); Loading Loading
core/java/android/os/Vibrator.java +28 −3 Original line number Diff line number Diff line Loading @@ -126,6 +126,7 @@ public abstract class Vibrator { // The default vibration intensity level for ringtones. @VibrationIntensity private int mDefaultRingVibrationIntensity; private float mHapticChannelMaxVibrationAmplitude; /** * @hide to prevent subclassing from outside of the framework Loading @@ -134,7 +135,7 @@ public abstract class Vibrator { public Vibrator() { mPackageName = ActivityThread.currentPackageName(); final Context ctx = ActivityThread.currentActivityThread().getSystemContext(); loadVibrationIntensities(ctx); loadVibrationConfig(ctx); } /** Loading @@ -142,22 +143,28 @@ public abstract class Vibrator { */ protected Vibrator(Context context) { mPackageName = context.getOpPackageName(); loadVibrationIntensities(context); loadVibrationConfig(context); } private void loadVibrationIntensities(Context context) { private void loadVibrationConfig(Context context) { mDefaultHapticFeedbackIntensity = loadDefaultIntensity(context, com.android.internal.R.integer.config_defaultHapticFeedbackIntensity); mDefaultNotificationVibrationIntensity = loadDefaultIntensity(context, com.android.internal.R.integer.config_defaultNotificationVibrationIntensity); mDefaultRingVibrationIntensity = loadDefaultIntensity(context, com.android.internal.R.integer.config_defaultRingVibrationIntensity); mHapticChannelMaxVibrationAmplitude = loadFloat(context, com.android.internal.R.dimen.config_hapticChannelMaxVibrationAmplitude, 0); } private int loadDefaultIntensity(Context ctx, int resId) { return ctx != null ? ctx.getResources().getInteger(resId) : VIBRATION_INTENSITY_MEDIUM; } private float loadFloat(Context ctx, int resId, float defaultValue) { return ctx != null ? ctx.getResources().getFloat(resId) : defaultValue; } /** @hide */ protected VibratorInfo getInfo() { return VibratorInfo.EMPTY_VIBRATOR_INFO; Loading Loading @@ -296,6 +303,24 @@ public abstract class Vibrator { return getInfo().getMaxAmplitude(relativeFrequency); } /** * Return the maximum amplitude the vibrator can play using the audio haptic channels. * * <p>This is a positive value, or {@link Float#NaN NaN} if it's unknown. If this returns a * positive value <code>maxAmplitude</code>, then the signals from the haptic channels of audio * tracks should be in the range <code>[-maxAmplitude, maxAmplitude]</code>. * * @return a positive value representing the maximum absolute value the device can play signals * from audio haptic channels, or {@link Float#NaN NaN} if it's unknown. * @hide */ public float getHapticChannelMaximumAmplitude() { if (mHapticChannelMaxVibrationAmplitude <= 0) { return Float.NaN; } return mHapticChannelMaxVibrationAmplitude; } /** * Configure an always-on haptics effect. * Loading
core/res/res/values/config.xml +4 −0 Original line number Diff line number Diff line Loading @@ -3350,6 +3350,10 @@ <!-- The default vibration strength, must be between 1 and 255 inclusive. --> <integer name="config_defaultVibrationAmplitude">255</integer> <!-- The max vibration strength allowed in audio haptic channels, must be positive or zero if limit is unknown. --> <item name="config_hapticChannelMaxVibrationAmplitude" format="float" type="dimen">0</item> <!-- If the device should still vibrate even in low power mode, for certain priority vibrations (e.g. accessibility, alarms). This is mainly for Wear devices that don't have speakers. --> <bool name="config_allowPriorityVibrationsInLowPowerMode">false</bool> Loading
core/res/res/values/symbols.xml +1 −0 Original line number Diff line number Diff line Loading @@ -2013,6 +2013,7 @@ <java-symbol type="integer" name="config_notificationServiceArchiveSize" /> <java-symbol type="integer" name="config_previousVibrationsDumpLimit" /> <java-symbol type="integer" name="config_defaultVibrationAmplitude" /> <java-symbol type="dimen" name="config_hapticChannelMaxVibrationAmplitude" /> <java-symbol type="integer" name="config_vibrationWaveformRampStepDuration" /> <java-symbol type="integer" name="config_vibrationWaveformRampDownDuration" /> <java-symbol type="integer" name="config_radioScanningTimeout" /> Loading
services/core/java/com/android/server/vibrator/VibrationSettings.java +7 −0 Original line number Diff line number Diff line Loading @@ -353,6 +353,7 @@ final class VibrationSettings { + ", mLowPowerMode=" + mLowPowerMode + ", mZenMode=" + Settings.Global.zenModeToString(mZenMode) + ", mProcStatesCache=" + mUidObserver.mProcStatesCache + ", mHapticChannelMaxVibrationAmplitude=" + getHapticChannelMaxVibrationAmplitude() + ", mHapticFeedbackIntensity=" + intensityToString(getCurrentIntensity(VibrationAttributes.USAGE_TOUCH)) + ", mHapticFeedbackDefaultIntensity=" Loading Loading @@ -411,6 +412,12 @@ final class VibrationSettings { } } private float getHapticChannelMaxVibrationAmplitude() { synchronized (mLock) { return mVibrator == null ? Float.NaN : mVibrator.getHapticChannelMaximumAmplitude(); } } private int getSystemSetting(String settingName, int defaultValue) { return Settings.System.getIntForUser(mContext.getContentResolver(), settingName, defaultValue, UserHandle.USER_CURRENT); Loading