Merge "[SUBID01-1]Grow NetworkIdentity to include a new mSubId field"
This commit is contained in:
@@ -42,6 +42,7 @@ package android.net {
|
||||
public class NetworkIdentity {
|
||||
method public int getOemManaged();
|
||||
method public int getRatType();
|
||||
method public int getSubId();
|
||||
method @Nullable public String getSubscriberId();
|
||||
method public int getType();
|
||||
method @Nullable public String getWifiNetworkKey();
|
||||
@@ -60,6 +61,7 @@ package android.net {
|
||||
method @NonNull public android.net.NetworkIdentity.Builder setOemManaged(int);
|
||||
method @NonNull public android.net.NetworkIdentity.Builder setRatType(int);
|
||||
method @NonNull public android.net.NetworkIdentity.Builder setRoaming(boolean);
|
||||
method @NonNull public android.net.NetworkIdentity.Builder setSubId(int);
|
||||
method @NonNull public android.net.NetworkIdentity.Builder setSubscriberId(@Nullable String);
|
||||
method @NonNull public android.net.NetworkIdentity.Builder setType(int);
|
||||
method @NonNull public android.net.NetworkIdentity.Builder setWifiNetworkKey(@Nullable String);
|
||||
@@ -72,7 +74,8 @@ package android.net {
|
||||
method @NonNull public android.net.LinkProperties getLinkProperties();
|
||||
method @NonNull public android.net.Network getNetwork();
|
||||
method @NonNull public android.net.NetworkCapabilities getNetworkCapabilities();
|
||||
method @Nullable public String getSubscriberId();
|
||||
method public int getSubId();
|
||||
method @Deprecated @Nullable public String getSubscriberId();
|
||||
method public void writeToParcel(@NonNull android.os.Parcel, int);
|
||||
field @NonNull public static final android.os.Parcelable.Creator<android.net.NetworkStateSnapshot> CREATOR;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.net.ConnectivityManager.TYPE_ETHERNET
|
||||
import android.net.ConnectivityManager.TYPE_MOBILE
|
||||
import android.net.ConnectivityManager.TYPE_NONE
|
||||
import android.net.ConnectivityManager.TYPE_WIFI
|
||||
import android.net.NetworkCapabilities.TRANSPORT_CELLULAR
|
||||
import android.net.NetworkIdentity.OEM_NONE
|
||||
import android.net.NetworkIdentity.OEM_PAID
|
||||
import android.net.NetworkIdentity.OEM_PRIVATE
|
||||
@@ -39,8 +40,11 @@ import kotlin.test.assertFailsWith
|
||||
import kotlin.test.assertFalse
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
private const val TEST_IMSI = "testimsi"
|
||||
private const val TEST_WIFI_KEY = "testwifikey"
|
||||
private const val TEST_IMSI1 = "testimsi1"
|
||||
private const val TEST_IMSI2 = "testimsi2"
|
||||
private const val TEST_SUBID1 = 1
|
||||
private const val TEST_SUBID2 = 2
|
||||
|
||||
@RunWith(DevSdkIgnoreRunner::class)
|
||||
@DevSdkIgnoreRule.IgnoreUpTo(Build.VERSION_CODES.R)
|
||||
@@ -84,7 +88,7 @@ class NetworkIdentityTest {
|
||||
fun testIsMetered() {
|
||||
// Verify network is metered.
|
||||
val netIdent1 = NetworkIdentity.buildNetworkIdentity(mockContext,
|
||||
buildMobileNetworkStateSnapshot(NetworkCapabilities(), TEST_IMSI),
|
||||
buildMobileNetworkStateSnapshot(NetworkCapabilities(), TEST_IMSI1),
|
||||
false /* defaultNetwork */, TelephonyManager.NETWORK_TYPE_UMTS)
|
||||
assertTrue(netIdent1.isMetered())
|
||||
|
||||
@@ -93,7 +97,7 @@ class NetworkIdentityTest {
|
||||
addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED)
|
||||
}.build()
|
||||
val netIdent2 = NetworkIdentity.buildNetworkIdentity(mockContext,
|
||||
buildMobileNetworkStateSnapshot(capsNotMetered, TEST_IMSI),
|
||||
buildMobileNetworkStateSnapshot(capsNotMetered, TEST_IMSI1),
|
||||
false /* defaultNetwork */, TelephonyManager.NETWORK_TYPE_UMTS)
|
||||
assertFalse(netIdent2.isMetered())
|
||||
|
||||
@@ -103,33 +107,38 @@ class NetworkIdentityTest {
|
||||
setCapability(NetworkCapabilities.NET_CAPABILITY_TEMPORARILY_NOT_METERED, true)
|
||||
}
|
||||
val netIdent3 = NetworkIdentity.buildNetworkIdentity(mockContext,
|
||||
buildMobileNetworkStateSnapshot(capsTempNotMetered, TEST_IMSI),
|
||||
buildMobileNetworkStateSnapshot(capsTempNotMetered, TEST_IMSI1),
|
||||
false /* defaultNetwork */, TelephonyManager.NETWORK_TYPE_UMTS)
|
||||
assertFalse(netIdent3.isMetered())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testBuilder() {
|
||||
val specifier1 = TelephonyNetworkSpecifier(TEST_SUBID1)
|
||||
val oemPrivateRoamingNotMeteredCap = NetworkCapabilities().apply {
|
||||
addCapability(NetworkCapabilities.NET_CAPABILITY_OEM_PRIVATE)
|
||||
addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED)
|
||||
addTransportType(TRANSPORT_CELLULAR)
|
||||
setNetworkSpecifier(specifier1)
|
||||
}
|
||||
val identFromSnapshot = NetworkIdentity.Builder().setNetworkStateSnapshot(
|
||||
buildMobileNetworkStateSnapshot(oemPrivateRoamingNotMeteredCap, TEST_IMSI))
|
||||
buildMobileNetworkStateSnapshot(oemPrivateRoamingNotMeteredCap, TEST_IMSI1))
|
||||
.setDefaultNetwork(true)
|
||||
.setRatType(TelephonyManager.NETWORK_TYPE_UMTS)
|
||||
.setSubId(TEST_SUBID1)
|
||||
.build()
|
||||
val identFromLegacyBuild = NetworkIdentity.buildNetworkIdentity(mockContext,
|
||||
buildMobileNetworkStateSnapshot(oemPrivateRoamingNotMeteredCap, TEST_IMSI),
|
||||
buildMobileNetworkStateSnapshot(oemPrivateRoamingNotMeteredCap, TEST_IMSI1),
|
||||
true /* defaultNetwork */, TelephonyManager.NETWORK_TYPE_UMTS)
|
||||
val identFromConstructor = NetworkIdentity(TYPE_MOBILE,
|
||||
TelephonyManager.NETWORK_TYPE_UMTS,
|
||||
TEST_IMSI,
|
||||
TEST_IMSI1,
|
||||
null /* wifiNetworkKey */,
|
||||
true /* roaming */,
|
||||
false /* metered */,
|
||||
true /* defaultNetwork */,
|
||||
NetworkTemplate.OEM_MANAGED_PRIVATE)
|
||||
NetworkTemplate.OEM_MANAGED_PRIVATE,
|
||||
TEST_SUBID1)
|
||||
assertEquals(identFromLegacyBuild, identFromSnapshot)
|
||||
assertEquals(identFromConstructor, identFromSnapshot)
|
||||
|
||||
@@ -222,4 +231,28 @@ class NetworkIdentityTest {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testGetSubId() {
|
||||
val specifier1 = TelephonyNetworkSpecifier(TEST_SUBID1)
|
||||
val specifier2 = TelephonyNetworkSpecifier(TEST_SUBID2)
|
||||
val capSUBID1 = NetworkCapabilities().apply {
|
||||
addTransportType(TRANSPORT_CELLULAR)
|
||||
setNetworkSpecifier(specifier1)
|
||||
}
|
||||
val capSUBID2 = NetworkCapabilities().apply {
|
||||
addTransportType(TRANSPORT_CELLULAR)
|
||||
setNetworkSpecifier(specifier2)
|
||||
}
|
||||
|
||||
val netIdent1 = NetworkIdentity.buildNetworkIdentity(mockContext,
|
||||
buildMobileNetworkStateSnapshot(capSUBID1, TEST_IMSI1),
|
||||
false /* defaultNetwork */, TelephonyManager.NETWORK_TYPE_UMTS)
|
||||
assertEquals(TEST_SUBID1, netIdent1.getSubId())
|
||||
|
||||
val netIdent2 = NetworkIdentity.buildNetworkIdentity(mockContext,
|
||||
buildMobileNetworkStateSnapshot(capSUBID2, TEST_IMSI2),
|
||||
false /* defaultNetwork */, TelephonyManager.NETWORK_TYPE_UMTS)
|
||||
assertEquals(TEST_SUBID2, netIdent2.getSubId())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,6 +87,7 @@ public class NetworkStatsCollectionTest {
|
||||
|
||||
private static final String TEST_FILE = "test.bin";
|
||||
private static final String TEST_IMSI = "310260000000000";
|
||||
private static final int TEST_SUBID = 1;
|
||||
|
||||
private static final long TIME_A = 1326088800000L; // UTC: Monday 9th January 2012 06:00:00 AM
|
||||
private static final long TIME_B = 1326110400000L; // UTC: Monday 9th January 2012 12:00:00 PM
|
||||
@@ -213,7 +214,7 @@ public class NetworkStatsCollectionTest {
|
||||
final NetworkStats.Entry entry = new NetworkStats.Entry();
|
||||
final NetworkIdentitySet identSet = new NetworkIdentitySet();
|
||||
identSet.add(new NetworkIdentity(TYPE_MOBILE, TelephonyManager.NETWORK_TYPE_UNKNOWN,
|
||||
TEST_IMSI, null, false, true, true, OEM_NONE));
|
||||
TEST_IMSI, null, false, true, true, OEM_NONE, TEST_SUBID));
|
||||
|
||||
int myUid = Process.myUid();
|
||||
int otherUidInSameUser = Process.myUid() + 1;
|
||||
@@ -475,7 +476,7 @@ public class NetworkStatsCollectionTest {
|
||||
final NetworkStatsCollection large = new NetworkStatsCollection(HOUR_IN_MILLIS);
|
||||
final NetworkIdentitySet ident = new NetworkIdentitySet();
|
||||
ident.add(new NetworkIdentity(ConnectivityManager.TYPE_MOBILE, -1, TEST_IMSI, null,
|
||||
false, true, true, OEM_NONE));
|
||||
false, true, true, OEM_NONE, TEST_SUBID));
|
||||
large.recordData(ident, UID_ALL, SET_ALL, TAG_NONE, TIME_A, TIME_B,
|
||||
new NetworkStats.Entry(12_730_893_164L, 1, 0, 0, 0));
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ class NetworkStatsDataMigrationUtilsTest {
|
||||
|
||||
@Test
|
||||
fun testReadPlatformCollection() {
|
||||
// Verify the method throws for wrong file version.
|
||||
// Verify the method throws for wrong file format.
|
||||
assertFailsWith<ProtocolException> {
|
||||
NetworkStatsDataMigrationUtils.readPlatformCollection(
|
||||
NetworkStatsCollection.Builder(BUCKET_DURATION_MS),
|
||||
|
||||
@@ -78,6 +78,7 @@ public class NetworkStatsObserversTest {
|
||||
|
||||
private static final String IMSI_1 = "310004";
|
||||
private static final String IMSI_2 = "310260";
|
||||
private static final int SUBID_1 = 1;
|
||||
private static final String TEST_SSID = "AndroidAP";
|
||||
|
||||
private static NetworkTemplate sTemplateWifi = buildTemplateWifiWildcard();
|
||||
@@ -224,7 +225,7 @@ public class NetworkStatsObserversTest {
|
||||
identSet.add(new NetworkIdentity(
|
||||
TYPE_MOBILE, TelephonyManager.NETWORK_TYPE_UNKNOWN,
|
||||
IMSI_1, null /* networkId */, false /* roaming */, true /* metered */,
|
||||
true /* defaultNetwork */, OEM_NONE));
|
||||
true /* defaultNetwork */, OEM_NONE, SUBID_1));
|
||||
return identSet;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user