From 0cf9e87c796ba136977f22adb805cb74ed9a1275 Mon Sep 17 00:00:00 2001 From: Junyu Lai Date: Tue, 28 Dec 2021 14:33:57 +0000 Subject: [PATCH] [MS27] Expose noteUntaggedSocket SystemApi While Data usage related codes are moving to mainline module, StrictMode#vmUntaggedSocketEnabled() and onUntaggedSocket() can no longer be accessed from NetworkManagementSocketTagger. Thus, expose alternative SystemApi to allow invocations from the module. Test: TH Bug: 204830222 Exempt-From-Owner-Approval: 1. Owner approved the change with explicitly granted submission after adderessing the straight-forward comment. 2. Owner is OOO for 3 months. Change-Id: Ib54ff54ce3617ae0d04080a1740e78b086bbb039 --- core/api/module-lib-current.txt | 4 ++++ core/java/android/os/StrictMode.java | 9 +++++++++ .../android/server/NetworkManagementSocketTagger.java | 4 ++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/core/api/module-lib-current.txt b/core/api/module-lib-current.txt index a646a681afc11..6343c67cebea9 100644 --- a/core/api/module-lib-current.txt +++ b/core/api/module-lib-current.txt @@ -321,6 +321,10 @@ package android.os { method @Nullable public android.os.IBinder getOrThrow() throws android.os.StatsServiceManager.ServiceNotFoundException; } + public final class StrictMode { + method public static void noteUntaggedSocket(); + } + public class SystemConfigManager { method @NonNull public java.util.List getEnabledComponentOverrides(@NonNull String); } diff --git a/core/java/android/os/StrictMode.java b/core/java/android/os/StrictMode.java index 44c3d61b87609..983a0aa363ce0 100644 --- a/core/java/android/os/StrictMode.java +++ b/core/java/android/os/StrictMode.java @@ -15,10 +15,13 @@ */ package android.os; +import static android.annotation.SystemApi.Client.MODULE_LIBRARIES; + import android.animation.ValueAnimator; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; +import android.annotation.SystemApi; import android.annotation.TestApi; import android.app.ActivityManager; import android.app.ActivityThread; @@ -2694,6 +2697,12 @@ public final class StrictMode { ((AndroidBlockGuardPolicy) policy).onCustomSlowCall(name); } + /** @hide */ + @SystemApi(client = MODULE_LIBRARIES) + public static void noteUntaggedSocket() { + if (vmUntaggedSocketEnabled()) onUntaggedSocket(); + } + /** * For code to note that a resource was obtained using a type other than its defined type. This * is a no-op unless the current thread's {@link android.os.StrictMode.ThreadPolicy} has {@link diff --git a/core/java/com/android/server/NetworkManagementSocketTagger.java b/core/java/com/android/server/NetworkManagementSocketTagger.java index 26ff192521da5..d89566c9119ca 100644 --- a/core/java/com/android/server/NetworkManagementSocketTagger.java +++ b/core/java/com/android/server/NetworkManagementSocketTagger.java @@ -70,8 +70,8 @@ public final class NetworkManagementSocketTagger extends SocketTagger { Log.d(TAG, "tagSocket(" + fd.getInt$() + ") with statsTag=0x" + Integer.toHexString(options.statsTag) + ", statsUid=" + options.statsUid); } - if (options.statsTag == -1 && StrictMode.vmUntaggedSocketEnabled()) { - StrictMode.onUntaggedSocket(); + if (options.statsTag == -1) { + StrictMode.noteUntaggedSocket(); } // TODO: skip tagging when options would be no-op tagSocketFd(fd, options.statsTag, options.statsUid);