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

Commit 0c5993fa authored by beatricemarch's avatar beatricemarch Committed by Beatrice Marchegiani
Browse files

Implement the ability to log extras relating to version mismatches between...

Implement the ability to log extras relating to version mismatches between packages on the source and target.
Imporve readability of events in dumpsys.

Test: manual, do restore on test device, verify that the correct events
are printed in the dumpsys
atest CtsBackupHostTestCases, GtsBackupHostTestCases
atest BackupManagerMonitorDumpsysUtilsTest
Bug: 296818666

Change-Id: Ifd2d68861fcd33637c49f0e7802c456e43ffd9a2
parent 3f8ff834
Loading
Loading
Loading
Loading
+43 −13
Original line number Diff line number Diff line
@@ -84,8 +84,8 @@ public class BackupManagerMonitorDumpsysUtils {
     * - Agent logs (if available)
     *
     * Example of formatting:
     * RESTORE Event: [2023-08-18 17:16:00.735] Agent - Agent logging results
     * Package name: com.android.wallpaperbackup
     * [2023-09-21 14:43:33.824] - Agent logging results
     *   Package: com.android.wallpaperbackup
     *   Agent Logs:
     *           Data Type: wlp_img_system
     *                   Item restored: 0/1
@@ -139,17 +139,16 @@ public class BackupManagerMonitorDumpsysUtils {
                return;
            }

            pw.println("RESTORE Event: [" + timestamp() + "] " +
                    getCategory(eventCategory) + " - " +
                    getId(eventId));
            pw.println("[" + timestamp() + "] - " + getId(eventId));

            if (eventBundle.containsKey(BackupManagerMonitor.EXTRA_LOG_EVENT_PACKAGE_NAME)) {
                pw.println("\tPackage name: "
                pw.println("\tPackage: "
                        + eventBundle.getString(BackupManagerMonitor.EXTRA_LOG_EVENT_PACKAGE_NAME));
            }

            // TODO(b/296818666): add extras to the events
            addAgentLogsIfAvailable(eventBundle, pw);
            addExtrasIfAvailable(eventBundle, pw);
        } catch (java.io.IOException e) {
            Slog.e(TAG, "IO Exception when writing BMM events to file: " + e);
        }
@@ -194,6 +193,37 @@ public class BackupManagerMonitorDumpsysUtils {
        }
    }

    /**
     * Extracts some extras (defined in BackupManagerMonitor as EXTRA_LOG_<description>)
     * from the BackupManagerMonitor event. Not all extras have the same importance. For now only
     * focus on extras relating to version mismatches between packages on the source and target.
     *
     * When an event with ID LOG_EVENT_ID_RESTORE_VERSION_HIGHER (trying to restore from higher to
     * lower version of a package) parse:
     * EXTRA_LOG_RESTORE_VERSION [int]: the version of the package on the source
     * EXTRA_LOG_RESTORE_ANYWAY [bool]: if the package allows restore any version
     * EXTRA_LOG_RESTORE_VERSION_TARGET [int]: an extra to record the package version on the target
     */
    private void addExtrasIfAvailable(Bundle eventBundle, PrintWriter pw) {
        if (eventBundle.getInt(BackupManagerMonitor.EXTRA_LOG_EVENT_ID) ==
                BackupManagerMonitor.LOG_EVENT_ID_RESTORE_VERSION_HIGHER) {
            if (eventBundle.containsKey(BackupManagerMonitor.EXTRA_LOG_RESTORE_ANYWAY)) {
                pw.println("\t\tPackage supports RestoreAnyVersion: "
                        + eventBundle.getBoolean(BackupManagerMonitor.EXTRA_LOG_RESTORE_ANYWAY));
            }
            if (eventBundle.containsKey(BackupManagerMonitor.EXTRA_LOG_RESTORE_VERSION)) {
                pw.println("\t\tPackage version on source: "
                        + eventBundle.getLong(BackupManagerMonitor.EXTRA_LOG_RESTORE_VERSION));
            }
            if (eventBundle.containsKey(
                      BackupManagerMonitor.EXTRA_LOG_EVENT_PACKAGE_LONG_VERSION)) {
                pw.println("\t\tPackage version on target: "
                        + eventBundle.getLong(
                        BackupManagerMonitor.EXTRA_LOG_EVENT_PACKAGE_LONG_VERSION));
            }
        }
    }

    /*
     * Get the path of the text files which stores the BMM events
     */