RF Sentinel (RFSentinel): free, open-source police detector app for Android. Spots police body cams, Flock ALPR cameras, AirTag trackers, Remote ID drones, smart glasses and fake cell towers from Bluetooth LE and WiFi. No root.
Kotlin airtagalprandroidandroid-autoanti-surveillancebluetooth-low-energybody-cameracounter-surveillancedrone-detectionflock-safetyimsi-catcher-detectorpolice-detectorpolice-scannerprivacyremote-idrtl-sdrsdrsurveillance-detectiontracker-detectionwifi
Whitelist WiFi networks by name
CIS-C0e9fe26bf1a0c
diff --git a/app/src/main/java/com/rfsentinel/app/RFSentinelApp.kt b/app/src/main/java/com/rfsentinel/app/RFSentinelApp.ktindex ea9cfdc..9597893 100644--- a/app/src/main/java/com/rfsentinel/app/RFSentinelApp.kt+++ b/app/src/main/java/com/rfsentinel/app/RFSentinelApp.kt@@ -62,6 +62,7 @@ class RFSentinelApp : Application() {OuiWatchlist.load(this)WhitelistCache.start(this, appScope)appScope.launch(Dispatchers.IO) { com.rfsentinel.app.data.TrackerMutes.load(this@RFSentinelApp) }+ appScope.launch(Dispatchers.IO) { com.rfsentinel.app.data.TrustedNetworks.load(this@RFSentinelApp) }appScope.launch(Dispatchers.IO) { com.rfsentinel.app.alpr.IgnoredCameras.load(this@RFSentinelApp) }CarState.start(this)// ~60k vendor rows: load off the main thread; lookups return null until ready.diff --git a/app/src/main/java/com/rfsentinel/app/data/TrustedNetworks.kt b/app/src/main/java/com/rfsentinel/app/data/TrustedNetworks.ktnew file mode 100644index 0000000..7626efa--- /dev/null+++ b/app/src/main/java/com/rfsentinel/app/data/TrustedNetworks.kt@@ -0,0 +1,82 @@+package com.rfsentinel.app.data++import android.content.Context+import com.google.gson.Gson+import com.google.gson.reflect.TypeToken+import com.rfsentinel.app.service.DeviceRegistry++/**+ * WiFi networks trusted by name (Whitelist > Network names): every access point whose SSID matches a rule+ * is treated like a whitelisted address. A router that is on every bus of a fleet ("LAUSD-Bus-123") is+ * trusted once, by its name, rather than address by address.+ *+ * Pure matching in [matches] (unit-tested); this object keeps the rules and the addresses they caught.+ */+object TrustedNetworks {++ data class Rule(+ val text: String,+ /** The whole SSID must be [text]; else any SSID containing it matches. Case never matters. */+ val exact: Boolean+ ) {+ val label get() = if (exact) "Exact name" else "Name contains"+ }++ private const val PREFS = "trusted_networks"+ private const val KEY = "rules"+ private val gson = Gson()+ private val type = object : TypeToken<List<Rule>>() {}.type++ @Volatile var rules: List<Rule> = emptyList()+ private set+ /** Access points heard with a matching SSID (an address that later broadcasts another name drops out). */+ private val trusted = java.util.concurrent.ConcurrentHashMap.newKeySet<String>()++ fun matches(rules: List<Rule>, ssid: String?): Boolean {+ val name = ssid?.trim().orEmpty()+ if (name.isEmpty()) return false+ return rules.any { r -> if (r.exact) name.equals(r.text, ignoreCase = true) else name.contains(r.text, ignoreCase = true) }+ }++ fun contains(mac: String): Boolean = mac in trusted++ /** The rule that trusts this network name, if any. */+ fun ruleFor(ssid: String?): Rule? = rules.firstOrNull { matches(listOf(it), ssid) }++ /** A WiFi access point was heard: trusted while its SSID matches (a hidden SSID keeps what it had). */+ fun onSeen(mac: String, ssid: String?) {+ if (ssid.isNullOrBlank()) return+ if (matches(rules, ssid)) trusted.add(mac) else trusted.remove(mac)+ }++ fun load(context: Context) {+ rules = runCatching {+ gson.fromJson<List<Rule>>(context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).getString(KEY, null), type)+ }.getOrNull().orEmpty()+ recheck()+ }++ /** Adds [rule], or puts it in place of [replacing] (an edit). */+ fun save(context: Context, rule: Rule, replacing: Rule? = null) {+ val clean = rule.copy(text = rule.text.trim())+ if (clean.text.isEmpty()) return+ val others = rules.filterNot { it == replacing || it.text.equals(clean.text, ignoreCase = true) && it.exact == clean.exact }+ write(context, others + clean)+ }++ fun remove(context: Context, rule: Rule) = write(context, rules.filterNot { it == rule })++ private fun write(context: Context, list: List<Rule>) {+ rules = list.sortedBy { it.text.lowercase() }+ context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit().putString(KEY, gson.toJson(rules)).apply()+ recheck()+ }++ /** The rules changed: the networks in range are trusted (or not) at once, not at their next beacon. */+ private fun recheck() {+ val now = rules+ val caught = DeviceRegistry.snapshot().filter { it.source == com.rfsentinel.app.detect.Advert.Source.WIFI && matches(now, it.name) }.map { it.mac }+ trusted.retainAll(caught.toSet())+ trusted.addAll(caught)+ }+}diff --git a/app/src/main/java/com/rfsentinel/app/data/WhitelistCache.kt b/app/src/main/java/com/rfsentinel/app/data/WhitelistCache.ktindex 43c7489..5ddf3ef 100644--- a/app/src/main/java/com/rfsentinel/app/data/WhitelistCache.kt+++ b/app/src/main/java/com/rfsentinel/app/data/WhitelistCache.kt@@ -13,8 +13,8 @@ object WhitelistCache {@Volatileprivate var macs: Set<String> = emptySet()- /** Trusted devices, plus trackers the user chose to ignore (see [TrackerMutes]). */- fun contains(mac: String): Boolean = mac in macs || TrackerMutes.isMuted(mac)+ /** Trusted devices, trackers the user chose to ignore (see [TrackerMutes]) and WiFi networks trusted by name ([TrustedNetworks]). */+ fun contains(mac: String): Boolean = mac in macs || TrackerMutes.isMuted(mac) || TrustedNetworks.contains(mac)/** Only the user's whitelist table (not ignored trackers). */fun inTable(mac: String): Boolean = mac in macsdiff --git a/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt b/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.ktindex b8cf9ff..80b683a 100644--- a/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt+++ b/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt@@ -588,6 +588,7 @@ class ScanForegroundService : Service() {val now = a.timestampval mac = a.macif (OuiWatchlist.version != watchlistVersion) recheckWatchlist(now)+ if (a.isWifi) com.rfsentinel.app.data.TrustedNetworks.onSeen(mac, a.name) // before anything asks whether it's whitelisted// Remote ID messages arrive one type at a time; merge every packet.var remoteId: RemoteId.Info? = reportedRemoteIddiff --git a/app/src/main/java/com/rfsentinel/app/ui/DeviceActions.kt b/app/src/main/java/com/rfsentinel/app/ui/DeviceActions.ktindex f9970bc..86150d3 100644--- a/app/src/main/java/com/rfsentinel/app/ui/DeviceActions.kt+++ b/app/src/main/java/com/rfsentinel/app/ui/DeviceActions.kt@@ -16,6 +16,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilderimport com.rfsentinel.app.BuildConfigimport com.rfsentinel.app.data.AppDatabaseimport com.rfsentinel.app.data.Favorites+import com.rfsentinel.app.data.TrustedNetworksimport com.rfsentinel.app.data.WhitelistCacheimport com.rfsentinel.app.data.WhitelistEntityimport com.rfsentinel.app.databinding.DialogAddWatchlistBinding@@ -74,14 +75,16 @@ object DeviceActions {} else {items += "Add to watchlist..." to { addToWatchlist(activity, mac, snap?.name, snap?.advert?.isWifi == true) }}+ val trustedName = !whitelisted && TrustedNetworks.contains(mac)when {+ trustedName -> items += "Remove network name from whitelist" to { untrustNetwork(activity, ssidOf(snap)) }ignoredTracker -> items += "Stop ignoring this tracker" to {com.rfsentinel.app.data.TrackerMutes.unmute(activity, mac)toast(activity, "Tracker no longer ignored")}rotatingTracker && !whitelisted -> items += "Ignore this tracker..." to { ignoreTracker(activity, mac) }else -> items += (if (whitelisted) "Remove from whitelist" else "Whitelist (trust & ignore)") to {- if (whitelisted) unwhitelist(activity, mac) else whitelist(activity, mac, snap?.best?.label ?: snap?.name ?: "")+ if (whitelisted) unwhitelist(activity, mac) else whitelist(activity, mac, snap?.best?.label ?: snap?.name ?: "", ssidOf(snap))}}items += (if (favorite) "Remove from favorites" else "Add to favorites ★") to {@@ -353,20 +356,48 @@ object DeviceActions {.show()}- fun whitelist(activity: AppCompatActivity, mac: String, label: String) {+ /** [ssid]: a WiFi network's name, offered as a choice too (every network of that name, whatever its address). */+ fun whitelist(activity: AppCompatActivity, mac: String, label: String, ssid: String? = null) {+ fun addDevice() = activity.lifecycleScope.launch {+ AppDatabase.getInstance(activity).whitelistDao().add(WhitelistEntity(mac, label))+ toast(activity, "Whitelisted $mac")+ }+ val name = ssid?.trim().orEmpty()+ if (name.isEmpty()) {+ MaterialAlertDialogBuilder(activity)+ .setTitle("Whitelist this device?")+ .setMessage("$mac\n$label\n\nIt will be marked trusted and never logged, flashed or alerted on.")+ .setPositiveButton("Whitelist") { _, _ -> addDevice() }+ .setNegativeButton("Cancel", null)+ .show()+ return+ }+ // A network on many vehicles (a bus fleet's routers) has a new address on each: its name catches them all.+ var byName = falseMaterialAlertDialogBuilder(activity)- .setTitle("Whitelist this device?")- .setMessage("$mac\n$label\n\nIt will be marked trusted and never logged, flashed or alerted on.")+ .setTitle("Whitelist: trusted, never logged, flashed or alerted on")+ .setSingleChoiceItems(arrayOf("Only this device ($mac)", "Every network named \"$name\""), 0) { _, which -> byName = which == 1 }.setPositiveButton("Whitelist") { _, _ ->- activity.lifecycleScope.launch {- AppDatabase.getInstance(activity).whitelistDao().add(WhitelistEntity(mac, label))- toast(activity, "Whitelisted $mac")- }+ if (!byName) { addDevice(); return@setPositiveButton }+ TrustedNetworks.save(activity, TrustedNetworks.Rule(name, exact = true))+ toast(activity, "Every network named $name is whitelisted")}.setNegativeButton("Cancel", null).show()}+ /** The device is trusted by its network name: that name comes off the whitelist (with Undo). */+ fun untrustNetwork(activity: AppCompatActivity, ssid: String?) {+ val rule = TrustedNetworks.ruleFor(ssid)+ if (rule == null) { toast(activity, "Edit network names under Whitelist"); return }+ TrustedNetworks.remove(activity, rule)+ com.rfsentinel.app.util.Undo.show(activity, "Removed ${rule.text} from the whitelist") { TrustedNetworks.save(activity, rule) }+ }++ /** A WiFi network's name, for whitelisting it by name; null for Bluetooth and hidden networks. */+ fun ssidOf(s: DeviceRegistry.Snapshot?): String? =+ s?.takeIf { it.source == com.rfsentinel.app.detect.Advert.Source.WIFI }?.name?.trim()?.takeIf { it.isNotEmpty() }+fun unwhitelist(activity: AppCompatActivity, mac: String) {activity.lifecycleScope.launch {val dao = AppDatabase.getInstance(activity).whitelistDao()diff --git a/app/src/main/java/com/rfsentinel/app/ui/DeviceDetailActivity.kt b/app/src/main/java/com/rfsentinel/app/ui/DeviceDetailActivity.ktindex 9b85cf8..c446973 100644--- a/app/src/main/java/com/rfsentinel/app/ui/DeviceDetailActivity.kt+++ b/app/src/main/java/com/rfsentinel/app/ui/DeviceDetailActivity.kt@@ -101,8 +101,9 @@ class DeviceDetailActivity : AppCompatActivity() {refresh()}WhitelistCache.inTable(mac) -> DeviceActions.unwhitelist(this, mac)+ com.rfsentinel.app.data.TrustedNetworks.contains(mac) -> { DeviceActions.untrustNetwork(this, DeviceActions.ssidOf(s)); refresh() }isRotatingTracker(s) -> DeviceActions.ignoreTracker(this, mac)- else -> DeviceActions.whitelist(this, mac, s?.let { it.best?.label ?: it.name } ?: "")+ else -> DeviceActions.whitelist(this, mac, s?.let { it.best?.label ?: it.name } ?: "", DeviceActions.ssidOf(s))}}binding.actionFavorite.setOnClickListener {diff --git a/app/src/main/java/com/rfsentinel/app/whitelist/WhitelistActivity.kt b/app/src/main/java/com/rfsentinel/app/whitelist/WhitelistActivity.ktindex 92ff577..4a63746 100644--- a/app/src/main/java/com/rfsentinel/app/whitelist/WhitelistActivity.kt+++ b/app/src/main/java/com/rfsentinel/app/whitelist/WhitelistActivity.kt@@ -1,10 +1,17 @@package com.rfsentinel.app.whitelistimport android.os.Bundle+import android.widget.ArrayAdapter+import android.widget.EditText+import android.widget.LinearLayout+import android.widget.RadioButton+import android.widget.RadioGroupimport androidx.appcompat.app.AppCompatActivityimport androidx.lifecycle.lifecycleScopeimport androidx.recyclerview.widget.LinearLayoutManager+import com.google.android.material.dialog.MaterialAlertDialogBuilderimport com.rfsentinel.app.data.AppDatabase+import com.rfsentinel.app.data.TrustedNetworksimport com.rfsentinel.app.data.WhitelistEntityimport com.rfsentinel.app.databinding.ActivityWhitelistBindingimport com.rfsentinel.app.util.MacUtil@@ -14,7 +21,11 @@ import kotlinx.coroutines.launchclass WhitelistActivity : AppCompatActivity() {private lateinit var binding: ActivityWhitelistBindingprivate val entries = mutableListOf<WhitelistEntity>()- private lateinit var adapter: WhitelistAdapter+ private lateinit var adapter: WhitelistAdapter<WhitelistEntity>+ private val networks = mutableListOf<TrustedNetworks.Rule>()+ private lateinit var networkAdapter: WhitelistAdapter<TrustedNetworks.Rule>+ /** The Match dropdown: whole name (true) or part of it. */+ private var exact = falseoverride fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)@@ -23,7 +34,7 @@ class WhitelistActivity : AppCompatActivity() {binding.root.applySystemBarInsets()title = "Whitelist"- adapter = WhitelistAdapter(entries) { entry ->+ adapter = WhitelistAdapter(entries, { it.mac }, { it.note }) { entry ->lifecycleScope.launch {val dao = AppDatabase.getInstance(this@WhitelistActivity).whitelistDao()dao.remove(entry)@@ -60,5 +71,81 @@ class WhitelistActivity : AppCompatActivity() {adapter.notifyDataSetChanged()}}++ setupNetworks(savedInstanceState)+ }++ private fun setupNetworks(savedInstanceState: Bundle?) {+ val choices = listOf("Name contains", "Exact name")+ binding.networkMatch.setAdapter(ArrayAdapter(this, android.R.layout.simple_list_item_1, choices))+ binding.networkMatch.setOnItemClickListener { _, _, position, _ -> setExact(position == 1) }+ setExact(savedInstanceState?.getBoolean(STATE_EXACT) ?: false)++ networkAdapter = WhitelistAdapter(networks, { it.text }, { it.label }, { editNetwork(it) }) { rule ->+ TrustedNetworks.remove(this, rule)+ showNetworks()+ com.rfsentinel.app.util.Undo.show(this, "Removed ${rule.text}") {+ TrustedNetworks.save(this, rule)+ showNetworks()+ }+ }+ binding.networkList.layoutManager = LinearLayoutManager(this)+ binding.networkList.adapter = networkAdapter++ binding.addNetworkButton.setOnClickListener {+ val text = binding.networkInput.text.toString().trim()+ if (text.isEmpty()) {+ binding.networkInput.error = "Type a network name or part of one"+ return@setOnClickListener+ }+ TrustedNetworks.save(this, TrustedNetworks.Rule(text, exact))+ binding.networkInput.text?.clear()+ showNetworks()+ }+ showNetworks()+ }++ private fun setExact(on: Boolean) {+ exact = on+ binding.networkMatch.setText(if (on) "Exact name" else "Name contains", false) // false: keep every choice in the list+ }++ private fun showNetworks() {+ networks.clear()+ networks.addAll(TrustedNetworks.rules)+ networkAdapter.notifyDataSetChanged()+ }++ /** A tap on a network rule: change its text or how it matches. */+ private fun editNetwork(rule: TrustedNetworks.Rule) {+ val pad = (16 * resources.displayMetrics.density).toInt()+ val input = EditText(this).apply { setText(rule.text); setSelection(rule.text.length); hint = "Network name or keyword" }+ val contains = RadioButton(this).apply { id = android.view.View.generateViewId(); text = "Name contains" }+ val whole = RadioButton(this).apply { id = android.view.View.generateViewId(); text = "Exact name" }+ val group = RadioGroup(this).apply { addView(contains); addView(whole); check(if (rule.exact) whole.id else contains.id) }+ val box = LinearLayout(this).apply {+ orientation = LinearLayout.VERTICAL+ setPadding(pad, pad / 2, pad, 0)+ addView(input); addView(group)+ }+ MaterialAlertDialogBuilder(this)+ .setTitle("Edit network name")+ .setView(box)+ .setPositiveButton("Save") { _, _ ->+ val text = input.text.toString().trim()+ if (text.isNotEmpty()) TrustedNetworks.save(this, TrustedNetworks.Rule(text, group.checkedRadioButtonId == whole.id), replacing = rule)+ showNetworks()+ }+ .setNegativeButton("Cancel", null)+ .show()+ }++ override fun onSaveInstanceState(outState: Bundle) {+ super.onSaveInstanceState(outState)+ outState.putBoolean(STATE_EXACT, exact)+ }++ private companion object {+ const val STATE_EXACT = "networkExact"}}diff --git a/app/src/main/java/com/rfsentinel/app/whitelist/WhitelistAdapter.kt b/app/src/main/java/com/rfsentinel/app/whitelist/WhitelistAdapter.ktindex 4091f60..7e84bde 100644--- a/app/src/main/java/com/rfsentinel/app/whitelist/WhitelistAdapter.kt+++ b/app/src/main/java/com/rfsentinel/app/whitelist/WhitelistAdapter.kt@@ -3,13 +3,16 @@ package com.rfsentinel.app.whitelistimport android.view.LayoutInflaterimport android.view.ViewGroupimport androidx.recyclerview.widget.RecyclerView-import com.rfsentinel.app.data.WhitelistEntityimport com.rfsentinel.app.databinding.ItemWhitelistBinding-class WhitelistAdapter(- private val items: List<WhitelistEntity>,- private val onRemove: (WhitelistEntity) -> Unit-) : RecyclerView.Adapter<WhitelistAdapter.VH>() {+/** One whitelist section's rows: a device ([title] = its address) or a network name rule; [onClick] edits it. */+class WhitelistAdapter<T>(+ private val items: List<T>,+ private val title: (T) -> String,+ private val subtitle: (T) -> String,+ private val onClick: ((T) -> Unit)? = null,+ private val onRemove: (T) -> Unit+) : RecyclerView.Adapter<WhitelistAdapter<T>.VH>() {inner class VH(val binding: ItemWhitelistBinding) : RecyclerView.ViewHolder(binding.root)@@ -20,9 +23,12 @@ class WhitelistAdapter(override fun onBindViewHolder(holder: VH, position: Int) {val item = items[position]- holder.binding.macText.text = item.mac- holder.binding.noteText.text = item.note+ holder.binding.macText.text = title(item)+ holder.binding.noteText.text = subtitle(item)holder.binding.removeButton.setOnClickListener { onRemove(item) }+ val click = onClick+ holder.binding.root.isClickable = click != null+ if (click != null) holder.binding.root.setOnClickListener { click(item) } else holder.binding.root.setOnClickListener(null)}override fun getItemCount() = items.sizediff --git a/app/src/main/res/layout/activity_whitelist.xml b/app/src/main/res/layout/activity_whitelist.xmlindex abab9c5..5d32185 100644--- a/app/src/main/res/layout/activity_whitelist.xml+++ b/app/src/main/res/layout/activity_whitelist.xml@@ -1,37 +1,104 @@<?xml version="1.0" encoding="utf-8"?>-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"+<!-- Two sections in one scroll: devices by address, then WiFi networks by name. -->+<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"+ xmlns:app="http://schemas.android.com/apk/res-auto"android:layout_width="match_parent"- android:layout_height="match_parent"- android:orientation="vertical"- android:padding="16dp">+ android:layout_height="match_parent">- <EditText- android:id="@+id/macInput"+ <LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"- android:inputType="textCapCharacters|textNoSuggestions"- android:importantForAutofill="no"- android:hint="MAC address (AA:BB:CC:DD:EE:FF)" />+ android:orientation="vertical"+ android:padding="16dp">- <EditText- android:id="@+id/noteInput"- android:layout_width="match_parent"- android:layout_height="wrap_content"- android:inputType="text"- android:importantForAutofill="no"- android:hint="Note (optional, e.g. 'my headphones')" />+ <TextView+ android:layout_width="match_parent"+ android:layout_height="wrap_content"+ android:text="Devices"+ android:textSize="@dimen/text_subtitle"+ android:textStyle="bold" />- <Button- android:id="@+id/addButton"- android:layout_width="wrap_content"- android:layout_height="wrap_content"- android:text="Add to whitelist" />+ <EditText+ android:id="@+id/macInput"+ android:layout_width="match_parent"+ android:layout_height="wrap_content"+ android:inputType="textCapCharacters|textNoSuggestions"+ android:importantForAutofill="no"+ android:hint="MAC address (AA:BB:CC:DD:EE:FF)" />- <androidx.recyclerview.widget.RecyclerView- android:id="@+id/recyclerView"- android:layout_width="match_parent"- android:layout_height="0dp"- android:layout_weight="1"- android:layout_marginTop="16dp" />+ <EditText+ android:id="@+id/noteInput"+ android:layout_width="match_parent"+ android:layout_height="wrap_content"+ android:inputType="text"+ android:importantForAutofill="no"+ android:hint="Note (optional, e.g. 'my headphones')" />++ <Button+ android:id="@+id/addButton"+ android:layout_width="wrap_content"+ android:layout_height="wrap_content"+ android:text="Add to whitelist" />++ <androidx.recyclerview.widget.RecyclerView+ android:id="@+id/recyclerView"+ android:layout_width="match_parent"+ android:layout_height="wrap_content"+ android:layout_marginTop="8dp"+ android:nestedScrollingEnabled="false" />++ <TextView+ android:layout_width="match_parent"+ android:layout_height="wrap_content"+ android:layout_marginTop="24dp"+ android:text="Network names"+ android:textSize="@dimen/text_subtitle"+ android:textStyle="bold" />++ <TextView+ android:layout_width="match_parent"+ android:layout_height="wrap_content"+ android:paddingTop="2dp"+ android:paddingBottom="8dp"+ android:text="WiFi networks with a matching name are trusted like a whitelisted device. Name contains also matches part of a name: LAUSD matches LAUSD-Bus-123 and WiFi-LAUSD."+ android:textColor="?android:attr/textColorSecondary"+ android:textSize="@dimen/text_caption" />++ <com.google.android.material.textfield.TextInputLayout+ style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"+ android:layout_width="match_parent"+ android:layout_height="wrap_content"+ android:hint="Match"+ app:endIconMode="dropdown_menu">++ <AutoCompleteTextView+ android:id="@+id/networkMatch"+ android:layout_width="match_parent"+ android:layout_height="wrap_content"+ android:inputType="none"+ android:saveEnabled="false" />+ </com.google.android.material.textfield.TextInputLayout>++ <EditText+ android:id="@+id/networkInput"+ android:layout_width="match_parent"+ android:layout_height="wrap_content"+ android:inputType="text|textNoSuggestions"+ android:importantForAutofill="no"+ android:hint="Network name or keyword, e.g. LAUSD" />++ <Button+ android:id="@+id/addNetworkButton"+ android:layout_width="wrap_content"+ android:layout_height="wrap_content"+ android:text="Add network name" />++ <androidx.recyclerview.widget.RecyclerView+ android:id="@+id/networkList"+ android:layout_width="match_parent"+ android:layout_height="wrap_content"+ android:layout_marginTop="8dp"+ android:nestedScrollingEnabled="false" />-</LinearLayout>+ </LinearLayout>+</androidx.core.widget.NestedScrollView>diff --git a/app/src/test/java/com/rfsentinel/app/data/TrustedNetworksTest.kt b/app/src/test/java/com/rfsentinel/app/data/TrustedNetworksTest.ktnew file mode 100644index 0000000..98198b8--- /dev/null+++ b/app/src/test/java/com/rfsentinel/app/data/TrustedNetworksTest.kt@@ -0,0 +1,34 @@+package com.rfsentinel.app.data++import com.rfsentinel.app.data.TrustedNetworks.Rule+import org.junit.Assert.assertFalse+import org.junit.Assert.assertTrue+import org.junit.Test++class TrustedNetworksTest {++ // Made-up network names.+ private val rules = listOf(Rule("FLEET", exact = false), Rule("Depot WiFi", exact = true))++ @Test+ fun keywordMatchesAnyPartOfTheNameWhateverTheCase() {+ assertTrue(TrustedNetworks.matches(rules, "FLEET-Bus-123"))+ assertTrue(TrustedNetworks.matches(rules, "WiFi-fleet"))+ assertTrue(TrustedNetworks.matches(rules, "myFleetNet"))+ }++ @Test+ fun exactNameMatchesOnlyTheWholeName() {+ assertTrue(TrustedNetworks.matches(rules, "depot wifi"))+ assertTrue(TrustedNetworks.matches(rules, " Depot WiFi "))+ assertFalse(TrustedNetworks.matches(rules, "Depot WiFi 2"))+ }++ @Test+ fun otherAndHiddenNetworksAreNotTrusted() {+ assertFalse(TrustedNetworks.matches(rules, "Patrol-7"))+ assertFalse(TrustedNetworks.matches(rules, ""))+ assertFalse(TrustedNetworks.matches(rules, null))+ assertFalse(TrustedNetworks.matches(emptyList(), "FLEET-Bus-123"))+ }+}