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

Commit 77754235 authored by Benjamin Schwartz's avatar Benjamin Schwartz Committed by Gerrit Code Review
Browse files

Merge "power/stats: Return exception codes on error"

parents 715c5334 be0e2ed7
Loading
Loading
Loading
Loading
+21 −18
Original line number Original line Diff line number Diff line
@@ -32,7 +32,7 @@ interface IPowerStats {
     * A PowerEntity is defined as a platform subsystem, peripheral, or power domain that impacts
     * A PowerEntity is defined as a platform subsystem, peripheral, or power domain that impacts
     * the total device power consumption.
     * the total device power consumption.
     *
     *
     * @return List of information on each PowerEntity
     * @return List of information on each PowerEntity for which state residency can be requested.
     */
     */
    PowerEntity[] getPowerEntityInfo();
    PowerEntity[] getPowerEntityInfo();


@@ -52,11 +52,12 @@ interface IPowerStats {
     *     Passing an empty list will return state residency for all available PowerEntitys.
     *     Passing an empty list will return state residency for all available PowerEntitys.
     *     ID of each PowerEntity is contained in PowerEntityInfo.
     *     ID of each PowerEntity is contained in PowerEntityInfo.
     *
     *
     * @return StateResidency since boot for each requested PowerEntity
     * @return StateResidencyResults since boot for each requested and available PowerEntity. Note
     * that StateResidencyResult for a given PowerEntity may not always be available. Clients shall
     * not rely on StateResidencyResult always being returned for every request.
     *
     *
     * Returns the following service-specific exceptions in order of highest priority:
     * Returns the following exception codes:
     *  - STATUS_BAD_VALUE if an invalid powerEntityId is provided
     *  - EX_ILLEGAL_ARGUMENT if an invalid powerEntityId is provided
     *  - STATUS_FAILED_TRANSACTION if any StateResidencyResult fails to be returned
     */
     */
    StateResidencyResult[] getStateResidency(in int[] powerEntityIds);
    StateResidencyResult[] getStateResidency(in int[] powerEntityIds);


@@ -66,7 +67,7 @@ interface IPowerStats {
     * An EnergyConsumer is a device subsystem or peripheral that consumes energy. Energy
     * An EnergyConsumer is a device subsystem or peripheral that consumes energy. Energy
     * consumption data may be used by framework for the purpose of power attribution.
     * consumption data may be used by framework for the purpose of power attribution.
     *
     *
     * @return List of EnergyConsumers that are available.
     * @return List of EnergyConsumers for which energy consumption can be requested.
     */
     */
    EnergyConsumer[] getEnergyConsumerInfo();
    EnergyConsumer[] getEnergyConsumerInfo();


@@ -74,38 +75,40 @@ interface IPowerStats {
     * Reports the energy consumed since boot by each requested EnergyConsumer.
     * Reports the energy consumed since boot by each requested EnergyConsumer.
     *
     *
     * @param energyConsumerIds List of IDs of EnergyConsumers for which data is requested.
     * @param energyConsumerIds List of IDs of EnergyConsumers for which data is requested.
     *     Passing an empty list will return state residency for all available EnergyConsumers.
     *     Passing an empty list will return results for all available EnergyConsumers.
     *
     *
     * @return Energy consumed since boot for each requested EnergyConsumer
     * @return Energy consumed since boot for each requested and available EnergyConsumer. Note
     * that EnergyConsumerResult for a given EnergyConsumer may not always be available. Clients
     * shall not rely on EnergyConsumerResult always being returned for every request.
     *
     *
     * Returns the following service-specific exceptions in order of highest priority:
     * Returns the following exception codes:
     *  - STATUS_BAD_VALUE if an invalid energyConsumerId is provided
     *  - EX_ILLEGAL_ARGUMENT if an invalid energyConsumerId is provided
     *  - STATUS_FAILED_TRANSACTION if any EnergyConsumerResult fails to be returned
     */
     */
    EnergyConsumerResult[] getEnergyConsumed(in int[] energyConsumerIds);
    EnergyConsumerResult[] getEnergyConsumed(in int[] energyConsumerIds);


    /**
    /**
     * Return information related to all channels monitored by Energy Meters.
     * Return information related to all Channels monitored by Energy Meters.
     *
     *
     * An Energy Meter is a device that monitors energy and may support monitoring multiple
     * An Energy Meter is a device that monitors energy and may support monitoring multiple
     * channels simultaneously. A channel may correspond a bus, sense resistor, or power rail.
     * channels simultaneously. A channel may correspond a bus, sense resistor, or power rail.
     *
     *
     * @return Channels monitored by Energy Meters.
     * @return All Channels for which energy measurements can be requested.
     */
     */
    Channel[] getEnergyMeterInfo();
    Channel[] getEnergyMeterInfo();


    /**
    /**
     * Reports accumulated energy for each specified channel.
     * Reports accumulated energy for each specified Channel.
     *
     *
     * @param channelIds IDs of channels for which data is requested.
     * @param channelIds IDs of channels for which data is requested.
     *     Passing an empty list will return energy measurements for all available channels.
     *     Passing an empty list will return energy measurements for all available channels.
     *     ID of each channel is contained in ChannelInfo.
     *     ID of each channel is contained in ChannelInfo.
     *
     *
     * @return Energy measured since boot for each requested channel
     * @return Energy measured since boot for each requested and available Channel. Note
     * that EnergyMeasurement for a given Channel may not always be available. Clients
     * shall not rely on EnergyMeasurement always being returned for every request.
     *
     *
     * Returns the following service-specific exceptions in order of highest priority:
     * Returns the following exception codes:
     *  - STATUS_BAD_VALUE if an invalid channelId is provided
     *  - EX_ILLEGAL_ARGUMENT if an invalid channelId is provided
     *  - STATUS_FAILED_TRANSACTION if any EnergyMeasurement fails to be returned
     */
     */
    EnergyMeasurement[] readEnergyMeter(in int[] channelIds);
    EnergyMeasurement[] readEnergyMeter(in int[] channelIds);
}
}
+5 −2
Original line number Original line Diff line number Diff line
@@ -60,9 +60,12 @@ class FakeEnergyMeter : public PowerStats::IEnergyMeter {
            *_aidl_return = mEnergyMeasurements;
            *_aidl_return = mEnergyMeasurements;
        } else {
        } else {
            for (int32_t id : in_channelIds) {
            for (int32_t id : in_channelIds) {
                if (id >= 0 && id < mEnergyMeasurements.size()) {
                // check for invalid ids
                    _aidl_return->push_back(mEnergyMeasurements[id]);
                if (id < 0 || id >= mEnergyMeasurements.size()) {
                    return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_ILLEGAL_ARGUMENT));
                }
                }

                _aidl_return->push_back(mEnergyMeasurements[id]);
            }
            }
        }
        }


+10 −14
Original line number Original line Diff line number Diff line
@@ -81,14 +81,12 @@ ndk::ScopedAStatus PowerStats::getStateResidency(const std::vector<int32_t>& in_
        return getStateResidency(v, _aidl_return);
        return getStateResidency(v, _aidl_return);
    }
    }


    binder_status_t err = STATUS_OK;

    std::unordered_map<std::string, std::vector<StateResidency>> stateResidencies;
    std::unordered_map<std::string, std::vector<StateResidency>> stateResidencies;


    for (const int32_t id : in_powerEntityIds) {
    for (const int32_t id : in_powerEntityIds) {
        // skip any invalid ids
        // check for invalid ids
        if (id < 0 || id >= mPowerEntityInfos.size()) {
        if (id < 0 || id >= mPowerEntityInfos.size()) {
            continue;
            return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_ILLEGAL_ARGUMENT));
        }
        }


        // Check to see if we already have data for the given id
        // Check to see if we already have data for the given id
@@ -106,12 +104,12 @@ ndk::ScopedAStatus PowerStats::getStateResidency(const std::vector<int32_t>& in_
            };
            };
            _aidl_return->emplace_back(res);
            _aidl_return->emplace_back(res);
        } else {
        } else {
            // Failed to retrieve results for the given id.
            // Failed to get results for the given id.
            err = STATUS_FAILED_TRANSACTION;
            LOG(ERROR) << "Failed to get results for " << powerEntityName;
        }
        }
    }
    }


    return ndk::ScopedAStatus::fromStatus(err);
    return ndk::ScopedAStatus::ok();
}
}


ndk::ScopedAStatus PowerStats::getEnergyConsumerInfo(std::vector<EnergyConsumer>* _aidl_return) {
ndk::ScopedAStatus PowerStats::getEnergyConsumerInfo(std::vector<EnergyConsumer>* _aidl_return) {
@@ -132,12 +130,10 @@ ndk::ScopedAStatus PowerStats::getEnergyConsumed(const std::vector<int32_t>& in_
        return getEnergyConsumed(v, _aidl_return);
        return getEnergyConsumed(v, _aidl_return);
    }
    }


    binder_status_t err = STATUS_OK;

    for (const auto id : in_energyConsumerIds) {
    for (const auto id : in_energyConsumerIds) {
        // skip any invalid ids
        // check for invalid ids
        if (id < 0 || id >= mEnergyConsumers.size()) {
        if (id < 0 || id >= mEnergyConsumers.size()) {
            continue;
            return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_ILLEGAL_ARGUMENT));
        }
        }


        auto optionalResult = mEnergyConsumers[id]->getEnergyConsumed();
        auto optionalResult = mEnergyConsumers[id]->getEnergyConsumed();
@@ -146,12 +142,12 @@ ndk::ScopedAStatus PowerStats::getEnergyConsumed(const std::vector<int32_t>& in_
            result.id = id;
            result.id = id;
            _aidl_return->emplace_back(result);
            _aidl_return->emplace_back(result);
        } else {
        } else {
            // Failed to retrieve results for the given id.
            // Failed to get results for the given id.
            err = STATUS_FAILED_TRANSACTION;
            LOG(ERROR) << "Failed to get results for " << mEnergyConsumerInfos[id].name;
        }
        }
    }
    }


    return ndk::ScopedAStatus::fromStatus(err);
    return ndk::ScopedAStatus::ok();
}
}


ndk::ScopedAStatus PowerStats::getEnergyMeterInfo(std::vector<Channel>* _aidl_return) {
ndk::ScopedAStatus PowerStats::getEnergyMeterInfo(std::vector<Channel>* _aidl_return) {