Merge "SoundTriggerHelper: fix state after audioserver death" into qt-qpr1-dev
am: e5a3106cc5
Change-Id: I93be2df0ceb65fa2b78ea73d9d2cca679afd2f26
This commit is contained in:
@@ -325,9 +325,8 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
|
|||||||
false /* Don't notify for synchronous calls */);
|
false /* Don't notify for synchronous calls */);
|
||||||
|
|
||||||
// Initialize power save, call active state monitoring logic.
|
// Initialize power save, call active state monitoring logic.
|
||||||
if (status == STATUS_OK && !mRecognitionRequested) {
|
if (status == STATUS_OK) {
|
||||||
initializeTelephonyAndPowerStateListeners();
|
initializeTelephonyAndPowerStateListeners();
|
||||||
mRecognitionRequested = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
@@ -481,6 +480,9 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
|
|||||||
|
|
||||||
if (unloadModel && modelData.isModelLoaded()) {
|
if (unloadModel && modelData.isModelLoaded()) {
|
||||||
Slog.d(TAG, "Unloading previously loaded stale model.");
|
Slog.d(TAG, "Unloading previously loaded stale model.");
|
||||||
|
if (mModule == null) {
|
||||||
|
return STATUS_ERROR;
|
||||||
|
}
|
||||||
status = mModule.unloadSoundModel(modelData.getHandle());
|
status = mModule.unloadSoundModel(modelData.getHandle());
|
||||||
MetricsLogger.count(mContext, "sth_unloading_stale_model", 1);
|
MetricsLogger.count(mContext, "sth_unloading_stale_model", 1);
|
||||||
if (status != SoundTrigger.STATUS_OK) {
|
if (status != SoundTrigger.STATUS_OK) {
|
||||||
@@ -550,6 +552,9 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mModule == null) {
|
||||||
|
return STATUS_ERROR;
|
||||||
|
}
|
||||||
int status = mModule.unloadSoundModel(modelData.getHandle());
|
int status = mModule.unloadSoundModel(modelData.getHandle());
|
||||||
if (status != SoundTrigger.STATUS_OK) {
|
if (status != SoundTrigger.STATUS_OK) {
|
||||||
Slog.w(TAG, "unloadGenericSoundModel() call failed with " + status);
|
Slog.w(TAG, "unloadGenericSoundModel() call failed with " + status);
|
||||||
@@ -878,6 +883,7 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
|
|||||||
mContext.unregisterReceiver(mPowerSaveModeListener);
|
mContext.unregisterReceiver(mPowerSaveModeListener);
|
||||||
mPowerSaveModeListener = null;
|
mPowerSaveModeListener = null;
|
||||||
}
|
}
|
||||||
|
mRecognitionRequested = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clears state for all models (generic and keyphrase).
|
// Clears state for all models (generic and keyphrase).
|
||||||
@@ -924,6 +930,9 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initializeTelephonyAndPowerStateListeners() {
|
private void initializeTelephonyAndPowerStateListeners() {
|
||||||
|
if (mRecognitionRequested) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
long token = Binder.clearCallingIdentity();
|
long token = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
// Get the current call state synchronously for the first recognition.
|
// Get the current call state synchronously for the first recognition.
|
||||||
@@ -941,6 +950,8 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
|
|||||||
}
|
}
|
||||||
mIsPowerSaveMode = mPowerManager.getPowerSaveState(ServiceType.SOUND)
|
mIsPowerSaveMode = mPowerManager.getPowerSaveState(ServiceType.SOUND)
|
||||||
.batterySaverEnabled;
|
.batterySaverEnabled;
|
||||||
|
|
||||||
|
mRecognitionRequested = true;
|
||||||
} finally {
|
} finally {
|
||||||
Binder.restoreCallingIdentity(token);
|
Binder.restoreCallingIdentity(token);
|
||||||
}
|
}
|
||||||
@@ -987,6 +998,9 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
|
|||||||
if (exception != null) {
|
if (exception != null) {
|
||||||
Slog.e(TAG, "forceStopAndUnloadModel", exception);
|
Slog.e(TAG, "forceStopAndUnloadModel", exception);
|
||||||
}
|
}
|
||||||
|
if (mModule == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (modelData.isModelStarted()) {
|
if (modelData.isModelStarted()) {
|
||||||
Slog.d(TAG, "Stopping previously started dangling model " + modelData.getHandle());
|
Slog.d(TAG, "Stopping previously started dangling model " + modelData.getHandle());
|
||||||
if (mModule.stopRecognition(modelData.getHandle()) != STATUS_OK) {
|
if (mModule.stopRecognition(modelData.getHandle()) != STATUS_OK) {
|
||||||
@@ -1093,6 +1107,13 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
|
|||||||
// a recognition include: no active phone call or not being in a power save mode. Also,
|
// a recognition include: no active phone call or not being in a power save mode. Also,
|
||||||
// the native service should be enabled.
|
// the native service should be enabled.
|
||||||
private boolean isRecognitionAllowed() {
|
private boolean isRecognitionAllowed() {
|
||||||
|
// if mRecognitionRequested is false, call and power state listeners are not registered so
|
||||||
|
// we read current state directly from services
|
||||||
|
if (!mRecognitionRequested) {
|
||||||
|
mCallActive = mTelephonyManager.getCallState() == TelephonyManager.CALL_STATE_OFFHOOK;
|
||||||
|
mIsPowerSaveMode =
|
||||||
|
mPowerManager.getPowerSaveState(ServiceType.SOUND).batterySaverEnabled;
|
||||||
|
}
|
||||||
return !mCallActive && !mServiceDisabled && !mIsPowerSaveMode;
|
return !mCallActive && !mServiceDisabled && !mIsPowerSaveMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1116,6 +1137,9 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
|
|||||||
return STATUS_OK;
|
return STATUS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mModule == null) {
|
||||||
|
return STATUS_ERROR;
|
||||||
|
}
|
||||||
int status = mModule.startRecognition(handle, config);
|
int status = mModule.startRecognition(handle, config);
|
||||||
if (status != SoundTrigger.STATUS_OK) {
|
if (status != SoundTrigger.STATUS_OK) {
|
||||||
Slog.w(TAG, "startRecognition failed with " + status);
|
Slog.w(TAG, "startRecognition failed with " + status);
|
||||||
@@ -1152,8 +1176,11 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int stopRecognitionLocked(ModelData modelData, boolean notify) {
|
private int stopRecognitionLocked(ModelData modelData, boolean notify) {
|
||||||
IRecognitionStatusCallback callback = modelData.getCallback();
|
if (mModule == null) {
|
||||||
|
return STATUS_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
IRecognitionStatusCallback callback = modelData.getCallback();
|
||||||
// Stop recognition.
|
// Stop recognition.
|
||||||
int status = STATUS_OK;
|
int status = STATUS_OK;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user