Add privilege check for audio capturer 34/321134/2
authorpeng.yin <peng8.yin@samsung.com>
Wed, 27 Nov 2024 03:41:36 +0000 (11:41 +0800)
committerBot Blink <blinkbot@samsung.com>
Thu, 28 Nov 2024 10:06:17 +0000 (10:06 +0000)
any app that wants to capture system audio should have the
corresponding privilege, so before opening the corresponding
device we check it by the cynara module.

Change-Id: I45cec311b095ef65a325704c69fb16aab3e8b80b
Signed-off-by: peng.yin <peng8.yin@samsung.com>
tizen_src/chromium_impl/media/audio/tizen/capi_usb_audio_input_stream.cc

index 1d3f23154e68bc7a051eafc7b45d9958c6ad5def..98061c6781cc37606ab60beb33687de7f28615a4 100644 (file)
 #include "base/logging.h"
 #include "media/audio/tizen/audio_manager_capi.h"
 
+#if BUILDFLAG(IS_TIZEN_TV)
+#include "wrt/src/common/privilege.h"
+#endif
+
 #include <sound_manager_internal.h>
 namespace media {
 
+#if BUILDFLAG(IS_TIZEN_TV)
+constexpr char kMediaCapturePrivilege[] =
+    "http://tizen.org/privilege/mediacapture";
+#endif
+
 CapiUsbAudioInputStream::CapiUsbAudioInputStream(
     AudioManagerCapi* audio_manager,
     const std::string& device_name,
@@ -96,6 +105,19 @@ bool CapiUsbAudioInputStream::OpenMic() {
     return false;
   }
 
+#if BUILDFLAG(IS_TIZEN_TV)
+  // Check privilege for audio forwarding device used to capture system
+  // output audio.
+  if (device_type == SOUND_DEVICE_FORWARDING) {
+    auto has_privilege =
+        wrt::privilege::FindPrivilegeFromCynara(kMediaCapturePrivilege);
+    if (!has_privilege) {
+      LOG(ERROR) << "No system audio capture privilege.";
+      return false;
+    }
+  }
+#endif
+
   stream_info_ = nullptr;
 
   ret = sound_manager_create_stream_information(stream_type, nullptr, nullptr,