diff --git a/core/java/android/app/usage/NetworkStatsManager.java b/core/java/android/app/usage/NetworkStatsManager.java index 1ddfe0d247..1d5dc1d5df 100644 --- a/core/java/android/app/usage/NetworkStatsManager.java +++ b/core/java/android/app/usage/NetworkStatsManager.java @@ -28,7 +28,6 @@ import android.content.Context; import android.net.ConnectivityManager; import android.net.DataUsageRequest; import android.net.INetworkStatsService; -import android.net.NetworkIdentity; import android.net.NetworkStack; import android.net.NetworkTemplate; import android.net.netstats.provider.INetworkStatsProviderCallback; @@ -47,6 +46,7 @@ import android.util.DataUnit; import android.util.Log; import com.android.internal.annotations.VisibleForTesting; +import com.android.net.module.util.NetworkIdentityUtils; import java.util.Objects; @@ -628,7 +628,7 @@ public class NetworkStatsManager { default: throw new IllegalArgumentException("Cannot create template for network type " + networkType + ", subscriberId '" - + NetworkIdentity.scrubSubscriberId(subscriberId) + "'."); + + NetworkIdentityUtils.scrubSubscriberId(subscriberId) + "'."); } return template; } diff --git a/core/java/android/net/NetworkIdentity.java b/core/java/android/net/NetworkIdentity.java index 06d0fc1bf9..5d8122b6ce 100644 --- a/core/java/android/net/NetworkIdentity.java +++ b/core/java/android/net/NetworkIdentity.java @@ -22,11 +22,12 @@ import android.annotation.Nullable; import android.content.Context; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; -import android.os.Build; import android.service.NetworkIdentityProto; import android.telephony.Annotation.NetworkType; import android.util.proto.ProtoOutputStream; +import com.android.net.module.util.NetworkIdentityUtils; + import java.util.Objects; /** @@ -90,7 +91,8 @@ public class NetworkIdentity implements Comparable { builder.append(mSubType); } if (mSubscriberId != null) { - builder.append(", subscriberId=").append(scrubSubscriberId(mSubscriberId)); + builder.append(", subscriberId=") + .append(NetworkIdentityUtils.scrubSubscriberId(mSubscriberId)); } if (mNetworkId != null) { builder.append(", networkId=").append(mNetworkId); @@ -111,7 +113,8 @@ public class NetworkIdentity implements Comparable { // Not dumping mSubType, subtypes are no longer supported. if (mSubscriberId != null) { - proto.write(NetworkIdentityProto.SUBSCRIBER_ID, scrubSubscriberId(mSubscriberId)); + proto.write(NetworkIdentityProto.SUBSCRIBER_ID, + NetworkIdentityUtils.scrubSubscriberId(mSubscriberId)); } proto.write(NetworkIdentityProto.NETWORK_ID, mNetworkId); proto.write(NetworkIdentityProto.ROAMING, mRoaming); @@ -149,32 +152,6 @@ public class NetworkIdentity implements Comparable { return mDefaultNetwork; } - /** - * Scrub given IMSI on production builds. - */ - public static String scrubSubscriberId(String subscriberId) { - if (Build.IS_ENG) { - return subscriberId; - } else if (subscriberId != null) { - // TODO: parse this as MCC+MNC instead of hard-coding - return subscriberId.substring(0, Math.min(6, subscriberId.length())) + "..."; - } else { - return "null"; - } - } - - /** - * Scrub given IMSI on production builds. - */ - public static String[] scrubSubscriberId(String[] subscriberId) { - if (subscriberId == null) return null; - final String[] res = new String[subscriberId.length]; - for (int i = 0; i < res.length; i++) { - res[i] = NetworkIdentity.scrubSubscriberId(subscriberId[i]); - } - return res; - } - /** * Build a {@link NetworkIdentity} from the given {@link NetworkState} and {@code subType}, * assuming that any mobile networks are using the current IMSI. The subType if applicable, diff --git a/core/java/android/net/NetworkTemplate.java b/core/java/android/net/NetworkTemplate.java index dc33cc7b61..aa61e03b28 100644 --- a/core/java/android/net/NetworkTemplate.java +++ b/core/java/android/net/NetworkTemplate.java @@ -48,6 +48,7 @@ import android.util.Log; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.ArrayUtils; +import com.android.net.module.util.NetworkIdentityUtils; import java.io.ByteArrayOutputStream; import java.io.DataInputStream; @@ -296,11 +297,11 @@ public class NetworkTemplate implements Parcelable { builder.append("matchRule=").append(getMatchRuleName(mMatchRule)); if (mSubscriberId != null) { builder.append(", subscriberId=").append( - NetworkIdentity.scrubSubscriberId(mSubscriberId)); + NetworkIdentityUtils.scrubSubscriberId(mSubscriberId)); } if (mMatchSubscriberIds != null) { builder.append(", matchSubscriberIds=").append( - Arrays.toString(NetworkIdentity.scrubSubscriberId(mMatchSubscriberIds))); + Arrays.toString(NetworkIdentityUtils.scrubSubscriberIds(mMatchSubscriberIds))); } if (mNetworkId != null) { builder.append(", networkId=").append(mNetworkId);