Commit 6b23be7a authored by Jason Lin's avatar Jason Lin Committed by Chromium LUCI CQ

Connect VmCameraMicManager with cras audio service

Bug: b/167491603
Change-Id: Ie4da3308869873ba57699daa4cc32659d188615e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2592577
Commit-Queue: Jason Lin <lxj@google.com>
Reviewed-by: default avatarJoel Hockey <joelhockey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#837475}
parent 4cfad706
...@@ -89,8 +89,7 @@ void VmCameraMicManager::OnPrimaryUserSessionStarted(Profile* primary_profile) { ...@@ -89,8 +89,7 @@ void VmCameraMicManager::OnPrimaryUserSessionStarted(Profile* primary_profile) {
vm_info_map_[vm] = {}; vm_info_map_[vm] = {};
} }
// Camera service does not behave in non ChromeOS environment (e.g. testing, // Only do the subscription in real ChromeOS environment.
// linux chromeos).
if (base::SysInfo::IsRunningOnChromeOS() && if (base::SysInfo::IsRunningOnChromeOS() &&
media::ShouldUseCrosCameraService()) { media::ShouldUseCrosCameraService()) {
auto* camera = media::CameraHalDispatcherImpl::GetInstance(); auto* camera = media::CameraHalDispatcherImpl::GetInstance();
...@@ -99,6 +98,14 @@ void VmCameraMicManager::OnPrimaryUserSessionStarted(Profile* primary_profile) { ...@@ -99,6 +98,14 @@ void VmCameraMicManager::OnPrimaryUserSessionStarted(Profile* primary_profile) {
camera->AddActiveClientObserver(this); camera->AddActiveClientObserver(this);
OnCameraPrivacySwitchStatusChanged( OnCameraPrivacySwitchStatusChanged(
camera->AddCameraPrivacySwitchObserver(this)); camera->AddCameraPrivacySwitchObserver(this));
CrasAudioHandler::Get()->AddAudioObserver(this);
// Fetch the current value.
content::GetUIThreadTaskRunner({})->PostTask(
FROM_HERE,
base::BindOnce(
&VmCameraMicManager::OnNumberOfInputStreamsWithPermissionChanged,
base::Unretained(this)));
} }
} }
...@@ -365,4 +372,21 @@ void VmCameraMicManager::VmNotificationObserver::Click( ...@@ -365,4 +372,21 @@ void VmCameraMicManager::VmNotificationObserver::Click(
open_settings_.Run(profile_); open_settings_.Run(profile_);
} }
void VmCameraMicManager::OnNumberOfInputStreamsWithPermissionChanged() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
const auto& clients_and_numbers =
CrasAudioHandler::Get()->GetNumberOfInputStreamsWithPermission();
auto update = [&](CrasAudioHandler::ClientType cras_client_type, VmType vm) {
auto it = clients_and_numbers.find(cras_client_type);
bool active = (it != clients_and_numbers.end() && it->second != 0);
UpdateVmInfoAndNotifications(vm, &VmInfo::SetMicActive, active);
};
update(CrasAudioHandler::ClientType::VM_TERMINA, VmType::kCrostiniVm);
update(CrasAudioHandler::ClientType::VM_PLUGIN, VmType::kPluginVm);
}
} // namespace chromeos } // namespace chromeos
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "base/observer_list_types.h" #include "base/observer_list_types.h"
#include "base/scoped_observation.h" #include "base/scoped_observation.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "chromeos/audio/cras_audio_handler.h"
#include "components/keyed_service/core/keyed_service.h" #include "components/keyed_service/core/keyed_service.h"
#include "media/capture/video/chromeos/camera_hal_dispatcher_impl.h" #include "media/capture/video/chromeos/camera_hal_dispatcher_impl.h"
#include "ui/message_center/public/cpp/notification.h" #include "ui/message_center/public/cpp/notification.h"
...@@ -31,7 +32,8 @@ namespace chromeos { ...@@ -31,7 +32,8 @@ namespace chromeos {
// we will also need to make the notification ids different for different // we will also need to make the notification ids different for different
// profiles. // profiles.
class VmCameraMicManager : public media::CameraActiveClientObserver, class VmCameraMicManager : public media::CameraActiveClientObserver,
public media::CameraPrivacySwitchObserver { public media::CameraPrivacySwitchObserver,
public CrasAudioHandler::AudioObserver {
public: public:
enum class VmType { kCrostiniVm, kPluginVm }; enum class VmType { kCrostiniVm, kPluginVm };
...@@ -136,6 +138,9 @@ class VmCameraMicManager : public media::CameraActiveClientObserver, ...@@ -136,6 +138,9 @@ class VmCameraMicManager : public media::CameraActiveClientObserver,
void OnCameraPrivacySwitchStatusChanged( void OnCameraPrivacySwitchStatusChanged(
cros::mojom::CameraPrivacySwitchState state) override; cros::mojom::CameraPrivacySwitchState state) override;
// CrasAudioHandler::AudioObserver
void OnNumberOfInputStreamsWithPermissionChanged() override;
static std::string GetNotificationId(VmType vm, NotificationType type); static std::string GetNotificationId(VmType vm, NotificationType type);
void UpdateVmInfoAndNotifications(VmType vm, void UpdateVmInfoAndNotifications(VmType vm,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment