Catch STHAL factory exceptions

The ST HAL factory may throw on back-to-back HAL process deaths.

Loop until the factory successfully creates.

Bug: 271058477
Test: AlwaysOnHotwordDetectorTest
Test: Successful attach on boot, audioserver death
Change-Id: Ifeb84d604cd0330cd0f9f2e11aa8cb6e14bc7b26
This commit is contained in:
Atneya Nair
2023-05-08 10:54:17 -07:00
parent d2c2751bff
commit c3de5db645

View File

@@ -168,9 +168,18 @@ class SoundTriggerModule implements IBinder.DeathRecipient, ISoundTriggerHal.Glo
* Attached to the HAL service via factory.
*/
private void attachToHal() {
mHalService = new SoundTriggerHalEnforcer(
new SoundTriggerHalWatchdog(
new SoundTriggerDuplicateModelHandler(mHalFactory.create())));
mHalService = null;
while (mHalService == null) {
try {
mHalService = new SoundTriggerHalEnforcer(
new SoundTriggerHalWatchdog(
new SoundTriggerDuplicateModelHandler(mHalFactory.create())));
} catch (RuntimeException e) {
if (!(e.getCause() instanceof RemoteException)) {
throw e;
}
}
}
mHalService.linkToDeath(this);
mHalService.registerCallback(this);
mProperties = mHalService.getProperties();