Add API to get Subscription Id
Bug: 172867224 Test: atest android.net.wifi Change-Id: I0534a71784060f1613b0b76602e9ed379ab3104e
This commit is contained in:
@@ -427,6 +427,7 @@ package android.net.wifi {
|
||||
method @Nullable public String getRequestingPackageName();
|
||||
method public double getRetriedTxPacketsPerSecond();
|
||||
method public int getScore();
|
||||
method public int getSubscriptionId();
|
||||
method public double getSuccessfulRxPacketsPerSecond();
|
||||
method public double getSuccessfulTxPacketsPerSecond();
|
||||
method public boolean isCarrierMerged();
|
||||
|
||||
@@ -25,6 +25,7 @@ import android.net.NetworkInfo.DetailedState;
|
||||
import android.os.Build;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.modules.utils.build.SdkLevel;
|
||||
@@ -195,6 +196,11 @@ public class WifiInfo implements Parcelable {
|
||||
*/
|
||||
private String mRequestingPackageName;
|
||||
|
||||
/**
|
||||
* Identify which Telephony subscription provides this network.
|
||||
*/
|
||||
private int mSubscriptionId;
|
||||
|
||||
/**
|
||||
* Running total count of lost (not ACKed) transmitted unicast data packets.
|
||||
* @hide
|
||||
@@ -321,6 +327,7 @@ public class WifiInfo implements Parcelable {
|
||||
mRssi = INVALID_RSSI;
|
||||
mLinkSpeed = LINK_SPEED_UNKNOWN;
|
||||
mFrequency = -1;
|
||||
mSubscriptionId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
@@ -347,6 +354,7 @@ public class WifiInfo implements Parcelable {
|
||||
setFQDN(null);
|
||||
setProviderFriendlyName(null);
|
||||
setPasspointUniqueId(null);
|
||||
setSubscriptionId(SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||
txBad = 0;
|
||||
txSuccess = 0;
|
||||
rxSuccess = 0;
|
||||
@@ -386,6 +394,7 @@ public class WifiInfo implements Parcelable {
|
||||
mOsuAp = source.mOsuAp;
|
||||
mFqdn = source.mFqdn;
|
||||
mProviderFriendlyName = source.mProviderFriendlyName;
|
||||
mSubscriptionId = source.mSubscriptionId;
|
||||
txBad = source.txBad;
|
||||
txRetries = source.txRetries;
|
||||
txSuccess = source.txSuccess;
|
||||
@@ -874,6 +883,28 @@ public class WifiInfo implements Parcelable {
|
||||
return mRequestingPackageName;
|
||||
}
|
||||
|
||||
/** {@hide} */
|
||||
public void setSubscriptionId(int subId) {
|
||||
mSubscriptionId = subId;
|
||||
}
|
||||
|
||||
/**
|
||||
* If this network is provisioned by a carrier, returns subscription Id corresponding to the
|
||||
* associated SIM on the device. If this network is not provisioned by a carrier, returns
|
||||
* {@link android.telephony.SubscriptionManager#INVALID_SUBSCRIPTION_ID}
|
||||
*
|
||||
* @see WifiNetworkSuggestion.Builder#setSubscriptionId(int)
|
||||
* @see android.telephony.SubscriptionInfo#getSubscriptionId()
|
||||
* {@hide}
|
||||
*/
|
||||
@SystemApi
|
||||
public int getSubscriptionId() {
|
||||
if (!SdkLevel.isAtLeastS()) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
return mSubscriptionId;
|
||||
}
|
||||
|
||||
|
||||
/** @hide */
|
||||
@UnsupportedAppUsage
|
||||
@@ -1064,6 +1095,7 @@ public class WifiInfo implements Parcelable {
|
||||
dest.writeInt(mMaxSupportedTxLinkSpeed);
|
||||
dest.writeInt(mMaxSupportedRxLinkSpeed);
|
||||
dest.writeString(mPasspointUniqueId);
|
||||
dest.writeInt(mSubscriptionId);
|
||||
}
|
||||
|
||||
/** Implement the Parcelable interface {@hide} */
|
||||
@@ -1112,6 +1144,7 @@ public class WifiInfo implements Parcelable {
|
||||
info.mMaxSupportedTxLinkSpeed = in.readInt();
|
||||
info.mMaxSupportedRxLinkSpeed = in.readInt();
|
||||
info.mPasspointUniqueId = in.readString();
|
||||
info.mSubscriptionId = in.readInt();
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.telephony.SubscriptionManager;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
@@ -50,6 +51,7 @@ public class WifiInfoTest {
|
||||
private static final int TEST_RSSI = -60;
|
||||
private static final int TEST_NETWORK_ID = 5;
|
||||
private static final int TEST_NETWORK_ID2 = 6;
|
||||
private static final int TEST_SUB_ID = 1;
|
||||
|
||||
/**
|
||||
* Verify parcel write/read with WifiInfo.
|
||||
@@ -72,6 +74,7 @@ public class WifiInfoTest {
|
||||
writeWifiInfo.setWifiStandard(TEST_WIFI_STANDARD);
|
||||
writeWifiInfo.setMaxSupportedTxLinkSpeedMbps(TEST_MAX_SUPPORTED_TX_LINK_SPEED_MBPS);
|
||||
writeWifiInfo.setMaxSupportedRxLinkSpeedMbps(TEST_MAX_SUPPORTED_RX_LINK_SPEED_MBPS);
|
||||
writeWifiInfo.setSubscriptionId(TEST_SUB_ID);
|
||||
|
||||
Parcel parcel = Parcel.obtain();
|
||||
writeWifiInfo.writeToParcel(parcel, 0);
|
||||
@@ -98,6 +101,7 @@ public class WifiInfoTest {
|
||||
readWifiInfo.getMaxSupportedTxLinkSpeedMbps());
|
||||
assertEquals(TEST_MAX_SUPPORTED_RX_LINK_SPEED_MBPS,
|
||||
readWifiInfo.getMaxSupportedRxLinkSpeedMbps());
|
||||
assertEquals(TEST_SUB_ID, readWifiInfo.getSubscriptionId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -118,6 +122,7 @@ public class WifiInfoTest {
|
||||
writeWifiInfo.setWifiStandard(TEST_WIFI_STANDARD);
|
||||
writeWifiInfo.setMaxSupportedTxLinkSpeedMbps(TEST_MAX_SUPPORTED_TX_LINK_SPEED_MBPS);
|
||||
writeWifiInfo.setMaxSupportedRxLinkSpeedMbps(TEST_MAX_SUPPORTED_RX_LINK_SPEED_MBPS);
|
||||
writeWifiInfo.setSubscriptionId(TEST_SUB_ID);
|
||||
|
||||
WifiInfo readWifiInfo = new WifiInfo(writeWifiInfo);
|
||||
|
||||
@@ -139,6 +144,7 @@ public class WifiInfoTest {
|
||||
readWifiInfo.getMaxSupportedTxLinkSpeedMbps());
|
||||
assertEquals(TEST_MAX_SUPPORTED_RX_LINK_SPEED_MBPS,
|
||||
readWifiInfo.getMaxSupportedRxLinkSpeedMbps());
|
||||
assertEquals(TEST_SUB_ID, readWifiInfo.getSubscriptionId());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,6 +165,7 @@ public class WifiInfoTest {
|
||||
assertFalse(wifiInfo.isOemPaid());
|
||||
assertFalse(wifiInfo.isOemPrivate());
|
||||
assertFalse(wifiInfo.isCarrierMerged());
|
||||
assertEquals(SubscriptionManager.INVALID_SUBSCRIPTION_ID, wifiInfo.getSubscriptionId());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user