Fix Automated API Review issues.
These API's argument/return value must be marked either @NonNull
or @Nullable.
Bug: 126701148
Bug: 126699090
Bug: 126701058
Bug: 126700772
Bug: 126699941
Bug: 126701299
Bug: 126700007
Bug: 126700900
Test: atest FrameworksNetTests
Change-Id: Id030a9f1116178b96aa3d4614b10969a537b2fc4
diff --git a/core/java/android/net/CaptivePortal.java b/core/java/android/net/CaptivePortal.java
index ba7323d..ebd8a7e 100644
--- a/core/java/android/net/CaptivePortal.java
+++ b/core/java/android/net/CaptivePortal.java
@@ -15,6 +15,7 @@
*/
package android.net;
+import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.os.IBinder;
@@ -65,7 +66,7 @@
/** @hide */
@SystemApi
@TestApi
- public CaptivePortal(IBinder binder) {
+ public CaptivePortal(@NonNull IBinder binder) {
mBinder = binder;
}
@@ -142,7 +143,7 @@
*/
@SystemApi
@TestApi
- public void logEvent(int eventId, String packageName) {
+ public void logEvent(int eventId, @NonNull String packageName) {
try {
ICaptivePortal.Stub.asInterface(mBinder).logEvent(eventId, packageName);
} catch (RemoteException e) {
diff --git a/core/java/android/net/StaticIpConfiguration.java b/core/java/android/net/StaticIpConfiguration.java
index 99cf3a9..0728d83 100644
--- a/core/java/android/net/StaticIpConfiguration.java
+++ b/core/java/android/net/StaticIpConfiguration.java
@@ -16,6 +16,8 @@
package android.net;
+import android.annotation.NonNull;
+import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.annotation.UnsupportedAppUsage;
@@ -53,22 +55,26 @@
public final class StaticIpConfiguration implements Parcelable {
/** @hide */
@UnsupportedAppUsage
+ @Nullable
public LinkAddress ipAddress;
/** @hide */
@UnsupportedAppUsage
+ @Nullable
public InetAddress gateway;
/** @hide */
@UnsupportedAppUsage
+ @NonNull
public final ArrayList<InetAddress> dnsServers;
/** @hide */
@UnsupportedAppUsage
+ @Nullable
public String domains;
public StaticIpConfiguration() {
dnsServers = new ArrayList<InetAddress>();
}
- public StaticIpConfiguration(StaticIpConfiguration source) {
+ public StaticIpConfiguration(@Nullable StaticIpConfiguration source) {
this();
if (source != null) {
// All of these except dnsServers are immutable, so no need to make copies.
@@ -86,38 +92,38 @@
domains = null;
}
- public LinkAddress getIpAddress() {
+ public @Nullable LinkAddress getIpAddress() {
return ipAddress;
}
- public void setIpAddress(LinkAddress ipAddress) {
+ public void setIpAddress(@Nullable LinkAddress ipAddress) {
this.ipAddress = ipAddress;
}
- public InetAddress getGateway() {
+ public @Nullable InetAddress getGateway() {
return gateway;
}
- public void setGateway(InetAddress gateway) {
+ public void setGateway(@Nullable InetAddress gateway) {
this.gateway = gateway;
}
- public List<InetAddress> getDnsServers() {
+ public @NonNull List<InetAddress> getDnsServers() {
return dnsServers;
}
- public String getDomains() {
+ public @Nullable String getDomains() {
return domains;
}
- public void setDomains(String newDomains) {
+ public void setDomains(@Nullable String newDomains) {
domains = newDomains;
}
/**
* Add a DNS server to this configuration.
*/
- public void addDnsServer(InetAddress server) {
+ public void addDnsServer(@NonNull InetAddress server) {
dnsServers.add(server);
}
@@ -128,7 +134,7 @@
* route to the gateway as well. This configuration is arguably invalid, but it used to work
* in K and earlier, and other OSes appear to accept it.
*/
- public List<RouteInfo> getRoutes(String iface) {
+ public @NonNull List<RouteInfo> getRoutes(String iface) {
List<RouteInfo> routes = new ArrayList<RouteInfo>(3);
if (ipAddress != null) {
RouteInfo connectedRoute = new RouteInfo(ipAddress, null, iface);
@@ -150,7 +156,7 @@
* IPv6 configuration) will not be included.
* @hide
*/
- public LinkProperties toLinkProperties(String iface) {
+ public @NonNull LinkProperties toLinkProperties(String iface) {
LinkProperties lp = new LinkProperties();
lp.setInterfaceName(iface);
if (ipAddress != null) {
diff --git a/core/java/android/net/captiveportal/CaptivePortalProbeResult.java b/core/java/android/net/captiveportal/CaptivePortalProbeResult.java
index 3930344..a1d3de2 100644
--- a/core/java/android/net/captiveportal/CaptivePortalProbeResult.java
+++ b/core/java/android/net/captiveportal/CaptivePortalProbeResult.java
@@ -16,6 +16,7 @@
package android.net.captiveportal;
+import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.annotation.TestApi;
@@ -39,14 +40,18 @@
*/
public static final int PARTIAL_CODE = -1;
+ @NonNull
public static final CaptivePortalProbeResult FAILED = new CaptivePortalProbeResult(FAILED_CODE);
+ @NonNull
public static final CaptivePortalProbeResult SUCCESS =
new CaptivePortalProbeResult(SUCCESS_CODE);
public static final CaptivePortalProbeResult PARTIAL =
new CaptivePortalProbeResult(PARTIAL_CODE);
private final int mHttpResponseCode; // HTTP response code returned from Internet probe.
+ @Nullable
public final String redirectUrl; // Redirect destination returned from Internet probe.
+ @Nullable
public final String detectUrl; // URL where a 204 response code indicates
// captive portal has been appeased.
@Nullable
@@ -56,12 +61,13 @@
this(httpResponseCode, null, null);
}
- public CaptivePortalProbeResult(int httpResponseCode, String redirectUrl, String detectUrl) {
+ public CaptivePortalProbeResult(int httpResponseCode, @Nullable String redirectUrl,
+ @Nullable String detectUrl) {
this(httpResponseCode, redirectUrl, detectUrl, null);
}
- public CaptivePortalProbeResult(int httpResponseCode, String redirectUrl, String detectUrl,
- CaptivePortalProbeSpec probeSpec) {
+ public CaptivePortalProbeResult(int httpResponseCode, @Nullable String redirectUrl,
+ @Nullable String detectUrl, @Nullable CaptivePortalProbeSpec probeSpec) {
mHttpResponseCode = httpResponseCode;
this.redirectUrl = redirectUrl;
this.detectUrl = detectUrl;
diff --git a/core/java/android/net/captiveportal/CaptivePortalProbeSpec.java b/core/java/android/net/captiveportal/CaptivePortalProbeSpec.java
index 7ad4ecf..6c6a16c 100644
--- a/core/java/android/net/captiveportal/CaptivePortalProbeSpec.java
+++ b/core/java/android/net/captiveportal/CaptivePortalProbeSpec.java
@@ -19,6 +19,8 @@
import static android.net.captiveportal.CaptivePortalProbeResult.PORTAL_CODE;
import static android.net.captiveportal.CaptivePortalProbeResult.SUCCESS_CODE;
+import static com.android.internal.util.Preconditions.checkNotNull;
+
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
@@ -48,9 +50,10 @@
private final String mEncodedSpec;
private final URL mUrl;
- CaptivePortalProbeSpec(String encodedSpec, URL url) {
- mEncodedSpec = encodedSpec;
- mUrl = url;
+ CaptivePortalProbeSpec(@NonNull String encodedSpec, @NonNull URL url)
+ throws NullPointerException {
+ mEncodedSpec = checkNotNull(encodedSpec);
+ mUrl = checkNotNull(url);
}
/**
@@ -64,7 +67,7 @@
*/
@VisibleForTesting
@NonNull
- public static CaptivePortalProbeSpec parseSpec(String spec) throws ParseException,
+ public static CaptivePortalProbeSpec parseSpec(@NonNull String spec) throws ParseException,
MalformedURLException {
if (TextUtils.isEmpty(spec)) {
throw new ParseException("Empty probe spec", 0 /* errorOffset */);
@@ -84,7 +87,8 @@
}
@Nullable
- private static Pattern parsePatternIfNonEmpty(String pattern, int pos) throws ParseException {
+ private static Pattern parsePatternIfNonEmpty(@Nullable String pattern, int pos)
+ throws ParseException {
if (TextUtils.isEmpty(pattern)) {
return null;
}
@@ -120,8 +124,9 @@
* <p>Each spec is separated by @@,@@ and follows the format for {@link #parseSpec(String)}.
* <p>This method does not throw but ignores any entry that could not be parsed.
*/
+ @NonNull
public static Collection<CaptivePortalProbeSpec> parseCaptivePortalProbeSpecs(
- String settingsVal) {
+ @NonNull String settingsVal) {
List<CaptivePortalProbeSpec> specs = new ArrayList<>();
if (settingsVal != null) {
for (String spec : TextUtils.split(settingsVal, SPEC_SEPARATOR)) {
@@ -142,12 +147,15 @@
/**
* Get the probe result from HTTP status and location header.
*/
+ @NonNull
public abstract CaptivePortalProbeResult getResult(int status, @Nullable String locationHeader);
+ @NonNull
public String getEncodedSpec() {
return mEncodedSpec;
}
+ @NonNull
public URL getUrl() {
return mUrl;
}
diff --git a/core/java/android/net/metrics/ApfProgramEvent.java b/core/java/android/net/metrics/ApfProgramEvent.java
index 8601005..30d3b84 100644
--- a/core/java/android/net/metrics/ApfProgramEvent.java
+++ b/core/java/android/net/metrics/ApfProgramEvent.java
@@ -17,6 +17,7 @@
package android.net.metrics;
import android.annotation.IntDef;
+import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.annotation.UnsupportedAppUsage;
@@ -95,7 +96,7 @@
/**
* Utility to create an instance of {@link ApfProgramEvent}.
*/
- public static class Builder {
+ public static final class Builder {
private long mLifetime;
private long mActualLifetime;
private int mFilteredRas;
@@ -106,6 +107,7 @@
/**
* Set the maximum computed lifetime of the program in seconds.
*/
+ @NonNull
public Builder setLifetime(long lifetime) {
mLifetime = lifetime;
return this;
@@ -114,6 +116,7 @@
/**
* Set the effective program lifetime in seconds.
*/
+ @NonNull
public Builder setActualLifetime(long lifetime) {
mActualLifetime = lifetime;
return this;
@@ -122,6 +125,7 @@
/**
* Set the number of RAs filtered by the APF program.
*/
+ @NonNull
public Builder setFilteredRas(int filteredRas) {
mFilteredRas = filteredRas;
return this;
@@ -130,6 +134,7 @@
/**
* Set the total number of current RAs at generation time.
*/
+ @NonNull
public Builder setCurrentRas(int currentRas) {
mCurrentRas = currentRas;
return this;
@@ -138,6 +143,7 @@
/**
* Set the length of the APF program in bytes.
*/
+ @NonNull
public Builder setProgramLength(int programLength) {
mProgramLength = programLength;
return this;
@@ -146,6 +152,7 @@
/**
* Set the flags describing what an Apf program filters.
*/
+ @NonNull
public Builder setFlags(boolean hasIPv4, boolean multicastFilterOn) {
mFlags = flagsFor(hasIPv4, multicastFilterOn);
return this;
@@ -154,6 +161,7 @@
/**
* Build a new {@link ApfProgramEvent}.
*/
+ @NonNull
public ApfProgramEvent build() {
return new ApfProgramEvent(mLifetime, mActualLifetime, mFilteredRas, mCurrentRas,
mProgramLength, mFlags);
diff --git a/core/java/android/net/metrics/ApfStats.java b/core/java/android/net/metrics/ApfStats.java
index 844a134..ddc788d 100644
--- a/core/java/android/net/metrics/ApfStats.java
+++ b/core/java/android/net/metrics/ApfStats.java
@@ -16,6 +16,7 @@
package android.net.metrics;
+import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.annotation.UnsupportedAppUsage;
@@ -125,7 +126,7 @@
*/
@SystemApi
@TestApi
- public static class Builder {
+ public static final class Builder {
private long mDurationMs;
private int mReceivedRas;
private int mMatchingRas;
@@ -140,6 +141,7 @@
/**
* Set the time interval in milliseconds these statistics covers.
*/
+ @NonNull
public Builder setDurationMs(long durationMs) {
mDurationMs = durationMs;
return this;
@@ -148,6 +150,7 @@
/**
* Set the number of received RAs.
*/
+ @NonNull
public Builder setReceivedRas(int receivedRas) {
mReceivedRas = receivedRas;
return this;
@@ -156,6 +159,7 @@
/**
* Set the number of received RAs matching a known RA.
*/
+ @NonNull
public Builder setMatchingRas(int matchingRas) {
mMatchingRas = matchingRas;
return this;
@@ -164,6 +168,7 @@
/**
* Set the number of received RAs ignored due to the MAX_RAS limit.
*/
+ @NonNull
public Builder setDroppedRas(int droppedRas) {
mDroppedRas = droppedRas;
return this;
@@ -172,6 +177,7 @@
/**
* Set the number of received RAs with a minimum lifetime of 0.
*/
+ @NonNull
public Builder setZeroLifetimeRas(int zeroLifetimeRas) {
mZeroLifetimeRas = zeroLifetimeRas;
return this;
@@ -180,6 +186,7 @@
/**
* Set the number of received RAs that could not be parsed.
*/
+ @NonNull
public Builder setParseErrors(int parseErrors) {
mParseErrors = parseErrors;
return this;
@@ -188,6 +195,7 @@
/**
* Set the number of APF program updates from receiving RAs.
*/
+ @NonNull
public Builder setProgramUpdates(int programUpdates) {
mProgramUpdates = programUpdates;
return this;
@@ -196,6 +204,7 @@
/**
* Set the total number of APF program updates.
*/
+ @NonNull
public Builder setProgramUpdatesAll(int programUpdatesAll) {
mProgramUpdatesAll = programUpdatesAll;
return this;
@@ -204,6 +213,7 @@
/**
* Set the number of APF program updates from allowing multicast traffic.
*/
+ @NonNull
public Builder setProgramUpdatesAllowingMulticast(int programUpdatesAllowingMulticast) {
mProgramUpdatesAllowingMulticast = programUpdatesAllowingMulticast;
return this;
@@ -212,6 +222,7 @@
/**
* Set the maximum APF program size advertised by hardware.
*/
+ @NonNull
public Builder setMaxProgramSize(int maxProgramSize) {
mMaxProgramSize = maxProgramSize;
return this;
@@ -220,6 +231,7 @@
/**
* Create a new {@link ApfStats}.
*/
+ @NonNull
public ApfStats build() {
return new ApfStats(mDurationMs, mReceivedRas, mMatchingRas, mDroppedRas,
mZeroLifetimeRas, mParseErrors, mProgramUpdates, mProgramUpdatesAll,
diff --git a/core/java/android/net/metrics/DhcpClientEvent.java b/core/java/android/net/metrics/DhcpClientEvent.java
index 3008115..93063cb 100644
--- a/core/java/android/net/metrics/DhcpClientEvent.java
+++ b/core/java/android/net/metrics/DhcpClientEvent.java
@@ -16,6 +16,7 @@
package android.net.metrics;
+import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.annotation.UnsupportedAppUsage;
@@ -51,13 +52,14 @@
/**
* Utility to create an instance of {@link ApfProgramEvent}.
*/
- public static class Builder {
+ public static final class Builder {
private String mMsg;
private int mDurationMs;
/**
* Set the message of the event.
*/
+ @NonNull
public Builder setMsg(String msg) {
mMsg = msg;
return this;
@@ -66,6 +68,7 @@
/**
* Set the duration of the event in milliseconds.
*/
+ @NonNull
public Builder setDurationMs(int durationMs) {
mDurationMs = durationMs;
return this;
@@ -74,6 +77,7 @@
/**
* Create a new {@link DhcpClientEvent}.
*/
+ @NonNull
public DhcpClientEvent build() {
return new DhcpClientEvent(mMsg, mDurationMs);
}
diff --git a/core/java/android/net/metrics/IpConnectivityLog.java b/core/java/android/net/metrics/IpConnectivityLog.java
index 5b5a235..680c015 100644
--- a/core/java/android/net/metrics/IpConnectivityLog.java
+++ b/core/java/android/net/metrics/IpConnectivityLog.java
@@ -16,6 +16,7 @@
package android.net.metrics;
+import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.net.ConnectivityMetricsEvent;
@@ -41,7 +42,7 @@
/** @hide */
public static final String SERVICE_NAME = "connmetrics";
-
+ @NonNull
private IIpConnectivityMetrics mService;
/**
@@ -57,7 +58,7 @@
/** @hide */
@VisibleForTesting
- public IpConnectivityLog(IIpConnectivityMetrics service) {
+ public IpConnectivityLog(@NonNull IIpConnectivityMetrics service) {
mService = service;
}
@@ -83,7 +84,7 @@
* @return true if the event was successfully logged.
* @hide
*/
- public boolean log(ConnectivityMetricsEvent ev) {
+ public boolean log(@NonNull ConnectivityMetricsEvent ev) {
if (!checkLoggerService()) {
if (DBG) {
Log.d(TAG, SERVICE_NAME + " service was not ready");
@@ -109,7 +110,7 @@
* @param data is a Parcelable instance representing the event.
* @return true if the event was successfully logged.
*/
- public boolean log(long timestamp, Event data) {
+ public boolean log(long timestamp, @NonNull Event data) {
ConnectivityMetricsEvent ev = makeEv(data);
ev.timestamp = timestamp;
return log(ev);
@@ -121,7 +122,7 @@
* @param data is a Parcelable instance representing the event.
* @return true if the event was successfully logged.
*/
- public boolean log(String ifname, Event data) {
+ public boolean log(@NonNull String ifname, @NonNull Event data) {
ConnectivityMetricsEvent ev = makeEv(data);
ev.ifname = ifname;
return log(ev);
@@ -135,7 +136,7 @@
* @param data is a Parcelable instance representing the event.
* @return true if the event was successfully logged.
*/
- public boolean log(Network network, int[] transports, Event data) {
+ public boolean log(@NonNull Network network, @NonNull int[] transports, @NonNull Event data) {
return log(network.netId, transports, data);
}
@@ -147,7 +148,7 @@
* @param data is a Parcelable instance representing the event.
* @return true if the event was successfully logged.
*/
- public boolean log(int netid, int[] transports, Event data) {
+ public boolean log(int netid, @NonNull int[] transports, @NonNull Event data) {
ConnectivityMetricsEvent ev = makeEv(data);
ev.netId = netid;
ev.transports = BitUtils.packBits(transports);
@@ -159,7 +160,7 @@
* @param data is a Parcelable instance representing the event.
* @return true if the event was successfully logged.
*/
- public boolean log(Event data) {
+ public boolean log(@NonNull Event data) {
return log(makeEv(data));
}
diff --git a/core/java/android/net/metrics/ValidationProbeEvent.java b/core/java/android/net/metrics/ValidationProbeEvent.java
index a43dc60..9eb87ef 100644
--- a/core/java/android/net/metrics/ValidationProbeEvent.java
+++ b/core/java/android/net/metrics/ValidationProbeEvent.java
@@ -17,6 +17,7 @@
package android.net.metrics;
import android.annotation.IntDef;
+import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.os.Parcel;
@@ -81,7 +82,7 @@
/**
* Utility to create an instance of {@link ValidationProbeEvent}.
*/
- public static class Builder {
+ public static final class Builder {
private long mDurationMs;
private int mProbeType;
private int mReturnCode;
@@ -89,6 +90,7 @@
/**
* Set the duration of the probe in milliseconds.
*/
+ @NonNull
public Builder setDurationMs(long durationMs) {
mDurationMs = durationMs;
return this;
@@ -97,6 +99,7 @@
/**
* Set the probe type based on whether it was the first validation.
*/
+ @NonNull
public Builder setProbeType(int probeType, boolean firstValidation) {
mProbeType = makeProbeType(probeType, firstValidation);
return this;
@@ -105,6 +108,7 @@
/**
* Set the return code of the probe.
*/
+ @NonNull
public Builder setReturnCode(int returnCode) {
mReturnCode = returnCode;
return this;
@@ -113,6 +117,7 @@
/**
* Create a new {@link ValidationProbeEvent}.
*/
+ @NonNull
public ValidationProbeEvent build() {
return new ValidationProbeEvent(mDurationMs, mProbeType, mReturnCode);
}
diff --git a/core/java/android/os/ServiceSpecificException.java b/core/java/android/os/ServiceSpecificException.java
index 3b0f26ae..03d5d3e 100644
--- a/core/java/android/os/ServiceSpecificException.java
+++ b/core/java/android/os/ServiceSpecificException.java
@@ -15,6 +15,7 @@
*/
package android.os;
+import android.annotation.Nullable;
import android.annotation.SystemApi;
/**
@@ -34,7 +35,7 @@
public class ServiceSpecificException extends RuntimeException {
public final int errorCode;
- public ServiceSpecificException(int errorCode, String message) {
+ public ServiceSpecificException(int errorCode, @Nullable String message) {
super(message);
this.errorCode = errorCode;
}