Merge "Add additional fields to RecommendationRequest."
am: b8f0e69ef0
Change-Id: I9a50c8aca36cf740abbc62af6879b4e6ea736855
This commit is contained in:
@@ -25758,6 +25758,8 @@ package android.net {
|
||||
method public android.net.wifi.WifiConfiguration[] getConnectableConfigs();
|
||||
method public android.net.wifi.WifiConfiguration getConnectedConfig();
|
||||
method public android.net.wifi.WifiConfiguration getDefaultWifiConfig();
|
||||
method public int getLastSelectedNetworkId();
|
||||
method public long getLastSelectedNetworkTimestamp();
|
||||
method public android.net.wifi.ScanResult[] getScanResults();
|
||||
method public void setConnectableConfigs(android.net.wifi.WifiConfiguration[]);
|
||||
method public void setConnectedConfig(android.net.wifi.WifiConfiguration);
|
||||
@@ -25771,6 +25773,7 @@ package android.net {
|
||||
method public android.net.RecommendationRequest.Builder setConnectableConfigs(android.net.wifi.WifiConfiguration[]);
|
||||
method public android.net.RecommendationRequest.Builder setConnectedWifiConfig(android.net.wifi.WifiConfiguration);
|
||||
method public android.net.RecommendationRequest.Builder setDefaultWifiConfig(android.net.wifi.WifiConfiguration);
|
||||
method public android.net.RecommendationRequest.Builder setLastSelectedNetwork(int, long);
|
||||
method public android.net.RecommendationRequest.Builder setScanResults(android.net.wifi.ScanResult[]);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,8 @@ public final class RecommendationRequest implements Parcelable {
|
||||
private final WifiConfiguration mDefaultConfig;
|
||||
private WifiConfiguration mConnectedConfig;
|
||||
private WifiConfiguration[] mConnectableConfigs;
|
||||
private final int mLastSelectedNetworkId;
|
||||
private final long mLastSelectedNetworkTimestamp;
|
||||
|
||||
/**
|
||||
* Builder class for constructing {@link RecommendationRequest} instances.
|
||||
@@ -48,17 +50,9 @@ public final class RecommendationRequest implements Parcelable {
|
||||
private WifiConfiguration mDefaultConfig;
|
||||
private WifiConfiguration mConnectedConfig;
|
||||
private WifiConfiguration[] mConnectableConfigs;
|
||||
private int mLastSelectedNetworkId;
|
||||
private long mLastSelectedTimestamp;
|
||||
|
||||
/**
|
||||
* @param scanResults the array of {@link ScanResult}s the recommendation must be
|
||||
* constrained to i.e. if a non-null wifi config recommendation is
|
||||
* returned then it must be able to connect to one of the networks in
|
||||
* the results list.
|
||||
*
|
||||
* If the array is {@code null} or empty then there is no constraint.
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public Builder setScanResults(ScanResult[] scanResults) {
|
||||
mScanResults = scanResults;
|
||||
return this;
|
||||
@@ -89,7 +83,20 @@ public final class RecommendationRequest implements Parcelable {
|
||||
* @return this
|
||||
*/
|
||||
public Builder setConnectableConfigs(WifiConfiguration[] connectableConfigs) {
|
||||
mConnectableConfigs = connectableConfigs;
|
||||
this.mConnectableConfigs = connectableConfigs;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param networkId The {@link WifiConfiguration#networkId} of the last user selected
|
||||
* network.
|
||||
* @param timestamp The {@link android.os.SystemClock#elapsedRealtime()} when the user
|
||||
* selected {@code networkId}.
|
||||
* @return this
|
||||
*/
|
||||
public Builder setLastSelectedNetwork(int networkId, long timestamp) {
|
||||
this.mLastSelectedNetworkId = networkId;
|
||||
this.mLastSelectedTimestamp = timestamp;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -97,10 +104,8 @@ public final class RecommendationRequest implements Parcelable {
|
||||
* @return a new {@link RecommendationRequest} instance
|
||||
*/
|
||||
public RecommendationRequest build() {
|
||||
return new RecommendationRequest(mScanResults,
|
||||
mDefaultConfig,
|
||||
mConnectedConfig,
|
||||
mConnectableConfigs);
|
||||
return new RecommendationRequest(mScanResults, mDefaultConfig, mConnectedConfig,
|
||||
mConnectableConfigs, mLastSelectedNetworkId, mLastSelectedTimestamp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,15 +159,35 @@ public final class RecommendationRequest implements Parcelable {
|
||||
mConnectableConfigs = connectableConfigs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The {@link WifiConfiguration#networkId} of the last user selected network.
|
||||
* {@code 0} if not set.
|
||||
*/
|
||||
public int getLastSelectedNetworkId() {
|
||||
return mLastSelectedNetworkId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The {@link android.os.SystemClock#elapsedRealtime()} when the user selected
|
||||
* {@link #getLastSelectedNetworkId()}. {@code 0} if not set.
|
||||
*/
|
||||
public long getLastSelectedNetworkTimestamp() {
|
||||
return mLastSelectedNetworkTimestamp;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
RecommendationRequest(ScanResult[] scanResults,
|
||||
WifiConfiguration defaultWifiConfig,
|
||||
WifiConfiguration connectedWifiConfig,
|
||||
WifiConfiguration[] connectableConfigs) {
|
||||
WifiConfiguration[] connectableConfigs,
|
||||
int lastSelectedNetworkId,
|
||||
long lastSelectedNetworkTimestamp) {
|
||||
mScanResults = scanResults;
|
||||
mDefaultConfig = defaultWifiConfig;
|
||||
mConnectedConfig = connectedWifiConfig;
|
||||
mConnectableConfigs = connectableConfigs;
|
||||
mLastSelectedNetworkId = lastSelectedNetworkId;
|
||||
mLastSelectedNetworkTimestamp = lastSelectedNetworkTimestamp;
|
||||
}
|
||||
|
||||
protected RecommendationRequest(Parcel in) {
|
||||
@@ -190,6 +215,9 @@ public final class RecommendationRequest implements Parcelable {
|
||||
} else {
|
||||
mConnectableConfigs = null;
|
||||
}
|
||||
|
||||
mLastSelectedNetworkId = in.readInt();
|
||||
mLastSelectedNetworkTimestamp = in.readLong();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -220,7 +248,8 @@ public final class RecommendationRequest implements Parcelable {
|
||||
dest.writeInt(0);
|
||||
}
|
||||
|
||||
|
||||
dest.writeInt(mLastSelectedNetworkId);
|
||||
dest.writeLong(mLastSelectedNetworkTimestamp);
|
||||
}
|
||||
|
||||
public static final Creator<RecommendationRequest> CREATOR =
|
||||
|
||||
@@ -3,6 +3,7 @@ package android.net;
|
||||
import android.net.wifi.ScanResult;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.os.Parcel;
|
||||
import android.os.SystemClock;
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
public class RecommendationRequestTest extends AndroidTestCase {
|
||||
@@ -10,6 +11,8 @@ public class RecommendationRequestTest extends AndroidTestCase {
|
||||
private WifiConfiguration mDefaultConfig;
|
||||
private WifiConfiguration mConnectedConfig;
|
||||
private WifiConfiguration[] mConnectableConfigs;
|
||||
private int mLastSelectedNetworkId;
|
||||
private long mLastSelectedNetworkTimestamp;
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
@@ -35,6 +38,8 @@ public class RecommendationRequestTest extends AndroidTestCase {
|
||||
mConnectedConfig = new WifiConfiguration();
|
||||
mConnectedConfig.SSID = "connected_config";
|
||||
mConnectableConfigs = new WifiConfiguration[] {mDefaultConfig, mConnectedConfig};
|
||||
mLastSelectedNetworkId = 5;
|
||||
mLastSelectedNetworkTimestamp = SystemClock.elapsedRealtime();
|
||||
}
|
||||
|
||||
public void testParceling() throws Exception {
|
||||
@@ -43,6 +48,7 @@ public class RecommendationRequestTest extends AndroidTestCase {
|
||||
.setScanResults(mScanResults)
|
||||
.setConnectedWifiConfig(mConnectedConfig)
|
||||
.setConnectableConfigs(mConnectableConfigs)
|
||||
.setLastSelectedNetwork(mLastSelectedNetworkId, mLastSelectedNetworkTimestamp)
|
||||
.build();
|
||||
|
||||
RecommendationRequest parceled = passThroughParcel(request);
|
||||
@@ -60,6 +66,8 @@ public class RecommendationRequestTest extends AndroidTestCase {
|
||||
for (int i = 0; i < parceledConfigs.length; i++) {
|
||||
assertEquals(mConnectableConfigs[i].SSID, parceledConfigs[i].SSID);
|
||||
}
|
||||
assertEquals(mLastSelectedNetworkId, parceled.getLastSelectedNetworkId());
|
||||
assertEquals(mLastSelectedNetworkTimestamp, parceled.getLastSelectedNetworkTimestamp());
|
||||
}
|
||||
|
||||
public void testParceling_nullScanResults() throws Exception {
|
||||
@@ -82,6 +90,16 @@ public class RecommendationRequestTest extends AndroidTestCase {
|
||||
assertNull(parceledConfigs);
|
||||
}
|
||||
|
||||
public void testParceling_unsetLastSelectedNetwork() throws Exception {
|
||||
RecommendationRequest request = new RecommendationRequest.Builder()
|
||||
.build();
|
||||
|
||||
RecommendationRequest parceled = passThroughParcel(request);
|
||||
|
||||
assertEquals(0, parceled.getLastSelectedNetworkId());
|
||||
assertEquals(0, parceled.getLastSelectedNetworkTimestamp());
|
||||
}
|
||||
|
||||
private RecommendationRequest passThroughParcel(RecommendationRequest request) {
|
||||
Parcel p = Parcel.obtain();
|
||||
RecommendationRequest output = null;
|
||||
|
||||
Reference in New Issue
Block a user