Merge "Make VcnTransportInfo unparcel to null if no data contained" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
e0ee346120
@@ -16,11 +16,12 @@
|
|||||||
|
|
||||||
package android.net.vcn;
|
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 static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||||
|
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
|
import android.net.NetworkCapabilities;
|
||||||
import android.net.TransportInfo;
|
import android.net.TransportInfo;
|
||||||
import android.net.wifi.WifiInfo;
|
import android.net.wifi.WifiInfo;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
@@ -108,13 +109,24 @@ public class VcnTransportInfo implements TransportInfo, Parcelable {
|
|||||||
@Override
|
@Override
|
||||||
@NonNull
|
@NonNull
|
||||||
public TransportInfo makeCopy(long redactions) {
|
public TransportInfo makeCopy(long redactions) {
|
||||||
|
if ((redactions & NetworkCapabilities.REDACT_FOR_NETWORK_SETTINGS) != 0) {
|
||||||
|
return new VcnTransportInfo(null, INVALID_SUBSCRIPTION_ID);
|
||||||
|
}
|
||||||
|
|
||||||
return new VcnTransportInfo(
|
return new VcnTransportInfo(
|
||||||
(mWifiInfo == null) ? null : mWifiInfo.makeCopy(redactions), mSubId);
|
(mWifiInfo == null) ? null : mWifiInfo.makeCopy(redactions), mSubId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getApplicableRedactions() {
|
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} */
|
/** {@inheritDoc} */
|
||||||
@@ -135,6 +147,14 @@ public class VcnTransportInfo implements TransportInfo, Parcelable {
|
|||||||
public VcnTransportInfo createFromParcel(Parcel in) {
|
public VcnTransportInfo createFromParcel(Parcel in) {
|
||||||
final int subId = in.readInt();
|
final int subId = in.readInt();
|
||||||
final WifiInfo wifiInfo = in.readParcelable(null);
|
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);
|
return new VcnTransportInfo(wifiInfo, subId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
package android.net.vcn;
|
package android.net.vcn;
|
||||||
|
|
||||||
import static android.net.NetworkCapabilities.REDACT_FOR_ACCESS_FINE_LOCATION;
|
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_FOR_NETWORK_SETTINGS;
|
||||||
import static android.net.NetworkCapabilities.REDACT_NONE;
|
import static android.net.NetworkCapabilities.REDACT_NONE;
|
||||||
import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
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.assertNotEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
|
|
||||||
|
import android.net.NetworkCapabilities;
|
||||||
import android.net.wifi.WifiConfiguration;
|
import android.net.wifi.WifiConfiguration;
|
||||||
import android.net.wifi.WifiInfo;
|
import android.net.wifi.WifiInfo;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class VcnTransportInfoTest {
|
public class VcnTransportInfoTest {
|
||||||
private static final int SUB_ID = 1;
|
private static final int SUB_ID = 1;
|
||||||
private static final int NETWORK_ID = 5;
|
private static final int NETWORK_ID = 5;
|
||||||
@@ -55,6 +57,19 @@ public class VcnTransportInfoTest {
|
|||||||
assertEquals(INVALID_SUBSCRIPTION_ID, WIFI_UNDERLYING_INFO.getSubId());
|
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
|
@Test
|
||||||
public void testMakeCopyRedactForAccessFineLocation() {
|
public void testMakeCopyRedactForAccessFineLocation() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
@@ -75,11 +90,20 @@ public class VcnTransportInfoTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testApplicableRedactions() {
|
public void testParcelUnparcel() {
|
||||||
assertEquals(REDACT_NONE, CELL_UNDERLYING_INFO.getApplicableRedactions());
|
verifyParcelingIsNull(CELL_UNDERLYING_INFO);
|
||||||
assertEquals(REDACT_FOR_ACCESS_FINE_LOCATION | REDACT_FOR_LOCAL_MAC_ADDRESS
|
verifyParcelingIsNull(WIFI_UNDERLYING_INFO);
|
||||||
| REDACT_FOR_NETWORK_SETTINGS,
|
}
|
||||||
WIFI_UNDERLYING_INFO.getApplicableRedactions());
|
|
||||||
|
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
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user