Skip to content

Commit 88e218e

Browse files
jianbingfruitChromium LUCI CQ
authored andcommitted
Reland "[CameraRoll]Send camera roll setting to the Android device in CrosState"
This is a reland of 3895114 Camera roll feature was not part of default feature map in MultiDeviceSetupClient,thus the newly added camera roll feature state entry in unit test was not destroyed correctly, causing memory leak. Added new camera roll feature into the default feature map in MultiDeviceSetupClient to address memory leak. Original change's description: > [CameraRoll]Send camera roll setting to the Android device in CrosState > > Include camera roll setting state as part of CrosState, > so connected mobile device would be able to get update > when setting value is toggled. > > Change-Id: I04d0ed3872d5adeff5e8f8dc76c6eb6df3a50b9c > Bug: https://crbug.com/1221297 > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3173740 > Commit-Queue: Jianbing Wu <[email protected]> > Auto-Submit: Jianbing Wu <[email protected]> > Reviewed-by: Jon Mann <[email protected]> > Cr-Commit-Position: refs/heads/main@{#924995} Bug: https://crbug.com/1221297 Change-Id: If1db5963f2a6689583f90c780c0a214421870180 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3187416 Commit-Queue: Jianbing Wu <[email protected]> Auto-Submit: Jianbing Wu <[email protected]> Reviewed-by: Jon Mann <[email protected]> Cr-Commit-Position: refs/heads/main@{#925646}
1 parent 6d41ee8 commit 88e218e

File tree

10 files changed

+60
-19
lines changed

10 files changed

+60
-19
lines changed

chromeos/components/phonehub/cros_state_sender.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,16 @@ void CrosStateSender::PerformUpdateCrosState() {
8989
bool are_notifications_enabled =
9090
multidevice_setup_client_->GetFeatureState(
9191
Feature::kPhoneHubNotifications) == FeatureState::kEnabledByUser;
92+
bool is_camera_roll_enabled =
93+
multidevice_setup_client_->GetFeatureState(
94+
Feature::kPhoneHubCameraRoll) == FeatureState::kEnabledByUser;
9295

9396
PA_LOG(INFO) << "Attempting to send cros state with notifications enabled "
94-
<< "state as: " << are_notifications_enabled;
95-
message_sender_->SendCrosState(are_notifications_enabled);
97+
<< "state as: " << are_notifications_enabled
98+
<< " and camera roll enabled state as: "
99+
<< is_camera_roll_enabled;
100+
message_sender_->SendCrosState(are_notifications_enabled,
101+
is_camera_roll_enabled);
96102

97103
retry_timer_->Start(FROM_HERE, retry_delay_,
98104
base::BindOnce(&CrosStateSender::OnRetryTimerFired,

chromeos/components/phonehub/cros_state_sender_unittest.cc

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ TEST_F(CrosStateSenderTest, UpdatesOnConnected) {
106106
// Set notification feature to be enabled.
107107
fake_multidevice_setup_client_->SetFeatureState(
108108
Feature::kPhoneHubNotifications, FeatureState::kEnabledByUser);
109+
// Set camera roll feature to be enabled.
110+
fake_multidevice_setup_client_->SetFeatureState(Feature::kPhoneHubCameraRoll,
111+
FeatureState::kEnabledByUser);
109112
// Expect no new messages since connection has not been established.
110113
EXPECT_EQ(0u, fake_message_sender_->GetCrosStateCallCount());
111114
EXPECT_FALSE(mock_timer_->IsRunning());
@@ -120,7 +123,8 @@ TEST_F(CrosStateSenderTest, UpdatesOnConnected) {
120123
// Simulate connected state. Expect a new message to be sent.
121124
fake_connection_manager_->SetStatus(
122125
secure_channel::ConnectionManager::Status::kConnected);
123-
EXPECT_TRUE(fake_message_sender_->GetRecentCrosState());
126+
EXPECT_TRUE(fake_message_sender_->GetRecentCrosState().first);
127+
EXPECT_TRUE(fake_message_sender_->GetRecentCrosState().second);
124128
EXPECT_EQ(1u, fake_message_sender_->GetCrosStateCallCount());
125129

126130
// Phone model is populated.
@@ -131,7 +135,8 @@ TEST_F(CrosStateSenderTest, UpdatesOnConnected) {
131135
// Simulate disconnected state, this should not trigger a new request.
132136
fake_connection_manager_->SetStatus(
133137
secure_channel::ConnectionManager::Status::kDisconnected);
134-
EXPECT_TRUE(fake_message_sender_->GetRecentCrosState());
138+
EXPECT_TRUE(fake_message_sender_->GetRecentCrosState().first);
139+
EXPECT_TRUE(fake_message_sender_->GetRecentCrosState().second);
135140
EXPECT_EQ(1u, fake_message_sender_->GetCrosStateCallCount());
136141
EXPECT_FALSE(mock_timer_->IsRunning());
137142
}
@@ -146,36 +151,44 @@ TEST_F(CrosStateSenderTest, NotificationFeatureStateChanged) {
146151
EXPECT_TRUE(mock_timer_->IsRunning());
147152

148153
// Expect new messages to be sent when connection state is connected.
149-
EXPECT_FALSE(fake_message_sender_->GetRecentCrosState());
154+
EXPECT_FALSE(fake_message_sender_->GetRecentCrosState().first);
155+
EXPECT_FALSE(fake_message_sender_->GetRecentCrosState().second);
150156
EXPECT_EQ(1u, fake_message_sender_->GetCrosStateCallCount());
151157
mock_timer_->Fire();
152158

153159
// Simulate enabling notification feature state and expect cros state to be
154160
// enabled.
155161
fake_multidevice_setup_client_->SetFeatureState(
156162
Feature::kPhoneHubNotifications, FeatureState::kEnabledByUser);
157-
EXPECT_TRUE(fake_message_sender_->GetRecentCrosState());
163+
EXPECT_TRUE(fake_message_sender_->GetRecentCrosState().first);
158164
EXPECT_EQ(2u, fake_message_sender_->GetCrosStateCallCount());
159165
mock_timer_->Fire();
160166

161167
// Update a different feature state and expect that it did not affect the
162168
// cros state.
163169
fake_multidevice_setup_client_->SetFeatureState(
164170
Feature::kSmartLock, FeatureState::kDisabledByUser);
165-
EXPECT_TRUE(fake_message_sender_->GetRecentCrosState());
171+
EXPECT_TRUE(fake_message_sender_->GetRecentCrosState().first);
166172
EXPECT_EQ(3u, fake_message_sender_->GetCrosStateCallCount());
167173
mock_timer_->Fire();
168174

169175
// Simulate disabling notification feature state and expect cros state to be
170176
// disabled.
171177
fake_multidevice_setup_client_->SetFeatureState(
172178
Feature::kPhoneHubNotifications, FeatureState::kDisabledByUser);
173-
EXPECT_FALSE(fake_message_sender_->GetRecentCrosState());
179+
EXPECT_FALSE(fake_message_sender_->GetRecentCrosState().first);
174180
EXPECT_EQ(4u, fake_message_sender_->GetCrosStateCallCount());
175181

182+
// Simulate enabling camera roll feature state and expect cros state to be
183+
// updated.
184+
fake_multidevice_setup_client_->SetFeatureState(Feature::kPhoneHubCameraRoll,
185+
FeatureState::kEnabledByUser);
186+
EXPECT_TRUE(fake_message_sender_->GetRecentCrosState().second);
187+
EXPECT_EQ(5u, fake_message_sender_->GetCrosStateCallCount());
188+
176189
// Firing the timer does not cause the cros state to be sent again.
177190
mock_timer_->Fire();
178-
EXPECT_EQ(4u, fake_message_sender_->GetCrosStateCallCount());
191+
EXPECT_EQ(5u, fake_message_sender_->GetCrosStateCallCount());
179192
}
180193

181194
} // namespace phonehub

chromeos/components/phonehub/fake_message_sender.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ namespace phonehub {
1010
FakeMessageSender::FakeMessageSender() = default;
1111
FakeMessageSender::~FakeMessageSender() = default;
1212

13-
void FakeMessageSender::SendCrosState(bool notification_enabled) {
14-
cros_states_.push_back(notification_enabled);
13+
void FakeMessageSender::SendCrosState(bool notification_enabled,
14+
bool camera_roll_enabled) {
15+
cros_states_.push_back(
16+
std::make_pair(notification_enabled, camera_roll_enabled));
1517
}
1618

1719
void FakeMessageSender::SendUpdateNotificationModeRequest(
@@ -77,7 +79,7 @@ size_t FakeMessageSender::GetFetchCameraRollItemsRequestCallCount() const {
7779
return fetch_camera_roll_items_requests_.size();
7880
}
7981

80-
bool FakeMessageSender::GetRecentCrosState() const {
82+
std::pair<bool, bool> FakeMessageSender::GetRecentCrosState() const {
8183
return cros_states_.back();
8284
}
8385

chromeos/components/phonehub/fake_message_sender.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class FakeMessageSender : public MessageSender {
2222
~FakeMessageSender() override;
2323

2424
// MessageSender:
25-
void SendCrosState(bool notification_enabled) override;
25+
void SendCrosState(bool notification_enabled,
26+
bool camera_roll_enabled) override;
2627
void SendUpdateNotificationModeRequest(bool do_not_disturb_enabled) override;
2728
void SendUpdateBatteryModeRequest(bool battery_saver_mode_enabled) override;
2829
void SendDismissNotificationRequest(int64_t notification_id) override;
@@ -34,7 +35,7 @@ class FakeMessageSender : public MessageSender {
3435
void SendFetchCameraRollItemsRequest(
3536
const proto::FetchCameraRollItemsRequest& request) override;
3637

37-
bool GetRecentCrosState() const;
38+
std::pair<bool, bool> GetRecentCrosState() const;
3839
bool GetRecentUpdateNotificationModeRequest() const;
3940
bool GetRecentUpdateBatteryModeRequest() const;
4041
int64_t GetRecentDismissNotificationRequest() const;
@@ -63,7 +64,9 @@ class FakeMessageSender : public MessageSender {
6364
size_t GetFetchCameraRollItemsRequestCallCount() const;
6465

6566
private:
66-
std::vector<bool> cros_states_;
67+
std::vector<std::pair</*is_notifications_setting_enabled*/ bool,
68+
/*is_camera_roll_setting_enabled*/ bool>>
69+
cros_states_;
6770
std::vector<bool> update_notification_mode_requests_;
6871
std::vector<bool> update_battery_mode_requests_;
6972
std::vector<int64_t> dismiss_notification_requests_;

chromeos/components/phonehub/message_sender.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class MessageSender {
2222
virtual ~MessageSender() = default;
2323

2424
// Sends whether the notification setting is enabled in the Chrome OS device.
25-
virtual void SendCrosState(bool notification_setting_enabled) = 0;
25+
virtual void SendCrosState(bool notification_setting_enabled,
26+
bool camera_roll_setting_enabled) = 0;
2627

2728
// Requests that the phone enables or disables Do Not Disturb mode.
2829
virtual void SendUpdateNotificationModeRequest(

chromeos/components/phonehub/message_sender_impl.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,18 @@ MessageSenderImpl::MessageSenderImpl(
3838

3939
MessageSenderImpl::~MessageSenderImpl() = default;
4040

41-
void MessageSenderImpl::SendCrosState(bool notification_setting_enabled) {
41+
void MessageSenderImpl::SendCrosState(bool notification_setting_enabled,
42+
bool camera_roll_setting_enabled) {
4243
proto::NotificationSetting is_notification_enabled =
4344
notification_setting_enabled
4445
? proto::NotificationSetting::NOTIFICATIONS_ON
4546
: proto::NotificationSetting::NOTIFICATIONS_OFF;
47+
proto::CameraRollSetting is_camera_roll_enabled =
48+
camera_roll_setting_enabled ? proto::CameraRollSetting::CAMERA_ROLL_ON
49+
: proto::CameraRollSetting::CAMERA_ROLL_OFF;
4650
proto::CrosState request;
4751
request.set_notification_setting(is_notification_enabled);
52+
request.set_camera_roll_setting(is_camera_roll_enabled);
4853

4954
SendMessage(proto::MessageType::PROVIDE_CROS_STATE, &request);
5055
}

chromeos/components/phonehub/message_sender_impl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class MessageSenderImpl : public MessageSender {
2727
~MessageSenderImpl() override;
2828

2929
// MessageSender:
30-
void SendCrosState(bool notification_setting_enabled) override;
30+
void SendCrosState(bool notification_setting_enabled,
31+
bool camera_roll_setting_enabled) override;
3132
void SendUpdateNotificationModeRequest(bool do_not_disturb_enabled) override;
3233
void SendUpdateBatteryModeRequest(bool battery_saver_mode_enabled) override;
3334
void SendDismissNotificationRequest(int64_t notification_id) override;

chromeos/components/phonehub/message_sender_unittest.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ TEST_F(MessageSenderImplTest, SendCrossState) {
6464
proto::CrosState request;
6565
request.set_notification_setting(
6666
proto::NotificationSetting::NOTIFICATIONS_ON);
67+
request.set_camera_roll_setting(proto::CameraRollSetting::CAMERA_ROLL_OFF);
6768

68-
message_sender_->SendCrosState(/*notification_enabled=*/true);
69+
message_sender_->SendCrosState(/*notification_enabled=*/true,
70+
/*camera_roll_enabled=*/false);
6971
VerifyMessage(proto::MessageType::PROVIDE_CROS_STATE, &request,
7072
fake_connection_manager_->sent_messages().back());
7173
}

chromeos/components/phonehub/proto/phonehub_api.proto

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ enum NotificationSetting {
4040
NOTIFICATIONS_ON = 1;
4141
}
4242

43+
enum CameraRollSetting {
44+
CAMERA_ROLL_OFF = 0;
45+
CAMERA_ROLL_ON = 1;
46+
}
47+
4348
enum ChargingState {
4449
NOT_CHARGING = 0;
4550
CHARGING_AC = 1;
@@ -162,6 +167,7 @@ message App {
162167

163168
message CrosState {
164169
NotificationSetting notification_setting = 1;
170+
CameraRollSetting camera_roll_setting = 2;
165171
}
166172

167173
message Action {

chromeos/services/multidevice_setup/public/cpp/multidevice_setup_client.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ MultiDeviceSetupClient::GenerateDefaultFeatureStatesMap() {
2828
{mojom::Feature::kPhoneHub, mojom::FeatureState::kProhibitedByPolicy},
2929
{mojom::Feature::kPhoneHubNotifications,
3030
mojom::FeatureState::kProhibitedByPolicy},
31+
{mojom::Feature::kPhoneHubCameraRoll,
32+
mojom::FeatureState::kProhibitedByPolicy},
3133
{mojom::Feature::kPhoneHubTaskContinuation,
3234
mojom::FeatureState::kProhibitedByPolicy},
3335
{mojom::Feature::kWifiSync, mojom::FeatureState::kProhibitedByPolicy},

0 commit comments

Comments
 (0)