Merge "Fix ExternalVibrationTest for parcelable serialization" into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
3932a331d9
@@ -23,6 +23,8 @@ import android.util.Slog;
|
||||
|
||||
import com.android.internal.util.Preconditions;
|
||||
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
/**
|
||||
* An ExternalVibration represents an on-going vibration being controlled by something other than
|
||||
* the core vibrator service.
|
||||
@@ -149,7 +151,7 @@ public class ExternalVibration implements Parcelable {
|
||||
try {
|
||||
mToken.linkToDeath(recipient, 0);
|
||||
} catch (RemoteException e) {
|
||||
return;
|
||||
Slog.wtf(TAG, "Failed to link to token death: " + this, e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,7 +159,11 @@ public class ExternalVibration implements Parcelable {
|
||||
* Unlinks a recipient to death against this external vibration token
|
||||
*/
|
||||
public void unlinkToDeath(IBinder.DeathRecipient recipient) {
|
||||
mToken.unlinkToDeath(recipient, 0);
|
||||
try {
|
||||
mToken.unlinkToDeath(recipient, 0);
|
||||
} catch (NoSuchElementException e) {
|
||||
Slog.wtf(TAG, "Failed to unlink to token death", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -184,12 +190,12 @@ public class ExternalVibration implements Parcelable {
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
out.writeInt(mUid);
|
||||
out.writeString(mPkg);
|
||||
writeAudioAttributes(mAttrs, out, flags);
|
||||
writeAudioAttributes(mAttrs, out);
|
||||
out.writeStrongBinder(mController.asBinder());
|
||||
out.writeStrongBinder(mToken);
|
||||
}
|
||||
|
||||
private static void writeAudioAttributes(AudioAttributes attrs, Parcel out, int flags) {
|
||||
private static void writeAudioAttributes(AudioAttributes attrs, Parcel out) {
|
||||
out.writeInt(attrs.getUsage());
|
||||
out.writeInt(attrs.getContentType());
|
||||
out.writeInt(attrs.getCapturePreset());
|
||||
|
||||
@@ -16,34 +16,37 @@
|
||||
|
||||
package android.os;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.media.AudioAttributes;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@RunWith(JUnit4.class)
|
||||
public class ExternalVibrationTest {
|
||||
@Ignore("b/291713224")
|
||||
|
||||
@Test
|
||||
public void testSerialization() {
|
||||
AudioAttributes audio = new AudioAttributes.Builder().build();
|
||||
IExternalVibrationController controller = mock(IExternalVibrationController.class);
|
||||
ExternalVibration original = new ExternalVibration(
|
||||
123, // uid
|
||||
/* uid= */ 123,
|
||||
"pkg",
|
||||
audio,
|
||||
controller);
|
||||
new AudioAttributes.Builder()
|
||||
.setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
|
||||
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
|
||||
.setFlags(AudioAttributes.FLAG_BYPASS_MUTE)
|
||||
.build(),
|
||||
IExternalVibrationController.Stub.asInterface(new Binder()));
|
||||
Parcel p = Parcel.obtain();
|
||||
original.writeToParcel(p, 0);
|
||||
p.setDataPosition(0);
|
||||
ExternalVibration restored = ExternalVibration.CREATOR.createFromParcel(p);
|
||||
assertEquals(original, restored);
|
||||
assertThat(restored).isEqualTo(original);
|
||||
// ExternalVibration.equals relies on the binder token only, check other attributes as well
|
||||
assertThat(restored.getUid()).isEqualTo(original.getUid());
|
||||
assertThat(restored.getPackage()).isEqualTo(original.getPackage());
|
||||
assertThat(restored.getAudioAttributes()).isEqualTo(original.getAudioAttributes());
|
||||
assertThat(restored.getToken()).isEqualTo(original.getToken());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user