Replace com.android.internal.util.Preconditions.checkNotNull with
java.util.Objects.requireNonNull Bug: 126528330 Test: Treehugger Change-Id: I920fce3eba271c8621861df6788e68abf3e5f7c4
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.android.server.backup.encryption;
|
||||
|
||||
import static com.android.internal.util.Preconditions.checkNotNull;
|
||||
import static com.android.internal.util.Preconditions.checkState;
|
||||
|
||||
import android.content.Context;
|
||||
@@ -29,6 +28,7 @@ import android.util.Slog;
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
|
||||
import java.security.KeyStoreException;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -88,8 +88,8 @@ public class CryptoSettings {
|
||||
}
|
||||
|
||||
private CryptoSettings(SharedPreferences sharedPreferences, Context context) {
|
||||
mSharedPreferences = checkNotNull(sharedPreferences);
|
||||
mContext = checkNotNull(context);
|
||||
mSharedPreferences = Objects.requireNonNull(sharedPreferences);
|
||||
mContext = Objects.requireNonNull(context);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package com.android.server.backup.encryption.chunking;
|
||||
|
||||
import static com.android.internal.util.Preconditions.checkArgument;
|
||||
import static com.android.internal.util.Preconditions.checkNotNull;
|
||||
import static com.android.internal.util.Preconditions.checkState;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
@@ -35,6 +34,7 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Writes batches of {@link EncryptedChunk} to a diff script, and generates the associated {@link
|
||||
@@ -174,7 +174,7 @@ public class BackupFileBuilder {
|
||||
* IllegalStateException}.
|
||||
*/
|
||||
public void finish(ChunksMetadataProto.ChunksMetadata metadata) throws IOException {
|
||||
checkNotNull(metadata, "Metadata cannot be null");
|
||||
Objects.requireNonNull(metadata, "Metadata cannot be null");
|
||||
|
||||
long startOfMetadata = mBackupWriter.getBytesWritten();
|
||||
mBackupWriter.writeBytes(ChunksMetadataProto.ChunksMetadata.toByteArray(metadata));
|
||||
@@ -190,7 +190,7 @@ public class BackupFileBuilder {
|
||||
*/
|
||||
private void writeChunkToFileAndListing(
|
||||
ChunkHash chunkHash, Map<ChunkHash, EncryptedChunk> newChunks) throws IOException {
|
||||
checkNotNull(chunkHash, "Hash cannot be null");
|
||||
Objects.requireNonNull(chunkHash, "Hash cannot be null");
|
||||
|
||||
if (mOldChunkListing.hasChunk(chunkHash)) {
|
||||
ChunkListingMap.Entry oldChunk = mOldChunkListing.getChunkEntry(chunkHash);
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package com.android.server.backup.encryption.chunking;
|
||||
|
||||
import static com.android.internal.util.Preconditions.checkNotNull;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AtomicFile;
|
||||
@@ -34,6 +32,7 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
@@ -75,7 +74,7 @@ public class ProtoStore<T extends MessageNano> {
|
||||
*/
|
||||
@VisibleForTesting
|
||||
ProtoStore(Class<T> clazz, File storeFolder) throws IOException {
|
||||
mClazz = checkNotNull(clazz);
|
||||
mClazz = Objects.requireNonNull(clazz);
|
||||
mStoreFolder = ensureDirectoryExistsOrThrow(storeFolder);
|
||||
}
|
||||
|
||||
@@ -118,7 +117,7 @@ public class ProtoStore<T extends MessageNano> {
|
||||
|
||||
/** Saves a proto to disk, associating it with the given package. */
|
||||
public void saveProto(String packageName, T proto) throws IOException {
|
||||
checkNotNull(proto);
|
||||
Objects.requireNonNull(proto);
|
||||
File file = getFileForPackage(packageName);
|
||||
|
||||
try (FileOutputStream os = new FileOutputStream(file)) {
|
||||
|
||||
@@ -16,10 +16,9 @@
|
||||
|
||||
package com.android.server.backup.encryption.chunking.cdc;
|
||||
|
||||
import static com.android.internal.util.Preconditions.checkNotNull;
|
||||
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
@@ -49,9 +48,9 @@ public final class Hkdf {
|
||||
* @throws InvalidKeyException If the salt can not be used as a valid key.
|
||||
*/
|
||||
static byte[] hkdf(byte[] masterKey, byte[] salt, byte[] data) throws InvalidKeyException {
|
||||
checkNotNull(masterKey, "HKDF requires master key to be set.");
|
||||
checkNotNull(salt, "HKDF requires a salt.");
|
||||
checkNotNull(data, "No data provided to HKDF.");
|
||||
Objects.requireNonNull(masterKey, "HKDF requires master key to be set.");
|
||||
Objects.requireNonNull(salt, "HKDF requires a salt.");
|
||||
Objects.requireNonNull(data, "No data provided to HKDF.");
|
||||
return hkdfSha256Expand(hkdfSha256Extract(masterKey, salt), data);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,14 +16,14 @@
|
||||
|
||||
package com.android.server.backup.encryption.keys;
|
||||
|
||||
import static com.android.internal.util.Preconditions.checkNotNull;
|
||||
|
||||
import android.annotation.IntDef;
|
||||
import android.content.Context;
|
||||
import android.security.keystore.recovery.InternalRecoveryServiceException;
|
||||
import android.security.keystore.recovery.RecoveryController;
|
||||
import android.util.Slog;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.crypto.SecretKey;
|
||||
|
||||
/**
|
||||
@@ -46,8 +46,8 @@ public class RecoverableKeyStoreSecondaryKey {
|
||||
* @param secretKey The key.
|
||||
*/
|
||||
public RecoverableKeyStoreSecondaryKey(String alias, SecretKey secretKey) {
|
||||
mAlias = checkNotNull(alias);
|
||||
mSecretKey = checkNotNull(secretKey);
|
||||
mAlias = Objects.requireNonNull(alias);
|
||||
mSecretKey = Objects.requireNonNull(secretKey);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package com.android.server.backup.encryption.kv;
|
||||
|
||||
import static com.android.internal.util.Preconditions.checkArgument;
|
||||
import static com.android.internal.util.Preconditions.checkNotNull;
|
||||
|
||||
import com.android.server.backup.encryption.chunk.ChunkHash;
|
||||
import com.android.server.backup.encryption.protos.nano.KeyValueListingProto;
|
||||
@@ -26,6 +25,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Builds a {@link KeyValueListingProto.KeyValueListing}, which is a nano proto and so has no
|
||||
@@ -37,7 +37,7 @@ public class KeyValueListingBuilder {
|
||||
/** Adds a new pair entry to the listing. */
|
||||
public KeyValueListingBuilder addPair(String key, ChunkHash hash) {
|
||||
checkArgument(key.length() != 0, "Key must have non-zero length");
|
||||
checkNotNull(hash, "Hash must not be null");
|
||||
Objects.requireNonNull(hash, "Hash must not be null");
|
||||
|
||||
KeyValueListingProto.KeyValueEntry entry = new KeyValueListingProto.KeyValueEntry();
|
||||
entry.key = key;
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.android.server.backup.encryption.tasks;
|
||||
|
||||
import static com.android.internal.util.Preconditions.checkNotNull;
|
||||
import static com.android.internal.util.Preconditions.checkState;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
@@ -34,6 +33,7 @@ import java.io.InputStream;
|
||||
import java.io.PipedInputStream;
|
||||
import java.io.PipedOutputStream;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@@ -67,12 +67,12 @@ public class EncryptedFullBackupDataProcessor implements FullBackupDataProcessor
|
||||
SecureRandom secureRandom,
|
||||
RecoverableKeyStoreSecondaryKey secondaryKey,
|
||||
String packageName) {
|
||||
mContext = checkNotNull(context);
|
||||
mExecutorService = checkNotNull(executorService);
|
||||
mCryptoBackupServer = checkNotNull(cryptoBackupServer);
|
||||
mSecureRandom = checkNotNull(secureRandom);
|
||||
mSecondaryKey = checkNotNull(secondaryKey);
|
||||
mPackageName = checkNotNull(packageName);
|
||||
mContext = Objects.requireNonNull(context);
|
||||
mExecutorService = Objects.requireNonNull(executorService);
|
||||
mCryptoBackupServer = Objects.requireNonNull(cryptoBackupServer);
|
||||
mSecureRandom = Objects.requireNonNull(secureRandom);
|
||||
mSecondaryKey = Objects.requireNonNull(secondaryKey);
|
||||
mPackageName = Objects.requireNonNull(packageName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,8 +18,6 @@ package com.android.server.backup.encryption.tasks;
|
||||
|
||||
import static android.os.Build.VERSION_CODES.P;
|
||||
|
||||
import static com.android.internal.util.Preconditions.checkNotNull;
|
||||
|
||||
import android.content.Context;
|
||||
import android.security.keystore.recovery.InternalRecoveryServiceException;
|
||||
import android.security.keystore.recovery.RecoveryController;
|
||||
@@ -42,6 +40,7 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.crypto.IllegalBlockSizeException;
|
||||
@@ -77,10 +76,10 @@ public class RotateSecondaryKeyTask {
|
||||
CryptoSettings cryptoSettings,
|
||||
RecoveryController recoveryController) {
|
||||
mContext = context;
|
||||
mSecondaryKeyManager = checkNotNull(secondaryKeyManager);
|
||||
mCryptoSettings = checkNotNull(cryptoSettings);
|
||||
mBackupServer = checkNotNull(backupServer);
|
||||
mRecoveryController = checkNotNull(recoveryController);
|
||||
mSecondaryKeyManager = Objects.requireNonNull(secondaryKeyManager);
|
||||
mCryptoSettings = Objects.requireNonNull(cryptoSettings);
|
||||
mBackupServer = Objects.requireNonNull(backupServer);
|
||||
mRecoveryController = Objects.requireNonNull(recoveryController);
|
||||
}
|
||||
|
||||
/** Runs the task. */
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.android.server.backup.encryption.keys.RecoverableKeyStoreSecondaryKey
|
||||
import com.android.server.backup.encryption.keys.RecoverableKeyStoreSecondaryKeyManager;
|
||||
|
||||
import java.security.UnrecoverableKeyException;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
@@ -41,8 +42,8 @@ public class StartSecondaryKeyRotationTask {
|
||||
public StartSecondaryKeyRotationTask(
|
||||
CryptoSettings cryptoSettings,
|
||||
RecoverableKeyStoreSecondaryKeyManager secondaryKeyManager) {
|
||||
mCryptoSettings = Preconditions.checkNotNull(cryptoSettings);
|
||||
mSecondaryKeyManager = Preconditions.checkNotNull(secondaryKeyManager);
|
||||
mCryptoSettings = Objects.requireNonNull(cryptoSettings);
|
||||
mSecondaryKeyManager = Objects.requireNonNull(secondaryKeyManager);
|
||||
}
|
||||
|
||||
/** Begin the key rotation */
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package com.android.server.backup.encryption.testing;
|
||||
|
||||
import static com.android.internal.util.Preconditions.checkArgument;
|
||||
import static com.android.internal.util.Preconditions.checkNotNull;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
@@ -29,6 +28,7 @@ import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Scanner;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -69,7 +69,7 @@ public class DiffScriptProcessor {
|
||||
checkArgument(input.exists(), "input file did not exist.");
|
||||
mInput = input;
|
||||
mInputLength = input.length();
|
||||
mOutput = checkNotNull(output);
|
||||
mOutput = Objects.requireNonNull(output);
|
||||
}
|
||||
|
||||
public void process(InputStream diffScript) throws IOException, MalformedDiffScriptException {
|
||||
|
||||
@@ -16,10 +16,9 @@
|
||||
|
||||
package com.android.server.testing.shadows;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Represents a key value pair in {@link ShadowBackupDataInput} and {@link ShadowBackupDataOutput}.
|
||||
@@ -34,7 +33,7 @@ public class DataEntity {
|
||||
* StandardCharsets#UTF_8}.
|
||||
*/
|
||||
public DataEntity(String key, String value) {
|
||||
this.mKey = checkNotNull(key);
|
||||
this.mKey = Objects.requireNonNull(key);
|
||||
this.mValue = value.getBytes(StandardCharsets.UTF_8);
|
||||
mSize = this.mValue.length;
|
||||
}
|
||||
@@ -44,7 +43,7 @@ public class DataEntity {
|
||||
* pair.
|
||||
*/
|
||||
public DataEntity(String key) {
|
||||
this.mKey = checkNotNull(key);
|
||||
this.mKey = Objects.requireNonNull(key);
|
||||
mSize = -1;
|
||||
mValue = null;
|
||||
}
|
||||
@@ -62,7 +61,7 @@ public class DataEntity {
|
||||
* @param size the length of the value in bytes
|
||||
*/
|
||||
public DataEntity(String key, byte[] data, int size) {
|
||||
this.mKey = checkNotNull(key);
|
||||
this.mKey = Objects.requireNonNull(key);
|
||||
this.mSize = size;
|
||||
mValue = new byte[size];
|
||||
for (int i = 0; i < size; i++) {
|
||||
|
||||
Reference in New Issue
Block a user