diff --git a/SystemUIGoogle/src/com/google/android/systemui/googlebattery/AdaptiveChargingManager.java b/SystemUIGoogle/src/com/google/android/systemui/googlebattery/AdaptiveChargingManager.java index bbc471c..3bd7d96 100644 --- a/SystemUIGoogle/src/com/google/android/systemui/googlebattery/AdaptiveChargingManager.java +++ b/SystemUIGoogle/src/com/google/android/systemui/googlebattery/AdaptiveChargingManager.java @@ -40,9 +40,11 @@ public class AdaptiveChargingManager { private static final String TAG = "AdaptiveChargingManager"; private Context mContext; + private boolean mHasSystemFeature = false; public AdaptiveChargingManager(Context context) { mContext = context; + mHasSystemFeature = mContext.getPackageManager().hasSystemFeature("com.google.android.feature.ADAPTIVE_CHARGING"); } public interface AdaptiveChargingStatusReceiver { @@ -61,8 +63,7 @@ public String formatTimeToFull(long j) { } public boolean hasAdaptiveChargingFeature() { - return mContext.getPackageManager().hasSystemFeature("com.google.android.feature.ADAPTIVE_CHARGING") - && isGoogleBatteryServiceAvailable(); + return mHasSystemFeature ? isGoogleBatteryServiceAvailable() : false; } private boolean isGoogleBatteryServiceAvailable() { @@ -115,7 +116,10 @@ public final void binderDied() { } } }; - IGoogleBattery initHalInterface = GoogleBatteryManager.initHalInterface(deathRecipient); + IGoogleBattery initHalInterface = null; + if(mHasSystemFeature) { + initHalInterface = GoogleBatteryManager.initHalInterface(deathRecipient); + } if (initHalInterface == null) { return false; } @@ -140,7 +144,10 @@ public final void binderDied() { adaptiveChargingStatusReceiver.onDestroyInterface(); } }; - IGoogleBattery initHalInterface = GoogleBatteryManager.initHalInterface(deathRecipient); + IGoogleBattery initHalInterface = null; + if(mHasSystemFeature) { + initHalInterface = GoogleBatteryManager.initHalInterface(deathRecipient); + } if (initHalInterface == null) { adaptiveChargingStatusReceiver.onDestroyInterface(); return; diff --git a/SystemUIGoogle/src/com/google/android/systemui/power/BatteryDefenderNotification.java b/SystemUIGoogle/src/com/google/android/systemui/power/BatteryDefenderNotification.java index ad8b1db..6ace6eb 100644 --- a/SystemUIGoogle/src/com/google/android/systemui/power/BatteryDefenderNotification.java +++ b/SystemUIGoogle/src/com/google/android/systemui/power/BatteryDefenderNotification.java @@ -58,11 +58,13 @@ class BatteryDefenderNotification { boolean mRunBypassActionTask = true; private int mBatteryLevel; private SharedPreferences mSharedPreferences; + private boolean mHasSystemFeature = false; BatteryDefenderNotification(Context context, UiEventLogger uiEventLogger) { mContext = context; mUiEventLogger = uiEventLogger; mNotificationManager = context.getSystemService(NotificationManager.class); + mHasSystemFeature = mContext.getPackageManager().hasSystemFeature("com.google.android.feature.ADAPTIVE_CHARGING"); } void dispatchIntent(Intent intent) { @@ -166,6 +168,10 @@ public final void binderDied() { Log.d(TAG, "serviceDied"); } }; + if(!mHasSystemFeature) { + Log.d(TAG, "Device does not support Google Battery"); + return; + } IGoogleBattery initHalInterface = initHalInterface(cbRecipient); if (initHalInterface == null) { Log.d(TAG, "Can not init hal interface");