Loading services/core/java/com/android/server/soundtrigger_middleware/SoundTriggerHw2Enforcer.java +18 −16 Original line number Diff line number Diff line Loading @@ -42,7 +42,7 @@ public class SoundTriggerHw2Enforcer implements ISoundTriggerHw2 { static final String TAG = "SoundTriggerHw2Enforcer"; final ISoundTriggerHw2 mUnderlying; final Map<Integer, Boolean> mModelStates = new HashMap<>(); Map<Integer, Boolean> mModelStates = new HashMap<>(); public SoundTriggerHw2Enforcer( ISoundTriggerHw2 underlying) { Loading @@ -62,12 +62,12 @@ public class SoundTriggerHw2Enforcer implements ISoundTriggerHw2 { public int loadSoundModel(ISoundTriggerHw.SoundModel soundModel, Callback callback, int cookie) { try { synchronized (mModelStates) { int handle = mUnderlying.loadSoundModel(soundModel, new CallbackEnforcer(callback), cookie); synchronized (mModelStates) { mModelStates.put(handle, false); return handle; } return handle; } catch (RuntimeException e) { throw handleException(e); } Loading @@ -77,13 +77,13 @@ public class SoundTriggerHw2Enforcer implements ISoundTriggerHw2 { public int loadPhraseSoundModel(ISoundTriggerHw.PhraseSoundModel soundModel, Callback callback, int cookie) { try { synchronized (mModelStates) { int handle = mUnderlying.loadPhraseSoundModel(soundModel, new CallbackEnforcer(callback), cookie); synchronized (mModelStates) { mModelStates.put(handle, false); return handle; } return handle; } catch (RuntimeException e) { throw handleException(e); } Loading @@ -92,8 +92,8 @@ public class SoundTriggerHw2Enforcer implements ISoundTriggerHw2 { @Override public void unloadSoundModel(int modelHandle) { try { synchronized (mModelStates) { mUnderlying.unloadSoundModel(modelHandle); synchronized (mModelStates) { mModelStates.remove(modelHandle); } } catch (RuntimeException e) { Loading @@ -104,8 +104,8 @@ public class SoundTriggerHw2Enforcer implements ISoundTriggerHw2 { @Override public void stopRecognition(int modelHandle) { try { synchronized (mModelStates) { mUnderlying.stopRecognition(modelHandle); synchronized (mModelStates) { mModelStates.replace(modelHandle, false); } } catch (RuntimeException e) { Loading @@ -116,8 +116,8 @@ public class SoundTriggerHw2Enforcer implements ISoundTriggerHw2 { @Override public void stopAllRecognitions() { try { synchronized (mModelStates) { mUnderlying.stopAllRecognitions(); synchronized (mModelStates) { for (Map.Entry<Integer, Boolean> entry : mModelStates.entrySet()) { entry.setValue(false); } Loading @@ -130,12 +130,14 @@ public class SoundTriggerHw2Enforcer implements ISoundTriggerHw2 { @Override public void startRecognition(int modelHandle, RecognitionConfig config, Callback callback, int cookie) { try { // It is possible that an event will be sent before the HAL returns from the // startRecognition call, thus it is important to set the state to active before the call. synchronized (mModelStates) { mUnderlying.startRecognition(modelHandle, config, new CallbackEnforcer(callback), cookie); mModelStates.replace(modelHandle, true); } try { mUnderlying.startRecognition(modelHandle, config, new CallbackEnforcer(callback), cookie); } catch (RuntimeException e) { throw handleException(e); } Loading Loading
services/core/java/com/android/server/soundtrigger_middleware/SoundTriggerHw2Enforcer.java +18 −16 Original line number Diff line number Diff line Loading @@ -42,7 +42,7 @@ public class SoundTriggerHw2Enforcer implements ISoundTriggerHw2 { static final String TAG = "SoundTriggerHw2Enforcer"; final ISoundTriggerHw2 mUnderlying; final Map<Integer, Boolean> mModelStates = new HashMap<>(); Map<Integer, Boolean> mModelStates = new HashMap<>(); public SoundTriggerHw2Enforcer( ISoundTriggerHw2 underlying) { Loading @@ -62,12 +62,12 @@ public class SoundTriggerHw2Enforcer implements ISoundTriggerHw2 { public int loadSoundModel(ISoundTriggerHw.SoundModel soundModel, Callback callback, int cookie) { try { synchronized (mModelStates) { int handle = mUnderlying.loadSoundModel(soundModel, new CallbackEnforcer(callback), cookie); synchronized (mModelStates) { mModelStates.put(handle, false); return handle; } return handle; } catch (RuntimeException e) { throw handleException(e); } Loading @@ -77,13 +77,13 @@ public class SoundTriggerHw2Enforcer implements ISoundTriggerHw2 { public int loadPhraseSoundModel(ISoundTriggerHw.PhraseSoundModel soundModel, Callback callback, int cookie) { try { synchronized (mModelStates) { int handle = mUnderlying.loadPhraseSoundModel(soundModel, new CallbackEnforcer(callback), cookie); synchronized (mModelStates) { mModelStates.put(handle, false); return handle; } return handle; } catch (RuntimeException e) { throw handleException(e); } Loading @@ -92,8 +92,8 @@ public class SoundTriggerHw2Enforcer implements ISoundTriggerHw2 { @Override public void unloadSoundModel(int modelHandle) { try { synchronized (mModelStates) { mUnderlying.unloadSoundModel(modelHandle); synchronized (mModelStates) { mModelStates.remove(modelHandle); } } catch (RuntimeException e) { Loading @@ -104,8 +104,8 @@ public class SoundTriggerHw2Enforcer implements ISoundTriggerHw2 { @Override public void stopRecognition(int modelHandle) { try { synchronized (mModelStates) { mUnderlying.stopRecognition(modelHandle); synchronized (mModelStates) { mModelStates.replace(modelHandle, false); } } catch (RuntimeException e) { Loading @@ -116,8 +116,8 @@ public class SoundTriggerHw2Enforcer implements ISoundTriggerHw2 { @Override public void stopAllRecognitions() { try { synchronized (mModelStates) { mUnderlying.stopAllRecognitions(); synchronized (mModelStates) { for (Map.Entry<Integer, Boolean> entry : mModelStates.entrySet()) { entry.setValue(false); } Loading @@ -130,12 +130,14 @@ public class SoundTriggerHw2Enforcer implements ISoundTriggerHw2 { @Override public void startRecognition(int modelHandle, RecognitionConfig config, Callback callback, int cookie) { try { // It is possible that an event will be sent before the HAL returns from the // startRecognition call, thus it is important to set the state to active before the call. synchronized (mModelStates) { mUnderlying.startRecognition(modelHandle, config, new CallbackEnforcer(callback), cookie); mModelStates.replace(modelHandle, true); } try { mUnderlying.startRecognition(modelHandle, config, new CallbackEnforcer(callback), cookie); } catch (RuntimeException e) { throw handleException(e); } Loading