aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--java/Android.bp1
-rw-r--r--java/android/annotation/DurationMicrosLong.java36
-rw-r--r--java/com/android/modules/utils/build/testing/DeviceSdkLevel.java5
-rw-r--r--java/com/android/modules/utils/pm/PackageStateModulesUtils.java15
-rw-r--r--java/com/android/modules/utils/testing/Android.bp61
5 files changed, 100 insertions, 18 deletions
diff --git a/java/Android.bp b/java/Android.bp
index d1835f5..a872c41 100644
--- a/java/Android.bp
+++ b/java/Android.bp
@@ -102,6 +102,7 @@ filegroup {
"android/annotation/IntDef.java",
"android/annotation/SystemApi.java",
"android/annotation/TestApi.java",
+ "android/annotation/UserIdInt.java",
// aconfig annotations
"com/android/aconfig/annotations/*.java",
],
diff --git a/java/android/annotation/DurationMicrosLong.java b/java/android/annotation/DurationMicrosLong.java
new file mode 100644
index 0000000..621f601
--- /dev/null
+++ b/java/android/annotation/DurationMicrosLong.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2024 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 android.annotation;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.RetentionPolicy.SOURCE;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * @memberDoc Value is a non-negative duration in microseconds.
+ * @paramDoc Value is a non-negative duration in microseconds.
+ * @returnDoc Value is a non-negative duration in microseconds.
+ * @hide
+ */
+@Retention(SOURCE)
+@Target({METHOD, PARAMETER, FIELD})
+public @interface DurationMicrosLong {
+}
diff --git a/java/com/android/modules/utils/build/testing/DeviceSdkLevel.java b/java/com/android/modules/utils/build/testing/DeviceSdkLevel.java
index 041d6a5..2f76759 100644
--- a/java/com/android/modules/utils/build/testing/DeviceSdkLevel.java
+++ b/java/com/android/modules/utils/build/testing/DeviceSdkLevel.java
@@ -49,10 +49,9 @@ public final class DeviceSdkLevel {
return device.getApiLevel() >= 33;
}
- /** Checks if the device is running on a (pre-)release version of Android U or newer. */
+ /** Checks if the device is running on a release version of Android U or newer. */
public boolean isDeviceAtLeastU() throws DeviceNotAvailableException {
- return device.getApiLevel() >= 34 ||
- (device.getApiLevel() == 33 && isDeviceAtLeastPreReleaseCodename("UpsideDownCake"));
+ return device.getApiLevel() >= 34;
}
/** Checks if the device is running on a (pre-)release version of Android V or newer. */
diff --git a/java/com/android/modules/utils/pm/PackageStateModulesUtils.java b/java/com/android/modules/utils/pm/PackageStateModulesUtils.java
index 34fd16b..2944592 100644
--- a/java/com/android/modules/utils/pm/PackageStateModulesUtils.java
+++ b/java/com/android/modules/utils/pm/PackageStateModulesUtils.java
@@ -22,6 +22,7 @@ import android.text.TextUtils;
import androidx.annotation.RequiresApi;
+import com.android.server.pm.pkg.AndroidPackage;
import com.android.server.pm.pkg.AndroidPackageSplit;
import com.android.server.pm.pkg.PackageState;
@@ -35,8 +36,7 @@ public class PackageStateModulesUtils {
*/
@RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
public static boolean isDexoptable(@NonNull PackageState packageState) {
- if (packageState.isApex() || "android".equals(packageState.getPackageName())
- || packageState.getAppId() <= 0) {
+ if (packageState.isApex() || "android".equals(packageState.getPackageName())) {
return false;
}
@@ -45,6 +45,10 @@ public class PackageStateModulesUtils {
return false;
}
+ if ((packageState.getAppId() <= 0) && !isSdkLibrary(pkg)) {
+ return false;
+ }
+
List<AndroidPackageSplit> splits = pkg.getSplits();
for (int index = 0; index < splits.size(); index++) {
if (splits.get(index).isHasCode()) {
@@ -76,7 +80,7 @@ public class PackageStateModulesUtils {
return true;
}
- if (!TextUtils.isEmpty(pkg.getSdkLibraryName())) {
+ if (isSdkLibrary(pkg)) {
return true;
}
@@ -86,4 +90,9 @@ public class PackageStateModulesUtils {
return !codeOnly && pkg.isResourceOverlay();
}
+
+ @RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
+ private static boolean isSdkLibrary(AndroidPackage pkg) {
+ return !TextUtils.isEmpty(pkg.getSdkLibraryName());
+ }
}
diff --git a/java/com/android/modules/utils/testing/Android.bp b/java/com/android/modules/utils/testing/Android.bp
index 4b285f1..6e6926f 100644
--- a/java/com/android/modules/utils/testing/Android.bp
+++ b/java/com/android/modules/utils/testing/Android.bp
@@ -28,45 +28,82 @@ java_library {
visibility: ["//visibility:public"],
}
-// TODO(b/281577492): split in 2 (one for just ExtendedMockito stuff)
+// Utility for mocking DeviceConfig and other device state.
+//
// NOTE: clients should depend on modules-utils-testable-device-config-defaults
// instead of using this library directly (so it sets the proper JNI dependencies)
java_library {
name: "modules-utils-testable-device-config",
srcs: [
+ "TestableDeviceConfig.java",
+ ],
+ static_libs: [
+ "modules-utils-build",
+ "modules-utils-extended-mockito-rule",
+ ],
+ libs: [
+ "framework-configinfrastructure",
+ ],
+ visibility: ["//visibility:public"],
+}
+
+// Utility for mocking DeviceConfig and other device state.
+//
+// NOTE: if you're only using ExtendedMockitoRule (without TestableDevicConfig), you should use
+// modules-utils-extended-mockito-rule-defaults instead
+//
+// In order to use these utils successfully, both Java code and native libraries will be required.
+// If your code is in a library, you will have to depend on these defaults both in the library as
+// well as in the android_test that it gets linked into.
+// You will also need to specify android:debuggable="true" in the test's manifest.
+java_defaults {
+ name: "modules-utils-testable-device-config-defaults",
+ static_libs: ["modules-utils-testable-device-config"],
+ compile_multilib: "both",
+ defaults: ["modules-utils-extended-mockito-rule-defaults"],
+ defaults_visibility: ["//visibility:public"],
+}
+
+// Utility for using ExtendedMockitoRule.
+//
+// NOTE: most clients should depend on modules-utils-extended-mockito-rule-defaults
+// instead of using this library directly (so it sets the proper JNI dependencies)
+java_library {
+ name: "modules-utils-extended-mockito-rule",
+ srcs: [
"AbstractExtendedMockitoRule.java",
"StaticMockFixture.java",
"ExtendedMockitoRule.java",
- "TestableDeviceConfig.java",
],
static_libs: [
- "androidx.test.rules",
+ "junit",
"mockito-target-extended-minus-junit4",
- "modules-utils-build",
- "modules-utils-preconditions",
],
libs: [
- "framework-configinfrastructure",
- "framework-annotations-lib",
+ "framework-annotations-lib", // @VisibleForTesting
],
sdk_version: "module_current",
min_sdk_version: "29",
+ // compile_multilib: "both",
+ // TODO(b/338434399): figure out why adding compile_multib causes a failure:
+ // In file included from build/make/core/soong_java_prebuilt.mk:38:
+ // build/make/core/base_rules.mk:300: error: frameworks/libs/modules-utils/java/com/android/modules/utils/testing:
+ // MODULE.TARGET.JAVA_LIBRARIES.modules-utils-extended-mockito-rule already defined by frameworks/libs/modules-utils/java/com/android/modules/utils/testing.
visibility: ["//visibility:public"],
lint: {
baseline_filename: "lint-baseline.xml",
},
}
-// TODO(b/281577492): split in 2 (one for just ExtendedMockito stuff)
-// Utility for mocking DeviceConfig and other device state.
+// Utility for using ExtendedMockitoRule.
+//
// In order to use these utils successfully, both Java code and native libraries will be required.
// If your code is in a library, you will have to depend on these defaults both in the library as
// well as in the android_test that it gets linked into.
// You will also need to specify android:debuggable="true" in the test's manifest.
java_defaults {
- name: "modules-utils-testable-device-config-defaults",
- static_libs: ["modules-utils-testable-device-config"],
- compile_multilib: "both",
+ name: "modules-utils-extended-mockito-rule-defaults",
+ static_libs: ["modules-utils-extended-mockito-rule"],
jni_libs: [
"libdexmakerjvmtiagent",
"libstaticjvmtiagent",