powerstats: Add EnergyConsumer API

Also clean up rest of PowerStats HAL 2.0 API and type names

Bug: 168831183
Test: atest VtsHalPowerStatsTargetTest
Change-Id: I987f984bf717b107cf55213c7063ac9f310f8d54
This commit is contained in:
Benjamin Schwartz
2020-09-28 14:33:59 -07:00
parent a91c261c55
commit 42408279d8
21 changed files with 259 additions and 118 deletions

View File

@@ -17,7 +17,7 @@
package android.hardware.powerstats;
@VintfStability
parcelable PowerEntityStateInfo {
int powerEntityStateId;
String powerEntityStateName;
parcelable ChannelInfo {
int channelId;
String channelName;
}

View File

@@ -0,0 +1,23 @@
///////////////////////////////////////////////////////////////////////////////
// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. //
///////////////////////////////////////////////////////////////////////////////
// This file is a snapshot of an AIDL interface (or parcelable). Do not try to
// edit this file. It looks like you are doing that because you have modified
// an AIDL interface in a backward-incompatible way, e.g., deleting a function
// from an interface or a field from a parcelable and it broke the build. That
// breakage is intended.
//
// You must not make a backward incompatible changes to the AIDL files built
// with the aidl_interface module type with versions property set. The module
// type is used to build AIDL files in a way that they can be used across
// independently updatable components of the system. If a device is shipped
// with such a backward incompatible change, it has a high risk of breaking
// later when a module using the interface is updated, e.g., Mainline modules.
package android.hardware.powerstats;
@Backing(type="int") @VintfStability
enum EnergyConsumerId {
DISPLAY = 0,
GPS = 1,
}

View File

@@ -0,0 +1,24 @@
///////////////////////////////////////////////////////////////////////////////
// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. //
///////////////////////////////////////////////////////////////////////////////
// This file is a snapshot of an AIDL interface (or parcelable). Do not try to
// edit this file. It looks like you are doing that because you have modified
// an AIDL interface in a backward-incompatible way, e.g., deleting a function
// from an interface or a field from a parcelable and it broke the build. That
// breakage is intended.
//
// You must not make a backward incompatible changes to the AIDL files built
// with the aidl_interface module type with versions property set. The module
// type is used to build AIDL files in a way that they can be used across
// independently updatable components of the system. If a device is shipped
// with such a backward incompatible change, it has a high risk of breaking
// later when a module using the interface is updated, e.g., Mainline modules.
package android.hardware.powerstats;
@VintfStability
parcelable EnergyConsumerResult {
android.hardware.powerstats.EnergyConsumerId energyConsumerId;
long timestampMs;
long energyUWs;
}

View File

@@ -17,8 +17,8 @@
package android.hardware.powerstats;
@VintfStability
parcelable EnergyData {
int railIndex;
parcelable EnergyMeasurement {
int channelId;
long timestampMs;
long energyUWs;
}

View File

@@ -18,8 +18,10 @@
package android.hardware.powerstats;
@VintfStability
interface IPowerStats {
android.hardware.powerstats.EnergyData[] getEnergyData(in int[] railIndices);
android.hardware.powerstats.PowerEntityInfo[] getPowerEntityInfo();
android.hardware.powerstats.PowerEntityStateResidencyResult[] getPowerEntityStateResidencyData(in int[] powerEntityIds);
android.hardware.powerstats.RailInfo[] getRailInfo();
android.hardware.powerstats.StateResidencyResult[] getPowerEntityStateResidency(in int[] powerEntityIds);
android.hardware.powerstats.EnergyConsumerId[] getEnergyConsumerInfo();
android.hardware.powerstats.EnergyConsumerResult[] getEnergyConsumed(in android.hardware.powerstats.EnergyConsumerId[] energyConsumerIds);
android.hardware.powerstats.ChannelInfo[] getEnergyMeterInfo();
android.hardware.powerstats.EnergyMeasurement[] readEnergyMeters(in int[] channelIds);
}

View File

@@ -20,5 +20,5 @@ package android.hardware.powerstats;
parcelable PowerEntityInfo {
int powerEntityId;
String powerEntityName;
android.hardware.powerstats.PowerEntityStateInfo[] states;
android.hardware.powerstats.StateInfo[] states;
}

View File

@@ -17,9 +17,7 @@
package android.hardware.powerstats;
@VintfStability
parcelable RailInfo {
int railIndex;
String railName;
String subsysName;
int samplingRateHz;
parcelable StateInfo {
int stateId;
String stateName;
}

View File

@@ -17,8 +17,8 @@
package android.hardware.powerstats;
@VintfStability
parcelable PowerEntityStateResidencyData {
int powerEntityStateId;
parcelable StateResidency {
int stateId;
long totalTimeInStateMs;
long totalStateEntryCount;
long lastEntryTimestampMs;

View File

@@ -17,7 +17,7 @@
package android.hardware.powerstats;
@VintfStability
parcelable PowerEntityStateResidencyResult {
parcelable StateResidencyResult {
int powerEntityId;
android.hardware.powerstats.PowerEntityStateResidencyData[] stateResidencyData;
android.hardware.powerstats.StateResidency[] stateResidencyData;
}

View File

@@ -0,0 +1,32 @@
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.hardware.powerstats;
@VintfStability
parcelable ChannelInfo {
/**
* Unique ID
*/
int channelId;
/**
* Unique name of the ChannelInfo:
*
* Vendor/device specific. Opaque to framework
*/
String channelName;
}

View File

@@ -0,0 +1,24 @@
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.hardware.powerstats;
@VintfStability
@Backing(type="int")
enum EnergyConsumerId {
DISPLAY = 0,
GPS = 1,
}

View File

@@ -16,23 +16,21 @@
package android.hardware.powerstats;
import android.hardware.powerstats.EnergyConsumerId;
@VintfStability
parcelable RailInfo {
parcelable EnergyConsumerResult {
/**
* Index corresponding to the rail
* Unique ID associated with the given EnergyMeterInfo
*/
int railIndex;
EnergyConsumerId energyConsumerId;
/**
* Name of the rail (opaque to the framework)
* Time since device boot in milliseconds
*/
String railName;
long timestampMs;
/**
* Name of the subsystem to which this rail belongs (opaque to the framework)
* Accumulated energy since device boot in microwatt-seconds (uWs)
*/
String subsysName;
/**
* Hardware sampling rate in Hz
*/
int samplingRateHz;
long energyUWs;
}

View File

@@ -17,12 +17,11 @@
package android.hardware.powerstats;
@VintfStability
parcelable EnergyData {
parcelable EnergyMeasurement {
/**
* Index corresponding to the rail. This index matches
* the index returned in RailInfo
* Unique ID corresponding to the given ChannelInfo
*/
int railIndex;
int channelId;
/**
* Time since device boot(CLOCK_BOOTTIME) in milli-seconds
*/

View File

@@ -16,26 +16,16 @@
package android.hardware.powerstats;
import android.hardware.powerstats.EnergyData;
import android.hardware.powerstats.ChannelInfo;
import android.hardware.powerstats.EnergyConsumerId;
import android.hardware.powerstats.EnergyConsumerResult;
import android.hardware.powerstats.EnergyMeasurement;
import android.hardware.powerstats.PowerEntityInfo;
import android.hardware.powerstats.PowerEntityStateResidencyResult;
import android.hardware.powerstats.RailInfo;
import android.hardware.powerstats.StateResidencyResult;
@VintfStability
interface IPowerStats {
/**
* Rail level energy measurements for low frequency clients:
* Reports accumulated energy since boot on each rail.
*
* @param railIndices Indices of rails for which data is required.
* To get data for all rails pass an empty vector. Rail name to
* index mapping can be queried from getRailInfo() API.
* @return Energy values since boot for all requested rails.
*/
EnergyData[] getEnergyData(in int[] railIndices);
/**
* PowerEntity information:
* Reports information related to all supported PowerEntity(s) for which
* data is available. A PowerEntity is defined as a platform subsystem,
* peripheral, or power domain that impacts the total device power
@@ -46,29 +36,64 @@ interface IPowerStats {
PowerEntityInfo[] getPowerEntityInfo();
/**
* PowerEntity residencies for low frequency clients:
* Reports accumulated residency data for each specified PowerEntity.
* Each PowerEntity may reside in one of multiple states. It may also
* transition to another state. Residency data is an accumulation of time
* that a specified PowerEntity resided in each of its possible states,
* the number of times that each state was entered, and a timestamp
* corresponding to the last time that state was entered. Data is
* accumulated starting from the last time the PowerEntity was reset.
* transition from one state to another. StateResidency is defined as
* an accumulation of time that a PowerEntity resided in each
* of its possible states, the number of times that each state was
* entered, and a timestamp corresponding to the last time that state
* was entered. Data is accumulated starting from the last time the
* PowerEntity was reset.
*
* @param powerEntityId collection of IDs of PowerEntity(s) for which
* residency data is requested. PowerEntity name to ID mapping may
* be queried from getPowerEntityInfo(). To get state residency
* data for all PowerEntity(s) pass an empty vector.
* @return state residency data for each specified
* PowerEntity that provides state residency data.
* @param powerEntityIds IDs of PowerEntities for which data is required.
* To get data for all PowerEntities pass an empty vector. PowerEntity name to
* ID mapping can be queried from getPowerEntityInfo() API.
* @return StateResidency since boot for all requested PowerEntity(s).
*/
PowerEntityStateResidencyResult[] getPowerEntityStateResidencyData(in int[] powerEntityIds);
StateResidencyResult[] getPowerEntityStateResidency(in int[] powerEntityIds);
/**
* Rail information:
* Reports information related to the rails being monitored.
* Reports a list of IDs corresponding to all enabled EnergyConsumers.
*
* @return Information about monitored rails.
* @return list of EnergyConsumersIds that are available.
*/
RailInfo[] getRailInfo();
EnergyConsumerId[] getEnergyConsumerInfo();
/**
* Returns any available energy consumption results.
*
* @param energyConsumerIds IDs of EnergyConsumers for which data is requested.
* To get data for all EnergyConsumers pass an empty list.
* @return List of EnergyConsumerResults reporting energy consumed since boot for each requested
* EnergyConsumerId.
*
* Returns the following service-specific exceptions:
* STATUS_FAILED_TRANSACTION if any of the requested energy results is unavailable
* STATUS_BAD_VALUE if an invalid EnergyConsumer Id is provided
*/
EnergyConsumerResult[] getEnergyConsumed(in EnergyConsumerId[] energyConsumerIds);
/**
* Reports channels monitored by Energy Meters.
* Each channel has a name, which may correspond to the name of a power rail on the device,
* and an Id which is used to relate EnergyMeasurements returned by readEnergyMeters() with a
* given ChannelInfo.
*
* @return Information about channels monitored by Energy Meters.
*/
ChannelInfo[] getEnergyMeterInfo();
/**
* Reports accumulated energy since boot for each specified channel.
*
* @param channelIds IDs of channels for which data is requested.
* To get data for all channels pass an empty list. Channel name to
* ID mapping can be queried from getEnergyMeterInfo() API.
* @return Energy measured since boot for all requested channels.
*
* Returns the following service-specific exceptions:
* STATUS_FAILED_TRANSACTION if any of the requested energy measurements are unavailable
* STATUS_BAD_VALUE if an invalid channelId is provided
*/
EnergyMeasurement[] readEnergyMeters(in int[] channelIds);
}

View File

@@ -16,7 +16,7 @@
package android.hardware.powerstats;
import android.hardware.powerstats.PowerEntityStateInfo;
import android.hardware.powerstats.StateInfo;
/**
* PowerEntityInfo contains information, such as the ID, name, and type of a
@@ -29,11 +29,11 @@ parcelable PowerEntityInfo {
*/
int powerEntityId;
/**
* Name of the PowerEntity (opaque to the framework)
* Unique name of the PowerEntity. Vendor/device specific. Opaque to framework.
*/
String powerEntityName;
/**
* List of states that the PowerEntity may reside in
*/
PowerEntityStateInfo[] states;
StateInfo[] states;
}

View File

@@ -17,14 +17,15 @@
package android.hardware.powerstats;
@VintfStability
parcelable PowerEntityStateInfo {
parcelable StateInfo {
/**
* ID corresponding to the state. Unique for a given PowerEntityStateSpace
* ID corresponding to the state. Unique for a given PowerEntityInfo
*/
int powerEntityStateId;
int stateId;
/**
* Name of the state (opaque to the framework)
* Unique (for a given PowerEntityInfo) name of the state. Vendor/device specific.
* Opaque to framework.
*/
String powerEntityStateName;
String stateName;
}

View File

@@ -20,25 +20,22 @@ package android.hardware.powerstats;
* Contains residency data for a single state
*/
@VintfStability
parcelable PowerEntityStateResidencyData {
parcelable StateResidency {
/**
* Unique ID of the corresponding PowerEntityStateInfo
* ID of the corresponding StateInfo
*/
int powerEntityStateId;
int stateId;
/**
* Total time in milliseconds that the corresponding PowerEntity resided
* in this state since the PowerEntity was reset
* in since device boot
*/
long totalTimeInStateMs;
/**
* Total number of times that the state was entered since the corresponding
* PowerEntity was reset
* Total number of times that the state was entered since device boot
*/
long totalStateEntryCount;
/**
* Last time this state was entered. Time in milliseconds since the
* corresponding PowerEntity was reset
* Last time this state was entered. Time in milliseconds since device boot
*/
long lastEntryTimestampMs;
}
}

View File

@@ -16,17 +16,17 @@
package android.hardware.powerstats;
import android.hardware.powerstats.PowerEntityStateResidencyData;
import android.hardware.powerstats.StateResidency;
@VintfStability
parcelable PowerEntityStateResidencyResult {
parcelable StateResidencyResult {
/**
* Unique ID of the corresponding PowerEntity
* ID of the corresponding PowerEntity
*/
int powerEntityId;
/**
* Residency data for each state the PowerEntity's state space
*/
PowerEntityStateResidencyData[] stateResidencyData;
StateResidency[] stateResidencyData;
}

View File

@@ -23,27 +23,40 @@ namespace android {
namespace hardware {
namespace powerstats {
ndk::ScopedAStatus PowerStats::getEnergyData(const std::vector<int32_t>& in_railIndices,
std::vector<EnergyData>* _aidl_return) {
(void)in_railIndices;
(void)_aidl_return;
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus PowerStats::getPowerEntityInfo(std::vector<PowerEntityInfo>* _aidl_return) {
(void)_aidl_return;
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus PowerStats::getPowerEntityStateResidencyData(
ndk::ScopedAStatus PowerStats::getPowerEntityStateResidency(
const std::vector<int32_t>& in_powerEntityIds,
std::vector<PowerEntityStateResidencyResult>* _aidl_return) {
std::vector<StateResidencyResult>* _aidl_return) {
(void)in_powerEntityIds;
(void)_aidl_return;
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus PowerStats::getRailInfo(std::vector<RailInfo>* _aidl_return) {
ndk::ScopedAStatus PowerStats::getEnergyConsumerInfo(std::vector<EnergyConsumerId>* _aidl_return) {
(void)_aidl_return;
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus PowerStats::getEnergyConsumed(
const std::vector<EnergyConsumerId>& in_energyConsumerIds,
std::vector<EnergyConsumerResult>* _aidl_return) {
(void)in_energyConsumerIds;
(void)_aidl_return;
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus PowerStats::getEnergyMeterInfo(std::vector<ChannelInfo>* _aidl_return) {
(void)_aidl_return;
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus PowerStats::readEnergyMeters(const std::vector<int32_t>& in_channelIds,
std::vector<EnergyMeasurement>* _aidl_return) {
(void)in_channelIds;
(void)_aidl_return;
return ndk::ScopedAStatus::ok();
}

View File

@@ -26,13 +26,17 @@ namespace powerstats {
class PowerStats : public BnPowerStats {
public:
PowerStats() = default;
ndk::ScopedAStatus getEnergyData(const std::vector<int32_t>& in_railIndices,
std::vector<EnergyData>* _aidl_return) override;
// Methods from aidl::android::hardware::powerstats::IPowerStats
ndk::ScopedAStatus getPowerEntityInfo(std::vector<PowerEntityInfo>* _aidl_return) override;
ndk::ScopedAStatus getPowerEntityStateResidencyData(
ndk::ScopedAStatus getPowerEntityStateResidency(
const std::vector<int32_t>& in_powerEntityIds,
std::vector<PowerEntityStateResidencyResult>* _aidl_return) override;
ndk::ScopedAStatus getRailInfo(std::vector<RailInfo>* _aidl_return) override;
std::vector<StateResidencyResult>* _aidl_return) override;
ndk::ScopedAStatus getEnergyConsumerInfo(std::vector<EnergyConsumerId>* _aidl_return) override;
ndk::ScopedAStatus getEnergyConsumed(const std::vector<EnergyConsumerId>& in_energyConsumerIds,
std::vector<EnergyConsumerResult>* _aidl_return) override;
ndk::ScopedAStatus getEnergyMeterInfo(std::vector<ChannelInfo>* _aidl_return) override;
ndk::ScopedAStatus readEnergyMeters(const std::vector<int32_t>& in_channelIds,
std::vector<EnergyMeasurement>* _aidl_return) override;
};
} // namespace powerstats

View File

@@ -21,11 +21,12 @@
#include <android/binder_manager.h>
#include <android/binder_process.h>
using aidl::android::hardware::powerstats::EnergyData;
using aidl::android::hardware::powerstats::ChannelInfo;
using aidl::android::hardware::powerstats::EnergyMeasurement;
using aidl::android::hardware::powerstats::IPowerStats;
using aidl::android::hardware::powerstats::PowerEntityInfo;
using aidl::android::hardware::powerstats::PowerEntityStateResidencyResult;
using aidl::android::hardware::powerstats::RailInfo;
using aidl::android::hardware::powerstats::StateResidencyResult;
using ndk::SpAIBinder;
class PowerStatsAidl : public testing::TestWithParam<std::string> {
@@ -39,9 +40,9 @@ class PowerStatsAidl : public testing::TestWithParam<std::string> {
std::shared_ptr<IPowerStats> powerstats;
};
TEST_P(PowerStatsAidl, TestGetEnergyData) {
std::vector<EnergyData> data;
ASSERT_TRUE(powerstats->getEnergyData({}, &data).isOk());
TEST_P(PowerStatsAidl, TestReadEnergyMeter) {
std::vector<EnergyMeasurement> data;
ASSERT_TRUE(powerstats->readEnergyMeters({}, &data).isOk());
}
// Each PowerEntity must have a valid name
@@ -83,7 +84,7 @@ TEST_P(PowerStatsAidl, ValidateStateNames) {
for (auto info : infos) {
for (auto state : info.states) {
EXPECT_NE(state.powerEntityStateName, "");
EXPECT_NE(state.stateName, "");
}
}
}
@@ -96,7 +97,7 @@ TEST_P(PowerStatsAidl, ValidateStateUniqueNames) {
for (auto info : infos) {
std::set<std::string> stateNames;
for (auto state : info.states) {
EXPECT_TRUE(stateNames.insert(state.powerEntityStateName).second);
EXPECT_TRUE(stateNames.insert(state.stateName).second);
}
}
}
@@ -107,21 +108,21 @@ TEST_P(PowerStatsAidl, ValidateStateUniqueIds) {
ASSERT_TRUE(powerstats->getPowerEntityInfo(&infos).isOk());
for (auto info : infos) {
std::set<uint32_t> stateIds;
std::set<int32_t> stateIds;
for (auto state : info.states) {
EXPECT_TRUE(stateIds.insert(state.powerEntityStateId).second);
EXPECT_TRUE(stateIds.insert(state.stateId).second);
}
}
}
TEST_P(PowerStatsAidl, TestGetPowerEntityStateResidencyData) {
std::vector<PowerEntityStateResidencyResult> data;
ASSERT_TRUE(powerstats->getPowerEntityStateResidencyData({}, &data).isOk());
TEST_P(PowerStatsAidl, TestGetStateResidencyData) {
std::vector<StateResidencyResult> data;
ASSERT_TRUE(powerstats->getPowerEntityStateResidency({}, &data).isOk());
}
TEST_P(PowerStatsAidl, TestGetRailInfo) {
std::vector<RailInfo> info;
ASSERT_TRUE(powerstats->getRailInfo(&info).isOk());
TEST_P(PowerStatsAidl, TestGetEnergyMeterInfo) {
std::vector<ChannelInfo> info;
ASSERT_TRUE(powerstats->getEnergyMeterInfo(&info).isOk());
}
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(PowerStatsAidl);