Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit abf0df95 authored by Yeabkal Wubshit's avatar Yeabkal Wubshit
Browse files

Support -f option for Current shell command

We've had historically added "-f" as a valid shell command option for
the battery service dumpsys get commands. However, with the current
state of the code, using -f with "get" results in an error.

In an attempt to both fix this error, and to support up-to-date
current-value fetching, we're
[1] Supporting the inclusion of -f option in "get" commands
[2] When -f is used, we schedule update with the health service before
fetching the current value, to help get the latest current value

Bug: 315037695
Test: adb shell dumpsys battery get -f current_now
Change-Id: I8ef1c420005d505b36869b6cea4de095a47e4993
parent 44a32ba6
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -974,6 +974,7 @@ public final class BatteryService extends SystemService {
                unplugBattery(/* forceUpdate= */ (opts & OPTION_FORCE_UPDATE) != 0, pw);
            } break;
            case "get": {
                final int opts = parseOptions(shell);
                final String key = shell.getNextArg();
                if (key == null) {
                    pw.println("No property specified");
@@ -1007,11 +1008,17 @@ public final class BatteryService extends SystemService {
                        break;
                    case "current_now":
                        if (batteryServiceSupportCurrentAdbCommand()) {
                            if ((opts & OPTION_FORCE_UPDATE) != 0) {
                                updateHealthInfo();
                            }
                            pw.println(mHealthInfo.batteryCurrentMicroamps);
                        }
                        break;
                    case "current_average":
                        if (batteryServiceSupportCurrentAdbCommand()) {
                            if ((opts & OPTION_FORCE_UPDATE) != 0) {
                                updateHealthInfo();
                            }
                            pw.println(mHealthInfo.batteryCurrentAverageMicroamps);
                        }
                        break;
@@ -1125,6 +1132,14 @@ public final class BatteryService extends SystemService {
        return 0;
    }

    private void updateHealthInfo() {
        try {
            mHealthServiceWrapper.scheduleUpdate();
        } catch (RemoteException e) {
            Slog.e(TAG, "Unable to update health service data.", e);
        }
    }

    private void setChargerAcOnline(boolean online, boolean forceUpdate) {
        if (!mUpdatesStopped) {
            copyV1Battery(mLastHealthInfo, mHealthInfo);