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.net.NetworkInfo.DetailedState;
23 import android.net.NetworkInfo;
24 import android.net.LinkProperties;
25 import android.util.Slog;
28 * A dummy data state tracker for use when we don't have a real radio
29 * connection. useful when bringing up a board or when you have network
30 * access through other means.
34 public class DummyDataStateTracker implements NetworkStateTracker {
36 private static final String TAG = "DummyDataStateTracker";
37 private static final boolean DBG = true;
38 private static final boolean VDBG = false;
40 private NetworkInfo mNetworkInfo;
41 private boolean mTeardownRequested = false;
42 private Handler mTarget;
43 private Context mContext;
44 private LinkProperties mLinkProperties;
45 private LinkCapabilities mLinkCapabilities;
46 private boolean mPrivateDnsRouteSet = false;
47 private boolean mDefaultRouteSet = false;
49 // DEFAULT and HIPRI are the same connection. If we're one of these we need to check if
50 // the other is also disconnected before we reset sockets
51 private boolean mIsDefaultOrHipri = false;
54 * Create a new DummyDataStateTracker
55 * @param netType the ConnectivityManager network type
56 * @param tag the name of this network
58 public DummyDataStateTracker(int netType, String tag) {
59 mNetworkInfo = new NetworkInfo(netType);
63 * Begin monitoring data connectivity.
65 * @param context is the current Android context
66 * @param target is the Handler to which to return the events.
68 public void startMonitoring(Context context, Handler target) {
73 public boolean isPrivateDnsRouteSet() {
74 return mPrivateDnsRouteSet;
77 public void privateDnsRouteSet(boolean enabled) {
78 mPrivateDnsRouteSet = enabled;
81 public NetworkInfo getNetworkInfo() {
85 public boolean isDefaultRouteSet() {
86 return mDefaultRouteSet;
89 public void defaultRouteSet(boolean enabled) {
90 mDefaultRouteSet = enabled;
94 * This is not implemented.
96 public void releaseWakeLock() {
100 * Report whether data connectivity is possible.
102 public boolean isAvailable() {
107 * Return the system properties name associated with the tcp buffer sizes
110 public String getTcpBufferSizesPropName() {
111 return "net.tcp.buffersize.unknown";
115 * Tear down mobile data connectivity, i.e., disable the ability to create
116 * mobile data connections.
117 * TODO - make async and return nothing?
119 public boolean teardown() {
120 setDetailedState(NetworkInfo.DetailedState.DISCONNECTING, "disabled", null);
121 setDetailedState(NetworkInfo.DetailedState.DISCONNECTED, "disabled", null);
126 * Record the detailed state of a network, and if it is a
127 * change from the previous state, send a notification to
129 * @param state the new @{code DetailedState}
130 * @param reason a {@code String} indicating a reason for the state change,
131 * if one was supplied. May be {@code null}.
132 * @param extraInfo optional {@code String} providing extra information about the state change
134 private void setDetailedState(NetworkInfo.DetailedState state, String reason,
136 if (DBG) log("setDetailed state, old ="
137 + mNetworkInfo.getDetailedState() + " and new state=" + state);
138 mNetworkInfo.setDetailedState(state, reason, extraInfo);
139 Message msg = mTarget.obtainMessage(EVENT_STATE_CHANGED, mNetworkInfo);
143 public void setTeardownRequested(boolean isRequested) {
144 mTeardownRequested = isRequested;
147 public boolean isTeardownRequested() {
148 return mTeardownRequested;
152 * Re-enable mobile data connectivity after a {@link #teardown()}.
153 * TODO - make async and always get a notification?
155 public boolean reconnect() {
156 setDetailedState(NetworkInfo.DetailedState.CONNECTING, "enabled", null);
157 setDetailedState(NetworkInfo.DetailedState.CONNECTED, "enabled", null);
158 setTeardownRequested(false);
163 * Turn on or off the mobile radio. No connectivity will be possible while the
164 * radio is off. The operation is a no-op if the radio is already in the desired state.
165 * @param turnOn {@code true} if the radio should be turned on, {@code false} if
167 public boolean setRadio(boolean turnOn) {
171 public void setDataEnable(boolean enabled) {
175 public String toString() {
176 StringBuffer sb = new StringBuffer("Dummy data state: none, dummy!");
177 return sb.toString();
181 * @see android.net.NetworkStateTracker#getLinkProperties()
183 public LinkProperties getLinkProperties() {
184 return new LinkProperties(mLinkProperties);
188 * @see android.net.NetworkStateTracker#getLinkCapabilities()
190 public LinkCapabilities getLinkCapabilities() {
191 return new LinkCapabilities(mLinkCapabilities);
194 static private void log(String s) {
198 static private void loge(String s) {