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

Commit b07f0599 authored by Evan Severson's avatar Evan Severson
Browse files

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
parent 75c82108
Loading
Loading
Loading
Loading
+12 −0
Original line number Original line Diff line number Diff line
@@ -443,6 +443,8 @@ public class SoundTriggerService extends SystemService {


            enforceCallingPermission(Manifest.permission.MANAGE_SOUND_TRIGGER);
            enforceCallingPermission(Manifest.permission.MANAGE_SOUND_TRIGGER);


            enforceDetectionPermissions(detectionService);

            if (!isInitialized()) return STATUS_ERROR;
            if (!isInitialized()) return STATUS_ERROR;
            if (DEBUG) {
            if (DEBUG) {
                Slog.i(TAG, "startRecognition(): id = " + soundModelId);
                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
    // For logging