Merge change 2506 into donut

* changes:
  Integrate unsubmitted cupcake change 131139: 	CTS: add test cases for net.wifi.ScanResult, SupplicantState, WifiConfiguration, WifiInfo and WifiManager.     Added new tests as per mondrian comments. Cleaned code to get rid of eclipse warnings.
diff --git a/tests/tests/net/src/android/net/wifi/cts/ScanResultTest.java b/tests/tests/net/src/android/net/wifi/cts/ScanResultTest.java
new file mode 100644
index 0000000..0ab71c7
--- /dev/null
+++ b/tests/tests/net/src/android/net/wifi/cts/ScanResultTest.java
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net.wifi.cts;
+
+import java.util.List;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.net.wifi.ScanResult;
+import android.net.wifi.WifiManager;
+import android.net.wifi.WifiManager.WifiLock;
+import android.test.AndroidTestCase;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+
+@TestTargetClass(ScanResult.class)
+public class ScanResultTest extends AndroidTestCase {
+    private static class MySync {
+        int expectedState = STATE_NULL;
+    }
+
+    private WifiManager mWifiManager;
+    private WifiLock mWifiLock;
+    private static MySync mMySync;
+
+    private static final int STATE_NULL = 0;
+    private static final int STATE_WIFI_CHANGING = 1;
+    private static final int STATE_WIFI_CHANGED = 2;
+
+    private static final String TAG = "WifiInfoTest";
+    private static final int TIMEOUT_MSEC = 6000;
+    private static final int WAIT_MSEC = 60;
+    private static final int DURATION = 10000;
+    private IntentFilter mIntentFilter;
+    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            final String action = intent.getAction();
+            if (action.equals(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION)) {
+                synchronized (mMySync) {
+                    mMySync.expectedState = STATE_WIFI_CHANGED;
+                    mMySync.notify();
+                }
+            }
+        }
+    };
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mMySync = new MySync();
+        mIntentFilter = new IntentFilter();
+        mIntentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
+        mIntentFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
+        mIntentFilter.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION);
+        mIntentFilter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION);
+        mIntentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
+        mIntentFilter.addAction(WifiManager.RSSI_CHANGED_ACTION);
+        mIntentFilter.addAction(WifiManager.NETWORK_IDS_CHANGED_ACTION);
+        mIntentFilter.addAction(WifiManager.ACTION_PICK_WIFI_NETWORK);
+
+        mContext.registerReceiver(mReceiver, mIntentFilter);
+        mWifiManager = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE);
+        assertNotNull(mWifiManager);
+        mWifiLock = mWifiManager.createWifiLock(TAG);
+        mWifiLock.acquire();
+        if (!mWifiManager.isWifiEnabled())
+            setWifiEnabled(true);
+        Thread.sleep(DURATION);
+        assertTrue(mWifiManager.isWifiEnabled());
+        mMySync.expectedState = STATE_NULL;
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        mWifiLock.release();
+        mContext.unregisterReceiver(mReceiver);
+        if (!mWifiManager.isWifiEnabled())
+            setWifiEnabled(true);
+        Thread.sleep(DURATION);
+        super.tearDown();
+    }
+
+    private void setWifiEnabled(boolean enable) throws Exception {
+        synchronized (mMySync) {
+            mMySync.expectedState = STATE_WIFI_CHANGING;
+            assertTrue(mWifiManager.setWifiEnabled(enable));
+            long timeout = System.currentTimeMillis() + TIMEOUT_MSEC;
+            while (System.currentTimeMillis() < timeout
+                    && mMySync.expectedState == STATE_WIFI_CHANGING)
+                mMySync.wait(WAIT_MSEC);
+        }
+    }
+
+    @TestTargetNew(
+        level = TestLevel.COMPLETE,
+        method = "toString",
+        args = {}
+    )
+    public void testScanResultProperties() {
+        List<ScanResult> scanResults = mWifiManager.getScanResults();
+        // this test case should in Wifi environment
+        for (int i = 0; i < scanResults.size(); i++) {
+            ScanResult mScanResult = scanResults.get(i);
+            assertNotNull(mScanResult.toString());
+        }
+    }
+
+}
diff --git a/tests/tests/net/src/android/net/wifi/cts/SupplicantStateTest.java b/tests/tests/net/src/android/net/wifi/cts/SupplicantStateTest.java
new file mode 100644
index 0000000..4e03f5e
--- /dev/null
+++ b/tests/tests/net/src/android/net/wifi/cts/SupplicantStateTest.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net.wifi.cts;
+
+import android.net.wifi.SupplicantState;
+import android.test.AndroidTestCase;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
+
+@TestTargetClass(SupplicantState.class)
+public class SupplicantStateTest extends AndroidTestCase {
+
+    @TestTargets({
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "isValidState",
+            args = {android.net.wifi.SupplicantState.class}
+        )
+    })
+    public void testIsValidState() {
+        assertTrue(SupplicantState.isValidState(SupplicantState.DISCONNECTED));
+        assertTrue(SupplicantState.isValidState(SupplicantState.INACTIVE));
+        assertTrue(SupplicantState.isValidState(SupplicantState.SCANNING));
+        assertTrue(SupplicantState.isValidState(SupplicantState.ASSOCIATING));
+        assertTrue(SupplicantState.isValidState(SupplicantState.ASSOCIATED));
+        assertTrue(SupplicantState.isValidState(SupplicantState.FOUR_WAY_HANDSHAKE));
+        assertTrue(SupplicantState.isValidState(SupplicantState.GROUP_HANDSHAKE));
+        assertTrue(SupplicantState.isValidState(SupplicantState.COMPLETED));
+        assertTrue(SupplicantState.isValidState(SupplicantState.DORMANT));
+        assertFalse(SupplicantState.isValidState(SupplicantState.UNINITIALIZED));
+        assertFalse(SupplicantState.isValidState(SupplicantState.INVALID));
+    }
+
+}
diff --git a/tests/tests/net/src/android/net/wifi/cts/WifiConfigurationTest.java b/tests/tests/net/src/android/net/wifi/cts/WifiConfigurationTest.java
new file mode 100644
index 0000000..3018907
--- /dev/null
+++ b/tests/tests/net/src/android/net/wifi/cts/WifiConfigurationTest.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net.wifi.cts;
+
+import java.util.List;
+
+import android.content.Context;
+import android.net.wifi.WifiConfiguration;
+import android.net.wifi.WifiManager;
+import android.test.AndroidTestCase;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
+
+@TestTargetClass(WifiConfiguration.class)
+public class WifiConfigurationTest extends AndroidTestCase {
+    private  WifiManager mWifiManager;
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mWifiManager = (WifiManager) mContext
+                .getSystemService(Context.WIFI_SERVICE);
+    }
+
+    @TestTargets({
+        @TestTargetNew(
+            level = TestLevel.PARTIAL,
+            method = "WifiConfiguration",
+            args = {}
+        ),
+        @TestTargetNew(
+            level = TestLevel.PARTIAL,
+            method = "toString",
+            args = {}
+        )
+    })
+    public void testWifiConfiguration() {
+        List<WifiConfiguration> wifiConfigurations = mWifiManager.getConfiguredNetworks();
+        for (int i = 0; i < wifiConfigurations.size(); i++) {
+            WifiConfiguration wifiConfiguration = wifiConfigurations.get(i);
+            assertNotNull(wifiConfiguration);
+            assertNotNull(wifiConfiguration.toString());
+        }
+    }
+}
diff --git a/tests/tests/net/src/android/net/wifi/cts/WifiInfoTest.java b/tests/tests/net/src/android/net/wifi/cts/WifiInfoTest.java
new file mode 100644
index 0000000..42243c8
--- /dev/null
+++ b/tests/tests/net/src/android/net/wifi/cts/WifiInfoTest.java
@@ -0,0 +1,194 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net.wifi.cts;
+
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
+import dalvik.annotation.ToBeFixed;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.net.wifi.SupplicantState;
+import android.net.wifi.WifiInfo;
+import android.net.wifi.WifiManager;
+import android.net.wifi.WifiManager.WifiLock;
+import android.test.AndroidTestCase;
+
+@TestTargetClass(WifiInfo.class)
+public class WifiInfoTest extends AndroidTestCase {
+    private static class MySync {
+        int expectedState = STATE_NULL;
+    }
+
+    private WifiManager mWifiManager;
+    private WifiLock mWifiLock;
+    private static MySync mMySync;
+
+    private static final int STATE_NULL = 0;
+    private static final int STATE_WIFI_CHANGING = 1;
+    private static final int STATE_WIFI_CHANGED = 2;
+
+    private static final String TAG = "WifiInfoTest";
+    private static final int TIMEOUT_MSEC = 6000;
+    private static final int WAIT_MSEC = 60;
+    private static final int DURATION = 10000;
+    private IntentFilter mIntentFilter;
+    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            final String action = intent.getAction();
+            if (action.equals(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION)) {
+                synchronized (mMySync) {
+                    mMySync.expectedState = STATE_WIFI_CHANGED;
+                    mMySync.notify();
+                }
+            }
+        }
+    };
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mMySync = new MySync();
+        mIntentFilter = new IntentFilter();
+        mIntentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
+        mIntentFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
+        mIntentFilter.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION);
+        mIntentFilter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION);
+        mIntentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
+        mIntentFilter.addAction(WifiManager.RSSI_CHANGED_ACTION);
+        mIntentFilter.addAction(WifiManager.NETWORK_IDS_CHANGED_ACTION);
+        mIntentFilter.addAction(WifiManager.ACTION_PICK_WIFI_NETWORK);
+
+        mContext.registerReceiver(mReceiver, mIntentFilter);
+        mWifiManager = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE);
+        assertNotNull(mWifiManager);
+        mWifiLock = mWifiManager.createWifiLock(TAG);
+        mWifiLock.acquire();
+        if (!mWifiManager.isWifiEnabled())
+            setWifiEnabled(true);
+        Thread.sleep(DURATION);
+        assertTrue(mWifiManager.isWifiEnabled());
+        mMySync.expectedState = STATE_NULL;
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        mWifiLock.release();
+        mContext.unregisterReceiver(mReceiver);
+        if (!mWifiManager.isWifiEnabled())
+            setWifiEnabled(true);
+        Thread.sleep(DURATION);
+        super.tearDown();
+    }
+
+    private void setWifiEnabled(boolean enable) throws Exception {
+        synchronized (mMySync) {
+            mMySync.expectedState = STATE_WIFI_CHANGING;
+            assertTrue(mWifiManager.setWifiEnabled(enable));
+            long timeout = System.currentTimeMillis() + TIMEOUT_MSEC;
+            while (System.currentTimeMillis() < timeout
+                    && mMySync.expectedState == STATE_WIFI_CHANGING)
+                mMySync.wait(WAIT_MSEC);
+        }
+    }
+
+    @TestTargets({
+        @TestTargetNew(
+            level = TestLevel.PARTIAL,
+            method = "getMacAddress",
+            args = {}
+        ),
+        @TestTargetNew(
+            level = TestLevel.PARTIAL,
+            method = "getIpAddress",
+            args = {}
+        ),
+        @TestTargetNew(
+            level = TestLevel.PARTIAL,
+            method = "getDetailedStateOf",
+            args = {android.net.wifi.SupplicantState.class}
+        ),
+        @TestTargetNew(
+            level = TestLevel.PARTIAL,
+            method = "getNetworkId",
+            args = {}
+        ),
+        @TestTargetNew(
+            level = TestLevel.PARTIAL,
+            method = "getSSID",
+            args = {}
+        ),
+        @TestTargetNew(
+            level = TestLevel.PARTIAL,
+            method = "getBSSID",
+            args = {}
+        ),
+        @TestTargetNew(
+            level = TestLevel.PARTIAL,
+            method = "getSupplicantState",
+            args = {}
+        ),
+        @TestTargetNew(
+            level = TestLevel.PARTIAL,
+            method = "getLinkSpeed",
+            args = {}
+        ),
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "toString",
+            args = {}
+        ),
+        @TestTargetNew(
+            level = TestLevel.PARTIAL,
+            method = "getRssi",
+            args = {}
+        ),
+        @TestTargetNew(
+            level = TestLevel.PARTIAL,
+            method = "getHiddenSSID",
+            args = {}
+        )
+    })
+    @ToBeFixed(bug="1871573", explanation="android.net.wifi.WifiInfo#getNetworkId() return -1 when"
+        + " there is wifi connection")
+    public void testWifiInfoProperties() throws Exception {
+        // this test case should in Wifi environment
+        WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
+
+        assertNotNull(wifiInfo);
+        assertNotNull(wifiInfo.toString());
+        SupplicantState.isValidState(wifiInfo.getSupplicantState());
+        WifiInfo.getDetailedStateOf(SupplicantState.DISCONNECTED);
+        wifiInfo.getSSID();
+        wifiInfo.getBSSID();
+        wifiInfo.getIpAddress();
+        wifiInfo.getLinkSpeed();
+        wifiInfo.getRssi();
+        wifiInfo.getHiddenSSID();
+        wifiInfo.getMacAddress();
+        setWifiEnabled(false);
+        Thread.sleep(DURATION);
+        wifiInfo = mWifiManager.getConnectionInfo();
+        assertEquals(-1, wifiInfo.getNetworkId());
+    }
+
+}
diff --git a/tests/tests/net/src/android/net/wifi/cts/WifiManagerTest.java b/tests/tests/net/src/android/net/wifi/cts/WifiManagerTest.java
new file mode 100644
index 0000000..132ca92
--- /dev/null
+++ b/tests/tests/net/src/android/net/wifi/cts/WifiManagerTest.java
@@ -0,0 +1,427 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net.wifi.cts;
+
+import java.util.List;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.net.wifi.ScanResult;
+import android.net.wifi.WifiConfiguration;
+import android.net.wifi.WifiManager;
+import android.net.wifi.WifiConfiguration.Status;
+import android.net.wifi.WifiManager.WifiLock;
+import android.test.AndroidTestCase;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
+
+@TestTargetClass(WifiManager.class)
+public class WifiManagerTest extends AndroidTestCase {
+    private static class MySync {
+        int expectedState = STATE_NULL;
+    }
+
+    private WifiManager mWifiManager;
+    private WifiLock mWifiLock;
+    private static MySync mMySync;
+    private List<ScanResult> mScanResult = null;
+
+    // Please refer to WifiManager
+    private static final int MIN_RSSI = -100;
+    private static final int MAX_RSSI = -55;
+
+    private static final int STATE_NULL = 0;
+    private static final int STATE_WIFI_CHANGING = 1;
+    private static final int STATE_WIFI_CHANGED = 2;
+    private static final int STATE_SCANING = 3;
+    private static final int STATE_SCAN_RESULTS_AVAILABLE = 4;
+
+    private static final String TAG = "WifiManagerTest";
+    private static final String SSID1 = "\"WifiManagerTest\"";
+    private static final String SSID2 = "\"WifiManagerTestModified\"";
+    private static final int TIMEOUT_MSEC = 6000;
+    private static final int WAIT_MSEC = 60;
+    private static final int DURATION = 10000;
+    private IntentFilter mIntentFilter;
+    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            final String action = intent.getAction();
+            if (action.equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) {
+                synchronized (mMySync) {
+                    if (mWifiManager.getScanResults() != null) {
+                        mScanResult = mWifiManager.getScanResults();
+                        mMySync.expectedState = STATE_SCAN_RESULTS_AVAILABLE;
+                        mScanResult = mWifiManager.getScanResults();
+                        mMySync.notify();
+                    }
+                }
+            } else if (action.equals(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION)) {
+                synchronized (mMySync) {
+                    mMySync.expectedState = STATE_WIFI_CHANGED;
+                    mMySync.notify();
+                }
+            }
+        }
+    };
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mMySync = new MySync();
+        mIntentFilter = new IntentFilter();
+        mIntentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
+        mIntentFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
+        mIntentFilter.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION);
+        mIntentFilter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION);
+        mIntentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
+        mIntentFilter.addAction(WifiManager.RSSI_CHANGED_ACTION);
+        mIntentFilter.addAction(WifiManager.NETWORK_IDS_CHANGED_ACTION);
+        mIntentFilter.addAction(WifiManager.ACTION_PICK_WIFI_NETWORK);
+
+        mContext.registerReceiver(mReceiver, mIntentFilter);
+        mWifiManager = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE);
+        assertNotNull(mWifiManager);
+        mWifiLock = mWifiManager.createWifiLock(TAG);
+        mWifiLock.acquire();
+        if (!mWifiManager.isWifiEnabled())
+            setWifiEnabled(true);
+        Thread.sleep(DURATION);
+        assertTrue(mWifiManager.isWifiEnabled());
+        mMySync.expectedState = STATE_NULL;
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        mWifiLock.release();
+        mContext.unregisterReceiver(mReceiver);
+        if (!mWifiManager.isWifiEnabled())
+            setWifiEnabled(true);
+        Thread.sleep(DURATION);
+        super.tearDown();
+    }
+
+    private void setWifiEnabled(boolean enable) throws Exception {
+        synchronized (mMySync) {
+            mMySync.expectedState = STATE_WIFI_CHANGING;
+            assertTrue(mWifiManager.setWifiEnabled(enable));
+            long timeout = System.currentTimeMillis() + TIMEOUT_MSEC;
+            while (System.currentTimeMillis() < timeout
+                    && mMySync.expectedState == STATE_WIFI_CHANGING)
+                mMySync.wait(WAIT_MSEC);
+        }
+    }
+
+    private void startScan() throws Exception {
+        synchronized (mMySync) {
+            mMySync.expectedState = STATE_SCANING;
+            assertTrue(mWifiManager.startScan());
+            long timeout = System.currentTimeMillis() + TIMEOUT_MSEC;
+            while (System.currentTimeMillis() < timeout && mMySync.expectedState == STATE_SCANING)
+                mMySync.wait(WAIT_MSEC);
+        }
+    }
+
+    private boolean existSSID(String ssid) {
+        for (final WifiConfiguration w : mWifiManager.getConfiguredNetworks()) {
+            if (w.SSID.equals(ssid))
+                return true;
+        }
+        return false;
+    }
+
+    private int findConfiguredNetworks(String SSID, List<WifiConfiguration> networks) {
+        for (final WifiConfiguration w : networks) {
+            if (w.SSID.equals(SSID))
+                return networks.indexOf(w);
+        }
+        return -1;
+    }
+
+    private void assertDisableOthers(WifiConfiguration wifiConfiguration, boolean disableOthers) {
+        for (WifiConfiguration w : mWifiManager.getConfiguredNetworks()) {
+            if ((!w.SSID.equals(wifiConfiguration.SSID)) && w.status != Status.CURRENT) {
+                if (disableOthers)
+                    assertEquals(Status.DISABLED, w.status);
+            }
+        }
+    }
+
+    /**
+     * test point of wifiManager actions:
+     * 1.reconnect
+     * 2.reassociate
+     * 3.disconnect
+     * 4.pingSupplicant
+     * 5.satrtScan
+     */
+    @TestTargets({
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "isWifiEnabled",
+            args = {}
+        ),
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "setWifiEnabled",
+            args = {boolean.class}
+        ),
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "startScan",
+            args = {}
+        ),
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "getScanResults",
+            args = {}
+        ),
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "pingSupplicant",
+            args = {}
+        ),
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "reassociate",
+            args = {}
+        ),
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "reconnect",
+            args = {}
+        ),
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "disconnect",
+            args = {}
+        ),
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "createWifiLock",
+            args = {int.class, String.class}
+        ),
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "createWifiLock",
+            args = {String.class}
+        )
+    })
+    public void testWifiManagerActions() throws Exception {
+        assertTrue(mWifiManager.reconnect());
+        assertTrue(mWifiManager.reassociate());
+        assertTrue(mWifiManager.disconnect());
+        assertTrue(mWifiManager.pingSupplicant());
+        startScan();
+        setWifiEnabled(false);
+        Thread.sleep(DURATION);
+        assertFalse(mWifiManager.pingSupplicant());
+        final String TAG = "Test";
+        assertNotNull(mWifiManager.createWifiLock(TAG));
+        assertNotNull(mWifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, TAG));
+    }
+
+    /**
+     * test point of wifiManager properties:
+     * 1.enable properties
+     * 2.DhcpInfo properties
+     * 3.wifi state
+     * 4.ConnectionInfo
+     */
+    @TestTargets({
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "isWifiEnabled",
+            args = {}
+        ),
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "getWifiState",
+            args = {}
+        ),
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "setWifiEnabled",
+            args = {boolean.class}
+        ),
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "getConnectionInfo",
+            args = {}
+        ),
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "getDhcpInfo",
+            args = {}
+        )
+    })
+    public void testWifiManagerProperties() throws Exception {
+        setWifiEnabled(true);
+        assertTrue(mWifiManager.isWifiEnabled());
+        assertNotNull(mWifiManager.getDhcpInfo());
+        assertEquals(WifiManager.WIFI_STATE_ENABLED, mWifiManager.getWifiState());
+        mWifiManager.getConnectionInfo();
+        setWifiEnabled(false);
+        assertFalse(mWifiManager.isWifiEnabled());
+    }
+
+    /**
+     * test point of wifiManager NetWork:
+     * 1.add NetWork
+     * 2.update NetWork
+     * 3.remove NetWork
+     * 4.enable NetWork
+     * 5.disable NetWork
+     * 6.configured Networks
+     * 7.save configure;
+     */
+    @TestTargets({
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "isWifiEnabled",
+            args = {}
+        ),
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "setWifiEnabled",
+            args = {boolean.class}
+        ),
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "getConfiguredNetworks",
+            args = {}
+        ),
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "addNetwork",
+            args = {android.net.wifi.WifiConfiguration.class}
+        ),
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "updateNetwork",
+            args = {android.net.wifi.WifiConfiguration.class}
+        ),
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "removeNetwork",
+            args = {int.class}
+        ),
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "enableNetwork",
+            args = {int.class, boolean.class}
+        ),
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "disableNetwork",
+            args = {int.class}
+        ),
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "saveConfiguration",
+            args = {}
+        )
+    })
+    public void testWifiManagerNetWork() throws Exception {
+        WifiConfiguration wifiConfiguration;
+        // add a WifiConfig
+        final int notExist = -1;
+        List<WifiConfiguration> wifiConfiguredNetworks = mWifiManager.getConfiguredNetworks();
+        int pos = findConfiguredNetworks(SSID1, wifiConfiguredNetworks);
+        if (notExist != pos) {
+            wifiConfiguration = wifiConfiguredNetworks.get(pos);
+            mWifiManager.removeNetwork(wifiConfiguration.networkId);
+        }
+        pos = findConfiguredNetworks(SSID1, wifiConfiguredNetworks);
+        assertEquals(notExist, pos);
+        final int size = wifiConfiguredNetworks.size();
+
+        wifiConfiguration = new WifiConfiguration();
+        wifiConfiguration.SSID = SSID1;
+        int netId = mWifiManager.addNetwork(wifiConfiguration);
+        assertTrue(existSSID(SSID1));
+
+        wifiConfiguredNetworks = mWifiManager.getConfiguredNetworks();
+        assertEquals(size + 1, wifiConfiguredNetworks.size());
+        pos = findConfiguredNetworks(SSID1, wifiConfiguredNetworks);
+        assertTrue(notExist != pos);
+
+        // Enable & disable network
+        boolean disableOthers = false;
+        assertTrue(mWifiManager.enableNetwork(netId, disableOthers));
+        wifiConfiguration = mWifiManager.getConfiguredNetworks().get(pos);
+        assertDisableOthers(wifiConfiguration, disableOthers);
+        assertEquals(Status.ENABLED, wifiConfiguration.status);
+        disableOthers = true;
+        assertTrue(mWifiManager.enableNetwork(netId, disableOthers));
+        wifiConfiguration = mWifiManager.getConfiguredNetworks().get(pos);
+        assertDisableOthers(wifiConfiguration, disableOthers);
+
+        assertTrue(mWifiManager.disableNetwork(netId));
+        wifiConfiguration = mWifiManager.getConfiguredNetworks().get(pos);
+        assertEquals(Status.DISABLED, wifiConfiguration.status);
+
+        // Update a WifiConfig
+        wifiConfiguration = wifiConfiguredNetworks.get(pos);
+        wifiConfiguration.SSID = SSID2;
+        netId = mWifiManager.updateNetwork(wifiConfiguration);
+        assertFalse(existSSID(SSID1));
+        assertTrue(existSSID(SSID2));
+
+        // Remove a WifiConfig
+        assertTrue(mWifiManager.removeNetwork(netId));
+        assertFalse(mWifiManager.removeNetwork(notExist));
+        assertFalse(existSSID(SSID1));
+        assertFalse(existSSID(SSID2));
+
+        assertTrue(mWifiManager.saveConfiguration());
+    }
+
+    @TestTargets({
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "compareSignalLevel",
+            args = {int.class, int.class}
+        ),
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "calculateSignalLevel",
+            args = {int.class, int.class}
+        )
+    })
+    public void testSignal() {
+        final int numLevels = 9;
+        int expectLevel = 0;
+        assertEquals(expectLevel, WifiManager.calculateSignalLevel(MIN_RSSI, numLevels));
+        assertEquals(numLevels - 1, WifiManager.calculateSignalLevel(MAX_RSSI, numLevels));
+        expectLevel = 4;
+        assertEquals(expectLevel, WifiManager.calculateSignalLevel((MIN_RSSI + MAX_RSSI) / 2,
+                numLevels));
+        int rssiA = 4;
+        int rssiB = 5;
+        assertTrue(WifiManager.compareSignalLevel(rssiA, rssiB) < 0);
+        rssiB = 4;
+        assertTrue(WifiManager.compareSignalLevel(rssiA, rssiB) == 0);
+        rssiA = 5;
+        rssiB = 4;
+        assertTrue(WifiManager.compareSignalLevel(rssiA, rssiB) > 0);
+    }
+}
diff --git a/tests/tests/net/src/android/net/wifi/cts/WifiManager_WifiLockTest.java b/tests/tests/net/src/android/net/wifi/cts/WifiManager_WifiLockTest.java
new file mode 100644
index 0000000..53150c9
--- /dev/null
+++ b/tests/tests/net/src/android/net/wifi/cts/WifiManager_WifiLockTest.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net.wifi.cts;
+
+import android.content.Context;
+import android.net.wifi.WifiManager;
+import android.net.wifi.WifiManager.WifiLock;
+import android.test.AndroidTestCase;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
+
+@TestTargetClass(WifiManager.WifiLock.class)
+public class WifiManager_WifiLockTest extends AndroidTestCase {
+
+    private static final String WIFI_TAG = "WifiManager_WifiLockTest";
+
+    @TestTargets({
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "acquire",
+            args = {}
+        ),
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "finalize",
+            args = {}
+        ),
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "isHeld",
+            args = {}
+        ),
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "release",
+            args = {}
+        ),
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "setReferenceCounted",
+            args = {boolean.class}
+        ),
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "toString",
+            args = {}
+        )
+    })
+    public void testWifiLock() {
+        WifiManager wm = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE);
+        WifiLock wl = wm.createWifiLock(WIFI_TAG);
+
+        wl.setReferenceCounted(true);
+        assertFalse(wl.isHeld());
+        wl.acquire();
+        assertTrue(wl.isHeld());
+        wl.release();
+        assertFalse(wl.isHeld());
+        wl.acquire();
+        wl.acquire();
+        assertTrue(wl.isHeld());
+        wl.release();
+        assertTrue(wl.isHeld());
+        wl.release();
+        assertFalse(wl.isHeld());
+        assertNotNull(wl.toString());
+        try {
+            wl.release();
+            fail("should throw out exception because release is called"
+                    +" a greater number of times than acquire");
+        } catch (RuntimeException e) {
+            // expected
+        }
+
+        wl = wm.createWifiLock(WIFI_TAG);
+        wl.setReferenceCounted(false);
+        assertFalse(wl.isHeld());
+        wl.acquire();
+        assertTrue(wl.isHeld());
+        wl.release();
+        assertFalse(wl.isHeld());
+        wl.acquire();
+        wl.acquire();
+        assertTrue(wl.isHeld());
+        wl.release();
+        assertFalse(wl.isHeld());
+        assertNotNull(wl.toString());
+        // should be ignored
+        wl.release();
+    }
+}