Merge "Add missing validation in data classes" into udc-dev

This commit is contained in:
Andrew Sapperstein
2023-03-02 02:43:10 +00:00
committed by Android (Google) Code Review
5 changed files with 39 additions and 10 deletions

View File

@@ -207,7 +207,7 @@ public final class HotspotNetwork implements Parcelable {
} }
} }
private static void validate(long deviceId, int networkType, String networkName) { private static void validate(long deviceId, @NetworkType int networkType, String networkName) {
if (deviceId < 0) { if (deviceId < 0) {
throw new IllegalArgumentException("DeviceId must be set"); throw new IllegalArgumentException("DeviceId must be set");
} }

View File

@@ -163,9 +163,24 @@ public final class HotspotNetworkConnectionStatus implements Parcelable {
} }
} }
private static void validate(@ConnectionStatus int status) {
if (status != CONNECTION_STATUS_UNKNOWN
&& status != CONNECTION_STATUS_ENABLING_HOTSPOT
&& status != CONNECTION_STATUS_UNKNOWN_ERROR
&& status != CONNECTION_STATUS_PROVISIONING_FAILED
&& status != CONNECTION_STATUS_TETHERING_TIMEOUT
&& status != CONNECTION_STATUS_TETHERING_UNSUPPORTED
&& status != CONNECTION_STATUS_NO_CELL_DATA
&& status != CONNECTION_STATUS_ENABLING_HOTSPOT_FAILED
&& status != CONNECTION_STATUS_ENABLING_HOTSPOT_TIMEOUT
&& status != CONNECTION_STATUS_CONNECT_TO_HOTSPOT_FAILED) {
throw new IllegalArgumentException("Illegal connection status");
}
}
private HotspotNetworkConnectionStatus(@ConnectionStatus int status, private HotspotNetworkConnectionStatus(@ConnectionStatus int status,
HotspotNetwork hotspotNetwork, HotspotNetwork hotspotNetwork, Bundle extras) {
Bundle extras) { validate(status);
mStatus = status; mStatus = status;
mHotspotNetwork = hotspotNetwork; mHotspotNetwork = hotspotNetwork;
mExtras = extras; mExtras = extras;

View File

@@ -64,20 +64,25 @@ public final class KnownNetwork implements Parcelable {
NETWORK_SOURCE_NEARBY_SELF, NETWORK_SOURCE_NEARBY_SELF,
NETWORK_SOURCE_CLOUD_SELF NETWORK_SOURCE_CLOUD_SELF
}) })
public @interface NetworkSource {} public @interface NetworkSource {
}
@NetworkSource private final int mNetworkSource; @NetworkSource
private final int mNetworkSource;
private final String mSsid; private final String mSsid;
@SecurityType private final ArraySet<Integer> mSecurityTypes; @SecurityType
private final ArraySet<Integer> mSecurityTypes;
private final NetworkProviderInfo mNetworkProviderInfo; private final NetworkProviderInfo mNetworkProviderInfo;
/** /**
* Builder class for {@link KnownNetwork}. * Builder class for {@link KnownNetwork}.
*/ */
public static final class Builder { public static final class Builder {
@NetworkSource private int mNetworkSource = -1; @NetworkSource
private int mNetworkSource = -1;
private String mSsid; private String mSsid;
@SecurityType private final ArraySet<Integer> mSecurityTypes = new ArraySet<>(); @SecurityType
private final ArraySet<Integer> mSecurityTypes = new ArraySet<>();
private NetworkProviderInfo mNetworkProviderInfo; private NetworkProviderInfo mNetworkProviderInfo;
/** /**
@@ -144,7 +149,8 @@ public final class KnownNetwork implements Parcelable {
} }
} }
private static void validate(int networkSource, String ssid, Set<Integer> securityTypes, private static void validate(@NetworkSource int networkSource, String ssid,
@SecurityType Set<Integer> securityTypes,
NetworkProviderInfo networkProviderInfo) { NetworkProviderInfo networkProviderInfo) {
if (networkSource != NETWORK_SOURCE_UNKNOWN if (networkSource != NETWORK_SOURCE_UNKNOWN
&& networkSource != NETWORK_SOURCE_CLOUD_SELF && networkSource != NETWORK_SOURCE_CLOUD_SELF

View File

@@ -120,8 +120,16 @@ public final class KnownNetworkConnectionStatus implements Parcelable {
} }
} }
private static void validate(@ConnectionStatus int status) {
if (status != CONNECTION_STATUS_UNKNOWN && status != CONNECTION_STATUS_SAVED
&& status != CONNECTION_STATUS_SAVE_FAILED) {
throw new IllegalArgumentException("Illegal connection status");
}
}
private KnownNetworkConnectionStatus(@ConnectionStatus int status, KnownNetwork knownNetwork, private KnownNetworkConnectionStatus(@ConnectionStatus int status, KnownNetwork knownNetwork,
Bundle extras) { Bundle extras) {
validate(status);
mStatus = status; mStatus = status;
mKnownNetwork = knownNetwork; mKnownNetwork = knownNetwork;
mExtras = extras; mExtras = extras;

View File

@@ -172,7 +172,7 @@ public final class NetworkProviderInfo implements Parcelable {
} }
} }
private static void validate(int deviceType, String deviceName, String modelName, private static void validate(@DeviceType int deviceType, String deviceName, String modelName,
int batteryPercentage, int connectionStrength) { int batteryPercentage, int connectionStrength) {
if (deviceType != DEVICE_TYPE_UNKNOWN && deviceType != DEVICE_TYPE_PHONE if (deviceType != DEVICE_TYPE_UNKNOWN && deviceType != DEVICE_TYPE_PHONE
&& deviceType != DEVICE_TYPE_TABLET && deviceType != DEVICE_TYPE_LAPTOP && deviceType != DEVICE_TYPE_TABLET && deviceType != DEVICE_TYPE_LAPTOP