Merge "Expose ScanResult#untrusted as a @SystemApi." am: a93e57f1ac

am: a3943850ab

Change-Id: Id763d2f82e10dd5843258ef09d0e65824e2c2de6
This commit is contained in:
Amin Shaikh
2016-12-21 20:02:03 +00:00
committed by android-build-merger
6 changed files with 65 additions and 16 deletions

View File

@@ -25757,9 +25757,11 @@ package android.net {
}
public final class RecommendationResult implements android.os.Parcelable {
ctor public RecommendationResult(android.net.wifi.WifiConfiguration);
method public static android.net.RecommendationResult createDoNotConnectRecommendation();
method public static android.net.RecommendationResult createConnectRecommendation(android.net.wifi.WifiConfiguration);
method public int describeContents();
method public android.net.wifi.WifiConfiguration getWifiConfiguration();
method public boolean hasRecommendation();
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator<android.net.RecommendationResult> CREATOR;
}
@@ -26808,6 +26810,7 @@ package android.net.wifi {
field public int level;
field public java.lang.CharSequence operatorFriendlyName;
field public long timestamp;
field public boolean untrusted;
field public java.lang.CharSequence venueName;
}

View File

@@ -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,13 +70,28 @@ public final class RecommendationResult implements Parcelable {
}
/**
* @return The recommended {@link WifiConfiguration} to connect to. A {@code null} value
* indicates that no WiFi connection should be attempted at this time.
* @return {@code true} if a network recommendation exists. {@code false} indicates that
* no connection should be attempted at this time.
*/
public WifiConfiguration getWifiConfiguration() {
public boolean hasRecommendation() {
return mWifiConfiguration != null;
}
/**
* @return The recommended {@link WifiConfiguration} to connect to. A {@code null} value
* is returned if {@link #hasRecommendation} returns {@code false}.
*/
@Nullable public WifiConfiguration getWifiConfiguration() {
return mWifiConfiguration;
}
@Override
public String toString() {
return "RecommendationResult{" +
"mWifiConfiguration=" + mWifiConfiguration +
"}";
}
@Override
public int describeContents() {
return 0;

View File

@@ -77,7 +77,7 @@ public class NetworkRecommendationProviderTest extends InstrumentationTestCase {
final NetworkRecommendationProvider.ResultCallback callback =
new NetworkRecommendationProvider.ResultCallback(mMockRemoteCallback, sequence);
final RecommendationResult result = new RecommendationResult(null);
final RecommendationResult result = RecommendationResult.createDoNotConnectRecommendation();
callback.onResult(result);
final ArgumentCaptor<Bundle> bundleCaptor = ArgumentCaptor.forClass(Bundle.class);
@@ -93,7 +93,7 @@ public class NetworkRecommendationProviderTest extends InstrumentationTestCase {
final NetworkRecommendationProvider.ResultCallback callback =
new NetworkRecommendationProvider.ResultCallback(mMockRemoteCallback, sequence);
final RecommendationResult result = new RecommendationResult(null);
final RecommendationResult result = RecommendationResult.createDoNotConnectRecommendation();
callback.onResult(result);
try {

View File

@@ -478,11 +478,11 @@ public class NetworkScoreService extends INetworkScoreService.Stub {
Log.d(TAG, "Returning the default network recommendation.");
}
WifiConfiguration selectedConfig = null;
if (request != null) {
selectedConfig = request.getCurrentSelectedConfig();
if (request != null && request.getCurrentSelectedConfig() != null) {
return RecommendationResult.createConnectRecommendation(
request.getCurrentSelectedConfig());
}
return new RecommendationResult(selectedConfig);
return RecommendationResult.createDoNotConnectRecommendation();
}
@Override

View File

@@ -232,9 +232,10 @@ public class NetworkScoreServiceTest {
injectProvider();
when(mContext.getMainLooper()).thenReturn(Looper.getMainLooper());
final WifiConfiguration wifiConfiguration = new WifiConfiguration();
wifiConfiguration.SSID = "testRequestRecommendation_resultReturned";
final RecommendationResult providerResult =
new RecommendationResult(wifiConfiguration);
wifiConfiguration.SSID = "testRequestRecommendation_resultReturned_SSID";
wifiConfiguration.BSSID = "testRequestRecommendation_resultReturned_BSSID";
final RecommendationResult providerResult = RecommendationResult
.createConnectRecommendation(wifiConfiguration);
final Bundle bundle = new Bundle();
bundle.putParcelable(EXTRA_RECOMMENDATION_RESULT, providerResult);
doAnswer(invocation -> {
@@ -250,6 +251,8 @@ public class NetworkScoreServiceTest {
assertNotNull(result);
assertEquals(providerResult.getWifiConfiguration().SSID,
result.getWifiConfiguration().SSID);
assertEquals(providerResult.getWifiConfiguration().BSSID,
result.getWifiConfiguration().BSSID);
}
@Test

View File

@@ -16,6 +16,7 @@
package android.net.wifi;
import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;
@@ -259,10 +260,10 @@ public class ScanResult implements Parcelable {
public long blackListTimestamp;
/**
* Status: indicating the scan result is not a result
* that is part of user's saved configurations
* Status indicating the scan result does not correspond to a user's saved configuration
* @hide
*/
@SystemApi
public boolean untrusted;
/**