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.NonNull;
20 import android.annotation.Nullable;
21 import android.os.WorkSource;
22 
23 import java.io.FileDescriptor;
24 import java.io.PrintWriter;
25 
26 /**
27  * Base class for available WiFi operating modes.
28  *
29  * Currently supported modes include Client, ScanOnly and SoftAp.
30  */
31 public interface ActiveModeManager {
32     /**
33      * Listener for ActiveModeManager state changes.
34      * @param <T> type of ActiveModeManager that is being listened
35      */
36     interface Listener<T extends ActiveModeManager> {
37         /**
38          * Invoked when mode manager completes start.
39          */
onStarted(@onNull T activeModeManager)40         void onStarted(@NonNull T activeModeManager);
41         /**
42          * Invoked when mode manager completes stop.
43          */
onStopped(@onNull T activeModeManager)44         void onStopped(@NonNull T activeModeManager);
45         /**
46          * Invoked when mode manager completes a role switch.
47          */
onRoleChanged(@onNull T activeModeManager)48         void onRoleChanged(@NonNull T activeModeManager);
49         /**
50          * Invoked when mode manager encountered a failure on start or on mode switch.
51          */
onStartFailure(@onNull T activeModeManager)52         void onStartFailure(@NonNull T activeModeManager);
53     }
54 
55     /**
56      * Method used to stop the Manager for a given Wifi operational mode.
57      */
stop()58     void stop();
59 
60     // Hierarchy of roles - note that currently, the roles form a tree: no role has more than 1
61     // parent. However, since interfaces support multiple inheritance, a role could have more than 1
62     // parent if needed.
63 
64     /** Roles assigned to each mode manager. */
65     interface Role {}
66 
67     /** SoftAp roles */
68     interface SoftApRole extends Role {}
69     /** SoftApManager - Tethering, will respond to public APIs. */
70     SoftApRole ROLE_SOFTAP_TETHERED = new SoftApRole() {
71         @Override
72         public String toString() {
73             return "ROLE_SOFTAP_TETHERED";
74         }
75     };
76     /** SoftApManager - Local only hotspot. */
77     SoftApRole ROLE_SOFTAP_LOCAL_ONLY = new SoftApRole() {
78         @Override
79         public String toString() {
80             return "ROLE_SOFTAP_LOCAL_ONLY";
81         }
82     };
83 
84     /** Client roles */
85     interface ClientRole extends Role {}
86     /** ClientModeManager, STA created for scans only. */
87     ClientRole ROLE_CLIENT_SCAN_ONLY = new ClientRole() {
88         @Override
89         public String toString() {
90             return "ROLE_CLIENT_SCAN_ONLY";
91         }
92     };
93 
94     /** Client roles that could initiate a wifi connection */
95     interface ClientConnectivityRole extends ClientRole {}
96     /**
97      * ClientModeManager, secondary STA used for make before break, can switch to primary later.
98      * Note: ClientModeManagers in this role will call {@link #stop()} upon disconnecting from Wifi.
99      */
100     ClientConnectivityRole ROLE_CLIENT_SECONDARY_TRANSIENT = new ClientConnectivityRole() {
101         @Override
102         public String toString() {
103             return "ROLE_CLIENT_SECONDARY_TRANSIENT";
104         }
105     };
106     /** ClientModeManager, secondary STA created for local connection (no internet connectivity). */
107     ClientConnectivityRole ROLE_CLIENT_LOCAL_ONLY = new ClientConnectivityRole() {
108         @Override
109         public String toString() {
110             return "ROLE_CLIENT_LOCAL_ONLY";
111         }
112     };
113 
114     /** Long running Client roles that could initiate a wifi connection for internet connectivity */
115     interface ClientInternetConnectivityRole extends ClientConnectivityRole {}
116     /**
117      * ClientModeManager, primary STA, will respond to public WifiManager APIs
118      * Note: Primary STA can be used to satisfy any of the other client roles whenever it is not
119      * possible to create a concurrent ClientModeManager for the specified role. This is only true
120      * for primary role. ClientModeManager in any of the other roles are dedicated to the
121      * corresponding role.
122      */
123     ClientInternetConnectivityRole ROLE_CLIENT_PRIMARY =
124             new ClientInternetConnectivityRole() {
125                 @Override
126                 public String toString() {
127                     return "ROLE_CLIENT_PRIMARY";
128                 }
129             };
130     /**
131      * ClientModeManager, secondary STA used for duplication/bonding use cases, will not respond to
132      * public WifiManager APIs.
133      *
134      * Note: ClientModeManagers in this role will call {@link #stop()} upon disconnecting from Wifi.
135      */
136     ClientInternetConnectivityRole ROLE_CLIENT_SECONDARY_LONG_LIVED =
137             new ClientInternetConnectivityRole() {
138                 @Override
139                 public String toString() {
140                     return "ROLE_CLIENT_SECONDARY_LONG_LIVED";
141                 }
142             };
143 
144     /**
145      * Method to get the role for a mode manager.
146      */
getRole()147     @Nullable Role getRole();
148 
149     /**
150      * Method to get the previous role a mode manager.
151      */
getPreviousRole()152     @Nullable Role getPreviousRole();
153 
154     /**
155      * Get the time in ms since boot of the last role change.
156      */
getLastRoleChangeSinceBootMs()157     long getLastRoleChangeSinceBootMs();
158 
159     /**
160      * Method to get the iface name for the mode manager.
161      */
getInterfaceName()162     String getInterfaceName();
163 
164     /**
165      * Method to retrieve the original requestorWs
166      */
getRequestorWs()167     WorkSource getRequestorWs();
168 
169     /**
170      * Method to dump for logging state.
171      */
dump(FileDescriptor fd, PrintWriter pw, String[] args)172     void dump(FileDescriptor fd, PrintWriter pw, String[] args);
173 
174     /**
175      * Method to enable verbose logging.
176      */
enableVerboseLogging(boolean verbose)177     void enableVerboseLogging(boolean verbose);
178 
179     /** Unique ID for this ActiveModeManager instance, used for debugging. */
getId()180     long getId();
181 }
182