1 /*
2  * Copyright (C) 2016 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.IntDef;
20 
21 import java.io.FileDescriptor;
22 import java.io.PrintWriter;
23 import java.lang.annotation.Retention;
24 import java.lang.annotation.RetentionPolicy;
25 import java.util.Arrays;
26 import java.util.List;
27 
28 /**
29  * Base class for available WiFi operating modes.
30  *
31  * Currently supported modes include Client, ScanOnly and SoftAp.
32  */
33 public interface ActiveModeManager {
34     /**
35      * Listener for ActiveModeManager state changes.
36      */
37     interface Listener {
38         /**
39          * Invoked when mode manager completes start or on mode switch.
40          */
onStarted()41         void onStarted();
42         /**
43          * Invoked when mode manager completes stop.
44          */
onStopped()45         void onStopped();
46         /**
47          * Invoked when mode manager encountered a failure on start or on mode switch.
48          */
onStartFailure()49         void onStartFailure();
50     }
51 
52     /**
53      * Method used to start the Manager for a given Wifi operational mode.
54      */
start()55     void start();
56 
57     /**
58      * Method used to stop the Manager for a given Wifi operational mode.
59      */
stop()60     void stop();
61 
62     /**
63      * Method used to indicate if the mode manager is still stopping.
64      */
isStopping()65     boolean isStopping();
66 
67     /** Roles assigned to each mode manager. */
68     int ROLE_UNSPECIFIED = -1;
69     // SoftApManager - Tethering, will respond to public APIs.
70     int ROLE_SOFTAP_TETHERED = 0;
71     // SoftApManager - Local only hotspot.
72     int ROLE_SOFTAP_LOCAL_ONLY = 1;
73     // ClientModeManager, primary STA, will respond to public APIs
74     int ROLE_CLIENT_PRIMARY = 2;
75     // ClientModeManager, secondary STA, can switch to primary later.
76     int ROLE_CLIENT_SECONDARY = 3;
77     // ClientModeManager, secondary STA created for local connection (no internet connectivity).
78     int ROLE_CLIENT_LOCAL_ONLY = 4;
79     // ClientModeManager, STA created for scans only.
80     int ROLE_CLIENT_SCAN_ONLY = 5;
81 
82     @IntDef(prefix = { "ROLE_" }, value = {
83             ROLE_SOFTAP_TETHERED,
84             ROLE_SOFTAP_LOCAL_ONLY,
85             ROLE_CLIENT_PRIMARY,
86             ROLE_CLIENT_SECONDARY,
87             ROLE_CLIENT_LOCAL_ONLY,
88             ROLE_CLIENT_SCAN_ONLY
89     })
90     @Retention(RetentionPolicy.SOURCE)
91     @interface Role{}
92 
93     /** List of Client roles */
94     List<Integer> CLIENT_ROLES = Arrays.asList(
95             ROLE_CLIENT_PRIMARY,
96             ROLE_CLIENT_SECONDARY,
97             ROLE_CLIENT_LOCAL_ONLY,
98             ROLE_CLIENT_SCAN_ONLY);
99     /** List of Client roles that could initiate a wifi connection */
100     List<Integer> CLIENT_CONNECTIVITY_ROLES = Arrays.asList(
101             ROLE_CLIENT_PRIMARY,
102             ROLE_CLIENT_SECONDARY,
103             ROLE_CLIENT_LOCAL_ONLY);
104     /** List of Client roles that could initiate a wifi connection for internet connectivity */
105     List<Integer> CLIENT_INTERNET_CONNECTIVITY_ROLES = Arrays.asList(
106             ROLE_CLIENT_PRIMARY,
107             ROLE_CLIENT_SECONDARY);
108     /** List of SoftAp roles */
109     List<Integer> SOFTAP_ROLES = Arrays.asList(
110             ROLE_SOFTAP_LOCAL_ONLY,
111             ROLE_SOFTAP_TETHERED);
112 
113     /**
114      * Method to get the role for a mode manager.
115      */
getRole()116     @Role int getRole();
117 
118     /**
119      * Method to set the role for a mode manager.
120      */
setRole(@ole int role)121     void setRole(@Role int role);
122 
123     /**
124      * Method to dump for logging state.
125      */
dump(FileDescriptor fd, PrintWriter pw, String[] args)126     void dump(FileDescriptor fd, PrintWriter pw, String[] args);
127 }
128