Adding recovery logic for IAudioControl
When HAL dies
- AudioControlWrapper grabs a new HAL Handle
- AudioControlWrapper calls CarAudioService#resetHalAudioFocus
- resetHalAudioFocus resets HalAudioFocus and re-registers the listener
Bug: 153475563
Test: atest com.android.car.audio, also manually killed audiocontrol and
verified it recovered
Change-Id: If689af0dc7cc1c628ae750a46a2452079a093762
diff --git a/service/src/com/android/car/audio/hal/AudioControlWrapperV2.java b/service/src/com/android/car/audio/hal/AudioControlWrapperV2.java
index 6bf9a00..c623c15 100644
--- a/service/src/com/android/car/audio/hal/AudioControlWrapperV2.java
+++ b/service/src/com/android/car/audio/hal/AudioControlWrapperV2.java
@@ -35,6 +35,7 @@
private IAudioControl mAudioControlV2;
+ private AudioControlDeathRecipient mDeathRecipient;
private ICloseHandle mCloseHandle;
public static @Nullable IAudioControl getService() {
@@ -122,4 +123,33 @@
Log.e(TAG, "setBalanceTowardRight failed", e);
}
}
+
+ @Override
+ public void linkToDeath(@Nullable AudioControlDeathRecipient deathRecipient) {
+ try {
+ mAudioControlV2.linkToDeath(this::serviceDied, 0);
+ mDeathRecipient = deathRecipient;
+ } catch (RemoteException e) {
+ throw new IllegalStateException("Call to IAudioControl@2.0#linkToDeath failed", e);
+ }
+ }
+
+ @Override
+ public void unlinkToDeath() {
+ try {
+ mAudioControlV2.unlinkToDeath(this::serviceDied);
+ mDeathRecipient = null;
+ } catch (RemoteException e) {
+ throw new IllegalStateException("Call to IAudioControl@2.0#unlinkToDeath failed", e);
+ }
+ }
+
+ private void serviceDied(long cookie) {
+ Log.w(TAG, "IAudioControl@2.0 died. Fetching new handle");
+ mAudioControlV2 = AudioControlWrapperV2.getService();
+ linkToDeath(mDeathRecipient);
+ if (mDeathRecipient != null) {
+ mDeathRecipient.serviceDied();
+ }
+ }
}