NetworkStateTracker.java revision da6da0907b28d4704aabbdb1bbeb4300954670d1
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 * msg.what = EVENT_NETWORK_SUBTYPE_CHANGED 67 * msg.obj = NetworkInfo object 68 */ 69 public static final int EVENT_NETWORK_SUBTYPE_CHANGED = 7; 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 * Ready to switch on to the network after captive portal check 127 */ 128 public void captivePortalCheckComplete(); 129 130 /** 131 * Turn the wireless radio off for a network. 132 * @param turnOn {@code true} to turn the radio on, {@code false} 133 */ 134 public boolean setRadio(boolean turnOn); 135 136 /** 137 * Returns an indication of whether this network is available for 138 * connections. A value of {@code false} means that some quasi-permanent 139 * condition prevents connectivity to this network. 140 * 141 * NOTE that this is broken on multi-connection devices. Should be fixed in J release 142 * TODO - fix on multi-pdp devices 143 */ 144 public boolean isAvailable(); 145 146 /** 147 * User control of data connection through this network, typically persisted 148 * internally. 149 */ 150 public void setUserDataEnable(boolean enabled); 151 152 /** 153 * Policy control of data connection through this network, typically not 154 * persisted internally. Usually used when {@link NetworkPolicy#limitBytes} 155 * is passed. 156 */ 157 public void setPolicyDataEnable(boolean enabled); 158 159 /** 160 * ------------------------------------------------------------- 161 * Storage API used by ConnectivityService for saving 162 * Network specific information. 163 * ------------------------------------------------------------- 164 */ 165 166 /** 167 * Check if private DNS route is set for the network 168 */ 169 public boolean isPrivateDnsRouteSet(); 170 171 /** 172 * Set a flag indicating private DNS route is set 173 */ 174 public void privateDnsRouteSet(boolean enabled); 175 176 /** 177 * Check if default route is set 178 */ 179 public boolean isDefaultRouteSet(); 180 181 /** 182 * Set a flag indicating default route is set for the network 183 */ 184 public void defaultRouteSet(boolean enabled); 185 186 /** 187 * Check if tear down was requested 188 */ 189 public boolean isTeardownRequested(); 190 191 /** 192 * Indicate tear down requested from connectivity 193 */ 194 public void setTeardownRequested(boolean isRequested); 195 196 /** 197 * An external dependency has been met/unmet 198 */ 199 public void setDependencyMet(boolean met); 200} 201