Replace com.android.internal.util.Preconditions.checkNotNull with
java.util.Objects.requireNonNull
Bug: 126528330
Test: Treehugger
Change-Id: Iaa2abbefc532965e257a68502ec60aadbe465ed2
diff --git a/core/java/android/content/ClipboardManager.java b/core/java/android/content/ClipboardManager.java
index dec9589..7f73238 100644
--- a/core/java/android/content/ClipboardManager.java
+++ b/core/java/android/content/ClipboardManager.java
@@ -25,9 +25,8 @@
import android.os.ServiceManager;
import android.os.ServiceManager.ServiceNotFoundException;
-import com.android.internal.util.Preconditions;
-
import java.util.ArrayList;
+import java.util.Objects;
/**
* Interface to the clipboard service, for placing and retrieving text in
@@ -101,7 +100,7 @@
*/
public void setPrimaryClip(@NonNull ClipData clip) {
try {
- Preconditions.checkNotNull(clip);
+ Objects.requireNonNull(clip);
clip.prepareToLeaveProcess(true);
mService.setPrimaryClip(clip, mContext.getOpPackageName(), mContext.getUserId());
} catch (RemoteException e) {
diff --git a/core/java/android/content/ContentProviderClient.java b/core/java/android/content/ContentProviderClient.java
index 4008f2b..a9b7862 100644
--- a/core/java/android/content/ContentProviderClient.java
+++ b/core/java/android/content/ContentProviderClient.java
@@ -41,7 +41,6 @@
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
-import com.android.internal.util.Preconditions;
import dalvik.system.CloseGuard;
@@ -49,6 +48,7 @@
import java.io.FileNotFoundException;
import java.util.ArrayList;
+import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean;
/**
@@ -184,7 +184,7 @@
public @Nullable Cursor query(@NonNull Uri uri, @Nullable String[] projection,
Bundle queryArgs, @Nullable CancellationSignal cancellationSignal)
throws RemoteException {
- Preconditions.checkNotNull(uri, "url");
+ Objects.requireNonNull(uri, "url");
beforeRemote();
try {
@@ -213,7 +213,7 @@
/** See {@link ContentProvider#getType ContentProvider.getType} */
@Override
public @Nullable String getType(@NonNull Uri url) throws RemoteException {
- Preconditions.checkNotNull(url, "url");
+ Objects.requireNonNull(url, "url");
beforeRemote();
try {
@@ -232,8 +232,8 @@
@Override
public @Nullable String[] getStreamTypes(@NonNull Uri url, @NonNull String mimeTypeFilter)
throws RemoteException {
- Preconditions.checkNotNull(url, "url");
- Preconditions.checkNotNull(mimeTypeFilter, "mimeTypeFilter");
+ Objects.requireNonNull(url, "url");
+ Objects.requireNonNull(mimeTypeFilter, "mimeTypeFilter");
beforeRemote();
try {
@@ -251,7 +251,7 @@
/** See {@link ContentProvider#canonicalize} */
@Override
public final @Nullable Uri canonicalize(@NonNull Uri url) throws RemoteException {
- Preconditions.checkNotNull(url, "url");
+ Objects.requireNonNull(url, "url");
beforeRemote();
try {
@@ -269,7 +269,7 @@
/** See {@link ContentProvider#uncanonicalize} */
@Override
public final @Nullable Uri uncanonicalize(@NonNull Uri url) throws RemoteException {
- Preconditions.checkNotNull(url, "url");
+ Objects.requireNonNull(url, "url");
beforeRemote();
try {
@@ -288,7 +288,7 @@
@Override
public boolean refresh(Uri url, @Nullable Bundle extras,
@Nullable CancellationSignal cancellationSignal) throws RemoteException {
- Preconditions.checkNotNull(url, "url");
+ Objects.requireNonNull(url, "url");
beforeRemote();
try {
@@ -314,7 +314,7 @@
@Override
public int checkUriPermission(@NonNull Uri uri, int uid, @Intent.AccessUriMode int modeFlags)
throws RemoteException {
- Preconditions.checkNotNull(uri, "uri");
+ Objects.requireNonNull(uri, "uri");
beforeRemote();
try {
@@ -340,7 +340,7 @@
@Override
public @Nullable Uri insert(@NonNull Uri url, @Nullable ContentValues initialValues,
@Nullable Bundle extras) throws RemoteException {
- Preconditions.checkNotNull(url, "url");
+ Objects.requireNonNull(url, "url");
beforeRemote();
try {
@@ -359,8 +359,8 @@
@Override
public int bulkInsert(@NonNull Uri url, @NonNull ContentValues[] initialValues)
throws RemoteException {
- Preconditions.checkNotNull(url, "url");
- Preconditions.checkNotNull(initialValues, "initialValues");
+ Objects.requireNonNull(url, "url");
+ Objects.requireNonNull(initialValues, "initialValues");
beforeRemote();
try {
@@ -384,7 +384,7 @@
/** See {@link ContentProvider#delete ContentProvider.delete} */
@Override
public int delete(@NonNull Uri url, @Nullable Bundle extras) throws RemoteException {
- Preconditions.checkNotNull(url, "url");
+ Objects.requireNonNull(url, "url");
beforeRemote();
try {
@@ -409,7 +409,7 @@
@Override
public int update(@NonNull Uri url, @Nullable ContentValues values, @Nullable Bundle extras)
throws RemoteException {
- Preconditions.checkNotNull(url, "url");
+ Objects.requireNonNull(url, "url");
beforeRemote();
try {
@@ -446,8 +446,8 @@
@Override
public @Nullable ParcelFileDescriptor openFile(@NonNull Uri url, @NonNull String mode,
@Nullable CancellationSignal signal) throws RemoteException, FileNotFoundException {
- Preconditions.checkNotNull(url, "url");
- Preconditions.checkNotNull(mode, "mode");
+ Objects.requireNonNull(url, "url");
+ Objects.requireNonNull(mode, "mode");
beforeRemote();
try {
@@ -491,8 +491,8 @@
@Override
public @Nullable AssetFileDescriptor openAssetFile(@NonNull Uri url, @NonNull String mode,
@Nullable CancellationSignal signal) throws RemoteException, FileNotFoundException {
- Preconditions.checkNotNull(url, "url");
- Preconditions.checkNotNull(mode, "mode");
+ Objects.requireNonNull(url, "url");
+ Objects.requireNonNull(mode, "mode");
beforeRemote();
try {
@@ -532,8 +532,8 @@
public final @Nullable AssetFileDescriptor openTypedAssetFile(@NonNull Uri uri,
@NonNull String mimeTypeFilter, @Nullable Bundle opts,
@Nullable CancellationSignal signal) throws RemoteException, FileNotFoundException {
- Preconditions.checkNotNull(uri, "uri");
- Preconditions.checkNotNull(mimeTypeFilter, "mimeTypeFilter");
+ Objects.requireNonNull(uri, "uri");
+ Objects.requireNonNull(mimeTypeFilter, "mimeTypeFilter");
beforeRemote();
try {
@@ -567,7 +567,7 @@
public @NonNull ContentProviderResult[] applyBatch(@NonNull String authority,
@NonNull ArrayList<ContentProviderOperation> operations)
throws RemoteException, OperationApplicationException {
- Preconditions.checkNotNull(operations, "operations");
+ Objects.requireNonNull(operations, "operations");
beforeRemote();
try {
@@ -592,8 +592,8 @@
@Override
public @Nullable Bundle call(@NonNull String authority, @NonNull String method,
@Nullable String arg, @Nullable Bundle extras) throws RemoteException {
- Preconditions.checkNotNull(authority, "authority");
- Preconditions.checkNotNull(method, "method");
+ Objects.requireNonNull(authority, "authority");
+ Objects.requireNonNull(method, "method");
beforeRemote();
try {
diff --git a/core/java/android/content/ContentResolver.java b/core/java/android/content/ContentResolver.java
index ede668a..1d3c650 100644
--- a/core/java/android/content/ContentResolver.java
+++ b/core/java/android/content/ContentResolver.java
@@ -68,7 +68,6 @@
import android.util.SparseArray;
import com.android.internal.util.MimeIconUtils;
-import com.android.internal.util.Preconditions;
import dalvik.system.CloseGuard;
@@ -711,7 +710,7 @@
/** {@hide} */
public static @NonNull ContentResolver wrap(@NonNull ContentInterface wrapped) {
- Preconditions.checkNotNull(wrapped);
+ Objects.requireNonNull(wrapped);
return new ContentResolver(null, wrapped) {
@Override
@@ -796,7 +795,7 @@
*/
@Override
public final @Nullable String getType(@NonNull Uri url) {
- Preconditions.checkNotNull(url, "url");
+ Objects.requireNonNull(url, "url");
try {
if (mWrapped != null) return mWrapped.getType(url);
@@ -856,8 +855,8 @@
*/
@Override
public @Nullable String[] getStreamTypes(@NonNull Uri url, @NonNull String mimeTypeFilter) {
- Preconditions.checkNotNull(url, "url");
- Preconditions.checkNotNull(mimeTypeFilter, "mimeTypeFilter");
+ Objects.requireNonNull(url, "url");
+ Objects.requireNonNull(mimeTypeFilter, "mimeTypeFilter");
try {
if (mWrapped != null) return mWrapped.getStreamTypes(url, mimeTypeFilter);
@@ -998,7 +997,7 @@
public final @Nullable Cursor query(final @RequiresPermission.Read @NonNull Uri uri,
@Nullable String[] projection, @Nullable Bundle queryArgs,
@Nullable CancellationSignal cancellationSignal) {
- Preconditions.checkNotNull(uri, "uri");
+ Objects.requireNonNull(uri, "uri");
try {
if (mWrapped != null) {
@@ -1112,7 +1111,7 @@
*/
@Override
public final @Nullable Uri canonicalize(@NonNull Uri url) {
- Preconditions.checkNotNull(url, "url");
+ Objects.requireNonNull(url, "url");
try {
if (mWrapped != null) return mWrapped.canonicalize(url);
@@ -1156,7 +1155,7 @@
*/
@Override
public final @Nullable Uri uncanonicalize(@NonNull Uri url) {
- Preconditions.checkNotNull(url, "url");
+ Objects.requireNonNull(url, "url");
try {
if (mWrapped != null) return mWrapped.uncanonicalize(url);
@@ -1202,7 +1201,7 @@
@Override
public final boolean refresh(@NonNull Uri url, @Nullable Bundle extras,
@Nullable CancellationSignal cancellationSignal) {
- Preconditions.checkNotNull(url, "url");
+ Objects.requireNonNull(url, "url");
try {
if (mWrapped != null) return mWrapped.refresh(url, extras, cancellationSignal);
@@ -1236,7 +1235,7 @@
/** {@hide} */
@Override
public int checkUriPermission(@NonNull Uri uri, int uid, @Intent.AccessUriMode int modeFlags) {
- Preconditions.checkNotNull(uri, "uri");
+ Objects.requireNonNull(uri, "uri");
try {
if (mWrapped != null) return mWrapped.checkUriPermission(uri, uid, modeFlags);
@@ -1272,7 +1271,7 @@
*/
public final @Nullable InputStream openInputStream(@NonNull Uri uri)
throws FileNotFoundException {
- Preconditions.checkNotNull(uri, "uri");
+ Objects.requireNonNull(uri, "uri");
String scheme = uri.getScheme();
if (SCHEME_ANDROID_RESOURCE.equals(scheme)) {
// Note: left here to avoid breaking compatibility. May be removed
@@ -1579,8 +1578,8 @@
public final @Nullable AssetFileDescriptor openAssetFileDescriptor(@NonNull Uri uri,
@NonNull String mode, @Nullable CancellationSignal cancellationSignal)
throws FileNotFoundException {
- Preconditions.checkNotNull(uri, "uri");
- Preconditions.checkNotNull(mode, "mode");
+ Objects.requireNonNull(uri, "uri");
+ Objects.requireNonNull(mode, "mode");
try {
if (mWrapped != null) return mWrapped.openAssetFile(uri, mode, cancellationSignal);
@@ -1764,8 +1763,8 @@
public final @Nullable AssetFileDescriptor openTypedAssetFileDescriptor(@NonNull Uri uri,
@NonNull String mimeType, @Nullable Bundle opts,
@Nullable CancellationSignal cancellationSignal) throws FileNotFoundException {
- Preconditions.checkNotNull(uri, "uri");
- Preconditions.checkNotNull(mimeType, "mimeType");
+ Objects.requireNonNull(uri, "uri");
+ Objects.requireNonNull(mimeType, "mimeType");
try {
if (mWrapped != null) return mWrapped.openTypedAssetFile(uri, mimeType, opts, cancellationSignal);
@@ -1933,7 +1932,7 @@
@Override
public final @Nullable Uri insert(@RequiresPermission.Write @NonNull Uri url,
@Nullable ContentValues values, @Nullable Bundle extras) {
- Preconditions.checkNotNull(url, "url");
+ Objects.requireNonNull(url, "url");
try {
if (mWrapped != null) return mWrapped.insert(url, values, extras);
@@ -1980,8 +1979,8 @@
public @NonNull ContentProviderResult[] applyBatch(@NonNull String authority,
@NonNull ArrayList<ContentProviderOperation> operations)
throws RemoteException, OperationApplicationException {
- Preconditions.checkNotNull(authority, "authority");
- Preconditions.checkNotNull(operations, "operations");
+ Objects.requireNonNull(authority, "authority");
+ Objects.requireNonNull(operations, "operations");
try {
if (mWrapped != null) return mWrapped.applyBatch(authority, operations);
@@ -2013,8 +2012,8 @@
@Override
public final int bulkInsert(@RequiresPermission.Write @NonNull Uri url,
@NonNull ContentValues[] values) {
- Preconditions.checkNotNull(url, "url");
- Preconditions.checkNotNull(values, "values");
+ Objects.requireNonNull(url, "url");
+ Objects.requireNonNull(values, "values");
try {
if (mWrapped != null) return mWrapped.bulkInsert(url, values);
@@ -2068,7 +2067,7 @@
*/
@Override
public final int delete(@RequiresPermission.Write @NonNull Uri url, @Nullable Bundle extras) {
- Preconditions.checkNotNull(url, "url");
+ Objects.requireNonNull(url, "url");
try {
if (mWrapped != null) return mWrapped.delete(url, extras);
@@ -2130,7 +2129,7 @@
@Override
public final int update(@RequiresPermission.Write @NonNull Uri uri,
@Nullable ContentValues values, @Nullable Bundle extras) {
- Preconditions.checkNotNull(uri, "uri");
+ Objects.requireNonNull(uri, "uri");
try {
if (mWrapped != null) return mWrapped.update(uri, values, extras);
@@ -2179,8 +2178,8 @@
@Override
public final @Nullable Bundle call(@NonNull String authority, @NonNull String method,
@Nullable String arg, @Nullable Bundle extras) {
- Preconditions.checkNotNull(authority, "authority");
- Preconditions.checkNotNull(method, "method");
+ Objects.requireNonNull(authority, "authority");
+ Objects.requireNonNull(method, "method");
try {
if (mWrapped != null) return mWrapped.call(authority, method, arg, extras);
@@ -2297,7 +2296,7 @@
* that services the content at uri or null if there isn't one.
*/
public final @Nullable ContentProviderClient acquireContentProviderClient(@NonNull Uri uri) {
- Preconditions.checkNotNull(uri, "uri");
+ Objects.requireNonNull(uri, "uri");
IContentProvider provider = acquireProvider(uri);
if (provider != null) {
return new ContentProviderClient(this, provider, uri.getAuthority(), true);
@@ -2318,7 +2317,7 @@
*/
public final @Nullable ContentProviderClient acquireContentProviderClient(
@NonNull String name) {
- Preconditions.checkNotNull(name, "name");
+ Objects.requireNonNull(name, "name");
IContentProvider provider = acquireProvider(name);
if (provider != null) {
return new ContentProviderClient(this, provider, name, true);
@@ -2345,7 +2344,7 @@
*/
public final @Nullable ContentProviderClient acquireUnstableContentProviderClient(
@NonNull Uri uri) {
- Preconditions.checkNotNull(uri, "uri");
+ Objects.requireNonNull(uri, "uri");
IContentProvider provider = acquireUnstableProvider(uri);
if (provider != null) {
return new ContentProviderClient(this, provider, uri.getAuthority(), false);
@@ -2372,7 +2371,7 @@
*/
public final @Nullable ContentProviderClient acquireUnstableContentProviderClient(
@NonNull String name) {
- Preconditions.checkNotNull(name, "name");
+ Objects.requireNonNull(name, "name");
IContentProvider provider = acquireUnstableProvider(name);
if (provider != null) {
return new ContentProviderClient(this, provider, name, false);
@@ -2401,8 +2400,8 @@
*/
public final void registerContentObserver(@NonNull Uri uri, boolean notifyForDescendants,
@NonNull ContentObserver observer) {
- Preconditions.checkNotNull(uri, "uri");
- Preconditions.checkNotNull(observer, "observer");
+ Objects.requireNonNull(uri, "uri");
+ Objects.requireNonNull(observer, "observer");
registerContentObserver(
ContentProvider.getUriWithoutUserId(uri),
notifyForDescendants,
@@ -2429,7 +2428,7 @@
* @see #registerContentObserver
*/
public final void unregisterContentObserver(@NonNull ContentObserver observer) {
- Preconditions.checkNotNull(observer, "observer");
+ Objects.requireNonNull(observer, "observer");
try {
IContentObserver contentObserver = observer.releaseContentObserver();
if (contentObserver != null) {
@@ -2523,7 +2522,7 @@
*/
public void notifyChange(@NonNull Uri uri, @Nullable ContentObserver observer,
@NotifyFlags int flags) {
- Preconditions.checkNotNull(uri, "uri");
+ Objects.requireNonNull(uri, "uri");
notifyChange(
ContentProvider.getUriWithoutUserId(uri),
observer,
@@ -2557,7 +2556,7 @@
*/
public void notifyChange(@NonNull Iterable<Uri> uris, @Nullable ContentObserver observer,
@NotifyFlags int flags) {
- Preconditions.checkNotNull(uris, "uris");
+ Objects.requireNonNull(uris, "uris");
// Cluster based on user ID
final SparseArray<ArrayList<Uri>> clusteredByUser = new SparseArray<>();
@@ -2628,7 +2627,7 @@
*/
public void takePersistableUriPermission(@NonNull Uri uri,
@Intent.AccessUriMode int modeFlags) {
- Preconditions.checkNotNull(uri, "uri");
+ Objects.requireNonNull(uri, "uri");
try {
UriGrantsManager.getService().takePersistableUriPermission(
ContentProvider.getUriWithoutUserId(uri), modeFlags, /* toPackage= */ null,
@@ -2644,8 +2643,8 @@
@UnsupportedAppUsage
public void takePersistableUriPermission(@NonNull String toPackage, @NonNull Uri uri,
@Intent.AccessUriMode int modeFlags) {
- Preconditions.checkNotNull(toPackage, "toPackage");
- Preconditions.checkNotNull(uri, "uri");
+ Objects.requireNonNull(toPackage, "toPackage");
+ Objects.requireNonNull(uri, "uri");
try {
UriGrantsManager.getService().takePersistableUriPermission(
ContentProvider.getUriWithoutUserId(uri), modeFlags, toPackage,
@@ -2665,7 +2664,7 @@
*/
public void releasePersistableUriPermission(@NonNull Uri uri,
@Intent.AccessUriMode int modeFlags) {
- Preconditions.checkNotNull(uri, "uri");
+ Objects.requireNonNull(uri, "uri");
try {
UriGrantsManager.getService().releasePersistableUriPermission(
ContentProvider.getUriWithoutUserId(uri), modeFlags, /* toPackage= */ null,
diff --git a/core/java/android/content/integrity/AppInstallMetadata.java b/core/java/android/content/integrity/AppInstallMetadata.java
index 70776c7..85af881 100644
--- a/core/java/android/content/integrity/AppInstallMetadata.java
+++ b/core/java/android/content/integrity/AppInstallMetadata.java
@@ -16,15 +16,14 @@
package android.content.integrity;
-import static com.android.internal.util.Preconditions.checkArgument;
-import static com.android.internal.util.Preconditions.checkNotNull;
-
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import com.android.internal.annotations.VisibleForTesting;
+import java.util.Objects;
+
/**
* The app install metadata.
*
@@ -115,7 +114,7 @@
*/
@NonNull
public Builder setPackageName(@NonNull String packageName) {
- this.mPackageName = checkNotNull(packageName);
+ this.mPackageName = Objects.requireNonNull(packageName);
return this;
}
@@ -129,7 +128,7 @@
*/
@NonNull
public Builder setAppCertificate(@NonNull String appCertificate) {
- this.mAppCertificate = checkNotNull(appCertificate);
+ this.mAppCertificate = Objects.requireNonNull(appCertificate);
return this;
}
@@ -140,7 +139,7 @@
*/
@NonNull
public Builder setInstallerName(@NonNull String installerName) {
- this.mInstallerName = checkNotNull(installerName);
+ this.mInstallerName = Objects.requireNonNull(installerName);
return this;
}
@@ -154,7 +153,7 @@
*/
@NonNull
public Builder setInstallerCertificate(@NonNull String installerCertificate) {
- this.mInstallerCertificate = checkNotNull(installerCertificate);
+ this.mInstallerCertificate = Objects.requireNonNull(installerCertificate);
return this;
}
@@ -187,8 +186,8 @@
*/
@NonNull
public AppInstallMetadata build() {
- checkArgument(mPackageName != null);
- checkArgument(mAppCertificate != null);
+ Objects.requireNonNull(mPackageName);
+ Objects.requireNonNull(mAppCertificate);
return new AppInstallMetadata(this);
}
}
diff --git a/core/java/android/content/integrity/Rule.java b/core/java/android/content/integrity/Rule.java
index 39a0909..7758785 100644
--- a/core/java/android/content/integrity/Rule.java
+++ b/core/java/android/content/integrity/Rule.java
@@ -17,7 +17,6 @@
package android.content.integrity;
import static com.android.internal.util.Preconditions.checkArgument;
-import static com.android.internal.util.Preconditions.checkNotNull;
import android.annotation.IntDef;
import android.annotation.NonNull;
@@ -65,7 +64,7 @@
public Rule(@NonNull Formula formula, @Effect int effect) {
checkArgument(isValidEffect(effect), String.format("Unknown effect: %d", effect));
- this.mFormula = checkNotNull(formula);
+ this.mFormula = Objects.requireNonNull(formula);
this.mEffect = effect;
}
diff --git a/core/java/android/content/integrity/RuleSet.java b/core/java/android/content/integrity/RuleSet.java
index a78f8c9..b423b54 100644
--- a/core/java/android/content/integrity/RuleSet.java
+++ b/core/java/android/content/integrity/RuleSet.java
@@ -16,14 +16,13 @@
package android.content.integrity;
-import static com.android.internal.util.Preconditions.checkNotNull;
-
import android.annotation.NonNull;
import android.annotation.SystemApi;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.Objects;
/**
* Immutable data class encapsulating all parameters of a rule set.
@@ -85,7 +84,7 @@
*/
@NonNull
public RuleSet build() {
- checkNotNull(mVersion);
+ Objects.requireNonNull(mVersion);
return new RuleSet(mVersion, mRules);
}
}
diff --git a/core/java/android/content/pm/LauncherApps.java b/core/java/android/content/pm/LauncherApps.java
index 94a5375..ed958b1 100644
--- a/core/java/android/content/pm/LauncherApps.java
+++ b/core/java/android/content/pm/LauncherApps.java
@@ -62,8 +62,6 @@
import android.util.DisplayMetrics;
import android.util.Log;
-import com.android.internal.util.Preconditions;
-
import java.io.IOException;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -72,6 +70,7 @@
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
+import java.util.Objects;
import java.util.concurrent.Executor;
/**
@@ -766,8 +765,8 @@
*/
public boolean shouldHideFromSuggestions(@NonNull String packageName,
@NonNull UserHandle user) {
- Preconditions.checkNotNull(packageName, "packageName");
- Preconditions.checkNotNull(user, "user");
+ Objects.requireNonNull(packageName, "packageName");
+ Objects.requireNonNull(user, "user");
try {
return mService.shouldHideFromSuggestions(packageName, user);
} catch (RemoteException re) {
@@ -789,8 +788,8 @@
public ApplicationInfo getApplicationInfo(@NonNull String packageName,
@ApplicationInfoFlags int flags, @NonNull UserHandle user)
throws PackageManager.NameNotFoundException {
- Preconditions.checkNotNull(packageName, "packageName");
- Preconditions.checkNotNull(user, "user");
+ Objects.requireNonNull(packageName, "packageName");
+ Objects.requireNonNull(user, "user");
logErrorForInvalidProfileAccess(user);
try {
final ApplicationInfo ai = mService
diff --git a/core/java/android/content/pm/PackageInstaller.java b/core/java/android/content/pm/PackageInstaller.java
index e4a0bc0..7a28022 100644
--- a/core/java/android/content/pm/PackageInstaller.java
+++ b/core/java/android/content/pm/PackageInstaller.java
@@ -56,7 +56,6 @@
import android.util.ExceptionUtils;
import com.android.internal.util.IndentingPrintWriter;
-import com.android.internal.util.Preconditions;
import com.android.internal.util.function.pooled.PooledLambda;
import java.io.Closeable;
@@ -70,6 +69,7 @@
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
+import java.util.Objects;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
@@ -634,7 +634,7 @@
Manifest.permission.REQUEST_DELETE_PACKAGES})
public void uninstall(@NonNull VersionedPackage versionedPackage, @DeleteFlags int flags,
@NonNull IntentSender statusReceiver) {
- Preconditions.checkNotNull(versionedPackage, "versionedPackage cannot be null");
+ Objects.requireNonNull(versionedPackage, "versionedPackage cannot be null");
try {
mInstaller.uninstall(versionedPackage, mInstallerPackageName,
flags, statusReceiver, mUserId);
@@ -661,7 +661,7 @@
public void installExistingPackage(@NonNull String packageName,
@InstallReason int installReason,
@Nullable IntentSender statusReceiver) {
- Preconditions.checkNotNull(packageName, "packageName cannot be null");
+ Objects.requireNonNull(packageName, "packageName cannot be null");
try {
mInstaller.installExistingPackage(packageName,
PackageManager.INSTALL_ALL_WHITELIST_RESTRICTED_PERMISSIONS, installReason,
@@ -1202,8 +1202,8 @@
*/
public void transfer(@NonNull String packageName, @NonNull IntentSender statusReceiver)
throws PackageManager.NameNotFoundException {
- Preconditions.checkNotNull(statusReceiver);
- Preconditions.checkNotNull(packageName);
+ Objects.requireNonNull(statusReceiver);
+ Objects.requireNonNull(packageName);
try {
mSession.transfer(packageName, statusReceiver);
@@ -1231,7 +1231,7 @@
*/
public void transfer(@NonNull String packageName)
throws PackageManager.NameNotFoundException {
- Preconditions.checkNotNull(packageName);
+ Objects.requireNonNull(packageName);
CompletableFuture<Intent> intentFuture = new CompletableFuture<Intent>();
try {
diff --git a/core/java/android/content/pm/PackageItemInfo.java b/core/java/android/content/pm/PackageItemInfo.java
index 50a2f00..7fd5531 100644
--- a/core/java/android/content/pm/PackageItemInfo.java
+++ b/core/java/android/content/pm/PackageItemInfo.java
@@ -33,10 +33,10 @@
import android.util.Printer;
import android.util.proto.ProtoOutputStream;
-import com.android.internal.util.Preconditions;
import java.text.Collator;
import java.util.Comparator;
+import java.util.Objects;
/**
* Base class containing information common to all package items held by
@@ -240,7 +240,7 @@
@SystemApi
public @NonNull CharSequence loadSafeLabel(@NonNull PackageManager pm,
@FloatRange(from = 0) float ellipsizeDip, @TextUtils.SafeStringFlags int flags) {
- Preconditions.checkNotNull(pm);
+ Objects.requireNonNull(pm);
return makeSafeForPresentation(loadUnsafeLabel(pm).toString(), MAX_SAFE_LABEL_LENGTH,
ellipsizeDip, flags);
diff --git a/core/java/android/content/pm/ShortcutInfo.java b/core/java/android/content/pm/ShortcutInfo.java
index 2c4ccbf..d5fb848 100644
--- a/core/java/android/content/pm/ShortcutInfo.java
+++ b/core/java/android/content/pm/ShortcutInfo.java
@@ -51,6 +51,7 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List;
+import java.util.Objects;
import java.util.Set;
/**
@@ -519,12 +520,12 @@
public void enforceMandatoryFields(boolean forPinned) {
Preconditions.checkStringNotEmpty(mId, "Shortcut ID must be provided");
if (!forPinned) {
- Preconditions.checkNotNull(mActivity, "Activity must be provided");
+ Objects.requireNonNull(mActivity, "Activity must be provided");
}
if (mTitle == null && mTitleResId == 0) {
throw new IllegalArgumentException("Short label must be provided");
}
- Preconditions.checkNotNull(mIntents, "Shortcut Intent must be provided");
+ Objects.requireNonNull(mIntents, "Shortcut Intent must be provided");
Preconditions.checkArgument(mIntents.length > 0, "Shortcut Intent must be provided");
}
@@ -1008,7 +1009,7 @@
*/
@NonNull
public Builder setLocusId(@NonNull LocusId locusId) {
- mLocusId = Preconditions.checkNotNull(locusId, "locusId cannot be null");
+ mLocusId = Objects.requireNonNull(locusId, "locusId cannot be null");
return this;
}
@@ -1039,7 +1040,7 @@
*/
@NonNull
public Builder setActivity(@NonNull ComponentName activity) {
- mActivity = Preconditions.checkNotNull(activity, "activity cannot be null");
+ mActivity = Objects.requireNonNull(activity, "activity cannot be null");
return this;
}
@@ -1229,11 +1230,11 @@
*/
@NonNull
public Builder setIntents(@NonNull Intent[] intents) {
- Preconditions.checkNotNull(intents, "intents cannot be null");
- Preconditions.checkNotNull(intents.length, "intents cannot be empty");
+ Objects.requireNonNull(intents, "intents cannot be null");
+ Objects.requireNonNull(intents.length, "intents cannot be empty");
for (Intent intent : intents) {
- Preconditions.checkNotNull(intent, "intents cannot contain null");
- Preconditions.checkNotNull(intent.getAction(), "intent's action must be set");
+ Objects.requireNonNull(intent, "intents cannot contain null");
+ Objects.requireNonNull(intent.getAction(), "intent's action must be set");
}
// Make sure always clone incoming intents.
mIntents = cloneIntents(intents);
@@ -1267,10 +1268,10 @@
*/
@NonNull
public Builder setPersons(@NonNull Person[] persons) {
- Preconditions.checkNotNull(persons, "persons cannot be null");
- Preconditions.checkNotNull(persons.length, "persons cannot be empty");
+ Objects.requireNonNull(persons, "persons cannot be null");
+ Objects.requireNonNull(persons.length, "persons cannot be empty");
for (Person person : persons) {
- Preconditions.checkNotNull(person, "persons cannot contain null");
+ Objects.requireNonNull(person, "persons cannot contain null");
}
mPersons = clonePersons(persons);
return this;
@@ -1979,7 +1980,7 @@
* @hide
*/
public void setIntents(Intent[] intents) throws IllegalArgumentException {
- Preconditions.checkNotNull(intents);
+ Objects.requireNonNull(intents);
Preconditions.checkArgument(intents.length > 0);
mIntents = cloneIntents(intents);
diff --git a/core/java/android/content/res/ApkAssets.java b/core/java/android/content/res/ApkAssets.java
index 0e4a8e6..8db2785 100644
--- a/core/java/android/content/res/ApkAssets.java
+++ b/core/java/android/content/res/ApkAssets.java
@@ -23,10 +23,10 @@
import android.text.TextUtils;
import com.android.internal.annotations.GuardedBy;
-import com.android.internal.util.Preconditions;
import java.io.FileDescriptor;
import java.io.IOException;
+import java.util.Objects;
/**
* The loaded, immutable, in-memory representation of an APK.
@@ -193,7 +193,7 @@
private ApkAssets(@NonNull String path, boolean system, boolean forceSharedLib, boolean overlay,
boolean arscOnly, boolean forLoader) throws IOException {
mForLoader = forLoader;
- Preconditions.checkNotNull(path, "path");
+ Objects.requireNonNull(path, "path");
mNativePtr = arscOnly ? nativeLoadArsc(path, forLoader)
: nativeLoad(path, system, forceSharedLib, overlay, forLoader);
mStringBlock = new StringBlock(nativeGetStringBlock(mNativePtr), true /*useSparse*/);
@@ -202,8 +202,8 @@
private ApkAssets(@NonNull FileDescriptor fd, @NonNull String friendlyName, boolean system,
boolean forceSharedLib, boolean arscOnly, boolean forLoader) throws IOException {
mForLoader = forLoader;
- Preconditions.checkNotNull(fd, "fd");
- Preconditions.checkNotNull(friendlyName, "friendlyName");
+ Objects.requireNonNull(fd, "fd");
+ Objects.requireNonNull(friendlyName, "friendlyName");
mNativePtr = arscOnly ? nativeLoadArscFromFd(fd, friendlyName, forLoader)
: nativeLoadFromFd(fd, friendlyName, system, forceSharedLib, forLoader);
mStringBlock = new StringBlock(nativeGetStringBlock(mNativePtr), true /*useSparse*/);
@@ -240,7 +240,7 @@
* @throws IOException if the file was not found or an error occurred retrieving it.
*/
public @NonNull XmlResourceParser openXml(@NonNull String fileName) throws IOException {
- Preconditions.checkNotNull(fileName, "fileName");
+ Objects.requireNonNull(fileName, "fileName");
synchronized (this) {
long nativeXmlPtr = nativeOpenXml(mNativePtr, fileName);
try (XmlBlock block = new XmlBlock(null, nativeXmlPtr)) {
diff --git a/core/java/android/content/res/AssetManager.java b/core/java/android/content/res/AssetManager.java
index d20dca1..96fbe91 100644
--- a/core/java/android/content/res/AssetManager.java
+++ b/core/java/android/content/res/AssetManager.java
@@ -39,7 +39,6 @@
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
-import com.android.internal.util.Preconditions;
import java.io.FileDescriptor;
import java.io.FileNotFoundException;
@@ -52,6 +51,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Objects;
/**
* Provides access to an application's raw asset files; see {@link Resources}
@@ -273,7 +273,7 @@
* @hide
*/
public void setApkAssets(@NonNull ApkAssets[] apkAssets, boolean invalidateCaches) {
- Preconditions.checkNotNull(apkAssets, "apkAssets");
+ Objects.requireNonNull(apkAssets, "apkAssets");
ApkAssets[] newApkAssets = new ApkAssets[sSystemApkAssets.length + apkAssets.length];
@@ -352,7 +352,7 @@
* @hide
*/
public int findCookieForPath(@NonNull String path) {
- Preconditions.checkNotNull(path, "path");
+ Objects.requireNonNull(path, "path");
synchronized (this) {
ensureValidLocked();
final int count = mApkAssets.length;
@@ -396,7 +396,7 @@
}
private int addAssetPathInternal(String path, boolean overlay, boolean appAsLib) {
- Preconditions.checkNotNull(path, "path");
+ Objects.requireNonNull(path, "path");
synchronized (this) {
ensureOpenLocked();
final int count = mApkAssets.length;
@@ -471,7 +471,7 @@
@UnsupportedAppUsage
boolean getResourceValue(@AnyRes int resId, int densityDpi, @NonNull TypedValue outValue,
boolean resolveRefs) {
- Preconditions.checkNotNull(outValue, "outValue");
+ Objects.requireNonNull(outValue, "outValue");
synchronized (this) {
ensureValidLocked();
final int cookie = nativeGetResourceValue(
@@ -568,7 +568,7 @@
* @see TypedArray#STYLE_DENSITY
*/
int getResourceArray(@ArrayRes int resId, @NonNull int[] outData) {
- Preconditions.checkNotNull(outData, "outData");
+ Objects.requireNonNull(outData, "outData");
synchronized (this) {
ensureValidLocked();
return nativeGetResourceArray(mObject, resId, outData);
@@ -652,7 +652,7 @@
*/
boolean getThemeValue(long theme, @AnyRes int resId, @NonNull TypedValue outValue,
boolean resolveRefs) {
- Preconditions.checkNotNull(outValue, "outValue");
+ Objects.requireNonNull(outValue, "outValue");
synchronized (this) {
ensureValidLocked();
final int cookie = nativeThemeGetAttributeValue(mObject, theme, resId, outValue,
@@ -791,7 +791,7 @@
* @see #list
*/
public @NonNull InputStream open(@NonNull String fileName, int accessMode) throws IOException {
- Preconditions.checkNotNull(fileName, "fileName");
+ Objects.requireNonNull(fileName, "fileName");
synchronized (this) {
ensureOpenLocked();
@@ -822,7 +822,7 @@
* @return An open AssetFileDescriptor.
*/
public @NonNull AssetFileDescriptor openFd(@NonNull String fileName) throws IOException {
- Preconditions.checkNotNull(fileName, "fileName");
+ Objects.requireNonNull(fileName, "fileName");
synchronized (this) {
ensureOpenLocked();
@@ -853,7 +853,7 @@
* @see #open
*/
public @Nullable String[] list(@NonNull String path) throws IOException {
- Preconditions.checkNotNull(path, "path");
+ Objects.requireNonNull(path, "path");
synchronized (this) {
ensureValidLocked();
return nativeList(mObject, path);
@@ -922,7 +922,7 @@
@UnsupportedAppUsage
public @NonNull InputStream openNonAsset(int cookie, @NonNull String fileName, int accessMode)
throws IOException {
- Preconditions.checkNotNull(fileName, "fileName");
+ Objects.requireNonNull(fileName, "fileName");
synchronized (this) {
ensureOpenLocked();
@@ -967,7 +967,7 @@
*/
public @NonNull AssetFileDescriptor openNonAssetFd(int cookie, @NonNull String fileName)
throws IOException {
- Preconditions.checkNotNull(fileName, "fileName");
+ Objects.requireNonNull(fileName, "fileName");
synchronized (this) {
ensureOpenLocked();
@@ -1034,7 +1034,7 @@
* @hide
*/
@NonNull XmlBlock openXmlBlockAsset(int cookie, @NonNull String fileName) throws IOException {
- Preconditions.checkNotNull(fileName, "fileName");
+ Objects.requireNonNull(fileName, "fileName");
synchronized (this) {
ensureOpenLocked();
@@ -1145,7 +1145,7 @@
void applyStyle(long themePtr, @AttrRes int defStyleAttr, @StyleRes int defStyleRes,
@Nullable XmlBlock.Parser parser, @NonNull int[] inAttrs, long outValuesAddress,
long outIndicesAddress) {
- Preconditions.checkNotNull(inAttrs, "inAttrs");
+ Objects.requireNonNull(inAttrs, "inAttrs");
synchronized (this) {
// Need to synchronize on AssetManager because we will be accessing
// the native implementation of AssetManager.
@@ -1168,9 +1168,9 @@
boolean resolveAttrs(long themePtr, @AttrRes int defStyleAttr, @StyleRes int defStyleRes,
@Nullable int[] inValues, @NonNull int[] inAttrs, @NonNull int[] outValues,
@NonNull int[] outIndices) {
- Preconditions.checkNotNull(inAttrs, "inAttrs");
- Preconditions.checkNotNull(outValues, "outValues");
- Preconditions.checkNotNull(outIndices, "outIndices");
+ Objects.requireNonNull(inAttrs, "inAttrs");
+ Objects.requireNonNull(outValues, "outValues");
+ Objects.requireNonNull(outIndices, "outIndices");
synchronized (this) {
// Need to synchronize on AssetManager because we will be accessing
// the native implementation of AssetManager.
@@ -1183,10 +1183,10 @@
@UnsupportedAppUsage
boolean retrieveAttributes(@NonNull XmlBlock.Parser parser, @NonNull int[] inAttrs,
@NonNull int[] outValues, @NonNull int[] outIndices) {
- Preconditions.checkNotNull(parser, "parser");
- Preconditions.checkNotNull(inAttrs, "inAttrs");
- Preconditions.checkNotNull(outValues, "outValues");
- Preconditions.checkNotNull(outIndices, "outIndices");
+ Objects.requireNonNull(parser, "parser");
+ Objects.requireNonNull(inAttrs, "inAttrs");
+ Objects.requireNonNull(outValues, "outValues");
+ Objects.requireNonNull(outIndices, "outIndices");
synchronized (this) {
// Need to synchronize on AssetManager because we will be accessing
// the native implementation of AssetManager.
@@ -1290,14 +1290,14 @@
@Override
public final int read(@NonNull byte[] b) throws IOException {
ensureOpen();
- Preconditions.checkNotNull(b, "b");
+ Objects.requireNonNull(b, "b");
return nativeAssetRead(mAssetNativePtr, b, 0, b.length);
}
@Override
public final int read(@NonNull byte[] b, int off, int len) throws IOException {
ensureOpen();
- Preconditions.checkNotNull(b, "b");
+ Objects.requireNonNull(b, "b");
return nativeAssetRead(mAssetNativePtr, b, off, len);
}