Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 76d8de1c authored by Eric Miao's avatar Eric Miao Committed by Android (Google) Code Review
Browse files

Merge changes from topic "fix-isolated-process" into main

* changes:
  Use readonly flag of native_metrics for HardwareBuffer
  Revert^2 "Track Bitmap native allocations"
  Add a readonly version for flags in libcore
parents d23e8834 369e6eb9
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -110,6 +110,7 @@ aconfig_declarations_group {
        "hwui_flags_java_lib",
        "interaction_jank_monitor_flags_lib",
        "libcore_exported_aconfig_flags_lib",
        "libcore_readonly_aconfig_flags_lib",
        "libgui_flags_java_lib",
        "power_flags_lib",
        "sdk_sandbox_flags_lib",
@@ -169,6 +170,26 @@ java_aconfig_library {
    defaults: ["framework-minus-apex-aconfig-java-defaults"],
}

// See b/368409430 - This is for libcore flags to be generated with
// force-read-only mode, so access to the flags does not involve I/O,
// which could break Isolated Processes with I/O permission disabled.
// The issue will be addressed once new Aconfig storage API is landed
// and the readonly version will be removed.
aconfig_declarations {
    name: "libcore-readonly-aconfig-flags",
    package: "com.android.libcore.readonly",
    container: "system",
    srcs: ["libcore-readonly.aconfig"],
}

// Core Libraries / libcore
java_aconfig_library {
    name: "libcore_readonly_aconfig_flags_lib",
    aconfig_declarations: "libcore-readonly-aconfig-flags",
    mode: "force-read-only",
    defaults: ["framework-minus-apex-aconfig-java-defaults"],
}

// Telecom
java_aconfig_library {
    name: "telecom_flags_core_java_lib",
+1 −1
Original line number Diff line number Diff line
@@ -283,7 +283,7 @@ public final class HardwareBuffer implements Parcelable, AutoCloseable {
    private static NativeAllocationRegistry getRegistry(long size) {
        final long func = nGetNativeFinalizer();
        final Class cls = HardwareBuffer.class;
        return com.android.libcore.Flags.nativeMetrics()
        return com.android.libcore.readonly.Flags.nativeMetrics()
            ? NativeAllocationRegistry.createNonmalloced(cls, func, size)
            : NativeAllocationRegistry.createNonmalloced(cls.getClassLoader(), func, size);
    }
+18 −11
Original line number Diff line number Diff line
@@ -127,6 +127,22 @@ public final class Bitmap implements Parcelable {
     */
    private static final WeakHashMap<Bitmap, Void> sAllBitmaps = new WeakHashMap<>();

    /**
     * @hide
     */
    private static NativeAllocationRegistry getRegistry(boolean malloc, long size) {
        final long free = nativeGetNativeFinalizer();
        if (com.android.libcore.readonly.Flags.nativeMetrics()) {
            Class cls = Bitmap.class;
            return malloc ? NativeAllocationRegistry.createMalloced(cls, free, size)
                          : NativeAllocationRegistry.createNonmalloced(cls, free, size);
        } else {
            ClassLoader loader = Bitmap.class.getClassLoader();
            return malloc ? NativeAllocationRegistry.createMalloced(loader, free, size)
                          : NativeAllocationRegistry.createNonmalloced(loader, free, size);
        }
    }

    /**
     * Private constructor that must receive an already allocated native bitmap
     * int (pointer).
@@ -151,7 +167,6 @@ public final class Bitmap implements Parcelable {
        mWidth = width;
        mHeight = height;
        mRequestPremultiplied = requestPremultiplied;

        mNinePatchChunk = ninePatchChunk;
        mNinePatchInsets = ninePatchInsets;
        if (density >= 0) {
@@ -159,17 +174,9 @@ public final class Bitmap implements Parcelable {
        }

        mNativePtr = nativeBitmap;

        final int allocationByteCount = getAllocationByteCount();
        NativeAllocationRegistry registry;
        if (fromMalloc) {
            registry = NativeAllocationRegistry.createMalloced(
                    Bitmap.class.getClassLoader(), nativeGetNativeFinalizer(), allocationByteCount);
        } else {
            registry = NativeAllocationRegistry.createNonmalloced(
                    Bitmap.class.getClassLoader(), nativeGetNativeFinalizer(), allocationByteCount);
        }
        registry.registerNativeAllocation(this, nativeBitmap);
        getRegistry(fromMalloc, allocationByteCount).registerNativeAllocation(this, mNativePtr);

        synchronized (Bitmap.class) {
          sAllBitmaps.put(this, null);
        }
+25 −0
Original line number Diff line number Diff line
package: "com.android.libcore.readonly"
container: "system"

# These are the read-only version of the aconfig flags in com.android.libcore
# that will be built with 'force-read-only' mode.
# See b/368409430 - these flags will be removed once the new aconfig API landed.
flag {
    namespace: "core_libraries"
    name: "post_cleanup_apis"
    is_exported: false
    description: "This flag includes APIs to add/remove/call callbacks post-cleanup"
    bug: "331243037"
    # APIs provided by a mainline module can only use a frozen flag.
    is_fixed_read_only: true
}

flag {
    namespace: "core_libraries"
    name: "native_metrics"
    is_exported: false
    description: "This flag includes APIs fo maintaining and exposing native allocation metrics"
    bug: "331243037"
    # APIs provided by a mainline module can only use a frozen flag.
    is_fixed_read_only: true
}