Loading core/jni/android_net_wifi_Wifi.cpp +34 −1 Original line number Diff line number Diff line Loading @@ -30,6 +30,8 @@ namespace android { static jboolean sScanModeActive = false; //TODO: check general errors in addition to overflow on snprintf /* * The following remembers the jfieldID's of the fields * of the DhcpInfo Java object, so that we don't have Loading Loading @@ -155,6 +157,36 @@ static jint android_net_wifi_addNetworkCommand(JNIEnv* env, jobject clazz) return doIntCommand("ADD_NETWORK"); } static jboolean android_net_wifi_wpsPbcCommand(JNIEnv* env, jobject clazz, jstring bssid) { char cmdstr[50]; jboolean isCopy; const char *bssidStr = env->GetStringUTFChars(bssid, &isCopy); int numWritten = snprintf(cmdstr, sizeof(cmdstr), "WPS_PBC %s", bssidStr); env->ReleaseStringUTFChars(bssid, bssidStr); if ((numWritten == -1) || (numWritten >= sizeof(cmdstr))) { return false; } return doBooleanCommand(cmdstr, "OK"); } static jboolean android_net_wifi_wpsPinCommand(JNIEnv* env, jobject clazz, jstring bssid, int apPin) { char cmdstr[50]; jboolean isCopy; const char *bssidStr = env->GetStringUTFChars(bssid, &isCopy); int numWritten = snprintf(cmdstr, sizeof(cmdstr), "WPS_REG %s %d", bssidStr, apPin); env->ReleaseStringUTFChars(bssid, bssidStr); if ((numWritten == -1) || (numWritten >= (int)sizeof(cmdstr))) { return false; } return doBooleanCommand(cmdstr, "OK"); } static jboolean android_net_wifi_setNetworkVariableCommand(JNIEnv* env, jobject clazz, jint netId, Loading Loading @@ -603,7 +635,8 @@ static JNINativeMethod gWifiMethods[] = { { "setScanResultHandlingCommand", "(I)Z", (void*) android_net_wifi_setScanResultHandlingCommand }, { "addToBlacklistCommand", "(Ljava/lang/String;)Z", (void*) android_net_wifi_addToBlacklistCommand }, { "clearBlacklistCommand", "()Z", (void*) android_net_wifi_clearBlacklistCommand }, { "startWpsPbcCommand", "(Ljava/lang/String;)Z", (void*) android_net_wifi_wpsPbcCommand }, { "startWpsPinCommand", "(Ljava/lang/String;I)Z", (void*) android_net_wifi_wpsPinCommand }, { "doDhcpRequest", "(Landroid/net/DhcpInfo;)Z", (void*) android_net_wifi_doDhcpRequest }, { "getDhcpError", "()Ljava/lang/String;", (void*) android_net_wifi_getDhcpError }, }; Loading services/java/com/android/server/WifiService.java +10 −0 Original line number Diff line number Diff line Loading @@ -804,6 +804,16 @@ public class WifiService extends IWifiManager.Stub { mWifiStateMachine.forgetNetwork(netId); } public void startWpsPbc(String bssid) { enforceChangePermission(); mWifiStateMachine.startWpsPbc(bssid); } public void startWpsPin(String bssid, int apPin) { enforceChangePermission(); mWifiStateMachine.startWpsPin(bssid, apPin); } private final BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Loading wifi/java/android/net/wifi/IWifiManager.aidl +4 −0 Original line number Diff line number Diff line Loading @@ -105,5 +105,9 @@ interface IWifiManager void saveNetwork(in WifiConfiguration wifiConfig); void forgetNetwork(int networkId); void startWpsPbc(String bssid); void startWpsPin(String bssid, int apPin); } wifi/java/android/net/wifi/WifiConfigStore.java +56 −19 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.net.DhcpInfo; import android.net.wifi.WifiConfiguration.IpAssignment; import android.net.wifi.WifiConfiguration.KeyMgmt; import android.net.wifi.WifiConfiguration.Status; import static android.net.wifi.WifiConfiguration.INVALID_NETWORK_ID; import android.os.Environment; import android.text.TextUtils; import android.util.Log; Loading Loading @@ -95,9 +96,9 @@ class WifiConfigStore { * and enable all stored networks in supplicant. */ static void initialize(Context context) { Log.d(TAG, "Updating config and enabling all networks"); Log.d(TAG, "Loading config and enabling all networks"); sContext = context; updateConfiguredNetworks(); loadConfiguredNetworks(); enableAllNetworks(); } Loading Loading @@ -150,7 +151,7 @@ class WifiConfigStore { static void selectNetwork(WifiConfiguration config) { if (config != null) { int netId = addOrUpdateNetworkNative(config); if (netId != -1) { if (netId != INVALID_NETWORK_ID) { selectNetwork(netId); } else { Log.e(TAG, "Failed to update network " + config); Loading @@ -174,7 +175,7 @@ class WifiConfigStore { if (sLastPriority == -1 || sLastPriority > 1000000) { synchronized (sConfiguredNetworks) { for(WifiConfiguration config : sConfiguredNetworks.values()) { if (config.networkId != -1) { if (config.networkId != INVALID_NETWORK_ID) { config.priority = 0; addOrUpdateNetworkNative(config); } Loading Loading @@ -204,10 +205,10 @@ class WifiConfigStore { * @param config WifiConfiguration to be saved */ static void saveNetwork(WifiConfiguration config) { boolean newNetwork = (config.networkId == -1); boolean newNetwork = (config.networkId == INVALID_NETWORK_ID); int netId = addOrUpdateNetworkNative(config); /* enable a new network */ if (newNetwork && netId >= 0) { if (newNetwork && netId != INVALID_NETWORK_ID) { WifiNative.enableNetworkCommand(netId, false); synchronized (sConfiguredNetworks) { sConfiguredNetworks.get(netId).status = Status.ENABLED; Loading Loading @@ -288,13 +289,7 @@ class WifiConfigStore { } if (disableOthers) { synchronized (sConfiguredNetworks) { for(WifiConfiguration config : sConfiguredNetworks.values()) { if(config != null && config.networkId != netId) { config.status = Status.DISABLED; } } } markAllNetworksDisabledExcept(netId); } return ret; } Loading @@ -320,6 +315,32 @@ class WifiConfigStore { return WifiNative.saveConfigCommand(); } /** * Start WPS pin method configuration */ static boolean startWpsPin(String bssid, int apPin) { if (WifiNative.startWpsPinCommand(bssid, apPin)) { /* WPS leaves all networks disabled */ markAllNetworksDisabled(); return true; } Log.e(TAG, "Failed to start WPS pin method configuration"); return false; } /** * Start WPS push button configuration */ static boolean startWpsPbc(String bssid) { if (WifiNative.startWpsPbcCommand(bssid)) { /* WPS leaves all networks disabled */ markAllNetworksDisabled(); return true; } Log.e(TAG, "Failed to start WPS push button configuration"); return false; } /** * Fetch the IP configuration for a given network id */ Loading Loading @@ -350,7 +371,7 @@ class WifiConfigStore { sContext.sendBroadcast(intent); } private static void updateConfiguredNetworks() { static void loadConfiguredNetworks() { String listStr = WifiNative.listNetworksCommand(); sLastPriority = 0; Loading Loading @@ -391,6 +412,22 @@ class WifiConfigStore { } } readIpConfigurations(); sendConfigChangeBroadcast(); } /* Mark all networks except specified netId as disabled */ private static void markAllNetworksDisabledExcept(int netId) { synchronized (sConfiguredNetworks) { for(WifiConfiguration config : sConfiguredNetworks.values()) { if(config != null && config.networkId != netId) { config.status = Status.DISABLED; } } } } private static void markAllNetworksDisabled() { markAllNetworksDisabledExcept(INVALID_NETWORK_ID); } private static void writeIpConfigurations() { Loading Loading @@ -513,20 +550,20 @@ class WifiConfigStore { private static int addOrUpdateNetworkNative(WifiConfiguration config) { /* * If the supplied networkId is -1, we create a new empty * If the supplied networkId is INVALID_NETWORK_ID, we create a new empty * network configuration. Otherwise, the networkId should * refer to an existing configuration. */ int netId = config.networkId; boolean updateFailed = true; boolean newNetwork = netId == -1; // networkId of -1 means we want to create a new network boolean newNetwork = (netId == INVALID_NETWORK_ID); // networkId of INVALID_NETWORK_ID means we want to create a new network if (newNetwork) { netId = WifiNative.addNetworkCommand(); if (netId < 0) { Log.e(TAG, "Failed to add a network!"); return -1; return INVALID_NETWORK_ID; } } Loading Loading @@ -700,7 +737,7 @@ class WifiConfigStore { "Failed to set a network variable, removed network: " + netId); } return -1; return INVALID_NETWORK_ID; } /* An update of the network variables requires reading them Loading wifi/java/android/net/wifi/WifiConfiguration.java +3 −1 Original line number Diff line number Diff line Loading @@ -43,6 +43,8 @@ public class WifiConfiguration implements Parcelable { public static final String priorityVarName = "priority"; /** {@hide} */ public static final String hiddenSSIDVarName = "scan_ssid"; /** {@hide} */ public static final int INVALID_NETWORK_ID = -1; /** {@hide} */ public class EnterpriseField { Loading Loading @@ -313,7 +315,7 @@ public class WifiConfiguration implements Parcelable { public DhcpInfo ipConfig; public WifiConfiguration() { networkId = -1; networkId = INVALID_NETWORK_ID; SSID = null; BSSID = null; priority = 0; Loading Loading
core/jni/android_net_wifi_Wifi.cpp +34 −1 Original line number Diff line number Diff line Loading @@ -30,6 +30,8 @@ namespace android { static jboolean sScanModeActive = false; //TODO: check general errors in addition to overflow on snprintf /* * The following remembers the jfieldID's of the fields * of the DhcpInfo Java object, so that we don't have Loading Loading @@ -155,6 +157,36 @@ static jint android_net_wifi_addNetworkCommand(JNIEnv* env, jobject clazz) return doIntCommand("ADD_NETWORK"); } static jboolean android_net_wifi_wpsPbcCommand(JNIEnv* env, jobject clazz, jstring bssid) { char cmdstr[50]; jboolean isCopy; const char *bssidStr = env->GetStringUTFChars(bssid, &isCopy); int numWritten = snprintf(cmdstr, sizeof(cmdstr), "WPS_PBC %s", bssidStr); env->ReleaseStringUTFChars(bssid, bssidStr); if ((numWritten == -1) || (numWritten >= sizeof(cmdstr))) { return false; } return doBooleanCommand(cmdstr, "OK"); } static jboolean android_net_wifi_wpsPinCommand(JNIEnv* env, jobject clazz, jstring bssid, int apPin) { char cmdstr[50]; jboolean isCopy; const char *bssidStr = env->GetStringUTFChars(bssid, &isCopy); int numWritten = snprintf(cmdstr, sizeof(cmdstr), "WPS_REG %s %d", bssidStr, apPin); env->ReleaseStringUTFChars(bssid, bssidStr); if ((numWritten == -1) || (numWritten >= (int)sizeof(cmdstr))) { return false; } return doBooleanCommand(cmdstr, "OK"); } static jboolean android_net_wifi_setNetworkVariableCommand(JNIEnv* env, jobject clazz, jint netId, Loading Loading @@ -603,7 +635,8 @@ static JNINativeMethod gWifiMethods[] = { { "setScanResultHandlingCommand", "(I)Z", (void*) android_net_wifi_setScanResultHandlingCommand }, { "addToBlacklistCommand", "(Ljava/lang/String;)Z", (void*) android_net_wifi_addToBlacklistCommand }, { "clearBlacklistCommand", "()Z", (void*) android_net_wifi_clearBlacklistCommand }, { "startWpsPbcCommand", "(Ljava/lang/String;)Z", (void*) android_net_wifi_wpsPbcCommand }, { "startWpsPinCommand", "(Ljava/lang/String;I)Z", (void*) android_net_wifi_wpsPinCommand }, { "doDhcpRequest", "(Landroid/net/DhcpInfo;)Z", (void*) android_net_wifi_doDhcpRequest }, { "getDhcpError", "()Ljava/lang/String;", (void*) android_net_wifi_getDhcpError }, }; Loading
services/java/com/android/server/WifiService.java +10 −0 Original line number Diff line number Diff line Loading @@ -804,6 +804,16 @@ public class WifiService extends IWifiManager.Stub { mWifiStateMachine.forgetNetwork(netId); } public void startWpsPbc(String bssid) { enforceChangePermission(); mWifiStateMachine.startWpsPbc(bssid); } public void startWpsPin(String bssid, int apPin) { enforceChangePermission(); mWifiStateMachine.startWpsPin(bssid, apPin); } private final BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Loading
wifi/java/android/net/wifi/IWifiManager.aidl +4 −0 Original line number Diff line number Diff line Loading @@ -105,5 +105,9 @@ interface IWifiManager void saveNetwork(in WifiConfiguration wifiConfig); void forgetNetwork(int networkId); void startWpsPbc(String bssid); void startWpsPin(String bssid, int apPin); }
wifi/java/android/net/wifi/WifiConfigStore.java +56 −19 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.net.DhcpInfo; import android.net.wifi.WifiConfiguration.IpAssignment; import android.net.wifi.WifiConfiguration.KeyMgmt; import android.net.wifi.WifiConfiguration.Status; import static android.net.wifi.WifiConfiguration.INVALID_NETWORK_ID; import android.os.Environment; import android.text.TextUtils; import android.util.Log; Loading Loading @@ -95,9 +96,9 @@ class WifiConfigStore { * and enable all stored networks in supplicant. */ static void initialize(Context context) { Log.d(TAG, "Updating config and enabling all networks"); Log.d(TAG, "Loading config and enabling all networks"); sContext = context; updateConfiguredNetworks(); loadConfiguredNetworks(); enableAllNetworks(); } Loading Loading @@ -150,7 +151,7 @@ class WifiConfigStore { static void selectNetwork(WifiConfiguration config) { if (config != null) { int netId = addOrUpdateNetworkNative(config); if (netId != -1) { if (netId != INVALID_NETWORK_ID) { selectNetwork(netId); } else { Log.e(TAG, "Failed to update network " + config); Loading @@ -174,7 +175,7 @@ class WifiConfigStore { if (sLastPriority == -1 || sLastPriority > 1000000) { synchronized (sConfiguredNetworks) { for(WifiConfiguration config : sConfiguredNetworks.values()) { if (config.networkId != -1) { if (config.networkId != INVALID_NETWORK_ID) { config.priority = 0; addOrUpdateNetworkNative(config); } Loading Loading @@ -204,10 +205,10 @@ class WifiConfigStore { * @param config WifiConfiguration to be saved */ static void saveNetwork(WifiConfiguration config) { boolean newNetwork = (config.networkId == -1); boolean newNetwork = (config.networkId == INVALID_NETWORK_ID); int netId = addOrUpdateNetworkNative(config); /* enable a new network */ if (newNetwork && netId >= 0) { if (newNetwork && netId != INVALID_NETWORK_ID) { WifiNative.enableNetworkCommand(netId, false); synchronized (sConfiguredNetworks) { sConfiguredNetworks.get(netId).status = Status.ENABLED; Loading Loading @@ -288,13 +289,7 @@ class WifiConfigStore { } if (disableOthers) { synchronized (sConfiguredNetworks) { for(WifiConfiguration config : sConfiguredNetworks.values()) { if(config != null && config.networkId != netId) { config.status = Status.DISABLED; } } } markAllNetworksDisabledExcept(netId); } return ret; } Loading @@ -320,6 +315,32 @@ class WifiConfigStore { return WifiNative.saveConfigCommand(); } /** * Start WPS pin method configuration */ static boolean startWpsPin(String bssid, int apPin) { if (WifiNative.startWpsPinCommand(bssid, apPin)) { /* WPS leaves all networks disabled */ markAllNetworksDisabled(); return true; } Log.e(TAG, "Failed to start WPS pin method configuration"); return false; } /** * Start WPS push button configuration */ static boolean startWpsPbc(String bssid) { if (WifiNative.startWpsPbcCommand(bssid)) { /* WPS leaves all networks disabled */ markAllNetworksDisabled(); return true; } Log.e(TAG, "Failed to start WPS push button configuration"); return false; } /** * Fetch the IP configuration for a given network id */ Loading Loading @@ -350,7 +371,7 @@ class WifiConfigStore { sContext.sendBroadcast(intent); } private static void updateConfiguredNetworks() { static void loadConfiguredNetworks() { String listStr = WifiNative.listNetworksCommand(); sLastPriority = 0; Loading Loading @@ -391,6 +412,22 @@ class WifiConfigStore { } } readIpConfigurations(); sendConfigChangeBroadcast(); } /* Mark all networks except specified netId as disabled */ private static void markAllNetworksDisabledExcept(int netId) { synchronized (sConfiguredNetworks) { for(WifiConfiguration config : sConfiguredNetworks.values()) { if(config != null && config.networkId != netId) { config.status = Status.DISABLED; } } } } private static void markAllNetworksDisabled() { markAllNetworksDisabledExcept(INVALID_NETWORK_ID); } private static void writeIpConfigurations() { Loading Loading @@ -513,20 +550,20 @@ class WifiConfigStore { private static int addOrUpdateNetworkNative(WifiConfiguration config) { /* * If the supplied networkId is -1, we create a new empty * If the supplied networkId is INVALID_NETWORK_ID, we create a new empty * network configuration. Otherwise, the networkId should * refer to an existing configuration. */ int netId = config.networkId; boolean updateFailed = true; boolean newNetwork = netId == -1; // networkId of -1 means we want to create a new network boolean newNetwork = (netId == INVALID_NETWORK_ID); // networkId of INVALID_NETWORK_ID means we want to create a new network if (newNetwork) { netId = WifiNative.addNetworkCommand(); if (netId < 0) { Log.e(TAG, "Failed to add a network!"); return -1; return INVALID_NETWORK_ID; } } Loading Loading @@ -700,7 +737,7 @@ class WifiConfigStore { "Failed to set a network variable, removed network: " + netId); } return -1; return INVALID_NETWORK_ID; } /* An update of the network variables requires reading them Loading
wifi/java/android/net/wifi/WifiConfiguration.java +3 −1 Original line number Diff line number Diff line Loading @@ -43,6 +43,8 @@ public class WifiConfiguration implements Parcelable { public static final String priorityVarName = "priority"; /** {@hide} */ public static final String hiddenSSIDVarName = "scan_ssid"; /** {@hide} */ public static final int INVALID_NETWORK_ID = -1; /** {@hide} */ public class EnterpriseField { Loading Loading @@ -313,7 +315,7 @@ public class WifiConfiguration implements Parcelable { public DhcpInfo ipConfig; public WifiConfiguration() { networkId = -1; networkId = INVALID_NETWORK_ID; SSID = null; BSSID = null; priority = 0; Loading