Loading services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java +22 −11 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -194,7 +195,7 @@ final class HotwordDetectionConnection { new Intent(VisualQueryDetectionService.SERVICE_INTERFACE); visualQueryDetectionServiceIntent.setComponent(mVisualQueryDetectionComponentName); initAudioFlingerLocked(); initAudioFlinger(); mHotwordDetectionServiceConnectionFactory = new ServiceConnectionFactory(hotwordDetectionServiceIntent, Loading Loading @@ -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(); 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."); synchronized (mLock) { // TODO: Check if this needs to be scheduled on a different thread. initAudioFlingerLocked(); initAudioFlinger(); synchronized (mLock) { // We restart the process instead of simply sending over the new binder, to avoid race // conditions with audio reading in the service. restartProcessLocked(); Loading Loading
services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java +22 −11 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -194,7 +195,7 @@ final class HotwordDetectionConnection { new Intent(VisualQueryDetectionService.SERVICE_INTERFACE); visualQueryDetectionServiceIntent.setComponent(mVisualQueryDetectionComponentName); initAudioFlingerLocked(); initAudioFlinger(); mHotwordDetectionServiceConnectionFactory = new ServiceConnectionFactory(hotwordDetectionServiceIntent, Loading Loading @@ -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(); 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."); synchronized (mLock) { // TODO: Check if this needs to be scheduled on a different thread. initAudioFlingerLocked(); initAudioFlinger(); synchronized (mLock) { // We restart the process instead of simply sending over the new binder, to avoid race // conditions with audio reading in the service. restartProcessLocked(); Loading