1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.wifi.mockwifi.nl80211; 18 19 import android.content.Context; 20 import android.net.wifi.nl80211.DeviceWiphyCapabilities; 21 import android.net.wifi.nl80211.IApInterface; 22 import android.net.wifi.nl80211.IClientInterface; 23 import android.net.wifi.nl80211.IInterfaceEventCallback; 24 import android.net.wifi.nl80211.IWificond; 25 import android.net.wifi.nl80211.IWificondEventCallback; 26 import android.os.IBinder; 27 import android.wifi.mockwifi.MockWifiModemService; 28 29 import java.util.HashMap; 30 import java.util.HashSet; 31 import java.util.List; 32 import java.util.Set; 33 34 public class WifiNL80211ManagerImp extends IWificond.Stub { 35 private static final String TAG = "WifiNL80211ManagerImp"; 36 37 private static Context sContext; 38 Set<String> mConfiguredMethodSet; 39 private HashMap<String, IClientInterfaceImp> mMockIClientInterfaces = new HashMap<>(); 40 WifiNL80211ManagerImp(Context context)41 public WifiNL80211ManagerImp(Context context) { 42 sContext = context; 43 mConfiguredMethodSet = new HashSet<>(); 44 } 45 46 @Override createApInterface(String ifaceName)47 public IApInterface createApInterface(String ifaceName) { 48 // TODO: Mock it when we have a use (test) case. 49 return null; 50 } 51 52 @Override createClientInterface(String ifaceName)53 public IClientInterface createClientInterface(String ifaceName) { 54 IClientInterfaceImp mockIClientInterface = new IClientInterfaceImp(ifaceName); 55 mMockIClientInterfaces.put(ifaceName, mockIClientInterface); 56 return mockIClientInterface; 57 } 58 59 @Override tearDownApInterface(String ifaceName)60 public boolean tearDownApInterface(String ifaceName) { 61 // TODO: Mock it when we have a use (test) case. 62 return true; 63 } 64 65 @Override tearDownClientInterface(String ifaceName)66 public boolean tearDownClientInterface(String ifaceName) { 67 return mMockIClientInterfaces.remove(ifaceName) != null; 68 } 69 70 @Override tearDownInterfaces()71 public void tearDownInterfaces() { 72 // TODO: Mock it when we have a use (test) case. 73 } 74 75 @Override getAvailable2gChannels()76 public int[] getAvailable2gChannels() { 77 // TODO: Mock it when we have a use (test) case. 78 return null; 79 } 80 81 @Override getAvailable5gNonDFSChannels()82 public int[] getAvailable5gNonDFSChannels() { 83 // TODO: Mock it when we have a use (test) case. 84 return null; 85 } 86 87 @Override getAvailableDFSChannels()88 public int[] getAvailableDFSChannels() { 89 // TODO: Mock it when we have a use (test) case. 90 return null; 91 } 92 93 @Override getAvailable6gChannels()94 public int[] getAvailable6gChannels() { 95 // TODO: Mock it when we have a use (test) case. 96 return null; 97 } 98 99 @Override getAvailable60gChannels()100 public int[] getAvailable60gChannels() { 101 // TODO: Mock it when we have a use (test) case. 102 return null; 103 } 104 105 @Override registerWificondEventCallback(IWificondEventCallback callback)106 public void registerWificondEventCallback(IWificondEventCallback callback) { 107 // TODO: Mock it when we have a use (test) case. 108 } 109 110 @Override unregisterWificondEventCallback(IWificondEventCallback callback)111 public void unregisterWificondEventCallback(IWificondEventCallback callback) { 112 // TODO: Mock it when we have a use (test) case. 113 } 114 115 @Override getDeviceWiphyCapabilities(String ifaceName)116 public DeviceWiphyCapabilities getDeviceWiphyCapabilities(String ifaceName) { 117 // TODO: Mock it when we have a use (test) case. 118 return null; 119 } 120 121 @Override notifyCountryCodeChanged()122 public void notifyCountryCodeChanged() { 123 // TODO: Mock it when we have a use (test) case. 124 } 125 126 // CHECKSTYLE:OFF Generated code 127 @Override UnregisterCallback(IInterfaceEventCallback callback)128 public void UnregisterCallback(IInterfaceEventCallback callback) { 129 // TODO: Mock it when we have a use (test) case. 130 } 131 132 @Override RegisterCallback(IInterfaceEventCallback callback)133 public void RegisterCallback(IInterfaceEventCallback callback) { 134 // TODO: Mock it when we have a use (test) case. 135 } 136 137 @Override GetClientInterfaces()138 public List<IBinder> GetClientInterfaces() { 139 // TODO: Mock it when we have a use (test) case. 140 return null; 141 } 142 143 @Override GetApInterfaces()144 public List<IBinder> GetApInterfaces() { 145 // TODO: Mock it when we have a use (test) case. 146 return null; 147 } 148 // CHECKSTYLE:ON Generated code 149 configureSignalPoll(String ifaceName, int currentRssiDbm, int txBitrateMbps, int rxBitrateMbps, int associationFrequencyMHz)150 public boolean configureSignalPoll(String ifaceName, int currentRssiDbm, int txBitrateMbps, 151 int rxBitrateMbps, int associationFrequencyMHz) { 152 IClientInterfaceImp clientInterface = mMockIClientInterfaces.get(ifaceName); 153 if (clientInterface == null) return false; 154 mConfiguredMethodSet.add("signalPoll"); 155 clientInterface.setRxBitrateMbps(rxBitrateMbps); 156 clientInterface.setTxBitrateMbps(txBitrateMbps); 157 clientInterface.setCurrentRssiDbm(currentRssiDbm); 158 clientInterface.setAssociationFrequencyMHz(associationFrequencyMHz); 159 return true; 160 } 161 getConfiguredMethods()162 public String getConfiguredMethods() { 163 StringBuilder sbuf = new StringBuilder(); 164 for (String methodName : mConfiguredMethodSet) { 165 sbuf.append(TAG + MockWifiModemService.CLASS_IDENTIFIER + methodName 166 + MockWifiModemService.METHOD_IDENTIFIER); 167 } 168 return sbuf.toString(); 169 } 170 } 171