Skip to content

Commit

Permalink
[WIP] LineageHealth: hook up charging policy with lineage health
Browse files Browse the repository at this point in the history
Change-Id: Idbeb523388f1e857eeb35422a4dd69ae477efa3e
  • Loading branch information
hellobbn authored and fazilsheik96 committed Feb 27, 2025
1 parent 74176fe commit 9a31d1a
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions services/core/java/com/android/server/BatteryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.android.server;

import static android.os.BatteryManager.CHARGING_POLICY_DEFAULT;
import static android.os.Flags.batteryServiceSupportCurrentAdbCommand;
import static android.os.Flags.stateOfHealthPublic;

Expand Down Expand Up @@ -66,6 +67,7 @@
import android.util.proto.ProtoOutputStream;

import com.android.internal.app.IBatteryStats;
import com.android.internal.lineage.health.HealthInterface;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.util.DumpUtils;
import com.android.server.am.BatteryStatsService;
Expand Down Expand Up @@ -137,6 +139,7 @@ public final class BatteryService extends SystemService {
private static final int BATTERY_PLUGGED_NONE = OsProtoEnums.BATTERY_PLUGGED_NONE; // = 0

private final Context mContext;
private HealthInterface mLineageHealthInterface;
private final IBatteryStats mBatteryStats;
BinderService mBinderService;
private final Handler mHandler;
Expand Down Expand Up @@ -307,6 +310,16 @@ public void onChange(boolean selfChange) {
false, obs, UserHandle.USER_ALL);
updateBatteryWarningLevelLocked();
}
} else if (phase == PHASE_BOOT_COMPLETED) {
HealthInterface lineageHealthInterface;
try {
lineageHealthInterface = HealthInterface.getInstance(mContext);
} catch (RuntimeException e) {
Slog.e(TAG, "Unable to get HealthInterface instance. Health service is not available.");
lineageHealthInterface = null;
}

mLineageHealthInterface = lineageHealthInterface;
}
}

Expand Down Expand Up @@ -484,6 +497,13 @@ private void update(android.hardware.health.HealthInfo info) {
synchronized (mLock) {
if (!mUpdatesStopped) {
mHealthInfo = info;
if (mLineageHealthInterface != null) {
int status = mLineageHealthInterface.getChargingControlStatus();
if (status != CHARGING_POLICY_DEFAULT) {
mHealthInfo.chargingState = status;
}
Slog.i(TAG, "[Lineage] Charging control status: " + status);
}
// Process the new values.
processValuesLocked(false);
mLock.notifyAll(); // for any waiters on new info
Expand Down

0 comments on commit 9a31d1a

Please sign in to comment.