Search in sources :

Example 16 with IRecognitionStatusCallback

use of android.hardware.soundtrigger.IRecognitionStatusCallback in project android_frameworks_base by DirtyUnicorns.

the class SoundTriggerHelper method stopRecognition.

/**
     * Stops recognition for the given ModelData instance.
     *
     * @param modelData Instance of {@link #ModelData} sound model.
     * @param callback The callback for the recognition events related to the given keyphrase.
     * @return One of {@link #STATUS_ERROR} or {@link #STATUS_OK}.
     */
private int stopRecognition(ModelData modelData, IRecognitionStatusCallback callback) {
    synchronized (mLock) {
        if (callback == null) {
            return STATUS_ERROR;
        }
        if (mModuleProperties == null || mModule == null) {
            Slog.w(TAG, "Attempting stopRecognition without the capability");
            return STATUS_ERROR;
        }
        IRecognitionStatusCallback currentCallback = modelData.getCallback();
        if (modelData == null || currentCallback == null || (!modelData.isRequested() && !modelData.isModelStarted())) {
            // startGenericRecognition hasn't been called or it failed.
            Slog.w(TAG, "Attempting stopRecognition without a successful startRecognition");
            return STATUS_ERROR;
        }
        if (currentCallback.asBinder() != callback.asBinder()) {
            // We don't allow a different listener to stop the recognition than the one
            // that started it.
            Slog.w(TAG, "Attempting stopRecognition for another recognition");
            return STATUS_ERROR;
        }
        // Request stop recognition via the update() method.
        modelData.setRequested(false);
        int status = updateRecognitionLocked(modelData, isRecognitionAllowed(), false);
        if (status != SoundTrigger.STATUS_OK) {
            return status;
        }
        // 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.
        modelData.setLoaded();
        modelData.clearCallback();
        modelData.setRecognitionConfig(null);
        if (!computeRecognitionRunningLocked()) {
            internalClearGlobalStateLocked();
        }
        return status;
    }
}
Also used : IRecognitionStatusCallback(android.hardware.soundtrigger.IRecognitionStatusCallback)

Example 17 with IRecognitionStatusCallback

use of android.hardware.soundtrigger.IRecognitionStatusCallback in project android_frameworks_base by ResurrectionRemix.

the class SoundTriggerHelper method onGenericRecognitionSuccessLocked.

private void onGenericRecognitionSuccessLocked(GenericRecognitionEvent event) {
    MetricsLogger.count(mContext, "sth_generic_recognition_event", 1);
    if (event.status != SoundTrigger.RECOGNITION_STATUS_SUCCESS) {
        return;
    }
    ModelData model = getModelDataForLocked(event.soundModelHandle);
    if (model == null || !model.isGenericModel()) {
        Slog.w(TAG, "Generic recognition event: Model does not exist for handle: " + event.soundModelHandle);
        return;
    }
    IRecognitionStatusCallback callback = model.getCallback();
    if (callback == null) {
        Slog.w(TAG, "Generic recognition event: Null callback for model handle: " + event.soundModelHandle);
        return;
    }
    try {
        callback.onGenericSoundTriggerDetected((GenericRecognitionEvent) event);
    } catch (RemoteException e) {
        Slog.w(TAG, "RemoteException in onGenericSoundTriggerDetected", e);
    }
    model.setStopped();
    RecognitionConfig config = model.getRecognitionConfig();
    if (config == null) {
        Slog.w(TAG, "Generic recognition event: Null RecognitionConfig for model handle: " + event.soundModelHandle);
        return;
    }
    model.setRequested(config.allowMultipleTriggers);
    // TODO: Remove this block if the lower layer supports multiple triggers.
    if (model.isRequested()) {
        updateRecognitionLocked(model, isRecognitionAllowed(), /* isAllowed */
        true);
    }
}
Also used : RecognitionConfig(android.hardware.soundtrigger.SoundTrigger.RecognitionConfig) RemoteException(android.os.RemoteException) IRecognitionStatusCallback(android.hardware.soundtrigger.IRecognitionStatusCallback)

Example 18 with IRecognitionStatusCallback

use of android.hardware.soundtrigger.IRecognitionStatusCallback in project android_frameworks_base by crdroidandroid.

the class SoundTriggerHelper method stopRecognition.

/**
     * Stops recognition for the given ModelData instance.
     *
     * @param modelData Instance of {@link #ModelData} sound model.
     * @param callback The callback for the recognition events related to the given keyphrase.
     * @return One of {@link #STATUS_ERROR} or {@link #STATUS_OK}.
     */
private int stopRecognition(ModelData modelData, IRecognitionStatusCallback callback) {
    synchronized (mLock) {
        if (callback == null) {
            return STATUS_ERROR;
        }
        if (mModuleProperties == null || mModule == null) {
            Slog.w(TAG, "Attempting stopRecognition without the capability");
            return STATUS_ERROR;
        }
        IRecognitionStatusCallback currentCallback = modelData.getCallback();
        if (modelData == null || currentCallback == null || (!modelData.isRequested() && !modelData.isModelStarted())) {
            // startGenericRecognition hasn't been called or it failed.
            Slog.w(TAG, "Attempting stopRecognition without a successful startRecognition");
            return STATUS_ERROR;
        }
        if (currentCallback.asBinder() != callback.asBinder()) {
            // We don't allow a different listener to stop the recognition than the one
            // that started it.
            Slog.w(TAG, "Attempting stopRecognition for another recognition");
            return STATUS_ERROR;
        }
        // Request stop recognition via the update() method.
        modelData.setRequested(false);
        int status = updateRecognitionLocked(modelData, isRecognitionAllowed(), false);
        if (status != SoundTrigger.STATUS_OK) {
            return status;
        }
        // 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.
        modelData.setLoaded();
        modelData.clearCallback();
        modelData.setRecognitionConfig(null);
        if (!computeRecognitionRunningLocked()) {
            internalClearGlobalStateLocked();
        }
        return status;
    }
}
Also used : IRecognitionStatusCallback(android.hardware.soundtrigger.IRecognitionStatusCallback)

Example 19 with IRecognitionStatusCallback

use of android.hardware.soundtrigger.IRecognitionStatusCallback in project android_frameworks_base by crdroidandroid.

the class SoundTriggerHelper method startRecognitionLocked.

// A single routine that implements the start recognition logic for both generic and keyphrase
// models.
private int startRecognitionLocked(ModelData modelData, boolean notify) {
    IRecognitionStatusCallback callback = modelData.getCallback();
    int handle = modelData.getHandle();
    RecognitionConfig config = modelData.getRecognitionConfig();
    if (callback == null || handle == INVALID_VALUE || config == null) {
        // Nothing to do here.
        Slog.w(TAG, "startRecognition: Bad data passed in.");
        MetricsLogger.count(mContext, "sth_start_recognition_error", 1);
        return STATUS_ERROR;
    }
    if (!isRecognitionAllowed()) {
        // Nothing to do here.
        Slog.w(TAG, "startRecognition requested but not allowed.");
        MetricsLogger.count(mContext, "sth_start_recognition_not_allowed", 1);
        return STATUS_OK;
    }
    int status = mModule.startRecognition(handle, config);
    if (status != SoundTrigger.STATUS_OK) {
        Slog.w(TAG, "startRecognition failed with " + status);
        MetricsLogger.count(mContext, "sth_start_recognition_error", 1);
        // Notify of error if needed.
        if (notify) {
            try {
                callback.onError(status);
            } catch (RemoteException e) {
                Slog.w(TAG, "RemoteException in onError", e);
            }
        }
    } else {
        Slog.i(TAG, "startRecognition successful.");
        MetricsLogger.count(mContext, "sth_start_recognition_success", 1);
        modelData.setStarted();
        // Notify of resume if needed.
        if (notify) {
            try {
                callback.onRecognitionResumed();
            } catch (RemoteException e) {
                Slog.w(TAG, "RemoteException in onRecognitionResumed", e);
            }
        }
    }
    if (DBG) {
        Slog.d(TAG, "Model being started :" + modelData.toString());
    }
    return status;
}
Also used : RecognitionConfig(android.hardware.soundtrigger.SoundTrigger.RecognitionConfig) RemoteException(android.os.RemoteException) IRecognitionStatusCallback(android.hardware.soundtrigger.IRecognitionStatusCallback)

Example 20 with IRecognitionStatusCallback

use of android.hardware.soundtrigger.IRecognitionStatusCallback in project android_frameworks_base by crdroidandroid.

the class SoundTriggerHelper method stopRecognitionLocked.

private int stopRecognitionLocked(ModelData modelData, boolean notify) {
    IRecognitionStatusCallback callback = modelData.getCallback();
    // Stop recognition.
    int status = STATUS_OK;
    status = mModule.stopRecognition(modelData.getHandle());
    if (status != SoundTrigger.STATUS_OK) {
        Slog.w(TAG, "stopRecognition call failed with " + status);
        MetricsLogger.count(mContext, "sth_stop_recognition_error", 1);
        if (notify) {
            try {
                callback.onError(status);
            } catch (RemoteException e) {
                Slog.w(TAG, "RemoteException in onError", e);
            }
        }
    } else {
        modelData.setStopped();
        MetricsLogger.count(mContext, "sth_stop_recognition_success", 1);
        // Notify of pause if needed.
        if (notify) {
            try {
                callback.onRecognitionPaused();
            } catch (RemoteException e) {
                Slog.w(TAG, "RemoteException in onRecognitionPaused", e);
            }
        }
    }
    if (DBG) {
        Slog.d(TAG, "Model being stopped :" + modelData.toString());
    }
    return status;
}
Also used : RemoteException(android.os.RemoteException) IRecognitionStatusCallback(android.hardware.soundtrigger.IRecognitionStatusCallback)

Aggregations

IRecognitionStatusCallback (android.hardware.soundtrigger.IRecognitionStatusCallback)20 RemoteException (android.os.RemoteException)16 RecognitionConfig (android.hardware.soundtrigger.SoundTrigger.RecognitionConfig)8