Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d3975a91 authored by Irfan Sheriff's avatar Irfan Sheriff
Browse files

Fix WifiManager async API

Fix the current asynchronous API to use callback like the way
was done with p2p API.

In the process, fix the use of WPS

Change-Id: Ib6f8714cf51b3525b655948268804e7eaaf17587
parent 5bb59daf
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ public class Protocol {
    public static final int BASE_WIFI_P2P_MANAGER                                   = 0x00022000;
    public static final int BASE_WIFI_P2P_SERVICE                                   = 0x00023000;
    public static final int BASE_WIFI_MONITOR                                       = 0x00024000;
    public static final int BASE_WIFI_MANAGER                                       = 0x00025000;
    public static final int BASE_DHCP                                               = 0x00030000;
    public static final int BASE_DATA_CONNECTION                                    = 0x00040000;
    public static final int BASE_DATA_CONNECTION_AC                                 = 0x00041000;
+17 −3
Original line number Diff line number Diff line
@@ -94,6 +94,7 @@ public class ConnectivityManagerTestActivity extends Activity {
     * Control Wifi States
     */
    public WifiManager mWifiManager;
    public WifiManager.Channel mChannel;

    /*
     * Verify connectivity state
@@ -240,7 +241,7 @@ public class ConnectivityManagerTestActivity extends Activity {
        mCM = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
        // Get an instance of WifiManager
        mWifiManager =(WifiManager)getSystemService(Context.WIFI_SERVICE);
        mWifiManager.asyncConnect(this, new WifiServiceHandler());
        mChannel = mWifiManager.initialize(mContext, mContext.getMainLooper(), null);

        initializeNetworkStates();

@@ -594,7 +595,14 @@ public class ConnectivityManagerTestActivity extends Activity {
                        log("found " + ssid + " in the scan result list");
                        log("retry: " + retry);
                        foundApInScanResults = true;
                        mWifiManager.connectNetwork(config);
                        mWifiManager.connect(mChannel, config,
                                new WifiManager.ActionListener() {
                                    public void onSuccess() {
                                    }
                                    public void onFailure(int reason) {
                                        log("connect failure " + reason);
                                    }
                                });
                        break;
                   }
                }
@@ -641,7 +649,13 @@ public class ConnectivityManagerTestActivity extends Activity {
        for (WifiConfiguration wifiConfig: wifiConfigList) {
            log("remove wifi configuration: " + wifiConfig.networkId);
            int netId = wifiConfig.networkId;
            mWifiManager.forgetNetwork(netId);
            mWifiManager.forget(mChannel, netId, new WifiManager.ActionListener() {
                    public void onSuccess() {
                    }
                    public void onFailure(int reason) {
                        log("Failed to forget " + reason);
                    }
                });
        }
        return true;
    }
+3 −1
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@ public class WifiConnectionTest
    private ConnectivityManagerTestActivity mAct;
    private ConnectivityManagerTestRunner mRunner;
    private WifiManager mWifiManager = null;
    private WifiManager.Channel mChannel;
    private Set<WifiConfiguration> enabledNetworks = null;

    public WifiConnectionTest() {
@@ -76,7 +77,8 @@ public class WifiConnectionTest
        mWifiManager = (WifiManager) mRunner.getContext().getSystemService(Context.WIFI_SERVICE);

        mAct = getActivity();
        mWifiManager.asyncConnect(mAct, new WifiServiceHandler());
        mChannel = mWifiManager.initialize(mAct, mAct.getMainLooper(), null);

        networks = mAct.loadNetworkConfigurations();
        if (DEBUG) {
            printNetworkConfigurations();
+18 −4
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ public class ConnectionUtil {
    private int mWifiState;
    private NetworkInfo mWifiNetworkInfo;
    private WifiManager mWifiManager;
    private WifiManager.Channel mChannel;
    private Context mContext;
    // Verify connectivity state
    private static final int NUM_NETWORK_TYPES = ConnectivityManager.MAX_NETWORK_TYPE + 1;
@@ -114,7 +115,7 @@ public class ConnectionUtil {

        // Get an instance of WifiManager
        mWifiManager =(WifiManager)mContext.getSystemService(Context.WIFI_SERVICE);
        mWifiManager.asyncConnect(mContext, new WifiServiceHandler());
        mChannel = mWifiManager.initialize(mContext, mContext.getMainLooper(), null);

        mDownloadManager = (DownloadManager)mContext.getSystemService(Context.DOWNLOAD_SERVICE);

@@ -567,7 +568,14 @@ public class ConnectionUtil {
                        Log.v(LOG_TAG, "Found " + ssid + " in the scan result list.");
                        Log.v(LOG_TAG, "Retry: " + retry);
                        foundApInScanResults = true;
                        mWifiManager.connectNetwork(config);
                        mWifiManager.connect(mChannel, config, new WifiManager.ActionListener() {
                                public void onSuccess() {
                                }
                                public void onFailure(int reason) {
                                    Log.e(LOG_TAG, "connect failed " + reason);
                                }
                            });

                        break;
                    }
                }
@@ -614,7 +622,13 @@ public class ConnectionUtil {
        for (WifiConfiguration wifiConfig: wifiConfigList) {
            Log.v(LOG_TAG, "Remove wifi configuration: " + wifiConfig.networkId);
            int netId = wifiConfig.networkId;
            mWifiManager.forgetNetwork(netId);
            mWifiManager.forget(mChannel, netId, new WifiManager.ActionListener() {
                    public void onSuccess() {
                    }
                    public void onFailure(int reason) {
                        Log.e(LOG_TAG, "forget failed " + reason);
                    }
                });
        }
        return true;
    }
+16 −21
Original line number Diff line number Diff line
@@ -263,47 +263,42 @@ public class WifiService extends IWifiManager.Stub {
                    ac.connect(mContext, this, msg.replyTo);
                    break;
                }
                case WifiManager.CMD_ENABLE_TRAFFIC_STATS_POLL: {
                case WifiManager.ENABLE_TRAFFIC_STATS_POLL: {
                    mEnableTrafficStatsPoll = (msg.arg1 == 1);
                    mTrafficStatsPollToken++;
                    if (mEnableTrafficStatsPoll) {
                        notifyOnDataActivity();
                        sendMessageDelayed(Message.obtain(this, WifiManager.CMD_TRAFFIC_STATS_POLL,
                        sendMessageDelayed(Message.obtain(this, WifiManager.TRAFFIC_STATS_POLL,
                                mTrafficStatsPollToken, 0), POLL_TRAFFIC_STATS_INTERVAL_MSECS);
                    }
                    break;
                }
                case WifiManager.CMD_TRAFFIC_STATS_POLL: {
                case WifiManager.TRAFFIC_STATS_POLL: {
                    if (msg.arg1 == mTrafficStatsPollToken) {
                        notifyOnDataActivity();
                        sendMessageDelayed(Message.obtain(this, WifiManager.CMD_TRAFFIC_STATS_POLL,
                        sendMessageDelayed(Message.obtain(this, WifiManager.TRAFFIC_STATS_POLL,
                                mTrafficStatsPollToken, 0), POLL_TRAFFIC_STATS_INTERVAL_MSECS);
                    }
                    break;
                }
                case WifiManager.CMD_CONNECT_NETWORK: {
                    if (msg.obj != null) {
                        mWifiStateMachine.connectNetwork((WifiConfiguration)msg.obj);
                    } else {
                        mWifiStateMachine.connectNetwork(msg.arg1);
                    }
                case WifiManager.CONNECT_NETWORK: {
                    mWifiStateMachine.sendMessage(Message.obtain(msg));
                    break;
                }
                case WifiManager.CMD_SAVE_NETWORK: {
                    mWifiStateMachine.saveNetwork((WifiConfiguration)msg.obj);
                case WifiManager.SAVE_NETWORK: {
                    mWifiStateMachine.sendMessage(Message.obtain(msg));
                    break;
                }
                case WifiManager.CMD_FORGET_NETWORK: {
                    mWifiStateMachine.forgetNetwork(msg.arg1);
                case WifiManager.FORGET_NETWORK: {
                    mWifiStateMachine.sendMessage(Message.obtain(msg));
                    break;
                }
                case WifiManager.CMD_START_WPS: {
                    //replyTo has the original source
                    mWifiStateMachine.startWps(msg.replyTo, (WpsInfo)msg.obj);
                case WifiManager.START_WPS: {
                    mWifiStateMachine.sendMessage(Message.obtain(msg));
                    break;
                }
                case WifiManager.CMD_DISABLE_NETWORK: {
                    mWifiStateMachine.disableNetwork(msg.replyTo, msg.arg1, msg.arg2);
                case WifiManager.DISABLE_NETWORK: {
                    mWifiStateMachine.sendMessage(Message.obtain(msg));
                    break;
                }
                default: {
@@ -1594,10 +1589,10 @@ public class WifiService extends IWifiManager.Stub {
        Message msg;
        if (mNetworkInfo.getDetailedState() == DetailedState.CONNECTED && !mScreenOff) {
            msg = Message.obtain(mAsyncServiceHandler,
                    WifiManager.CMD_ENABLE_TRAFFIC_STATS_POLL, 1, 0);
                    WifiManager.ENABLE_TRAFFIC_STATS_POLL, 1, 0);
        } else {
            msg = Message.obtain(mAsyncServiceHandler,
                    WifiManager.CMD_ENABLE_TRAFFIC_STATS_POLL, 0, 0);
                    WifiManager.ENABLE_TRAFFIC_STATS_POLL, 0, 0);
        }
        msg.sendToTarget();
    }
Loading