WifiStateMachine: dynamically configure WifiHAL log level

By default, VERBOSE level logging is disabled for native code.
However, when debugging Wifi issues, we'll sometimes want to
include VERBOSE level log messages from the HAL implementation.

Update WifiStateMachine's verbose-debugging logic, to support
this case.

Note that VERBOSE level messages will not be compiled in
on user builds. Nor will system server be permitted to change
the logging level on user builds. For these reasons, the
log level is only modified on non-user builds.

BUG=27857554
TEST=manual

Manual test (bullhead + forthcoming HAL patch)
- On userdebug build with 'Enable Wi-Fi Verbose Logging' set:
  $ adb reboot && adb wait-for-device && adb logcat -d | grep 'V WifiHAL'
  -> matching lines seen
  $ adb shell getprop | grep WifiHAL
  [log.tag.WifiHAL]: [V]
- On userdebug build with 'Enable Wi-Fi Verbose Logging' unset:
  $ adb reboot && adb wait-for-device && adb logcat -d | grep 'V WifiHAL'
  -> NO matching lines
  $ adb shell getprop | grep WifiHAL
  [log.tag.WifiHAL]: [D]
- On user build with 'Enable Wi-Fi Verbose Logging' set:
  $ adb logcat -d | grep 'V WifiHAL'
  -> NO matching lines
  $ adb shell getprop | grep WifiHAL
  -> NO matching lines

Change-Id: I43af6852cd445f9a7daee04981f253a6c0ebc499
diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java
index ce6a9f6..2356cf8 100644
--- a/service/java/com/android/server/wifi/WifiStateMachine.java
+++ b/service/java/com/android/server/wifi/WifiStateMachine.java
@@ -76,6 +76,7 @@
 import android.net.wifi.p2p.IWifiP2pManager;
 import android.os.BatteryStats;
 import android.os.Binder;
+import android.os.Build;
 import android.os.Bundle;
 import android.os.IBinder;
 import android.os.INetworkManagementService;
@@ -1311,10 +1312,12 @@
             mWifiNative.setSupplicantLogLevel("DEBUG");
             setLogRecSize(ActivityManager.isLowRamDeviceStatic()
                     ? NUM_LOG_RECS_VERBOSE_LOW_MEMORY : NUM_LOG_RECS_VERBOSE);
+            configureVerboseHalLogging(true);
         } else {
             DBG = false;
             mWifiNative.setSupplicantLogLevel("INFO");
             setLogRecSize(NUM_LOG_RECS_NORMAL);
+            configureVerboseHalLogging(false);
         }
         mCountryCode.enableVerboseLogging(mVerboseLoggingLevel);
         mWifiLogger.startLogging(DBG);
@@ -1328,6 +1331,18 @@
         }
     }
 
+    private static final String BUILD_TYPE_USER = "user";
+    private static final String SYSTEM_PROPERTY_LOG_CONTROL_WIFIHAL = "log.tag.WifiHAL";
+    private static final String LOGD_LEVEL_DEBUG = "D";
+    private static final String LOGD_LEVEL_VERBOSE = "V";
+    private void configureVerboseHalLogging(boolean enableVerbose) {
+        if (Build.TYPE == BUILD_TYPE_USER) {  // Verbose HAL logging not supported on user builds.
+            return;
+        }
+        SystemProperties.set(SYSTEM_PROPERTY_LOG_CONTROL_WIFIHAL,
+                enableVerbose ? LOGD_LEVEL_VERBOSE : LOGD_LEVEL_DEBUG);
+    }
+
     long mLastScanPermissionUpdate = 0;
     boolean mConnectedModeGScanOffloadStarted = false;
     // Don't do a G-scan enable/re-enable cycle more than once within 20seconds