Commit f4366520 authored by isandrk's avatar isandrk Committed by Commit bot

Add sound volume to device attribute reporting

This CL adds another device attribute to the report which is uploaded to admin console.

More context can be found by reading the design doc go/remote-audio-management

BUG=699589

Review-Url: https://codereview.chromium.org/2736903004
Cr-Commit-Position: refs/heads/master@{#456039}
parent afc56429
......@@ -43,6 +43,7 @@
#include "chrome/browser/policy/profile_policy_connector_factory.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/pref_names.h"
#include "chromeos/audio/cras_audio_handler.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/update_engine_client.h"
#include "chromeos/disks/disk_mount_manager.h"
......@@ -989,6 +990,11 @@ bool DeviceStatusCollector::GetHardwareStatus(
status->add_cpu_utilization_pct(usage.cpu_usage_percent);
status->add_system_ram_free(usage.bytes_of_ram_free);
}
// Get the current device sound volume level.
chromeos::CrasAudioHandler* audio_handler = chromeos::CrasAudioHandler::Get();
status->set_sound_volume(audio_handler->GetOutputVolumePercent());
return true;
}
......
......@@ -39,6 +39,7 @@
#include "chrome/test/base/chrome_unit_test_suite.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "chromeos/audio/cras_audio_handler.h"
#include "chromeos/dbus/cros_disks_client.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/fake_update_engine_client.h"
......@@ -345,6 +346,8 @@ class DeviceStatusCollectorTest : public testing::Test {
chromeos::DBusThreadManager::GetSetterForTesting();
dbus_setter->SetUpdateEngineClient(
base::WrapUnique<chromeos::UpdateEngineClient>(update_engine_client_));
chromeos::CrasAudioHandler::InitializeForTesting();
}
void AddMountPoint(const std::string& mount_point) {
......@@ -356,6 +359,7 @@ class DeviceStatusCollectorTest : public testing::Test {
}
~DeviceStatusCollectorTest() override {
chromeos::CrasAudioHandler::Shutdown();
chromeos::KioskAppManager::Shutdown();
TestingBrowserProcess::GetGlobal()->SetLocalState(nullptr);
......@@ -1295,6 +1299,26 @@ TEST_F(DeviceStatusCollectorTest, ReportRunningKioskApp) {
EXPECT_FALSE(app.has_error());
}
TEST_F(DeviceStatusCollectorTest, TestSoundVolume) {
// Expect the sound volume to be reported by default (default sound volume
// used in testing is 75).
GetStatus();
EXPECT_EQ(75, device_status_.sound_volume());
// When the pref to collect this data is not enabled, expect that the field
// isn't present in the protobuf.
settings_helper_.SetBoolean(chromeos::kReportDeviceHardwareStatus, false);
GetStatus();
EXPECT_FALSE(device_status_.has_sound_volume());
// Try setting a custom volume value and check that it matches.
const int kCustomVolume = 42;
settings_helper_.SetBoolean(chromeos::kReportDeviceHardwareStatus, true);
chromeos::CrasAudioHandler::Get()->SetOutputVolumePercent(kCustomVolume);
GetStatus();
EXPECT_EQ(kCustomVolume, device_status_.sound_volume());
}
// Fake device state.
struct FakeDeviceData {
const char* device_path;
......
......@@ -767,6 +767,9 @@ message DeviceStatusReportRequest {
// Set only when there is an auto launched with zero delay kiosk app
// and it is currently running. Otherwise, this field is empty.
optional AppStatus running_kiosk_app = 18;
// Sound output volume level in range [0,100].
optional int32 sound_volume = 19;
}
message OsUpdateStatus {
......
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