Skip to content

Commit 7bb2d94

Browse files
Wink SavilleAndroid Git Automerger
authored andcommitted
am 090df1d: Merge "Delay connectivity change notifications." into honeycomb-LTE
* commit '090df1dc4188e5b9ef10a0aca5081a196085ff56': Delay connectivity change notifications.
2 parents 03f8fcb + 090df1d commit 7bb2d94

2 files changed

Lines changed: 76 additions & 9 deletions

File tree

core/java/android/provider/Settings.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3022,6 +3022,18 @@ public static final String getBluetoothInputDevicePriorityKey(String address) {
30223022
*/
30233023
public static final String TTY_MODE_ENABLED = "tty_mode_enabled";
30243024

3025+
/**
3026+
* The number of milliseconds to delay before sending out Connectivyt Change broadcasts
3027+
* @hide
3028+
*/
3029+
public static final String CONNECTIVITY_CHANGE_DELAY = "connectivity_change_delay";
3030+
3031+
/**
3032+
* Default value for CONNECTIVITY_CHANGE_DELAY in milliseconds.
3033+
* @hide
3034+
*/
3035+
public static final int CONNECTIVITY_CHANGE_DELAY_DEFAULT = 3000;
3036+
30253037
/**
30263038
* Controls whether settings backup is enabled.
30273039
* Type: int ( 0 = disabled, 1 = enabled )

services/java/com/android/server/ConnectivityService.java

Lines changed: 64 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,12 @@ public class ConnectivityService extends IConnectivityManager.Stub {
216216
private static final int EVENT_SET_DEPENDENCY_MET =
217217
MAX_NETWORK_STATE_TRACKER_EVENT + 10;
218218

219+
/**
220+
* used internally to send a sticky broadcast delayed.
221+
*/
222+
private static final int EVENT_SEND_STICKY_BROADCAST_INTENT =
223+
MAX_NETWORK_STATE_TRACKER_EVENT + 11;
224+
219225
private Handler mHandler;
220226

221227
// list of DeathRecipients used to make sure features are turned off when
@@ -511,6 +517,17 @@ private void handleSetNetworkPreference(int preference) {
511517
}
512518
}
513519

520+
private int getConnectivityChangeDelay() {
521+
final ContentResolver cr = mContext.getContentResolver();
522+
523+
/** Check system properties for the default value then use secure settings value, if any. */
524+
int defaultDelay = SystemProperties.getInt(
525+
"conn." + Settings.Secure.CONNECTIVITY_CHANGE_DELAY,
526+
Settings.Secure.CONNECTIVITY_CHANGE_DELAY_DEFAULT);
527+
return Settings.Secure.getInt(cr, Settings.Secure.CONNECTIVITY_CHANGE_DELAY,
528+
defaultDelay);
529+
}
530+
514531
private int getPersistedNetworkPreference() {
515532
final ContentResolver cr = mContext.getContentResolver();
516533

@@ -1243,13 +1260,14 @@ private void handleDisconnect(NetworkInfo info) {
12431260
// do this before we broadcast the change
12441261
handleConnectivityChange(prevNetType, doReset);
12451262

1246-
sendStickyBroadcast(intent);
1263+
sendStickyBroadcastDelayed(intent, getConnectivityChangeDelay());
12471264
/*
12481265
* If the failover network is already connected, then immediately send
12491266
* out a followup broadcast indicating successful failover
12501267
*/
12511268
if (mActiveDefaultNetwork != -1) {
1252-
sendConnectedBroadcast(mNetTrackers[mActiveDefaultNetwork].getNetworkInfo());
1269+
sendConnectedBroadcastDelayed(mNetTrackers[mActiveDefaultNetwork].getNetworkInfo(),
1270+
getConnectivityChangeDelay());
12531271
}
12541272
}
12551273

@@ -1303,11 +1321,15 @@ private void sendConnectedBroadcast(NetworkInfo info) {
13031321
sendGeneralBroadcast(info, ConnectivityManager.CONNECTIVITY_ACTION);
13041322
}
13051323

1324+
private void sendConnectedBroadcastDelayed(NetworkInfo info, int delayMs) {
1325+
sendGeneralBroadcastDelayed(info, ConnectivityManager.CONNECTIVITY_ACTION, delayMs);
1326+
}
1327+
13061328
private void sendInetConditionBroadcast(NetworkInfo info) {
13071329
sendGeneralBroadcast(info, ConnectivityManager.INET_CONDITION_ACTION);
13081330
}
13091331

1310-
private void sendGeneralBroadcast(NetworkInfo info, String bcastType) {
1332+
private Intent makeGeneralIntent(NetworkInfo info, String bcastType) {
13111333
Intent intent = new Intent(bcastType);
13121334
intent.putExtra(ConnectivityManager.EXTRA_NETWORK_INFO, info);
13131335
if (info.isFailover()) {
@@ -1322,7 +1344,15 @@ private void sendGeneralBroadcast(NetworkInfo info, String bcastType) {
13221344
info.getExtraInfo());
13231345
}
13241346
intent.putExtra(ConnectivityManager.EXTRA_INET_CONDITION, mDefaultInetConditionPublished);
1325-
sendStickyBroadcast(intent);
1347+
return intent;
1348+
}
1349+
1350+
private void sendGeneralBroadcast(NetworkInfo info, String bcastType) {
1351+
sendStickyBroadcast(makeGeneralIntent(info, bcastType));
1352+
}
1353+
1354+
private void sendGeneralBroadcastDelayed(NetworkInfo info, String bcastType, int delayMs) {
1355+
sendStickyBroadcastDelayed(makeGeneralIntent(info, bcastType), delayMs);
13261356
}
13271357

13281358
/**
@@ -1387,10 +1417,25 @@ private void sendStickyBroadcast(Intent intent) {
13871417
mInitialBroadcast = new Intent(intent);
13881418
}
13891419
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
1420+
if (DBG) {
1421+
log("sendStickyBroadcast: NetworkInfo=" +
1422+
intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO));
1423+
}
1424+
13901425
mContext.sendStickyBroadcast(intent);
13911426
}
13921427
}
13931428

1429+
private void sendStickyBroadcastDelayed(Intent intent, int delayMs) {
1430+
if (delayMs <= 0) {
1431+
sendStickyBroadcast(intent);
1432+
} else {
1433+
if (DBG) log("sendStickyBroadcastDelayed: delayMs=" + delayMs + " intent=" + intent);
1434+
mHandler.sendMessageDelayed(mHandler.obtainMessage(
1435+
EVENT_SEND_STICKY_BROADCAST_INTENT, intent), delayMs);
1436+
}
1437+
}
1438+
13941439
void systemReady() {
13951440
IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE);
13961441
mNetd = INetworkManagementService.Stub.asInterface(b);
@@ -1467,7 +1512,7 @@ private void handleConnect(NetworkInfo info) {
14671512
thisNet.setTeardownRequested(false);
14681513
updateNetworkSettings(thisNet);
14691514
handleConnectivityChange(type, false);
1470-
sendConnectedBroadcast(info);
1515+
sendConnectedBroadcastDelayed(info, getConnectivityChangeDelay());
14711516
}
14721517

14731518
/**
@@ -2037,6 +2082,13 @@ public void handleMessage(Message msg) {
20372082
handleSetDependencyMet(msg.arg2, met);
20382083
break;
20392084
}
2085+
case EVENT_SEND_STICKY_BROADCAST_INTENT:
2086+
{
2087+
Intent intent = (Intent)msg.obj;
2088+
log("EVENT_SEND_STICKY_BROADCAST_INTENT: sendStickyBroadcast intent=" + intent);
2089+
sendStickyBroadcast(intent);
2090+
break;
2091+
}
20402092
}
20412093
}
20422094
}
@@ -2223,10 +2275,13 @@ private void handleInetConditionHoldEnd(int netType, int sequence) {
22232275
if (DBG) log("event hold for obsolete network - aborting");
22242276
return;
22252277
}
2226-
if (mDefaultInetConditionPublished == mDefaultInetCondition) {
2227-
if (DBG) log("no change in condition - aborting");
2228-
return;
2229-
}
2278+
// TODO: Figure out why this optimization sometimes causes a
2279+
// change in mDefaultInetCondition to be missed and the
2280+
// UI to not be updated.
2281+
//if (mDefaultInetConditionPublished == mDefaultInetCondition) {
2282+
// if (DBG) log("no change in condition - aborting");
2283+
// return;
2284+
//}
22302285
NetworkInfo networkInfo = mNetTrackers[mActiveDefaultNetwork].getNetworkInfo();
22312286
if (networkInfo.isConnected() == false) {
22322287
if (DBG) log("default network not connected - aborting");

0 commit comments

Comments
 (0)