From 6df1d751f48d45450df1ae98261ccfd68d7b282d Mon Sep 17 00:00:00 2001 From: Yan Yan Date: Fri, 13 Sep 2024 19:01:15 -0700 Subject: Expose Handler methods for mainlining VCN Expose the following three methods as a prerequisite for moving VCN to mainline. - #hasMessagesOrCallbacks() - #removeCallbacksAndEqualMessages(Object) - #removeEqualMessages(int, Object) Bug: 366598445 Test: atest CtsOsTestCases:HandlerTest Flag: android.os.mainline_vcn_platform_api Change-Id: If16bbcdd5aba7438397f50d82b2ffd1555b2dddf Merged-In: If16bbcdd5aba7438397f50d82b2ffd1555b2dddf --- core/api/module-lib-current.txt | 6 ++++++ core/java/android/os/Handler.java | 30 ++++++++++++++++++++++++++++-- core/java/android/os/flags.aconfig | 8 ++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/core/api/module-lib-current.txt b/core/api/module-lib-current.txt index 24e73352ff33..84f2ab2f0915 100644 --- a/core/api/module-lib-current.txt +++ b/core/api/module-lib-current.txt @@ -380,6 +380,12 @@ package android.os { method @FlaggedApi("android.crashrecovery.flags.enable_crashrecovery") @NonNull public static java.io.File getDataSystemDeDirectory(); } + public class Handler { + method @FlaggedApi("android.os.mainline_vcn_platform_api") public final boolean hasMessagesOrCallbacks(); + method @FlaggedApi("android.os.mainline_vcn_platform_api") public final void removeCallbacksAndEqualMessages(@Nullable Object); + method @FlaggedApi("android.os.mainline_vcn_platform_api") public final void removeEqualMessages(int, @Nullable Object); + } + public class IpcDataCache { ctor public IpcDataCache(int, @NonNull String, @NonNull String, @NonNull String, @NonNull android.os.IpcDataCache.QueryHandler); method public void disableForCurrentProcess(); diff --git a/core/java/android/os/Handler.java b/core/java/android/os/Handler.java index 80f39bfbdc21..d0828c384664 100644 --- a/core/java/android/os/Handler.java +++ b/core/java/android/os/Handler.java @@ -16,8 +16,10 @@ package android.os; +import android.annotation.FlaggedApi; import android.annotation.NonNull; import android.annotation.Nullable; +import android.annotation.SystemApi; import android.compat.annotation.UnsupportedAppUsage; import android.util.Log; import android.util.Printer; @@ -819,16 +821,25 @@ public class Handler { } /** + * WARNING: This API is dangerous because if the implementation + * of equals() is broken, it would delete unrelated events. For example, + * if object.equals() always returns true, it'd remove all messages. + * + * For this reason, never expose this API to non-platform code. i.e. + * this shouldn't be exposed to SystemApi.PRIVILEGED_APPS. + * * Remove any pending posts of messages with code 'what' and whose obj is * 'object' that are in the message queue. If object is null, * all messages will be removed. - *

- * Similar to {@link #removeMessages(int, Object)} but uses object equality + * + *

Similar to {@link #removeMessages(int, Object)} but uses object equality * ({@link Object#equals(Object)}) instead of reference equality (==) in * determining whether object is the message's obj'. * *@hide */ + @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) + @FlaggedApi(android.os.Flags.FLAG_MAINLINE_VCN_PLATFORM_API) public final void removeEqualMessages(int what, @Nullable Object object) { mQueue.removeEqualMessages(this, what, disallowNullArgumentIfShared(object)); } @@ -843,12 +854,25 @@ public class Handler { } /** + * WARNING: This API is dangerous because if the implementation + * of equals() is broken, it would delete unrelated events. For example, + * if object.equals() always returns true, it'd remove all messages. + * + * For this reason, never expose this API to non-platform code. i.e. + * this shouldn't be exposed to SystemApi.PRIVILEGED_APPS. + * * Remove any pending posts of callbacks and sent messages whose * obj is token. If token is null, * all callbacks and messages will be removed. * + *

Similar to {@link #removeCallbacksAndMessages(Object)} but uses object + * equality ({@link Object#equals(Object)}) instead of reference equality (==) in + * determining whether object is the message's obj'. + * *@hide */ + @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) + @FlaggedApi(android.os.Flags.FLAG_MAINLINE_VCN_PLATFORM_API) public final void removeCallbacksAndEqualMessages(@Nullable Object token) { mQueue.removeCallbacksAndEqualMessages(this, disallowNullArgumentIfShared(token)); } @@ -864,6 +888,8 @@ public class Handler { * Return whether there are any messages or callbacks currently scheduled on this handler. * @hide */ + @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) + @FlaggedApi(android.os.Flags.FLAG_MAINLINE_VCN_PLATFORM_API) public final boolean hasMessagesOrCallbacks() { return mQueue.hasMessages(this); } diff --git a/core/java/android/os/flags.aconfig b/core/java/android/os/flags.aconfig index 11b1b08b787d..941ae892f428 100644 --- a/core/java/android/os/flags.aconfig +++ b/core/java/android/os/flags.aconfig @@ -209,3 +209,11 @@ flag { description: "Tracing using Perfetto SDK." bug: "303199244" } + +flag { + name: "mainline_vcn_platform_api" + namespace: "vcn" + description: "Expose platform APIs to mainline VCN" + is_exported: true + bug: "366598445" +} -- cgit v1.2.3-59-g8ed1b