Loading Android.bp +1 −0 Original line number Original line Diff line number Diff line Loading @@ -368,6 +368,7 @@ java_defaults { "view-inspector-annotation-processor", "view-inspector-annotation-processor", "staledataclass-annotation-processor", "staledataclass-annotation-processor", "error_prone_android_framework", "error_prone_android_framework", "systemfeatures-metadata-processor", ], ], // Exports needed for staledataclass-annotation-processor, see b/139342589. // Exports needed for staledataclass-annotation-processor, see b/139342589. javacflags: [ javacflags: [ Loading core/java/android/content/pm/PackageManager.java +10 −0 Original line number Original line Diff line number Diff line Loading @@ -3115,6 +3115,16 @@ public abstract class PackageManager { */ */ public static final long MAXIMUM_VERIFICATION_TIMEOUT = 60*60*1000; public static final long MAXIMUM_VERIFICATION_TIMEOUT = 60*60*1000; /** * As the generated feature count is useful for classes that may not be compiled in the same * annotation processing unit as PackageManager, we redeclare it here for visibility. * * @hide */ @VisibleForTesting public static final int SDK_FEATURE_COUNT = com.android.internal.pm.SystemFeaturesMetadata.SDK_FEATURE_COUNT; /** /** * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}: The device's * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}: The device's * audio pipeline is low-latency, more suitable for audio applications sensitive to delays or * audio pipeline is low-latency, more suitable for audio applications sensitive to delays or Loading core/tests/coretests/src/android/content/pm/PackageManagerTest.java +24 −0 Original line number Original line Diff line number Diff line Loading @@ -24,6 +24,9 @@ import androidx.test.runner.AndroidJUnit4; import org.junit.Test; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runner.RunWith; import java.lang.reflect.Modifier; import java.util.Arrays; @RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class) @SmallTest @SmallTest public class PackageManagerTest { public class PackageManagerTest { Loading @@ -46,4 +49,25 @@ public class PackageManagerTest { public void testResolveInfoFlags() throws Exception { public void testResolveInfoFlags() throws Exception { assertThat(PackageManager.ResolveInfoFlags.of(42L).getValue()).isEqualTo(42L); assertThat(PackageManager.ResolveInfoFlags.of(42L).getValue()).isEqualTo(42L); } } @Test public void testSdkFeatureCount() throws Exception { // Check to make sure the system feature `SdkConst` annotation processor yields sensible // results. We don't care about the exactness, just that it's not pathologically wrong. assertThat(PackageManager.SDK_FEATURE_COUNT).isGreaterThan(150); assertThat(PackageManager.SDK_FEATURE_COUNT).isLessThan(500); assertThat(PackageManager.SDK_FEATURE_COUNT) .isWithin(50) .of(getApproximateFeatureCountUsingReflection()); } /* Return a ballpark estimate of the feature count using FEATURE_ field names. */ private static int getApproximateFeatureCountUsingReflection() { return (int) Arrays.stream(PackageManager.class.getFields()) .filter(field -> Modifier.isStatic(field.getModifiers())) .filter(field -> Modifier.isFinal(field.getModifiers())) .filter(field -> field.getName().startsWith("FEATURE_")) .count(); } } } Loading
Android.bp +1 −0 Original line number Original line Diff line number Diff line Loading @@ -368,6 +368,7 @@ java_defaults { "view-inspector-annotation-processor", "view-inspector-annotation-processor", "staledataclass-annotation-processor", "staledataclass-annotation-processor", "error_prone_android_framework", "error_prone_android_framework", "systemfeatures-metadata-processor", ], ], // Exports needed for staledataclass-annotation-processor, see b/139342589. // Exports needed for staledataclass-annotation-processor, see b/139342589. javacflags: [ javacflags: [ Loading
core/java/android/content/pm/PackageManager.java +10 −0 Original line number Original line Diff line number Diff line Loading @@ -3115,6 +3115,16 @@ public abstract class PackageManager { */ */ public static final long MAXIMUM_VERIFICATION_TIMEOUT = 60*60*1000; public static final long MAXIMUM_VERIFICATION_TIMEOUT = 60*60*1000; /** * As the generated feature count is useful for classes that may not be compiled in the same * annotation processing unit as PackageManager, we redeclare it here for visibility. * * @hide */ @VisibleForTesting public static final int SDK_FEATURE_COUNT = com.android.internal.pm.SystemFeaturesMetadata.SDK_FEATURE_COUNT; /** /** * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}: The device's * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}: The device's * audio pipeline is low-latency, more suitable for audio applications sensitive to delays or * audio pipeline is low-latency, more suitable for audio applications sensitive to delays or Loading
core/tests/coretests/src/android/content/pm/PackageManagerTest.java +24 −0 Original line number Original line Diff line number Diff line Loading @@ -24,6 +24,9 @@ import androidx.test.runner.AndroidJUnit4; import org.junit.Test; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runner.RunWith; import java.lang.reflect.Modifier; import java.util.Arrays; @RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class) @SmallTest @SmallTest public class PackageManagerTest { public class PackageManagerTest { Loading @@ -46,4 +49,25 @@ public class PackageManagerTest { public void testResolveInfoFlags() throws Exception { public void testResolveInfoFlags() throws Exception { assertThat(PackageManager.ResolveInfoFlags.of(42L).getValue()).isEqualTo(42L); assertThat(PackageManager.ResolveInfoFlags.of(42L).getValue()).isEqualTo(42L); } } @Test public void testSdkFeatureCount() throws Exception { // Check to make sure the system feature `SdkConst` annotation processor yields sensible // results. We don't care about the exactness, just that it's not pathologically wrong. assertThat(PackageManager.SDK_FEATURE_COUNT).isGreaterThan(150); assertThat(PackageManager.SDK_FEATURE_COUNT).isLessThan(500); assertThat(PackageManager.SDK_FEATURE_COUNT) .isWithin(50) .of(getApproximateFeatureCountUsingReflection()); } /* Return a ballpark estimate of the feature count using FEATURE_ field names. */ private static int getApproximateFeatureCountUsingReflection() { return (int) Arrays.stream(PackageManager.class.getFields()) .filter(field -> Modifier.isStatic(field.getModifiers())) .filter(field -> Modifier.isFinal(field.getModifiers())) .filter(field -> field.getName().startsWith("FEATURE_")) .count(); } } }