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

Commit a550801c authored by Tyler Freeman's avatar Tyler Freeman Committed by android-build-merger
Browse files

Merge "Vibrator: Allow priority vibrations in low-power mode for...

Merge "Vibrator: Allow priority vibrations in low-power mode for accessibility." into oc-dev am: ac36c42a
am: 8cb65392

Change-Id: I7abd446e96368b50eeff92ea134aeea6999f7c7a
parents ef762dc6 8cb65392
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -2580,6 +2580,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.
+1 −0
Original line number Diff line number Diff line
@@ -1815,6 +1815,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"/>
+25 −1
Original line number Diff line number Diff line
@@ -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();
@@ -461,7 +465,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");
            }
@@ -510,6 +514,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();