The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
Wink Saville | c7a9834 | 2010-08-13 16:11:42 -0700 | [diff] [blame] | 19 | import android.content.Context; |
| 20 | import android.os.Handler; |
Robert Greenwalt | 665e1ae | 2012-08-21 19:27:00 -0700 | [diff] [blame] | 21 | import android.os.Messenger; |
| 22 | |
| 23 | import static com.android.internal.util.Protocol.BASE_NETWORK_STATE_TRACKER; |
Wink Saville | c7a9834 | 2010-08-13 16:11:42 -0700 | [diff] [blame] | 24 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | /** |
Wink Saville | c7a9834 | 2010-08-13 16:11:42 -0700 | [diff] [blame] | 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. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | * |
| 34 | * {@hide} |
| 35 | */ |
Irfan Sheriff | d649c12 | 2010-06-09 15:39:36 -0700 | [diff] [blame] | 36 | public interface NetworkStateTracker { |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 37 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | /** |
Wink Saville | c7a9834 | 2010-08-13 16:11:42 -0700 | [diff] [blame] | 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 | * ------------------------------------------------------------- |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | */ |
Wink Saville | c7a9834 | 2010-08-13 16:11:42 -0700 | [diff] [blame] | 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 | */ |
Robert Greenwalt | 665e1ae | 2012-08-21 19:27:00 -0700 | [diff] [blame] | 54 | public static final int EVENT_STATE_CHANGED = BASE_NETWORK_STATE_TRACKER; |
Wink Saville | c7a9834 | 2010-08-13 16:11:42 -0700 | [diff] [blame] | 55 | |
| 56 | /** |
| 57 | * msg.what = EVENT_CONFIGURATION_CHANGED |
| 58 | * msg.obj = NetworkInfo object |
| 59 | */ |
Robert Greenwalt | 665e1ae | 2012-08-21 19:27:00 -0700 | [diff] [blame] | 60 | public static final int EVENT_CONFIGURATION_CHANGED = BASE_NETWORK_STATE_TRACKER + 1; |
Wink Saville | c7a9834 | 2010-08-13 16:11:42 -0700 | [diff] [blame] | 61 | |
| 62 | /** |
| 63 | * msg.what = EVENT_RESTORE_DEFAULT_NETWORK |
| 64 | * msg.obj = FeatureUser object |
| 65 | */ |
Robert Greenwalt | 665e1ae | 2012-08-21 19:27:00 -0700 | [diff] [blame] | 66 | public static final int EVENT_RESTORE_DEFAULT_NETWORK = BASE_NETWORK_STATE_TRACKER + 2; |
Wink Saville | c7a9834 | 2010-08-13 16:11:42 -0700 | [diff] [blame] | 67 | |
| 68 | /** |
Robert Greenwalt | d14e176 | 2012-08-20 11:15:39 -0700 | [diff] [blame] | 69 | * msg.what = EVENT_NETWORK_SUBTYPE_CHANGED |
| 70 | * msg.obj = NetworkInfo object |
| 71 | */ |
Robert Greenwalt | 665e1ae | 2012-08-21 19:27:00 -0700 | [diff] [blame] | 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 | |
Robert Greenwalt | d14e176 | 2012-08-20 11:15:39 -0700 | [diff] [blame] | 86 | /** |
Wink Saville | c7a9834 | 2010-08-13 16:11:42 -0700 | [diff] [blame] | 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 | */ |
| 99 | public void startMonitoring(Context context, Handler target); |
| 100 | |
| 101 | /** |
Irfan Sheriff | d649c12 | 2010-06-09 15:39:36 -0700 | [diff] [blame] | 102 | * Fetch NetworkInfo for the network |
| 103 | */ |
| 104 | public NetworkInfo getNetworkInfo(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 105 | |
| 106 | /** |
Wink Saville | f61101f | 2010-09-16 16:36:42 -0700 | [diff] [blame] | 107 | * Return the LinkProperties for the connection. |
| 108 | * |
| 109 | * @return a copy of the LinkProperties, is never null. |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 110 | */ |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 111 | public LinkProperties getLinkProperties(); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 112 | |
| 113 | /** |
Wink Saville | f61101f | 2010-09-16 16:36:42 -0700 | [diff] [blame] | 114 | * A capability is an Integer/String pair, the capabilities |
| 115 | * are defined in the class LinkSocket#Key. |
| 116 | * |
| 117 | * @return a copy of this connections capabilities, may be empty but never null. |
| 118 | */ |
| 119 | public LinkCapabilities getLinkCapabilities(); |
| 120 | |
| 121 | /** |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 122 | * Get interesting information about this network link |
| 123 | * @return a copy of link information, null if not available |
| 124 | */ |
Vinit Deshapnde | 6a2d325 | 2013-09-04 14:11:24 -0700 | [diff] [blame] | 125 | public LinkQualityInfo getLinkQualityInfo(); |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 126 | |
| 127 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 128 | * Return the system properties name associated with the tcp buffer sizes |
| 129 | * for this network. |
| 130 | */ |
Irfan Sheriff | d649c12 | 2010-06-09 15:39:36 -0700 | [diff] [blame] | 131 | public String getTcpBufferSizesPropName(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 132 | |
| 133 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 134 | * Disable connectivity to a network |
| 135 | * @return {@code true} if a teardown occurred, {@code false} if the |
| 136 | * teardown did not occur. |
| 137 | */ |
Irfan Sheriff | d649c12 | 2010-06-09 15:39:36 -0700 | [diff] [blame] | 138 | public boolean teardown(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 139 | |
| 140 | /** |
| 141 | * Reenable connectivity to a network after a {@link #teardown()}. |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 142 | * @return {@code true} if we're connected or expect to be connected |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 143 | */ |
Irfan Sheriff | d649c12 | 2010-06-09 15:39:36 -0700 | [diff] [blame] | 144 | public boolean reconnect(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | |
| 146 | /** |
Irfan Sheriff | da6da09 | 2012-08-16 12:49:23 -0700 | [diff] [blame] | 147 | * Ready to switch on to the network after captive portal check |
| 148 | */ |
| 149 | public void captivePortalCheckComplete(); |
| 150 | |
| 151 | /** |
Wink Saville | d747cbc | 2013-08-07 16:22:47 -0700 | [diff] [blame] | 152 | * Captive portal check has completed |
| 153 | */ |
| 154 | public void captivePortalCheckCompleted(boolean isCaptive); |
| 155 | |
| 156 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 157 | * Turn the wireless radio off for a network. |
| 158 | * @param turnOn {@code true} to turn the radio on, {@code false} |
| 159 | */ |
Irfan Sheriff | d649c12 | 2010-06-09 15:39:36 -0700 | [diff] [blame] | 160 | public boolean setRadio(boolean turnOn); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 161 | |
| 162 | /** |
| 163 | * Returns an indication of whether this network is available for |
| 164 | * connections. A value of {@code false} means that some quasi-permanent |
| 165 | * condition prevents connectivity to this network. |
Robert Greenwalt | 12e24ae | 2011-10-17 22:10:03 -0700 | [diff] [blame] | 166 | * |
| 167 | * NOTE that this is broken on multi-connection devices. Should be fixed in J release |
| 168 | * TODO - fix on multi-pdp devices |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 169 | */ |
Irfan Sheriff | d649c12 | 2010-06-09 15:39:36 -0700 | [diff] [blame] | 170 | public boolean isAvailable(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 171 | |
| 172 | /** |
Jeff Sharkey | 8e28b7d | 2011-08-19 02:24:24 -0700 | [diff] [blame] | 173 | * User control of data connection through this network, typically persisted |
| 174 | * internally. |
Wink Saville | e798268 | 2010-12-07 10:31:02 -0800 | [diff] [blame] | 175 | */ |
Jeff Sharkey | 8e28b7d | 2011-08-19 02:24:24 -0700 | [diff] [blame] | 176 | public void setUserDataEnable(boolean enabled); |
| 177 | |
| 178 | /** |
| 179 | * Policy control of data connection through this network, typically not |
| 180 | * persisted internally. Usually used when {@link NetworkPolicy#limitBytes} |
| 181 | * is passed. |
| 182 | */ |
| 183 | public void setPolicyDataEnable(boolean enabled); |
Wink Saville | e798268 | 2010-12-07 10:31:02 -0800 | [diff] [blame] | 184 | |
| 185 | /** |
Wink Saville | c7a9834 | 2010-08-13 16:11:42 -0700 | [diff] [blame] | 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); |
Robert Greenwalt | d55a6b4 | 2011-03-25 13:09:25 -0700 | [diff] [blame] | 221 | |
| 222 | /** |
| 223 | * An external dependency has been met/unmet |
| 224 | */ |
| 225 | public void setDependencyMet(boolean met); |
Lorenzo Colitti | 69edd64 | 2013-03-07 11:01:12 -0800 | [diff] [blame] | 226 | |
| 227 | /** |
| 228 | * Informs the state tracker that another interface is stacked on top of it. |
| 229 | **/ |
| 230 | public void addStackedLink(LinkProperties link); |
| 231 | |
| 232 | /** |
| 233 | * Informs the state tracker that a stacked interface has been removed. |
| 234 | **/ |
| 235 | public void removeStackedLink(LinkProperties link); |
Robert Greenwalt | 665e1ae | 2012-08-21 19:27:00 -0700 | [diff] [blame] | 236 | |
| 237 | /* |
| 238 | * Called once to setup async channel between this and |
| 239 | * the underlying network specific code. |
| 240 | */ |
| 241 | public void supplyMessenger(Messenger messenger); |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 242 | |
| 243 | /* |
| 244 | * Network interface name that we'll lookup for sampling data |
| 245 | */ |
| 246 | public String getNetworkInterfaceName(); |
| 247 | |
| 248 | /* |
| 249 | * Save the starting sample |
| 250 | */ |
| 251 | public void startSampling(SamplingDataTracker.SamplingSnapshot s); |
| 252 | |
| 253 | /* |
| 254 | * Save the ending sample |
| 255 | */ |
| 256 | public void stopSampling(SamplingDataTracker.SamplingSnapshot s); |
| 257 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 258 | } |