Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit e3951996 authored by LuK1337's avatar LuK1337
Browse files

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
parent a5c37ace
Loading
Loading
Loading
Loading
+2 −8
Original line number Diff line number Diff line
@@ -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);
        }
    }
+2 −3
Original line number Diff line number Diff line
@@ -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);
        }
    }