Skip to content

Commit

Permalink
boca:A few boca notification modifications.
Browse files Browse the repository at this point in the history
1. Use two different notification Id for caption and session
   notification, so that when caption turned on, a pop up would be
   triggered.
2. Update notification text.
3. Update warning level, which will show in non-ongoing process
   notification.

Test: Unit tested.
Bug: b:376143203
Change-Id: Iaa10d8aa6c95b15ed7eeb62662bd4305fea65ef9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5983834
Reviewed-by: Benjamin Zielinski <[email protected]>
Commit-Queue: April Zhou <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1378536}
  • Loading branch information
zhouyuzhe authored and Chromium LUCI CQ committed Nov 5, 2024
1 parent e22a0e7 commit ca74935
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 101 deletions.
1 change: 1 addition & 0 deletions chromeos/ash/components/boca/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ source_set("unit_tests") {
"//chromeos/ash/components/network",
"//chromeos/ash/services/network_config/public/cpp:test_support",
"//chromeos/services/network_config/public/cpp",
"//chromeos/strings:strings_grit",
"//components/gcm_driver",
"//components/gcm_driver:test_support",
"//components/prefs",
Expand Down
23 changes: 10 additions & 13 deletions chromeos/ash/components/boca/boca_session_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,12 @@ void BocaSessionManager::NotifyLocalCaptionEvents(
observer.OnLocalCaptionConfigUpdated(std::move(caption_config));
}
is_local_caption_enabled_ = caption_config.captions_enabled();
bool is_caption_enabled =
is_local_caption_enabled_ || GetSessionConfigSafe(current_session_.get())
.captions_config()
.captions_enabled();
if (is_producer_) {
BocaNotificationHandler::HandleCaptionNotification(
message_center::MessageCenter::Get(), is_caption_enabled);
notification_handler_.HandleCaptionNotification(
message_center::MessageCenter::Get(), is_local_caption_enabled_,
GetSessionConfigSafe(current_session_.get())
.captions_config()
.captions_enabled());
}
}

Expand Down Expand Up @@ -292,7 +291,7 @@ void BocaSessionManager::NotifySessionUpdate() {
StartSessionPolling(/*in_session=*/false);
observer.OnSessionEnded(previous_session_->session_id());
if (is_producer_) {
BocaNotificationHandler::HandleSessionEndedNotification(
notification_handler_.HandleSessionEndedNotification(
message_center::MessageCenter::Get());
}
}
Expand All @@ -305,7 +304,7 @@ void BocaSessionManager::NotifySessionUpdate() {
observer.OnSessionStarted(current_session_->session_id(),
current_session_->teacher());
if (is_producer_) {
BocaNotificationHandler::HandleSessionStartedNotification(
notification_handler_.HandleSessionStartedNotification(
message_center::MessageCenter::Get());
}
}
Expand Down Expand Up @@ -362,11 +361,9 @@ void BocaSessionManager::NotifySessionCaptionConfigUpdate() {
: std::string());
}
if (is_producer_) {
bool is_caption_enabled =
is_local_caption_enabled_ ||
current_session_caption_config.captions_enabled();
BocaNotificationHandler::HandleCaptionNotification(
message_center::MessageCenter::Get(), is_caption_enabled);
notification_handler_.HandleCaptionNotification(
message_center::MessageCenter::Get(), is_local_caption_enabled_,
current_session_caption_config.captions_enabled());
}
}
}
Expand Down
1 change: 1 addition & 0 deletions chromeos/ash/components/boca/boca_session_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ class BocaSessionManager
cros_network_config_observer_{this};
AccountId account_id_;
std::u16string active_tab_title_;
BocaNotificationHandler notification_handler_;
raw_ptr<SessionClientImpl> session_client_impl_;
raw_ptr<signin::IdentityManager> identity_manager_;
bool is_local_caption_enabled_ = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,26 @@
#include "ui/message_center/public/cpp/notification_types.h"

namespace ash::boca {
void BocaNotificationHandler::HandleSessionStartedNotification(
message_center::MessageCenter* message_center) {
if (!message_center) {
return;
}
if (message_center->FindNotificationById(kNotificationId)) {
return;
}

namespace {
std::unique_ptr<message_center::Notification> CreateBaseNotificationForMessage(
std::string notification_id,
int message_id) {
message_center::RichNotificationData optional_fields;
optional_fields.pinned = true;
optional_fields.priority = message_center::HIGH_PRIORITY;

optional_fields.buttons.emplace_back(
l10n_util::GetStringUTF16(IDS_BOCA_CONNECTED_TO_CLASS_BUTTON_TEXT));
auto notification = CreateSystemNotificationPtr(
return CreateSystemNotificationPtr(
message_center::NotificationType::NOTIFICATION_TYPE_SIMPLE,
kNotificationId, l10n_util::GetStringUTF16(IDS_BOCA_NOTIFICATION_TITLE),
l10n_util::GetStringUTF16(
IDS_BOCA_CONNECTED_TO_CLASS_NOTIFICATION_MESSAGE),
notification_id,
/*title=*/l10n_util::GetStringUTF16(IDS_BOCA_NOTIFICATION_TITLE),
l10n_util::GetStringUTF16(message_id),
/*display_source=*/std::u16string(),
/*origin_url=*/GURL(),
message_center::NotifierId(message_center::NotifierType::SYSTEM_COMPONENT,
kPrivacyIndicatorsNotifierId,
NotificationCatalogName::kPrivacyIndicators),
message_center::NotifierId(
message_center::NotifierType::SYSTEM_COMPONENT,
BocaNotificationHandler::kSessionNotificationId,
NotificationCatalogName::kPrivacyIndicators),
optional_fields,
base::MakeRefCounted<message_center::HandleNotificationClickDelegate>(
base::BindRepeating([](std::optional<int> button_index) {
Expand All @@ -46,37 +42,72 @@ void BocaNotificationHandler::HandleSessionStartedNotification(
}
BocaAppClient::Get()->LaunchApp();
})),
kSecurityIcon,
message_center::SystemNotificationWarningLevel::CRITICAL_WARNING);
kSecurityIcon, message_center::SystemNotificationWarningLevel::NORMAL);
}
} // namespace

message_center->AddNotification(std::move(notification));
void BocaNotificationHandler::HandleSessionStartedNotification(
message_center::MessageCenter* message_center) {
is_session_started_ = true;
if (!message_center) {
return;
}
message_center->RemoveNotification(kCaptionNotificationId,
/*by_user=*/false);
if (message_center->FindNotificationById(kSessionNotificationId)) {
return;
}
message_center->AddNotification(CreateBaseNotificationForMessage(
kSessionNotificationId,
IDS_BOCA_CONNECTED_TO_CLASS_NOTIFICATION_MESSAGE));
}

void BocaNotificationHandler::HandleSessionEndedNotification(
message_center::MessageCenter* message_center) {
is_session_started_ = false;
if (!message_center) {
return;
}

auto* notification_exists =
message_center->FindNotificationById(kNotificationId);
if (notification_exists) {
message_center->RemoveNotification(kNotificationId, /*by_user=*/false);
message_center->RemoveNotification(kSessionNotificationId,
/*by_user=*/false);
// Remove session caption notification when session ended.
if (!is_local_caption_enabled_) {
message_center->RemoveNotification(kCaptionNotificationId,
/*by_user=*/false);
}
}

void BocaNotificationHandler::HandleCaptionNotification(
message_center::MessageCenter* message_center,
bool is_caption_enabled) {
bool is_local_caption_enabled,
bool is_session_caption_enabled) {
is_local_caption_enabled_ = is_local_caption_enabled;
is_session_caption_enabled_ = is_session_caption_enabled;
if (!message_center) {
return;
}
auto* notification = message_center->FindNotificationById(kNotificationId);
if (!notification) {
return;
auto* notification =
message_center->FindNotificationById(kCaptionNotificationId);

if (is_local_caption_enabled || is_session_caption_enabled) {
if (notification) {
return;
}
message_center->RemoveNotification(kSessionNotificationId,
/*by_user=*/false);
message_center->AddNotification(CreateBaseNotificationForMessage(
kCaptionNotificationId,
IDS_BOCA_MICROPHONE_IN_USE_NOTIFICATION_MESSAGE));
} else {
message_center->RemoveNotification(kCaptionNotificationId,
/*by_user=*/false);

if (is_session_started_) {
message_center->AddNotification(CreateBaseNotificationForMessage(
kSessionNotificationId,
IDS_BOCA_CONNECTED_TO_CLASS_NOTIFICATION_MESSAGE));
}
}
is_caption_enabled ? notification->set_message(l10n_util::GetStringUTF16(
IDS_BOCA_MICROPHONE_IN_USE_NOTIFICATION_MESSAGE))
: notification->set_message(l10n_util::GetStringUTF16(
IDS_BOCA_CONNECTED_TO_CLASS_NOTIFICATION_MESSAGE));
}

} // namespace ash::boca
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,26 @@ namespace ash::boca {
// Handles Class hub notifications.
class BocaNotificationHandler {
public:
inline static constexpr char kNotificationId[] = "school-tools";
inline static constexpr char kSessionNotificationId[] =
"school-tools-session";
inline static constexpr char kCaptionNotificationId[] =
"school-tools-caption";

// Handle session started notification.
static void HandleSessionStartedNotification(
void HandleSessionStartedNotification(
message_center::MessageCenter* message_center);
// Handle session ended notification.
static void HandleSessionEndedNotification(
void HandleSessionEndedNotification(
message_center::MessageCenter* message_center);
// Handle caption notification.
static void HandleCaptionNotification(
message_center::MessageCenter* message_center,
bool is_caption_enabled);
void HandleCaptionNotification(message_center::MessageCenter* message_center,
bool is_local_caption_enabled,
bool is_session_caption_enabled);

private:
bool is_local_caption_enabled_ = false;
bool is_session_caption_enabled_ = false;
bool is_session_started_ = false;
};
} // namespace ash::boca

Expand Down
Loading

0 comments on commit ca74935

Please sign in to comment.