Skip to content

Commit 67881c4

Browse files
author
Robert Greenwalt
committed
Update networktype before sending state change.
Fixes potential race condition in network-type info. May fix this issue. bug:3376930 Change-Id: I3d5fd7c76e54923b62c56defa947be3c9c1cd585
1 parent c33acae commit 67881c4

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

core/java/android/net/MobileDataStateTracker.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ private class MobileDataStateReceiver extends BroadcastReceiver {
149149
ConnectivityManager mConnectivityManager;
150150
public void onReceive(Context context, Intent intent) {
151151
synchronized(this) {
152+
// update state and roaming before we set the state - only state changes are
153+
// noticed
154+
TelephonyManager tm = TelephonyManager.getDefault();
155+
setRoamingStatus(tm.isNetworkRoaming());
156+
setSubtype(tm.getNetworkType(), tm.getNetworkTypeName());
152157
if (intent.getAction().equals(TelephonyIntents.
153158
ACTION_ANY_DATA_CONNECTION_STATE_CHANGED)) {
154159
Phone.DataState state = getMobileDataState(intent);
@@ -254,9 +259,6 @@ public void onReceive(Context context, Intent intent) {
254259
reason == null ? "" : "(" + reason + ")");
255260
setDetailedState(DetailedState.FAILED, reason, apnName);
256261
}
257-
TelephonyManager tm = TelephonyManager.getDefault();
258-
setRoamingStatus(tm.isNetworkRoaming());
259-
setSubtype(tm.getNetworkType(), tm.getNetworkTypeName());
260262
}
261263
}
262264
}

core/java/android/net/NetworkStateTracker.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ public void setTeardownRequested(boolean isRequested) {
302302
public boolean isTeardownRequested() {
303303
return mTeardownRequested;
304304
}
305-
305+
306306
/**
307307
* Send a notification that the results of a scan for network access
308308
* points has completed, and results are available.
@@ -327,10 +327,10 @@ protected void setRoamingStatus(boolean isRoaming) {
327327
}
328328

329329
protected void setSubtype(int subtype, String subtypeName) {
330-
if (mNetworkInfo.isConnected()) {
331-
int oldSubtype = mNetworkInfo.getSubtype();
332-
if (subtype != oldSubtype) {
333-
mNetworkInfo.setSubtype(subtype, subtypeName);
330+
int oldSubtype = mNetworkInfo.getSubtype();
331+
if (subtype != oldSubtype) {
332+
mNetworkInfo.setSubtype(subtype, subtypeName);
333+
if (mNetworkInfo.isConnected()) {
334334
Message msg = mTarget.obtainMessage(
335335
EVENT_NETWORK_SUBTYPE_CHANGED, oldSubtype, 0, mNetworkInfo);
336336
msg.sendToTarget();

0 commit comments

Comments
 (0)