diff --git a/SystemUIGoogle/src/com/google/android/systemui/googlebattery/AdaptiveChargingManager.java b/SystemUIGoogle/src/com/google/android/systemui/googlebattery/AdaptiveChargingManager.java index c99c3d4..8146c2e 100644 --- a/SystemUIGoogle/src/com/google/android/systemui/googlebattery/AdaptiveChargingManager.java +++ b/SystemUIGoogle/src/com/google/android/systemui/googlebattery/AdaptiveChargingManager.java @@ -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() { @@ -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(); @@ -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); @@ -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; } }