Merge "Revert "Clean up published network condition reporting.""

This commit is contained in:
Wink Saville
2013-01-31 00:32:36 +00:00
committed by Android (Google) Code Review

View File

@@ -194,6 +194,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
private int mNetworkPreference; private int mNetworkPreference;
private int mActiveDefaultNetwork = -1; private int mActiveDefaultNetwork = -1;
// 0 is full bad, 100 is full good // 0 is full bad, 100 is full good
private int mDefaultInetCondition = 0;
private int mDefaultInetConditionPublished = 0; private int mDefaultInetConditionPublished = 0;
private boolean mInetConditionChangeInFlight = false; private boolean mInetConditionChangeInFlight = false;
private int mDefaultConnectionSequence = 0; private int mDefaultConnectionSequence = 0;
@@ -1729,10 +1730,6 @@ public class ConnectivityService extends IConnectivityManager.Stub {
intent.putExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO, switchTo); intent.putExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO, switchTo);
} else { } else {
mDefaultInetConditionPublished = 0; // we're not connected anymore mDefaultInetConditionPublished = 0; // we're not connected anymore
if (DBG) {
log("handleDisconnect: net=" + mActiveDefaultNetwork +
", published condition=" + mDefaultInetConditionPublished);
}
intent.putExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, true); intent.putExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, true);
} }
} }
@@ -1923,10 +1920,6 @@ public class ConnectivityService extends IConnectivityManager.Stub {
intent.putExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO, switchTo); intent.putExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO, switchTo);
} else { } else {
mDefaultInetConditionPublished = 0; mDefaultInetConditionPublished = 0;
if (DBG) {
log("handleConnectionFailure: net=" + mActiveDefaultNetwork +
", published condition=" + mDefaultInetConditionPublished);
}
intent.putExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, true); intent.putExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, true);
} }
} }
@@ -2071,10 +2064,6 @@ public class ConnectivityService extends IConnectivityManager.Stub {
mDefaultInetConditionPublished = 0; mDefaultInetConditionPublished = 0;
mDefaultConnectionSequence++; mDefaultConnectionSequence++;
mInetConditionChangeInFlight = false; mInetConditionChangeInFlight = false;
if (DBG) {
log("handleConnect: net=" + newNetType +
", published condition=" + mDefaultInetConditionPublished);
}
// Don't do this - if we never sign in stay, grey // Don't do this - if we never sign in stay, grey
//reportNetworkCondition(mActiveDefaultNetwork, 100); //reportNetworkCondition(mActiveDefaultNetwork, 100);
} }
@@ -2790,8 +2779,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
{ {
int netType = msg.arg1; int netType = msg.arg1;
int sequence = msg.arg2; int sequence = msg.arg2;
int condition = (Integer)msg.obj; handleInetConditionHoldEnd(netType, sequence);
handleInetConditionHoldEnd(netType, sequence, condition);
break; break;
} }
case EVENT_SET_NETWORK_PREFERENCE: case EVENT_SET_NETWORK_PREFERENCE:
@@ -3004,13 +2992,14 @@ public class ConnectivityService extends IConnectivityManager.Stub {
if (VDBG) { if (VDBG) {
log("handleInetConditionChange: net=" + log("handleInetConditionChange: net=" +
netType + ", condition=" + condition + netType + ", condition=" + condition +
" mActiveDefaultNetwork=" + mActiveDefaultNetwork); ",mActiveDefaultNetwork=" + mActiveDefaultNetwork);
} }
mDefaultInetCondition = condition;
int delay; int delay;
if (mInetConditionChangeInFlight == false) { if (mInetConditionChangeInFlight == false) {
if (VDBG) log("handleInetConditionChange: starting a change hold"); if (VDBG) log("handleInetConditionChange: starting a change hold");
// setup a new hold to debounce this // setup a new hold to debounce this
if (condition > 50) { if (mDefaultInetCondition > 50) {
delay = Settings.Global.getInt(mContext.getContentResolver(), delay = Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.INET_CONDITION_DEBOUNCE_UP_DELAY, 500); Settings.Global.INET_CONDITION_DEBOUNCE_UP_DELAY, 500);
} else { } else {
@@ -3019,16 +3008,18 @@ public class ConnectivityService extends IConnectivityManager.Stub {
} }
mInetConditionChangeInFlight = true; mInetConditionChangeInFlight = true;
mHandler.sendMessageDelayed(mHandler.obtainMessage(EVENT_INET_CONDITION_HOLD_END, mHandler.sendMessageDelayed(mHandler.obtainMessage(EVENT_INET_CONDITION_HOLD_END,
mActiveDefaultNetwork, mDefaultConnectionSequence, new Integer(condition)), delay); mActiveDefaultNetwork, mDefaultConnectionSequence), delay);
} else { } else {
// we've set the new condition, when this hold ends that will get picked up // we've set the new condition, when this hold ends that will get picked up
if (VDBG) log("handleInetConditionChange: currently in hold - not setting new end evt"); if (VDBG) log("handleInetConditionChange: currently in hold - not setting new end evt");
} }
} }
private void handleInetConditionHoldEnd(int netType, int sequence, int condition) { private void handleInetConditionHoldEnd(int netType, int sequence) {
if (DBG) { if (DBG) {
log("handleInetConditionHoldEnd: net=" + netType + ", condition=" + condition); log("handleInetConditionHoldEnd: net=" + netType +
", condition=" + mDefaultInetCondition +
", published condition=" + mDefaultInetConditionPublished);
} }
mInetConditionChangeInFlight = false; mInetConditionChangeInFlight = false;
@@ -3040,13 +3031,19 @@ public class ConnectivityService extends IConnectivityManager.Stub {
if (DBG) log("handleInetConditionHoldEnd: event hold for obsolete network - ignoring"); if (DBG) log("handleInetConditionHoldEnd: event hold for obsolete network - ignoring");
return; return;
} }
// TODO: Figure out why this optimization sometimes causes a
// change in mDefaultInetCondition to be missed and the
// UI to not be updated.
//if (mDefaultInetConditionPublished == mDefaultInetCondition) {
// if (DBG) log("no change in condition - aborting");
// return;
//}
NetworkInfo networkInfo = mNetTrackers[mActiveDefaultNetwork].getNetworkInfo(); NetworkInfo networkInfo = mNetTrackers[mActiveDefaultNetwork].getNetworkInfo();
if (networkInfo.isConnected() == false) { if (networkInfo.isConnected() == false) {
if (DBG) log("handleInetConditionHoldEnd: default network not connected - ignoring"); if (DBG) log("handleInetConditionHoldEnd: default network not connected - ignoring");
return; return;
} }
mDefaultInetConditionPublished = condition; mDefaultInetConditionPublished = mDefaultInetCondition;
sendInetConditionBroadcast(networkInfo); sendInetConditionBroadcast(networkInfo);
return; return;
} }