summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
authorAmin Shaikh <ashaikh@google.com>2016-12-09 17:11:50 -0800
committerAmin Shaikh <ashaikh@google.com>2016-12-21 11:46:22 -0800
commit3d18c621cbff73fb6fe4bf68ae55c17c8545d3e9 (patch)
tree759cf48d47792165b416b8bf8de3183d2433144f /core/java/android
parent48d5d6cda821282a77926795237ce895cc1dfde7 (diff)
Expose ScanResult#untrusted as a @SystemApi.
- Expose ScanResult#untrusted to inform NetworkRecommendationProviders that a ScanResult does not correspond to a saved network. - Add static construction methods and assertions to RecommendationResult Test: runtest frameworks-services Bug: 33490132 Change-Id: If7006040f63843c1c468c9d95c5c017383c5c5dd Merged-In: If7006040f63843c1c468c9d95c5c017383c5c5dd
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/net/RecommendationResult.java48
1 files changed, 45 insertions, 3 deletions
diff --git a/core/java/android/net/RecommendationResult.java b/core/java/android/net/RecommendationResult.java
index a330d8445151..70cf09c7df5b 100644
--- a/core/java/android/net/RecommendationResult.java
+++ b/core/java/android/net/RecommendationResult.java
@@ -16,6 +16,7 @@
package android.net;
+import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.net.wifi.WifiConfiguration;
@@ -23,6 +24,7 @@ import android.os.Parcel;
import android.os.Parcelable;
import com.android.internal.annotations.VisibleForTesting;
+import com.android.internal.util.Preconditions;
/**
* The result of a network recommendation.
@@ -34,7 +36,32 @@ import com.android.internal.annotations.VisibleForTesting;
public final class RecommendationResult implements Parcelable {
private final WifiConfiguration mWifiConfiguration;
- public RecommendationResult(@Nullable WifiConfiguration wifiConfiguration) {
+ /**
+ * Create a {@link RecommendationResult} that indicates that no network connection should be
+ * attempted at this time.
+ *
+ * @return a {@link RecommendationResult}
+ */
+ public static RecommendationResult createDoNotConnectRecommendation() {
+ return new RecommendationResult((WifiConfiguration) null);
+ }
+
+ /**
+ * Create a {@link RecommendationResult} that indicates that a connection attempt should be
+ * made for the given Wi-Fi network.
+ *
+ * @param wifiConfiguration {@link WifiConfiguration} with at least SSID and BSSID set.
+ * @return a {@link RecommendationResult}
+ */
+ public static RecommendationResult createConnectRecommendation(
+ @NonNull WifiConfiguration wifiConfiguration) {
+ Preconditions.checkNotNull(wifiConfiguration, "wifiConfiguration must not be null");
+ Preconditions.checkNotNull(wifiConfiguration.SSID, "SSID must not be null");
+ Preconditions.checkNotNull(wifiConfiguration.BSSID, "BSSID must not be null");
+ return new RecommendationResult(wifiConfiguration);
+ }
+
+ private RecommendationResult(@Nullable WifiConfiguration wifiConfiguration) {
mWifiConfiguration = wifiConfiguration;
}
@@ -43,14 +70,29 @@ public final class RecommendationResult implements Parcelable {
}
/**
+ * @return {@code true} if a network recommendation exists. {@code false} indicates that
+ * no connection should be attempted at this time.
+ */
+ public boolean hasRecommendation() {
+ return mWifiConfiguration != null;
+ }
+
+ /**
* @return The recommended {@link WifiConfiguration} to connect to. A {@code null} value
- * indicates that no WiFi connection should be attempted at this time.
+ * is returned if {@link #hasRecommendation} returns {@code false}.
*/
- public WifiConfiguration getWifiConfiguration() {
+ @Nullable public WifiConfiguration getWifiConfiguration() {
return mWifiConfiguration;
}
@Override
+ public String toString() {
+ return "RecommendationResult{" +
+ "mWifiConfiguration=" + mWifiConfiguration +
+ "}";
+ }
+
+ @Override
public int describeContents() {
return 0;
}