Commit bc02ced3 authored by Andrei-Laurențiu Olteanu's avatar Andrei-Laurențiu Olteanu Committed by Commit Bot

[Telemetry SWX] Add battery health routine

Add implementation to chrome://.

Add implementation to chrome-untrusted://.

Add tests.

Bug: b:162051831
Change-Id: Ied981248389b38caee411d09ff4a6cb207e540b3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2372427
Commit-Queue: Laurențiu Olteanu <lolteanu@google.com>
Reviewed-by: default avatarMahmoud Gawad <mgawad@google.com>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarOleh Lamzin <lamzin@google.com>
Cr-Commit-Position: refs/heads/master@{#803492}
parent 4141d3e7
......@@ -79,4 +79,19 @@ void DiagnosticsService::RunBatteryCapacityRoutine(
std::move(callback)));
}
void DiagnosticsService::RunBatteryHealthRoutine(
uint32_t maximum_cycle_count,
uint32_t percent_battery_wear_allowed,
RunBatteryHealthRoutineCallback callback) {
GetService()->RunBatteryHealthRoutine(
maximum_cycle_count, percent_battery_wear_allowed,
base::BindOnce(
[](health::mojom::DiagnosticsService::RunBatteryHealthRoutineCallback
callback,
cros_healthd::mojom::RunRoutineResponsePtr ptr) {
std::move(callback).Run(converters::ConvertPtr(std::move(ptr)));
},
std::move(callback)));
}
} // namespace chromeos
......@@ -35,6 +35,10 @@ class DiagnosticsService : public health::mojom::DiagnosticsService {
uint32_t low_mah,
uint32_t high_mah,
RunBatteryCapacityRoutineCallback callback) override;
void RunBatteryHealthRoutine(
uint32_t maximum_cycle_count,
uint32_t percent_battery_wear_allowed,
RunBatteryHealthRoutineCallback callback) override;
// Ensures that |service_| created and connected to the
// CrosHealthdProbeService.
......
......@@ -56,6 +56,24 @@ interface DiagnosticsService {
// routine.
RunBatteryCapacityRoutine(uint32 low_mah, uint32 high_mah)
=> (RunRoutineResponse response);
// Requests that the BatteryHealth routine is created and started on the
// platform. This routine checks the cycle count and percent wear of the
// battery. This routine is only available if GetAvailableRoutines returned
// kBatteryHealth.
//
// The request:
// * |maximum_cycle_count| - maximum cycle count allowed for the routine to
// pass.
// * |percent_battery_wear_allowed| - maximum percent battery wear allowed for
// the routine to pass.
//
// The response:
// * |response| - contains a unique identifier and status for the created
// routine.
RunBatteryHealthRoutine(uint32 maximum_cycle_count,
uint32 percent_battery_wear_allowed)
=> (RunRoutineResponse response);
};
// Enumeration of each of the diagnostics routines the platform may support.
......
......@@ -22,6 +22,8 @@ dpsl_internal.Message = {
DIAGNOSTICS_ROUTINE_UPDATE: 'DiagnosticsService.GetRoutineUpdate',
DIAGNOSTICS_RUN_BATTERY_CAPACITY_ROUTINE:
'DiagnosticsService.RunBatteryCapacityRoutine',
DIAGNOSTICS_RUN_BATTERY_HEALTH_ROUTINE:
'DiagnosticsService.RunBatteryHealthRoutine',
PROBE_TELEMETRY_INFO: 'ProbeService.ProbeTelemetryInfo',
};
......@@ -65,6 +67,15 @@ dpsl_internal.DiagnosticsGetRoutineUpdateResponse;
*/
dpsl_internal.DiagnosticsRunBatteryCapacityRoutineRequest;
/**
* Request message sent by the unprivileged context to the privileged
* context to run battery health routine.
* @typedef {{
* maximumCycleCount: !number,
* percentBatteryWearAllowed: !number}}
*/
dpsl_internal.DiagnosticsRunBatteryHealthRoutineRequest;
/**
* Response message sent by the privileged context containing routine
* information.
......
......@@ -302,6 +302,21 @@ class DiagnosticsProxy {
return await getOrCreateDiagnosticsService().runBatteryCapacityRoutine(
request.lowMah, request.highMah);
};
/**
* Runs battery health routine.
* @param { !Object } message
* @return { !RunRoutineResponsePromise }
*/
async handleRunBatteryHealthRoutine(message) {
const request =
/**
* @type {!dpsl_internal.DiagnosticsRunBatteryHealthRoutineRequest}
*/
(message);
return await getOrCreateDiagnosticsService().runBatteryHealthRoutine(
request.maximumCycleCount, request.percentBatteryWearAllowed);
};
};
const diagnosticsProxy = new DiagnosticsProxy();
......@@ -492,6 +507,12 @@ untrustedMessagePipe.registerHandler(
(message) => diagnosticsProxy.handleRunBatteryCapacityRoutine(message),
message));
untrustedMessagePipe.registerHandler(
dpsl_internal.Message.DIAGNOSTICS_RUN_BATTERY_HEALTH_ROUTINE,
(message) => diagnosticsProxy.genericRunRoutineHandler(
(message) => diagnosticsProxy.handleRunBatteryHealthRoutine(message),
message));
untrustedMessagePipe.registerHandler(
dpsl_internal.Message.PROBE_TELEMETRY_INFO,
(message) => telemetryProxy.handleProbeTelemetryInfo(message));
......@@ -97,6 +97,33 @@ chromeos.test_support = {};
}
return response;
}
/**
* Requests battery health routine to be run.
* @param { !number } maximumCycleCount
* @param { !number } percentBatteryWearAllowed
* @return { !Promise<!Object> }
* @public
*/
async runBatteryHealthRoutine(
maximumCycleCount, percentBatteryWearAllowed) {
const message =
/**
@type {!dpsl_internal.DiagnosticsRunBatteryCapacityRoutineRequest}
*/
({
maximumCycleCount: maximumCycleCount,
percentBatteryWearAllowed: percentBatteryWearAllowed
});
const response =
/** @type {!Object} */ (await messagePipe.sendMessage(
dpsl_internal.Message.DIAGNOSTICS_RUN_BATTERY_HEALTH_ROUTINE,
message));
if (response instanceof Error) {
throw response;
}
return response;
}
};
/**
......
......@@ -231,6 +231,14 @@ TEST_F(
testDone();
});
TEST_F(
'TelemetryExtensionUIBrowserTest',
'UntrustedDiagnosticsRequestRunBatteryHealthRoutine', async () => {
await runTestInUntrusted(
'UntrustedDiagnosticsRequestRunBatteryHealthRoutine');
testDone();
});
TEST_F(
'TelemetryExtensionUIBrowserTest',
'UntrustedRequestTelemetryInfoUnknownCategory', async () => {
......
......@@ -137,6 +137,14 @@ UNTRUSTED_TEST(
assertDeepEquals(response, {id: 123456789, status: 'ready'});
});
// Tests that runBatteryHealthRoutine returns the correct Object.
UNTRUSTED_TEST(
'UntrustedDiagnosticsRequestRunBatteryHealthRoutine', async () => {
const response =
await chromeos.diagnostics.runBatteryHealthRoutine(10, 5);
assertDeepEquals(response, {id: 123456789, status: 'ready'});
});
// Tests that TelemetryInfo can be successfully requested from
// from chrome-untrusted://.
UNTRUSTED_TEST('UntrustedRequestTelemetryInfo', async () => {
......
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