From e9eb8e2b8a3589825d86c598ec4653fe3b02bbaa Mon Sep 17 00:00:00 2001 From: Junyu Lai Date: Thu, 21 Aug 2025 16:37:45 +0800 Subject: [PATCH 1/5] Remove service-side TrafficStats rate limit cache The service-side TrafficStats rate limit cache is no longer needed as client-side caching is now solely responsible for rate-limiting traffic stats queries. This commit removes: - The `clearTrafficStatsRateLimitCaches` AIDL method. - The service-side cache implementation, including member variables and logic within `NetworkStatsService`. - Related feature flags and constants used for the service-side cache. - All unit tests specifically for the service-side cache. This simplifies the overall traffic statistics caching architecture by centralizing rate-limiting responsibility on the client side. Flag: EXEMPT refactoring Test: atest ConnectivityCoverageTests --test-filter '.*NetworkStats.*' --update-device Test: atest ConnectivityCoverageTests --test-filter '.*TrafficStats.*' --update-device Fix: 428098676 Fix: 428097311 Change-Id: I41cbb80a52f04dcf387c3352677a91cb692ffe73 --- .../src/android/net/INetworkStatsService.aidl | 3 - framework-t/src/android/net/TrafficStats.java | 5 - .../server/net/NetworkStatsService.java | 142 +---------------- .../net/TrafficStatsRateLimitCache.java | 115 -------------- .../server/net/NetworkStatsServiceTest.java | 119 +------------- .../net/TrafficStatsRateLimitCacheTest.kt | 150 ------------------ 6 files changed, 9 insertions(+), 525 deletions(-) delete mode 100644 service-t/src/com/android/server/net/TrafficStatsRateLimitCache.java delete mode 100644 tests/unit/java/com/android/server/net/TrafficStatsRateLimitCacheTest.kt diff --git a/framework-t/src/android/net/INetworkStatsService.aidl b/framework-t/src/android/net/INetworkStatsService.aidl index b459a13d8f..a02d8d03a6 100644 --- a/framework-t/src/android/net/INetworkStatsService.aidl +++ b/framework-t/src/android/net/INetworkStatsService.aidl @@ -103,9 +103,6 @@ interface INetworkStatsService { */ void setStatsProviderWarningAndLimitAsync(String iface, long warning, long limit); - /** Clear TrafficStats rate-limit caches. */ - void clearTrafficStatsRateLimitCaches(); - /** Get rate-limit cache config. */ TrafficStatsRateLimitCacheConfig getRateLimitCacheConfig(); } diff --git a/framework-t/src/android/net/TrafficStats.java b/framework-t/src/android/net/TrafficStats.java index 868033ad5b..2eebfbfa57 100644 --- a/framework-t/src/android/net/TrafficStats.java +++ b/framework-t/src/android/net/TrafficStats.java @@ -892,11 +892,6 @@ public class TrafficStats { if (uidCache != null) { uidCache.clear(); } - try { - getStatsService().clearTrafficStatsRateLimitCaches(); - } catch (RemoteException e) { - throw e.rethrowFromSystemServer(); - } } /** diff --git a/service-t/src/com/android/server/net/NetworkStatsService.java b/service-t/src/com/android/server/net/NetworkStatsService.java index 7dd7c5d760..c82955f44f 100644 --- a/service-t/src/com/android/server/net/NetworkStatsService.java +++ b/service-t/src/com/android/server/net/NetworkStatsService.java @@ -16,7 +16,6 @@ package com.android.server.net; -import static android.Manifest.permission.NETWORK_SETTINGS; import static android.Manifest.permission.NETWORK_STATS_PROVIDER; import static android.Manifest.permission.READ_NETWORK_USAGE_HISTORY; import static android.Manifest.permission.UPDATE_DEVICE_STATS; @@ -308,10 +307,10 @@ public class NetworkStatsService extends INetworkStatsService.Stub { static final String TRAFFIC_STATS_CACHE_EXPIRY_DURATION_NAME = "trafficstats_cache_expiry_duration_ms"; - static final String TRAFFIC_STATS_SERVICE_CACHE_MAX_ENTRIES_NAME = + static final String TRAFFIC_STATS_CACHE_MAX_ENTRIES_NAME = "trafficstats_cache_max_entries"; static final int DEFAULT_TRAFFIC_STATS_CACHE_EXPIRY_DURATION_MS = 1000; - static final int DEFAULT_TRAFFIC_STATS_SERVICE_CACHE_MAX_ENTRIES = 400; + static final int DEFAULT_TRAFFIC_STATS_CACHE_MAX_ENTRIES = 400; /** * The delay time between to network stats update intents. * Added to fix intent spams (b/343844995) @@ -489,25 +488,14 @@ public class NetworkStatsService extends INetworkStatsService.Stub { @GuardedBy("mStatsLock") private long mLatestNetworkStatsUpdatedBroadcastScheduledTime = Long.MIN_VALUE; - @Nullable - private final TrafficStatsRateLimitCache mTrafficStatsTotalCache; - @Nullable - private final TrafficStatsRateLimitCache mTrafficStatsIfaceCache; - @Nullable - private final TrafficStatsRateLimitCache mTrafficStatsUidCache; // A feature flag to control whether the client-side rate limit cache should be enabled. @VisibleForTesting public static final String TRAFFICSTATS_CLIENT_RATE_LIMIT_CACHE_ENABLED_FLAG = "trafficstats_client_rate_limit_cache_enabled_flag"; @VisibleForTesting public static final String STORE_TRANSPORT_TYPES = "store_transport_types"; - static final String TRAFFICSTATS_SERVICE_RATE_LIMIT_CACHE_ENABLED_FLAG = - "trafficstats_rate_limit_cache_enabled_flag"; static final String BROADCAST_NETWORK_STATS_UPDATED_RATE_LIMIT_ENABLED_FLAG = "broadcast_network_stats_updated_rate_limit_enabled_flag"; - private final boolean mIsTrafficStatsServiceRateLimitCacheEnabled; - private final int mTrafficStatsRateLimitCacheExpiryDuration; - private final int mTrafficStatsServiceRateLimitCacheMaxEntries; private final TrafficStatsRateLimitCacheConfig mTrafficStatsRateLimitCacheClientSideConfig; private final boolean mBroadcastNetworkStatsUpdatedRateLimitEnabled; @@ -706,32 +694,8 @@ public class NetworkStatsService extends INetworkStatsService.Stub { mTrafficStatsRateLimitCacheClientSideConfig = mDeps.getTrafficStatsRateLimitCacheClientSideConfig(mContext); - // If the client side cache feature is enabled, disable the service side - // cache unconditionally. - mIsTrafficStatsServiceRateLimitCacheEnabled = - mDeps.isTrafficStatsServiceRateLimitCacheEnabled(mContext, - mTrafficStatsRateLimitCacheClientSideConfig.isCacheEnabled); mBroadcastNetworkStatsUpdatedRateLimitEnabled = mDeps.enabledBroadcastNetworkStatsUpdatedRateLimiting(mContext); - mTrafficStatsRateLimitCacheExpiryDuration = - mDeps.getTrafficStatsRateLimitCacheExpiryDuration(); - mTrafficStatsServiceRateLimitCacheMaxEntries = - mDeps.getTrafficStatsServiceRateLimitCacheMaxEntries(); - if (mIsTrafficStatsServiceRateLimitCacheEnabled) { - mTrafficStatsTotalCache = new TrafficStatsRateLimitCache(mClock, - mTrafficStatsRateLimitCacheExpiryDuration, - mTrafficStatsServiceRateLimitCacheMaxEntries); - mTrafficStatsIfaceCache = new TrafficStatsRateLimitCache(mClock, - mTrafficStatsRateLimitCacheExpiryDuration, - mTrafficStatsServiceRateLimitCacheMaxEntries); - mTrafficStatsUidCache = new TrafficStatsRateLimitCache(mClock, - mTrafficStatsRateLimitCacheExpiryDuration, - mTrafficStatsServiceRateLimitCacheMaxEntries); - } else { - mTrafficStatsTotalCache = null; - mTrafficStatsIfaceCache = null; - mTrafficStatsUidCache = null; - } mSkDestroyListener = mDeps.makeSkDestroyListener((message) -> { final StructInetDiagSockId sockId = message.inetDiagMsg.id; @@ -1012,52 +976,12 @@ public class NetworkStatsService extends INetworkStatsService.Stub { DEFAULT_TRAFFIC_STATS_CACHE_EXPIRY_DURATION_MS)) .setMaxEntries(getDeviceConfigPropertyInt( NAMESPACE_TETHERING, - TRAFFIC_STATS_SERVICE_CACHE_MAX_ENTRIES_NAME, - DEFAULT_TRAFFIC_STATS_SERVICE_CACHE_MAX_ENTRIES)) + TRAFFIC_STATS_CACHE_MAX_ENTRIES_NAME, + DEFAULT_TRAFFIC_STATS_CACHE_MAX_ENTRIES)) .build(); return config; } - /** - * Determines whether the service-side rate-limiting cache is enabled. - * - * The cache is enabled for devices running Android V+ or apps targeting SDK V+ - * if the `TRAFFICSTATS_SERVICE_RATE_LIMIT_CACHE_ENABLED_FLAG` feature flag - * is enabled and client-side caching is disabled. - * - * This method should only be called once in the constructor, - * to ensure that the code does not need to deal with flag values changing at runtime. - */ - public boolean isTrafficStatsServiceRateLimitCacheEnabled(@NonNull Context ctx, - boolean clientCacheEnabled) { - return !clientCacheEnabled && DeviceConfigUtils.isTetheringFeatureNotChickenedOut( - ctx, TRAFFICSTATS_SERVICE_RATE_LIMIT_CACHE_ENABLED_FLAG); - } - - /** - * Get TrafficStats rate-limit cache expiry. - * - * This method should only be called once in the constructor, - * to ensure that the code does not need to deal with flag values changing at runtime. - */ - public int getTrafficStatsRateLimitCacheExpiryDuration() { - return getDeviceConfigPropertyInt( - NAMESPACE_TETHERING, TRAFFIC_STATS_CACHE_EXPIRY_DURATION_NAME, - DEFAULT_TRAFFIC_STATS_CACHE_EXPIRY_DURATION_MS); - } - - /** - * Get TrafficStats service side rate-limit cache max entries. - * - * This method should only be called once in the constructor, - * to ensure that the code does not need to deal with flag values changing at runtime. - */ - public int getTrafficStatsServiceRateLimitCacheMaxEntries() { - return getDeviceConfigPropertyInt( - NAMESPACE_TETHERING, TRAFFIC_STATS_SERVICE_CACHE_MAX_ENTRIES_NAME, - DEFAULT_TRAFFIC_STATS_SERVICE_CACHE_MAX_ENTRIES); - } - /** * Wrapper method for {@link CompatChanges#isChangeEnabled(long, int)} */ @@ -2207,20 +2131,6 @@ public class NetworkStatsService extends INetworkStatsService.Stub { || mDeps.isChangeEnabled(ENABLE_TRAFFICSTATS_RATE_LIMIT_CACHE, callingUid)); } - /** - * Determines whether to use the service-side cache for traffic stats rate limiting. - * - * This is based on the cache enabled feature flag. If enabled, the service-side cache - * is used for V+ devices or callers with V+ target sdk. - * - * @param callingUid The UID of the app making the request. - * @return True if the service-side cache should be used, false otherwise. - */ - private boolean useServiceSideCache(int callingUid) { - return mIsTrafficStatsServiceRateLimitCacheEnabled && (SdkLevel.isAtLeastV() - || mDeps.isChangeEnabled(ENABLE_TRAFFICSTATS_RATE_LIMIT_CACHE, callingUid)); - } - @Nullable @Override public StatsResult getUidStats(int uid) { @@ -2228,13 +2138,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub { if (callingUid != android.os.Process.SYSTEM_UID && callingUid != uid) { return null; } - final NetworkStats.Entry entry; - if (useServiceSideCache(callingUid)) { - entry = mTrafficStatsUidCache.getOrCompute(IFACE_ALL, uid, - () -> mDeps.nativeGetUidStat(uid)); - } else entry = mDeps.nativeGetUidStat(uid); - - return getStatsResultFromEntryOrNull(entry); + return getStatsResultFromEntryOrNull(mDeps.nativeGetUidStat(uid)); } @Nullable @@ -2255,14 +2159,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub { @Override public StatsResult getIfaceStats(@NonNull String iface) { Objects.requireNonNull(iface); - - final NetworkStats.Entry entry; - if (useServiceSideCache(Binder.getCallingUid())) { - entry = mTrafficStatsIfaceCache.getOrCompute(iface, UID_ALL, - () -> getIfaceStatsInternal(iface)); - } else entry = getIfaceStatsInternal(iface); - - return getStatsResultFromEntryOrNull(entry); + return getStatsResultFromEntryOrNull(getIfaceStatsInternal(iface)); } @Nullable @@ -2284,23 +2181,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub { @Nullable @Override public StatsResult getTotalStats() { - final NetworkStats.Entry entry; - if (useServiceSideCache(Binder.getCallingUid())) { - entry = mTrafficStatsTotalCache.getOrCompute( - IFACE_ALL, UID_ALL, () -> getTotalStatsInternal()); - } else entry = getTotalStatsInternal(); - - return getStatsResultFromEntryOrNull(entry); - } - - @Override - public void clearTrafficStatsRateLimitCaches() { - PermissionUtils.enforceNetworkStackPermissionOr(mContext, NETWORK_SETTINGS); - if (mIsTrafficStatsServiceRateLimitCacheEnabled) { - mTrafficStatsUidCache.clear(); - mTrafficStatsIfaceCache.clear(); - mTrafficStatsTotalCache.clear(); - } + return getStatsResultFromEntryOrNull(getTotalStatsInternal()); } @Override @@ -3084,15 +2965,6 @@ public class NetworkStatsService extends INetworkStatsService.Stub { } catch (IOException e) { pw.println("(failed to dump FastDataInput counters)"); } - pw.print("trafficstats.service.cache.isenabled", - mIsTrafficStatsServiceRateLimitCacheEnabled); - pw.println(); - pw.print(TRAFFIC_STATS_CACHE_EXPIRY_DURATION_NAME, - mTrafficStatsRateLimitCacheExpiryDuration); - pw.println(); - pw.print(TRAFFIC_STATS_SERVICE_CACHE_MAX_ENTRIES_NAME, - mTrafficStatsServiceRateLimitCacheMaxEntries); - pw.println(); pw.print("trafficstats.client.cache.config", mTrafficStatsRateLimitCacheClientSideConfig); pw.println(); diff --git a/service-t/src/com/android/server/net/TrafficStatsRateLimitCache.java b/service-t/src/com/android/server/net/TrafficStatsRateLimitCache.java deleted file mode 100644 index 4f99d1b361..0000000000 --- a/service-t/src/com/android/server/net/TrafficStatsRateLimitCache.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (C) 2024 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.server.net; - -import android.annotation.NonNull; -import android.annotation.Nullable; -import android.net.NetworkStats; - -import com.android.net.module.util.LruCacheWithExpiry; - -import java.time.Clock; -import java.util.Objects; -import java.util.function.Supplier; - -/** - * A thread-safe cache for storing and retrieving {@link NetworkStats.Entry} objects, - * with an adjustable expiry duration to manage data freshness. - * - * @deprecated Use {@link LruCacheWithExpiry} instead. - */ -// TODO: Remove this when service side rate limit cache solution is removed. -class TrafficStatsRateLimitCache extends - LruCacheWithExpiry { - - /** - * Constructs a new {@link TrafficStatsRateLimitCache} with the specified expiry duration. - * - * @param clock The {@link Clock} to use for determining timestamps. - * @param expiryDurationMs The expiry duration in milliseconds. - * @param maxSize Maximum number of entries. - */ - TrafficStatsRateLimitCache(@NonNull Clock clock, long expiryDurationMs, int maxSize) { - super(()-> clock.millis(), expiryDurationMs, maxSize, it -> !it.isEmpty()); - } - - public static class TrafficStatsCacheKey { - @Nullable - private final String mIface; - private final int mUid; - - TrafficStatsCacheKey(@Nullable String iface, int uid) { - this.mIface = iface; - this.mUid = uid; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof TrafficStatsCacheKey)) return false; - TrafficStatsCacheKey that = (TrafficStatsCacheKey) o; - return mUid == that.mUid && Objects.equals(mIface, that.mIface); - } - - @Override - public int hashCode() { - return Objects.hash(mIface, mUid); - } - } - - /** - * Retrieves a {@link NetworkStats.Entry} from the cache, associated with the given key. - * - * @param iface The interface name to include in the cache key. Null if not applicable. - * @param uid The UID to include in the cache key. {@code UID_ALL} if not applicable. - * @return The cached {@link NetworkStats.Entry}, or null if not found or expired. - */ - @Nullable - NetworkStats.Entry get(String iface, int uid) { - return super.get(new TrafficStatsCacheKey(iface, uid)); - } - - /** - * Retrieves a {@link NetworkStats.Entry} from the cache, associated with the given key. - * If the entry is not found in the cache or has expired, computes it using the provided - * {@code supplier} and stores the result in the cache. - * - * @param iface The interface name to include in the cache key. {@code IFACE_ALL} - * if not applicable. - * @param uid The UID to include in the cache key. {@code UID_ALL} if not applicable. - * @param supplier The {@link Supplier} to compute the {@link NetworkStats.Entry} if not found. - * @return The cached or computed {@link NetworkStats.Entry}, or null if not found, expired, - * or if the {@code supplier} returns null. - */ - @Nullable - NetworkStats.Entry getOrCompute(String iface, int uid, - @NonNull Supplier supplier) { - return super.getOrCompute(new TrafficStatsCacheKey(iface, uid), supplier); - } - - /** - * Stores a {@link NetworkStats.Entry} in the cache, associated with the given key. - * - * @param iface The interface name to include in the cache key. Null if not applicable. - * @param uid The UID to include in the cache key. {@code UID_ALL} if not applicable. - * @param entry The {@link NetworkStats.Entry} to store in the cache. - */ - void put(String iface, int uid, @NonNull final NetworkStats.Entry entry) { - super.put(new TrafficStatsCacheKey(iface, uid), entry); - } - -} diff --git a/tests/unit/java/com/android/server/net/NetworkStatsServiceTest.java b/tests/unit/java/com/android/server/net/NetworkStatsServiceTest.java index 74073ad09c..9ab7e3355d 100644 --- a/tests/unit/java/com/android/server/net/NetworkStatsServiceTest.java +++ b/tests/unit/java/com/android/server/net/NetworkStatsServiceTest.java @@ -73,14 +73,13 @@ import static com.android.server.net.NetworkStatsService.ACTION_NETWORK_STATS_PO import static com.android.server.net.NetworkStatsService.ACTION_NETWORK_STATS_UPDATED; import static com.android.server.net.NetworkStatsService.BROADCAST_NETWORK_STATS_UPDATED_RATE_LIMIT_ENABLED_FLAG; import static com.android.server.net.NetworkStatsService.DEFAULT_TRAFFIC_STATS_CACHE_EXPIRY_DURATION_MS; -import static com.android.server.net.NetworkStatsService.DEFAULT_TRAFFIC_STATS_SERVICE_CACHE_MAX_ENTRIES; +import static com.android.server.net.NetworkStatsService.DEFAULT_TRAFFIC_STATS_CACHE_MAX_ENTRIES; import static com.android.server.net.NetworkStatsService.NETSTATS_FASTDATAINPUT_FALLBACKS_COUNTER_NAME; import static com.android.server.net.NetworkStatsService.NETSTATS_FASTDATAINPUT_SUCCESSES_COUNTER_NAME; import static com.android.server.net.NetworkStatsService.NETSTATS_IMPORT_ATTEMPTS_COUNTER_NAME; import static com.android.server.net.NetworkStatsService.NETSTATS_IMPORT_FALLBACKS_COUNTER_NAME; import static com.android.server.net.NetworkStatsService.NETSTATS_IMPORT_SUCCESSES_COUNTER_NAME; import static com.android.server.net.NetworkStatsService.TRAFFICSTATS_CLIENT_RATE_LIMIT_CACHE_ENABLED_FLAG; -import static com.android.server.net.NetworkStatsService.TRAFFICSTATS_SERVICE_RATE_LIMIT_CACHE_ENABLED_FLAG; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -130,7 +129,6 @@ import android.net.TestNetworkSpecifier; import android.net.TetherStatsParcel; import android.net.TetheringManager; import android.net.UnderlyingNetworkInfo; -import android.net.netstats.StatsResult; import android.net.netstats.TrafficStatsRateLimitCacheConfig; import android.net.netstats.provider.INetworkStatsProviderCallback; import android.net.wifi.WifiInfo; @@ -625,29 +623,12 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest { return mFeatureFlags.getOrDefault(feature, true); } - @Override - public boolean isTrafficStatsServiceRateLimitCacheEnabled(Context ctx, - boolean isClientCacheEnabled) { - return !isClientCacheEnabled && mFeatureFlags.getOrDefault( - TRAFFICSTATS_SERVICE_RATE_LIMIT_CACHE_ENABLED_FLAG, false); - } - @Override public boolean enabledBroadcastNetworkStatsUpdatedRateLimiting(Context ctx) { return mFeatureFlags.getOrDefault( BROADCAST_NETWORK_STATS_UPDATED_RATE_LIMIT_ENABLED_FLAG, true); } - @Override - public int getTrafficStatsRateLimitCacheExpiryDuration() { - return DEFAULT_TRAFFIC_STATS_CACHE_EXPIRY_DURATION_MS; - } - - @Override - public int getTrafficStatsServiceRateLimitCacheMaxEntries() { - return DEFAULT_TRAFFIC_STATS_SERVICE_CACHE_MAX_ENTRIES; - } - @Override public TrafficStatsRateLimitCacheConfig getTrafficStatsRateLimitCacheClientSideConfig( @NonNull Context ctx) { @@ -656,7 +637,7 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest { .setIsCacheEnabled(mFeatureFlags.getOrDefault( TRAFFICSTATS_CLIENT_RATE_LIMIT_CACHE_ENABLED_FLAG, false)) .setExpiryDurationMs(DEFAULT_TRAFFIC_STATS_CACHE_EXPIRY_DURATION_MS) - .setMaxEntries(DEFAULT_TRAFFIC_STATS_SERVICE_CACHE_MAX_ENTRIES) + .setMaxEntries(DEFAULT_TRAFFIC_STATS_CACHE_MAX_ENTRIES) .build(); return config; } @@ -2573,102 +2554,6 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest { assertTrue(mService.getRateLimitCacheConfig().isCacheEnabled); } - @FeatureFlag(name = TRAFFICSTATS_CLIENT_RATE_LIMIT_CACHE_ENABLED_FLAG) - @FeatureFlag(name = TRAFFICSTATS_SERVICE_RATE_LIMIT_CACHE_ENABLED_FLAG) - @Test - public void testTrafficStatsRateLimitCache_clientCacheEnabledDisableServiceCache() - throws Exception { - mDeps.setChangeEnabled(ENABLE_TRAFFICSTATS_RATE_LIMIT_CACHE, true); - doTestTrafficStatsRateLimitCache(false /* expectCached */); - } - - @FeatureFlag(name = TRAFFICSTATS_SERVICE_RATE_LIMIT_CACHE_ENABLED_FLAG, enabled = false) - @Test - public void testTrafficStatsRateLimitCache_disabledWithCompatChangeEnabled() throws Exception { - mDeps.setChangeEnabled(ENABLE_TRAFFICSTATS_RATE_LIMIT_CACHE, true); - doTestTrafficStatsRateLimitCache(false /* expectCached */); - } - - @FeatureFlag(name = TRAFFICSTATS_SERVICE_RATE_LIMIT_CACHE_ENABLED_FLAG) - @Test - public void testTrafficStatsRateLimitCache_enabledWithCompatChangeEnabled() throws Exception { - mDeps.setChangeEnabled(ENABLE_TRAFFICSTATS_RATE_LIMIT_CACHE, true); - doTestTrafficStatsRateLimitCache(true /* expectCached */); - } - - @FeatureFlag(name = TRAFFICSTATS_SERVICE_RATE_LIMIT_CACHE_ENABLED_FLAG, enabled = false) - @Test - public void testTrafficStatsRateLimitCache_disabledWithCompatChangeDisabled() throws Exception { - mDeps.setChangeEnabled(ENABLE_TRAFFICSTATS_RATE_LIMIT_CACHE, false); - doTestTrafficStatsRateLimitCache(false /* expectCached */); - } - - @FeatureFlag(name = TRAFFICSTATS_SERVICE_RATE_LIMIT_CACHE_ENABLED_FLAG) - @DevSdkIgnoreRule.IgnoreAfter(Build.VERSION_CODES.UPSIDE_DOWN_CAKE) - @Test - public void testTrafficStatsRateLimitCache_enabledWithCompatChangeDisabled_belowV() - throws Exception { - mDeps.setChangeEnabled(ENABLE_TRAFFICSTATS_RATE_LIMIT_CACHE, false); - doTestTrafficStatsRateLimitCache(false /* expectCached */); - } - - @FeatureFlag(name = TRAFFICSTATS_SERVICE_RATE_LIMIT_CACHE_ENABLED_FLAG) - @DevSdkIgnoreRule.IgnoreUpTo(Build.VERSION_CODES.UPSIDE_DOWN_CAKE) - @Test - public void testTrafficStatsRateLimitCache_enabledWithCompatChangeDisabled_vOrAbove() - throws Exception { - mDeps.setChangeEnabled(ENABLE_TRAFFICSTATS_RATE_LIMIT_CACHE, false); - doTestTrafficStatsRateLimitCache(true /* expectCached */); - } - - private void doTestTrafficStatsRateLimitCache(boolean expectCached) throws Exception { - mockDefaultSettings(); - // Calling uid is not injected into the service, use the real uid to pass the caller check. - final int myUid = Process.myUid(); - mockTrafficStatsValues(64L, 3L, 1024L, 8L); - assertTrafficStatsValues(TEST_IFACE, myUid, 64L, 3L, 1024L, 8L); - - // Verify the values are cached. - incrementCurrentTime(DEFAULT_TRAFFIC_STATS_CACHE_EXPIRY_DURATION_MS / 2); - mockTrafficStatsValues(65L, 8L, 1055L, 9L); - if (expectCached) { - assertTrafficStatsValues(TEST_IFACE, myUid, 64L, 3L, 1024L, 8L); - } else { - assertTrafficStatsValues(TEST_IFACE, myUid, 65L, 8L, 1055L, 9L); - } - - // Verify the values are updated after cache expiry. - incrementCurrentTime(DEFAULT_TRAFFIC_STATS_CACHE_EXPIRY_DURATION_MS); - assertTrafficStatsValues(TEST_IFACE, myUid, 65L, 8L, 1055L, 9L); - } - - private void mockTrafficStatsValues(long rxBytes, long rxPackets, - long txBytes, long txPackets) { - // In practice, keys and operations are not used and filled with default values when - // returned by JNI layer. - final NetworkStats.Entry entry = new NetworkStats.Entry(IFACE_ALL, UID_ALL, SET_DEFAULT, - TAG_NONE, METERED_NO, ROAMING_NO, DEFAULT_NETWORK_NO, - rxBytes, rxPackets, txBytes, txPackets, 0L); - mDeps.setNativeStat(entry); - } - - // Assert for 3 different API return values respectively. - private void assertTrafficStatsValues(String iface, int uid, long rxBytes, long rxPackets, - long txBytes, long txPackets) { - assertStatsResultEquals(mService.getTotalStats(), rxBytes, rxPackets, txBytes, txPackets); - assertStatsResultEquals(mService.getIfaceStats(iface), rxBytes, rxPackets, txBytes, - txPackets); - assertStatsResultEquals(mService.getUidStats(uid), rxBytes, rxPackets, txBytes, txPackets); - } - - private void assertStatsResultEquals(StatsResult stats, long rxBytes, long rxPackets, - long txBytes, long txPackets) { - assertEquals(rxBytes, stats.rxBytes); - assertEquals(rxPackets, stats.rxPackets); - assertEquals(txBytes, stats.txBytes); - assertEquals(txPackets, stats.txPackets); - } - private void assertShouldRunComparison(boolean expected, boolean isDebuggable) { assertEquals("shouldRunComparison (debuggable=" + isDebuggable + "): ", expected, mService.shouldRunComparison()); diff --git a/tests/unit/java/com/android/server/net/TrafficStatsRateLimitCacheTest.kt b/tests/unit/java/com/android/server/net/TrafficStatsRateLimitCacheTest.kt deleted file mode 100644 index 99f762d0c2..0000000000 --- a/tests/unit/java/com/android/server/net/TrafficStatsRateLimitCacheTest.kt +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright (C) 2024 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.server.net - -import android.net.NetworkStats.Entry -import com.android.testutils.DevSdkIgnoreRunner -import java.time.Clock -import java.util.function.Supplier -import kotlin.test.assertEquals -import kotlin.test.assertNull -import kotlin.test.fail -import org.junit.Test -import org.junit.runner.RunWith -import org.mockito.Mockito.doReturn -import org.mockito.Mockito.mock -import org.mockito.Mockito.verify -import org.mockito.Mockito.`when` - -@RunWith(DevSdkIgnoreRunner::class) -class TrafficStatsRateLimitCacheTest { - companion object { - private const val expiryDurationMs = 1000L - private const val maxSize = 2 - } - - private val clock = mock(Clock::class.java) - private val entry = mock(Entry::class.java) - private val cache = TrafficStatsRateLimitCache(clock, expiryDurationMs, maxSize) - - @Test - fun testGet_returnsEntryIfNotExpired() { - cache.put("iface", 2, entry) - doReturn(500L).`when`(clock).millis() // Set clock to before expiry - val result = cache.get("iface", 2) - assertEquals(entry, result) - } - - @Test - fun testGet_returnsNullIfExpired() { - cache.put("iface", 2, entry) - doReturn(2000L).`when`(clock).millis() // Set clock to after expiry - assertNull(cache.get("iface", 2)) - } - - @Test - fun testGet_returnsNullForNonExistentKey() { - val result = cache.get("otherIface", 99) - assertNull(result) - } - - @Test - fun testPutAndGet_retrievesCorrectEntryForDifferentKeys() { - val entry1 = mock(Entry::class.java) - val entry2 = mock(Entry::class.java) - - cache.put("iface1", 2, entry1) - cache.put("iface2", 4, entry2) - - assertEquals(entry1, cache.get("iface1", 2)) - assertEquals(entry2, cache.get("iface2", 4)) - } - - @Test - fun testPut_overridesExistingEntry() { - val entry1 = mock(Entry::class.java) - val entry2 = mock(Entry::class.java) - - cache.put("iface", 2, entry1) - cache.put("iface", 2, entry2) // Put with the same key - - assertEquals(entry2, cache.get("iface", 2)) - } - - @Test - fun testPut_removeLru() { - // Assumes max size is 2. Verify eldest entry get removed. - val entry1 = mock(Entry::class.java) - val entry2 = mock(Entry::class.java) - val entry3 = mock(Entry::class.java) - - cache.put("iface1", 2, entry1) - cache.put("iface2", 4, entry2) - cache.put("iface3", 8, entry3) - - assertNull(cache.get("iface1", 2)) - assertEquals(entry2, cache.get("iface2", 4)) - assertEquals(entry3, cache.get("iface3", 8)) - } - - @Test - fun testGetOrCompute_cacheHit() { - val entry1 = mock(Entry::class.java) - - cache.put("iface1", 2, entry1) - - // Set clock to before expiry. - doReturn(500L).`when`(clock).millis() - - // Now call getOrCompute - val result = cache.getOrCompute("iface1", 2) { - fail("Supplier should not be called") - } - - // Assertions - assertEquals(entry1, result) // Should get the cached entry. - } - - @Suppress("UNCHECKED_CAST") - @Test - fun testGetOrCompute_cacheMiss() { - val entry1 = mock(Entry::class.java) - - cache.put("iface1", 2, entry1) - - // Set clock to after expiry. - doReturn(1500L).`when`(clock).millis() - - // Mock the supplier to return our network stats entry. - val supplier = mock(Supplier::class.java) as Supplier - doReturn(entry1).`when`(supplier).get() - - // Now call getOrCompute. - val result = cache.getOrCompute("iface1", 2, supplier) - - // Assertions. - assertEquals(entry1, result) // Should get the cached entry. - verify(supplier).get() - } - - @Test - fun testClear() { - cache.put("iface", 2, entry) - cache.clear() - assertNull(cache.get("iface", 2)) - } -} From 6eaa8416572a876ed1cfaa0b2af6b6ad4a627fac Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Fri, 29 Aug 2025 16:26:42 +0000 Subject: [PATCH 2/5] Convert uses of @hide to block tag In most places the `@hide` doctag is treated as a block tag on its own line. However, there are a few places where it is treated as an inline doctag, e,g. `{@hide}`, and some places where it looks like a block tag but is inline in the text, e.g. `Some text. @hide`. Dealing with all the types increases the complexity of Metalava and makes it slightly slower. This change replaces the non-block tag forms with a block tag. Flag: EXEMPT change the form of @hide does not change the API or behavior Bug: 429965593 Test: m checkapi Change-Id: I4ffe44a329dbcb7f0a7bd61af16c3bd99cacdac4 --- .../src/android/net/IIntResultListener.aidl | 2 +- .../src/android/net/TetherStatesParcel.aidl | 2 +- .../src/android/net/TetheringManager.java | 14 +-- .../networkstack/tethering/BpfUtils.java | 2 +- .../tethering/util/TetheringUtils.java | 2 +- .../src/android/net/vcn/VcnManager.java | 5 +- .../src/android/net/IEthernetManager.aidl | 2 +- .../src/android/net/INetworkStatsService.aidl | 2 +- .../src/android/net/INetworkStatsSession.aidl | 2 +- framework-t/src/android/net/TrafficStats.java | 22 ++-- .../src/android/net/nsd/INsdManager.aidl | 2 +- .../android/net/nsd/INsdServiceConnector.aidl | 2 +- .../src/android/net/ConnectivityManager.java | 108 +++++++++--------- framework/src/android/net/DhcpInfo.java | 5 +- .../src/android/net/IConnectivityManager.aidl | 2 +- .../NetworkAndAgentRegistryParcelable.aidl | 2 +- framework/src/android/net/NetworkInfo.java | 4 +- framework/src/android/net/NetworkUtils.java | 2 +- framework/src/android/net/QosCallback.java | 2 +- .../src/android/net/QosCallbackException.java | 16 +-- framework/src/android/net/UidRange.aidl | 2 +- .../java/android/nearby/FastPairDevice.aidl | 2 +- .../android/nearby/IBroadcastListener.aidl | 2 +- .../java/android/nearby/IScanListener.aidl | 2 +- .../android/nearby/OffloadCapability.aidl | 2 +- .../android/nearby/aidl/IOffloadCallback.aidl | 2 +- .../remoteauth/IDeviceDiscoveryListener.aidl | 2 +- .../src/com/android/server/BpfNetMaps.java | 2 +- .../server/connectivity/ClatCoordinator.java | 2 +- .../com/android/net/module/util/BpfUtils.java | 2 +- staticlibs/netd/binder/android/net/INetd.aidl | 2 +- .../net/INetdUnsolicitedEventListener.aidl | 2 +- .../net/InterfaceConfigurationParcel.aidl | 2 +- .../binder/android/net/MarkMaskParcel.aidl | 2 +- .../android/net/NativeNetworkConfig.aidl | 2 +- .../android/net/TetherConfigParcel.aidl | 2 +- .../android/net/TetherOffloadRuleParcel.aidl | 2 +- .../binder/android/net/TetherStatsParcel.aidl | 2 +- .../binder/android/net/UidRangeParcel.aidl | 2 +- .../android/net/mdns/aidl/DiscoveryInfo.aidl | 2 +- .../android/net/mdns/aidl/GetAddressInfo.aidl | 2 +- .../binder/android/net/mdns/aidl/IMDns.aidl | 2 +- .../net/mdns/aidl/IMDnsEventListener.aidl | 2 +- .../net/mdns/aidl/RegistrationInfo.aidl | 2 +- .../android/net/mdns/aidl/ResolutionInfo.aidl | 2 +- .../net/metrics/INetdEventListener.aidl | 2 +- .../net/netd/aidl/NativeUidRangeConfig.aidl | 2 +- .../net/thread/ActiveOperationalDataset.java | 5 +- .../android/net/thread/ChannelMaxPower.aidl | 2 +- .../IActiveOperationalDatasetReceiver.aidl | 5 +- .../net/thread/IConfigurationReceiver.aidl | 5 +- .../net/thread/IOperationReceiver.aidl | 5 +- .../android/net/thread/IOutputReceiver.aidl | 5 +- .../thread/IScheduleMigrationReceiver.aidl | 5 +- .../net/thread/ThreadNetworkController.java | 5 +- 55 files changed, 159 insertions(+), 132 deletions(-) diff --git a/Tethering/common/TetheringLib/src/android/net/IIntResultListener.aidl b/Tethering/common/TetheringLib/src/android/net/IIntResultListener.aidl index c3d66ee145..45245de760 100644 --- a/Tethering/common/TetheringLib/src/android/net/IIntResultListener.aidl +++ b/Tethering/common/TetheringLib/src/android/net/IIntResultListener.aidl @@ -18,7 +18,7 @@ package android.net; /** * Listener interface allowing objects to listen to various module event. - * {@hide} + * @hide */ oneway interface IIntResultListener { void onResult(int resultCode); diff --git a/Tethering/common/TetheringLib/src/android/net/TetherStatesParcel.aidl b/Tethering/common/TetheringLib/src/android/net/TetherStatesParcel.aidl index 43262fb9d1..1c273157d8 100644 --- a/Tethering/common/TetheringLib/src/android/net/TetherStatesParcel.aidl +++ b/Tethering/common/TetheringLib/src/android/net/TetherStatesParcel.aidl @@ -20,7 +20,7 @@ import android.net.TetheringInterface; /** * Status details for tethering downstream interfaces. - * {@hide} + * @hide */ parcelable TetherStatesParcel { TetheringInterface[] availableList; diff --git a/Tethering/common/TetheringLib/src/android/net/TetheringManager.java b/Tethering/common/TetheringLib/src/android/net/TetheringManager.java index a8a471dbc1..c37ee6c5f4 100644 --- a/Tethering/common/TetheringLib/src/android/net/TetheringManager.java +++ b/Tethering/common/TetheringLib/src/android/net/TetheringManager.java @@ -381,7 +381,7 @@ public class TetheringManager { * @param context Context for the manager. * @param connectorSupplier Supplier for the manager connector; may return null while the * service is not connected. - * {@hide} + * @hide */ @SystemApi(client = MODULE_LIBRARIES) public TetheringManager(@NonNull final Context context, @@ -574,7 +574,7 @@ public class TetheringManager { * already released. * 2. This is not synchronous, so it's not useful to use try-with-resources. * - * {@hide} + * @hide */ @SystemApi(client = MODULE_LIBRARIES) @SuppressLint("NotCloseable") @@ -588,7 +588,7 @@ public class TetheringManager { /** * Callback for requestTetheredInterface. * - * {@hide} + * @hide */ @SystemApi(client = MODULE_LIBRARIES) public interface TetheredInterfaceCallback { @@ -694,7 +694,7 @@ public class TetheringManager { * @param iface the interface name to tether. * @return error a {@code TETHER_ERROR} value indicating success or failure type * - * {@hide} + * @hide */ @Deprecated @SystemApi(client = MODULE_LIBRARIES) @@ -729,7 +729,7 @@ public class TetheringManager { * On SDK versions after {@link Build.VERSION_CODES.VANILLA_ICE_CREAM}, this will * throw an UnsupportedOperationException. * - * {@hide} + * @hide */ @Deprecated @SystemApi(client = MODULE_LIBRARIES) @@ -758,7 +758,7 @@ public class TetheringManager { * used and an entitlement check is needed, downstream USB tethering will be enabled but will * not have any upstream. * - * {@hide} + * @hide */ @Deprecated @SystemApi(client = MODULE_LIBRARIES) @@ -1553,7 +1553,7 @@ public class TetheringManager { * Helper function of #requestLatestTetheringEntitlementResult to remain backwards compatible * with ConnectivityManager#getLatestTetheringEntitlementResult * - * {@hide} + * @hide */ // TODO: improve the usage of ResultReceiver, b/145096122 @SystemApi(client = MODULE_LIBRARIES) diff --git a/Tethering/src/com/android/networkstack/tethering/BpfUtils.java b/Tethering/src/com/android/networkstack/tethering/BpfUtils.java index 12a0c96f0b..8fa3d640b3 100644 --- a/Tethering/src/com/android/networkstack/tethering/BpfUtils.java +++ b/Tethering/src/com/android/networkstack/tethering/BpfUtils.java @@ -30,7 +30,7 @@ import java.io.IOException; /** * The classes and the methods for BPF utilization. * - * {@hide} + * @hide */ public class BpfUtils { static { diff --git a/Tethering/src/com/android/networkstack/tethering/util/TetheringUtils.java b/Tethering/src/com/android/networkstack/tethering/util/TetheringUtils.java index 9392ae8d53..39e22cd0c4 100644 --- a/Tethering/src/com/android/networkstack/tethering/util/TetheringUtils.java +++ b/Tethering/src/com/android/networkstack/tethering/util/TetheringUtils.java @@ -48,7 +48,7 @@ import java.util.Arrays; /** * The classes and the methods for tethering utilization. * - * {@hide} + * @hide */ public class TetheringUtils { static { diff --git a/Vcn/framework-b/src/android/net/vcn/VcnManager.java b/Vcn/framework-b/src/android/net/vcn/VcnManager.java index 594bbb8a20..33da18697c 100644 --- a/Vcn/framework-b/src/android/net/vcn/VcnManager.java +++ b/Vcn/framework-b/src/android/net/vcn/VcnManager.java @@ -192,7 +192,10 @@ public class VcnManager { public static final String VCN_TUNNEL_AGGREGATION_SA_COUNT_MAX_KEY = "vcn_tunnel_aggregation_sa_count_max"; - /** List of Carrier Config options to extract from Carrier Config bundles. @hide */ + /** + * List of Carrier Config options to extract from Carrier Config bundles. + * @hide + */ @NonNull public static final String[] VCN_RELATED_CARRIER_CONFIG_KEYS = new String[] { diff --git a/framework-t/src/android/net/IEthernetManager.aidl b/framework-t/src/android/net/IEthernetManager.aidl index b9a3b380b8..a6eded331b 100644 --- a/framework-t/src/android/net/IEthernetManager.aidl +++ b/framework-t/src/android/net/IEthernetManager.aidl @@ -29,7 +29,7 @@ import java.util.List; * Interface that answers queries about, and allows changing * ethernet configuration. */ -/** {@hide} */ +/** @hide */ interface IEthernetManager { String[] getAvailableInterfaces(); diff --git a/framework-t/src/android/net/INetworkStatsService.aidl b/framework-t/src/android/net/INetworkStatsService.aidl index b459a13d8f..e9956f4366 100644 --- a/framework-t/src/android/net/INetworkStatsService.aidl +++ b/framework-t/src/android/net/INetworkStatsService.aidl @@ -31,7 +31,7 @@ import android.net.netstats.provider.INetworkStatsProviderCallback; import android.os.IBinder; import android.os.Messenger; -/** {@hide} */ +/** @hide */ interface INetworkStatsService { /** Start a statistics query session. */ diff --git a/framework-t/src/android/net/INetworkStatsSession.aidl b/framework-t/src/android/net/INetworkStatsSession.aidl index ab70be826f..78dea774d6 100644 --- a/framework-t/src/android/net/INetworkStatsSession.aidl +++ b/framework-t/src/android/net/INetworkStatsSession.aidl @@ -20,7 +20,7 @@ import android.net.NetworkStats; import android.net.NetworkStatsHistory; import android.net.NetworkTemplate; -/** {@hide} */ +/** @hide */ interface INetworkStatsSession { /** Return device aggregated network layer usage summary for traffic that matches template. */ diff --git a/framework-t/src/android/net/TrafficStats.java b/framework-t/src/android/net/TrafficStats.java index 868033ad5b..7754a47a10 100644 --- a/framework-t/src/android/net/TrafficStats.java +++ b/framework-t/src/android/net/TrafficStats.java @@ -773,7 +773,7 @@ public class TrafficStats { } } - /** {@hide} */ + /** @hide */ public static void closeQuietly(INetworkStatsSession session) { // TODO: move to NetworkStatsService once it exists if (session != null) { @@ -858,13 +858,13 @@ public class TrafficStats { return total; } - /** {@hide} */ + /** @hide */ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) public static long getMobileTcpRxPackets() { return UNSUPPORTED; } - /** {@hide} */ + /** @hide */ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) public static long getMobileTcpTxPackets() { return UNSUPPORTED; @@ -975,25 +975,25 @@ public class TrafficStats { return getIfaceStats(iface, TYPE_RX_BYTES); } - /** {@hide} */ + /** @hide */ @TestApi public static long getLoopbackTxPackets() { return getIfaceStats(LOOPBACK_IFACE, TYPE_TX_PACKETS); } - /** {@hide} */ + /** @hide */ @TestApi public static long getLoopbackRxPackets() { return getIfaceStats(LOOPBACK_IFACE, TYPE_RX_PACKETS); } - /** {@hide} */ + /** @hide */ @TestApi public static long getLoopbackTxBytes() { return getIfaceStats(LOOPBACK_IFACE, TYPE_TX_BYTES); } - /** {@hide} */ + /** @hide */ @TestApi public static long getLoopbackRxBytes() { return getIfaceStats(LOOPBACK_IFACE, TYPE_RX_BYTES); @@ -1330,13 +1330,13 @@ public class TrafficStats { } // NOTE: keep these in sync with {@code com_android_server_net_NetworkStatsService.cpp}. - /** {@hide} */ + /** @hide */ public static final int TYPE_RX_BYTES = 0; - /** {@hide} */ + /** @hide */ public static final int TYPE_RX_PACKETS = 1; - /** {@hide} */ + /** @hide */ public static final int TYPE_TX_BYTES = 2; - /** {@hide} */ + /** @hide */ public static final int TYPE_TX_PACKETS = 3; /** @hide */ diff --git a/framework-t/src/android/net/nsd/INsdManager.aidl b/framework-t/src/android/net/nsd/INsdManager.aidl index 9d14b1a1b9..812d4ede7b 100644 --- a/framework-t/src/android/net/nsd/INsdManager.aidl +++ b/framework-t/src/android/net/nsd/INsdManager.aidl @@ -23,7 +23,7 @@ import android.os.Messenger; /** * Interface that NsdService implements to connect NsdManager clients. * - * {@hide} + * @hide */ interface INsdManager { INsdServiceConnector connect(INsdManagerCallback cb, boolean useJavaBackend); diff --git a/framework-t/src/android/net/nsd/INsdServiceConnector.aidl b/framework-t/src/android/net/nsd/INsdServiceConnector.aidl index 9a3127843c..4534871d89 100644 --- a/framework-t/src/android/net/nsd/INsdServiceConnector.aidl +++ b/framework-t/src/android/net/nsd/INsdServiceConnector.aidl @@ -26,7 +26,7 @@ import android.os.Messenger; /** * Interface that NsdService implements for each NsdManager client. * - * {@hide} + * @hide */ interface INsdServiceConnector { void registerService(int listenerKey, in AdvertisingRequest advertisingRequest); diff --git a/framework/src/android/net/ConnectivityManager.java b/framework/src/android/net/ConnectivityManager.java index 5a939219b2..c076c25f1c 100644 --- a/framework/src/android/net/ConnectivityManager.java +++ b/framework/src/android/net/ConnectivityManager.java @@ -271,7 +271,7 @@ public class ConnectivityManager { * our connection to the internet at large. 0 indicates no connection, * 100 indicates a great connection. Retrieve it with * {@link android.content.Intent#getIntExtra(String, int)}. - * {@hide} + * @hide */ public static final String EXTRA_INET_CONDITION = "inetCondition"; /** @@ -292,7 +292,7 @@ public class ConnectivityManager { /** * Key for passing a {@link android.net.captiveportal.CaptivePortalProbeSpec} to the captive * portal login activity. - * {@hide} + * @hide */ @SystemApi public static final String EXTRA_CAPTIVE_PORTAL_PROBE_SPEC = @@ -300,7 +300,7 @@ public class ConnectivityManager { /** * Key for passing a user agent string to the captive portal login activity. - * {@hide} + * @hide */ @SystemApi public static final String EXTRA_CAPTIVE_PORTAL_USER_AGENT = @@ -311,7 +311,7 @@ public class ConnectivityManager { * (idle or active) on a network in a recent period. * The network becomes active when data transmission is started, or * idle if there is no data transmission for a period of time. - * {@hide} + * @hide */ @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) public static final String ACTION_DATA_ACTIVITY_CHANGE = @@ -319,18 +319,18 @@ public class ConnectivityManager { /** * The lookup key for an enum that indicates the network device type on which this data activity * change happens. - * {@hide} + * @hide */ public static final String EXTRA_DEVICE_TYPE = "deviceType"; /** * The lookup key for a boolean that indicates the device is active or not. {@code true} means * it is actively sending or receiving data and {@code false} means it is idle. - * {@hide} + * @hide */ public static final String EXTRA_IS_ACTIVE = "isActive"; /** * The lookup key for a long that contains the timestamp (nanos) of the radio state change. - * {@hide} + * @hide */ public static final String EXTRA_REALTIME_NS = "tsNanos"; @@ -674,7 +674,7 @@ public class ConnectivityManager { /** * Over the air Administration. * @deprecated Use {@link NetworkCapabilities} instead. - * {@hide} + * @hide */ @Deprecated @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 130143562) @@ -683,7 +683,7 @@ public class ConnectivityManager { /** * IP Multimedia Subsystem. * @deprecated Use {@link NetworkCapabilities#NET_CAPABILITY_IMS} instead. - * {@hide} + * @hide */ @Deprecated @UnsupportedAppUsage @@ -692,7 +692,7 @@ public class ConnectivityManager { /** * Carrier Branded Services. * @deprecated Use {@link NetworkCapabilities#NET_CAPABILITY_CBS} instead. - * {@hide} + * @hide */ @Deprecated @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 130143562) @@ -702,7 +702,7 @@ public class ConnectivityManager { * A Wi-Fi p2p connection. Only requesting processes will have access to * the peers connected. * @deprecated Use {@link NetworkCapabilities#NET_CAPABILITY_WIFI_P2P} instead. - * {@hide} + * @hide */ @Deprecated @SystemApi @@ -711,7 +711,7 @@ public class ConnectivityManager { /** * The network to use for initially attaching to the network * @deprecated Use {@link NetworkCapabilities#NET_CAPABILITY_IA} instead. - * {@hide} + * @hide */ @Deprecated @UnsupportedAppUsage @@ -721,7 +721,7 @@ public class ConnectivityManager { * Emergency PDN connection for emergency services. This * may include IMS and MMS in emergency situations. * @deprecated Use {@link NetworkCapabilities#NET_CAPABILITY_EIMS} instead. - * {@hide} + * @hide */ @Deprecated @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 130143562) @@ -730,7 +730,7 @@ public class ConnectivityManager { /** * The network that uses proxy to achieve connectivity. * @deprecated Use {@link NetworkCapabilities} instead. - * {@hide} + * @hide */ @Deprecated @SystemApi @@ -789,10 +789,10 @@ public class ConnectivityManager { private static final int DEPRECATED_PHONE_CONSTANT_APN_REQUEST_STARTED = 1; private static final int DEPRECATED_PHONE_CONSTANT_APN_REQUEST_FAILED = 3; - /** {@hide} */ + /** @hide */ public static final int MAX_RADIO_TYPE = TYPE_TEST; - /** {@hide} */ + /** @hide */ public static final int MAX_NETWORK_TYPE = TYPE_TEST; private static final int MIN_NETWORK_TYPE = TYPE_MOBILE; @@ -1293,7 +1293,7 @@ public class ConnectivityManager { * @return a String for the given type, or a string version of the type ("87") * if no name is known. * @deprecated Types are deprecated. Use {@link NetworkCapabilities} instead. - * {@hide} + * @hide */ @Deprecated @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) @@ -1362,7 +1362,7 @@ public class ConnectivityManager { * @param networkType the type to check * @return a boolean - {@code true} if uses cellular network, else {@code false} * @deprecated Types are deprecated. Use {@link NetworkCapabilities} instead. - * {@hide} + * @hide */ @Deprecated @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 130143562) @@ -1564,7 +1564,7 @@ public class ConnectivityManager { return getActiveNetworkForUid(uid, false); } - /** {@hide} */ + /** @hide */ public Network getActiveNetworkForUid(int uid, boolean ignoreBlocked) { try { return mService.getActiveNetworkForUid(uid, ignoreBlocked); @@ -1734,7 +1734,7 @@ public class ConnectivityManager { * for the given uid or {@code null} if no default network is * available for the specified uid. * - * {@hide} + * @hide */ @RequiresPermission(android.Manifest.permission.NETWORK_STACK) @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) @@ -1742,7 +1742,7 @@ public class ConnectivityManager { return getActiveNetworkInfoForUid(uid, false); } - /** {@hide} */ + /** @hide */ public NetworkInfo getActiveNetworkInfoForUid(int uid, boolean ignoreBlocked) { try { return mService.getActiveNetworkInfoForUid(uid, ignoreBlocked); @@ -1796,7 +1796,7 @@ public class ConnectivityManager { return getNetworkInfoForUid(network, Process.myUid(), false); } - /** {@hide} */ + /** @hide */ public NetworkInfo getNetworkInfoForUid(Network network, int uid, boolean ignoreBlocked) { try { return mService.getNetworkInfoForUid(network, uid, ignoreBlocked); @@ -1910,7 +1910,7 @@ public class ConnectivityManager { * for the current default network, or {@code null} if there * is no current default network. * - * {@hide} + * @hide * @deprecated please use {@link #getLinkProperties(Network)} on the return * value of {@link #getActiveNetwork()} instead. In particular, * this method will return non-null LinkProperties even if the @@ -1934,7 +1934,7 @@ public class ConnectivityManager { * for the given networkType, or {@code null} if there is * no current default network. * - * {@hide} + * @hide * @deprecated This method does not support multiple connected networks * of the same type. Use {@link #getAllNetworks}, * {@link #getNetworkInfo(android.net.Network)}, and @@ -2929,7 +2929,7 @@ public class ConnectivityManager { } /** - * {@hide} + * @hide */ public ConnectivityManager(Context context, IConnectivityManager service) { this(context, service, true /* newStatic */); @@ -2952,7 +2952,7 @@ public class ConnectivityManager { } } - /** {@hide} */ + /** @hide */ @UnsupportedAppUsage public static ConnectivityManager from(Context context) { return (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); @@ -3013,7 +3013,7 @@ public class ConnectivityManager { * @return an array of 0 or more Strings of tetherable interface names. * * @deprecated Use {@link TetheringEventCallback#onTetherableInterfacesChanged(List)} instead. - * {@hide} + * @hide */ @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE) @UnsupportedAppUsage @@ -3028,7 +3028,7 @@ public class ConnectivityManager { * @return an array of 0 or more String of currently tethered interface names. * * @deprecated Use {@link TetheringEventCallback#onTetherableInterfacesChanged(List)} instead. - * {@hide} + * @hide */ @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE) @UnsupportedAppUsage @@ -3049,7 +3049,7 @@ public class ConnectivityManager { * which failed to tether. * * @deprecated Use {@link TetheringEventCallback#onError(String, int)} instead. - * {@hide} + * @hide */ @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE) @UnsupportedAppUsage @@ -3063,7 +3063,7 @@ public class ConnectivityManager { * * @deprecated This method is not supported. * TODO: remove this function when all of clients are removed. - * {@hide} + * @hide */ @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) @Deprecated @@ -3095,7 +3095,7 @@ public class ConnectivityManager { * @return error a {@code TETHER_ERROR} value indicating success or failure type * @deprecated Use {@link TetheringManager#startTethering} instead * - * {@hide} + * @hide */ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) @Deprecated @@ -3120,7 +3120,7 @@ public class ConnectivityManager { * @param iface the interface name to untether. * @return error a {@code TETHER_ERROR} value indicating success or failure type * - * {@hide} + * @hide */ @UnsupportedAppUsage @Deprecated @@ -3145,7 +3145,7 @@ public class ConnectivityManager { * @return a boolean - {@code true} indicating Tethering is supported. * * @deprecated Use {@link TetheringEventCallback#onTetheringSupported(boolean)} instead. - * {@hide} + * @hide */ @SystemApi @RequiresPermission(anyOf = {android.Manifest.permission.TETHER_PRIVILEGED, @@ -3357,7 +3357,7 @@ public class ConnectivityManager { * what interfaces are considered tetherable usb interfaces. * * @deprecated Use {@link TetheringEventCallback#onTetherableInterfaceRegexpsChanged} instead. - * {@hide} + * @hide */ @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE) @UnsupportedAppUsage @@ -3375,7 +3375,7 @@ public class ConnectivityManager { * what interfaces are considered tetherable wifi interfaces. * * @deprecated Use {@link TetheringEventCallback#onTetherableInterfaceRegexpsChanged} instead. - * {@hide} + * @hide */ @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE) @UnsupportedAppUsage @@ -3394,7 +3394,7 @@ public class ConnectivityManager { * * @deprecated Use {@link TetheringEventCallback#onTetherableInterfaceRegexpsChanged( *TetheringManager.TetheringInterfaceRegexps)} instead. - * {@hide} + * @hide */ @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE) @UnsupportedAppUsage @@ -3419,7 +3419,7 @@ public class ConnectivityManager { * @return error a {@code TETHER_ERROR} value indicating success or failure type * @deprecated Use {@link TetheringManager#startTethering} instead * - * {@hide} + * @hide */ @UnsupportedAppUsage @Deprecated @@ -3429,97 +3429,97 @@ public class ConnectivityManager { /** * @deprecated Use {@link TetheringManager#TETHER_ERROR_NO_ERROR}. - * {@hide} + * @hide */ @SystemApi @Deprecated public static final int TETHER_ERROR_NO_ERROR = 0; /** * @deprecated Use {@link TetheringManager#TETHER_ERROR_UNKNOWN_IFACE}. - * {@hide} + * @hide */ @Deprecated public static final int TETHER_ERROR_UNKNOWN_IFACE = TetheringManager.TETHER_ERROR_UNKNOWN_IFACE; /** * @deprecated Use {@link TetheringManager#TETHER_ERROR_SERVICE_UNAVAIL}. - * {@hide} + * @hide */ @Deprecated public static final int TETHER_ERROR_SERVICE_UNAVAIL = TetheringManager.TETHER_ERROR_SERVICE_UNAVAIL; /** * @deprecated Use {@link TetheringManager#TETHER_ERROR_UNSUPPORTED}. - * {@hide} + * @hide */ @Deprecated public static final int TETHER_ERROR_UNSUPPORTED = TetheringManager.TETHER_ERROR_UNSUPPORTED; /** * @deprecated Use {@link TetheringManager#TETHER_ERROR_UNAVAIL_IFACE}. - * {@hide} + * @hide */ @Deprecated public static final int TETHER_ERROR_UNAVAIL_IFACE = TetheringManager.TETHER_ERROR_UNAVAIL_IFACE; /** * @deprecated Use {@link TetheringManager#TETHER_ERROR_INTERNAL_ERROR}. - * {@hide} + * @hide */ @Deprecated public static final int TETHER_ERROR_MASTER_ERROR = TetheringManager.TETHER_ERROR_INTERNAL_ERROR; /** * @deprecated Use {@link TetheringManager#TETHER_ERROR_TETHER_IFACE_ERROR}. - * {@hide} + * @hide */ @Deprecated public static final int TETHER_ERROR_TETHER_IFACE_ERROR = TetheringManager.TETHER_ERROR_TETHER_IFACE_ERROR; /** * @deprecated Use {@link TetheringManager#TETHER_ERROR_UNTETHER_IFACE_ERROR}. - * {@hide} + * @hide */ @Deprecated public static final int TETHER_ERROR_UNTETHER_IFACE_ERROR = TetheringManager.TETHER_ERROR_UNTETHER_IFACE_ERROR; /** * @deprecated Use {@link TetheringManager#TETHER_ERROR_ENABLE_FORWARDING_ERROR}. - * {@hide} + * @hide */ @Deprecated public static final int TETHER_ERROR_ENABLE_NAT_ERROR = TetheringManager.TETHER_ERROR_ENABLE_FORWARDING_ERROR; /** * @deprecated Use {@link TetheringManager#TETHER_ERROR_DISABLE_FORWARDING_ERROR}. - * {@hide} + * @hide */ @Deprecated public static final int TETHER_ERROR_DISABLE_NAT_ERROR = TetheringManager.TETHER_ERROR_DISABLE_FORWARDING_ERROR; /** * @deprecated Use {@link TetheringManager#TETHER_ERROR_IFACE_CFG_ERROR}. - * {@hide} + * @hide */ @Deprecated public static final int TETHER_ERROR_IFACE_CFG_ERROR = TetheringManager.TETHER_ERROR_IFACE_CFG_ERROR; /** * @deprecated Use {@link TetheringManager#TETHER_ERROR_PROVISIONING_FAILED}. - * {@hide} + * @hide */ @SystemApi @Deprecated public static final int TETHER_ERROR_PROVISION_FAILED = 11; /** * @deprecated Use {@link TetheringManager#TETHER_ERROR_DHCPSERVER_ERROR}. - * {@hide} + * @hide */ @Deprecated public static final int TETHER_ERROR_DHCPSERVER_ERROR = TetheringManager.TETHER_ERROR_DHCPSERVER_ERROR; /** * @deprecated Use {@link TetheringManager#TETHER_ERROR_ENTITLEMENT_UNKNOWN}. - * {@hide} + * @hide */ @SystemApi @Deprecated @@ -3534,7 +3534,7 @@ public class ConnectivityManager { * interface * * @deprecated Use {@link TetheringEventCallback#onError(String, int)} instead. - * {@hide} + * @hide */ @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE) @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) @@ -3599,7 +3599,7 @@ public class ConnectivityManager { * notify the caller of the result of entitlement check. The listener may be called zero * or one time. * @deprecated Use {@link TetheringManager#requestLatestTetheringEntitlementResult} instead. - * {@hide} + * @hide */ @SystemApi @Deprecated @@ -3635,7 +3635,7 @@ public class ConnectivityManager { * @param networkType The type of network you want to report on * @param percentage The quality of the connection 0 is bad, 100 is good * @deprecated Types are deprecated. Use {@link #reportNetworkConnectivity} instead. - * {@hide} + * @hide */ public void reportInetCondition(int networkType, int percentage) { printStackTrace(); diff --git a/framework/src/android/net/DhcpInfo.java b/framework/src/android/net/DhcpInfo.java index 912df67a0b..4d24f580a8 100644 --- a/framework/src/android/net/DhcpInfo.java +++ b/framework/src/android/net/DhcpInfo.java @@ -36,7 +36,10 @@ public class DhcpInfo implements Parcelable { super(); } - /** copy constructor {@hide} */ + /** + * copy constructor + * @hide + */ public DhcpInfo(DhcpInfo source) { if (source != null) { ipAddress = source.ipAddress; diff --git a/framework/src/android/net/IConnectivityManager.aidl b/framework/src/android/net/IConnectivityManager.aidl index 0146e729a7..067a76f5bd 100644 --- a/framework/src/android/net/IConnectivityManager.aidl +++ b/framework/src/android/net/IConnectivityManager.aidl @@ -54,7 +54,7 @@ import android.os.UserHandle; * Interface that answers queries about, and allows changing, the * state of network connectivity. */ -/** {@hide} */ +/** @hide */ interface IConnectivityManager { Network getActiveNetwork(); diff --git a/framework/src/android/net/NetworkAndAgentRegistryParcelable.aidl b/framework/src/android/net/NetworkAndAgentRegistryParcelable.aidl index 8c01bbcda1..2dfa259882 100644 --- a/framework/src/android/net/NetworkAndAgentRegistryParcelable.aidl +++ b/framework/src/android/net/NetworkAndAgentRegistryParcelable.aidl @@ -22,7 +22,7 @@ import android.net.Network; /** * A pair of Network and NetworkAgentRegistry. * - * {@hide} + * @hide */ @JavaDerive(toString=true) parcelable NetworkAndAgentRegistryParcelable { diff --git a/framework/src/android/net/NetworkInfo.java b/framework/src/android/net/NetworkInfo.java index 7aa984709b..b85f315257 100644 --- a/framework/src/android/net/NetworkInfo.java +++ b/framework/src/android/net/NetworkInfo.java @@ -178,7 +178,7 @@ public class NetworkInfo implements Parcelable { mState = State.UNKNOWN; } - /** {@hide} */ + /** @hide */ @UnsupportedAppUsage public NetworkInfo(@NonNull NetworkInfo source) { // S- didn't use to crash when passing null. This plants a timebomb where mState and @@ -445,7 +445,7 @@ public class NetworkInfo implements Parcelable { /** * @deprecated Use {@link NetworkCapabilities#NET_CAPABILITY_NOT_ROAMING} instead. - * {@hide} + * @hide */ @VisibleForTesting @Deprecated diff --git a/framework/src/android/net/NetworkUtils.java b/framework/src/android/net/NetworkUtils.java index 6b2eb08f7a..84793a1359 100644 --- a/framework/src/android/net/NetworkUtils.java +++ b/framework/src/android/net/NetworkUtils.java @@ -39,7 +39,7 @@ import java.util.TreeSet; /** * Native methods for managing network interfaces. * - * {@hide} + * @hide */ public class NetworkUtils { static { diff --git a/framework/src/android/net/QosCallback.java b/framework/src/android/net/QosCallback.java index 22f06bc0e6..a7b90a513c 100644 --- a/framework/src/android/net/QosCallback.java +++ b/framework/src/android/net/QosCallback.java @@ -35,7 +35,7 @@ import java.util.concurrent.Executor; *
  • A network specific issue occurs. eg. Congestion on a carrier network.
  • *
  • The network registered with the callback has no associated QoS providers
  • * - * {@hide} + * @hide */ @SystemApi public abstract class QosCallback { diff --git a/framework/src/android/net/QosCallbackException.java b/framework/src/android/net/QosCallbackException.java index 7de3dd1376..628dc87ca0 100644 --- a/framework/src/android/net/QosCallbackException.java +++ b/framework/src/android/net/QosCallbackException.java @@ -60,32 +60,32 @@ public final class QosCallbackException extends Exception { // The constants are used for the sendQosCallbackError system API, so they must not be changed // as there may be callers relying on their historical values to call that API. // TODO: mark the constants as @SystemApi, since they are necessary to call a system API. - /** {@hide} */ + /** @hide */ public static final int EX_TYPE_FILTER_NONE = 0; - /** {@hide} */ + /** @hide */ public static final int EX_TYPE_FILTER_NETWORK_RELEASED = 1; - /** {@hide} */ + /** @hide */ public static final int EX_TYPE_FILTER_SOCKET_NOT_BOUND = 2; - /** {@hide} */ + /** @hide */ public static final int EX_TYPE_FILTER_NOT_SUPPORTED = 3; - /** {@hide} */ + /** @hide */ public static final int EX_TYPE_FILTER_SOCKET_LOCAL_ADDRESS_CHANGED = 4; - /** {@hide} */ + /** @hide */ public static final int EX_TYPE_FILTER_SOCKET_NOT_CONNECTED = 5; - /** {@hide} */ + /** @hide */ public static final int EX_TYPE_FILTER_SOCKET_REMOTE_ADDRESS_CHANGED = 6; /** * Creates exception based off of a type and message. Not all types of exceptions accept a * custom message. * - * {@hide} + * @hide */ @NonNull public static QosCallbackException createException(@ExceptionType final int type) { diff --git a/framework/src/android/net/UidRange.aidl b/framework/src/android/net/UidRange.aidl index f70fc8e2fe..7da6487207 100644 --- a/framework/src/android/net/UidRange.aidl +++ b/framework/src/android/net/UidRange.aidl @@ -19,6 +19,6 @@ package android.net; /** * An inclusive range of UIDs. * - * {@hide} + * @hide */ parcelable UidRange; \ No newline at end of file diff --git a/nearby/framework/java/android/nearby/FastPairDevice.aidl b/nearby/framework/java/android/nearby/FastPairDevice.aidl index 5942966994..e3614e6848 100644 --- a/nearby/framework/java/android/nearby/FastPairDevice.aidl +++ b/nearby/framework/java/android/nearby/FastPairDevice.aidl @@ -19,6 +19,6 @@ package android.nearby; /** * A class represents a Fast Pair device that can be discovered by multiple mediums. * - * {@hide} + * @hide */ parcelable FastPairDevice; diff --git a/nearby/framework/java/android/nearby/IBroadcastListener.aidl b/nearby/framework/java/android/nearby/IBroadcastListener.aidl index 98c7e173ff..91ebbe9129 100644 --- a/nearby/framework/java/android/nearby/IBroadcastListener.aidl +++ b/nearby/framework/java/android/nearby/IBroadcastListener.aidl @@ -19,7 +19,7 @@ package android.nearby; /** * Callback when brodacast status changes. * - * {@hide} + * @hide */ oneway interface IBroadcastListener { /** Called when the broadcast status changes. */ diff --git a/nearby/framework/java/android/nearby/IScanListener.aidl b/nearby/framework/java/android/nearby/IScanListener.aidl index 80563b7e8c..f885356437 100644 --- a/nearby/framework/java/android/nearby/IScanListener.aidl +++ b/nearby/framework/java/android/nearby/IScanListener.aidl @@ -21,7 +21,7 @@ import android.nearby.NearbyDeviceParcelable; /** * Binder callback for ScanCallback. * - * {@hide} + * @hide */ oneway interface IScanListener { /** Reports a {@link NearbyDevice} being discovered. */ diff --git a/nearby/framework/java/android/nearby/OffloadCapability.aidl b/nearby/framework/java/android/nearby/OffloadCapability.aidl index fe1c45e66b..ae52234ec9 100644 --- a/nearby/framework/java/android/nearby/OffloadCapability.aidl +++ b/nearby/framework/java/android/nearby/OffloadCapability.aidl @@ -19,7 +19,7 @@ package android.nearby; /** * A class that can describe what offload functions are available. * - * {@hide} + * @hide */ parcelable OffloadCapability; diff --git a/nearby/framework/java/android/nearby/aidl/IOffloadCallback.aidl b/nearby/framework/java/android/nearby/aidl/IOffloadCallback.aidl index 8bef8177bb..642a7ff380 100644 --- a/nearby/framework/java/android/nearby/aidl/IOffloadCallback.aidl +++ b/nearby/framework/java/android/nearby/aidl/IOffloadCallback.aidl @@ -21,7 +21,7 @@ import android.nearby.OffloadCapability; /** * Listener for offload queries. * - * {@hide} + * @hide */ oneway interface IOffloadCallback { /** Invokes when ContextHub transaction completes. */ diff --git a/remoteauth/framework/java/android/remoteauth/IDeviceDiscoveryListener.aidl b/remoteauth/framework/java/android/remoteauth/IDeviceDiscoveryListener.aidl index 2ad6a6a0d1..2dbb2af079 100644 --- a/remoteauth/framework/java/android/remoteauth/IDeviceDiscoveryListener.aidl +++ b/remoteauth/framework/java/android/remoteauth/IDeviceDiscoveryListener.aidl @@ -21,7 +21,7 @@ import android.remoteauth.RemoteDevice; /** * Binder callback for DeviceDiscoveryCallback. * - * {@hide} + * @hide */ oneway interface IDeviceDiscoveryListener { /** Reports a {@link RemoteDevice} being discovered. */ diff --git a/service/src/com/android/server/BpfNetMaps.java b/service/src/com/android/server/BpfNetMaps.java index be1bbce18d..a96819380c 100644 --- a/service/src/com/android/server/BpfNetMaps.java +++ b/service/src/com/android/server/BpfNetMaps.java @@ -101,7 +101,7 @@ import java.util.StringJoiner; /** * BpfNetMaps is responsible for providing traffic controller relevant functionality. * - * {@hide} + * @hide */ public class BpfNetMaps { static { diff --git a/service/src/com/android/server/connectivity/ClatCoordinator.java b/service/src/com/android/server/connectivity/ClatCoordinator.java index 0902e1ac30..8266a87212 100644 --- a/service/src/com/android/server/connectivity/ClatCoordinator.java +++ b/service/src/com/android/server/connectivity/ClatCoordinator.java @@ -64,7 +64,7 @@ import java.util.Objects; /** * This coordinator is responsible for providing clat relevant functionality. * - * {@hide} + * @hide */ @RequiresApi(Build.VERSION_CODES.TIRAMISU) public class ClatCoordinator { diff --git a/staticlibs/device/com/android/net/module/util/BpfUtils.java b/staticlibs/device/com/android/net/module/util/BpfUtils.java index a41eeba1e2..e6e2f1feaf 100644 --- a/staticlibs/device/com/android/net/module/util/BpfUtils.java +++ b/staticlibs/device/com/android/net/module/util/BpfUtils.java @@ -25,7 +25,7 @@ import java.io.IOException; /** * The classes and the methods for BPF utilization. * - * {@hide} + * @hide */ @RequiresApi(Build.VERSION_CODES.TIRAMISU) public class BpfUtils { diff --git a/staticlibs/netd/binder/android/net/INetd.aidl b/staticlibs/netd/binder/android/net/INetd.aidl index be8f538db7..b147126eb6 100644 --- a/staticlibs/netd/binder/android/net/INetd.aidl +++ b/staticlibs/netd/binder/android/net/INetd.aidl @@ -28,7 +28,7 @@ import android.net.TetherStatsParcel; import android.net.UidRangeParcel; import android.net.netd.aidl.NativeUidRangeConfig; -/** {@hide} */ +/** @hide */ interface INetd { /** * Returns true if the service is responding. diff --git a/staticlibs/netd/binder/android/net/INetdUnsolicitedEventListener.aidl b/staticlibs/netd/binder/android/net/INetdUnsolicitedEventListener.aidl index 652a79cb68..cb0a94dcb3 100644 --- a/staticlibs/netd/binder/android/net/INetdUnsolicitedEventListener.aidl +++ b/staticlibs/netd/binder/android/net/INetdUnsolicitedEventListener.aidl @@ -21,7 +21,7 @@ package android.net; * This one-way interface groups asynchronous notifications sent * by netd to any process that registered itself via INetd.registerUnsolEventListener. * - * {@hide} + * @hide */ oneway interface INetdUnsolicitedEventListener { diff --git a/staticlibs/netd/binder/android/net/InterfaceConfigurationParcel.aidl b/staticlibs/netd/binder/android/net/InterfaceConfigurationParcel.aidl index c20792c0df..fd7d207eb6 100644 --- a/staticlibs/netd/binder/android/net/InterfaceConfigurationParcel.aidl +++ b/staticlibs/netd/binder/android/net/InterfaceConfigurationParcel.aidl @@ -19,7 +19,7 @@ package android.net; /** * Configuration details for a network interface. * - * {@hide} + * @hide */ parcelable InterfaceConfigurationParcel { @utf8InCpp String ifName; diff --git a/staticlibs/netd/binder/android/net/MarkMaskParcel.aidl b/staticlibs/netd/binder/android/net/MarkMaskParcel.aidl index 932b7bffbd..2ce7ff515f 100644 --- a/staticlibs/netd/binder/android/net/MarkMaskParcel.aidl +++ b/staticlibs/netd/binder/android/net/MarkMaskParcel.aidl @@ -19,7 +19,7 @@ package android.net; /** * Structure that stores a firewall mark and its mask. * - * {@hide} + * @hide */ parcelable MarkMaskParcel { // The fwmark. diff --git a/staticlibs/netd/binder/android/net/NativeNetworkConfig.aidl b/staticlibs/netd/binder/android/net/NativeNetworkConfig.aidl index 96eccc7acf..bf2d83facf 100644 --- a/staticlibs/netd/binder/android/net/NativeNetworkConfig.aidl +++ b/staticlibs/netd/binder/android/net/NativeNetworkConfig.aidl @@ -22,7 +22,7 @@ import android.net.NativeVpnType; /** * The configuration to create a network. * - * {@hide} + * @hide */ @JavaDerive(toString=true, equals=true) @JavaOnlyImmutable diff --git a/staticlibs/netd/binder/android/net/TetherConfigParcel.aidl b/staticlibs/netd/binder/android/net/TetherConfigParcel.aidl index 9f371ce106..cba8ca81ae 100644 --- a/staticlibs/netd/binder/android/net/TetherConfigParcel.aidl +++ b/staticlibs/netd/binder/android/net/TetherConfigParcel.aidl @@ -19,7 +19,7 @@ package android.net; /** * The configuration to start tethering. * - * {@hide} + * @hide */ parcelable TetherConfigParcel { // Whether to enable or disable legacy DNS proxy server. diff --git a/staticlibs/netd/binder/android/net/TetherOffloadRuleParcel.aidl b/staticlibs/netd/binder/android/net/TetherOffloadRuleParcel.aidl index c549e610c0..7f71a92c5a 100644 --- a/staticlibs/netd/binder/android/net/TetherOffloadRuleParcel.aidl +++ b/staticlibs/netd/binder/android/net/TetherOffloadRuleParcel.aidl @@ -19,7 +19,7 @@ package android.net; /** * Represents a forwarding rule for tethering offload. * - * {@hide} + * @hide */ parcelable TetherOffloadRuleParcel { /** The interface index of the input interface. */ diff --git a/staticlibs/netd/binder/android/net/TetherStatsParcel.aidl b/staticlibs/netd/binder/android/net/TetherStatsParcel.aidl index 6bf60a86e3..c0c8c82706 100644 --- a/staticlibs/netd/binder/android/net/TetherStatsParcel.aidl +++ b/staticlibs/netd/binder/android/net/TetherStatsParcel.aidl @@ -19,7 +19,7 @@ package android.net; /** * The statistics of tethering interface * - * {@hide} + * @hide */ parcelable TetherStatsParcel { /** diff --git a/staticlibs/netd/binder/android/net/UidRangeParcel.aidl b/staticlibs/netd/binder/android/net/UidRangeParcel.aidl index 8f1fef6f11..f18ccb6ab6 100644 --- a/staticlibs/netd/binder/android/net/UidRangeParcel.aidl +++ b/staticlibs/netd/binder/android/net/UidRangeParcel.aidl @@ -19,7 +19,7 @@ package android.net; /** * An inclusive range of UIDs. * - * {@hide} + * @hide */ @JavaOnlyImmutable @JavaDerive(toString=true, equals=true) parcelable UidRangeParcel { diff --git a/staticlibs/netd/binder/android/net/mdns/aidl/DiscoveryInfo.aidl b/staticlibs/netd/binder/android/net/mdns/aidl/DiscoveryInfo.aidl index f8273828b1..e561a6f290 100644 --- a/staticlibs/netd/binder/android/net/mdns/aidl/DiscoveryInfo.aidl +++ b/staticlibs/netd/binder/android/net/mdns/aidl/DiscoveryInfo.aidl @@ -33,7 +33,7 @@ package android.net.mdns.aidl; * - netId * - result * - * {@hide} + * @hide */ @JavaOnlyImmutable @JavaDerive(equals=true, toString=true) diff --git a/staticlibs/netd/binder/android/net/mdns/aidl/GetAddressInfo.aidl b/staticlibs/netd/binder/android/net/mdns/aidl/GetAddressInfo.aidl index d53174a4d7..85faa3dad8 100644 --- a/staticlibs/netd/binder/android/net/mdns/aidl/GetAddressInfo.aidl +++ b/staticlibs/netd/binder/android/net/mdns/aidl/GetAddressInfo.aidl @@ -32,7 +32,7 @@ package android.net.mdns.aidl; * - address * - result * - * {@hide} + * @hide */ @JavaOnlyImmutable @JavaDerive(equals=true, toString=true) diff --git a/staticlibs/netd/binder/android/net/mdns/aidl/IMDns.aidl b/staticlibs/netd/binder/android/net/mdns/aidl/IMDns.aidl index 3bf1da8201..bb825dfb4f 100644 --- a/staticlibs/netd/binder/android/net/mdns/aidl/IMDns.aidl +++ b/staticlibs/netd/binder/android/net/mdns/aidl/IMDns.aidl @@ -22,7 +22,7 @@ import android.net.mdns.aidl.IMDnsEventListener; import android.net.mdns.aidl.RegistrationInfo; import android.net.mdns.aidl.ResolutionInfo; -/** {@hide} */ +/** @hide */ interface IMDns { /** * Start the MDNSResponder daemon. diff --git a/staticlibs/netd/binder/android/net/mdns/aidl/IMDnsEventListener.aidl b/staticlibs/netd/binder/android/net/mdns/aidl/IMDnsEventListener.aidl index f7f028bcb6..7f0b2b04cb 100644 --- a/staticlibs/netd/binder/android/net/mdns/aidl/IMDnsEventListener.aidl +++ b/staticlibs/netd/binder/android/net/mdns/aidl/IMDnsEventListener.aidl @@ -26,7 +26,7 @@ import android.net.mdns.aidl.ResolutionInfo; * This one-way interface defines the asynchronous notifications sent by mdns service to any process * that registered itself via IMDns.registerEventListener. * - * {@hide} + * @hide */ oneway interface IMDnsEventListener { /** diff --git a/staticlibs/netd/binder/android/net/mdns/aidl/RegistrationInfo.aidl b/staticlibs/netd/binder/android/net/mdns/aidl/RegistrationInfo.aidl index 5483559453..10cf93a1ca 100644 --- a/staticlibs/netd/binder/android/net/mdns/aidl/RegistrationInfo.aidl +++ b/staticlibs/netd/binder/android/net/mdns/aidl/RegistrationInfo.aidl @@ -33,7 +33,7 @@ package android.net.mdns.aidl; * - registrationType * - result * - * {@hide} + * @hide */ @JavaOnlyImmutable @JavaDerive(equals=true, toString=true) diff --git a/staticlibs/netd/binder/android/net/mdns/aidl/ResolutionInfo.aidl b/staticlibs/netd/binder/android/net/mdns/aidl/ResolutionInfo.aidl index 26e0cee75e..983dac37b1 100644 --- a/staticlibs/netd/binder/android/net/mdns/aidl/ResolutionInfo.aidl +++ b/staticlibs/netd/binder/android/net/mdns/aidl/ResolutionInfo.aidl @@ -35,7 +35,7 @@ package android.net.mdns.aidl; * - interfaceIdx * - result * - * {@hide} + * @hide */ @JavaOnlyImmutable @JavaDerive(equals=true, toString=true) diff --git a/staticlibs/netd/binder/android/net/metrics/INetdEventListener.aidl b/staticlibs/netd/binder/android/net/metrics/INetdEventListener.aidl index ef1b2cbcd2..6634bb4a5f 100644 --- a/staticlibs/netd/binder/android/net/metrics/INetdEventListener.aidl +++ b/staticlibs/netd/binder/android/net/metrics/INetdEventListener.aidl @@ -19,7 +19,7 @@ package android.net.metrics; /** * Logs netd events. * - * {@hide} + * @hide */ oneway interface INetdEventListener { const int EVENT_GETADDRINFO = 1; diff --git a/staticlibs/netd/binder/android/net/netd/aidl/NativeUidRangeConfig.aidl b/staticlibs/netd/binder/android/net/netd/aidl/NativeUidRangeConfig.aidl index 99497a863c..054ebd9877 100644 --- a/staticlibs/netd/binder/android/net/netd/aidl/NativeUidRangeConfig.aidl +++ b/staticlibs/netd/binder/android/net/netd/aidl/NativeUidRangeConfig.aidl @@ -21,7 +21,7 @@ import android.net.UidRangeParcel; /** * The configuration to add or remove UID ranges. * - * {@hide} + * @hide */ @JavaDerive(toString=true, equals=true) @JavaOnlyImmutable diff --git a/thread/framework/java/android/net/thread/ActiveOperationalDataset.java b/thread/framework/java/android/net/thread/ActiveOperationalDataset.java index cd256c9991..51a3f47e27 100644 --- a/thread/framework/java/android/net/thread/ActiveOperationalDataset.java +++ b/thread/framework/java/android/net/thread/ActiveOperationalDataset.java @@ -930,7 +930,10 @@ public final class ActiveOperationalDataset implements Parcelable { return this; } - /** Adds one more unknown TLV. @hide */ + /** + * Adds one more unknown TLV. + * @hide + */ @VisibleForTesting @NonNull public Builder addUnknownTlv(int type, byte[] value) { diff --git a/thread/framework/java/android/net/thread/ChannelMaxPower.aidl b/thread/framework/java/android/net/thread/ChannelMaxPower.aidl index abc00b98ab..0d6f58a97d 100644 --- a/thread/framework/java/android/net/thread/ChannelMaxPower.aidl +++ b/thread/framework/java/android/net/thread/ChannelMaxPower.aidl @@ -19,7 +19,7 @@ package android.net.thread; /** * Mapping from a channel to its max power. * - * {@hide} + * @hide */ parcelable ChannelMaxPower { int channel; // The Thread radio channel. diff --git a/thread/framework/java/android/net/thread/IActiveOperationalDatasetReceiver.aidl b/thread/framework/java/android/net/thread/IActiveOperationalDatasetReceiver.aidl index aba54ebe1e..d6782ee2e2 100644 --- a/thread/framework/java/android/net/thread/IActiveOperationalDatasetReceiver.aidl +++ b/thread/framework/java/android/net/thread/IActiveOperationalDatasetReceiver.aidl @@ -18,7 +18,10 @@ package android.net.thread; import android.net.thread.ActiveOperationalDataset; -/** Receives the result of an operation which returns an Active Operational Dataset. @hide */ +/** + * Receives the result of an operation which returns an Active Operational Dataset. + * @hide + */ oneway interface IActiveOperationalDatasetReceiver { void onSuccess(in ActiveOperationalDataset dataset); void onError(int errorCode, String errorMessage); diff --git a/thread/framework/java/android/net/thread/IConfigurationReceiver.aidl b/thread/framework/java/android/net/thread/IConfigurationReceiver.aidl index dcc4545515..30dd8de3c0 100644 --- a/thread/framework/java/android/net/thread/IConfigurationReceiver.aidl +++ b/thread/framework/java/android/net/thread/IConfigurationReceiver.aidl @@ -18,7 +18,10 @@ package android.net.thread; import android.net.thread.ThreadConfiguration; -/** Receives the result of a Thread Configuration change. @hide */ +/** + * Receives the result of a Thread Configuration change. + * @hide + */ oneway interface IConfigurationReceiver { void onConfigurationChanged(in ThreadConfiguration configuration); } diff --git a/thread/framework/java/android/net/thread/IOperationReceiver.aidl b/thread/framework/java/android/net/thread/IOperationReceiver.aidl index 42e157b009..b3b579ab86 100644 --- a/thread/framework/java/android/net/thread/IOperationReceiver.aidl +++ b/thread/framework/java/android/net/thread/IOperationReceiver.aidl @@ -16,7 +16,10 @@ package android.net.thread; -/** Receives the result of a Thread network operation. @hide */ +/** + * Receives the result of a Thread network operation. + * @hide + */ oneway interface IOperationReceiver { void onSuccess(); void onError(int errorCode, String errorMessage); diff --git a/thread/framework/java/android/net/thread/IOutputReceiver.aidl b/thread/framework/java/android/net/thread/IOutputReceiver.aidl index b6b4375292..e0990720b6 100644 --- a/thread/framework/java/android/net/thread/IOutputReceiver.aidl +++ b/thread/framework/java/android/net/thread/IOutputReceiver.aidl @@ -16,7 +16,10 @@ package android.net.thread; -/** Receives the output of a Thread network operation. @hide */ +/** + * Receives the output of a Thread network operation. + * @hide + */ oneway interface IOutputReceiver { void onOutput(in String output); void onComplete(); diff --git a/thread/framework/java/android/net/thread/IScheduleMigrationReceiver.aidl b/thread/framework/java/android/net/thread/IScheduleMigrationReceiver.aidl index c45d4638c7..872e021387 100644 --- a/thread/framework/java/android/net/thread/IScheduleMigrationReceiver.aidl +++ b/thread/framework/java/android/net/thread/IScheduleMigrationReceiver.aidl @@ -16,7 +16,10 @@ package android.net.thread; -/** Receives the result of {@link ThreadNetworkManager#scheduleMigration}. @hide */ +/** + * Receives the result of {@link ThreadNetworkManager#scheduleMigration}. + * @hide + */ oneway interface IScheduleMigrationReceiver { void onScheduled(long delayTimerMillis); void onMigrated(); diff --git a/thread/framework/java/android/net/thread/ThreadNetworkController.java b/thread/framework/java/android/net/thread/ThreadNetworkController.java index b64971614d..b0f58e8388 100644 --- a/thread/framework/java/android/net/thread/ThreadNetworkController.java +++ b/thread/framework/java/android/net/thread/ThreadNetworkController.java @@ -137,7 +137,10 @@ public final class ThreadNetworkController { @SuppressLint("MinMaxConstant") public static final int MAX_POWER_CHANNEL_DISABLED = Integer.MIN_VALUE; - /** The maximum lifetime of an ephemeral key. @hide */ + /** + * The maximum lifetime of an ephemeral key. + * @hide + */ @NonNull private static final Duration EPHEMERAL_KEY_LIFETIME_MAX = Duration.ofMinutes(10); /** @hide */ From b5ad6f83b2bcdbca1da71d04bdb483b79f007cc8 Mon Sep 17 00:00:00 2001 From: Chuwei He Date: Wed, 3 Sep 2025 13:16:00 +0900 Subject: [PATCH 3/5] Add conversion util methods for MeteredOverride This patch adds util methods to convert MeteredOverride to and from its proto equivalent, and also adds unit tests to test the conversion. Test: atest ConnectivityCoverageTests Bug: 397536853 Flag: EXEMPT mainline Change-Id: Ie19a19c1124e87b8e23a9b4e216e170e1cfb22b2 --- .../android/server/net/ProtoConfigUtils.java | 72 +++++++++++++++++++ .../server/net/ProtoConfigUtilsTest.java | 62 ++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 service-t/src/com/android/server/net/ProtoConfigUtils.java create mode 100644 tests/unit/java/com/android/server/net/ProtoConfigUtilsTest.java diff --git a/service-t/src/com/android/server/net/ProtoConfigUtils.java b/service-t/src/com/android/server/net/ProtoConfigUtils.java new file mode 100644 index 0000000000..5428bd3da8 --- /dev/null +++ b/service-t/src/com/android/server/net/ProtoConfigUtils.java @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2025 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.server.net; + +import static java.util.Objects.requireNonNull; + +import android.net.EthernetConfiguration; +import android.net.EthernetConfiguration.MeteredOverride; +import android.util.Log; + +import com.android.server.network.configstore.proto.NetworkConfigStoreProto.MeteredOverrideProto; + +/** + * Static util methods for {@link ProtoConfig}. + */ +public class ProtoConfigUtils { + private static final String TAG = "ProtoConfigUtils"; + + /** + * Converts an {@link EthernetConfiguration.MeteredOverride} value to a corresponding value of + * {@link MeteredOverrideProto} type. + */ + public static MeteredOverrideProto convertMeteredOverrideToProto( + @MeteredOverride int override) { + return switch (override) { + case EthernetConfiguration.METERED_OVERRIDE_FORCE_METERED -> + MeteredOverrideProto.METERED_OVERRIDE_FORCE_METERED; + case EthernetConfiguration.METERED_OVERRIDE_FORCE_UNMETERED -> + MeteredOverrideProto.METERED_OVERRIDE_FORCE_UNMETERED; + case EthernetConfiguration.METERED_OVERRIDE_NONE -> + MeteredOverrideProto.METERED_OVERRIDE_NONE; + default -> { + Log.e(TAG, "Ignore invalid metered override: " + override); + yield MeteredOverrideProto.METERED_OVERRIDE_NONE; + } + }; + } + + /** + * Converts a {@link MeteredOverrideProto} value to a corresponding value of + * {@link EthernetConfiguration.MeteredOverride} type. + */ + public static @MeteredOverride int convertMeteredOverrideFromProto( + MeteredOverrideProto protoOverride) { + requireNonNull(protoOverride, "MeteredOverrideProto must not be null"); + return switch (protoOverride) { + case METERED_OVERRIDE_FORCE_METERED -> + EthernetConfiguration.METERED_OVERRIDE_FORCE_METERED; + case METERED_OVERRIDE_FORCE_UNMETERED -> + EthernetConfiguration.METERED_OVERRIDE_FORCE_UNMETERED; + case METERED_OVERRIDE_NONE -> + EthernetConfiguration.METERED_OVERRIDE_NONE; + default -> { + Log.e(TAG, "Ignore invalid metered override: " + protoOverride); + yield EthernetConfiguration.METERED_OVERRIDE_NONE; + } + }; + } +} diff --git a/tests/unit/java/com/android/server/net/ProtoConfigUtilsTest.java b/tests/unit/java/com/android/server/net/ProtoConfigUtilsTest.java new file mode 100644 index 0000000000..b555c56df9 --- /dev/null +++ b/tests/unit/java/com/android/server/net/ProtoConfigUtilsTest.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2025 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.server.net; + +import static org.junit.Assert.assertEquals; + +import android.net.EthernetConfiguration; +import android.os.Build; + +import com.android.server.network.configstore.proto.NetworkConfigStoreProto.MeteredOverrideProto; +import com.android.testutils.DevSdkIgnoreRule; +import com.android.testutils.DevSdkIgnoreRunner; + +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * Unit tests for {@link ProtoConfigUtils} + */ +@RunWith(DevSdkIgnoreRunner.class) +@DevSdkIgnoreRule.IgnoreUpTo(Build.VERSION_CODES.S_V2) +public class ProtoConfigUtilsTest { + @Test + public void testconvertMeteredOverrideToProto() { + assertEquals(MeteredOverrideProto.METERED_OVERRIDE_FORCE_METERED, + ProtoConfigUtils.convertMeteredOverrideToProto( + EthernetConfiguration.METERED_OVERRIDE_FORCE_METERED)); + assertEquals(MeteredOverrideProto.METERED_OVERRIDE_FORCE_UNMETERED, + ProtoConfigUtils.convertMeteredOverrideToProto( + EthernetConfiguration.METERED_OVERRIDE_FORCE_UNMETERED)); + assertEquals(MeteredOverrideProto.METERED_OVERRIDE_NONE, + ProtoConfigUtils.convertMeteredOverrideToProto( + EthernetConfiguration.METERED_OVERRIDE_NONE)); + } + + @Test + public void testConvertMeteredOverrideFromProto() { + assertEquals(EthernetConfiguration.METERED_OVERRIDE_FORCE_METERED, + ProtoConfigUtils.convertMeteredOverrideFromProto( + MeteredOverrideProto.METERED_OVERRIDE_FORCE_METERED)); + assertEquals(EthernetConfiguration.METERED_OVERRIDE_FORCE_UNMETERED, + ProtoConfigUtils.convertMeteredOverrideFromProto( + MeteredOverrideProto.METERED_OVERRIDE_FORCE_UNMETERED)); + assertEquals(EthernetConfiguration.METERED_OVERRIDE_NONE, + ProtoConfigUtils.convertMeteredOverrideFromProto( + MeteredOverrideProto.METERED_OVERRIDE_NONE)); + } +} From a9454a1b48746a4536d454f1cfecddf80f0452f3 Mon Sep 17 00:00:00 2001 From: Chuwei He Date: Wed, 3 Sep 2025 13:44:32 +0900 Subject: [PATCH 4/5] Add conversion util methods for LinkAddress This patch adds util methods to convert LinkAddress to and from its proto equivalent, and also adds unit tests to test the conversion. Test: atest ConnectivityCoverageTests Bug: 397536853 Flag: EXEMPT mainline Change-Id: I66243dc94f9b2619551f957c698b3bc0c285aced --- .../android/server/net/ProtoConfigUtils.java | 27 +++++++++++++++++++ .../server/net/ProtoConfigUtilsTest.java | 27 +++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/service-t/src/com/android/server/net/ProtoConfigUtils.java b/service-t/src/com/android/server/net/ProtoConfigUtils.java index 5428bd3da8..6988516714 100644 --- a/service-t/src/com/android/server/net/ProtoConfigUtils.java +++ b/service-t/src/com/android/server/net/ProtoConfigUtils.java @@ -19,8 +19,11 @@ import static java.util.Objects.requireNonNull; import android.net.EthernetConfiguration; import android.net.EthernetConfiguration.MeteredOverride; +import android.net.InetAddresses; +import android.net.LinkAddress; import android.util.Log; +import com.android.server.network.configstore.proto.NetworkConfigStoreProto.LinkAddressProto; import com.android.server.network.configstore.proto.NetworkConfigStoreProto.MeteredOverrideProto; /** @@ -69,4 +72,28 @@ public class ProtoConfigUtils { } }; } + + /** + * Converts an {@link LinkAddress} object to a corresponding {@link LinkAddressProto} object. + */ + public static LinkAddressProto convertLinkAddressToProto(LinkAddress linkAddress) { + requireNonNull(linkAddress, "LinkAddress must not be null"); + return LinkAddressProto.newBuilder() + .setAddress(linkAddress.getAddress().getHostAddress()) + .setPrefixLength(linkAddress.getPrefixLength()) + .build(); + } + + /** + * Converts an {@link LinkAddressProto} object to a corresponding value of {@link LinkAddress} + * type. + * + * @throws IllegalArgumentException if the address string in the proto is not a valid IP + * address. + */ + public static LinkAddress convertLinkAddressFromProto(LinkAddressProto linkAddress) { + requireNonNull(linkAddress, "LinkAddressProto must not be null"); + return new LinkAddress(InetAddresses.parseNumericAddress(linkAddress.getAddress()), + linkAddress.getPrefixLength()); + } } diff --git a/tests/unit/java/com/android/server/net/ProtoConfigUtilsTest.java b/tests/unit/java/com/android/server/net/ProtoConfigUtilsTest.java index b555c56df9..986b0a0c51 100644 --- a/tests/unit/java/com/android/server/net/ProtoConfigUtilsTest.java +++ b/tests/unit/java/com/android/server/net/ProtoConfigUtilsTest.java @@ -19,8 +19,10 @@ package com.android.server.net; import static org.junit.Assert.assertEquals; import android.net.EthernetConfiguration; +import android.net.LinkAddress; import android.os.Build; +import com.android.server.network.configstore.proto.NetworkConfigStoreProto.LinkAddressProto; import com.android.server.network.configstore.proto.NetworkConfigStoreProto.MeteredOverrideProto; import com.android.testutils.DevSdkIgnoreRule; import com.android.testutils.DevSdkIgnoreRunner; @@ -34,6 +36,10 @@ import org.junit.runner.RunWith; @RunWith(DevSdkIgnoreRunner.class) @DevSdkIgnoreRule.IgnoreUpTo(Build.VERSION_CODES.S_V2) public class ProtoConfigUtilsTest { + private static final String LINK_ADDRESS_STRING = "192.168.1.10/24"; + private static final String IP_ADDRESS_STRING = "192.168.1.10"; + private static final int PREFIX_LENGTH = 24; + @Test public void testconvertMeteredOverrideToProto() { assertEquals(MeteredOverrideProto.METERED_OVERRIDE_FORCE_METERED, @@ -59,4 +65,25 @@ public class ProtoConfigUtilsTest { ProtoConfigUtils.convertMeteredOverrideFromProto( MeteredOverrideProto.METERED_OVERRIDE_NONE)); } + + @Test + public void testConvertLinkAddressToProto() { + LinkAddress linkAddr = new LinkAddress(LINK_ADDRESS_STRING); + LinkAddressProto proto = ProtoConfigUtils.convertLinkAddressToProto(linkAddr); + + assertEquals(IP_ADDRESS_STRING, proto.getAddress()); + assertEquals(PREFIX_LENGTH, proto.getPrefixLength()); + } + + @Test + public void testConvertLinkAddressFromProto() { + LinkAddressProto proto = LinkAddressProto.newBuilder() + .setAddress(IP_ADDRESS_STRING) + .setPrefixLength(PREFIX_LENGTH) + .build(); + + LinkAddress actual = ProtoConfigUtils.convertLinkAddressFromProto(proto); + LinkAddress target = new LinkAddress(LINK_ADDRESS_STRING); + assertEquals(actual, target); + } } From c0293a238bb8b395676e8d45eb291b18da79bd65 Mon Sep 17 00:00:00 2001 From: Chuwei He Date: Wed, 3 Sep 2025 13:50:04 +0900 Subject: [PATCH 5/5] Add conversion util methods for EthernetPortSelector This patch adds util methods to convert EthernetPortSelector to and from its proto equivalent, and also adds unit tests to test the conversion. Test: atest ConnectivityCoverageTests Bug: 397536853 Flag: EXEMPT mainline Change-Id: I0603c7a4004a83448c3d6ec4c1d0c6149708fd9d --- .../android/server/net/ProtoConfigUtils.java | 47 ++++++++++++++ .../server/net/ProtoConfigUtilsTest.java | 64 +++++++++++++++++++ 2 files changed, 111 insertions(+) diff --git a/service-t/src/com/android/server/net/ProtoConfigUtils.java b/service-t/src/com/android/server/net/ProtoConfigUtils.java index 6988516714..7ed124d231 100644 --- a/service-t/src/com/android/server/net/ProtoConfigUtils.java +++ b/service-t/src/com/android/server/net/ProtoConfigUtils.java @@ -19,10 +19,14 @@ import static java.util.Objects.requireNonNull; import android.net.EthernetConfiguration; import android.net.EthernetConfiguration.MeteredOverride; +import android.net.EthernetPortSelector; import android.net.InetAddresses; import android.net.LinkAddress; +import android.net.MacAddress; +import android.text.TextUtils; import android.util.Log; +import com.android.server.network.configstore.proto.NetworkConfigStoreProto.EthernetPortSelectorProto; import com.android.server.network.configstore.proto.NetworkConfigStoreProto.LinkAddressProto; import com.android.server.network.configstore.proto.NetworkConfigStoreProto.MeteredOverrideProto; @@ -96,4 +100,47 @@ public class ProtoConfigUtils { return new LinkAddress(InetAddresses.parseNumericAddress(linkAddress.getAddress()), linkAddress.getPrefixLength()); } + + /** + * Converts an {@link EthernetPortSelector} object to a corresponding + * {@link EthernetPortSelectorProto} object. + * + * @throws IllegalArgumentException if both MAC address and interface name in + * {@code portSelector} are invalid. + */ + public static EthernetPortSelectorProto convertPortSelectorToProto( + EthernetPortSelector portSelector) { + requireNonNull(portSelector, "EthernetPortSelector must not be null"); + EthernetPortSelectorProto.Builder selectorBuilder = + EthernetPortSelectorProto.newBuilder(); + if (portSelector.getMacAddress() != null) { + selectorBuilder.setMacAddr(portSelector.getMacAddress().toString()); + } else if (!TextUtils.isEmpty(portSelector.getInterfaceName())) { + selectorBuilder.setIfaceName(portSelector.getInterfaceName()); + } else { + // This branch should not be reached theoretically. Added for safety reason. + throw new IllegalArgumentException("Both MAC address and interface name are invalid in " + + "port selector: " + portSelector); + } + return selectorBuilder.build(); + } + + /** + * Converts an {@link EthernetPortSelectorProto} object to a corresponding value of + * {@link EthernetPortSelector} type. + * + * @throws IllegalArgumentException if both MAC address and interface in {@code portSelector} + * are invalid. + */ + public static EthernetPortSelector convertPortSelectorFromProto( + EthernetPortSelectorProto portSelector) { + requireNonNull(portSelector, "EthernetPortSelectorProto must not be null"); + if (portSelector.hasMacAddr()) { + return new EthernetPortSelector(MacAddress.fromString(portSelector.getMacAddr())); + } else if (portSelector.hasIfaceName()) { + return new EthernetPortSelector(portSelector.getIfaceName()); + } else { + throw new IllegalArgumentException("No MAC address or interface is found."); + } + } } diff --git a/tests/unit/java/com/android/server/net/ProtoConfigUtilsTest.java b/tests/unit/java/com/android/server/net/ProtoConfigUtilsTest.java index 986b0a0c51..1f7b74115a 100644 --- a/tests/unit/java/com/android/server/net/ProtoConfigUtilsTest.java +++ b/tests/unit/java/com/android/server/net/ProtoConfigUtilsTest.java @@ -17,11 +17,18 @@ package com.android.server.net; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; import android.net.EthernetConfiguration; +import android.net.EthernetPortSelector; import android.net.LinkAddress; +import android.net.MacAddress; import android.os.Build; +import com.android.server.network.configstore.proto.NetworkConfigStoreProto.EthernetPortSelectorProto; import com.android.server.network.configstore.proto.NetworkConfigStoreProto.LinkAddressProto; import com.android.server.network.configstore.proto.NetworkConfigStoreProto.MeteredOverrideProto; import com.android.testutils.DevSdkIgnoreRule; @@ -39,6 +46,8 @@ public class ProtoConfigUtilsTest { private static final String LINK_ADDRESS_STRING = "192.168.1.10/24"; private static final String IP_ADDRESS_STRING = "192.168.1.10"; private static final int PREFIX_LENGTH = 24; + private static final String IFACE_NAME = "eth0"; + private static final MacAddress MAC_ADDR = MacAddress.fromString("aa:bb:cc:dd:ee:11"); @Test public void testconvertMeteredOverrideToProto() { @@ -86,4 +95,59 @@ public class ProtoConfigUtilsTest { LinkAddress target = new LinkAddress(LINK_ADDRESS_STRING); assertEquals(actual, target); } + + @Test + public void testConvertPortSelectorToProto_withMacAddress_setsMacAddrField() { + final EthernetPortSelector portSelector = new EthernetPortSelector(MAC_ADDR); + + final EthernetPortSelectorProto proto = + ProtoConfigUtils.convertPortSelectorToProto(portSelector); + + assertNotNull(proto); + assertTrue(proto.hasMacAddr()); + assertFalse(proto.hasIfaceName()); + assertEquals(MAC_ADDR.toString(), proto.getMacAddr()); + } + + @Test + public void testConvertPortSelectorToProto_withInterfaceName_setsIfaceNameField() { + final EthernetPortSelector portSelector = new EthernetPortSelector(IFACE_NAME); + + final EthernetPortSelectorProto proto = + ProtoConfigUtils.convertPortSelectorToProto(portSelector); + + assertNotNull(proto); + assertTrue(proto.hasIfaceName()); + assertFalse(proto.hasMacAddr()); + assertEquals(IFACE_NAME, proto.getIfaceName()); + } + + + @Test + public void testConvertPortSelectorFromProto_withMacAddress() { + EthernetPortSelectorProto proto = EthernetPortSelectorProto.newBuilder() + .setMacAddr(MAC_ADDR.toString()) + .build(); + + EthernetPortSelector selector = ProtoConfigUtils.convertPortSelectorFromProto(proto); + assertEquals(MAC_ADDR, selector.getMacAddress()); + } + + @Test + public void testConvertPortSelectorFromProto_withInterfaceName() { + EthernetPortSelectorProto proto = EthernetPortSelectorProto.newBuilder() + .setIfaceName(IFACE_NAME) + .build(); + + EthernetPortSelector selector = ProtoConfigUtils.convertPortSelectorFromProto(proto); + assertEquals(IFACE_NAME, selector.getInterfaceName()); + } + + @Test + public void testConvertPortSelectorFromProto_emptyProto_throwsException() { + EthernetPortSelectorProto emptyProto = EthernetPortSelectorProto.newBuilder().build(); + + assertThrows(IllegalArgumentException.class, () -> + ProtoConfigUtils.convertPortSelectorFromProto(emptyProto)); + } }