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

Commit c800a04b authored by Atneya Nair's avatar Atneya Nair
Browse files

Remove STService dependency on model database

The loaded model can mismatch the model in the database.
Removing this dependency while preserving existing behavior
for STDetector clients. These clients already must load the
model to prevent state mismatch.

Test: Compiles
Bug: 266963008
Change-Id: I0c0ea9081e9507c2237796ac11a7585dec1c148d
parent fb399b7d
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -36,7 +36,8 @@ interface ISoundTriggerSession {

    void deleteSoundModel(in ParcelUuid soundModelId);

    int startRecognition(in ParcelUuid soundModelId, in IRecognitionStatusCallback callback,
    int startRecognition(in SoundTrigger.GenericSoundModel soundModel,
         in IRecognitionStatusCallback callback,
         in SoundTrigger.RecognitionConfig config, boolean runInBatterySaver);

    int stopRecognition(in ParcelUuid soundModelId, in IRecognitionStatusCallback callback);
+8 −5
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.annotation.SystemApi;
import android.compat.annotation.UnsupportedAppUsage;
import android.hardware.soundtrigger.IRecognitionStatusCallback;
import android.hardware.soundtrigger.SoundTrigger;
import android.hardware.soundtrigger.SoundTrigger.GenericSoundModel;
import android.hardware.soundtrigger.SoundTrigger.ModuleProperties;
import android.hardware.soundtrigger.SoundTrigger.RecognitionConfig;
import android.media.AudioFormat;
@@ -50,6 +51,7 @@ import java.util.UUID;
 * VoiceInteractionService} instead. Access to this class is protected by a permission
 * granted only to system or privileged apps.
 * @deprecated use {@link SoundTriggerManager} directly
 *
 * @hide
 */
@Deprecated
@@ -67,7 +69,7 @@ public final class SoundTriggerDetector {
    private final Object mLock = new Object();

    private final ISoundTriggerSession mSoundTriggerSession;
    private final UUID mSoundModelId;
    private final GenericSoundModel mSoundModel;
    private final Callback mCallback;
    private final Handler mHandler;
    private final RecognitionCallback mRecognitionCallback;
@@ -277,10 +279,11 @@ public final class SoundTriggerDetector {
     * This class should be constructed by the {@link SoundTriggerManager}.
     * @hide
     */
    SoundTriggerDetector(ISoundTriggerSession soundTriggerSession, UUID soundModelId,
    SoundTriggerDetector(ISoundTriggerSession soundTriggerSession,
            @NonNull GenericSoundModel soundModel,
            @NonNull Callback callback, @Nullable Handler handler) {
        mSoundTriggerSession = soundTriggerSession;
        mSoundModelId = soundModelId;
        mSoundModel = soundModel;
        mCallback = callback;
        if (handler == null) {
            mHandler = new MyHandler();
@@ -320,7 +323,7 @@ public final class SoundTriggerDetector {

        int status;
        try {
            status = mSoundTriggerSession.startRecognition(new ParcelUuid(mSoundModelId),
            status = mSoundTriggerSession.startRecognition(mSoundModel,
                    mRecognitionCallback, new RecognitionConfig(captureTriggerAudio,
                            allowMultipleTriggers, null, null, audioCapabilities),
                    runInBatterySaver);
@@ -339,7 +342,7 @@ public final class SoundTriggerDetector {
    public boolean stopRecognition() {
        int status = STATUS_OK;
        try {
            status = mSoundTriggerSession.stopRecognition(new ParcelUuid(mSoundModelId),
            status = mSoundTriggerSession.stopRecognition(new ParcelUuid(mSoundModel.getUuid()),
                    mRecognitionCallback);
        } catch (RemoteException e) {
            return false;
+10 −5
Original line number Diff line number Diff line
@@ -184,10 +184,15 @@ public final class SoundTriggerManager {
        if (oldInstance != null) {
            // Shutdown old instance.
        }
        try {
            SoundTriggerDetector newInstance = new SoundTriggerDetector(mSoundTriggerSession,
                soundModelId, callback, handler);
                    mSoundTriggerSession.getSoundModel(new ParcelUuid(soundModelId)),
                    callback, handler);
            mReceiverInstanceMap.put(soundModelId, newInstance);
            return newInstance;
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
   }

    /**
+14 −17
Original line number Diff line number Diff line
@@ -298,35 +298,33 @@ public class SoundTriggerService extends SystemService {
        }

        @Override
        public int startRecognition(ParcelUuid parcelUuid, IRecognitionStatusCallback callback,
        public int startRecognition(GenericSoundModel soundModel,
                IRecognitionStatusCallback callback,
                RecognitionConfig config, boolean runInBatterySaverMode) {
            try (SafeCloseable ignored = ClearCallingIdentityContext.create()) {
                enforceCallingPermission(Manifest.permission.MANAGE_SOUND_TRIGGER);

                if (soundModel == null) {
                    Slog.e(TAG, "Null model passed to startRecognition");
                    return STATUS_ERROR;
                }

                if (runInBatterySaverMode) {
                    enforceCallingPermission(Manifest.permission.SOUND_TRIGGER_RUN_IN_BATTERY_SAVER);
                }

                if (DEBUG) {
                    Slog.i(TAG, "startRecognition(): Uuid : " + parcelUuid);
                    Slog.i(TAG, "startRecognition(): Uuid : " + soundModel.toString());
                }

                sEventLogger.enqueue(new EventLogger.StringEvent(
                        "startRecognition(): Uuid : " + parcelUuid));

                GenericSoundModel model = getSoundModel(parcelUuid);
                if (model == null) {
                    Slog.w(TAG, "Null model in database for id: " + parcelUuid);

                    sEventLogger.enqueue(new EventLogger.StringEvent(
                            "startRecognition(): Null model in database for id: " + parcelUuid));

                    return STATUS_ERROR;
                }
                        "startRecognition(): Uuid : " + soundModel.getUuid().toString()));

                int ret = mSoundTriggerHelper.startGenericRecognition(parcelUuid.getUuid(), model,
                int ret = mSoundTriggerHelper.startGenericRecognition(soundModel.getUuid(),
                        soundModel,
                        callback, config, runInBatterySaverMode);
                if (ret == STATUS_OK) {
                    mSoundModelStatTracker.onStart(parcelUuid.getUuid());
                    mSoundModelStatTracker.onStart(soundModel.getUuid());
                }
                return ret;
            }
@@ -379,7 +377,6 @@ public class SoundTriggerService extends SystemService {

                sEventLogger.enqueue(new EventLogger.StringEvent("updateSoundModel(): model = "
                        + soundModel));

               mDbHelper.updateGenericSoundModel(soundModel);
            }
        }