Vibrator: Allow priority vibrations in low-power mode for accessibility.
This is mainly for Wear devices that don't have speakers. Bug: 37543478 Test: Manual: 1. Activate low power mode `adb shell dumpsys battery unplug && adb shell settings put global low_power 1` 2. Then see if Alarm/Timer will vibrate. 3. Send a Hangout Test notification, make sure it does NOT vibrate. On phones there should be no change. Alarms will not vibrate. Change-Id: Ia6dffa7e528886e7c84390dbb33b44f298c7afa4
This commit is contained in:
@@ -2531,6 +2531,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.
|
||||
|
||||
@@ -1808,6 +1808,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"/>
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user