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