diff options
| author | Amin Shaikh <ashaikh@google.com> | 2016-12-21 19:56:19 +0000 |
|---|---|---|
| committer | android-build-merger <android-build-merger@google.com> | 2016-12-21 19:56:19 +0000 |
| commit | a3943850ab67dc2df1639202de6735c3991e4dc8 (patch) | |
| tree | 8dd3ca666da4373eda51aa9748d62ca907b5ce6c /core/java | |
| parent | fe35f0f4f6870e4891be1b171e7d691d7f49f23a (diff) | |
| parent | a93e57f1acbb4bb15a2516018973457bfff8d8d5 (diff) | |
Merge "Expose ScanResult#untrusted as a @SystemApi."
am: a93e57f1ac
Change-Id: I9cac16dbceb36d6ff72e92d2ab8de20bd8d70e36
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/net/RecommendationResult.java | 48 |
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; } |
