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