@@ -188,95 +188,81 @@ public class ConnectivityService extends IConnectivityManager.Stub {
188188 private static final boolean TO_DEFAULT_TABLE = true ;
189189 private static final boolean TO_SECONDARY_TABLE = false ;
190190
191- // Share the event space with NetworkStateTracker (which can't see this
192- // internal class but sends us events). If you change these, change
193- // NetworkStateTracker.java too.
194- private static final int MIN_NETWORK_STATE_TRACKER_EVENT = 1 ;
195- private static final int MAX_NETWORK_STATE_TRACKER_EVENT = 100 ;
196-
197191 /**
198192 * used internally as a delayed event to make us switch back to the
199193 * default network
200194 */
201- private static final int EVENT_RESTORE_DEFAULT_NETWORK =
202- MAX_NETWORK_STATE_TRACKER_EVENT + 1 ;
195+ private static final int EVENT_RESTORE_DEFAULT_NETWORK = 1 ;
203196
204197 /**
205198 * used internally to change our mobile data enabled flag
206199 */
207- private static final int EVENT_CHANGE_MOBILE_DATA_ENABLED =
208- MAX_NETWORK_STATE_TRACKER_EVENT + 2 ;
200+ private static final int EVENT_CHANGE_MOBILE_DATA_ENABLED = 2 ;
209201
210202 /**
211203 * used internally to change our network preference setting
212204 * arg1 = networkType to prefer
213205 */
214- private static final int EVENT_SET_NETWORK_PREFERENCE =
215- MAX_NETWORK_STATE_TRACKER_EVENT + 3 ;
206+ private static final int EVENT_SET_NETWORK_PREFERENCE = 3 ;
216207
217208 /**
218209 * used internally to synchronize inet condition reports
219210 * arg1 = networkType
220211 * arg2 = condition (0 bad, 100 good)
221212 */
222- private static final int EVENT_INET_CONDITION_CHANGE =
223- MAX_NETWORK_STATE_TRACKER_EVENT + 4 ;
213+ private static final int EVENT_INET_CONDITION_CHANGE = 4 ;
224214
225215 /**
226216 * used internally to mark the end of inet condition hold periods
227217 * arg1 = networkType
228218 */
229- private static final int EVENT_INET_CONDITION_HOLD_END =
230- MAX_NETWORK_STATE_TRACKER_EVENT + 5 ;
219+ private static final int EVENT_INET_CONDITION_HOLD_END = 5 ;
231220
232221 /**
233222 * used internally to set enable/disable cellular data
234223 * arg1 = ENBALED or DISABLED
235224 */
236- private static final int EVENT_SET_MOBILE_DATA =
237- MAX_NETWORK_STATE_TRACKER_EVENT + 7 ;
225+ private static final int EVENT_SET_MOBILE_DATA = 7 ;
238226
239227 /**
240228 * used internally to clear a wakelock when transitioning
241229 * from one net to another
242230 */
243- private static final int EVENT_CLEAR_NET_TRANSITION_WAKELOCK =
244- MAX_NETWORK_STATE_TRACKER_EVENT + 8 ;
231+ private static final int EVENT_CLEAR_NET_TRANSITION_WAKELOCK = 8 ;
245232
246233 /**
247234 * used internally to reload global proxy settings
248235 */
249- private static final int EVENT_APPLY_GLOBAL_HTTP_PROXY =
250- MAX_NETWORK_STATE_TRACKER_EVENT + 9 ;
236+ private static final int EVENT_APPLY_GLOBAL_HTTP_PROXY = 9 ;
251237
252238 /**
253239 * used internally to set external dependency met/unmet
254240 * arg1 = ENABLED (met) or DISABLED (unmet)
255241 * arg2 = NetworkType
256242 */
257- private static final int EVENT_SET_DEPENDENCY_MET =
258- MAX_NETWORK_STATE_TRACKER_EVENT + 10 ;
243+ private static final int EVENT_SET_DEPENDENCY_MET = 10 ;
259244
260245 /**
261246 * used internally to restore DNS properties back to the
262247 * default network
263248 */
264- private static final int EVENT_RESTORE_DNS =
265- MAX_NETWORK_STATE_TRACKER_EVENT + 11 ;
249+ private static final int EVENT_RESTORE_DNS = 11 ;
266250
267251 /**
268252 * used internally to send a sticky broadcast delayed.
269253 */
270- private static final int EVENT_SEND_STICKY_BROADCAST_INTENT =
271- MAX_NETWORK_STATE_TRACKER_EVENT + 12 ;
254+ private static final int EVENT_SEND_STICKY_BROADCAST_INTENT = 12 ;
272255
273256 /**
274257 * Used internally to
275258 * {@link NetworkStateTracker#setPolicyDataEnable(boolean)}.
276259 */
277- private static final int EVENT_SET_POLICY_DATA_ENABLE = MAX_NETWORK_STATE_TRACKER_EVENT + 13 ;
260+ private static final int EVENT_SET_POLICY_DATA_ENABLE = 13 ;
278261
279- private Handler mHandler ;
262+ /** Handler used for internal events. */
263+ private InternalHandler mHandler ;
264+ /** Handler used for incoming {@link NetworkStateTracker} events. */
265+ private NetworkStateTrackerHandler mTrackerHandler ;
280266
281267 // list of DeathRecipients used to make sure features are turned off when
282268 // a process dies
@@ -334,7 +320,8 @@ public ConnectivityService(Context context, INetworkManagementService netd,
334320
335321 HandlerThread handlerThread = new HandlerThread ("ConnectivityServiceThread" );
336322 handlerThread .start ();
337- mHandler = new MyHandler (handlerThread .getLooper ());
323+ mHandler = new InternalHandler (handlerThread .getLooper ());
324+ mTrackerHandler = new NetworkStateTrackerHandler (handlerThread .getLooper ());
338325
339326 // setup our unique device name
340327 if (TextUtils .isEmpty (SystemProperties .get ("net.hostname" ))) {
@@ -484,33 +471,33 @@ public ConnectivityService(Context context, INetworkManagementService netd,
484471 for (int netType : mPriorityList ) {
485472 switch (mNetConfigs [netType ].radio ) {
486473 case ConnectivityManager .TYPE_WIFI :
487- mNetTrackers [netType ] = new WifiStateTracker (netType ,
488- mNetConfigs [netType ].name );
489- mNetTrackers [netType ].startMonitoring (context , mHandler );
490- break ;
474+ mNetTrackers [netType ] = new WifiStateTracker (
475+ netType , mNetConfigs [netType ].name );
476+ mNetTrackers [netType ].startMonitoring (context , mTrackerHandler );
477+ break ;
491478 case ConnectivityManager .TYPE_MOBILE :
492479 mNetTrackers [netType ] = new MobileDataStateTracker (netType ,
493480 mNetConfigs [netType ].name );
494- mNetTrackers [netType ].startMonitoring (context , mHandler );
481+ mNetTrackers [netType ].startMonitoring (context , mTrackerHandler );
495482 break ;
496483 case ConnectivityManager .TYPE_DUMMY :
497484 mNetTrackers [netType ] = new DummyDataStateTracker (netType ,
498485 mNetConfigs [netType ].name );
499- mNetTrackers [netType ].startMonitoring (context , mHandler );
486+ mNetTrackers [netType ].startMonitoring (context , mTrackerHandler );
500487 break ;
501488 case ConnectivityManager .TYPE_BLUETOOTH :
502489 mNetTrackers [netType ] = BluetoothTetheringDataTracker .getInstance ();
503- mNetTrackers [netType ].startMonitoring (context , mHandler );
490+ mNetTrackers [netType ].startMonitoring (context , mTrackerHandler );
504491 break ;
505492 case ConnectivityManager .TYPE_WIMAX :
506493 mNetTrackers [netType ] = makeWimaxStateTracker ();
507494 if (mNetTrackers [netType ]!= null ) {
508- mNetTrackers [netType ].startMonitoring (context , mHandler );
495+ mNetTrackers [netType ].startMonitoring (context , mTrackerHandler );
509496 }
510497 break ;
511498 case ConnectivityManager .TYPE_ETHERNET :
512499 mNetTrackers [netType ] = EthernetDataTracker .getInstance ();
513- mNetTrackers [netType ].startMonitoring (context , mHandler );
500+ mNetTrackers [netType ].startMonitoring (context , mTrackerHandler );
514501 break ;
515502 default :
516503 loge ("Trying to create a DataStateTracker for an unknown radio type " +
@@ -557,8 +544,9 @@ public ConnectivityService(Context context, INetworkManagementService netd,
557544
558545 loadGlobalProxy ();
559546 }
560- private NetworkStateTracker makeWimaxStateTracker () {
561- //Initialize Wimax
547+
548+ private NetworkStateTracker makeWimaxStateTracker () {
549+ // Initialize Wimax
562550 DexClassLoader wimaxClassLoader ;
563551 Class wimaxStateTrackerClass = null ;
564552 Class wimaxServiceClass = null ;
@@ -611,7 +599,7 @@ private NetworkStateTracker makeWimaxStateTracker() {
611599 Constructor wmxStTrkrConst = wimaxStateTrackerClass .getConstructor
612600 (new Class [] {Context .class , Handler .class });
613601 wimaxStateTracker = (NetworkStateTracker )wmxStTrkrConst .newInstance (mContext ,
614- mHandler );
602+ mTrackerHandler );
615603
616604 Constructor wmxSrvConst = wimaxServiceClass .getDeclaredConstructor
617605 (new Class [] {Context .class , wimaxStateTrackerClass });
@@ -632,14 +620,16 @@ private NetworkStateTracker makeWimaxStateTracker() {
632620
633621 return wimaxStateTracker ;
634622 }
623+
635624 /**
636625 * Sets the preferred network.
637626 * @param preference the new preference
638627 */
639628 public void setNetworkPreference (int preference ) {
640629 enforceChangePermission ();
641630
642- mHandler .sendMessage (mHandler .obtainMessage (EVENT_SET_NETWORK_PREFERENCE , preference , 0 ));
631+ mHandler .sendMessage (
632+ mHandler .obtainMessage (EVENT_SET_NETWORK_PREFERENCE , preference , 0 ));
643633 }
644634
645635 public int getNetworkPreference () {
@@ -2460,8 +2450,8 @@ protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
24602450 }
24612451
24622452 // must be stateless - things change under us.
2463- private class MyHandler extends Handler {
2464- public MyHandler (Looper looper ) {
2453+ private class NetworkStateTrackerHandler extends Handler {
2454+ public NetworkStateTrackerHandler (Looper looper ) {
24652455 super (looper );
24662456 }
24672457
@@ -2519,6 +2509,19 @@ public void handleMessage(Message msg) {
25192509 // @see bug/4455071
25202510 handleConnectivityChange (info .getType (), false );
25212511 break ;
2512+ }
2513+ }
2514+ }
2515+
2516+ private class InternalHandler extends Handler {
2517+ public InternalHandler (Looper looper ) {
2518+ super (looper );
2519+ }
2520+
2521+ @ Override
2522+ public void handleMessage (Message msg ) {
2523+ NetworkInfo info ;
2524+ switch (msg .what ) {
25222525 case EVENT_CLEAR_NET_TRANSITION_WAKELOCK :
25232526 String causedBy = null ;
25242527 synchronized (ConnectivityService .this ) {
0 commit comments