NetworkStateTracker.java revision 37e65ebb7eb932e1a144b1cab262e11ca5fd109b
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     * -------------------------------------------------------------
75     * Control Interface
76     * -------------------------------------------------------------
77     */
78    /**
79     * Begin monitoring data connectivity.
80     *
81     * This is the first method called when this interface is used.
82     *
83     * @param context is the current Android context
84     * @param target is the Hander to which to return the events.
85     */
86    public void startMonitoring(Context context, Handler target);
87
88    /**
89     * Fetch NetworkInfo for the network
90     */
91    public NetworkInfo getNetworkInfo();
92
93    /**
94     * Fetch LinkProperties for the network
95     */
96    public LinkProperties getLinkProperties();
97
98    /**
99     * Return the system properties name associated with the tcp buffer sizes
100     * for this network.
101     */
102    public String getTcpBufferSizesPropName();
103
104    /**
105     * Disable connectivity to a network
106     * @return {@code true} if a teardown occurred, {@code false} if the
107     * teardown did not occur.
108     */
109    public boolean teardown();
110
111    /**
112     * Reenable connectivity to a network after a {@link #teardown()}.
113     * @return {@code true} if we're connected or expect to be connected
114     */
115    public boolean reconnect();
116
117    /**
118     * Turn the wireless radio off for a network.
119     * @param turnOn {@code true} to turn the radio on, {@code false}
120     */
121    public boolean setRadio(boolean turnOn);
122
123    /**
124     * Returns an indication of whether this network is available for
125     * connections. A value of {@code false} means that some quasi-permanent
126     * condition prevents connectivity to this network.
127     */
128    public boolean isAvailable();
129
130    /**
131     * Fetch default gateway address for the network
132     */
133    public int getDefaultGatewayAddr();
134
135    /**
136     * Tells the underlying networking system that the caller wants to
137     * begin using the named feature. The interpretation of {@code feature}
138     * is completely up to each networking implementation.
139     * @param feature the name of the feature to be used
140     * @param callingPid the process ID of the process that is issuing this request
141     * @param callingUid the user ID of the process that is issuing this request
142     * @return an integer value representing the outcome of the request.
143     * The interpretation of this value is specific to each networking
144     * implementation+feature combination, except that the value {@code -1}
145     * always indicates failure.
146     */
147    public int startUsingNetworkFeature(String feature, int callingPid, int callingUid);
148
149    /**
150     * Tells the underlying networking system that the caller is finished
151     * using the named feature. The interpretation of {@code feature}
152     * is completely up to each networking implementation.
153     * @param feature the name of the feature that is no longer needed.
154     * @param callingPid the process ID of the process that is issuing this request
155     * @param callingUid the user ID of the process that is issuing this request
156     * @return an integer value representing the outcome of the request.
157     * The interpretation of this value is specific to each networking
158     * implementation+feature combination, except that the value {@code -1}
159     * always indicates failure.
160     */
161    public int stopUsingNetworkFeature(String feature, int callingPid, int callingUid);
162
163    /**
164     * -------------------------------------------------------------
165     * Storage API used by ConnectivityService for saving
166     * Network specific information.
167     * -------------------------------------------------------------
168     */
169
170    /**
171     * Check if private DNS route is set for the network
172     */
173    public boolean isPrivateDnsRouteSet();
174
175    /**
176     * Set a flag indicating private DNS route is set
177     */
178    public void privateDnsRouteSet(boolean enabled);
179
180    /**
181     * Check if default route is set
182     */
183    public boolean isDefaultRouteSet();
184
185    /**
186     * Set a flag indicating default route is set for the network
187     */
188    public void defaultRouteSet(boolean enabled);
189
190    /**
191     * Check if tear down was requested
192     */
193    public boolean isTeardownRequested();
194
195    /**
196     * Indicate tear down requested from connectivity
197     */
198    public void setTeardownRequested(boolean isRequested);
199
200}
201