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

Commit b0336518 authored by Oli Lan's avatar Oli Lan
Browse files

Update nullability of extension versions in Rollback.

This updates nullability annotations in Rollback and RollbackStore as
suggested in comments on ag/11256434.

Bug: 152737927
Test: atest RollbackUnitTest
Test: atest RollbackTest
Test: atest RollbackStoreTest
Change-Id: Ib0973378fdd24ce275b0f3e1a687f9161d3c0e7d
parent 266fba16
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ import java.text.ParseException;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;


/**
@@ -182,7 +183,7 @@ class Rollback {
    /**
     * The extension versions supported at the time of rollback creation.
     */
    private final SparseIntArray mExtensionVersions;
    @NonNull private final SparseIntArray mExtensionVersions;

    /**
     * Constructs a new, empty Rollback instance.
@@ -210,7 +211,7 @@ class Rollback {
        mState = ROLLBACK_STATE_ENABLING;
        mTimestamp = Instant.now();
        mPackageSessionIds = packageSessionIds != null ? packageSessionIds : new int[0];
        mExtensionVersions = extensionVersions;
        mExtensionVersions = Objects.requireNonNull(extensionVersions);
    }

    Rollback(int rollbackId, File backupDir, int stagedSessionId, int userId,
@@ -234,7 +235,7 @@ class Rollback {
        mState = state;
        mApkSessionId = apkSessionId;
        mRestoreUserDataInProgress = restoreUserDataInProgress;
        mExtensionVersions = extensionVersions;
        mExtensionVersions = Objects.requireNonNull(extensionVersions);
        // TODO(b/120200473): Include this field during persistence. This field will be used to
        // decide which rollback to expire when ACTION_PACKAGE_REPLACED is received. Note persisting
        // this field is not backward compatible. We won't fix b/120200473 until S to minimize the
+2 −3
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import static android.os.UserHandle.USER_SYSTEM;
import static com.android.server.rollback.Rollback.rollbackStateFromString;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.pm.PackageManager;
import android.content.pm.VersionedPackage;
import android.content.rollback.PackageRollbackInfo;
@@ -178,7 +177,7 @@ class RollbackStore {
        return ceSnapshotInodes;
    }

    private static @Nullable JSONArray extensionVersionsToJson(
    private static @NonNull JSONArray extensionVersionsToJson(
            SparseIntArray extensionVersions) throws JSONException {
        JSONArray array = new JSONArray();
        for (int i = 0; i < extensionVersions.size(); i++) {
@@ -190,7 +189,7 @@ class RollbackStore {
        return array;
    }

    private static @Nullable SparseIntArray extensionVersionsFromJson(JSONArray json)
    private static @NonNull SparseIntArray extensionVersionsFromJson(JSONArray json)
            throws JSONException {
        if (json == null) {
            return new SparseIntArray(0);
+2 −2
Original line number Diff line number Diff line
@@ -331,7 +331,7 @@ public class RollbackUnitTest {
    public void notifySessionWithSuccess() {
        int[] sessionIds = new int[]{ 7777, 8888 };
        Rollback rollback = new Rollback(123, new File("/test/testing"), -1, USER, INSTALLER,
                sessionIds, null);
                sessionIds, new SparseIntArray(0));
        // The 1st invocation returns false because not all child sessions are notified.
        assertThat(rollback.notifySessionWithSuccess()).isFalse();
        // The 2nd invocation returns true because now all child sessions are notified.
@@ -342,7 +342,7 @@ public class RollbackUnitTest {
    public void allPackagesEnabled() {
        int[] sessionIds = new int[]{ 7777, 8888 };
        Rollback rollback = new Rollback(123, new File("/test/testing"), -1, USER, INSTALLER,
                sessionIds, null);
                sessionIds, new SparseIntArray(0));
        // #allPackagesEnabled returns false when 1 out of 2 packages is enabled.
        rollback.info.getPackages().add(newPkgInfoFor(PKG_1, 12, 10, false));
        assertThat(rollback.allPackagesEnabled()).isFalse();