Merge "Remove STService dependency on model database"

This commit is contained in:
Atneya Nair
2023-02-01 01:15:34 +00:00
committed by Android (Google) Code Review
4 changed files with 34 additions and 28 deletions

View File

@@ -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);

View File

@@ -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;

View File

@@ -184,11 +184,16 @@ public final class SoundTriggerManager {
if (oldInstance != null) {
// Shutdown old instance.
}
SoundTriggerDetector newInstance = new SoundTriggerDetector(mSoundTriggerSession,
soundModelId, callback, handler);
mReceiverInstanceMap.put(soundModelId, newInstance);
return newInstance;
}
try {
SoundTriggerDetector newInstance = new SoundTriggerDetector(mSoundTriggerSession,
mSoundTriggerSession.getSoundModel(new ParcelUuid(soundModelId)),
callback, handler);
mReceiverInstanceMap.put(soundModelId, newInstance);
return newInstance;
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Class captures the data and fields that represent a non-keyphrase sound model. Use the

View File

@@ -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));
"startRecognition(): Uuid : " + soundModel.getUuid().toString()));
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;
}
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,8 +377,7 @@ public class SoundTriggerService extends SystemService {
sEventLogger.enqueue(new EventLogger.StringEvent("updateSoundModel(): model = "
+ soundModel));
mDbHelper.updateGenericSoundModel(soundModel);
mDbHelper.updateGenericSoundModel(soundModel);
}
}