Merge "Update mActiveIdleTimers to use netId as a key" into main
This commit is contained in:
@@ -11468,7 +11468,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
// If there is no default network, default network is considered active to keep the existing
|
// If there is no default network, default network is considered active to keep the existing
|
||||||
// behavior. Initial value is used until first connect to the default network.
|
// behavior. Initial value is used until first connect to the default network.
|
||||||
private volatile boolean mIsDefaultNetworkActive = true;
|
private volatile boolean mIsDefaultNetworkActive = true;
|
||||||
private final ArrayMap<String, IdleTimerParams> mActiveIdleTimers = new ArrayMap<>();
|
// Key is netId. Value is configured idle timer information.
|
||||||
|
private final SparseArray<IdleTimerParams> mActiveIdleTimers = new SparseArray<>();
|
||||||
|
|
||||||
private static class IdleTimerParams {
|
private static class IdleTimerParams {
|
||||||
public final int timeout;
|
public final int timeout;
|
||||||
@@ -11496,7 +11497,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
|
|
||||||
public void handleReportNetworkActivity(NetworkActivityParams activityParams) {
|
public void handleReportNetworkActivity(NetworkActivityParams activityParams) {
|
||||||
ensureRunningOnConnectivityServiceThread();
|
ensureRunningOnConnectivityServiceThread();
|
||||||
if (mActiveIdleTimers.isEmpty()) {
|
if (mActiveIdleTimers.size() == 0) {
|
||||||
// This activity change is not for the current default network.
|
// This activity change is not for the current default network.
|
||||||
// This can happen if netd callback post activity change event message but
|
// This can happen if netd callback post activity change event message but
|
||||||
// the default network is lost before processing this message.
|
// the default network is lost before processing this message.
|
||||||
@@ -11572,6 +11573,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
*/
|
*/
|
||||||
private boolean setupDataActivityTracking(NetworkAgentInfo networkAgent) {
|
private boolean setupDataActivityTracking(NetworkAgentInfo networkAgent) {
|
||||||
final String iface = networkAgent.linkProperties.getInterfaceName();
|
final String iface = networkAgent.linkProperties.getInterfaceName();
|
||||||
|
final int netId = networkAgent.network().netId;
|
||||||
|
|
||||||
final int timeout;
|
final int timeout;
|
||||||
final int type;
|
final int type;
|
||||||
@@ -11596,7 +11598,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
|
|
||||||
if (timeout > 0 && iface != null) {
|
if (timeout > 0 && iface != null) {
|
||||||
try {
|
try {
|
||||||
mActiveIdleTimers.put(iface, new IdleTimerParams(timeout, type));
|
mActiveIdleTimers.put(netId, new IdleTimerParams(timeout, type));
|
||||||
mNetd.idletimerAddInterface(iface, timeout, Integer.toString(type));
|
mNetd.idletimerAddInterface(iface, timeout, Integer.toString(type));
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -11612,6 +11614,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
*/
|
*/
|
||||||
private void removeDataActivityTracking(NetworkAgentInfo networkAgent) {
|
private void removeDataActivityTracking(NetworkAgentInfo networkAgent) {
|
||||||
final String iface = networkAgent.linkProperties.getInterfaceName();
|
final String iface = networkAgent.linkProperties.getInterfaceName();
|
||||||
|
final int netId = networkAgent.network().netId;
|
||||||
final NetworkCapabilities caps = networkAgent.networkCapabilities;
|
final NetworkCapabilities caps = networkAgent.networkCapabilities;
|
||||||
|
|
||||||
if (iface == null) return;
|
if (iface == null) return;
|
||||||
@@ -11627,11 +11630,12 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
updateRadioPowerState(false /* isActive */, type);
|
updateRadioPowerState(false /* isActive */, type);
|
||||||
final IdleTimerParams params = mActiveIdleTimers.remove(iface);
|
final IdleTimerParams params = mActiveIdleTimers.get(netId);
|
||||||
if (params == null) {
|
if (params == null) {
|
||||||
// IdleTimer is not added if the configured timeout is 0 or negative value
|
// IdleTimer is not added if the configured timeout is 0 or negative value
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
mActiveIdleTimers.remove(netId);
|
||||||
// The call fails silently if no idle timer setup for this interface
|
// The call fails silently if no idle timer setup for this interface
|
||||||
mNetd.idletimerRemoveInterface(iface, params.timeout,
|
mNetd.idletimerRemoveInterface(iface, params.timeout,
|
||||||
Integer.toString(params.transportType));
|
Integer.toString(params.transportType));
|
||||||
@@ -11702,9 +11706,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
pw.print("mIsDefaultNetworkActive="); pw.println(mIsDefaultNetworkActive);
|
pw.print("mIsDefaultNetworkActive="); pw.println(mIsDefaultNetworkActive);
|
||||||
pw.println("Idle timers:");
|
pw.println("Idle timers:");
|
||||||
try {
|
try {
|
||||||
for (Map.Entry<String, IdleTimerParams> ent : mActiveIdleTimers.entrySet()) {
|
for (int i = 0; i < mActiveIdleTimers.size(); i++) {
|
||||||
pw.print(" "); pw.print(ent.getKey()); pw.println(":");
|
pw.print(" "); pw.print(mActiveIdleTimers.keyAt(i)); pw.println(":");
|
||||||
final IdleTimerParams params = ent.getValue();
|
final IdleTimerParams params = mActiveIdleTimers.valueAt(i);
|
||||||
pw.print(" timeout="); pw.print(params.timeout);
|
pw.print(" timeout="); pw.print(params.timeout);
|
||||||
pw.print(" type="); pw.println(params.transportType);
|
pw.print(" type="); pw.println(params.transportType);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user