1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.connectivitymanagertest.unit;
18
19import android.content.BroadcastReceiver;
20import android.content.Intent;
21import android.content.Context;
22import android.app.Instrumentation;
23import android.os.Handler;
24import android.os.Message;
25import android.net.ConnectivityManager;
26import android.net.wifi.WifiManager;
27import android.net.wifi.WifiConfiguration;
28import android.net.wifi.WifiConfiguration.KeyMgmt;
29
30import android.test.suitebuilder.annotation.LargeTest;
31import android.test.AndroidTestCase;
32
33import java.util.ArrayList;
34
35import android.util.Log;
36
37/**
38 * Test Wifi soft AP configuration
39 */
40public class WifiSoftAPTest extends AndroidTestCase {
41
42    private WifiManager mWifiManager;
43    private WifiConfiguration mWifiConfig = null;
44    private final String TAG = "WifiSoftAPTest";
45    private final int DURATION = 10000;
46
47    @Override
48    protected void setUp() throws Exception {
49        super.setUp();
50        mWifiManager = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE);
51        assertNotNull(mWifiManager);
52        assertTrue(mWifiManager.setWifiApEnabled(null, true));
53        mWifiConfig = mWifiManager.getWifiApConfiguration();
54        if (mWifiConfig != null) {
55            Log.v(TAG, "mWifiConfig is " + mWifiConfig.toString());
56        } else {
57            Log.v(TAG, "mWifiConfig is null.");
58        }
59    }
60
61    @Override
62    protected void tearDown() throws Exception {
63        Log.v(TAG, "turn off wifi tethering");
64        mWifiManager.setWifiApEnabled(null, false);
65        super.tearDown();
66    }
67
68    // Test case 1: Test the soft AP SSID with letters
69    @LargeTest
70    public void testApSsidWithAlphabet() {
71        WifiConfiguration config = new WifiConfiguration();
72        config.SSID = "abcdefghijklmnopqrstuvwxyz";
73        config.allowedKeyManagement.set(KeyMgmt.NONE);
74        mWifiConfig = config;
75        assertTrue(mWifiManager.setWifiApEnabled(mWifiConfig, true));
76        try {
77            Thread.sleep(DURATION);
78        } catch (InterruptedException e) {
79            Log.v(TAG, "exception " + e.getStackTrace());
80            assertFalse(true);
81        }
82        assertNotNull(mWifiManager.getWifiApConfiguration());
83        assertEquals("wifi AP state is not enabled", WifiManager.WIFI_AP_STATE_ENABLED,
84                     mWifiManager.getWifiApState());
85    }
86}
87