Merge "Replace com.android.internal.util.Preconditions.checkNotNull with java.util.Objects.requireNonNull"
diff --git a/apex/sdkext/Android.bp b/apex/sdkext/Android.bp
index 5369a96..f62f167 100644
--- a/apex/sdkext/Android.bp
+++ b/apex/sdkext/Android.bp
@@ -32,7 +32,7 @@
sdk {
name: "sdkext-sdk",
- java_libs: [ "framework-sdkext-stubs-systemapi" ],
+ java_header_libs: [ "framework-sdkext-stubs-systemapi" ],
}
apex_key {
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);
}
diff --git a/core/java/android/hardware/hdmi/HdmiControlManager.java b/core/java/android/hardware/hdmi/HdmiControlManager.java
index 2295d2b..65a8e15 100644
--- a/core/java/android/hardware/hdmi/HdmiControlManager.java
+++ b/core/java/android/hardware/hdmi/HdmiControlManager.java
@@ -36,10 +36,10 @@
import android.util.Log;
import com.android.internal.annotations.GuardedBy;
-import com.android.internal.util.Preconditions;
import java.util.ArrayList;
import java.util.List;
+import java.util.Objects;
/**
* The {@link HdmiControlManager} class is used to send HDMI control messages
@@ -532,7 +532,7 @@
*/
@SystemApi
public void powerOffDevice(@NonNull HdmiDeviceInfo deviceInfo) {
- Preconditions.checkNotNull(deviceInfo);
+ Objects.requireNonNull(deviceInfo);
try {
mService.powerOffRemoteDevice(
deviceInfo.getLogicalAddress(), deviceInfo.getDevicePowerStatus());
@@ -549,7 +549,7 @@
@Deprecated
@SystemApi
public void powerOffRemoteDevice(@NonNull HdmiDeviceInfo deviceInfo) {
- Preconditions.checkNotNull(deviceInfo);
+ Objects.requireNonNull(deviceInfo);
try {
mService.powerOffRemoteDevice(
deviceInfo.getLogicalAddress(), deviceInfo.getDevicePowerStatus());
@@ -569,7 +569,7 @@
* @hide
*/
public void powerOnDevice(HdmiDeviceInfo deviceInfo) {
- Preconditions.checkNotNull(deviceInfo);
+ Objects.requireNonNull(deviceInfo);
try {
mService.powerOnRemoteDevice(
deviceInfo.getLogicalAddress(), deviceInfo.getDevicePowerStatus());
@@ -586,7 +586,7 @@
@Deprecated
@SystemApi
public void powerOnRemoteDevice(HdmiDeviceInfo deviceInfo) {
- Preconditions.checkNotNull(deviceInfo);
+ Objects.requireNonNull(deviceInfo);
try {
mService.powerOnRemoteDevice(
deviceInfo.getLogicalAddress(), deviceInfo.getDevicePowerStatus());
@@ -610,7 +610,7 @@
*/
@SystemApi
public void setActiveSource(@NonNull HdmiDeviceInfo deviceInfo) {
- Preconditions.checkNotNull(deviceInfo);
+ Objects.requireNonNull(deviceInfo);
try {
mService.askRemoteDeviceToBecomeActiveSource(deviceInfo.getPhysicalAddress());
} catch (RemoteException e) {
@@ -626,7 +626,7 @@
@Deprecated
@SystemApi
public void requestRemoteDeviceToBecomeActiveSource(@NonNull HdmiDeviceInfo deviceInfo) {
- Preconditions.checkNotNull(deviceInfo);
+ Objects.requireNonNull(deviceInfo);
try {
mService.askRemoteDeviceToBecomeActiveSource(deviceInfo.getPhysicalAddress());
} catch (RemoteException e) {
@@ -689,7 +689,7 @@
*/
@SystemApi
public boolean isDeviceConnected(@NonNull HdmiDeviceInfo targetDevice) {
- Preconditions.checkNotNull(targetDevice);
+ Objects.requireNonNull(targetDevice);
int physicalAddress = getLocalPhysicalAddress();
if (physicalAddress == INVALID_PHYSICAL_ADDRESS) {
return false;
@@ -710,7 +710,7 @@
@Deprecated
@SystemApi
public boolean isRemoteDeviceConnected(@NonNull HdmiDeviceInfo targetDevice) {
- Preconditions.checkNotNull(targetDevice);
+ Objects.requireNonNull(targetDevice);
int physicalAddress = getLocalPhysicalAddress();
if (physicalAddress == INVALID_PHYSICAL_ADDRESS) {
return false;
diff --git a/core/java/android/hardware/hdmi/HdmiSwitchClient.java b/core/java/android/hardware/hdmi/HdmiSwitchClient.java
index 6a72a4a..7833653 100644
--- a/core/java/android/hardware/hdmi/HdmiSwitchClient.java
+++ b/core/java/android/hardware/hdmi/HdmiSwitchClient.java
@@ -23,10 +23,9 @@
import android.os.RemoteException;
import android.util.Log;
-import com.android.internal.util.Preconditions;
-
import java.util.Collections;
import java.util.List;
+import java.util.Objects;
import java.util.concurrent.Executor;
/**
@@ -70,7 +69,7 @@
* @hide
*/
public void selectDevice(int logicalAddress, @NonNull OnSelectListener listener) {
- Preconditions.checkNotNull(listener);
+ Objects.requireNonNull(listener);
try {
mService.deviceSelect(logicalAddress, getCallbackWrapper(listener));
} catch (RemoteException e) {
@@ -91,7 +90,7 @@
*/
@SystemApi
public void selectPort(int portId, @NonNull OnSelectListener listener) {
- Preconditions.checkNotNull(listener);
+ Objects.requireNonNull(listener);
try {
mService.portSelect(portId, getCallbackWrapper(listener));
} catch (RemoteException e) {
@@ -114,7 +113,7 @@
int logicalAddress,
@NonNull @CallbackExecutor Executor executor,
@NonNull OnSelectListener listener) {
- Preconditions.checkNotNull(listener);
+ Objects.requireNonNull(listener);
try {
mService.deviceSelect(logicalAddress,
new IHdmiControlCallback.Stub() {
@@ -146,7 +145,7 @@
int portId,
@NonNull @CallbackExecutor Executor executor,
@NonNull OnSelectListener listener) {
- Preconditions.checkNotNull(listener);
+ Objects.requireNonNull(listener);
try {
mService.portSelect(portId,
new IHdmiControlCallback.Stub() {
diff --git a/core/java/android/hardware/location/ContextHubClient.java b/core/java/android/hardware/location/ContextHubClient.java
index 3adc101..c6a5dd0 100644
--- a/core/java/android/hardware/location/ContextHubClient.java
+++ b/core/java/android/hardware/location/ContextHubClient.java
@@ -22,11 +22,10 @@
import android.os.RemoteException;
import android.util.Log;
-import com.android.internal.util.Preconditions;
-
import dalvik.system.CloseGuard;
import java.io.Closeable;
+import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean;
/**
@@ -80,7 +79,7 @@
* @param clientProxy the proxy of the client at the service
*/
/* package */ void setClientProxy(IContextHubClient clientProxy) {
- Preconditions.checkNotNull(clientProxy, "IContextHubClient cannot be null");
+ Objects.requireNonNull(clientProxy, "IContextHubClient cannot be null");
if (mClientProxy != null) {
throw new IllegalStateException("Cannot change client proxy multiple times");
}
@@ -140,7 +139,7 @@
@RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE)
@ContextHubTransaction.Result
public int sendMessageToNanoApp(@NonNull NanoAppMessage message) {
- Preconditions.checkNotNull(message, "NanoAppMessage cannot be null");
+ Objects.requireNonNull(message, "NanoAppMessage cannot be null");
int maxPayloadBytes = mAttachedHub.getMaxPacketLengthBytes();
byte[] payload = message.getMessageBody();
diff --git a/core/java/android/hardware/location/ContextHubIntentEvent.java b/core/java/android/hardware/location/ContextHubIntentEvent.java
index 754327a..917f62b 100644
--- a/core/java/android/hardware/location/ContextHubIntentEvent.java
+++ b/core/java/android/hardware/location/ContextHubIntentEvent.java
@@ -21,7 +21,7 @@
import android.app.PendingIntent;
import android.content.Intent;
-import com.android.internal.util.Preconditions;
+import java.util.Objects;
/**
* A helper class to retrieve information about a Intent event received for a PendingIntent
@@ -89,7 +89,7 @@
*/
@NonNull
public static ContextHubIntentEvent fromIntent(@NonNull Intent intent) {
- Preconditions.checkNotNull(intent, "Intent cannot be null");
+ Objects.requireNonNull(intent, "Intent cannot be null");
hasExtraOrThrow(intent, ContextHubManager.EXTRA_CONTEXT_HUB_INFO);
ContextHubInfo info = intent.getParcelableExtra(ContextHubManager.EXTRA_CONTEXT_HUB_INFO);
diff --git a/core/java/android/hardware/location/ContextHubManager.java b/core/java/android/hardware/location/ContextHubManager.java
index 7639302..a51d2c9 100644
--- a/core/java/android/hardware/location/ContextHubManager.java
+++ b/core/java/android/hardware/location/ContextHubManager.java
@@ -34,11 +34,10 @@
import android.os.ServiceManager.ServiceNotFoundException;
import android.util.Log;
-import com.android.internal.util.Preconditions;
-
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List;
+import java.util.Objects;
import java.util.concurrent.Executor;
/**
@@ -470,8 +469,8 @@
@RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE)
@NonNull public ContextHubTransaction<Void> loadNanoApp(
@NonNull ContextHubInfo hubInfo, @NonNull NanoAppBinary appBinary) {
- Preconditions.checkNotNull(hubInfo, "ContextHubInfo cannot be null");
- Preconditions.checkNotNull(appBinary, "NanoAppBinary cannot be null");
+ Objects.requireNonNull(hubInfo, "ContextHubInfo cannot be null");
+ Objects.requireNonNull(appBinary, "NanoAppBinary cannot be null");
ContextHubTransaction<Void> transaction =
new ContextHubTransaction<>(ContextHubTransaction.TYPE_LOAD_NANOAPP);
@@ -499,7 +498,7 @@
@RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE)
@NonNull public ContextHubTransaction<Void> unloadNanoApp(
@NonNull ContextHubInfo hubInfo, long nanoAppId) {
- Preconditions.checkNotNull(hubInfo, "ContextHubInfo cannot be null");
+ Objects.requireNonNull(hubInfo, "ContextHubInfo cannot be null");
ContextHubTransaction<Void> transaction =
new ContextHubTransaction<>(ContextHubTransaction.TYPE_UNLOAD_NANOAPP);
@@ -527,7 +526,7 @@
@RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE)
@NonNull public ContextHubTransaction<Void> enableNanoApp(
@NonNull ContextHubInfo hubInfo, long nanoAppId) {
- Preconditions.checkNotNull(hubInfo, "ContextHubInfo cannot be null");
+ Objects.requireNonNull(hubInfo, "ContextHubInfo cannot be null");
ContextHubTransaction<Void> transaction =
new ContextHubTransaction<>(ContextHubTransaction.TYPE_ENABLE_NANOAPP);
@@ -555,7 +554,7 @@
@RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE)
@NonNull public ContextHubTransaction<Void> disableNanoApp(
@NonNull ContextHubInfo hubInfo, long nanoAppId) {
- Preconditions.checkNotNull(hubInfo, "ContextHubInfo cannot be null");
+ Objects.requireNonNull(hubInfo, "ContextHubInfo cannot be null");
ContextHubTransaction<Void> transaction =
new ContextHubTransaction<>(ContextHubTransaction.TYPE_DISABLE_NANOAPP);
@@ -582,7 +581,7 @@
@RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE)
@NonNull public ContextHubTransaction<List<NanoAppState>> queryNanoApps(
@NonNull ContextHubInfo hubInfo) {
- Preconditions.checkNotNull(hubInfo, "ContextHubInfo cannot be null");
+ Objects.requireNonNull(hubInfo, "ContextHubInfo cannot be null");
ContextHubTransaction<List<NanoAppState>> transaction =
new ContextHubTransaction<>(ContextHubTransaction.TYPE_QUERY_NANOAPPS);
@@ -729,9 +728,9 @@
@NonNull public ContextHubClient createClient(
@NonNull ContextHubInfo hubInfo, @NonNull ContextHubClientCallback callback,
@NonNull @CallbackExecutor Executor executor) {
- Preconditions.checkNotNull(callback, "Callback cannot be null");
- Preconditions.checkNotNull(hubInfo, "ContextHubInfo cannot be null");
- Preconditions.checkNotNull(executor, "Executor cannot be null");
+ Objects.requireNonNull(callback, "Callback cannot be null");
+ Objects.requireNonNull(hubInfo, "ContextHubInfo cannot be null");
+ Objects.requireNonNull(executor, "Executor cannot be null");
ContextHubClient client = new ContextHubClient(hubInfo, false /* persistent */);
IContextHubClientCallback clientInterface = createClientCallback(
@@ -808,8 +807,8 @@
@RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE)
@NonNull public ContextHubClient createClient(
@NonNull ContextHubInfo hubInfo, @NonNull PendingIntent pendingIntent, long nanoAppId) {
- Preconditions.checkNotNull(pendingIntent);
- Preconditions.checkNotNull(hubInfo);
+ Objects.requireNonNull(pendingIntent);
+ Objects.requireNonNull(hubInfo);
ContextHubClient client = new ContextHubClient(hubInfo, true /* persistent */);
diff --git a/core/java/android/hardware/location/ContextHubTransaction.java b/core/java/android/hardware/location/ContextHubTransaction.java
index bc7efef..d11e0a9 100644
--- a/core/java/android/hardware/location/ContextHubTransaction.java
+++ b/core/java/android/hardware/location/ContextHubTransaction.java
@@ -22,10 +22,9 @@
import android.os.Handler;
import android.os.HandlerExecutor;
-import com.android.internal.util.Preconditions;
-
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
+import java.util.Objects;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
@@ -291,8 +290,8 @@
@NonNull ContextHubTransaction.OnCompleteListener<T> listener,
@NonNull @CallbackExecutor Executor executor) {
synchronized (this) {
- Preconditions.checkNotNull(listener, "OnCompleteListener cannot be null");
- Preconditions.checkNotNull(executor, "Executor cannot be null");
+ Objects.requireNonNull(listener, "OnCompleteListener cannot be null");
+ Objects.requireNonNull(executor, "Executor cannot be null");
if (mListener != null) {
throw new IllegalStateException(
"Cannot set ContextHubTransaction listener multiple times");
@@ -340,7 +339,7 @@
*/
/* package */ void setResponse(ContextHubTransaction.Response<T> response) {
synchronized (this) {
- Preconditions.checkNotNull(response, "Response cannot be null");
+ Objects.requireNonNull(response, "Response cannot be null");
if (mIsResponseSet) {
throw new IllegalStateException(
"Cannot set response of ContextHubTransaction multiple times");
diff --git a/core/java/android/hardware/location/NanoApp.java b/core/java/android/hardware/location/NanoApp.java
index 6a734f3..242c9e2 100644
--- a/core/java/android/hardware/location/NanoApp.java
+++ b/core/java/android/hardware/location/NanoApp.java
@@ -21,7 +21,7 @@
import android.os.Parcelable;
import android.util.Log;
-import com.android.internal.util.Preconditions;
+import java.util.Objects;
/** A class describing nano apps.
* A nano app is a piece of executable code that can be
@@ -198,12 +198,12 @@
* needed Sensors
*/
public void setNeededSensors(int[] neededSensors) {
- Preconditions.checkNotNull(neededSensors, "neededSensors must not be null");
+ Objects.requireNonNull(neededSensors, "neededSensors must not be null");
mNeededSensors = neededSensors;
}
public void setOutputEvents(int[] outputEvents) {
- Preconditions.checkNotNull(outputEvents, "outputEvents must not be null");
+ Objects.requireNonNull(outputEvents, "outputEvents must not be null");
mOutputEvents = outputEvents;
}
@@ -213,7 +213,7 @@
* @param appBinary generated events
*/
public void setAppBinary(byte[] appBinary) {
- Preconditions.checkNotNull(appBinary, "appBinary must not be null");
+ Objects.requireNonNull(appBinary, "appBinary must not be null");
mAppBinary = appBinary;
}
diff --git a/core/java/android/hardware/usb/UsbAccessory.java b/core/java/android/hardware/usb/UsbAccessory.java
index a76e4ad..a725205 100644
--- a/core/java/android/hardware/usb/UsbAccessory.java
+++ b/core/java/android/hardware/usb/UsbAccessory.java
@@ -24,6 +24,7 @@
import android.os.RemoteException;
import com.android.internal.util.Preconditions;
+import java.util.Objects;
/**
* A class representing a USB accessory, which is an external hardware component
@@ -79,8 +80,8 @@
public UsbAccessory(@NonNull String manufacturer, @NonNull String model,
@Nullable String description, @Nullable String version, @Nullable String uri,
@NonNull IUsbSerialReader serialNumberReader) {
- mManufacturer = Preconditions.checkNotNull(manufacturer);
- mModel = Preconditions.checkNotNull(model);
+ mManufacturer = Objects.requireNonNull(manufacturer);
+ mModel = Objects.requireNonNull(model);
mDescription = description;
mVersion = version;
mUri = uri;
diff --git a/core/java/android/hardware/usb/UsbDevice.java b/core/java/android/hardware/usb/UsbDevice.java
index ee2e262..67e05c8 100644
--- a/core/java/android/hardware/usb/UsbDevice.java
+++ b/core/java/android/hardware/usb/UsbDevice.java
@@ -25,6 +25,7 @@
import android.os.RemoteException;
import com.android.internal.util.Preconditions;
+import java.util.Objects;
/**
* This class represents a USB device attached to the android device with the android device
@@ -81,7 +82,7 @@
@NonNull IUsbSerialReader serialNumberReader,
boolean hasAudioPlayback, boolean hasAudioCapture, boolean hasMidi,
boolean hasVideoPlayback, boolean hasVideoCapture) {
- mName = Preconditions.checkNotNull(name);
+ mName = Objects.requireNonNull(name);
mVendorId = vendorId;
mProductId = productId;
mClass = Class;
@@ -91,7 +92,7 @@
mProductName = productName;
mVersion = Preconditions.checkStringNotEmpty(version);
mConfigurations = Preconditions.checkArrayElementsNotNull(configurations, "configurations");
- mSerialNumberReader = Preconditions.checkNotNull(serialNumberReader);
+ mSerialNumberReader = Objects.requireNonNull(serialNumberReader);
mHasAudioPlayback = hasAudioPlayback;
mHasAudioCapture = hasAudioCapture;
mHasMidi = hasMidi;
@@ -441,7 +442,7 @@
@Nullable String serialNumber,
boolean hasAudioPlayback, boolean hasAudioCapture, boolean hasMidi,
boolean hasVideoPlayback, boolean hasVideoCapture) {
- mName = Preconditions.checkNotNull(name);
+ mName = Objects.requireNonNull(name);
mVendorId = vendorId;
mProductId = productId;
mClass = Class;
diff --git a/core/java/android/hardware/usb/UsbPort.java b/core/java/android/hardware/usb/UsbPort.java
index 506230e..274e23f 100644
--- a/core/java/android/hardware/usb/UsbPort.java
+++ b/core/java/android/hardware/usb/UsbPort.java
@@ -42,6 +42,8 @@
import com.android.internal.util.Preconditions;
+import java.util.Objects;
+
/**
* Represents a physical USB port and describes its characteristics.
*
@@ -67,7 +69,7 @@
int supportedContaminantProtectionModes,
boolean supportsEnableContaminantPresenceProtection,
boolean supportsEnableContaminantPresenceDetection) {
- Preconditions.checkNotNull(id);
+ Objects.requireNonNull(id);
Preconditions.checkFlagsArgument(supportedModes,
MODE_DFP | MODE_UFP | MODE_AUDIO_ACCESSORY | MODE_DEBUG_ACCESSORY);
diff --git a/core/java/android/hardware/usb/UsbRequest.java b/core/java/android/hardware/usb/UsbRequest.java
index cc4ba08..d464ab5 100644
--- a/core/java/android/hardware/usb/UsbRequest.java
+++ b/core/java/android/hardware/usb/UsbRequest.java
@@ -27,6 +27,7 @@
import java.nio.BufferOverflowException;
import java.nio.ByteBuffer;
+import java.util.Objects;
/**
* A class representing USB request packet.
@@ -96,7 +97,7 @@
*/
public boolean initialize(UsbDeviceConnection connection, UsbEndpoint endpoint) {
mEndpoint = endpoint;
- mConnection = Preconditions.checkNotNull(connection, "connection");
+ mConnection = Objects.requireNonNull(connection, "connection");
boolean wasInitialized = native_init(connection, endpoint.getAddress(),
endpoint.getAttributes(), endpoint.getMaxPacketSize(), endpoint.getInterval());
diff --git a/media/java/android/media/IMediaRoute2ProviderClient.aidl b/media/java/android/media/IMediaRoute2ProviderClient.aidl
index 6a763c5..b1f93a3 100644
--- a/media/java/android/media/IMediaRoute2ProviderClient.aidl
+++ b/media/java/android/media/IMediaRoute2ProviderClient.aidl
@@ -25,6 +25,7 @@
* @hide
*/
oneway interface IMediaRoute2ProviderClient {
- void updateProviderInfo(in MediaRoute2ProviderInfo info);
+ void updateState(in MediaRoute2ProviderInfo providerInfo,
+ in List<RouteSessionInfo> sessionInfos);
void notifySessionCreated(in @nullable RouteSessionInfo sessionInfo, long requestId);
}
diff --git a/media/java/android/media/IMediaRouterService.aidl b/media/java/android/media/IMediaRouterService.aidl
index 86fa20f..e89fc1e 100644
--- a/media/java/android/media/IMediaRouterService.aidl
+++ b/media/java/android/media/IMediaRouterService.aidl
@@ -22,6 +22,7 @@
import android.media.IMediaRouterClient;
import android.media.MediaRoute2Info;
import android.media.MediaRouterClientState;
+import android.media.RouteSessionInfo;
/**
* {@hide}
@@ -63,4 +64,6 @@
in MediaRoute2Info route, int volume);
void requestUpdateVolume2Manager(IMediaRouter2Manager manager,
in MediaRoute2Info route, int direction);
+
+ List<RouteSessionInfo> getActiveSessions(IMediaRouter2Manager manager);
}
diff --git a/media/java/android/media/MediaRoute2Info.java b/media/java/android/media/MediaRoute2Info.java
index d919d78..506d616 100644
--- a/media/java/android/media/MediaRoute2Info.java
+++ b/media/java/android/media/MediaRoute2Info.java
@@ -195,11 +195,15 @@
private String createUniqueId() {
String uniqueId = null;
if (mProviderId != null) {
- uniqueId = mProviderId + ":" + mId;
+ uniqueId = toUniqueId(mProviderId, mId);
}
return uniqueId;
}
+ static String toUniqueId(String providerId, String routeId) {
+ return providerId + ":" + routeId;
+ }
+
/**
* Returns true if the route info has all of the required field.
* A route info only obtained from {@link com.android.server.media.MediaRouterService}
diff --git a/media/java/android/media/MediaRoute2ProviderService.java b/media/java/android/media/MediaRoute2ProviderService.java
index d3f47e9..9b44c6e 100644
--- a/media/java/android/media/MediaRoute2ProviderService.java
+++ b/media/java/android/media/MediaRoute2ProviderService.java
@@ -37,6 +37,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
+import java.util.concurrent.atomic.AtomicBoolean;
/**
* @hide
@@ -48,6 +49,7 @@
private final Handler mHandler;
private final Object mSessionLock = new Object();
+ private final AtomicBoolean mStatePublishScheduled = new AtomicBoolean(false);
private ProviderStub mStub;
private IMediaRoute2ProviderClient mClient;
private MediaRoute2ProviderInfo mProviderInfo;
@@ -132,20 +134,22 @@
*/
public final void updateSessionInfo(@NonNull RouteSessionInfo sessionInfo) {
Objects.requireNonNull(sessionInfo, "sessionInfo must not be null");
- int sessionId = sessionInfo.getSessionId();
- //TODO: notify updated session info
+ int sessionId = sessionInfo.getSessionId();
+ if (sessionInfo.getSelectedRoutes().isEmpty()) {
+ releaseSession(sessionId);
+ return;
+ }
synchronized (mSessionLock) {
if (mSessionInfo.containsKey(sessionId)) {
mSessionInfo.put(sessionId, sessionInfo);
+ schedulePublishState();
} else {
Log.w(TAG, "Ignoring unknown session info.");
+ return;
}
}
- if (sessionInfo.getSelectedRoutes().isEmpty()) {
- releaseSession(sessionId);
- }
}
/**
@@ -169,6 +173,7 @@
}
mSessionInfo.put(sessionInfo.getSessionId(), sessionInfo);
}
+ schedulePublishState();
}
if (mClient == null) {
@@ -192,11 +197,12 @@
//TODO: notify media router service of release.
RouteSessionInfo sessionInfo;
synchronized (mSessionLock) {
- sessionInfo = mSessionInfo.put(sessionId, null);
+ sessionInfo = mSessionInfo.remove(sessionId);
}
if (sessionInfo != null) {
mHandler.sendMessage(obtainMessage(
MediaRoute2ProviderService::onDestroySession, this, sessionId, sessionInfo));
+ schedulePublishState();
}
}
@@ -268,23 +274,37 @@
/**
* Updates provider info and publishes routes and session info.
*/
- public final void updateProviderInfo(MediaRoute2ProviderInfo info) {
- mProviderInfo = info;
- publishState();
+ public final void updateProviderInfo(@NonNull MediaRoute2ProviderInfo providerInfo) {
+ mProviderInfo = Objects.requireNonNull(providerInfo, "providerInfo must not be null");
+ schedulePublishState();
}
void setClient(IMediaRoute2ProviderClient client) {
mClient = client;
- publishState();
+ schedulePublishState();
}
- void publishState() {
- //TODO: sends session info
+ void schedulePublishState() {
+ if (mStatePublishScheduled.compareAndSet(false, true)) {
+ mHandler.post(this::publishState);
+ }
+ }
+
+ private void publishState() {
+ if (!mStatePublishScheduled.compareAndSet(true, false)) {
+ return;
+ }
+
if (mClient == null) {
return;
}
+
+ List<RouteSessionInfo> sessionInfos;
+ synchronized (mSessionLock) {
+ sessionInfos = new ArrayList<>(mSessionInfo.values());
+ }
try {
- mClient.updateProviderInfo(mProviderInfo);
+ mClient.updateState(mProviderInfo, sessionInfos);
} catch (RemoteException ex) {
Log.w(TAG, "Failed to send onProviderInfoUpdated");
}
diff --git a/media/java/android/media/MediaRouter2.java b/media/java/android/media/MediaRouter2.java
index 046a8bb..600e630 100644
--- a/media/java/android/media/MediaRouter2.java
+++ b/media/java/android/media/MediaRouter2.java
@@ -110,7 +110,7 @@
private final String mPackageName;
@GuardedBy("sLock")
- private final Map<String, MediaRoute2Info> mRoutes = new HashMap<>();
+ final Map<String, MediaRoute2Info> mRoutes = new HashMap<>();
@GuardedBy("sLock")
private List<String> mControlCategories = Collections.emptyList();
@@ -678,8 +678,6 @@
* A class to control media route session in media route provider.
* For example, selecting/deselcting/transferring routes to session can be done through this
* class. Instances are created by {@link MediaRouter2}.
- *
- * @hide
*/
public final class RouteSessionController {
private final Object mLock = new Object();
@@ -724,42 +722,42 @@
}
/**
- * @return the unmodifiable list of IDs of currently selected routes
+ * @return the unmodifiable list of currently selected routes
*/
@NonNull
- public List<String> getSelectedRoutes() {
+ public List<MediaRoute2Info> getSelectedRoutes() {
synchronized (mLock) {
- return Collections.unmodifiableList(mSessionInfo.getSelectedRoutes());
+ return getRoutesWithIdsLocked(mSessionInfo.getSelectedRoutes());
}
}
/**
- * @return the unmodifiable list of IDs of selectable routes for the session.
+ * @return the unmodifiable list of selectable routes for the session.
*/
@NonNull
- public List<String> getSelectableRoutes() {
+ public List<MediaRoute2Info> getSelectableRoutes() {
synchronized (mLock) {
- return Collections.unmodifiableList(mSessionInfo.getSelectableRoutes());
+ return getRoutesWithIdsLocked(mSessionInfo.getSelectableRoutes());
}
}
/**
- * @return the unmodifiable list of IDs of deselectable routes for the session.
+ * @return the unmodifiable list of deselectable routes for the session.
*/
@NonNull
- public List<String> getDeselectableRoutes() {
+ public List<MediaRoute2Info> getDeselectableRoutes() {
synchronized (mLock) {
- return Collections.unmodifiableList(mSessionInfo.getDeselectableRoutes());
+ return getRoutesWithIdsLocked(mSessionInfo.getDeselectableRoutes());
}
}
/**
- * @return the unmodifiable list of IDs of transferrable routes for the session.
+ * @return the unmodifiable list of transferrable routes for the session.
*/
@NonNull
- public List<String> getTransferrableRoutes() {
+ public List<MediaRoute2Info> getTransferrableRoutes() {
synchronized (mLock) {
- return Collections.unmodifiableList(mSessionInfo.getTransferrableRoutes());
+ return getRoutesWithIdsLocked(mSessionInfo.getTransferrableRoutes());
}
}
@@ -784,7 +782,7 @@
* @see #getSelectedRoutes()
* @see SessionCallback#onSessionInfoChanged
*/
- public void selectRoute(MediaRoute2Info route) {
+ public void selectRoute(@NonNull MediaRoute2Info route) {
// TODO: Implement this when the actual connection logic is implemented.
}
@@ -796,7 +794,7 @@
* @see #getSelectedRoutes()
* @see SessionCallback#onSessionInfoChanged
*/
- public void deselectRoute(MediaRoute2Info route) {
+ public void deselectRoute(@NonNull MediaRoute2Info route) {
// TODO: Implement this when the actual connection logic is implemented.
}
@@ -817,6 +815,20 @@
}
// TODO: Use stopMedia variable when the actual connection logic is implemented.
}
+
+ private List<MediaRoute2Info> getRoutesWithIdsLocked(List<String> routeIds) {
+ List<MediaRoute2Info> routes = new ArrayList<>();
+ synchronized (mLock) {
+ for (String routeId : routeIds) {
+ MediaRoute2Info route = mRoutes.get(
+ MediaRoute2Info.toUniqueId(mSessionInfo.mProviderId, routeId));
+ if (route != null) {
+ routes.add(route);
+ }
+ }
+ }
+ return Collections.unmodifiableList(routes);
+ }
}
final class RouteCallbackRecord {
diff --git a/media/java/android/media/MediaRouter2Manager.java b/media/java/android/media/MediaRouter2Manager.java
index 4213dd3..2e68e42 100644
--- a/media/java/android/media/MediaRouter2Manager.java
+++ b/media/java/android/media/MediaRouter2Manager.java
@@ -176,7 +176,18 @@
}
@NonNull
- public List<RouteSessionInfo> getRouteSessions() {
+ public List<RouteSessionInfo> getActiveSessions() {
+ Client client;
+ synchronized (sLock) {
+ client = mClient;
+ }
+ if (client != null) {
+ try {
+ return mMediaRouterService.getActiveSessions(client);
+ } catch (RemoteException ex) {
+ Log.e(TAG, "Unable to get sessions. Service probably died.", ex);
+ }
+ }
return Collections.emptyList();
}
diff --git a/media/tests/MediaRouter/src/com/android/mediaroutertest/MediaRouter2Test.java b/media/tests/MediaRouter/src/com/android/mediaroutertest/MediaRouter2Test.java
index 6e79dd1..0c4c437 100644
--- a/media/tests/MediaRouter/src/com/android/mediaroutertest/MediaRouter2Test.java
+++ b/media/tests/MediaRouter/src/com/android/mediaroutertest/MediaRouter2Test.java
@@ -260,7 +260,7 @@
@Override
public void onSessionCreated(RouteSessionController controller) {
assertNotNull(controller);
- assertTrue(controller.getSelectedRoutes().contains(ROUTE_ID1));
+ assertTrue(createRouteMap(controller.getSelectedRoutes()).containsKey(ROUTE_ID1));
assertTrue(TextUtils.equals(CATEGORY_SAMPLE, controller.getControlCategory()));
successLatch.countDown();
}
@@ -384,8 +384,8 @@
RouteSessionController controller2 = createdControllers.get(1);
assertNotEquals(controller1.getSessionId(), controller2.getSessionId());
- assertTrue(controller1.getSelectedRoutes().contains(ROUTE_ID1));
- assertTrue(controller2.getSelectedRoutes().contains(ROUTE_ID2));
+ assertTrue(createRouteMap(controller1.getSelectedRoutes()).containsKey(ROUTE_ID1));
+ assertTrue(createRouteMap(controller2.getSelectedRoutes()).containsKey(ROUTE_ID2));
assertTrue(TextUtils.equals(CATEGORY_SAMPLE, controller1.getControlCategory()));
assertTrue(TextUtils.equals(CATEGORY_SAMPLE, controller2.getControlCategory()));
} finally {
diff --git a/media/tests/MediaRouter/src/com/android/mediaroutertest/MediaRouterManagerTest.java b/media/tests/MediaRouter/src/com/android/mediaroutertest/MediaRouterManagerTest.java
index cd3b50a..768716d 100644
--- a/media/tests/MediaRouter/src/com/android/mediaroutertest/MediaRouterManagerTest.java
+++ b/media/tests/MediaRouter/src/com/android/mediaroutertest/MediaRouterManagerTest.java
@@ -280,12 +280,12 @@
});
//TODO: it fails due to not releasing session
- assertEquals(0, mManager.getActiveRoutes().size());
+ assertEquals(0, mManager.getActiveSessions().size());
mManager.selectRoute(mPackageName, routes.get(ROUTE_ID1));
latch.await(TIMEOUT_MS, TimeUnit.MILLISECONDS);
- assertEquals(1, mManager.getActiveRoutes().size());
+ assertEquals(1, mManager.getActiveSessions().size());
//TODO: release the session
/*
diff --git a/packages/SystemUI/res/values-television/config.xml b/packages/SystemUI/res/values-television/config.xml
index 27db294..4cc5a67 100644
--- a/packages/SystemUI/res/values-television/config.xml
+++ b/packages/SystemUI/res/values-television/config.xml
@@ -22,6 +22,7 @@
<resources>
<!-- SystemUI Services: The classes of the stuff to start. -->
<string-array name="config_systemUIServiceComponents" translatable="false">
+ <item>com.android.systemui.util.NotificationChannels</item>
<item>com.android.systemui.volume.VolumeUI</item>
<item>com.android.systemui.stackdivider.Divider</item>
<item>com.android.systemui.statusbar.tv.TvStatusBar</item>
diff --git a/services/core/java/com/android/server/integrity/AppIntegrityManagerServiceImpl.java b/services/core/java/com/android/server/integrity/AppIntegrityManagerServiceImpl.java
index e5292a0..f3d60f5 100644
--- a/services/core/java/com/android/server/integrity/AppIntegrityManagerServiceImpl.java
+++ b/services/core/java/com/android/server/integrity/AppIntegrityManagerServiceImpl.java
@@ -225,11 +225,13 @@
builder.setIsPreInstalled(isSystemApp(packageName));
AppInstallMetadata appInstallMetadata = builder.build();
+ Map<String, String> allowedInstallers = getAllowedInstallers(packageInfo);
- Slog.i(TAG, "To be verified: " + appInstallMetadata);
+ Slog.i(
+ TAG,
+ "To be verified: " + appInstallMetadata + " installers " + allowedInstallers);
IntegrityCheckResult result =
- mEvaluationEngine.evaluate(
- appInstallMetadata, getAllowedInstallers(packageInfo));
+ mEvaluationEngine.evaluate(appInstallMetadata, allowedInstallers);
Slog.i(
TAG,
"Integrity check result: "
@@ -371,7 +373,7 @@
String[] packageAndCert =
packageCertPair.split(INSTALLER_PACKAGE_CERT_DELIMITER);
if (packageAndCert.length == 2) {
- String packageName = packageAndCert[0];
+ String packageName = getPackageNameNormalized(packageAndCert[0]);
String cert = packageAndCert[1];
packageCertMap.put(packageName, cert);
}
@@ -379,21 +381,9 @@
}
}
- Slog.i("DEBUG", "allowed installers map " + packageCertMap);
return packageCertMap;
}
- private boolean getPreInstalled(String packageName) {
- try {
- PackageInfo existingPackageInfo =
- mContext.getPackageManager().getPackageInfo(packageName, 0);
- return existingPackageInfo.applicationInfo != null
- && existingPackageInfo.applicationInfo.isSystemApp();
- } catch (PackageManager.NameNotFoundException e) {
- return false;
- }
- }
-
private static Signature getSignature(@NonNull PackageInfo packageInfo) {
if (packageInfo.signatures == null || packageInfo.signatures.length < 1) {
throw new IllegalArgumentException("Package signature not found in " + packageInfo);
@@ -463,7 +453,8 @@
PackageInfo basePackageInfo =
mContext.getPackageManager()
.getPackageArchiveInfo(
- baseFile.getAbsolutePath(), PackageManager.GET_SIGNATURES);
+ baseFile.getAbsolutePath(),
+ PackageManager.GET_SIGNATURES | PackageManager.GET_META_DATA);
if (basePackageInfo == null) {
for (File apkFile : multiApkDirectory.listFiles()) {
@@ -477,7 +468,8 @@
mContext.getPackageManager()
.getPackageArchiveInfo(
apkFile.getAbsolutePath(),
- PackageManager.GET_SIGNING_CERTIFICATES);
+ PackageManager.GET_SIGNING_CERTIFICATES
+ | PackageManager.GET_META_DATA);
if (basePackageInfo != null) {
Slog.i(TAG, "Found package info from " + apkFile);
break;
diff --git a/services/core/java/com/android/server/integrity/IntegrityFileManager.java b/services/core/java/com/android/server/integrity/IntegrityFileManager.java
index bdf0279..e224724 100644
--- a/services/core/java/com/android/server/integrity/IntegrityFileManager.java
+++ b/services/core/java/com/android/server/integrity/IntegrityFileManager.java
@@ -24,14 +24,14 @@
import com.android.internal.annotations.VisibleForTesting;
import com.android.server.integrity.model.RuleMetadata;
-import com.android.server.integrity.parser.RuleBinaryParser;
import com.android.server.integrity.parser.RuleMetadataParser;
import com.android.server.integrity.parser.RuleParseException;
import com.android.server.integrity.parser.RuleParser;
-import com.android.server.integrity.serializer.RuleBinarySerializer;
+import com.android.server.integrity.parser.RuleXmlParser;
import com.android.server.integrity.serializer.RuleMetadataSerializer;
import com.android.server.integrity.serializer.RuleSerializeException;
import com.android.server.integrity.serializer.RuleSerializer;
+import com.android.server.integrity.serializer.RuleXmlSerializer;
import java.io.File;
import java.io.FileInputStream;
@@ -75,8 +75,8 @@
private IntegrityFileManager() {
this(
- new RuleBinaryParser(),
- new RuleBinarySerializer(),
+ new RuleXmlParser(),
+ new RuleXmlSerializer(),
Environment.getDataSystemDirectory());
}
diff --git a/services/core/java/com/android/server/integrity/engine/RuleEvaluationEngine.java b/services/core/java/com/android/server/integrity/engine/RuleEvaluationEngine.java
index 0ea6efc..07eacbf 100644
--- a/services/core/java/com/android/server/integrity/engine/RuleEvaluationEngine.java
+++ b/services/core/java/com/android/server/integrity/engine/RuleEvaluationEngine.java
@@ -17,15 +17,21 @@
package com.android.server.integrity.engine;
import android.content.integrity.AppInstallMetadata;
+import android.content.integrity.AtomicFormula;
+import android.content.integrity.CompoundFormula;
+import android.content.integrity.Formula;
import android.content.integrity.Rule;
import android.util.Slog;
+import com.android.internal.annotations.VisibleForTesting;
import com.android.server.integrity.IntegrityFileManager;
import com.android.server.integrity.model.IntegrityCheckResult;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
/**
* The engine used to evaluate rules against app installs.
@@ -42,7 +48,8 @@
private final IntegrityFileManager mIntegrityFileManager;
- private RuleEvaluationEngine(IntegrityFileManager integrityFileManager) {
+ @VisibleForTesting
+ RuleEvaluationEngine(IntegrityFileManager integrityFileManager) {
mIntegrityFileManager = integrityFileManager;
}
@@ -64,6 +71,7 @@
public IntegrityCheckResult evaluate(
AppInstallMetadata appInstallMetadata, Map<String, String> allowedInstallers) {
List<Rule> rules = loadRules(appInstallMetadata);
+ allowedInstallersRule(allowedInstallers).ifPresent(rules::add);
return RuleEvaluator.evaluateRules(rules, appInstallMetadata);
}
@@ -75,4 +83,42 @@
return new ArrayList<>();
}
}
+
+ private static Optional<Rule> allowedInstallersRule(Map<String, String> allowedInstallers) {
+ if (allowedInstallers.isEmpty()) {
+ return Optional.empty();
+ }
+
+ List<Formula> formulas = new ArrayList<>(allowedInstallers.size());
+ allowedInstallers.forEach(
+ (installer, cert) -> {
+ formulas.add(allowedInstallerFormula(installer, cert));
+ });
+
+ // We need this special case since OR-formulas require at least two operands.
+ Formula allInstallersFormula =
+ formulas.size() == 1
+ ? formulas.get(0)
+ : new CompoundFormula(CompoundFormula.OR, formulas);
+
+ return Optional.of(
+ new Rule(
+ new CompoundFormula(
+ CompoundFormula.NOT, Arrays.asList(allInstallersFormula)),
+ Rule.DENY));
+ }
+
+ private static Formula allowedInstallerFormula(String installer, String cert) {
+ return new CompoundFormula(
+ CompoundFormula.AND,
+ Arrays.asList(
+ new AtomicFormula.StringAtomicFormula(
+ AtomicFormula.INSTALLER_NAME,
+ installer,
+ /* isHashedValue= */ false),
+ new AtomicFormula.StringAtomicFormula(
+ AtomicFormula.INSTALLER_CERTIFICATE,
+ cert,
+ /* isHashedValue= */ false)));
+ }
}
diff --git a/services/core/java/com/android/server/integrity/engine/RuleEvaluator.java b/services/core/java/com/android/server/integrity/engine/RuleEvaluator.java
index ee51d4f..b1c20d2 100644
--- a/services/core/java/com/android/server/integrity/engine/RuleEvaluator.java
+++ b/services/core/java/com/android/server/integrity/engine/RuleEvaluator.java
@@ -21,9 +21,6 @@
import android.annotation.NonNull;
import android.content.integrity.AppInstallMetadata;
-import android.content.integrity.AtomicFormula;
-import android.content.integrity.CompoundFormula;
-import android.content.integrity.Formula;
import android.content.integrity.Rule;
import android.util.Slog;
@@ -56,8 +53,7 @@
List<Rule> rules, AppInstallMetadata appInstallMetadata) {
List<Rule> matchedRules = new ArrayList<>();
for (Rule rule : rules) {
- if (isConjunctionOfFormulas(rule.getFormula())
- && rule.getFormula().isSatisfied(appInstallMetadata)) {
+ if (rule.getFormula().isSatisfied(appInstallMetadata)) {
matchedRules.add(rule);
}
}
@@ -81,25 +77,4 @@
}
return denied ? IntegrityCheckResult.deny(denyRule) : IntegrityCheckResult.allow();
}
-
- private static boolean isConjunctionOfFormulas(Formula formula) {
- if (formula == null) {
- return false;
- }
- if (isAtomicFormula(formula)) {
- return true;
- }
- CompoundFormula compoundFormula = (CompoundFormula) formula;
- return compoundFormula.getConnector() == CompoundFormula.AND
- && compoundFormula.getFormulas().stream().allMatch(RuleEvaluator::isAtomicFormula);
- }
-
- private static boolean isAtomicFormula(Formula formula) {
- if (formula instanceof AtomicFormula) {
- return true;
- }
- CompoundFormula compoundFormula = (CompoundFormula) formula;
- return compoundFormula.getConnector() == CompoundFormula.NOT
- && compoundFormula.getFormulas().get(0) instanceof AtomicFormula;
- }
}
diff --git a/services/core/java/com/android/server/integrity/model/BitOutputStream.java b/services/core/java/com/android/server/integrity/model/BitOutputStream.java
index ecb9189..b8ea041 100644
--- a/services/core/java/com/android/server/integrity/model/BitOutputStream.java
+++ b/services/core/java/com/android/server/integrity/model/BitOutputStream.java
@@ -42,7 +42,7 @@
int offset = 1 << (numOfBits - 1);
while (numOfBits-- > 0) {
mBitSet.set(mIndex, (value & offset) != 0);
- offset >>= 1;
+ offset >>>= 1;
mIndex++;
}
}
diff --git a/services/core/java/com/android/server/integrity/model/ComponentBitSize.java b/services/core/java/com/android/server/integrity/model/ComponentBitSize.java
index d47ce2d..6ec2d5f 100644
--- a/services/core/java/com/android/server/integrity/model/ComponentBitSize.java
+++ b/services/core/java/com/android/server/integrity/model/ComponentBitSize.java
@@ -29,7 +29,7 @@
public static final int OPERATOR_BITS = 3;
public static final int CONNECTOR_BITS = 2;
public static final int SEPARATOR_BITS = 2;
- public static final int VALUE_SIZE_BITS = 5;
+ public static final int VALUE_SIZE_BITS = 6;
public static final int IS_HASHED_BITS = 1;
public static final int ATOMIC_FORMULA_START = 0;
diff --git a/services/core/java/com/android/server/integrity/serializer/RuleBinarySerializer.java b/services/core/java/com/android/server/integrity/serializer/RuleBinarySerializer.java
index cb83765..25defb0 100644
--- a/services/core/java/com/android/server/integrity/serializer/RuleBinarySerializer.java
+++ b/services/core/java/com/android/server/integrity/serializer/RuleBinarySerializer.java
@@ -179,6 +179,9 @@
private void serializeStringValue(
String value, boolean isHashedValue, BitOutputStream bitOutputStream) {
+ if (value == null) {
+ throw new IllegalArgumentException("String value can not be null.");
+ }
byte[] valueBytes = getBytesForString(value, isHashedValue);
bitOutputStream.setNext(isHashedValue);
diff --git a/services/core/java/com/android/server/media/MediaRoute2Provider.java b/services/core/java/com/android/server/media/MediaRoute2Provider.java
index a30dd98..3cc18b6 100644
--- a/services/core/java/com/android/server/media/MediaRoute2Provider.java
+++ b/services/core/java/com/android/server/media/MediaRoute2Provider.java
@@ -24,6 +24,9 @@
import android.media.MediaRoute2ProviderInfo;
import android.media.RouteSessionInfo;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
import java.util.Objects;
abstract class MediaRoute2Provider {
@@ -31,7 +34,8 @@
final String mUniqueId;
Callback mCallback;
- private MediaRoute2ProviderInfo mProviderInfo;
+ private volatile MediaRoute2ProviderInfo mProviderInfo;
+ private volatile List<RouteSessionInfo> mSessionInfos = Collections.emptyList();
MediaRoute2Provider(@NonNull ComponentName componentName) {
mComponentName = Objects.requireNonNull(componentName, "Component name must not be null.");
@@ -64,15 +68,29 @@
return mProviderInfo;
}
- void setAndNotifyProviderInfo(MediaRoute2ProviderInfo info) {
- //TODO: check if info is not updated
- if (info == null) {
+ @NonNull
+ public List<RouteSessionInfo> getSessionInfos() {
+ return mSessionInfos;
+ }
+
+ void setAndNotifyProviderState(MediaRoute2ProviderInfo providerInfo,
+ List<RouteSessionInfo> sessionInfos) {
+ if (providerInfo == null) {
mProviderInfo = null;
} else {
- mProviderInfo = new MediaRoute2ProviderInfo.Builder(info)
+ mProviderInfo = new MediaRoute2ProviderInfo.Builder(providerInfo)
.setUniqueId(mUniqueId)
.build();
}
+ List<RouteSessionInfo> sessionInfoWithProviderId = new ArrayList<RouteSessionInfo>();
+ for (RouteSessionInfo sessionInfo : sessionInfos) {
+ sessionInfoWithProviderId.add(
+ new RouteSessionInfo.Builder(sessionInfo)
+ .setProviderId(mUniqueId)
+ .build());
+ }
+ mSessionInfos = sessionInfoWithProviderId;
+
if (mCallback != null) {
mCallback.onProviderStateChanged(this);
}
diff --git a/services/core/java/com/android/server/media/MediaRoute2ProviderProxy.java b/services/core/java/com/android/server/media/MediaRoute2ProviderProxy.java
index 0fc0606..f9cfe7d 100644
--- a/services/core/java/com/android/server/media/MediaRoute2ProviderProxy.java
+++ b/services/core/java/com/android/server/media/MediaRoute2ProviderProxy.java
@@ -38,6 +38,8 @@
import java.io.PrintWriter;
import java.lang.ref.WeakReference;
+import java.util.Collections;
+import java.util.List;
import java.util.Objects;
/**
@@ -268,14 +270,15 @@
}
}
- private void onProviderInfoUpdated(Connection connection, MediaRoute2ProviderInfo info) {
+ private void onProviderStateUpdated(Connection connection,
+ MediaRoute2ProviderInfo providerInfo, List<RouteSessionInfo> sessionInfos) {
if (mActiveConnection != connection) {
return;
}
if (DEBUG) {
Slog.d(TAG, this + ": State changed ");
}
- setAndNotifyProviderInfo(info);
+ setAndNotifyProviderState(providerInfo, sessionInfos);
}
private void onSessionCreated(Connection connection, @Nullable RouteSessionInfo sessionInfo,
@@ -291,7 +294,7 @@
mConnectionReady = false;
mActiveConnection.dispose();
mActiveConnection = null;
- setAndNotifyProviderInfo(null);
+ setAndNotifyProviderState(null, Collections.emptyList());
}
}
@@ -397,8 +400,10 @@
mHandler.post(() -> onConnectionDied(Connection.this));
}
- void postProviderInfoUpdated(MediaRoute2ProviderInfo info) {
- mHandler.post(() -> onProviderInfoUpdated(Connection.this, info));
+ void postProviderStateUpdated(MediaRoute2ProviderInfo providerInfo,
+ List<RouteSessionInfo> sessionInfos) {
+ mHandler.post(() -> onProviderStateUpdated(Connection.this,
+ providerInfo, sessionInfos));
}
void postSessionCreated(@Nullable RouteSessionInfo sessionInfo, long requestId) {
@@ -419,10 +424,11 @@
}
@Override
- public void updateProviderInfo(MediaRoute2ProviderInfo info) {
+ public void updateState(MediaRoute2ProviderInfo providerInfo,
+ List<RouteSessionInfo> sessionInfos) {
Connection connection = mConnectionRef.get();
if (connection != null) {
- connection.postProviderInfoUpdated(info);
+ connection.postProviderStateUpdated(providerInfo, sessionInfos);
}
}
diff --git a/services/core/java/com/android/server/media/MediaRouter2ServiceImpl.java b/services/core/java/com/android/server/media/MediaRouter2ServiceImpl.java
index fd41b6f..d78879f 100644
--- a/services/core/java/com/android/server/media/MediaRouter2ServiceImpl.java
+++ b/services/core/java/com/android/server/media/MediaRouter2ServiceImpl.java
@@ -288,6 +288,18 @@
}
}
+ @NonNull
+ public List<RouteSessionInfo> getActiveSessions(IMediaRouter2Manager manager) {
+ final long token = Binder.clearCallingIdentity();
+ try {
+ synchronized (mLock) {
+ return getActiveSessionsLocked(manager);
+ }
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
+ }
+
//TODO: Review this is handling multi-user properly.
void switchUser() {
synchronized (mLock) {
@@ -523,6 +535,21 @@
}
}
+ private List<RouteSessionInfo> getActiveSessionsLocked(IMediaRouter2Manager manager) {
+ final IBinder binder = manager.asBinder();
+ ManagerRecord managerRecord = mAllManagerRecords.get(binder);
+
+ if (managerRecord == null) {
+ return Collections.emptyList();
+ }
+
+ List<RouteSessionInfo> sessionInfos = new ArrayList<>();
+ for (MediaRoute2Provider provider : managerRecord.mUserRecord.mHandler.mMediaProviders) {
+ sessionInfos.addAll(provider.getSessionInfos());
+ }
+ return sessionInfos;
+ }
+
private void initializeUserLocked(UserRecord userRecord) {
if (DEBUG) {
Slog.d(TAG, userRecord + ": Initialized");
@@ -731,6 +758,7 @@
this, provider, sessionInfo, requestId));
}
+ //TODO: notify session info updates
private void updateProvider(MediaRoute2Provider provider) {
int providerIndex = getProviderInfoIndex(provider.getUniqueId());
MediaRoute2ProviderInfo providerInfo = provider.getProviderInfo();
diff --git a/services/core/java/com/android/server/media/MediaRouterService.java b/services/core/java/com/android/server/media/MediaRouterService.java
index a51158b..8a0d232 100644
--- a/services/core/java/com/android/server/media/MediaRouterService.java
+++ b/services/core/java/com/android/server/media/MediaRouterService.java
@@ -39,6 +39,7 @@
import android.media.MediaRouterClientState;
import android.media.RemoteDisplayState;
import android.media.RemoteDisplayState.RemoteDisplayInfo;
+import android.media.RouteSessionInfo;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
@@ -523,6 +524,12 @@
mService2.requestUpdateVolume2Manager(manager, route, delta);
}
+ // Binder call
+ @Override
+ public List<RouteSessionInfo> getActiveSessions(IMediaRouter2Manager manager) {
+ return mService2.getActiveSessions(manager);
+ }
+
void restoreBluetoothA2dp() {
try {
boolean a2dpOn;
diff --git a/services/core/java/com/android/server/media/SystemMediaRoute2Provider.java b/services/core/java/com/android/server/media/SystemMediaRoute2Provider.java
index 8451662..263af70 100644
--- a/services/core/java/com/android/server/media/SystemMediaRoute2Provider.java
+++ b/services/core/java/com/android/server/media/SystemMediaRoute2Provider.java
@@ -35,6 +35,8 @@
import com.android.internal.R;
+import java.util.Collections;
+
/**
* Provides routes for local playbacks such as phone speaker, wired headset, or Bluetooth speakers.
*/
@@ -214,6 +216,6 @@
builder.addRoute(mBluetoothA2dpRoute);
}
builder.addRoute(mDefaultRoute);
- setAndNotifyProviderInfo(builder.build());
+ setAndNotifyProviderState(builder.build(), Collections.emptyList());
}
}
diff --git a/services/tests/servicestests/src/com/android/server/integrity/engine/RuleEvaluationEngineTest.java b/services/tests/servicestests/src/com/android/server/integrity/engine/RuleEvaluationEngineTest.java
new file mode 100644
index 0000000..d386487
--- /dev/null
+++ b/services/tests/servicestests/src/com/android/server/integrity/engine/RuleEvaluationEngineTest.java
@@ -0,0 +1,197 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.integrity.engine;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
+import android.content.integrity.AppInstallMetadata;
+import android.content.integrity.Rule;
+
+import com.android.server.integrity.IntegrityFileManager;
+import com.android.server.integrity.model.IntegrityCheckResult;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@RunWith(JUnit4.class)
+public class RuleEvaluationEngineTest {
+
+ private static final String INSTALLER_1 = "installer1";
+ private static final String INSTALLER_1_CERT = "installer1_cert";
+ private static final String INSTALLER_2 = "installer2";
+ private static final String INSTALLER_2_CERT = "installer2_cert";
+
+ private static final String RANDOM_INSTALLER = "random";
+ private static final String RANDOM_INSTALLER_CERT = "random_cert";
+
+ @Mock private IntegrityFileManager mIntegrityFileManager;
+
+ private RuleEvaluationEngine mEngine;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+
+ mEngine = new RuleEvaluationEngine(mIntegrityFileManager);
+
+ when(mIntegrityFileManager.readRules(any())).thenReturn(new ArrayList<>());
+ }
+
+ @Test
+ public void testAllowedInstallers_empty() {
+ Map<String, String> allowedInstallers = Collections.emptyMap();
+
+ assertEquals(
+ IntegrityCheckResult.Effect.ALLOW,
+ mEngine.evaluate(
+ getAppInstallMetadataBuilder()
+ .setInstallerName(INSTALLER_1)
+ .setInstallerCertificate(INSTALLER_1_CERT)
+ .build(),
+ allowedInstallers)
+ .getEffect());
+ assertEquals(
+ IntegrityCheckResult.Effect.ALLOW,
+ mEngine.evaluate(
+ getAppInstallMetadataBuilder()
+ .setInstallerName(INSTALLER_2)
+ .setInstallerCertificate(INSTALLER_2_CERT)
+ .build(),
+ allowedInstallers)
+ .getEffect());
+ assertEquals(
+ IntegrityCheckResult.Effect.ALLOW,
+ mEngine.evaluate(
+ getAppInstallMetadataBuilder()
+ .setInstallerName(RANDOM_INSTALLER)
+ .setInstallerCertificate(RANDOM_INSTALLER_CERT)
+ .build(),
+ allowedInstallers)
+ .getEffect());
+ }
+
+ @Test
+ public void testAllowedInstallers_oneElement() {
+ Map<String, String> allowedInstallers =
+ Collections.singletonMap(INSTALLER_1, INSTALLER_1_CERT);
+
+ assertEquals(
+ IntegrityCheckResult.Effect.ALLOW,
+ mEngine.evaluate(
+ getAppInstallMetadataBuilder()
+ .setInstallerName(INSTALLER_1)
+ .setInstallerCertificate(INSTALLER_1_CERT)
+ .build(),
+ allowedInstallers)
+ .getEffect());
+ assertEquals(
+ IntegrityCheckResult.Effect.DENY,
+ mEngine.evaluate(
+ getAppInstallMetadataBuilder()
+ .setInstallerName(RANDOM_INSTALLER)
+ .setInstallerCertificate(INSTALLER_1_CERT)
+ .build(),
+ allowedInstallers)
+ .getEffect());
+ assertEquals(
+ IntegrityCheckResult.Effect.DENY,
+ mEngine.evaluate(
+ getAppInstallMetadataBuilder()
+ .setInstallerName(INSTALLER_1)
+ .setInstallerCertificate(RANDOM_INSTALLER_CERT)
+ .build(),
+ allowedInstallers)
+ .getEffect());
+ assertEquals(
+ IntegrityCheckResult.Effect.DENY,
+ mEngine.evaluate(
+ getAppInstallMetadataBuilder()
+ .setInstallerName(RANDOM_INSTALLER)
+ .setInstallerCertificate(RANDOM_INSTALLER_CERT)
+ .build(),
+ allowedInstallers)
+ .getEffect());
+ }
+
+ @Test
+ public void testAllowedInstallers_multipleElement() {
+ List<Rule> rules = new ArrayList<>();
+ Map<String, String> allowedInstallers = new HashMap<>(2);
+ allowedInstallers.put(INSTALLER_1, INSTALLER_1_CERT);
+ allowedInstallers.put(INSTALLER_2, INSTALLER_2_CERT);
+
+ assertEquals(
+ IntegrityCheckResult.Effect.ALLOW,
+ mEngine.evaluate(
+ getAppInstallMetadataBuilder()
+ .setInstallerName(INSTALLER_1)
+ .setInstallerCertificate(INSTALLER_1_CERT)
+ .build(),
+ allowedInstallers)
+ .getEffect());
+ assertEquals(
+ IntegrityCheckResult.Effect.ALLOW,
+ mEngine.evaluate(
+ getAppInstallMetadataBuilder()
+ .setInstallerName(INSTALLER_2)
+ .setInstallerCertificate(INSTALLER_2_CERT)
+ .build(),
+ allowedInstallers)
+ .getEffect());
+ assertEquals(
+ IntegrityCheckResult.Effect.DENY,
+ mEngine.evaluate(
+ getAppInstallMetadataBuilder()
+ .setInstallerName(INSTALLER_1)
+ .setInstallerCertificate(INSTALLER_2_CERT)
+ .build(),
+ allowedInstallers)
+ .getEffect());
+ assertEquals(
+ IntegrityCheckResult.Effect.DENY,
+ mEngine.evaluate(
+ getAppInstallMetadataBuilder()
+ .setInstallerName(INSTALLER_2)
+ .setInstallerCertificate(INSTALLER_1_CERT)
+ .build(),
+ allowedInstallers)
+ .getEffect());
+ }
+
+ /** Returns a builder with all fields filled with some dummy data. */
+ private AppInstallMetadata.Builder getAppInstallMetadataBuilder() {
+ return new AppInstallMetadata.Builder()
+ .setPackageName("abc")
+ .setAppCertificate("abc")
+ .setInstallerCertificate("abc")
+ .setInstallerName("abc")
+ .setVersionCode(-1)
+ .setIsPreInstalled(true);
+ }
+}
diff --git a/services/tests/servicestests/src/com/android/server/integrity/parser/RuleBinaryParserTest.java b/services/tests/servicestests/src/com/android/server/integrity/parser/RuleBinaryParserTest.java
index 86778f5..9cc0ed8 100644
--- a/services/tests/servicestests/src/com/android/server/integrity/parser/RuleBinaryParserTest.java
+++ b/services/tests/servicestests/src/com/android/server/integrity/parser/RuleBinaryParserTest.java
@@ -305,7 +305,7 @@
@Test
public void testBinaryString_validAtomicFormula_hashedValue() throws Exception {
- String appCertificate = "test_cert";
+ String appCertificate = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
String ruleBits =
START_BIT
+ ATOMIC_FORMULA_START_BITS
diff --git a/services/tests/servicestests/src/com/android/server/integrity/serializer/RuleBinarySerializerTest.java b/services/tests/servicestests/src/com/android/server/integrity/serializer/RuleBinarySerializerTest.java
index 3c78c37..981db6a 100644
--- a/services/tests/servicestests/src/com/android/server/integrity/serializer/RuleBinarySerializerTest.java
+++ b/services/tests/servicestests/src/com/android/server/integrity/serializer/RuleBinarySerializerTest.java
@@ -334,7 +334,7 @@
@Test
public void testBinaryString_serializeValidAtomicFormula_hashedValue() throws Exception {
- String appCertificate = "test_cert";
+ String appCertificate = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
Rule rule =
new Rule(
new AtomicFormula.StringAtomicFormula(
diff --git a/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerService.java b/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerService.java
index 96d2df1..68b16f3 100644
--- a/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerService.java
+++ b/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerService.java
@@ -74,13 +74,13 @@
import com.android.internal.annotations.GuardedBy;
import com.android.internal.app.ISoundTriggerService;
-import com.android.internal.util.Preconditions;
import com.android.server.SystemService;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Map;
+import java.util.Objects;
import java.util.TreeMap;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
@@ -429,9 +429,9 @@
@Override
public int startRecognitionForService(ParcelUuid soundModelId, Bundle params,
ComponentName detectionService, SoundTrigger.RecognitionConfig config) {
- Preconditions.checkNotNull(soundModelId);
- Preconditions.checkNotNull(detectionService);
- Preconditions.checkNotNull(config);
+ Objects.requireNonNull(soundModelId);
+ Objects.requireNonNull(detectionService);
+ Objects.requireNonNull(config);
enforceCallingPermission(Manifest.permission.MANAGE_SOUND_TRIGGER);
diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java
index 404346f..e9db31b 100644
--- a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java
+++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java
@@ -76,7 +76,6 @@
import com.android.internal.content.PackageMonitor;
import com.android.internal.os.BackgroundThread;
import com.android.internal.util.DumpUtils;
-import com.android.internal.util.Preconditions;
import com.android.server.FgThread;
import com.android.server.LocalServices;
import com.android.server.SystemService;
@@ -89,6 +88,7 @@
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.List;
+import java.util.Objects;
import java.util.concurrent.Executor;
/**
@@ -117,11 +117,11 @@
mResolver = context.getContentResolver();
mDbHelper = new DatabaseHelper(context);
mServiceStub = new VoiceInteractionManagerServiceStub();
- mAmInternal = Preconditions.checkNotNull(
+ mAmInternal = Objects.requireNonNull(
LocalServices.getService(ActivityManagerInternal.class));
- mAtmInternal = Preconditions.checkNotNull(
+ mAtmInternal = Objects.requireNonNull(
LocalServices.getService(ActivityTaskManagerInternal.class));
- mUserManagerInternal = Preconditions.checkNotNull(
+ mUserManagerInternal = Objects.requireNonNull(
LocalServices.getService(UserManagerInternal.class));
PermissionManagerServiceInternal permissionManagerInternal = LocalServices.getService(
@@ -149,7 +149,7 @@
@Override
public void onBootPhase(int phase) {
if (PHASE_SYSTEM_SERVICES_READY == phase) {
- mShortcutServiceInternal = Preconditions.checkNotNull(
+ mShortcutServiceInternal = Objects.requireNonNull(
LocalServices.getService(ShortcutServiceInternal.class));
mSoundTriggerInternal = LocalServices.getService(SoundTriggerInternal.class);
} else if (phase == PHASE_THIRD_PARTY_APPS_CAN_START) {