Skip to content

Commit

Permalink
[Telemetry] Add GetOemData method to probe service
Browse files Browse the repository at this point in the history
Introduce GetOemData method to the mojo probe service. This method will
be used for Chrome extension API function implementation to retrieve OEM
data.

Bug: b:188897824
Change-Id: I7f6601454686e02ca08f08af52fcb73da37576f5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3009581
Commit-Queue: Oleh Lamzin <lamzin@google.com>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Mahmoud Gawad <mgawad@google.com>
Cr-Commit-Position: refs/heads/master@{#907370}
  • Loading branch information
Lamzin authored and Chromium LUCI CQ committed Jul 31, 2021
1 parent 9100c2b commit 5a9e108
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 1 deletion.
Expand Up @@ -61,6 +61,12 @@ interface ProbeService {
// will be non-null.
ProbeTelemetryInfo(array<ProbeCategoryEnum> categories)
=> (TelemetryInfo telemetry_info);

// Returns OEM data.
//
// The response:
// * |oem_data| - OEM data.
GetOemData() => (OemData oem_data);
};

// An enumeration of each category of information that cros_healthd can report.
Expand Down Expand Up @@ -457,3 +463,8 @@ struct TelemetryInfo {
// when kBluetooth was included in the categories input to ProbeTelemetryInfo.
BluetoothResult? bluetooth_result;
};

// Result of running /usr/share/cros/oemdata.sh script.
struct OemData {
string? oem_data;
};
4 changes: 4 additions & 0 deletions chromeos/components/telemetry_extension_ui/services/BUILD.gn
Expand Up @@ -29,6 +29,8 @@ source_set("telemetry_services") {
"//base",
"//chrome/browser/ash/wilco_dtc_supportd:mojo_utils",
"//chromeos/components/telemetry_extension_ui/mojom",
"//chromeos/dbus",
"//chromeos/dbus/debug_daemon",
"//chromeos/services/cros_healthd/public/cpp",
"//chromeos/services/cros_healthd/public/mojom",
]
Expand All @@ -49,7 +51,9 @@ source_set("unit_tests") {
"//base/test:test_support",
"//chrome/browser/ash/wilco_dtc_supportd:mojo_utils",
"//chromeos/components/telemetry_extension_ui/mojom",
"//chromeos/dbus",
"//chromeos/dbus/cros_healthd",
"//chromeos/dbus/debug_daemon",
"//chromeos/services/cros_healthd/public/cpp",
"//chromeos/services/cros_healthd/public/mojom",
"//testing/gmock",
Expand Down
Expand Up @@ -9,11 +9,18 @@
#include "base/bind.h"
#include "chromeos/components/telemetry_extension_ui/services/convert_ptr.h"
#include "chromeos/components/telemetry_extension_ui/services/probe_service_converters.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/debug_daemon/debug_daemon_client.h"
#include "chromeos/services/cros_healthd/public/cpp/service_connection.h"
#include "chromeos/services/cros_healthd/public/mojom/cros_healthd_probe.mojom.h"
#include "third_party/abseil-cpp/absl/types/optional.h"

namespace chromeos {

namespace {
constexpr char kOemDataLogName[] = "oemdata";
} // namespace

ProbeService::ProbeService(
mojo::PendingReceiver<health::mojom::ProbeService> receiver)
: receiver_(this, std::move(receiver)) {}
Expand All @@ -33,6 +40,20 @@ void ProbeService::ProbeTelemetryInfo(
std::move(callback)));
}

void ProbeService::GetOemData(GetOemDataCallback callback) {
chromeos::DebugDaemonClient* debugd_client =
chromeos::DBusThreadManager::Get()->GetDebugDaemonClient();
debugd_client->GetLog(
kOemDataLogName,
base::BindOnce(
[](GetOemDataCallback callback,
absl::optional<std::string> oem_data) {
std::move(callback).Run(
health::mojom::OemData::New(std::move(oem_data)));
},
std::move(callback)));
}

cros_healthd::mojom::CrosHealthdProbeService* ProbeService::GetService() {
if (!service_ || !service_.is_connected()) {
cros_healthd::ServiceConnection::GetInstance()->GetProbeService(
Expand Down
Expand Up @@ -27,6 +27,7 @@ class ProbeService : public health::mojom::ProbeService {
void ProbeTelemetryInfo(
const std::vector<health::mojom::ProbeCategoryEnum>& categories,
ProbeTelemetryInfoCallback callback) override;
void GetOemData(GetOemDataCallback callback) override;

// Ensures that |service_| created and connected to the
// CrosHealthdProbeService.
Expand Down
Expand Up @@ -12,6 +12,8 @@
#include "base/test/task_environment.h"
#include "chromeos/dbus/cros_healthd/cros_healthd_client.h"
#include "chromeos/dbus/cros_healthd/fake_cros_healthd_client.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/debug_daemon/fake_debug_daemon_client.h"
#include "chromeos/services/cros_healthd/public/cpp/service_connection.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "testing/gtest/include/gtest/gtest.h"
Expand All @@ -20,25 +22,42 @@ namespace chromeos {

class ProbeServiceTest : public testing::Test {
public:
void SetUp() override { CrosHealthdClient::InitializeFake(); }
void SetUp() override {
auto fake_debugd_client = std::make_unique<FakeDebugDaemonClient>();
fake_debugd_client_ = fake_debugd_client.get();

chromeos::DBusThreadManager::Initialize();
chromeos::DBusThreadManager::GetSetterForTesting()->SetDebugDaemonClient(
std::move(fake_debugd_client));

CrosHealthdClient::InitializeFake();
}

void TearDown() override {
CrosHealthdClient::Shutdown();

// Wait for ServiceConnection to observe the destruction of the client.
cros_healthd::ServiceConnection::GetInstance()->FlushForTesting();

chromeos::DBusThreadManager::Shutdown();
}

health::mojom::ProbeServiceProxy* probe_service() const {
return remote_probe_service_.get();
}

FakeDebugDaemonClient* fake_debugd_client() const {
return fake_debugd_client_;
}

private:
base::test::TaskEnvironment task_environment_;

mojo::Remote<health::mojom::ProbeService> remote_probe_service_;
ProbeService probe_service_{
remote_probe_service_.BindNewPipeAndPassReceiver()};

FakeDebugDaemonClient* fake_debugd_client_ = nullptr;
};

// Tests that ProbeTelemetryInfo requests telemetry info in cros_healthd and
Expand Down Expand Up @@ -75,4 +94,19 @@ TEST_F(ProbeServiceTest, ProbeTelemetryInfoSuccess) {
run_loop.Run();
}

// Tests that GetOemData requests OEM data in debugd and
// forwards response via callback.
TEST_F(ProbeServiceTest, GetOemDataSuccess) {
base::RunLoop run_loop;
probe_service()->GetOemData(
base::BindLambdaForTesting([&](health::mojom::OemDataPtr ptr) {
ASSERT_TRUE(ptr);
ASSERT_TRUE(ptr->oem_data.has_value());
EXPECT_EQ(ptr->oem_data.value(), "oemdata: response from GetLog");

run_loop.Quit();
}));
run_loop.Run();
}

} // namespace chromeos
Expand Up @@ -632,6 +632,13 @@ class TestProbeService {

return Promise.resolve({ telemetryInfo });
}

/**
* @override
*/
getOemData() {
throw 'This method should not be called from telemetry extension';
}
};

// Tests with a testing Mojo probe service, so we can test for example strings
Expand Down

0 comments on commit 5a9e108

Please sign in to comment.