1 /* 2 * Copyright (C) 2024 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 com.android.server.wifi.util; 18 19 import android.net.wifi.WifiManager; 20 import android.util.SparseArray; 21 22 import java.util.BitSet; 23 24 /** 25 * Utilities for formatting the WifiManager.FEATURE_ BitSet as a String. 26 */ 27 public class FeatureBitsetUtils { 28 // All WifiManager.WIFI_FEATURE_ values should be added to the ALL_FEATURES map below 29 // to keep the feature logging up to date. 30 protected static final SparseArray ALL_FEATURES = new SparseArray() { 31 { 32 append(WifiManager.WIFI_FEATURE_INFRA, "WIFI_FEATURE_INFRA"); 33 append(WifiManager.WIFI_FEATURE_PASSPOINT, "WIFI_FEATURE_PASSPOINT"); 34 append(WifiManager.WIFI_FEATURE_P2P, "WIFI_FEATURE_P2P"); 35 append(WifiManager.WIFI_FEATURE_MOBILE_HOTSPOT, "WIFI_FEATURE_MOBILE_HOTSPOT"); 36 append(WifiManager.WIFI_FEATURE_SCANNER, "WIFI_FEATURE_SCANNER"); 37 append(WifiManager.WIFI_FEATURE_AWARE, "WIFI_FEATURE_AWARE"); 38 append(WifiManager.WIFI_FEATURE_D2D_RTT, "WIFI_FEATURE_D2D_RTT"); 39 append(WifiManager.WIFI_FEATURE_D2AP_RTT, "WIFI_FEATURE_D2AP_RTT"); 40 append(WifiManager.WIFI_FEATURE_PNO, "WIFI_FEATURE_PNO"); 41 append(WifiManager.WIFI_FEATURE_TDLS, "WIFI_FEATURE_TDLS"); 42 append(WifiManager.WIFI_FEATURE_TDLS_OFFCHANNEL, "WIFI_FEATURE_TDLS_OFFCHANNEL"); 43 append(WifiManager.WIFI_FEATURE_AP_STA, "WIFI_FEATURE_AP_STA"); 44 append(WifiManager.WIFI_FEATURE_LINK_LAYER_STATS, "WIFI_FEATURE_LINK_LAYER_STATS"); 45 append(WifiManager.WIFI_FEATURE_LOGGER, "WIFI_FEATURE_LOGGER"); 46 append(WifiManager.WIFI_FEATURE_RSSI_MONITOR, "WIFI_FEATURE_RSSI_MONITOR"); 47 append(WifiManager.WIFI_FEATURE_MKEEP_ALIVE, "WIFI_FEATURE_MKEEP_ALIVE"); 48 append(WifiManager.WIFI_FEATURE_CONFIG_NDO, "WIFI_FEATURE_CONFIG_NDO"); 49 append(WifiManager.WIFI_FEATURE_CONTROL_ROAMING, "WIFI_FEATURE_CONTROL_ROAMING"); 50 append(WifiManager.WIFI_FEATURE_IE_WHITELIST, "WIFI_FEATURE_IE_WHITELIST"); 51 append(WifiManager.WIFI_FEATURE_SCAN_RAND, "WIFI_FEATURE_SCAN_RAND"); 52 append(WifiManager.WIFI_FEATURE_TX_POWER_LIMIT, "WIFI_FEATURE_TX_POWER_LIMIT"); 53 append(WifiManager.WIFI_FEATURE_WPA3_SAE, "WIFI_FEATURE_WPA3_SAE"); 54 append(WifiManager.WIFI_FEATURE_WPA3_SUITE_B, "WIFI_FEATURE_WPA3_SUITE_B"); 55 append(WifiManager.WIFI_FEATURE_OWE, "WIFI_FEATURE_OWE"); 56 append(WifiManager.WIFI_FEATURE_LOW_LATENCY, "WIFI_FEATURE_LOW_LATENCY"); 57 append(WifiManager.WIFI_FEATURE_DPP, "WIFI_FEATURE_DPP"); 58 append(WifiManager.WIFI_FEATURE_P2P_RAND_MAC, "WIFI_FEATURE_P2P_RAND_MAC"); 59 append(WifiManager.WIFI_FEATURE_CONNECTED_RAND_MAC, "WIFI_FEATURE_CONNECTED_RAND_MAC"); 60 append(WifiManager.WIFI_FEATURE_AP_RAND_MAC, "WIFI_FEATURE_AP_RAND_MAC"); 61 append(WifiManager.WIFI_FEATURE_MBO, "WIFI_FEATURE_MBO"); 62 append(WifiManager.WIFI_FEATURE_OCE, "WIFI_FEATURE_OCE"); 63 append(WifiManager.WIFI_FEATURE_WAPI, "WIFI_FEATURE_WAPI"); 64 append(WifiManager.WIFI_FEATURE_FILS_SHA256, "WIFI_FEATURE_FILS_SHA256"); 65 append(WifiManager.WIFI_FEATURE_FILS_SHA384, "WIFI_FEATURE_FILS_SHA384"); 66 append(WifiManager.WIFI_FEATURE_SAE_PK, "WIFI_FEATURE_SAE_PK"); 67 append(WifiManager.WIFI_FEATURE_STA_BRIDGED_AP, "WIFI_FEATURE_STA_BRIDGED_AP"); 68 append(WifiManager.WIFI_FEATURE_BRIDGED_AP, "WIFI_FEATURE_BRIDGED_AP"); 69 append(WifiManager.WIFI_FEATURE_INFRA_60G, "WIFI_FEATURE_INFRA_60G"); 70 append(WifiManager.WIFI_FEATURE_ADDITIONAL_STA_LOCAL_ONLY, 71 "WIFI_FEATURE_ADDITIONAL_STA_LOCAL_ONLY"); 72 append(WifiManager.WIFI_FEATURE_ADDITIONAL_STA_MBB, "WIFI_FEATURE_ADDITIONAL_STA_MBB"); 73 append(WifiManager.WIFI_FEATURE_ADDITIONAL_STA_RESTRICTED, 74 "WIFI_FEATURE_ADDITIONAL_STA_RESTRICTED"); 75 append(WifiManager.WIFI_FEATURE_DPP_ENROLLEE_RESPONDER, 76 "WIFI_FEATURE_DPP_ENROLLEE_RESPONDER"); 77 append(WifiManager.WIFI_FEATURE_PASSPOINT_TERMS_AND_CONDITIONS, 78 "WIFI_FEATURE_PASSPOINT_TERMS_AND_CONDITIONS"); 79 append(WifiManager.WIFI_FEATURE_SAE_H2E, "WIFI_FEATURE_SAE_H2E"); 80 append(WifiManager.WIFI_FEATURE_WFD_R2, "WIFI_FEATURE_WFD_R2"); 81 append(WifiManager.WIFI_FEATURE_DECORATED_IDENTITY, "WIFI_FEATURE_DECORATED_IDENTITY"); 82 append(WifiManager.WIFI_FEATURE_TRUST_ON_FIRST_USE, "WIFI_FEATURE_TRUST_ON_FIRST_USE"); 83 append(WifiManager.WIFI_FEATURE_ADDITIONAL_STA_MULTI_INTERNET, 84 "WIFI_FEATURE_ADDITIONAL_STA_MULTI_INTERNET"); 85 append(WifiManager.WIFI_FEATURE_DPP_AKM, "WIFI_FEATURE_DPP_AKM"); 86 append(WifiManager.WIFI_FEATURE_SET_TLS_MINIMUM_VERSION, 87 "WIFI_FEATURE_SET_TLS_MINIMUM_VERSION"); 88 append(WifiManager.WIFI_FEATURE_TLS_V1_3, "WIFI_FEATURE_TLS_V1_3"); 89 append(WifiManager.WIFI_FEATURE_DUAL_BAND_SIMULTANEOUS, 90 "WIFI_FEATURE_DUAL_BAND_SIMULTANEOUS"); 91 append(WifiManager.WIFI_FEATURE_T2LM_NEGOTIATION, "WIFI_FEATURE_T2LM_NEGOTIATION"); 92 append(WifiManager.WIFI_FEATURE_WEP, "WIFI_FEATURE_WEP"); 93 append(WifiManager.WIFI_FEATURE_WPA_PERSONAL, "WIFI_FEATURE_WPA_PERSONAL"); 94 append(WifiManager.WIFI_FEATURE_AGGRESSIVE_ROAMING_MODE_SUPPORT, 95 "WIFI_FEATURE_AGGRESSIVE_ROAMING_MODE_SUPPORT"); 96 append(WifiManager.WIFI_FEATURE_D2D_WHEN_INFRA_STA_DISABLED, 97 "WIFI_FEATURE_D2D_WHEN_INFRA_STA_DISABLED"); 98 append(WifiManager.WIFI_FEATURE_SOFTAP_MLO, "WIFI_FEATURE_SOFTAP_MLO"); 99 append(WifiManager.WIFI_FEATURE_MULTIPLE_MLD_ON_SAP, 100 "WIFI_FEATURE_MULTIPLE_MLD_ON_SAP"); 101 } 102 }; 103 104 // Index of the newest available feature. This will be calculated automatically 105 // in the static block below. 106 protected static final int NEWEST_FEATURE_INDEX; 107 static { 108 int newestFeatureIndex = 0; 109 for (int i = 0; i < ALL_FEATURES.size(); i++) { 110 newestFeatureIndex = Math.max(ALL_FEATURES.keyAt(i), newestFeatureIndex); 111 } 112 NEWEST_FEATURE_INDEX = newestFeatureIndex; 113 } 114 115 /** 116 * Format a BitSet of WifiManager.WIFI_FEATURE_ features as a String. 117 */ formatSupportedFeatures(BitSet supportedFeatures)118 public static String formatSupportedFeatures(BitSet supportedFeatures) { 119 if (supportedFeatures == null || supportedFeatures.isEmpty()) return "[]"; 120 StringBuilder formatted = new StringBuilder("["); 121 for (int i = 0; i < ALL_FEATURES.size(); i++) { 122 int capabilityIndex = ALL_FEATURES.keyAt(i); 123 if (supportedFeatures.get(capabilityIndex)) { 124 String capabilityName = (String) ALL_FEATURES.valueAt(i); 125 formatted.append(capabilityName); 126 formatted.append(", "); 127 } 128 } 129 130 // Include a warning if an unrecognized feature is supported. It may have been added 131 // to WifiManager without updating this file. 132 if (supportedFeatures.length() > NEWEST_FEATURE_INDEX + 1) { 133 formatted.append("+ UNRECOGNIZED FEATURE(S)"); 134 } else { 135 // Otherwise, trim the last 2 characters (", ") from the string 136 formatted.setLength(formatted.length() - 2); 137 } 138 formatted.append("]"); 139 return formatted.toString(); 140 } 141 } 142