WifiApConfigStorepublic class WifiApConfigStore extends com.android.internal.util.StateMachine Provides API to the WifiStateMachine for doing read/write access
to soft access point configuration |
Fields Summary |
---|
private android.content.Context | mContext | private static final String | TAG | private static final String | AP_CONFIG_FILE | private static final int | AP_CONFIG_FILE_VERSION | private com.android.internal.util.State | mDefaultState | private com.android.internal.util.State | mInactiveState | private com.android.internal.util.State | mActiveState | private android.net.wifi.WifiConfiguration | mWifiApConfig | private com.android.internal.util.AsyncChannel | mReplyChannel |
Constructors Summary |
---|
WifiApConfigStore(android.content.Context context, android.os.Handler target)
super(TAG, target.getLooper());
mContext = context;
addState(mDefaultState);
addState(mInactiveState, mDefaultState);
addState(mActiveState, mDefaultState);
setInitialState(mInactiveState);
|
Methods Summary |
---|
android.os.Messenger | getMessenger()
return new Messenger(getHandler());
| void | loadApConfiguration()
DataInputStream in = null;
try {
WifiConfiguration config = new WifiConfiguration();
in = new DataInputStream(new BufferedInputStream(new FileInputStream(
AP_CONFIG_FILE)));
int version = in.readInt();
if (version != 1) {
Log.e(TAG, "Bad version on hotspot configuration file, set defaults");
setDefaultApConfiguration();
return;
}
config.SSID = in.readUTF();
int authType = in.readInt();
config.allowedKeyManagement.set(authType);
if (authType != KeyMgmt.NONE) {
config.preSharedKey = in.readUTF();
}
mWifiApConfig = config;
} catch (IOException ignore) {
setDefaultApConfiguration();
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {}
}
}
| public static com.android.server.wifi.WifiApConfigStore | makeWifiApConfigStore(android.content.Context context, android.os.Handler target)
WifiApConfigStore s = new WifiApConfigStore(context, target);
s.start();
return s;
| private void | setDefaultApConfiguration()
WifiConfiguration config = new WifiConfiguration();
config.SSID = mContext.getString(R.string.wifi_tether_configure_ssid_default);
config.allowedKeyManagement.set(KeyMgmt.WPA2_PSK);
String randomUUID = UUID.randomUUID().toString();
//first 12 chars from xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
config.preSharedKey = randomUUID.substring(0, 8) + randomUUID.substring(9,13);
sendMessage(WifiStateMachine.CMD_SET_AP_CONFIG, config);
| private void | writeApConfiguration(android.net.wifi.WifiConfiguration config)
DataOutputStream out = null;
try {
out = new DataOutputStream(new BufferedOutputStream(
new FileOutputStream(AP_CONFIG_FILE)));
out.writeInt(AP_CONFIG_FILE_VERSION);
out.writeUTF(config.SSID);
int authType = config.getAuthType();
out.writeInt(authType);
if(authType != KeyMgmt.NONE) {
out.writeUTF(config.preSharedKey);
}
} catch (IOException e) {
Log.e(TAG, "Error writing hotspot configuration" + e);
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e) {}
}
}
|
|