Converting sound trigger v2.2 getModelState to be asynchronous

Test: built android with checkbuild flag

Change-Id: I4c6f2388c93b6e577113fc7f2cd19242628ee50f
Bug-Id: 70206501
diff --git a/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerService.java b/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerService.java
index d57fcb1..8c82cc8 100644
--- a/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerService.java
+++ b/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerService.java
@@ -436,9 +436,10 @@
         }
 
         @Override
-        public SoundTrigger.RecognitionEvent getModelState(ParcelUuid soundModelId) {
+        public int getModelState(ParcelUuid soundModelId) {
             enforceCallingPermission(Manifest.permission.MANAGE_SOUND_TRIGGER);
-            if (!isInitialized()) return null;
+            int ret = STATUS_ERROR;
+            if (!isInitialized()) return ret;
             if (DEBUG) {
                 Slog.i(TAG, "getModelState(): id = " + soundModelId);
             }
@@ -447,9 +448,8 @@
                 SoundModel soundModel = mLoadedModels.get(soundModelId.getUuid());
                 if (soundModel == null) {
                     Slog.e(TAG, soundModelId + " is not loaded");
-                    return null;
+                    return ret;
                 }
-                SoundTrigger.RecognitionEvent ret = null;
                 switch (soundModel.type) {
                     case SoundModel.TYPE_KEYPHRASE:
                         ret = mSoundTriggerHelper.getKeyphraseModelState(soundModel.uuid);
@@ -461,9 +461,6 @@
                         Slog.e(TAG, "Unknown model type");
                         break;
                 }
-                if (ret == null) {
-                    Slog.e(TAG, "Failed to get model state");
-                }
 
                 return ret;
             }
@@ -942,7 +939,11 @@
             runOrAddOperation(new Operation(
                     // always execute:
                     () -> {
-                        if (!mRecognitionConfig.allowMultipleTriggers) {
+                        // Don't remove the callback if multiple triggers are allowed or
+                        // if this event was triggered by a getModelState request
+                        if (!mRecognitionConfig.allowMultipleTriggers
+                                && event.status
+                                    != SoundTrigger.RECOGNITION_STATUS_GET_STATE_RESPONSE) {
                             // Unregister this remoteService once op is done
                             synchronized (mCallbacksLock) {
                                 mCallbacks.remove(mPuuid.getUuid());