Merge "Revert "Reboot sound trigger HAL on exception"" into rvc-dev am: 8c63eb2705
Change-Id: I6e37339093234e550b572976366a1761630a03e1
This commit is contained in:
@@ -23,7 +23,6 @@ import android.hardware.soundtrigger.V2_3.Properties;
|
|||||||
import android.hardware.soundtrigger.V2_3.RecognitionConfig;
|
import android.hardware.soundtrigger.V2_3.RecognitionConfig;
|
||||||
import android.os.IHwBinder;
|
import android.os.IHwBinder;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.SystemProperties;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -49,130 +48,83 @@ public class SoundTriggerHw2Enforcer implements ISoundTriggerHw2 {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Properties getProperties() {
|
public Properties getProperties() {
|
||||||
try {
|
return mUnderlying.getProperties();
|
||||||
return mUnderlying.getProperties();
|
|
||||||
} catch (RuntimeException e) {
|
|
||||||
throw handleException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int loadSoundModel(ISoundTriggerHw.SoundModel soundModel, Callback callback,
|
public int loadSoundModel(ISoundTriggerHw.SoundModel soundModel, Callback callback,
|
||||||
int cookie) {
|
int cookie) {
|
||||||
try {
|
int handle = mUnderlying.loadSoundModel(soundModel, new CallbackEnforcer(callback), cookie);
|
||||||
int handle = mUnderlying.loadSoundModel(soundModel, new CallbackEnforcer(callback),
|
synchronized (mModelStates) {
|
||||||
cookie);
|
mModelStates.put(handle, false);
|
||||||
synchronized (mModelStates) {
|
|
||||||
mModelStates.put(handle, false);
|
|
||||||
}
|
|
||||||
return handle;
|
|
||||||
} catch (RuntimeException e) {
|
|
||||||
throw handleException(e);
|
|
||||||
}
|
}
|
||||||
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int loadPhraseSoundModel(ISoundTriggerHw.PhraseSoundModel soundModel, Callback callback,
|
public int loadPhraseSoundModel(ISoundTriggerHw.PhraseSoundModel soundModel, Callback callback,
|
||||||
int cookie) {
|
int cookie) {
|
||||||
try {
|
int handle = mUnderlying.loadPhraseSoundModel(soundModel, new CallbackEnforcer(callback),
|
||||||
int handle = mUnderlying.loadPhraseSoundModel(soundModel,
|
cookie);
|
||||||
new CallbackEnforcer(callback),
|
synchronized (mModelStates) {
|
||||||
cookie);
|
mModelStates.put(handle, false);
|
||||||
synchronized (mModelStates) {
|
|
||||||
mModelStates.put(handle, false);
|
|
||||||
}
|
|
||||||
return handle;
|
|
||||||
} catch (RuntimeException e) {
|
|
||||||
throw handleException(e);
|
|
||||||
}
|
}
|
||||||
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void unloadSoundModel(int modelHandle) {
|
public void unloadSoundModel(int modelHandle) {
|
||||||
try {
|
mUnderlying.unloadSoundModel(modelHandle);
|
||||||
mUnderlying.unloadSoundModel(modelHandle);
|
synchronized (mModelStates) {
|
||||||
synchronized (mModelStates) {
|
mModelStates.remove(modelHandle);
|
||||||
mModelStates.remove(modelHandle);
|
|
||||||
}
|
|
||||||
} catch (RuntimeException e) {
|
|
||||||
throw handleException(e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stopRecognition(int modelHandle) {
|
public void stopRecognition(int modelHandle) {
|
||||||
try {
|
mUnderlying.stopRecognition(modelHandle);
|
||||||
mUnderlying.stopRecognition(modelHandle);
|
synchronized (mModelStates) {
|
||||||
synchronized (mModelStates) {
|
mModelStates.replace(modelHandle, false);
|
||||||
mModelStates.replace(modelHandle, false);
|
|
||||||
}
|
|
||||||
} catch (RuntimeException e) {
|
|
||||||
throw handleException(e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stopAllRecognitions() {
|
public void stopAllRecognitions() {
|
||||||
try {
|
mUnderlying.stopAllRecognitions();
|
||||||
mUnderlying.stopAllRecognitions();
|
synchronized (mModelStates) {
|
||||||
synchronized (mModelStates) {
|
for (Map.Entry<Integer, Boolean> entry : mModelStates.entrySet()) {
|
||||||
for (Map.Entry<Integer, Boolean> entry : mModelStates.entrySet()) {
|
entry.setValue(false);
|
||||||
entry.setValue(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (RuntimeException e) {
|
|
||||||
throw handleException(e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startRecognition(int modelHandle, RecognitionConfig config, Callback callback,
|
public void startRecognition(int modelHandle, RecognitionConfig config, Callback callback,
|
||||||
int cookie) {
|
int cookie) {
|
||||||
try {
|
mUnderlying.startRecognition(modelHandle, config, new CallbackEnforcer(callback), cookie);
|
||||||
mUnderlying.startRecognition(modelHandle, config, new CallbackEnforcer(callback),
|
synchronized (mModelStates) {
|
||||||
cookie);
|
mModelStates.replace(modelHandle, true);
|
||||||
synchronized (mModelStates) {
|
|
||||||
mModelStates.replace(modelHandle, true);
|
|
||||||
}
|
|
||||||
} catch (RuntimeException e) {
|
|
||||||
throw handleException(e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void getModelState(int modelHandle) {
|
public void getModelState(int modelHandle) {
|
||||||
try {
|
mUnderlying.getModelState(modelHandle);
|
||||||
mUnderlying.getModelState(modelHandle);
|
|
||||||
} catch (RuntimeException e) {
|
|
||||||
throw handleException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getModelParameter(int modelHandle, int param) {
|
public int getModelParameter(int modelHandle, int param) {
|
||||||
try {
|
return mUnderlying.getModelParameter(modelHandle, param);
|
||||||
return mUnderlying.getModelParameter(modelHandle, param);
|
|
||||||
} catch (RuntimeException e) {
|
|
||||||
throw handleException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setModelParameter(int modelHandle, int param, int value) {
|
public void setModelParameter(int modelHandle, int param, int value) {
|
||||||
try {
|
mUnderlying.setModelParameter(modelHandle, param, value);
|
||||||
mUnderlying.setModelParameter(modelHandle, param, value);
|
|
||||||
} catch (RuntimeException e) {
|
|
||||||
throw handleException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ModelParameterRange queryParameter(int modelHandle, int param) {
|
public ModelParameterRange queryParameter(int modelHandle, int param) {
|
||||||
try {
|
return mUnderlying.queryParameter(modelHandle, param);
|
||||||
return mUnderlying.queryParameter(modelHandle, param);
|
|
||||||
} catch (RuntimeException e) {
|
|
||||||
throw handleException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -190,17 +142,6 @@ public class SoundTriggerHw2Enforcer implements ISoundTriggerHw2 {
|
|||||||
return mUnderlying.interfaceDescriptor();
|
return mUnderlying.interfaceDescriptor();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static RuntimeException handleException(RuntimeException e) {
|
|
||||||
Log.e(TAG, "Exception caught from HAL, rebooting HAL");
|
|
||||||
rebootHal();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void rebootHal() {
|
|
||||||
// This property needs to be defined in an init.rc script and trigger a HAL reboot.
|
|
||||||
SystemProperties.set("sys.audio.restart.hal", "1");
|
|
||||||
}
|
|
||||||
|
|
||||||
private class CallbackEnforcer implements Callback {
|
private class CallbackEnforcer implements Callback {
|
||||||
private final Callback mUnderlying;
|
private final Callback mUnderlying;
|
||||||
|
|
||||||
@@ -216,8 +157,6 @@ public class SoundTriggerHw2Enforcer implements ISoundTriggerHw2 {
|
|||||||
synchronized (mModelStates) {
|
synchronized (mModelStates) {
|
||||||
if (!mModelStates.getOrDefault(model, false)) {
|
if (!mModelStates.getOrDefault(model, false)) {
|
||||||
Log.wtfStack(TAG, "Unexpected recognition event for model: " + model);
|
Log.wtfStack(TAG, "Unexpected recognition event for model: " + model);
|
||||||
rebootHal();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (event.header.status
|
if (event.header.status
|
||||||
!= android.media.soundtrigger_middleware.RecognitionStatus.FORCED) {
|
!= android.media.soundtrigger_middleware.RecognitionStatus.FORCED) {
|
||||||
@@ -234,8 +173,6 @@ public class SoundTriggerHw2Enforcer implements ISoundTriggerHw2 {
|
|||||||
synchronized (mModelStates) {
|
synchronized (mModelStates) {
|
||||||
if (!mModelStates.getOrDefault(model, false)) {
|
if (!mModelStates.getOrDefault(model, false)) {
|
||||||
Log.wtfStack(TAG, "Unexpected recognition event for model: " + model);
|
Log.wtfStack(TAG, "Unexpected recognition event for model: " + model);
|
||||||
rebootHal();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (event.common.header.status
|
if (event.common.header.status
|
||||||
!= android.media.soundtrigger_middleware.RecognitionStatus.FORCED) {
|
!= android.media.soundtrigger_middleware.RecognitionStatus.FORCED) {
|
||||||
|
|||||||
@@ -27,7 +27,9 @@ import android.media.soundtrigger_middleware.PhraseSoundModel;
|
|||||||
import android.media.soundtrigger_middleware.RecognitionConfig;
|
import android.media.soundtrigger_middleware.RecognitionConfig;
|
||||||
import android.media.soundtrigger_middleware.SoundModel;
|
import android.media.soundtrigger_middleware.SoundModel;
|
||||||
import android.media.soundtrigger_middleware.SoundTriggerModuleDescriptor;
|
import android.media.soundtrigger_middleware.SoundTriggerModuleDescriptor;
|
||||||
|
import android.os.Parcel;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
|
import android.os.SystemProperties;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.server.SystemService;
|
import com.android.server.SystemService;
|
||||||
@@ -99,6 +101,28 @@ public class SoundTriggerMiddlewareService extends ISoundTriggerMiddlewareServic
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
|
||||||
|
throws RemoteException {
|
||||||
|
try {
|
||||||
|
return super.onTransact(code, data, reply, flags);
|
||||||
|
} catch (InternalServerError e) {
|
||||||
|
if (e.getCause() instanceof HalException) {
|
||||||
|
// We recover from any sort of HAL failure by rebooting the HAL process.
|
||||||
|
// This will likely reboot more than just the sound trigger HAL.
|
||||||
|
// The rest of the system should be able to tolerate that.
|
||||||
|
rebootHal();
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void rebootHal() {
|
||||||
|
Log.i(TAG, "Rebooting the sound trigger HAL");
|
||||||
|
// This property needs to be defined in an init.rc script and trigger a HAL reboot.
|
||||||
|
SystemProperties.set("sys.audio.restart.hal", "1");
|
||||||
|
}
|
||||||
|
|
||||||
private final static class ModuleService extends ISoundTriggerModule.Stub {
|
private final static class ModuleService extends ISoundTriggerModule.Stub {
|
||||||
private final ISoundTriggerModule mDelegate;
|
private final ISoundTriggerModule mDelegate;
|
||||||
|
|
||||||
@@ -158,6 +182,22 @@ public class SoundTriggerMiddlewareService extends ISoundTriggerMiddlewareServic
|
|||||||
public void detach() throws RemoteException {
|
public void detach() throws RemoteException {
|
||||||
mDelegate.detach();
|
mDelegate.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
|
||||||
|
throws RemoteException {
|
||||||
|
try {
|
||||||
|
return super.onTransact(code, data, reply, flags);
|
||||||
|
} catch (InternalServerError e) {
|
||||||
|
if (e.getCause() instanceof HalException) {
|
||||||
|
// We recover from any sort of HAL failure by rebooting the HAL process.
|
||||||
|
// This will likely reboot more than just the sound trigger HAL.
|
||||||
|
// The rest of the system should be able to tolerate that.
|
||||||
|
rebootHal();
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user