NetworkStateTracker.java revision 1968256926a13e8d809256f652073b0532199fd1
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 * msg.what = EVENT_NETWORK_SUBTYPE_CHANGED 73 * msg.obj = NetworkInfo object 74 */ 75 public static final int EVENT_NETWORK_SUBTYPE_CHANGED = 7; 76 77 /** 78 * ------------------------------------------------------------- 79 * Control Interface 80 * ------------------------------------------------------------- 81 */ 82 /** 83 * Begin monitoring data connectivity. 84 * 85 * This is the first method called when this interface is used. 86 * 87 * @param context is the current Android context 88 * @param target is the Hander to which to return the events. 89 */ 90 public void startMonitoring(Context context, Handler target); 91 92 /** 93 * Fetch NetworkInfo for the network 94 */ 95 public NetworkInfo getNetworkInfo(); 96 97 /** 98 * Return the LinkProperties for the connection. 99 * 100 * @return a copy of the LinkProperties, is never null. 101 */ 102 public LinkProperties getLinkProperties(); 103 104 /** 105 * A capability is an Integer/String pair, the capabilities 106 * are defined in the class LinkSocket#Key. 107 * 108 * @return a copy of this connections capabilities, may be empty but never null. 109 */ 110 public LinkCapabilities getLinkCapabilities(); 111 112 /** 113 * Return the system properties name associated with the tcp buffer sizes 114 * for this network. 115 */ 116 public String getTcpBufferSizesPropName(); 117 118 /** 119 * Disable connectivity to a network 120 * @return {@code true} if a teardown occurred, {@code false} if the 121 * teardown did not occur. 122 */ 123 public boolean teardown(); 124 125 /** 126 * Reenable connectivity to a network after a {@link #teardown()}. 127 * @return {@code true} if we're connected or expect to be connected 128 */ 129 public boolean reconnect(); 130 131 /** 132 * Turn the wireless radio off for a network. 133 * @param turnOn {@code true} to turn the radio on, {@code false} 134 */ 135 public boolean setRadio(boolean turnOn); 136 137 /** 138 * Returns an indication of whether this network is available for 139 * connections. A value of {@code false} means that some quasi-permanent 140 * condition prevents connectivity to this network. 141 * 142 * NOTE that this is broken on multi-connection devices. Should be fixed in J release 143 * TODO - fix on multi-pdp devices 144 */ 145 public boolean isAvailable(); 146 147 /** 148 * User control of data connection through this network, typically persisted 149 * internally. 150 */ 151 public void setUserDataEnable(boolean enabled); 152 153 /** 154 * Policy control of data connection through this network, typically not 155 * persisted internally. Usually used when {@link NetworkPolicy#limitBytes} 156 * is passed. 157 */ 158 public void setPolicyDataEnable(boolean enabled); 159 160 /** 161 * ------------------------------------------------------------- 162 * Storage API used by ConnectivityService for saving 163 * Network specific information. 164 * ------------------------------------------------------------- 165 */ 166 167 /** 168 * Check if private DNS route is set for the network 169 */ 170 public boolean isPrivateDnsRouteSet(); 171 172 /** 173 * Set a flag indicating private DNS route is set 174 */ 175 public void privateDnsRouteSet(boolean enabled); 176 177 /** 178 * Check if default route is set 179 */ 180 public boolean isDefaultRouteSet(); 181 182 /** 183 * Set a flag indicating default route is set for the network 184 */ 185 public void defaultRouteSet(boolean enabled); 186 187 /** 188 * Check if tear down was requested 189 */ 190 public boolean isTeardownRequested(); 191 192 /** 193 * Indicate tear down requested from connectivity 194 */ 195 public void setTeardownRequested(boolean isRequested); 196 197 /** 198 * An external dependency has been met/unmet 199 */ 200 public void setDependencyMet(boolean met); 201} 202