Merge "Cancel RecognitionService if permission check fails" into sc-dev
This commit is contained in:
@@ -120,9 +120,15 @@ public abstract class RecognitionService extends Service {
|
|||||||
}
|
}
|
||||||
mCurrentCallback = new Callback(listener, attributionSource);
|
mCurrentCallback = new Callback(listener, attributionSource);
|
||||||
|
|
||||||
RecognitionService.this.onStartListening(intent, mCurrentCallback);
|
boolean preflightPermissionCheckPassed =
|
||||||
if (!checkPermissionAndStartDataDelivery()) {
|
checkPermissionForPreflight();
|
||||||
|
if (preflightPermissionCheckPassed) {
|
||||||
|
RecognitionService.this.onStartListening(intent, mCurrentCallback);
|
||||||
|
}
|
||||||
|
if (!preflightPermissionCheckPassed || !checkPermissionAndStartDataDelivery()) {
|
||||||
listener.onError(SpeechRecognizer.ERROR_INSUFFICIENT_PERMISSIONS);
|
listener.onError(SpeechRecognizer.ERROR_INSUFFICIENT_PERMISSIONS);
|
||||||
|
RecognitionService.this.onCancel(mCurrentCallback);
|
||||||
|
dispatchClearCallback();
|
||||||
Log.i(TAG, "caller doesn't have permission:"
|
Log.i(TAG, "caller doesn't have permission:"
|
||||||
+ Manifest.permission.RECORD_AUDIO);
|
+ Manifest.permission.RECORD_AUDIO);
|
||||||
}
|
}
|
||||||
@@ -460,6 +466,12 @@ public abstract class RecognitionService extends Service {
|
|||||||
return mStartedDataDelivery;
|
return mStartedDataDelivery;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean checkPermissionForPreflight() {
|
||||||
|
return PermissionChecker.checkPermissionForPreflight(RecognitionService.this,
|
||||||
|
Manifest.permission.RECORD_AUDIO, mCurrentCallback.getAttributionContextForCaller()
|
||||||
|
.getAttributionSource()) == PermissionChecker.PERMISSION_GRANTED;
|
||||||
|
}
|
||||||
|
|
||||||
void finishDataDelivery() {
|
void finishDataDelivery() {
|
||||||
if (mStartedDataDelivery) {
|
if (mStartedDataDelivery) {
|
||||||
mStartedDataDelivery = false;
|
mStartedDataDelivery = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user