summaryrefslogtreecommitdiffstats
path: root/services/voiceinteraction/java/com/android/server
diff options
context:
space:
mode:
Diffstat (limited to 'services/voiceinteraction/java/com/android/server')
-rw-r--r--services/voiceinteraction/java/com/android/server/voiceinteraction/SoundTriggerHelper.java47
-rw-r--r--services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java19
2 files changed, 34 insertions, 32 deletions
diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/SoundTriggerHelper.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/SoundTriggerHelper.java
index 8ce7f74..3ca0c84 100644
--- a/services/voiceinteraction/java/com/android/server/voiceinteraction/SoundTriggerHelper.java
+++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/SoundTriggerHelper.java
@@ -40,7 +40,6 @@ import android.util.Slog;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;
-import java.util.UUID;
/**
* Helper for {@link SoundTrigger} APIs.
@@ -78,7 +77,7 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
private IRecognitionStatusCallback mActiveListener;
private int mKeyphraseId = INVALID_VALUE;
private int mCurrentSoundModelHandle = INVALID_VALUE;
- private UUID mCurrentSoundModelUuid = null;
+ private KeyphraseSoundModel mCurrentSoundModel = null;
// FIXME: Ideally this should not be stored if allowMultipleTriggers happens at a lower layer.
private RecognitionConfig mRecognitionConfig = null;
private boolean mRequested = false;
@@ -134,7 +133,7 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
+ (mActiveListener == null ? "null" : mActiveListener.asBinder()));
Slog.d(TAG, "current SoundModel handle=" + mCurrentSoundModelHandle);
Slog.d(TAG, "current SoundModel UUID="
- + (mCurrentSoundModelUuid == null ? null : mCurrentSoundModelUuid));
+ + (mCurrentSoundModel == null ? null : mCurrentSoundModel.uuid));
}
if (!mStarted) {
@@ -166,20 +165,16 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
}
// Unload the previous model if the current one isn't invalid
- // and, it's not the same as the new one, or we are already started
- // if we are already started, we can get multiple calls to start
- // if the underlying sound model changes, in which case we should unload and reload.
- // The model reuse helps only in cases when we trigger and stop internally
- // without a start recognition call.
+ // and, it's not the same as the new one.
+ // This helps use cache and reuse the model and just start/stop it when necessary.
if (mCurrentSoundModelHandle != INVALID_VALUE
- && (!soundModel.uuid.equals(mCurrentSoundModelUuid) || mStarted)) {
+ && !soundModel.equals(mCurrentSoundModel)) {
Slog.w(TAG, "Unloading previous sound model");
int status = mModule.unloadSoundModel(mCurrentSoundModelHandle);
if (status != SoundTrigger.STATUS_OK) {
Slog.w(TAG, "unloadSoundModel call failed with " + status);
}
- mCurrentSoundModelHandle = INVALID_VALUE;
- mCurrentSoundModelUuid = null;
+ internalClearSoundModelLocked();
mStarted = false;
}
@@ -198,7 +193,7 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
// Load the sound model if the current one is null.
int soundModelHandle = mCurrentSoundModelHandle;
if (mCurrentSoundModelHandle == INVALID_VALUE
- || mCurrentSoundModelUuid == null) {
+ || mCurrentSoundModel == null) {
int[] handle = new int[] { INVALID_VALUE };
int status = mModule.loadSoundModel(soundModel, handle);
if (status != SoundTrigger.STATUS_OK) {
@@ -218,7 +213,7 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
mRequested = true;
mKeyphraseId = keyphraseId;
mCurrentSoundModelHandle = soundModelHandle;
- mCurrentSoundModelUuid = soundModel.uuid;
+ mCurrentSoundModel = soundModel;
mRecognitionConfig = recognitionConfig;
// Register the new listener. This replaces the old one.
// There can only be a maximum of one active listener at any given time.
@@ -275,14 +270,9 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
return status;
}
- status = mModule.unloadSoundModel(mCurrentSoundModelHandle);
- if (status != SoundTrigger.STATUS_OK) {
- Slog.w(TAG, "unloadSoundModel call failed with " + status);
- }
-
- // Clear the internal state once the recognition has been stopped.
- // Unload sound model call may fail in scenarios, and we'd still want
- // to reload the sound model.
+ // We leave the sound model loaded but not started, this helps us when we start
+ // back.
+ // Also clear the internal state once the recognition has been stopped.
internalClearStateLocked();
return status;
}
@@ -303,11 +293,6 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
mRequested = false;
int status = updateRecognitionLocked(false /* don't notify for synchronous calls */);
- status = mModule.unloadSoundModel(mCurrentSoundModelHandle);
- if (status != SoundTrigger.STATUS_OK) {
- Slog.w(TAG, "unloadSoundModel call failed with " + status);
- }
-
internalClearStateLocked();
}
}
@@ -456,6 +441,7 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
} catch (RemoteException e) {
Slog.w(TAG, "RemoteException in onError", e);
} finally {
+ internalClearSoundModelLocked();
internalClearStateLocked();
if (mModule != null) {
mModule.detach();
@@ -535,8 +521,6 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
mRequested = false;
mKeyphraseId = INVALID_VALUE;
- mCurrentSoundModelHandle = INVALID_VALUE;
- mCurrentSoundModelUuid = null;
mRecognitionConfig = null;
mActiveListener = null;
@@ -550,6 +534,11 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
}
}
+ private void internalClearSoundModelLocked() {
+ mCurrentSoundModelHandle = INVALID_VALUE;
+ mCurrentSoundModel = null;
+ }
+
class MyCallStateListener extends PhoneStateListener {
@Override
public void onCallStateChanged(int state, String arg1) {
@@ -581,7 +570,7 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
pw.print(" keyphrase ID="); pw.println(mKeyphraseId);
pw.print(" sound model handle="); pw.println(mCurrentSoundModelHandle);
pw.print(" sound model UUID=");
- pw.println(mCurrentSoundModelUuid == null ? "null" : mCurrentSoundModelUuid);
+ pw.println(mCurrentSoundModel == null ? "null" : mCurrentSoundModel.uuid);
pw.print(" current listener=");
pw.println(mActiveListener == null ? "null" : mActiveListener.asBinder());
diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java
index 82b7f8b..f5d4867 100644
--- a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java
+++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java
@@ -136,11 +136,14 @@ public class VoiceInteractionManagerService extends SystemService {
Settings.Secure.VOICE_INTERACTION_SERVICE, userHandle);
ComponentName curRecognizer = getCurRecognizer(userHandle);
VoiceInteractionServiceInfo curInteractorInfo = null;
- if (curInteractorStr == null && curRecognizer != null) {
+ if (curInteractorStr == null && curRecognizer != null
+ && !ActivityManager.isLowRamDeviceStatic()) {
// If there is no interactor setting, that means we are upgrading
// from an older platform version. If the current recognizer is not
// set or matches the preferred recognizer, then we want to upgrade
// the user to have the default voice interaction service enabled.
+ // Note that we don't do this for low-RAM devices, since we aren't
+ // supporting voice interaction services there.
curInteractorInfo = findAvailInteractor(userHandle, curRecognizer);
if (curInteractorInfo != null) {
// Looks good! We'll apply this one. To make it happen, we clear the
@@ -150,6 +153,15 @@ public class VoiceInteractionManagerService extends SystemService {
}
}
+ // If we are on a svelte device, make sure an interactor is not currently
+ // enabled; if it is, turn it off.
+ if (ActivityManager.isLowRamDeviceStatic() && curInteractorStr != null) {
+ if (!TextUtils.isEmpty(curInteractorStr)) {
+ setCurInteractor(null, userHandle);
+ curInteractorStr = "";
+ }
+ }
+
if (curRecognizer != null) {
// If we already have at least a recognizer, then we probably want to
// leave things as they are... unless something has disappeared.
@@ -171,10 +183,11 @@ public class VoiceInteractionManagerService extends SystemService {
}
}
- // Initializing settings, look for an interactor first.
- if (curInteractorInfo == null) {
+ // Initializing settings, look for an interactor first (but only on non-svelte).
+ if (curInteractorInfo == null && !ActivityManager.isLowRamDeviceStatic()) {
curInteractorInfo = findAvailInteractor(userHandle, null);
}
+
if (curInteractorInfo != null) {
// Eventually it will be an error to not specify this.
setCurInteractor(new ComponentName(curInteractorInfo.getServiceInfo().packageName,