Setup idletimer for network interface.
Cherry-picked from commit 8ce570b0f3 in
master. DO NOT MERGE
Change-Id: I6101c7ae041b4cc1237ce7a9983753dbdfa301d3
This commit is contained in:
@@ -1625,6 +1625,10 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
int prevNetType = info.getType();
|
int prevNetType = info.getType();
|
||||||
|
|
||||||
mNetTrackers[prevNetType].setTeardownRequested(false);
|
mNetTrackers[prevNetType].setTeardownRequested(false);
|
||||||
|
|
||||||
|
// Remove idletimer previously setup in {@code handleConnect}
|
||||||
|
removeDataActivityTracking(prevNetType);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the disconnected network is not the active one, then don't report
|
* If the disconnected network is not the active one, then don't report
|
||||||
* this as a loss of connectivity. What probably happened is that we're
|
* this as a loss of connectivity. What probably happened is that we're
|
||||||
@@ -1905,6 +1909,8 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
private void handleConnect(NetworkInfo info) {
|
private void handleConnect(NetworkInfo info) {
|
||||||
final int type = info.getType();
|
final int type = info.getType();
|
||||||
|
|
||||||
|
setupDataActivityTracking(type);
|
||||||
|
|
||||||
// snapshot isFailover, because sendConnectedBroadcast() resets it
|
// snapshot isFailover, because sendConnectedBroadcast() resets it
|
||||||
boolean isFailover = info.isFailover();
|
boolean isFailover = info.isFailover();
|
||||||
final NetworkStateTracker thisNet = mNetTrackers[type];
|
final NetworkStateTracker thisNet = mNetTrackers[type];
|
||||||
@@ -1976,6 +1982,58 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup data activity tracking for the given network interface.
|
||||||
|
*
|
||||||
|
* Every {@code setupDataActivityTracking} should be paired with a
|
||||||
|
* {@link removeDataActivityTracking} for cleanup.
|
||||||
|
*/
|
||||||
|
private void setupDataActivityTracking(int type) {
|
||||||
|
final NetworkStateTracker thisNet = mNetTrackers[type];
|
||||||
|
final String iface = thisNet.getLinkProperties().getInterfaceName();
|
||||||
|
|
||||||
|
final int timeout;
|
||||||
|
|
||||||
|
if (ConnectivityManager.isNetworkTypeMobile(type)) {
|
||||||
|
timeout = Settings.Secure.getInt(mContext.getContentResolver(),
|
||||||
|
Settings.Secure.DATA_ACTIVITY_TIMEOUT_MOBILE,
|
||||||
|
0);
|
||||||
|
// Canonicalize mobile network type
|
||||||
|
type = ConnectivityManager.TYPE_MOBILE;
|
||||||
|
} else if (ConnectivityManager.TYPE_WIFI == type) {
|
||||||
|
timeout = Settings.Secure.getInt(mContext.getContentResolver(),
|
||||||
|
Settings.Secure.DATA_ACTIVITY_TIMEOUT_WIFI,
|
||||||
|
0);
|
||||||
|
} else {
|
||||||
|
// do not track any other networks
|
||||||
|
timeout = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (timeout > 0 && iface != null) {
|
||||||
|
try {
|
||||||
|
mNetd.addIdleTimer(iface, timeout, Integer.toString(type));
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove data activity tracking when network disconnects.
|
||||||
|
*/
|
||||||
|
private void removeDataActivityTracking(int type) {
|
||||||
|
final NetworkStateTracker net = mNetTrackers[type];
|
||||||
|
final String iface = net.getLinkProperties().getInterfaceName();
|
||||||
|
|
||||||
|
if (iface != null && (ConnectivityManager.isNetworkTypeMobile(type) ||
|
||||||
|
ConnectivityManager.TYPE_WIFI == type)) {
|
||||||
|
try {
|
||||||
|
// the call fails silently if no idletimer setup for this interface
|
||||||
|
mNetd.removeIdleTimer(iface);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* After a change in the connectivity state of a network. We're mainly
|
* After a change in the connectivity state of a network. We're mainly
|
||||||
* concerned with making sure that the list of DNS servers is set up
|
* concerned with making sure that the list of DNS servers is set up
|
||||||
|
|||||||
Reference in New Issue
Block a user