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

Commit d2f50759 authored by Mohammad Samiul Islam's avatar Mohammad Samiul Islam
Browse files

Store the correct rollback id for logging on boot complete

Previously, RPHO expected there can be only one train staged for
installation. Hence, it expected there can be only one rollback
committed at any time. As such, it only saved the latest comitted
rollbackId and on boot complete, used that rollbackId to extract
ModuleMetadata package and log.

Now that we allow multiple staged installation and on native crash
during boot we commit more than one rollback, we cannot blindly store
the latest rollbackId for logging. The logging is only meaningful for
mainline trains, that is, when when we are rolling back a train that
contains ModuleMetaData.

In this CL, instead of storing the latest comitted rollback id, we store
the rollbackId of train that contains a valid logPackage, i.e,
ModuleMetaData package.

Bug: 141843321
Test: atest StagedRollbackTest
Change-Id: I94a3330c8abbc9470f4a698c3333c55a044cbd10
parent 2f9fa5c9
Loading
Loading
Loading
Loading
+18 −14
Original line number Diff line number Diff line
@@ -179,10 +179,10 @@ public final class RollbackPackageHealthObserver implements PackageHealthObserve

        // Use the version of the metadata package that was installed before
        // we rolled back for logging purposes.
        VersionedPackage oldModuleMetadataPackage = null;
        VersionedPackage oldLogPackage = null;
        for (PackageRollbackInfo packageRollback : rollback.getPackages()) {
            if (packageRollback.getPackageName().equals(moduleMetadataPackageName)) {
                oldModuleMetadataPackage = packageRollback.getVersionRolledBackFrom();
                oldLogPackage = packageRollback.getVersionRolledBackFrom();
                break;
            }
        }
@@ -194,13 +194,13 @@ public final class RollbackPackageHealthObserver implements PackageHealthObserve
            return;
        }
        if (sessionInfo.isStagedSessionApplied()) {
            logEvent(oldModuleMetadataPackage,
            logEvent(oldLogPackage,
                    StatsLog.WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_TYPE__ROLLBACK_SUCCESS,
                    WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_REASON__REASON_UNKNOWN, "");
        } else if (sessionInfo.isStagedSessionReady()) {
            // TODO: What do for staged session ready but not applied
        } else {
            logEvent(oldModuleMetadataPackage,
            logEvent(oldLogPackage,
                    StatsLog.WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_TYPE__ROLLBACK_FAILURE,
                    WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_REASON__REASON_UNKNOWN, "");
        }
@@ -245,12 +245,12 @@ public final class RollbackPackageHealthObserver implements PackageHealthObserve
    }

    private BroadcastReceiver listenForStagedSessionReady(RollbackManager rollbackManager,
            int rollbackId, @Nullable VersionedPackage moduleMetadataPackage) {
            int rollbackId, @Nullable VersionedPackage logPackage) {
        BroadcastReceiver sessionUpdatedReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                handleStagedSessionChange(rollbackManager,
                        rollbackId, this /* BroadcastReceiver */, moduleMetadataPackage);
                        rollbackId, this /* BroadcastReceiver */, logPackage);
            }
        };
        IntentFilter sessionUpdatedFilter =
@@ -260,7 +260,7 @@ public final class RollbackPackageHealthObserver implements PackageHealthObserve
    }

    private void handleStagedSessionChange(RollbackManager rollbackManager, int rollbackId,
            BroadcastReceiver listener, @Nullable VersionedPackage moduleMetadataPackage) {
            BroadcastReceiver listener, @Nullable VersionedPackage logPackage) {
        PackageInstaller packageInstaller =
                mContext.getPackageManager().getPackageInstaller();
        List<RollbackInfo> recentRollbacks =
@@ -274,15 +274,19 @@ public final class RollbackPackageHealthObserver implements PackageHealthObserve
                        packageInstaller.getSessionInfo(sessionId);
                if (sessionInfo.isStagedSessionReady() && markStagedSessionHandled(rollbackId)) {
                    mContext.unregisterReceiver(listener);
                    if (logPackage != null) {
                        // We save the rollback id so that after reboot, we can log if rollback was
                        // successful or not. If logPackage is null, then there is nothing to log.
                        saveLastStagedRollbackId(rollbackId);
                    logEvent(moduleMetadataPackage,
                    }
                    logEvent(logPackage,
                            StatsLog
                            .WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_TYPE__ROLLBACK_BOOT_TRIGGERED,
                            WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_REASON__REASON_UNKNOWN,
                            "");
                } else if (sessionInfo.isStagedSessionFailed()
                        && markStagedSessionHandled(rollbackId)) {
                    logEvent(moduleMetadataPackage,
                    logEvent(logPackage,
                            StatsLog.WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_TYPE__ROLLBACK_FAILURE,
                            WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_REASON__REASON_UNKNOWN,
                            "");
@@ -362,12 +366,12 @@ public final class RollbackPackageHealthObserver implements PackageHealthObserve
        }
    }

    private static void logEvent(@Nullable VersionedPackage moduleMetadataPackage, int type,
    private static void logEvent(@Nullable VersionedPackage logPackage, int type,
            int rollbackReason, @NonNull String failingPackageName) {
        Slog.i(TAG, "Watchdog event occurred of type: " + rollbackTypeToString(type));
        if (moduleMetadataPackage != null) {
            StatsLog.logWatchdogRollbackOccurred(type, moduleMetadataPackage.getPackageName(),
                    moduleMetadataPackage.getVersionCode(), rollbackReason, failingPackageName);
        if (logPackage != null) {
            StatsLog.logWatchdogRollbackOccurred(type, logPackage.getPackageName(),
                    logPackage.getVersionCode(), rollbackReason, failingPackageName);
        }
    }