Have MobileDataStateTracker & DataConnectionTracker communicate directly.

Added CMD_SET_DATA_ENABLE which is sent when data is enabled/disabled
via the ConnectivityService. It is anticipated that the communication
channel will be used for additional commands and to receive unsoliciated
commands from DataConnectionTracker back to MobileDataStateTracker.

Change-Id: I3863e7385155d503f069b1dcb7e4f766ec78b5f8
This commit is contained in:
Wink Saville
2010-12-07 10:31:02 -08:00
parent eb123acefc
commit b9024c6009

View File

@@ -387,7 +387,6 @@ public class ConnectivityService extends IConnectivityManager.Stub {
* the number of different network types is not going * the number of different network types is not going
* to change very often. * to change very often.
*/ */
boolean noMobileData = !getMobileDataEnabled();
for (int netType : mPriorityList) { for (int netType : mPriorityList) {
switch (mNetAttributes[netType].mRadio) { switch (mNetAttributes[netType].mRadio) {
case ConnectivityManager.TYPE_WIFI: case ConnectivityManager.TYPE_WIFI:
@@ -407,10 +406,6 @@ public class ConnectivityService extends IConnectivityManager.Stub {
mNetTrackers[netType] = new MobileDataStateTracker(netType, mNetTrackers[netType] = new MobileDataStateTracker(netType,
mNetAttributes[netType].mName); mNetAttributes[netType].mName);
mNetTrackers[netType].startMonitoring(context, mHandler); mNetTrackers[netType].startMonitoring(context, mHandler);
if (noMobileData) {
if (DBG) log("tearing down Mobile networks due to setting");
mNetTrackers[netType].teardown();
}
break; break;
case ConnectivityManager.TYPE_DUMMY: case ConnectivityManager.TYPE_DUMMY:
mNetTrackers[netType] = new DummyDataStateTracker(netType, mNetTrackers[netType] = new DummyDataStateTracker(netType,
@@ -691,10 +686,6 @@ public class ConnectivityService extends IConnectivityManager.Stub {
// TODO - move this into the MobileDataStateTracker // TODO - move this into the MobileDataStateTracker
int usedNetworkType = networkType; int usedNetworkType = networkType;
if(networkType == ConnectivityManager.TYPE_MOBILE) { if(networkType == ConnectivityManager.TYPE_MOBILE) {
if (!getMobileDataEnabled()) {
if (DBG) log("requested special network with data disabled - rejected");
return Phone.APN_TYPE_NOT_AVAILABLE;
}
if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_MMS)) { if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_MMS)) {
usedNetworkType = ConnectivityManager.TYPE_MOBILE_MMS; usedNetworkType = ConnectivityManager.TYPE_MOBILE_MMS;
} else if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_SUPL)) { } else if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_SUPL)) {
@@ -985,6 +976,9 @@ public class ConnectivityService extends IConnectivityManager.Stub {
* @see ConnectivityManager#getMobileDataEnabled() * @see ConnectivityManager#getMobileDataEnabled()
*/ */
public boolean getMobileDataEnabled() { public boolean getMobileDataEnabled() {
// TODO: This detail should probably be in DataConnectionTracker's
// which is where we store the value and maybe make this
// asynchronous.
enforceAccessPermission(); enforceAccessPermission();
boolean retVal = Settings.Secure.getInt(mContext.getContentResolver(), boolean retVal = Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.MOBILE_DATA, 1) == 1; Settings.Secure.MOBILE_DATA, 1) == 1;
@@ -1004,42 +998,14 @@ public class ConnectivityService extends IConnectivityManager.Stub {
} }
private void handleSetMobileData(boolean enabled) { private void handleSetMobileData(boolean enabled) {
if (getMobileDataEnabled() == enabled) return; if (mNetTrackers[ConnectivityManager.TYPE_MOBILE] != null) {
if (DBG) {
Settings.Secure.putInt(mContext.getContentResolver(), Slog.d(TAG, mNetTrackers[ConnectivityManager.TYPE_MOBILE].toString() + enabled);
Settings.Secure.MOBILE_DATA, enabled ? 1 : 0);
if (enabled) {
if (mNetTrackers[ConnectivityManager.TYPE_MOBILE] != null) {
if (DBG) {
log("starting up " + mNetTrackers[ConnectivityManager.TYPE_MOBILE]);
}
mNetTrackers[ConnectivityManager.TYPE_MOBILE].reconnect();
}
} else {
for (NetworkStateTracker nt : mNetTrackers) {
if (nt == null) continue;
int netType = nt.getNetworkInfo().getType();
if (mNetAttributes[netType].mRadio == ConnectivityManager.TYPE_MOBILE) {
if (DBG) log("tearing down " + nt);
nt.teardown();
}
} }
mNetTrackers[ConnectivityManager.TYPE_MOBILE].setDataEnable(enabled);
} }
} }
private int getNumConnectedNetworks() {
int numConnectedNets = 0;
for (NetworkStateTracker nt : mNetTrackers) {
if (nt != null && nt.getNetworkInfo().isConnected() &&
!nt.isTeardownRequested()) {
++numConnectedNets;
}
}
return numConnectedNets;
}
private void enforceAccessPermission() { private void enforceAccessPermission() {
mContext.enforceCallingOrSelfPermission( mContext.enforceCallingOrSelfPermission(
android.Manifest.permission.ACCESS_NETWORK_STATE, android.Manifest.permission.ACCESS_NETWORK_STATE,
@@ -1159,16 +1125,9 @@ public class ConnectivityService extends IConnectivityManager.Stub {
int newType = -1; int newType = -1;
int newPriority = -1; int newPriority = -1;
boolean noMobileData = !getMobileDataEnabled();
for (int checkType=0; checkType <= ConnectivityManager.MAX_NETWORK_TYPE; checkType++) { for (int checkType=0; checkType <= ConnectivityManager.MAX_NETWORK_TYPE; checkType++) {
if (checkType == prevNetType) continue; if (checkType == prevNetType) continue;
if (mNetAttributes[checkType] == null) continue; if (mNetAttributes[checkType] == null) continue;
if (mNetAttributes[checkType].mRadio == ConnectivityManager.TYPE_MOBILE &&
noMobileData) {
loge("not failing over to mobile type " + checkType +
" because Mobile Data Disabled");
continue;
}
if (mNetAttributes[checkType].isDefault()) { if (mNetAttributes[checkType].isDefault()) {
/* TODO - if we have multiple nets we could use /* TODO - if we have multiple nets we could use
* we may want to put more thought into which we choose * we may want to put more thought into which we choose