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

Commit ff146155 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add metrics for post install" into main

parents 2f932434 46608d9f
Loading
Loading
Loading
Loading
+36 −32
Original line number Original line Diff line number Diff line
@@ -856,7 +856,9 @@ final class InstallPackageHelper {
        if (DEBUG_INSTALL) Log.v(TAG, "+ starting restore round-trip " + token);
        if (DEBUG_INSTALL) Log.v(TAG, "+ starting restore round-trip " + token);


        final boolean succeeded = request.getReturnCode() == PackageManager.INSTALL_SUCCEEDED;
        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
                // Pass responsibility to the Backup Manager.  It will perform a
                // restore if appropriate, then pass responsibility back to the
                // restore if appropriate, then pass responsibility back to the
                // Package Manager to run the post-install observer callbacks
                // 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.
            // need to be snapshotted or restored for the package.
            //
            //
            // TODO(narayan): Get this working for cases where userId == UserHandle.USER_ALL.
            // TODO(narayan): Get this working for cases where userId == UserHandle.USER_ALL.
        if (succeeded && !doRestore && update) {
            if (!doRestore && update) {
                doRestore = performRollbackManagerRestore(userId, token, request);
                doRestore = performRollbackManagerRestore(userId, token, request);
            }
            }


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


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


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