TcpSocketMonitor: add polling loop

TcpSocketMonitor starts a sock_diag polling thread in its ctor whose
polling interval can be controlled with setPollingInterval() and
suspendPolling().

Initially the polling thread will immediately be suspended. The polling
thread is automatically started when 1 or more physical network exists,
and automatically stopped when there is 0 physical networks.

By default the polling interval is set to 30 secs.

Also fix some code indentation issues.

Bug: 64147860
Test: tested manually, watching the result of
      $ adb shell dumpsys netd tcp_socket_info
Change-Id: I7fe356a0a073ebc83486bc774a3002648e9dd457
diff --git a/server/NetworkController.cpp b/server/NetworkController.cpp
index 43a55bd..5b2cd89 100644
--- a/server/NetworkController.cpp
+++ b/server/NetworkController.cpp
@@ -355,6 +355,9 @@
     }
 
     mNetworks[netId] = physicalNetwork;
+
+    updateTcpSocketMonitorPolling();
+
     return 0;
 }
 
@@ -448,6 +451,9 @@
     mNetworks.erase(netId);
     delete network;
     _resolv_delete_cache_for_net(netId);
+
+    updateTcpSocketMonitorPolling();
+
     return ret;
 }
 
@@ -730,5 +736,22 @@
     return 0;
 }
 
+void NetworkController::updateTcpSocketMonitorPolling() {
+    bool physicalNetworkExists = false;
+    for (const auto& entry : mNetworks) {
+        const auto& network = entry.second;
+        if (network->getType() == Network::PHYSICAL && network->getNetId() >= MIN_NET_ID) {
+            physicalNetworkExists = true;
+            break;
+        }
+    }
+
+    if (physicalNetworkExists) {
+        android::net::gCtls->tcpSocketMonitor.resumePolling();
+    } else {
+        android::net::gCtls->tcpSocketMonitor.suspendPolling();
+    }
+}
+
 }  // namespace net
 }  // namespace android