2 * Copyright (C) 2010 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.connectivitymanagertest.unit;
19 import android.content.BroadcastReceiver;
20 import android.content.Intent;
21 import android.content.Context;
22 import android.app.Instrumentation;
23 import android.os.Handler;
24 import android.os.Message;
25 import android.net.ConnectivityManager;
26 import android.net.wifi.WifiManager;
27 import android.net.wifi.WifiConfiguration;
28 import android.net.wifi.WifiConfiguration.KeyMgmt;
30 import android.test.suitebuilder.annotation.LargeTest;
31 import android.test.AndroidTestCase;
33 import java.util.ArrayList;
35 import android.util.Log;
38 * Test Wifi soft AP configuration
40 public class WifiSoftAPTest extends AndroidTestCase {
42 private WifiManager mWifiManager;
43 private WifiConfiguration mWifiConfig = null;
44 private final String TAG = "WifiSoftAPTest";
45 private final int DURATION = 10000;
48 protected void setUp() throws Exception {
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());
57 Log.v(TAG, "mWifiConfig is null.");
62 protected void tearDown() throws Exception {
63 Log.v(TAG, "turn off wifi tethering");
64 mWifiManager.setWifiApEnabled(null, false);
68 // Test case 1: Test the soft AP SSID with letters
70 public void testApSsidWithAlphabet() {
71 WifiConfiguration config = new WifiConfiguration();
72 config.SSID = "abcdefghijklmnopqrstuvwxyz";
73 config.allowedKeyManagement.set(KeyMgmt.NONE);
75 assertTrue(mWifiManager.setWifiApEnabled(mWifiConfig, true));
77 Thread.sleep(DURATION);
78 } catch (InterruptedException e) {
79 Log.v(TAG, "exception " + e.getStackTrace());
82 assertNotNull(mWifiManager.getWifiApConfiguration());
83 assertEquals("wifi AP state is not enabled", WifiManager.WIFI_AP_STATE_ENABLED,
84 mWifiManager.getWifiApState());