NetworkStateTracker.java revision f61101f6266be243c481d163b95e65d67b8d1669
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
17package android.net;
18
19import android.content.Context;
20import android.os.Handler;
21
22/**
23 * Interface provides the {@link com.android.server.ConnectivityService}
24 * with three services. Events to the ConnectivityService when
25 * changes occur, an API for controlling the network and storage
26 * for network specific information.
27 *
28 * The Connectivity will call startMonitoring before any other
29 * method is called.
30 *
31 * {@hide}
32 */
33public interface NetworkStateTracker {
34
35    /**
36     * -------------------------------------------------------------
37     * Event Interface back to ConnectivityService.
38     *
39     * The events that are to be sent back to the Handler passed
40     * to startMonitoring when the particular event occurs.
41     * -------------------------------------------------------------
42     */
43
44    /**
45     * The network state has changed and the NetworkInfo object
46     * contains the new state.
47     *
48     * msg.what = EVENT_STATE_CHANGED
49     * msg.obj = NetworkInfo object
50     */
51    public static final int EVENT_STATE_CHANGED = 1;
52
53    /**
54     * msg.what = EVENT_CONFIGURATION_CHANGED
55     * msg.obj = NetworkInfo object
56     */
57    public static final int EVENT_CONFIGURATION_CHANGED = 3;
58
59    /**
60     * msg.what = EVENT_RESTORE_DEFAULT_NETWORK
61     * msg.obj = FeatureUser object
62     */
63    public static final int EVENT_RESTORE_DEFAULT_NETWORK = 6;
64
65    /**
66     * USED by ConnectivityService only
67     *
68     * msg.what = EVENT_CLEAR_NET_TRANSITION_WAKELOCK
69     * msg.arg1 = mNetTransitionWakeLockSerialNumber
70     */
71    public static final int EVENT_CLEAR_NET_TRANSITION_WAKELOCK = 7;
72
73    /**
74     * msg.arg1 = network type
75     * msg.arg2 = condition (0 bad, 100 good)
76     */
77    public static final int EVENT_INET_CONDITION_CHANGE = 8;
78
79    /**
80     * msg.arg1 = network type
81     * msg.arg2 = default connection sequence number
82     */
83    public static final int EVENT_INET_CONDITION_HOLD_END = 9;
84
85    /**
86     * -------------------------------------------------------------
87     * Control Interface
88     * -------------------------------------------------------------
89     */
90    /**
91     * Begin monitoring data connectivity.
92     *
93     * This is the first method called when this interface is used.
94     *
95     * @param context is the current Android context
96     * @param target is the Hander to which to return the events.
97     */
98    public void startMonitoring(Context context, Handler target);
99
100    /**
101     * Fetch NetworkInfo for the network
102     */
103    public NetworkInfo getNetworkInfo();
104
105    /**
106     * Return the LinkProperties for the connection.
107     *
108     * @return a copy of the LinkProperties, is never null.
109     */
110    public LinkProperties getLinkProperties();
111
112    /**
113     * A capability is an Integer/String pair, the capabilities
114     * are defined in the class LinkSocket#Key.
115     *
116     * @return a copy of this connections capabilities, may be empty but never null.
117     */
118    public LinkCapabilities getLinkCapabilities();
119
120    /**
121     * Return the system properties name associated with the tcp buffer sizes
122     * for this network.
123     */
124    public String getTcpBufferSizesPropName();
125
126    /**
127     * Disable connectivity to a network
128     * @return {@code true} if a teardown occurred, {@code false} if the
129     * teardown did not occur.
130     */
131    public boolean teardown();
132
133    /**
134     * Reenable connectivity to a network after a {@link #teardown()}.
135     * @return {@code true} if we're connected or expect to be connected
136     */
137    public boolean reconnect();
138
139    /**
140     * Turn the wireless radio off for a network.
141     * @param turnOn {@code true} to turn the radio on, {@code false}
142     */
143    public boolean setRadio(boolean turnOn);
144
145    /**
146     * Returns an indication of whether this network is available for
147     * connections. A value of {@code false} means that some quasi-permanent
148     * condition prevents connectivity to this network.
149     */
150    public boolean isAvailable();
151
152    /**
153     * Fetch default gateway address for the network
154     */
155    public int getDefaultGatewayAddr();
156
157    /**
158     * Tells the underlying networking system that the caller wants to
159     * begin using the named feature. The interpretation of {@code feature}
160     * is completely up to each networking implementation.
161     * @param feature the name of the feature to be used
162     * @param callingPid the process ID of the process that is issuing this request
163     * @param callingUid the user ID of the process that is issuing this request
164     * @return an integer value representing the outcome of the request.
165     * The interpretation of this value is specific to each networking
166     * implementation+feature combination, except that the value {@code -1}
167     * always indicates failure.
168     */
169    public int startUsingNetworkFeature(String feature, int callingPid, int callingUid);
170
171    /**
172     * Tells the underlying networking system that the caller is finished
173     * using the named feature. The interpretation of {@code feature}
174     * is completely up to each networking implementation.
175     * @param feature the name of the feature that is no longer needed.
176     * @param callingPid the process ID of the process that is issuing this request
177     * @param callingUid the user ID of the process that is issuing this request
178     * @return an integer value representing the outcome of the request.
179     * The interpretation of this value is specific to each networking
180     * implementation+feature combination, except that the value {@code -1}
181     * always indicates failure.
182     */
183    public int stopUsingNetworkFeature(String feature, int callingPid, int callingUid);
184
185    /**
186     * -------------------------------------------------------------
187     * Storage API used by ConnectivityService for saving
188     * Network specific information.
189     * -------------------------------------------------------------
190     */
191
192    /**
193     * Check if private DNS route is set for the network
194     */
195    public boolean isPrivateDnsRouteSet();
196
197    /**
198     * Set a flag indicating private DNS route is set
199     */
200    public void privateDnsRouteSet(boolean enabled);
201
202    /**
203     * Check if default route is set
204     */
205    public boolean isDefaultRouteSet();
206
207    /**
208     * Set a flag indicating default route is set for the network
209     */
210    public void defaultRouteSet(boolean enabled);
211
212    /**
213     * Check if tear down was requested
214     */
215    public boolean isTeardownRequested();
216
217    /**
218     * Indicate tear down requested from connectivity
219     */
220    public void setTeardownRequested(boolean isRequested);
221
222}
223