diff --git a/services/core/java/com/android/server/vibrator/HalVibration.java b/services/core/java/com/android/server/vibrator/HalVibration.java new file mode 100644 index 0000000000000..53f04d7209cee --- /dev/null +++ b/services/core/java/com/android/server/vibrator/HalVibration.java @@ -0,0 +1,219 @@ +/* + * Copyright (C) 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.server.vibrator; + +import android.annotation.Nullable; +import android.os.CombinedVibration; +import android.os.IBinder; +import android.os.VibrationAttributes; +import android.os.VibrationEffect; +import android.util.SparseArray; + +import com.android.internal.util.FrameworkStatsLog; + +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.function.Function; + +/** + * Represents a vibration defined by a {@link CombinedVibration} that will be performed by + * the IVibrator HAL. + */ +final class HalVibration extends Vibration { + + public final VibrationAttributes attrs; + public final long id; + public final int uid; + public final int displayId; + public final String opPkg; + public final String reason; + public final IBinder token; + public final SparseArray mFallbacks = new SparseArray<>(); + + /** The actual effect to be played. */ + @Nullable + private CombinedVibration mEffect; + + /** + * The original effect that was requested. Typically these two things differ because the effect + * was scaled based on the users vibration intensity settings. + */ + @Nullable + private CombinedVibration mOriginalEffect; + + /** Vibration status. */ + private Vibration.Status mStatus; + + /** Vibration runtime stats. */ + private final VibrationStats mStats = new VibrationStats(); + + /** A {@link CountDownLatch} to enable waiting for completion. */ + private final CountDownLatch mCompletionLatch = new CountDownLatch(1); + + HalVibration(IBinder token, int id, CombinedVibration effect, + VibrationAttributes attrs, int uid, int displayId, String opPkg, String reason) { + this.token = token; + this.mEffect = effect; + this.id = id; + this.attrs = attrs; + this.uid = uid; + this.displayId = displayId; + this.opPkg = opPkg; + this.reason = reason; + mStatus = Vibration.Status.RUNNING; + } + + VibrationStats stats() { + return mStats; + } + + /** + * Set the {@link Status} of this vibration and reports the current system time as this + * vibration end time, for debugging purposes. + * + *

This method will only accept given value if the current status is {@link + * Status#RUNNING}. + */ + public void end(EndInfo info) { + if (hasEnded()) { + // Vibration already ended, keep first ending status set and ignore this one. + return; + } + mStatus = info.status; + mStats.reportEnded(info.endedByUid, info.endedByUsage); + mCompletionLatch.countDown(); + } + + /** Waits indefinitely until another thread calls {@link #end} on this vibration. */ + public void waitForEnd() throws InterruptedException { + mCompletionLatch.await(); + } + + /** + * Return the effect to be played when given prebaked effect id is not supported by the + * vibrator. + */ + @Nullable + public VibrationEffect getFallback(int effectId) { + return mFallbacks.get(effectId); + } + + /** + * Add a fallback {@link VibrationEffect} to be played when given effect id is not supported, + * which might be necessary for replacement in realtime. + */ + public void addFallback(int effectId, VibrationEffect effect) { + mFallbacks.put(effectId, effect); + } + + /** + * Applied update function to the current effect held by this vibration, and to each fallback + * effect added. + */ + public void updateEffects(Function updateFn) { + CombinedVibration newEffect = transformCombinedEffect(mEffect, updateFn); + if (!newEffect.equals(mEffect)) { + if (mOriginalEffect == null) { + mOriginalEffect = mEffect; + } + mEffect = newEffect; + } + for (int i = 0; i < mFallbacks.size(); i++) { + mFallbacks.setValueAt(i, updateFn.apply(mFallbacks.valueAt(i))); + } + } + + /** + * Creates a new {@link CombinedVibration} by applying the given transformation function + * to each {@link VibrationEffect}. + */ + private static CombinedVibration transformCombinedEffect( + CombinedVibration combinedEffect, Function fn) { + if (combinedEffect instanceof CombinedVibration.Mono) { + VibrationEffect effect = ((CombinedVibration.Mono) combinedEffect).getEffect(); + return CombinedVibration.createParallel(fn.apply(effect)); + } else if (combinedEffect instanceof CombinedVibration.Stereo) { + SparseArray effects = + ((CombinedVibration.Stereo) combinedEffect).getEffects(); + CombinedVibration.ParallelCombination combination = + CombinedVibration.startParallel(); + for (int i = 0; i < effects.size(); i++) { + combination.addVibrator(effects.keyAt(i), fn.apply(effects.valueAt(i))); + } + return combination.combine(); + } else if (combinedEffect instanceof CombinedVibration.Sequential) { + List effects = + ((CombinedVibration.Sequential) combinedEffect).getEffects(); + CombinedVibration.SequentialCombination combination = + CombinedVibration.startSequential(); + for (CombinedVibration effect : effects) { + combination.addNext(transformCombinedEffect(effect, fn)); + } + return combination.combine(); + } else { + // Unknown combination, return same effect. + return combinedEffect; + } + } + + /** Return true is current status is different from {@link Status#RUNNING}. */ + public boolean hasEnded() { + return mStatus != Status.RUNNING; + } + + /** Return true is effect is a repeating vibration. */ + public boolean isRepeating() { + return mEffect.getDuration() == Long.MAX_VALUE; + } + + /** Return the effect that should be played by this vibration. */ + @Nullable + public CombinedVibration getEffect() { + return mEffect; + } + + /** + * Return {@link Vibration.DebugInfo} with read-only debug information about this vibration. + */ + public Vibration.DebugInfo getDebugInfo() { + return new Vibration.DebugInfo(mStatus, mStats, mEffect, mOriginalEffect, /* scale= */ 0, + attrs, uid, displayId, opPkg, reason); + } + + /** Return {@link VibrationStats.StatsInfo} with read-only metrics about this vibration. */ + public VibrationStats.StatsInfo getStatsInfo(long completionUptimeMillis) { + int vibrationType = isRepeating() + ? FrameworkStatsLog.VIBRATION_REPORTED__VIBRATION_TYPE__REPEATED + : FrameworkStatsLog.VIBRATION_REPORTED__VIBRATION_TYPE__SINGLE; + return new VibrationStats.StatsInfo( + uid, vibrationType, attrs.getUsage(), mStatus, mStats, completionUptimeMillis); + } + + /** + * Returns true if this vibration can pipeline with the specified one. + * + *

Note that currently, repeating vibrations can't pipeline with following vibrations, + * because the cancel() call to stop the repetition will cancel a pending vibration too. This + * can be changed if we have a use-case to reason around behavior for. It may also be nice to + * pipeline very short vibrations together, regardless of the flag. + */ + public boolean canPipelineWith(HalVibration vib) { + return uid == vib.uid && attrs.isFlagSet(VibrationAttributes.FLAG_PIPELINED_EFFECT) + && vib.attrs.isFlagSet(VibrationAttributes.FLAG_PIPELINED_EFFECT) + && !isRepeating(); + } +} diff --git a/services/core/java/com/android/server/vibrator/Step.java b/services/core/java/com/android/server/vibrator/Step.java index 042e8a0e6ad52..5faa51687c9fe 100644 --- a/services/core/java/com/android/server/vibrator/Step.java +++ b/services/core/java/com/android/server/vibrator/Step.java @@ -38,7 +38,7 @@ abstract class Step implements Comparable { this.startTime = startTime; } - protected Vibration getVibration() { + protected HalVibration getVibration() { return conductor.getVibration(); } diff --git a/services/core/java/com/android/server/vibrator/Vibration.java b/services/core/java/com/android/server/vibrator/Vibration.java index a451ee28ff095..5667c72db5dd7 100644 --- a/services/core/java/com/android/server/vibrator/Vibration.java +++ b/services/core/java/com/android/server/vibrator/Vibration.java @@ -19,7 +19,6 @@ package com.android.server.vibrator; import android.annotation.NonNull; import android.annotation.Nullable; import android.os.CombinedVibration; -import android.os.IBinder; import android.os.VibrationAttributes; import android.os.VibrationEffect; import android.os.vibrator.PrebakedSegment; @@ -27,20 +26,16 @@ import android.os.vibrator.PrimitiveSegment; import android.os.vibrator.RampSegment; import android.os.vibrator.StepSegment; import android.os.vibrator.VibrationEffectSegment; -import android.util.SparseArray; import android.util.proto.ProtoOutputStream; -import com.android.internal.util.FrameworkStatsLog; - import java.text.SimpleDateFormat; import java.util.Date; -import java.util.List; import java.util.Objects; -import java.util.concurrent.CountDownLatch; -import java.util.function.Function; -/** Represents a vibration request to the vibrator service. */ -final class Vibration { +/** + * The base class for all vibrations. + */ +class Vibration { private static final SimpleDateFormat DEBUG_DATE_FORMAT = new SimpleDateFormat("MM-dd HH:mm:ss.SSS"); @@ -85,186 +80,6 @@ final class Vibration { } } - public final VibrationAttributes attrs; - public final long id; - public final int uid; - public final int displayId; - public final String opPkg; - public final String reason; - public final IBinder token; - public final SparseArray mFallbacks = new SparseArray<>(); - - /** The actual effect to be played. */ - @Nullable - private CombinedVibration mEffect; - - /** - * The original effect that was requested. Typically these two things differ because the effect - * was scaled based on the users vibration intensity settings. - */ - @Nullable - private CombinedVibration mOriginalEffect; - - /** Vibration status. */ - private Vibration.Status mStatus; - - /** Vibration runtime stats. */ - private final VibrationStats mStats = new VibrationStats(); - - /** A {@link CountDownLatch} to enable waiting for completion. */ - private final CountDownLatch mCompletionLatch = new CountDownLatch(1); - - Vibration(IBinder token, int id, CombinedVibration effect, - VibrationAttributes attrs, int uid, int displayId, String opPkg, String reason) { - this.token = token; - this.mEffect = effect; - this.id = id; - this.attrs = attrs; - this.uid = uid; - this.displayId = displayId; - this.opPkg = opPkg; - this.reason = reason; - mStatus = Vibration.Status.RUNNING; - } - - VibrationStats stats() { - return mStats; - } - - /** - * Set the {@link Status} of this vibration and reports the current system time as this - * vibration end time, for debugging purposes. - * - *

This method will only accept given value if the current status is {@link - * Status#RUNNING}. - */ - public void end(EndInfo info) { - if (hasEnded()) { - // Vibration already ended, keep first ending status set and ignore this one. - return; - } - mStatus = info.status; - mStats.reportEnded(info.endedByUid, info.endedByUsage); - mCompletionLatch.countDown(); - } - - /** Waits indefinitely until another thread calls {@link #end} on this vibration. */ - public void waitForEnd() throws InterruptedException { - mCompletionLatch.await(); - } - - /** - * Return the effect to be played when given prebaked effect id is not supported by the - * vibrator. - */ - @Nullable - public VibrationEffect getFallback(int effectId) { - return mFallbacks.get(effectId); - } - - /** - * Add a fallback {@link VibrationEffect} to be played when given effect id is not supported, - * which might be necessary for replacement in realtime. - */ - public void addFallback(int effectId, VibrationEffect effect) { - mFallbacks.put(effectId, effect); - } - - /** - * Applied update function to the current effect held by this vibration, and to each fallback - * effect added. - */ - public void updateEffects(Function updateFn) { - CombinedVibration newEffect = transformCombinedEffect(mEffect, updateFn); - if (!newEffect.equals(mEffect)) { - if (mOriginalEffect == null) { - mOriginalEffect = mEffect; - } - mEffect = newEffect; - } - for (int i = 0; i < mFallbacks.size(); i++) { - mFallbacks.setValueAt(i, updateFn.apply(mFallbacks.valueAt(i))); - } - } - - /** - * Creates a new {@link CombinedVibration} by applying the given transformation function - * to each {@link VibrationEffect}. - */ - private static CombinedVibration transformCombinedEffect( - CombinedVibration combinedEffect, Function fn) { - if (combinedEffect instanceof CombinedVibration.Mono) { - VibrationEffect effect = ((CombinedVibration.Mono) combinedEffect).getEffect(); - return CombinedVibration.createParallel(fn.apply(effect)); - } else if (combinedEffect instanceof CombinedVibration.Stereo) { - SparseArray effects = - ((CombinedVibration.Stereo) combinedEffect).getEffects(); - CombinedVibration.ParallelCombination combination = - CombinedVibration.startParallel(); - for (int i = 0; i < effects.size(); i++) { - combination.addVibrator(effects.keyAt(i), fn.apply(effects.valueAt(i))); - } - return combination.combine(); - } else if (combinedEffect instanceof CombinedVibration.Sequential) { - List effects = - ((CombinedVibration.Sequential) combinedEffect).getEffects(); - CombinedVibration.SequentialCombination combination = - CombinedVibration.startSequential(); - for (CombinedVibration effect : effects) { - combination.addNext(transformCombinedEffect(effect, fn)); - } - return combination.combine(); - } else { - // Unknown combination, return same effect. - return combinedEffect; - } - } - - /** Return true is current status is different from {@link Status#RUNNING}. */ - public boolean hasEnded() { - return mStatus != Status.RUNNING; - } - - /** Return true is effect is a repeating vibration. */ - public boolean isRepeating() { - return mEffect.getDuration() == Long.MAX_VALUE; - } - - /** Return the effect that should be played by this vibration. */ - @Nullable - public CombinedVibration getEffect() { - return mEffect; - } - - /** Return {@link Vibration.DebugInfo} with read-only debug information about this vibration. */ - public Vibration.DebugInfo getDebugInfo() { - return new Vibration.DebugInfo(mStatus, mStats, mEffect, mOriginalEffect, /* scale= */ 0, - attrs, uid, displayId, opPkg, reason); - } - - /** Return {@link VibrationStats.StatsInfo} with read-only metrics about this vibration. */ - public VibrationStats.StatsInfo getStatsInfo(long completionUptimeMillis) { - int vibrationType = isRepeating() - ? FrameworkStatsLog.VIBRATION_REPORTED__VIBRATION_TYPE__REPEATED - : FrameworkStatsLog.VIBRATION_REPORTED__VIBRATION_TYPE__SINGLE; - return new VibrationStats.StatsInfo( - uid, vibrationType, attrs.getUsage(), mStatus, mStats, completionUptimeMillis); - } - - /** - * Returns true if this vibration can pipeline with the specified one. - * - *

Note that currently, repeating vibrations can't pipeline with following vibrations, - * because the cancel() call to stop the repetition will cancel a pending vibration too. This - * can be changed if we have a use-case to reason around behavior for. It may also be nice to - * pipeline very short vibrations together, regardless of the flag. - */ - public boolean canPipelineWith(Vibration vib) { - return uid == vib.uid && attrs.isFlagSet(VibrationAttributes.FLAG_PIPELINED_EFFECT) - && vib.attrs.isFlagSet(VibrationAttributes.FLAG_PIPELINED_EFFECT) - && !isRepeating(); - } - /** Immutable info passed as a signal to end a vibration. */ static final class EndInfo { /** The {@link Status} to be set to the vibration when it ends with this info. */ @@ -505,5 +320,4 @@ final class Vibration { proto.end(token); } } - } diff --git a/services/core/java/com/android/server/vibrator/VibrationStepConductor.java b/services/core/java/com/android/server/vibrator/VibrationStepConductor.java index 141be702ee13e..11cab4b83fb85 100644 --- a/services/core/java/com/android/server/vibrator/VibrationStepConductor.java +++ b/services/core/java/com/android/server/vibrator/VibrationStepConductor.java @@ -68,7 +68,7 @@ final class VibrationStepConductor implements IBinder.DeathRecipient { // Not guarded by lock because they're not modified by this conductor, it's used here only to // check immutable attributes. The status and other mutable states are changed by the service or // by the vibrator steps. - private final Vibration mVibration; + private final HalVibration mVibration; private final SparseArray mVibrators = new SparseArray<>(); private final PriorityQueue mNextSteps = new PriorityQueue<>(); @@ -95,7 +95,7 @@ final class VibrationStepConductor implements IBinder.DeathRecipient { private int mRemainingStartSequentialEffectSteps; private int mSuccessfulVibratorOnSteps; - VibrationStepConductor(Vibration vib, VibrationSettings vibrationSettings, + VibrationStepConductor(HalVibration vib, VibrationSettings vibrationSettings, DeviceVibrationEffectAdapter effectAdapter, SparseArray availableVibrators, VibrationThread.VibratorManagerHooks vibratorManagerHooks) { @@ -160,7 +160,7 @@ final class VibrationStepConductor implements IBinder.DeathRecipient { mVibration.stats().reportStarted(); } - public Vibration getVibration() { + public HalVibration getVibration() { // No thread assertion: immutable return mVibration; } diff --git a/services/core/java/com/android/server/vibrator/VibrationThread.java b/services/core/java/com/android/server/vibrator/VibrationThread.java index 3fd9594723b5d..d2dc43c68e5de 100644 --- a/services/core/java/com/android/server/vibrator/VibrationThread.java +++ b/services/core/java/com/android/server/vibrator/VibrationThread.java @@ -33,12 +33,12 @@ import com.android.internal.annotations.VisibleForTesting; import java.util.NoSuchElementException; import java.util.Objects; -/** Plays a {@link Vibration} in dedicated thread. */ +/** Plays a {@link HalVibration} in dedicated thread. */ final class VibrationThread extends Thread { static final String TAG = "VibrationThread"; static final boolean DEBUG = false; - /** Calls into VibratorManager functionality needed for playing a {@link Vibration}. */ + /** Calls into VibratorManager functionality needed for playing a {@link HalVibration}. */ interface VibratorManagerHooks { /** diff --git a/services/core/java/com/android/server/vibrator/VibratorManagerService.java b/services/core/java/com/android/server/vibrator/VibratorManagerService.java index 966329e486f9b..c87332d2ff36b 100644 --- a/services/core/java/com/android/server/vibrator/VibratorManagerService.java +++ b/services/core/java/com/android/server/vibrator/VibratorManagerService.java @@ -385,12 +385,13 @@ public class VibratorManagerService extends IVibratorManagerService.Stub { } /** - * An internal-only version of vibrate that allows the caller access to the {@link Vibration}. + * An internal-only version of vibrate that allows the caller access to the + * {@link HalVibration}. * The Vibration is only returned if it is ongoing after this method returns. */ @VisibleForTesting @Nullable - Vibration vibrateInternal(int uid, int displayId, String opPkg, + HalVibration vibrateInternal(int uid, int displayId, String opPkg, @NonNull CombinedVibration effect, @Nullable VibrationAttributes attrs, String reason, IBinder token) { Trace.traceBegin(Trace.TRACE_TAG_VIBRATOR, "vibrate, reason = " + reason); @@ -407,8 +408,8 @@ public class VibratorManagerService extends IVibratorManagerService.Stub { } attrs = fixupVibrationAttributes(attrs, effect); // Create Vibration.Stats as close to the received request as possible, for tracking. - Vibration vib = new Vibration(token, mNextVibrationId.getAndIncrement(), effect, attrs, - uid, displayId, opPkg, reason); + HalVibration vib = new HalVibration(token, mNextVibrationId.getAndIncrement(), effect, + attrs, uid, displayId, opPkg, reason); fillVibrationFallbacks(vib, effect); if (attrs.isFlagSet(VibrationAttributes.FLAG_INVALIDATE_SETTINGS_CACHE)) { @@ -639,7 +640,7 @@ public class VibratorManagerService extends IVibratorManagerService.Stub { return; } - Vibration vib = mCurrentVibration.getVibration(); + HalVibration vib = mCurrentVibration.getVibration(); Vibration.Status ignoreStatus = shouldIgnoreVibrationLocked( vib.uid, vib.displayId, vib.opPkg, vib.attrs); @@ -683,7 +684,7 @@ public class VibratorManagerService extends IVibratorManagerService.Stub { } @GuardedBy("mLock") - private Vibration.Status startVibrationLocked(Vibration vib) { + private Vibration.Status startVibrationLocked(HalVibration vib) { Trace.traceBegin(Trace.TRACE_TAG_VIBRATOR, "startVibrationLocked"); try { vib.updateEffects(effect -> mVibrationScaler.scale(effect, vib.attrs.getUsage())); @@ -716,7 +717,7 @@ public class VibratorManagerService extends IVibratorManagerService.Stub { private Vibration.Status startVibrationOnThreadLocked(VibrationStepConductor conductor) { Trace.traceBegin(Trace.TRACE_TAG_VIBRATOR, "startVibrationThreadLocked"); try { - Vibration vib = conductor.getVibration(); + HalVibration vib = conductor.getVibration(); int mode = startAppOpModeLocked(vib.uid, vib.opPkg, vib.attrs); switch (mode) { case AppOpsManager.MODE_ALLOWED: @@ -741,7 +742,7 @@ public class VibratorManagerService extends IVibratorManagerService.Stub { } @GuardedBy("mLock") - private void endVibrationLocked(Vibration vib, Vibration.EndInfo vibrationEndInfo, + private void endVibrationLocked(HalVibration vib, Vibration.EndInfo vibrationEndInfo, boolean shouldWriteStats) { vib.end(vibrationEndInfo); logVibrationStatus(vib.uid, vib.attrs, vibrationEndInfo.status); @@ -763,7 +764,8 @@ public class VibratorManagerService extends IVibratorManagerService.Stub { vib.getStatsInfo(/* completionUptimeMillis= */ SystemClock.uptimeMillis())); } - private void logVibrationStatus(int uid, VibrationAttributes attrs, Vibration.Status status) { + private void logVibrationStatus(int uid, VibrationAttributes attrs, + Vibration.Status status) { switch (status) { case IGNORED_BACKGROUND: Slog.e(TAG, "Ignoring incoming vibration as process with" @@ -813,7 +815,7 @@ public class VibratorManagerService extends IVibratorManagerService.Stub { Trace.traceBegin(Trace.TRACE_TAG_VIBRATOR, "reportFinishVibrationLocked"); Trace.asyncTraceEnd(Trace.TRACE_TAG_VIBRATOR, "vibration", 0); try { - Vibration vib = mCurrentVibration.getVibration(); + HalVibration vib = mCurrentVibration.getVibration(); if (DEBUG) { Slog.d(TAG, "Reporting vibration " + vib.id + " finished with " + vibrationEndInfo); } @@ -857,13 +859,13 @@ public class VibratorManagerService extends IVibratorManagerService.Stub { */ @GuardedBy("mLock") @Nullable - private Vibration.Status shouldIgnoreVibrationForOngoingLocked(Vibration vib) { + private Vibration.Status shouldIgnoreVibrationForOngoingLocked(HalVibration vib) { if (mCurrentVibration == null || vib.isRepeating()) { // Incoming repeating vibrations always take precedence over ongoing vibrations. return null; } - Vibration currentVibration = mCurrentVibration.getVibration(); + HalVibration currentVibration = mCurrentVibration.getVibration(); if (currentVibration.hasEnded() || mCurrentVibration.wasNotifiedToCancel()) { // Current vibration has ended or is cancelling, should not block incoming vibrations. return null; @@ -945,7 +947,7 @@ public class VibratorManagerService extends IVibratorManagerService.Stub { * @param token The binder token to identify the vibration origin. Only vibrations * started with the same token can be cancelled with it. */ - private boolean shouldCancelVibration(Vibration vib, int usageFilter, IBinder token) { + private boolean shouldCancelVibration(HalVibration vib, int usageFilter, IBinder token) { return (vib.token == token) && shouldCancelVibration(vib.attrs, usageFilter); } @@ -1041,7 +1043,7 @@ public class VibratorManagerService extends IVibratorManagerService.Stub { * Sets fallback effects to all prebaked ones in given combination of effects, based on {@link * VibrationSettings#getFallbackEffect}. */ - private void fillVibrationFallbacks(Vibration vib, CombinedVibration effect) { + private void fillVibrationFallbacks(HalVibration vib, CombinedVibration effect) { if (effect instanceof CombinedVibration.Mono) { fillVibrationFallbacks(vib, ((CombinedVibration.Mono) effect).getEffect()); } else if (effect instanceof CombinedVibration.Stereo) { @@ -1059,7 +1061,7 @@ public class VibratorManagerService extends IVibratorManagerService.Stub { } } - private void fillVibrationFallbacks(Vibration vib, VibrationEffect effect) { + private void fillVibrationFallbacks(HalVibration vib, VibrationEffect effect) { VibrationEffect.Composed composed = (VibrationEffect.Composed) effect; int segmentCount = composed.getSegments().size(); for (int i = 0; i < segmentCount; i++) { @@ -1183,7 +1185,7 @@ public class VibratorManagerService extends IVibratorManagerService.Stub { if (conductor == null) { return false; } - Vibration vib = conductor.getVibration(); + HalVibration vib = conductor.getVibration(); return mVibrationSettings.shouldCancelVibrationOnScreenOff( vib.uid, vib.opPkg, vib.attrs.getUsage(), vib.stats().getCreateUptimeMillis()); } @@ -1535,7 +1537,7 @@ public class VibratorManagerService extends IVibratorManagerService.Stub { mPreviousVibrationsLimit = limit; } - synchronized void record(Vibration vib) { + synchronized void record(HalVibration vib) { int usage = vib.attrs.getUsage(); if (!mPreviousVibrations.contains(usage)) { mPreviousVibrations.put(usage, new LinkedList<>()); @@ -1870,7 +1872,7 @@ public class VibratorManagerService extends IVibratorManagerService.Stub { // only cancel background vibrations. IBinder deathBinder = commonOptions.background ? VibratorManagerService.this : mShellCallbacksToken; - Vibration vib = vibrateInternal(Binder.getCallingUid(), Display.DEFAULT_DISPLAY, + HalVibration vib = vibrateInternal(Binder.getCallingUid(), Display.DEFAULT_DISPLAY, SHELL_PACKAGE_NAME, combined, attrs, commonOptions.description, deathBinder); if (vib != null && !commonOptions.background) { try { diff --git a/services/tests/servicestests/src/com/android/server/vibrator/VibrationThreadTest.java b/services/tests/servicestests/src/com/android/server/vibrator/VibrationThreadTest.java index fc830a9f61adf..9facb4bc87eb4 100644 --- a/services/tests/servicestests/src/com/android/server/vibrator/VibrationThreadTest.java +++ b/services/tests/servicestests/src/com/android/server/vibrator/VibrationThreadTest.java @@ -516,7 +516,7 @@ public class VibrationThreadTest { long vibrationId = 1; VibrationEffect fallback = VibrationEffect.createOneShot(10, 100); - Vibration vibration = createVibration(vibrationId, CombinedVibration.createParallel( + HalVibration vibration = createVibration(vibrationId, CombinedVibration.createParallel( VibrationEffect.get(VibrationEffect.EFFECT_CLICK))); vibration.addFallback(VibrationEffect.EFFECT_CLICK, fallback); startThreadAndDispatcher(vibration); @@ -683,7 +683,7 @@ public class VibrationThreadTest { .addEffect(VibrationEffect.get(VibrationEffect.EFFECT_TICK)) .addPrimitive(VibrationEffect.Composition.PRIMITIVE_TICK, 0.5f) .compose(); - Vibration vib = createVibration(vibrationId, CombinedVibration.createParallel(effect)); + HalVibration vib = createVibration(vibrationId, CombinedVibration.createParallel(effect)); vib.addFallback(VibrationEffect.EFFECT_TICK, fallback); startThreadAndDispatcher(vib); waitForCompletion(); @@ -1592,7 +1592,7 @@ public class VibrationThreadTest { return startThreadAndDispatcher(createVibration(vibrationId, effect)); } - private VibrationStepConductor startThreadAndDispatcher(Vibration vib) { + private VibrationStepConductor startThreadAndDispatcher(HalVibration vib) { mControllers = createVibratorControllers(); VibrationStepConductor conductor = new VibrationStepConductor(vib, mVibrationSettings, mEffectAdapter, mControllers, mManagerHooks); @@ -1624,8 +1624,8 @@ public class VibrationThreadTest { mTestLooper.dispatchAll(); // Flush callbacks } - private Vibration createVibration(long id, CombinedVibration effect) { - return new Vibration(mVibrationToken, (int) id, effect, ATTRS, UID, DISPLAY_ID, + private HalVibration createVibration(long id, CombinedVibration effect) { + return new HalVibration(mVibrationToken, (int) id, effect, ATTRS, UID, DISPLAY_ID, PACKAGE_NAME, "reason"); } diff --git a/services/tests/servicestests/src/com/android/server/vibrator/VibratorManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/vibrator/VibratorManagerServiceTest.java index c83afb74ccba6..f040da8fa2d40 100644 --- a/services/tests/servicestests/src/com/android/server/vibrator/VibratorManagerServiceTest.java +++ b/services/tests/servicestests/src/com/android/server/vibrator/VibratorManagerServiceTest.java @@ -2034,7 +2034,7 @@ public class VibratorManagerServiceTest { private void vibrateAndWaitUntilFinished(VibratorManagerService service, CombinedVibration effect, VibrationAttributes attrs) throws InterruptedException { - Vibration vib = + HalVibration vib = service.vibrateInternal(UID, Display.DEFAULT_DISPLAY, PACKAGE_NAME, effect, attrs, "some reason", service); if (vib != null) {