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

Commit 48cacba2 authored by Harshit Mahajan's avatar Harshit Mahajan
Browse files

Move few APIs out of CrashRecovery

We are moving following methods out of module as having them as SystemApi doesn't add much value.
1. isRecoveryTriggeredReboot: This would return true is reboot is triggered during recovery mitigations.
2. registerConnectivityModuleHealthListener: This is used in parallel to detect Connectivity errors. We will be moving away from this in future.

Bug: 338468233
Test: TH
Flag: EXEMPT refactor
Change-Id: I3fe132398b250d6e750a2da5f0438324f650a275
parent 4432c5d0
Loading
Loading
Loading
Loading
+26 −6
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.VersionedPackage;
import android.net.ConnectivityModuleConnector;
import android.sysprop.CrashRecoveryProperties;
import android.text.TextUtils;
import android.util.Slog;

@@ -35,7 +36,7 @@ import java.util.List;

/**
 * Provides helper methods for the CrashRecovery APEX
 *
 *  TODO: b/354112511 Add tests for this class when it is finalized.
 * @hide
 */
public final class CrashRecoveryHelper {
@@ -76,11 +77,13 @@ public final class CrashRecoveryHelper {
    }

    /**
     * Register health listeners for explicit package failures.
     * Currently only registering for Connectivity Module health.
     * @hide
     * Register health listeners for Connectivity packages health.
     *
     * TODO: b/354112511 Have an internal method to trigger a rollback by reporting high severity errors,
     * and rely on ActivityManager to inform the watchdog of severe network stack crashes
     * instead of having this listener in parallel.
     */
    public void registerConnectivityModuleHealthListener(@NonNull int failureReason) {
    public void registerConnectivityModuleHealthListener() {
        // register listener for ConnectivityModule
        mConnectivityModuleConnector.registerHealthListener(
                packageName -> {
@@ -90,7 +93,7 @@ public final class CrashRecoveryHelper {
                    return;
                }
                final List<VersionedPackage> pkgList = Collections.singletonList(pkg);
                PackageWatchdog.getInstance(mContext).onPackageFailure(pkgList, failureReason);
                PackageWatchdog.getInstance(mContext).onPackageFailure(pkgList,  PackageWatchdog.FAILURE_REASON_EXPLICIT_HEALTH_CHECK);
            });
    }

@@ -126,4 +129,21 @@ public final class CrashRecoveryHelper {
            return pm.getPackageInfo(packageName, PackageManager.MATCH_APEX);
        }
    }

    /**
     * Check if we're currently attempting to reboot for a factory reset. This method must
     * return true if RescueParty tries to reboot early during a boot loop, since the device
     * will not be fully booted at this time.
     */
    public static boolean isRecoveryTriggeredReboot() {
        return isFactoryResetPropertySet() || isRebootPropertySet();
    }

    static boolean isFactoryResetPropertySet() {
        return CrashRecoveryProperties.attemptingFactoryReset().orElse(false);
    }

    static boolean isRebootPropertySet() {
        return CrashRecoveryProperties.attemptingReboot().orElse(false);
    }
}