• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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 
17 package com.android.cts.deviceowner.wificonfigcreator;
18 
19 import android.app.Activity;
20 import android.content.Intent;
21 import android.os.Bundle;
22 import android.util.Log;
23 
24 import com.android.compatibility.common.util.WifiConfigCreator;
25 import static com.android.compatibility.common.util.WifiConfigCreator.ACTION_CREATE_WIFI_CONFIG;
26 import static com.android.compatibility.common.util.WifiConfigCreator.EXTRA_NETID;
27 import static com.android.compatibility.common.util.WifiConfigCreator.EXTRA_PASSWORD;
28 import static com.android.compatibility.common.util.WifiConfigCreator.EXTRA_SECURITY_TYPE;
29 import static com.android.compatibility.common.util.WifiConfigCreator.EXTRA_SSID;
30 import static com.android.compatibility.common.util.WifiConfigCreator.ACTION_REMOVE_WIFI_CONFIG;
31 import static com.android.compatibility.common.util.WifiConfigCreator.SECURITY_TYPE_NONE;
32 import static com.android.compatibility.common.util.WifiConfigCreator.ACTION_UPDATE_WIFI_CONFIG;
33 
34 /**
35  * A simple activity to create and manage wifi configurations.
36  */
37 public class WifiConfigCreatorActivity extends Activity {
38     private static final String TAG = "WifiConfigCreatorActivity";
39 
40     @Override
onCreate(Bundle icicle)41     public void onCreate(Bundle icicle) {
42         super.onCreate(icicle);
43         Log.i(TAG, "Created for user " + android.os.Process.myUserHandle());
44         WifiConfigCreator configCreator = new WifiConfigCreator(this);
45         try {
46             Intent intent = getIntent();
47             String action = intent.getAction();
48             if (ACTION_CREATE_WIFI_CONFIG.equals(action)) {
49                 String ssid = intent.getStringExtra(EXTRA_SSID);
50                 int securityType = intent.getIntExtra(EXTRA_SECURITY_TYPE, SECURITY_TYPE_NONE);
51                 String password = intent.getStringExtra(EXTRA_PASSWORD);
52                 configCreator.addNetwork(ssid, false, securityType, password);
53             } else if (ACTION_UPDATE_WIFI_CONFIG.equals(action)) {
54                 int netId = intent.getIntExtra(EXTRA_NETID, -1);
55                 String ssid = intent.getStringExtra(EXTRA_SSID);
56                 int securityType = intent.getIntExtra(EXTRA_SECURITY_TYPE, SECURITY_TYPE_NONE);
57                 String password = intent.getStringExtra(EXTRA_PASSWORD);
58                 configCreator.updateNetwork(netId, ssid, false, securityType, password);
59             } else if (ACTION_REMOVE_WIFI_CONFIG.equals(action)) {
60                 int netId = intent.getIntExtra(EXTRA_NETID, -1);
61                 if (netId != -1) {
62                     configCreator.removeNetwork(netId);
63                 }
64             } else {
65                 Log.i(TAG, "Unknown command: " + action);
66             }
67         } catch (InterruptedException ie) {
68             Log.e(TAG, "Interrupted while changing wifi settings", ie);
69         } finally {
70             finish();
71         }
72     }
73 }
74