OSDN Git Service

Enforce permission for accessing fm tuner
authorScott Mertz <scott@cyngn.com>
Wed, 6 Jul 2016 17:18:52 +0000 (10:18 -0700)
committerGerrit Code Review <gerrit@cyanogenmod.org>
Fri, 8 Jul 2016 19:01:48 +0000 (12:01 -0700)
Change-Id: I13f3ba8fc9caaeee21597a2405a8c3629e985502

services/audioflinger/ServiceUtilities.cpp
services/audioflinger/ServiceUtilities.h
services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp
services/audiopolicy/service/AudioPolicyInterfaceImplLegacy.cpp

index 2e68dad..031ff05 100644 (file)
@@ -106,6 +106,14 @@ bool captureAudioOutputAllowed() {
     return ok;
 }
 
+bool accessFmRadioAllowed() {
+    static const String16 sAccessFmRadio("android.permission.ACCESS_FM_RADIO");
+    // IMPORTANT: Use PermissionCache - not a runtime permission and may not change.
+    bool ok = PermissionCache::checkCallingPermission(sAccessFmRadio);
+    if (!ok) ALOGE("Request requires android.permission.ACCESS_FM_RADIO");
+    return ok;
+}
+
 bool captureHotwordAllowed() {
     static const String16 sCaptureHotwordAllowed("android.permission.CAPTURE_AUDIO_HOTWORD");
     // IMPORTANT: Use PermissionCache - not a runtime permission and may not change.
index fba6dce..dffb114 100644 (file)
@@ -21,6 +21,7 @@ namespace android {
 extern pid_t getpid_cached;
 
 bool recordingAllowed(const String16& opPackageName);
+bool accessFmRadioAllowed();
 bool captureAudioOutputAllowed();
 bool captureHotwordAllowed();
 bool settingsAllowed();
index f0be341..b23c35e 100644 (file)
@@ -316,6 +316,11 @@ status_t AudioPolicyService::getInputForAttr(const audio_attributes_t *attr,
     if ((attr->source == AUDIO_SOURCE_HOTWORD) && !captureHotwordAllowed()) {
         return BAD_VALUE;
     }
+
+    if ((attr->source == AUDIO_SOURCE_FM_TUNER) && !accessFmRadioAllowed()) {
+        return BAD_VALUE;
+    }
+
     sp<AudioPolicyEffects>audioPolicyEffects;
     status_t status;
     AudioPolicyInterface::input_type_t inputType;
index 0aad54d..da7f45d 100644 (file)
@@ -275,6 +275,10 @@ status_t AudioPolicyService::getInputForAttr(const audio_attributes_t *attr,
         return BAD_VALUE;
     }
 
+    if ((inputSource == AUDIO_SOURCE_FM_TUNER) && !accessFmRadioAllowed()) {
+        return BAD_VALUE;
+    }
+
 #ifdef HAVE_PRE_KITKAT_AUDIO_POLICY_BLOB
     if (inputSource == AUDIO_SOURCE_HOTWORD)
         inputSource = AUDIO_SOURCE_VOICE_RECOGNITION;