am 090df1dc
: Merge "Delay connectivity change notifications." into honeycomb-LTE
* commit '090df1dc4188e5b9ef10a0aca5081a196085ff56': Delay connectivity change notifications.
This commit is contained in:
@ -3022,6 +3022,18 @@ public final class Settings {
|
|||||||
*/
|
*/
|
||||||
public static final String TTY_MODE_ENABLED = "tty_mode_enabled";
|
public static final String TTY_MODE_ENABLED = "tty_mode_enabled";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The number of milliseconds to delay before sending out Connectivyt Change broadcasts
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static final String CONNECTIVITY_CHANGE_DELAY = "connectivity_change_delay";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default value for CONNECTIVITY_CHANGE_DELAY in milliseconds.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static final int CONNECTIVITY_CHANGE_DELAY_DEFAULT = 3000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controls whether settings backup is enabled.
|
* Controls whether settings backup is enabled.
|
||||||
* Type: int ( 0 = disabled, 1 = enabled )
|
* Type: int ( 0 = disabled, 1 = enabled )
|
||||||
|
@ -216,6 +216,12 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
private static final int EVENT_SET_DEPENDENCY_MET =
|
private static final int EVENT_SET_DEPENDENCY_MET =
|
||||||
MAX_NETWORK_STATE_TRACKER_EVENT + 10;
|
MAX_NETWORK_STATE_TRACKER_EVENT + 10;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* used internally to send a sticky broadcast delayed.
|
||||||
|
*/
|
||||||
|
private static final int EVENT_SEND_STICKY_BROADCAST_INTENT =
|
||||||
|
MAX_NETWORK_STATE_TRACKER_EVENT + 11;
|
||||||
|
|
||||||
private Handler mHandler;
|
private Handler mHandler;
|
||||||
|
|
||||||
// list of DeathRecipients used to make sure features are turned off when
|
// list of DeathRecipients used to make sure features are turned off when
|
||||||
@ -511,6 +517,17 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getConnectivityChangeDelay() {
|
||||||
|
final ContentResolver cr = mContext.getContentResolver();
|
||||||
|
|
||||||
|
/** Check system properties for the default value then use secure settings value, if any. */
|
||||||
|
int defaultDelay = SystemProperties.getInt(
|
||||||
|
"conn." + Settings.Secure.CONNECTIVITY_CHANGE_DELAY,
|
||||||
|
Settings.Secure.CONNECTIVITY_CHANGE_DELAY_DEFAULT);
|
||||||
|
return Settings.Secure.getInt(cr, Settings.Secure.CONNECTIVITY_CHANGE_DELAY,
|
||||||
|
defaultDelay);
|
||||||
|
}
|
||||||
|
|
||||||
private int getPersistedNetworkPreference() {
|
private int getPersistedNetworkPreference() {
|
||||||
final ContentResolver cr = mContext.getContentResolver();
|
final ContentResolver cr = mContext.getContentResolver();
|
||||||
|
|
||||||
@ -1243,13 +1260,14 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
// do this before we broadcast the change
|
// do this before we broadcast the change
|
||||||
handleConnectivityChange(prevNetType, doReset);
|
handleConnectivityChange(prevNetType, doReset);
|
||||||
|
|
||||||
sendStickyBroadcast(intent);
|
sendStickyBroadcastDelayed(intent, getConnectivityChangeDelay());
|
||||||
/*
|
/*
|
||||||
* If the failover network is already connected, then immediately send
|
* If the failover network is already connected, then immediately send
|
||||||
* out a followup broadcast indicating successful failover
|
* out a followup broadcast indicating successful failover
|
||||||
*/
|
*/
|
||||||
if (mActiveDefaultNetwork != -1) {
|
if (mActiveDefaultNetwork != -1) {
|
||||||
sendConnectedBroadcast(mNetTrackers[mActiveDefaultNetwork].getNetworkInfo());
|
sendConnectedBroadcastDelayed(mNetTrackers[mActiveDefaultNetwork].getNetworkInfo(),
|
||||||
|
getConnectivityChangeDelay());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1303,11 +1321,15 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
sendGeneralBroadcast(info, ConnectivityManager.CONNECTIVITY_ACTION);
|
sendGeneralBroadcast(info, ConnectivityManager.CONNECTIVITY_ACTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sendConnectedBroadcastDelayed(NetworkInfo info, int delayMs) {
|
||||||
|
sendGeneralBroadcastDelayed(info, ConnectivityManager.CONNECTIVITY_ACTION, delayMs);
|
||||||
|
}
|
||||||
|
|
||||||
private void sendInetConditionBroadcast(NetworkInfo info) {
|
private void sendInetConditionBroadcast(NetworkInfo info) {
|
||||||
sendGeneralBroadcast(info, ConnectivityManager.INET_CONDITION_ACTION);
|
sendGeneralBroadcast(info, ConnectivityManager.INET_CONDITION_ACTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendGeneralBroadcast(NetworkInfo info, String bcastType) {
|
private Intent makeGeneralIntent(NetworkInfo info, String bcastType) {
|
||||||
Intent intent = new Intent(bcastType);
|
Intent intent = new Intent(bcastType);
|
||||||
intent.putExtra(ConnectivityManager.EXTRA_NETWORK_INFO, info);
|
intent.putExtra(ConnectivityManager.EXTRA_NETWORK_INFO, info);
|
||||||
if (info.isFailover()) {
|
if (info.isFailover()) {
|
||||||
@ -1322,7 +1344,15 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
info.getExtraInfo());
|
info.getExtraInfo());
|
||||||
}
|
}
|
||||||
intent.putExtra(ConnectivityManager.EXTRA_INET_CONDITION, mDefaultInetConditionPublished);
|
intent.putExtra(ConnectivityManager.EXTRA_INET_CONDITION, mDefaultInetConditionPublished);
|
||||||
sendStickyBroadcast(intent);
|
return intent;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendGeneralBroadcast(NetworkInfo info, String bcastType) {
|
||||||
|
sendStickyBroadcast(makeGeneralIntent(info, bcastType));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendGeneralBroadcastDelayed(NetworkInfo info, String bcastType, int delayMs) {
|
||||||
|
sendStickyBroadcastDelayed(makeGeneralIntent(info, bcastType), delayMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1387,10 +1417,25 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
mInitialBroadcast = new Intent(intent);
|
mInitialBroadcast = new Intent(intent);
|
||||||
}
|
}
|
||||||
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
|
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
|
||||||
|
if (DBG) {
|
||||||
|
log("sendStickyBroadcast: NetworkInfo=" +
|
||||||
|
intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO));
|
||||||
|
}
|
||||||
|
|
||||||
mContext.sendStickyBroadcast(intent);
|
mContext.sendStickyBroadcast(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sendStickyBroadcastDelayed(Intent intent, int delayMs) {
|
||||||
|
if (delayMs <= 0) {
|
||||||
|
sendStickyBroadcast(intent);
|
||||||
|
} else {
|
||||||
|
if (DBG) log("sendStickyBroadcastDelayed: delayMs=" + delayMs + " intent=" + intent);
|
||||||
|
mHandler.sendMessageDelayed(mHandler.obtainMessage(
|
||||||
|
EVENT_SEND_STICKY_BROADCAST_INTENT, intent), delayMs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void systemReady() {
|
void systemReady() {
|
||||||
IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE);
|
IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE);
|
||||||
mNetd = INetworkManagementService.Stub.asInterface(b);
|
mNetd = INetworkManagementService.Stub.asInterface(b);
|
||||||
@ -1467,7 +1512,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
thisNet.setTeardownRequested(false);
|
thisNet.setTeardownRequested(false);
|
||||||
updateNetworkSettings(thisNet);
|
updateNetworkSettings(thisNet);
|
||||||
handleConnectivityChange(type, false);
|
handleConnectivityChange(type, false);
|
||||||
sendConnectedBroadcast(info);
|
sendConnectedBroadcastDelayed(info, getConnectivityChangeDelay());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2037,6 +2082,13 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
handleSetDependencyMet(msg.arg2, met);
|
handleSetDependencyMet(msg.arg2, met);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case EVENT_SEND_STICKY_BROADCAST_INTENT:
|
||||||
|
{
|
||||||
|
Intent intent = (Intent)msg.obj;
|
||||||
|
log("EVENT_SEND_STICKY_BROADCAST_INTENT: sendStickyBroadcast intent=" + intent);
|
||||||
|
sendStickyBroadcast(intent);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2223,10 +2275,13 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
if (DBG) log("event hold for obsolete network - aborting");
|
if (DBG) log("event hold for obsolete network - aborting");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (mDefaultInetConditionPublished == mDefaultInetCondition) {
|
// TODO: Figure out why this optimization sometimes causes a
|
||||||
if (DBG) log("no change in condition - aborting");
|
// change in mDefaultInetCondition to be missed and the
|
||||||
return;
|
// 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("default network not connected - aborting");
|
if (DBG) log("default network not connected - aborting");
|
||||||
|
Reference in New Issue
Block a user