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

Commit b92de553 authored by Jeffrey Huang's avatar Jeffrey Huang
Browse files

Migrate pullTemperature and pullCooldownDevice

Test: adb shell cmd stats pull-source 10021
Test: adb shell cmd stats pull-source 10059
Change-Id: I9d58a4b8aa32daa0b750d4e45c1dcc6a34407865
parent a0e1cd2d
Loading
Loading
Loading
Loading
+0 −53
Original line number Diff line number Diff line
@@ -1247,49 +1247,6 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
        }
    }

    private void pullTemperature(int tagId, long elapsedNanos, long wallClockNanos,
            List<StatsLogEventWrapper> pulledData) {
        long callingToken = Binder.clearCallingIdentity();
        try {
            List<Temperature> temperatures = sThermalService.getCurrentTemperatures();
            for (Temperature temp : temperatures) {
                StatsLogEventWrapper e =
                        new StatsLogEventWrapper(tagId, elapsedNanos, wallClockNanos);
                e.writeInt(temp.getType());
                e.writeString(temp.getName());
                e.writeInt((int) (temp.getValue() * 10));
                e.writeInt(temp.getStatus());
                pulledData.add(e);
            }
        } catch (RemoteException e) {
            // Should not happen.
            Slog.e(TAG, "Disconnected from thermal service. Cannot pull temperatures.");
        } finally {
            Binder.restoreCallingIdentity(callingToken);
        }
    }

    private void pullCoolingDevices(int tagId, long elapsedNanos, long wallClockNanos,
            List<StatsLogEventWrapper> pulledData) {
        long callingToken = Binder.clearCallingIdentity();
        try {
            List<CoolingDevice> devices = sThermalService.getCurrentCoolingDevices();
            for (CoolingDevice device : devices) {
                StatsLogEventWrapper e =
                        new StatsLogEventWrapper(tagId, elapsedNanos, wallClockNanos);
                e.writeInt(device.getType());
                e.writeString(device.getName());
                e.writeInt((int) (device.getValue()));
                pulledData.add(e);
            }
        } catch (RemoteException e) {
            // Should not happen.
            Slog.e(TAG, "Disconnected from thermal service. Cannot pull temperatures.");
        } finally {
            Binder.restoreCallingIdentity(callingToken);
        }
    }

    private void pullDebugElapsedClock(int tagId,
            long elapsedNanos, final long wallClockNanos, List<StatsLogEventWrapper> pulledData) {
        final long elapsedMillis = SystemClock.elapsedRealtime();
@@ -1745,16 +1702,6 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
                break;
            }

            case StatsLog.TEMPERATURE: {
                pullTemperature(tagId, elapsedNanos, wallClockNanos, ret);
                break;
            }

            case StatsLog.COOLING_DEVICE: {
                pullCoolingDevices(tagId, elapsedNanos, wallClockNanos, ret);
                break;
            }

            case StatsLog.DEBUG_ELAPSED_CLOCK: {
                pullDebugElapsedClock(tagId, elapsedNanos, wallClockNanos, ret);
                break;
+0 −8
Original line number Diff line number Diff line
@@ -95,14 +95,6 @@ std::map<PullerKey, PullAtomInfo> StatsPullerManager::kAllPullAtomInfo = {
        {{.atomTag = android::util::BATTERY_CYCLE_COUNT},
         {.puller = new ResourceHealthManagerPuller(android::util::BATTERY_CYCLE_COUNT)}},

        // temperature
        {{.atomTag = android::util::TEMPERATURE},
         {.puller = new StatsCompanionServicePuller(android::util::TEMPERATURE)}},

        // cooling_device
        {{.atomTag = android::util::COOLING_DEVICE},
         {.puller = new StatsCompanionServicePuller(android::util::COOLING_DEVICE)}},

        // binder_calls
        {{.atomTag = android::util::BINDER_CALLS},
         {.additiveFields = {4, 5, 6, 8, 12},
+65 −6
Original line number Diff line number Diff line
@@ -1274,19 +1274,78 @@ public class StatsPullAtomService extends SystemService {
    }

    private void registerTemperature() {
        // No op.
        int tagId = StatsLog.TEMPERATURE;
        mStatsManager.registerPullAtomCallback(
                tagId,
                null, // use default PullAtomMetadata values
                (atomTag, data) -> pullTemperature(atomTag, data),
                BackgroundThread.getExecutor()
        );
    }

    private void pullTemperature() {
        // No op.
    private int pullTemperature(int atomTag, List<StatsEvent> pulledData) {
        IThermalService thermalService = getIThermalService();
        if (thermalService == null) {
            return StatsManager.PULL_SKIP;
        }
        final long callingToken = Binder.clearCallingIdentity();
        try {
            List<Temperature> temperatures = thermalService.getCurrentTemperatures();
            for (Temperature temp : temperatures) {
                StatsEvent e = StatsEvent.newBuilder()
                        .setAtomId(atomTag)
                        .writeInt(temp.getType())
                        .writeString(temp.getName())
                        .writeInt((int) (temp.getValue() * 10))
                        .writeInt(temp.getStatus())
                        .build();
                pulledData.add(e);
            }
        } catch (RemoteException e) {
            // Should not happen.
            Slog.e(TAG, "Disconnected from thermal service. Cannot pull temperatures.");
            return StatsManager.PULL_SKIP;
        } finally {
            Binder.restoreCallingIdentity(callingToken);
        }
        return StatsManager.PULL_SUCCESS;
    }

    private void registerCoolingDevice() {
        // No op.
        int tagId = StatsLog.COOLING_DEVICE;
        mStatsManager.registerPullAtomCallback(
                tagId,
                null, // use default PullAtomMetadata values
                (atomTag, data) -> pullCooldownDevice(atomTag, data),
                BackgroundThread.getExecutor()
        );
    }

    private void pullCooldownDevice() {
        // No op.
    private int pullCooldownDevice(int atomTag, List<StatsEvent> pulledData) {
        IThermalService thermalService = getIThermalService();
        if (thermalService == null) {
            return StatsManager.PULL_SKIP;
        }
        final long callingToken = Binder.clearCallingIdentity();
        try {
            List<CoolingDevice> devices = thermalService.getCurrentCoolingDevices();
            for (CoolingDevice device : devices) {
                StatsEvent e = StatsEvent.newBuilder()
                        .setAtomId(atomTag)
                        .writeInt(device.getType())
                        .writeString(device.getName())
                        .writeInt((int) (device.getValue()))
                        .build();
                pulledData.add(e);
            }
        } catch (RemoteException e) {
            // Should not happen.
            Slog.e(TAG, "Disconnected from thermal service. Cannot pull temperatures.");
            return StatsManager.PULL_SKIP;
        } finally {
            Binder.restoreCallingIdentity(callingToken);
        }
        return StatsManager.PULL_SUCCESS;
    }

    private void registerBinderCalls() {