Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 096643f5 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge changes from topics "presubmit-am-41e144351270485b94f495fc32653e46",...

Merge changes from topics "presubmit-am-41e144351270485b94f495fc32653e46", "presubmit-am-d52b531f305c4668b1dfe4f906403ae6" into tm-dev am: 36e2df5b

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17626108



Change-Id: I4af89c739aacba9818edbc98079cd1ff4c9d844f
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 9548c68d 36e2df5b
Loading
Loading
Loading
Loading
+28 −19
Original line number Diff line number Diff line
@@ -395,20 +395,8 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
                return STATUS_OK;
            }

            int status = prepareForRecognition(modelData);
            if (status != STATUS_OK) {
                Slog.w(TAG, "startRecognition failed to prepare model for recognition");
                return status;
            }
            status = startRecognitionLocked(modelData,
            return updateRecognitionLocked(modelData,
                    false /* Don't notify for synchronous calls */);

            // Initialize power save, call active state monitoring logic.
            if (status == STATUS_OK) {
                initializeDeviceStateListeners();
            }

            return status;
        }
    }

@@ -557,7 +545,7 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
            }
        }

        if (unloadModel && modelData.isModelLoaded()) {
        if (unloadModel && (modelData.isModelLoaded() || modelData.isStopPending())) {
            Slog.d(TAG, "Unloading previously loaded stale model.");
            if (mModule == null) {
                return STATUS_ERROR;
@@ -917,7 +905,7 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
        Slog.w(TAG, "Recognition aborted");
        MetricsLogger.count(mContext, "sth_recognition_aborted", 1);
        ModelData modelData = getModelDataForLocked(event.soundModelHandle);
        if (modelData != null && modelData.isModelStarted()) {
        if (modelData != null && (modelData.isModelStarted() || modelData.isStopPending())) {
            modelData.setStopped();
            try {
                IRecognitionStatusCallback callback = modelData.getCallback();
@@ -929,6 +917,7 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
            } catch (RemoteException e) {
                Slog.w(TAG, "RemoteException in onRecognitionPaused", e);
            }
            updateRecognitionLocked(modelData, true);
        }
    }

@@ -1008,16 +997,22 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {

    private int updateRecognitionLocked(ModelData model, boolean notifyClientOnError) {
        boolean shouldStartModel = model.isRequested() && isRecognitionAllowedByDeviceState(model);
        if (shouldStartModel == model.isModelStarted()) {
        if (shouldStartModel == model.isModelStarted() || model.isStopPending()) {
            // No-op.
            return STATUS_OK;
        }
        if (shouldStartModel) {
            int status = prepareForRecognition(model);
            if (status != STATUS_OK) {
                Slog.w(TAG, "startRecognition failed to prepare model for recognition");
                return status;
            }
            return startRecognitionLocked(model, notifyClientOnError);
            status = startRecognitionLocked(model, notifyClientOnError);
            // Initialize power save, call active state monitoring logic.
            if (status == STATUS_OK) {
                initializeDeviceStateListeners();
            }
            return status;
        } else {
            return stopRecognitionLocked(model, notifyClientOnError);
        }
@@ -1200,7 +1195,10 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
        if (mModule == null) {
            return;
        }
        if (modelData.isModelStarted()) {
        if (modelData.isStopPending()) {
            // No need to wait for the stop to be confirmed.
            modelData.setStopped();
        } else if (modelData.isModelStarted()) {
            Slog.d(TAG, "Stopping previously started dangling model " + modelData.getHandle());
            if (mModule.stopRecognition(modelData.getHandle()) == STATUS_OK) {
                modelData.setStopped();
@@ -1417,7 +1415,7 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
                }
            }
        } else {
            modelData.setStopped();
            modelData.setStopPending();
            MetricsLogger.count(mContext, "sth_stop_recognition_success", 1);
            // Notify of pause if needed.
            if (notify) {
@@ -1472,6 +1470,9 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
        // Started implies model was successfully loaded and start was called.
        static final int MODEL_STARTED = 2;

        // Model stop request has been sent. Waiting for an event to signal model being stopped.
        static final int MODEL_STOP_PENDING = 3;

        // One of MODEL_NOTLOADED, MODEL_LOADED, MODEL_STARTED (which implies loaded).
        private int mModelState;
        private UUID mModelId;
@@ -1549,6 +1550,10 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
            return mModelState == MODEL_NOTLOADED;
        }

        synchronized boolean isStopPending() {
            return mModelState == MODEL_STOP_PENDING;
        }

        synchronized void setStarted() {
            mModelState = MODEL_STARTED;
        }
@@ -1557,6 +1562,10 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
            mModelState = MODEL_LOADED;
        }

        synchronized void setStopPending() {
            mModelState = MODEL_STOP_PENDING;
        }

        synchronized void setLoaded() {
            mModelState = MODEL_LOADED;
        }