Loading services/audiopolicy/service/AudioRecordClient.cpp +25 −1 Original line number Diff line number Diff line Loading @@ -14,6 +14,8 @@ * limitations under the License. */ #include <android/content/pm/IPackageManagerNative.h> #include "AudioRecordClient.h" #include "AudioPolicyService.h" Loading @@ -34,6 +36,24 @@ bool isAppOpSource(audio_source_t source) } return true; } int getTargetSdkForPackageName(std::string_view packageName) { const auto binder = defaultServiceManager()->checkService(String16{"package_native"}); int targetSdk = -1; if (binder != nullptr) { const auto pm = interface_cast<content::pm::IPackageManagerNative>(binder); if (pm != nullptr) { const auto status = pm->getTargetSdkVersionForPackage( String16{packageName.data(), packageName.size()}, &targetSdk); return status.isOk() ? targetSdk : -1; } } return targetSdk; } bool doesPackageTargetAtLeastU(std::string_view packageName) { return getTargetSdkForPackageName(packageName) >= __ANDROID_API_U__; } } // static Loading Loading @@ -82,11 +102,15 @@ void OpRecordAudioMonitor::onFirstRef() checkOp(); mOpCallback = new RecordAudioOpCallback(this); ALOGV("start watching op %d for %s", mAppOp, mAttributionSource.toString().c_str()); int flags = doesPackageTargetAtLeastU( mAttributionSource.packageName.value_or("")) ? AppOpsManager::WATCH_FOREGROUND_CHANGES : 0; // TODO: We need to always watch AppOpsManager::OP_RECORD_AUDIO too // since it controls the mic permission for legacy apps. mAppOpsManager.startWatchingMode(mAppOp, VALUE_OR_FATAL(aidl2legacy_string_view_String16( mAttributionSource.packageName.value_or(""))), AppOpsManager::WATCH_FOREGROUND_CHANGES, flags, mOpCallback); } Loading Loading
services/audiopolicy/service/AudioRecordClient.cpp +25 −1 Original line number Diff line number Diff line Loading @@ -14,6 +14,8 @@ * limitations under the License. */ #include <android/content/pm/IPackageManagerNative.h> #include "AudioRecordClient.h" #include "AudioPolicyService.h" Loading @@ -34,6 +36,24 @@ bool isAppOpSource(audio_source_t source) } return true; } int getTargetSdkForPackageName(std::string_view packageName) { const auto binder = defaultServiceManager()->checkService(String16{"package_native"}); int targetSdk = -1; if (binder != nullptr) { const auto pm = interface_cast<content::pm::IPackageManagerNative>(binder); if (pm != nullptr) { const auto status = pm->getTargetSdkVersionForPackage( String16{packageName.data(), packageName.size()}, &targetSdk); return status.isOk() ? targetSdk : -1; } } return targetSdk; } bool doesPackageTargetAtLeastU(std::string_view packageName) { return getTargetSdkForPackageName(packageName) >= __ANDROID_API_U__; } } // static Loading Loading @@ -82,11 +102,15 @@ void OpRecordAudioMonitor::onFirstRef() checkOp(); mOpCallback = new RecordAudioOpCallback(this); ALOGV("start watching op %d for %s", mAppOp, mAttributionSource.toString().c_str()); int flags = doesPackageTargetAtLeastU( mAttributionSource.packageName.value_or("")) ? AppOpsManager::WATCH_FOREGROUND_CHANGES : 0; // TODO: We need to always watch AppOpsManager::OP_RECORD_AUDIO too // since it controls the mic permission for legacy apps. mAppOpsManager.startWatchingMode(mAppOp, VALUE_OR_FATAL(aidl2legacy_string_view_String16( mAttributionSource.packageName.value_or(""))), AppOpsManager::WATCH_FOREGROUND_CHANGES, flags, mOpCallback); } Loading