Make VcnTransportInfo unparcel to null if no data contained
When VcnTransportInfo is redacted, it contains no useful information. In order to preserve the abstraction, the VcnTransportInfo should be unparcelled to null Bug: 8675309 Test: atest VcnTransportInfoTest Change-Id: Ia9dbb9f259027acc74004eb1207e0a13cea56088
This commit is contained in:
@@ -16,11 +16,12 @@
|
||||
|
||||
package android.net.vcn;
|
||||
|
||||
import static android.net.NetworkCapabilities.REDACT_NONE;
|
||||
import static android.net.NetworkCapabilities.REDACT_FOR_NETWORK_SETTINGS;
|
||||
import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.net.TransportInfo;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.os.Parcel;
|
||||
@@ -108,13 +109,24 @@ public class VcnTransportInfo implements TransportInfo, Parcelable {
|
||||
@Override
|
||||
@NonNull
|
||||
public TransportInfo makeCopy(long redactions) {
|
||||
if ((redactions & NetworkCapabilities.REDACT_FOR_NETWORK_SETTINGS) != 0) {
|
||||
return new VcnTransportInfo(null, INVALID_SUBSCRIPTION_ID);
|
||||
}
|
||||
|
||||
return new VcnTransportInfo(
|
||||
(mWifiInfo == null) ? null : mWifiInfo.makeCopy(redactions), mSubId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getApplicableRedactions() {
|
||||
return (mWifiInfo == null) ? REDACT_NONE : mWifiInfo.getApplicableRedactions();
|
||||
long redactions = REDACT_FOR_NETWORK_SETTINGS;
|
||||
|
||||
// Add additional wifi redactions if necessary
|
||||
if (mWifiInfo != null) {
|
||||
redactions |= mWifiInfo.getApplicableRedactions();
|
||||
}
|
||||
|
||||
return redactions;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@@ -135,6 +147,14 @@ public class VcnTransportInfo implements TransportInfo, Parcelable {
|
||||
public VcnTransportInfo createFromParcel(Parcel in) {
|
||||
final int subId = in.readInt();
|
||||
final WifiInfo wifiInfo = in.readParcelable(null);
|
||||
|
||||
// If all fields are their null values, return null TransportInfo to avoid
|
||||
// leaking information about this being a VCN Network (instead of macro
|
||||
// cellular, etc)
|
||||
if (wifiInfo == null && subId == INVALID_SUBSCRIPTION_ID) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new VcnTransportInfo(wifiInfo, subId);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package android.net.vcn;
|
||||
|
||||
import static android.net.NetworkCapabilities.REDACT_FOR_ACCESS_FINE_LOCATION;
|
||||
import static android.net.NetworkCapabilities.REDACT_FOR_LOCAL_MAC_ADDRESS;
|
||||
import static android.net.NetworkCapabilities.REDACT_FOR_NETWORK_SETTINGS;
|
||||
import static android.net.NetworkCapabilities.REDACT_NONE;
|
||||
import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||
@@ -26,12 +25,15 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.os.Parcel;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class VcnTransportInfoTest {
|
||||
private static final int SUB_ID = 1;
|
||||
private static final int NETWORK_ID = 5;
|
||||
@@ -55,6 +57,19 @@ public class VcnTransportInfoTest {
|
||||
assertEquals(INVALID_SUBSCRIPTION_ID, WIFI_UNDERLYING_INFO.getSubId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMakeCopyRedactForNetworkSettings() {
|
||||
for (VcnTransportInfo info : Arrays.asList(CELL_UNDERLYING_INFO, WIFI_UNDERLYING_INFO)) {
|
||||
assertEquals(
|
||||
INVALID_SUBSCRIPTION_ID,
|
||||
((VcnTransportInfo) info.makeCopy(REDACT_FOR_NETWORK_SETTINGS))
|
||||
.getSubId());
|
||||
assertNull(
|
||||
((VcnTransportInfo) info.makeCopy(REDACT_FOR_NETWORK_SETTINGS))
|
||||
.getWifiInfo());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMakeCopyRedactForAccessFineLocation() {
|
||||
assertEquals(
|
||||
@@ -75,11 +90,20 @@ public class VcnTransportInfoTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApplicableRedactions() {
|
||||
assertEquals(REDACT_NONE, CELL_UNDERLYING_INFO.getApplicableRedactions());
|
||||
assertEquals(REDACT_FOR_ACCESS_FINE_LOCATION | REDACT_FOR_LOCAL_MAC_ADDRESS
|
||||
| REDACT_FOR_NETWORK_SETTINGS,
|
||||
WIFI_UNDERLYING_INFO.getApplicableRedactions());
|
||||
public void testParcelUnparcel() {
|
||||
verifyParcelingIsNull(CELL_UNDERLYING_INFO);
|
||||
verifyParcelingIsNull(WIFI_UNDERLYING_INFO);
|
||||
}
|
||||
|
||||
private void verifyParcelingIsNull(VcnTransportInfo vcnTransportInfo) {
|
||||
VcnTransportInfo redacted = (VcnTransportInfo) vcnTransportInfo.makeCopy(
|
||||
NetworkCapabilities.REDACT_FOR_NETWORK_SETTINGS);
|
||||
|
||||
Parcel parcel = Parcel.obtain();
|
||||
redacted.writeToParcel(parcel, 0 /* flags */);
|
||||
parcel.setDataPosition(0);
|
||||
|
||||
assertNull(VcnTransportInfo.CREATOR.createFromParcel(parcel));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user