From 50bc17cdaa9d092b10c389ade52116e252e58e94 Mon Sep 17 00:00:00 2001 From: Alex Buynytskyy Date: Thu, 11 Feb 2021 15:09:34 -0800 Subject: [PATCH] Add a new feature to store IncFs version. And deprecating the old feature which didn't have versioning support. V2 means that the new features are either required if the device was shipped with S, or available if device updated kernel to S. Bug: 180010901 Test: atest PackageManagerShellCommandTest PackageManagerShellCommandIncrementalTest IncrementalServiceTest PackageManagerServiceTest ChecksumsTest Change-Id: If037f0eb23260f354b0929ff7afaf1af9627e5fa --- core/api/system-current.txt | 3 ++- .../android/content/pm/PackageManager.java | 19 ++++++++++++++++++- .../os/incremental/IncrementalManager.java | 8 ++++++++ .../java/com/android/server/SystemConfig.java | 2 ++ ...roid_os_incremental_IncrementalManager.cpp | 16 ++++++++++------ 5 files changed, 40 insertions(+), 8 deletions(-) diff --git a/core/api/system-current.txt b/core/api/system-current.txt index fdd1e66606973..fd986e1325f2e 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -2523,7 +2523,8 @@ package android.content.pm { field public static final String FEATURE_BROADCAST_RADIO = "android.hardware.broadcastradio"; field public static final String FEATURE_CONTEXT_HUB = "android.hardware.context_hub"; field public static final String FEATURE_CROSS_LAYER_BLUR = "android.software.cross_layer_blur"; - field public static final String FEATURE_INCREMENTAL_DELIVERY = "android.software.incremental_delivery"; + field @Deprecated public static final String FEATURE_INCREMENTAL_DELIVERY = "android.software.incremental_delivery"; + field public static final String FEATURE_INCREMENTAL_DELIVERY_VERSION = "android.software.incremental_delivery_version"; field public static final String FEATURE_REBOOT_ESCROW = "android.hardware.reboot_escrow"; field public static final String FEATURE_TELEPHONY_CARRIERLOCK = "android.hardware.telephony.carrierlock"; field public static final String FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION = "android.hardware.telephony.ims.singlereg"; diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java index 6cfcce3f76612..a3c3500f742fe 100644 --- a/core/java/android/content/pm/PackageManager.java +++ b/core/java/android/content/pm/PackageManager.java @@ -3592,14 +3592,31 @@ public abstract class PackageManager { * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}: The device has * the requisite kernel support to support incremental delivery aka Incremental FileSystem. * - * @see IncrementalManager#isEnabled + * @see IncrementalManager#isFeatureEnabled * @hide + * + * @deprecated Use {@link #FEATURE_INCREMENTAL_DELIVERY_VERSION} instead. */ + @Deprecated @SystemApi @SdkConstant(SdkConstantType.FEATURE) public static final String FEATURE_INCREMENTAL_DELIVERY = "android.software.incremental_delivery"; + /** + * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}: + * feature not present - IncFs is not present on the device. + * 1 - IncFs v1, core features, no PerUid support. Optional in R. + * 2 - IncFs v2, PerUid support, fs-verity support. Required in S. + * + * @see IncrementalManager#isFeatureEnabled and IncrementalManager#isV2() + * @hide + */ + @SystemApi + @SdkConstant(SdkConstantType.FEATURE) + public static final String FEATURE_INCREMENTAL_DELIVERY_VERSION = + "android.software.incremental_delivery_version"; + /** * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}: * The device has tuner hardware to support tuner operations. diff --git a/core/java/android/os/incremental/IncrementalManager.java b/core/java/android/os/incremental/IncrementalManager.java index 0ff68fc582d83..05899947c3df0 100644 --- a/core/java/android/os/incremental/IncrementalManager.java +++ b/core/java/android/os/incremental/IncrementalManager.java @@ -240,6 +240,13 @@ public final class IncrementalManager { return nativeIsEnabled(); } + /** + * Checks if device supports V2 calls (e.g. PerUid). + */ + public static boolean isV2Available() { + return nativeIsV2Available(); + } + /** * Checks if Incremental installations are allowed. * A developer can disable Incremental installations by setting the property. @@ -439,6 +446,7 @@ public final class IncrementalManager { /* Native methods */ private static native boolean nativeIsEnabled(); + private static native boolean nativeIsV2Available(); private static native boolean nativeIsIncrementalPath(@NonNull String path); private static native byte[] nativeUnsafeGetFileSignature(@NonNull String path); } diff --git a/core/java/com/android/server/SystemConfig.java b/core/java/com/android/server/SystemConfig.java index cb586d6606343..8982519eff966 100644 --- a/core/java/com/android/server/SystemConfig.java +++ b/core/java/com/android/server/SystemConfig.java @@ -1236,6 +1236,8 @@ public class SystemConfig { if (IncrementalManager.isFeatureEnabled()) { addFeature(PackageManager.FEATURE_INCREMENTAL_DELIVERY, 0); + addFeature(PackageManager.FEATURE_INCREMENTAL_DELIVERY_VERSION, + IncrementalManager.isV2Available() ? 2 : 1); } if (PackageManager.APP_ENUMERATION_ENABLED_BY_DEFAULT) { diff --git a/core/jni/android_os_incremental_IncrementalManager.cpp b/core/jni/android_os_incremental_IncrementalManager.cpp index 44bff01885446..2384efaf1a542 100644 --- a/core/jni/android_os_incremental_IncrementalManager.cpp +++ b/core/jni/android_os_incremental_IncrementalManager.cpp @@ -30,6 +30,10 @@ static jboolean nativeIsEnabled(JNIEnv* env, jobject clazz) { return IncFs_IsEnabled(); } +static jboolean nativeIsV2Available(JNIEnv* env, jobject clazz) { + return !!(IncFs_Features() & INCFS_FEATURE_V2); +} + static jboolean nativeIsIncrementalPath(JNIEnv* env, jobject clazz, jstring javaPath) { @@ -53,12 +57,12 @@ static jbyteArray nativeUnsafeGetFileSignature(JNIEnv* env, jobject clazz, jstri return result; } -static const JNINativeMethod method_table[] = {{"nativeIsEnabled", "()Z", (void*)nativeIsEnabled}, - {"nativeIsIncrementalPath", "(Ljava/lang/String;)Z", - (void*)nativeIsIncrementalPath}, - {"nativeUnsafeGetFileSignature", - "(Ljava/lang/String;)[B", - (void*)nativeUnsafeGetFileSignature}}; +static const JNINativeMethod method_table[] = + {{"nativeIsEnabled", "()Z", (void*)nativeIsEnabled}, + {"nativeIsV2Available", "()Z", (void*)nativeIsV2Available}, + {"nativeIsIncrementalPath", "(Ljava/lang/String;)Z", (void*)nativeIsIncrementalPath}, + {"nativeUnsafeGetFileSignature", "(Ljava/lang/String;)[B", + (void*)nativeUnsafeGetFileSignature}}; int register_android_os_incremental_IncrementalManager(JNIEnv* env) { return jniRegisterNativeMethods(env, "android/os/incremental/IncrementalManager",