From 42312c48ccdee7a06cf039a0a3dd71256350b18e Mon Sep 17 00:00:00 2001 From: Junyu Lai Date: Wed, 5 Jan 2022 08:09:16 +0000 Subject: [PATCH 1/3] [MS40.1] Remove Clock dependencies from NetworkStatsService This includes: 1. Re-implement the BestClock in the static library. 2. Expose SystemClock#currentNetworkTimeClock as public Api Test: TH Bug: 204830222 CTS-Coverage-Bug: 213393821 Exempt-From-Owner-Approval: 1. Owner approved the change with explicitly granted submission after adderessing the straight-forward comment. 2. Owner is OOO for 3 months. Change-Id: I08c0162a7101cc6184f3eca3d4a59211183fb843 --- service-t/src/com/android/server/net/NetworkStatsService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service-t/src/com/android/server/net/NetworkStatsService.java b/service-t/src/com/android/server/net/NetworkStatsService.java index ef84ce02e2..5584293b7d 100644 --- a/service-t/src/com/android/server/net/NetworkStatsService.java +++ b/service-t/src/com/android/server/net/NetworkStatsService.java @@ -113,7 +113,6 @@ import android.net.Uri; import android.net.netstats.provider.INetworkStatsProvider; import android.net.netstats.provider.INetworkStatsProviderCallback; import android.net.netstats.provider.NetworkStatsProvider; -import android.os.BestClock; import android.os.Binder; import android.os.DropBoxManager; import android.os.Environment; @@ -149,6 +148,7 @@ import android.util.proto.ProtoOutputStream; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.FileRotator; +import com.android.net.module.util.BestClock; import com.android.net.module.util.BinderUtils; import com.android.net.module.util.CollectionUtils; import com.android.net.module.util.NetworkStatsUtils; From b2f359cc56615abf17adab88fb8a594db33390b5 Mon Sep 17 00:00:00 2001 From: Junyu Lai Date: Mon, 3 Jan 2022 14:05:45 +0000 Subject: [PATCH 2/3] [MS34.1] Replace TelephonyManager#getSubscriberId(subId) with public API Test: atest com.android.server.net.NetworkStatsSubscriptionsMonitorTest Bug: 204830222 Change-Id: I57aa4470aea1715217fa7d74f2c9067b096d1bae --- .../android/server/net/NetworkStatsSubscriptionsMonitor.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/service-t/src/com/android/server/net/NetworkStatsSubscriptionsMonitor.java b/service-t/src/com/android/server/net/NetworkStatsSubscriptionsMonitor.java index 93d0ae7da0..9bb7bb8078 100644 --- a/service-t/src/com/android/server/net/NetworkStatsSubscriptionsMonitor.java +++ b/service-t/src/com/android/server/net/NetworkStatsSubscriptionsMonitor.java @@ -101,7 +101,8 @@ public class NetworkStatsSubscriptionsMonitor extends // with empty IMSI. So filter the subs w/o a valid IMSI to prevent such registration. final List> filteredNewSubs = new ArrayList<>(); for (final int subId : newSubs) { - final String subscriberId = mTeleManager.getSubscriberId(subId); + final String subscriberId = + mTeleManager.createForSubscriptionId(subId).getSubscriberId(); if (!TextUtils.isEmpty(subscriberId)) { filteredNewSubs.add(new Pair(subId, subscriberId)); } From 6ba0487c9134a64675006a98c86488715075ac62 Mon Sep 17 00:00:00 2001 From: Junyu Lai Date: Tue, 4 Jan 2022 10:23:47 +0000 Subject: [PATCH 3/3] [MS09] Expose NetworkTemplate APIs which are needed by NetworkPolicy This change also remove getWifiNetworkKey which should not be exposed as system API. Test: atest NetworkTemplateTest Bug: 204830222 Change-Id: I924f62025a8672167f778ff790cd208c74eed878 --- framework-t/src/android/net/NetworkStats.java | 23 ++++--------------- .../src/android/net/NetworkTemplate.java | 23 ++++++++----------- 2 files changed, 14 insertions(+), 32 deletions(-) diff --git a/framework-t/src/android/net/NetworkStats.java b/framework-t/src/android/net/NetworkStats.java index 181a594cbc..b00fea4de2 100644 --- a/framework-t/src/android/net/NetworkStats.java +++ b/framework-t/src/android/net/NetworkStats.java @@ -83,10 +83,7 @@ public final class NetworkStats implements Parcelable { */ // TODO: Rename TAG_ALL to TAG_ANY. public static final int TAG_ALL = -1; - /** - * {@link #set} value for all sets combined, not including debug sets. - * @hide - */ + /** {@link #set} value for all sets combined, not including debug sets. */ public static final int SET_ALL = -1; /** {@link #set} value where background data is accounted. */ public static final int SET_DEFAULT = 0; @@ -114,9 +111,6 @@ public final class NetworkStats implements Parcelable { SET_ALL, SET_DEFAULT, SET_FOREGROUND, - SET_DEBUG_START, - SET_DBG_VPN_IN, - SET_DBG_VPN_OUT }) public @interface State { } @@ -131,10 +125,7 @@ public final class NetworkStats implements Parcelable { // TODO: Rename TAG_NONE to TAG_ALL. public static final int TAG_NONE = 0; - /** - * {@link #metered} value to account for all metered states. - * @hide - */ + /** {@link #metered} value to account for all metered states. */ public static final int METERED_ALL = -1; /** {@link #metered} value where native, unmetered data is accounted. */ public static final int METERED_NO = 0; @@ -152,10 +143,7 @@ public final class NetworkStats implements Parcelable { } - /** - * {@link #roaming} value to account for all roaming states. - * @hide - */ + /** {@link #roaming} value to account for all roaming states. */ public static final int ROAMING_ALL = -1; /** {@link #roaming} value where native, non-roaming data is accounted. */ public static final int ROAMING_NO = 0; @@ -172,10 +160,7 @@ public final class NetworkStats implements Parcelable { public @interface Roaming { } - /** - * {@link #onDefaultNetwork} value to account for all default network states. - * @hide - */ + /** {@link #onDefaultNetwork} value to account for all default network states. */ public static final int DEFAULT_NETWORK_ALL = -1; /** {@link #onDefaultNetwork} value to account for usage while not the default network. */ public static final int DEFAULT_NETWORK_NO = 0; diff --git a/framework-t/src/android/net/NetworkTemplate.java b/framework-t/src/android/net/NetworkTemplate.java index 659ad06039..e9084b0196 100644 --- a/framework-t/src/android/net/NetworkTemplate.java +++ b/framework-t/src/android/net/NetworkTemplate.java @@ -16,6 +16,7 @@ package android.net; +import static android.annotation.SystemApi.Client.MODULE_LIBRARIES; import static android.net.ConnectivityManager.TYPE_BLUETOOTH; import static android.net.ConnectivityManager.TYPE_ETHERNET; import static android.net.ConnectivityManager.TYPE_MOBILE; @@ -39,7 +40,9 @@ import static android.net.NetworkStats.ROAMING_YES; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; +import android.annotation.SystemApi; import android.compat.annotation.UnsupportedAppUsage; +import android.net.wifi.WifiInfo; import android.os.Build; import android.os.Parcel; import android.os.Parcelable; @@ -70,7 +73,7 @@ import java.util.TreeSet; * * @hide */ -// @SystemApi(client = MODULE_LIBRARIES) +@SystemApi(client = MODULE_LIBRARIES) public final class NetworkTemplate implements Parcelable { /** @hide */ @Retention(RetentionPolicy.SOURCE) @@ -572,6 +575,7 @@ public final class NetworkTemplate implements Parcelable { /** * Get subscriber Id of the template. + * @hide */ @Nullable @UnsupportedAppUsage @@ -588,26 +592,19 @@ public final class NetworkTemplate implements Parcelable { } /** - * Get Wifi Network Key of the template. See {@link WifiInfo#getCurrentNetworkKey()}. + * Get the set of Wifi Network Keys of the template. + * See {@link WifiInfo#getCurrentNetworkKey()}. */ - @Nullable - public String getWifiNetworkKey() { - return CollectionUtils.isEmpty(mMatchWifiNetworkKeys) ? null : mMatchWifiNetworkKeys[0]; - } - - /** - * Get set of Wifi Network Keys of the template. - */ - @Nullable + @NonNull public Set getWifiNetworkKeys() { return new ArraySet<>(Arrays.asList(mMatchWifiNetworkKeys)); } /** @hide */ - // TODO: Remove this and replace all callers with {@link #getWifiNetworkKey()}. + // TODO: Remove this and replace all callers with {@link #getWifiNetworkKeys()}. @Nullable public String getNetworkId() { - return getWifiNetworkKey(); + return getWifiNetworkKeys().isEmpty() ? null : getWifiNetworkKeys().iterator().next(); } /**