Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bae80e0d authored by Nate Myren's avatar Nate Myren Committed by Android (Google) Code Review
Browse files

Merge "Cancel RecognitionService if permission check fails" into sc-dev

parents ece342ba 6978614a
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -120,9 +120,15 @@ public abstract class RecognitionService extends Service {
                }
                mCurrentCallback = new Callback(listener, attributionSource);

                boolean preflightPermissionCheckPassed =
                        checkPermissionForPreflight();
                if (preflightPermissionCheckPassed) {
                    RecognitionService.this.onStartListening(intent, mCurrentCallback);
                if (!checkPermissionAndStartDataDelivery()) {
                }
                if (!preflightPermissionCheckPassed || !checkPermissionAndStartDataDelivery()) {
                    listener.onError(SpeechRecognizer.ERROR_INSUFFICIENT_PERMISSIONS);
                    RecognitionService.this.onCancel(mCurrentCallback);
                    dispatchClearCallback();
                    Log.i(TAG, "caller doesn't have permission:"
                            + Manifest.permission.RECORD_AUDIO);
                }
@@ -460,6 +466,12 @@ public abstract class RecognitionService extends Service {
        return mStartedDataDelivery;
    }

    private boolean checkPermissionForPreflight() {
        return PermissionChecker.checkPermissionForPreflight(RecognitionService.this,
                Manifest.permission.RECORD_AUDIO, mCurrentCallback.getAttributionContextForCaller()
                        .getAttributionSource()) == PermissionChecker.PERMISSION_GRANTED;
    }

    void finishDataDelivery() {
        if (mStartedDataDelivery) {
            mStartedDataDelivery = false;