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

Commit 46608d9f authored by TYM Tsai's avatar TYM Tsai
Browse files

Add metrics for post install

Bug: 388132224
FLAG: EXEMPT add metrics
Test: atest CtsPackageInstallTestCases
Test: run statsd_testdrive and check output: install_steps: 7
Change-Id: If0ba8f407434e1ddce66350a9147d0d220ae9046
parent 0c6506a4
Loading
Loading
Loading
Loading
+36 −32
Original line number Diff line number Diff line
@@ -856,7 +856,9 @@ final class InstallPackageHelper {
        if (DEBUG_INSTALL) Log.v(TAG, "+ starting restore round-trip " + token);

        final boolean succeeded = request.getReturnCode() == PackageManager.INSTALL_SUCCEEDED;
        if (succeeded && doRestore) {
        if (succeeded) {
            request.onRestoreStarted();
            if (doRestore) {
                // Pass responsibility to the Backup Manager.  It will perform a
                // restore if appropriate, then pass responsibility back to the
                // Package Manager to run the post-install observer callbacks
@@ -869,17 +871,18 @@ final class InstallPackageHelper {
            // need to be snapshotted or restored for the package.
            //
            // TODO(narayan): Get this working for cases where userId == UserHandle.USER_ALL.
        if (succeeded && !doRestore && update) {
            if (!doRestore && update) {
                doRestore = performRollbackManagerRestore(userId, token, request);
            }

        if (succeeded && doRestore && !request.hasPostInstallRunnable()) {
            if (doRestore && !request.hasPostInstallRunnable()) {
                boolean hasNeverBeenRestored =
                        packageSetting != null && packageSetting.isPendingRestore();
                request.setPostInstallRunnable(() -> {
                // Permissions should be restored on each user that has the app installed for the
                // first time, unless it's an unarchive install for an archived app, in which case
                // the permissions should be restored on each user that has the app updated.
                    // Permissions should be restored on each user that has the app installed for
                    // the first time, unless it's an unarchive install for an archived app, in
                    // which case the permissions should be restored on each user that has the
                    // app updated.
                    int[] userIdsToRestorePermissions = hasNeverBeenRestored
                            ? request.getUpdateBroadcastUserIds()
                            : request.getFirstTimeBroadcastUserIds();
@@ -889,6 +892,7 @@ final class InstallPackageHelper {
                    }
                });
            }
        }

        if (doRestore) {
            if (packageSetting != null) {
+12 −0
Original line number Diff line number Diff line
@@ -1016,6 +1016,18 @@ final class InstallRequest {
        }
    }

    public void onRestoreStarted() {
        if (mPackageMetrics != null) {
            mPackageMetrics.onStepStarted(PackageMetrics.STEP_RESTORE);
        }
    }

    public void onRestoreFinished() {
        if (mPackageMetrics != null) {
            mPackageMetrics.onStepFinished(PackageMetrics.STEP_RESTORE);
        }
    }

    public void onDexoptFinished(DexoptResult dexoptResult) {
        // Only report external profile warnings when installing from adb. The goal is to warn app
        // developers if they have provided bad external profiles, so it's not beneficial to report
+1 −0
Original line number Diff line number Diff line
@@ -99,6 +99,7 @@ final class PackageHandler extends Handler {
                    }
                    break;
                }
                request.onRestoreFinished();
                request.closeFreezer();
                request.onInstallCompleted();
                request.runPostInstallRunnable();
+3 −1
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ final class PackageMetrics {
    public static final int STEP_COMMIT = 4;
    public static final int STEP_DEXOPT = 5;
    public static final int STEP_FREEZE_INSTALL = 6;
    public static final int STEP_RESTORE = 7;

    @IntDef(prefix = {"STEP_"}, value = {
            STEP_PREPARE,
@@ -79,7 +80,8 @@ final class PackageMetrics {
            STEP_RECONCILE,
            STEP_COMMIT,
            STEP_DEXOPT,
            STEP_FREEZE_INSTALL
            STEP_FREEZE_INSTALL,
            STEP_RESTORE
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface StepInt {