health: expose battery health data and update version to V2
1. add the new propertes - batteryHealthData - batteryStateOfHealth - chargingState - chargingPolicy 2. add new types to health status 3. add new methods - setChargingPolicy - getChargingPolicy - getBatteryHealthData Bug: 251425963 Test: m android.hardware.health-update-api Change-Id: Ie2339c50e1f9bfc28427e4108a95b1a16c739205 Signed-off-by: Jack Wu <wjack@google.com>
This commit is contained in:
parent
022e49b684
commit
3356161d6c
23 changed files with 477 additions and 14 deletions
|
@ -349,7 +349,7 @@
|
|||
</hal>
|
||||
<hal format="aidl" optional="false">
|
||||
<name>android.hardware.health</name>
|
||||
<version>1</version>
|
||||
<version>1-2</version>
|
||||
<interface>
|
||||
<name>IHealth</name>
|
||||
<instance>default</instance>
|
||||
|
|
|
@ -74,7 +74,7 @@ cc_library {
|
|||
name: "android.hardware.health-translate-ndk",
|
||||
defaults: ["android.hardware.health-translate-ndk_defaults"],
|
||||
shared_libs: [
|
||||
"android.hardware.health-V1-ndk",
|
||||
"android.hardware.health-V2-ndk",
|
||||
],
|
||||
}
|
||||
|
||||
|
@ -91,7 +91,7 @@ java_library {
|
|||
name: "android.hardware.health-translate-java",
|
||||
srcs: ["android/hardware/health/Translate.java"],
|
||||
libs: [
|
||||
"android.hardware.health-V1-java",
|
||||
"android.hardware.health-V2-java",
|
||||
"android.hardware.health-V2.0-java",
|
||||
"android.hardware.health-V2.1-java",
|
||||
],
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (C) 2022 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.
|
||||
*/
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. //
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// This file is a snapshot of an AIDL file. Do not edit it manually. There are
|
||||
// two cases:
|
||||
// 1). this is a frozen version file - do not edit this in any case.
|
||||
// 2). this is a 'current' file. If you make a backwards compatible change to
|
||||
// the interface (from the latest frozen version), the build system will
|
||||
// prompt you to update this file with `m <name>-update-api`.
|
||||
//
|
||||
// You must not make a backward incompatible change to any AIDL file 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.health;
|
||||
@Backing(type="int") @VintfStability
|
||||
enum BatteryChargingPolicy {
|
||||
INVALID = 0,
|
||||
DEFAULT = 1,
|
||||
LONG_LIFE = 2,
|
||||
ADAPTIVE = 3,
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright (C) 2021 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.
|
||||
*/
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. //
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// This file is a snapshot of an AIDL file. Do not edit it manually. There are
|
||||
// two cases:
|
||||
// 1). this is a frozen version file - do not edit this in any case.
|
||||
// 2). this is a 'current' file. If you make a backwards compatible change to
|
||||
// the interface (from the latest frozen version), the build system will
|
||||
// prompt you to update this file with `m <name>-update-api`.
|
||||
//
|
||||
// You must not make a backward incompatible change to any AIDL file 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.health;
|
||||
@Backing(type="int") @VintfStability
|
||||
enum BatteryChargingState {
|
||||
INVALID = 0,
|
||||
NORMAL = 1,
|
||||
TOO_COLD = 2,
|
||||
TOO_HOT = 3,
|
||||
LONG_LIFE = 4,
|
||||
ADAPTIVE = 5,
|
||||
}
|
|
@ -41,4 +41,7 @@ enum BatteryHealth {
|
|||
OVER_VOLTAGE = 5,
|
||||
UNSPECIFIED_FAILURE = 6,
|
||||
COLD = 7,
|
||||
FAIR = 8,
|
||||
NOT_AVAILABLE = 11,
|
||||
INCONSISTENT = 12,
|
||||
}
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright (C) 2022 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.
|
||||
*/
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. //
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// This file is a snapshot of an AIDL file. Do not edit it manually. There are
|
||||
// two cases:
|
||||
// 1). this is a frozen version file - do not edit this in any case.
|
||||
// 2). this is a 'current' file. If you make a backwards compatible change to
|
||||
// the interface (from the latest frozen version), the build system will
|
||||
// prompt you to update this file with `m <name>-update-api`.
|
||||
//
|
||||
// You must not make a backward incompatible change to any AIDL file 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.health;
|
||||
@VintfStability
|
||||
parcelable BatteryHealthData {
|
||||
long batteryManufacturingDateSeconds;
|
||||
long batteryFirstUsageSeconds;
|
||||
}
|
|
@ -57,5 +57,9 @@ parcelable HealthInfo {
|
|||
android.hardware.health.BatteryCapacityLevel batteryCapacityLevel;
|
||||
long batteryChargeTimeToFullNowSeconds;
|
||||
int batteryFullChargeDesignCapacityUah;
|
||||
int batteryStateOfHealth;
|
||||
android.hardware.health.BatteryChargingState chargingState;
|
||||
android.hardware.health.BatteryChargingPolicy chargingPolicy;
|
||||
@nullable android.hardware.health.BatteryHealthData batteryHealthData;
|
||||
const int BATTERY_CHARGE_TIME_TO_FULL_NOW_SECONDS_UNSUPPORTED = -1;
|
||||
}
|
||||
|
|
|
@ -46,6 +46,9 @@ interface IHealth {
|
|||
android.hardware.health.StorageInfo[] getStorageInfo();
|
||||
android.hardware.health.DiskStats[] getDiskStats();
|
||||
android.hardware.health.HealthInfo getHealthInfo();
|
||||
void setChargingPolicy(android.hardware.health.BatteryChargingPolicy in_value);
|
||||
android.hardware.health.BatteryChargingPolicy getChargingPolicy();
|
||||
android.hardware.health.BatteryHealthData getBatteryHealthData();
|
||||
const int STATUS_UNKNOWN = 2;
|
||||
const int STATUS_CALLBACK_DIED = 4;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (C) 2022 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.health;
|
||||
|
||||
/**
|
||||
* Battery charging policy.
|
||||
*/
|
||||
@VintfStability
|
||||
@Backing(type="int")
|
||||
enum BatteryChargingPolicy {
|
||||
INVALID = 0,
|
||||
/**
|
||||
* default policy
|
||||
*/
|
||||
DEFAULT = 1,
|
||||
/**
|
||||
* @see BatteryChargingState.LONG_LIFE
|
||||
*/
|
||||
LONG_LIFE = 2,
|
||||
/**
|
||||
* @see BatteryChargingState.ADAPTIVE
|
||||
*/
|
||||
ADAPTIVE = 3,
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (C) 2021 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.health;
|
||||
|
||||
/**
|
||||
* Possible values for Battery Health.
|
||||
* Note: These are currently in sync with BatteryManager and must not
|
||||
* be extended / altered.
|
||||
*/
|
||||
@VintfStability
|
||||
@Backing(type="int")
|
||||
enum BatteryChargingState {
|
||||
INVALID = 0,
|
||||
/**
|
||||
* Default state.
|
||||
*/
|
||||
NORMAL = 1,
|
||||
/**
|
||||
* Reported when the battery is too cold to charge at a normal
|
||||
* rate or stopped charging due to low temperature.
|
||||
*/
|
||||
TOO_COLD = 2,
|
||||
/**
|
||||
* Reported when the battery is too hot to charge at a normal
|
||||
* rate or stopped charging due to hot temperature.
|
||||
*/
|
||||
TOO_HOT = 3,
|
||||
/**
|
||||
* The device is using a special charging profile that designed
|
||||
* to prevent accelerated aging.
|
||||
*/
|
||||
LONG_LIFE = 4,
|
||||
/**
|
||||
* The device is using a special charging profile designed to
|
||||
* improve battery cycle life, performances or both.
|
||||
*/
|
||||
ADAPTIVE = 5,
|
||||
}
|
|
@ -24,8 +24,15 @@ package android.hardware.health;
|
|||
@VintfStability
|
||||
@Backing(type="int")
|
||||
enum BatteryHealth {
|
||||
/**
|
||||
* Battery health is not supported from the device.
|
||||
*/
|
||||
UNKNOWN = 1,
|
||||
GOOD = 2,
|
||||
/**
|
||||
* Must be consistent with BatteryChargingState.
|
||||
* If BatteryHealth is OVERHEAT, then BatteryChargingState must be TOO_HOT.
|
||||
*/
|
||||
OVERHEAT = 3,
|
||||
DEAD = 4,
|
||||
OVER_VOLTAGE = 5,
|
||||
|
@ -33,5 +40,28 @@ enum BatteryHealth {
|
|||
* Battery experienced an unknown/unspecified failure.
|
||||
*/
|
||||
UNSPECIFIED_FAILURE = 6,
|
||||
/**
|
||||
* Must be consistent with BatteryChargingState.
|
||||
* If BatteryHealth is COLD, then BatteryChargingState must be TOO_COLD.
|
||||
*/
|
||||
COLD = 7,
|
||||
/**
|
||||
* Battery health is marginal.
|
||||
*/
|
||||
FAIR = 8,
|
||||
/**
|
||||
* The reserve data below 10 are used to recognize the battery real health.
|
||||
*/
|
||||
/**
|
||||
* There is not enough information to determine an accurate
|
||||
* value. The value might become UNSPECIFIED_FAILURE, DEAD
|
||||
* or any other state except for UNKNOWN later.
|
||||
*/
|
||||
NOT_AVAILABLE = 11,
|
||||
/**
|
||||
* The internal data is inconsistent and the battery needs to
|
||||
* go through a recalibration process. The value might become
|
||||
* UNSPECIFIED_FAILURE, DEAD or any other state except for UNKNOWN later.
|
||||
*/
|
||||
INCONSISTENT = 12,
|
||||
}
|
||||
|
|
32
health/aidl/android/hardware/health/BatteryHealthData.aidl
Normal file
32
health/aidl/android/hardware/health/BatteryHealthData.aidl
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (C) 2022 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.health;
|
||||
|
||||
/*
|
||||
* Battery health data
|
||||
*/
|
||||
@VintfStability
|
||||
parcelable BatteryHealthData {
|
||||
/**
|
||||
* Battery manufacturing date is reported in epoch.
|
||||
*/
|
||||
long batteryManufacturingDateSeconds;
|
||||
/**
|
||||
* The date of first usage is reported in epoch.
|
||||
*/
|
||||
long batteryFirstUsageSeconds;
|
||||
}
|
|
@ -17,7 +17,10 @@
|
|||
package android.hardware.health;
|
||||
|
||||
import android.hardware.health.BatteryCapacityLevel;
|
||||
import android.hardware.health.BatteryChargingPolicy;
|
||||
import android.hardware.health.BatteryChargingState;
|
||||
import android.hardware.health.BatteryHealth;
|
||||
import android.hardware.health.BatteryHealthData;
|
||||
import android.hardware.health.BatteryStatus;
|
||||
import android.hardware.health.DiskStats;
|
||||
import android.hardware.health.StorageInfo;
|
||||
|
@ -133,4 +136,23 @@ parcelable HealthInfo {
|
|||
* Value must be less than 100 000 000 µAh if known.
|
||||
*/
|
||||
int batteryFullChargeDesignCapacityUah;
|
||||
/**
|
||||
* Measured battery state of health (remaining estimate full charge capacity
|
||||
* relative to the rated capacity in %).
|
||||
* Value must be 0 if batteryStatus is UNKNOWN.
|
||||
* Otherwise, value must be in the range 0 to 100.
|
||||
*/
|
||||
int batteryStateOfHealth;
|
||||
/**
|
||||
* Battery charging state
|
||||
*/
|
||||
BatteryChargingState chargingState;
|
||||
/**
|
||||
* Battery charging policy. See {@link BatteryChargingPolicy} for more details.
|
||||
*/
|
||||
BatteryChargingPolicy chargingPolicy;
|
||||
/**
|
||||
* Battery health data
|
||||
*/
|
||||
@nullable BatteryHealthData batteryHealthData;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package android.hardware.health;
|
||||
|
||||
import android.hardware.health.BatteryChargingPolicy;
|
||||
import android.hardware.health.BatteryHealthData;
|
||||
import android.hardware.health.BatteryStatus;
|
||||
import android.hardware.health.DiskStats;
|
||||
import android.hardware.health.HealthInfo;
|
||||
|
@ -102,7 +104,7 @@ interface IHealth {
|
|||
* if this property is not supported
|
||||
* (e.g. the file that stores this property does not exist),
|
||||
* - Return service specific error with code STATUS_UNKNOWN
|
||||
* for for other errors.
|
||||
* for other errors.
|
||||
*/
|
||||
int getCurrentNowMicroamps();
|
||||
|
||||
|
@ -120,7 +122,7 @@ interface IHealth {
|
|||
* if this property is not supported
|
||||
* (e.g. the file that stores this property does not exist),
|
||||
* - Return service specific error with code STATUS_UNKNOWN
|
||||
* for for other errors.
|
||||
* for other errors.
|
||||
*/
|
||||
int getCurrentAverageMicroamps();
|
||||
|
||||
|
@ -134,7 +136,7 @@ interface IHealth {
|
|||
* if this property is not supported
|
||||
* (e.g. the file that stores this property does not exist),
|
||||
* - Return service specific error with code STATUS_UNKNOWN
|
||||
* for for other errors.
|
||||
* for other errors.
|
||||
*/
|
||||
int getCapacity();
|
||||
|
||||
|
@ -146,7 +148,7 @@ interface IHealth {
|
|||
* - Return exception with code EX_UNSUPPORTED_OPERATION
|
||||
* if this property is not supported,
|
||||
* - Return service specific error with code STATUS_UNKNOWN
|
||||
* for for other errors.
|
||||
* for other errors.
|
||||
*/
|
||||
long getEnergyCounterNwh();
|
||||
|
||||
|
@ -197,7 +199,47 @@ interface IHealth {
|
|||
* - Return exception with code EX_UNSUPPORTED_OPERATION
|
||||
* if this API is not supported,
|
||||
* - Return service specific error with code STATUS_UNKNOWN
|
||||
* for for other errors.
|
||||
* for other errors.
|
||||
*/
|
||||
HealthInfo getHealthInfo();
|
||||
|
||||
/**
|
||||
* Set battery charging policy
|
||||
*
|
||||
* @return If error, return service specific error with code:
|
||||
* - Return exception with code EX_UNSUPPORTED_OPERATION
|
||||
* if this property is not supported
|
||||
* (e.g. the file that stores this property does not exist),
|
||||
* - Return status with code INVALID_OPERATION
|
||||
* if the operation failed.
|
||||
* - Return service specific error with code STATUS_UNKNOWN
|
||||
* for other errors.
|
||||
*/
|
||||
void setChargingPolicy(BatteryChargingPolicy in_value);
|
||||
|
||||
/**
|
||||
* Get current battery charging policy
|
||||
*
|
||||
* @return current battery charging policy if successful.
|
||||
* If error:
|
||||
* - Return exception with code EX_UNSUPPORTED_OPERATION
|
||||
* if this property is not supported
|
||||
* (e.g. the file that stores this property does not exist),
|
||||
* - Return service specific error with code STATUS_UNKNOWN
|
||||
* for other errors.
|
||||
*/
|
||||
BatteryChargingPolicy getChargingPolicy();
|
||||
|
||||
/**
|
||||
* Get battery health data
|
||||
*
|
||||
* @return Battery health data if successful.
|
||||
* If error:
|
||||
* - Return exception with code EX_UNSUPPORTED_OPERATION
|
||||
* if this property is not supported
|
||||
* (e.g. the file that stores this property does not exist),
|
||||
* - Return service specific error with code STATUS_UNKNOWN
|
||||
* for other errors.
|
||||
*/
|
||||
BatteryHealthData getBatteryHealthData();
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ cc_defaults {
|
|||
"libcutils",
|
||||
"liblog",
|
||||
"libutils",
|
||||
"android.hardware.health-V1-ndk",
|
||||
"android.hardware.health-V2-ndk",
|
||||
|
||||
// TODO(b/177269435): remove when BatteryMonitor works with AIDL HealthInfo.
|
||||
"libhidlbase",
|
||||
|
@ -48,7 +48,7 @@ cc_defaults {
|
|||
name: "libhealth_aidl_charger_defaults",
|
||||
shared_libs: [
|
||||
// common
|
||||
"android.hardware.health-V1-ndk",
|
||||
"android.hardware.health-V2-ndk",
|
||||
"libbase",
|
||||
"libcutils",
|
||||
"liblog",
|
||||
|
@ -195,7 +195,7 @@ cc_fuzz {
|
|||
"service_fuzzer_defaults",
|
||||
],
|
||||
static_libs: [
|
||||
"android.hardware.health-V1-ndk",
|
||||
"android.hardware.health-V2-ndk",
|
||||
"libbase",
|
||||
"liblog",
|
||||
"fuzz_libhealth_aidl_impl",
|
||||
|
|
|
@ -115,6 +115,42 @@ ndk::ScopedAStatus Health::getChargeStatus(BatteryStatus* out) {
|
|||
BatteryStatus::UNKNOWN, out);
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Health::setChargingPolicy(BatteryChargingPolicy in_value) {
|
||||
::android::status_t err = battery_monitor_.setChargingPolicy(static_cast<int>(in_value));
|
||||
|
||||
switch (err) {
|
||||
case ::android::OK:
|
||||
return ndk::ScopedAStatus::ok();
|
||||
case ::android::NAME_NOT_FOUND:
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
case ::android::BAD_VALUE:
|
||||
return ndk::ScopedAStatus::fromStatus(::android::INVALID_OPERATION);
|
||||
default:
|
||||
return ndk::ScopedAStatus::fromServiceSpecificErrorWithMessage(
|
||||
IHealth::STATUS_UNKNOWN, ::android::statusToString(err).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Health::getChargingPolicy(BatteryChargingPolicy* out) {
|
||||
return GetProperty(&battery_monitor_, ::android::BATTERY_PROP_CHARGING_POLICY,
|
||||
BatteryChargingPolicy::DEFAULT, out);
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Health::getBatteryHealthData(BatteryHealthData* out) {
|
||||
if (auto res =
|
||||
GetProperty<int64_t>(&battery_monitor_, ::android::BATTERY_PROP_MANUFACTURING_DATE,
|
||||
0, &out->batteryManufacturingDateSeconds);
|
||||
!res.isOk()) {
|
||||
LOG(WARNING) << "Cannot get Manufacturing_date: " << res.getDescription();
|
||||
}
|
||||
if (auto res = GetProperty<int64_t>(&battery_monitor_, ::android::BATTERY_PROP_FIRST_USAGE_DATE,
|
||||
0, &out->batteryFirstUsageSeconds);
|
||||
!res.isOk()) {
|
||||
LOG(WARNING) << "Cannot get First_usage_date: " << res.getDescription();
|
||||
}
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Health::getDiskStats(std::vector<DiskStats>*) {
|
||||
// This implementation does not support DiskStats. An implementation may extend this
|
||||
// class and override this function to support disk stats.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<manifest version="1.0" type="device">
|
||||
<hal format="aidl">
|
||||
<name>android.hardware.health</name>
|
||||
<version>1</version>
|
||||
<version>2</version>
|
||||
<fqname>IHealth/default</fqname>
|
||||
</hal>
|
||||
</manifest>
|
||||
|
|
|
@ -72,6 +72,10 @@ class Health : public BnHealth, public HalHealthLoopCallback {
|
|||
ndk::ScopedAStatus getDiskStats(std::vector<DiskStats>* out) override;
|
||||
ndk::ScopedAStatus getStorageInfo(std::vector<StorageInfo>* out) override;
|
||||
|
||||
ndk::ScopedAStatus setChargingPolicy(BatteryChargingPolicy in_value) override;
|
||||
ndk::ScopedAStatus getChargingPolicy(BatteryChargingPolicy* out) override;
|
||||
ndk::ScopedAStatus getBatteryHealthData(BatteryHealthData* out) override;
|
||||
|
||||
// A subclass may override these to provide a different implementation.
|
||||
binder_status_t dump(int fd, const char** args, uint32_t num_args) override;
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ cc_test {
|
|||
"libbinder_ndk",
|
||||
],
|
||||
static_libs: [
|
||||
"android.hardware.health-V1-ndk",
|
||||
"android.hardware.health-V2-ndk",
|
||||
"libgmock",
|
||||
],
|
||||
header_libs: [
|
||||
|
|
|
@ -225,6 +225,61 @@ TEST_P(HealthAidl, getChargeStatus) {
|
|||
ASSERT_THAT(value, IsValidEnum<BatteryStatus>());
|
||||
}
|
||||
|
||||
/*
|
||||
* Tests the values returned by getChargingPolicy() from interface IHealth.
|
||||
*/
|
||||
TEST_P(HealthAidl, getChargingPolicy) {
|
||||
BatteryChargingPolicy value;
|
||||
auto status = health->getChargingPolicy(&value);
|
||||
ASSERT_THAT(status, AnyOf(IsOk(), ExceptionIs(EX_UNSUPPORTED_OPERATION)));
|
||||
if (!status.isOk()) return;
|
||||
ASSERT_THAT(value, IsValidEnum<BatteryChargingPolicy>());
|
||||
}
|
||||
|
||||
/*
|
||||
* Tests that setChargingPolicy() writes the value and compared the returned
|
||||
* value by getChargingPolicy() from interface IHealth.
|
||||
*/
|
||||
TEST_P(HealthAidl, setChargingPolicy) {
|
||||
BatteryChargingPolicy value;
|
||||
|
||||
/* set ChargingPolicy*/
|
||||
auto status = health->setChargingPolicy(static_cast<BatteryChargingPolicy>(2)); // LONG_LIFE
|
||||
ASSERT_THAT(status, AnyOf(IsOk(), ExceptionIs(EX_UNSUPPORTED_OPERATION)));
|
||||
if (!status.isOk()) return;
|
||||
|
||||
/* get ChargingPolicy*/
|
||||
status = health->getChargingPolicy(&value);
|
||||
ASSERT_THAT(status, AnyOf(IsOk(), ExceptionIs(EX_UNSUPPORTED_OPERATION)));
|
||||
if (!status.isOk()) return;
|
||||
ASSERT_THAT(static_cast<int>(value), Eq(2));
|
||||
}
|
||||
|
||||
MATCHER(IsValidHealthData, "") {
|
||||
*result_listener << "value is " << arg.toString() << ".";
|
||||
if (!ExplainMatchResult(Ge(-1), arg.batteryManufacturingDateSeconds, result_listener)) {
|
||||
*result_listener << " for batteryManufacturingDateSeconds.";
|
||||
return false;
|
||||
}
|
||||
if (!ExplainMatchResult(Ge(-1), arg.batteryFirstUsageSeconds, result_listener)) {
|
||||
*result_listener << " for batteryFirstUsageSeconds.";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Tests the values returned by getBatteryHealthData() from interface IHealth.
|
||||
*/
|
||||
TEST_P(HealthAidl, getBatteryHealthData) {
|
||||
BatteryHealthData value;
|
||||
auto status = health->getBatteryHealthData(&value);
|
||||
ASSERT_THAT(status, AnyOf(IsOk(), ExceptionIs(EX_UNSUPPORTED_OPERATION)));
|
||||
if (!status.isOk()) return;
|
||||
ASSERT_THAT(value, IsValidHealthData());
|
||||
}
|
||||
|
||||
MATCHER(IsValidStorageInfo, "") {
|
||||
*result_listener << "value is " << arg.toString() << ".";
|
||||
if (!ExplainMatchResult(InClosedRange(0, 3), arg.eol, result_listener)) {
|
||||
|
|
|
@ -34,7 +34,7 @@ cc_defaults {
|
|||
"-Werror",
|
||||
],
|
||||
static_libs: [
|
||||
"android.hardware.health-V1-ndk",
|
||||
"android.hardware.health-V2-ndk",
|
||||
"android.hardware.health-translate-ndk",
|
||||
"android.hardware.health@1.0",
|
||||
"android.hardware.health@2.0",
|
||||
|
|
|
@ -45,6 +45,9 @@ class HealthShim : public BnHealth {
|
|||
ndk::ScopedAStatus getStorageInfo(std::vector<StorageInfo>* _aidl_return) override;
|
||||
ndk::ScopedAStatus getDiskStats(std::vector<DiskStats>* _aidl_return) override;
|
||||
ndk::ScopedAStatus getHealthInfo(HealthInfo* _aidl_return) override;
|
||||
ndk::ScopedAStatus setChargingPolicy(BatteryChargingPolicy in_value) override;
|
||||
ndk::ScopedAStatus getChargingPolicy(BatteryChargingPolicy* _aidl_return) override;
|
||||
ndk::ScopedAStatus getBatteryHealthData(BatteryHealthData* _aidl_return) override;
|
||||
|
||||
private:
|
||||
::android::sp<HidlHealth> service_;
|
||||
|
|
|
@ -217,4 +217,20 @@ ScopedAStatus HealthShim::getHealthInfo(HealthInfo* out) {
|
|||
return ReturnAndResultToStatus(ret, out_result);
|
||||
}
|
||||
|
||||
ScopedAStatus HealthShim::setChargingPolicy(BatteryChargingPolicy in_value) {
|
||||
in_value = static_cast<BatteryChargingPolicy>(0);
|
||||
return ResultToStatus(Result::NOT_SUPPORTED);
|
||||
}
|
||||
|
||||
ScopedAStatus HealthShim::getChargingPolicy(BatteryChargingPolicy* out) {
|
||||
*out = static_cast<BatteryChargingPolicy>(0);
|
||||
return ResultToStatus(Result::NOT_SUPPORTED);
|
||||
}
|
||||
|
||||
ScopedAStatus HealthShim::getBatteryHealthData(BatteryHealthData* out) {
|
||||
out->batteryManufacturingDateSeconds = 0;
|
||||
out->batteryFirstUsageSeconds = 0;
|
||||
return ResultToStatus(Result::NOT_SUPPORTED);
|
||||
}
|
||||
|
||||
} // namespace aidl::android::hardware::health
|
||||
|
|
Loading…
Reference in a new issue