health: Catch all setCharging*() exceptions

Technically, this should be fixed device side, but random failure when
HAL side fails shouldn't crash the system either.

Fixes: https://gitlab.com/LineageOS/issues/android/-/issues/8391
Change-Id: Iedd869cbd74e4a5535655c977b8ead74e8d5868d
This commit is contained in:
LuK1337
2025-02-24 21:19:43 +01:00
parent a5c37aced7
commit e395199695
2 changed files with 4 additions and 11 deletions

View File

@@ -11,7 +11,6 @@ import static lineageos.health.HealthInterface.MODE_MANUAL;
import static org.lineageos.platform.internal.health.Util.msToString;
import android.content.Context;
import android.os.RemoteException;
import android.util.Log;
import vendor.lineage.health.ChargingControlSupportedMode;
@@ -41,14 +40,9 @@ public class Deadline extends ChargingControlProvider {
try {
mChargingControl.setChargingDeadline(deadline);
mSavedTargetTime = targetTime;
} catch (RemoteException e) {
} catch (Exception e) {
Log.e(TAG, "Failed to set charging deadline", e);
return false;
} catch (IllegalStateException e) {
// This is possible when the device is just plugged in and the sysfs node is not ready
// to be written to
Log.e(TAG, "Failed to set charging deadline, will retry on next battery change");
return false;
}
return true;
@@ -70,7 +64,7 @@ public class Deadline extends ChargingControlProvider {
try {
mChargingControl.setChargingDeadline(-1);
} catch (RemoteException e) {
} catch (Exception e) {
Log.e(TAG, "Failed to reset charging deadline", e);
}
}

View File

@@ -18,7 +18,6 @@ import android.content.IntentFilter;
import android.os.BatteryManager;
import android.os.BatteryStatsManager;
import android.os.BatteryUsageStats;
import android.os.RemoteException;
import android.util.Log;
import org.lineageos.platform.internal.R;
@@ -205,7 +204,7 @@ public class Toggle extends ChargingControlProvider {
mChargingControl.setChargingEnabled(enabled);
}
return true;
} catch (RemoteException e) {
} catch (Exception e) {
Log.e(TAG, "Failed to set charging enabled", e);
return false;
}
@@ -229,7 +228,7 @@ public class Toggle extends ChargingControlProvider {
mSavedTargetTime = 0;
mEstimatedFullTime = 0;
mStage = chgCtrlStage.STAGE_NONE;
} catch (RemoteException e) {
} catch (Exception e) {
Log.e(TAG, "Failed to set charging enabled", e);
}
}