Merge "Add additional fields to RecommendationRequest." am: b8f0e69ef0 am: ac05acad45
am: b7b9c6f889
Change-Id: Ieade1643bfc4c9039d6d4f702bf3ec527679ce74
This commit is contained in:
@@ -25762,6 +25762,8 @@ package android.net {
|
|||||||
method public android.net.wifi.WifiConfiguration[] getConnectableConfigs();
|
method public android.net.wifi.WifiConfiguration[] getConnectableConfigs();
|
||||||
method public android.net.wifi.WifiConfiguration getConnectedConfig();
|
method public android.net.wifi.WifiConfiguration getConnectedConfig();
|
||||||
method public android.net.wifi.WifiConfiguration getDefaultWifiConfig();
|
method public android.net.wifi.WifiConfiguration getDefaultWifiConfig();
|
||||||
|
method public int getLastSelectedNetworkId();
|
||||||
|
method public long getLastSelectedNetworkTimestamp();
|
||||||
method public android.net.wifi.ScanResult[] getScanResults();
|
method public android.net.wifi.ScanResult[] getScanResults();
|
||||||
method public void setConnectableConfigs(android.net.wifi.WifiConfiguration[]);
|
method public void setConnectableConfigs(android.net.wifi.WifiConfiguration[]);
|
||||||
method public void setConnectedConfig(android.net.wifi.WifiConfiguration);
|
method public void setConnectedConfig(android.net.wifi.WifiConfiguration);
|
||||||
@@ -25775,6 +25777,7 @@ package android.net {
|
|||||||
method public android.net.RecommendationRequest.Builder setConnectableConfigs(android.net.wifi.WifiConfiguration[]);
|
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 setConnectedWifiConfig(android.net.wifi.WifiConfiguration);
|
||||||
method public android.net.RecommendationRequest.Builder setDefaultWifiConfig(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[]);
|
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 final WifiConfiguration mDefaultConfig;
|
||||||
private WifiConfiguration mConnectedConfig;
|
private WifiConfiguration mConnectedConfig;
|
||||||
private WifiConfiguration[] mConnectableConfigs;
|
private WifiConfiguration[] mConnectableConfigs;
|
||||||
|
private final int mLastSelectedNetworkId;
|
||||||
|
private final long mLastSelectedNetworkTimestamp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder class for constructing {@link RecommendationRequest} instances.
|
* Builder class for constructing {@link RecommendationRequest} instances.
|
||||||
@@ -48,17 +50,9 @@ public final class RecommendationRequest implements Parcelable {
|
|||||||
private WifiConfiguration mDefaultConfig;
|
private WifiConfiguration mDefaultConfig;
|
||||||
private WifiConfiguration mConnectedConfig;
|
private WifiConfiguration mConnectedConfig;
|
||||||
private WifiConfiguration[] mConnectableConfigs;
|
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) {
|
public Builder setScanResults(ScanResult[] scanResults) {
|
||||||
mScanResults = scanResults;
|
mScanResults = scanResults;
|
||||||
return this;
|
return this;
|
||||||
@@ -89,7 +83,20 @@ public final class RecommendationRequest implements Parcelable {
|
|||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
public Builder setConnectableConfigs(WifiConfiguration[] connectableConfigs) {
|
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;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,10 +104,8 @@ public final class RecommendationRequest implements Parcelable {
|
|||||||
* @return a new {@link RecommendationRequest} instance
|
* @return a new {@link RecommendationRequest} instance
|
||||||
*/
|
*/
|
||||||
public RecommendationRequest build() {
|
public RecommendationRequest build() {
|
||||||
return new RecommendationRequest(mScanResults,
|
return new RecommendationRequest(mScanResults, mDefaultConfig, mConnectedConfig,
|
||||||
mDefaultConfig,
|
mConnectableConfigs, mLastSelectedNetworkId, mLastSelectedTimestamp);
|
||||||
mConnectedConfig,
|
|
||||||
mConnectableConfigs);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,15 +159,35 @@ public final class RecommendationRequest implements Parcelable {
|
|||||||
mConnectableConfigs = connectableConfigs;
|
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
|
@VisibleForTesting
|
||||||
RecommendationRequest(ScanResult[] scanResults,
|
RecommendationRequest(ScanResult[] scanResults,
|
||||||
WifiConfiguration defaultWifiConfig,
|
WifiConfiguration defaultWifiConfig,
|
||||||
WifiConfiguration connectedWifiConfig,
|
WifiConfiguration connectedWifiConfig,
|
||||||
WifiConfiguration[] connectableConfigs) {
|
WifiConfiguration[] connectableConfigs,
|
||||||
|
int lastSelectedNetworkId,
|
||||||
|
long lastSelectedNetworkTimestamp) {
|
||||||
mScanResults = scanResults;
|
mScanResults = scanResults;
|
||||||
mDefaultConfig = defaultWifiConfig;
|
mDefaultConfig = defaultWifiConfig;
|
||||||
mConnectedConfig = connectedWifiConfig;
|
mConnectedConfig = connectedWifiConfig;
|
||||||
mConnectableConfigs = connectableConfigs;
|
mConnectableConfigs = connectableConfigs;
|
||||||
|
mLastSelectedNetworkId = lastSelectedNetworkId;
|
||||||
|
mLastSelectedNetworkTimestamp = lastSelectedNetworkTimestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected RecommendationRequest(Parcel in) {
|
protected RecommendationRequest(Parcel in) {
|
||||||
@@ -190,6 +215,9 @@ public final class RecommendationRequest implements Parcelable {
|
|||||||
} else {
|
} else {
|
||||||
mConnectableConfigs = null;
|
mConnectableConfigs = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mLastSelectedNetworkId = in.readInt();
|
||||||
|
mLastSelectedNetworkTimestamp = in.readLong();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -220,7 +248,8 @@ public final class RecommendationRequest implements Parcelable {
|
|||||||
dest.writeInt(0);
|
dest.writeInt(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dest.writeInt(mLastSelectedNetworkId);
|
||||||
|
dest.writeLong(mLastSelectedNetworkTimestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Creator<RecommendationRequest> CREATOR =
|
public static final Creator<RecommendationRequest> CREATOR =
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package android.net;
|
|||||||
import android.net.wifi.ScanResult;
|
import android.net.wifi.ScanResult;
|
||||||
import android.net.wifi.WifiConfiguration;
|
import android.net.wifi.WifiConfiguration;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
|
import android.os.SystemClock;
|
||||||
import android.test.AndroidTestCase;
|
import android.test.AndroidTestCase;
|
||||||
|
|
||||||
public class RecommendationRequestTest extends AndroidTestCase {
|
public class RecommendationRequestTest extends AndroidTestCase {
|
||||||
@@ -10,6 +11,8 @@ public class RecommendationRequestTest extends AndroidTestCase {
|
|||||||
private WifiConfiguration mDefaultConfig;
|
private WifiConfiguration mDefaultConfig;
|
||||||
private WifiConfiguration mConnectedConfig;
|
private WifiConfiguration mConnectedConfig;
|
||||||
private WifiConfiguration[] mConnectableConfigs;
|
private WifiConfiguration[] mConnectableConfigs;
|
||||||
|
private int mLastSelectedNetworkId;
|
||||||
|
private long mLastSelectedNetworkTimestamp;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
@@ -35,6 +38,8 @@ public class RecommendationRequestTest extends AndroidTestCase {
|
|||||||
mConnectedConfig = new WifiConfiguration();
|
mConnectedConfig = new WifiConfiguration();
|
||||||
mConnectedConfig.SSID = "connected_config";
|
mConnectedConfig.SSID = "connected_config";
|
||||||
mConnectableConfigs = new WifiConfiguration[] {mDefaultConfig, mConnectedConfig};
|
mConnectableConfigs = new WifiConfiguration[] {mDefaultConfig, mConnectedConfig};
|
||||||
|
mLastSelectedNetworkId = 5;
|
||||||
|
mLastSelectedNetworkTimestamp = SystemClock.elapsedRealtime();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testParceling() throws Exception {
|
public void testParceling() throws Exception {
|
||||||
@@ -43,6 +48,7 @@ public class RecommendationRequestTest extends AndroidTestCase {
|
|||||||
.setScanResults(mScanResults)
|
.setScanResults(mScanResults)
|
||||||
.setConnectedWifiConfig(mConnectedConfig)
|
.setConnectedWifiConfig(mConnectedConfig)
|
||||||
.setConnectableConfigs(mConnectableConfigs)
|
.setConnectableConfigs(mConnectableConfigs)
|
||||||
|
.setLastSelectedNetwork(mLastSelectedNetworkId, mLastSelectedNetworkTimestamp)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
RecommendationRequest parceled = passThroughParcel(request);
|
RecommendationRequest parceled = passThroughParcel(request);
|
||||||
@@ -60,6 +66,8 @@ public class RecommendationRequestTest extends AndroidTestCase {
|
|||||||
for (int i = 0; i < parceledConfigs.length; i++) {
|
for (int i = 0; i < parceledConfigs.length; i++) {
|
||||||
assertEquals(mConnectableConfigs[i].SSID, parceledConfigs[i].SSID);
|
assertEquals(mConnectableConfigs[i].SSID, parceledConfigs[i].SSID);
|
||||||
}
|
}
|
||||||
|
assertEquals(mLastSelectedNetworkId, parceled.getLastSelectedNetworkId());
|
||||||
|
assertEquals(mLastSelectedNetworkTimestamp, parceled.getLastSelectedNetworkTimestamp());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testParceling_nullScanResults() throws Exception {
|
public void testParceling_nullScanResults() throws Exception {
|
||||||
@@ -82,6 +90,16 @@ public class RecommendationRequestTest extends AndroidTestCase {
|
|||||||
assertNull(parceledConfigs);
|
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) {
|
private RecommendationRequest passThroughParcel(RecommendationRequest request) {
|
||||||
Parcel p = Parcel.obtain();
|
Parcel p = Parcel.obtain();
|
||||||
RecommendationRequest output = null;
|
RecommendationRequest output = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user