NetworkStateTracker.java revision d55a6b498d66d8fc415908ecf63e50f46cce67e8
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    // Share the event space with ConnectivityService (which we can't see, but
45    // must send events to).  If you change these, change ConnectivityService
46    // too.
47    static final int MIN_NETWORK_STATE_TRACKER_EVENT = 1;
48    static final int MAX_NETWORK_STATE_TRACKER_EVENT = 100;
49
50    /**
51     * The network state has changed and the NetworkInfo object
52     * contains the new state.
53     *
54     * msg.what = EVENT_STATE_CHANGED
55     * msg.obj = NetworkInfo object
56     */
57    public static final int EVENT_STATE_CHANGED = 1;
58
59    /**
60     * msg.what = EVENT_CONFIGURATION_CHANGED
61     * msg.obj = NetworkInfo object
62     */
63    public static final int EVENT_CONFIGURATION_CHANGED = 3;
64
65    /**
66     * msg.what = EVENT_RESTORE_DEFAULT_NETWORK
67     * msg.obj = FeatureUser object
68     */
69    public static final int EVENT_RESTORE_DEFAULT_NETWORK = 6;
70
71    /**
72     * -------------------------------------------------------------
73     * Control Interface
74     * -------------------------------------------------------------
75     */
76    /**
77     * Begin monitoring data connectivity.
78     *
79     * This is the first method called when this interface is used.
80     *
81     * @param context is the current Android context
82     * @param target is the Hander to which to return the events.
83     */
84    public void startMonitoring(Context context, Handler target);
85
86    /**
87     * Fetch NetworkInfo for the network
88     */
89    public NetworkInfo getNetworkInfo();
90
91    /**
92     * Return the LinkProperties for the connection.
93     *
94     * @return a copy of the LinkProperties, is never null.
95     */
96    public LinkProperties getLinkProperties();
97
98    /**
99     * A capability is an Integer/String pair, the capabilities
100     * are defined in the class LinkSocket#Key.
101     *
102     * @return a copy of this connections capabilities, may be empty but never null.
103     */
104    public LinkCapabilities getLinkCapabilities();
105
106    /**
107     * Return the system properties name associated with the tcp buffer sizes
108     * for this network.
109     */
110    public String getTcpBufferSizesPropName();
111
112    /**
113     * Disable connectivity to a network
114     * @return {@code true} if a teardown occurred, {@code false} if the
115     * teardown did not occur.
116     */
117    public boolean teardown();
118
119    /**
120     * Reenable connectivity to a network after a {@link #teardown()}.
121     * @return {@code true} if we're connected or expect to be connected
122     */
123    public boolean reconnect();
124
125    /**
126     * Turn the wireless radio off for a network.
127     * @param turnOn {@code true} to turn the radio on, {@code false}
128     */
129    public boolean setRadio(boolean turnOn);
130
131    /**
132     * Returns an indication of whether this network is available for
133     * connections. A value of {@code false} means that some quasi-permanent
134     * condition prevents connectivity to this network.
135     */
136    public boolean isAvailable();
137
138    /**
139     * @param enabled
140     */
141    public void setDataEnable(boolean enabled);
142
143    /**
144     * -------------------------------------------------------------
145     * Storage API used by ConnectivityService for saving
146     * Network specific information.
147     * -------------------------------------------------------------
148     */
149
150    /**
151     * Check if private DNS route is set for the network
152     */
153    public boolean isPrivateDnsRouteSet();
154
155    /**
156     * Set a flag indicating private DNS route is set
157     */
158    public void privateDnsRouteSet(boolean enabled);
159
160    /**
161     * Check if default route is set
162     */
163    public boolean isDefaultRouteSet();
164
165    /**
166     * Set a flag indicating default route is set for the network
167     */
168    public void defaultRouteSet(boolean enabled);
169
170    /**
171     * Check if tear down was requested
172     */
173    public boolean isTeardownRequested();
174
175    /**
176     * Indicate tear down requested from connectivity
177     */
178    public void setTeardownRequested(boolean isRequested);
179
180    /**
181     * An external dependency has been met/unmet
182     */
183    public void setDependencyMet(boolean met);
184}
185