2 * Copyright (C) 2010 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 import android.content.Context;
20 import android.os.Handler;
21 import android.os.Message;
22 import android.os.Messenger;
23 import android.util.Slog;
26 * A dummy data state tracker for use when we don't have a real radio
27 * connection. useful when bringing up a board or when you have network
28 * access through other means.
32 public class DummyDataStateTracker implements NetworkStateTracker {
34 private static final String TAG = "DummyDataStateTracker";
35 private static final boolean DBG = true;
36 private static final boolean VDBG = false;
38 private NetworkInfo mNetworkInfo;
39 private boolean mTeardownRequested = false;
40 private Handler mTarget;
41 private Context mContext;
42 private LinkProperties mLinkProperties;
43 private LinkCapabilities mLinkCapabilities;
44 private boolean mPrivateDnsRouteSet = false;
45 private boolean mDefaultRouteSet = false;
47 // DEFAULT and HIPRI are the same connection. If we're one of these we need to check if
48 // the other is also disconnected before we reset sockets
49 private boolean mIsDefaultOrHipri = false;
52 * Create a new DummyDataStateTracker
53 * @param netType the ConnectivityManager network type
54 * @param tag the name of this network
56 public DummyDataStateTracker(int netType, String tag) {
57 mNetworkInfo = new NetworkInfo(netType);
61 * Begin monitoring data connectivity.
63 * @param context is the current Android context
64 * @param target is the Handler to which to return the events.
66 public void startMonitoring(Context context, Handler target) {
71 public boolean isPrivateDnsRouteSet() {
72 return mPrivateDnsRouteSet;
75 public void privateDnsRouteSet(boolean enabled) {
76 mPrivateDnsRouteSet = enabled;
79 public NetworkInfo getNetworkInfo() {
83 public boolean isDefaultRouteSet() {
84 return mDefaultRouteSet;
87 public void defaultRouteSet(boolean enabled) {
88 mDefaultRouteSet = enabled;
92 * This is not implemented.
94 public void releaseWakeLock() {
98 * Report whether data connectivity is possible.
100 public boolean isAvailable() {
105 * Return the system properties name associated with the tcp buffer sizes
108 public String getTcpBufferSizesPropName() {
109 return "net.tcp.buffersize.unknown";
113 * Tear down mobile data connectivity, i.e., disable the ability to create
114 * mobile data connections.
115 * TODO - make async and return nothing?
117 public boolean teardown() {
118 setDetailedState(NetworkInfo.DetailedState.DISCONNECTING, "disabled", null);
119 setDetailedState(NetworkInfo.DetailedState.DISCONNECTED, "disabled", null);
123 public void captivePortalCheckComplete() {
128 * Record the detailed state of a network, and if it is a
129 * change from the previous state, send a notification to
131 * @param state the new {@code DetailedState}
132 * @param reason a {@code String} indicating a reason for the state change,
133 * if one was supplied. May be {@code null}.
134 * @param extraInfo optional {@code String} providing extra information about the state change
136 private void setDetailedState(NetworkInfo.DetailedState state, String reason,
138 if (DBG) log("setDetailed state, old ="
139 + mNetworkInfo.getDetailedState() + " and new state=" + state);
140 mNetworkInfo.setDetailedState(state, reason, extraInfo);
141 Message msg = mTarget.obtainMessage(EVENT_STATE_CHANGED, mNetworkInfo);
145 public void setTeardownRequested(boolean isRequested) {
146 mTeardownRequested = isRequested;
149 public boolean isTeardownRequested() {
150 return mTeardownRequested;
154 * Re-enable mobile data connectivity after a {@link #teardown()}.
155 * TODO - make async and always get a notification?
157 public boolean reconnect() {
158 setDetailedState(NetworkInfo.DetailedState.CONNECTING, "enabled", null);
159 setDetailedState(NetworkInfo.DetailedState.CONNECTED, "enabled", null);
160 setTeardownRequested(false);
165 * Turn on or off the mobile radio. No connectivity will be possible while the
166 * radio is off. The operation is a no-op if the radio is already in the desired state.
167 * @param turnOn {@code true} if the radio should be turned on, {@code false} if
169 public boolean setRadio(boolean turnOn) {
174 public void setUserDataEnable(boolean enabled) {
179 public void setPolicyDataEnable(boolean enabled) {
184 public String toString() {
185 StringBuffer sb = new StringBuffer("Dummy data state: none, dummy!");
186 return sb.toString();
190 * @see android.net.NetworkStateTracker#getLinkProperties()
192 public LinkProperties getLinkProperties() {
193 return new LinkProperties(mLinkProperties);
197 * @see android.net.NetworkStateTracker#getLinkCapabilities()
199 public LinkCapabilities getLinkCapabilities() {
200 return new LinkCapabilities(mLinkCapabilities);
203 public void setDependencyMet(boolean met) {
204 // not supported on this network
208 public void addStackedLink(LinkProperties link) {
209 mLinkProperties.addStackedLink(link);
213 public void removeStackedLink(LinkProperties link) {
214 mLinkProperties.removeStackedLink(link);
218 public void supplyMessenger(Messenger messenger) {
219 // not supported on this network
222 static private void log(String s) {
226 static private void loge(String s) {