Merge "Update nullability of extension versions in Rollback." into rvc-dev
This commit is contained in:
@@ -59,6 +59,7 @@ import java.text.ParseException;
|
|||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -182,7 +183,7 @@ class Rollback {
|
|||||||
/**
|
/**
|
||||||
* The extension versions supported at the time of rollback creation.
|
* 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.
|
* Constructs a new, empty Rollback instance.
|
||||||
@@ -210,7 +211,7 @@ class Rollback {
|
|||||||
mState = ROLLBACK_STATE_ENABLING;
|
mState = ROLLBACK_STATE_ENABLING;
|
||||||
mTimestamp = Instant.now();
|
mTimestamp = Instant.now();
|
||||||
mPackageSessionIds = packageSessionIds != null ? packageSessionIds : new int[0];
|
mPackageSessionIds = packageSessionIds != null ? packageSessionIds : new int[0];
|
||||||
mExtensionVersions = extensionVersions;
|
mExtensionVersions = Objects.requireNonNull(extensionVersions);
|
||||||
}
|
}
|
||||||
|
|
||||||
Rollback(int rollbackId, File backupDir, int stagedSessionId, int userId,
|
Rollback(int rollbackId, File backupDir, int stagedSessionId, int userId,
|
||||||
@@ -234,7 +235,7 @@ class Rollback {
|
|||||||
mState = state;
|
mState = state;
|
||||||
mApkSessionId = apkSessionId;
|
mApkSessionId = apkSessionId;
|
||||||
mRestoreUserDataInProgress = restoreUserDataInProgress;
|
mRestoreUserDataInProgress = restoreUserDataInProgress;
|
||||||
mExtensionVersions = extensionVersions;
|
mExtensionVersions = Objects.requireNonNull(extensionVersions);
|
||||||
// TODO(b/120200473): Include this field during persistence. This field will be used to
|
// 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
|
// 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
|
// this field is not backward compatible. We won't fix b/120200473 until S to minimize the
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import static android.os.UserHandle.USER_SYSTEM;
|
|||||||
import static com.android.server.rollback.Rollback.rollbackStateFromString;
|
import static com.android.server.rollback.Rollback.rollbackStateFromString;
|
||||||
|
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.VersionedPackage;
|
import android.content.pm.VersionedPackage;
|
||||||
import android.content.rollback.PackageRollbackInfo;
|
import android.content.rollback.PackageRollbackInfo;
|
||||||
@@ -178,7 +177,7 @@ class RollbackStore {
|
|||||||
return ceSnapshotInodes;
|
return ceSnapshotInodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static @Nullable JSONArray extensionVersionsToJson(
|
private static @NonNull JSONArray extensionVersionsToJson(
|
||||||
SparseIntArray extensionVersions) throws JSONException {
|
SparseIntArray extensionVersions) throws JSONException {
|
||||||
JSONArray array = new JSONArray();
|
JSONArray array = new JSONArray();
|
||||||
for (int i = 0; i < extensionVersions.size(); i++) {
|
for (int i = 0; i < extensionVersions.size(); i++) {
|
||||||
@@ -190,7 +189,7 @@ class RollbackStore {
|
|||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static @Nullable SparseIntArray extensionVersionsFromJson(JSONArray json)
|
private static @NonNull SparseIntArray extensionVersionsFromJson(JSONArray json)
|
||||||
throws JSONException {
|
throws JSONException {
|
||||||
if (json == null) {
|
if (json == null) {
|
||||||
return new SparseIntArray(0);
|
return new SparseIntArray(0);
|
||||||
|
|||||||
@@ -331,7 +331,7 @@ public class RollbackUnitTest {
|
|||||||
public void notifySessionWithSuccess() {
|
public void notifySessionWithSuccess() {
|
||||||
int[] sessionIds = new int[]{ 7777, 8888 };
|
int[] sessionIds = new int[]{ 7777, 8888 };
|
||||||
Rollback rollback = new Rollback(123, new File("/test/testing"), -1, USER, INSTALLER,
|
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.
|
// The 1st invocation returns false because not all child sessions are notified.
|
||||||
assertThat(rollback.notifySessionWithSuccess()).isFalse();
|
assertThat(rollback.notifySessionWithSuccess()).isFalse();
|
||||||
// The 2nd invocation returns true because now all child sessions are notified.
|
// The 2nd invocation returns true because now all child sessions are notified.
|
||||||
@@ -342,7 +342,7 @@ public class RollbackUnitTest {
|
|||||||
public void allPackagesEnabled() {
|
public void allPackagesEnabled() {
|
||||||
int[] sessionIds = new int[]{ 7777, 8888 };
|
int[] sessionIds = new int[]{ 7777, 8888 };
|
||||||
Rollback rollback = new Rollback(123, new File("/test/testing"), -1, USER, INSTALLER,
|
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.
|
// #allPackagesEnabled returns false when 1 out of 2 packages is enabled.
|
||||||
rollback.info.getPackages().add(newPkgInfoFor(PKG_1, 12, 10, false));
|
rollback.info.getPackages().add(newPkgInfoFor(PKG_1, 12, 10, false));
|
||||||
assertThat(rollback.allPackagesEnabled()).isFalse();
|
assertThat(rollback.allPackagesEnabled()).isFalse();
|
||||||
|
|||||||
Reference in New Issue
Block a user