Skip to content

Commit

Permalink
[Telemetry] Introduce runFanRoutine
Browse files Browse the repository at this point in the history
This change adds the runFanRoutine extension function to the
os.diagnostics namespace. This feature is currently behind feature
flag.

Bug: b/241863950
Test: unit_tests --gtest_filter="*DiagnosticsServiceConvertersTest*"
Test: unit_tests --gtest_filter="*DiagnosticsServiceAshTest*"
Test: browser_tests --gtest_filter="*Telemetry*"
-ozone-platform=headless

Change-Id: I6b978f315dae03b1f120e101f42a3a1d2f3343a1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4940465
Reviewed-by: Byron Lee <byronlee@chromium.org>
Reviewed-by: Takashi Toyoshima <toyoshim@chromium.org>
Commit-Queue: Ethan Cheng <yycheng@google.com>
Reviewed-by: Giovanni Ortuno Urquidi <ortuno@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1211333}
  • Loading branch information
ycheng627 authored and Chromium LUCI CQ committed Oct 18, 2023
1 parent 7c3e8a3 commit 922068c
Show file tree
Hide file tree
Showing 19 changed files with 173 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,16 @@ void DiagnosticsServiceAsh::RunEmmcLifetimeRoutine(
std::move(callback)));
}

void DiagnosticsServiceAsh::RunFanRoutine(RunFanRoutineCallback callback) {
GetService()->RunFanRoutine(base::BindOnce(
[](crosapi::mojom::DiagnosticsService::RunFanRoutineCallback callback,
cros_healthd::mojom::RunRoutineResponsePtr ptr) {
std::move(callback).Run(
converters::diagnostics::ConvertDiagnosticsPtr(std::move(ptr)));
},
std::move(callback)));
}

void DiagnosticsServiceAsh::RunFingerprintAliveRoutine(
RunFingerprintAliveRoutineCallback callback) {
GetService()->RunFingerprintAliveRoutine(base::BindOnce(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class DiagnosticsServiceAsh : public crosapi::mojom::DiagnosticsService {
void RunDnsResolverPresentRoutine(
RunDnsResolverPresentRoutineCallback callback) override;
void RunEmmcLifetimeRoutine(RunEmmcLifetimeRoutineCallback callback) override;
void RunFanRoutine(RunFanRoutineCallback callback) override;
void RunFingerprintAliveRoutine(
RunFingerprintAliveRoutineCallback callback) override;
void RunFloatingPointAccuracyRoutine(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,19 @@ TEST_F(DiagnosticsServiceAshTest, RunEmmcLifetimeRoutineSuccess) {
cros_healthd::mojom::DiagnosticRoutineEnum::kEmmcLifetime);
}

TEST_F(DiagnosticsServiceAshTest, RunFanRoutineSuccess) {
// Configure FakeCrosHealthd.
SetSuccessfulRoutineResponse();

base::test::TestFuture<crosapi::mojom::DiagnosticsRunRoutineResponsePtr>
future;
diagnostics_service()->RunFanRoutine(future.GetCallback());

ASSERT_TRUE(future.Wait());
const auto& result = future.Get();
ValidateResponse(result, cros_healthd::mojom::DiagnosticRoutineEnum::kFan);
}

TEST_F(DiagnosticsServiceAshTest, RunFingerprintAliveRoutineSuccess) {
// Configure FakeCrosHealthd.
SetSuccessfulRoutineResponse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ absl::optional<crosapi::mojom::DiagnosticsRoutineEnum> Convert(
return crosapi::mojom::DiagnosticsRoutineEnum::kBluetoothScanning;
case cros_healthd::mojom::DiagnosticRoutineEnum::kBluetoothPairing:
return crosapi::mojom::DiagnosticsRoutineEnum::kBluetoothPairing;
case cros_healthd::mojom::DiagnosticRoutineEnum::kFan:
return crosapi::mojom::DiagnosticsRoutineEnum::kFan;
default:
return absl::nullopt;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ TEST(DiagnosticsServiceConvertersTest, ConvertDiagnosticRoutineEnum) {
crosapi::DiagnosticsRoutineEnum::kBluetoothScanning);
EXPECT_EQ(Convert(cros_healthd::DiagnosticRoutineEnum::kBluetoothPairing),
crosapi::DiagnosticsRoutineEnum::kBluetoothPairing);
EXPECT_EQ(Convert(cros_healthd::DiagnosticRoutineEnum::kFan),
crosapi::DiagnosticsRoutineEnum::kFan);

EXPECT_EQ(Convert(cros_healthd::DiagnosticRoutineEnum::kArcHttp),
absl::nullopt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,15 @@ std::string GetServiceWorkerForError(const std::string& error) {
);
chrome.test.succeed();
},
async function runFanRoutine() {
await chrome.test.assertPromiseRejects(
chrome.os.diagnostics.runFanRoutine(),
'Error: Unauthorized access to ' +
'chrome.os.diagnostics.runFanRoutine. ' +
'%s'
);
chrome.test.succeed();
},
async function runFingerprintAliveRoutine() {
await chrome.test.assertPromiseRejects(
chrome.os.diagnostics.runFingerprintAliveRoutine(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,12 @@ void OsDiagnosticsRunAudioDriverRoutineFunction::RunIfAllowed() {
GetRemoteService()->RunAudioDriverRoutine(GetOnResult());
}

// OsDiagnosticsRunFanRoutineFunction -------------------------------

void OsDiagnosticsRunFanRoutineFunction::RunIfAllowed() {
GetRemoteService()->RunFanRoutine(GetOnResult());
}

// OsDiagnosticsCreateMemoryRoutineFunction ------------------------------------

void OsDiagnosticsCreateMemoryRoutineFunction::RunIfAllowed() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,17 @@ class OsDiagnosticsRunAudioDriverRoutineFunction
void RunIfAllowed() override;
};

class OsDiagnosticsRunFanRoutineFunction
: public DiagnosticsApiRunRoutineFunctionBase {
DECLARE_EXTENSION_FUNCTION("os.diagnostics.runFanRoutine",
OS_DIAGNOSTICS_RUNFANROUTINE)
private:
~OsDiagnosticsRunFanRoutineFunction() override = default;

// BaseTelemetryExtensionApiGuardFunction:
void RunIfAllowed() override;
};

/****************** DIAGNOSTICS API V2 ******************/

class OsDiagnosticsCreateMemoryRoutineFunction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ IN_PROC_BROWSER_TEST_F(TelemetryExtensionDiagnosticsApiBrowserTest,
crosapi::DiagnosticsRoutineEnum::kBluetoothDiscovery,
crosapi::DiagnosticsRoutineEnum::kBluetoothScanning,
crosapi::DiagnosticsRoutineEnum::kBluetoothPairing,
crosapi::DiagnosticsRoutineEnum::kFan,
});

SetServiceForTesting(std::move(fake_service_impl));
Expand Down Expand Up @@ -164,7 +165,8 @@ IN_PROC_BROWSER_TEST_F(TelemetryExtensionDiagnosticsApiBrowserTest,
"audio_driver",
"bluetooth_discovery",
"bluetooth_scanning",
"bluetooth_pairing"
"bluetooth_pairing",
"fan"
]
}, response);
chrome.test.succeed();
Expand Down Expand Up @@ -1405,4 +1407,64 @@ IN_PROC_BROWSER_TEST_F(
)");
}

IN_PROC_BROWSER_TEST_F(TelemetryExtensionDiagnosticsApiBrowserTest,
RunFanRoutineWithoutFeatureFlagFail) {
CreateExtensionAndRunServiceWorker(R"(
chrome.test.runTests([
function runFanRoutineNotWorking() {
chrome.test.assertThrows(() => {
chrome.os.diagnostics.runFanRoutine();
}, [],
'chrome.os.diagnostics.runFanRoutine is not a function'
);
chrome.test.succeed();
}
]);
)");
}

class PendingApprovalTelemetryExtensionDiagnosticsApiBrowserTest
: public TelemetryExtensionDiagnosticsApiBrowserTest {
public:
PendingApprovalTelemetryExtensionDiagnosticsApiBrowserTest() {
feature_list_.InitAndEnableFeature(
extensions_features::kTelemetryExtensionPendingApprovalApi);
}

private:
base::test::ScopedFeatureList feature_list_;
};

IN_PROC_BROWSER_TEST_F(
PendingApprovalTelemetryExtensionDiagnosticsApiBrowserTest,
RunFanRoutineSuccess) {
// Configure FakeDiagnosticsService.
{
auto expected_response = crosapi::DiagnosticsRunRoutineResponse::New();
expected_response->id = 0;
expected_response->status = crosapi::DiagnosticsRoutineStatusEnum::kReady;

// Set the return value for a call to RunFanRoutine.
auto fake_service_impl = std::make_unique<FakeDiagnosticsService>();
fake_service_impl->SetRunRoutineResponse(std::move(expected_response));

// Set the expected called routine.
fake_service_impl->SetExpectedLastCalledRoutine(
crosapi::DiagnosticsRoutineEnum::kFan);

SetServiceForTesting(std::move(fake_service_impl));
}

CreateExtensionAndRunServiceWorker(R"(
chrome.test.runTests([
async function runFanRoutine() {
const response =
await chrome.os.diagnostics.runFanRoutine();
chrome.test.assertEq({id: 0, status: "ready"}, response);
chrome.test.succeed();
}
]);
)");
}

} // namespace chromeos
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ bool ConvertMojoRoutine(crosapi::DiagnosticsRoutineEnum in,
case crosapi::DiagnosticsRoutineEnum::kBluetoothPairing:
*out = cx_diag::RoutineType::kBluetoothPairing;
return true;
case crosapi::DiagnosticsRoutineEnum::kFan:
*out = cx_diag::RoutineType::kFan;
return true;
case crosapi::DiagnosticsRoutineEnum::kUnknown:
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ TEST(TelemetryExtensionDiagnosticsApiConvertersUnitTest,
crosapi::DiagnosticsRoutineEnum::kAudioDriver, &out));
EXPECT_EQ(out, cx_diag::RoutineType::kAudioDriver);
}
{
cx_diag::RoutineType out = cx_diag::RoutineType::kNone;
EXPECT_TRUE(
ConvertMojoRoutine(crosapi::DiagnosticsRoutineEnum::kFan, &out));
EXPECT_EQ(out, cx_diag::RoutineType::kFan);
}
}

TEST(TelemetryExtensionDiagnosticsApiConvertersUnitTest, ConvertRoutineStatus) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,14 @@ void FakeDiagnosticsService::RunAudioDriverRoutine(
base::BindOnce(std::move(callback), run_routine_response_->Clone()));
}

void FakeDiagnosticsService::RunFanRoutine(RunFanRoutineCallback callback) {
actual_passed_parameters_.clear();
actual_called_routine_ = crosapi::DiagnosticsRoutineEnum::kFan;
base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE,
base::BindOnce(std::move(callback), run_routine_response_->Clone()));
}

void FakeDiagnosticsService::SetRunRoutineResponse(
crosapi::DiagnosticsRunRoutineResponsePtr response) {
run_routine_response_ = std::move(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class FakeDiagnosticsService : public crosapi::mojom::DiagnosticsService {
void RunPowerButtonRoutine(uint32_t timeout_seconds,
RunPowerButtonRoutineCallback callback) override;
void RunAudioDriverRoutine(RunAudioDriverRoutineCallback callback) override;
void RunFanRoutine(RunFanRoutineCallback callback) override;

// Sets the return value for |Run*Routine|.
void SetRunRoutineResponse(
Expand Down
14 changes: 14 additions & 0 deletions chrome/common/chromeos/extensions/api/_api_features.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@
],
"channel": "stable"
},
"os.diagnostics.runFanRoutine": {
"dependencies": [
"permission:os.diagnostics.runFanRoutine"
],
"contexts": [
"blessed_extension"
],
"platforms": [
"chromeos",
"lacros"
],
"channel": "stable",
"feature_flag": "TelemetryExtensionPendingApprovalApi"
},
"os.events": {
"dependencies": [
"permission:os.events"
Expand Down
5 changes: 4 additions & 1 deletion chrome/common/chromeos/extensions/api/diagnostics.idl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ namespace os.diagnostics {
audio_driver,
bluetooth_discovery,
bluetooth_scanning,
bluetooth_pairing
bluetooth_pairing,
fan
};

enum RoutineStatus {
Expand Down Expand Up @@ -398,6 +399,8 @@ namespace os.diagnostics {

[supportsPromises] static void runAudioDriverRoutine(RunRoutineCallback callback);

[supportsPromises] static void runFanRoutine(RunRoutineCallback callback);

// ----------------- DIAGNOSTICS API V2 -----------------

// Starts execution of a routine. This can only be expected to work after
Expand Down
20 changes: 16 additions & 4 deletions chromeos/crosapi/mojom/diagnostics_service.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import "chromeos/crosapi/mojom/nullable_primitives.mojom";

// Interface for exposing diagnostics service. Implemented in ash-chrome.
//
// Next version: 8
// Next ID: 31
// Next version: 9
// Next ID: 32
[Stable, Uuid="14bc6194-c059-4048-9bea-ca6823eeda82",
RenamedFrom="ash.health.mojom.DiagnosticsService"]
interface DiagnosticsService {
Expand Down Expand Up @@ -484,12 +484,23 @@ interface DiagnosticsService {
// routine.
[MinVersion=7] RunBluetoothPairingRoutine@30(string peripheral_id)
=> (DiagnosticsRunRoutineResponse response);

// Requests that the Fan routine is created and started on the
// platform. This routine checks whether the fan is controllable.
// The availability of this routine can be determined by checking that
// kFan is returned by GetAvailableRoutines.
//
// The response:
// * |response| - contains a unique identifier and status for the created
// routine.
[MinVersion=8] RunFanRoutine@31()
=> (DiagnosticsRunRoutineResponse response);
};

// Enumeration of each of the diagnostics routines the platform may support.
//
// Next version: 7
// Next ID: 31
// Next version: 8
// Next ID: 32
[Stable, Extensible, RenamedFrom="ash.health.mojom.DiagnosticRoutineEnum"]
enum DiagnosticsRoutineEnum {
[Default] kUnknown = 15,
Expand Down Expand Up @@ -523,6 +534,7 @@ enum DiagnosticsRoutineEnum {
[MinVersion=5] kBluetoothDiscovery = 28,
[MinVersion=6] kBluetoothScanning = 29,
[MinVersion=6] kBluetoothPairing = 30,
[MinVersion=7] kFan = 31,
};

// Enumeration of each of the possible statuses for a diagnostics routine.
Expand Down
2 changes: 2 additions & 0 deletions docs/telemetry_extension/api_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ extension-event based interface in M119. The interface is described in
| bluetooth_discovery |
| bluetooth_scanning |
| bluetooth_pairing |
| fan |

### Enum RoutineStatus
| Property Name |
Expand Down Expand Up @@ -200,6 +201,7 @@ extension-event based interface in M119. The interface is described in
| runDnsResolutionRoutine | () => Promise<RunRoutineResponse\> | `os.diagnostics` | M108 |
| runDnsResolverPresentRoutine | () => Promise<RunRoutineResponse\> | `os.diagnostics` | M108 |
| runEmmcLifetimeRoutine | () => Promise<RunRoutineResponse\> | `os.diagnostics` | M110 |
| runFanRoutine | () => Promise<RunRoutineResponse\> | `os.diagnostics` | M120 |
| runFingerprintAliveRoutine | () => Promise<RunRoutineResponse\> | `os.diagnostics` | M110 |
| runGatewayCanBePingedRoutine | () => Promise<RunRoutineResponse\> | `os.diagnostics` | M108 |
| runLanConnectivityRoutine | () => Promise<RunRoutineResponse\> | `os.diagnostics` | M102 |
Expand Down
1 change: 1 addition & 0 deletions extensions/browser/extension_function_histogram_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -1892,6 +1892,7 @@ enum HistogramValue {
ACCESSIBILITY_PRIVATE_CLIPBOARDCOPYINACTIVELACROSGOOGLEDOC = 1830,
USERSCRIPTS_UPDATE = 1831,
INPUTMETHODPRIVATE_GETLANGUAGEPACKSTATUS = 1832,
OS_DIAGNOSTICS_RUNFANROUTINE = 1833,
// Last entry: Add new entries above, then run:
// tools/metrics/histograms/update_extension_histograms.py
ENUM_BOUNDARY
Expand Down
1 change: 1 addition & 0 deletions tools/metrics/histograms/enums.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37842,6 +37842,7 @@ Called by update_extension_histograms.py.-->
label="ACCESSIBILITY_PRIVATE_CLIPBOARDCOPYINACTIVELACROSGOOGLEDOC"/>
<int value="1831" label="USERSCRIPTS_UPDATE"/>
<int value="1832" label="INPUTMETHODPRIVATE_GETLANGUAGEPACKSTATUS"/>
<int value="1833" label="OS_DIAGNOSTICS_RUNFANROUTINE"/>
</enum>

<enum name="ExtensionIconState">
Expand Down

0 comments on commit 922068c

Please sign in to comment.