Loading services/core/java/com/android/server/soundtrigger_middleware/SoundTriggerHw2Enforcer.java +36 −20 Original line number Diff line number Diff line Loading @@ -33,7 +33,7 @@ import java.util.Map; * This is not necessarily a strict enforcement for the HAL contract, but a place to add checks for * common HAL malfunctions, to help track them and assist in debugging. * * The class is not thread-safe. * The class is thread-safe. */ public class SoundTriggerHw2Enforcer implements ISoundTriggerHw2 { static final String TAG = "SoundTriggerHw2Enforcer"; Loading @@ -55,7 +55,9 @@ public class SoundTriggerHw2Enforcer implements ISoundTriggerHw2 { public int loadSoundModel(ISoundTriggerHw.SoundModel soundModel, Callback callback, int cookie) { int handle = mUnderlying.loadSoundModel(soundModel, new CallbackEnforcer(callback), cookie); synchronized (mModelStates) { mModelStates.put(handle, false); } return handle; } Loading @@ -64,36 +66,46 @@ public class SoundTriggerHw2Enforcer implements ISoundTriggerHw2 { int cookie) { int handle = mUnderlying.loadPhraseSoundModel(soundModel, new CallbackEnforcer(callback), cookie); synchronized (mModelStates) { mModelStates.put(handle, false); } return handle; } @Override public void unloadSoundModel(int modelHandle) { mUnderlying.unloadSoundModel(modelHandle); synchronized (mModelStates) { mModelStates.remove(modelHandle); } } @Override public void stopRecognition(int modelHandle) { mUnderlying.stopRecognition(modelHandle); synchronized (mModelStates) { mModelStates.replace(modelHandle, false); } } @Override public void stopAllRecognitions() { mUnderlying.stopAllRecognitions(); synchronized (mModelStates) { for (Map.Entry<Integer, Boolean> entry : mModelStates.entrySet()) { entry.setValue(false); } } } @Override public void startRecognition(int modelHandle, RecognitionConfig config, Callback callback, int cookie) { mUnderlying.startRecognition(modelHandle, config, new CallbackEnforcer(callback), cookie); synchronized (mModelStates) { mModelStates.replace(modelHandle, true); } } @Override public void getModelState(int modelHandle) { Loading Loading @@ -142,6 +154,7 @@ public class SoundTriggerHw2Enforcer implements ISoundTriggerHw2 { public void recognitionCallback(ISoundTriggerHwCallback.RecognitionEvent event, int cookie) { int model = event.header.model; synchronized (mModelStates) { if (!mModelStates.getOrDefault(model, false)) { Log.wtfStack(TAG, "Unexpected recognition event for model: " + model); } Loading @@ -149,6 +162,7 @@ public class SoundTriggerHw2Enforcer implements ISoundTriggerHw2 { != android.media.soundtrigger_middleware.RecognitionStatus.FORCED) { mModelStates.replace(model, false); } } mUnderlying.recognitionCallback(event, cookie); } Loading @@ -156,6 +170,7 @@ public class SoundTriggerHw2Enforcer implements ISoundTriggerHw2 { public void phraseRecognitionCallback(ISoundTriggerHwCallback.PhraseRecognitionEvent event, int cookie) { int model = event.common.header.model; synchronized (mModelStates) { if (!mModelStates.getOrDefault(model, false)) { Log.wtfStack(TAG, "Unexpected recognition event for model: " + model); } Loading @@ -163,6 +178,7 @@ public class SoundTriggerHw2Enforcer implements ISoundTriggerHw2 { != android.media.soundtrigger_middleware.RecognitionStatus.FORCED) { mModelStates.replace(model, false); } } mUnderlying.phraseRecognitionCallback(event, cookie); } } Loading Loading
services/core/java/com/android/server/soundtrigger_middleware/SoundTriggerHw2Enforcer.java +36 −20 Original line number Diff line number Diff line Loading @@ -33,7 +33,7 @@ import java.util.Map; * This is not necessarily a strict enforcement for the HAL contract, but a place to add checks for * common HAL malfunctions, to help track them and assist in debugging. * * The class is not thread-safe. * The class is thread-safe. */ public class SoundTriggerHw2Enforcer implements ISoundTriggerHw2 { static final String TAG = "SoundTriggerHw2Enforcer"; Loading @@ -55,7 +55,9 @@ public class SoundTriggerHw2Enforcer implements ISoundTriggerHw2 { public int loadSoundModel(ISoundTriggerHw.SoundModel soundModel, Callback callback, int cookie) { int handle = mUnderlying.loadSoundModel(soundModel, new CallbackEnforcer(callback), cookie); synchronized (mModelStates) { mModelStates.put(handle, false); } return handle; } Loading @@ -64,36 +66,46 @@ public class SoundTriggerHw2Enforcer implements ISoundTriggerHw2 { int cookie) { int handle = mUnderlying.loadPhraseSoundModel(soundModel, new CallbackEnforcer(callback), cookie); synchronized (mModelStates) { mModelStates.put(handle, false); } return handle; } @Override public void unloadSoundModel(int modelHandle) { mUnderlying.unloadSoundModel(modelHandle); synchronized (mModelStates) { mModelStates.remove(modelHandle); } } @Override public void stopRecognition(int modelHandle) { mUnderlying.stopRecognition(modelHandle); synchronized (mModelStates) { mModelStates.replace(modelHandle, false); } } @Override public void stopAllRecognitions() { mUnderlying.stopAllRecognitions(); synchronized (mModelStates) { for (Map.Entry<Integer, Boolean> entry : mModelStates.entrySet()) { entry.setValue(false); } } } @Override public void startRecognition(int modelHandle, RecognitionConfig config, Callback callback, int cookie) { mUnderlying.startRecognition(modelHandle, config, new CallbackEnforcer(callback), cookie); synchronized (mModelStates) { mModelStates.replace(modelHandle, true); } } @Override public void getModelState(int modelHandle) { Loading Loading @@ -142,6 +154,7 @@ public class SoundTriggerHw2Enforcer implements ISoundTriggerHw2 { public void recognitionCallback(ISoundTriggerHwCallback.RecognitionEvent event, int cookie) { int model = event.header.model; synchronized (mModelStates) { if (!mModelStates.getOrDefault(model, false)) { Log.wtfStack(TAG, "Unexpected recognition event for model: " + model); } Loading @@ -149,6 +162,7 @@ public class SoundTriggerHw2Enforcer implements ISoundTriggerHw2 { != android.media.soundtrigger_middleware.RecognitionStatus.FORCED) { mModelStates.replace(model, false); } } mUnderlying.recognitionCallback(event, cookie); } Loading @@ -156,6 +170,7 @@ public class SoundTriggerHw2Enforcer implements ISoundTriggerHw2 { public void phraseRecognitionCallback(ISoundTriggerHwCallback.PhraseRecognitionEvent event, int cookie) { int model = event.common.header.model; synchronized (mModelStates) { if (!mModelStates.getOrDefault(model, false)) { Log.wtfStack(TAG, "Unexpected recognition event for model: " + model); } Loading @@ -163,6 +178,7 @@ public class SoundTriggerHw2Enforcer implements ISoundTriggerHw2 { != android.media.soundtrigger_middleware.RecognitionStatus.FORCED) { mModelStates.replace(model, false); } } mUnderlying.phraseRecognitionCallback(event, cookie); } } Loading