diff options
| author | Lais Andrade <lsandrade@google.com> | 2021-02-02 17:15:44 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2021-02-02 17:15:44 +0000 |
| commit | 14edd62216032f8756e7d7327328bdb96ed18b5b (patch) | |
| tree | 3a40852d043cb803ff76c67779be4a947ca88e70 /core/java/android | |
| parent | 277cfb354dc76da33cb7c2cfaa914cedf73e130c (diff) | |
| parent | 502e1ae7b76c942c1071450299c9e2f28e747d70 (diff) | |
Merge "Implement vibrate and cancelVibrate on VibratorManagerService" into sc-dev
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/os/CombinedVibrationEffect.java | 29 | ||||
| -rw-r--r-- | core/java/android/os/IVibratorManagerService.aidl | 4 |
2 files changed, 30 insertions, 3 deletions
diff --git a/core/java/android/os/CombinedVibrationEffect.java b/core/java/android/os/CombinedVibrationEffect.java index 869a72717f9f..cb4e9cba0977 100644 --- a/core/java/android/os/CombinedVibrationEffect.java +++ b/core/java/android/os/CombinedVibrationEffect.java @@ -364,8 +364,22 @@ public abstract class CombinedVibrationEffect implements Parcelable { @Override public long getDuration() { long maxDuration = Long.MIN_VALUE; + boolean hasUnknownStep = false; for (int i = 0; i < mEffects.size(); i++) { - maxDuration = Math.max(maxDuration, mEffects.valueAt(i).getDuration()); + long duration = mEffects.valueAt(i).getDuration(); + if (duration == Long.MAX_VALUE) { + // If any duration is repeating, this combination duration is also repeating. + return duration; + } + maxDuration = Math.max(maxDuration, duration); + // If any step is unknown, this combination duration will also be unknown, unless + // any step is repeating. Repeating vibrations take precedence over non-repeating + // ones in the service, so continue looping to check for repeating steps. + hasUnknownStep |= duration < 0; + } + if (hasUnknownStep) { + // If any step is unknown, this combination duration is also unknown. + return -1; } return maxDuration; } @@ -477,16 +491,25 @@ public abstract class CombinedVibrationEffect implements Parcelable { @Override public long getDuration() { + boolean hasUnknownStep = false; long durations = 0; final int effectCount = mEffects.size(); for (int i = 0; i < effectCount; i++) { CombinedVibrationEffect effect = mEffects.get(i); long duration = effect.getDuration(); - if (duration < 0) { - // If any duration is unknown, this combination duration is also unknown. + if (duration == Long.MAX_VALUE) { + // If any duration is repeating, this combination duration is also repeating. return duration; } durations += duration; + // If any step is unknown, this combination duration will also be unknown, unless + // any step is repeating. Repeating vibrations take precedence over non-repeating + // ones in the service, so continue looping to check for repeating steps. + hasUnknownStep |= duration < 0; + } + if (hasUnknownStep) { + // If any step is unknown, this combination duration is also unknown. + return -1; } long delays = 0; for (int i = 0; i < effectCount; i++) { diff --git a/core/java/android/os/IVibratorManagerService.aidl b/core/java/android/os/IVibratorManagerService.aidl index 804dc102c3f6..f9e294791cca 100644 --- a/core/java/android/os/IVibratorManagerService.aidl +++ b/core/java/android/os/IVibratorManagerService.aidl @@ -17,6 +17,7 @@ package android.os; import android.os.CombinedVibrationEffect; +import android.os.IVibratorStateListener; import android.os.VibrationAttributes; import android.os.VibratorInfo; @@ -24,6 +25,9 @@ import android.os.VibratorInfo; interface IVibratorManagerService { int[] getVibratorIds(); VibratorInfo getVibratorInfo(int vibratorId); + boolean isVibrating(int vibratorId); + boolean registerVibratorStateListener(int vibratorId, in IVibratorStateListener listener); + boolean unregisterVibratorStateListener(int vibratorId, in IVibratorStateListener listener); boolean setAlwaysOnEffect(int uid, String opPkg, int alwaysOnId, in CombinedVibrationEffect effect, in VibrationAttributes attributes); void vibrate(int uid, String opPkg, in CombinedVibrationEffect effect, |
