diff options
| author | 2017-06-07 06:33:03 +0000 | |
|---|---|---|
| committer | 2017-06-07 06:33:10 +0000 | |
| commit | ac36c42a865542a7fa294bfb3186d732fe4aebd3 (patch) | |
| tree | a99e202cfabb39190ccb01be4e6af2d551b69652 | |
| parent | d5ece513ec55584b9ea8874d149185170455290a (diff) | |
| parent | 319a34ae87def49d503c19b24d3e00a8f7442809 (diff) | |
Merge "Vibrator: Allow priority vibrations in low-power mode for accessibility." into oc-dev
| -rw-r--r-- | core/res/res/values/config.xml | 4 | ||||
| -rw-r--r-- | core/res/res/values/symbols.xml | 1 | ||||
| -rw-r--r-- | services/core/java/com/android/server/VibratorService.java | 26 |
3 files changed, 30 insertions, 1 deletions
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index ec0b0493c8d3..241e565c4280 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -2536,6 +2536,10 @@ <!-- The default vibration strength, must be between 1 and 255 inclusive. --> <integer name="config_defaultVibrationAmplitude">255</integer> + <!-- 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> + <!-- Number of retries Cell Data should attempt for a given error code before restarting the modem. Error codes not listed will not lead to modem restarts. diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 8678a3e68fa0..bdefd09e7627 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -1809,6 +1809,7 @@ <java-symbol type="dimen" name="default_minimal_size_pip_resizable_task" /> <java-symbol type="dimen" name="task_height_of_minimized_mode" /> <java-symbol type="fraction" name="config_screenAutoBrightnessDozeScaleFactor" /> + <java-symbol type="bool" name="config_allowPriorityVibrationsInLowPowerMode" /> <java-symbol type="fraction" name="config_autoBrightnessAdjustmentMaxGamma" /> <java-symbol type="integer" name="config_autoBrightnessAmbientLightHorizon"/> <java-symbol type="integer" name="config_autoBrightnessBrighteningLightDebounce"/> diff --git a/services/core/java/com/android/server/VibratorService.java b/services/core/java/com/android/server/VibratorService.java index 03e9dd2cc1ed..16e63b3e0e8f 100644 --- a/services/core/java/com/android/server/VibratorService.java +++ b/services/core/java/com/android/server/VibratorService.java @@ -73,6 +73,7 @@ public class VibratorService extends IVibratorService.Stub private final LinkedList<VibrationInfo> mPreviousVibrations; private final int mPreviousVibrationsLimit; + private final boolean mAllowPriorityVibrationsInLowPowerMode; private final boolean mSupportsAmplitudeControl; private final int mDefaultVibrationAmplitude; private final VibrationEffect[] mFallbackEffects; @@ -213,6 +214,9 @@ public class VibratorService extends IVibratorService.Stub mDefaultVibrationAmplitude = mContext.getResources().getInteger( com.android.internal.R.integer.config_defaultVibrationAmplitude); + mAllowPriorityVibrationsInLowPowerMode = mContext.getResources().getBoolean( + com.android.internal.R.bool.config_allowPriorityVibrationsInLowPowerMode); + mPreviousVibrations = new LinkedList<>(); IntentFilter filter = new IntentFilter(); @@ -456,7 +460,7 @@ public class VibratorService extends IVibratorService.Stub } private void startVibrationLocked(final Vibration vib) { - if (mLowPowerMode && vib.mUsageHint != AudioAttributes.USAGE_NOTIFICATION_RINGTONE) { + if (!isAllowedToVibrate(vib)) { if (DEBUG) { Slog.e(TAG, "Vibrate ignored, low power mode"); } @@ -505,6 +509,26 @@ public class VibratorService extends IVibratorService.Stub } } + private boolean isAllowedToVibrate(Vibration vib) { + if (!mLowPowerMode) { + return true; + } + if (vib.mUsageHint == AudioAttributes.USAGE_NOTIFICATION_RINGTONE) { + return true; + } + if (!mAllowPriorityVibrationsInLowPowerMode) { + return false; + } + if (vib.mUsageHint == AudioAttributes.USAGE_ALARM || + vib.mUsageHint == AudioAttributes.USAGE_ASSISTANCE_ACCESSIBILITY || + vib.mUsageHint == AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_REQUEST) { + + return true; + } + + return false; + } + private boolean shouldVibrateForRingtone() { AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); int ringerMode = audioManager.getRingerModeInternal(); |