Skip to content

Commit

Permalink
SystemUIGoogle: googlebattery: rework system feature check sequence
Browse files Browse the repository at this point in the history
* fix sepolicy denial and constant exception when receiving BATTERY_CHANGED broadcast on device without this feature
* Exception:
GoogleBatteryManager: failed to get Google Battery HAL:
GoogleBatteryManager: java.lang.SecurityException:
GoogleBatteryManager: 	at android.os.Parcel.createExceptionOrNull(Parcel.java:3011)
GoogleBatteryManager: 	at android.os.Parcel.createException(Parcel.java:2995)
GoogleBatteryManager: 	at android.os.Parcel.readException(Parcel.java:2978)
GoogleBatteryManager: 	at android.os.Parcel.readException(Parcel.java:2920)
GoogleBatteryManager: 	at android.os.IServiceManager$Stub$Proxy.isDeclared(IServiceManager.java:520)
GoogleBatteryManager: 	at android.os.ServiceManagerProxy.isDeclared(ServiceManagerNative.java:90)
GoogleBatteryManager: 	at android.os.ServiceManager.isDeclared(ServiceManager.java:247)
GoogleBatteryManager: 	at android.os.ServiceManager.waitForDeclaredService(ServiceManager.java:297)
GoogleBatteryManager: 	at com.google.android.systemui.googlebattery.GoogleBatteryManager.initHalInterface(GoogleBatteryManager.java:28)
GoogleBatteryManager: 	at com.google.android.systemui.googlebattery.AdaptiveChargingManager.queryStatus(AdaptiveChargingManager.java:143)
GoogleBatteryManager: 	at com.google.android.systemui.power.AdaptiveChargingNotification.lambda$checkAdaptiveChargingStatus$0(AdaptiveChargingNotification.java:104)
GoogleBatteryManager: 	at com.google.android.systemui.power.AdaptiveChargingNotification.$r8$lambda$JmlmfVOFzK18KL-iPJE4G9mC2vI(Unknown Source:0)
GoogleBatteryManager: 	at com.google.android.systemui.power.AdaptiveChargingNotification$$ExternalSyntheticLambda0.run(Unknown Source:4)
GoogleBatteryManager: 	at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305)
GoogleBatteryManager: 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
GoogleBatteryManager: 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
GoogleBatteryManager: 	at java.lang.Thread.run(Thread.java:1012)
* Denial:
SELinux : avc:  denied  { find } for pid=1783 uid=10149 name=vendor.google.google_battery.IGoogleBattery/default scontext=u:r:platform_app:s0:c512,c768 tcontext=u:object_r:default_android_service:s0 tclass=service_manager permissive=0

Change-Id: I36a076fa16fbb46ced8ff36466fea3fb4c2b360f
(cherry picked from commit 92753ed1b4b070312e0b72782872e567afd5167d)
  • Loading branch information
Alcatraz323 authored and basamaryan committed Sep 19, 2023
1 parent bf2e59a commit b2ee175
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Expand Up @@ -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 {
Expand All @@ -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() {
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down
Expand Up @@ -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) {
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit b2ee175

Please sign in to comment.