Skip to content

Commit

Permalink
SystemUIGoogle: AdaptiveChargingManager: Add google-hal checks and re…
Browse files Browse the repository at this point in the history
…solve possible regression

Change-Id: I74fb31b8932d770f01804fcc0a4525f1e1890c19
Signed-off-by: minaripenguin <minaripenguin@users.noreply.github.com>
  • Loading branch information
minaripenguin authored and basamaryan committed Jul 30, 2023
1 parent c27a93d commit 6313b7c
Showing 1 changed file with 20 additions and 10 deletions.
Expand Up @@ -62,7 +62,17 @@ public String formatTimeToFull(long j) {
}

public boolean hasAdaptiveChargingFeature() {
return mContext.getPackageManager().hasSystemFeature("com.google.android.feature.ADAPTIVE_CHARGING");
return mContext.getPackageManager().hasSystemFeature("com.google.android.feature.ADAPTIVE_CHARGING")
&& isGoogleBatteryServiceAvailable();
}

private boolean isGoogleBatteryServiceAvailable() {
try {
IBinder binder = ServiceManager.getService("vendor.google.google_battery.IGoogleBattery");
return binder != null;
} catch (SecurityException e) {
return false;
}
}

public boolean isAvailable() {
Expand Down Expand Up @@ -115,14 +125,14 @@ public boolean setAdaptiveChargingDeadline(int secondsFromNow) {

public void queryStatus(final AdaptiveChargingStatusReceiver adaptiveChargingStatusReceiver) {
IBinder.DeathRecipient deathRecipient = new IBinder.DeathRecipient() {
@Override
public final void binderDied() {
if (DEBUG) {
Log.d("AdaptiveChargingManager", "serviceDied");
}
adaptiveChargingStatusReceiver.onDestroyInterface();
@Override
public final void binderDied() {
if (DEBUG) {
Log.d("AdaptiveChargingManager", "serviceDied");
}
};
adaptiveChargingStatusReceiver.onDestroyInterface();
}
};
IGoogleBattery googBatteryIntf = initHalInterface(deathRecipient);
if (googBatteryIntf == null) {
adaptiveChargingStatusReceiver.onDestroyInterface();
Expand Down Expand Up @@ -152,7 +162,7 @@ private static IGoogleBattery initHalInterface(IBinder.DeathRecipient deathRecei
Log.d("AdaptiveChargingManager", "initHalInterface");
}
try {
IBinder binder = Binder.allowBlocking(ServiceManager.waitForDeclaredService("vendor.google.google_battery.IGoogleBattery/default"));
IBinder binder = ServiceManager.getService("vendor.google.google_battery.IGoogleBattery");
IGoogleBattery batteryInterface = null;
if (binder != null) {
batteryInterface = IGoogleBattery.Stub.asInterface(binder);
Expand All @@ -162,7 +172,7 @@ private static IGoogleBattery initHalInterface(IBinder.DeathRecipient deathRecei
}
return batteryInterface;
} catch (RemoteException | NoSuchElementException | SecurityException e) {
Log.e("AdaptiveChargingManager", "failed to get Google Battery HAL: ", e);
Log.e("AdaptiveChargingManager", "Failed to get Google Battery HAL: ", e);
return null;
}
}
Expand Down

0 comments on commit 6313b7c

Please sign in to comment.