From 801a2348713d5ebb819127ee81b2f2cf95aa39e0 Mon Sep 17 00:00:00 2001 From: Matt Garnes Date: Tue, 10 May 2016 15:30:22 -0700 Subject: Add hotword AudioService null check If an application tries to start recording with the HOTWORD input before AudioService is ready, the interface is not available to call handleHotwordInput on. Check for null and only log if AudioService is not available. Change-Id: I2e693c5aed7cdce6299d8ff16341c1af8dd5b54f Issue-Id: FOR-257 --- media/java/android/media/AudioRecord.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'media') diff --git a/media/java/android/media/AudioRecord.java b/media/java/android/media/AudioRecord.java index e819b8a..c96690b 100644 --- a/media/java/android/media/AudioRecord.java +++ b/media/java/android/media/AudioRecord.java @@ -974,7 +974,14 @@ public class AudioRecord final IBinder b = ServiceManager.getService(android.content.Context.AUDIO_SERVICE); final IAudioService ias = IAudioService.Stub.asInterface(b); try { - ias.handleHotwordInput(listening); + // If the caller tries to start recording with the HOTWORD input + // before AUDIO_SERVICE has started, IAudioService may not be available. + if (ias != null) { + ias.handleHotwordInput(listening); + } else { + Log.e(TAG, "Error talking to AudioService when handling hotword input, " + + "AudioService unavailable"); + } } catch (RemoteException e) { Log.e(TAG, "Error talking to AudioService when handling hotword input.", e); } -- cgit v1.1