Merge "Fix errorprone warnings that should be errors"
This commit is contained in:
@@ -76,8 +76,7 @@ public class TetheringMetrics {
|
|||||||
.setUpstreamType(UpstreamType.UT_UNKNOWN)
|
.setUpstreamType(UpstreamType.UT_UNKNOWN)
|
||||||
.setErrorCode(ErrorCode.EC_NO_ERROR)
|
.setErrorCode(ErrorCode.EC_NO_ERROR)
|
||||||
.setUpstreamEvents(UpstreamEvents.newBuilder())
|
.setUpstreamEvents(UpstreamEvents.newBuilder())
|
||||||
.setDurationMillis(0)
|
.setDurationMillis(0);
|
||||||
.build();
|
|
||||||
mBuilderMap.put(downstreamType, statsBuilder);
|
mBuilderMap.put(downstreamType, statsBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ import android.net.TetheringManager.StartTetheringCallback;
|
|||||||
import android.net.TetheringManager.TetheringEventCallback;
|
import android.net.TetheringManager.TetheringEventCallback;
|
||||||
import android.net.TetheringManager.TetheringRequest;
|
import android.net.TetheringManager.TetheringRequest;
|
||||||
import android.net.TetheringTester.TetheredDevice;
|
import android.net.TetheringTester.TetheredDevice;
|
||||||
import android.net.cts.util.CtsNetUtils;;
|
import android.net.cts.util.CtsNetUtils;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.HandlerThread;
|
import android.os.HandlerThread;
|
||||||
|
|||||||
@@ -138,6 +138,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
@SmallTest
|
@SmallTest
|
||||||
@@ -195,13 +196,11 @@ public class BpfCoordinatorTest {
|
|||||||
UPSTREAM_IFACE2, UPSTREAM_IFINDEX2, MacAddress.fromString("44:55:66:00:00:0c"),
|
UPSTREAM_IFACE2, UPSTREAM_IFINDEX2, MacAddress.fromString("44:55:66:00:00:0c"),
|
||||||
NetworkStackConstants.ETHER_MTU);
|
NetworkStackConstants.ETHER_MTU);
|
||||||
|
|
||||||
private static final HashMap<Integer, UpstreamInformation> UPSTREAM_INFORMATIONS =
|
private static final Map<Integer, UpstreamInformation> UPSTREAM_INFORMATIONS = Map.of(
|
||||||
new HashMap<Integer, UpstreamInformation>() {{
|
UPSTREAM_IFINDEX, new UpstreamInformation(UPSTREAM_IFACE_PARAMS,
|
||||||
put(UPSTREAM_IFINDEX, new UpstreamInformation(UPSTREAM_IFACE_PARAMS,
|
PUBLIC_ADDR, NetworkCapabilities.TRANSPORT_CELLULAR, TEST_NET_ID),
|
||||||
PUBLIC_ADDR, NetworkCapabilities.TRANSPORT_CELLULAR, TEST_NET_ID));
|
UPSTREAM_IFINDEX2, new UpstreamInformation(UPSTREAM_IFACE_PARAMS2,
|
||||||
put(UPSTREAM_IFINDEX2, new UpstreamInformation(UPSTREAM_IFACE_PARAMS2,
|
PUBLIC_ADDR2, NetworkCapabilities.TRANSPORT_WIFI, TEST_NET_ID2));
|
||||||
PUBLIC_ADDR2, NetworkCapabilities.TRANSPORT_WIFI, TEST_NET_ID2));
|
|
||||||
}};
|
|
||||||
|
|
||||||
private static final ClientInfo CLIENT_INFO_A = new ClientInfo(DOWNSTREAM_IFINDEX,
|
private static final ClientInfo CLIENT_INFO_A = new ClientInfo(DOWNSTREAM_IFINDEX,
|
||||||
DOWNSTREAM_MAC, PRIVATE_ADDR, MAC_A);
|
DOWNSTREAM_MAC, PRIVATE_ADDR, MAC_A);
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ public class Tether4Key extends Struct {
|
|||||||
Inet4Address.getByAddress(src4), Inet4Address.getByAddress(dst4),
|
Inet4Address.getByAddress(src4), Inet4Address.getByAddress(dst4),
|
||||||
Short.toUnsignedInt((short) srcPort), Short.toUnsignedInt((short) dstPort));
|
Short.toUnsignedInt((short) srcPort), Short.toUnsignedInt((short) dstPort));
|
||||||
} catch (UnknownHostException | IllegalArgumentException e) {
|
} catch (UnknownHostException | IllegalArgumentException e) {
|
||||||
return String.format("Invalid IP address", e);
|
return "Invalid IP address" + e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ public class Tether4Value extends Struct {
|
|||||||
Short.toUnsignedInt((short) srcPort), Short.toUnsignedInt((short) dstPort),
|
Short.toUnsignedInt((short) srcPort), Short.toUnsignedInt((short) dstPort),
|
||||||
lastUsed);
|
lastUsed);
|
||||||
} catch (UnknownHostException | IllegalArgumentException e) {
|
} catch (UnknownHostException | IllegalArgumentException e) {
|
||||||
return String.format("Invalid IP address", e);
|
return "Invalid IP address" + e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -488,4 +488,4 @@ public final class IpSecAlgorithm implements Parcelable {
|
|||||||
&& Arrays.equals(lhs.mKey, rhs.mKey)
|
&& Arrays.equals(lhs.mKey, rhs.mKey)
|
||||||
&& lhs.mTruncLenBits == rhs.mTruncLenBits);
|
&& lhs.mTruncLenBits == rhs.mTruncLenBits);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -2689,7 +2689,7 @@ public class ConnectivityServiceTest {
|
|||||||
final TestNetworkCallback generalCb = new TestNetworkCallback();
|
final TestNetworkCallback generalCb = new TestNetworkCallback();
|
||||||
final TestNetworkCallback defaultCb = new TestNetworkCallback();
|
final TestNetworkCallback defaultCb = new TestNetworkCallback();
|
||||||
mCm.registerNetworkCallback(
|
mCm.registerNetworkCallback(
|
||||||
new NetworkRequest.Builder().addTransportType(transport | transport).build(),
|
new NetworkRequest.Builder().addTransportType(transport).build(),
|
||||||
generalCb);
|
generalCb);
|
||||||
mCm.registerDefaultNetworkCallback(defaultCb);
|
mCm.registerDefaultNetworkCallback(defaultCb);
|
||||||
|
|
||||||
@@ -4755,6 +4755,81 @@ public class ConnectivityServiceTest {
|
|||||||
return new NetworkRequest.Builder().addTransportType(TRANSPORT_WIFI);
|
return new NetworkRequest.Builder().addTransportType(TRANSPORT_WIFI);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A NetworkSpecifier subclass that matches all networks but must not be visible to apps.
|
||||||
|
static class ConfidentialMatchAllNetworkSpecifier extends NetworkSpecifier implements
|
||||||
|
Parcelable {
|
||||||
|
public static final Parcelable.Creator<ConfidentialMatchAllNetworkSpecifier> CREATOR =
|
||||||
|
new Parcelable.Creator<ConfidentialMatchAllNetworkSpecifier>() {
|
||||||
|
public ConfidentialMatchAllNetworkSpecifier createFromParcel(Parcel in) {
|
||||||
|
return new ConfidentialMatchAllNetworkSpecifier();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfidentialMatchAllNetworkSpecifier[] newArray(int size) {
|
||||||
|
return new ConfidentialMatchAllNetworkSpecifier[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
@Override
|
||||||
|
public boolean canBeSatisfiedBy(NetworkSpecifier other) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NetworkSpecifier redact() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A network specifier that matches either another LocalNetworkSpecifier with the same
|
||||||
|
// string or a ConfidentialMatchAllNetworkSpecifier, and can be passed to apps as is.
|
||||||
|
static class LocalStringNetworkSpecifier extends NetworkSpecifier implements Parcelable {
|
||||||
|
public static final Parcelable.Creator<LocalStringNetworkSpecifier> CREATOR =
|
||||||
|
new Parcelable.Creator<LocalStringNetworkSpecifier>() {
|
||||||
|
public LocalStringNetworkSpecifier createFromParcel(Parcel in) {
|
||||||
|
return new LocalStringNetworkSpecifier(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalStringNetworkSpecifier[] newArray(int size) {
|
||||||
|
return new LocalStringNetworkSpecifier[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
private String mString;
|
||||||
|
|
||||||
|
LocalStringNetworkSpecifier(String string) {
|
||||||
|
mString = string;
|
||||||
|
}
|
||||||
|
|
||||||
|
LocalStringNetworkSpecifier(Parcel in) {
|
||||||
|
mString = in.readString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canBeSatisfiedBy(NetworkSpecifier other) {
|
||||||
|
if (other instanceof LocalStringNetworkSpecifier) {
|
||||||
|
return TextUtils.equals(mString,
|
||||||
|
((LocalStringNetworkSpecifier) other).mString);
|
||||||
|
}
|
||||||
|
if (other instanceof ConfidentialMatchAllNetworkSpecifier) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
dest.writeString(mString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verify request matching behavior with network specifiers.
|
* Verify request matching behavior with network specifiers.
|
||||||
*
|
*
|
||||||
@@ -4764,56 +4839,6 @@ public class ConnectivityServiceTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testNetworkSpecifier() throws Exception {
|
public void testNetworkSpecifier() throws Exception {
|
||||||
// A NetworkSpecifier subclass that matches all networks but must not be visible to apps.
|
|
||||||
class ConfidentialMatchAllNetworkSpecifier extends NetworkSpecifier implements
|
|
||||||
Parcelable {
|
|
||||||
@Override
|
|
||||||
public boolean canBeSatisfiedBy(NetworkSpecifier other) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int describeContents() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeToParcel(Parcel dest, int flags) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public NetworkSpecifier redact() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// A network specifier that matches either another LocalNetworkSpecifier with the same
|
|
||||||
// string or a ConfidentialMatchAllNetworkSpecifier, and can be passed to apps as is.
|
|
||||||
class LocalStringNetworkSpecifier extends NetworkSpecifier implements Parcelable {
|
|
||||||
private String mString;
|
|
||||||
|
|
||||||
LocalStringNetworkSpecifier(String string) {
|
|
||||||
mString = string;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canBeSatisfiedBy(NetworkSpecifier other) {
|
|
||||||
if (other instanceof LocalStringNetworkSpecifier) {
|
|
||||||
return TextUtils.equals(mString,
|
|
||||||
((LocalStringNetworkSpecifier) other).mString);
|
|
||||||
}
|
|
||||||
if (other instanceof ConfidentialMatchAllNetworkSpecifier) return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int describeContents() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void writeToParcel(Parcel dest, int flags) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NetworkRequest rEmpty1 = newWifiRequestBuilder().build();
|
NetworkRequest rEmpty1 = newWifiRequestBuilder().build();
|
||||||
NetworkRequest rEmpty2 = newWifiRequestBuilder().setNetworkSpecifier((String) null).build();
|
NetworkRequest rEmpty2 = newWifiRequestBuilder().setNetworkSpecifier((String) null).build();
|
||||||
NetworkRequest rEmpty3 = newWifiRequestBuilder().setNetworkSpecifier("").build();
|
NetworkRequest rEmpty3 = newWifiRequestBuilder().setNetworkSpecifier("").build();
|
||||||
@@ -4897,6 +4922,29 @@ public class ConnectivityServiceTest {
|
|||||||
return mContext.getAttributionTag();
|
return mContext.getAttributionTag();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class NonParcelableSpecifier extends NetworkSpecifier {
|
||||||
|
@Override
|
||||||
|
public boolean canBeSatisfiedBy(NetworkSpecifier other) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static class ParcelableSpecifier extends NonParcelableSpecifier implements Parcelable {
|
||||||
|
public static final Parcelable.Creator<NonParcelableSpecifier> CREATOR =
|
||||||
|
new Parcelable.Creator<NonParcelableSpecifier>() {
|
||||||
|
public NonParcelableSpecifier createFromParcel(Parcel in) {
|
||||||
|
return new NonParcelableSpecifier();
|
||||||
|
}
|
||||||
|
|
||||||
|
public NonParcelableSpecifier[] newArray(int size) {
|
||||||
|
return new NonParcelableSpecifier[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
@Override public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
@Override public void writeToParcel(Parcel p, int flags) {}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInvalidNetworkSpecifier() {
|
public void testInvalidNetworkSpecifier() {
|
||||||
assertThrows(IllegalArgumentException.class, () -> {
|
assertThrows(IllegalArgumentException.class, () -> {
|
||||||
@@ -4914,17 +4962,6 @@ public class ConnectivityServiceTest {
|
|||||||
mContext.getPackageName(), getAttributionTag());
|
mContext.getPackageName(), getAttributionTag());
|
||||||
});
|
});
|
||||||
|
|
||||||
class NonParcelableSpecifier extends NetworkSpecifier {
|
|
||||||
@Override
|
|
||||||
public boolean canBeSatisfiedBy(NetworkSpecifier other) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
class ParcelableSpecifier extends NonParcelableSpecifier implements Parcelable {
|
|
||||||
@Override public int describeContents() { return 0; }
|
|
||||||
@Override public void writeToParcel(Parcel p, int flags) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
final NetworkRequest.Builder builder =
|
final NetworkRequest.Builder builder =
|
||||||
new NetworkRequest.Builder().addTransportType(TRANSPORT_ETHERNET);
|
new NetworkRequest.Builder().addTransportType(TRANSPORT_ETHERNET);
|
||||||
assertThrows(ClassCastException.class, () -> {
|
assertThrows(ClassCastException.class, () -> {
|
||||||
|
|||||||
Reference in New Issue
Block a user