Commit 3d1898ca authored by Rachel Wong's avatar Rachel Wong Committed by Commit Bot

Implement logging for network settings.

The code that will call this logging function is at
https://chromium-review.googlesource.com/c/chromium/src/+/1999973.

Bug: 1014839
Change-Id: Iccf37f350ead2e5f900624e2ad554aedbd54bc6a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1989735Reviewed-by: default avatarJia Meng <jiameng@chromium.org>
Reviewed-by: default avatarThanh Nguyen <thanhdng@chromium.org>
Commit-Queue: Rachel Wong <wrong@chromium.org>
Cr-Commit-Position: refs/heads/master@{#733515}
parent cfbc3114
...@@ -93,10 +93,12 @@ message UserSettingsEvent { ...@@ -93,10 +93,12 @@ message UserSettingsEvent {
optional DeviceMode device_mode = 13; optional DeviceMode device_mode = 13;
optional DeviceOrientation device_orientation = 14; optional DeviceOrientation device_orientation = 14;
// Whether there are wifi networks available for connection. // The signal strength for the connected network. Only populated upon
optional bool has_available_wifi_networks = 15; // connection to a wifi or cellular network.
// Whether there are mobile data networks available for connection. optional int32 signal_strength = 15;
optional bool has_available_cellular_networks = 16; // Whether or not the current wifi network has security. Only populated upon
// connection to a wifi network.
optional bool has_wifi_security = 16;
// Whether the user has connected to a cellular network in the current // Whether the user has connected to a cellular network in the current
// session. // session.
optional bool used_cellular_in_session = 17; optional bool used_cellular_in_session = 17;
......
...@@ -4,11 +4,17 @@ ...@@ -4,11 +4,17 @@
#include "ash/system/machine_learning/user_settings_event_logger.h" #include "ash/system/machine_learning/user_settings_event_logger.h"
#include "ash/shell.h"
#include "base/logging.h" #include "base/logging.h"
#include "chromeos/services/network_config/public/mojom/cros_network_config.mojom.h"
namespace ash { namespace ash {
namespace ml { namespace ml {
using chromeos::network_config::mojom::NetworkStateProperties;
using chromeos::network_config::mojom::NetworkType;
using chromeos::network_config::mojom::SecurityType;
// static // static
UserSettingsEventLogger* UserSettingsEventLogger::instance_ = nullptr; UserSettingsEventLogger* UserSettingsEventLogger::instance_ = nullptr;
...@@ -29,13 +35,50 @@ UserSettingsEventLogger* UserSettingsEventLogger::Get() { ...@@ -29,13 +35,50 @@ UserSettingsEventLogger* UserSettingsEventLogger::Get() {
return instance_; return instance_;
} }
void UserSettingsEventLogger::LogUkmEvent() { UserSettingsEventLogger::UserSettingsEventLogger()
// TODO(crbug/1014839): Populate a settings event and log it to UKM. : used_cellular_in_session_(false) {}
UserSettingsEventLogger::~UserSettingsEventLogger() = default;
void UserSettingsEventLogger::LogNetworkUkmEvent(
const NetworkStateProperties& network) {
UserSettingsEvent settings_event;
auto* const event = settings_event.mutable_event();
auto* const features = settings_event.mutable_features();
if (network.type == NetworkType::kWiFi) {
event->set_setting_id(UserSettingsEvent::Event::WIFI);
const auto& wifi_state = network.type_state->get_wifi();
features->set_signal_strength(wifi_state->signal_strength);
features->set_has_wifi_security(wifi_state->security !=
SecurityType::kNone);
} else if (network.type == NetworkType::kCellular) {
event->set_setting_id(UserSettingsEvent::Event::CELLULAR);
features->set_signal_strength(
network.type_state->get_cellular()->signal_strength);
features->set_used_cellular_in_session(used_cellular_in_session_);
used_cellular_in_session_ = true;
} else {
// We are not interested in other types of networks.
return;
}
event->set_setting_type(UserSettingsEvent::Event::QUICK_SETTINGS);
// Convert the setting state to an int. Some settings have multiple states, so
// all setting states are stored as ints.
event->set_current_value(1);
PopulateSharedFeatures(&settings_event);
SendToUkm(settings_event);
} }
UserSettingsEventLogger::UserSettingsEventLogger() = default; void UserSettingsEventLogger::PopulateSharedFeatures(UserSettingsEvent* event) {
// TODO(crbug/1014839): Populate the shared contextual features.
}
UserSettingsEventLogger::~UserSettingsEventLogger() = default; void UserSettingsEventLogger::SendToUkm(const UserSettingsEvent& event) {
// TODO(crbug/1014839): Implement UKM logging.
}
} // namespace ml } // namespace ml
} // namespace ash } // namespace ash
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define ASH_SYSTEM_MACHINE_LEARNING_USER_SETTINGS_EVENT_LOGGER_H_ #define ASH_SYSTEM_MACHINE_LEARNING_USER_SETTINGS_EVENT_LOGGER_H_
#include "ash/system/machine_learning/user_settings_event.pb.h" #include "ash/system/machine_learning/user_settings_event.pb.h"
#include "chromeos/services/network_config/public/mojom/cros_network_config.mojom-forward.h"
namespace ash { namespace ash {
namespace ml { namespace ml {
...@@ -20,15 +21,25 @@ class UserSettingsEventLogger { ...@@ -20,15 +21,25 @@ class UserSettingsEventLogger {
// exist in the current process. // exist in the current process.
static void CreateInstance(); static void CreateInstance();
static void DeleteInstance(); static void DeleteInstance();
// Gets the current instance of the logger.
static UserSettingsEventLogger* Get(); static UserSettingsEventLogger* Get();
// Logs a settings change event to UKM. // Logs an event to UKM that the user has connected to the given network.
void LogUkmEvent(); void LogNetworkUkmEvent(
const chromeos::network_config::mojom::NetworkStateProperties& network);
private: private:
UserSettingsEventLogger(); UserSettingsEventLogger();
~UserSettingsEventLogger(); ~UserSettingsEventLogger();
// Populates contextual information shared by all settings events.
void PopulateSharedFeatures(UserSettingsEvent* event);
// Sends the given event to UKM.
void SendToUkm(const UserSettingsEvent& event);
bool used_cellular_in_session_;
static UserSettingsEventLogger* instance_; static UserSettingsEventLogger* instance_;
}; };
......
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