1 /* 2 * Copyright (C) 2019 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; 18 19 import android.provider.DeviceConfig; 20 import android.util.ArraySet; 21 22 import java.util.Set; 23 import java.util.concurrent.Executor; 24 import java.util.concurrent.TimeUnit; 25 26 /** 27 * This class allows getting all configurable flags from DeviceConfig. 28 */ 29 public class DeviceConfigFacade { 30 private static final int DEFAULT_ABNORMAL_CONNECTION_DURATION_MS = 31 (int) TimeUnit.SECONDS.toMillis(30); 32 private static final String NAMESPACE = "wifi"; 33 // Default duration for evaluating Wifi condition to trigger a data stall 34 // measured in milliseconds 35 public static final int DEFAULT_DATA_STALL_DURATION_MS = 1500; 36 // Default threshold of Tx throughput below which to trigger a data stall measured in Mbps 37 public static final int DEFAULT_DATA_STALL_TX_TPUT_THR_MBPS = 2; 38 // Default threshold of Rx throughput below which to trigger a data stall measured in Mbps 39 public static final int DEFAULT_DATA_STALL_RX_TPUT_THR_MBPS = 2; 40 // Default threshold of Tx packet error rate above which to trigger a data stall in percentage 41 public static final int DEFAULT_DATA_STALL_TX_PER_THR = 90; 42 // Default threshold of CCA level above which to trigger a data stall in percentage 43 public static final int DEFAULT_DATA_STALL_CCA_LEVEL_THR = 100; 44 45 /** 46 * Gets the feature flag for reporting abnormally long connections. 47 */ isAbnormalConnectionBugreportEnabled()48 public boolean isAbnormalConnectionBugreportEnabled() { 49 return DeviceConfig.getBoolean(NAMESPACE, "abnormal_connection_bugreport_enabled", false); 50 } 51 52 /** 53 * Gets the threshold for classifying abnormally long connections. 54 */ getAbnormalConnectionDurationMs()55 public int getAbnormalConnectionDurationMs() { 56 return DeviceConfig.getInt(NAMESPACE, "abnormal_connection_duration_ms", 57 DEFAULT_ABNORMAL_CONNECTION_DURATION_MS); 58 } 59 60 /** 61 * Adds a listener that will be run on the specified executor. 62 * @param executor 63 * @param onPropertiesChangedListener 64 */ addOnPropertiesChangedListener(Executor executor, DeviceConfig.OnPropertiesChangedListener onPropertiesChangedListener)65 public void addOnPropertiesChangedListener(Executor executor, 66 DeviceConfig.OnPropertiesChangedListener onPropertiesChangedListener) { 67 DeviceConfig.addOnPropertiesChangedListener(NAMESPACE, executor, 68 onPropertiesChangedListener); 69 } 70 71 /** 72 * Gets the duration of evaluating Wifi condition to trigger a data stall. 73 */ getDataStallDurationMs()74 public int getDataStallDurationMs() { 75 return DeviceConfig.getInt(NAMESPACE, "data_stall_duration_ms", 76 DEFAULT_DATA_STALL_DURATION_MS); 77 } 78 79 /** 80 * Gets the threshold of Tx throughput below which to trigger a data stall. 81 */ getDataStallTxTputThrMbps()82 public int getDataStallTxTputThrMbps() { 83 return DeviceConfig.getInt(NAMESPACE, "data_stall_tx_tput_thr_mbps", 84 DEFAULT_DATA_STALL_TX_TPUT_THR_MBPS); 85 } 86 87 /** 88 * Gets the threshold of Rx throughput below which to trigger a data stall. 89 */ getDataStallRxTputThrMbps()90 public int getDataStallRxTputThrMbps() { 91 return DeviceConfig.getInt(NAMESPACE, "data_stall_rx_tput_thr_mbps", 92 DEFAULT_DATA_STALL_RX_TPUT_THR_MBPS); 93 } 94 95 /** 96 * Gets the threshold of Tx packet error rate above which to trigger a data stall. 97 */ getDataStallTxPerThr()98 public int getDataStallTxPerThr() { 99 return DeviceConfig.getInt(NAMESPACE, "data_stall_tx_per_thr", 100 DEFAULT_DATA_STALL_TX_PER_THR); 101 } 102 103 /** 104 * Gets the threshold of CCA level above which to trigger a data stall. 105 */ getDataStallCcaLevelThr()106 public int getDataStallCcaLevelThr() { 107 return DeviceConfig.getInt(NAMESPACE, "data_stall_cca_level_thr", 108 DEFAULT_DATA_STALL_CCA_LEVEL_THR); 109 } 110 111 /** 112 * Gets the Set of SSIDs in the flaky SSID hotlist. 113 */ getRandomizationFlakySsidHotlist()114 public Set<String> getRandomizationFlakySsidHotlist() { 115 String ssidHotlist = DeviceConfig.getString(NAMESPACE, 116 "randomization_flaky_ssid_hotlist", ""); 117 Set<String> result = new ArraySet<String>(); 118 String[] ssidHotlistArray = ssidHotlist.split(","); 119 for (int i = 0; i < ssidHotlistArray.length; i++) { 120 String cur = ssidHotlistArray[i]; 121 if (cur.length() == 0) { 122 continue; 123 } 124 // Make sure the SSIDs are quoted. Server side should not quote ssids. 125 result.add("\"" + cur + "\""); 126 } 127 return result; 128 } 129 } 130