diff options
-rw-r--r-- | core/java/android/net/ConnectivityManager.java | 5 | ||||
-rw-r--r-- | core/java/android/net/DummyDataStateTracker.java | 219 | ||||
-rw-r--r-- | services/java/com/android/server/ConnectivityService.java | 6 |
3 files changed, 229 insertions, 1 deletions
diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java index ecfa2c1..3d685cb 100644 --- a/core/java/android/net/ConnectivityManager.java +++ b/core/java/android/net/ConnectivityManager.java @@ -212,10 +212,13 @@ public class ConnectivityManager * default connections. */ public static final int TYPE_WIMAX = 6; + + /** {@hide} */ + public static final int TYPE_DUMMY = 7; /** {@hide} TODO: Need to adjust this for WiMAX. */ public static final int MAX_RADIO_TYPE = TYPE_WIFI; /** {@hide} TODO: Need to adjust this for WiMAX. */ - public static final int MAX_NETWORK_TYPE = TYPE_MOBILE_HIPRI; + public static final int MAX_NETWORK_TYPE = TYPE_DUMMY; public static final int DEFAULT_NETWORK_PREFERENCE = TYPE_WIFI; diff --git a/core/java/android/net/DummyDataStateTracker.java b/core/java/android/net/DummyDataStateTracker.java new file mode 100644 index 0000000..a759865 --- /dev/null +++ b/core/java/android/net/DummyDataStateTracker.java @@ -0,0 +1,219 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.net; + +import android.content.Context; +import android.os.Handler; +import android.os.Message; +import android.net.NetworkInfo.DetailedState; +import android.net.NetworkInfo; +import android.net.LinkProperties; +import android.util.Slog; + +/** + * A dummy data state tracker for use when we don't have a real radio + * connection. useful when bringing up a board or when you have network + * access through other means. + * + * {@hide} + */ +public class DummyDataStateTracker implements NetworkStateTracker { + + private static final String TAG = "DummyDataStateTracker"; + private static final boolean DBG = true; + private static final boolean VDBG = false; + + private NetworkInfo mNetworkInfo; + private boolean mTeardownRequested = false; + private Handler mTarget; + private Context mContext; + private LinkProperties mLinkProperties; + private LinkCapabilities mLinkCapabilities; + private boolean mPrivateDnsRouteSet = false; + private boolean mDefaultRouteSet = false; + + // DEFAULT and HIPRI are the same connection. If we're one of these we need to check if + // the other is also disconnected before we reset sockets + private boolean mIsDefaultOrHipri = false; + + /** + * Create a new DummyDataStateTracker + * @param netType the ConnectivityManager network type + * @param tag the name of this network + */ + public DummyDataStateTracker(int netType, String tag) { + mNetworkInfo = new NetworkInfo(netType); + } + + /** + * Begin monitoring data connectivity. + * + * @param context is the current Android context + * @param target is the Handler to which to return the events. + */ + public void startMonitoring(Context context, Handler target) { + mTarget = target; + mContext = context; + } + + /** + * Return the IP addresses of the DNS servers available for the mobile data + * network interface. + * @return a list of DNS addresses, with no holes. + */ + public String[] getDnsPropNames() { + return new String[0]; + } + + public boolean isPrivateDnsRouteSet() { + return mPrivateDnsRouteSet; + } + + public void privateDnsRouteSet(boolean enabled) { + mPrivateDnsRouteSet = enabled; + } + + public NetworkInfo getNetworkInfo() { + return mNetworkInfo; + } + + public int getDefaultGatewayAddr() { + return 0; + } + + public boolean isDefaultRouteSet() { + return mDefaultRouteSet; + } + + public void defaultRouteSet(boolean enabled) { + mDefaultRouteSet = enabled; + } + + /** + * This is not implemented. + */ + public void releaseWakeLock() { + } + + /** + * Report whether data connectivity is possible. + */ + public boolean isAvailable() { + return true; + } + + /** + * Return the system properties name associated with the tcp buffer sizes + * for this network. + */ + public String getTcpBufferSizesPropName() { + return "net.tcp.buffersize.unknown"; + } + + /** + * Tear down mobile data connectivity, i.e., disable the ability to create + * mobile data connections. + * TODO - make async and return nothing? + */ + public boolean teardown() { + setDetailedState(NetworkInfo.DetailedState.DISCONNECTING, "disabled", null); + setDetailedState(NetworkInfo.DetailedState.DISCONNECTED, "disabled", null); + return true; + } + + /** + * Record the detailed state of a network, and if it is a + * change from the previous state, send a notification to + * any listeners. + * @param state the new @{code DetailedState} + * @param reason a {@code String} indicating a reason for the state change, + * if one was supplied. May be {@code null}. + * @param extraInfo optional {@code String} providing extra information about the state change + */ + private void setDetailedState(NetworkInfo.DetailedState state, String reason, + String extraInfo) { + if (DBG) log("setDetailed state, old =" + + mNetworkInfo.getDetailedState() + " and new state=" + state); + mNetworkInfo.setDetailedState(state, reason, extraInfo); + Message msg = mTarget.obtainMessage(EVENT_STATE_CHANGED, mNetworkInfo); + msg.sendToTarget(); + } + + public void setTeardownRequested(boolean isRequested) { + mTeardownRequested = isRequested; + } + + public boolean isTeardownRequested() { + return mTeardownRequested; + } + + /** + * Re-enable mobile data connectivity after a {@link #teardown()}. + * TODO - make async and always get a notification? + */ + public boolean reconnect() { + setDetailedState(NetworkInfo.DetailedState.CONNECTING, "enabled", null); + setDetailedState(NetworkInfo.DetailedState.CONNECTED, "enabled", null); + setTeardownRequested(false); + return true; + } + + /** + * Turn on or off the mobile radio. No connectivity will be possible while the + * radio is off. The operation is a no-op if the radio is already in the desired state. + * @param turnOn {@code true} if the radio should be turned on, {@code false} if + */ + public boolean setRadio(boolean turnOn) { + return true; + } + + public int startUsingNetworkFeature(String feature, int callingPid, int callingUid) { + return -1; + } + + public int stopUsingNetworkFeature(String feature, int callingPid, int callingUid) { + return -1; + } + + @Override + public String toString() { + StringBuffer sb = new StringBuffer("Dummy data state: none, dummy!"); + return sb.toString(); + } + + /** + * @see android.net.NetworkStateTracker#getLinkProperties() + */ + public LinkProperties getLinkProperties() { + return new LinkProperties(mLinkProperties); + } + + /** + * @see android.net.NetworkStateTracker#getLinkCapabilities() + */ + public LinkCapabilities getLinkCapabilities() { + return new LinkCapabilities(mLinkCapabilities); + } + + static private void log(String s) { + Slog.d(TAG, s); + } + + static private void loge(String s) { + Slog.e(TAG, s); + } +} diff --git a/services/java/com/android/server/ConnectivityService.java b/services/java/com/android/server/ConnectivityService.java index f1fce3e..758f9f3 100644 --- a/services/java/com/android/server/ConnectivityService.java +++ b/services/java/com/android/server/ConnectivityService.java @@ -24,6 +24,7 @@ import android.content.Intent; import android.content.pm.PackageManager; import android.database.ContentObserver; import android.net.ConnectivityManager; +import android.net.DummyDataStateTracker; import android.net.IConnectivityManager; import android.net.MobileDataStateTracker; import android.net.NetworkInfo; @@ -411,6 +412,11 @@ public class ConnectivityService extends IConnectivityManager.Stub { mNetTrackers[netType].teardown(); } break; + case ConnectivityManager.TYPE_DUMMY: + mNetTrackers[netType] = new DummyDataStateTracker(netType, + mNetAttributes[netType].mName); + mNetTrackers[netType].startMonitoring(context, mHandler); + break; default: loge("Trying to create a DataStateTracker for an unknown radio type " + mNetAttributes[netType].mRadio); |