Split NST handler events away from CS internals.
Instead of sharing event space, use a different handler backed by the same looper. Change-Id: I11f1e4701c341665770ca640f3cba0c295bb7561
This commit is contained in:
@@ -188,95 +188,81 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
private static final boolean TO_DEFAULT_TABLE = true;
|
private static final boolean TO_DEFAULT_TABLE = true;
|
||||||
private static final boolean TO_SECONDARY_TABLE = false;
|
private static final boolean TO_SECONDARY_TABLE = false;
|
||||||
|
|
||||||
// Share the event space with NetworkStateTracker (which can't see this
|
|
||||||
// internal class but sends us events). If you change these, change
|
|
||||||
// NetworkStateTracker.java too.
|
|
||||||
private static final int MIN_NETWORK_STATE_TRACKER_EVENT = 1;
|
|
||||||
private static final int MAX_NETWORK_STATE_TRACKER_EVENT = 100;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* used internally as a delayed event to make us switch back to the
|
* used internally as a delayed event to make us switch back to the
|
||||||
* default network
|
* default network
|
||||||
*/
|
*/
|
||||||
private static final int EVENT_RESTORE_DEFAULT_NETWORK =
|
private static final int EVENT_RESTORE_DEFAULT_NETWORK = 1;
|
||||||
MAX_NETWORK_STATE_TRACKER_EVENT + 1;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* used internally to change our mobile data enabled flag
|
* used internally to change our mobile data enabled flag
|
||||||
*/
|
*/
|
||||||
private static final int EVENT_CHANGE_MOBILE_DATA_ENABLED =
|
private static final int EVENT_CHANGE_MOBILE_DATA_ENABLED = 2;
|
||||||
MAX_NETWORK_STATE_TRACKER_EVENT + 2;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* used internally to change our network preference setting
|
* used internally to change our network preference setting
|
||||||
* arg1 = networkType to prefer
|
* arg1 = networkType to prefer
|
||||||
*/
|
*/
|
||||||
private static final int EVENT_SET_NETWORK_PREFERENCE =
|
private static final int EVENT_SET_NETWORK_PREFERENCE = 3;
|
||||||
MAX_NETWORK_STATE_TRACKER_EVENT + 3;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* used internally to synchronize inet condition reports
|
* used internally to synchronize inet condition reports
|
||||||
* arg1 = networkType
|
* arg1 = networkType
|
||||||
* arg2 = condition (0 bad, 100 good)
|
* arg2 = condition (0 bad, 100 good)
|
||||||
*/
|
*/
|
||||||
private static final int EVENT_INET_CONDITION_CHANGE =
|
private static final int EVENT_INET_CONDITION_CHANGE = 4;
|
||||||
MAX_NETWORK_STATE_TRACKER_EVENT + 4;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* used internally to mark the end of inet condition hold periods
|
* used internally to mark the end of inet condition hold periods
|
||||||
* arg1 = networkType
|
* arg1 = networkType
|
||||||
*/
|
*/
|
||||||
private static final int EVENT_INET_CONDITION_HOLD_END =
|
private static final int EVENT_INET_CONDITION_HOLD_END = 5;
|
||||||
MAX_NETWORK_STATE_TRACKER_EVENT + 5;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* used internally to set enable/disable cellular data
|
* used internally to set enable/disable cellular data
|
||||||
* arg1 = ENBALED or DISABLED
|
* arg1 = ENBALED or DISABLED
|
||||||
*/
|
*/
|
||||||
private static final int EVENT_SET_MOBILE_DATA =
|
private static final int EVENT_SET_MOBILE_DATA = 7;
|
||||||
MAX_NETWORK_STATE_TRACKER_EVENT + 7;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* used internally to clear a wakelock when transitioning
|
* used internally to clear a wakelock when transitioning
|
||||||
* from one net to another
|
* from one net to another
|
||||||
*/
|
*/
|
||||||
private static final int EVENT_CLEAR_NET_TRANSITION_WAKELOCK =
|
private static final int EVENT_CLEAR_NET_TRANSITION_WAKELOCK = 8;
|
||||||
MAX_NETWORK_STATE_TRACKER_EVENT + 8;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* used internally to reload global proxy settings
|
* used internally to reload global proxy settings
|
||||||
*/
|
*/
|
||||||
private static final int EVENT_APPLY_GLOBAL_HTTP_PROXY =
|
private static final int EVENT_APPLY_GLOBAL_HTTP_PROXY = 9;
|
||||||
MAX_NETWORK_STATE_TRACKER_EVENT + 9;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* used internally to set external dependency met/unmet
|
* used internally to set external dependency met/unmet
|
||||||
* arg1 = ENABLED (met) or DISABLED (unmet)
|
* arg1 = ENABLED (met) or DISABLED (unmet)
|
||||||
* arg2 = NetworkType
|
* arg2 = NetworkType
|
||||||
*/
|
*/
|
||||||
private static final int EVENT_SET_DEPENDENCY_MET =
|
private static final int EVENT_SET_DEPENDENCY_MET = 10;
|
||||||
MAX_NETWORK_STATE_TRACKER_EVENT + 10;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* used internally to restore DNS properties back to the
|
* used internally to restore DNS properties back to the
|
||||||
* default network
|
* default network
|
||||||
*/
|
*/
|
||||||
private static final int EVENT_RESTORE_DNS =
|
private static final int EVENT_RESTORE_DNS = 11;
|
||||||
MAX_NETWORK_STATE_TRACKER_EVENT + 11;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* used internally to send a sticky broadcast delayed.
|
* used internally to send a sticky broadcast delayed.
|
||||||
*/
|
*/
|
||||||
private static final int EVENT_SEND_STICKY_BROADCAST_INTENT =
|
private static final int EVENT_SEND_STICKY_BROADCAST_INTENT = 12;
|
||||||
MAX_NETWORK_STATE_TRACKER_EVENT + 12;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used internally to
|
* Used internally to
|
||||||
* {@link NetworkStateTracker#setPolicyDataEnable(boolean)}.
|
* {@link NetworkStateTracker#setPolicyDataEnable(boolean)}.
|
||||||
*/
|
*/
|
||||||
private static final int EVENT_SET_POLICY_DATA_ENABLE = MAX_NETWORK_STATE_TRACKER_EVENT + 13;
|
private static final int EVENT_SET_POLICY_DATA_ENABLE = 13;
|
||||||
|
|
||||||
private Handler mHandler;
|
/** Handler used for internal events. */
|
||||||
|
private InternalHandler mHandler;
|
||||||
|
/** Handler used for incoming {@link NetworkStateTracker} events. */
|
||||||
|
private NetworkStateTrackerHandler mTrackerHandler;
|
||||||
|
|
||||||
// list of DeathRecipients used to make sure features are turned off when
|
// list of DeathRecipients used to make sure features are turned off when
|
||||||
// a process dies
|
// a process dies
|
||||||
@@ -334,7 +320,8 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
|
|
||||||
HandlerThread handlerThread = new HandlerThread("ConnectivityServiceThread");
|
HandlerThread handlerThread = new HandlerThread("ConnectivityServiceThread");
|
||||||
handlerThread.start();
|
handlerThread.start();
|
||||||
mHandler = new MyHandler(handlerThread.getLooper());
|
mHandler = new InternalHandler(handlerThread.getLooper());
|
||||||
|
mTrackerHandler = new NetworkStateTrackerHandler(handlerThread.getLooper());
|
||||||
|
|
||||||
// setup our unique device name
|
// setup our unique device name
|
||||||
if (TextUtils.isEmpty(SystemProperties.get("net.hostname"))) {
|
if (TextUtils.isEmpty(SystemProperties.get("net.hostname"))) {
|
||||||
@@ -484,33 +471,33 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
for (int netType : mPriorityList) {
|
for (int netType : mPriorityList) {
|
||||||
switch (mNetConfigs[netType].radio) {
|
switch (mNetConfigs[netType].radio) {
|
||||||
case ConnectivityManager.TYPE_WIFI:
|
case ConnectivityManager.TYPE_WIFI:
|
||||||
mNetTrackers[netType] = new WifiStateTracker(netType,
|
mNetTrackers[netType] = new WifiStateTracker(
|
||||||
mNetConfigs[netType].name);
|
netType, mNetConfigs[netType].name);
|
||||||
mNetTrackers[netType].startMonitoring(context, mHandler);
|
mNetTrackers[netType].startMonitoring(context, mTrackerHandler);
|
||||||
break;
|
break;
|
||||||
case ConnectivityManager.TYPE_MOBILE:
|
case ConnectivityManager.TYPE_MOBILE:
|
||||||
mNetTrackers[netType] = new MobileDataStateTracker(netType,
|
mNetTrackers[netType] = new MobileDataStateTracker(netType,
|
||||||
mNetConfigs[netType].name);
|
mNetConfigs[netType].name);
|
||||||
mNetTrackers[netType].startMonitoring(context, mHandler);
|
mNetTrackers[netType].startMonitoring(context, mTrackerHandler);
|
||||||
break;
|
break;
|
||||||
case ConnectivityManager.TYPE_DUMMY:
|
case ConnectivityManager.TYPE_DUMMY:
|
||||||
mNetTrackers[netType] = new DummyDataStateTracker(netType,
|
mNetTrackers[netType] = new DummyDataStateTracker(netType,
|
||||||
mNetConfigs[netType].name);
|
mNetConfigs[netType].name);
|
||||||
mNetTrackers[netType].startMonitoring(context, mHandler);
|
mNetTrackers[netType].startMonitoring(context, mTrackerHandler);
|
||||||
break;
|
break;
|
||||||
case ConnectivityManager.TYPE_BLUETOOTH:
|
case ConnectivityManager.TYPE_BLUETOOTH:
|
||||||
mNetTrackers[netType] = BluetoothTetheringDataTracker.getInstance();
|
mNetTrackers[netType] = BluetoothTetheringDataTracker.getInstance();
|
||||||
mNetTrackers[netType].startMonitoring(context, mHandler);
|
mNetTrackers[netType].startMonitoring(context, mTrackerHandler);
|
||||||
break;
|
break;
|
||||||
case ConnectivityManager.TYPE_WIMAX:
|
case ConnectivityManager.TYPE_WIMAX:
|
||||||
mNetTrackers[netType] = makeWimaxStateTracker();
|
mNetTrackers[netType] = makeWimaxStateTracker();
|
||||||
if (mNetTrackers[netType]!= null) {
|
if (mNetTrackers[netType]!= null) {
|
||||||
mNetTrackers[netType].startMonitoring(context, mHandler);
|
mNetTrackers[netType].startMonitoring(context, mTrackerHandler);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ConnectivityManager.TYPE_ETHERNET:
|
case ConnectivityManager.TYPE_ETHERNET:
|
||||||
mNetTrackers[netType] = EthernetDataTracker.getInstance();
|
mNetTrackers[netType] = EthernetDataTracker.getInstance();
|
||||||
mNetTrackers[netType].startMonitoring(context, mHandler);
|
mNetTrackers[netType].startMonitoring(context, mTrackerHandler);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
loge("Trying to create a DataStateTracker for an unknown radio type " +
|
loge("Trying to create a DataStateTracker for an unknown radio type " +
|
||||||
@@ -557,8 +544,9 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
|
|
||||||
loadGlobalProxy();
|
loadGlobalProxy();
|
||||||
}
|
}
|
||||||
private NetworkStateTracker makeWimaxStateTracker() {
|
|
||||||
//Initialize Wimax
|
private NetworkStateTracker makeWimaxStateTracker() {
|
||||||
|
// Initialize Wimax
|
||||||
DexClassLoader wimaxClassLoader;
|
DexClassLoader wimaxClassLoader;
|
||||||
Class wimaxStateTrackerClass = null;
|
Class wimaxStateTrackerClass = null;
|
||||||
Class wimaxServiceClass = null;
|
Class wimaxServiceClass = null;
|
||||||
@@ -611,7 +599,7 @@ private NetworkStateTracker makeWimaxStateTracker() {
|
|||||||
Constructor wmxStTrkrConst = wimaxStateTrackerClass.getConstructor
|
Constructor wmxStTrkrConst = wimaxStateTrackerClass.getConstructor
|
||||||
(new Class[] {Context.class, Handler.class});
|
(new Class[] {Context.class, Handler.class});
|
||||||
wimaxStateTracker = (NetworkStateTracker)wmxStTrkrConst.newInstance(mContext,
|
wimaxStateTracker = (NetworkStateTracker)wmxStTrkrConst.newInstance(mContext,
|
||||||
mHandler);
|
mTrackerHandler);
|
||||||
|
|
||||||
Constructor wmxSrvConst = wimaxServiceClass.getDeclaredConstructor
|
Constructor wmxSrvConst = wimaxServiceClass.getDeclaredConstructor
|
||||||
(new Class[] {Context.class, wimaxStateTrackerClass});
|
(new Class[] {Context.class, wimaxStateTrackerClass});
|
||||||
@@ -632,6 +620,7 @@ private NetworkStateTracker makeWimaxStateTracker() {
|
|||||||
|
|
||||||
return wimaxStateTracker;
|
return wimaxStateTracker;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the preferred network.
|
* Sets the preferred network.
|
||||||
* @param preference the new preference
|
* @param preference the new preference
|
||||||
@@ -639,7 +628,8 @@ private NetworkStateTracker makeWimaxStateTracker() {
|
|||||||
public void setNetworkPreference(int preference) {
|
public void setNetworkPreference(int preference) {
|
||||||
enforceChangePermission();
|
enforceChangePermission();
|
||||||
|
|
||||||
mHandler.sendMessage(mHandler.obtainMessage(EVENT_SET_NETWORK_PREFERENCE, preference, 0));
|
mHandler.sendMessage(
|
||||||
|
mHandler.obtainMessage(EVENT_SET_NETWORK_PREFERENCE, preference, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getNetworkPreference() {
|
public int getNetworkPreference() {
|
||||||
@@ -2460,8 +2450,8 @@ private NetworkStateTracker makeWimaxStateTracker() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// must be stateless - things change under us.
|
// must be stateless - things change under us.
|
||||||
private class MyHandler extends Handler {
|
private class NetworkStateTrackerHandler extends Handler {
|
||||||
public MyHandler(Looper looper) {
|
public NetworkStateTrackerHandler(Looper looper) {
|
||||||
super(looper);
|
super(looper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2519,6 +2509,19 @@ private NetworkStateTracker makeWimaxStateTracker() {
|
|||||||
// @see bug/4455071
|
// @see bug/4455071
|
||||||
handleConnectivityChange(info.getType(), false);
|
handleConnectivityChange(info.getType(), false);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class InternalHandler extends Handler {
|
||||||
|
public InternalHandler(Looper looper) {
|
||||||
|
super(looper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleMessage(Message msg) {
|
||||||
|
NetworkInfo info;
|
||||||
|
switch (msg.what) {
|
||||||
case EVENT_CLEAR_NET_TRANSITION_WAKELOCK:
|
case EVENT_CLEAR_NET_TRANSITION_WAKELOCK:
|
||||||
String causedBy = null;
|
String causedBy = null;
|
||||||
synchronized (ConnectivityService.this) {
|
synchronized (ConnectivityService.this) {
|
||||||
|
|||||||
Reference in New Issue
Block a user