Commit ce2ec525 authored by Toni Barzic's avatar Toni Barzic Committed by Chromium LUCI CQ

Tweak logic for showing camera privacy switch notification

On some boards privacy switch state gets reported only when the camera
is active (due to hardware limitations). In these case, when the camera
is off, chrome will notice the privacy switch is on only after the
active camera client gets set - in these cases, prefer showing
notification over toast when the camera privacy switch state changes to
ON (from UNKNOWN).

Change-Id: I55990b10d3b89285b9fe064d87e5bf82adf453c3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2625821Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Toni Baržić <tbarzic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#843141}
parent 4f5be97a
......@@ -328,6 +328,17 @@ void MediaClientImpl::OnCameraPrivacySwitchStatusChanged(
case cros::mojom::CameraPrivacySwitchState::UNKNOWN:
break;
case cros::mojom::CameraPrivacySwitchState::ON: {
// On some devices, the camera privacy switch state can only be detected
// while the camera is active. In that case the privacy switch state will
// become known as the camera becomes active, in which case showing a
// notification is preferred to showing a toast.
if (is_camera_active_ &&
camera_privacy_switch_state_ ==
cros::mojom::CameraPrivacySwitchState::UNKNOWN) {
ShowCameraOffNotification();
break;
}
ash::ToastManager::Get()->Cancel(kCameraPrivacySwitchOffToastId);
ash::ToastData toast(
kCameraPrivacySwitchOnToastId,
......@@ -367,26 +378,11 @@ void MediaClientImpl::OnCameraPrivacySwitchStatusChanged(
void MediaClientImpl::OnActiveClientChange(cros::mojom::CameraClientType type,
bool is_active) {
is_camera_active_ = is_active;
if (is_active && camera_privacy_switch_state_ ==
cros::mojom::CameraPrivacySwitchState::ON) {
std::unique_ptr<message_center::Notification> notification =
ash::CreateSystemNotification(
message_center::NOTIFICATION_TYPE_SIMPLE,
kCameraPrivacySwitchOnNotificationId,
l10n_util::GetStringUTF16(
IDS_CAMERA_PRIVACY_SWITCH_ON_NOTIFICATION_TITLE),
l10n_util::GetStringUTF16(
IDS_CAMERA_PRIVACY_SWITCH_ON_NOTIFICATION_MESSAGE),
base::string16(), GURL(),
message_center::NotifierId(
message_center::NotifierType::SYSTEM_COMPONENT,
kCameraPrivacySwitchNotifierId),
message_center::RichNotificationData(),
new message_center::HandleNotificationClickDelegate(
base::DoNothing::Repeatedly()),
vector_icons::kVideocamOffIcon,
message_center::SystemNotificationWarningLevel::NORMAL);
SystemNotificationHelper::GetInstance()->Display(*notification);
ShowCameraOffNotification();
}
}
......@@ -476,3 +472,27 @@ void MediaClientImpl::HandleMediaAction(ui::KeyboardCode keycode) {
break;
}
}
void MediaClientImpl::ShowCameraOffNotification() {
SystemNotificationHelper::GetInstance()->Close(
kCameraPrivacySwitchOnNotificationId);
std::unique_ptr<message_center::Notification> notification =
ash::CreateSystemNotification(
message_center::NOTIFICATION_TYPE_SIMPLE,
kCameraPrivacySwitchOnNotificationId,
l10n_util::GetStringUTF16(
IDS_CAMERA_PRIVACY_SWITCH_ON_NOTIFICATION_TITLE),
l10n_util::GetStringUTF16(
IDS_CAMERA_PRIVACY_SWITCH_ON_NOTIFICATION_MESSAGE),
base::string16(), GURL(),
message_center::NotifierId(
message_center::NotifierType::SYSTEM_COMPONENT,
kCameraPrivacySwitchNotifierId),
message_center::RichNotificationData(),
new message_center::HandleNotificationClickDelegate(
base::DoNothing::Repeatedly()),
vector_icons::kVideocamOffIcon,
message_center::SystemNotificationWarningLevel::NORMAL);
SystemNotificationHelper::GetInstance()->Display(*notification);
}
......@@ -98,6 +98,10 @@ class MediaClientImpl : public ash::MediaClient,
// delegate. Otherwise, we will forward the action to the extensions API.
void HandleMediaAction(ui::KeyboardCode code);
// Shows a notification informing the user that an app is trying to use the
// camera while the camera privacy switch is turned on.
void ShowCameraOffNotification();
ash::MediaController* media_controller_ = nullptr;
base::flat_map<content::BrowserContext*, ui::MediaKeysListener::Delegate*>
......@@ -116,6 +120,8 @@ class MediaClientImpl : public ash::MediaClient,
cros::mojom::CameraPrivacySwitchState camera_privacy_switch_state_ =
cros::mojom::CameraPrivacySwitchState::UNKNOWN;
bool is_camera_active_ = false;
base::WeakPtrFactory<MediaClientImpl> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(MediaClientImpl);
......
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