SupplicantStaIface: Expose the 2 ISupplicant methods

These are 2 methods exposed in the top level ISupplicant object, which
needs to be exposed to WifiNative.

While there,
Add the new EAP phase 2 method conversions in SupplicantStaNetworkHal.

Bug: 33383725
Test: Unit tests
Change-Id: I46abd77b0616e4e3da7e9bbe3d2751e0783e93fe
diff --git a/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java b/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java
index 1447e3e..a86341b 100644
--- a/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java
+++ b/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java
@@ -1336,6 +1336,83 @@
         }
     }
 
+    public static final int LOG_LEVEL_EXCESSIVE = ISupplicant.DebugLevel.EXCESSIVE;
+    public static final int LOG_LEVEL_MSGDUMP = ISupplicant.DebugLevel.MSGDUMP;
+    public static final int LOG_LEVEL_DEBUG = ISupplicant.DebugLevel.DEBUG;
+    public static final int LOG_LEVEL_INFO = ISupplicant.DebugLevel.INFO;
+    public static final int LOG_LEVEL_WARNING = ISupplicant.DebugLevel.WARNING;
+    public static final int LOG_LEVEL_ERROR = ISupplicant.DebugLevel.ERROR;
+    /**
+     * Set the debug log level for wpa_supplicant
+     * @param level One of the above {@link #LOG_LEVEL_EXCESSIVE} - {@link #LOG_LEVEL_ERROR} value.
+     * @return true if request is sent successfully, false otherwise.
+     */
+    public boolean setLogLevel(int level) {
+        return setDebugParams(level, false, false);
+    }
+
+    /** See ISupplicant.hal for documentation */
+    private boolean setDebugParams(int level, boolean showTimestamp, boolean showKeys) {
+        synchronized (mLock) {
+            final String methodStr = "setDebugParams";
+            if (DBG) Log.i(TAG, methodStr);
+            if (!checkSupplicantAndLogFailure(methodStr)) return false;
+            try {
+                SupplicantStatus status =
+                        mISupplicant.setDebugParams(level, showTimestamp, showKeys);
+                return checkStatusAndLogFailure(status, methodStr);
+            } catch (RemoteException e) {
+                Log.e(TAG, "ISupplicant." + methodStr + ": exception:" + e);
+                supplicantServiceDiedHandler();
+                return false;
+            }
+        }
+    }
+
+    /**
+     * Set concurrency priority between P2P & STA operations.
+     *
+     * @param isStaHigherPriority Set to true to prefer STA over P2P during concurrency operations,
+     *                            false otherwise.
+     * @return true if request is sent successfully, false otherwise.
+     */
+    public boolean setConcurrencyPriority(boolean isStaHigherPriority) {
+        if (isStaHigherPriority) {
+            return setConcurrencyPriority(IfaceType.STA);
+        } else {
+            return setConcurrencyPriority(IfaceType.P2P);
+        }
+    }
+
+    /** See ISupplicant.hal for documentation */
+    private boolean setConcurrencyPriority(int type) {
+        synchronized (mLock) {
+            final String methodStr = "setConcurrencyPriority";
+            if (DBG) Log.i(TAG, methodStr);
+            if (!checkSupplicantAndLogFailure(methodStr)) return false;
+            try {
+                SupplicantStatus status = mISupplicant.setConcurrencyPriority(type);
+                return checkStatusAndLogFailure(status, methodStr);
+            } catch (RemoteException e) {
+                Log.e(TAG, "ISupplicant." + methodStr + ": exception:" + e);
+                supplicantServiceDiedHandler();
+                return false;
+            }
+        }
+    }
+
+    /**
+     * Returns false if Supplicant is null, and logs failure to call methodStr
+     */
+    private boolean checkSupplicantAndLogFailure(final String methodStr) {
+        if (DBG) Log.i(TAG, methodStr);
+        if (mISupplicant == null) {
+            Log.e(TAG, "Can't call " + methodStr + ", ISupplicant is null");
+            return false;
+        }
+        return true;
+    }
+
     /**
      * Returns false if SupplicantStaIface is null, and logs failure to call methodStr
      */
diff --git a/service/java/com/android/server/wifi/SupplicantStaNetworkHal.java b/service/java/com/android/server/wifi/SupplicantStaNetworkHal.java
index 91cdcc7..6f3aac2 100644
--- a/service/java/com/android/server/wifi/SupplicantStaNetworkHal.java
+++ b/service/java/com/android/server/wifi/SupplicantStaNetworkHal.java
@@ -703,6 +703,12 @@
                 return WifiEnterpriseConfig.Phase2.MSCHAPV2;
             case ISupplicantStaNetwork.EapPhase2Method.GTC:
                 return WifiEnterpriseConfig.Phase2.GTC;
+            case ISupplicantStaNetwork.EapPhase2Method.SIM:
+                return WifiEnterpriseConfig.Phase2.SIM;
+            case ISupplicantStaNetwork.EapPhase2Method.AKA:
+                return WifiEnterpriseConfig.Phase2.AKA;
+            case ISupplicantStaNetwork.EapPhase2Method.AKA_PRIME:
+                return WifiEnterpriseConfig.Phase2.AKA_PRIME;
             default:
                 Log.e(TAG, "invalid eap phase2 method value from supplicant: " + value);
                 return -1;
@@ -862,6 +868,12 @@
                 return ISupplicantStaNetwork.EapPhase2Method.MSPAPV2;
             case WifiEnterpriseConfig.Phase2.GTC:
                 return ISupplicantStaNetwork.EapPhase2Method.GTC;
+            case WifiEnterpriseConfig.Phase2.SIM:
+                return ISupplicantStaNetwork.EapPhase2Method.SIM;
+            case WifiEnterpriseConfig.Phase2.AKA:
+                return ISupplicantStaNetwork.EapPhase2Method.AKA;
+            case WifiEnterpriseConfig.Phase2.AKA_PRIME:
+                return ISupplicantStaNetwork.EapPhase2Method.AKA_PRIME;
             default:
                 Log.e(TAG, "invalid eap phase2 method value from WifiConfiguration: " + value);
                 return -1;
diff --git a/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java b/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java
index a8001f2..fb583ca 100644
--- a/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java
@@ -17,6 +17,7 @@
 
 import static org.junit.Assert.*;
 import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyBoolean;
 import static org.mockito.Matchers.anyInt;
 import static org.mockito.Matchers.anyLong;
 import static org.mockito.Matchers.anyShort;
@@ -605,6 +606,44 @@
     }
 
     /**
+     * Tests the setting of log level.
+     */
+    @Test
+    public void testSetLogLevel() throws Exception {
+        when(mISupplicantMock.setDebugParams(anyInt(), anyBoolean(), anyBoolean()))
+                .thenReturn(mStatusSuccess);
+
+        // Fail before initialization is performed.
+        assertFalse(mDut.setLogLevel(SupplicantStaIfaceHal.LOG_LEVEL_DEBUG));
+
+        executeAndValidateInitializationSequence(false, false, false);
+
+        // This should work.
+        assertTrue(mDut.setLogLevel(SupplicantStaIfaceHal.LOG_LEVEL_DEBUG));
+        verify(mISupplicantMock)
+                .setDebugParams(eq(ISupplicant.DebugLevel.DEBUG), eq(false), eq(false));
+    }
+
+    /**
+     * Tests the setting of concurrency priority.
+     */
+    @Test
+    public void testConcurrencyPriority() throws Exception {
+        when(mISupplicantMock.setConcurrencyPriority(anyInt())).thenReturn(mStatusSuccess);
+
+        // Fail before initialization is performed.
+        assertFalse(mDut.setConcurrencyPriority(false));
+
+        executeAndValidateInitializationSequence(false, false, false);
+
+        // This should work.
+        assertTrue(mDut.setConcurrencyPriority(false));
+        verify(mISupplicantMock).setConcurrencyPriority(eq(IfaceType.P2P));
+        assertTrue(mDut.setConcurrencyPriority(true));
+        verify(mISupplicantMock).setConcurrencyPriority(eq(IfaceType.STA));
+    }
+
+    /**
      * Calls.initialize(), mocking various call back answers and verifying flow, asserting for the
      * expected result. Verifies if ISupplicantStaIface manager is initialized or reset.
      * Each of the arguments will cause a different failure mode when set true.
diff --git a/tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java b/tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java
index 780b39c..c1596f0 100644
--- a/tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java
@@ -136,6 +136,17 @@
     }
 
     /**
+     * Tests the saving of WifiConfiguration to wpa_supplicant.
+     */
+    @Test
+    public void testEapTlsAkaNetworkWifiConfigurationSaveLoad() throws Exception {
+        WifiConfiguration config = WifiConfigurationTestUtil.createEapNetwork();
+        config.enterpriseConfig =
+                WifiConfigurationTestUtil.createTLSWifiEnterpriseConfigWithAkaPhase2();
+        testWifiConfigurationSaveLoad(config);
+    }
+
+    /**
      * Tests the loading of network ID.
      */
     @Test
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java
index fdf3ee3..28587d1 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java
@@ -379,6 +379,13 @@
         return config;
     }
 
+    public static WifiEnterpriseConfig createTLSWifiEnterpriseConfigWithAkaPhase2() {
+        WifiEnterpriseConfig config = new WifiEnterpriseConfig();
+        config.setEapMethod(WifiEnterpriseConfig.Eap.TLS);
+        config.setPhase2Method(WifiEnterpriseConfig.Phase2.AKA);
+        return config;
+    }
+
     /**
      * Asserts that the 2 WifiConfigurations are equal in the elements saved for both backup/restore
      * and config store.