Merge "Add WakeupLock."
diff --git a/libwifi_system/hostapd_manager.cpp b/libwifi_system/hostapd_manager.cpp
index 658eecd..8c7de32 100644
--- a/libwifi_system/hostapd_manager.cpp
+++ b/libwifi_system/hostapd_manager.cpp
@@ -78,10 +78,6 @@
 }  // namespace
 
 bool HostapdManager::StartHostapd() {
-  if (!SupplicantManager::EnsureEntropyFileExists()) {
-    LOG(WARNING) << "Wi-Fi entropy file was not created";
-  }
-
   if (property_set("ctl.start", kHostapdServiceName) != 0) {
     LOG(ERROR) << "Failed to start SoftAP";
     return false;
diff --git a/libwifi_system/supplicant_manager.cpp b/libwifi_system/supplicant_manager.cpp
index 28010ec..be0c33a 100644
--- a/libwifi_system/supplicant_manager.cpp
+++ b/libwifi_system/supplicant_manager.cpp
@@ -40,12 +40,6 @@
 const char kSupplicantServiceName[] = "wpa_supplicant";
 constexpr mode_t kConfigFileMode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP;
 
-const char kWiFiEntropyFile[] = "/data/misc/wifi/entropy.bin";
-
-const unsigned char kDummyKey[21] = {0x02, 0x11, 0xbe, 0x33, 0x43, 0x35, 0x68,
-                                     0x47, 0x84, 0x99, 0xa9, 0x2b, 0x1c, 0xd3,
-                                     0xee, 0xff, 0xf1, 0xe2, 0xf3, 0xf4, 0xf5};
-
 int ensure_config_file_exists(const char* config_file) {
   char buf[2048];
   int srcfd, destfd;
@@ -152,10 +146,6 @@
    */
   (void)ensure_config_file_exists(kP2pConfigFile);
 
-  if (!EnsureEntropyFileExists()) {
-    LOG(ERROR) << "Wi-Fi entropy file was not created";
-  }
-
   /*
    * Get a reference to the status property, so we can distinguish
    * the case where it goes stopped => running => stopped (i.e.,
@@ -225,43 +215,5 @@
   return false;  // Failed to read service status from init.
 }
 
-bool SupplicantManager::EnsureEntropyFileExists() {
-  int ret;
-  int destfd;
-
-  ret = access(kWiFiEntropyFile, R_OK | W_OK);
-  if ((ret == 0) || (errno == EACCES)) {
-    if ((ret != 0) &&
-        (chmod(kWiFiEntropyFile, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) != 0)) {
-      PLOG(ERROR) << "Cannot set RW to " << kWiFiEntropyFile;
-      return false;
-    }
-    return true;
-  }
-  destfd = TEMP_FAILURE_RETRY(open(kWiFiEntropyFile, O_CREAT | O_RDWR, 0660));
-  if (destfd < 0) {
-    PLOG(ERROR) << "Cannot create " << kWiFiEntropyFile;
-    return false;
-  }
-
-  if (TEMP_FAILURE_RETRY(write(destfd, kDummyKey, sizeof(kDummyKey))) !=
-      sizeof(kDummyKey)) {
-    PLOG(ERROR) << "Error writing " << kWiFiEntropyFile;
-    close(destfd);
-    return false;
-  }
-  close(destfd);
-
-  /* chmod is needed because open() didn't set permisions properly */
-  if (chmod(kWiFiEntropyFile, 0660) < 0) {
-    PLOG(ERROR) << "Error changing permissions of " << kWiFiEntropyFile
-                << " to 0600 ";
-    unlink(kWiFiEntropyFile);
-    return false;
-  }
-
-  return true;
-}
-
 }  // namespace wifi_system
 }  // namespace android
diff --git a/service/java/com/android/server/wifi/HalDeviceManager.java b/service/java/com/android/server/wifi/HalDeviceManager.java
index 1a2d43d..ffc7113 100644
--- a/service/java/com/android/server/wifi/HalDeviceManager.java
+++ b/service/java/com/android/server/wifi/HalDeviceManager.java
@@ -17,6 +17,7 @@
 package com.android.server.wifi;
 
 import android.annotation.NonNull;
+import android.annotation.Nullable;
 import android.hardware.wifi.V1_0.IWifi;
 import android.hardware.wifi.V1_0.IWifiApIface;
 import android.hardware.wifi.V1_0.IWifiChip;
@@ -35,7 +36,6 @@
 import android.hidl.manager.V1_0.IServiceNotification;
 import android.os.Handler;
 import android.os.HwRemoteBinder;
-import android.os.Looper;
 import android.os.RemoteException;
 import android.util.Log;
 import android.util.LongSparseArray;
@@ -103,13 +103,14 @@
      * single copy kept.
      *
      * @param listener ManagerStatusListener listener object.
-     * @param handler Handler on which to dispatch listener. Null implies a new Handler based on
-     *                the current looper.
+     * @param handler Handler on which to dispatch listener. Null implies the listener will be
+     *                invoked synchronously from the context of the client which triggered the
+     *                state change.
      */
-    public void registerStatusListener(ManagerStatusListener listener, Handler handler) {
+    public void registerStatusListener(@NonNull ManagerStatusListener listener,
+            @Nullable Handler handler) {
         synchronized (mLock) {
-            if (!mManagerStatusListeners.add(new ManagerStatusListenerProxy(listener,
-                    handler == null ? new Handler(Looper.myLooper()) : handler))) {
+            if (!mManagerStatusListeners.add(new ManagerStatusListenerProxy(listener, handler))) {
                 Log.w(TAG, "registerStatusListener: duplicate registration ignored");
             }
         }
@@ -198,36 +199,37 @@
      * @param destroyedListener Optional (nullable) listener to call when the allocated interface
      *                          is removed. Will only be registered and used if an interface is
      *                          created successfully.
-     * @param handler The Handler on which to dispatch the listener. A null implies a new Handler
-     *                based on the current looper.
+     * @param handler Handler on which to dispatch listener. Null implies the listener will be
+     *                invoked synchronously from the context of the client which triggered the
+     *                iface destruction.
      * @return A newly created interface - or null if the interface could not be created.
      */
-    public IWifiStaIface createStaIface(InterfaceDestroyedListener destroyedListener,
-            Handler handler) {
+    public IWifiStaIface createStaIface(@Nullable InterfaceDestroyedListener destroyedListener,
+            @Nullable Handler handler) {
         return (IWifiStaIface) createIface(IfaceType.STA, destroyedListener, handler);
     }
 
     /**
      * Create AP interface if possible (see createStaIface doc).
      */
-    public IWifiApIface createApIface(InterfaceDestroyedListener destroyedListener,
-            Handler handler) {
+    public IWifiApIface createApIface(@Nullable InterfaceDestroyedListener destroyedListener,
+            @Nullable Handler handler) {
         return (IWifiApIface) createIface(IfaceType.AP, destroyedListener, handler);
     }
 
     /**
      * Create P2P interface if possible (see createStaIface doc).
      */
-    public IWifiP2pIface createP2pIface(InterfaceDestroyedListener destroyedListener,
-            Handler handler) {
+    public IWifiP2pIface createP2pIface(@Nullable InterfaceDestroyedListener destroyedListener,
+            @Nullable Handler handler) {
         return (IWifiP2pIface) createIface(IfaceType.P2P, destroyedListener, handler);
     }
 
     /**
      * Create NAN interface if possible (see createStaIface doc).
      */
-    public IWifiNanIface createNanIface(InterfaceDestroyedListener destroyedListener,
-            Handler handler) {
+    public IWifiNanIface createNanIface(@Nullable InterfaceDestroyedListener destroyedListener,
+            @Nullable Handler handler) {
         return (IWifiNanIface) createIface(IfaceType.NAN, destroyedListener, handler);
     }
 
@@ -269,11 +271,16 @@
      * and false on failure. This listener is in addition to the one registered when the interface
      * was created - allowing non-creators to monitor interface status.
      *
-     * Listener called-back on the specified handler - or on the current looper if a null is passed.
+     * @param destroyedListener Listener to call when the allocated interface is removed.
+     *                          Will only be registered and used if an interface is created
+     *                          successfully.
+     * @param handler Handler on which to dispatch listener. Null implies the listener will be
+     *                invoked synchronously from the context of the client which triggered the
+     *                iface destruction.
      */
     public boolean registerDestroyedListener(IWifiIface iface,
-            InterfaceDestroyedListener destroyedListener,
-            Handler handler) {
+            @NonNull InterfaceDestroyedListener destroyedListener,
+            @Nullable Handler handler) {
         String name = getName(iface);
         if (DBG) Log.d(TAG, "registerDestroyedListener: iface(name)=" + name);
 
@@ -304,11 +311,12 @@
      * @param ifaceType The interface type (IfaceType) to be monitored.
      * @param listener Listener to call when an interface of the requested
      *                 type could be created
-     * @param handler The Handler on which to dispatch the listener. A null implies a new Handler
-     *                on the current looper.
+     * @param handler Handler on which to dispatch listener. Null implies the listener will be
+     *                invoked synchronously from the context of the client which triggered the
+     *                mode change.
      */
     public void registerInterfaceAvailableForRequestListener(int ifaceType,
-            InterfaceAvailableForRequestListener listener, Handler handler) {
+            @NonNull InterfaceAvailableForRequestListener listener, @Nullable Handler handler) {
         if (DBG) Log.d(TAG, "registerInterfaceAvailableForRequestListener: ifaceType=" + ifaceType);
 
         synchronized (mLock) {
@@ -1215,9 +1223,8 @@
 
     private class ManagerStatusListenerProxy  extends
             ListenerProxy<ManagerStatusListener> {
-        ManagerStatusListenerProxy(ManagerStatusListener statusListener,
-                Handler handler) {
-            super(statusListener, handler, true, "ManagerStatusListenerProxy");
+        ManagerStatusListenerProxy(ManagerStatusListener statusListener, Handler handler) {
+            super(statusListener, handler, "ManagerStatusListenerProxy");
         }
 
         @Override
@@ -1902,11 +1909,8 @@
     }
 
     private abstract class ListenerProxy<LISTENER>  {
-        private static final int LISTENER_TRIGGERED = 0;
-
         protected LISTENER mListener;
         private Handler mHandler;
-        private boolean mFrontOfQueue;
 
         // override equals & hash to make sure that the container HashSet is unique with respect to
         // the contained listener
@@ -1921,23 +1925,20 @@
         }
 
         void trigger() {
-            if (mFrontOfQueue) {
-                mHandler.postAtFrontOfQueue(() -> {
-                    action();
-                });
-            } else {
+            if (mHandler != null) {
                 mHandler.post(() -> {
                     action();
                 });
+            } else {
+                action();
             }
         }
 
         protected abstract void action();
 
-        ListenerProxy(LISTENER listener, Handler handler, boolean frontOfQueue, String tag) {
+        ListenerProxy(LISTENER listener, Handler handler, String tag) {
             mListener = listener;
             mHandler = handler;
-            mFrontOfQueue = frontOfQueue;
         }
     }
 
@@ -1947,8 +1948,7 @@
         InterfaceDestroyedListenerProxy(@NonNull String ifaceName,
                                         InterfaceDestroyedListener destroyedListener,
                                         Handler handler) {
-            super(destroyedListener, handler == null ? new Handler(Looper.myLooper()) : handler,
-                    true, "InterfaceDestroyedListenerProxy");
+            super(destroyedListener, handler, "InterfaceDestroyedListenerProxy");
             mIfaceName = ifaceName;
         }
 
@@ -1962,8 +1962,7 @@
             ListenerProxy<InterfaceAvailableForRequestListener> {
         InterfaceAvailableForRequestListenerProxy(
                 InterfaceAvailableForRequestListener destroyedListener, Handler handler) {
-            super(destroyedListener, handler == null ? new Handler(Looper.myLooper()) : handler,
-                    false, "InterfaceAvailableForRequestListenerProxy");
+            super(destroyedListener, handler, "InterfaceAvailableForRequestListenerProxy");
         }
 
         @Override
diff --git a/service/java/com/android/server/wifi/SoftApManager.java b/service/java/com/android/server/wifi/SoftApManager.java
index e045c39..429e3c3 100644
--- a/service/java/com/android/server/wifi/SoftApManager.java
+++ b/service/java/com/android/server/wifi/SoftApManager.java
@@ -25,9 +25,7 @@
 import android.content.Intent;
 import android.net.InterfaceConfiguration;
 import android.net.wifi.IApInterface;
-import android.net.wifi.IApInterfaceEventCallback;
 import android.net.wifi.WifiConfiguration;
-import android.net.wifi.WifiConfiguration.KeyMgmt;
 import android.net.wifi.WifiManager;
 import android.os.INetworkManagementService;
 import android.os.Looper;
@@ -41,9 +39,9 @@
 import com.android.internal.util.State;
 import com.android.internal.util.StateMachine;
 import com.android.server.net.BaseNetworkObserver;
+import com.android.server.wifi.WifiNative.SoftApListener;
 import com.android.server.wifi.util.ApConfigUtil;
 
-import java.nio.charset.StandardCharsets;
 import java.util.Locale;
 
 /**
@@ -76,16 +74,14 @@
 
     private int mNumAssociatedStations = 0;
 
-    /**
-     * Listener for AP Interface events.
-     */
-    public class ApInterfaceListener extends IApInterfaceEventCallback.Stub {
+    private final SoftApListener mSoftApListener = new SoftApListener() {
         @Override
         public void onNumAssociatedStationsChanged(int numStations) {
             mStateMachine.sendMessage(
                     SoftApStateMachine.CMD_NUM_ASSOCIATED_STATIONS_CHANGED, numStations);
         }
-    }
+    };
+
 
     /**
      * Listener for soft AP state changes.
@@ -227,71 +223,24 @@
                 return ERROR_GENERIC;
             }
         }
-
-        int encryptionType = getIApInterfaceEncryptionType(localConfig);
-
         if (localConfig.hiddenSSID) {
             Log.d(TAG, "SoftAP is a hidden network");
         }
-
-        try {
-            // Note that localConfig.SSID is intended to be either a hex string or "double quoted".
-            // However, it seems that whatever is handing us these configurations does not obey
-            // this convention.
-            boolean success = mApInterface.writeHostapdConfig(
-                    localConfig.SSID.getBytes(StandardCharsets.UTF_8), localConfig.hiddenSSID,
-                    localConfig.apChannel, encryptionType,
-                    (localConfig.preSharedKey != null)
-                            ? localConfig.preSharedKey.getBytes(StandardCharsets.UTF_8)
-                            : new byte[0]);
-            if (!success) {
-                Log.e(TAG, "Failed to write hostapd configuration");
-                return ERROR_GENERIC;
-            }
-
-            success = mApInterface.startHostapd(new ApInterfaceListener());
-            if (!success) {
-                Log.e(TAG, "Failed to start hostapd.");
-                return ERROR_GENERIC;
-            }
-        } catch (RemoteException e) {
-            Log.e(TAG, "Exception in starting soft AP: " + e);
+        if (!mWifiNative.startSoftAp(localConfig, mSoftApListener)) {
+            Log.e(TAG, "Soft AP start failed");
+            return ERROR_GENERIC;
         }
-
         Log.d(TAG, "Soft AP is started");
 
         return SUCCESS;
     }
 
-    private static int getIApInterfaceEncryptionType(WifiConfiguration localConfig) {
-        int encryptionType;
-        switch (localConfig.getAuthType()) {
-            case KeyMgmt.NONE:
-                encryptionType = IApInterface.ENCRYPTION_TYPE_NONE;
-                break;
-            case KeyMgmt.WPA_PSK:
-                encryptionType = IApInterface.ENCRYPTION_TYPE_WPA;
-                break;
-            case KeyMgmt.WPA2_PSK:
-                encryptionType = IApInterface.ENCRYPTION_TYPE_WPA2;
-                break;
-            default:
-                // We really shouldn't default to None, but this was how NetworkManagementService
-                // used to do this.
-                encryptionType = IApInterface.ENCRYPTION_TYPE_NONE;
-                break;
-        }
-        return encryptionType;
-    }
-
     /**
      * Teardown soft AP.
      */
     private void stopSoftAp() {
-        try {
-            mApInterface.stopHostapd();
-        } catch (RemoteException e) {
-            Log.e(TAG, "Exception in stopping soft AP: " + e);
+        if (!mWifiNative.stopSoftAp()) {
+            Log.d(TAG, "Soft AP stop failed");
             return;
         }
         Log.d(TAG, "Soft AP is stopped");
@@ -301,15 +250,16 @@
         // Commands for the state machine.
         public static final int CMD_START = 0;
         public static final int CMD_STOP = 1;
-        public static final int CMD_AP_INTERFACE_BINDER_DEATH = 2;
+        public static final int CMD_WIFICOND_BINDER_DEATH = 2;
         public static final int CMD_INTERFACE_STATUS_CHANGED = 3;
         public static final int CMD_NUM_ASSOCIATED_STATIONS_CHANGED = 4;
 
         private final State mIdleState = new IdleState();
         private final State mStartedState = new StartedState();
 
-        private final StateMachineDeathRecipient mDeathRecipient =
-                new StateMachineDeathRecipient(this, CMD_AP_INTERFACE_BINDER_DEATH);
+        private final WifiNative.WificondDeathEventHandler mWificondDeathRecipient = () -> {
+            sendMessage(CMD_WIFICOND_BINDER_DEATH);
+        };
 
         private NetworkObserver mNetworkObserver;
 
@@ -342,7 +292,7 @@
         private class IdleState extends State {
             @Override
             public void enter() {
-                mDeathRecipient.unlinkToDeath();
+                mWifiNative.deregisterWificondDeathHandler();
                 unregisterObserver();
             }
 
@@ -364,8 +314,7 @@
                         updateApState(WifiManager.WIFI_AP_STATE_ENABLING,
                                 WifiManager.WIFI_AP_STATE_DISABLED, 0);
                         setNumAssociatedStations(0);
-                        if (!mDeathRecipient.linkToDeath(mApInterface.asBinder())) {
-                            mDeathRecipient.unlinkToDeath();
+                        if (!mWifiNative.registerWificondDeathHandler(mWificondDeathRecipient)) {
                             updateApState(WifiManager.WIFI_AP_STATE_FAILED,
                                     WifiManager.WIFI_AP_STATE_ENABLING,
                                     WifiManager.SAP_START_FAILURE_GENERAL);
@@ -373,12 +322,11 @@
                                     false, WifiManager.SAP_START_FAILURE_GENERAL);
                             break;
                         }
-
                         try {
                             mNetworkObserver = new NetworkObserver(mApInterfaceName);
                             mNwService.registerObserver(mNetworkObserver);
                         } catch (RemoteException e) {
-                            mDeathRecipient.unlinkToDeath();
+                            mWifiNative.deregisterWificondDeathHandler();
                             unregisterObserver();
                             updateApState(WifiManager.WIFI_AP_STATE_FAILED,
                                           WifiManager.WIFI_AP_STATE_ENABLING,
@@ -394,7 +342,7 @@
                             if (result == ERROR_NO_CHANNEL) {
                                 failureReason = WifiManager.SAP_START_FAILURE_NO_CHANNEL;
                             }
-                            mDeathRecipient.unlinkToDeath();
+                            mWifiNative.deregisterWificondDeathHandler();
                             unregisterObserver();
                             updateApState(WifiManager.WIFI_AP_STATE_FAILED,
                                           WifiManager.WIFI_AP_STATE_ENABLING,
@@ -479,13 +427,13 @@
                     case CMD_START:
                         // Already started, ignore this command.
                         break;
-                    case CMD_AP_INTERFACE_BINDER_DEATH:
+                    case CMD_WIFICOND_BINDER_DEATH:
                     case CMD_STOP:
                         updateApState(WifiManager.WIFI_AP_STATE_DISABLING,
                                 WifiManager.WIFI_AP_STATE_ENABLED, 0);
                         setNumAssociatedStations(0);
                         stopSoftAp();
-                        if (message.what == CMD_AP_INTERFACE_BINDER_DEATH) {
+                        if (message.what == CMD_WIFICOND_BINDER_DEATH) {
                             updateApState(WifiManager.WIFI_AP_STATE_FAILED,
                                           WifiManager.WIFI_AP_STATE_DISABLING,
                                           WifiManager.SAP_START_FAILURE_GENERAL);
diff --git a/service/java/com/android/server/wifi/StateMachineDeathRecipient.java b/service/java/com/android/server/wifi/StateMachineDeathRecipient.java
deleted file mode 100644
index 64c4bee..0000000
--- a/service/java/com/android/server/wifi/StateMachineDeathRecipient.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.server.wifi;
-
-import android.os.IBinder;
-import android.os.IBinder.DeathRecipient;
-import android.os.RemoteException;
-import com.android.internal.util.StateMachine;
-
-/**
- * Allows StateMachine instances to subscribe to binder death.
- *
- * @hide
- */
-public class StateMachineDeathRecipient implements DeathRecipient {
-
-    private final StateMachine mStateMachine;
-    private final int mDeathCommand;
-    private IBinder mLinkedBinder;
-
-    /**
-     * Construct a StateMachineDeathRecipient.
-     *
-     * @param sm StateMachine instance to receive a message upon Binder death.
-     * @param command message to send the state machine.
-     */
-    public StateMachineDeathRecipient(StateMachine sm, int command) {
-        mStateMachine = sm;
-        mDeathCommand = command;
-    }
-
-    /**
-     * Listen for the death of a binder.
-     *
-     * This method will unlink from death notifications from any
-     * previously linked IBinder instance.
-     *
-     * @param binder remote object to listen for death.
-     * @return true iff we have successfully subscribed to death notifications of a live
-     *         IBinder instance.
-     */
-    public boolean linkToDeath(IBinder binder) {
-        unlinkToDeath();
-        try {
-            binder.linkToDeath(this, 0);
-        } catch (RemoteException e) {
-            // The remote has already died.
-            return false;
-        }
-        mLinkedBinder = binder;
-        return true;
-    }
-
-    /**
-     * Unlink from notifications from the last linked IBinder instance.
-     */
-    public void unlinkToDeath() {
-        if (mLinkedBinder == null) {
-            return;
-        }
-        mLinkedBinder.unlinkToDeath(this, 0);
-        mLinkedBinder = null;
-    }
-
-    /**
-     * Called by the binder subsystem upon remote object death.
-     */
-    @Override
-    public void binderDied() {
-        mStateMachine.sendMessage(mDeathCommand);
-    }
-}
\ No newline at end of file
diff --git a/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java b/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java
index c93e110..664b052 100644
--- a/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java
+++ b/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java
@@ -53,6 +53,7 @@
 import android.util.Pair;
 import android.util.SparseArray;
 
+import com.android.server.wifi.WifiNative.SupplicantDeathEventHandler;
 import com.android.server.wifi.hotspot2.AnqpEvent;
 import com.android.server.wifi.hotspot2.IconEvent;
 import com.android.server.wifi.hotspot2.WnmData;
@@ -97,8 +98,15 @@
     // Supplicant HAL interface objects
     private IServiceManager mIServiceManager = null;
     private ISupplicant mISupplicant;
-    private ISupplicantStaIface mISupplicantStaIface;
-    private ISupplicantStaIfaceCallback mISupplicantStaIfaceCallback;
+    private HashMap<String, ISupplicantStaIface> mISupplicantStaIfaces = new HashMap<>();
+    private HashMap<String, ISupplicantStaIfaceCallback> mISupplicantStaIfaceCallbacks =
+            new HashMap<>();
+    private HashMap<String, SupplicantStaNetworkHal> mCurrentNetworkRemoteHandles = new HashMap<>();
+    private HashMap<String, WifiConfiguration> mCurrentNetworkLocalConfigs = new HashMap<>();
+    private SupplicantDeathEventHandler mDeathEventHandler;
+    private final Context mContext;
+    private final WifiMonitor mWifiMonitor;
+
     private final IServiceNotification mServiceNotificationCallback =
             new IServiceNotification.Stub() {
         public void onRegistration(String fqName, String name, boolean preexisting) {
@@ -107,11 +115,11 @@
                     Log.i(TAG, "IServiceNotification.onRegistration for: " + fqName
                             + ", " + name + " preexisting=" + preexisting);
                 }
-                if (!initSupplicantService() || !initSupplicantStaIface()) {
-                    Log.e(TAG, "initalizing ISupplicantIfaces failed.");
+                if (!initSupplicantService()) {
+                    Log.e(TAG, "initalizing ISupplicant failed.");
                     supplicantServiceDiedHandler();
                 } else {
-                    Log.i(TAG, "Completed initialization of ISupplicant interfaces.");
+                    Log.i(TAG, "Completed initialization of ISupplicant.");
                 }
             }
         }
@@ -132,16 +140,10 @@
                 }
             };
 
-    private String mIfaceName;
-    private SupplicantStaNetworkHal mCurrentNetworkRemoteHandle;
-    private WifiConfiguration mCurrentNetworkLocalConfig;
-    private final Context mContext;
-    private final WifiMonitor mWifiMonitor;
 
     public SupplicantStaIfaceHal(Context context, WifiMonitor monitor) {
         mContext = context;
         mWifiMonitor = monitor;
-        mISupplicantStaIfaceCallback = new SupplicantStaIfaceHalCallback();
     }
 
     /**
@@ -184,7 +186,7 @@
                 Log.i(TAG, "Registering ISupplicant service ready callback.");
             }
             mISupplicant = null;
-            mISupplicantStaIface = null;
+            mISupplicantStaIfaces.clear();
             if (mIServiceManager != null) {
                 // Already have an IServiceManager and serviceNotification registered, don't
                 // don't register another.
@@ -253,11 +255,11 @@
         return true;
     }
 
-    private boolean linkToSupplicantStaIfaceDeath() {
+    private boolean linkToSupplicantStaIfaceDeath(ISupplicantStaIface iface) {
         synchronized (mLock) {
-            if (mISupplicantStaIface == null) return false;
+            if (iface == null) return false;
             try {
-                if (!mISupplicantStaIface.linkToDeath(mSupplicantDeathRecipient, 0)) {
+                if (!iface.linkToDeath(mSupplicantDeathRecipient, 0)) {
                     Log.wtf(TAG, "Error on linkToDeath on ISupplicantStaIface");
                     supplicantServiceDiedHandler();
                     return false;
@@ -270,16 +272,23 @@
         }
     }
 
-    private int getCurrentNetworkId() {
+    private int getCurrentNetworkId(@NonNull String ifaceName) {
         synchronized (mLock) {
-            if (mCurrentNetworkLocalConfig == null) {
+            WifiConfiguration currentConfig = getCurrentNetworkLocalConfig(ifaceName);
+            if (currentConfig == null) {
                 return WifiConfiguration.INVALID_NETWORK_ID;
             }
-            return mCurrentNetworkLocalConfig.networkId;
+            return currentConfig.networkId;
         }
     }
 
-    private boolean initSupplicantStaIface() {
+    /**
+     * Setup a STA interface for the specified iface name.
+     *
+     * @param ifaceName Name of the interface.
+     * @return true on success, false otherwise.
+     */
+    public boolean setupIface(@NonNull String ifaceName) {
         synchronized (mLock) {
             /** List all supplicant Ifaces */
             final ArrayList<ISupplicant.IfaceInfo> supplicantIfaces = new ArrayList<>();
@@ -294,6 +303,7 @@
                 });
             } catch (RemoteException e) {
                 Log.e(TAG, "ISupplicant.listInterfaces exception: " + e);
+                supplicantServiceDiedHandler(ifaceName);
                 return false;
             }
             if (supplicantIfaces.size() == 0) {
@@ -301,9 +311,8 @@
                 return false;
             }
             Mutable<ISupplicantIface> supplicantIface = new Mutable<>();
-            Mutable<String> ifaceName = new Mutable<>();
             for (ISupplicant.IfaceInfo ifaceInfo : supplicantIfaces) {
-                if (ifaceInfo.type == IfaceType.STA) {
+                if (ifaceInfo.type == IfaceType.STA && ifaceName.equals(ifaceInfo.name)) {
                     try {
                         mISupplicant.getInterface(ifaceInfo,
                                 (SupplicantStatus status, ISupplicantIface iface) -> {
@@ -315,33 +324,99 @@
                             });
                     } catch (RemoteException e) {
                         Log.e(TAG, "ISupplicant.getInterface exception: " + e);
+                        supplicantServiceDiedHandler(ifaceName);
                         return false;
                     }
-                    ifaceName.value = ifaceInfo.name;
                     break;
                 }
             }
             if (supplicantIface.value == null) {
-                Log.e(TAG, "initSupplicantStaIface got null iface");
+                Log.e(TAG, "setupSupplicantStaIface got null iface");
                 return false;
             }
-            mISupplicantStaIface = getStaIfaceMockable(supplicantIface.value);
-            mIfaceName = ifaceName.value;
-            if (!linkToSupplicantStaIfaceDeath()) {
+            ISupplicantStaIface iface = getStaIfaceMockable(supplicantIface.value);
+            if (!linkToSupplicantStaIfaceDeath(iface)) {
                 return false;
             }
-            if (!registerCallback(mISupplicantStaIfaceCallback)) {
+            ISupplicantStaIfaceCallback callback = new SupplicantStaIfaceHalCallback(ifaceName);
+            if (!registerCallback(iface, callback)) {
                 return false;
             }
+            mISupplicantStaIfaces.put(ifaceName, iface);
+            mISupplicantStaIfaceCallbacks.put(ifaceName, callback);
             return true;
         }
     }
 
+    /**
+     * Registers a death notification for supplicant.
+     * @return Returns true on success.
+     */
+    public boolean registerDeathHandler(@NonNull SupplicantDeathEventHandler handler) {
+        if (mDeathEventHandler != null) {
+            Log.e(TAG, "Death handler already present");
+            return false;
+        }
+        mDeathEventHandler = handler;
+        return true;
+    }
+
+    /**
+     * Deregisters a death notification for supplicant.
+     * @return Returns true on success.
+     */
+    public boolean deregisterDeathHandler() {
+        if (mDeathEventHandler == null) {
+            Log.e(TAG, "No Death handler present");
+            return false;
+        }
+        mDeathEventHandler = null;
+        return true;
+    }
+
+    /**
+     * Teardown a STA interface for the specified iface name.
+     *
+     * @param ifaceName Name of the interface.
+     * @return true on success, false otherwise.
+     */
+    public boolean teardownIface(@NonNull String ifaceName) {
+        synchronized (mLock) {
+            if (mISupplicantStaIfaces.remove(ifaceName) == null) {
+                return false;
+            }
+            mISupplicantStaIfaceCallbacks.remove(ifaceName);
+            // TODO(b/69162019): There are no HIDL calls to bring down interfaces
+            // from wpa_supplicant yet!
+            return true;
+        }
+    }
+
+    private void clearState() {
+        synchronized (mLock) {
+            mISupplicant = null;
+            mISupplicantStaIfaces.clear();
+            mCurrentNetworkLocalConfigs.clear();
+            mCurrentNetworkRemoteHandles.clear();
+        }
+    }
+
+    private void supplicantServiceDiedHandler(@NonNull String ifaceName) {
+        synchronized (mLock) {
+            mWifiMonitor.broadcastSupplicantDisconnectionEvent(ifaceName);
+            clearState();
+        }
+    }
+
     private void supplicantServiceDiedHandler() {
         synchronized (mLock) {
-            mISupplicant = null;
-            mISupplicantStaIface = null;
-            mWifiMonitor.broadcastSupplicantDisconnectionEvent(mIfaceName);
+            if (mDeathEventHandler != null) {
+                mDeathEventHandler.onDeath();
+            }
+            for (String ifaceName : mISupplicantStaIfaces.keySet()) {
+                mWifiMonitor.broadcastSupplicantDisconnectionEvent(ifaceName);
+            }
+            clearState();
         }
     }
 
@@ -359,7 +434,7 @@
      */
     public boolean isInitializationComplete() {
         synchronized (mLock) {
-            return mISupplicantStaIface != null;
+            return mISupplicant != null;
         }
     }
 
@@ -385,6 +460,27 @@
     }
 
     /**
+     * Helper method to look up the network object for the specified iface.
+     */
+    private ISupplicantStaIface getStaIface(@NonNull String ifaceName) {
+        return mISupplicantStaIfaces.get(ifaceName);
+    }
+
+    /**
+     * Helper method to look up the network object for the specified iface.
+     */
+    private SupplicantStaNetworkHal getCurrentNetworkRemoteHandle(@NonNull String ifaceName) {
+        return mCurrentNetworkRemoteHandles.get(ifaceName);
+    }
+
+    /**
+     * Helper method to look up the network config or the specified iface.
+     */
+    private WifiConfiguration getCurrentNetworkLocalConfig(@NonNull String ifaceName) {
+        return mCurrentNetworkLocalConfigs.get(ifaceName);
+    }
+
+    /**
      * Add a network configuration to wpa_supplicant.
      *
      * @param config Config corresponding to the network.
@@ -392,14 +488,14 @@
      * for the current network.
      */
     private Pair<SupplicantStaNetworkHal, WifiConfiguration>
-            addNetworkAndSaveConfig(WifiConfiguration config) {
+            addNetworkAndSaveConfig(@NonNull String ifaceName, WifiConfiguration config) {
         synchronized (mLock) {
             logi("addSupplicantStaNetwork via HIDL");
             if (config == null) {
                 loge("Cannot add NULL network!");
                 return null;
             }
-            SupplicantStaNetworkHal network = addNetwork();
+            SupplicantStaNetworkHal network = addNetwork(ifaceName);
             if (network == null) {
                 loge("Failed to add a network!");
                 return null;
@@ -412,7 +508,7 @@
             }
             if (!saveSuccess) {
                 loge("Failed to save variables for: " + config.configKey());
-                if (!removeAllNetworks()) {
+                if (!removeAllNetworks(ifaceName)) {
                     loge("Failed to remove all networks on failure.");
                 }
                 return null;
@@ -428,47 +524,50 @@
      * networks and saves |config|.
      * 2. Select the new network in wpa_supplicant.
      *
+     * @param ifaceName Name of the interface.
      * @param config WifiConfiguration parameters for the provided network.
      * @return {@code true} if it succeeds, {@code false} otherwise
      */
-    public boolean connectToNetwork(@NonNull WifiConfiguration config) {
+    public boolean connectToNetwork(@NonNull String ifaceName, @NonNull WifiConfiguration config) {
         synchronized (mLock) {
             logd("connectToNetwork " + config.configKey());
-            if (WifiConfigurationUtil.isSameNetwork(config, mCurrentNetworkLocalConfig)) {
+            WifiConfiguration currentConfig = getCurrentNetworkLocalConfig(ifaceName);
+            if (WifiConfigurationUtil.isSameNetwork(config, currentConfig)) {
                 String networkSelectionBSSID = config.getNetworkSelectionStatus()
                         .getNetworkSelectionBSSID();
                 String networkSelectionBSSIDCurrent =
-                        mCurrentNetworkLocalConfig.getNetworkSelectionStatus()
-                                .getNetworkSelectionBSSID();
+                        currentConfig.getNetworkSelectionStatus().getNetworkSelectionBSSID();
                 if (Objects.equals(networkSelectionBSSID, networkSelectionBSSIDCurrent)) {
                     logd("Network is already saved, will not trigger remove and add operation.");
                 } else {
                     logd("Network is already saved, but need to update BSSID.");
                     if (!setCurrentNetworkBssid(
+                            ifaceName,
                             config.getNetworkSelectionStatus().getNetworkSelectionBSSID())) {
                         loge("Failed to set current network BSSID.");
                         return false;
                     }
-                    mCurrentNetworkLocalConfig = new WifiConfiguration(config);
+                    mCurrentNetworkLocalConfigs.put(ifaceName, new WifiConfiguration(config));
                 }
             } else {
-                mCurrentNetworkRemoteHandle = null;
-                mCurrentNetworkLocalConfig = null;
-                if (!removeAllNetworks()) {
+                mCurrentNetworkRemoteHandles.remove(ifaceName);
+                mCurrentNetworkLocalConfigs.remove(ifaceName);
+                if (!removeAllNetworks(ifaceName)) {
                     loge("Failed to remove existing networks");
                     return false;
                 }
                 Pair<SupplicantStaNetworkHal, WifiConfiguration> pair =
-                        addNetworkAndSaveConfig(config);
+                        addNetworkAndSaveConfig(ifaceName, config);
                 if (pair == null) {
                     loge("Failed to add/save network configuration: " + config.configKey());
                     return false;
                 }
-                mCurrentNetworkRemoteHandle = pair.first;
-                mCurrentNetworkLocalConfig = pair.second;
+                mCurrentNetworkRemoteHandles.put(ifaceName, pair.first);
+                mCurrentNetworkLocalConfigs.put(ifaceName, pair.second);
             }
-
-            if (!mCurrentNetworkRemoteHandle.select()) {
+            SupplicantStaNetworkHal networkHandle =
+                    checkSupplicantStaNetworkAndLogFailure(ifaceName, "connectToNetwork");
+            if (networkHandle == null || !networkHandle.select()) {
                 loge("Failed to select network configuration: " + config.configKey());
                 return false;
             }
@@ -485,23 +584,27 @@
      * 2. Set the new bssid for the network in wpa_supplicant.
      * 3. Trigger reassociate command to wpa_supplicant.
      *
+     * @param ifaceName Name of the interface.
      * @param config WifiConfiguration parameters for the provided network.
      * @return {@code true} if it succeeds, {@code false} otherwise
      */
-    public boolean roamToNetwork(WifiConfiguration config) {
+    public boolean roamToNetwork(@NonNull String ifaceName, WifiConfiguration config) {
         synchronized (mLock) {
-            if (getCurrentNetworkId() != config.networkId) {
+            if (getCurrentNetworkId(ifaceName) != config.networkId) {
                 Log.w(TAG, "Cannot roam to a different network, initiate new connection. "
-                        + "Current network ID: " + getCurrentNetworkId());
-                return connectToNetwork(config);
+                        + "Current network ID: " + getCurrentNetworkId(ifaceName));
+                return connectToNetwork(ifaceName, config);
             }
             String bssid = config.getNetworkSelectionStatus().getNetworkSelectionBSSID();
             logd("roamToNetwork" + config.configKey() + " (bssid " + bssid + ")");
-            if (!mCurrentNetworkRemoteHandle.setBssid(bssid)) {
+
+            SupplicantStaNetworkHal networkHandle =
+                    checkSupplicantStaNetworkAndLogFailure(ifaceName, "roamToNetwork");
+            if (networkHandle == null || !networkHandle.setBssid(bssid)) {
                 loge("Failed to set new bssid on network: " + config.configKey());
                 return false;
             }
-            if (!reassociate()) {
+            if (!reassociate(ifaceName)) {
                 loge("Failed to trigger reassociate");
                 return false;
             }
@@ -512,21 +615,22 @@
     /**
      * Load all the configured networks from wpa_supplicant.
      *
+     * @param ifaceName     Name of the interface.
      * @param configs       Map of configuration key to configuration objects corresponding to all
      *                      the networks.
      * @param networkExtras Map of extra configuration parameters stored in wpa_supplicant.conf
      * @return true if succeeds, false otherwise.
      */
-    public boolean loadNetworks(Map<String, WifiConfiguration> configs,
+    public boolean loadNetworks(@NonNull String ifaceName, Map<String, WifiConfiguration> configs,
                                 SparseArray<Map<String, String>> networkExtras) {
         synchronized (mLock) {
-            List<Integer> networkIds = listNetworks();
+            List<Integer> networkIds = listNetworks(ifaceName);
             if (networkIds == null) {
                 Log.e(TAG, "Failed to list networks");
                 return false;
             }
             for (Integer networkId : networkIds) {
-                SupplicantStaNetworkHal network = getNetwork(networkId);
+                SupplicantStaNetworkHal network = getNetwork(ifaceName, networkId);
                 if (network == null) {
                     Log.e(TAG, "Failed to get network with ID: " + networkId);
                     return false;
@@ -555,7 +659,7 @@
                 if (duplicateConfig != null) {
                     // The network is already known. Overwrite the duplicate entry.
                     Log.i(TAG, "Replacing duplicate network: " + duplicateConfig.networkId);
-                    removeNetwork(duplicateConfig.networkId);
+                    removeNetwork(ifaceName, duplicateConfig.networkId);
                     networkExtras.remove(duplicateConfig.networkId);
                 }
             }
@@ -567,37 +671,40 @@
      * Remove the request |networkId| from supplicant if it's the current network,
      * if the current configured network matches |networkId|.
      *
+     * @param ifaceName Name of the interface.
      * @param networkId network id of the network to be removed from supplicant.
      */
-    public void removeNetworkIfCurrent(int networkId) {
+    public void removeNetworkIfCurrent(@NonNull String ifaceName, int networkId) {
         synchronized (mLock) {
-            if (getCurrentNetworkId() == networkId) {
+            if (getCurrentNetworkId(ifaceName) == networkId) {
                 // Currently we only save 1 network in supplicant.
-                removeAllNetworks();
+                removeAllNetworks(ifaceName);
             }
         }
     }
 
     /**
      * Remove all networks from supplicant
+     *
+     * @param ifaceName Name of the interface.
      */
-    public boolean removeAllNetworks() {
+    public boolean removeAllNetworks(@NonNull String ifaceName) {
         synchronized (mLock) {
-            ArrayList<Integer> networks = listNetworks();
+            ArrayList<Integer> networks = listNetworks(ifaceName);
             if (networks == null) {
                 Log.e(TAG, "removeAllNetworks failed, got null networks");
                 return false;
             }
             for (int id : networks) {
-                if (!removeNetwork(id)) {
+                if (!removeNetwork(ifaceName, id)) {
                     Log.e(TAG, "removeAllNetworks failed to remove network: " + id);
                     return false;
                 }
             }
             // Reset current network info.  Probably not needed once we add support to remove/reset
             // current network on receiving disconnection event from supplicant (b/32898136).
-            mCurrentNetworkLocalConfig = null;
-            mCurrentNetworkRemoteHandle = null;
+            mCurrentNetworkRemoteHandles.remove(ifaceName);
+            mCurrentNetworkLocalConfigs.remove(ifaceName);
             return true;
         }
     }
@@ -605,113 +712,152 @@
     /**
      * Set the currently configured network's bssid.
      *
+     * @param ifaceName Name of the interface.
      * @param bssidStr Bssid to set in the form of "XX:XX:XX:XX:XX:XX"
      * @return true if succeeds, false otherwise.
      */
-    public boolean setCurrentNetworkBssid(String bssidStr) {
+    public boolean setCurrentNetworkBssid(@NonNull String ifaceName, String bssidStr) {
         synchronized (mLock) {
-            if (mCurrentNetworkRemoteHandle == null) return false;
-            return mCurrentNetworkRemoteHandle.setBssid(bssidStr);
+            SupplicantStaNetworkHal networkHandle =
+                    checkSupplicantStaNetworkAndLogFailure(ifaceName, "setCurrentNetworkBssid");
+            if (networkHandle == null) return false;
+            return networkHandle.setBssid(bssidStr);
         }
     }
 
     /**
      * Get the currently configured network's WPS NFC token.
      *
+     * @param ifaceName Name of the interface.
      * @return Hex string corresponding to the WPS NFC token.
      */
-    public String getCurrentNetworkWpsNfcConfigurationToken() {
+    public String getCurrentNetworkWpsNfcConfigurationToken(@NonNull String ifaceName) {
         synchronized (mLock) {
-            if (mCurrentNetworkRemoteHandle == null) return null;
-            return mCurrentNetworkRemoteHandle.getWpsNfcConfigurationToken();
+            SupplicantStaNetworkHal networkHandle =
+                    checkSupplicantStaNetworkAndLogFailure(
+                            ifaceName, "getCurrentNetworkWpsNfcConfigurationToken");
+            if (networkHandle == null) return null;
+            return networkHandle.getWpsNfcConfigurationToken();
         }
     }
 
     /**
      * Get the eap anonymous identity for the currently configured network.
      *
+     * @param ifaceName Name of the interface.
      * @return anonymous identity string if succeeds, null otherwise.
      */
-    public String getCurrentNetworkEapAnonymousIdentity() {
+    public String getCurrentNetworkEapAnonymousIdentity(@NonNull String ifaceName) {
         synchronized (mLock) {
-            if (mCurrentNetworkRemoteHandle == null) return null;
-            return mCurrentNetworkRemoteHandle.fetchEapAnonymousIdentity();
+            SupplicantStaNetworkHal networkHandle =
+                    checkSupplicantStaNetworkAndLogFailure(
+                            ifaceName, "getCurrentNetworkEapAnonymousIdentity");
+            if (networkHandle == null) return null;
+            return networkHandle.fetchEapAnonymousIdentity();
         }
     }
 
     /**
      * Send the eap identity response for the currently configured network.
      *
+     * @param ifaceName Name of the interface.
      * @param identityStr String to send.
      * @return true if succeeds, false otherwise.
      */
-    public boolean sendCurrentNetworkEapIdentityResponse(String identityStr) {
+    public boolean sendCurrentNetworkEapIdentityResponse(
+            @NonNull String ifaceName, String identityStr) {
         synchronized (mLock) {
-            if (mCurrentNetworkRemoteHandle == null) return false;
-            return mCurrentNetworkRemoteHandle.sendNetworkEapIdentityResponse(identityStr);
+            SupplicantStaNetworkHal networkHandle =
+                    checkSupplicantStaNetworkAndLogFailure(
+                            ifaceName, "sendCurrentNetworkEapIdentityResponse");
+            if (networkHandle == null) return false;
+            return networkHandle.sendNetworkEapIdentityResponse(identityStr);
         }
     }
 
     /**
      * Send the eap sim gsm auth response for the currently configured network.
      *
+     * @param ifaceName Name of the interface.
      * @param paramsStr String to send.
      * @return true if succeeds, false otherwise.
      */
-    public boolean sendCurrentNetworkEapSimGsmAuthResponse(String paramsStr) {
+    public boolean sendCurrentNetworkEapSimGsmAuthResponse(
+            @NonNull String ifaceName, String paramsStr) {
         synchronized (mLock) {
-            if (mCurrentNetworkRemoteHandle == null) return false;
-            return mCurrentNetworkRemoteHandle.sendNetworkEapSimGsmAuthResponse(paramsStr);
+            SupplicantStaNetworkHal networkHandle =
+                    checkSupplicantStaNetworkAndLogFailure(
+                            ifaceName, "sendCurrentNetworkEapSimGsmAuthResponse");
+            if (networkHandle == null) return false;
+            return networkHandle.sendNetworkEapSimGsmAuthResponse(paramsStr);
         }
     }
 
     /**
      * Send the eap sim gsm auth failure for the currently configured network.
      *
+     * @param ifaceName Name of the interface.
      * @return true if succeeds, false otherwise.
      */
-    public boolean sendCurrentNetworkEapSimGsmAuthFailure() {
+    public boolean sendCurrentNetworkEapSimGsmAuthFailure(@NonNull String ifaceName) {
         synchronized (mLock) {
-            if (mCurrentNetworkRemoteHandle == null) return false;
-            return mCurrentNetworkRemoteHandle.sendNetworkEapSimGsmAuthFailure();
+            SupplicantStaNetworkHal networkHandle =
+                    checkSupplicantStaNetworkAndLogFailure(
+                            ifaceName, "sendCurrentNetworkEapSimGsmAuthFailure");
+            if (networkHandle == null) return false;
+            return networkHandle.sendNetworkEapSimGsmAuthFailure();
         }
     }
 
     /**
      * Send the eap sim umts auth response for the currently configured network.
      *
+     * @param ifaceName Name of the interface.
      * @param paramsStr String to send.
      * @return true if succeeds, false otherwise.
      */
-    public boolean sendCurrentNetworkEapSimUmtsAuthResponse(String paramsStr) {
+    public boolean sendCurrentNetworkEapSimUmtsAuthResponse(
+            @NonNull String ifaceName, String paramsStr) {
         synchronized (mLock) {
-            if (mCurrentNetworkRemoteHandle == null) return false;
-            return mCurrentNetworkRemoteHandle.sendNetworkEapSimUmtsAuthResponse(paramsStr);
+            SupplicantStaNetworkHal networkHandle =
+                    checkSupplicantStaNetworkAndLogFailure(
+                            ifaceName, "sendCurrentNetworkEapSimUmtsAuthResponse");
+            if (networkHandle == null) return false;
+            return networkHandle.sendNetworkEapSimUmtsAuthResponse(paramsStr);
         }
     }
 
     /**
      * Send the eap sim umts auts response for the currently configured network.
      *
+     * @param ifaceName Name of the interface.
      * @param paramsStr String to send.
      * @return true if succeeds, false otherwise.
      */
-    public boolean sendCurrentNetworkEapSimUmtsAutsResponse(String paramsStr) {
+    public boolean sendCurrentNetworkEapSimUmtsAutsResponse(
+            @NonNull String ifaceName, String paramsStr) {
         synchronized (mLock) {
-            if (mCurrentNetworkRemoteHandle == null) return false;
-            return mCurrentNetworkRemoteHandle.sendNetworkEapSimUmtsAutsResponse(paramsStr);
+            SupplicantStaNetworkHal networkHandle =
+                    checkSupplicantStaNetworkAndLogFailure(
+                            ifaceName, "sendCurrentNetworkEapSimUmtsAutsResponse");
+            if (networkHandle == null) return false;
+            return networkHandle.sendNetworkEapSimUmtsAutsResponse(paramsStr);
         }
     }
 
     /**
      * Send the eap sim umts auth failure for the currently configured network.
      *
+     * @param ifaceName Name of the interface.
      * @return true if succeeds, false otherwise.
      */
-    public boolean sendCurrentNetworkEapSimUmtsAuthFailure() {
+    public boolean sendCurrentNetworkEapSimUmtsAuthFailure(@NonNull String ifaceName) {
         synchronized (mLock) {
-            if (mCurrentNetworkRemoteHandle == null) return false;
-            return mCurrentNetworkRemoteHandle.sendNetworkEapSimUmtsAuthFailure();
+            SupplicantStaNetworkHal networkHandle =
+                    checkSupplicantStaNetworkAndLogFailure(
+                            ifaceName, "sendCurrentNetworkEapSimUmtsAuthFailure");
+            if (networkHandle == null) return false;
+            return networkHandle.sendNetworkEapSimUmtsAuthFailure();
         }
     }
 
@@ -720,13 +866,14 @@
      *
      * @return The ISupplicantNetwork object for the new network, or null if the call fails
      */
-    private SupplicantStaNetworkHal addNetwork() {
+    private SupplicantStaNetworkHal addNetwork(@NonNull String ifaceName) {
         synchronized (mLock) {
             final String methodStr = "addNetwork";
-            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return null;
+            ISupplicantStaIface iface = checkSupplicantStaIfaceAndLogFailure(ifaceName, methodStr);
+            if (iface == null) return null;
             Mutable<ISupplicantNetwork> newNetwork = new Mutable<>();
             try {
-                mISupplicantStaIface.addNetwork((SupplicantStatus status,
+                iface.addNetwork((SupplicantStatus status,
                         ISupplicantNetwork network) -> {
                     if (checkStatusAndLogFailure(status, methodStr)) {
                         newNetwork.value = network;
@@ -737,6 +884,7 @@
             }
             if (newNetwork.value != null) {
                 return getStaNetworkMockable(
+                        ifaceName,
                         ISupplicantStaNetwork.asInterface(newNetwork.value.asBinder()));
             } else {
                 return null;
@@ -749,12 +897,13 @@
      *
      * @return true if request is sent successfully, false otherwise.
      */
-    private boolean removeNetwork(int id) {
+    private boolean removeNetwork(@NonNull String ifaceName, int id) {
         synchronized (mLock) {
             final String methodStr = "removeNetwork";
-            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
+            ISupplicantStaIface iface = checkSupplicantStaIfaceAndLogFailure(ifaceName, methodStr);
+            if (iface == null) return false;
             try {
-                SupplicantStatus status = mISupplicantStaIface.removeNetwork(id);
+                SupplicantStatus status = iface.removeNetwork(id);
                 return checkStatusAndLogFailure(status, methodStr);
             } catch (RemoteException e) {
                 handleRemoteException(e, methodStr);
@@ -766,15 +915,16 @@
     /**
      * Use this to mock the creation of SupplicantStaNetworkHal instance.
      *
+     * @param ifaceName Name of the interface.
      * @param iSupplicantStaNetwork ISupplicantStaNetwork instance retrieved from HIDL.
      * @return The ISupplicantNetwork object for the given SupplicantNetworkId int, returns null if
      * the call fails
      */
     protected SupplicantStaNetworkHal getStaNetworkMockable(
-            ISupplicantStaNetwork iSupplicantStaNetwork) {
+            @NonNull String ifaceName, ISupplicantStaNetwork iSupplicantStaNetwork) {
         synchronized (mLock) {
             SupplicantStaNetworkHal network =
-                    new SupplicantStaNetworkHal(iSupplicantStaNetwork, mIfaceName, mContext,
+                    new SupplicantStaNetworkHal(iSupplicantStaNetwork, ifaceName, mContext,
                             mWifiMonitor);
             if (network != null) {
                 network.enableVerboseLogging(mVerboseLoggingEnabled);
@@ -787,14 +937,14 @@
      * @return The ISupplicantNetwork object for the given SupplicantNetworkId int, returns null if
      * the call fails
      */
-    private SupplicantStaNetworkHal getNetwork(int id) {
+    private SupplicantStaNetworkHal getNetwork(@NonNull String ifaceName, int id) {
         synchronized (mLock) {
             final String methodStr = "getNetwork";
+            ISupplicantStaIface iface = checkSupplicantStaIfaceAndLogFailure(ifaceName, methodStr);
+            if (iface == null) return null;
             Mutable<ISupplicantNetwork> gotNetwork = new Mutable<>();
-            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return null;
             try {
-                mISupplicantStaIface.getNetwork(id, (SupplicantStatus status,
-                        ISupplicantNetwork network) -> {
+                iface.getNetwork(id, (SupplicantStatus status, ISupplicantNetwork network) -> {
                     if (checkStatusAndLogFailure(status, methodStr)) {
                         gotNetwork.value = network;
                     }
@@ -804,6 +954,7 @@
             }
             if (gotNetwork.value != null) {
                 return getStaNetworkMockable(
+                        ifaceName,
                         ISupplicantStaNetwork.asInterface(gotNetwork.value.asBinder()));
             } else {
                 return null;
@@ -812,12 +963,13 @@
     }
 
     /** See ISupplicantStaNetwork.hal for documentation */
-    private boolean registerCallback(ISupplicantStaIfaceCallback callback) {
+    private boolean registerCallback(
+            ISupplicantStaIface iface, ISupplicantStaIfaceCallback callback) {
         synchronized (mLock) {
             final String methodStr = "registerCallback";
-            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
+            if (iface == null) return false;
             try {
-                SupplicantStatus status =  mISupplicantStaIface.registerCallback(callback);
+                SupplicantStatus status =  iface.registerCallback(callback);
                 return checkStatusAndLogFailure(status, methodStr);
             } catch (RemoteException e) {
                 handleRemoteException(e, methodStr);
@@ -830,14 +982,14 @@
      * @return a list of SupplicantNetworkID ints for all networks controlled by supplicant, returns
      * null if the call fails
      */
-    private java.util.ArrayList<Integer> listNetworks() {
+    private java.util.ArrayList<Integer> listNetworks(@NonNull String ifaceName) {
         synchronized (mLock) {
             final String methodStr = "listNetworks";
+            ISupplicantStaIface iface = checkSupplicantStaIfaceAndLogFailure(ifaceName, methodStr);
+            if (iface == null) return null;
             Mutable<ArrayList<Integer>> networkIdList = new Mutable<>();
-            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return null;
             try {
-                mISupplicantStaIface.listNetworks((SupplicantStatus status,
-                        java.util.ArrayList<Integer> networkIds) -> {
+                iface.listNetworks((SupplicantStatus status, ArrayList<Integer> networkIds) -> {
                     if (checkStatusAndLogFailure(status, methodStr)) {
                         networkIdList.value = networkIds;
                     }
@@ -852,15 +1004,17 @@
     /**
      * Set WPS device name.
      *
+     * @param ifaceName Name of the interface.
      * @param name String to be set.
      * @return true if request is sent successfully, false otherwise.
      */
-    public boolean setWpsDeviceName(String name) {
+    public boolean setWpsDeviceName(@NonNull String ifaceName, String name) {
         synchronized (mLock) {
             final String methodStr = "setWpsDeviceName";
-            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
+            ISupplicantStaIface iface = checkSupplicantStaIfaceAndLogFailure(ifaceName, methodStr);
+            if (iface == null) return false;
             try {
-                SupplicantStatus status = mISupplicantStaIface.setWpsDeviceName(name);
+                SupplicantStatus status = iface.setWpsDeviceName(name);
                 return checkStatusAndLogFailure(status, methodStr);
             } catch (RemoteException e) {
                 handleRemoteException(e, methodStr);
@@ -872,10 +1026,11 @@
     /**
      * Set WPS device type.
      *
+     * @param ifaceName Name of the interface.
      * @param typeStr Type specified as a string. Used format: <categ>-<OUI>-<subcateg>
      * @return true if request is sent successfully, false otherwise.
      */
-    public boolean setWpsDeviceType(String typeStr) {
+    public boolean setWpsDeviceType(@NonNull String ifaceName, String typeStr) {
         synchronized (mLock) {
             try {
                 Matcher match = WPS_DEVICE_TYPE_PATTERN.matcher(typeStr);
@@ -892,7 +1047,7 @@
                 byteBuffer.putShort(categ);
                 byteBuffer.put(oui);
                 byteBuffer.putShort(subCateg);
-                return setWpsDeviceType(bytes);
+                return setWpsDeviceType(ifaceName, bytes);
             } catch (IllegalArgumentException e) {
                 Log.e(TAG, "Illegal argument " + typeStr, e);
                 return false;
@@ -900,12 +1055,13 @@
         }
     }
 
-    private boolean setWpsDeviceType(byte[/* 8 */] type) {
+    private boolean setWpsDeviceType(@NonNull String ifaceName, byte[/* 8 */] type) {
         synchronized (mLock) {
             final String methodStr = "setWpsDeviceType";
-            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
+            ISupplicantStaIface iface = checkSupplicantStaIfaceAndLogFailure(ifaceName, methodStr);
+            if (iface == null) return false;
             try {
-                SupplicantStatus status = mISupplicantStaIface.setWpsDeviceType(type);
+                SupplicantStatus status = iface.setWpsDeviceType(type);
                 return checkStatusAndLogFailure(status, methodStr);
             } catch (RemoteException e) {
                 handleRemoteException(e, methodStr);
@@ -917,15 +1073,17 @@
     /**
      * Set WPS manufacturer.
      *
+     * @param ifaceName Name of the interface.
      * @param manufacturer String to be set.
      * @return true if request is sent successfully, false otherwise.
      */
-    public boolean setWpsManufacturer(String manufacturer) {
+    public boolean setWpsManufacturer(@NonNull String ifaceName, String manufacturer) {
         synchronized (mLock) {
             final String methodStr = "setWpsManufacturer";
-            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
+            ISupplicantStaIface iface = checkSupplicantStaIfaceAndLogFailure(ifaceName, methodStr);
+            if (iface == null) return false;
             try {
-                SupplicantStatus status = mISupplicantStaIface.setWpsManufacturer(manufacturer);
+                SupplicantStatus status = iface.setWpsManufacturer(manufacturer);
                 return checkStatusAndLogFailure(status, methodStr);
             } catch (RemoteException e) {
                 handleRemoteException(e, methodStr);
@@ -937,15 +1095,17 @@
     /**
      * Set WPS model name.
      *
+     * @param ifaceName Name of the interface.
      * @param modelName String to be set.
      * @return true if request is sent successfully, false otherwise.
      */
-    public boolean setWpsModelName(String modelName) {
+    public boolean setWpsModelName(@NonNull String ifaceName, String modelName) {
         synchronized (mLock) {
             final String methodStr = "setWpsModelName";
-            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
+            ISupplicantStaIface iface = checkSupplicantStaIfaceAndLogFailure(ifaceName, methodStr);
+            if (iface == null) return false;
             try {
-                SupplicantStatus status = mISupplicantStaIface.setWpsModelName(modelName);
+                SupplicantStatus status = iface.setWpsModelName(modelName);
                 return checkStatusAndLogFailure(status, methodStr);
             } catch (RemoteException e) {
                 handleRemoteException(e, methodStr);
@@ -957,15 +1117,17 @@
     /**
      * Set WPS model number.
      *
+     * @param ifaceName Name of the interface.
      * @param modelNumber String to be set.
      * @return true if request is sent successfully, false otherwise.
      */
-    public boolean setWpsModelNumber(String modelNumber) {
+    public boolean setWpsModelNumber(@NonNull String ifaceName, String modelNumber) {
         synchronized (mLock) {
             final String methodStr = "setWpsModelNumber";
-            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
+            ISupplicantStaIface iface = checkSupplicantStaIfaceAndLogFailure(ifaceName, methodStr);
+            if (iface == null) return false;
             try {
-                SupplicantStatus status = mISupplicantStaIface.setWpsModelNumber(modelNumber);
+                SupplicantStatus status = iface.setWpsModelNumber(modelNumber);
                 return checkStatusAndLogFailure(status, methodStr);
             } catch (RemoteException e) {
                 handleRemoteException(e, methodStr);
@@ -977,15 +1139,17 @@
     /**
      * Set WPS serial number.
      *
+     * @param ifaceName Name of the interface.
      * @param serialNumber String to be set.
      * @return true if request is sent successfully, false otherwise.
      */
-    public boolean setWpsSerialNumber(String serialNumber) {
+    public boolean setWpsSerialNumber(@NonNull String ifaceName, String serialNumber) {
         synchronized (mLock) {
             final String methodStr = "setWpsSerialNumber";
-            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
+            ISupplicantStaIface iface = checkSupplicantStaIfaceAndLogFailure(ifaceName, methodStr);
+            if (iface == null) return false;
             try {
-                SupplicantStatus status = mISupplicantStaIface.setWpsSerialNumber(serialNumber);
+                SupplicantStatus status = iface.setWpsSerialNumber(serialNumber);
                 return checkStatusAndLogFailure(status, methodStr);
             } catch (RemoteException e) {
                 handleRemoteException(e, methodStr);
@@ -997,26 +1161,28 @@
     /**
      * Set WPS config methods
      *
+     * @param ifaceName Name of the interface.
      * @param configMethodsStr List of config methods.
      * @return true if request is sent successfully, false otherwise.
      */
-    public boolean setWpsConfigMethods(String configMethodsStr) {
+    public boolean setWpsConfigMethods(@NonNull String ifaceName, String configMethodsStr) {
         synchronized (mLock) {
             short configMethodsMask = 0;
             String[] configMethodsStrArr = configMethodsStr.split("\\s+");
             for (int i = 0; i < configMethodsStrArr.length; i++) {
                 configMethodsMask |= stringToWpsConfigMethod(configMethodsStrArr[i]);
             }
-            return setWpsConfigMethods(configMethodsMask);
+            return setWpsConfigMethods(ifaceName, configMethodsMask);
         }
     }
 
-    private boolean setWpsConfigMethods(short configMethods) {
+    private boolean setWpsConfigMethods(@NonNull String ifaceName, short configMethods) {
         synchronized (mLock) {
             final String methodStr = "setWpsConfigMethods";
-            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
+            ISupplicantStaIface iface = checkSupplicantStaIfaceAndLogFailure(ifaceName, methodStr);
+            if (iface == null) return false;
             try {
-                SupplicantStatus status = mISupplicantStaIface.setWpsConfigMethods(configMethods);
+                SupplicantStatus status = iface.setWpsConfigMethods(configMethods);
                 return checkStatusAndLogFailure(status, methodStr);
             } catch (RemoteException e) {
                 handleRemoteException(e, methodStr);
@@ -1028,14 +1194,16 @@
     /**
      * Trigger a reassociation even if the iface is currently connected.
      *
+     * @param ifaceName Name of the interface.
      * @return true if request is sent successfully, false otherwise.
      */
-    public boolean reassociate() {
+    public boolean reassociate(@NonNull String ifaceName) {
         synchronized (mLock) {
             final String methodStr = "reassociate";
-            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
+            ISupplicantStaIface iface = checkSupplicantStaIfaceAndLogFailure(ifaceName, methodStr);
+            if (iface == null) return false;
             try {
-                SupplicantStatus status = mISupplicantStaIface.reassociate();
+                SupplicantStatus status = iface.reassociate();
                 return checkStatusAndLogFailure(status, methodStr);
             } catch (RemoteException e) {
                 handleRemoteException(e, methodStr);
@@ -1047,14 +1215,16 @@
     /**
      * Trigger a reconnection if the iface is disconnected.
      *
+     * @param ifaceName Name of the interface.
      * @return true if request is sent successfully, false otherwise.
      */
-    public boolean reconnect() {
+    public boolean reconnect(@NonNull String ifaceName) {
         synchronized (mLock) {
             final String methodStr = "reconnect";
-            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
+            ISupplicantStaIface iface = checkSupplicantStaIfaceAndLogFailure(ifaceName, methodStr);
+            if (iface == null) return false;
             try {
-                SupplicantStatus status = mISupplicantStaIface.reconnect();
+                SupplicantStatus status = iface.reconnect();
                 return checkStatusAndLogFailure(status, methodStr);
             } catch (RemoteException e) {
                 handleRemoteException(e, methodStr);
@@ -1066,14 +1236,16 @@
     /**
      * Trigger a disconnection from the currently connected network.
      *
+     * @param ifaceName Name of the interface.
      * @return true if request is sent successfully, false otherwise.
      */
-    public boolean disconnect() {
+    public boolean disconnect(@NonNull String ifaceName) {
         synchronized (mLock) {
             final String methodStr = "disconnect";
-            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
+            ISupplicantStaIface iface = checkSupplicantStaIfaceAndLogFailure(ifaceName, methodStr);
+            if (iface == null) return false;
             try {
-                SupplicantStatus status = mISupplicantStaIface.disconnect();
+                SupplicantStatus status = iface.disconnect();
                 return checkStatusAndLogFailure(status, methodStr);
             } catch (RemoteException e) {
                 handleRemoteException(e, methodStr);
@@ -1085,15 +1257,17 @@
     /**
      * Enable or disable power save mode.
      *
+     * @param ifaceName Name of the interface.
      * @param enable true to enable, false to disable.
      * @return true if request is sent successfully, false otherwise.
      */
-    public boolean setPowerSave(boolean enable) {
+    public boolean setPowerSave(@NonNull String ifaceName, boolean enable) {
         synchronized (mLock) {
             final String methodStr = "setPowerSave";
-            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
+            ISupplicantStaIface iface = checkSupplicantStaIfaceAndLogFailure(ifaceName, methodStr);
+            if (iface == null) return false;
             try {
-                SupplicantStatus status = mISupplicantStaIface.setPowerSave(enable);
+                SupplicantStatus status = iface.setPowerSave(enable);
                 return checkStatusAndLogFailure(status, methodStr);
             } catch (RemoteException e) {
                 handleRemoteException(e, methodStr);
@@ -1105,13 +1279,15 @@
     /**
      * Initiate TDLS discover with the specified AP.
      *
+     * @param ifaceName Name of the interface.
      * @param macAddress MAC Address of the AP.
      * @return true if request is sent successfully, false otherwise.
      */
-    public boolean initiateTdlsDiscover(String macAddress) {
+    public boolean initiateTdlsDiscover(@NonNull String ifaceName, String macAddress) {
         synchronized (mLock) {
             try {
-                return initiateTdlsDiscover(NativeUtil.macAddressToByteArray(macAddress));
+                return initiateTdlsDiscover(
+                        ifaceName, NativeUtil.macAddressToByteArray(macAddress));
             } catch (IllegalArgumentException e) {
                 Log.e(TAG, "Illegal argument " + macAddress, e);
                 return false;
@@ -1119,12 +1295,13 @@
         }
     }
     /** See ISupplicantStaIface.hal for documentation */
-    private boolean initiateTdlsDiscover(byte[/* 6 */] macAddress) {
+    private boolean initiateTdlsDiscover(@NonNull String ifaceName, byte[/* 6 */] macAddress) {
         synchronized (mLock) {
             final String methodStr = "initiateTdlsDiscover";
-            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
+            ISupplicantStaIface iface = checkSupplicantStaIfaceAndLogFailure(ifaceName, methodStr);
+            if (iface == null) return false;
             try {
-                SupplicantStatus status = mISupplicantStaIface.initiateTdlsDiscover(macAddress);
+                SupplicantStatus status = iface.initiateTdlsDiscover(macAddress);
                 return checkStatusAndLogFailure(status, methodStr);
             } catch (RemoteException e) {
                 handleRemoteException(e, methodStr);
@@ -1136,13 +1313,14 @@
     /**
      * Initiate TDLS setup with the specified AP.
      *
+     * @param ifaceName Name of the interface.
      * @param macAddress MAC Address of the AP.
      * @return true if request is sent successfully, false otherwise.
      */
-    public boolean initiateTdlsSetup(String macAddress) {
+    public boolean initiateTdlsSetup(@NonNull String ifaceName, String macAddress) {
         synchronized (mLock) {
             try {
-                return initiateTdlsSetup(NativeUtil.macAddressToByteArray(macAddress));
+                return initiateTdlsSetup(ifaceName, NativeUtil.macAddressToByteArray(macAddress));
             } catch (IllegalArgumentException e) {
                 Log.e(TAG, "Illegal argument " + macAddress, e);
                 return false;
@@ -1150,12 +1328,13 @@
         }
     }
     /** See ISupplicantStaIface.hal for documentation */
-    private boolean initiateTdlsSetup(byte[/* 6 */] macAddress) {
+    private boolean initiateTdlsSetup(@NonNull String ifaceName, byte[/* 6 */] macAddress) {
         synchronized (mLock) {
             final String methodStr = "initiateTdlsSetup";
-            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
+            ISupplicantStaIface iface = checkSupplicantStaIfaceAndLogFailure(ifaceName, methodStr);
+            if (iface == null) return false;
             try {
-                SupplicantStatus status = mISupplicantStaIface.initiateTdlsSetup(macAddress);
+                SupplicantStatus status = iface.initiateTdlsSetup(macAddress);
                 return checkStatusAndLogFailure(status, methodStr);
             } catch (RemoteException e) {
                 handleRemoteException(e, methodStr);
@@ -1166,13 +1345,15 @@
 
     /**
      * Initiate TDLS teardown with the specified AP.
+     * @param ifaceName Name of the interface.
      * @param macAddress MAC Address of the AP.
      * @return true if request is sent successfully, false otherwise.
      */
-    public boolean initiateTdlsTeardown(String macAddress) {
+    public boolean initiateTdlsTeardown(@NonNull String ifaceName, String macAddress) {
         synchronized (mLock) {
             try {
-                return initiateTdlsTeardown(NativeUtil.macAddressToByteArray(macAddress));
+                return initiateTdlsTeardown(
+                        ifaceName, NativeUtil.macAddressToByteArray(macAddress));
             } catch (IllegalArgumentException e) {
                 Log.e(TAG, "Illegal argument " + macAddress, e);
                 return false;
@@ -1181,12 +1362,13 @@
     }
 
     /** See ISupplicantStaIface.hal for documentation */
-    private boolean initiateTdlsTeardown(byte[/* 6 */] macAddress) {
+    private boolean initiateTdlsTeardown(@NonNull String ifaceName, byte[/* 6 */] macAddress) {
         synchronized (mLock) {
             final String methodStr = "initiateTdlsTeardown";
-            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
+            ISupplicantStaIface iface = checkSupplicantStaIfaceAndLogFailure(ifaceName, methodStr);
+            if (iface == null) return false;
             try {
-                SupplicantStatus status = mISupplicantStaIface.initiateTdlsTeardown(macAddress);
+                SupplicantStatus status = iface.initiateTdlsTeardown(macAddress);
                 return checkStatusAndLogFailure(status, methodStr);
             } catch (RemoteException e) {
                 handleRemoteException(e, methodStr);
@@ -1198,16 +1380,19 @@
     /**
      * Request the specified ANQP elements |elements| from the specified AP |bssid|.
      *
+     * @param ifaceName Name of the interface.
      * @param bssid BSSID of the AP
      * @param infoElements ANQP elements to be queried. Refer to ISupplicantStaIface.AnqpInfoId.
      * @param hs20SubTypes HS subtypes to be queried. Refer to ISupplicantStaIface.Hs20AnqpSubTypes.
      * @return true if request is sent successfully, false otherwise.
      */
-    public boolean initiateAnqpQuery(String bssid, ArrayList<Short> infoElements,
+    public boolean initiateAnqpQuery(@NonNull String ifaceName, String bssid,
+                                     ArrayList<Short> infoElements,
                                      ArrayList<Integer> hs20SubTypes) {
         synchronized (mLock) {
             try {
                 return initiateAnqpQuery(
+                        ifaceName,
                         NativeUtil.macAddressToByteArray(bssid), infoElements, hs20SubTypes);
             } catch (IllegalArgumentException e) {
                 Log.e(TAG, "Illegal argument " + bssid, e);
@@ -1217,14 +1402,15 @@
     }
 
     /** See ISupplicantStaIface.hal for documentation */
-    private boolean initiateAnqpQuery(byte[/* 6 */] macAddress,
+    private boolean initiateAnqpQuery(@NonNull String ifaceName, byte[/* 6 */] macAddress,
             java.util.ArrayList<Short> infoElements, java.util.ArrayList<Integer> subTypes) {
         synchronized (mLock) {
             final String methodStr = "initiateAnqpQuery";
-            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
+            ISupplicantStaIface iface = checkSupplicantStaIfaceAndLogFailure(ifaceName, methodStr);
+            if (iface == null) return false;
             try {
-                SupplicantStatus status = mISupplicantStaIface.initiateAnqpQuery(macAddress,
-                        infoElements, subTypes);
+                SupplicantStatus status = iface.initiateAnqpQuery(
+                        macAddress, infoElements, subTypes);
                 return checkStatusAndLogFailure(status, methodStr);
             } catch (RemoteException e) {
                 handleRemoteException(e, methodStr);
@@ -1236,14 +1422,16 @@
     /**
      * Request the specified ANQP ICON from the specified AP |bssid|.
      *
+     * @param ifaceName Name of the interface.
      * @param bssid BSSID of the AP
      * @param fileName Name of the file to request.
      * @return true if request is sent successfully, false otherwise.
      */
-    public boolean initiateHs20IconQuery(String bssid, String fileName) {
+    public boolean initiateHs20IconQuery(@NonNull String ifaceName, String bssid, String fileName) {
         synchronized (mLock) {
             try {
-                return initiateHs20IconQuery(NativeUtil.macAddressToByteArray(bssid), fileName);
+                return initiateHs20IconQuery(
+                        ifaceName, NativeUtil.macAddressToByteArray(bssid), fileName);
             } catch (IllegalArgumentException e) {
                 Log.e(TAG, "Illegal argument " + bssid, e);
                 return false;
@@ -1252,13 +1440,14 @@
     }
 
     /** See ISupplicantStaIface.hal for documentation */
-    private boolean initiateHs20IconQuery(byte[/* 6 */] macAddress, String fileName) {
+    private boolean initiateHs20IconQuery(@NonNull String ifaceName,
+                                          byte[/* 6 */] macAddress, String fileName) {
         synchronized (mLock) {
             final String methodStr = "initiateHs20IconQuery";
-            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
+            ISupplicantStaIface iface = checkSupplicantStaIfaceAndLogFailure(ifaceName, methodStr);
+            if (iface == null) return false;
             try {
-                SupplicantStatus status = mISupplicantStaIface.initiateHs20IconQuery(macAddress,
-                        fileName);
+                SupplicantStatus status = iface.initiateHs20IconQuery(macAddress, fileName);
                 return checkStatusAndLogFailure(status, methodStr);
             } catch (RemoteException e) {
                 handleRemoteException(e, methodStr);
@@ -1270,15 +1459,17 @@
     /**
      * Makes a callback to HIDL to getMacAddress from supplicant
      *
+     * @param ifaceName Name of the interface.
      * @return string containing the MAC address, or null on a failed call
      */
-    public String getMacAddress() {
+    public String getMacAddress(@NonNull String ifaceName) {
         synchronized (mLock) {
             final String methodStr = "getMacAddress";
-            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return null;
+            ISupplicantStaIface iface = checkSupplicantStaIfaceAndLogFailure(ifaceName, methodStr);
+            if (iface == null) return null;
             Mutable<String> gotMac = new Mutable<>();
             try {
-                mISupplicantStaIface.getMacAddress((SupplicantStatus status,
+                iface.getMacAddress((SupplicantStatus status,
                         byte[/* 6 */] macAddr) -> {
                     if (checkStatusAndLogFailure(status, methodStr)) {
                         gotMac.value = NativeUtil.macAddressFromByteArray(macAddr);
@@ -1294,14 +1485,16 @@
     /**
      * Start using the added RX filters.
      *
+     * @param ifaceName Name of the interface.
      * @return true if request is sent successfully, false otherwise.
      */
-    public boolean startRxFilter() {
+    public boolean startRxFilter(@NonNull String ifaceName) {
         synchronized (mLock) {
             final String methodStr = "startRxFilter";
-            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
+            ISupplicantStaIface iface = checkSupplicantStaIfaceAndLogFailure(ifaceName, methodStr);
+            if (iface == null) return false;
             try {
-                SupplicantStatus status = mISupplicantStaIface.startRxFilter();
+                SupplicantStatus status = iface.startRxFilter();
                 return checkStatusAndLogFailure(status, methodStr);
             } catch (RemoteException e) {
                 handleRemoteException(e, methodStr);
@@ -1313,14 +1506,16 @@
     /**
      * Stop using the added RX filters.
      *
+     * @param ifaceName Name of the interface.
      * @return true if request is sent successfully, false otherwise.
      */
-    public boolean stopRxFilter() {
+    public boolean stopRxFilter(@NonNull String ifaceName) {
         synchronized (mLock) {
             final String methodStr = "stopRxFilter";
-            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
+            ISupplicantStaIface iface = checkSupplicantStaIfaceAndLogFailure(ifaceName, methodStr);
+            if (iface == null) return false;
             try {
-                SupplicantStatus status = mISupplicantStaIface.stopRxFilter();
+                SupplicantStatus status = iface.stopRxFilter();
                 return checkStatusAndLogFailure(status, methodStr);
             } catch (RemoteException e) {
                 handleRemoteException(e, methodStr);
@@ -1332,11 +1527,12 @@
     /**
      * Add an RX filter.
      *
+     * @param ifaceName Name of the interface.
      * @param type one of {@link WifiNative#RX_FILTER_TYPE_V4_MULTICAST}
      *        {@link WifiNative#RX_FILTER_TYPE_V6_MULTICAST} values.
      * @return true if request is sent successfully, false otherwise.
      */
-    public boolean addRxFilter(int type) {
+    public boolean addRxFilter(@NonNull String ifaceName, int type) {
         synchronized (mLock) {
             byte halType;
             switch (type) {
@@ -1350,16 +1546,17 @@
                     Log.e(TAG, "Invalid Rx Filter type: " + type);
                     return false;
             }
-            return addRxFilter(halType);
+            return addRxFilter(ifaceName, halType);
         }
     }
 
-    public boolean addRxFilter(byte type) {
+    private boolean addRxFilter(@NonNull String ifaceName, byte type) {
         synchronized (mLock) {
             final String methodStr = "addRxFilter";
-            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
+            ISupplicantStaIface iface = checkSupplicantStaIfaceAndLogFailure(ifaceName, methodStr);
+            if (iface == null) return false;
             try {
-                SupplicantStatus status = mISupplicantStaIface.addRxFilter(type);
+                SupplicantStatus status = iface.addRxFilter(type);
                 return checkStatusAndLogFailure(status, methodStr);
             } catch (RemoteException e) {
                 handleRemoteException(e, methodStr);
@@ -1371,11 +1568,12 @@
     /**
      * Remove an RX filter.
      *
+     * @param ifaceName Name of the interface.
      * @param type one of {@link WifiNative#RX_FILTER_TYPE_V4_MULTICAST}
      *        {@link WifiNative#RX_FILTER_TYPE_V6_MULTICAST} values.
      * @return true if request is sent successfully, false otherwise.
      */
-    public boolean removeRxFilter(int type) {
+    public boolean removeRxFilter(@NonNull String ifaceName, int type) {
         synchronized (mLock) {
             byte halType;
             switch (type) {
@@ -1389,16 +1587,17 @@
                     Log.e(TAG, "Invalid Rx Filter type: " + type);
                     return false;
             }
-            return removeRxFilter(halType);
+            return removeRxFilter(ifaceName, halType);
         }
     }
 
-    public boolean removeRxFilter(byte type) {
+    private boolean removeRxFilter(@NonNull String ifaceName, byte type) {
         synchronized (mLock) {
             final String methodStr = "removeRxFilter";
-            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
+            ISupplicantStaIface iface = checkSupplicantStaIfaceAndLogFailure(ifaceName, methodStr);
+            if (iface == null) return false;
             try {
-                SupplicantStatus status = mISupplicantStaIface.removeRxFilter(type);
+                SupplicantStatus status = iface.removeRxFilter(type);
                 return checkStatusAndLogFailure(status, methodStr);
             } catch (RemoteException e) {
                 handleRemoteException(e, methodStr);
@@ -1410,12 +1609,13 @@
     /**
      * Set Bt co existense mode.
      *
+     * @param ifaceName Name of the interface.
      * @param mode one of the above {@link WifiNative#BLUETOOTH_COEXISTENCE_MODE_DISABLED},
      *             {@link WifiNative#BLUETOOTH_COEXISTENCE_MODE_ENABLED} or
      *             {@link WifiNative#BLUETOOTH_COEXISTENCE_MODE_SENSE}.
      * @return true if request is sent successfully, false otherwise.
      */
-    public boolean setBtCoexistenceMode(int mode) {
+    public boolean setBtCoexistenceMode(@NonNull String ifaceName, int mode) {
         synchronized (mLock) {
             byte halMode;
             switch (mode) {
@@ -1432,16 +1632,17 @@
                     Log.e(TAG, "Invalid Bt Coex mode: " + mode);
                     return false;
             }
-            return setBtCoexistenceMode(halMode);
+            return setBtCoexistenceMode(ifaceName, halMode);
         }
     }
 
-    private boolean setBtCoexistenceMode(byte mode) {
+    private boolean setBtCoexistenceMode(@NonNull String ifaceName, byte mode) {
         synchronized (mLock) {
             final String methodStr = "setBtCoexistenceMode";
-            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
+            ISupplicantStaIface iface = checkSupplicantStaIfaceAndLogFailure(ifaceName, methodStr);
+            if (iface == null) return false;
             try {
-                SupplicantStatus status = mISupplicantStaIface.setBtCoexistenceMode(mode);
+                SupplicantStatus status = iface.setBtCoexistenceMode(mode);
                 return checkStatusAndLogFailure(status, methodStr);
             } catch (RemoteException e) {
                 handleRemoteException(e, methodStr);
@@ -1452,16 +1653,18 @@
 
     /** Enable or disable BT coexistence mode.
      *
+     * @param ifaceName Name of the interface.
      * @param enable true to enable, false to disable.
      * @return true if request is sent successfully, false otherwise.
      */
-    public boolean setBtCoexistenceScanModeEnabled(boolean enable) {
+    public boolean setBtCoexistenceScanModeEnabled(@NonNull String ifaceName, boolean enable) {
         synchronized (mLock) {
             final String methodStr = "setBtCoexistenceScanModeEnabled";
-            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
+            ISupplicantStaIface iface = checkSupplicantStaIfaceAndLogFailure(ifaceName, methodStr);
+            if (iface == null) return false;
             try {
                 SupplicantStatus status =
-                        mISupplicantStaIface.setBtCoexistenceScanModeEnabled(enable);
+                        iface.setBtCoexistenceScanModeEnabled(enable);
                 return checkStatusAndLogFailure(status, methodStr);
             } catch (RemoteException e) {
                 handleRemoteException(e, methodStr);
@@ -1473,15 +1676,17 @@
     /**
      * Enable or disable suspend mode optimizations.
      *
+     * @param ifaceName Name of the interface.
      * @param enable true to enable, false otherwise.
      * @return true if request is sent successfully, false otherwise.
      */
-    public boolean setSuspendModeEnabled(boolean enable) {
+    public boolean setSuspendModeEnabled(@NonNull String ifaceName, boolean enable) {
         synchronized (mLock) {
             final String methodStr = "setSuspendModeEnabled";
-            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
+            ISupplicantStaIface iface = checkSupplicantStaIfaceAndLogFailure(ifaceName, methodStr);
+            if (iface == null) return false;
             try {
-                SupplicantStatus status = mISupplicantStaIface.setSuspendModeEnabled(enable);
+                SupplicantStatus status = iface.setSuspendModeEnabled(enable);
                 return checkStatusAndLogFailure(status, methodStr);
             } catch (RemoteException e) {
                 handleRemoteException(e, methodStr);
@@ -1493,23 +1698,25 @@
     /**
      * Set country code.
      *
+     * @param ifaceName Name of the interface.
      * @param codeStr 2 byte ASCII string. For ex: US, CA.
      * @return true if request is sent successfully, false otherwise.
      */
-    public boolean setCountryCode(String codeStr) {
+    public boolean setCountryCode(@NonNull String ifaceName, String codeStr) {
         synchronized (mLock) {
             if (TextUtils.isEmpty(codeStr)) return false;
-            return setCountryCode(NativeUtil.stringToByteArray(codeStr));
+            return setCountryCode(ifaceName, NativeUtil.stringToByteArray(codeStr));
         }
     }
 
     /** See ISupplicantStaIface.hal for documentation */
-    private boolean setCountryCode(byte[/* 2 */] code) {
+    private boolean setCountryCode(@NonNull String ifaceName, byte[/* 2 */] code) {
         synchronized (mLock) {
             final String methodStr = "setCountryCode";
-            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
+            ISupplicantStaIface iface = checkSupplicantStaIfaceAndLogFailure(ifaceName, methodStr);
+            if (iface == null) return false;
             try {
-                SupplicantStatus status = mISupplicantStaIface.setCountryCode(code);
+                SupplicantStatus status = iface.setCountryCode(code);
                 return checkStatusAndLogFailure(status, methodStr);
             } catch (RemoteException e) {
                 handleRemoteException(e, methodStr);
@@ -1521,15 +1728,17 @@
     /**
      * Start WPS pin registrar operation with the specified peer and pin.
      *
+     * @param ifaceName Name of the interface.
      * @param bssidStr BSSID of the peer.
      * @param pin Pin to be used.
      * @return true if request is sent successfully, false otherwise.
      */
-    public boolean startWpsRegistrar(String bssidStr, String pin) {
+    public boolean startWpsRegistrar(@NonNull String ifaceName, String bssidStr, String pin) {
         synchronized (mLock) {
             if (TextUtils.isEmpty(bssidStr) || TextUtils.isEmpty(pin)) return false;
             try {
-                return startWpsRegistrar(NativeUtil.macAddressToByteArray(bssidStr), pin);
+                return startWpsRegistrar(
+                        ifaceName, NativeUtil.macAddressToByteArray(bssidStr), pin);
             } catch (IllegalArgumentException e) {
                 Log.e(TAG, "Illegal argument " + bssidStr, e);
                 return false;
@@ -1538,12 +1747,13 @@
     }
 
     /** See ISupplicantStaIface.hal for documentation */
-    private boolean startWpsRegistrar(byte[/* 6 */] bssid, String pin) {
+    private boolean startWpsRegistrar(@NonNull String ifaceName, byte[/* 6 */] bssid, String pin) {
         synchronized (mLock) {
             final String methodStr = "startWpsRegistrar";
-            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
+            ISupplicantStaIface iface = checkSupplicantStaIfaceAndLogFailure(ifaceName, methodStr);
+            if (iface == null) return false;
             try {
-                SupplicantStatus status = mISupplicantStaIface.startWpsRegistrar(bssid, pin);
+                SupplicantStatus status = iface.startWpsRegistrar(bssid, pin);
                 return checkStatusAndLogFailure(status, methodStr);
             } catch (RemoteException e) {
                 handleRemoteException(e, methodStr);
@@ -1555,13 +1765,14 @@
     /**
      * Start WPS pin display operation with the specified peer.
      *
+     * @param ifaceName Name of the interface.
      * @param bssidStr BSSID of the peer. Use empty bssid to indicate wildcard.
      * @return true if request is sent successfully, false otherwise.
      */
-    public boolean startWpsPbc(String bssidStr) {
+    public boolean startWpsPbc(@NonNull String ifaceName, String bssidStr) {
         synchronized (mLock) {
             try {
-                return startWpsPbc(NativeUtil.macAddressToByteArray(bssidStr));
+                return startWpsPbc(ifaceName, NativeUtil.macAddressToByteArray(bssidStr));
             } catch (IllegalArgumentException e) {
                 Log.e(TAG, "Illegal argument " + bssidStr, e);
                 return false;
@@ -1570,12 +1781,13 @@
     }
 
     /** See ISupplicantStaIface.hal for documentation */
-    private boolean startWpsPbc(byte[/* 6 */] bssid) {
+    private boolean startWpsPbc(@NonNull String ifaceName, byte[/* 6 */] bssid) {
         synchronized (mLock) {
             final String methodStr = "startWpsPbc";
-            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
+            ISupplicantStaIface iface = checkSupplicantStaIfaceAndLogFailure(ifaceName, methodStr);
+            if (iface == null) return false;
             try {
-                SupplicantStatus status = mISupplicantStaIface.startWpsPbc(bssid);
+                SupplicantStatus status = iface.startWpsPbc(bssid);
                 return checkStatusAndLogFailure(status, methodStr);
             } catch (RemoteException e) {
                 handleRemoteException(e, methodStr);
@@ -1587,16 +1799,18 @@
     /**
      * Start WPS pin keypad operation with the specified pin.
      *
+     * @param ifaceName Name of the interface.
      * @param pin Pin to be used.
      * @return true if request is sent successfully, false otherwise.
      */
-    public boolean startWpsPinKeypad(String pin) {
+    public boolean startWpsPinKeypad(@NonNull String ifaceName, String pin) {
         if (TextUtils.isEmpty(pin)) return false;
         synchronized (mLock) {
             final String methodStr = "startWpsPinKeypad";
-            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
+            ISupplicantStaIface iface = checkSupplicantStaIfaceAndLogFailure(ifaceName, methodStr);
+            if (iface == null) return false;
             try {
-                SupplicantStatus status = mISupplicantStaIface.startWpsPinKeypad(pin);
+                SupplicantStatus status = iface.startWpsPinKeypad(pin);
                 return checkStatusAndLogFailure(status, methodStr);
             } catch (RemoteException e) {
                 handleRemoteException(e, methodStr);
@@ -1608,13 +1822,14 @@
     /**
      * Start WPS pin display operation with the specified peer.
      *
+     * @param ifaceName Name of the interface.
      * @param bssidStr BSSID of the peer. Use empty bssid to indicate wildcard.
      * @return new pin generated on success, null otherwise.
      */
-    public String startWpsPinDisplay(String bssidStr) {
+    public String startWpsPinDisplay(@NonNull String ifaceName, String bssidStr) {
         synchronized (mLock) {
             try {
-                return startWpsPinDisplay(NativeUtil.macAddressToByteArray(bssidStr));
+                return startWpsPinDisplay(ifaceName, NativeUtil.macAddressToByteArray(bssidStr));
             } catch (IllegalArgumentException e) {
                 Log.e(TAG, "Illegal argument " + bssidStr, e);
                 return null;
@@ -1623,13 +1838,14 @@
     }
 
     /** See ISupplicantStaIface.hal for documentation */
-    private String startWpsPinDisplay(byte[/* 6 */] bssid) {
+    private String startWpsPinDisplay(@NonNull String ifaceName, byte[/* 6 */] bssid) {
         synchronized (mLock) {
             final String methodStr = "startWpsPinDisplay";
-            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return null;
+            ISupplicantStaIface iface = checkSupplicantStaIfaceAndLogFailure(ifaceName, methodStr);
+            if (iface == null) return null;
             final Mutable<String> gotPin = new Mutable<>();
             try {
-                mISupplicantStaIface.startWpsPinDisplay(bssid,
+                iface.startWpsPinDisplay(bssid,
                         (SupplicantStatus status, String pin) -> {
                             if (checkStatusAndLogFailure(status, methodStr)) {
                                 gotPin.value = pin;
@@ -1645,14 +1861,16 @@
     /**
      * Cancels any ongoing WPS requests.
      *
+     * @param ifaceName Name of the interface.
      * @return true if request is sent successfully, false otherwise.
      */
-    public boolean cancelWps() {
+    public boolean cancelWps(@NonNull String ifaceName) {
         synchronized (mLock) {
             final String methodStr = "cancelWps";
-            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
+            ISupplicantStaIface iface = checkSupplicantStaIfaceAndLogFailure(ifaceName, methodStr);
+            if (iface == null) return false;
             try {
-                SupplicantStatus status = mISupplicantStaIface.cancelWps();
+                SupplicantStatus status = iface.cancelWps();
                 return checkStatusAndLogFailure(status, methodStr);
             } catch (RemoteException e) {
                 handleRemoteException(e, methodStr);
@@ -1664,15 +1882,17 @@
     /**
      * Sets whether to use external sim for SIM/USIM processing.
      *
+     * @param ifaceName Name of the interface.
      * @param useExternalSim true to enable, false otherwise.
      * @return true if request is sent successfully, false otherwise.
      */
-    public boolean setExternalSim(boolean useExternalSim) {
+    public boolean setExternalSim(@NonNull String ifaceName, boolean useExternalSim) {
         synchronized (mLock) {
             final String methodStr = "setExternalSim";
-            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
+            ISupplicantStaIface iface = checkSupplicantStaIfaceAndLogFailure(ifaceName, methodStr);
+            if (iface == null) return false;
             try {
-                SupplicantStatus status = mISupplicantStaIface.setExternalSim(useExternalSim);
+                SupplicantStatus status = iface.setExternalSim(useExternalSim);
                 return checkStatusAndLogFailure(status, methodStr);
             } catch (RemoteException e) {
                 handleRemoteException(e, methodStr);
@@ -1682,12 +1902,13 @@
     }
 
     /** See ISupplicant.hal for documentation */
-    public boolean enableAutoReconnect(boolean enable) {
+    public boolean enableAutoReconnect(@NonNull String ifaceName, boolean enable) {
         synchronized (mLock) {
             final String methodStr = "enableAutoReconnect";
-            if (!checkSupplicantAndLogFailure(methodStr)) return false;
+            ISupplicantStaIface iface = checkSupplicantStaIfaceAndLogFailure(ifaceName, methodStr);
+            if (iface == null) return false;
             try {
-                SupplicantStatus status = mISupplicantStaIface.enableAutoReconnect(enable);
+                SupplicantStatus status = iface.enableAutoReconnect(enable);
                 return checkStatusAndLogFailure(status, methodStr);
             } catch (RemoteException e) {
                 handleRemoteException(e, methodStr);
@@ -1775,13 +1996,30 @@
     /**
      * Returns false if SupplicantStaIface is null, and logs failure to call methodStr
      */
-    private boolean checkSupplicantStaIfaceAndLogFailure(final String methodStr) {
+    private ISupplicantStaIface checkSupplicantStaIfaceAndLogFailure(
+            @NonNull String ifaceName, final String methodStr) {
         synchronized (mLock) {
-            if (mISupplicantStaIface == null) {
+            ISupplicantStaIface iface = getStaIface(ifaceName);
+            if (iface == null) {
                 Log.e(TAG, "Can't call " + methodStr + ", ISupplicantStaIface is null");
-                return false;
+                return null;
             }
-            return true;
+            return iface;
+        }
+    }
+
+    /**
+     * Returns false if SupplicantStaNetwork is null, and logs failure to call methodStr
+     */
+    private SupplicantStaNetworkHal checkSupplicantStaNetworkAndLogFailure(
+            @NonNull String ifaceName, final String methodStr) {
+        synchronized (mLock) {
+            SupplicantStaNetworkHal networkHal = getCurrentNetworkRemoteHandle(ifaceName);
+            if (networkHal == null) {
+                Log.e(TAG, "Can't call " + methodStr + ", SupplicantStaNetwork is null");
+                return null;
+            }
+            return networkHal;
         }
     }
 
@@ -1938,8 +2176,13 @@
     }
 
     private class SupplicantStaIfaceHalCallback extends ISupplicantStaIfaceCallback.Stub {
+        private String mIfaceName;
         private boolean mStateIsFourway = false; // Used to help check for PSK password mismatch
 
+        SupplicantStaIfaceHalCallback(@NonNull String ifaceName) {
+            mIfaceName = ifaceName;
+        }
+
         /**
          * Parses the provided payload into an ANQP element.
          *
@@ -2008,10 +2251,11 @@
                 mStateIsFourway = (newState == ISupplicantStaIfaceCallback.State.FOURWAY_HANDSHAKE);
                 if (newSupplicantState == SupplicantState.COMPLETED) {
                     mWifiMonitor.broadcastNetworkConnectionEvent(
-                            mIfaceName, getCurrentNetworkId(), bssidStr);
+                            mIfaceName, getCurrentNetworkId(mIfaceName), bssidStr);
                 }
                 mWifiMonitor.broadcastSupplicantStateChangeEvent(
-                        mIfaceName, getCurrentNetworkId(), wifiSsid, bssidStr, newSupplicantState);
+                        mIfaceName, getCurrentNetworkId(mIfaceName), wifiSsid,
+                        bssidStr, newSupplicantState);
             }
         }
 
diff --git a/service/java/com/android/server/wifi/WifiNative.java b/service/java/com/android/server/wifi/WifiNative.java
index cda1cf6..fc815f8 100644
--- a/service/java/com/android/server/wifi/WifiNative.java
+++ b/service/java/com/android/server/wifi/WifiNative.java
@@ -111,7 +111,7 @@
             Log.e(mTAG, "Failed to start HAL for client mode");
             return Pair.create(SETUP_FAILURE_HAL, null);
         }
-        IClientInterface iClientInterface = mWificondControl.setupDriverForClientMode(ifaceName);
+        IClientInterface iClientInterface = mWificondControl.setupInterfaceForClientMode(ifaceName);
         if (iClientInterface == null) {
             return Pair.create(SETUP_FAILURE_WIFICOND, null);
         }
@@ -132,7 +132,7 @@
             Log.e(mTAG, "Failed to start HAL for AP mode");
             return Pair.create(SETUP_FAILURE_HAL, null);
         }
-        IApInterface iApInterface = mWificondControl.setupDriverForSoftApMode(ifaceName);
+        IApInterface iApInterface = mWificondControl.setupInterfaceForSoftApMode(ifaceName);
         if (iApInterface == null) {
             return Pair.create(SETUP_FAILURE_WIFICOND, null);
         }
@@ -179,6 +179,32 @@
     }
 
     /**
+     * Callback to notify wificond death.
+     */
+    public interface WificondDeathEventHandler {
+        /**
+         * Invoked when the wificond dies.
+         */
+        void onDeath();
+    }
+
+    /**
+     * Registers a death notification for wificond.
+     * @return Returns true on success.
+     */
+    public boolean registerWificondDeathHandler(@NonNull WificondDeathEventHandler handler) {
+        return mWificondControl.registerDeathHandler(handler);
+    }
+
+    /**
+     * Deregisters a death notification for wificond.
+     * @return Returns true on success.
+     */
+    public boolean deregisterWificondDeathHandler() {
+        return mWificondControl.deregisterDeathHandler();
+    }
+
+    /**
     * Disable wpa_supplicant via wificond.
     * @return Returns true on success.
     */
@@ -200,7 +226,7 @@
     * Returns null on failure.
     */
     public SignalPollResult signalPoll() {
-        return mWificondControl.signalPoll();
+        return mWificondControl.signalPoll(mInterfaceName);
     }
 
     /**
@@ -209,7 +235,7 @@
     * Returns null on failure.
     */
     public TxPacketCounters getTxPacketCounters() {
-        return mWificondControl.getTxPacketCounters();
+        return mWificondControl.getTxPacketCounters(mInterfaceName);
     }
 
     /**
@@ -235,7 +261,7 @@
      * @return Returns true on success.
      */
     public boolean scan(Set<Integer> freqs, Set<String> hiddenNetworkSSIDs) {
-        return mWificondControl.scan(freqs, hiddenNetworkSSIDs);
+        return mWificondControl.scan(mInterfaceName, freqs, hiddenNetworkSSIDs);
     }
 
     /**
@@ -244,7 +270,8 @@
      * Returns an empty ArrayList on failure.
      */
     public ArrayList<ScanDetail> getScanResults() {
-        return mWificondControl.getScanResults(WificondControl.SCAN_TYPE_SINGLE_SCAN);
+        return mWificondControl.getScanResults(
+                mInterfaceName, WificondControl.SCAN_TYPE_SINGLE_SCAN);
     }
 
     /**
@@ -253,7 +280,7 @@
      * Returns an empty ArrayList on failure.
      */
     public ArrayList<ScanDetail> getPnoScanResults() {
-        return mWificondControl.getScanResults(WificondControl.SCAN_TYPE_PNO_SCAN);
+        return mWificondControl.getScanResults(mInterfaceName, WificondControl.SCAN_TYPE_PNO_SCAN);
     }
 
     /**
@@ -262,7 +289,7 @@
      * @return true on success.
      */
     public boolean startPnoScan(PnoSettings pnoSettings) {
-        return mWificondControl.startPnoScan(pnoSettings);
+        return mWificondControl.startPnoScan(mInterfaceName, pnoSettings);
     }
 
     /**
@@ -270,7 +297,37 @@
      * @return true on success.
      */
     public boolean stopPnoScan() {
-        return mWificondControl.stopPnoScan();
+        return mWificondControl.stopPnoScan(mInterfaceName);
+    }
+
+    /**
+     * Callbacks for SoftAp interface.
+     */
+    public interface SoftApListener {
+        /**
+         * Invoked when the number of associated stations changes.
+         */
+        void onNumAssociatedStationsChanged(int numStations);
+    }
+
+    /**
+     * Start Soft AP operation using the provided configuration.
+     *
+     * @param config Configuration to use for the soft ap created.
+     * @param listener Callback for AP events.
+     * @return true on success, false otherwise.
+     */
+    public boolean startSoftAp(WifiConfiguration config, SoftApListener listener) {
+        return mWificondControl.startSoftAp(mInterfaceName, config, listener);
+    }
+
+    /**
+     * Stop the ongoing Soft AP operation.
+     *
+     * @return true on success, false otherwise.
+     */
+    public boolean stopSoftAp() {
+        return mWificondControl.stopSoftAp(mInterfaceName);
     }
 
     /********************************************************
@@ -278,7 +335,26 @@
      ********************************************************/
 
     /**
-     * This method is called repeatedly until the connection to wpa_supplicant is established.
+     * Callback to notify supplicant death.
+     */
+    public interface SupplicantDeathEventHandler {
+        /**
+         * Invoked when the supplicant dies.
+         */
+        void onDeath();
+    }
+
+    /**
+     * Registers a death notification for supplicant.
+     * @return Returns true on success.
+     */
+    public boolean registerSupplicantDeathHandler(@NonNull SupplicantDeathEventHandler handler) {
+        return mSupplicantStaIfaceHal.registerDeathHandler(handler);
+    }
+
+    /**
+     * This method is called repeatedly until the connection to wpa_supplicant is
+     * established and a STA iface is setup.
      *
      * @return true if connection is established, false otherwise.
      * TODO: Add unit tests for these once we remove the legacy code.
@@ -290,14 +366,19 @@
             return false;
         }
         // Check if the initialization is complete.
-        return mSupplicantStaIfaceHal.isInitializationComplete();
+        if (!mSupplicantStaIfaceHal.isInitializationComplete()) {
+            return false;
+        }
+        // Setup the STA iface once connection is established.
+        return mSupplicantStaIfaceHal.setupIface(mInterfaceName);
     }
 
     /**
      * Close supplicant connection.
      */
     public void closeSupplicantConnection() {
-        // Nothing to do for HIDL.
+        // Setup the STA iface once connection is established.
+        mSupplicantStaIfaceHal.teardownIface(mInterfaceName);
     }
 
     /**
@@ -315,7 +396,7 @@
      * @return true if request is sent successfully, false otherwise.
      */
     public boolean reconnect() {
-        return mSupplicantStaIfaceHal.reconnect();
+        return mSupplicantStaIfaceHal.reconnect(mInterfaceName);
     }
 
     /**
@@ -324,7 +405,7 @@
      * @return true if request is sent successfully, false otherwise.
      */
     public boolean reassociate() {
-        return mSupplicantStaIfaceHal.reassociate();
+        return mSupplicantStaIfaceHal.reassociate(mInterfaceName);
     }
 
     /**
@@ -333,7 +414,7 @@
      * @return true if request is sent successfully, false otherwise.
      */
     public boolean disconnect() {
-        return mSupplicantStaIfaceHal.disconnect();
+        return mSupplicantStaIfaceHal.disconnect(mInterfaceName);
     }
 
     /**
@@ -342,7 +423,7 @@
      * @return string containing the MAC address, or null on a failed call
      */
     public String getMacAddress() {
-        return mSupplicantStaIfaceHal.getMacAddress();
+        return mSupplicantStaIfaceHal.getMacAddress(mInterfaceName);
     }
 
     public static final int RX_FILTER_TYPE_V4_MULTICAST = 0;
@@ -372,10 +453,10 @@
      * The  SETSUSPENDOPT driver command overrides the filtering rules
      */
     public boolean startFilteringMulticastV4Packets() {
-        return mSupplicantStaIfaceHal.stopRxFilter()
+        return mSupplicantStaIfaceHal.stopRxFilter(mInterfaceName)
                 && mSupplicantStaIfaceHal.removeRxFilter(
-                RX_FILTER_TYPE_V4_MULTICAST)
-                && mSupplicantStaIfaceHal.startRxFilter();
+                        mInterfaceName, RX_FILTER_TYPE_V4_MULTICAST)
+                && mSupplicantStaIfaceHal.startRxFilter(mInterfaceName);
     }
 
     /**
@@ -383,10 +464,10 @@
      * @return {@code true} if the operation succeeded, {@code false} otherwise
      */
     public boolean stopFilteringMulticastV4Packets() {
-        return mSupplicantStaIfaceHal.stopRxFilter()
+        return mSupplicantStaIfaceHal.stopRxFilter(mInterfaceName)
                 && mSupplicantStaIfaceHal.addRxFilter(
-                RX_FILTER_TYPE_V4_MULTICAST)
-                && mSupplicantStaIfaceHal.startRxFilter();
+                        mInterfaceName, RX_FILTER_TYPE_V4_MULTICAST)
+                && mSupplicantStaIfaceHal.startRxFilter(mInterfaceName);
     }
 
     /**
@@ -394,10 +475,10 @@
      * @return {@code true} if the operation succeeded, {@code false} otherwise
      */
     public boolean startFilteringMulticastV6Packets() {
-        return mSupplicantStaIfaceHal.stopRxFilter()
+        return mSupplicantStaIfaceHal.stopRxFilter(mInterfaceName)
                 && mSupplicantStaIfaceHal.removeRxFilter(
-                RX_FILTER_TYPE_V6_MULTICAST)
-                && mSupplicantStaIfaceHal.startRxFilter();
+                        mInterfaceName, RX_FILTER_TYPE_V6_MULTICAST)
+                && mSupplicantStaIfaceHal.startRxFilter(mInterfaceName);
     }
 
     /**
@@ -405,10 +486,10 @@
      * @return {@code true} if the operation succeeded, {@code false} otherwise
      */
     public boolean stopFilteringMulticastV6Packets() {
-        return mSupplicantStaIfaceHal.stopRxFilter()
+        return mSupplicantStaIfaceHal.stopRxFilter(mInterfaceName)
                 && mSupplicantStaIfaceHal.addRxFilter(
-                RX_FILTER_TYPE_V6_MULTICAST)
-                && mSupplicantStaIfaceHal.startRxFilter();
+                        mInterfaceName, RX_FILTER_TYPE_V6_MULTICAST)
+                && mSupplicantStaIfaceHal.startRxFilter(mInterfaceName);
     }
 
     public static final int BLUETOOTH_COEXISTENCE_MODE_ENABLED  = 0;
@@ -423,7 +504,7 @@
       * @return Whether the mode was successfully set.
       */
     public boolean setBluetoothCoexistenceMode(int mode) {
-        return mSupplicantStaIfaceHal.setBtCoexistenceMode(mode);
+        return mSupplicantStaIfaceHal.setBtCoexistenceMode(mInterfaceName, mode);
     }
 
     /**
@@ -435,7 +516,8 @@
      * @return {@code true} if the command succeeded, {@code false} otherwise.
      */
     public boolean setBluetoothCoexistenceScanMode(boolean setCoexScanMode) {
-        return mSupplicantStaIfaceHal.setBtCoexistenceScanModeEnabled(setCoexScanMode);
+        return mSupplicantStaIfaceHal.setBtCoexistenceScanModeEnabled(
+                mInterfaceName, setCoexScanMode);
     }
 
     /**
@@ -445,7 +527,7 @@
      * @return true if request is sent successfully, false otherwise.
      */
     public boolean setSuspendOptimizations(boolean enabled) {
-        return mSupplicantStaIfaceHal.setSuspendModeEnabled(enabled);
+        return mSupplicantStaIfaceHal.setSuspendModeEnabled(mInterfaceName, enabled);
     }
 
     /**
@@ -455,7 +537,7 @@
      * @return true if request is sent successfully, false otherwise.
      */
     public boolean setCountryCode(String countryCode) {
-        return mSupplicantStaIfaceHal.setCountryCode(countryCode);
+        return mSupplicantStaIfaceHal.setCountryCode(mInterfaceName, countryCode);
     }
 
     /**
@@ -466,10 +548,10 @@
      */
     public void startTdls(String macAddr, boolean enable) {
         if (enable) {
-            mSupplicantStaIfaceHal.initiateTdlsDiscover(macAddr);
-            mSupplicantStaIfaceHal.initiateTdlsSetup(macAddr);
+            mSupplicantStaIfaceHal.initiateTdlsDiscover(mInterfaceName, macAddr);
+            mSupplicantStaIfaceHal.initiateTdlsSetup(mInterfaceName, macAddr);
         } else {
-            mSupplicantStaIfaceHal.initiateTdlsTeardown(macAddr);
+            mSupplicantStaIfaceHal.initiateTdlsTeardown(mInterfaceName, macAddr);
         }
     }
 
@@ -480,7 +562,7 @@
      * @return true if request is sent successfully, false otherwise.
      */
     public boolean startWpsPbc(String bssid) {
-        return mSupplicantStaIfaceHal.startWpsPbc(bssid);
+        return mSupplicantStaIfaceHal.startWpsPbc(mInterfaceName, bssid);
     }
 
     /**
@@ -490,7 +572,7 @@
      * @return true if request is sent successfully, false otherwise.
      */
     public boolean startWpsPinKeypad(String pin) {
-        return mSupplicantStaIfaceHal.startWpsPinKeypad(pin);
+        return mSupplicantStaIfaceHal.startWpsPinKeypad(mInterfaceName, pin);
     }
 
     /**
@@ -500,7 +582,7 @@
      * @return new pin generated on success, null otherwise.
      */
     public String startWpsPinDisplay(String bssid) {
-        return mSupplicantStaIfaceHal.startWpsPinDisplay(bssid);
+        return mSupplicantStaIfaceHal.startWpsPinDisplay(mInterfaceName, bssid);
     }
 
     /**
@@ -510,7 +592,7 @@
      * @return true if request is sent successfully, false otherwise.
      */
     public boolean setExternalSim(boolean external) {
-        return mSupplicantStaIfaceHal.setExternalSim(external);
+        return mSupplicantStaIfaceHal.setExternalSim(mInterfaceName, external);
     }
 
     /**
@@ -529,11 +611,14 @@
      */
     public boolean simAuthResponse(int id, String type, String response) {
         if (SIM_AUTH_RESP_TYPE_GSM_AUTH.equals(type)) {
-            return mSupplicantStaIfaceHal.sendCurrentNetworkEapSimGsmAuthResponse(response);
+            return mSupplicantStaIfaceHal.sendCurrentNetworkEapSimGsmAuthResponse(
+                    mInterfaceName, response);
         } else if (SIM_AUTH_RESP_TYPE_UMTS_AUTH.equals(type)) {
-            return mSupplicantStaIfaceHal.sendCurrentNetworkEapSimUmtsAuthResponse(response);
+            return mSupplicantStaIfaceHal.sendCurrentNetworkEapSimUmtsAuthResponse(
+                    mInterfaceName, response);
         } else if (SIM_AUTH_RESP_TYPE_UMTS_AUTS.equals(type)) {
-            return mSupplicantStaIfaceHal.sendCurrentNetworkEapSimUmtsAutsResponse(response);
+            return mSupplicantStaIfaceHal.sendCurrentNetworkEapSimUmtsAutsResponse(
+                    mInterfaceName, response);
         } else {
             return false;
         }
@@ -545,7 +630,7 @@
      * @return true if succeeds, false otherwise.
      */
     public boolean simAuthFailedResponse(int id) {
-        return mSupplicantStaIfaceHal.sendCurrentNetworkEapSimGsmAuthFailure();
+        return mSupplicantStaIfaceHal.sendCurrentNetworkEapSimGsmAuthFailure(mInterfaceName);
     }
 
     /**
@@ -554,7 +639,7 @@
      * @return true if succeeds, false otherwise.
      */
     public boolean umtsAuthFailedResponse(int id) {
-        return mSupplicantStaIfaceHal.sendCurrentNetworkEapSimUmtsAuthFailure();
+        return mSupplicantStaIfaceHal.sendCurrentNetworkEapSimUmtsAuthFailure(mInterfaceName);
     }
 
     /**
@@ -564,7 +649,8 @@
      * @return true if succeeds, false otherwise.
      */
     public boolean simIdentityResponse(int id, String response) {
-        return mSupplicantStaIfaceHal.sendCurrentNetworkEapIdentityResponse(response);
+        return mSupplicantStaIfaceHal.sendCurrentNetworkEapIdentityResponse(
+                mInterfaceName, response);
     }
 
     /**
@@ -573,7 +659,7 @@
      * @return anonymous identity string if succeeds, null otherwise.
      */
     public String getEapAnonymousIdentity() {
-        return mSupplicantStaIfaceHal.getCurrentNetworkEapAnonymousIdentity();
+        return mSupplicantStaIfaceHal.getCurrentNetworkEapAnonymousIdentity(mInterfaceName);
     }
 
     /**
@@ -584,7 +670,7 @@
      * @return true if request is sent successfully, false otherwise.
      */
     public boolean startWpsRegistrar(String bssid, String pin) {
-        return mSupplicantStaIfaceHal.startWpsRegistrar(bssid, pin);
+        return mSupplicantStaIfaceHal.startWpsRegistrar(mInterfaceName, bssid, pin);
     }
 
     /**
@@ -593,7 +679,7 @@
      * @return true if request is sent successfully, false otherwise.
      */
     public boolean cancelWps() {
-        return mSupplicantStaIfaceHal.cancelWps();
+        return mSupplicantStaIfaceHal.cancelWps(mInterfaceName);
     }
 
     /**
@@ -603,7 +689,7 @@
      * @return true if request is sent successfully, false otherwise.
      */
     public boolean setDeviceName(String name) {
-        return mSupplicantStaIfaceHal.setWpsDeviceName(name);
+        return mSupplicantStaIfaceHal.setWpsDeviceName(mInterfaceName, name);
     }
 
     /**
@@ -613,7 +699,7 @@
      * @return true if request is sent successfully, false otherwise.
      */
     public boolean setDeviceType(String type) {
-        return mSupplicantStaIfaceHal.setWpsDeviceType(type);
+        return mSupplicantStaIfaceHal.setWpsDeviceType(mInterfaceName, type);
     }
 
     /**
@@ -623,7 +709,7 @@
      * @return true if request is sent successfully, false otherwise.
      */
     public boolean setConfigMethods(String cfg) {
-        return mSupplicantStaIfaceHal.setWpsConfigMethods(cfg);
+        return mSupplicantStaIfaceHal.setWpsConfigMethods(mInterfaceName, cfg);
     }
 
     /**
@@ -633,7 +719,7 @@
      * @return true if request is sent successfully, false otherwise.
      */
     public boolean setManufacturer(String value) {
-        return mSupplicantStaIfaceHal.setWpsManufacturer(value);
+        return mSupplicantStaIfaceHal.setWpsManufacturer(mInterfaceName, value);
     }
 
     /**
@@ -643,7 +729,7 @@
      * @return true if request is sent successfully, false otherwise.
      */
     public boolean setModelName(String value) {
-        return mSupplicantStaIfaceHal.setWpsModelName(value);
+        return mSupplicantStaIfaceHal.setWpsModelName(mInterfaceName, value);
     }
 
     /**
@@ -653,7 +739,7 @@
      * @return true if request is sent successfully, false otherwise.
      */
     public boolean setModelNumber(String value) {
-        return mSupplicantStaIfaceHal.setWpsModelNumber(value);
+        return mSupplicantStaIfaceHal.setWpsModelNumber(mInterfaceName, value);
     }
 
     /**
@@ -663,7 +749,7 @@
      * @return true if request is sent successfully, false otherwise.
      */
     public boolean setSerialNumber(String value) {
-        return mSupplicantStaIfaceHal.setWpsSerialNumber(value);
+        return mSupplicantStaIfaceHal.setWpsSerialNumber(mInterfaceName, value);
     }
 
     /**
@@ -672,7 +758,7 @@
      * @param enabled true to enable, false to disable.
      */
     public void setPowerSave(boolean enabled) {
-        mSupplicantStaIfaceHal.setPowerSave(enabled);
+        mSupplicantStaIfaceHal.setPowerSave(mInterfaceName, enabled);
     }
 
     /**
@@ -693,7 +779,7 @@
      * @return true if request is sent successfully, false otherwise.
      */
     public boolean enableStaAutoReconnect(boolean enable) {
-        return mSupplicantStaIfaceHal.enableAutoReconnect(enable);
+        return mSupplicantStaIfaceHal.enableAutoReconnect(mInterfaceName, enable);
     }
 
     /**
@@ -706,7 +792,7 @@
      */
     public boolean migrateNetworksFromSupplicant(Map<String, WifiConfiguration> configs,
                                                  SparseArray<Map<String, String>> networkExtras) {
-        return mSupplicantStaIfaceHal.loadNetworks(configs, networkExtras);
+        return mSupplicantStaIfaceHal.loadNetworks(mInterfaceName, configs, networkExtras);
     }
 
     /**
@@ -724,8 +810,8 @@
      */
     public boolean connectToNetwork(WifiConfiguration configuration) {
         // Abort ongoing scan before connect() to unblock connection request.
-        mWificondControl.abortScan();
-        return mSupplicantStaIfaceHal.connectToNetwork(configuration);
+        mWificondControl.abortScan(mInterfaceName);
+        return mSupplicantStaIfaceHal.connectToNetwork(mInterfaceName, configuration);
     }
 
     /**
@@ -743,8 +829,8 @@
      */
     public boolean roamToNetwork(WifiConfiguration configuration) {
         // Abort ongoing scan before connect() to unblock roaming request.
-        mWificondControl.abortScan();
-        return mSupplicantStaIfaceHal.roamToNetwork(configuration);
+        mWificondControl.abortScan(mInterfaceName);
+        return mSupplicantStaIfaceHal.roamToNetwork(mInterfaceName, configuration);
     }
 
     /**
@@ -764,7 +850,7 @@
      * @return {@code true} if it succeeds, {@code false} otherwise
      */
     public boolean removeAllNetworks() {
-        return mSupplicantStaIfaceHal.removeAllNetworks();
+        return mSupplicantStaIfaceHal.removeAllNetworks(mInterfaceName);
     }
 
     /**
@@ -773,7 +859,7 @@
      * @return true if successful, false otherwise.
      */
     public boolean setConfiguredNetworkBSSID(String bssid) {
-        return mSupplicantStaIfaceHal.setCurrentNetworkBssid(bssid);
+        return mSupplicantStaIfaceHal.setCurrentNetworkBssid(mInterfaceName, bssid);
     }
 
     /**
@@ -796,7 +882,8 @@
         }
         ArrayList<Integer> hs20SubtypeList = new ArrayList<>();
         hs20SubtypeList.addAll(hs20Subtypes);
-        return mSupplicantStaIfaceHal.initiateAnqpQuery(bssid, anqpIdList, hs20SubtypeList);
+        return mSupplicantStaIfaceHal.initiateAnqpQuery(
+                mInterfaceName, bssid, anqpIdList, hs20SubtypeList);
     }
 
     /**
@@ -810,7 +897,7 @@
             Log.e(mTAG, "Invalid arguments for Icon request.");
             return false;
         }
-        return mSupplicantStaIfaceHal.initiateHs20IconQuery(bssid, fileName);
+        return mSupplicantStaIfaceHal.initiateHs20IconQuery(mInterfaceName, bssid, fileName);
     }
 
     /**
@@ -819,7 +906,7 @@
      * @return Hex string corresponding to the WPS NFC token.
      */
     public String getCurrentNetworkWpsNfcConfigurationToken() {
-        return mSupplicantStaIfaceHal.getCurrentNetworkWpsNfcConfigurationToken();
+        return mSupplicantStaIfaceHal.getCurrentNetworkWpsNfcConfigurationToken(mInterfaceName);
     }
 
     /** Remove the request |networkId| from supplicant if it's the current network,
@@ -828,7 +915,7 @@
      * @param networkId network id of the network to be removed from supplicant.
      */
     public void removeNetworkIfCurrent(int networkId) {
-        mSupplicantStaIfaceHal.removeNetworkIfCurrent(networkId);
+        mSupplicantStaIfaceHal.removeNetworkIfCurrent(mInterfaceName, networkId);
     }
 
     /********************************************************
@@ -862,7 +949,11 @@
             Log.i(mTAG, "Vendor HAL not supported, Ignore start...");
             return true;
         }
-        return mWifiVendorHal.startVendorHal(isStaMode);
+        if (isStaMode) {
+            return mWifiVendorHal.startVendorHalSta();
+        } else {
+            return mWifiVendorHal.startVendorHalAp();
+        }
     }
 
     /**
@@ -899,7 +990,7 @@
      * @return true for success. false for failure
      */
     public boolean getBgScanCapabilities(ScanCapabilities capabilities) {
-        return mWifiVendorHal.getBgScanCapabilities(capabilities);
+        return mWifiVendorHal.getBgScanCapabilities(mInterfaceName, capabilities);
     }
 
     public static class ChannelSettings {
@@ -1049,39 +1140,39 @@
      * @return true for success
      */
     public boolean startBgScan(ScanSettings settings, ScanEventHandler eventHandler) {
-        return mWifiVendorHal.startBgScan(settings, eventHandler);
+        return mWifiVendorHal.startBgScan(mInterfaceName, settings, eventHandler);
     }
 
     /**
      * Stops any ongoing backgound scan
      */
     public void stopBgScan() {
-        mWifiVendorHal.stopBgScan();
+        mWifiVendorHal.stopBgScan(mInterfaceName);
     }
 
     /**
      * Pauses an ongoing backgound scan
      */
     public void pauseBgScan() {
-        mWifiVendorHal.pauseBgScan();
+        mWifiVendorHal.pauseBgScan(mInterfaceName);
     }
 
     /**
      * Restarts a paused scan
      */
     public void restartBgScan() {
-        mWifiVendorHal.restartBgScan();
+        mWifiVendorHal.restartBgScan(mInterfaceName);
     }
 
     /**
      * Gets the latest scan results received.
      */
     public WifiScanner.ScanData[] getBgScanResults() {
-        return mWifiVendorHal.getBgScanResults();
+        return mWifiVendorHal.getBgScanResults(mInterfaceName);
     }
 
-    public WifiLinkLayerStats getWifiLinkLayerStats(String iface) {
-        return mWifiVendorHal.getWifiLinkLayerStats();
+    public WifiLinkLayerStats getWifiLinkLayerStats() {
+        return mWifiVendorHal.getWifiLinkLayerStats(mInterfaceName);
     }
 
     /**
@@ -1090,7 +1181,7 @@
      * @return bitmask defined by WifiManager.WIFI_FEATURE_*
      */
     public int getSupportedFeatureSet() {
-        return mWifiVendorHal.getSupportedFeatureSet();
+        return mWifiVendorHal.getSupportedFeatureSet(mInterfaceName);
     }
 
     public static interface RttEventHandler {
@@ -1147,7 +1238,7 @@
      * @return true for success
      */
     public boolean setScanningMacOui(byte[] oui) {
-        return mWifiVendorHal.setScanningMacOui(oui);
+        return mWifiVendorHal.setScanningMacOui(mInterfaceName, oui);
     }
 
     /**
@@ -1161,7 +1252,7 @@
      * Get the APF (Android Packet Filter) capabilities of the device
      */
     public ApfCapabilities getApfCapabilities() {
-        return mWifiVendorHal.getApfCapabilities();
+        return mWifiVendorHal.getApfCapabilities(mInterfaceName);
     }
 
     /**
@@ -1171,7 +1262,7 @@
      * @return true for success
      */
     public boolean installPacketFilter(byte[] filter) {
-        return mWifiVendorHal.installPacketFilter(filter);
+        return mWifiVendorHal.installPacketFilter(mInterfaceName, filter);
     }
 
     /**
@@ -1181,7 +1272,7 @@
      * @return true for success
      */
     public boolean setCountryCodeHal(String countryCode) {
-        return mWifiVendorHal.setCountryCodeHal(countryCode);
+        return mWifiVendorHal.setCountryCodeHal(mInterfaceName, countryCode);
     }
 
     //---------------------------------------------------------------------------------
@@ -1521,7 +1612,7 @@
      * @return true for success, false otherwise.
      */
     public boolean startPktFateMonitoring() {
-        return mWifiVendorHal.startPktFateMonitoring();
+        return mWifiVendorHal.startPktFateMonitoring(mInterfaceName);
     }
 
     /**
@@ -1530,14 +1621,14 @@
      * @return true for success, false otherwise.
      */
     public boolean getTxPktFates(TxFateReport[] reportBufs) {
-        return mWifiVendorHal.getTxPktFates(reportBufs);
+        return mWifiVendorHal.getTxPktFates(mInterfaceName, reportBufs);
     }
 
     /**
      * Fetch the most recent RX packet fates from the HAL. Fails unless HAL is started.
      */
     public boolean getRxPktFates(RxFateReport[] reportBufs) {
-        return mWifiVendorHal.getRxPktFates(reportBufs);
+        return mWifiVendorHal.getRxPktFates(mInterfaceName, reportBufs);
     }
 
     /**
@@ -1556,7 +1647,7 @@
             Integer hexVal = Integer.parseInt(macAddrStr[i], 16);
             srcMac[i] = hexVal.byteValue();
         }
-        return mWifiVendorHal.startSendingOffloadedPacket(
+        return mWifiVendorHal.startSendingOffloadedPacket(mInterfaceName,
                 slot, srcMac, keepAlivePacket, period);
     }
 
@@ -1567,7 +1658,7 @@
      * @return 0 for success, -1 for error
      */
     public int stopSendingOffloadedPacket(int slot) {
-        return mWifiVendorHal.stopSendingOffloadedPacket(slot);
+        return mWifiVendorHal.stopSendingOffloadedPacket(mInterfaceName, slot);
     }
 
     public static interface WifiRssiEventHandler {
@@ -1584,11 +1675,12 @@
      */
     public int startRssiMonitoring(byte maxRssi, byte minRssi,
                                    WifiRssiEventHandler rssiEventHandler) {
-        return mWifiVendorHal.startRssiMonitoring(maxRssi, minRssi, rssiEventHandler);
+        return mWifiVendorHal.startRssiMonitoring(
+                mInterfaceName, maxRssi, minRssi, rssiEventHandler);
     }
 
     public int stopRssiMonitoring() {
-        return mWifiVendorHal.stopRssiMonitoring();
+        return mWifiVendorHal.stopRssiMonitoring(mInterfaceName);
     }
 
     /**
@@ -1607,7 +1699,7 @@
      * @return true for success, false otherwise.
      */
     public boolean configureNeighborDiscoveryOffload(boolean enabled) {
-        return mWifiVendorHal.configureNeighborDiscoveryOffload(enabled);
+        return mWifiVendorHal.configureNeighborDiscoveryOffload(mInterfaceName, enabled);
     }
 
     // Firmware roaming control.
@@ -1625,7 +1717,7 @@
      * @return true for success, false otherwise.
      */
     public boolean getRoamingCapabilities(RoamingCapabilities capabilities) {
-        return mWifiVendorHal.getRoamingCapabilities(capabilities);
+        return mWifiVendorHal.getRoamingCapabilities(mInterfaceName, capabilities);
     }
 
     /**
@@ -1640,7 +1732,7 @@
      * @return error code returned from HAL.
      */
     public int enableFirmwareRoaming(int state) {
-        return mWifiVendorHal.enableFirmwareRoaming(state);
+        return mWifiVendorHal.enableFirmwareRoaming(mInterfaceName, state);
     }
 
     /**
@@ -1656,7 +1748,7 @@
      */
     public boolean configureRoaming(RoamingConfig config) {
         Log.d(mTAG, "configureRoaming ");
-        return mWifiVendorHal.configureRoaming(config);
+        return mWifiVendorHal.configureRoaming(mInterfaceName, config);
     }
 
     /**
@@ -1665,7 +1757,7 @@
     public boolean resetRoamingConfiguration() {
         // Pass in an empty RoamingConfig object which translates to zero size
         // blacklist and whitelist to reset the firmware roaming configuration.
-        return mWifiVendorHal.configureRoaming(new RoamingConfig());
+        return mWifiVendorHal.configureRoaming(mInterfaceName, new RoamingConfig());
     }
 
     /**
diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java
index e77fefb..8db180f 100644
--- a/service/java/com/android/server/wifi/WifiServiceImpl.java
+++ b/service/java/com/android/server/wifi/WifiServiceImpl.java
@@ -73,6 +73,7 @@
 import android.net.wifi.WifiManager;
 import android.net.wifi.WifiManager.LocalOnlyHotspotCallback;
 import android.net.wifi.WifiScanner;
+import android.net.wifi.hotspot2.IProvisioningCallback;
 import android.net.wifi.hotspot2.OsuProvider;
 import android.net.wifi.hotspot2.PasspointConfiguration;
 import android.os.AsyncTask;
@@ -2659,4 +2660,33 @@
         restoreNetworks(wifiConfigurations);
         Slog.d(TAG, "Restored supplicant backup data");
     }
+
+    /**
+     * Starts subscription provisioning with a provider
+     *
+     * @param provider {@link OsuProvider} the provider to provision with
+     * @param callback {@link IProvisoningCallback} the callback object to inform status
+     */
+    @Override
+    public void startSubscriptionProvisioning(OsuProvider provider,
+            IProvisioningCallback callback) {
+        if (provider == null) {
+            throw new IllegalArgumentException("Provider must not be null");
+        }
+        if (callback == null) {
+            throw new IllegalArgumentException("Callback must not be null");
+        }
+        enforceNetworkSettingsPermission();
+        if (!mContext.getPackageManager().hasSystemFeature(
+                PackageManager.FEATURE_WIFI_PASSPOINT)) {
+            throw new UnsupportedOperationException("Passpoint not enabled");
+        }
+        final int uid = Binder.getCallingUid();
+        mLog.trace("startSubscriptionProvisioning uid=%").c(uid).flush();
+        if (mWifiStateMachine.syncStartSubscriptionProvisioning(uid, provider,
+                callback, mWifiStateMachineChannel)) {
+            mLog.trace("Subscription provisioning started with %")
+                    .c(provider.toString()).flush();
+        }
+    }
 }
diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java
index 2c8c0b7..e386654 100644
--- a/service/java/com/android/server/wifi/WifiStateMachine.java
+++ b/service/java/com/android/server/wifi/WifiStateMachine.java
@@ -78,6 +78,7 @@
 import android.net.wifi.WpsInfo;
 import android.net.wifi.WpsResult;
 import android.net.wifi.WpsResult.Status;
+import android.net.wifi.hotspot2.IProvisioningCallback;
 import android.net.wifi.hotspot2.OsuProvider;
 import android.net.wifi.hotspot2.PasspointConfiguration;
 import android.net.wifi.p2p.IWifiP2pManager;
@@ -181,6 +182,7 @@
 
     private static final String EXTRA_OSU_ICON_QUERY_BSSID = "BSSID";
     private static final String EXTRA_OSU_ICON_QUERY_FILENAME = "FILENAME";
+    private static final String EXTRA_OSU_PROVIDER = "OsuProvider";
 
     private boolean mVerboseLoggingEnabled = false;
 
@@ -250,8 +252,9 @@
     private String mLastBssid;
     private int mLastNetworkId; // The network Id we successfully joined
     private boolean mIsLinkDebouncing = false;
-    private final StateMachineDeathRecipient mDeathRecipient =
-            new StateMachineDeathRecipient(this, CMD_CLIENT_INTERFACE_BINDER_DEATH);
+    private final WifiNative.WificondDeathEventHandler mWificondDeathRecipient = () -> {
+        sendMessage(CMD_WIFICOND_BINDER_DEATH);
+    };
     private final WifiNative.VendorHalDeathEventHandler mVendorHalDeathRecipient = () -> {
         sendMessage(CMD_VENDOR_HAL_HWBINDER_DEATH);
     };
@@ -728,8 +731,8 @@
     /* used to indicate that the foreground user was switched */
     static final int CMD_USER_STOP                                      = BASE + 207;
 
-    /* Signals that IClientInterface instance underpinning our state is dead. */
-    private static final int CMD_CLIENT_INTERFACE_BINDER_DEATH          = BASE + 250;
+    /* Signals that wificond is dead. */
+    private static final int CMD_WIFICOND_BINDER_DEATH          = BASE + 250;
 
     /* Signals that the Vendor HAL instance underpinning our state is dead. */
     private static final int CMD_VENDOR_HAL_HWBINDER_DEATH              = BASE + 251;
@@ -740,6 +743,9 @@
     /* Used to set the tx power limit for SAR during the start of a phone call. */
     private static final int CMD_SELECT_TX_POWER_SCENARIO               = BASE + 253;
 
+    // Start subscription provisioning with a given provider
+    private static final int CMD_START_SUBSCRIPTION_PROVISIONING        = BASE + 254;
+
     // For message logging.
     private static final Class[] sMessageClasses = {
             AsyncChannel.class, WifiStateMachine.class, DhcpClient.class };
@@ -1246,6 +1252,7 @@
         mWifiNative.enableVerboseLogging(verbose);
         mWifiConfigManager.enableVerboseLogging(verbose);
         mSupplicantStateTracker.enableVerboseLogging(verbose);
+        mPasspointManager.enableVerboseLogging(verbose);
     }
 
     private static final String SYSTEM_PROPERTY_LOG_CONTROL_WIFIHAL = "log.tag.WifiHAL";
@@ -1466,9 +1473,8 @@
     WifiLinkLayerStats getWifiLinkLayerStats() {
         WifiLinkLayerStats stats = null;
         if (mWifiLinkLayerStatsSupported > 0) {
-            String name = "wlan0";
-            stats = mWifiNative.getWifiLinkLayerStats(name);
-            if (name != null && stats == null && mWifiLinkLayerStatsSupported > 0) {
+            stats = mWifiNative.getWifiLinkLayerStats();
+            if (stats == null && mWifiLinkLayerStatsSupported > 0) {
                 mWifiLinkLayerStatsSupported -= 1;
             } else if (stats != null) {
                 lastLinkLayerStatsUpdate = mClock.getWallClockMillis();
@@ -2011,6 +2017,25 @@
     }
 
     /**
+     * Start subscription provisioning synchronously
+     *
+     * @param provider {@link OsuProvider} the provider to provision with
+     * @param callback {@link IProvisioningCallback} callback for provisioning status
+     * @return boolean true indicates provisioning was started, false otherwise
+     */
+    public boolean syncStartSubscriptionProvisioning(int callingUid, OsuProvider provider,
+            IProvisioningCallback callback, AsyncChannel channel) {
+        Message msg = Message.obtain();
+        msg.what = CMD_START_SUBSCRIPTION_PROVISIONING;
+        msg.arg1 = callingUid;
+        msg.obj = callback;
+        msg.getData().putParcelable(EXTRA_OSU_PROVIDER, provider);
+        Message resultMsg = channel.sendMessageSynchronously(msg);
+        boolean result = resultMsg.arg1 != 0;
+        resultMsg.recycle();
+        return result;
+    }
+    /**
      * Get connection statistics synchronously
      *
      * @param channel
@@ -3896,6 +3921,8 @@
                     break;
                 case CMD_INITIALIZE:
                     ok = mWifiNative.initializeVendorHal(mVendorHalDeathRecipient);
+                    mPasspointManager.initializeProvisioner(
+                            mWifiInjector.getWifiServiceHandlerThread().getLooper());
                     replyToMessage(message, message.what, ok ? SUCCESS : FAILURE);
                     break;
                 case CMD_BOOT_COMPLETED:
@@ -4028,6 +4055,9 @@
                 case CMD_GET_MATCHING_OSU_PROVIDERS:
                     replyToMessage(message, message.what, new ArrayList<OsuProvider>());
                     break;
+                case CMD_START_SUBSCRIPTION_PROVISIONING:
+                    replyToMessage(message, message.what, 0);
+                    break;
                 case CMD_IP_CONFIGURATION_SUCCESSFUL:
                 case CMD_IP_CONFIGURATION_LOST:
                 case CMD_IP_REACHABILITY_LOST:
@@ -4109,7 +4139,7 @@
                         mWifiNative.stopFilteringMulticastV4Packets();
                     }
                     break;
-                case CMD_CLIENT_INTERFACE_BINDER_DEATH:
+                case CMD_WIFICOND_BINDER_DEATH:
                     Log.e(TAG, "wificond died unexpectedly. Triggering recovery");
                     mWifiMetrics.incrementNumWificondCrashes();
                     mWifiDiagnostics.captureBugReportData(
@@ -4148,7 +4178,7 @@
             // Tearing down the client interfaces below is going to stop our supplicant.
             mWifiMonitor.stopAllMonitoring();
 
-            mDeathRecipient.unlinkToDeath();
+            mWifiNative.deregisterWificondDeathHandler();
             mWifiNative.tearDown();
         }
 
@@ -4171,7 +4201,7 @@
                         incrementMetricsForSetupFailure(statusAndInterface.first);
                     }
                     if (mClientInterface == null
-                            || !mDeathRecipient.linkToDeath(mClientInterface.asBinder())) {
+                            || !mWifiNative.registerWificondDeathHandler(mWificondDeathRecipient)) {
                         setWifiState(WifiManager.WIFI_STATE_UNKNOWN);
                         cleanup();
                         break;
@@ -5156,6 +5186,14 @@
                     replyToMessage(message, message.what,
                             mPasspointManager.getMatchingOsuProviders((ScanResult) message.obj));
                     break;
+                case CMD_START_SUBSCRIPTION_PROVISIONING:
+                    IProvisioningCallback callback = (IProvisioningCallback) message.obj;
+                    OsuProvider provider =
+                            (OsuProvider) message.getData().getParcelable(EXTRA_OSU_PROVIDER);
+                    int res = mPasspointManager.startSubscriptionProvisioning(
+                                    message.arg1, provider, callback) ? 1 : 0;
+                    replyToMessage(message, message.what, res);
+                    break;
                 case CMD_RECONNECT:
                     WorkSource workSource = (WorkSource) message.obj;
                     mWifiConnectivityManager.forceConnectivityScan(workSource);
diff --git a/service/java/com/android/server/wifi/WifiVendorHal.java b/service/java/com/android/server/wifi/WifiVendorHal.java
index 3f39e45..d552e7d 100644
--- a/service/java/com/android/server/wifi/WifiVendorHal.java
+++ b/service/java/com/android/server/wifi/WifiVendorHal.java
@@ -67,6 +67,7 @@
 import android.os.Handler;
 import android.os.Looper;
 import android.os.RemoteException;
+import android.text.TextUtils;
 import android.util.Log;
 import android.util.MutableBoolean;
 import android.util.MutableInt;
@@ -74,10 +75,14 @@
 import com.android.internal.annotations.VisibleForTesting;
 import com.android.internal.util.ArrayUtils;
 import com.android.server.connectivity.KeepalivePacketData;
+import com.android.server.wifi.HalDeviceManager.InterfaceDestroyedListener;
 import com.android.server.wifi.util.BitMask;
 import com.android.server.wifi.util.NativeUtil;
 
+import libcore.util.NonNull;
+
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.Set;
 
 /**
@@ -139,7 +144,7 @@
     }
 
     /**
-     * Logs if the argument is false.
+     * Logs the argument along with the method name.
      *
      * Always returns its argument.
      */
@@ -159,6 +164,26 @@
     }
 
     /**
+     * Logs the argument along with the method name.
+     *
+     * Always returns its argument.
+     */
+    private String stringResult(String result) {
+        if (mVerboseLog == sNoLog) return result;
+        // Currently only seen if verbose logging is on
+
+        Thread cur = Thread.currentThread();
+        StackTraceElement[] trace = cur.getStackTrace();
+
+        mVerboseLog.err("% returns %")
+                .c(niceMethodName(trace, 3))
+                .c(result)
+                .flush();
+
+        return result;
+    }
+
+    /**
      * Logs at method entry
      *
      * @param format string with % placeholders
@@ -201,9 +226,9 @@
 
     // Vendor HAL HIDL interface objects.
     private IWifiChip mIWifiChip;
-    private IWifiStaIface mIWifiStaIface;
-    private IWifiApIface mIWifiApIface;
     private IWifiRttController mIWifiRttController;
+    private HashMap<String, IWifiStaIface> mIWifiStaIfaces = new HashMap<>();
+    private HashMap<String, IWifiApIface> mIWifiApIfaces = new HashMap<>();
     private final HalDeviceManager mHalDeviceManager;
     private final HalDeviceManagerStatusListener mHalDeviceManagerStatusCallbacks;
     private final IWifiStaIfaceEventCallback mIWifiStaIfaceEventCallback;
@@ -271,7 +296,16 @@
      * @return true for success
      */
     public boolean startVendorHalAp() {
-        return startVendorHal(AP_MODE);
+        synchronized (sLock) {
+            if (!startVendorHal()) {
+                return false;
+            }
+            if (TextUtils.isEmpty(createApIface(null))) {
+                stopVendorHal();
+                return false;
+            }
+            return true;
+        }
     }
 
     /**
@@ -280,85 +314,182 @@
      * @return true for success
      */
     public boolean startVendorHalSta() {
-        return startVendorHal(STA_MODE);
+        synchronized (sLock) {
+            if (!startVendorHal()) {
+                return false;
+            }
+            if (TextUtils.isEmpty(createStaIface(null))) {
+                stopVendorHal();
+                return false;
+            }
+            return true;
+        }
     }
 
-    public static final boolean STA_MODE = true;
-    public static final boolean AP_MODE = false;
-
     /**
-     * Bring up the HIDL Vendor HAL and configure for STA mode or AP mode.
-     *
-     * @param isStaMode true to start HAL in STA mode, false to start in AP mode.
+     * Bring up the HIDL Vendor HAL.
+     * @return true on success, false otherwise.
      */
-    public boolean startVendorHal(boolean isStaMode) {
+    public boolean startVendorHal() {
         synchronized (sLock) {
-            if (mIWifiStaIface != null) return boolResult(false);
-            if (mIWifiApIface != null) return boolResult(false);
             if (!mHalDeviceManager.start()) {
-                return startFailedTo("start the vendor HAL");
-            }
-            IWifiIface iface;
-            if (isStaMode) {
-                mIWifiStaIface = mHalDeviceManager.createStaIface(null, null);
-                if (mIWifiStaIface == null) {
-                    return startFailedTo("create STA Iface");
-                }
-                iface = (IWifiIface) mIWifiStaIface;
-                if (!registerStaIfaceCallback()) {
-                    return startFailedTo("register sta iface callback");
-                }
-                mIWifiRttController = mHalDeviceManager.createRttController();
-                if (mIWifiRttController == null) {
-                    return startFailedTo("create RTT controller");
-                }
-                if (!registerRttEventCallback()) {
-                    return startFailedTo("register RTT iface callback");
-                }
-                enableLinkLayerStats();
-            } else {
-                mIWifiApIface = mHalDeviceManager.createApIface(null, null);
-                if (mIWifiApIface == null) {
-                    return startFailedTo("create AP Iface");
-                }
-                iface = (IWifiIface) mIWifiApIface;
-            }
-            mIWifiChip = mHalDeviceManager.getChip(iface);
-            if (mIWifiChip == null) {
-                return startFailedTo("get the chip created for the Iface");
-            }
-            if (!registerChipCallback()) {
-                return startFailedTo("register chip callback");
+                mLog.err("Failed to start vendor HAL");
+                return false;
             }
             mLog.i("Vendor Hal started successfully");
             return true;
         }
     }
 
+    /** Helper method to lookup the corresponding STA iface object using iface name. */
+    private IWifiStaIface getStaIface(@NonNull String ifaceName) {
+        synchronized (sLock) {
+            return mIWifiStaIfaces.get(ifaceName);
+        }
+    }
+
     /**
-     * Logs a message and cleans up after a failing start attempt
+     * Create a STA iface using {@link HalDeviceManager}.
      *
-     * The lock should be held.
-     * @param message describes what was being attempted
-     * @return false
+     * @param destroyedListener Listener to be invoked when the interface is destroyed.
+     * @return iface name on success, null otherwise.
      */
-    private boolean startFailedTo(String message) {
-        mVerboseLog.err("Failed to %. Vendor Hal start failed").c(message).flush();
-        mHalDeviceManager.stop();
-        clearState();
-        return false;
+    public String createStaIface(InterfaceDestroyedListener destroyedListener) {
+        synchronized (sLock) {
+            IWifiStaIface iface;
+            iface = mHalDeviceManager.createStaIface(destroyedListener, null);
+            if (iface == null) {
+                mLog.err("Failed to create STA iface");
+                return stringResult(null);
+            }
+            String ifaceName = mHalDeviceManager.getName((IWifiIface) iface);
+            if (TextUtils.isEmpty(ifaceName)) {
+                mLog.err("Failed to get iface name");
+                return stringResult(null);
+            }
+            if (!registerStaIfaceCallback(iface)) {
+                mLog.err("Failed to register STA iface callback");
+                return stringResult(null);
+            }
+            mIWifiRttController = mHalDeviceManager.createRttController();
+            if (mIWifiRttController == null) {
+                mLog.err("Failed to create RTT controller");
+                return stringResult(null);
+            }
+            if (!registerRttEventCallback()) {
+                mLog.err("Failed to register RTT controller callback");
+                return stringResult(null);
+            }
+            if (!retrieveWifiChip((IWifiIface) iface)) {
+                mLog.err("Failed to get wifi chip");
+                return stringResult(null);
+            }
+            enableLinkLayerStats(iface);
+            mIWifiStaIfaces.put(ifaceName, iface);
+            return ifaceName;
+        }
+    }
+
+    /**
+     * Remove a STA iface using {@link HalDeviceManager}.
+     *
+     * @param ifaceName Name of the interface being removed.
+     * @return true on success, false otherwise.
+     */
+    public boolean removeStaIface(@NonNull String ifaceName) {
+        synchronized (sLock) {
+            IWifiStaIface iface = getStaIface(ifaceName);
+            if (iface == null) return boolResult(false);
+
+            if (!mHalDeviceManager.removeIface((IWifiIface) iface)) {
+                mLog.err("Failed to remove STA iface");
+                return boolResult(false);
+            }
+            mIWifiStaIfaces.remove(ifaceName);
+            return true;
+        }
+    }
+
+    /** Helper method to lookup the corresponding AP iface object using iface name. */
+    private IWifiApIface getApIface(@NonNull String ifaceName) {
+        synchronized (sLock) {
+            return mIWifiApIfaces.get(ifaceName);
+        }
+    }
+
+    /**
+     * Create a AP iface using {@link HalDeviceManager}.
+     *
+     * @param destroyedListener Listener to be invoked when the interface is destroyed.
+     * @return iface name on success, null otherwise.
+     */
+    public String createApIface(InterfaceDestroyedListener destroyedListener) {
+        synchronized (sLock) {
+            IWifiApIface iface;
+            iface = mHalDeviceManager.createApIface(destroyedListener, null);
+            if (iface == null) {
+                mLog.err("Failed to create AP iface");
+                return stringResult(null);
+            }
+            String ifaceName = mHalDeviceManager.getName((IWifiIface) iface);
+            if (TextUtils.isEmpty(ifaceName)) {
+                mLog.err("Failed to get iface name");
+                return stringResult(null);
+            }
+            if (!retrieveWifiChip((IWifiIface) iface)) {
+                mLog.err("Failed to get wifi chip");
+                return stringResult(null);
+            }
+            mIWifiApIfaces.put(ifaceName, iface);
+            return ifaceName;
+        }
+    }
+
+    /**
+     * Remove an AP iface using {@link HalDeviceManager}.
+     *
+     * @param ifaceName Name of the interface being removed.
+     * @return true on success, false otherwise.
+     */
+    public boolean removeApIface(@NonNull String ifaceName) {
+        synchronized (sLock) {
+            IWifiApIface iface = getApIface(ifaceName);
+            if (iface == null) return boolResult(false);
+
+            if (!mHalDeviceManager.removeIface((IWifiIface) iface)) {
+                mLog.err("Failed to remove AP iface");
+                return boolResult(false);
+            }
+            mIWifiApIfaces.remove(ifaceName);
+            return true;
+        }
+    }
+
+    private boolean retrieveWifiChip(IWifiIface iface) {
+        synchronized (sLock) {
+            mIWifiChip = mHalDeviceManager.getChip(iface);
+            if (mIWifiChip == null) {
+                mLog.err("Failed to get the chip created for the Iface");
+                return false;
+            }
+            if (!registerChipCallback()) {
+                mLog.err("Failed to register chip callback");
+                return false;
+            }
+            return true;
+        }
     }
 
     /**
      * Registers the sta iface callback.
      */
-    private boolean registerStaIfaceCallback() {
+    private boolean registerStaIfaceCallback(IWifiStaIface iface) {
         synchronized (sLock) {
-            if (mIWifiStaIface == null) return boolResult(false);
+            if (iface == null) return boolResult(false);
             if (mIWifiStaIfaceEventCallback == null) return boolResult(false);
             try {
                 WifiStatus status =
-                        mIWifiStaIface.registerEventCallback(mIWifiStaIfaceEventCallback);
+                        iface.registerEventCallback(mIWifiStaIfaceEventCallback);
                 return ok(status);
             } catch (RemoteException e) {
                 handleRemoteException(e);
@@ -390,6 +521,7 @@
     private boolean registerRttEventCallback() {
         synchronized (sLock) {
             if (mIWifiRttController == null) return boolResult(false);
+            if (mRttEventCallback == null) return boolResult(false);
             try {
                 WifiStatus status = mIWifiRttController.registerEventCallback(mRttEventCallback);
                 return ok(status);
@@ -418,36 +550,39 @@
      */
     private void clearState() {
         mIWifiChip = null;
-        mIWifiStaIface = null;
-        mIWifiApIface = null;
+        mIWifiStaIfaces.clear();
+        mIWifiApIfaces.clear();
         mIWifiRttController = null;
         mDriverDescription = null;
         mFirmwareDescription = null;
     }
 
     /**
-     * Tests whether the HAL is running or not
+     * Tests whether the HAL is started and atleast one iface is up.
      */
     public boolean isHalStarted() {
         // For external use only. Methods in this class should test for null directly.
         synchronized (sLock) {
-            return (mIWifiStaIface != null || mIWifiApIface != null);
+            return (!mIWifiStaIfaces.isEmpty() || !mIWifiApIfaces.isEmpty());
         }
     }
 
     /**
      * Gets the scan capabilities
      *
+     * @param ifaceName Name of the interface.
      * @param capabilities object to be filled in
      * @return true for success, false for failure
      */
-    public boolean getBgScanCapabilities(WifiNative.ScanCapabilities capabilities) {
+    public boolean getBgScanCapabilities(
+            @NonNull String ifaceName, WifiNative.ScanCapabilities capabilities) {
         synchronized (sLock) {
-            if (mIWifiStaIface == null) return boolResult(false);
+            IWifiStaIface iface = getStaIface(ifaceName);
+            if (iface == null) return boolResult(false);
             try {
                 MutableBoolean ans = new MutableBoolean(false);
                 WifiNative.ScanCapabilities out = capabilities;
-                mIWifiStaIface.getBackgroundScanCapabilities((status, cap) -> {
+                iface.getBackgroundScanCapabilities((status, cap) -> {
                             if (!ok(status)) return;
                             mVerboseLog.info("scan capabilities %").c(cap.toString()).flush();
                             out.max_scan_cache_size = cap.maxCacheSize;
@@ -582,24 +717,27 @@
      *
      * Any ongoing scan will be stopped first
      *
+     * @param ifaceName    Name of the interface.
      * @param settings     to control the scan
      * @param eventHandler to call with the results
      * @return true for success
      */
-    public boolean startBgScan(WifiNative.ScanSettings settings,
+    public boolean startBgScan(@NonNull String ifaceName,
+                               WifiNative.ScanSettings settings,
                                WifiNative.ScanEventHandler eventHandler) {
         WifiStatus status;
         if (eventHandler == null) return boolResult(false);
         synchronized (sLock) {
-            if (mIWifiStaIface == null) return boolResult(false);
+            IWifiStaIface iface = getStaIface(ifaceName);
+            if (iface == null) return boolResult(false);
             try {
                 if (mScan != null && !mScan.paused) {
-                    ok(mIWifiStaIface.stopBackgroundScan(mScan.cmdId));
+                    ok(iface.stopBackgroundScan(mScan.cmdId));
                     mScan = null;
                 }
                 mLastScanCmdId = (mLastScanCmdId % 9) + 1; // cycle through non-zero single digits
                 CurrentBackgroundScan scan = new CurrentBackgroundScan(mLastScanCmdId, settings);
-                status = mIWifiStaIface.startBackgroundScan(scan.cmdId, scan.param);
+                status = iface.startBackgroundScan(scan.cmdId, scan.param);
                 if (!ok(status)) return false;
                 scan.eventHandler = eventHandler;
                 mScan = scan;
@@ -614,14 +752,17 @@
 
     /**
      * Stops any ongoing backgound scan
+     *
+     * @param ifaceName Name of the interface.
      */
-    public void stopBgScan() {
+    public void stopBgScan(@NonNull String ifaceName) {
         WifiStatus status;
         synchronized (sLock) {
-            if (mIWifiStaIface == null) return;
+            IWifiStaIface iface = getStaIface(ifaceName);
+            if (iface == null) return;
             try {
                 if (mScan != null) {
-                    ok(mIWifiStaIface.stopBackgroundScan(mScan.cmdId));
+                    ok(iface.stopBackgroundScan(mScan.cmdId));
                     mScan = null;
                 }
             } catch (RemoteException e) {
@@ -632,14 +773,17 @@
 
     /**
      * Pauses an ongoing backgound scan
+     *
+     * @param ifaceName Name of the interface.
      */
-    public void pauseBgScan() {
+    public void pauseBgScan(@NonNull String ifaceName) {
         WifiStatus status;
         synchronized (sLock) {
             try {
-                if (mIWifiStaIface == null) return;
+                IWifiStaIface iface = getStaIface(ifaceName);
+                if (iface == null) return;
                 if (mScan != null && !mScan.paused) {
-                    status = mIWifiStaIface.stopBackgroundScan(mScan.cmdId);
+                    status = iface.stopBackgroundScan(mScan.cmdId);
                     if (!ok(status)) return;
                     mScan.paused = true;
                 }
@@ -651,14 +795,17 @@
 
     /**
      * Restarts a paused background scan
+     *
+     * @param ifaceName Name of the interface.
      */
-    public void restartBgScan() {
+    public void restartBgScan(@NonNull String ifaceName) {
         WifiStatus status;
         synchronized (sLock) {
-            if (mIWifiStaIface == null) return;
+            IWifiStaIface iface = getStaIface(ifaceName);
+            if (iface == null) return;
             try {
                 if (mScan != null && mScan.paused) {
-                    status = mIWifiStaIface.startBackgroundScan(mScan.cmdId, mScan.param);
+                    status = iface.startBackgroundScan(mScan.cmdId, mScan.param);
                     if (!ok(status)) return;
                     mScan.paused = false;
                 }
@@ -672,10 +819,13 @@
      * Gets the latest scan results received from the HIDL interface callback.
      * TODO(b/35754840): This hop to fetch scan results after callback is unnecessary. Refactor
      * WifiScanner to use the scan results from the callback.
+     *
+     * @param ifaceName Name of the interface.
      */
-    public WifiScanner.ScanData[] getBgScanResults() {
+    public WifiScanner.ScanData[] getBgScanResults(@NonNull String ifaceName) {
         synchronized (sLock) {
-            if (mIWifiStaIface == null) return null;
+            IWifiStaIface iface = getStaIface(ifaceName);
+            if (iface == null) return null;
             if (mScan == null) return null;
             return mScan.latestScanResults;
         }
@@ -686,17 +836,19 @@
      *
      * Note - we always enable link layer stats on a STA interface.
      *
+     * @param ifaceName Name of the interface.
      * @return the statistics, or null if unable to do so
      */
-    public WifiLinkLayerStats getWifiLinkLayerStats() {
+    public WifiLinkLayerStats getWifiLinkLayerStats(@NonNull String ifaceName) {
         class AnswerBox {
             public StaLinkLayerStats value = null;
         }
         AnswerBox answer = new AnswerBox();
         synchronized (sLock) {
             try {
-                if (mIWifiStaIface == null) return null;
-                mIWifiStaIface.getLinkLayerStats((status, stats) -> {
+                IWifiStaIface iface = getStaIface(ifaceName);
+                if (iface == null) return null;
+                iface.getLinkLayerStats((status, stats) -> {
                     if (!ok(status)) return;
                     answer.value = stats;
                 });
@@ -763,12 +915,14 @@
      * Enables the linkLayerStats in the Hal.
      *
      * This is called unconditionally whenever we create a STA interface.
+     *
+     * @param iface Iface object.
      */
-    private void enableLinkLayerStats() {
+    private void enableLinkLayerStats(IWifiStaIface iface) {
         synchronized (sLock) {
             try {
                 WifiStatus status;
-                status = mIWifiStaIface.enableLinkLayerStatsCollection(mLinkLayerStatsDebug);
+                status = iface.enableLinkLayerStatsCollection(mLinkLayerStatsDebug);
                 if (!ok(status)) {
                     mLog.e("unable to enable link layer stats collection");
                 }
@@ -877,9 +1031,10 @@
      *
      * The result may differ depending on the mode (STA or AP)
      *
+     * @param ifaceName Name of the interface.
      * @return bitmask defined by WifiManager.WIFI_FEATURE_*
      */
-    public int getSupportedFeatureSet() {
+    public int getSupportedFeatureSet(@NonNull String ifaceName) {
         int featureSet = 0;
         if (!mHalDeviceManager.isStarted()) {
             return featureSet; // TODO: can't get capabilities with Wi-Fi down
@@ -893,8 +1048,9 @@
                         feat.value = wifiFeatureMaskFromChipCapabilities(capabilities);
                     });
                 }
-                if (mIWifiStaIface != null) {
-                    mIWifiStaIface.getCapabilities((status, capabilities) -> {
+                IWifiStaIface iface = getStaIface(ifaceName);
+                if (iface != null) {
+                    iface.getCapabilities((status, capabilities) -> {
                         if (!ok(status)) return;
                         feat.value |= wifiFeatureMaskFromStaCapabilities(capabilities);
                     });
@@ -1433,16 +1589,18 @@
      * An OUI {Organizationally Unique Identifier} is a 24-bit number that
      * uniquely identifies a vendor or manufacturer.
      *
+     * @param ifaceName Name of the interface.
      * @param oui
      * @return true for success
      */
-    public boolean setScanningMacOui(byte[] oui) {
+    public boolean setScanningMacOui(@NonNull String ifaceName, byte[] oui) {
         if (oui == null) return boolResult(false);
         if (oui.length != 3) return boolResult(false);
         synchronized (sLock) {
             try {
-                if (mIWifiStaIface == null) return boolResult(false);
-                WifiStatus status = mIWifiStaIface.setScanningMacOui(oui);
+                IWifiStaIface iface = getStaIface(ifaceName);
+                if (iface == null) return boolResult(false);
+                WifiStatus status = iface.setScanningMacOui(oui);
                 if (!ok(status)) return false;
                 return true;
             } catch (RemoteException e) {
@@ -1454,16 +1612,20 @@
 
     /**
      * Get the APF (Android Packet Filter) capabilities of the device
+     *
+     * @param ifaceName Name of the interface.
+     * @return APF capabilities object.
      */
-    public ApfCapabilities getApfCapabilities() {
+    public ApfCapabilities getApfCapabilities(@NonNull String ifaceName) {
         class AnswerBox {
             public ApfCapabilities value = sNoApfCapabilities;
         }
         synchronized (sLock) {
             try {
-                if (mIWifiStaIface == null) return sNoApfCapabilities;
+                IWifiStaIface iface = getStaIface(ifaceName);
+                if (iface == null) return sNoApfCapabilities;
                 AnswerBox box = new AnswerBox();
-                mIWifiStaIface.getApfPacketFilterCapabilities((status, capabilities) -> {
+                iface.getApfPacketFilterCapabilities((status, capabilities) -> {
                     if (!ok(status)) return;
                     box.value = new ApfCapabilities(
                         /* apfVersionSupported */   capabilities.version,
@@ -1483,10 +1645,11 @@
     /**
      * Installs an APF program on this iface, replacing any existing program.
      *
+     * @param ifaceName Name of the interface.
      * @param filter is the android packet filter program
      * @return true for success
      */
-    public boolean installPacketFilter(byte[] filter) {
+    public boolean installPacketFilter(@NonNull String ifaceName, byte[] filter) {
         int cmdId = 0; // We only aspire to support one program at a time
         if (filter == null) return boolResult(false);
         // Copy the program before taking the lock.
@@ -1494,8 +1657,9 @@
         enter("filter length %").c(filter.length).flush();
         synchronized (sLock) {
             try {
-                if (mIWifiStaIface == null) return boolResult(false);
-                WifiStatus status = mIWifiStaIface.installApfPacketFilter(cmdId, program);
+                IWifiStaIface iface = getStaIface(ifaceName);
+                if (iface == null) return boolResult(false);
+                WifiStatus status = iface.installApfPacketFilter(cmdId, program);
                 if (!ok(status)) return false;
                 return true;
             } catch (RemoteException e) {
@@ -1508,10 +1672,11 @@
     /**
      * Set country code for this AP iface.
      *
+     * @param ifaceName Name of the interface.
      * @param countryCode - two-letter country code (as ISO 3166)
      * @return true for success
      */
-    public boolean setCountryCodeHal(String countryCode) {
+    public boolean setCountryCodeHal(@NonNull String ifaceName, String countryCode) {
         if (countryCode == null) return boolResult(false);
         if (countryCode.length() != 2) return boolResult(false);
         byte[] code;
@@ -1522,8 +1687,9 @@
         }
         synchronized (sLock) {
             try {
-                if (mIWifiApIface == null) return boolResult(false);
-                WifiStatus status = mIWifiApIface.setCountryCode(code);
+                IWifiApIface iface = getApIface(ifaceName);
+                if (iface == null) return boolResult(false);
+                WifiStatus status = iface.setCountryCode(code);
                 if (!ok(status)) return false;
                 return true;
             } catch (RemoteException e) {
@@ -1809,13 +1975,15 @@
      * <p>
      * Once started, monitoring remains active until HAL is unloaded.
      *
+     * @param ifaceName Name of the interface.
      * @return true for success
      */
-    public boolean startPktFateMonitoring() {
+    public boolean startPktFateMonitoring(@NonNull String ifaceName) {
         synchronized (sLock) {
-            if (mIWifiStaIface == null) return boolResult(false);
+            IWifiStaIface iface = getStaIface(ifaceName);
+            if (iface == null) return boolResult(false);
             try {
-                WifiStatus status = mIWifiStaIface.startDebugPacketFateMonitoring();
+                WifiStatus status = iface.startDebugPacketFateMonitoring();
                 return ok(status);
             } catch (RemoteException e) {
                 handleRemoteException(e);
@@ -1898,16 +2066,18 @@
      * <p>
      * Reports the outbound frames for the most recent association (space allowing).
      *
+     * @param ifaceName Name of the interface.
      * @param reportBufs
      * @return true for success
      */
-    public boolean getTxPktFates(WifiNative.TxFateReport[] reportBufs) {
+    public boolean getTxPktFates(@NonNull String ifaceName, WifiNative.TxFateReport[] reportBufs) {
         if (ArrayUtils.isEmpty(reportBufs)) return boolResult(false);
         synchronized (sLock) {
-            if (mIWifiStaIface == null) return boolResult(false);
+            IWifiStaIface iface = getStaIface(ifaceName);
+            if (iface == null) return boolResult(false);
             try {
                 MutableBoolean ok = new MutableBoolean(false);
-                mIWifiStaIface.getDebugTxPacketFates((status, fates) -> {
+                iface.getDebugTxPacketFates((status, fates) -> {
                             if (!ok(status)) return;
                             int i = 0;
                             for (WifiDebugTxPacketFateReport fate : fates) {
@@ -1938,16 +2108,18 @@
      * <p>
      * Reports the inbound frames for the most recent association (space allowing).
      *
+     * @param ifaceName Name of the interface.
      * @param reportBufs
      * @return true for success
      */
-    public boolean getRxPktFates(WifiNative.RxFateReport[] reportBufs) {
+    public boolean getRxPktFates(@NonNull String ifaceName, WifiNative.RxFateReport[] reportBufs) {
         if (ArrayUtils.isEmpty(reportBufs)) return boolResult(false);
         synchronized (sLock) {
-            if (mIWifiStaIface == null) return boolResult(false);
+            IWifiStaIface iface = getStaIface(ifaceName);
+            if (iface == null) return boolResult(false);
             try {
                 MutableBoolean ok = new MutableBoolean(false);
-                mIWifiStaIface.getDebugRxPacketFates((status, fates) -> {
+                iface.getDebugRxPacketFates((status, fates) -> {
                             if (!ok(status)) return;
                             int i = 0;
                             for (WifiDebugRxPacketFateReport fate : fates) {
@@ -1976,6 +2148,7 @@
     /**
      * Start sending the specified keep alive packets periodically.
      *
+     * @param ifaceName Name of the interface.
      * @param slot
      * @param srcMac
      * @param keepAlivePacket
@@ -1983,16 +2156,18 @@
      * @return 0 for success, -1 for error
      */
     public int startSendingOffloadedPacket(
-            int slot, byte[] srcMac, KeepalivePacketData keepAlivePacket, int periodInMs) {
+            @NonNull String ifaceName, int slot, byte[] srcMac,
+            KeepalivePacketData keepAlivePacket, int periodInMs) {
         enter("slot=% periodInMs=%").c(slot).c(periodInMs).flush();
 
         ArrayList<Byte> data = NativeUtil.byteArrayToArrayList(keepAlivePacket.data);
         short protocol = (short) (keepAlivePacket.protocol);
 
         synchronized (sLock) {
-            if (mIWifiStaIface == null) return -1;
+            IWifiStaIface iface = getStaIface(ifaceName);
+            if (iface == null) return -1;
             try {
-                WifiStatus status = mIWifiStaIface.startSendingKeepAlivePackets(
+                WifiStatus status = iface.startSendingKeepAlivePackets(
                         slot,
                         data,
                         protocol,
@@ -2011,16 +2186,18 @@
     /**
      * Stop sending the specified keep alive packets.
      *
+     * @param ifaceName Name of the interface.
      * @param slot id - same as startSendingOffloadedPacket call.
      * @return 0 for success, -1 for error
      */
-    public int stopSendingOffloadedPacket(int slot) {
+    public int stopSendingOffloadedPacket(@NonNull String ifaceName, int slot) {
         enter("slot=%").c(slot).flush();
 
         synchronized (sLock) {
-            if (mIWifiStaIface == null) return -1;
+            IWifiStaIface iface = getStaIface(ifaceName);
+            if (iface == null) return -1;
             try {
-                WifiStatus status = mIWifiStaIface.stopSendingKeepAlivePackets(slot);
+                WifiStatus status = iface.stopSendingKeepAlivePackets(slot);
                 if (!ok(status)) return -1;
                 return 0;
             } catch (RemoteException e) {
@@ -2044,22 +2221,24 @@
     /**
      * Start RSSI monitoring on the currently connected access point.
      *
+     * @param ifaceName        Name of the interface.
      * @param maxRssi          Maximum RSSI threshold.
      * @param minRssi          Minimum RSSI threshold.
      * @param rssiEventHandler Called when RSSI goes above maxRssi or below minRssi
      * @return 0 for success, -1 for failure
      */
-    public int startRssiMonitoring(byte maxRssi, byte minRssi,
+    public int startRssiMonitoring(@NonNull String ifaceName, byte maxRssi, byte minRssi,
                                    WifiNative.WifiRssiEventHandler rssiEventHandler) {
         enter("maxRssi=% minRssi=%").c(maxRssi).c(minRssi).flush();
         if (maxRssi <= minRssi) return -1;
         if (rssiEventHandler == null) return -1;
         synchronized (sLock) {
-            if (mIWifiStaIface == null) return -1;
+            IWifiStaIface iface = getStaIface(ifaceName);
+            if (iface == null) return -1;
             try {
-                mIWifiStaIface.stopRssiMonitoring(sRssiMonCmdId);
+                iface.stopRssiMonitoring(sRssiMonCmdId);
                 WifiStatus status;
-                status = mIWifiStaIface.startRssiMonitoring(sRssiMonCmdId, maxRssi, minRssi);
+                status = iface.startRssiMonitoring(sRssiMonCmdId, maxRssi, minRssi);
                 if (!ok(status)) return -1;
                 mWifiRssiEventHandler = rssiEventHandler;
                 return 0;
@@ -2073,15 +2252,16 @@
     /**
      * Stop RSSI monitoring
      *
+     * @param ifaceName Name of the interface.
      * @return 0 for success, -1 for failure
      */
-    public int stopRssiMonitoring() {
+    public int stopRssiMonitoring(@NonNull String ifaceName) {
         synchronized (sLock) {
             mWifiRssiEventHandler = null;
-            if (mIWifiStaIface == null) return -1;
+            IWifiStaIface iface = getStaIface(ifaceName);
+            if (iface == null) return -1;
             try {
-                mIWifiStaIface.stopRssiMonitoring(sRssiMonCmdId);
-                WifiStatus status = mIWifiStaIface.stopRssiMonitoring(sRssiMonCmdId);
+                WifiStatus status = iface.stopRssiMonitoring(sRssiMonCmdId);
                 if (!ok(status)) return -1;
                 return 0;
             } catch (RemoteException e) {
@@ -2158,14 +2338,17 @@
     /**
      * Enable/Disable Neighbour discovery offload functionality in the firmware.
      *
+     * @param ifaceName Name of the interface.
      * @param enabled true to enable, false to disable.
+     * @return true for success, false for failure
      */
-    public boolean configureNeighborDiscoveryOffload(boolean enabled) {
+    public boolean configureNeighborDiscoveryOffload(@NonNull String ifaceName, boolean enabled) {
         enter("enabled=%").c(enabled).flush();
         synchronized (sLock) {
-            if (mIWifiStaIface == null) return boolResult(false);
+            IWifiStaIface iface = getStaIface(ifaceName);
+            if (iface == null) return boolResult(false);
             try {
-                WifiStatus status = mIWifiStaIface.enableNdOffload(enabled);
+                WifiStatus status = iface.enableNdOffload(enabled);
                 if (!ok(status)) return false;
             } catch (RemoteException e) {
                 handleRemoteException(e);
@@ -2180,16 +2363,19 @@
     /**
      * Query the firmware roaming capabilities.
      *
+     * @param ifaceName Name of the interface.
      * @param capabilities object to be filled in
      * @return true for success; false for failure
      */
-    public boolean getRoamingCapabilities(WifiNative.RoamingCapabilities capabilities) {
+    public boolean getRoamingCapabilities(@NonNull String ifaceName,
+                                          WifiNative.RoamingCapabilities capabilities) {
         synchronized (sLock) {
-            if (mIWifiStaIface == null) return boolResult(false);
+            IWifiStaIface iface = getStaIface(ifaceName);
+            if (iface == null) return boolResult(false);
             try {
                 MutableBoolean ok = new MutableBoolean(false);
                 WifiNative.RoamingCapabilities out = capabilities;
-                mIWifiStaIface.getRoamingCapabilities((status, cap) -> {
+                iface.getRoamingCapabilities((status, cap) -> {
                     if (!ok(status)) return;
                     out.maxBlacklistSize = cap.maxBlacklistSize;
                     out.maxWhitelistSize = cap.maxWhitelistSize;
@@ -2206,12 +2392,14 @@
     /**
      * Enable/disable firmware roaming.
      *
+     * @param ifaceName Name of the interface.
      * @param state the intended roaming state
      * @return SUCCESS, FAILURE, or BUSY
      */
-    public int enableFirmwareRoaming(int state) {
+    public int enableFirmwareRoaming(@NonNull String ifaceName, int state) {
         synchronized (sLock) {
-            if (mIWifiStaIface == null) return WifiStatusCode.ERROR_NOT_STARTED;
+            IWifiStaIface iface = getStaIface(ifaceName);
+            if (iface == null) return WifiStatusCode.ERROR_NOT_STARTED;
             try {
                 byte val;
                 switch (state) {
@@ -2226,7 +2414,7 @@
                         return WifiStatusCode.ERROR_INVALID_ARGS;
                 }
 
-                WifiStatus status = mIWifiStaIface.setRoamingState(val);
+                WifiStatus status = iface.setRoamingState(val);
                 mVerboseLog.d("setRoamingState returned " + status.code);
                 return status.code;
             } catch (RemoteException e) {
@@ -2239,12 +2427,14 @@
     /**
      * Set firmware roaming configurations.
      *
+     * @param ifaceName Name of the interface.
      * @param config new roaming configuration object
      * @return true for success; false for failure
      */
-    public boolean configureRoaming(WifiNative.RoamingConfig config) {
+    public boolean configureRoaming(@NonNull String ifaceName, WifiNative.RoamingConfig config) {
         synchronized (sLock) {
-            if (mIWifiStaIface == null) return boolResult(false);
+            IWifiStaIface iface = getStaIface(ifaceName);
+            if (iface == null) return boolResult(false);
             try {
                 StaRoamingConfig roamingConfig = new StaRoamingConfig();
 
@@ -2275,7 +2465,7 @@
                     }
                 }
 
-                WifiStatus status = mIWifiStaIface.configureRoaming(roamingConfig);
+                WifiStatus status = iface.configureRoaming(roamingConfig);
                 if (!ok(status)) return false;
             } catch (RemoteException e) {
                 handleRemoteException(e);
diff --git a/service/java/com/android/server/wifi/WificondControl.java b/service/java/com/android/server/wifi/WificondControl.java
index 9f58715..68da98f 100644
--- a/service/java/com/android/server/wifi/WificondControl.java
+++ b/service/java/com/android/server/wifi/WificondControl.java
@@ -18,18 +18,22 @@
 
 import android.annotation.NonNull;
 import android.net.wifi.IApInterface;
+import android.net.wifi.IApInterfaceEventCallback;
 import android.net.wifi.IClientInterface;
 import android.net.wifi.IPnoScanEvent;
 import android.net.wifi.IScanEvent;
 import android.net.wifi.IWifiScannerImpl;
 import android.net.wifi.IWificond;
 import android.net.wifi.ScanResult;
+import android.net.wifi.WifiConfiguration;
 import android.net.wifi.WifiScanner;
 import android.net.wifi.WifiSsid;
 import android.os.Binder;
+import android.os.IBinder;
 import android.os.RemoteException;
 import android.util.Log;
 
+import com.android.server.wifi.WifiNative.SoftApListener;
 import com.android.server.wifi.hotspot2.NetworkDetail;
 import com.android.server.wifi.util.InformationElementUtil;
 import com.android.server.wifi.util.NativeUtil;
@@ -41,14 +45,17 @@
 import com.android.server.wifi.wificond.PnoSettings;
 import com.android.server.wifi.wificond.SingleScanSettings;
 
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.Set;
 
 /**
  * This class provides methods for WifiNative to send control commands to wificond.
  * NOTE: This class should only be used from WifiNative.
  */
-public class WificondControl {
+public class WificondControl implements IBinder.DeathRecipient {
     private boolean mVerboseLoggingEnabled = false;
 
     private static final String TAG = "WificondControl";
@@ -65,26 +72,31 @@
 
     // Cached wificond binder handlers.
     private IWificond mWificond;
-    private IClientInterface mClientInterface;
-    private IApInterface mApInterface;
-    private IWifiScannerImpl mWificondScanner;
-    private IScanEvent mScanEventHandler;
-    private IPnoScanEvent mPnoScanEventHandler;
-
-    private String mClientInterfaceName;
-
+    private HashMap<String, IClientInterface> mClientInterfaces = new HashMap<>();
+    private HashMap<String, IApInterface> mApInterfaces = new HashMap<>();
+    private HashMap<String, IWifiScannerImpl> mWificondScanners = new HashMap<>();
+    private HashMap<String, IScanEvent> mScanEventHandlers = new HashMap<>();
+    private HashMap<String, IPnoScanEvent> mPnoScanEventHandlers = new HashMap<>();
+    private HashMap<String, IApInterfaceEventCallback> mApInterfaceListeners = new HashMap<>();
+    private WifiNative.WificondDeathEventHandler mDeathEventHandler;
 
     private class ScanEventHandler extends IScanEvent.Stub {
+        private String mIfaceName;
+
+        ScanEventHandler(@NonNull String ifaceName) {
+            mIfaceName = ifaceName;
+        }
+
         @Override
         public void OnScanResultReady() {
             Log.d(TAG, "Scan result ready event");
-            mWifiMonitor.broadcastScanResultEvent(mClientInterfaceName);
+            mWifiMonitor.broadcastScanResultEvent(mIfaceName);
         }
 
         @Override
         public void OnScanFailed() {
             Log.d(TAG, "Scan failed event");
-            mWifiMonitor.broadcastScanFailedEvent(mClientInterfaceName);
+            mWifiMonitor.broadcastScanFailedEvent(mIfaceName);
         }
     }
 
@@ -96,10 +108,16 @@
     }
 
     private class PnoScanEventHandler extends IPnoScanEvent.Stub {
+        private String mIfaceName;
+
+        PnoScanEventHandler(@NonNull String ifaceName) {
+            mIfaceName = ifaceName;
+        }
+
         @Override
         public void OnPnoNetworkFound() {
             Log.d(TAG, "Pno scan result event");
-            mWifiMonitor.broadcastPnoScanResultEvent(mClientInterfaceName);
+            mWifiMonitor.broadcastPnoScanResultEvent(mIfaceName);
             mWifiInjector.getWifiMetrics().incrementPnoFoundNetworkEventCount();
         }
 
@@ -122,6 +140,38 @@
         }
     }
 
+    /**
+     * Listener for AP Interface events.
+     */
+    private class ApInterfaceEventCallback extends IApInterfaceEventCallback.Stub {
+        private SoftApListener mSoftApListener;
+
+        ApInterfaceEventCallback(SoftApListener listener) {
+            mSoftApListener = listener;
+        }
+
+        @Override
+        public void onNumAssociatedStationsChanged(int numStations) {
+            mSoftApListener.onNumAssociatedStationsChanged(numStations);
+        }
+    }
+
+    /**
+     * Called by the binder subsystem upon remote object death.
+     * Invoke all the register death handlers and clear state.
+     */
+    @Override
+    public void binderDied() {
+        Log.e(TAG, "Wificond died!");
+        if (mDeathEventHandler != null) {
+            mDeathEventHandler.onDeath();
+        }
+        clearState();
+        // Invalidate the global wificond handle on death. Will be refereshed
+        // on the next setup call.
+        mWificond = null;
+    }
+
     /** Enable or disable verbose logging of WificondControl.
      *  @param enable True to enable verbose logging. False to disable verbose logging.
      */
@@ -130,15 +180,64 @@
     }
 
     /**
-    * Setup driver for client mode via wificond.
-    * @return An IClientInterface as wificond client interface binder handler.
-    * Returns null on failure.
-    */
-    public IClientInterface setupDriverForClientMode(@NonNull String ifaceName) {
-        Log.d(TAG, "Setting up driver for client mode");
+     * Registers a death notification for wificond.
+     * @return Returns true on success.
+     */
+    public boolean registerDeathHandler(@NonNull WifiNative.WificondDeathEventHandler handler) {
+        if (mDeathEventHandler != null) {
+            Log.e(TAG, "Death handler already present");
+            return false;
+        }
+        mDeathEventHandler = handler;
+        return true;
+    }
+
+    /**
+     * Deregisters a death notification for wificond.
+     * @return Returns true on success.
+     */
+    public boolean deregisterDeathHandler() {
+        if (mDeathEventHandler == null) {
+            Log.e(TAG, "No Death handler present");
+            return false;
+        }
+        mDeathEventHandler = null;
+        return true;
+    }
+
+    /**
+     * Helper method to retrieve the global wificond handle and register for
+     * death notifications.
+     */
+    private boolean retrieveWificondAndRegisterForDeath() {
+        if (mWificond != null) {
+            Log.d(TAG, "Wificond handle already retrieved");
+            // We already have a wificond handle.
+            return true;
+        }
         mWificond = mWifiInjector.makeWificond();
         if (mWificond == null) {
             Log.e(TAG, "Failed to get reference to wificond");
+            return false;
+        }
+        try {
+            mWificond.asBinder().linkToDeath(this, 0);
+        } catch (RemoteException e) {
+            Log.e(TAG, "Failed to register death notification for wificond");
+            // The remote has already died.
+            return false;
+        }
+        return true;
+    }
+
+    /**
+    * Setup interface for client mode via wificond.
+    * @return An IClientInterface as wificond client interface binder handler.
+    * Returns null on failure.
+    */
+    public IClientInterface setupInterfaceForClientMode(@NonNull String ifaceName) {
+        Log.d(TAG, "Setting up interface for client mode");
+        if (!retrieveWificondAndRegisterForDeath()) {
             return null;
         }
 
@@ -157,19 +256,21 @@
         Binder.allowBlocking(clientInterface.asBinder());
 
         // Refresh Handlers
-        mClientInterface = clientInterface;
+        mClientInterfaces.put(ifaceName, clientInterface);
         try {
-            mClientInterfaceName = clientInterface.getInterfaceName();
-            mWificondScanner = mClientInterface.getWifiScannerImpl();
-            if (mWificondScanner == null) {
+            IWifiScannerImpl wificondScanner = clientInterface.getWifiScannerImpl();
+            if (wificondScanner == null) {
                 Log.e(TAG, "Failed to get WificondScannerImpl");
                 return null;
             }
-            Binder.allowBlocking(mWificondScanner.asBinder());
-            mScanEventHandler = new ScanEventHandler();
-            mWificondScanner.subscribeScanEvents(mScanEventHandler);
-            mPnoScanEventHandler = new PnoScanEventHandler();
-            mWificondScanner.subscribePnoScanEvents(mPnoScanEventHandler);
+            mWificondScanners.put(ifaceName, wificondScanner);
+            Binder.allowBlocking(wificondScanner.asBinder());
+            ScanEventHandler scanEventHandler = new ScanEventHandler(ifaceName);
+            mScanEventHandlers.put(ifaceName,  scanEventHandler);
+            wificondScanner.subscribeScanEvents(scanEventHandler);
+            PnoScanEventHandler pnoScanEventHandler = new PnoScanEventHandler(ifaceName);
+            mPnoScanEventHandlers.put(ifaceName,  pnoScanEventHandler);
+            wificondScanner.subscribePnoScanEvents(pnoScanEventHandler);
         } catch (RemoteException e) {
             Log.e(TAG, "Failed to refresh wificond scanner due to remote exception");
         }
@@ -178,15 +279,49 @@
     }
 
     /**
-    * Setup driver for softAp mode via wificond.
+     * Teardown a specific STA interface configured in wificond.
+     *
+     * @return Returns true on success.
+     */
+    public boolean tearDownClientInterface(@NonNull String ifaceName) {
+        boolean success;
+        try {
+            IWifiScannerImpl scannerImpl = mWificondScanners.get(ifaceName);
+            if (scannerImpl != null) {
+                scannerImpl.unsubscribeScanEvents();
+                scannerImpl.unsubscribePnoScanEvents();
+            }
+        } catch (RemoteException e) {
+            Log.e(TAG, "Failed to unsubscribe wificond scanner due to remote exception");
+            return false;
+        }
+
+        try {
+            success = mWificond.tearDownClientInterface(ifaceName);
+        } catch (RemoteException e1) {
+            Log.e(TAG, "Failed to teardown client interface due to remote exception");
+            return false;
+        }
+        if (!success) {
+            Log.e(TAG, "Failed to teardown client interface");
+            return false;
+        }
+
+        mClientInterfaces.remove(ifaceName);
+        mWificondScanners.remove(ifaceName);
+        mScanEventHandlers.remove(ifaceName);
+        mPnoScanEventHandlers.remove(ifaceName);
+        return true;
+    }
+
+    /**
+    * Setup interface for softAp mode via wificond.
     * @return An IApInterface as wificond Ap interface binder handler.
     * Returns null on failure.
     */
-    public IApInterface setupDriverForSoftApMode(@NonNull String ifaceName) {
-        Log.d(TAG, "Setting up driver for soft ap mode");
-        mWificond = mWifiInjector.makeWificond();
-        if (mWificond == null) {
-            Log.e(TAG, "Failed to get reference to wificond");
+    public IApInterface setupInterfaceForSoftApMode(@NonNull String ifaceName) {
+        Log.d(TAG, "Setting up interface for soft ap mode");
+        if (!retrieveWificondAndRegisterForDeath()) {
             return null;
         }
 
@@ -205,12 +340,33 @@
         Binder.allowBlocking(apInterface.asBinder());
 
         // Refresh Handlers
-        mApInterface = apInterface;
-
+        mApInterfaces.put(ifaceName, apInterface);
         return apInterface;
     }
 
     /**
+     * Teardown a specific AP interface configured in wificond.
+     *
+     * @return Returns true on success.
+     */
+    public boolean tearDownSoftApInterface(@NonNull String ifaceName) {
+        boolean success;
+        try {
+            success = mWificond.tearDownApInterface(ifaceName);
+        } catch (RemoteException e1) {
+            Log.e(TAG, "Failed to teardown AP interface due to remote exception");
+            return false;
+        }
+        if (!success) {
+            Log.e(TAG, "Failed to teardown AP interface");
+            return false;
+        }
+        mApInterfaces.remove(ifaceName);
+        mApInterfaceListeners.remove(ifaceName);
+        return true;
+    }
+
+    /**
     * Teardown all interfaces configured in wificond.
     * @return Returns true on success.
     */
@@ -218,26 +374,17 @@
         Log.d(TAG, "tearing down interfaces in wificond");
         // Explicitly refresh the wificodn handler because |tearDownInterfaces()|
         // could be used to cleanup before we setup any interfaces.
-        mWificond = mWifiInjector.makeWificond();
-        if (mWificond == null) {
-            Log.e(TAG, "Failed to get reference to wificond");
+        if (!retrieveWificondAndRegisterForDeath()) {
             return false;
         }
 
         try {
-            if (mWificondScanner != null) {
-                mWificondScanner.unsubscribeScanEvents();
-                mWificondScanner.unsubscribePnoScanEvents();
+            for (Map.Entry<String, IWifiScannerImpl> entry : mWificondScanners.entrySet()) {
+                entry.getValue().unsubscribeScanEvents();
+                entry.getValue().unsubscribePnoScanEvents();
             }
             mWificond.tearDownInterfaces();
-
-            // Refresh handlers
-            mClientInterface = null;
-            mWificondScanner = null;
-            mPnoScanEventHandler = null;
-            mScanEventHandler = null;
-            mApInterface = null;
-
+            clearState();
             return true;
         } catch (RemoteException e) {
             Log.e(TAG, "Failed to tear down interfaces due to remote exception");
@@ -246,13 +393,17 @@
         return false;
     }
 
+    /** Helper function to look up the interface handle using name */
+    private IClientInterface getClientInterface(@NonNull String ifaceName) {
+        return mClientInterfaces.get(ifaceName);
+    }
+
     /**
     * Disable wpa_supplicant via wificond.
     * @return Returns true on success.
     */
     public boolean disableSupplicant() {
-        if (mWificond == null) {
-            Log.e(TAG, "No valid handler");
+        if (!retrieveWificondAndRegisterForDeath()) {
             return false;
         }
         try {
@@ -268,11 +419,9 @@
     * @return Returns true on success.
     */
     public boolean enableSupplicant() {
-        if (mWificond == null) {
-            Log.e(TAG, "No valid wificond handler");
+        if (!retrieveWificondAndRegisterForDeath()) {
             return false;
         }
-
         try {
             return mWificond.enableSupplicant();
         } catch (RemoteException e) {
@@ -282,19 +431,21 @@
     }
 
     /**
-    * Request signal polling to wificond.
-    * Returns an SignalPollResult object.
-    * Returns null on failure.
-    */
-    public WifiNative.SignalPollResult signalPoll() {
-        if (mClientInterface == null) {
+     * Request signal polling to wificond.
+     * @param ifaceName Name of the interface.
+     * Returns an SignalPollResult object.
+     * Returns null on failure.
+     */
+    public WifiNative.SignalPollResult signalPoll(@NonNull String ifaceName) {
+        IClientInterface iface = getClientInterface(ifaceName);
+        if (iface == null) {
             Log.e(TAG, "No valid wificond client interface handler");
             return null;
         }
 
         int[] resultArray;
         try {
-            resultArray = mClientInterface.signalPoll();
+            resultArray = iface.signalPoll();
             if (resultArray == null || resultArray.length != 3) {
                 Log.e(TAG, "Invalid signal poll result from wificond");
                 return null;
@@ -311,19 +462,21 @@
     }
 
     /**
-    * Fetch TX packet counters on current connection from wificond.
-    * Returns an TxPacketCounters object.
-    * Returns null on failure.
-    */
-    public WifiNative.TxPacketCounters getTxPacketCounters() {
-        if (mClientInterface == null) {
+     * Fetch TX packet counters on current connection from wificond.
+     * @param ifaceName Name of the interface.
+     * Returns an TxPacketCounters object.
+     * Returns null on failure.
+     */
+    public WifiNative.TxPacketCounters getTxPacketCounters(@NonNull String ifaceName) {
+        IClientInterface iface = getClientInterface(ifaceName);
+        if (iface == null) {
             Log.e(TAG, "No valid wificond client interface handler");
             return null;
         }
 
         int[] resultArray;
         try {
-            resultArray = mClientInterface.getPacketCounters();
+            resultArray = iface.getPacketCounters();
             if (resultArray == null || resultArray.length != 2) {
                 Log.e(TAG, "Invalid signal poll result from wificond");
                 return null;
@@ -338,23 +491,30 @@
         return counters;
     }
 
+    /** Helper function to look up the scanner impl handle using name */
+    private IWifiScannerImpl getScannerImpl(@NonNull String ifaceName) {
+        return mWificondScanners.get(ifaceName);
+    }
+
     /**
     * Fetch the latest scan result from kernel via wificond.
+    * @param ifaceName Name of the interface.
     * @return Returns an ArrayList of ScanDetail.
     * Returns an empty ArrayList on failure.
     */
-    public ArrayList<ScanDetail> getScanResults(int scanType) {
+    public ArrayList<ScanDetail> getScanResults(@NonNull String ifaceName, int scanType) {
         ArrayList<ScanDetail> results = new ArrayList<>();
-        if (mWificondScanner == null) {
+        IWifiScannerImpl scannerImpl = getScannerImpl(ifaceName);
+        if (scannerImpl == null) {
             Log.e(TAG, "No valid wificond scanner interface handler");
             return results;
         }
         try {
             NativeScanResult[] nativeResults;
             if (scanType == SCAN_TYPE_SINGLE_SCAN) {
-                nativeResults = mWificondScanner.getScanResults();
+                nativeResults = scannerImpl.getScanResults();
             } else {
-                nativeResults = mWificondScanner.getPnoScanResults();
+                nativeResults = scannerImpl.getPnoScanResults();
             }
             for (NativeScanResult result : nativeResults) {
                 WifiSsid wifiSsid = WifiSsid.createFromByteArray(result.ssid);
@@ -409,12 +569,16 @@
 
     /**
      * Start a scan using wificond for the given parameters.
+     * @param ifaceName Name of the interface.
      * @param freqs list of frequencies to scan for, if null scan all supported channels.
      * @param hiddenNetworkSSIDs List of hidden networks to be scanned for.
      * @return Returns true on success.
      */
-    public boolean scan(Set<Integer> freqs, Set<String> hiddenNetworkSSIDs) {
-        if (mWificondScanner == null) {
+    public boolean scan(@NonNull String ifaceName,
+                        Set<Integer> freqs,
+                        Set<String> hiddenNetworkSSIDs) {
+        IWifiScannerImpl scannerImpl = getScannerImpl(ifaceName);
+        if (scannerImpl == null) {
             Log.e(TAG, "No valid wificond scanner interface handler");
             return false;
         }
@@ -443,7 +607,7 @@
         }
 
         try {
-            return mWificondScanner.scan(settings);
+            return scannerImpl.scan(settings);
         } catch (RemoteException e1) {
             Log.e(TAG, "Failed to request scan due to remote exception");
         }
@@ -452,11 +616,13 @@
 
     /**
      * Start PNO scan.
+     * @param ifaceName Name of the interface.
      * @param pnoSettings Pno scan configuration.
      * @return true on success.
      */
-    public boolean startPnoScan(WifiNative.PnoSettings pnoSettings) {
-        if (mWificondScanner == null) {
+    public boolean startPnoScan(@NonNull String ifaceName, WifiNative.PnoSettings pnoSettings) {
+        IWifiScannerImpl scannerImpl = getScannerImpl(ifaceName);
+        if (scannerImpl == null) {
             Log.e(TAG, "No valid wificond scanner interface handler");
             return false;
         }
@@ -482,7 +648,7 @@
         }
 
         try {
-            boolean success = mWificondScanner.startPnoScan(settings);
+            boolean success = scannerImpl.startPnoScan(settings);
             mWifiInjector.getWifiMetrics().incrementPnoScanStartAttempCount();
             if (!success) {
                 mWifiInjector.getWifiMetrics().incrementPnoScanFailedCount();
@@ -496,15 +662,17 @@
 
     /**
      * Stop PNO scan.
+     * @param ifaceName Name of the interface.
      * @return true on success.
      */
-    public boolean stopPnoScan() {
-        if (mWificondScanner == null) {
+    public boolean stopPnoScan(@NonNull String ifaceName) {
+        IWifiScannerImpl scannerImpl = getScannerImpl(ifaceName);
+        if (scannerImpl == null) {
             Log.e(TAG, "No valid wificond scanner interface handler");
             return false;
         }
         try {
-            return mWificondScanner.stopPnoScan();
+            return scannerImpl.stopPnoScan();
         } catch (RemoteException e1) {
             Log.e(TAG, "Failed to stop pno scan due to remote exception");
         }
@@ -513,20 +681,21 @@
 
     /**
      * Abort ongoing single scan.
+     * @param ifaceName Name of the interface.
      */
-    public void abortScan() {
-        if (mWificondScanner == null) {
+    public void abortScan(@NonNull String ifaceName) {
+        IWifiScannerImpl scannerImpl = getScannerImpl(ifaceName);
+        if (scannerImpl == null) {
             Log.e(TAG, "No valid wificond scanner interface handler");
             return;
         }
         try {
-            mWificondScanner.abortScan();
+            scannerImpl.abortScan();
         } catch (RemoteException e1) {
             Log.e(TAG, "Failed to request abortScan due to remote exception");
         }
     }
 
-
     /**
      * Query the list of valid frequencies for the provided band.
      * The result depends on the on the country code that has been set.
@@ -560,4 +729,115 @@
         }
         return null;
     }
+
+    /** Helper function to look up the interface handle using name */
+    private IApInterface getApInterface(@NonNull String ifaceName) {
+        return mApInterfaces.get(ifaceName);
+    }
+
+    /**
+     * Start Soft AP operation using the provided configuration.
+     *
+     * @param ifaceName Name of the interface.
+     * @param config Configuration to use for the soft ap created.
+     * @param listener Callback for AP events.
+     * @return true on success, false otherwise.
+     */
+    public boolean startSoftAp(@NonNull String ifaceName,
+                               WifiConfiguration config,
+                               SoftApListener listener) {
+        IApInterface iface = getApInterface(ifaceName);
+        if (iface == null) {
+            Log.e(TAG, "No valid ap interface handler");
+            return false;
+        }
+        int encryptionType = getIApInterfaceEncryptionType(config);
+        try {
+            // TODO(b/67745880) Note that config.SSID is intended to be either a
+            // hex string or "double quoted".
+            // However, it seems that whatever is handing us these configurations does not obey
+            // this convention.
+            boolean success = iface.writeHostapdConfig(
+                    config.SSID.getBytes(StandardCharsets.UTF_8), config.hiddenSSID,
+                    config.apChannel, encryptionType,
+                    (config.preSharedKey != null)
+                            ? config.preSharedKey.getBytes(StandardCharsets.UTF_8)
+                            : new byte[0]);
+            if (!success) {
+                Log.e(TAG, "Failed to write hostapd configuration");
+                return false;
+            }
+            IApInterfaceEventCallback  callback = new ApInterfaceEventCallback(listener);
+            mApInterfaceListeners.put(ifaceName, callback);
+            success = iface.startHostapd(callback);
+            if (!success) {
+                Log.e(TAG, "Failed to start hostapd.");
+                return false;
+            }
+        } catch (RemoteException e) {
+            Log.e(TAG, "Exception in starting soft AP: " + e);
+            return false;
+        }
+        return true;
+    }
+
+    /**
+     * Stop the ongoing Soft AP operation.
+     *
+     * @param ifaceName Name of the interface.
+     * @return true on success, false otherwise.
+     */
+    public boolean stopSoftAp(@NonNull String ifaceName) {
+        IApInterface iface = getApInterface(ifaceName);
+        if (iface == null) {
+            Log.e(TAG, "No valid ap interface handler");
+            return false;
+        }
+        try {
+            boolean success = iface.stopHostapd();
+            if (!success) {
+                Log.e(TAG, "Failed to stop hostapd.");
+                return false;
+            }
+        } catch (RemoteException e) {
+            Log.e(TAG, "Exception in stopping soft AP: " + e);
+            return false;
+        }
+        mApInterfaceListeners.remove(ifaceName);
+        return true;
+    }
+
+    private static int getIApInterfaceEncryptionType(WifiConfiguration localConfig) {
+        int encryptionType;
+        switch (localConfig.getAuthType()) {
+            case WifiConfiguration.KeyMgmt.NONE:
+                encryptionType = IApInterface.ENCRYPTION_TYPE_NONE;
+                break;
+            case WifiConfiguration.KeyMgmt.WPA_PSK:
+                encryptionType = IApInterface.ENCRYPTION_TYPE_WPA;
+                break;
+            case WifiConfiguration.KeyMgmt.WPA2_PSK:
+                encryptionType = IApInterface.ENCRYPTION_TYPE_WPA2;
+                break;
+            default:
+                // We really shouldn't default to None, but this was how NetworkManagementService
+                // used to do this.
+                encryptionType = IApInterface.ENCRYPTION_TYPE_NONE;
+                break;
+        }
+        return encryptionType;
+    }
+
+    /**
+     * Clear all internal handles.
+     */
+    private void clearState() {
+        // Refresh handlers
+        mClientInterfaces.clear();
+        mWificondScanners.clear();
+        mPnoScanEventHandlers.clear();
+        mScanEventHandlers.clear();
+        mApInterfaces.clear();
+        mApInterfaceListeners.clear();
+    }
 }
diff --git a/service/java/com/android/server/wifi/hotspot2/OsuNetworkConnection.java b/service/java/com/android/server/wifi/hotspot2/OsuNetworkConnection.java
new file mode 100644
index 0000000..f1bf117
--- /dev/null
+++ b/service/java/com/android/server/wifi/hotspot2/OsuNetworkConnection.java
@@ -0,0 +1,270 @@
+/*
+ * Copyright 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.wifi.hotspot2;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.net.Network;
+import android.net.NetworkInfo;
+import android.net.wifi.WifiConfiguration;
+import android.net.wifi.WifiInfo;
+import android.net.wifi.WifiManager;
+import android.net.wifi.WifiSsid;
+import android.os.Handler;
+import android.text.TextUtils;
+import android.util.Log;
+
+/**
+ * Responsible for setup/monitor on Wi-Fi state and connection to the OSU AP.
+ */
+public class OsuNetworkConnection {
+    private static final String TAG = "OsuNetworkConnection";
+
+    private final Context mContext;
+
+    private boolean mVerboseLoggingEnabled = false;
+    private WifiManager mWifiManager;
+    private Callbacks mCallbacks;
+    private boolean mConnected = false;
+    private int mNetworkId = -1;
+    private boolean mWifiEnabled = false;
+
+    /**
+     * Callbacks on Wi-Fi connection state changes.
+     */
+    public interface Callbacks {
+        /**
+         * Invoked when network connection is established with IP connectivity.
+         *
+         * @param network {@link Network} associated with the connected network.
+         */
+        void onConnected(Network network);
+
+        /**
+         * Invoked when the targeted network is disconnected.
+         */
+        void onDisconnected();
+
+        /**
+         * Invoked when a timer tracking connection request is not reset by successfull connection.
+         */
+        void onTimeOut();
+
+        /**
+         * Invoked when Wifi is enabled.
+         */
+        void onWifiEnabled();
+
+        /**
+         * Invoked when Wifi is disabled.
+         */
+        void onWifiDisabled();
+    }
+
+    /**
+     * Create an instance of {@link NetworkConnection} for the specified Wi-Fi network.
+     * @param context The application context
+     */
+    public OsuNetworkConnection(Context context) {
+        mContext = context;
+    }
+
+    /**
+     * Called to initialize tracking of wifi state and network events by registering for the
+     * corresponding intents.
+     */
+    public void init(Handler handler) {
+        IntentFilter filter = new IntentFilter();
+        filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
+        filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
+        BroadcastReceiver receiver = new BroadcastReceiver() {
+            @Override
+            public void onReceive(Context context, Intent intent) {
+                String action = intent.getAction();
+                if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
+                    handleNetworkStateChanged(
+                            intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO),
+                            intent.getParcelableExtra(WifiManager.EXTRA_WIFI_INFO));
+                } else if (action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {
+                    int state = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,
+                            WifiManager.WIFI_STATE_UNKNOWN);
+                    handleWifiStateChanged(state);
+                }
+            }
+        };
+        mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
+        mContext.registerReceiver(receiver, filter, null, handler);
+        mWifiEnabled = mWifiManager.isWifiEnabled();
+    }
+
+    /**
+     * Disconnect, if required in the two cases
+     * - still connected to the OSU AP
+     * - connection to OSU AP was requested and in progress
+     */
+    public void disconnectIfNeeded() {
+        if (mNetworkId < 0) {
+            if (mVerboseLoggingEnabled) {
+                Log.v(TAG, "No connection to tear down");
+            }
+            return;
+        }
+        mWifiManager.removeNetwork(mNetworkId);
+        mNetworkId = -1;
+        mConnected = false;
+        if (mCallbacks != null) {
+            mCallbacks.onDisconnected();
+        }
+    }
+
+    /**
+     * Register for network and Wifi state events
+     * @param callbacks The callbacks to be invoked on network change events
+     */
+    public void setEventCallback(Callbacks callbacks) {
+        mCallbacks = callbacks;
+    }
+
+    /**
+     * Connect to a OSU Wi-Fi network specified by the given SSID. The security type of the Wi-Fi
+     * network is either open or OSEN (OSU Server-only authenticated layer 2 Encryption Network).
+     * When network access identifier is provided, OSEN is used.
+     *
+     * @param ssid The SSID to connect to
+     * @param nai Network access identifier of the network
+     *
+     * @return boolean true if connection was successfully initiated
+     */
+    public boolean connect(WifiSsid ssid, String nai) {
+        if (mConnected) {
+            if (mVerboseLoggingEnabled) {
+                // Already connected
+                Log.v(TAG, "Connect called twice");
+            }
+            return true;
+        }
+        if (!mWifiManager.isWifiEnabled()) {
+            Log.w(TAG, "Wifi is not enabled");
+            return false;
+        }
+        WifiConfiguration config = new WifiConfiguration();
+        config.SSID = "\"" + ssid.toString() + "\"";
+        if (TextUtils.isEmpty(nai)) {
+            config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
+        } else {
+            // TODO(sohanirao): Handle OSEN.
+            Log.w(TAG, "OSEN not supported");
+            return false;
+        }
+        mNetworkId = mWifiManager.addNetwork(config);
+        if (mNetworkId < 0) {
+            Log.e(TAG, "Unable to add network");
+            return false;
+        }
+        if (!mWifiManager.enableNetwork(mNetworkId, true)) {
+            Log.e(TAG, "Unable to enable network " + mNetworkId);
+            disconnectIfNeeded();
+            return false;
+        }
+        if (mVerboseLoggingEnabled) {
+            Log.v(TAG, "Current network ID " + mNetworkId);
+        }
+        // TODO(sohanirao): setup alarm to time out the connection attempt.
+        return true;
+    }
+
+    /**
+     * Method to update logging level in this class
+     * @param verbose more than 0 enables verbose logging
+     */
+    public void enableVerboseLogging(int verbose) {
+        mVerboseLoggingEnabled = verbose > 0 ? true : false;
+    }
+
+    /**
+     * Handle network state changed events.
+     *
+     * @param networkInfo {@link NetworkInfo} indicating the current network state
+     * @param wifiInfo {@link WifiInfo} associated with the current network when connected
+     */
+    private void handleNetworkStateChanged(NetworkInfo networkInfo, WifiInfo wifiInfo) {
+        if (networkInfo == null) {
+            Log.w(TAG, "NetworkInfo not provided for network state changed event");
+            return;
+        }
+        switch (networkInfo.getDetailedState()) {
+            case CONNECTED:
+                if (mVerboseLoggingEnabled) {
+                    Log.v(TAG, "Connected event received");
+                }
+                if (wifiInfo == null) {
+                    Log.w(TAG, "WifiInfo not provided for network state changed event");
+                    return;
+                }
+                handleConnectedEvent(wifiInfo);
+                break;
+            case DISCONNECTED:
+                if (mVerboseLoggingEnabled) {
+                    Log.v(TAG, "Disconnected event received");
+                }
+                disconnectIfNeeded();
+                break;
+            default:
+                if (mVerboseLoggingEnabled) {
+                    Log.v(TAG, "Ignore uninterested state: " + networkInfo.getDetailedState());
+                }
+                break;
+        }
+    }
+
+    /**
+     * Handle network connected event.
+     *
+     * @param wifiInfo {@link WifiInfo} associated with the current connection
+     */
+    private void handleConnectedEvent(WifiInfo wifiInfo) {
+        if (mVerboseLoggingEnabled) {
+            Log.v(TAG, "handleConnectedEvent " + wifiInfo.getNetworkId());
+        }
+        if (wifiInfo.getNetworkId() != mNetworkId) {
+            disconnectIfNeeded();
+            return;
+        }
+        if (!mConnected) {
+            mConnected = true;
+            if (mCallbacks != null) {
+                mCallbacks.onConnected(mWifiManager.getCurrentNetwork());
+            }
+        }
+    }
+
+    /**
+     * Handle Wifi state change event
+     */
+    private void handleWifiStateChanged(int state) {
+        if (state == WifiManager.WIFI_STATE_DISABLED && mWifiEnabled) {
+            mWifiEnabled = false;
+            if (mCallbacks != null) mCallbacks.onWifiDisabled();
+        }
+        if (state == WifiManager.WIFI_STATE_ENABLED && !mWifiEnabled) {
+            mWifiEnabled = true;
+            if (mCallbacks != null) mCallbacks.onWifiEnabled();
+        }
+    }
+}
diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointManager.java b/service/java/com/android/server/wifi/hotspot2/PasspointManager.java
index 3580c83..fec3dd8 100644
--- a/service/java/com/android/server/wifi/hotspot2/PasspointManager.java
+++ b/service/java/com/android/server/wifi/hotspot2/PasspointManager.java
@@ -33,8 +33,10 @@
 import android.net.wifi.ScanResult;
 import android.net.wifi.WifiConfiguration;
 import android.net.wifi.WifiEnterpriseConfig;
+import android.net.wifi.hotspot2.IProvisioningCallback;
 import android.net.wifi.hotspot2.OsuProvider;
 import android.net.wifi.hotspot2.PasspointConfiguration;
+import android.os.Looper;
 import android.os.UserHandle;
 import android.text.TextUtils;
 import android.util.Log;
@@ -99,6 +101,7 @@
     private final WifiConfigManager mWifiConfigManager;
     private final CertificateVerifier mCertVerifier;
     private final WifiMetrics mWifiMetrics;
+    private final PasspointProvisioner mPasspointProvisioner;
 
     // Counter used for assigning unique identifier to each provider.
     private long mProviderIndex;
@@ -212,10 +215,27 @@
         mProviderIndex = 0;
         wifiConfigStore.registerStoreData(objectFactory.makePasspointConfigStoreData(
                 mKeyStore, mSimAccessor, new DataSourceHandler()));
+        mPasspointProvisioner = objectFactory.makePasspointProvisioner(context,
+                objectFactory.makeOsuNetworkConnection(context));
         sPasspointManager = this;
     }
 
     /**
+     * Initializes the provisioning flow with a looper
+     */
+    public void initializeProvisioner(Looper looper) {
+        mPasspointProvisioner.init(looper);
+    }
+
+    /**
+     * Enable verbose logging
+     * @param verbose more than 0 enables verbose logging
+     */
+    public void enableVerboseLogging(int verbose) {
+        mPasspointProvisioner.enableVerboseLogging(verbose);
+    }
+
+    /**
      * Add or update a Passpoint provider with the given configuration.
      *
      * Each provider is uniquely identified by its FQDN (Fully Qualified Domain Name).
@@ -704,4 +724,16 @@
         mProviders.put(passpointConfig.getHomeSp().getFqdn(), provider);
         return true;
     }
+
+    /**
+     * Start the subscription provisioning flow with a provider.
+     * @param callingUid integer indicating the uid of the caller
+     * @param provider {@link OsuProvider} the provider to subscribe to
+     * @param callback {@link IProvisioningCallback} callback to update status to the caller
+     * @return boolean return value from the provisioning method
+     */
+    public boolean startSubscriptionProvisioning(int callingUid, OsuProvider provider,
+            IProvisioningCallback callback) {
+        return mPasspointProvisioner.startSubscriptionProvisioning(callingUid, provider, callback);
+    }
 }
diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointObjectFactory.java b/service/java/com/android/server/wifi/hotspot2/PasspointObjectFactory.java
index c41c49a..71fc47a 100644
--- a/service/java/com/android/server/wifi/hotspot2/PasspointObjectFactory.java
+++ b/service/java/com/android/server/wifi/hotspot2/PasspointObjectFactory.java
@@ -16,6 +16,7 @@
 
 package com.android.server.wifi.hotspot2;
 
+import android.content.Context;
 import android.net.wifi.hotspot2.PasspointConfiguration;
 
 import com.android.server.wifi.Clock;
@@ -95,4 +96,25 @@
     public CertificateVerifier makeCertificateVerifier() {
         return new CertificateVerifier();
     }
+
+    /**
+     * Create an instance of {@link PasspointProvisioner}.
+     *
+     * @param context
+     * @return {@link PasspointProvisioner}
+     */
+    public PasspointProvisioner makePasspointProvisioner(Context context,
+            OsuNetworkConnection osuNetworkConnection) {
+        return new PasspointProvisioner(context, osuNetworkConnection);
+    }
+
+    /**
+     * Create an instance of {@link OsuNetworkConnection}.
+     *
+     * @param context
+     * @return {@link OsuNetworkConnection}
+     */
+    public OsuNetworkConnection makeOsuNetworkConnection(Context context) {
+        return new OsuNetworkConnection(context);
+    }
 }
diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointProvisioner.java b/service/java/com/android/server/wifi/hotspot2/PasspointProvisioner.java
new file mode 100644
index 0000000..d3bb773
--- /dev/null
+++ b/service/java/com/android/server/wifi/hotspot2/PasspointProvisioner.java
@@ -0,0 +1,309 @@
+/*
+ * Copyright 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.wifi.hotspot2;
+
+import android.content.Context;
+import android.net.Network;
+import android.net.wifi.hotspot2.IProvisioningCallback;
+import android.net.wifi.hotspot2.OsuProvider;
+import android.net.wifi.hotspot2.ProvisioningCallback;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.RemoteException;
+import android.util.Log;
+
+/**
+ * Provides methods to carry out provisioning flow
+ */
+public class PasspointProvisioner {
+    private static final String TAG = "PasspointProvisioner";
+
+    private static final int PROVISIONING_STATUS = 0;
+    private static final int PROVISIONING_FAILURE = 1;
+
+    private final Context mContext;
+    private final ProvisioningStateMachine mProvisioningStateMachine;
+    private final OsuNetworkCallbacks mOsuNetworkCallbacks;
+    private final OsuNetworkConnection mOsuNetworkConnection;
+
+    private int mCallingUid;
+    private boolean mVerboseLoggingEnabled = false;
+
+    PasspointProvisioner(Context context, OsuNetworkConnection osuNetworkConnection) {
+        mContext = context;
+        mOsuNetworkConnection = osuNetworkConnection;
+        mProvisioningStateMachine = new ProvisioningStateMachine();
+        mOsuNetworkCallbacks = new OsuNetworkCallbacks();
+    }
+
+    /**
+     * Sets up for provisioning
+     * @param looper Looper on which the Provisioning state machine will run
+     */
+    public void init(Looper looper) {
+        mProvisioningStateMachine.start(new Handler(looper));
+        mOsuNetworkConnection.init(mProvisioningStateMachine.getHandler());
+    }
+
+    /**
+     * Enable verbose logging to help debug failures
+     * @param level integer indicating verbose logging enabled if > 0
+     */
+    public void enableVerboseLogging(int level) {
+        mVerboseLoggingEnabled = (level > 0) ? true : false;
+        mOsuNetworkConnection.enableVerboseLogging(level);
+    }
+
+    /**
+     * Start provisioning flow with a given provider.
+     * @param callingUid calling uid.
+     * @param provider {@link OsuProvider} to provision with.
+     * @param callback {@link IProvisioningCallback} to provide provisioning status.
+     * @return boolean value, true if provisioning was started, false otherwise.
+     *
+     * Implements HS2.0 provisioning flow with a given HS2.0 provider.
+     */
+    public boolean startSubscriptionProvisioning(int callingUid, OsuProvider provider,
+            IProvisioningCallback callback) {
+        mCallingUid = callingUid;
+
+        Log.v(TAG, "Provisioning started with " + provider.toString());
+
+        mProvisioningStateMachine.getHandler().post(() -> {
+            mProvisioningStateMachine.startProvisioning(provider, callback);
+        });
+
+        return true;
+    }
+
+    /**
+     * Handles the provisioning flow state transitions
+     */
+    class ProvisioningStateMachine {
+        private static final String TAG = "ProvisioningStateMachine";
+
+        private static final int DEFAULT_STATE                             = 0;
+        private static final int INITIAL_STATE                             = 1;
+        private static final int WAITING_TO_CONNECT                        = 2;
+        private static final int OSU_AP_CONNECTED                          = 3;
+        private static final int FAILED_STATE                              = 4;
+
+        private OsuProvider mOsuProvider;
+        private IProvisioningCallback mProvisioningCallback;
+        private Handler mHandler;
+        private int mState;
+
+        ProvisioningStateMachine() {
+            mState = DEFAULT_STATE;
+        }
+
+        /**
+         * Initializes and starts the state machine with a handler to handle incoming events
+         */
+        public void start(Handler handler) {
+            mHandler = handler;
+            changeState(INITIAL_STATE);
+        }
+
+        /**
+         * Returns the handler on which a runnable can be posted
+         * @return Handler State Machine's handler
+         */
+        public Handler getHandler() {
+            return mHandler;
+        }
+
+        /**
+         * Start Provisioning with the Osuprovider and invoke callbacks
+         * @param provider OsuProvider to provision with
+         * @param callback IProvisioningCallback to invoke callbacks on
+         */
+        public void startProvisioning(OsuProvider provider, IProvisioningCallback callback) {
+            if (mVerboseLoggingEnabled) {
+                Log.v(TAG, "startProvisioning received in state=" + mState);
+            }
+            if (mState != INITIAL_STATE) {
+                Log.v(TAG, "State Machine needs to be reset before starting provisioning");
+                resetStateMachine();
+            }
+            mProvisioningCallback = callback;
+            mOsuProvider = provider;
+
+            // Register for network and wifi state events during provisioning flow
+            mOsuNetworkConnection.setEventCallback(mOsuNetworkCallbacks);
+
+            if (mOsuNetworkConnection.connect(mOsuProvider.getOsuSsid(),
+                    mOsuProvider.getNetworkAccessIdentifier())) {
+                invokeProvisioningCallback(PROVISIONING_STATUS,
+                        ProvisioningCallback.OSU_STATUS_AP_CONNECTING);
+                changeState(WAITING_TO_CONNECT);
+            } else {
+                invokeProvisioningCallback(PROVISIONING_FAILURE,
+                        ProvisioningCallback.OSU_FAILURE_AP_CONNECTION);
+                enterFailedState();
+            }
+        }
+
+        /**
+         * Handle Wifi Disable event
+         */
+        public void handleWifiDisabled() {
+            if (mVerboseLoggingEnabled) {
+                Log.v(TAG, "Wifi Disabled in state=" + mState);
+            }
+            if (mState == INITIAL_STATE || mState == FAILED_STATE) {
+                Log.w(TAG, "Wifi Disable unhandled in state=" + mState);
+                return;
+            }
+            invokeProvisioningCallback(PROVISIONING_FAILURE,
+                    ProvisioningCallback.OSU_FAILURE_AP_CONNECTION);
+            enterFailedState();
+        }
+
+        private void resetStateMachine() {
+            // Set to null so that no callbacks are invoked during reset
+            mProvisioningCallback = null;
+            if (mState != INITIAL_STATE || mState != FAILED_STATE) {
+                // Transition through Failed state to clean up
+                enterFailedState();
+            }
+            changeState(INITIAL_STATE);
+        }
+
+        /**
+         * Connected event received
+         * @param network Network object for this connection
+         */
+        public void handleConnectedEvent(Network network) {
+            if (mVerboseLoggingEnabled) {
+                Log.v(TAG, "Connected event received in state=" + mState);
+            }
+            if (mState != WAITING_TO_CONNECT) {
+                // Not waiting for a connection
+                Log.w(TAG, "Connection event unhandled in state=" + mState);
+                return;
+            }
+            invokeProvisioningCallback(PROVISIONING_STATUS,
+                    ProvisioningCallback.OSU_STATUS_AP_CONNECTED);
+            changeState(OSU_AP_CONNECTED);
+        }
+
+        /**
+         * Disconnect event received
+         */
+        public void handleDisconnect() {
+            if (mVerboseLoggingEnabled) {
+                Log.v(TAG, "Connection failed in state=" + mState);
+            }
+            if (mState == INITIAL_STATE || mState == FAILED_STATE) {
+                Log.w(TAG, "Disconnect event unhandled in state=" + mState);
+                return;
+            }
+            invokeProvisioningCallback(PROVISIONING_FAILURE,
+                    ProvisioningCallback.OSU_FAILURE_AP_CONNECTION);
+            enterFailedState();
+        }
+
+        private void changeState(int nextState) {
+            if (nextState != mState) {
+                if (mVerboseLoggingEnabled) {
+                    Log.v(TAG, "Changing state from " + mState + " -> " + nextState);
+                }
+                mState = nextState;
+            }
+        }
+
+        private void invokeProvisioningCallback(int callbackType, int status) {
+            if (mProvisioningCallback == null) {
+                Log.e(TAG, "Provisioning callback " + callbackType + " with status " + status
+                        + " not invoked, callback is null");
+                return;
+            }
+            try {
+                if (callbackType == PROVISIONING_STATUS) {
+                    mProvisioningCallback.onProvisioningStatus(status);
+                } else {
+                    mProvisioningCallback.onProvisioningFailure(status);
+                }
+            } catch (RemoteException e) {
+                if (callbackType == PROVISIONING_STATUS) {
+                    Log.e(TAG, "Remote Exception while posting Provisioning status " + status);
+                } else {
+                    Log.e(TAG, "Remote Exception while posting Provisioning failure " + status);
+                }
+            }
+        }
+
+        private void enterFailedState() {
+            changeState(FAILED_STATE);
+            mOsuNetworkConnection.setEventCallback(null);
+            mOsuNetworkConnection.disconnectIfNeeded();
+        }
+    }
+
+    /**
+     * Callbacks for network and wifi events
+     */
+    class OsuNetworkCallbacks implements OsuNetworkConnection.Callbacks {
+
+        OsuNetworkCallbacks() {
+        }
+
+        @Override
+        public void onConnected(Network network) {
+            Log.v(TAG, "onConnected to " + network);
+            if (network == null) {
+                mProvisioningStateMachine.getHandler().post(() -> {
+                    mProvisioningStateMachine.handleDisconnect();
+                });
+            } else {
+                mProvisioningStateMachine.getHandler().post(() -> {
+                    mProvisioningStateMachine.handleConnectedEvent(network);
+                });
+            }
+        }
+
+        @Override
+        public void onDisconnected() {
+            Log.v(TAG, "onDisconnected");
+            mProvisioningStateMachine.getHandler().post(() -> {
+                mProvisioningStateMachine.handleDisconnect();
+            });
+        }
+
+        @Override
+        public void onTimeOut() {
+            Log.v(TAG, "Timed out waiting for connection to OSU AP");
+            mProvisioningStateMachine.getHandler().post(() -> {
+                mProvisioningStateMachine.handleDisconnect();
+            });
+        }
+
+        @Override
+        public void onWifiEnabled() {
+            Log.v(TAG, "onWifiEnabled");
+        }
+
+        @Override
+        public void onWifiDisabled() {
+            Log.v(TAG, "onWifiDisabled");
+            mProvisioningStateMachine.getHandler().post(() -> {
+                mProvisioningStateMachine.handleWifiDisabled();
+            });
+        }
+    }
+}
diff --git a/service/java/com/android/server/wifi/rtt/RttNative.java b/service/java/com/android/server/wifi/rtt/RttNative.java
index dd54c24..e920310 100644
--- a/service/java/com/android/server/wifi/rtt/RttNative.java
+++ b/service/java/com/android/server/wifi/rtt/RttNative.java
@@ -27,14 +27,13 @@
 import android.hardware.wifi.V1_0.WifiChannelWidthInMhz;
 import android.hardware.wifi.V1_0.WifiStatus;
 import android.hardware.wifi.V1_0.WifiStatusCode;
-import android.net.wifi.ScanResult;
 import android.net.wifi.rtt.RangingRequest;
 import android.net.wifi.rtt.RangingResult;
+import android.net.wifi.rtt.ResponderConfig;
 import android.os.RemoteException;
 import android.util.Log;
 
 import com.android.server.wifi.HalDeviceManager;
-import com.android.server.wifi.util.NativeUtil;
 
 import java.io.FileDescriptor;
 import java.io.PrintWriter;
@@ -204,123 +203,119 @@
 
         // Skipping any configurations which have an error (printing out a message).
         // The caller will only get results for valid configurations.
-        for (RangingRequest.RttPeer peer: request.mRttPeers) {
+        for (ResponderConfig responder: request.mRttPeers) {
             RttConfig config = new RttConfig();
 
-            if (peer instanceof RangingRequest.RttPeerAp) {
-                ScanResult scanResult = ((RangingRequest.RttPeerAp) peer).scanResult;
+            if (responder.macAddress.length != config.addr.length) {
+                Log.e(TAG, "Invalid configuration: unexpected BSSID length -- " + responder);
+                continue;
+            }
+            System.arraycopy(responder.macAddress, 0, config.addr, 0, config.addr.length);
 
-                byte[] addr = NativeUtil.macAddressToByteArray(scanResult.BSSID);
-                if (addr.length != config.addr.length) {
-                    Log.e(TAG, "Invalid configuration: unexpected BSSID length -- " + scanResult);
-                    continue;
-                }
-                System.arraycopy(addr, 0, config.addr, 0, config.addr.length);
+            try {
+                config.type = responder.supports80211mc ? RttType.TWO_SIDED : RttType.ONE_SIDED;
+                config.peer = halRttPeerTypeFromResponderType(responder.responderType);
+                config.channel.width = halChannelWidthFromResponderChannelWidth(
+                        responder.channelWidth);
+                config.channel.centerFreq = responder.frequency;
+                config.channel.centerFreq0 = responder.centerFreq0;
+                config.channel.centerFreq1 = responder.centerFreq1;
+                config.bw = halRttChannelBandwidthFromResponderChannelWidth(responder.channelWidth);
+                config.preamble = halRttPreambleFromResponderPreamble(responder.preamble);
 
-                try {
-                    config.type =
-                            scanResult.is80211mcResponder() ? RttType.TWO_SIDED : RttType.ONE_SIDED;
-                    config.peer = RttPeerType.AP;
-                    config.channel.width = halChannelWidthFromScanResult(
-                            scanResult.channelWidth);
-                    config.channel.centerFreq = scanResult.frequency;
-                    if (scanResult.centerFreq0 > 0) {
-                        config.channel.centerFreq0 = scanResult.centerFreq0;
-                    }
-                    if (scanResult.centerFreq1 > 0) {
-                        config.channel.centerFreq1 = scanResult.centerFreq1;
-                    }
+                config.mustRequestLci = false;
+                config.mustRequestLcr = false;
+                if (config.peer == RttPeerType.NAN) {
+                    config.burstPeriod = 0;
+                    config.numBurst = 0;
+                    config.numFramesPerBurst = 5;
+                    config.numRetriesPerRttFrame = 3;
+                    config.numRetriesPerFtmr = 3;
+                    config.burstDuration = 15;
+                } else { // AP + all non-NAN requests
                     config.burstPeriod = 0;
                     config.numBurst = 0;
                     config.numFramesPerBurst = 8;
                     config.numRetriesPerRttFrame = 0;
                     config.numRetriesPerFtmr = 0;
-                    config.mustRequestLci = false;
-                    config.mustRequestLcr = false;
                     config.burstDuration = 15;
-                    config.bw = halChannelBandwidthFromScanResult(scanResult.channelWidth);
-                    if (config.bw == RttBw.BW_80MHZ || config.bw == RttBw.BW_160MHZ) {
-                        config.preamble = RttPreamble.VHT;
-                    } else {
-                        config.preamble = RttPreamble.HT;
-                    }
-                } catch (IllegalArgumentException e) {
-                    Log.e(TAG, "Invalid configuration: " + e.getMessage());
-                    continue;
                 }
-            } else if (peer instanceof RangingRequest.RttPeerAware) {
-                RangingRequest.RttPeerAware rttPeerAware = (RangingRequest.RttPeerAware) peer;
-
-                if (rttPeerAware.peerMacAddress == null
-                        || rttPeerAware.peerMacAddress.length != config.addr.length) {
-                    Log.e(TAG, "Invalid configuration: null MAC or incorrect length");
-                    continue;
-                }
-                System.arraycopy(rttPeerAware.peerMacAddress, 0, config.addr, 0,
-                        config.addr.length);
-
-                config.type = RttType.TWO_SIDED;
-                config.peer = RttPeerType.NAN;
-                config.channel.width = WifiChannelWidthInMhz.WIDTH_80;
-                config.channel.centerFreq = 5200;
-                config.channel.centerFreq0 = 5210;
-                config.channel.centerFreq1 = 0;
-                config.burstPeriod = 0;
-                config.numBurst = 0;
-                config.numFramesPerBurst = 5;
-                config.numRetriesPerRttFrame = 3;
-                config.numRetriesPerFtmr = 3;
-                config.mustRequestLci = false;
-                config.mustRequestLcr = false;
-                config.burstDuration = 15;
-                config.preamble = RttPreamble.VHT;
-                config.bw = RttBw.BW_80MHZ;
-            } else {
-                Log.e(TAG, "convertRangingRequestToRttConfigs: unknown request type -- "
-                        + peer.getClass().getCanonicalName());
-                return null;
+            } catch (IllegalArgumentException e) {
+                Log.e(TAG, "Invalid configuration: " + e.getMessage());
+                continue;
             }
 
             rttConfigs.add(config);
         }
 
-
         return rttConfigs;
     }
 
-    static int halChannelWidthFromScanResult(int scanResultChannelWidth) {
-        switch (scanResultChannelWidth) {
-            case ScanResult.CHANNEL_WIDTH_20MHZ:
-                return WifiChannelWidthInMhz.WIDTH_20;
-            case ScanResult.CHANNEL_WIDTH_40MHZ:
-                return WifiChannelWidthInMhz.WIDTH_40;
-            case ScanResult.CHANNEL_WIDTH_80MHZ:
-                return WifiChannelWidthInMhz.WIDTH_80;
-            case ScanResult.CHANNEL_WIDTH_160MHZ:
-                return WifiChannelWidthInMhz.WIDTH_160;
-            case ScanResult.CHANNEL_WIDTH_80MHZ_PLUS_MHZ:
-                return WifiChannelWidthInMhz.WIDTH_80P80;
+    static int halRttPeerTypeFromResponderType(int responderType) {
+        switch (responderType) {
+            case ResponderConfig.RESPONDER_AP:
+                return RttPeerType.AP;
+            case ResponderConfig.RESPONDER_STA:
+                return RttPeerType.STA;
+            case ResponderConfig.RESPONDER_P2P_GO:
+                return RttPeerType.P2P_GO;
+            case ResponderConfig.RESPONDER_P2P_CLIENT:
+                return RttPeerType.P2P_CLIENT;
+            case ResponderConfig.RESPONDER_AWARE:
+                return RttPeerType.NAN;
             default:
                 throw new IllegalArgumentException(
-                        "halChannelWidthFromScanResult: bad " + scanResultChannelWidth);
+                        "halRttPeerTypeFromResponderType: bad " + responderType);
         }
     }
 
-    static int halChannelBandwidthFromScanResult(int scanResultChannelWidth) {
-        switch (scanResultChannelWidth) {
-            case ScanResult.CHANNEL_WIDTH_20MHZ:
+    static int halChannelWidthFromResponderChannelWidth(int responderChannelWidth) {
+        switch (responderChannelWidth) {
+            case ResponderConfig.CHANNEL_WIDTH_20MHZ:
+                return WifiChannelWidthInMhz.WIDTH_20;
+            case ResponderConfig.CHANNEL_WIDTH_40MHZ:
+                return WifiChannelWidthInMhz.WIDTH_40;
+            case ResponderConfig.CHANNEL_WIDTH_80MHZ:
+                return WifiChannelWidthInMhz.WIDTH_80;
+            case ResponderConfig.CHANNEL_WIDTH_160MHZ:
+                return WifiChannelWidthInMhz.WIDTH_160;
+            case ResponderConfig.CHANNEL_WIDTH_80MHZ_PLUS_MHZ:
+                return WifiChannelWidthInMhz.WIDTH_80P80;
+            default:
+                throw new IllegalArgumentException(
+                        "halChannelWidthFromResponderChannelWidth: bad " + responderChannelWidth);
+        }
+    }
+
+    static int halRttChannelBandwidthFromResponderChannelWidth(int responderChannelWidth) {
+        switch (responderChannelWidth) {
+            case ResponderConfig.CHANNEL_WIDTH_20MHZ:
                 return RttBw.BW_20MHZ;
-            case ScanResult.CHANNEL_WIDTH_40MHZ:
+            case ResponderConfig.CHANNEL_WIDTH_40MHZ:
                 return RttBw.BW_40MHZ;
-            case ScanResult.CHANNEL_WIDTH_80MHZ:
+            case ResponderConfig.CHANNEL_WIDTH_80MHZ:
                 return RttBw.BW_80MHZ;
-            case ScanResult.CHANNEL_WIDTH_160MHZ:
+            case ResponderConfig.CHANNEL_WIDTH_160MHZ:
                 return RttBw.BW_160MHZ;
-            case ScanResult.CHANNEL_WIDTH_80MHZ_PLUS_MHZ:
+            case ResponderConfig.CHANNEL_WIDTH_80MHZ_PLUS_MHZ:
                 return RttBw.BW_160MHZ;
             default:
                 throw new IllegalArgumentException(
-                        "halChannelBandwidthFromScanResult: bad " + scanResultChannelWidth);
+                        "halRttChannelBandwidthFromHalBandwidth: bad " + responderChannelWidth);
+        }
+    }
+
+    static int halRttPreambleFromResponderPreamble(int responderPreamble) {
+        switch (responderPreamble) {
+            case ResponderConfig.PREAMBLE_LEGACY:
+                return RttPreamble.LEGACY;
+            case ResponderConfig.PREAMBLE_HT:
+                return RttPreamble.HT;
+            case ResponderConfig.PREAMBLE_VHT:
+                return RttPreamble.VHT;
+            default:
+                throw new IllegalArgumentException(
+                        "halRttPreambleFromResponderPreamble: bad " + responderPreamble);
         }
     }
 
diff --git a/service/java/com/android/server/wifi/rtt/RttServiceImpl.java b/service/java/com/android/server/wifi/rtt/RttServiceImpl.java
index 401daab..ff722ae 100644
--- a/service/java/com/android/server/wifi/rtt/RttServiceImpl.java
+++ b/service/java/com/android/server/wifi/rtt/RttServiceImpl.java
@@ -24,15 +24,14 @@
 import android.content.pm.PackageManager;
 import android.hardware.wifi.V1_0.RttResult;
 import android.hardware.wifi.V1_0.RttStatus;
-import android.net.wifi.ScanResult;
 import android.net.wifi.aware.IWifiAwareMacAddressProvider;
 import android.net.wifi.aware.IWifiAwareManager;
-import android.net.wifi.aware.PeerHandle;
 import android.net.wifi.rtt.IRttCallback;
 import android.net.wifi.rtt.IWifiRttManager;
 import android.net.wifi.rtt.RangingRequest;
 import android.net.wifi.rtt.RangingResult;
 import android.net.wifi.rtt.RangingResultCallback;
+import android.net.wifi.rtt.ResponderConfig;
 import android.net.wifi.rtt.WifiRttManager;
 import android.os.Binder;
 import android.os.Handler;
@@ -43,11 +42,10 @@
 import android.os.UserHandle;
 import android.os.WorkSource;
 import android.util.Log;
+import android.util.SparseIntArray;
 
-import com.android.internal.annotations.VisibleForTesting;
 import com.android.internal.util.WakeupMessage;
 import com.android.server.wifi.Clock;
-import com.android.server.wifi.util.NativeUtil;
 import com.android.server.wifi.util.WifiPermissionsUtil;
 
 import libcore.util.HexEncoding;
@@ -79,14 +77,16 @@
 
     private RttServiceSynchronized mRttServiceSynchronized;
 
-    @VisibleForTesting
-    public static final String HAL_RANGING_TIMEOUT_TAG = TAG + " HAL Ranging Timeout";
+    /* package */ static final String HAL_RANGING_TIMEOUT_TAG = TAG + " HAL Ranging Timeout";
 
     private static final long HAL_RANGING_TIMEOUT_MS = 5_000; // 5 sec
 
     // TODO: b/69323456 convert to a settable value
     /* package */ static final long BACKGROUND_PROCESS_EXEC_GAP_MS = 1_800_000; // 30 min
 
+    // arbitrary, larger than anything reasonable
+    /* package */ static final int MAX_QUEUED_PER_UID = 20;
+
     public RttServiceImpl(Context context) {
         mContext = context;
     }
@@ -349,24 +349,12 @@
 
         private void cancelRanging(RttRequestInfo rri) {
             ArrayList<byte[]> macAddresses = new ArrayList<>();
-            for (RangingRequest.RttPeer peer : rri.request.mRttPeers) {
-                if (peer instanceof RangingRequest.RttPeerAp) {
-                    ScanResult scanResult =
-                            ((RangingRequest.RttPeerAp) peer).scanResult;
-
-                    byte[] addr = NativeUtil.macAddressToByteArray(scanResult.BSSID);
-                    if (addr.length != 6) {
-                        Log.e(TAG, "Invalid configuration: unexpected BSSID length -- "
-                                + peer);
-                        continue;
-                    }
-                    macAddresses.add(addr);
-                } else if (peer instanceof RangingRequest.RttPeerAware) {
-                    if (((RangingRequest.RttPeerAware) peer).peerMacAddress != null) {
-                        macAddresses.add(
-                                ((RangingRequest.RttPeerAware) peer).peerMacAddress);
-                    }
+            for (ResponderConfig peer : rri.request.mRttPeers) {
+                if (peer.macAddress.length != 6) {
+                    Log.e(TAG, "Invalid configuration: unexpected BSSID length -- " + peer);
+                    continue;
                 }
+                macAddresses.add(peer.macAddress);
             }
 
             mRttNative.rangeCancel(rri.cmdId, macAddresses);
@@ -477,6 +465,19 @@
         private void queueRangingRequest(int uid, WorkSource workSource, IBinder binder,
                 IBinder.DeathRecipient dr, String callingPackage, RangingRequest request,
                 IRttCallback callback) {
+            if (isRequestorSpamming(workSource)) {
+                Log.w(TAG,
+                        "Work source " + workSource + " is spamming, dropping request: " + request);
+                binder.unlinkToDeath(dr, 0);
+                try {
+                    callback.onRangingFailure(RangingResultCallback.STATUS_CODE_FAIL);
+                } catch (RemoteException e) {
+                    Log.e(TAG,  "RttServiceSynchronized.queueRangingRequest: spamming, callback "
+                            + "failed -- " + e);
+                }
+                return;
+            }
+
             RttRequestInfo newRequest = new RttRequestInfo();
             newRequest.uid = uid;
             newRequest.workSource = workSource;
@@ -494,6 +495,30 @@
             executeNextRangingRequestIfPossible(false);
         }
 
+        private boolean isRequestorSpamming(WorkSource ws) {
+            if (VDBG) Log.v(TAG, "isRequestorSpamming: ws" + ws);
+
+            SparseIntArray counts = new SparseIntArray();
+
+            for (RttRequestInfo rri : mRttRequestQueue) {
+                for (int i = 0; i < rri.workSource.size(); ++i) {
+                    int uid = rri.workSource.get(i);
+                    counts.put(uid, counts.get(uid) + 1);
+                }
+            }
+
+            for (int i = 0; i < ws.size(); ++i) {
+                if (counts.get(ws.get(i)) < MAX_QUEUED_PER_UID) {
+                    return false;
+                }
+            }
+
+            if (VDBG) {
+                Log.v(TAG, "isRequestorSpamming: ws=" + ws + ", someone is spamming: " + counts);
+            }
+            return true;
+        }
+
         private void executeNextRangingRequestIfPossible(boolean popFirst) {
             if (VDBG) Log.v(TAG, "executeNextRangingRequestIfPossible: popFirst=" + popFirst);
 
@@ -652,12 +677,9 @@
          */
         private boolean processAwarePeerHandles(RttRequestInfo request) {
             List<Integer> peerIdsNeedingTranslation = new ArrayList<>();
-            for (RangingRequest.RttPeer rttPeer: request.request.mRttPeers) {
-                if (rttPeer instanceof RangingRequest.RttPeerAware) {
-                    RangingRequest.RttPeerAware awarePeer = (RangingRequest.RttPeerAware) rttPeer;
-                    if (awarePeer.peerHandle != null && awarePeer.peerMacAddress == null) {
-                        peerIdsNeedingTranslation.add(awarePeer.peerHandle.peerId);
-                    }
+            for (ResponderConfig rttPeer : request.request.mRttPeers) {
+                if (rttPeer.peerHandle != null && rttPeer.macAddress == null) {
+                    peerIdsNeedingTranslation.add(rttPeer.peerHandle.peerId);
                 }
             }
 
@@ -713,12 +735,9 @@
                         + ", peerIdToMacMap=" + peerIdToMacMap);
             }
 
-            for (RangingRequest.RttPeer rttPeer: request.request.mRttPeers) {
-                if (rttPeer instanceof RangingRequest.RttPeerAware) {
-                    RangingRequest.RttPeerAware awarePeer = (RangingRequest.RttPeerAware) rttPeer;
-                    if (awarePeer.peerHandle != null && awarePeer.peerMacAddress == null) {
-                        awarePeer.peerMacAddress = peerIdToMacMap.get(awarePeer.peerHandle.peerId);
-                    }
+            for (ResponderConfig rttPeer: request.request.mRttPeers) {
+                if (rttPeer.peerHandle != null && rttPeer.macAddress == null) {
+                    rttPeer.macAddress = peerIdToMacMap.get(rttPeer.peerHandle.peerId);
                 }
             }
 
@@ -787,45 +806,38 @@
 
             List<RangingResult> finalResults = new ArrayList<>(request.mRttPeers.size());
 
-            for (RangingRequest.RttPeer peer: request.mRttPeers) {
-                byte[] addr;
-                if (peer instanceof RangingRequest.RttPeerAp) {
-                    addr = NativeUtil.macAddressToByteArray(
-                            ((RangingRequest.RttPeerAp) peer).scanResult.BSSID);
-                } else if (peer instanceof RangingRequest.RttPeerAware) {
-                    addr = ((RangingRequest.RttPeerAware) peer).peerMacAddress;
-                } else {
-                    Log.w(TAG, "postProcessResults: unknown peer type -- " + peer.getClass());
-                    continue;
-                }
-
+            for (ResponderConfig peer: request.mRttPeers) {
                 RttResult resultForRequest = resultEntries.get(
-                        new String(HexEncoding.encode(addr)));
+                        new String(HexEncoding.encode(peer.macAddress)));
                 if (resultForRequest == null) {
                     if (VDBG) {
                         Log.v(TAG, "postProcessResults: missing=" + new String(
-                                HexEncoding.encode(addr)));
+                                HexEncoding.encode(peer.macAddress)));
                     }
-                    finalResults.add(
-                            new RangingResult(RangingResult.STATUS_FAIL, addr, 0, 0, 0, 0));
+                    if (peer.peerHandle == null) {
+                        finalResults.add(
+                                new RangingResult(RangingResult.STATUS_FAIL, peer.macAddress, 0, 0,
+                                        0, 0));
+                    } else {
+                        finalResults.add(
+                                new RangingResult(RangingResult.STATUS_FAIL, peer.peerHandle, 0, 0,
+                                        0, 0));
+                    }
                 } else {
                     int status = resultForRequest.status == RttStatus.SUCCESS
                             ? RangingResult.STATUS_SUCCESS : RangingResult.STATUS_FAIL;
-                    PeerHandle peerHandle = null;
-                    if (peer instanceof RangingRequest.RttPeerAware) {
-                        peerHandle = ((RangingRequest.RttPeerAware) peer).peerHandle;
-                    }
-
-                    if (peerHandle == null) {
+                    if (peer.peerHandle == null) {
                         finalResults.add(
-                                new RangingResult(status, addr, resultForRequest.distanceInMm,
-                                        resultForRequest.distanceSdInMm, resultForRequest.rssi,
-                                        resultForRequest.timeStampInUs));
+                                new RangingResult(status, peer.macAddress,
+                                        resultForRequest.distanceInMm,
+                                        resultForRequest.distanceSdInMm,
+                                        resultForRequest.rssi, resultForRequest.timeStampInUs));
                     } else {
                         finalResults.add(
-                                new RangingResult(status, peerHandle, resultForRequest.distanceInMm,
-                                        resultForRequest.distanceSdInMm, resultForRequest.rssi,
-                                        resultForRequest.timeStampInUs));
+                                new RangingResult(status, peer.peerHandle,
+                                        resultForRequest.distanceInMm,
+                                        resultForRequest.distanceSdInMm,
+                                        resultForRequest.rssi, resultForRequest.timeStampInUs));
                     }
                 }
             }
diff --git a/tests/wifitests/src/com/android/server/wifi/HalDeviceManagerTest.java b/tests/wifitests/src/com/android/server/wifi/HalDeviceManagerTest.java
index 6dfd13a..18a1f8f 100644
--- a/tests/wifitests/src/com/android/server/wifi/HalDeviceManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/HalDeviceManagerTest.java
@@ -637,6 +637,77 @@
     }
 
     /**
+     * Validate creation of AP interface when in STA mode with a single STA iface created.
+     * Expect a change in chip mode.
+     */
+    @Test
+    public void testCreateApWithStIfaceUpTestChipV1UsingNoHandlerListeners() throws Exception {
+        TestChipV1 chipMock = new TestChipV1();
+        chipMock.initialize();
+
+        InterfaceDestroyedListener staIdl = mock(
+                InterfaceDestroyedListener.class);
+        HalDeviceManager.InterfaceAvailableForRequestListener staIafrl = mock(
+                HalDeviceManager.InterfaceAvailableForRequestListener.class);
+        InterfaceDestroyedListener apIdl = mock(
+                InterfaceDestroyedListener.class);
+        HalDeviceManager.InterfaceAvailableForRequestListener apIafrl = mock(
+                HalDeviceManager.InterfaceAvailableForRequestListener.class);
+
+        mInOrder = inOrder(mServiceManagerMock, mWifiMock, chipMock.chip,
+                mManagerStatusListenerMock, staIdl, staIafrl, apIdl, apIafrl);
+        executeAndValidateInitializationSequence();
+
+        // Register listener & start Wi-Fi
+        mDut.registerStatusListener(mManagerStatusListenerMock, null);
+        assertTrue(mDut.start());
+        mInOrder.verify(mManagerStatusListenerMock).onStatusChanged();
+
+        mDut.registerInterfaceAvailableForRequestListener(IfaceType.STA, staIafrl, null);
+        mDut.registerInterfaceAvailableForRequestListener(IfaceType.AP, apIafrl, null);
+
+        mInOrder.verify(staIafrl).onAvailableForRequest();
+        mInOrder.verify(apIafrl).onAvailableForRequest();
+
+        // Create STA Iface first.
+        IWifiStaIface staIface = mock(IWifiStaIface.class);
+        doAnswer(new GetNameAnswer("wlan0")).when(staIface).getName(
+                any(IWifiIface.getNameCallback.class));
+        doAnswer(new GetTypeAnswer(IfaceType.STA)).when(staIface).getType(
+                any(IWifiIface.getTypeCallback.class));
+        doAnswer(new CreateXxxIfaceAnswer(chipMock, mStatusOk, staIface)).when(
+                chipMock.chip).createStaIface(any(IWifiChip.createStaIfaceCallback.class));
+        assertEquals(staIface, mDut.createStaIface(staIdl, null));
+
+        mInOrder.verify(chipMock.chip).configureChip(TestChipV1.STA_CHIP_MODE_ID);
+        mInOrder.verify(apIafrl).onAvailableForRequest();
+
+        // Now Create AP Iface.
+        IWifiApIface apIface = mock(IWifiApIface.class);
+        doAnswer(new GetNameAnswer("wlan0")).when(apIface).getName(
+                any(IWifiIface.getNameCallback.class));
+        doAnswer(new GetTypeAnswer(IfaceType.AP)).when(apIface).getType(
+                any(IWifiIface.getTypeCallback.class));
+        doAnswer(new CreateXxxIfaceAnswer(chipMock, mStatusOk, apIface)).when(
+                chipMock.chip).createApIface(any(IWifiChip.createApIfaceCallback.class));
+        assertEquals(apIface, mDut.createApIface(apIdl, null));
+
+        mInOrder.verify(chipMock.chip).removeStaIface(getName(staIface));
+        mInOrder.verify(staIdl).onDestroyed(getName(staIface));
+        mInOrder.verify(chipMock.chip).configureChip(TestChipV1.AP_CHIP_MODE_ID);
+        mInOrder.verify(staIafrl).onAvailableForRequest();
+
+        // Stop Wi-Fi
+        mDut.stop();
+
+        mInOrder.verify(mWifiMock).stop();
+        mInOrder.verify(mManagerStatusListenerMock).onStatusChanged();
+        mInOrder.verify(apIdl).onDestroyed(getName(apIface));
+
+        verifyNoMoreInteractions(mManagerStatusListenerMock, staIdl, staIafrl, apIdl, apIafrl);
+    }
+
+    /**
      * Validate creation of AP interface when in AP mode - but with no interface created. Expect
      * no change in chip mode.
      */
diff --git a/tests/wifitests/src/com/android/server/wifi/PasspointProvisioningTestUtil.java b/tests/wifitests/src/com/android/server/wifi/PasspointProvisioningTestUtil.java
new file mode 100644
index 0000000..c78135d
--- /dev/null
+++ b/tests/wifitests/src/com/android/server/wifi/PasspointProvisioningTestUtil.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.wifi.hotspot2;
+
+import android.graphics.drawable.Icon;
+import android.net.Uri;
+import android.net.wifi.WifiSsid;
+import android.net.wifi.hotspot2.OsuProvider;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Helper for creating and populating WifiConfigurations in unit tests.
+ */
+public class PasspointProvisioningTestUtil {
+    /**
+     * These are constants used to generate predefined OsuProvider.
+     */
+    public static final WifiSsid TEST_SSID =
+            WifiSsid.createFromByteArray("TEST SSID".getBytes(StandardCharsets.UTF_8));
+    public static final String TEST_FRIENDLY_NAME = "Friendly Name";
+    public static final String TEST_SERVICE_DESCRIPTION = "Dummy Service";
+    public static final Uri TEST_SERVER_URI = Uri.parse("https://test.com");
+    public static final String TEST_NAI = "test.access.com";
+    public static final List<Integer> TEST_METHOD_LIST =
+            Arrays.asList(OsuProvider.METHOD_SOAP_XML_SPP);
+    public static final Icon TEST_ICON = Icon.createWithData(new byte[10], 0, 10);
+
+    /**
+     * Construct a {@link android.net.wifi.hotspot2.OsuProvider}.
+     * @param openOsuAP indicates if the OSU AP belongs to an open or OSEN network
+     * @return the constructed {@link android.net.wifi.hotspot2.OsuProvider}
+     */
+    public static OsuProvider generateOsuProvider(boolean openOsuAP) {
+        if (openOsuAP) {
+            return new OsuProvider(TEST_SSID, TEST_FRIENDLY_NAME, TEST_SERVICE_DESCRIPTION,
+                    TEST_SERVER_URI, null, TEST_METHOD_LIST, TEST_ICON);
+        } else {
+            return new OsuProvider(TEST_SSID, TEST_FRIENDLY_NAME, TEST_SERVICE_DESCRIPTION,
+                    TEST_SERVER_URI, TEST_NAI, TEST_METHOD_LIST, TEST_ICON);
+        }
+    }
+}
diff --git a/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java b/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java
index 88c874e..cda9cf5 100644
--- a/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java
@@ -16,6 +16,7 @@
 
 package com.android.server.wifi;
 
+import static android.net.wifi.WifiConfiguration.KeyMgmt.WPA_PSK;
 import static android.net.wifi.WifiManager.EXTRA_PREVIOUS_WIFI_AP_STATE;
 import static android.net.wifi.WifiManager.EXTRA_WIFI_AP_FAILURE_REASON;
 import static android.net.wifi.WifiManager.EXTRA_WIFI_AP_INTERFACE_NAME;
@@ -38,8 +39,6 @@
 import android.net.wifi.IApInterface;
 import android.net.wifi.WifiConfiguration;
 import android.net.wifi.WifiManager;
-import android.os.IBinder;
-import android.os.IBinder.DeathRecipient;
 import android.os.INetworkManagementService;
 import android.os.UserHandle;
 import android.os.test.TestLooper;
@@ -54,7 +53,6 @@
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 
-import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -68,6 +66,7 @@
 
     private static final String DEFAULT_SSID = "DefaultTestSSID";
     private static final String TEST_SSID = "TestSSID";
+    private static final String TEST_PASSWORD = "TestPassword";
     private static final String TEST_COUNTRY_CODE = "TestCountry";
     private static final Integer[] ALLOWED_2G_CHANNELS = {1, 2, 3, 4};
     private static final String TEST_INTERFACE_NAME = "testif0";
@@ -83,17 +82,16 @@
     @Mock WifiNative mWifiNative;
     @Mock SoftApManager.Listener mListener;
     @Mock InterfaceConfiguration mInterfaceConfiguration;
-    @Mock IBinder mApInterfaceBinder;
     @Mock IApInterface mApInterface;
     @Mock INetworkManagementService mNmService;
     @Mock WifiApConfigStore mWifiApConfigStore;
     @Mock WifiMetrics mWifiMetrics;
-    final ArgumentCaptor<DeathRecipient> mDeathListenerCaptor =
-            ArgumentCaptor.forClass(DeathRecipient.class);
+    final ArgumentCaptor<WifiNative.WificondDeathEventHandler> mDeathListenerCaptor =
+            ArgumentCaptor.forClass(WifiNative.WificondDeathEventHandler.class);
     final ArgumentCaptor<BaseNetworkObserver> mNetworkObserverCaptor =
             ArgumentCaptor.forClass(BaseNetworkObserver.class);
-    final ArgumentCaptor<SoftApManager.ApInterfaceListener> mApInterfaceListenerCaptor =
-            ArgumentCaptor.forClass(SoftApManager.ApInterfaceListener.class);
+    final ArgumentCaptor<WifiNative.SoftApListener> mSoftApListenerCaptor =
+            ArgumentCaptor.forClass(WifiNative.SoftApListener.class);
 
     SoftApManager mSoftApManager;
 
@@ -103,12 +101,9 @@
         MockitoAnnotations.initMocks(this);
         mLooper = new TestLooper();
 
-        when(mApInterface.asBinder()).thenReturn(mApInterfaceBinder);
-        when(mApInterface.startHostapd(any())).thenReturn(true);
-        when(mApInterface.stopHostapd()).thenReturn(true);
-        when(mApInterface.writeHostapdConfig(
-                any(), anyBoolean(), anyInt(), anyInt(), any())).thenReturn(true);
-        when(mApInterface.getInterfaceName()).thenReturn(TEST_INTERFACE_NAME);
+        when(mWifiNative.startSoftAp(any(), any())).thenReturn(true);
+        when(mWifiNative.stopSoftAp()).thenReturn(true);
+        when(mWifiNative.registerWificondDeathHandler(any())).thenReturn(true);
     }
 
     private WifiConfiguration createDefaultApConfig() {
@@ -118,9 +113,6 @@
     }
 
     private SoftApManager createSoftApManager(SoftApModeConfiguration config) throws Exception {
-        when(mApInterface.asBinder()).thenReturn(mApInterfaceBinder);
-        when(mApInterface.startHostapd(any())).thenReturn(true);
-        when(mApInterface.stopHostapd()).thenReturn(true);
         if (config.getWifiConfiguration() == null) {
             when(mWifiApConfigStore.getApConfiguration()).thenReturn(mDefaultApConfig);
         }
@@ -158,7 +150,6 @@
         startSoftApAndVerifyEnabled(apConfig);
     }
 
-
     /**
      * Verifies startSoftAp will start with the hiddenSSID param set when it is set to true in the
      * supplied config.
@@ -174,12 +165,25 @@
         startSoftApAndVerifyEnabled(apConfig);
     }
 
+    /**
+     * Verifies startSoftAp will start with the password param set in the
+     * supplied config.
+     */
+    @Test
+    public void startSoftApWithPassphraseInConfig() throws Exception {
+        WifiConfiguration config = new WifiConfiguration();
+        config.apBand = WifiConfiguration.AP_BAND_5GHZ;
+        config.SSID = TEST_SSID;
+        config.allowedKeyManagement.set(WPA_PSK);
+        config.preSharedKey = TEST_PASSWORD;
+        SoftApModeConfiguration apConfig =
+                new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, config);
+        startSoftApAndVerifyEnabled(apConfig);
+    }
+
     /** Tests softap startup if default config fails to load. **/
     @Test
     public void startSoftApDefaultConfigFailedToLoad() throws Exception {
-        when(mApInterface.asBinder()).thenReturn(mApInterfaceBinder);
-        when(mApInterface.startHostapd(any())).thenReturn(true);
-        when(mApInterface.stopHostapd()).thenReturn(true);
         when(mWifiApConfigStore.getApConfiguration()).thenReturn(null);
         SoftApModeConfiguration nullApConfig =
                 new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, null);
@@ -224,9 +228,6 @@
         SoftApModeConfiguration softApConfig =
                 new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, config);
 
-        when(mApInterface.asBinder()).thenReturn(mApInterfaceBinder);
-        when(mApInterface.startHostapd(any())).thenReturn(true);
-        when(mApInterface.stopHostapd()).thenReturn(true);
         when(mWifiNative.isHalStarted()).thenReturn(true);
 
         SoftApManager newSoftApManager = new SoftApManager(mContext,
@@ -270,9 +271,6 @@
         SoftApModeConfiguration softApConfig =
                 new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, config);
 
-        when(mApInterface.asBinder()).thenReturn(mApInterfaceBinder);
-        when(mApInterface.startHostapd(any())).thenReturn(true);
-        when(mApInterface.stopHostapd()).thenReturn(true);
         when(mWifiNative.isHalStarted()).thenReturn(true);
 
         SoftApManager newSoftApManager = new SoftApManager(mContext,
@@ -308,9 +306,7 @@
      */
     @Test
     public void startSoftApApInterfaceFailedToStart() throws Exception {
-        when(mApInterface.asBinder()).thenReturn(mApInterfaceBinder);
-        when(mApInterface.startHostapd(any())).thenReturn(false);
-        when(mApInterface.stopHostapd()).thenReturn(true);
+        when(mWifiNative.startSoftAp(any(), any())).thenReturn(false);
         SoftApModeConfiguration softApModeConfig =
                 new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, mDefaultApConfig);
         SoftApManager newSoftApManager = new SoftApManager(mContext,
@@ -363,7 +359,7 @@
         mSoftApManager.stop();
         mLooper.dispatchAll();
 
-        verify(mApInterface).stopHostapd();
+        verify(mWifiNative).stopSoftAp();
         order.verify(mListener).onStateChanged(WifiManager.WIFI_AP_STATE_DISABLING, 0);
         order.verify(mListener).onStateChanged(WifiManager.WIFI_AP_STATE_DISABLED, 0);
         ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
@@ -391,7 +387,7 @@
         // reset to clear verified Intents for ap state change updates
         reset(mContext);
 
-        mDeathListenerCaptor.getValue().binderDied();
+        mDeathListenerCaptor.getValue().onDeath();
         mLooper.dispatchAll();
         InOrder order = inOrder(mListener);
         order.verify(mListener).onStateChanged(WifiManager.WIFI_AP_STATE_DISABLING, 0);
@@ -416,7 +412,7 @@
                 new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, null);
         startSoftApAndVerifyEnabled(apConfig);
 
-        mApInterfaceListenerCaptor.getValue().onNumAssociatedStationsChanged(
+        mSoftApListenerCaptor.getValue().onNumAssociatedStationsChanged(
                 TEST_NUM_CONNECTED_CLIENTS);
         mLooper.dispatchAll();
         assertEquals(TEST_NUM_CONNECTED_CLIENTS, mSoftApManager.getNumAssociatedStations());
@@ -432,7 +428,7 @@
         mSoftApManager.stop();
         mLooper.dispatchAll();
 
-        mApInterfaceListenerCaptor.getValue().onNumAssociatedStationsChanged(
+        mSoftApListenerCaptor.getValue().onNumAssociatedStationsChanged(
                 TEST_NUM_CONNECTED_CLIENTS);
         mLooper.dispatchAll();
         /* Verify numAssociatedStations is not updated when soft AP is not started */
@@ -448,10 +444,10 @@
                 new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, null);
         startSoftApAndVerifyEnabled(apConfig);
 
-        mApInterfaceListenerCaptor.getValue().onNumAssociatedStationsChanged(
+        mSoftApListenerCaptor.getValue().onNumAssociatedStationsChanged(
                 TEST_NUM_CONNECTED_CLIENTS);
         /* Invalid values should be ignored */
-        mApInterfaceListenerCaptor.getValue().onNumAssociatedStationsChanged(-1);
+        mSoftApListenerCaptor.getValue().onNumAssociatedStationsChanged(-1);
         mLooper.dispatchAll();
         assertEquals(TEST_NUM_CONNECTED_CLIENTS, mSoftApManager.getNumAssociatedStations());
         verify(mWifiMetrics, times(1)).addSoftApNumAssociatedStationsChangedEvent(
@@ -464,7 +460,7 @@
                 new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, null);
         startSoftApAndVerifyEnabled(apConfig);
 
-        mApInterfaceListenerCaptor.getValue().onNumAssociatedStationsChanged(
+        mSoftApListenerCaptor.getValue().onNumAssociatedStationsChanged(
                 TEST_NUM_CONNECTED_CLIENTS);
         mSoftApManager.stop();
         mLooper.dispatchAll();
@@ -478,10 +474,10 @@
                 new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, null);
         startSoftApAndVerifyEnabled(apConfig);
 
-        mApInterfaceListenerCaptor.getValue().onNumAssociatedStationsChanged(
+        mSoftApListenerCaptor.getValue().onNumAssociatedStationsChanged(
                 TEST_NUM_CONNECTED_CLIENTS);
         /* Force soft AP to fail */
-        mDeathListenerCaptor.getValue().binderDied();
+        mDeathListenerCaptor.getValue().onDeath();
         mLooper.dispatchAll();
         verify(mListener).onStateChanged(WifiManager.WIFI_AP_STATE_FAILED,
                 WifiManager.SAP_START_FAILURE_GENERAL);
@@ -493,9 +489,9 @@
     /** Starts soft AP and verifies that it is enabled successfully. */
     protected void startSoftApAndVerifyEnabled(
             SoftApModeConfiguration softApConfig) throws Exception {
-        String expectedSSID;
-        boolean expectedHiddenSsid;
-        InOrder order = inOrder(mListener, mApInterfaceBinder, mApInterface, mNmService);
+        WifiConfiguration expectedConfig;
+        InOrder order =
+                inOrder(mListener, mApInterface, mWifiNative, mNmService);
 
         when(mWifiNative.isHalStarted()).thenReturn(false);
         when(mWifiNative.setCountryCodeHal(TEST_COUNTRY_CODE.toUpperCase(Locale.ROOT)))
@@ -505,11 +501,9 @@
         WifiConfiguration config = softApConfig.getWifiConfiguration();
         if (config == null) {
             when(mWifiApConfigStore.getApConfiguration()).thenReturn(mDefaultApConfig);
-            expectedSSID = mDefaultApConfig.SSID;
-            expectedHiddenSsid = mDefaultApConfig.hiddenSSID;
+            expectedConfig = new WifiConfiguration(mDefaultApConfig);
         } else {
-            expectedSSID = config.SSID;
-            expectedHiddenSsid = config.hiddenSSID;
+            expectedConfig = new WifiConfiguration(config);
         }
 
         ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
@@ -517,12 +511,13 @@
         mSoftApManager.start();
         mLooper.dispatchAll();
         order.verify(mListener).onStateChanged(WifiManager.WIFI_AP_STATE_ENABLING, 0);
-        order.verify(mApInterfaceBinder).linkToDeath(mDeathListenerCaptor.capture(), eq(0));
+        order.verify(mWifiNative).registerWificondDeathHandler(mDeathListenerCaptor.capture());
         order.verify(mNmService).registerObserver(mNetworkObserverCaptor.capture());
-        order.verify(mApInterface).writeHostapdConfig(
-                eq(expectedSSID.getBytes(StandardCharsets.UTF_8)), eq(expectedHiddenSsid),
-                anyInt(), anyInt(), any());
-        order.verify(mApInterface).startHostapd(mApInterfaceListenerCaptor.capture());
+        ArgumentCaptor<WifiConfiguration> configCaptor =
+                ArgumentCaptor.forClass(WifiConfiguration.class);
+        order.verify(mWifiNative).startSoftAp(
+                configCaptor.capture(), mSoftApListenerCaptor.capture());
+        WifiConfigurationTestUtil.assertConfigurationEqual(expectedConfig, configCaptor.getValue());
         mNetworkObserverCaptor.getValue().interfaceLinkStateChanged(TEST_INTERFACE_NAME, true);
         mLooper.dispatchAll();
         order.verify(mListener).onStateChanged(WifiManager.WIFI_AP_STATE_ENABLED, 0);
diff --git a/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java b/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java
index a7bb192..0303d9a 100644
--- a/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java
@@ -23,15 +23,7 @@
 import static org.mockito.Matchers.anyShort;
 import static org.mockito.Matchers.anyString;
 import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.doAnswer;
-import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.inOrder;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.reset;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
 
 import android.app.test.MockAnswerUtil;
 import android.content.Context;
@@ -62,6 +54,8 @@
 import com.android.server.wifi.hotspot2.WnmData;
 import com.android.server.wifi.util.NativeUtil;
 
+import libcore.util.NonNull;
+
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.ArgumentCaptor;
@@ -91,7 +85,8 @@
     private static final String SUPPLICANT_SSID = NETWORK_ID_TO_SSID.get(SUPPLICANT_NETWORK_ID);
     private static final int ROAM_NETWORK_ID = 4;
     private static final String BSSID = "fa:45:23:23:12:12";
-    private static final String WLAN_IFACE_NAME = "wlan0";
+    private static final String WLAN0_IFACE_NAME = "wlan0";
+    private static final String WLAN1_IFACE_NAME = "wlan1";
     private static final String P2P_IFACE_NAME = "p2p0";
     private static final String ICON_FILE_NAME  = "blahblah";
     private static final int ICON_FILE_SIZE = 72;
@@ -104,9 +99,11 @@
     @Mock Context mContext;
     @Mock WifiMonitor mWifiMonitor;
     @Mock SupplicantStaNetworkHal mSupplicantStaNetworkMock;
+    @Mock WifiNative.SupplicantDeathEventHandler mSupplicantHalDeathHandler;
     SupplicantStatus mStatusSuccess;
     SupplicantStatus mStatusFailure;
-    ISupplicant.IfaceInfo mStaIface;
+    ISupplicant.IfaceInfo mStaIface0;
+    ISupplicant.IfaceInfo mStaIface1;
     ISupplicant.IfaceInfo mP2pIface;
     ArrayList<ISupplicant.IfaceInfo> mIfaceInfoList;
     ISupplicantStaIfaceCallback mISupplicantStaIfaceCallback;
@@ -143,6 +140,7 @@
 
         @Override
         protected SupplicantStaNetworkHal getStaNetworkMockable(
+                @NonNull String ifaceName,
                 ISupplicantStaNetwork iSupplicantStaNetwork) {
             return mSupplicantStaNetworkMock;
         }
@@ -153,11 +151,13 @@
         MockitoAnnotations.initMocks(this);
         mStatusSuccess = createSupplicantStatus(SupplicantStatusCode.SUCCESS);
         mStatusFailure = createSupplicantStatus(SupplicantStatusCode.FAILURE_UNKNOWN);
-        mStaIface = createIfaceInfo(IfaceType.STA, WLAN_IFACE_NAME);
+        mStaIface0 = createIfaceInfo(IfaceType.STA, WLAN0_IFACE_NAME);
+        mStaIface1 = createIfaceInfo(IfaceType.STA, WLAN1_IFACE_NAME);
         mP2pIface = createIfaceInfo(IfaceType.P2P, P2P_IFACE_NAME);
 
         mIfaceInfoList = new ArrayList<>();
-        mIfaceInfoList.add(mStaIface);
+        mIfaceInfoList.add(mStaIface0);
+        mIfaceInfoList.add(mStaIface1);
         mIfaceInfoList.add(mP2pIface);
 
         when(mServiceManagerMock.linkToDeath(any(IHwBinder.DeathRecipient.class),
@@ -216,6 +216,50 @@
         executeAndValidateInitializationSequence(false, false, false, true);
     }
 
+
+    /**
+     * Sunny day scenario for SupplicantStaIfaceHal initialization
+     * Asserts successful initialization of second interface
+     */
+    @Test
+    public void testSetupTwoInterfaces() throws Exception {
+        executeAndValidateInitializationSequence(false, false, false, false);
+        assertTrue(mDut.setupIface(WLAN1_IFACE_NAME));
+    }
+
+    /**
+     * Ensures that we do not allow operations on an interface until it's setup.
+     */
+    @Test
+    public void testEnsureOperationFailsUntilSetupInterfaces() throws Exception {
+        executeAndValidateInitializationSequence(false, false, false, false);
+
+        // Ensure that the cancel wps operation is failed because wlan1 interface is not yet setup.
+        assertFalse(mDut.cancelWps(WLAN1_IFACE_NAME));
+        verify(mISupplicantStaIfaceMock, never()).cancelWps();
+
+        // Now setup the wlan1 interface and Ensure that the cancel wps operation is successful.
+        assertTrue(mDut.setupIface(WLAN1_IFACE_NAME));
+        when(mISupplicantStaIfaceMock.cancelWps()).thenReturn(mStatusSuccess);
+        assertTrue(mDut.cancelWps(WLAN1_IFACE_NAME));
+        verify(mISupplicantStaIfaceMock).cancelWps();
+    }
+
+    /**
+     * Sunny day scenario for SupplicantStaIfaceHal interface teardown.
+     * Asserts successful initialization of second interface
+     */
+    @Test
+    public void testTeardownTwoInterfaces() throws Exception {
+        testSetupTwoInterfaces();
+        assertTrue(mDut.teardownIface(WLAN0_IFACE_NAME));
+        assertTrue(mDut.teardownIface(WLAN1_IFACE_NAME));
+
+        // Ensure that the cancel wps operation is failed because there are no interfaces setup.
+        assertFalse(mDut.cancelWps(WLAN0_IFACE_NAME));
+        verify(mISupplicantStaIfaceMock, never()).cancelWps();
+    }
+
     /**
      * Tests the loading of networks using {@link SupplicantStaNetworkHal}.
      * Fills up only the SSID field of configs and uses it as a configKey as well.
@@ -251,7 +295,7 @@
 
         Map<String, WifiConfiguration> configs = new HashMap<>();
         SparseArray<Map<String, String>> extras = new SparseArray<>();
-        assertTrue(mDut.loadNetworks(configs, extras));
+        assertTrue(mDut.loadNetworks(WLAN0_IFACE_NAME, configs, extras));
 
         assertEquals(3, configs.size());
         assertEquals(3, extras.size());
@@ -317,7 +361,7 @@
 
         Map<String, WifiConfiguration> configs = new HashMap<>();
         SparseArray<Map<String, String>> extras = new SparseArray<>();
-        assertTrue(mDut.loadNetworks(configs, extras));
+        assertTrue(mDut.loadNetworks(WLAN0_IFACE_NAME, configs, extras));
 
         assertEquals(2, configs.size());
         assertEquals(2, extras.size());
@@ -356,7 +400,7 @@
 
         Map<String, WifiConfiguration> configs = new HashMap<>();
         SparseArray<Map<String, String>> extras = new SparseArray<>();
-        assertFalse(mDut.loadNetworks(configs, extras));
+        assertFalse(mDut.loadNetworks(WLAN0_IFACE_NAME, configs, extras));
     }
 
     /**
@@ -381,7 +425,7 @@
 
         Map<String, WifiConfiguration> configs = new HashMap<>();
         SparseArray<Map<String, String>> extras = new SparseArray<>();
-        assertFalse(mDut.loadNetworks(configs, extras));
+        assertFalse(mDut.loadNetworks(WLAN0_IFACE_NAME, configs, extras));
     }
 
     /**
@@ -412,7 +456,7 @@
 
         Map<String, WifiConfiguration> configs = new HashMap<>();
         SparseArray<Map<String, String>> extras = new SparseArray<>();
-        assertTrue(mDut.loadNetworks(configs, extras));
+        assertTrue(mDut.loadNetworks(WLAN0_IFACE_NAME, configs, extras));
         assertTrue(configs.isEmpty());
     }
 
@@ -445,7 +489,7 @@
 
         Map<String, WifiConfiguration> configs = new HashMap<>();
         SparseArray<Map<String, String>> extras = new SparseArray<>();
-        assertTrue(mDut.loadNetworks(configs, extras));
+        assertTrue(mDut.loadNetworks(WLAN0_IFACE_NAME, configs, extras));
         assertTrue(configs.isEmpty());
     }
 
@@ -469,7 +513,7 @@
         setupMocksForConnectSequence(true /*haveExistingNetwork*/);
         // Make this network different by changing SSID.
         config.SSID = "AnDifferentSSID";
-        assertTrue(mDut.connectToNetwork(config));
+        assertTrue(mDut.connectToNetwork(WLAN0_IFACE_NAME, config));
         verify(mISupplicantStaIfaceMock).removeNetwork(SUPPLICANT_NETWORK_ID);
         verify(mISupplicantStaIfaceMock)
                 .addNetwork(any(ISupplicantStaIface.addNetworkCallback.class));
@@ -483,7 +527,7 @@
         // Reset mocks for mISupplicantStaIfaceMock because we finished the first connection.
         reset(mISupplicantStaIfaceMock);
         setupMocksForConnectSequence(true /*haveExistingNetwork*/);
-        assertTrue(mDut.connectToNetwork(config));
+        assertTrue(mDut.connectToNetwork(WLAN0_IFACE_NAME, config));
         verify(mISupplicantStaIfaceMock, never()).removeNetwork(anyInt());
         verify(mISupplicantStaIfaceMock, never())
                 .addNetwork(any(ISupplicantStaIface.addNetworkCallback.class));
@@ -504,7 +548,7 @@
         assertFalse(TextUtils.equals(
                 testBssid, config.getNetworkSelectionStatus().getNetworkSelectionBSSID()));
         config.getNetworkSelectionStatus().setNetworkSelectionBSSID(testBssid);
-        assertTrue(mDut.connectToNetwork(config));
+        assertTrue(mDut.connectToNetwork(WLAN0_IFACE_NAME, config));
         verify(mSupplicantStaNetworkMock).setBssid(eq(testBssid));
         verify(mISupplicantStaIfaceMock, never()).removeNetwork(anyInt());
         verify(mISupplicantStaIfaceMock, never())
@@ -526,7 +570,7 @@
         }).when(mISupplicantStaIfaceMock).addNetwork(
                 any(ISupplicantStaIface.addNetworkCallback.class));
 
-        assertFalse(mDut.connectToNetwork(createTestWifiConfiguration()));
+        assertFalse(mDut.connectToNetwork(WLAN0_IFACE_NAME, createTestWifiConfiguration()));
     }
 
     /**
@@ -540,7 +584,7 @@
         when(mSupplicantStaNetworkMock.saveWifiConfiguration(any(WifiConfiguration.class)))
                 .thenReturn(false);
 
-        assertFalse(mDut.connectToNetwork(createTestWifiConfiguration()));
+        assertFalse(mDut.connectToNetwork(WLAN0_IFACE_NAME, createTestWifiConfiguration()));
         // We should have removed the existing network once before connection and once more
         // on failure to save network configuration.
         verify(mISupplicantStaIfaceMock, times(2)).removeNetwork(anyInt());
@@ -558,7 +602,7 @@
                 .when(mSupplicantStaNetworkMock).saveWifiConfiguration(
                         any(WifiConfiguration.class));
 
-        assertFalse(mDut.connectToNetwork(createTestWifiConfiguration()));
+        assertFalse(mDut.connectToNetwork(WLAN0_IFACE_NAME, createTestWifiConfiguration()));
         // We should have removed the existing network once before connection and once more
         // on failure to save network configuration.
         verify(mISupplicantStaIfaceMock, times(2)).removeNetwork(anyInt());
@@ -574,7 +618,7 @@
 
         when(mSupplicantStaNetworkMock.select()).thenReturn(false);
 
-        assertFalse(mDut.connectToNetwork(createTestWifiConfiguration()));
+        assertFalse(mDut.connectToNetwork(WLAN0_IFACE_NAME, createTestWifiConfiguration()));
     }
 
     /**
@@ -584,7 +628,7 @@
     public void testRoamToSameNetwork() throws Exception {
         executeAndValidateInitializationSequence();
         executeAndValidateRoamSequence(true);
-        assertTrue(mDut.connectToNetwork(createTestWifiConfiguration()));
+        assertTrue(mDut.connectToNetwork(WLAN0_IFACE_NAME, createTestWifiConfiguration()));
     }
 
     /**
@@ -609,7 +653,7 @@
         WifiConfiguration roamingConfig = new WifiConfiguration();
         roamingConfig.networkId = connectedNetworkId;
         roamingConfig.getNetworkSelectionStatus().setNetworkSelectionBSSID("45:34:23:23:ab:ed");
-        assertFalse(mDut.roamToNetwork(roamingConfig));
+        assertFalse(mDut.roamToNetwork(WLAN0_IFACE_NAME, roamingConfig));
     }
 
     /**
@@ -631,7 +675,7 @@
             }
         }).when(mISupplicantStaIfaceMock).removeNetwork(anyInt());
 
-        assertTrue(mDut.removeAllNetworks());
+        assertTrue(mDut.removeAllNetworks(WLAN0_IFACE_NAME));
         verify(mISupplicantStaIfaceMock, times(NETWORK_ID_TO_SSID.size())).removeNetwork(anyInt());
     }
 
@@ -647,13 +691,13 @@
 
         // Connect to a network and verify current network is set.
         executeAndValidateConnectSequence(4, false);
-        assertTrue(mDut.setCurrentNetworkBssid(testBssid));
+        assertTrue(mDut.setCurrentNetworkBssid(WLAN0_IFACE_NAME, testBssid));
         verify(mSupplicantStaNetworkMock).setBssid(eq(testBssid));
         reset(mSupplicantStaNetworkMock);
 
         // Remove all networks and verify current network info is resetted.
-        assertTrue(mDut.removeAllNetworks());
-        assertFalse(mDut.setCurrentNetworkBssid(testBssid));
+        assertTrue(mDut.removeAllNetworks(WLAN0_IFACE_NAME));
+        assertFalse(mDut.setCurrentNetworkBssid(WLAN0_IFACE_NAME, testBssid));
         verify(mSupplicantStaNetworkMock, never()).setBssid(eq(testBssid));
     }
 
@@ -676,7 +720,7 @@
         WifiConfiguration roamingConfig = new WifiConfiguration();
         roamingConfig.networkId = connectedNetworkId;
         roamingConfig.getNetworkSelectionStatus().setNetworkSelectionBSSID("45:34:23:23:ab:ed");
-        assertFalse(mDut.roamToNetwork(roamingConfig));
+        assertFalse(mDut.roamToNetwork(WLAN0_IFACE_NAME, roamingConfig));
     }
 
     /**
@@ -689,10 +733,10 @@
 
         executeAndValidateInitializationSequence();
         // Return null when not connected to the network.
-        assertTrue(mDut.getCurrentNetworkWpsNfcConfigurationToken() == null);
+        assertTrue(mDut.getCurrentNetworkWpsNfcConfigurationToken(WLAN0_IFACE_NAME) == null);
         verify(mSupplicantStaNetworkMock, never()).getWpsNfcConfigurationToken();
         executeAndValidateConnectSequence(4, false);
-        assertEquals(token, mDut.getCurrentNetworkWpsNfcConfigurationToken());
+        assertEquals(token, mDut.getCurrentNetworkWpsNfcConfigurationToken(WLAN0_IFACE_NAME));
         verify(mSupplicantStaNetworkMock).getWpsNfcConfigurationToken();
     }
 
@@ -706,10 +750,10 @@
 
         executeAndValidateInitializationSequence();
         // Fail when not connected to a network.
-        assertFalse(mDut.setCurrentNetworkBssid(bssidStr));
+        assertFalse(mDut.setCurrentNetworkBssid(WLAN0_IFACE_NAME, bssidStr));
         verify(mSupplicantStaNetworkMock, never()).setBssid(eq(bssidStr));
         executeAndValidateConnectSequence(4, false);
-        assertTrue(mDut.setCurrentNetworkBssid(bssidStr));
+        assertTrue(mDut.setCurrentNetworkBssid(WLAN0_IFACE_NAME, bssidStr));
         verify(mSupplicantStaNetworkMock).setBssid(eq(bssidStr));
     }
 
@@ -724,10 +768,10 @@
 
         executeAndValidateInitializationSequence();
         // Fail when not connected to a network.
-        assertFalse(mDut.sendCurrentNetworkEapIdentityResponse(identity));
+        assertFalse(mDut.sendCurrentNetworkEapIdentityResponse(WLAN0_IFACE_NAME, identity));
         verify(mSupplicantStaNetworkMock, never()).sendNetworkEapIdentityResponse(eq(identity));
         executeAndValidateConnectSequence(4, false);
-        assertTrue(mDut.sendCurrentNetworkEapIdentityResponse(identity));
+        assertTrue(mDut.sendCurrentNetworkEapIdentityResponse(WLAN0_IFACE_NAME, identity));
         verify(mSupplicantStaNetworkMock).sendNetworkEapIdentityResponse(eq(identity));
     }
 
@@ -742,10 +786,11 @@
         executeAndValidateInitializationSequence();
 
         // Return null when not connected to the network.
-        assertEquals(null, mDut.getCurrentNetworkEapAnonymousIdentity());
+        assertEquals(null, mDut.getCurrentNetworkEapAnonymousIdentity(WLAN0_IFACE_NAME));
         executeAndValidateConnectSequence(4, false);
         // Return anonymous identity for the current network.
-        assertEquals(anonymousIdentity, mDut.getCurrentNetworkEapAnonymousIdentity());
+        assertEquals(
+                anonymousIdentity, mDut.getCurrentNetworkEapAnonymousIdentity(WLAN0_IFACE_NAME));
     }
 
     /**
@@ -759,10 +804,10 @@
 
         executeAndValidateInitializationSequence();
         // Fail when not connected to a network.
-        assertFalse(mDut.sendCurrentNetworkEapSimGsmAuthResponse(params));
+        assertFalse(mDut.sendCurrentNetworkEapSimGsmAuthResponse(WLAN0_IFACE_NAME, params));
         verify(mSupplicantStaNetworkMock, never()).sendNetworkEapSimGsmAuthResponse(eq(params));
         executeAndValidateConnectSequence(4, false);
-        assertTrue(mDut.sendCurrentNetworkEapSimGsmAuthResponse(params));
+        assertTrue(mDut.sendCurrentNetworkEapSimGsmAuthResponse(WLAN0_IFACE_NAME, params));
         verify(mSupplicantStaNetworkMock).sendNetworkEapSimGsmAuthResponse(eq(params));
     }
 
@@ -777,10 +822,10 @@
 
         executeAndValidateInitializationSequence();
         // Fail when not connected to a network.
-        assertFalse(mDut.sendCurrentNetworkEapSimUmtsAuthResponse(params));
+        assertFalse(mDut.sendCurrentNetworkEapSimUmtsAuthResponse(WLAN0_IFACE_NAME, params));
         verify(mSupplicantStaNetworkMock, never()).sendNetworkEapSimUmtsAuthResponse(eq(params));
         executeAndValidateConnectSequence(4, false);
-        assertTrue(mDut.sendCurrentNetworkEapSimUmtsAuthResponse(params));
+        assertTrue(mDut.sendCurrentNetworkEapSimUmtsAuthResponse(WLAN0_IFACE_NAME, params));
         verify(mSupplicantStaNetworkMock).sendNetworkEapSimUmtsAuthResponse(eq(params));
     }
 
@@ -795,10 +840,10 @@
 
         executeAndValidateInitializationSequence();
         // Fail when not connected to a network.
-        assertFalse(mDut.sendCurrentNetworkEapSimUmtsAutsResponse(params));
+        assertFalse(mDut.sendCurrentNetworkEapSimUmtsAutsResponse(WLAN0_IFACE_NAME, params));
         verify(mSupplicantStaNetworkMock, never()).sendNetworkEapSimUmtsAutsResponse(eq(params));
         executeAndValidateConnectSequence(4, false);
-        assertTrue(mDut.sendCurrentNetworkEapSimUmtsAutsResponse(params));
+        assertTrue(mDut.sendCurrentNetworkEapSimUmtsAutsResponse(WLAN0_IFACE_NAME, params));
         verify(mSupplicantStaNetworkMock).sendNetworkEapSimUmtsAutsResponse(eq(params));
     }
 
@@ -817,13 +862,13 @@
         executeAndValidateInitializationSequence();
 
         // This should work.
-        assertTrue(mDut.setWpsDeviceType(validDeviceTypeStr));
+        assertTrue(mDut.setWpsDeviceType(WLAN0_IFACE_NAME, validDeviceTypeStr));
         verify(mISupplicantStaIfaceMock).setWpsDeviceType(eq(expectedDeviceType));
 
         // This should not work
-        assertFalse(mDut.setWpsDeviceType(invalidDeviceType1Str));
+        assertFalse(mDut.setWpsDeviceType(WLAN0_IFACE_NAME, invalidDeviceType1Str));
         // This should not work
-        assertFalse(mDut.setWpsDeviceType(invalidDeviceType2Str));
+        assertFalse(mDut.setWpsDeviceType(WLAN0_IFACE_NAME, invalidDeviceType2Str));
     }
 
     /**
@@ -840,12 +885,12 @@
         executeAndValidateInitializationSequence();
 
         // This should work.
-        assertTrue(mDut.setWpsConfigMethods(validConfigMethodsStr));
+        assertTrue(mDut.setWpsConfigMethods(WLAN0_IFACE_NAME, validConfigMethodsStr));
         verify(mISupplicantStaIfaceMock).setWpsConfigMethods(eq(expectedConfigMethods));
 
         // This should throw an illegal argument exception.
         try {
-            assertFalse(mDut.setWpsConfigMethods(invalidConfigMethodsStr));
+            assertFalse(mDut.setWpsConfigMethods(WLAN0_IFACE_NAME, invalidConfigMethodsStr));
         } catch (IllegalArgumentException e) {
             return;
         }
@@ -868,7 +913,8 @@
                 new ISupplicantStaIfaceCallback.Hs20AnqpData());
 
         ArgumentCaptor<AnqpEvent> anqpEventCaptor = ArgumentCaptor.forClass(AnqpEvent.class);
-        verify(mWifiMonitor).broadcastAnqpDoneEvent(eq(WLAN_IFACE_NAME), anqpEventCaptor.capture());
+        verify(mWifiMonitor).broadcastAnqpDoneEvent(
+                eq(WLAN0_IFACE_NAME), anqpEventCaptor.capture());
         assertEquals(
                 ByteBufferReader.readInteger(
                         ByteBuffer.wrap(bssid), ByteOrder.BIG_ENDIAN, bssid.length),
@@ -890,7 +936,8 @@
                 bssid, ICON_FILE_NAME, NativeUtil.byteArrayToArrayList(iconData));
 
         ArgumentCaptor<IconEvent> iconEventCaptor = ArgumentCaptor.forClass(IconEvent.class);
-        verify(mWifiMonitor).broadcastIconDoneEvent(eq(WLAN_IFACE_NAME), iconEventCaptor.capture());
+        verify(mWifiMonitor).broadcastIconDoneEvent(
+                eq(WLAN0_IFACE_NAME), iconEventCaptor.capture());
         assertEquals(
                 ByteBufferReader.readInteger(
                         ByteBuffer.wrap(bssid), ByteOrder.BIG_ENDIAN, bssid.length),
@@ -913,7 +960,7 @@
                 bssid, osuMethod, HS20_URL);
 
         ArgumentCaptor<WnmData> wnmDataCaptor = ArgumentCaptor.forClass(WnmData.class);
-        verify(mWifiMonitor).broadcastWnmEvent(eq(WLAN_IFACE_NAME), wnmDataCaptor.capture());
+        verify(mWifiMonitor).broadcastWnmEvent(eq(WLAN0_IFACE_NAME), wnmDataCaptor.capture());
         assertEquals(
                 ByteBufferReader.readInteger(
                         ByteBuffer.wrap(bssid), ByteOrder.BIG_ENDIAN, bssid.length),
@@ -954,7 +1001,7 @@
 
         // Can't compare WifiSsid instances because they lack an equals.
         verify(mWifiMonitor).broadcastSupplicantStateChangeEvent(
-                eq(WLAN_IFACE_NAME), eq(WifiConfiguration.INVALID_NETWORK_ID),
+                eq(WLAN0_IFACE_NAME), eq(WifiConfiguration.INVALID_NETWORK_ID),
                 any(WifiSsid.class), eq(BSSID), eq(SupplicantState.INACTIVE));
     }
 
@@ -974,7 +1021,7 @@
                 NativeUtil.decodeSsid(SUPPLICANT_SSID));
 
         verify(mWifiMonitor).broadcastSupplicantStateChangeEvent(
-                eq(WLAN_IFACE_NAME), eq(frameworkNetworkId),
+                eq(WLAN0_IFACE_NAME), eq(frameworkNetworkId),
                 any(WifiSsid.class), eq(BSSID), eq(SupplicantState.ASSOCIATED));
     }
 
@@ -995,9 +1042,9 @@
                 NativeUtil.decodeSsid(SUPPLICANT_SSID));
 
         wifiMonitorInOrder.verify(mWifiMonitor).broadcastNetworkConnectionEvent(
-                eq(WLAN_IFACE_NAME), eq(frameworkNetworkId), eq(BSSID));
+                eq(WLAN0_IFACE_NAME), eq(frameworkNetworkId), eq(BSSID));
         wifiMonitorInOrder.verify(mWifiMonitor).broadcastSupplicantStateChangeEvent(
-                eq(WLAN_IFACE_NAME), eq(frameworkNetworkId),
+                eq(WLAN0_IFACE_NAME), eq(frameworkNetworkId),
                 any(WifiSsid.class), eq(BSSID), eq(SupplicantState.COMPLETED));
     }
 
@@ -1013,12 +1060,12 @@
         mISupplicantStaIfaceCallback.onDisconnected(
                 NativeUtil.macAddressToByteArray(BSSID), true, reasonCode);
         verify(mWifiMonitor).broadcastNetworkDisconnectionEvent(
-                eq(WLAN_IFACE_NAME), eq(1), eq(reasonCode), eq(BSSID));
+                eq(WLAN0_IFACE_NAME), eq(1), eq(reasonCode), eq(BSSID));
 
         mISupplicantStaIfaceCallback.onDisconnected(
                 NativeUtil.macAddressToByteArray(BSSID), false, reasonCode);
         verify(mWifiMonitor).broadcastNetworkDisconnectionEvent(
-                eq(WLAN_IFACE_NAME), eq(0), eq(reasonCode), eq(BSSID));
+                eq(WLAN0_IFACE_NAME), eq(0), eq(reasonCode), eq(BSSID));
     }
 
     /**
@@ -1048,7 +1095,7 @@
         mISupplicantStaIfaceCallback.onDisconnected(
                 NativeUtil.macAddressToByteArray(BSSID), false, reasonCode);
 
-        verify(mWifiMonitor, times(2)).broadcastAuthenticationFailureEvent(eq(WLAN_IFACE_NAME),
+        verify(mWifiMonitor, times(2)).broadcastAuthenticationFailureEvent(eq(WLAN0_IFACE_NAME),
                 eq(WifiManager.ERROR_AUTH_FAILURE_WRONG_PSWD));
 
     }
@@ -1086,7 +1133,7 @@
         int reasonCode = ISupplicantStaIfaceCallback.ReasonCode.IEEE_802_1X_AUTH_FAILED;
         mISupplicantStaIfaceCallback.onDisconnected(
                 NativeUtil.macAddressToByteArray(BSSID), false, reasonCode);
-        verify(mWifiMonitor).broadcastAuthenticationFailureEvent(eq(WLAN_IFACE_NAME),
+        verify(mWifiMonitor).broadcastAuthenticationFailureEvent(eq(WLAN0_IFACE_NAME),
                 eq(WifiManager.ERROR_AUTH_FAILURE_EAP_FAILURE));
     }
 
@@ -1102,7 +1149,7 @@
         mISupplicantStaIfaceCallback.onAssociationRejected(
                 NativeUtil.macAddressToByteArray(BSSID), statusCode, false);
         verify(mWifiMonitor).broadcastAssociationRejectionEvent(
-                eq(WLAN_IFACE_NAME), eq(statusCode), eq(false), eq(BSSID));
+                eq(WLAN0_IFACE_NAME), eq(statusCode), eq(false), eq(BSSID));
     }
 
     /**
@@ -1115,7 +1162,7 @@
 
         mISupplicantStaIfaceCallback.onAuthenticationTimeout(
                 NativeUtil.macAddressToByteArray(BSSID));
-        verify(mWifiMonitor).broadcastAuthenticationFailureEvent(eq(WLAN_IFACE_NAME),
+        verify(mWifiMonitor).broadcastAuthenticationFailureEvent(eq(WLAN0_IFACE_NAME),
                 eq(WifiManager.ERROR_AUTH_FAILURE_TIMEOUT));
     }
 
@@ -1129,20 +1176,22 @@
 
         mISupplicantStaIfaceCallback.onBssidChanged(
                 BssidChangeReason.ASSOC_START, NativeUtil.macAddressToByteArray(BSSID));
-        verify(mWifiMonitor).broadcastTargetBssidEvent(eq(WLAN_IFACE_NAME), eq(BSSID));
-        verify(mWifiMonitor, never()).broadcastAssociatedBssidEvent(eq(WLAN_IFACE_NAME), eq(BSSID));
+        verify(mWifiMonitor).broadcastTargetBssidEvent(eq(WLAN0_IFACE_NAME), eq(BSSID));
+        verify(mWifiMonitor, never()).broadcastAssociatedBssidEvent(
+                eq(WLAN0_IFACE_NAME), eq(BSSID));
 
         reset(mWifiMonitor);
         mISupplicantStaIfaceCallback.onBssidChanged(
                 BssidChangeReason.ASSOC_COMPLETE, NativeUtil.macAddressToByteArray(BSSID));
-        verify(mWifiMonitor, never()).broadcastTargetBssidEvent(eq(WLAN_IFACE_NAME), eq(BSSID));
-        verify(mWifiMonitor).broadcastAssociatedBssidEvent(eq(WLAN_IFACE_NAME), eq(BSSID));
+        verify(mWifiMonitor, never()).broadcastTargetBssidEvent(eq(WLAN0_IFACE_NAME), eq(BSSID));
+        verify(mWifiMonitor).broadcastAssociatedBssidEvent(eq(WLAN0_IFACE_NAME), eq(BSSID));
 
         reset(mWifiMonitor);
         mISupplicantStaIfaceCallback.onBssidChanged(
                 BssidChangeReason.DISASSOC, NativeUtil.macAddressToByteArray(BSSID));
-        verify(mWifiMonitor, never()).broadcastTargetBssidEvent(eq(WLAN_IFACE_NAME), eq(BSSID));
-        verify(mWifiMonitor, never()).broadcastAssociatedBssidEvent(eq(WLAN_IFACE_NAME), eq(BSSID));
+        verify(mWifiMonitor, never()).broadcastTargetBssidEvent(eq(WLAN0_IFACE_NAME), eq(BSSID));
+        verify(mWifiMonitor, never()).broadcastAssociatedBssidEvent(
+                eq(WLAN0_IFACE_NAME), eq(BSSID));
     }
 
     /**
@@ -1154,7 +1203,7 @@
         assertNotNull(mISupplicantStaIfaceCallback);
 
         mISupplicantStaIfaceCallback.onEapFailure();
-        verify(mWifiMonitor).broadcastAuthenticationFailureEvent(eq(WLAN_IFACE_NAME),
+        verify(mWifiMonitor).broadcastAuthenticationFailureEvent(eq(WLAN0_IFACE_NAME),
                 eq(WifiManager.ERROR_AUTH_FAILURE_EAP_FAILURE));
     }
 
@@ -1167,7 +1216,7 @@
         assertNotNull(mISupplicantStaIfaceCallback);
 
         mISupplicantStaIfaceCallback.onWpsEventSuccess();
-        verify(mWifiMonitor).broadcastWpsSuccessEvent(eq(WLAN_IFACE_NAME));
+        verify(mWifiMonitor).broadcastWpsSuccessEvent(eq(WLAN0_IFACE_NAME));
     }
 
     /**
@@ -1182,7 +1231,7 @@
         short errorInd = ISupplicantStaIfaceCallback.WpsErrorIndication.SECURITY_WEP_PROHIBITED;
         mISupplicantStaIfaceCallback.onWpsEventFail(
                 NativeUtil.macAddressToByteArray(BSSID), cfgError, errorInd);
-        verify(mWifiMonitor).broadcastWpsFailEvent(eq(WLAN_IFACE_NAME),
+        verify(mWifiMonitor).broadcastWpsFailEvent(eq(WLAN0_IFACE_NAME),
                 eq((int) cfgError), eq((int) errorInd));
     }
 
@@ -1198,7 +1247,7 @@
         short errorInd = ISupplicantStaIfaceCallback.WpsErrorIndication.NO_ERROR;
         mISupplicantStaIfaceCallback.onWpsEventFail(
                 NativeUtil.macAddressToByteArray(BSSID), cfgError, errorInd);
-        verify(mWifiMonitor).broadcastWpsTimeoutEvent(eq(WLAN_IFACE_NAME));
+        verify(mWifiMonitor).broadcastWpsTimeoutEvent(eq(WLAN0_IFACE_NAME));
     }
 
     /**
@@ -1210,7 +1259,7 @@
         assertNotNull(mISupplicantStaIfaceCallback);
 
         mISupplicantStaIfaceCallback.onWpsEventPbcOverlap();
-        verify(mWifiMonitor).broadcastWpsOverlapEvent(eq(WLAN_IFACE_NAME));
+        verify(mWifiMonitor).broadcastWpsOverlapEvent(eq(WLAN0_IFACE_NAME));
     }
 
     /**
@@ -1221,11 +1270,13 @@
         executeAndValidateInitializationSequence();
         assertNotNull(mServiceManagerDeathCaptor.getValue());
         assertTrue(mDut.isInitializationComplete());
+        assertTrue(mDut.registerDeathHandler(mSupplicantHalDeathHandler));
 
         mServiceManagerDeathCaptor.getValue().serviceDied(5L);
 
         assertFalse(mDut.isInitializationComplete());
-        verify(mWifiMonitor).broadcastSupplicantDisconnectionEvent(eq(WLAN_IFACE_NAME));
+        verify(mWifiMonitor).broadcastSupplicantDisconnectionEvent(eq(WLAN0_IFACE_NAME));
+        verify(mSupplicantHalDeathHandler).onDeath();
     }
 
     /**
@@ -1236,11 +1287,13 @@
         executeAndValidateInitializationSequence();
         assertNotNull(mSupplicantDeathCaptor.getValue());
         assertTrue(mDut.isInitializationComplete());
+        assertTrue(mDut.registerDeathHandler(mSupplicantHalDeathHandler));
 
         mSupplicantDeathCaptor.getValue().serviceDied(5L);
 
         assertFalse(mDut.isInitializationComplete());
-        verify(mWifiMonitor).broadcastSupplicantDisconnectionEvent(eq(WLAN_IFACE_NAME));
+        verify(mWifiMonitor).broadcastSupplicantDisconnectionEvent(eq(WLAN0_IFACE_NAME));
+        verify(mSupplicantHalDeathHandler).onDeath();
     }
 
     /**
@@ -1255,7 +1308,7 @@
         mSupplicantStaIfaceDeathCaptor.getValue().serviceDied(5L);
 
         assertFalse(mDut.isInitializationComplete());
-        verify(mWifiMonitor).broadcastSupplicantDisconnectionEvent(eq(WLAN_IFACE_NAME));
+        verify(mWifiMonitor).broadcastSupplicantDisconnectionEvent(eq(WLAN0_IFACE_NAME));
     }
 
     /**
@@ -1305,17 +1358,17 @@
                 .thenReturn(mStatusSuccess);
 
         // Fail before initialization is performed.
-        assertFalse(mDut.startWpsRegistrar(null, null));
+        assertFalse(mDut.startWpsRegistrar(WLAN0_IFACE_NAME, null, null));
 
         executeAndValidateInitializationSequence();
 
-        assertFalse(mDut.startWpsRegistrar(null, null));
+        assertFalse(mDut.startWpsRegistrar(WLAN0_IFACE_NAME, null, null));
         verify(mISupplicantStaIfaceMock, never()).startWpsRegistrar(any(byte[].class), anyString());
 
-        assertFalse(mDut.startWpsRegistrar(new String(), "452233"));
+        assertFalse(mDut.startWpsRegistrar(WLAN0_IFACE_NAME, new String(), "452233"));
         verify(mISupplicantStaIfaceMock, never()).startWpsRegistrar(any(byte[].class), anyString());
 
-        assertTrue(mDut.startWpsRegistrar("45:23:12:12:12:98", "562535"));
+        assertTrue(mDut.startWpsRegistrar(WLAN0_IFACE_NAME, "45:23:12:12:12:98", "562535"));
         verify(mISupplicantStaIfaceMock).startWpsRegistrar(any(byte[].class), anyString());
     }
 
@@ -1330,15 +1383,15 @@
         byte[] anyBssidBytes = {0, 0, 0, 0, 0, 0};
 
         // Fail before initialization is performed.
-        assertFalse(mDut.startWpsPbc(bssid));
+        assertFalse(mDut.startWpsPbc(WLAN0_IFACE_NAME, bssid));
         verify(mISupplicantStaIfaceMock, never()).startWpsPbc(any(byte[].class));
 
         executeAndValidateInitializationSequence();
 
-        assertTrue(mDut.startWpsPbc(bssid));
+        assertTrue(mDut.startWpsPbc(WLAN0_IFACE_NAME, bssid));
         verify(mISupplicantStaIfaceMock).startWpsPbc(eq(bssidBytes));
 
-        assertTrue(mDut.startWpsPbc(null));
+        assertTrue(mDut.startWpsPbc(WLAN0_IFACE_NAME, null));
         verify(mISupplicantStaIfaceMock).startWpsPbc(eq(anyBssidBytes));
     }
 
@@ -1359,7 +1412,7 @@
                 bssid, reasonCode, reauthDelay, HS20_URL);
 
         ArgumentCaptor<WnmData> wnmDataCaptor = ArgumentCaptor.forClass(WnmData.class);
-        verify(mWifiMonitor).broadcastWnmEvent(eq(WLAN_IFACE_NAME), wnmDataCaptor.capture());
+        verify(mWifiMonitor).broadcastWnmEvent(eq(WLAN0_IFACE_NAME), wnmDataCaptor.capture());
         assertEquals(
                 ByteBufferReader.readInteger(
                         ByteBuffer.wrap(bssid), ByteOrder.BIG_ENDIAN, bssid.length),
@@ -1436,7 +1489,8 @@
         // act: cause the onRegistration(...) callback to execute
         mServiceNotificationCaptor.getValue().onRegistration(ISupplicant.kInterfaceName, "", true);
 
-        assertTrue(mDut.isInitializationComplete() == shouldSucceed);
+        assertTrue(mDut.isInitializationComplete());
+        assertTrue(mDut.setupIface(WLAN0_IFACE_NAME) == shouldSucceed);
         mInOrder.verify(mISupplicantMock).linkToDeath(mSupplicantDeathCaptor.capture(),
                 anyLong());
         // verify: listInterfaces is called
@@ -1448,7 +1502,8 @@
                             any(ISupplicant.getInterfaceCallback.class));
         }
         if (causeRemoteException) {
-            mInOrder.verify(mWifiMonitor).broadcastSupplicantDisconnectionEvent(eq(null));
+            mInOrder.verify(mWifiMonitor).broadcastSupplicantDisconnectionEvent(
+                    eq(WLAN0_IFACE_NAME));
         }
         if (!causeRemoteException && !getZeroInterfaces && !getNullInterface) {
             mInOrder.verify(mISupplicantStaIfaceMock).linkToDeath(
@@ -1566,7 +1621,7 @@
         setupMocksForConnectSequence(haveExistingNetwork);
         WifiConfiguration config = new WifiConfiguration();
         config.networkId = newFrameworkNetworkId;
-        assertTrue(mDut.connectToNetwork(config));
+        assertTrue(mDut.connectToNetwork(WLAN0_IFACE_NAME, config));
         validateConnectSequence(haveExistingNetwork, 1);
         return config;
     }
@@ -1603,7 +1658,7 @@
         WifiConfiguration roamingConfig = new WifiConfiguration();
         roamingConfig.networkId = roamNetworkId;
         roamingConfig.getNetworkSelectionStatus().setNetworkSelectionBSSID(roamBssid);
-        assertTrue(mDut.roamToNetwork(roamingConfig));
+        assertTrue(mDut.roamToNetwork(WLAN0_IFACE_NAME, roamingConfig));
 
         if (!sameNetwork) {
             validateConnectSequence(false, 2);
diff --git a/tests/wifitests/src/com/android/server/wifi/TestUtil.java b/tests/wifitests/src/com/android/server/wifi/TestUtil.java
index a0a1030..ab2cda5 100644
--- a/tests/wifitests/src/com/android/server/wifi/TestUtil.java
+++ b/tests/wifitests/src/com/android/server/wifi/TestUtil.java
@@ -21,6 +21,7 @@
 import android.content.Intent;
 import android.net.ConnectivityManager;
 import android.net.NetworkInfo;
+import android.net.wifi.WifiInfo;
 import android.net.wifi.WifiManager;
 
 import java.util.ArrayList;
@@ -42,6 +43,17 @@
     }
 
     /**
+     * Send {@link WifiManager#NETWORK_STATE_CHANGED_ACTION} broadcast.
+     */
+    public static void sendNetworkStateChanged(BroadcastReceiver broadcastReceiver,
+            Context context, NetworkInfo nwInfo, WifiInfo wifiInfo) {
+        Intent intent = new Intent(WifiManager.NETWORK_STATE_CHANGED_ACTION);
+        intent.putExtra(WifiManager.EXTRA_NETWORK_INFO, nwInfo);
+        intent.putExtra(WifiManager.EXTRA_WIFI_INFO, wifiInfo);
+        broadcastReceiver.onReceive(context, intent);
+    }
+
+    /**
      * Send {@link WifiManager#SCAN_RESULTS_AVAILABLE_ACTION} broadcast.
      */
     public static void sendScanResultsAvailable(BroadcastReceiver broadcastReceiver,
@@ -85,7 +97,6 @@
         }
         intent.putExtra(WifiManager.EXTRA_WIFI_AP_INTERFACE_NAME, ifaceName);
         intent.putExtra(WifiManager.EXTRA_WIFI_AP_MODE, mode);
-
         broadcastReceiver.onReceive(context, intent);
     }
 
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java
index 72a2479..9a79a23 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java
@@ -20,8 +20,6 @@
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.anyBoolean;
-import static org.mockito.Mockito.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
@@ -156,8 +154,10 @@
     public void setUp() throws Exception {
         MockitoAnnotations.initMocks(this);
         when(mWifiVendorHal.isVendorHalSupported()).thenReturn(true);
-        when(mWifiVendorHal.startVendorHal(anyBoolean())).thenReturn(true);
-        mWifiNative = new WifiNative("test0", mWifiVendorHal, mStaIfaceHal, mWificondControl);
+        when(mWifiVendorHal.startVendorHalSta()).thenReturn(true);
+        when(mWifiVendorHal.startVendorHalAp()).thenReturn(true);
+        mWifiNative =
+                new WifiNative(WIFI_IFACE_NAME, mWifiVendorHal, mStaIfaceHal, mWificondControl);
     }
 
     /**
@@ -482,139 +482,139 @@
     // TODO(b/28005116): Add test for the success case of getDriverStateDump().
 
     /**
-     * Verifies that setupDriverForClientMode(WIFI_IFACE_NAME) calls underlying WificondControl.
+     * Verifies that setupInterfaceForClientMode(WIFI_IFACE_NAME) calls underlying WificondControl.
      */
     @Test
     public void testSetupDriverForClientMode() {
         IClientInterface clientInterface = mock(IClientInterface.class);
-        when(mWificondControl.setupDriverForClientMode(WIFI_IFACE_NAME))
+        when(mWificondControl.setupInterfaceForClientMode(WIFI_IFACE_NAME))
                 .thenReturn(clientInterface);
 
         Pair<Integer, IClientInterface> statusAndClientInterface =
                 mWifiNative.setupForClientMode(WIFI_IFACE_NAME);
         assertTrue(WifiNative.SETUP_SUCCESS == statusAndClientInterface.first);
         assertEquals(clientInterface, statusAndClientInterface.second);
-        verify(mWifiVendorHal).startVendorHal(eq(true));
-        verify(mWificondControl).setupDriverForClientMode(WIFI_IFACE_NAME);
+        verify(mWifiVendorHal).startVendorHalSta();
+        verify(mWificondControl).setupInterfaceForClientMode(WIFI_IFACE_NAME);
     }
 
     /**
-     * Verifies that setupDriverForClientMode(WIFI_IFACE_NAME) does not call start vendor HAL
+     * Verifies that setupInterfaceForClientMode(WIFI_IFACE_NAME) does not call start vendor HAL
      * when it is not supported and calls underlying WificondControl setup.
      */
     @Test
     public void testSetupDriverForClientModeWithNoVendorHal() {
         when(mWifiVendorHal.isVendorHalSupported()).thenReturn(false);
         IClientInterface clientInterface = mock(IClientInterface.class);
-        when(mWificondControl.setupDriverForClientMode(WIFI_IFACE_NAME))
+        when(mWificondControl.setupInterfaceForClientMode(WIFI_IFACE_NAME))
                 .thenReturn(clientInterface);
 
         Pair<Integer, IClientInterface> statusAndClientInterface =
                 mWifiNative.setupForClientMode(WIFI_IFACE_NAME);
         assertTrue(WifiNative.SETUP_SUCCESS == statusAndClientInterface.first);
         assertEquals(clientInterface, statusAndClientInterface.second);
-        verify(mWifiVendorHal, never()).startVendorHal(anyBoolean());
-        verify(mWificondControl).setupDriverForClientMode(WIFI_IFACE_NAME);
+        verify(mWifiVendorHal, never()).startVendorHalSta();
+        verify(mWificondControl).setupInterfaceForClientMode(WIFI_IFACE_NAME);
     }
 
     /**
-     * Verifies that setupDriverForClientMode(WIFI_IFACE_NAME) returns null when underlying
+     * Verifies that setupInterfaceForClientMode(WIFI_IFACE_NAME) returns null when underlying
      * WificondControl call fails.
      */
     @Test
     public void testSetupDriverForClientModeWificondError() {
-        when(mWificondControl.setupDriverForClientMode(WIFI_IFACE_NAME)).thenReturn(null);
+        when(mWificondControl.setupInterfaceForClientMode(WIFI_IFACE_NAME)).thenReturn(null);
 
         Pair<Integer, IClientInterface> statusAndClientInterface =
                 mWifiNative.setupForClientMode(WIFI_IFACE_NAME);
         assertTrue(WifiNative.SETUP_FAILURE_WIFICOND == statusAndClientInterface.first);
         assertEquals(null, statusAndClientInterface.second);
-        verify(mWifiVendorHal).startVendorHal(eq(true));
-        verify(mWificondControl).setupDriverForClientMode(WIFI_IFACE_NAME);
+        verify(mWifiVendorHal).startVendorHalSta();
+        verify(mWificondControl).setupInterfaceForClientMode(WIFI_IFACE_NAME);
     }
 
     /**
-     * Verifies that setupDriverForClientMode(WIFI_IFACE_NAME) returns null when underlying Hal
+     * Verifies that setupInterfaceForClientMode(WIFI_IFACE_NAME) returns null when underlying Hal
      * call fails.
      */
     @Test
     public void testSetupDriverForClientModeHalError() {
-        when(mWifiVendorHal.startVendorHal(anyBoolean())).thenReturn(false);
+        when(mWifiVendorHal.startVendorHalSta()).thenReturn(false);
 
         Pair<Integer, IClientInterface> statusAndClientInterface =
                 mWifiNative.setupForClientMode(WIFI_IFACE_NAME);
         assertTrue(WifiNative.SETUP_FAILURE_HAL == statusAndClientInterface.first);
         assertEquals(null, statusAndClientInterface.second);
-        verify(mWifiVendorHal).startVendorHal(eq(true));
-        verify(mWificondControl, never()).setupDriverForClientMode(WIFI_IFACE_NAME);
+        verify(mWifiVendorHal).startVendorHalSta();
+        verify(mWificondControl, never()).setupInterfaceForClientMode(WIFI_IFACE_NAME);
     }
 
     /**
-     * Verifies that setupDriverForSoftApMode(WIFI_IFACE_NAME) calls underlying WificondControl.
+     * Verifies that setupInterfaceForSoftApMode(WIFI_IFACE_NAME) calls underlying WificondControl.
      */
     @Test
     public void testSetupDriverForSoftApMode() {
         IApInterface apInterface = mock(IApInterface.class);
-        when(mWificondControl.setupDriverForSoftApMode(WIFI_IFACE_NAME)).thenReturn(apInterface);
+        when(mWificondControl.setupInterfaceForSoftApMode(WIFI_IFACE_NAME)).thenReturn(apInterface);
 
         Pair<Integer, IApInterface> statusAndApInterface =
                 mWifiNative.setupForSoftApMode(WIFI_IFACE_NAME);
         assertTrue(WifiNative.SETUP_SUCCESS == statusAndApInterface.first);
         assertEquals(apInterface, statusAndApInterface.second);
-        verify(mWifiVendorHal).startVendorHal(eq(false));
-        verify(mWificondControl).setupDriverForSoftApMode(WIFI_IFACE_NAME);
+        verify(mWifiVendorHal).startVendorHalAp();
+        verify(mWificondControl).setupInterfaceForSoftApMode(WIFI_IFACE_NAME);
     }
 
     /**
-     * Verifies that setupDriverForClientMode(WIFI_IFACE_NAME) does not call start vendor HAL when
-     * it is not supported and calls underlying WificondControl setup.
+     * Verifies that setupInterfaceForClientMode(WIFI_IFACE_NAME) does not call start vendor HAL
+     * when it is not supported and calls underlying WificondControl setup.
      */
     @Test
     public void testSetupDriverForSoftApModeWithNoVendorHal() {
         when(mWifiVendorHal.isVendorHalSupported()).thenReturn(false);
         IApInterface apInterface = mock(IApInterface.class);
-        when(mWificondControl.setupDriverForSoftApMode(WIFI_IFACE_NAME)).thenReturn(apInterface);
+        when(mWificondControl.setupInterfaceForSoftApMode(WIFI_IFACE_NAME)).thenReturn(apInterface);
 
         Pair<Integer, IApInterface> statusAndApInterface =
                 mWifiNative.setupForSoftApMode(WIFI_IFACE_NAME);
         assertTrue(WifiNative.SETUP_SUCCESS == statusAndApInterface.first);
         assertEquals(apInterface, statusAndApInterface.second);
-        verify(mWifiVendorHal, never()).startVendorHal(anyBoolean());
-        verify(mWificondControl).setupDriverForSoftApMode(WIFI_IFACE_NAME);
+        verify(mWifiVendorHal, never()).startVendorHalAp();
+        verify(mWificondControl).setupInterfaceForSoftApMode(WIFI_IFACE_NAME);
     }
 
     /**
-     * Verifies that setupDriverForSoftApMode(WIFI_IFACE_NAME) returns null when underlying
+     * Verifies that setupInterfaceForSoftApMode(WIFI_IFACE_NAME) returns null when underlying
      * WificondControl call fails.
      */
     @Test
     public void testSetupDriverForSoftApModeWificondError() {
-        when(mWificondControl.setupDriverForSoftApMode(WIFI_IFACE_NAME)).thenReturn(null);
+        when(mWificondControl.setupInterfaceForSoftApMode(WIFI_IFACE_NAME)).thenReturn(null);
 
         Pair<Integer, IApInterface> statusAndApInterface =
                 mWifiNative.setupForSoftApMode(WIFI_IFACE_NAME);
         assertTrue(WifiNative.SETUP_FAILURE_WIFICOND == statusAndApInterface.first);
         assertEquals(null, statusAndApInterface.second);
 
-        verify(mWifiVendorHal).startVendorHal(eq(false));
-        verify(mWificondControl).setupDriverForSoftApMode(WIFI_IFACE_NAME);
+        verify(mWifiVendorHal).startVendorHalAp();
+        verify(mWificondControl).setupInterfaceForSoftApMode(WIFI_IFACE_NAME);
     }
 
     /**
-     * Verifies that setupDriverForSoftApMode(WIFI_IFACE_NAME) returns null when underlying Hal
+     * Verifies that setupInterfaceForSoftApMode(WIFI_IFACE_NAME) returns null when underlying Hal
      * call fails.
      */
     @Test
     public void testSetupDriverForSoftApModeHalError() {
-        when(mWifiVendorHal.startVendorHal(anyBoolean())).thenReturn(false);
+        when(mWifiVendorHal.startVendorHalAp()).thenReturn(false);
 
         Pair<Integer, IApInterface> statusAndApInterface =
                 mWifiNative.setupForSoftApMode(WIFI_IFACE_NAME);
         assertTrue(WifiNative.SETUP_FAILURE_HAL == statusAndApInterface.first);
         assertEquals(null, statusAndApInterface.second);
 
-        verify(mWifiVendorHal).startVendorHal(eq(false));
-        verify(mWificondControl, never()).setupDriverForSoftApMode(WIFI_IFACE_NAME);
+        verify(mWifiVendorHal).startVendorHalAp();
+        verify(mWificondControl, never()).setupInterfaceForSoftApMode(WIFI_IFACE_NAME);
     }
 
     /**
@@ -670,10 +670,11 @@
      */
     @Test
     public void testSignalPoll() throws Exception {
-        when(mWificondControl.signalPoll()).thenReturn(SIGNAL_POLL_RESULT);
+        when(mWificondControl.signalPoll(WIFI_IFACE_NAME))
+                .thenReturn(SIGNAL_POLL_RESULT);
 
         assertEquals(SIGNAL_POLL_RESULT, mWifiNative.signalPoll());
-        verify(mWificondControl).signalPoll();
+        verify(mWificondControl).signalPoll(WIFI_IFACE_NAME);
     }
 
     /**
@@ -681,10 +682,11 @@
      */
     @Test
     public void testGetTxPacketCounters() throws Exception {
-        when(mWificondControl.getTxPacketCounters()).thenReturn(PACKET_COUNTERS_RESULT);
+        when(mWificondControl.getTxPacketCounters(WIFI_IFACE_NAME))
+                .thenReturn(PACKET_COUNTERS_RESULT);
 
         assertEquals(PACKET_COUNTERS_RESULT, mWifiNative.getTxPacketCounters());
-        verify(mWificondControl).getTxPacketCounters();
+        verify(mWificondControl).getTxPacketCounters(WIFI_IFACE_NAME);
     }
 
     /**
@@ -693,7 +695,8 @@
     @Test
     public void testScan() throws Exception {
         mWifiNative.scan(SCAN_FREQ_SET, SCAN_HIDDEN_NETWORK_SSID_SET);
-        verify(mWificondControl).scan(SCAN_FREQ_SET, SCAN_HIDDEN_NETWORK_SSID_SET);
+        verify(mWificondControl).scan(
+                WIFI_IFACE_NAME, SCAN_FREQ_SET, SCAN_HIDDEN_NETWORK_SSID_SET);
     }
 
     /**
@@ -702,7 +705,8 @@
     @Test
     public void testStartPnoScan() throws Exception {
         mWifiNative.startPnoScan(TEST_PNO_SETTINGS);
-        verify(mWificondControl).startPnoScan(TEST_PNO_SETTINGS);
+        verify(mWificondControl).startPnoScan(
+                WIFI_IFACE_NAME, TEST_PNO_SETTINGS);
     }
 
     /**
@@ -711,7 +715,7 @@
     @Test
     public void testStopPnoScan() throws Exception {
         mWifiNative.stopPnoScan();
-        verify(mWificondControl).stopPnoScan();
+        verify(mWificondControl).stopPnoScan(WIFI_IFACE_NAME);
     }
 
     /**
@@ -722,8 +726,8 @@
         WifiConfiguration config = mock(WifiConfiguration.class);
         mWifiNative.connectToNetwork(config);
         // connectToNetwork() should abort ongoing scan before connection.
-        verify(mWificondControl).abortScan();
-        verify(mStaIfaceHal).connectToNetwork(config);
+        verify(mWificondControl).abortScan(WIFI_IFACE_NAME);
+        verify(mStaIfaceHal).connectToNetwork(WIFI_IFACE_NAME, config);
     }
 
     /**
@@ -734,8 +738,7 @@
         WifiConfiguration config = mock(WifiConfiguration.class);
         mWifiNative.roamToNetwork(config);
         // roamToNetwork() should abort ongoing scan before connection.
-        verify(mWificondControl).abortScan();
-        verify(mStaIfaceHal).roamToNetwork(config);
+        verify(mWificondControl).abortScan(WIFI_IFACE_NAME);
+        verify(mStaIfaceHal).roamToNetwork(WIFI_IFACE_NAME, config);
     }
-
 }
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
index fe2ede7..ea81d53 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
@@ -64,6 +64,8 @@
 import android.net.wifi.WifiEnterpriseConfig;
 import android.net.wifi.WifiManager;
 import android.net.wifi.WifiManager.LocalOnlyHotspotCallback;
+import android.net.wifi.hotspot2.IProvisioningCallback;
+import android.net.wifi.hotspot2.OsuProvider;
 import android.net.wifi.hotspot2.PasspointConfiguration;
 import android.os.Handler;
 import android.os.HandlerThread;
@@ -83,10 +85,10 @@
 
 import com.android.internal.util.AsyncChannel;
 import com.android.server.wifi.WifiServiceImpl.LocalOnlyRequestorCallback;
+import com.android.server.wifi.hotspot2.PasspointProvisioningTestUtil;
 import com.android.server.wifi.util.WifiAsyncChannel;
 import com.android.server.wifi.util.WifiPermissionsUtil;
 
-
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.ArgumentCaptor;
@@ -128,6 +130,7 @@
     private Messenger mAppMessenger;
     private int mPid;
     private int mPid2 = Process.myPid();
+    private OsuProvider mOsuProvider;
 
     final ArgumentCaptor<BroadcastReceiver> mBroadcastReceiverCaptor =
             ArgumentCaptor.forClass(BroadcastReceiver.class);
@@ -165,6 +168,7 @@
     @Mock IBinder mAppBinder;
     @Mock LocalOnlyHotspotRequestInfo mRequestInfo;
     @Mock LocalOnlyHotspotRequestInfo mRequestInfo2;
+    @Mock IProvisioningCallback mProvisioningCallback;
 
     @Spy FakeWifiLog mLog;
 
@@ -280,6 +284,12 @@
         when(mWifiInjector.getWifiPermissionsUtil()).thenReturn(mWifiPermissionsUtil);
         when(mWifiInjector.getWifiSettingsStore()).thenReturn(mSettingsStore);
         when(mWifiInjector.getClock()).thenReturn(mClock);
+        when(mWifiStateMachine.syncStartSubscriptionProvisioning(anyInt(),
+                any(OsuProvider.class), any(IProvisioningCallback.class), any())).thenReturn(true);
+        when(mPackageManager.hasSystemFeature(
+                PackageManager.FEATURE_WIFI_PASSPOINT)).thenReturn(true);
+        // Create an OSU provider that can be provisioned via an open OSU AP
+        mOsuProvider = PasspointProvisioningTestUtil.generateOsuProvider(true);
         mWifiServiceImpl = new WifiServiceImpl(mContext, mWifiInjector, mAsyncChannel);
         mWifiServiceImpl.setWifiHandlerLogForTest(mLog);
     }
@@ -1515,6 +1525,60 @@
     }
 
     /**
+     * Verify that the call to startSubscriptionProvisioning is redirected to the Passpoint
+     * specific API startSubscriptionProvisioning when the caller has the right permissions.
+     */
+    @Test
+    public void testStartSubscriptionProvisioningWithPermission() throws Exception {
+        mWifiServiceImpl.startSubscriptionProvisioning(mOsuProvider, mProvisioningCallback);
+        verify(mWifiStateMachine).syncStartSubscriptionProvisioning(anyInt(),
+                eq(mOsuProvider), eq(mProvisioningCallback), any());
+    }
+
+    /**
+     * Verify that the call to startSubscriptionProvisioning is not directed to the Passpoint
+     * specific API startSubscriptionProvisioning when the feature is not supported.
+     */
+    @Test(expected = UnsupportedOperationException.class)
+    public void testStartSubscriptionProvisioniningPasspointUnsupported() throws Exception {
+        when(mPackageManager.hasSystemFeature(
+                PackageManager.FEATURE_WIFI_PASSPOINT)).thenReturn(false);
+        mWifiServiceImpl.startSubscriptionProvisioning(mOsuProvider, mProvisioningCallback);
+    }
+
+    /**
+     * Verify that the call to startSubscriptionProvisioning is not redirected to the Passpoint
+     * specific API startSubscriptionProvisioning when the caller provides invalid arguments
+     */
+    @Test(expected = IllegalArgumentException.class)
+    public void testStartSubscriptionProvisioningWithInvalidProvider() throws Exception {
+        mWifiServiceImpl.startSubscriptionProvisioning(null, mProvisioningCallback);
+    }
+
+
+    /**
+     * Verify that the call to startSubscriptionProvisioning is not redirected to the Passpoint
+     * specific API startSubscriptionProvisioning when the caller provides invalid callback
+     */
+    @Test(expected = IllegalArgumentException.class)
+    public void testStartSubscriptionProvisioningWithInvalidCallback() throws Exception {
+        mWifiServiceImpl.startSubscriptionProvisioning(mOsuProvider, null);
+    }
+
+    /**
+     * Verify that the call to startSubscriptionProvisioning is not redirected to the Passpoint
+     * specific API startSubscriptionProvisioning when the caller doesn't have NETWORK_SETTINGS
+     * permissions.
+     */
+    @Test(expected = SecurityException.class)
+    public void testStartSubscriptionProvisioningWithoutPermission() throws Exception {
+        doThrow(new SecurityException()).when(mContext)
+                .enforceCallingOrSelfPermission(eq(android.Manifest.permission.NETWORK_SETTINGS),
+                        eq("WifiService"));
+        mWifiServiceImpl.startSubscriptionProvisioning(mOsuProvider, mProvisioningCallback);
+    }
+
+    /**
      * Verify that a call to {@link WifiServiceImpl#restoreBackupData(byte[])} is only allowed from
      * callers with the signature only NETWORK_SETTINGS permission.
      */
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
index 94589b0..ad5aa43 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
@@ -63,6 +63,8 @@
 import android.net.wifi.WifiScanner;
 import android.net.wifi.WifiSsid;
 import android.net.wifi.WpsInfo;
+import android.net.wifi.hotspot2.IProvisioningCallback;
+import android.net.wifi.hotspot2.OsuProvider;
 import android.net.wifi.hotspot2.PasspointConfiguration;
 import android.net.wifi.hotspot2.pps.HomeSp;
 import android.net.wifi.p2p.IWifiP2pManager;
@@ -80,7 +82,6 @@
 import android.os.Messenger;
 import android.os.PowerManager;
 import android.os.Process;
-import android.os.RemoteException;
 import android.os.UserHandle;
 import android.os.UserManager;
 import android.os.test.TestLooper;
@@ -102,6 +103,7 @@
 import com.android.internal.util.StateMachine;
 import com.android.server.wifi.hotspot2.NetworkDetail;
 import com.android.server.wifi.hotspot2.PasspointManager;
+import com.android.server.wifi.hotspot2.PasspointProvisioningTestUtil;
 import com.android.server.wifi.p2p.WifiP2pServiceImpl;
 import com.android.server.wifi.util.WifiPermissionsUtil;
 
@@ -334,6 +336,7 @@
     IpClient.Callback mIpClientCallback;
     PhoneStateListener mPhoneStateListener;
     NetworkRequest mDefaultNetworkRequest;
+    OsuProvider mOsuProvider;
 
     final ArgumentCaptor<SoftApManager.Listener> mSoftApManagerListenerCaptor =
                     ArgumentCaptor.forClass(SoftApManager.Listener.class);
@@ -352,8 +355,6 @@
     @Mock IWificond mWificond;
     @Mock IApInterface mApInterface;
     @Mock IClientInterface mClientInterface;
-    @Mock IBinder mApInterfaceBinder;
-    @Mock IBinder mClientInterfaceBinder;
     @Mock IBinder mPackageManagerBinder;
     @Mock WifiConfigManager mWifiConfigManager;
     @Mock WifiNative mWifiNative;
@@ -370,6 +371,8 @@
     @Mock ScanDetailCache mScanDetailCache;
     @Mock BaseWifiDiagnostics mWifiDiagnostics;
     @Mock ConnectivityManager mConnectivityManager;
+    @Mock IProvisioningCallback mProvisioningCallback;
+    @Mock HandlerThread mWifiServiceHandlerThread;
 
     public WifiStateMachineTest() throws Exception {
     }
@@ -413,6 +416,8 @@
         when(mWifiInjector.getWifiPermissionsUtil()).thenReturn(mWifiPermissionsUtil);
         when(mWifiInjector.makeTelephonyManager()).thenReturn(mTelephonyManager);
         when(mWifiInjector.getClock()).thenReturn(mClock);
+        when(mWifiServiceHandlerThread.getLooper()).thenReturn(mLooper.getLooper());
+        when(mWifiInjector.getWifiServiceHandlerThread()).thenReturn(mWifiServiceHandlerThread);
 
         when(mWifiNative.setupForClientMode(WIFI_IFACE_NAME))
                 .thenReturn(Pair.create(WifiNative.SETUP_SUCCESS, mClientInterface));
@@ -423,7 +428,9 @@
         when(mWifiNative.enableSupplicant()).thenReturn(true);
         when(mWifiNative.disableSupplicant()).thenReturn(true);
         when(mWifiNative.getFrameworkNetworkId(anyInt())).thenReturn(0);
-
+        when(mWifiNative.initializeVendorHal(any(WifiNative.VendorHalDeathEventHandler.class)))
+                .thenReturn(true);
+        when(mWifiNative.registerWificondDeathHandler(any())).thenReturn(true);
 
         mFrameworkFacade = getFrameworkFacade();
         mContext = getContext();
@@ -449,9 +456,6 @@
                 new UserInfo(UserHandle.USER_SYSTEM, "owner", 0),
                 new UserInfo(11, "managed profile", 0)));
 
-        when(mApInterface.asBinder()).thenReturn(mApInterfaceBinder);
-        when(mClientInterface.asBinder()).thenReturn(mClientInterfaceBinder);
-
         doAnswer(new AnswerWithArguments() {
             public void answer(PhoneStateListener phoneStateListener, int events)
                     throws Exception {
@@ -461,6 +465,8 @@
 
         when(mWifiPermissionsUtil.checkNetworkSettingsPermission(anyInt())).thenReturn(true);
         initializeWsm();
+
+        mOsuProvider = PasspointProvisioningTestUtil.generateOsuProvider(true);
     }
 
     private void registerAsyncChannel(Consumer<AsyncChannel> consumer, Messenger messenger) {
@@ -644,8 +650,8 @@
         // We start out with valid default values, break them going backwards so that
         // we test all the bailout cases.
 
-        // ClientInterface dies after creation.
-        doThrow(new RemoteException()).when(mClientInterfaceBinder).linkToDeath(any(), anyInt());
+        // wificond dies after inteface creation.
+        when(mWifiNative.registerWificondDeathHandler(any())).thenReturn(false);
         mWsm.setSupplicantRunning(true);
         mLooper.dispatchAll();
         assertEquals("InitialState", getCurrentState().getName());
@@ -1779,6 +1785,57 @@
     }
 
     /**
+     * Verify that syncStartSubscriptionProvisioning will redirect calls with right parameters
+     * to {@link PasspointManager} with expected true being returned when in client mode.
+     */
+    @Test
+    public void syncStartSubscriptionProvisioningInClientMode() throws Exception {
+        mLooper.startAutoDispatch();
+        mWsm.syncInitialize(mWsmAsyncChannel);
+        verify(mPasspointManager).initializeProvisioner(any(Looper.class));
+        mLooper.stopAutoDispatch();
+
+        loadComponentsInStaMode();
+        when(mPasspointManager.startSubscriptionProvisioning(anyInt(),
+                any(OsuProvider.class), any(IProvisioningCallback.class))).thenReturn(true);
+        mLooper.startAutoDispatch();
+        assertEquals(true, mWsm.syncStartSubscriptionProvisioning(
+                OTHER_USER_UID, mOsuProvider, mProvisioningCallback, mWsmAsyncChannel));
+        verify(mPasspointManager).startSubscriptionProvisioning(OTHER_USER_UID, mOsuProvider,
+                mProvisioningCallback);
+        mLooper.stopAutoDispatch();
+    }
+
+    /**
+     * Verify that syncStartSubscriptionProvisioning will be a no-op and return false before
+     * SUPPLICANT_START command is received by the WSM.
+     */
+    @Test
+    public void syncStartSubscriptionProvisioningBeforeSupplicantOrAPStart() throws Exception {
+        mLooper.startAutoDispatch();
+        assertEquals(false, mWsm.syncStartSubscriptionProvisioning(
+                OTHER_USER_UID, mOsuProvider, mProvisioningCallback, mWsmAsyncChannel));
+        mLooper.stopAutoDispatch();
+        verify(mPasspointManager, never()).startSubscriptionProvisioning(
+                anyInt(), any(OsuProvider.class), any(IProvisioningCallback.class));
+    }
+
+    /**
+     * Verify that syncStartSubscriptionProvisioning will be a no-op and return false when not in
+     * client mode.
+     */
+    @Test
+    public void syncStartSubscriptionProvisioningInAPMode() throws Exception {
+        loadComponentsInApMode(WifiManager.IFACE_IP_MODE_LOCAL_ONLY);
+        mLooper.startAutoDispatch();
+        assertEquals(false, mWsm.syncStartSubscriptionProvisioning(
+                OTHER_USER_UID, mOsuProvider, mProvisioningCallback, mWsmAsyncChannel));
+        mLooper.stopAutoDispatch();
+        verify(mPasspointManager, never()).startSubscriptionProvisioning(
+                anyInt(), any(OsuProvider.class), any(IProvisioningCallback.class));
+    }
+
+    /**
      *  Test that we disconnect from a network if it was removed while we are in the
      *  ObtainingIpState.
      */
@@ -2058,20 +2115,19 @@
 
     @Test
     public void handleWificondDeath() throws Exception {
-        ArgumentCaptor<StateMachineDeathRecipient> deathHandlerCapturer =
-                ArgumentCaptor.forClass(StateMachineDeathRecipient.class);
+        ArgumentCaptor<WifiNative.WificondDeathEventHandler> deathHandlerCapturer =
+                ArgumentCaptor.forClass(WifiNative.WificondDeathEventHandler.class);
 
         // Trigger initialize to capture the death handler registration.
         loadComponentsInStaMode();
 
-        verify(mClientInterfaceBinder).linkToDeath(deathHandlerCapturer.capture(), anyInt());
-        StateMachineDeathRecipient deathHandler = deathHandlerCapturer.getValue();
+        verify(mWifiNative).registerWificondDeathHandler(deathHandlerCapturer.capture());
 
         mWsm.setOperationalMode(WifiStateMachine.CONNECT_MODE);
         mLooper.dispatchAll();
 
         // Now trigger the death notification.
-        deathHandler.binderDied();
+        deathHandlerCapturer.getValue().onDeath();
         mLooper.dispatchAll();
 
         verify(mWifiMetrics).incrementNumWificondCrashes();
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java b/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java
index aa2318e..af8bda4 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java
@@ -111,6 +111,7 @@
  */
 public class WifiVendorHalTest {
 
+    private static final String TEST_IFACE_NAME = "wlan0";
     WifiVendorHal mWifiVendorHal;
     private WifiStatus mWifiStatusSuccess;
     private WifiStatus mWifiStatusFailure;
@@ -195,6 +196,7 @@
                 .thenReturn(mIWifiStaIface);
         when(mHalDeviceManager.createApIface(eq(null), eq(null)))
                 .thenReturn(mIWifiApIface);
+        when(mHalDeviceManager.removeIface(any())).thenReturn(true);
         when(mHalDeviceManager.getChip(any(IWifiIface.class)))
                 .thenReturn(mIWifiChip);
         when(mHalDeviceManager.createRttController()).thenReturn(mIWifiRttController);
@@ -218,6 +220,19 @@
         when(mIWifiRttController.registerEventCallback(any(IWifiRttControllerEventCallback.class)))
                 .thenReturn(mWifiStatusSuccess);
 
+        doAnswer(new AnswerWithArguments() {
+            public void answer(IWifiIface.getNameCallback cb)
+                    throws RemoteException {
+                cb.onValues(mWifiStatusSuccess, TEST_IFACE_NAME);
+            }
+        }).when(mIWifiStaIface).getName(any(IWifiIface.getNameCallback.class));
+        doAnswer(new AnswerWithArguments() {
+            public void answer(IWifiIface.getNameCallback cb)
+                    throws RemoteException {
+                cb.onValues(mWifiStatusSuccess, TEST_IFACE_NAME);
+            }
+        }).when(mIWifiApIface).getName(any(IWifiIface.getNameCallback.class));
+
         // Create the vendor HAL object under test.
         mWifiVendorHal = new WifiVendorHal(mHalDeviceManager, mLooper.getLooper());
 
@@ -233,11 +248,11 @@
 
     /**
      * Tests the successful starting of HAL in STA mode using
-     * {@link WifiVendorHal#startVendorHal(boolean)}.
+     * {@link WifiVendorHal#startVendorHalSta()}.
      */
     @Test
     public void testStartHalSuccessInStaMode() throws  Exception {
-        assertTrue(mWifiVendorHal.startVendorHal(true));
+        assertTrue(mWifiVendorHal.startVendorHalSta());
         assertTrue(mWifiVendorHal.isHalStarted());
 
         verify(mHalDeviceManager).start();
@@ -254,11 +269,11 @@
 
     /**
      * Tests the successful starting of HAL in AP mode using
-     * {@link WifiVendorHal#startVendorHal(boolean)}.
+     * {@link WifiVendorHal#startVendorHalAp()}.
      */
     @Test
     public void testStartHalSuccessInApMode() throws Exception {
-        assertTrue(mWifiVendorHal.startVendorHal(false));
+        assertTrue(mWifiVendorHal.startVendorHalAp());
         assertTrue(mWifiVendorHal.isHalStarted());
 
         verify(mHalDeviceManager).start();
@@ -273,7 +288,7 @@
 
     /**
      * Tests the failure to start HAL in STA mode using
-     * {@link WifiVendorHal#startVendorHal(boolean)}.
+     * {@link WifiVendorHal#startVendorHalSta()}.
      */
     @Test
     public void testStartHalFailureInStaMode() throws Exception {
@@ -284,7 +299,7 @@
                 return false;
             }
         }).when(mHalDeviceManager).start();
-        assertFalse(mWifiVendorHal.startVendorHal(true));
+        assertFalse(mWifiVendorHal.startVendorHalSta());
         assertFalse(mWifiVendorHal.isHalStarted());
 
         verify(mHalDeviceManager).start();
@@ -299,12 +314,12 @@
 
     /**
      * Tests the failure to start HAL in STA mode using
-     * {@link WifiVendorHal#startVendorHal(boolean)}.
+     * {@link WifiVendorHal#startVendorHalSta()}.
      */
     @Test
     public void testStartHalFailureInIfaceCreationInStaMode() throws Exception {
         when(mHalDeviceManager.createStaIface(eq(null), eq(null))).thenReturn(null);
-        assertFalse(mWifiVendorHal.startVendorHal(true));
+        assertFalse(mWifiVendorHal.startVendorHalSta());
         assertFalse(mWifiVendorHal.isHalStarted());
 
         verify(mHalDeviceManager).start();
@@ -320,12 +335,12 @@
 
     /**
      * Tests the failure to start HAL in STA mode using
-     * {@link WifiVendorHal#startVendorHal(boolean)}.
+     * {@link WifiVendorHal#startVendorHalSta()}.
      */
     @Test
     public void testStartHalFailureInRttControllerCreationInStaMode() throws Exception {
         when(mHalDeviceManager.createRttController()).thenReturn(null);
-        assertFalse(mWifiVendorHal.startVendorHal(true));
+        assertFalse(mWifiVendorHal.startVendorHalSta());
         assertFalse(mWifiVendorHal.isHalStarted());
 
         verify(mHalDeviceManager).start();
@@ -340,12 +355,12 @@
 
     /**
      * Tests the failure to start HAL in STA mode using
-     * {@link WifiVendorHal#startVendorHal(boolean)}.
+     * {@link WifiVendorHal#startVendorHalSta()}.
      */
     @Test
     public void testStartHalFailureInChipGetInStaMode() throws Exception {
         when(mHalDeviceManager.getChip(any(IWifiIface.class))).thenReturn(null);
-        assertFalse(mWifiVendorHal.startVendorHal(true));
+        assertFalse(mWifiVendorHal.startVendorHalSta());
         assertFalse(mWifiVendorHal.isHalStarted());
 
         verify(mHalDeviceManager).start();
@@ -360,13 +375,13 @@
 
     /**
      * Tests the failure to start HAL in STA mode using
-     * {@link WifiVendorHal#startVendorHal(boolean)}.
+     * {@link WifiVendorHal#startVendorHalSta()}.
      */
     @Test
     public void testStartHalFailureInStaIfaceCallbackRegistration() throws Exception {
         when(mIWifiStaIface.registerEventCallback(any(IWifiStaIfaceEventCallback.class)))
                 .thenReturn(mWifiStatusFailure);
-        assertFalse(mWifiVendorHal.startVendorHal(true));
+        assertFalse(mWifiVendorHal.startVendorHalSta());
         assertFalse(mWifiVendorHal.isHalStarted());
 
         verify(mHalDeviceManager).start();
@@ -381,13 +396,13 @@
 
     /**
      * Tests the failure to start HAL in STA mode using
-     * {@link WifiVendorHal#startVendorHal(boolean)}.
+     * {@link WifiVendorHal#startVendorHalSta()}.
      */
     @Test
     public void testStartHalFailureInChipCallbackRegistration() throws Exception {
         when(mIWifiChip.registerEventCallback(any(IWifiChipEventCallback.class)))
                 .thenReturn(mWifiStatusFailure);
-        assertFalse(mWifiVendorHal.startVendorHal(true));
+        assertFalse(mWifiVendorHal.startVendorHalSta());
         assertFalse(mWifiVendorHal.isHalStarted());
 
         verify(mHalDeviceManager).start();
@@ -402,13 +417,13 @@
     }
 
     /**
-     * Tests the failure to start HAL in STA mode using
-     * {@link WifiVendorHal#startVendorHal(boolean)}.
+     * Tests the failure to start HAL in AP mode using
+     * {@link WifiVendorHal#startVendorHalAp()}.
      */
     @Test
     public void testStartHalFailureInApMode() throws Exception {
         when(mHalDeviceManager.createApIface(eq(null), eq(null))).thenReturn(null);
-        assertFalse(mWifiVendorHal.startVendorHal(false));
+        assertFalse(mWifiVendorHal.startVendorHalAp());
         assertFalse(mWifiVendorHal.isHalStarted());
 
         verify(mHalDeviceManager).start();
@@ -426,7 +441,7 @@
      */
     @Test
     public void testStopHalInStaMode() {
-        assertTrue(mWifiVendorHal.startVendorHal(true));
+        assertTrue(mWifiVendorHal.startVendorHalSta());
         assertTrue(mWifiVendorHal.isHalStarted());
 
         mWifiVendorHal.stopVendorHal();
@@ -449,7 +464,7 @@
      */
     @Test
     public void testStopHalInApMode() {
-        assertTrue(mWifiVendorHal.startVendorHal(false));
+        assertTrue(mWifiVendorHal.startVendorHalAp());
         assertTrue(mWifiVendorHal.isHalStarted());
 
         mWifiVendorHal.stopVendorHal();
@@ -473,7 +488,7 @@
     public void testEnterLogging() {
         mWifiVendorHal.mLog = spy(mWifiLog);
         mWifiVendorHal.enableVerboseLogging(true);
-        mWifiVendorHal.installPacketFilter(new byte[0]);
+        mWifiVendorHal.installPacketFilter(TEST_IFACE_NAME, new byte[0]);
         verify(mWifiVendorHal.mLog).trace(eq("% filter length %"));
     }
 
@@ -483,10 +498,10 @@
     @Test
     public void testEnterSilenceWhenNotEnabled() {
         mWifiVendorHal.mLog = spy(mWifiLog);
-        mWifiVendorHal.installPacketFilter(new byte[0]);
+        mWifiVendorHal.installPacketFilter(TEST_IFACE_NAME, new byte[0]);
         mWifiVendorHal.enableVerboseLogging(true);
         mWifiVendorHal.enableVerboseLogging(false);
-        mWifiVendorHal.installPacketFilter(new byte[0]);
+        mWifiVendorHal.installPacketFilter(TEST_IFACE_NAME, new byte[0]);
         verify(mWifiVendorHal.mLog, never()).trace(eq("% filter length %"));
     }
 
@@ -498,7 +513,8 @@
         mWifiLog = spy(mWifiLog);
         mWifiVendorHal.mLog = mWifiLog;
         mWifiVendorHal.mVerboseLog = mWifiLog;
-        assertFalse(mWifiVendorHal.getBgScanCapabilities(new WifiNative.ScanCapabilities()));
+        assertFalse(mWifiVendorHal.getBgScanCapabilities(
+                TEST_IFACE_NAME, new WifiNative.ScanCapabilities()));
         verify(mWifiLog).err("% returns %");
     }
 
@@ -527,9 +543,12 @@
 
         WifiNative.ScanCapabilities result = new WifiNative.ScanCapabilities();
 
-        assertFalse(mWifiVendorHal.getBgScanCapabilities(result));  // should fail - not started
-        assertTrue(mWifiVendorHal.startVendorHalSta());           // Start the vendor hal
-        assertTrue(mWifiVendorHal.getBgScanCapabilities(result));   // should succeed
+        // should fail - not started
+        assertFalse(mWifiVendorHal.getBgScanCapabilities(TEST_IFACE_NAME, result));
+        // Start the vendor hal
+        assertTrue(mWifiVendorHal.startVendorHalSta());
+        // should succeed
+        assertTrue(mWifiVendorHal.getBgScanCapabilities(TEST_IFACE_NAME, result));
 
         assertEquals(12, result.max_scan_cache_size);
         assertEquals(34, result.max_scan_buckets);
@@ -583,7 +602,7 @@
      */
     @Test
     public void testGetSupportedFeatures() throws Exception {
-        assertTrue(mWifiVendorHal.startVendorHal(true));
+        assertTrue(mWifiVendorHal.startVendorHalSta());
 
         int staIfaceHidlCaps = (
                 IWifiStaIface.StaIfaceCapabilityMask.BACKGROUND_SCAN
@@ -616,7 +635,7 @@
         when(mHalDeviceManager.getSupportedIfaceTypes())
                 .thenReturn(halDeviceManagerSupportedIfaces);
 
-        assertEquals(expectedFeatureSet, mWifiVendorHal.getSupportedFeatureSet());
+        assertEquals(expectedFeatureSet, mWifiVendorHal.getSupportedFeatureSet(TEST_IFACE_NAME));
     }
 
     /**
@@ -633,13 +652,13 @@
     public void testLinkLayerStatsEnableAfterStartup() throws Exception {
         doNothing().when(mIWifiStaIface).getLinkLayerStats(any());
 
-        assertNull(mWifiVendorHal.getWifiLinkLayerStats());
+        assertNull(mWifiVendorHal.getWifiLinkLayerStats(TEST_IFACE_NAME));
         assertTrue(mWifiVendorHal.startVendorHalSta());
         assertTrue(mWifiVendorHal.isHalStarted());
 
         verify(mHalDeviceManager).start();
-        mWifiVendorHal.getWifiLinkLayerStats();
-        mWifiVendorHal.getWifiLinkLayerStats();
+        mWifiVendorHal.getWifiLinkLayerStats(TEST_IFACE_NAME);
+        mWifiVendorHal.getWifiLinkLayerStats(TEST_IFACE_NAME);
         verify(mIWifiStaIface).enableLinkLayerStatsCollection(false); // mLinkLayerStatsDebug
         verify(mIWifiStaIface, times(2)).getLinkLayerStats(any());
     }
@@ -658,7 +677,7 @@
 
         assertTrue(mWifiVendorHal.startVendorHalAp());
         assertTrue(mWifiVendorHal.isHalStarted());
-        assertNull(mWifiVendorHal.getWifiLinkLayerStats());
+        assertNull(mWifiVendorHal.getWifiLinkLayerStats(TEST_IFACE_NAME));
 
         verify(mHalDeviceManager).start();
 
@@ -947,12 +966,15 @@
 
         when(mIWifiStaIface.setScanningMacOui(any())).thenReturn(mWifiStatusSuccess);
 
-        assertFalse(mWifiVendorHal.setScanningMacOui(oui)); // expect fail - STA not started
+        // expect fail - STA not started
+        assertFalse(mWifiVendorHal.setScanningMacOui(TEST_IFACE_NAME, oui));
         assertTrue(mWifiVendorHal.startVendorHalSta());
-        assertFalse(mWifiVendorHal.setScanningMacOui(null));  // expect fail - null
-        assertFalse(mWifiVendorHal.setScanningMacOui(new byte[]{(byte) 1})); // expect fail - len
-        assertTrue(mWifiVendorHal.setScanningMacOui(oui));
-        assertTrue(mWifiVendorHal.setScanningMacOui(zzz));
+        // expect fail - null
+        assertFalse(mWifiVendorHal.setScanningMacOui(TEST_IFACE_NAME, null));
+        // expect fail - len
+        assertFalse(mWifiVendorHal.setScanningMacOui(TEST_IFACE_NAME, new byte[]{(byte) 1}));
+        assertTrue(mWifiVendorHal.setScanningMacOui(TEST_IFACE_NAME, oui));
+        assertTrue(mWifiVendorHal.setScanningMacOui(TEST_IFACE_NAME, zzz));
 
         verify(mIWifiStaIface).setScanningMacOui(eq(oui));
         verify(mIWifiStaIface).setScanningMacOui(eq(zzz));
@@ -973,7 +995,8 @@
         )).thenReturn(mWifiStatusSuccess);
 
         assertTrue(mWifiVendorHal.startVendorHalSta());
-        assertTrue(0 == mWifiVendorHal.startSendingOffloadedPacket(slot, srcMac, kap, millis));
+        assertTrue(0 == mWifiVendorHal.startSendingOffloadedPacket(
+                TEST_IFACE_NAME, slot, srcMac, kap, millis));
 
         verify(mIWifiStaIface).startSendingKeepAlivePackets(
                 eq(slot), any(), anyShort(), any(), any(), eq(millis));
@@ -986,7 +1009,8 @@
         when(mIWifiStaIface.stopSendingKeepAlivePackets(anyInt())).thenReturn(mWifiStatusSuccess);
 
         assertTrue(mWifiVendorHal.startVendorHalSta());
-        assertTrue(0 == mWifiVendorHal.stopSendingOffloadedPacket(slot));
+        assertTrue(0 == mWifiVendorHal.stopSendingOffloadedPacket(
+                TEST_IFACE_NAME, slot));
 
         verify(mIWifiStaIface).stopSendingKeepAlivePackets(eq(slot));
     }
@@ -1011,20 +1035,26 @@
         handler = ((cur) -> {
             breach.add(cur);
         });
-        assertEquals(-1, mWifiVendorHal.startRssiMonitoring(hi, lo, handler)); // not started
-        assertEquals(-1, mWifiVendorHal.stopRssiMonitoring()); // not started
+        // not started
+        assertEquals(-1, mWifiVendorHal.startRssiMonitoring(TEST_IFACE_NAME, hi, lo, handler));
+        // not started
+        assertEquals(-1, mWifiVendorHal.stopRssiMonitoring(TEST_IFACE_NAME));
         assertTrue(mWifiVendorHal.startVendorHalSta());
-        assertEquals(0, mWifiVendorHal.startRssiMonitoring(hi, lo, handler));
+        assertEquals(0, mWifiVendorHal.startRssiMonitoring(TEST_IFACE_NAME, hi, lo, handler));
         int theCmdId = mWifiVendorHal.sRssiMonCmdId;
         breach.clear();
         mIWifiStaIfaceEventCallback.onRssiThresholdBreached(theCmdId, new byte[6], lower);
         assertEquals(breach.get(0), lower);
-        assertEquals(0, mWifiVendorHal.stopRssiMonitoring());
-        assertEquals(0, mWifiVendorHal.startRssiMonitoring(hi, lo, handler));
-        assertEquals(0, mWifiVendorHal.startRssiMonitoring(med, lo, handler)); // replacing works
-        assertEquals(-1, mWifiVendorHal.startRssiMonitoring(hi, lo, null)); // null handler fails
-        assertEquals(0, mWifiVendorHal.startRssiMonitoring(hi, lo, handler));
-        assertEquals(-1, mWifiVendorHal.startRssiMonitoring(lo, hi, handler)); // empty range
+        assertEquals(0, mWifiVendorHal.stopRssiMonitoring(TEST_IFACE_NAME));
+        assertEquals(0, mWifiVendorHal.startRssiMonitoring(TEST_IFACE_NAME, hi, lo, handler));
+        // replacing works
+        assertEquals(0, mWifiVendorHal.startRssiMonitoring(TEST_IFACE_NAME, med, lo, handler));
+        // null handler fails
+        assertEquals(-1, mWifiVendorHal.startRssiMonitoring(
+                TEST_IFACE_NAME, hi, lo, null));
+        assertEquals(0, mWifiVendorHal.startRssiMonitoring(TEST_IFACE_NAME, hi, lo, handler));
+        // empty range
+        assertEquals(-1, mWifiVendorHal.startRssiMonitoring(TEST_IFACE_NAME, lo, hi, handler));
     }
 
     /**
@@ -1052,11 +1082,12 @@
                 IWifiStaIface.getApfPacketFilterCapabilitiesCallback.class));
 
 
-        assertEquals(0, mWifiVendorHal.getApfCapabilities().apfVersionSupported);
+        assertEquals(0, mWifiVendorHal.getApfCapabilities(TEST_IFACE_NAME)
+                .apfVersionSupported);
 
         assertTrue(mWifiVendorHal.startVendorHalSta());
 
-        ApfCapabilities actual = mWifiVendorHal.getApfCapabilities();
+        ApfCapabilities actual = mWifiVendorHal.getApfCapabilities(TEST_IFACE_NAME);
 
         assertEquals(myVersion, actual.apfVersionSupported);
         assertEquals(myMaxSize, actual.maximumApfProgramSize);
@@ -1078,7 +1109,7 @@
                 .thenReturn(mWifiStatusSuccess);
 
         assertTrue(mWifiVendorHal.startVendorHalSta());
-        assertTrue(mWifiVendorHal.installPacketFilter(filter));
+        assertTrue(mWifiVendorHal.installPacketFilter(TEST_IFACE_NAME, filter));
 
         verify(mIWifiStaIface).installApfPacketFilter(eq(0), eq(expected));
     }
@@ -1095,11 +1126,12 @@
 
         assertTrue(mWifiVendorHal.startVendorHalAp());
 
-        assertFalse(mWifiVendorHal.setCountryCodeHal(null));
-        assertFalse(mWifiVendorHal.setCountryCodeHal(""));
-        assertFalse(mWifiVendorHal.setCountryCodeHal("A"));
-        assertTrue(mWifiVendorHal.setCountryCodeHal("CA")); // Only one expected to succeed
-        assertFalse(mWifiVendorHal.setCountryCodeHal("ZZZ"));
+        assertFalse(mWifiVendorHal.setCountryCodeHal(TEST_IFACE_NAME, null));
+        assertFalse(mWifiVendorHal.setCountryCodeHal(TEST_IFACE_NAME, ""));
+        assertFalse(mWifiVendorHal.setCountryCodeHal(TEST_IFACE_NAME, "A"));
+        // Only one expected to succeed
+        assertTrue(mWifiVendorHal.setCountryCodeHal(TEST_IFACE_NAME, "CA"));
+        assertFalse(mWifiVendorHal.setCountryCodeHal(TEST_IFACE_NAME, "ZZZ"));
 
         verify(mIWifiApIface).setCountryCode(eq(expected));
     }
@@ -1114,7 +1146,7 @@
         when(mIWifiApIface.setCountryCode(any()))
                 .thenThrow(new RemoteException("oops"));
         assertTrue(mWifiVendorHal.startVendorHalAp());
-        assertFalse(mWifiVendorHal.setCountryCodeHal("CA"));
+        assertFalse(mWifiVendorHal.setCountryCodeHal(TEST_IFACE_NAME, "CA"));
         assertFalse(mWifiVendorHal.isHalStarted());
         verify(mWifiLog).err(any());
     }
@@ -1231,11 +1263,11 @@
     public void testStartPktFateMonitoring() throws Exception {
         when(mIWifiStaIface.startDebugPacketFateMonitoring()).thenReturn(mWifiStatusSuccess);
 
-        assertFalse(mWifiVendorHal.startPktFateMonitoring());
+        assertFalse(mWifiVendorHal.startPktFateMonitoring(TEST_IFACE_NAME));
         verify(mIWifiStaIface, never()).startDebugPacketFateMonitoring();
 
         assertTrue(mWifiVendorHal.startVendorHalSta());
-        assertTrue(mWifiVendorHal.startPktFateMonitoring());
+        assertTrue(mWifiVendorHal.startPktFateMonitoring(TEST_IFACE_NAME));
         verify(mIWifiStaIface).startDebugPacketFateMonitoring();
     }
 
@@ -1264,13 +1296,13 @@
                 .getDebugTxPacketFates(any(IWifiStaIface.getDebugTxPacketFatesCallback.class));
 
         WifiNative.TxFateReport[] retrievedFates = new WifiNative.TxFateReport[1];
-        assertFalse(mWifiVendorHal.getTxPktFates(retrievedFates));
+        assertFalse(mWifiVendorHal.getTxPktFates(TEST_IFACE_NAME, retrievedFates));
         verify(mIWifiStaIface, never())
                 .getDebugTxPacketFates(any(IWifiStaIface.getDebugTxPacketFatesCallback.class));
 
         assertTrue(mWifiVendorHal.startVendorHalSta());
 
-        assertTrue(mWifiVendorHal.getTxPktFates(retrievedFates));
+        assertTrue(mWifiVendorHal.getTxPktFates(TEST_IFACE_NAME, retrievedFates));
         verify(mIWifiStaIface)
                 .getDebugTxPacketFates(any(IWifiStaIface.getDebugTxPacketFatesCallback.class));
         assertEquals(WifiLoggerHal.TX_PKT_FATE_DRV_QUEUED, retrievedFates[0].mFate);
@@ -1307,13 +1339,13 @@
                 .getDebugTxPacketFates(any(IWifiStaIface.getDebugTxPacketFatesCallback.class));
 
         WifiNative.TxFateReport[] retrievedFates = new WifiNative.TxFateReport[1];
-        assertFalse(mWifiVendorHal.getTxPktFates(retrievedFates));
+        assertFalse(mWifiVendorHal.getTxPktFates(TEST_IFACE_NAME, retrievedFates));
         verify(mIWifiStaIface, never())
                 .getDebugTxPacketFates(any(IWifiStaIface.getDebugTxPacketFatesCallback.class));
 
         assertTrue(mWifiVendorHal.startVendorHalSta());
 
-        assertTrue(mWifiVendorHal.getTxPktFates(retrievedFates));
+        assertTrue(mWifiVendorHal.getTxPktFates(TEST_IFACE_NAME, retrievedFates));
         verify(mIWifiStaIface)
                 .getDebugTxPacketFates(any(IWifiStaIface.getDebugTxPacketFatesCallback.class));
         assertEquals(WifiLoggerHal.TX_PKT_FATE_FW_DROP_OTHER, retrievedFates[0].mFate);
@@ -1348,13 +1380,13 @@
                 .getDebugRxPacketFates(any(IWifiStaIface.getDebugRxPacketFatesCallback.class));
 
         WifiNative.RxFateReport[] retrievedFates = new WifiNative.RxFateReport[1];
-        assertFalse(mWifiVendorHal.getRxPktFates(retrievedFates));
+        assertFalse(mWifiVendorHal.getRxPktFates(TEST_IFACE_NAME, retrievedFates));
         verify(mIWifiStaIface, never())
                 .getDebugRxPacketFates(any(IWifiStaIface.getDebugRxPacketFatesCallback.class));
 
         assertTrue(mWifiVendorHal.startVendorHalSta());
 
-        assertTrue(mWifiVendorHal.getRxPktFates(retrievedFates));
+        assertTrue(mWifiVendorHal.getRxPktFates(TEST_IFACE_NAME, retrievedFates));
         verify(mIWifiStaIface)
                 .getDebugRxPacketFates(any(IWifiStaIface.getDebugRxPacketFatesCallback.class));
         assertEquals(WifiLoggerHal.RX_PKT_FATE_SUCCESS, retrievedFates[0].mFate);
@@ -1391,13 +1423,13 @@
                 .getDebugRxPacketFates(any(IWifiStaIface.getDebugRxPacketFatesCallback.class));
 
         WifiNative.RxFateReport[] retrievedFates = new WifiNative.RxFateReport[1];
-        assertFalse(mWifiVendorHal.getRxPktFates(retrievedFates));
+        assertFalse(mWifiVendorHal.getRxPktFates(TEST_IFACE_NAME, retrievedFates));
         verify(mIWifiStaIface, never())
                 .getDebugRxPacketFates(any(IWifiStaIface.getDebugRxPacketFatesCallback.class));
 
         assertTrue(mWifiVendorHal.startVendorHalSta());
 
-        assertTrue(mWifiVendorHal.getRxPktFates(retrievedFates));
+        assertTrue(mWifiVendorHal.getRxPktFates(TEST_IFACE_NAME, retrievedFates));
         verify(mIWifiStaIface)
                 .getDebugRxPacketFates(any(IWifiStaIface.getDebugRxPacketFatesCallback.class));
         assertEquals(WifiLoggerHal.RX_PKT_FATE_FW_DROP_FILTER, retrievedFates[0].mFate);
@@ -1413,7 +1445,7 @@
     @Test
     public void testGetTxPktFatesEmptyInputArray() throws Exception {
         assertTrue(mWifiVendorHal.startVendorHalSta());
-        assertFalse(mWifiVendorHal.getTxPktFates(new WifiNative.TxFateReport[0]));
+        assertFalse(mWifiVendorHal.getTxPktFates(TEST_IFACE_NAME, new WifiNative.TxFateReport[0]));
         verify(mIWifiStaIface, never())
                 .getDebugTxPacketFates(any(IWifiStaIface.getDebugTxPacketFatesCallback.class));
     }
@@ -1424,7 +1456,7 @@
     @Test
     public void testGetRxPktFatesEmptyInputArray() throws Exception {
         assertTrue(mWifiVendorHal.startVendorHalSta());
-        assertFalse(mWifiVendorHal.getRxPktFates(new WifiNative.RxFateReport[0]));
+        assertFalse(mWifiVendorHal.getRxPktFates(TEST_IFACE_NAME, new WifiNative.RxFateReport[0]));
         verify(mIWifiStaIface, never())
                 .getDebugRxPacketFates(any(IWifiStaIface.getDebugRxPacketFatesCallback.class));
     }
@@ -1436,14 +1468,14 @@
     public void testEnableDisableNdOffload() throws Exception {
         when(mIWifiStaIface.enableNdOffload(anyBoolean())).thenReturn(mWifiStatusSuccess);
 
-        assertFalse(mWifiVendorHal.configureNeighborDiscoveryOffload(true));
+        assertFalse(mWifiVendorHal.configureNeighborDiscoveryOffload(TEST_IFACE_NAME, true));
         verify(mIWifiStaIface, never()).enableNdOffload(anyBoolean());
 
         assertTrue(mWifiVendorHal.startVendorHalSta());
 
-        assertTrue(mWifiVendorHal.configureNeighborDiscoveryOffload(true));
+        assertTrue(mWifiVendorHal.configureNeighborDiscoveryOffload(TEST_IFACE_NAME, true));
         verify(mIWifiStaIface).enableNdOffload(eq(true));
-        assertTrue(mWifiVendorHal.configureNeighborDiscoveryOffload(false));
+        assertTrue(mWifiVendorHal.configureNeighborDiscoveryOffload(TEST_IFACE_NAME, false));
         verify(mIWifiStaIface).enableNdOffload(eq(false));
     }
 
@@ -1456,7 +1488,7 @@
 
         assertTrue(mWifiVendorHal.startVendorHalSta());
 
-        assertFalse(mWifiVendorHal.configureNeighborDiscoveryOffload(true));
+        assertFalse(mWifiVendorHal.configureNeighborDiscoveryOffload(TEST_IFACE_NAME, true));
         verify(mIWifiStaIface).enableNdOffload(eq(true));
     }
 
@@ -1672,8 +1704,8 @@
 
         int cmdId = mWifiVendorHal.mScan.cmdId;
 
-        mWifiVendorHal.stopBgScan();
-        mWifiVendorHal.stopBgScan(); // second call should not do anything
+        mWifiVendorHal.stopBgScan(TEST_IFACE_NAME);
+        mWifiVendorHal.stopBgScan(TEST_IFACE_NAME); // second call should not do anything
         verify(mIWifiStaIface).stopBackgroundScan(cmdId); // Should be called just once
     }
 
@@ -1690,8 +1722,8 @@
 
         int cmdId = mWifiVendorHal.mScan.cmdId;
 
-        mWifiVendorHal.pauseBgScan();
-        mWifiVendorHal.restartBgScan();
+        mWifiVendorHal.pauseBgScan(TEST_IFACE_NAME);
+        mWifiVendorHal.restartBgScan(TEST_IFACE_NAME);
         verify(mIWifiStaIface).stopBackgroundScan(cmdId); // Should be called just once
         verify(mIWifiStaIface, times(2)).startBackgroundScan(eq(cmdId), any());
     }
@@ -1854,7 +1886,7 @@
      */
     @Test
     public void testSelectTxPowerScenario() throws RemoteException {
-        assertTrue(mWifiVendorHal.startVendorHal(true));
+        assertTrue(mWifiVendorHal.startVendorHalSta());
         // Should fail because we exposed the 1.0 IWifiChip.
         assertFalse(
                 mWifiVendorHal.selectTxPowerScenario(WifiNative.TX_POWER_SCENARIO_VOICE_CALL));
@@ -1865,7 +1897,7 @@
         mWifiVendorHal = new WifiVendorHalSpyV1_1(mHalDeviceManager, mLooper.getLooper());
         when(mIWifiChipV11.selectTxPowerScenario(anyInt())).thenReturn(mWifiStatusSuccess);
 
-        assertTrue(mWifiVendorHal.startVendorHal(true));
+        assertTrue(mWifiVendorHal.startVendorHalSta());
         assertTrue(
                 mWifiVendorHal.selectTxPowerScenario(WifiNative.TX_POWER_SCENARIO_VOICE_CALL));
         verify(mIWifiChipV11).selectTxPowerScenario(
@@ -1880,7 +1912,7 @@
      */
     @Test
     public void testResetTxPowerScenario() throws RemoteException {
-        assertTrue(mWifiVendorHal.startVendorHal(true));
+        assertTrue(mWifiVendorHal.startVendorHalSta());
         // Should fail because we exposed the 1.0 IWifiChip.
         assertFalse(mWifiVendorHal.selectTxPowerScenario(WifiNative.TX_POWER_SCENARIO_NORMAL));
         verify(mIWifiChipV11, never()).resetTxPowerScenario();
@@ -1890,7 +1922,7 @@
         mWifiVendorHal = new WifiVendorHalSpyV1_1(mHalDeviceManager, mLooper.getLooper());
         when(mIWifiChipV11.resetTxPowerScenario()).thenReturn(mWifiStatusSuccess);
 
-        assertTrue(mWifiVendorHal.startVendorHal(true));
+        assertTrue(mWifiVendorHal.startVendorHalSta());
         assertTrue(mWifiVendorHal.selectTxPowerScenario(WifiNative.TX_POWER_SCENARIO_NORMAL));
         verify(mIWifiChipV11).resetTxPowerScenario();
         verify(mIWifiChipV11, never()).selectTxPowerScenario(anyInt());
@@ -1906,13 +1938,73 @@
         mWifiVendorHal = new WifiVendorHalSpyV1_1(mHalDeviceManager, mLooper.getLooper());
         when(mIWifiChipV11.selectTxPowerScenario(anyInt())).thenReturn(mWifiStatusSuccess);
 
-        assertTrue(mWifiVendorHal.startVendorHal(true));
+        assertTrue(mWifiVendorHal.startVendorHalSta());
         assertFalse(mWifiVendorHal.selectTxPowerScenario(-6));
         verify(mIWifiChipV11, never()).selectTxPowerScenario(anyInt());
         verify(mIWifiChipV11, never()).resetTxPowerScenario();
         mWifiVendorHal.stopVendorHal();
     }
 
+    /**
+     * Test the STA Iface creation failure due to iface name retrieval failure.
+     */
+    @Test
+    public void testCreateStaIfaceFailureInIfaceName() throws RemoteException {
+        doAnswer(new AnswerWithArguments() {
+            public void answer(IWifiIface.getNameCallback cb)
+                    throws RemoteException {
+                cb.onValues(mWifiStatusFailure, "wlan0");
+            }
+        }).when(mIWifiStaIface).getName(any(IWifiIface.getNameCallback.class));
+
+        assertTrue(mWifiVendorHal.startVendorHal());
+        assertNull(mWifiVendorHal.createStaIface(null));
+        verify(mHalDeviceManager).createStaIface(eq(null), eq(null));
+    }
+
+    /**
+     * Test the STA Iface creation failure due to iface name retrieval failure.
+     */
+    @Test
+    public void testCreateApIfaceFailureInIfaceName() throws RemoteException {
+        doAnswer(new AnswerWithArguments() {
+            public void answer(IWifiIface.getNameCallback cb)
+                    throws RemoteException {
+                cb.onValues(mWifiStatusFailure, "wlan0");
+            }
+        }).when(mIWifiApIface).getName(any(IWifiIface.getNameCallback.class));
+
+        assertTrue(mWifiVendorHal.startVendorHal());
+        assertNull(mWifiVendorHal.createApIface(null));
+        verify(mHalDeviceManager).createApIface(eq(null), eq(null));
+    }
+
+    /**
+     * Test the creation and removal of STA Iface.
+     */
+    @Test
+    public void testCreateRemoveStaIface() throws RemoteException {
+        assertTrue(mWifiVendorHal.startVendorHal());
+        String ifaceName = mWifiVendorHal.createStaIface(null);
+        verify(mHalDeviceManager).createStaIface(eq(null), eq(null));
+        assertEquals(TEST_IFACE_NAME, ifaceName);
+        assertTrue(mWifiVendorHal.removeStaIface(ifaceName));
+        verify(mHalDeviceManager).removeIface(eq(mIWifiStaIface));
+    }
+
+    /**
+     * Test the creation and removal of Ap Iface.
+     */
+    @Test
+    public void testCreateRemoveApIface() throws RemoteException {
+        assertTrue(mWifiVendorHal.startVendorHal());
+        String ifaceName = mWifiVendorHal.createApIface(null);
+        verify(mHalDeviceManager).createApIface(eq(null), eq(null));
+        assertEquals(TEST_IFACE_NAME, ifaceName);
+        assertTrue(mWifiVendorHal.removeApIface(ifaceName));
+        verify(mHalDeviceManager).removeIface(eq(mIWifiApIface));
+    }
+
     private void startBgScan(WifiNative.ScanEventHandler eventHandler) throws Exception {
         when(mIWifiStaIface.startBackgroundScan(
                 anyInt(), any(StaBackgroundScanParameters.class))).thenReturn(mWifiStatusSuccess);
@@ -1923,7 +2015,7 @@
         bucketSettings.period_ms = 16000;
         bucketSettings.report_events = WifiScanner.REPORT_EVENT_AFTER_EACH_SCAN;
         settings.buckets = new WifiNative.BucketSettings[] {bucketSettings};
-        assertTrue(mWifiVendorHal.startBgScan(settings, eventHandler));
+        assertTrue(mWifiVendorHal.startBgScan(TEST_IFACE_NAME, settings, eventHandler));
     }
 
     // Create a pair of HIDL scan result and its corresponding framework scan result for
diff --git a/tests/wifitests/src/com/android/server/wifi/WificondControlTest.java b/tests/wifitests/src/com/android/server/wifi/WificondControlTest.java
index 2aba969..524324a 100644
--- a/tests/wifitests/src/com/android/server/wifi/WificondControlTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WificondControlTest.java
@@ -16,28 +16,29 @@
 
 package com.android.server.wifi;
 
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static android.net.wifi.WifiConfiguration.KeyMgmt.NONE;
+import static android.net.wifi.WifiConfiguration.KeyMgmt.WPA_PSK;
+
+import static org.junit.Assert.*;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Matchers.argThat;
-import static org.mockito.Mockito.any;
-import static org.mockito.Mockito.anyString;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.reset;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
 
 import android.net.wifi.IApInterface;
+import android.net.wifi.IApInterfaceEventCallback;
 import android.net.wifi.IClientInterface;
 import android.net.wifi.IPnoScanEvent;
 import android.net.wifi.IScanEvent;
 import android.net.wifi.IWifiScannerImpl;
 import android.net.wifi.IWificond;
 import android.net.wifi.ScanResult;
+import android.net.wifi.WifiConfiguration;
 import android.net.wifi.WifiEnterpriseConfig;
 import android.net.wifi.WifiScanner;
+import android.os.IBinder;
+import android.os.RemoteException;
 import android.test.suitebuilder.annotation.SmallTest;
 
 import com.android.server.wifi.util.NativeUtil;
@@ -55,6 +56,7 @@
 import org.mockito.MockitoAnnotations;
 
 import java.io.ByteArrayOutputStream;
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.BitSet;
 import java.util.HashSet;
@@ -69,14 +71,19 @@
     @Mock private WifiMonitor mWifiMonitor;
     @Mock private WifiMetrics mWifiMetrics;
     @Mock private IWificond mWificond;
+    @Mock private IBinder mWifiCondBinder;
     @Mock private IClientInterface mClientInterface;
     @Mock private IWifiScannerImpl mWifiScannerImpl;
     @Mock private CarrierNetworkConfig mCarrierNetworkConfig;
     @Mock private IApInterface mApInterface;
+    @Mock private WifiNative.SoftApListener mSoftApListener;
     private WificondControl mWificondControl;
     private static final String TEST_INTERFACE_NAME = "test_wlan_if";
+    private static final String TEST_INTERFACE_NAME1 = "test_wlan_if1";
     private static final byte[] TEST_SSID =
             new byte[] {'G', 'o', 'o', 'g', 'l', 'e', 'G', 'u', 'e', 's', 't'};
+    private static final byte[] TEST_PSK =
+            new byte[] {'T', 'e', 's', 't'};
     private static final byte[] TEST_BSSID =
             new byte[] {(byte) 0x12, (byte) 0xef, (byte) 0xa1,
                         (byte) 0x2c, (byte) 0x97, (byte) 0x8b};
@@ -153,132 +160,308 @@
         // created in specific tests
         MockitoAnnotations.initMocks(this);
         when(mWifiInjector.makeWificond()).thenReturn(mWificond);
+        when(mWificond.asBinder()).thenReturn(mWifiCondBinder);
         when(mClientInterface.getWifiScannerImpl()).thenReturn(mWifiScannerImpl);
-        when(mWificond.createClientInterface(TEST_INTERFACE_NAME)).thenReturn(mClientInterface);
+        when(mWificond.createClientInterface(any())).thenReturn(mClientInterface);
+        when(mWificond.createApInterface(any())).thenReturn(mApInterface);
+        when(mWificond.tearDownClientInterface(any())).thenReturn(true);
+        when(mWificond.tearDownApInterface(any())).thenReturn(true);
         when(mClientInterface.getWifiScannerImpl()).thenReturn(mWifiScannerImpl);
         when(mClientInterface.getInterfaceName()).thenReturn(TEST_INTERFACE_NAME);
         when(mWifiInjector.getWifiMetrics()).thenReturn(mWifiMetrics);
         mWificondControl = new WificondControl(mWifiInjector, mWifiMonitor, mCarrierNetworkConfig);
-        assertEquals(
-                mClientInterface, mWificondControl.setupDriverForClientMode(TEST_INTERFACE_NAME));
+        assertEquals(mClientInterface, mWificondControl.setupInterfaceForClientMode(
+                TEST_INTERFACE_NAME));
+        verify(mWifiInjector).makeWificond();
+        verify(mWifiCondBinder).linkToDeath(any(IBinder.DeathRecipient.class), anyInt());
     }
 
     /**
-     * Verifies that setupDriverForClientMode(TEST_INTERFACE_NAME) calls Wificond.
+     * Verifies that setupInterfaceForClientMode(TEST_INTERFACE_NAME) calls Wificond.
      */
     @Test
-    public void testSetupDriverForClientMode() throws Exception {
+    public void testSetupInterfaceForClientMode() throws Exception {
         when(mWifiInjector.makeWificond()).thenReturn(mWificond);
         when(mWificond.createClientInterface(TEST_INTERFACE_NAME)).thenReturn(mClientInterface);
         verify(mWificond).createClientInterface(TEST_INTERFACE_NAME);
     }
 
     /**
-     * Verifies that setupDriverForClientMode(TEST_INTERFACE_NAME) calls subscribeScanEvents().
+     * Verifies that setupInterfaceForClientMode(TEST_INTERFACE_NAME) calls subscribeScanEvents().
      */
     @Test
-    public void testSetupDriverForClientModeCallsScanEventSubscripiton() throws Exception {
+    public void testSetupInterfaceForClientModeCallsScanEventSubscripiton() throws Exception {
         verify(mWifiScannerImpl).subscribeScanEvents(any(IScanEvent.class));
     }
 
     /**
-     * Verifies that setupDriverForClientMode(TEST_INTERFACE_NAME) returns null when wificond is
+     * Verifies that setupInterfaceForClientMode(TEST_INTERFACE_NAME) returns null when wificond is
      * not started.
      */
     @Test
-    public void testSetupDriverForClientModeErrorWhenWificondIsNotStarted() throws Exception {
+    public void testSetupInterfaceForClientModeErrorWhenWificondIsNotStarted() throws Exception {
+        // Invoke wificond death handler to clear the handle.
+        mWificondControl.binderDied();
         when(mWifiInjector.makeWificond()).thenReturn(null);
         IClientInterface returnedClientInterface =
-                mWificondControl.setupDriverForClientMode(TEST_INTERFACE_NAME);
+                mWificondControl.setupInterfaceForClientMode(TEST_INTERFACE_NAME);
         assertEquals(null, returnedClientInterface);
+        verify(mWifiInjector, times(2)).makeWificond();
     }
 
     /**
-     * Verifies that setupDriverForClientMode(TEST_INTERFACE_NAME) returns null when wificond failed
-     * to setup client interface.
+     * Verifies that setupInterfaceForClientMode(TEST_INTERFACE_NAME) returns null when wificond
+     * failed to setup client interface.
      */
     @Test
-    public void testSetupDriverForClientModeErrorWhenWificondFailedToSetupInterface()
+    public void testSetupInterfaceForClientModeErrorWhenWificondFailedToSetupInterface()
             throws Exception {
         when(mWifiInjector.makeWificond()).thenReturn(mWificond);
         when(mWificond.createClientInterface(TEST_INTERFACE_NAME)).thenReturn(null);
 
         IClientInterface returnedClientInterface =
-                mWificondControl.setupDriverForClientMode(TEST_INTERFACE_NAME);
+                mWificondControl.setupInterfaceForClientMode(TEST_INTERFACE_NAME);
         assertEquals(null, returnedClientInterface);
     }
 
     /**
-     * Verifies that setupDriverForSoftApMode(TEST_INTERFACE_NAME) calls wificond.
+     * Verifies that tearDownClientInterface(TEST_INTERFACE_NAME) calls Wificond.
      */
     @Test
-    public void testSetupDriverForSoftApMode() throws Exception {
+    public void testTeardownClientInterface() throws Exception {
+        when(mWificond.tearDownClientInterface(TEST_INTERFACE_NAME)).thenReturn(true);
+
+        assertTrue(mWificondControl.tearDownClientInterface(TEST_INTERFACE_NAME));
+        verify(mWifiScannerImpl).unsubscribeScanEvents();
+        verify(mWifiScannerImpl).unsubscribePnoScanEvents();
+        verify(mWificond).tearDownClientInterface(TEST_INTERFACE_NAME);
+    }
+
+    /**
+     * Verifies that tearDownClientInterface(TEST_INTERFACE_NAME) calls Wificond.
+     */
+    @Test
+    public void testTeardownClientInterfaceFailDueToExceptionScannerUnsubscribe() throws Exception {
+        when(mWificond.tearDownClientInterface(TEST_INTERFACE_NAME)).thenReturn(true);
+        doThrow(new RemoteException()).when(mWifiScannerImpl).unsubscribeScanEvents();
+
+        assertFalse(mWificondControl.tearDownClientInterface(TEST_INTERFACE_NAME));
+        verify(mWifiScannerImpl).unsubscribeScanEvents();
+        verify(mWifiScannerImpl, never()).unsubscribePnoScanEvents();
+        verify(mWificond, never()).tearDownClientInterface(TEST_INTERFACE_NAME);
+    }
+    /**
+     * Verifies that tearDownClientInterface(TEST_INTERFACE_NAME) calls Wificond.
+     */
+    @Test
+    public void testTeardownClientInterfaceErrorWhenWificondFailed() throws Exception {
+        when(mWificond.tearDownClientInterface(TEST_INTERFACE_NAME)).thenReturn(false);
+
+        assertFalse(mWificondControl.tearDownClientInterface(TEST_INTERFACE_NAME));
+        verify(mWifiScannerImpl).unsubscribeScanEvents();
+        verify(mWifiScannerImpl).unsubscribePnoScanEvents();
+        verify(mWificond).tearDownClientInterface(TEST_INTERFACE_NAME);
+    }
+
+    /**
+     * Verifies that the client handles are cleared after teardown.
+     */
+    @Test
+    public void testTeardownClientInterfaceClearsHandles() throws Exception {
+        testTeardownClientInterface();
+
+        assertNull(mWificondControl.signalPoll(TEST_INTERFACE_NAME));
+        verify(mClientInterface, never()).signalPoll();
+
+        assertFalse(mWificondControl.scan(
+                TEST_INTERFACE_NAME, SCAN_FREQ_SET, SCAN_HIDDEN_NETWORK_SSID_SET));
+        verify(mWifiScannerImpl, never()).scan(any());
+    }
+
+    /**
+     * Verifies that setupInterfaceForSoftApMode(TEST_INTERFACE_NAME) calls wificond.
+     */
+    @Test
+    public void testSetupInterfaceForSoftApMode() throws Exception {
         when(mWifiInjector.makeWificond()).thenReturn(mWificond);
         when(mWificond.createApInterface(TEST_INTERFACE_NAME)).thenReturn(mApInterface);
 
         IApInterface returnedApInterface =
-                mWificondControl.setupDriverForSoftApMode(TEST_INTERFACE_NAME);
+                mWificondControl.setupInterfaceForSoftApMode(TEST_INTERFACE_NAME);
         assertEquals(mApInterface, returnedApInterface);
+        verify(mWifiInjector).makeWificond();
+        verify(mWifiCondBinder).linkToDeath(any(IBinder.DeathRecipient.class), anyInt());
         verify(mWificond).createApInterface(TEST_INTERFACE_NAME);
     }
 
     /**
-     * Verifies that setupDriverForSoftAp() returns null when wificond is not started.
+     * Verifies that setupInterfaceForSoftAp() returns null when wificond is not started.
      */
     @Test
-    public void testSetupDriverForSoftApModeErrorWhenWificondIsNotStarted() throws Exception {
+    public void testSetupInterfaceForSoftApModeErrorWhenWificondIsNotStarted() throws Exception {
+        // Invoke wificond death handler to clear the handle.
+        mWificondControl.binderDied();
         when(mWifiInjector.makeWificond()).thenReturn(null);
 
         IApInterface returnedApInterface =
-                mWificondControl.setupDriverForSoftApMode(TEST_INTERFACE_NAME);
+                mWificondControl.setupInterfaceForSoftApMode(TEST_INTERFACE_NAME);
 
         assertEquals(null, returnedApInterface);
+        verify(mWifiInjector, times(2)).makeWificond();
     }
 
     /**
-     * Verifies that setupDriverForSoftApMode(TEST_INTERFACE_NAME) returns null when wificond failed
-     * to setup AP interface.
+     * Verifies that setupInterfaceForSoftApMode(TEST_INTERFACE_NAME) returns null when wificond
+     * failed to setup AP interface.
      */
     @Test
-    public void testSetupDriverForSoftApModeErrorWhenWificondFailedToSetupInterface()
+    public void testSetupInterfaceForSoftApModeErrorWhenWificondFailedToSetupInterface()
             throws Exception {
         when(mWifiInjector.makeWificond()).thenReturn(mWificond);
         when(mWificond.createApInterface(TEST_INTERFACE_NAME)).thenReturn(null);
 
         IApInterface returnedApInterface =
-                mWificondControl.setupDriverForSoftApMode(TEST_INTERFACE_NAME);
+                mWificondControl.setupInterfaceForSoftApMode(TEST_INTERFACE_NAME);
         assertEquals(null, returnedApInterface);
     }
 
     /**
+     * Verifies that tearDownClientInterface(TEST_INTERFACE_NAME) calls Wificond.
+     */
+    @Test
+    public void testTeardownSoftApInterface() throws Exception {
+        testSetupInterfaceForSoftApMode();
+        when(mWificond.tearDownApInterface(TEST_INTERFACE_NAME)).thenReturn(true);
+
+        assertTrue(mWificondControl.tearDownSoftApInterface(TEST_INTERFACE_NAME));
+        verify(mWificond).tearDownApInterface(TEST_INTERFACE_NAME);
+    }
+
+    /**
+     * Verifies that tearDownClientInterface(TEST_INTERFACE_NAME) calls Wificond.
+     */
+    @Test
+    public void testTeardownSoftApInterfaceErrorWhenWificondFailed() throws Exception {
+        testSetupInterfaceForSoftApMode();
+        when(mWificond.tearDownApInterface(TEST_INTERFACE_NAME)).thenReturn(false);
+
+        assertFalse(mWificondControl.tearDownSoftApInterface(TEST_INTERFACE_NAME));
+        verify(mWificond).tearDownApInterface(TEST_INTERFACE_NAME);
+    }
+
+    /**
+     * Verifies that the SoftAp handles are cleared after teardown.
+     */
+    @Test
+    public void testTeardownSoftApInterfaceClearsHandles() throws Exception {
+        testTeardownSoftApInterface();
+
+        assertFalse(mWificondControl.startSoftAp(
+                TEST_INTERFACE_NAME, new WifiConfiguration(), mSoftApListener));
+        verify(mApInterface, never()).writeHostapdConfig(
+                any(byte[].class), anyBoolean(), anyInt(), anyInt(), any(byte[].class));
+        verify(mApInterface, never()).startHostapd(any());
+    }
+
+    /**
+     * Verifies that we can setup concurrent interfaces.
+     */
+    @Test
+    public void testSetupMulitpleInterfaces() throws Exception {
+        when(mWificond.createApInterface(TEST_INTERFACE_NAME1)).thenReturn(mApInterface);
+
+        IApInterface returnedApInterface =
+                mWificondControl.setupInterfaceForSoftApMode(TEST_INTERFACE_NAME1);
+        assertEquals(mApInterface, returnedApInterface);
+        verify(mWifiInjector).makeWificond();
+        verify(mWifiCondBinder).linkToDeath(any(IBinder.DeathRecipient.class), anyInt());
+
+        verify(mWificond).createClientInterface(TEST_INTERFACE_NAME);
+        verify(mWificond).createApInterface(TEST_INTERFACE_NAME1);
+    }
+
+    /**
+     * Verifies that we can setup concurrent interfaces.
+     */
+    @Test
+    public void testTeardownMulitpleInterfaces() throws Exception {
+        testSetupMulitpleInterfaces();
+        assertTrue(mWificondControl.tearDownClientInterface(TEST_INTERFACE_NAME));
+        assertTrue(mWificondControl.tearDownSoftApInterface(TEST_INTERFACE_NAME1));
+
+        verify(mWificond).tearDownClientInterface(TEST_INTERFACE_NAME);
+        verify(mWificond).tearDownApInterface(TEST_INTERFACE_NAME1);
+    }
+
+    /**
      * Verifies that enableSupplicant() calls wificond.
      */
     @Test
     public void testEnableSupplicant() throws Exception {
         when(mWifiInjector.makeWificond()).thenReturn(mWificond);
-        when(mWificond.createClientInterface(TEST_INTERFACE_NAME)).thenReturn(mClientInterface);
         when(mWificond.enableSupplicant()).thenReturn(true);
 
-        mWificondControl.setupDriverForClientMode(TEST_INTERFACE_NAME);
         assertTrue(mWificondControl.enableSupplicant());
+        verify(mWifiInjector).makeWificond();
         verify(mWificond).enableSupplicant();
     }
 
     /**
+     * Verifies that enableSupplicant() returns false when there is no configured
+     * client interface.
+     */
+    @Test
+    public void testEnableSupplicantErrorWhenNoClientInterfaceConfigured() throws Exception {
+        when(mWifiInjector.makeWificond()).thenReturn(mWificond);
+        when(mWificond.createClientInterface(TEST_INTERFACE_NAME)).thenReturn(mClientInterface);
+
+        // Configure client interface.
+        IClientInterface returnedClientInterface =
+                mWificondControl.setupInterfaceForClientMode(TEST_INTERFACE_NAME);
+        assertEquals(mClientInterface, returnedClientInterface);
+
+        // Tear down interfaces.
+        assertTrue(mWificondControl.tearDownInterfaces());
+
+        // Enabling supplicant should fail.
+        assertFalse(mWificondControl.enableSupplicant());
+    }
+
+    /**
      * Verifies that disableSupplicant() calls wificond.
      */
     @Test
     public void testDisableSupplicant() throws Exception {
         when(mWifiInjector.makeWificond()).thenReturn(mWificond);
-        when(mWificond.createClientInterface(TEST_INTERFACE_NAME)).thenReturn(mClientInterface);
         when(mWificond.disableSupplicant()).thenReturn(true);
 
-        mWificondControl.setupDriverForClientMode(TEST_INTERFACE_NAME);
         assertTrue(mWificondControl.disableSupplicant());
+        verify(mWifiInjector).makeWificond();
         verify(mWificond).disableSupplicant();
     }
 
     /**
+     * Verifies that disableSupplicant() returns false when there is no configured
+     * client interface.
+     */
+    @Test
+    public void testDisableSupplicantErrorWhenNoClientInterfaceConfigured() throws Exception {
+        when(mWifiInjector.makeWificond()).thenReturn(mWificond);
+        when(mWificond.createClientInterface(TEST_INTERFACE_NAME)).thenReturn(mClientInterface);
+
+        // Configure client interface.
+        IClientInterface returnedClientInterface =
+                mWificondControl.setupInterfaceForClientMode(TEST_INTERFACE_NAME);
+        assertEquals(mClientInterface, returnedClientInterface);
+
+        // Tear down interfaces.
+        assertTrue(mWificondControl.tearDownInterfaces());
+
+        // Disabling supplicant should fail.
+        assertFalse(mWificondControl.disableSupplicant());
+    }
+
+    /**
      * Verifies that tearDownInterfaces() calls wificond.
      */
     @Test
@@ -304,6 +487,8 @@
      */
     @Test
     public void testTearDownInterfacesErrorWhenWificondIsNotStarterd() throws Exception {
+        // Invoke wificond death handler to clear the handle.
+        mWificondControl.binderDied();
         when(mWifiInjector.makeWificond()).thenReturn(null);
         assertFalse(mWificondControl.tearDownInterfaces());
     }
@@ -316,8 +501,8 @@
         when(mWifiInjector.makeWificond()).thenReturn(mWificond);
         when(mWificond.createClientInterface(TEST_INTERFACE_NAME)).thenReturn(mClientInterface);
 
-        mWificondControl.setupDriverForClientMode(TEST_INTERFACE_NAME);
-        mWificondControl.signalPoll();
+        mWificondControl.setupInterfaceForClientMode(TEST_INTERFACE_NAME);
+        mWificondControl.signalPoll(TEST_INTERFACE_NAME);
         verify(mClientInterface).signalPoll();
     }
 
@@ -331,14 +516,14 @@
 
         // Configure client interface.
         IClientInterface returnedClientInterface =
-                mWificondControl.setupDriverForClientMode(TEST_INTERFACE_NAME);
+                mWificondControl.setupInterfaceForClientMode(TEST_INTERFACE_NAME);
         assertEquals(mClientInterface, returnedClientInterface);
 
         // Tear down interfaces.
         assertTrue(mWificondControl.tearDownInterfaces());
 
         // Signal poll should fail.
-        assertEquals(null, mWificondControl.signalPoll());
+        assertEquals(null, mWificondControl.signalPoll(TEST_INTERFACE_NAME));
     }
 
     /**
@@ -349,8 +534,8 @@
         when(mWifiInjector.makeWificond()).thenReturn(mWificond);
         when(mWificond.createClientInterface(TEST_INTERFACE_NAME)).thenReturn(mClientInterface);
 
-        mWificondControl.setupDriverForClientMode(TEST_INTERFACE_NAME);
-        mWificondControl.getTxPacketCounters();
+        mWificondControl.setupInterfaceForClientMode(TEST_INTERFACE_NAME);
+        mWificondControl.getTxPacketCounters(TEST_INTERFACE_NAME);
         verify(mClientInterface).getPacketCounters();
     }
 
@@ -365,14 +550,14 @@
 
         // Configure client interface.
         IClientInterface returnedClientInterface =
-                mWificondControl.setupDriverForClientMode(TEST_INTERFACE_NAME);
+                mWificondControl.setupInterfaceForClientMode(TEST_INTERFACE_NAME);
         assertEquals(mClientInterface, returnedClientInterface);
 
         // Tear down interfaces.
         assertTrue(mWificondControl.tearDownInterfaces());
 
         // Signal poll should fail.
-        assertEquals(null, mWificondControl.getTxPacketCounters());
+        assertEquals(null, mWificondControl.getTxPacketCounters(TEST_INTERFACE_NAME));
     }
 
     /**
@@ -386,7 +571,7 @@
 
         // Configure client interface.
         IClientInterface returnedClientInterface =
-                mWificondControl.setupDriverForClientMode(TEST_INTERFACE_NAME);
+                mWificondControl.setupInterfaceForClientMode(TEST_INTERFACE_NAME);
         assertEquals(mClientInterface, returnedClientInterface);
 
         // Tear down interfaces.
@@ -394,7 +579,8 @@
 
         // getScanResults should fail.
         assertEquals(0,
-                mWificondControl.getScanResults(WificondControl.SCAN_TYPE_SINGLE_SCAN).size());
+                mWificondControl.getScanResults(TEST_INTERFACE_NAME,
+                        WificondControl.SCAN_TYPE_SINGLE_SCAN).size());
     }
 
     /**
@@ -409,7 +595,7 @@
         when(mWifiScannerImpl.getScanResults()).thenReturn(mockScanResults);
 
         ArrayList<ScanDetail> returnedScanResults = mWificondControl.getScanResults(
-                WificondControl.SCAN_TYPE_SINGLE_SCAN);
+                TEST_INTERFACE_NAME, WificondControl.SCAN_TYPE_SINGLE_SCAN);
         // The test IEs {@link #TEST_INFO_ELEMENT} doesn't contained RSN IE, which means non-EAP
         // AP. So verify carrier network is not checked, since EAP is currently required for a
         // carrier network.
@@ -457,7 +643,7 @@
         when(mCarrierNetworkConfig.getCarrierName(new String(nativeScanResult.ssid)))
                 .thenReturn(carrierName);
         ArrayList<ScanDetail> returnedScanResults = mWificondControl.getScanResults(
-                WificondControl.SCAN_TYPE_SINGLE_SCAN);
+                TEST_INTERFACE_NAME, WificondControl.SCAN_TYPE_SINGLE_SCAN);
         assertEquals(1, returnedScanResults.size());
         // Verify returned scan result.
         ScanResult scanResult = returnedScanResults.get(0).getScanResult();
@@ -471,7 +657,7 @@
         when(mCarrierNetworkConfig.isCarrierNetwork(new String(nativeScanResult.ssid)))
                 .thenReturn(false);
         returnedScanResults = mWificondControl.getScanResults(
-                WificondControl.SCAN_TYPE_SINGLE_SCAN);
+                TEST_INTERFACE_NAME, WificondControl.SCAN_TYPE_SINGLE_SCAN);
         assertEquals(1, returnedScanResults.size());
         // Verify returned scan result.
         scanResult = returnedScanResults.get(0).getScanResult();
@@ -487,7 +673,8 @@
     @Test
     public void testScan() throws Exception {
         when(mWifiScannerImpl.scan(any(SingleScanSettings.class))).thenReturn(true);
-        assertTrue(mWificondControl.scan(SCAN_FREQ_SET, SCAN_HIDDEN_NETWORK_SSID_SET));
+        assertTrue(mWificondControl.scan(
+                TEST_INTERFACE_NAME, SCAN_FREQ_SET, SCAN_HIDDEN_NETWORK_SSID_SET));
         verify(mWifiScannerImpl).scan(argThat(new ScanMatcher(
                 SCAN_FREQ_SET, SCAN_HIDDEN_NETWORK_SSID_SET)));
     }
@@ -498,7 +685,7 @@
     @Test
     public void testScanNullParameters() throws Exception {
         when(mWifiScannerImpl.scan(any(SingleScanSettings.class))).thenReturn(true);
-        assertTrue(mWificondControl.scan(null, null));
+        assertTrue(mWificondControl.scan(TEST_INTERFACE_NAME, null, null));
         verify(mWifiScannerImpl).scan(argThat(new ScanMatcher(null, null)));
     }
 
@@ -508,7 +695,8 @@
     @Test
     public void testScanFailure() throws Exception {
         when(mWifiScannerImpl.scan(any(SingleScanSettings.class))).thenReturn(false);
-        assertFalse(mWificondControl.scan(SCAN_FREQ_SET, SCAN_HIDDEN_NETWORK_SSID_SET));
+        assertFalse(mWificondControl.scan(
+                TEST_INTERFACE_NAME, SCAN_FREQ_SET, SCAN_HIDDEN_NETWORK_SSID_SET));
         verify(mWifiScannerImpl).scan(any(SingleScanSettings.class));
     }
 
@@ -518,7 +706,7 @@
     @Test
     public void testStartPnoScan() throws Exception {
         when(mWifiScannerImpl.startPnoScan(any(PnoSettings.class))).thenReturn(true);
-        assertTrue(mWificondControl.startPnoScan(TEST_PNO_SETTINGS));
+        assertTrue(mWificondControl.startPnoScan(TEST_INTERFACE_NAME, TEST_PNO_SETTINGS));
         verify(mWifiScannerImpl).startPnoScan(argThat(new PnoScanMatcher(TEST_PNO_SETTINGS)));
     }
 
@@ -528,7 +716,7 @@
     @Test
     public void testStopPnoScan() throws Exception {
         when(mWifiScannerImpl.stopPnoScan()).thenReturn(true);
-        assertTrue(mWificondControl.stopPnoScan());
+        assertTrue(mWificondControl.stopPnoScan(TEST_INTERFACE_NAME));
         verify(mWifiScannerImpl).stopPnoScan();
     }
 
@@ -539,7 +727,7 @@
     public void testStopPnoScanFailure() throws Exception {
 
         when(mWifiScannerImpl.stopPnoScan()).thenReturn(false);
-        assertFalse(mWificondControl.stopPnoScan());
+        assertFalse(mWificondControl.stopPnoScan(TEST_INTERFACE_NAME));
         verify(mWifiScannerImpl).stopPnoScan();
     }
 
@@ -617,7 +805,7 @@
     @Test
     public void testStartPnoScanForMetrics() throws Exception {
         when(mWifiScannerImpl.startPnoScan(any(PnoSettings.class))).thenReturn(false);
-        assertFalse(mWificondControl.startPnoScan(TEST_PNO_SETTINGS));
+        assertFalse(mWificondControl.startPnoScan(TEST_INTERFACE_NAME, TEST_PNO_SETTINGS));
         verify(mWifiMetrics).incrementPnoScanStartAttempCount();
         verify(mWifiMetrics).incrementPnoScanFailedCount();
     }
@@ -627,10 +815,283 @@
      */
     @Test
     public void testAbortScan() throws Exception {
-        mWificondControl.abortScan();
+        mWificondControl.abortScan(TEST_INTERFACE_NAME);
         verify(mWifiScannerImpl).abortScan();
     }
 
+    /**
+     * Verifies successful soft ap start.
+     */
+    @Test
+    public void testStartSoftApWithPskConfig() throws Exception {
+        testSetupInterfaceForSoftApMode();
+        WifiConfiguration config = new WifiConfiguration();
+        config.SSID = new String(TEST_SSID, StandardCharsets.UTF_8);
+        config.allowedKeyManagement.set(WPA_PSK);
+        config.preSharedKey = new String(TEST_PSK, StandardCharsets.UTF_8);
+        config.hiddenSSID = false;
+        config.apChannel = TEST_FREQUENCY;
+
+        when(mApInterface.writeHostapdConfig(
+                any(byte[].class), anyBoolean(), anyInt(), anyInt(), any(byte[].class)))
+                .thenReturn(true);
+        when(mApInterface.startHostapd(any())).thenReturn(true);
+
+        assertTrue(mWificondControl.startSoftAp(
+                TEST_INTERFACE_NAME, config, mSoftApListener));
+        verify(mApInterface).writeHostapdConfig(
+                eq(TEST_SSID), eq(false), eq(TEST_FREQUENCY),
+                eq(IApInterface.ENCRYPTION_TYPE_WPA), eq(TEST_PSK));
+        verify(mApInterface).startHostapd(any());
+    }
+
+    /**
+     * Verifies successful soft ap start.
+     */
+    @Test
+    public void testStartSoftApWithOpenHiddenConfig() throws Exception {
+        testSetupInterfaceForSoftApMode();
+        WifiConfiguration config = new WifiConfiguration();
+        config.SSID = new String(TEST_SSID, StandardCharsets.UTF_8);
+        config.allowedKeyManagement.set(NONE);
+        config.hiddenSSID = true;
+        config.apChannel = TEST_FREQUENCY;
+
+        when(mApInterface.writeHostapdConfig(
+                any(byte[].class), anyBoolean(), anyInt(), anyInt(), any(byte[].class)))
+                .thenReturn(true);
+        when(mApInterface.startHostapd(any())).thenReturn(true);
+
+        assertTrue(mWificondControl.startSoftAp(
+                TEST_INTERFACE_NAME, config, mSoftApListener));
+        verify(mApInterface).writeHostapdConfig(
+                eq(TEST_SSID), eq(true), eq(TEST_FREQUENCY),
+                eq(IApInterface.ENCRYPTION_TYPE_NONE), eq(new byte[0]));
+        verify(mApInterface).startHostapd(any());
+    }
+
+    /**
+     * Ensures that the Ap interface callbacks are forwarded to the
+     * SoftApListener used for starting soft AP.
+     */
+    @Test
+    public void testSoftApListenerInvocation() throws Exception {
+        testSetupInterfaceForSoftApMode();
+
+        WifiConfiguration config = new WifiConfiguration();
+        config.SSID = new String(TEST_SSID, StandardCharsets.UTF_8);
+
+        when(mApInterface.writeHostapdConfig(
+                any(byte[].class), anyBoolean(), anyInt(), anyInt(), any(byte[].class)))
+                .thenReturn(true);
+        when(mApInterface.startHostapd(any())).thenReturn(true);
+
+        final ArgumentCaptor<IApInterfaceEventCallback> apInterfaceCallbackCaptor =
+                ArgumentCaptor.forClass(IApInterfaceEventCallback.class);
+
+        assertTrue(mWificondControl.startSoftAp(
+                TEST_INTERFACE_NAME, config, mSoftApListener));
+        verify(mApInterface).writeHostapdConfig(
+                eq(TEST_SSID), anyBoolean(), anyInt(),
+                anyInt(), any(byte[].class));
+        verify(mApInterface).startHostapd(apInterfaceCallbackCaptor.capture());
+
+        int numStations = 5;
+        apInterfaceCallbackCaptor.getValue().onNumAssociatedStationsChanged(numStations);
+        verify(mSoftApListener).onNumAssociatedStationsChanged(eq(numStations));
+
+    }
+
+    /**
+     * Ensure that soft ap start fails when the interface is not setup.
+     */
+    @Test
+    public void testStartSoftApWithoutSetupInterface() throws Exception {
+        assertFalse(mWificondControl.startSoftAp(
+                TEST_INTERFACE_NAME, new WifiConfiguration(), mSoftApListener));
+        verify(mApInterface, never()).writeHostapdConfig(
+                any(byte[].class), anyBoolean(), anyInt(), anyInt(), any(byte[].class));
+        verify(mApInterface, never()).startHostapd(any());
+    }
+
+    /**
+     * Verifies soft ap start failure.
+     */
+    @Test
+    public void testStartSoftApFailDueToWriteConfigError() throws Exception {
+        testSetupInterfaceForSoftApMode();
+        WifiConfiguration config = new WifiConfiguration();
+        config.SSID = new String(TEST_SSID, StandardCharsets.UTF_8);
+
+        when(mApInterface.writeHostapdConfig(
+                any(byte[].class), anyBoolean(), anyInt(), anyInt(), any(byte[].class)))
+                .thenReturn(false);
+        when(mApInterface.startHostapd(any())).thenReturn(true);
+
+        assertFalse(mWificondControl.startSoftAp(
+                TEST_INTERFACE_NAME, config, mSoftApListener));
+        verify(mApInterface).writeHostapdConfig(
+                eq(TEST_SSID), anyBoolean(), anyInt(),
+                anyInt(), any(byte[].class));
+        verify(mApInterface, never()).startHostapd(any());
+    }
+
+    /**
+     * Verifies soft ap start failure.
+     */
+    @Test
+    public void testStartSoftApFailDueToStartError() throws Exception {
+        testSetupInterfaceForSoftApMode();
+        WifiConfiguration config = new WifiConfiguration();
+        config.SSID = new String(TEST_SSID, StandardCharsets.UTF_8);
+
+        when(mApInterface.writeHostapdConfig(
+                any(byte[].class), anyBoolean(), anyInt(), anyInt(), any(byte[].class)))
+                .thenReturn(true);
+        when(mApInterface.startHostapd(any())).thenReturn(false);
+
+        assertFalse(mWificondControl.startSoftAp(
+                TEST_INTERFACE_NAME, config, mSoftApListener));
+        verify(mApInterface).writeHostapdConfig(
+                eq(TEST_SSID), anyBoolean(), anyInt(),
+                anyInt(), any(byte[].class));
+        verify(mApInterface).startHostapd(any());
+    }
+
+    /**
+     * Verifies soft ap start failure.
+     */
+    @Test
+    public void testStartSoftApFailDueToExceptionInStart() throws Exception {
+        testSetupInterfaceForSoftApMode();
+        WifiConfiguration config = new WifiConfiguration();
+        config.SSID = new String(TEST_SSID, StandardCharsets.UTF_8);
+
+        when(mApInterface.writeHostapdConfig(
+                any(byte[].class), anyBoolean(), anyInt(), anyInt(), any(byte[].class)))
+                .thenReturn(true);
+        doThrow(new RemoteException()).when(mApInterface).startHostapd(any());
+
+        assertFalse(mWificondControl.startSoftAp(
+                TEST_INTERFACE_NAME, config, mSoftApListener));
+        verify(mApInterface).writeHostapdConfig(
+                eq(TEST_SSID), anyBoolean(), anyInt(),
+                anyInt(), any(byte[].class));
+        verify(mApInterface).startHostapd(any());
+    }
+
+    /**
+     * Verifies soft ap stop success.
+     */
+    @Test
+    public void testStopSoftAp() throws Exception {
+        testSetupInterfaceForSoftApMode();
+
+        when(mApInterface.stopHostapd()).thenReturn(true);
+
+        assertTrue(mWificondControl.stopSoftAp(TEST_INTERFACE_NAME));
+        verify(mApInterface).stopHostapd();
+    }
+
+    /**
+     * Ensure that soft ap stop fails when the interface is not setup.
+     */
+    @Test
+    public void testStopSoftApWithOutSetupInterface() throws Exception {
+        when(mApInterface.stopHostapd()).thenReturn(true);
+        assertFalse(mWificondControl.stopSoftAp(TEST_INTERFACE_NAME));
+        verify(mApInterface, never()).stopHostapd();
+    }
+
+    /**
+     * Verifies soft ap stop failure.
+     */
+    @Test
+    public void testStopSoftApFailDueToStopError() throws Exception {
+        testSetupInterfaceForSoftApMode();
+
+        when(mApInterface.stopHostapd()).thenReturn(false);
+
+        assertFalse(mWificondControl.stopSoftAp(TEST_INTERFACE_NAME));
+        verify(mApInterface).stopHostapd();
+    }
+
+    /**
+     * Verifies soft ap stop failure.
+     */
+    @Test
+    public void testStopSoftApFailDueToExceptionInStop() throws Exception {
+        testSetupInterfaceForSoftApMode();
+
+        doThrow(new RemoteException()).when(mApInterface).stopHostapd();
+
+        assertFalse(mWificondControl.stopSoftAp(TEST_INTERFACE_NAME));
+        verify(mApInterface).stopHostapd();
+    }
+
+    /**
+     * Verifies registration and invocation of wificond death handler.
+     */
+    @Test
+    public void testRegisterDeathHandler() throws Exception {
+        WifiNative.WificondDeathEventHandler handler =
+                mock(WifiNative.WificondDeathEventHandler.class);
+        assertTrue(mWificondControl.registerDeathHandler(handler));
+        mWificondControl.binderDied();
+        verify(handler).onDeath();
+    }
+
+    /**
+     * Verifies registration and invocation of 2 wificond death handlers.
+     */
+    @Test
+    public void testRegisterTwoDeathHandlers() throws Exception {
+        WifiNative.WificondDeathEventHandler handler1 =
+                mock(WifiNative.WificondDeathEventHandler.class);
+        WifiNative.WificondDeathEventHandler handler2 =
+                mock(WifiNative.WificondDeathEventHandler.class);
+        assertTrue(mWificondControl.registerDeathHandler(handler1));
+        assertFalse(mWificondControl.registerDeathHandler(handler2));
+        mWificondControl.binderDied();
+        verify(handler1).onDeath();
+        verify(handler2, never()).onDeath();
+    }
+
+    /**
+     * Verifies de-registration of wificond death handler.
+     */
+    @Test
+    public void testDeregisterDeathHandler() throws Exception {
+        WifiNative.WificondDeathEventHandler handler =
+                mock(WifiNative.WificondDeathEventHandler.class);
+        assertTrue(mWificondControl.registerDeathHandler(handler));
+        assertTrue(mWificondControl.deregisterDeathHandler());
+        mWificondControl.binderDied();
+        verify(handler, never()).onDeath();
+    }
+
+    /**
+     * Verifies handling of wificond death and ensures that all internal state is cleared and
+     * handlers are invoked.
+     */
+    @Test
+    public void testDeathHandling() throws Exception {
+        WifiNative.WificondDeathEventHandler handler =
+                mock(WifiNative.WificondDeathEventHandler.class);
+        assertTrue(mWificondControl.registerDeathHandler(handler));
+
+        testSetupInterfaceForClientMode();
+
+        mWificondControl.binderDied();
+        verify(handler).onDeath();
+
+        // The handles should be cleared after death, so these should retrieve new handles.
+        when(mWificond.enableSupplicant()).thenReturn(true);
+        assertTrue(mWificondControl.enableSupplicant());
+        verify(mWifiInjector, times(2)).makeWificond();
+        verify(mWificond).enableSupplicant();
+    }
+
     // Create a ArgumentMatcher which captures a SingleScanSettings parameter and checks if it
     // matches the provided frequency set and ssid set.
     private class ScanMatcher implements ArgumentMatcher<SingleScanSettings> {
diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/OsuNetworkConnectionTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/OsuNetworkConnectionTest.java
new file mode 100644
index 0000000..c0d319f
--- /dev/null
+++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/OsuNetworkConnectionTest.java
@@ -0,0 +1,239 @@
+/*
+ * Copyright 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.server.wifi.hotspot2;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.IntentFilter;
+import android.net.Network;
+import android.net.NetworkInfo;
+import android.net.wifi.WifiConfiguration;
+import android.net.wifi.WifiInfo;
+import android.net.wifi.WifiManager;
+import android.net.wifi.WifiSsid;
+import android.os.Handler;
+import android.os.test.TestLooper;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import com.android.server.wifi.TestUtil;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+/**
+ * Unit tests for {@link com.android.server.wifi.hotspot2.PasspointProvisioner}.
+ */
+@SmallTest
+public class OsuNetworkConnectionTest {
+    private static final String TAG = "OsuNetworkConnectionTest";
+    private static final int ENABLE_LOGGING = 1;
+    private static final int DISABLE_LOGGING = 0;
+
+    private static final int TEST_NETWORK_ID = 6;
+    private static final String TEST_NAI = null;
+    private static final String TEST_NAI_OSEN = "access.test.com";
+    private static final WifiSsid TEST_SSID = WifiSsid.createFromAsciiEncoded("Test SSID");
+
+    private BroadcastReceiver mBroadcastReceiver;
+    private OsuNetworkConnection mNetworkConnection;
+    private TestLooper mLooper;
+    private Handler mHandler;
+
+    @Mock Context mContext;
+    @Mock WifiManager mWifiManager;
+    @Mock OsuNetworkConnection.Callbacks mNetworkCallbacks;
+    @Mock NetworkInfo mNwInfo;
+    @Mock WifiInfo mWifiInfo;
+    @Mock Network mCurrentNetwork;
+
+    ArgumentCaptor<BroadcastReceiver> mBroadcastReceiverCaptor = ArgumentCaptor.forClass(
+            BroadcastReceiver.class);
+    ArgumentCaptor<IntentFilter> mIntentFilterCaptor = ArgumentCaptor.forClass(
+            IntentFilter.class);
+
+    @Before
+    public void setUp() throws Exception {
+        MockitoAnnotations.initMocks(this);
+        doReturn(mWifiManager).when(mContext)
+                .getSystemService(eq(Context.WIFI_SERVICE));
+        when(mWifiManager.isWifiEnabled()).thenReturn(true);
+        when(mWifiManager.enableNetwork(TEST_NETWORK_ID, true)).thenReturn(true);
+        when(mWifiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(TEST_NETWORK_ID);
+        when(mWifiManager.getCurrentNetwork()).thenReturn(mCurrentNetwork);
+        when(mWifiInfo.getNetworkId()).thenReturn(TEST_NETWORK_ID);
+        mLooper = new TestLooper();
+        mHandler = new Handler(mLooper.getLooper());
+        mNetworkConnection = new OsuNetworkConnection(mContext);
+        mNetworkConnection.enableVerboseLogging(ENABLE_LOGGING);
+    }
+
+    /**
+     * Verify that the class registers for receiving the necessary broadcast intents upon init.
+     * Verify that the initialization only occurs once even if init() is called  multiple times.
+     */
+    @Test
+    public void verifyBroadcastIntentRegistration() {
+        mNetworkConnection.init(mHandler);
+        verify(mContext).registerReceiver(mBroadcastReceiverCaptor.capture(),
+                mIntentFilterCaptor.capture(), any(), eq(mHandler));
+        verify(mWifiManager).isWifiEnabled();
+        mLooper.dispatchAll();
+        IntentFilter intentFilter = mIntentFilterCaptor.getValue();
+        assertEquals(intentFilter.countActions(), 2);
+    }
+
+    /**
+     * Verifies that onWifiEnabled() callback is invoked when the relevant intent is
+     * received and the caller is subscribed to receive the callback.
+     */
+    @Test
+    public void verifyWifiStateCallbacks() {
+        when(mWifiManager.isWifiEnabled()).thenReturn(false);
+        mNetworkConnection.init(mHandler);
+        verify(mContext).registerReceiver(mBroadcastReceiverCaptor.capture(),
+                any(IntentFilter.class), any(), eq(mHandler));
+        mBroadcastReceiver = mBroadcastReceiverCaptor.getValue();
+        mLooper.dispatchAll();
+        mNetworkConnection.setEventCallback(mNetworkCallbacks);
+        TestUtil.sendWifiStateChanged(mBroadcastReceiver, mContext,
+                WifiManager.WIFI_STATE_ENABLED);
+        TestUtil.sendWifiStateChanged(mBroadcastReceiver, mContext,
+                WifiManager.WIFI_STATE_DISABLED);
+        mNetworkConnection.setEventCallback(null);
+        TestUtil.sendWifiStateChanged(mBroadcastReceiver, mContext,
+                WifiManager.WIFI_STATE_ENABLED);
+        TestUtil.sendWifiStateChanged(mBroadcastReceiver, mContext,
+                WifiManager.WIFI_STATE_DISABLED);
+        verify(mNetworkCallbacks, times(1)).onWifiEnabled();
+        verify(mNetworkCallbacks, times(1)).onWifiDisabled();
+    }
+
+    /**
+     * Verifies that connect() API returns false when Wifi is not enabled
+     */
+    @Test
+    public void verifyNetworkConnectionWhenWifiIsDisabled() {
+        when(mWifiManager.isWifiEnabled()).thenReturn(false);
+        mNetworkConnection.init(mHandler);
+        assertEquals(false, mNetworkConnection.connect(TEST_SSID, TEST_NAI));
+    }
+
+    /**
+     * Verifies that connect() API returns false when OSU AP is a part of an OSEN
+     */
+    @Test
+    public void verifyOSENUnsupported() {
+        mNetworkConnection.init(mHandler);
+        assertEquals(false, mNetworkConnection.connect(TEST_SSID, TEST_NAI_OSEN));
+    }
+
+    /**
+     * Verifies that connect() API returns false when WifiManager's addNetwork()
+     * returns an invalid network ID
+     */
+    @Test
+    public void verifyNetworkConnectionWhenAddNetworkFails() {
+        when(mWifiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(-1);
+        mNetworkConnection.init(mHandler);
+        assertEquals(false, mNetworkConnection.connect(TEST_SSID, TEST_NAI));
+    }
+
+    /**
+     * Verifies that connect() API returns false when WifiManager's enableNetwork()
+     * fails for the given network ID corresponding to the OSU AP
+     */
+    @Test
+    public void verifyNetworkConnectionWhenEnableNetworkFails() {
+        when(mWifiManager.enableNetwork(TEST_NETWORK_ID, true)).thenReturn(false);
+        mNetworkConnection.init(mHandler);
+        assertEquals(false, mNetworkConnection.connect(TEST_SSID, TEST_NAI));
+        verify(mWifiManager).removeNetwork(TEST_NETWORK_ID);
+    }
+
+    /**
+     * Verifies that network state callbacks are invoked when the NETWORK_STATE_CHANGED intent
+     * is received and when WifiManager has successfully requested connection to the OSU AP.
+     */
+    @Test
+    public void verifyNetworkCallbackInvokedWhenRegistered() {
+        mNetworkConnection.init(mHandler);
+        verify(mContext).registerReceiver(mBroadcastReceiverCaptor.capture(),
+                any(IntentFilter.class), any(), eq(mHandler));
+        mBroadcastReceiver = mBroadcastReceiverCaptor.getValue();
+
+        mNetworkConnection.setEventCallback(mNetworkCallbacks);
+        assertEquals(true, mNetworkConnection.connect(TEST_SSID, TEST_NAI));
+        mLooper.dispatchAll();
+
+        when(mNwInfo.getDetailedState()).thenReturn(NetworkInfo.DetailedState.CONNECTED);
+        TestUtil.sendNetworkStateChanged(mBroadcastReceiver, mContext,
+                mNwInfo, mWifiInfo);
+        verify(mNetworkCallbacks).onConnected(mCurrentNetwork);
+
+        when(mNwInfo.getDetailedState()).thenReturn(NetworkInfo.DetailedState.DISCONNECTED);
+        TestUtil.sendNetworkStateChanged(mBroadcastReceiver, mContext, mNwInfo, mWifiInfo);
+        verify(mNetworkCallbacks).onDisconnected();
+        verify(mWifiManager).removeNetwork(TEST_NETWORK_ID);
+    }
+
+    /**
+     * Verifies that the onConnected() callback is not invoked when the Network State Changed
+     * intent is called when WifiManager has successfully connected to a network that's not the
+     * OSU AP.
+     */
+    @Test
+    public void verifyNetworkDisconnectedCallbackConnectedToAnotherNetwork() {
+        when(mWifiInfo.getNetworkId()).thenReturn(TEST_NETWORK_ID + 1);
+        when(mNwInfo.getDetailedState()).thenReturn(NetworkInfo.DetailedState.CONNECTED);
+        mNetworkConnection.init(mHandler);
+        verify(mContext).registerReceiver(mBroadcastReceiverCaptor.capture(),
+                any(IntentFilter.class), any(), eq(mHandler));
+        mLooper.dispatchAll();
+
+        mBroadcastReceiver = mBroadcastReceiverCaptor.getValue();
+        mNetworkConnection.setEventCallback(mNetworkCallbacks);
+        assertEquals(true, mNetworkConnection.connect(TEST_SSID, TEST_NAI));
+        TestUtil.sendNetworkStateChanged(mBroadcastReceiver, mContext,
+                mNwInfo, mWifiInfo);
+        verify(mNetworkCallbacks, never()).onConnected(any(Network.class));
+        verify(mWifiManager).removeNetwork(TEST_NETWORK_ID);
+    }
+
+    /**
+     * Verifies that WifiManager's removeNetwork() is called when disconnectIfNeeded() is called
+     * on the OSU AP's network ID.
+     */
+    @Test
+    public void verifyNetworkTearDown() {
+        mNetworkConnection.init(mHandler);
+        assertEquals(true, mNetworkConnection.connect(TEST_SSID, TEST_NAI));
+        mNetworkConnection.disconnectIfNeeded();
+        verify(mWifiManager).removeNetwork(TEST_NETWORK_ID);
+    }
+}
+
diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java
index eb0f5ef..e0e6df1 100644
--- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java
@@ -33,6 +33,7 @@
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.any;
 import static org.mockito.Mockito.anyBoolean;
+import static org.mockito.Mockito.anyInt;
 import static org.mockito.Mockito.anyLong;
 import static org.mockito.Mockito.anyMap;
 import static org.mockito.Mockito.doThrow;
@@ -54,11 +55,14 @@
 import android.net.wifi.WifiEnterpriseConfig;
 import android.net.wifi.WifiManager;
 import android.net.wifi.WifiSsid;
+import android.net.wifi.hotspot2.IProvisioningCallback;
 import android.net.wifi.hotspot2.OsuProvider;
 import android.net.wifi.hotspot2.PasspointConfiguration;
 import android.net.wifi.hotspot2.pps.Credential;
 import android.net.wifi.hotspot2.pps.HomeSp;
+import android.os.Looper;
 import android.os.UserHandle;
+import android.os.test.TestLooper;
 import android.test.suitebuilder.annotation.SmallTest;
 import android.util.Base64;
 import android.util.Pair;
@@ -116,6 +120,7 @@
     private static final ANQPNetworkKey TEST_ANQP_KEY = ANQPNetworkKey.buildKey(
             TEST_SSID, TEST_BSSID, TEST_HESSID, TEST_ANQP_DOMAIN_ID);
     private static final int TEST_CREATOR_UID = 1234;
+    private static final int TEST_UID = 1500;
 
     @Mock Context mContext;
     @Mock WifiNative mWifiNative;
@@ -131,6 +136,11 @@
     @Mock WifiConfigStore mWifiConfigStore;
     @Mock PasspointConfigStoreData.DataSource mDataSource;
     @Mock WifiMetrics mWifiMetrics;
+    @Mock OsuNetworkConnection mOsuNetworkConnection;
+    @Mock PasspointProvisioner mPasspointProvisioner;
+    @Mock IProvisioningCallback mCallback;
+
+    TestLooper mLooper;
     PasspointManager mManager;
 
     /** Sets up test. */
@@ -141,6 +151,10 @@
         when(mObjectFactory.makeANQPRequestManager(any(), eq(mClock)))
                 .thenReturn(mAnqpRequestManager);
         when(mObjectFactory.makeCertificateVerifier()).thenReturn(mCertVerifier);
+        when(mObjectFactory.makeOsuNetworkConnection(any(Context.class)))
+                .thenReturn(mOsuNetworkConnection);
+        when(mObjectFactory.makePasspointProvisioner(any(Context.class),
+                any(OsuNetworkConnection.class))).thenReturn(mPasspointProvisioner);
         mManager = new PasspointManager(mContext, mWifiNative, mWifiKeyStore, mClock,
                 mSimAccessor, mObjectFactory, mWifiConfigManager, mWifiConfigStore, mWifiMetrics);
         ArgumentCaptor<PasspointEventHandler.Callbacks> callbacks =
@@ -153,6 +167,7 @@
                 any(WifiKeyStore.class), any(SIMAccessor.class), dataSource.capture());
         mCallbacks = callbacks.getValue();
         mDataSource = dataSource.getValue();
+        mLooper = new TestLooper();
     }
 
     /**
@@ -1365,4 +1380,18 @@
         verify(mWifiMetrics).updateSavedPasspointProfiles(
                 eq(expectedInstalledProviders), eq(expectedConnectedProviders));
     }
+    /**
+     * Verify Passpoint Manager's provisioning APIs by invoking methods in PasspointProvisioner for
+     * initiailization and provisioning a provider.
+     */
+    @Test
+    public void verifyPasspointProvisioner() {
+        mManager.initializeProvisioner(mLooper.getLooper());
+        verify(mPasspointProvisioner).init(any(Looper.class));
+        when(mPasspointProvisioner.startSubscriptionProvisioning(anyInt(), any(OsuProvider.class),
+                any(IProvisioningCallback.class))).thenReturn(true);
+        OsuProvider osuProvider = PasspointProvisioningTestUtil.generateOsuProvider(true);
+        assertEquals(true,
+                mManager.startSubscriptionProvisioning(TEST_UID, osuProvider, mCallback));
+    }
 }
diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProvisionerTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProvisionerTest.java
new file mode 100644
index 0000000..4583531
--- /dev/null
+++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProvisionerTest.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.wifi.hotspot2;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.net.wifi.WifiManager;
+import android.net.wifi.hotspot2.IProvisioningCallback;
+import android.net.wifi.hotspot2.OsuProvider;
+import android.os.test.TestLooper;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+/**
+ * Unit tests for {@link com.android.server.wifi.hotspot2.PasspointProvisioner}.
+ */
+@SmallTest
+public class PasspointProvisionerTest {
+    private static final String TAG = "PasspointProvisionerTest";
+
+    private static final int TEST_UID = 1500;
+
+    private PasspointProvisioner mPasspointProvisioner;
+    private TestLooper mLooper = new TestLooper();
+
+    @Mock Context mContext;
+    @Mock WifiManager mWifiManager;
+    @Mock IProvisioningCallback mCallback;
+
+    @Before
+    public void setUp() throws Exception {
+        MockitoAnnotations.initMocks(this);
+        when(mWifiManager.isWifiEnabled()).thenReturn(true);
+        doReturn(mWifiManager).when(mContext)
+                .getSystemService(eq(Context.WIFI_SERVICE));
+        OsuNetworkConnection osuNetworkConnection = new OsuNetworkConnection(mContext);
+        mPasspointProvisioner = new PasspointProvisioner(mContext, osuNetworkConnection);
+    }
+
+    /**
+     * Verifies that initialization is required before starting subscription
+     * provisioning with a provider
+     */
+    @Test
+    public void verifyInitBeforeStartProvisioning() {
+        OsuProvider osuProvider = PasspointProvisioningTestUtil.generateOsuProvider(true);
+        mPasspointProvisioner.init(mLooper.getLooper());
+        assertTrue(mPasspointProvisioner.startSubscriptionProvisioning(
+                TEST_UID, osuProvider, mCallback));
+    }
+}
diff --git a/tests/wifitests/src/com/android/server/wifi/rtt/RttServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/rtt/RttServiceImplTest.java
index 9d04580..ee8c15f 100644
--- a/tests/wifitests/src/com/android/server/wifi/rtt/RttServiceImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/rtt/RttServiceImplTest.java
@@ -53,6 +53,7 @@
 import android.net.wifi.rtt.RangingRequest;
 import android.net.wifi.rtt.RangingResult;
 import android.net.wifi.rtt.RangingResultCallback;
+import android.net.wifi.rtt.ResponderConfig;
 import android.net.wifi.rtt.WifiRttManager;
 import android.os.Handler;
 import android.os.IBinder;
@@ -201,6 +202,9 @@
 
     @After
     public void tearDown() throws Exception {
+        assertEquals("Binder links != unlinks to death (size)",
+                mBinderLinkToDeathCounter.mUniqueExecs.size(),
+                mBinderUnlinkToDeathCounter.mUniqueExecs.size());
         assertEquals("Binder links != unlinks to death", mBinderLinkToDeathCounter.mUniqueExecs,
                 mBinderUnlinkToDeathCounter.mUniqueExecs);
     }
@@ -253,11 +257,15 @@
     @Test
     public void testRangingFlowUsingAwarePeerHandles() throws Exception {
         RangingRequest request = RttTestUtils.getDummyRangingRequest((byte) 0xA);
-        PeerHandle peerHandle = new PeerHandle(1022);
-        request.mRttPeers.add(new RangingRequest.RttPeerAware(peerHandle));
+        PeerHandle peerHandle1 = new PeerHandle(1022);
+        PeerHandle peerHandle2 = new PeerHandle(1023);
+        request.mRttPeers.add(ResponderConfig.fromWifiAwarePeerHandleWithDefaults(peerHandle1));
+        request.mRttPeers.add(ResponderConfig.fromWifiAwarePeerHandleWithDefaults(peerHandle2));
         Map<Integer, byte[]> peerHandleToMacMap = new HashMap<>();
-        byte[] macAwarePeer = HexEncoding.decode("AABBCCDDEEFF".toCharArray(), false);
-        peerHandleToMacMap.put(1022, macAwarePeer);
+        byte[] macAwarePeer1 = HexEncoding.decode("AABBCCDDEEFF".toCharArray(), false);
+        byte[] macAwarePeer2 = HexEncoding.decode("BBBBBBEEEEEE".toCharArray(), false);
+        peerHandleToMacMap.put(peerHandle1.peerId, macAwarePeer1);
+        peerHandleToMacMap.put(peerHandle2.peerId, macAwarePeer2);
 
         AwareTranslatePeerHandlesToMac answer = new AwareTranslatePeerHandlesToMac(mDefaultUid,
                 peerHandleToMacMap);
@@ -274,13 +282,18 @@
         RangingRequest finalRequest = mRequestCaptor.getValue();
         assertNotEquals("Request to native is not null", null, finalRequest);
         assertEquals("Size of request", request.mRttPeers.size(), finalRequest.mRttPeers.size());
-        assertEquals("Aware peer MAC", macAwarePeer,
-                ((RangingRequest.RttPeerAware) finalRequest.mRttPeers.get(
-                        finalRequest.mRttPeers.size() - 1)).peerMacAddress);
+        assertEquals("Aware peer 1 MAC", macAwarePeer1,
+                finalRequest.mRttPeers.get(finalRequest.mRttPeers.size() - 2).macAddress);
+        assertEquals("Aware peer 2 MAC", macAwarePeer2,
+                finalRequest.mRttPeers.get(finalRequest.mRttPeers.size() - 1).macAddress);
 
-        // issue results
+        // issue results - but remove the one for peer #2
         Pair<List<RttResult>, List<RangingResult>> results =
                 RttTestUtils.getDummyRangingResults(mRequestCaptor.getValue());
+        results.first.remove(results.first.size() - 1);
+        RangingResult removed = results.second.remove(results.second.size() - 1);
+        results.second.add(
+                new RangingResult(RangingResult.STATUS_FAIL, removed.getPeerHandle(), 0, 0, 0, 0));
         mDut.onRangingResults(mIntCaptor.getValue(), results.first);
         mMockLooper.dispatchAll();
 
@@ -607,8 +620,12 @@
         RangingRequest request = RttTestUtils.getDummyRangingRequest((byte) 0);
         Pair<List<RttResult>, List<RangingResult>> results = RttTestUtils.getDummyRangingResults(
                 request);
-        results.first.remove(0);
-        RangingResult removed = results.second.remove(0);
+        results.first.remove(2); // remove a direct AWARE request
+        RangingResult removed = results.second.remove(2);
+        results.second.add(
+                new RangingResult(RangingResult.STATUS_FAIL, removed.getMacAddress(), 0, 0, 0, 0));
+        results.first.remove(0); // remove an AP request
+        removed = results.second.remove(0);
         results.second.add(
                 new RangingResult(RangingResult.STATUS_FAIL, removed.getMacAddress(), 0, 0, 0, 0));
 
@@ -849,6 +866,125 @@
     }
 
     /**
+     * Validate that flooding the service with ranging requests will cause it to start rejecting
+     * rejects from the flooding uid. Single UID.
+     */
+    @Test
+    public void testRejectFloodingRequestsSingleUid() throws Exception {
+        runFloodRequestsTest(true);
+    }
+
+    /**
+     * Validate that flooding the service with ranging requests will cause it to start rejecting
+     * rejects from the flooding uid. WorkSource (all identical).
+     */
+    @Test
+    public void testRejectFloodingRequestsIdenticalWorksources() throws Exception {
+        runFloodRequestsTest(false);
+    }
+
+    /**
+     * Validate that flooding the service with ranging requests will cause it to start rejecting
+     * rejects from the flooding uid. WorkSource (with one constant UID but other varying UIDs -
+     * the varying UIDs should prevent the flood throttle)
+     */
+    @Test
+    public void testDontRejectFloodingRequestsVariousUids() throws Exception {
+        RangingRequest request = RttTestUtils.getDummyRangingRequest((byte) 1);
+        WorkSource ws = new WorkSource(10);
+
+        // 1. issue a request
+        mDut.startRanging(mockIbinder, mPackageName, ws, request, mockCallback);
+        mMockLooper.dispatchAll();
+
+        verify(mockNative).rangeRequest(mIntCaptor.capture(), eq(request));
+        verifyWakeupSet();
+
+        // 2. issue FLOOD LEVEL requests + 10 at various UIDs - no failure expected
+        for (int i = 0; i < RttServiceImpl.MAX_QUEUED_PER_UID + 10; ++i) {
+            WorkSource wsExtra = new WorkSource(ws);
+            wsExtra.add(11 + i);
+            mDut.startRanging(mockIbinder, mPackageName, wsExtra, request, mockCallback);
+        }
+        mMockLooper.dispatchAll();
+
+        // 3. clear queue
+        mDut.disable();
+        mMockLooper.dispatchAll();
+
+        verifyWakeupCancelled();
+        verify(mockNative).rangeCancel(eq(mIntCaptor.getValue()), any());
+        verify(mockCallback, times(RttServiceImpl.MAX_QUEUED_PER_UID + 11)).onRangingFailure(
+                RangingResultCallback.STATUS_CODE_FAIL_RTT_NOT_AVAILABLE);
+
+        verify(mockNative, atLeastOnce()).isReady();
+        verifyNoMoreInteractions(mockNative, mockCallback, mAlarmManager.getAlarmManager());
+    }
+
+    /**
+     * Utility to run configurable tests for flooding range requests.
+     * - Execute a single request
+     * - Flood service with requests: using same ID or same WorkSource
+     * - Provide results (to clear queue) and execute another test: validate succeeds
+     */
+    private void runFloodRequestsTest(boolean useUids) throws Exception {
+        RangingRequest request = RttTestUtils.getDummyRangingRequest((byte) 1);
+        Pair<List<RttResult>, List<RangingResult>> result = RttTestUtils.getDummyRangingResults(
+                request);
+
+        WorkSource ws = new WorkSource();
+        ws.add(10);
+        ws.add(20);
+        ws.add(30);
+
+        InOrder cbInorder = inOrder(mockCallback);
+        InOrder nativeInorder = inOrder(mockNative);
+
+        // 1. issue a request
+        mDut.startRanging(mockIbinder, mPackageName, useUids ? null : ws, request, mockCallback);
+        mMockLooper.dispatchAll();
+
+        nativeInorder.verify(mockNative).rangeRequest(mIntCaptor.capture(), eq(request));
+        verifyWakeupSet();
+
+        // 2. issue FLOOD LEVEL requests + 10: should get 11 failures (10 extra + 1 original)
+        for (int i = 0; i < RttServiceImpl.MAX_QUEUED_PER_UID + 10; ++i) {
+            mDut.startRanging(mockIbinder, mPackageName, useUids ? null : ws, request,
+                    mockCallback);
+        }
+        mMockLooper.dispatchAll();
+
+        cbInorder.verify(mockCallback, times(11)).onRangingFailure(
+                RangingResultCallback.STATUS_CODE_FAIL);
+
+        // 3. provide results
+        mDut.onRangingResults(mIntCaptor.getValue(), result.first);
+        mMockLooper.dispatchAll();
+
+        cbInorder.verify(mockCallback).onRangingResults(result.second);
+        verifyWakeupCancelled();
+
+        nativeInorder.verify(mockNative).rangeRequest(mIntCaptor.capture(), eq(request));
+        verifyWakeupSet();
+
+        // 4. issue a request: don't expect a failure
+        mDut.startRanging(mockIbinder, mPackageName, useUids ? null : ws, request, mockCallback);
+        mMockLooper.dispatchAll();
+
+        // 5. clear queue
+        mDut.disable();
+        mMockLooper.dispatchAll();
+
+        verifyWakeupCancelled();
+        nativeInorder.verify(mockNative).rangeCancel(eq(mIntCaptor.getValue()), any());
+        cbInorder.verify(mockCallback, times(RttServiceImpl.MAX_QUEUED_PER_UID)).onRangingFailure(
+                RangingResultCallback.STATUS_CODE_FAIL_RTT_NOT_AVAILABLE);
+
+        verify(mockNative, atLeastOnce()).isReady();
+        verifyNoMoreInteractions(mockNative, mockCallback, mAlarmManager.getAlarmManager());
+    }
+
+    /**
      * Validate that when Wi-Fi gets disabled (HAL level) the ranging queue gets cleared.
      */
     @Test
diff --git a/tests/wifitests/src/com/android/server/wifi/rtt/RttTestUtils.java b/tests/wifitests/src/com/android/server/wifi/rtt/RttTestUtils.java
index a014878..db3cd17 100644
--- a/tests/wifitests/src/com/android/server/wifi/rtt/RttTestUtils.java
+++ b/tests/wifitests/src/com/android/server/wifi/rtt/RttTestUtils.java
@@ -16,13 +16,12 @@
 
 package com.android.server.wifi.rtt;
 
-import static com.android.server.wifi.util.NativeUtil.macAddressToByteArray;
-
 import android.hardware.wifi.V1_0.RttResult;
 import android.hardware.wifi.V1_0.RttStatus;
 import android.net.wifi.ScanResult;
 import android.net.wifi.rtt.RangingRequest;
 import android.net.wifi.rtt.RangingResult;
+import android.net.wifi.rtt.ResponderConfig;
 import android.util.Pair;
 
 import libcore.util.HexEncoding;
@@ -92,29 +91,19 @@
         List<RangingResult> results = new ArrayList<>();
 
         if (request != null) {
-            for (RangingRequest.RttPeer peer: request.mRttPeers) {
-                RangingResult rangingResult = null;
-                byte[] overrideMac = null;
-                if (peer instanceof RangingRequest.RttPeerAp) {
+            for (ResponderConfig peer: request.mRttPeers) {
+                RangingResult rangingResult;
+                if (peer.peerHandle == null) {
                     rangingResult = new RangingResult(RangingResult.STATUS_SUCCESS,
-                            macAddressToByteArray(
-                                    ((RangingRequest.RttPeerAp) peer).scanResult.BSSID),
-                            rangeCmBase++, rangeStdDevCmBase++, rssiBase++, rangeTimestampBase++);
-                } else if (peer instanceof RangingRequest.RttPeerAware) {
-                    RangingRequest.RttPeerAware awarePeer = (RangingRequest.RttPeerAware) peer;
-                    if (awarePeer.peerHandle != null) {
-                        rangingResult = new RangingResult(RangingResult.STATUS_SUCCESS,
-                                awarePeer.peerHandle, rangeCmBase++, rangeStdDevCmBase++,
-                                rssiBase++, rangeTimestampBase++);
-                        overrideMac = awarePeer.peerMacAddress;
-                    } else {
-                        rangingResult = new RangingResult(RangingResult.STATUS_SUCCESS,
-                                awarePeer.peerMacAddress, rangeCmBase++, rangeStdDevCmBase++,
-                                rssiBase++, rangeTimestampBase++);
-                    }
+                            peer.macAddress, rangeCmBase++, rangeStdDevCmBase++, rssiBase++,
+                            rangeTimestampBase++);
+                } else {
+                    rangingResult = new RangingResult(RangingResult.STATUS_SUCCESS,
+                            peer.peerHandle, rangeCmBase++, rangeStdDevCmBase++, rssiBase++,
+                            rangeTimestampBase++);
                 }
                 results.add(rangingResult);
-                halResults.add(getMatchingRttResult(rangingResult, overrideMac));
+                halResults.add(getMatchingRttResult(rangingResult, peer.macAddress));
             }
         } else {
             results.add(new RangingResult(RangingResult.STATUS_SUCCESS,