Handle hiddenSSID as one of soft ap config for backup & restore
In addition to the change to persist hiddenSSID, this CL takes care of backup and restore use case for hiddenSSID as one of soft ap config. cherry-picked from aog/773385 Bug: 117052143 Test: Unit tests Change-Id: I4af897f466c5d8fea66aec93e39faf3f13bd23fb
This commit is contained in:
@@ -57,7 +57,7 @@ public class WifiConfiguration implements Parcelable {
|
||||
/**
|
||||
* Current Version of the Backup Serializer.
|
||||
*/
|
||||
private static final int BACKUP_VERSION = 2;
|
||||
private static final int BACKUP_VERSION = 3;
|
||||
/** {@hide} */
|
||||
public static final String ssidVarName = "ssid";
|
||||
/** {@hide} */
|
||||
@@ -2286,6 +2286,7 @@ public class WifiConfiguration implements Parcelable {
|
||||
out.writeInt(apChannel);
|
||||
BackupUtils.writeString(out, preSharedKey);
|
||||
out.writeInt(getAuthType());
|
||||
out.writeBoolean(hiddenSSID);
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
@@ -2308,6 +2309,9 @@ public class WifiConfiguration implements Parcelable {
|
||||
config.apChannel = in.readInt();
|
||||
config.preSharedKey = BackupUtils.readString(in);
|
||||
config.allowedKeyManagement.set(in.readInt());
|
||||
if (version >= 3) {
|
||||
config.hiddenSSID = in.readBoolean();
|
||||
}
|
||||
return config;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import android.net.MacAddress;
|
||||
import android.net.wifi.WifiConfiguration.KeyMgmt;
|
||||
import android.net.wifi.WifiConfiguration.NetworkSelectionStatus;
|
||||
import android.os.Parcel;
|
||||
import android.support.test.filters.SmallTest;
|
||||
@@ -30,6 +31,9 @@ import android.support.test.filters.SmallTest;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link android.net.wifi.WifiConfiguration}.
|
||||
*/
|
||||
@@ -239,4 +243,30 @@ public class WifiConfigurationTest {
|
||||
config.setRandomizedMacAddress(null);
|
||||
assertEquals(defaultMac, config.getRandomizedMacAddress());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that the serialization/de-serialization for softap config works.
|
||||
*/
|
||||
@Test
|
||||
public void testSoftApConfigBackupAndRestore() throws Exception {
|
||||
WifiConfiguration config = new WifiConfiguration();
|
||||
config.SSID = "TestAP";
|
||||
config.apBand = WifiConfiguration.AP_BAND_5GHZ;
|
||||
config.apChannel = 40;
|
||||
config.allowedKeyManagement.set(KeyMgmt.WPA2_PSK);
|
||||
config.preSharedKey = "TestPsk";
|
||||
config.hiddenSSID = true;
|
||||
|
||||
byte[] data = config.getBytesForBackup();
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(data);
|
||||
DataInputStream in = new DataInputStream(bais);
|
||||
WifiConfiguration restoredConfig = WifiConfiguration.getWifiConfigFromBackup(in);
|
||||
|
||||
assertEquals(config.SSID, restoredConfig.SSID);
|
||||
assertEquals(config.preSharedKey, restoredConfig.preSharedKey);
|
||||
assertEquals(config.getAuthType(), restoredConfig.getAuthType());
|
||||
assertEquals(config.apBand, restoredConfig.apBand);
|
||||
assertEquals(config.apChannel, restoredConfig.apChannel);
|
||||
assertEquals(config.hiddenSSID, restoredConfig.hiddenSSID);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user