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.wifitrackerlib; 18 19 import android.net.wifi.ScanResult; 20 import android.net.wifi.WifiConfiguration; 21 import android.net.wifi.WifiSsid; 22 23 import java.nio.charset.StandardCharsets; 24 25 /** 26 * Utility methods for testing purposes. 27 */ 28 class TestUtils { 29 public static final int GOOD_RSSI = -50; 30 public static final int OKAY_RSSI = -60; 31 public static final int BAD_RSSI = -70; 32 33 public static final int GOOD_LEVEL = 5; 34 public static final int OKAY_LEVEL = 3; 35 public static final int BAD_LEVEL = 1; 36 37 /** 38 * Creates a mock scan result with SSID, BSSID, and timestamp. 39 */ buildScanResult(String utf8Ssid, String bssid, long timestampMillis)40 static ScanResult buildScanResult(String utf8Ssid, String bssid, long timestampMillis) { 41 final ScanResult result = new ScanResult(); 42 result.SSID = utf8Ssid; 43 if (utf8Ssid != null) { 44 result.setWifiSsid(WifiSsid.fromBytes(utf8Ssid.getBytes(StandardCharsets.UTF_8))); 45 } 46 result.BSSID = bssid; 47 result.timestamp = timestampMillis * 1000; 48 result.capabilities = ""; 49 return result; 50 } 51 buildScanResult( String utf8Ssid, String bssid, long timestampMillis, int rssi)52 static ScanResult buildScanResult( 53 String utf8Ssid, String bssid, long timestampMillis, int rssi) { 54 final ScanResult result = buildScanResult(utf8Ssid, bssid, timestampMillis); 55 result.level = rssi; 56 result.capabilities = ""; 57 return result; 58 } 59 buildScanResult( String utf8Ssid, String bssid, long timestampMillis, String securityTypesString)60 static ScanResult buildScanResult( 61 String utf8Ssid, String bssid, long timestampMillis, String securityTypesString) { 62 final ScanResult result = buildScanResult(utf8Ssid, bssid, timestampMillis); 63 result.capabilities = securityTypesString; 64 return result; 65 } 66 buildWifiConfiguration(String utf8Ssid)67 static WifiConfiguration buildWifiConfiguration(String utf8Ssid) { 68 final WifiConfiguration config = new WifiConfiguration(); 69 config.SSID = "\"" + utf8Ssid + "\""; 70 return config; 71 } 72 } 73