Check permission for soundtrigger detection service

The app which gets bound to use microphone in the background should be
holding the CAPTURE_AUDIO_HOTWORD permission.

Test: Verify current services still work
      Verify that app without permission can't be registered
Bug: 155438570
Change-Id: I4b53c45bc74df4e91026e13c7e2bfa0f5461df52
This commit is contained in:
Evan Severson
2020-04-30 17:03:48 -07:00
parent 75c82108f6
commit b07f0599bb

View File

@@ -443,6 +443,8 @@ public class SoundTriggerService extends SystemService {
enforceCallingPermission(Manifest.permission.MANAGE_SOUND_TRIGGER);
enforceDetectionPermissions(detectionService);
if (!isInitialized()) return STATUS_ERROR;
if (DEBUG) {
Slog.i(TAG, "startRecognition(): id = " + soundModelId);
@@ -1532,6 +1534,16 @@ public class SoundTriggerService extends SystemService {
}
}
private void enforceDetectionPermissions(ComponentName detectionService) {
PackageManager packageManager = mContext.getPackageManager();
String packageName = detectionService.getPackageName();
if (packageManager.checkPermission(Manifest.permission.CAPTURE_AUDIO_HOTWORD, packageName)
!= PackageManager.PERMISSION_GRANTED) {
throw new SecurityException(detectionService.getPackageName() + " does not have"
+ " permission " + Manifest.permission.CAPTURE_AUDIO_HOTWORD);
}
}
//=================================================================
// For logging