summaryrefslogtreecommitdiff
path: root/services
diff options
context:
space:
mode:
authorAlexander Martinz <alex@amartinz.at>2017-08-25 12:01:11 +0200
committeralk3pInjection <webmaster@raspii.tech>2022-05-07 00:20:58 +0800
commitb56b36abbdc4f34a924d106c0b954efb5d52bc3d (patch)
tree2548e0edd918a4836f06876ae165c9010d5045a8 /services
parentb22a41ebeb8fc9bf9093bf5a713edf2abb47f838 (diff)
BatteryService: Add support for OEM fast charger detection
Allows to indicate, whether a device is charged using a proprietary OEM fast charge solution, which write their status to sysfs. The OEM fast charge detection tries to be as generic as possible and is configured via overlays. Path to sysfs to read status - core/res/res/values/custom_config.xml - config_oemFastChargerStatusPath Value expected from read status (Defaults to "1" if not specified) - core/res/res/values/custom_config.xml - config_oemFastChargerStatusValue Change-Id: I6f3598a5a6a3efc76553261d2cf73094170d4110 Signed-off-by: Adithya R <gh0strider.2k18.reborn@gmail.com>
Diffstat (limited to 'services')
-rw-r--r--services/core/java/com/android/server/BatteryService.java32
1 files changed, 30 insertions, 2 deletions
diff --git a/services/core/java/com/android/server/BatteryService.java b/services/core/java/com/android/server/BatteryService.java
index 1e608f5c1240..325a02ec0e38 100644
--- a/services/core/java/com/android/server/BatteryService.java
+++ b/services/core/java/com/android/server/BatteryService.java
@@ -177,6 +177,9 @@ public final class BatteryService extends SystemService {
private boolean mBatteryLevelLow;
+ private boolean mOemFastCharger;
+ private boolean mLastOemFastCharger;
+
private long mDischargeStartTime;
private int mDischargeStartLevel;
@@ -517,6 +520,8 @@ public final class BatteryService extends SystemService {
shutdownIfNoPowerLocked();
shutdownIfOverTempLocked();
+ mOemFastCharger = isOemFastCharger();
+
if (force || (mHealthInfo.batteryStatus != mLastBatteryStatus ||
mHealthInfo.batteryHealth != mLastBatteryHealth ||
mHealthInfo.batteryPresent != mLastBatteryPresent ||
@@ -527,7 +532,8 @@ public final class BatteryService extends SystemService {
mHealthInfo.maxChargingCurrent != mLastMaxChargingCurrent ||
mHealthInfo.maxChargingVoltage != mLastMaxChargingVoltage ||
mHealthInfo.batteryChargeCounter != mLastChargeCounter ||
- mInvalidCharger != mLastInvalidCharger)) {
+ mInvalidCharger != mLastInvalidCharger ||
+ mOemFastCharger != mLastOemFastCharger)) {
if (mPlugType != mLastPlugType) {
if (mLastPlugType == BATTERY_PLUGGED_NONE) {
@@ -698,6 +704,7 @@ public final class BatteryService extends SystemService {
mLastChargeCounter = mHealthInfo.batteryChargeCounter;
mLastBatteryLevelCritical = mBatteryLevelCritical;
mLastInvalidCharger = mInvalidCharger;
+ mLastOemFastCharger = mOemFastCharger;
}
}
@@ -725,9 +732,11 @@ public final class BatteryService extends SystemService {
intent.putExtra(BatteryManager.EXTRA_MAX_CHARGING_CURRENT, mHealthInfo.maxChargingCurrent);
intent.putExtra(BatteryManager.EXTRA_MAX_CHARGING_VOLTAGE, mHealthInfo.maxChargingVoltage);
intent.putExtra(BatteryManager.EXTRA_CHARGE_COUNTER, mHealthInfo.batteryChargeCounter);
+ intent.putExtra(BatteryManager.EXTRA_OEM_FAST_CHARGER, mOemFastCharger);
if (DEBUG) {
Slog.d(TAG, "Sending ACTION_BATTERY_CHANGED. scale:" + BATTERY_SCALE
- + ", info:" + mHealthInfo.toString());
+ + ", info:" + mHealthInfo.toString()
+ + ", mOemFastCharger:" + mOemFastCharger);
}
mHandler.post(() -> ActivityManager.broadcastStickyIntent(intent, UserHandle.USER_ALL));
@@ -779,6 +788,25 @@ public final class BatteryService extends SystemService {
mLastBatteryLevelChangedSentMs = SystemClock.elapsedRealtime();
}
+ private boolean isOemFastCharger() {
+ final String path = mContext.getResources().getString(
+ com.android.internal.R.string.config_oemFastChargerStatusPath);
+
+ if (path.isEmpty())
+ return false;
+
+ final String value = mContext.getResources().getString(
+ com.android.internal.R.string.config_oemFastChargerStatusValue);
+
+ try {
+ return FileUtils.readTextFile(new File(path), value.length(), null).equals(value);
+ } catch (IOException e) {
+ Slog.e(TAG, "Failed to read oem fast charger status path: " + path);
+ }
+
+ return false;
+ }
+
// TODO: Current code doesn't work since "--unplugged" flag in BSS was purposefully removed.
private void logBatteryStatsLocked() {
IBinder batteryInfoService = ServiceManager.getService(BatteryStats.SERVICE_NAME);