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

Commit b8adffc3 authored by Ikjoon Jang's avatar Ikjoon Jang Committed by Android (Google) Code Review
Browse files

Merge "Revert "Fix IllegalStateException in getSupportedPowerMonitors API"" into main

parents 1e86367f 6aaf75ca
Loading
Loading
Loading
Loading
+30 −41
Original line number Diff line number Diff line
@@ -603,37 +603,9 @@ public class PowerStatsService extends SystemService {
    @NonNull
    private String getEnergyConsumerName(EnergyConsumer consumer,
            EnergyConsumer[] energyConsumers) {
        if (consumer.type != EnergyConsumerType.OTHER) {
            StringBuilder sb = new StringBuilder();
        switch (consumer.type) {
            case EnergyConsumerType.BLUETOOTH:
                sb.append("BLUETOOTH");
                break;
            case EnergyConsumerType.CPU_CLUSTER:
                sb.append("CPU");
                break;
            case EnergyConsumerType.DISPLAY:
                sb.append("DISPLAY");
                break;
            case EnergyConsumerType.GNSS:
                sb.append("GNSS");
                break;
            case EnergyConsumerType.MOBILE_RADIO:
                sb.append("MOBILE_RADIO");
                break;
            case EnergyConsumerType.WIFI:
                sb.append("WIFI");
                break;
            case EnergyConsumerType.CAMERA:
                sb.append("CAMERA");
                break;
            default:
                if (consumer.name != null && !consumer.name.isBlank()) {
                    sb.append(consumer.name.toUpperCase(Locale.ENGLISH));
                } else {
                    sb.append("CONSUMER_").append(consumer.type);
                }
                break;
        }
            sb.append(energyConsumerTypeToString(consumer.type));
            boolean hasOrdinal = consumer.ordinal != 0;
            if (!hasOrdinal) {
                // See if any other EnergyConsumer of the same type has an ordinal
@@ -648,6 +620,23 @@ public class PowerStatsService extends SystemService {
                sb.append('/').append(consumer.ordinal);
            }
            return sb.toString();
        } else {
            return consumer.name;
        }
    }

    private static String energyConsumerTypeToString(int type) {
        switch(type) {
            case EnergyConsumerType.BLUETOOTH: return "BLUETOOTH";
            case EnergyConsumerType.CPU_CLUSTER: return "CPU";
            case EnergyConsumerType.DISPLAY: return "DISPLAY";
            case EnergyConsumerType.GNSS: return "GNSS";
            case EnergyConsumerType.MOBILE_RADIO: return "MOBILE_RADIO";
            case EnergyConsumerType.WIFI: return "WIFI";
            case EnergyConsumerType.OTHER: return "";
            default:
                throw new IllegalStateException("Unrecognized EnergyConsumerType: " + type);
        }
    }

    /**