• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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.server.wifi;
18 
19 import android.annotation.SystemApi;
20 import android.os.SystemService;
21 import android.util.Log;
22 
23 import java.util.NoSuchElementException;
24 
25 /**
26  * Wrapper to start/stop supplicant daemon using init system.
27  * @hide
28  */
29 @SystemApi(client = SystemApi.Client.SYSTEM_SERVER)
30 public class SupplicantManager {
31     private static final String TAG = "SupplicantManager";
32 
33     private static final String WPA_SUPPLICANT_DAEMON_NAME = "wpa_supplicant";
34 
SupplicantManager()35     private SupplicantManager() {}
36 
37     /**
38      * Start the wpa_supplicant daemon.
39      * Note: This uses the init system to start the "wpa_supplicant" service.
40      *
41      * @throws NoSuchElementException if supplicant daemon failed to start
42      */
start()43     public static void start() {
44         try {
45             SystemService.start(WPA_SUPPLICANT_DAEMON_NAME);
46         } catch (RuntimeException e) {
47             // likely a "failed to set system property" runtime exception
48             throw new NoSuchElementException("Failed to start Supplicant");
49         }
50     }
51 
52     /**
53      * Stop the wpa_supplicant daemon.
54      * Note: This uses the init system to stop the "wpa_supplicant" service.
55      */
stop()56     public static void stop() {
57         try {
58             SystemService.stop(WPA_SUPPLICANT_DAEMON_NAME);
59         } catch (RuntimeException e) {
60             // likely a "failed to set system property" runtime exception
61             Log.w(TAG, "Failed to stop Supplicant", e);
62         }
63     }
64 }
65