From 3646cbdfe77ff37475259b39171aa49686c5501a Mon Sep 17 00:00:00 2001 From: Amith Yamasani Date: Wed, 13 Apr 2016 14:04:53 -0700 Subject: [PATCH] Update interface quota on the handler This avoids making expensive netd calls while holding the mRulesLock Doesn't fix the problem of turning on hotspot while WiFi was connected. It is no longer blocked on isNetworkMetered() call though. Partial fix for following bugs... Bug: 27857665 Bug: 28201280 Change-Id: I62f3c0b0571292cc1e156b48ce3329def41cdd07 --- .../net/NetworkPolicyManagerService.java | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/net/NetworkPolicyManagerService.java b/services/core/java/com/android/server/net/NetworkPolicyManagerService.java index c24860886d729..3fb786bc599e2 100644 --- a/services/core/java/com/android/server/net/NetworkPolicyManagerService.java +++ b/services/core/java/com/android/server/net/NetworkPolicyManagerService.java @@ -260,6 +260,8 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { private static final int MSG_ADVISE_PERSIST_THRESHOLD = 7; private static final int MSG_SCREEN_ON_CHANGED = 8; private static final int MSG_RESTRICT_BACKGROUND_WHITELIST_CHANGED = 9; + private static final int MSG_UPDATE_INTERFACE_QUOTA = 10; + private static final int MSG_REMOVE_INTERFACE_QUOTA = 11; private final Context mContext; private final IActivityManager mActivityManager; @@ -1275,8 +1277,10 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { } for (String iface : ifaces) { - removeInterfaceQuota(iface); - setInterfaceQuota(iface, quotaBytes); + // long quotaBytes split up into two ints to fit in message + mHandler.obtainMessage(MSG_UPDATE_INTERFACE_QUOTA, + (int) (quotaBytes >> 32), (int) (quotaBytes & 0xFFFFFFFF), iface) + .sendToTarget(); newMeteredIfaces.add(iface); } } @@ -1292,8 +1296,10 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { for (int i = connIfaces.size()-1; i >= 0; i--) { String iface = connIfaces.valueAt(i); - removeInterfaceQuota(iface); - setInterfaceQuota(iface, Long.MAX_VALUE); + // long quotaBytes split up into two ints to fit in message + mHandler.obtainMessage(MSG_UPDATE_INTERFACE_QUOTA, + (int) (Long.MAX_VALUE >> 32), (int) (Long.MAX_VALUE & 0xFFFFFFFF), iface) + .sendToTarget(); newMeteredIfaces.add(iface); } @@ -1303,7 +1309,8 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { for (int i = mMeteredIfaces.size() - 1; i >= 0; i--) { final String iface = mMeteredIfaces.valueAt(i); if (!newMeteredIfaces.contains(iface)) { - removeInterfaceQuota(iface); + mHandler.obtainMessage(MSG_REMOVE_INTERFACE_QUOTA, iface) + .sendToTarget(); } } mMeteredIfaces = newMeteredIfaces; @@ -2950,6 +2957,17 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { updateScreenOn(); return true; } + case MSG_UPDATE_INTERFACE_QUOTA: { + removeInterfaceQuota((String) msg.obj); + // int params need to be stitched back into a long + setInterfaceQuota((String) msg.obj, + ((long) msg.arg1 << 32) | (msg.arg2 & 0xFFFFFFFFL)); + return true; + } + case MSG_REMOVE_INTERFACE_QUOTA: { + removeInterfaceQuota((String) msg.obj); + return true; + } default: { return false; }