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
diff --git a/services/core/java/com/android/server/net/NetworkPolicyManagerService.java b/services/core/java/com/android/server/net/NetworkPolicyManagerService.java
index c248608..3fb786b 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 @@
     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 @@
                 }
 
                 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 @@
 
         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 @@
         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 @@
                     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;
                 }