• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 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 android.net;
18 
19 import android.content.Context;
20 import android.os.Handler;
21 import android.os.Messenger;
22 
23 import static com.android.internal.util.Protocol.BASE_NETWORK_STATE_TRACKER;
24 
25 /**
26  * Interface provides the {@link com.android.server.ConnectivityService}
27  * with three services. Events to the ConnectivityService when
28  * changes occur, an API for controlling the network and storage
29  * for network specific information.
30  *
31  * The Connectivity will call startMonitoring before any other
32  * method is called.
33  *
34  * {@hide}
35  */
36 public interface NetworkStateTracker {
37 
38     /**
39      * -------------------------------------------------------------
40      * Event Interface back to ConnectivityService.
41      *
42      * The events that are to be sent back to the Handler passed
43      * to startMonitoring when the particular event occurs.
44      * -------------------------------------------------------------
45      */
46 
47     /**
48      * The network state has changed and the NetworkInfo object
49      * contains the new state.
50      *
51      * msg.what = EVENT_STATE_CHANGED
52      * msg.obj = NetworkInfo object
53      */
54     public static final int EVENT_STATE_CHANGED = BASE_NETWORK_STATE_TRACKER;
55 
56     /**
57      * msg.what = EVENT_CONFIGURATION_CHANGED
58      * msg.obj = NetworkInfo object
59      */
60     public static final int EVENT_CONFIGURATION_CHANGED = BASE_NETWORK_STATE_TRACKER + 1;
61 
62     /**
63      * msg.what = EVENT_RESTORE_DEFAULT_NETWORK
64      * msg.obj = FeatureUser object
65      */
66     public static final int EVENT_RESTORE_DEFAULT_NETWORK = BASE_NETWORK_STATE_TRACKER + 2;
67 
68     /**
69      * msg.what = EVENT_NETWORK_SUBTYPE_CHANGED
70      * msg.obj = NetworkInfo object
71      */
72     public static final int EVENT_NETWORK_SUBTYPE_CHANGED = BASE_NETWORK_STATE_TRACKER + 3;
73 
74     /**
75      * msg.what = EVENT_NETWORK_CONNECTED
76      * msg.obj = LinkProperties object
77      */
78     public static final int EVENT_NETWORK_CONNECTED = BASE_NETWORK_STATE_TRACKER + 4;
79 
80     /**
81      * msg.what = EVENT_NETWORK_CONNECTION_DISCONNECTED
82      * msg.obj = LinkProperties object, same iface name
83      */
84     public static final int EVENT_NETWORK_DISCONNECTED = BASE_NETWORK_STATE_TRACKER + 5;
85 
86     /**
87      * -------------------------------------------------------------
88      * Control Interface
89      * -------------------------------------------------------------
90      */
91     /**
92      * Begin monitoring data connectivity.
93      *
94      * This is the first method called when this interface is used.
95      *
96      * @param context is the current Android context
97      * @param target is the Hander to which to return the events.
98      */
startMonitoring(Context context, Handler target)99     public void startMonitoring(Context context, Handler target);
100 
101     /**
102      * Fetch NetworkInfo for the network
103      */
getNetworkInfo()104     public NetworkInfo getNetworkInfo();
105 
106     /**
107      * Return the LinkProperties for the connection.
108      *
109      * @return a copy of the LinkProperties, is never null.
110      */
getLinkProperties()111     public LinkProperties getLinkProperties();
112 
113     /**
114      * @return a copy of this connections capabilities, may be empty but never null.
115      */
getNetworkCapabilities()116     public NetworkCapabilities getNetworkCapabilities();
117 
118     /**
119      * Get interesting information about this network link
120      * @return a copy of link information, null if not available
121      */
getLinkQualityInfo()122     public LinkQualityInfo getLinkQualityInfo();
123 
124     /**
125      * Return the system properties name associated with the tcp buffer sizes
126      * for this network.
127      */
getTcpBufferSizesPropName()128     public String getTcpBufferSizesPropName();
129 
130     /**
131      * Disable connectivity to a network
132      * @return {@code true} if a teardown occurred, {@code false} if the
133      * teardown did not occur.
134      */
teardown()135     public boolean teardown();
136 
137     /**
138      * Reenable connectivity to a network after a {@link #teardown()}.
139      * @return {@code true} if we're connected or expect to be connected
140      */
reconnect()141     public boolean reconnect();
142 
143     /**
144      * Captive portal check has completed
145      */
captivePortalCheckCompleted(boolean isCaptive)146     public void captivePortalCheckCompleted(boolean isCaptive);
147 
148     /**
149      * Turn the wireless radio off for a network.
150      * @param turnOn {@code true} to turn the radio on, {@code false}
151      */
setRadio(boolean turnOn)152     public boolean setRadio(boolean turnOn);
153 
154     /**
155      * Returns an indication of whether this network is available for
156      * connections. A value of {@code false} means that some quasi-permanent
157      * condition prevents connectivity to this network.
158      *
159      * NOTE that this is broken on multi-connection devices.  Should be fixed in J release
160      * TODO - fix on multi-pdp devices
161      */
isAvailable()162     public boolean isAvailable();
163 
164     /**
165      * User control of data connection through this network, typically persisted
166      * internally.
167      */
setUserDataEnable(boolean enabled)168     public void setUserDataEnable(boolean enabled);
169 
170     /**
171      * Policy control of data connection through this network, typically not
172      * persisted internally. Usually used when {@link NetworkPolicy#limitBytes}
173      * is passed.
174      */
setPolicyDataEnable(boolean enabled)175     public void setPolicyDataEnable(boolean enabled);
176 
177     /**
178      * -------------------------------------------------------------
179      * Storage API used by ConnectivityService for saving
180      * Network specific information.
181      * -------------------------------------------------------------
182      */
183 
184     /**
185      * Check if private DNS route is set for the network
186      */
isPrivateDnsRouteSet()187     public boolean isPrivateDnsRouteSet();
188 
189     /**
190      * Set a flag indicating private DNS route is set
191      */
privateDnsRouteSet(boolean enabled)192     public void privateDnsRouteSet(boolean enabled);
193 
194     /**
195      * Check if default route is set
196      */
isDefaultRouteSet()197     public boolean isDefaultRouteSet();
198 
199     /**
200      * Set a flag indicating default route is set for the network
201      */
defaultRouteSet(boolean enabled)202     public void defaultRouteSet(boolean enabled);
203 
204     /**
205      * Check if tear down was requested
206      */
isTeardownRequested()207     public boolean isTeardownRequested();
208 
209     /**
210      * Indicate tear down requested from connectivity
211      */
setTeardownRequested(boolean isRequested)212     public void setTeardownRequested(boolean isRequested);
213 
214     /**
215      * An external dependency has been met/unmet
216      */
setDependencyMet(boolean met)217     public void setDependencyMet(boolean met);
218 
219     /**
220      * Informs the state tracker that another interface is stacked on top of it.
221      **/
addStackedLink(LinkProperties link)222     public void addStackedLink(LinkProperties link);
223 
224     /**
225      * Informs the state tracker that a stacked interface has been removed.
226      **/
removeStackedLink(LinkProperties link)227     public void removeStackedLink(LinkProperties link);
228 
229     /*
230      * Called once to setup async channel between this and
231      * the underlying network specific code.
232      */
supplyMessenger(Messenger messenger)233     public void supplyMessenger(Messenger messenger);
234 
235     /*
236      * Network interface name that we'll lookup for sampling data
237      */
getNetworkInterfaceName()238     public String getNetworkInterfaceName();
239 
240     /*
241      * Save the starting sample
242      */
startSampling(SamplingDataTracker.SamplingSnapshot s)243     public void startSampling(SamplingDataTracker.SamplingSnapshot s);
244 
245     /*
246      * Save the ending sample
247      */
stopSampling(SamplingDataTracker.SamplingSnapshot s)248     public void stopSampling(SamplingDataTracker.SamplingSnapshot s);
249 
250     /*
251      * Record the current netId
252      */
setNetId(int netId)253     public void setNetId(int netId);
254 
255     /*
256      * ?
257      */
getNetwork()258     public Network getNetwork();
259 
260 }
261