diff options
| -rw-r--r-- | services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java index a1adee732701..486945d9159e 100644 --- a/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java +++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java @@ -154,7 +154,8 @@ final class HotwordDetectionConnection { private int mRestartCount = 0; @NonNull private ServiceConnection mRemoteHotwordDetectionService; @NonNull private ServiceConnection mRemoteVisualQueryDetectionService; - private IBinder mAudioFlinger; + @GuardedBy("mLock") + @Nullable private IBinder mAudioFlinger; @GuardedBy("mLock") private boolean mDebugHotwordLogging = false; @@ -194,7 +195,7 @@ final class HotwordDetectionConnection { new Intent(VisualQueryDetectionService.SERVICE_INTERFACE); visualQueryDetectionServiceIntent.setComponent(mVisualQueryDetectionComponentName); - initAudioFlingerLocked(); + initAudioFlinger(); mHotwordDetectionServiceConnectionFactory = new ServiceConnectionFactory(hotwordDetectionServiceIntent, @@ -227,31 +228,41 @@ final class HotwordDetectionConnection { } } - private void initAudioFlingerLocked() { + private void initAudioFlinger() { if (DEBUG) { - Slog.d(TAG, "initAudioFlingerLocked"); + Slog.d(TAG, "initAudioFlinger"); } - mAudioFlinger = ServiceManager.waitForService("media.audio_flinger"); - if (mAudioFlinger == null) { + final IBinder audioFlinger = ServiceManager.waitForService("media.audio_flinger"); + if (audioFlinger == null) { + setAudioFlinger(null); throw new IllegalStateException("Service media.audio_flinger wasn't found."); } if (DEBUG) { Slog.d(TAG, "Obtained audio_flinger binder."); } try { - mAudioFlinger.linkToDeath(mAudioServerDeathRecipient, /* flags= */ 0); + audioFlinger.linkToDeath(mAudioServerDeathRecipient, /* flags= */ 0); } catch (RemoteException e) { Slog.w(TAG, "Audio server died before we registered a DeathRecipient; " - + "retrying init.", e); - initAudioFlingerLocked(); + + "retrying init.", e); + initAudioFlinger(); + return; + } + + setAudioFlinger(audioFlinger); + } + + private void setAudioFlinger(@Nullable IBinder audioFlinger) { + synchronized (mLock) { + mAudioFlinger = audioFlinger; } } private void audioServerDied() { Slog.w(TAG, "Audio server died; restarting the HotwordDetectionService."); + // TODO: Check if this needs to be scheduled on a different thread. + initAudioFlinger(); synchronized (mLock) { - // TODO: Check if this needs to be scheduled on a different thread. - initAudioFlingerLocked(); // We restart the process instead of simply sending over the new binder, to avoid race // conditions with audio reading in the service. restartProcessLocked(); |