Skip to content

Commit

Permalink
feat(bin): improve dumpsys.battery
Browse files Browse the repository at this point in the history
  • Loading branch information
yume-chan committed Sep 27, 2023
1 parent 3ecf231 commit a47b25c
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion libraries/android-bin/src/dumpsys.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-namespace */

import { AdbCommandBase } from "@yume-chan/adb";

export class DumpSys extends AdbCommandBase {
Expand Down Expand Up @@ -47,7 +49,9 @@ export class DumpSys extends AdbCommandBase {
let scale: number | undefined;
let voltage: number | undefined;
let current: number | undefined;
for (const line of output) {
let status: DumpSys.Battery.Status | undefined;
let health: DumpSys.Battery.Health | undefined;
for (const line of output.split("\n")) {
const parts = line.split(":");
if (parts.length !== 2) {
continue;
Expand Down Expand Up @@ -75,6 +79,18 @@ export class DumpSys extends AdbCommandBase {
case "current now":
current = Number.parseInt(parts[1]!.trim(), 10);
break;
case "status":
status = Number.parseInt(
parts[1]!.trim(),
10,
) as DumpSys.Battery.Status;
break;
case "health":
health = Number.parseInt(
parts[1]!.trim(),
10,
) as DumpSys.Battery.Health;
break;
}
}

Expand All @@ -86,6 +102,30 @@ export class DumpSys extends AdbCommandBase {
scale,
voltage,
current,
status,
health,
};
}
}

export namespace DumpSys {
export namespace Battery {
export enum Status {
Unknown = 1,
Charging,
Discharging,
NotCharging,
Full,
}

export enum Health {
Unknown = 1,
Good,
Overheat,
Dead,
OverVoltage,
UnspecifiedFailure,
Cold,
}
}
}

0 comments on commit a47b25c

Please sign in to comment.