1 package com.android.settings.wifi.tether; 2 3 import android.net.wifi.WifiClient; 4 import android.net.wifi.WifiManager; 5 import android.os.Handler; 6 import android.os.HandlerExecutor; 7 8 import java.util.List; 9 10 /** 11 * Wrapper for {@link android.net.wifi.WifiManager.SoftApCallback} to pass the robo test 12 */ 13 public class WifiTetherSoftApManager { 14 15 private WifiManager mWifiManager; 16 private WifiTetherSoftApCallback mWifiTetherSoftApCallback; 17 18 private WifiManager.SoftApCallback mSoftApCallback = new WifiManager.SoftApCallback() { 19 @Override 20 public void onStateChanged(int state, int failureReason) { 21 mWifiTetherSoftApCallback.onStateChanged(state, failureReason); 22 } 23 24 @Override 25 public void onConnectedClientsChanged(List<WifiClient> clients) { 26 mWifiTetherSoftApCallback.onConnectedClientsChanged(clients); 27 } 28 }; 29 private Handler mHandler; 30 WifiTetherSoftApManager(WifiManager wifiManager, WifiTetherSoftApCallback wifiTetherSoftApCallback)31 WifiTetherSoftApManager(WifiManager wifiManager, 32 WifiTetherSoftApCallback wifiTetherSoftApCallback) { 33 mWifiManager = wifiManager; 34 mWifiTetherSoftApCallback = wifiTetherSoftApCallback; 35 mHandler = new Handler(); 36 } 37 registerSoftApCallback()38 public void registerSoftApCallback() { 39 mWifiManager.registerSoftApCallback(new HandlerExecutor(mHandler), mSoftApCallback); 40 } 41 unRegisterSoftApCallback()42 public void unRegisterSoftApCallback() { 43 mWifiManager.unregisterSoftApCallback(mSoftApCallback); 44 } 45 46 public interface WifiTetherSoftApCallback { onStateChanged(int state, int failureReason)47 void onStateChanged(int state, int failureReason); 48 49 /** 50 * Called when the connected clients to soft AP changes. 51 * 52 * @param clients the currently connected clients 53 */ onConnectedClientsChanged(List<WifiClient> clients)54 void onConnectedClientsChanged(List<WifiClient> clients); 55 } 56 } 57