Skip to content

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.

Fake cell tower warning signs (IMSI catchers)

CIS-C01df9c3be7064
diff --git a/app/src/main/java/com/rfsentinel/app/MainActivity.kt b/app/src/main/java/com/rfsentinel/app/MainActivity.kt
index 1199e47..925356c 100644
--- a/app/src/main/java/com/rfsentinel/app/MainActivity.kt
+++ b/app/src/main/java/com/rfsentinel/app/MainActivity.kt
@@ -176,7 +176,10 @@ class MainActivity : AppCompatActivity() {
!running -> "Idle - tap Start to listen for nearby devices"
!bluetoothOn() && !demoMode -> "Scanning WiFi only - turn on Bluetooth for BLE (picked up automatically)"
else -> "Scanning · $deviceCount ${plural(deviceCount, "device", "devices")} nearby" +
- if (flaggedCount > 0) " · $flaggedCount flagged" else ""
+ (if (flaggedCount > 0) " · $flaggedCount flagged" else "") +
+ (com.rfsentinel.app.service.CellMonitor.lastAnomaly
+ ?.takeIf { System.currentTimeMillis() - it.first < 15 * 60_000L }
+ ?.let { " · ⚠ ${it.second.title}" } ?: "")
}
}
diff --git a/app/src/main/java/com/rfsentinel/app/detect/Category.kt b/app/src/main/java/com/rfsentinel/app/detect/Category.kt
index c40ba57..82c4052 100644
--- a/app/src/main/java/com/rfsentinel/app/detect/Category.kt
+++ b/app/src/main/java/com/rfsentinel/app/detect/Category.kt
@@ -19,6 +19,7 @@ enum class Category(
TRACKER("Item tracker away from its owner", "TRACKER", 0xFF6A3FB5.toInt(), true),
GLASSES("Smart / recording glasses", "GLASSES", 0xFF00796B.toInt(), true),
NETWORK_CAMERA("Network / home security camera", "CAMERA", 0xFF5D6D7E.toInt(), false),
+ CELL_ANOMALY("Fake cell tower signs (IMSI catcher)", "CELL", 0xFF7B1FA2.toInt(), true),
CUSTOM("Your watchlist", "WATCHLIST", 0xFFC8431A.toInt(), true);
companion object {
diff --git a/app/src/main/java/com/rfsentinel/app/detect/CellAnalyzer.kt b/app/src/main/java/com/rfsentinel/app/detect/CellAnalyzer.kt
new file mode 100644
index 0000000..135840d
--- /dev/null
+++ b/app/src/main/java/com/rfsentinel/app/detect/CellAnalyzer.kt
@@ -0,0 +1,136 @@
+package com.rfsentinel.app.detect
+
+/**
+ * Heuristic warning signs of a fake cell tower (IMSI catcher / "Stingray"),
+ * from what Android shows any app without root: the cells the phone sees,
+ * their technology, network code, area and signal. Android does not expose
+ * ciphering or signalling messages, so none of this is proof - each sign has
+ * innocent explanations, which is why most are weak on their own.
+ *
+ * Pure Kotlin: fed with snapshots by the scanner, unit-tested on the JVM.
+ */
+class CellAnalyzer {
+
+ enum class Rat(val label: String, val generation: Int) {
+ GSM("2G (GSM)", 2), CDMA("2G/3G (CDMA)", 2), WCDMA("3G (UMTS)", 3), TDSCDMA("3G (TD-SCDMA)", 3),
+ LTE("4G (LTE)", 4), NR("5G (NR)", 5)
+ }
+
+ /** One cell as seen in a snapshot. Unknown fields are null. */
+ data class Cell(
+ val rat: Rat,
+ val registered: Boolean,
+ val mcc: String?,
+ val mnc: String?,
+ /** LAC (2G/3G) or TAC (4G/5G). */
+ val area: Int?,
+ val cellId: Long?,
+ val dbm: Int?
+ ) {
+ val key get() = "${rat.name} ${mcc ?: "?"}-${mnc ?: "?"} ${area ?: "?"}/${cellId ?: "?"}"
+ }
+
+ /** What the scanner knows about you at the time of a snapshot. */
+ data class Context(
+ val time: Long,
+ /** SIM's home network MCC+MNC (e.g. "302720"), if known. */
+ val simOperator: String?,
+ val roaming: Boolean,
+ /** True when GPS shows you haven't moved (speed < ~1 m/s, < 50 m over a few minutes). */
+ val stationary: Boolean?
+ )
+
+ data class Anomaly(val key: String, val title: String, val detail: String, val confidence: Int)
+
+ private data class Seen(val time: Long, val registered: Cell?, val neighbours: Int, val stationary: Boolean?)
+
+ private val history = ArrayDeque<Seen>()
+
+ /** Analyses one snapshot of visible cells; returns the warning signs found in it. */
+ fun analyze(cells: List<Cell>, ctx: Context): List<Anomaly> {
+ val out = mutableListOf<Anomaly>()
+ val serving = cells.firstOrNull { it.registered }
+ val neighbours = cells.count { !it.registered }
+ val window = history.filter { ctx.time - it.time <= WINDOW_MS }
+
+ if (serving != null) {
+ // 1. Test / reserved network codes: never used by real public networks.
+ if (serving.mcc in TEST_MCC) {
+ out += Anomaly(
+ "test-plmn:${serving.key}", "Test network code on your cell",
+ "Your phone is connected to ${serving.rat.label} network ${serving.mcc}-${serving.mnc}. " +
+ "MCC ${serving.mcc} is reserved for test networks and lab equipment - real operators never use it, " +
+ "but some IMSI catchers do.", 85
+ )
+ }
+
+ // 2. Unexpected country: cell's MCC differs from your SIM's while the phone says it isn't roaming.
+ val simMcc = ctx.simOperator?.take(3)
+ if (simMcc != null && serving.mcc != null && serving.mcc !in TEST_MCC &&
+ serving.mcc != simMcc && !ctx.roaming && simMcc !in SHARED_COUNTRY[serving.mcc].orEmpty()
+ ) {
+ out += Anomaly(
+ "foreign:${serving.key}", "Unexpected network country code",
+ "Your cell announces country code ${serving.mcc}, but your SIM is from $simMcc and the phone " +
+ "doesn't report roaming. Near a border this can be normal.", 55
+ )
+ }
+
+ // 3. Forced 2G: dropped to 2G/CDMA recently after 4G/5G, while 4G/5G cells are still in view.
+ val wasModern = window.any { (it.registered?.rat?.generation ?: 0) >= 4 }
+ val modernStillVisible = cells.any { !it.registered && it.rat.generation >= 4 }
+ if (serving.rat.generation <= 2 && wasModern) {
+ out += Anomaly(
+ "downgrade:${serving.key}", "Network downgraded to 2G",
+ "Your phone moved from 4G/5G to ${serving.rat.label}" +
+ (if (modernStillVisible) " although 4G/5G cells are still in range" else "") +
+ ". IMSI catchers force phones onto 2G, which has no network authentication. " +
+ "Weak coverage can also cause this.",
+ if (modernStillVisible) 65 else 40
+ )
+ }
+
+ // 4. Area changed while you stood still: a fake cell forces a location update.
+ val prev = window.lastOrNull()?.registered
+ if (ctx.stationary == true && prev != null && prev.rat == serving.rat && prev.mcc == serving.mcc &&
+ prev.area != null && serving.area != null && prev.area != serving.area
+ ) {
+ out += Anomaly(
+ "area:${serving.key}", "Location area changed while you weren't moving",
+ "Your cell's area code changed from ${prev.area} to ${serving.area} while GPS shows you standing still. " +
+ "Fake cells often do this to make phones re-register. Area borders and network load can also cause it.",
+ 40
+ )
+ }
+
+ // 5. No neighbours on a cell where several were visible moments ago.
+ val hadNeighbours = window.takeLast(4).let { recent -> recent.size >= 2 && recent.all { it.neighbours >= 2 } }
+ if (neighbours == 0 && hadNeighbours && prev != null && prev.key != serving.key) {
+ out += Anomaly(
+ "isolated:${serving.key}", "New cell with no neighbours",
+ "Your phone switched to a cell that shows no neighbouring cells, where several were visible " +
+ "moments ago. Fake stations often advertise no neighbours.", 35
+ )
+ }
+ }
+
+ history.addLast(Seen(ctx.time, serving, neighbours, ctx.stationary))
+ while (history.size > 120 || (history.isNotEmpty() && ctx.time - history.first().time > WINDOW_MS)) history.removeFirst()
+ return out
+ }
+
+ companion object {
+ /** Memory for "recently" (downgrade, area change, neighbours). */
+ const val WINDOW_MS = 10 * 60_000L
+ /** ITU test / reserved codes. */
+ val TEST_MCC = setOf("001", "002", "999")
+ /** Countries that share networks with a neighbour's MCC (e.g. US 310-316). */
+ private val SHARED_COUNTRY = mapOf(
+ "310" to setOf("311", "312", "313", "314", "315", "316"),
+ "311" to setOf("310", "312", "313", "314", "315", "316"),
+ "312" to setOf("310", "311"), "313" to setOf("310", "311"), "314" to setOf("310", "311"),
+ "315" to setOf("310", "311"), "316" to setOf("310", "311"),
+ "405" to setOf("404"), "404" to setOf("405")
+ )
+ }
+}
diff --git a/app/src/main/java/com/rfsentinel/app/service/CellMonitor.kt b/app/src/main/java/com/rfsentinel/app/service/CellMonitor.kt
new file mode 100644
index 0000000..8b14f94
--- /dev/null
+++ b/app/src/main/java/com/rfsentinel/app/service/CellMonitor.kt
@@ -0,0 +1,147 @@
+package com.rfsentinel.app.service
+
+import android.annotation.SuppressLint
+import android.content.Context
+import android.location.Location
+import android.os.Build
+import android.telephony.CellIdentityNr
+import android.telephony.CellInfo
+import android.telephony.CellInfoCdma
+import android.telephony.CellInfoGsm
+import android.telephony.CellInfoLte
+import android.telephony.CellInfoNr
+import android.telephony.CellInfoTdscdma
+import android.telephony.CellInfoWcdma
+import android.telephony.TelephonyManager
+import com.rfsentinel.app.detect.CellAnalyzer
+import kotlinx.coroutines.suspendCancellableCoroutine
+import kotlinx.coroutines.withTimeoutOrNull
+import java.util.concurrent.Executors
+import kotlin.coroutines.resume
+
+/**
+ * Reads the cells the phone can see (passively - Android reports what the
+ * modem already knows; nothing is transmitted) and feeds them to
+ * [CellAnalyzer]. Needs only the location permission the app already has.
+ */
+class CellMonitor(private val context: Context) {
+
+ private val analyzer = CellAnalyzer()
+ private val tm = context.getSystemService(TelephonyManager::class.java)
+ private val executor = Executors.newSingleThreadExecutor()
+ private val fixes = ArrayDeque<Location>()
+
+ /** Called by the scanner with every location fix, for the "standing still" test. */
+ @Synchronized
+ fun onLocation(loc: Location) {
+ fixes.addLast(loc)
+ while (fixes.size > 12) fixes.removeFirst()
+ }
+
+ /** True / false when GPS knows whether you've been still for ~2 minutes; null otherwise. */
+ @Synchronized
+ private fun stationary(now: Long): Boolean? {
+ val recent = fixes.filter { now - it.time <= 3 * 60_000L }
+ if (recent.size < 3 || now - recent.last().time > 60_000L) return null
+ val first = recent.first()
+ val span = recent.last().time - first.time
+ if (span < 2 * 60_000L) return null
+ val still = recent.all { (!it.hasSpeed() || it.speed < 1f) && first.distanceTo(it) < 50f }
+ return still
+ }
+
+ /** One snapshot: returns any warning signs. */
+ suspend fun check(): List<CellAnalyzer.Anomaly> {
+ val tm = tm ?: return emptyList()
+ val infos = fetch(tm) ?: return emptyList()
+ val cells = infos.mapNotNull(::toCell)
+ if (cells.isEmpty()) return emptyList()
+ val now = System.currentTimeMillis()
+ val ctx = CellAnalyzer.Context(
+ time = now,
+ simOperator = runCatching { tm.simOperator }.getOrNull()?.takeIf { it.length >= 5 },
+ roaming = runCatching { tm.isNetworkRoaming }.getOrDefault(false),
+ stationary = stationary(now)
+ )
+ return analyzer.analyze(cells, ctx)
+ }
+
+ /** Fresh cell info on Android 10+ (falls back to the cached list). */
+ @SuppressLint("MissingPermission") // location permission is checked by the scanner before calling
+ private suspend fun fetch(tm: TelephonyManager): List<CellInfo>? = runCatching {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
+ withTimeoutOrNull(5_000) {
+ suspendCancellableCoroutine { cont ->
+ tm.requestCellInfoUpdate(executor, object : TelephonyManager.CellInfoCallback() {
+ override fun onCellInfo(cellInfo: MutableList<CellInfo>) { if (cont.isActive) cont.resume(cellInfo) }
+ override fun onError(errorCode: Int, detail: Throwable?) { if (cont.isActive) cont.resume(tm.allCellInfo) }
+ })
+ }
+ } ?: tm.allCellInfo
+ } else {
+ tm.allCellInfo
+ }
+ }.getOrNull()
+
+ private fun Int.orNull() = takeIf { it != CellInfo.UNAVAILABLE && it != Int.MAX_VALUE && it >= 0 }
+
+ private fun toCell(info: CellInfo): CellAnalyzer.Cell? {
+ val reg = info.isRegistered
+ return when (info) {
+ is CellInfoLte -> info.cellIdentity.let {
+ CellAnalyzer.Cell(CellAnalyzer.Rat.LTE, reg, mcc(it.mccCompat()), mnc(it.mncCompat()), it.tac.orNull(), it.ci.orNull()?.toLong(), info.cellSignalStrength.dbm)
+ }
+ is CellInfoGsm -> info.cellIdentity.let {
+ CellAnalyzer.Cell(CellAnalyzer.Rat.GSM, reg, mcc(it.mccCompat()), mnc(it.mncCompat()), it.lac.orNull(), it.cid.orNull()?.toLong(), info.cellSignalStrength.dbm)
+ }
+ is CellInfoWcdma -> info.cellIdentity.let {
+ CellAnalyzer.Cell(CellAnalyzer.Rat.WCDMA, reg, mcc(it.mccCompat()), mnc(it.mncCompat()), it.lac.orNull(), it.cid.orNull()?.toLong(), info.cellSignalStrength.dbm)
+ }
+ is CellInfoCdma -> CellAnalyzer.Cell(CellAnalyzer.Rat.CDMA, reg, null, null,
+ info.cellIdentity.networkId.orNull(), info.cellIdentity.basestationId.orNull()?.toLong(), info.cellSignalStrength.dbm)
+ else -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) newer(info, reg) else null
+ }
+ }
+
+ @android.annotation.TargetApi(Build.VERSION_CODES.Q)
+ private fun newer(info: CellInfo, reg: Boolean): CellAnalyzer.Cell? = when (info) {
+ is CellInfoNr -> (info.cellIdentity as CellIdentityNr).let {
+ CellAnalyzer.Cell(CellAnalyzer.Rat.NR, reg, it.mccString, it.mncString, it.tac.orNull(),
+ it.nci.takeIf { n -> n != CellInfo.UNAVAILABLE_LONG && n >= 0 }, info.cellSignalStrength.dbm)
+ }
+ is CellInfoTdscdma -> info.cellIdentity.let {
+ CellAnalyzer.Cell(CellAnalyzer.Rat.TDSCDMA, reg, it.mccString, it.mncString, it.lac.orNull(), it.cid.orNull()?.toLong(), info.cellSignalStrength.dbm)
+ }
+ else -> null
+ }
+
+ // Operator codes: the String getters are API 28+; older phones only have the int ones.
+ private fun mcc(v: String?) = v?.takeIf { it.isNotBlank() }
+ private fun mnc(v: String?) = v?.takeIf { it.isNotBlank() }
+
+ @Suppress("DEPRECATION")
+ private fun android.telephony.CellIdentityLte.mccCompat() =
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) mccString else mcc.orNull()?.let { "%03d".format(it) }
+ @Suppress("DEPRECATION")
+ private fun android.telephony.CellIdentityLte.mncCompat() =
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) mncString else mnc.orNull()?.let { "%02d".format(it) }
+ @Suppress("DEPRECATION")
+ private fun android.telephony.CellIdentityGsm.mccCompat() =
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) mccString else mcc.orNull()?.let { "%03d".format(it) }
+ @Suppress("DEPRECATION")
+ private fun android.telephony.CellIdentityGsm.mncCompat() =
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) mncString else mnc.orNull()?.let { "%02d".format(it) }
+ @Suppress("DEPRECATION")
+ private fun android.telephony.CellIdentityWcdma.mccCompat() =
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) mccString else mcc.orNull()?.let { "%03d".format(it) }
+ @Suppress("DEPRECATION")
+ private fun android.telephony.CellIdentityWcdma.mncCompat() =
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) mncString else mnc.orNull()?.let { "%02d".format(it) }
+
+ fun close() = executor.shutdown()
+
+ companion object {
+ /** Last warning sign raised (for the main screen), and when. */
+ @Volatile var lastAnomaly: Pair<Long, CellAnalyzer.Anomaly>? = null
+ }
+}
diff --git a/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt b/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt
index d5cffe6..20e18e9 100644
--- a/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt
+++ b/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt
@@ -84,6 +84,8 @@ class ScanForegroundService : Service() {
private const val HISTORY_FLUSH_MS = 60_000L
private const val DRONE_OVERHEAD_REPEAT_MS = 5 * 60_000L
private const val KNOWN_ALPR_REPEAT_MS = 30 * 60_000L
+ private const val CELL_CHECK_MS = 15_000L
+ private const val CELL_REPEAT_MS = 30 * 60_000L
/** True while an instance is alive in this process. Source of truth for the UI. */
@Volatile
@@ -122,6 +124,9 @@ class ScanForegroundService : Service() {
private var wifiPollJob: Job? = null
private var bleRestartJob: Job? = null
private var housekeepingJob: Job? = null
+ private var cellJob: Job? = null
+ private var cellMonitor: CellMonitor? = null
+ private val lastCellAlert = HashMap<String, Long>()
private var btStateReceiverRegistered = false
private var lastHistoryFlush = 0L
@@ -132,6 +137,7 @@ class ScanForegroundService : Service() {
lastLocation = it
TripRecorder.onLocation(it)
checkKnownAlpr(it)
+ cellMonitor?.onLocation(it)
}
/** Known plate cameras: distance at the previous fix, and when each last alerted. */
@@ -203,6 +209,7 @@ class ScanForegroundService : Service() {
if (Prefs.wifiEnabled(this)) startWifiPolling() else stopWifiPolling()
updateLocationUpdates()
startHousekeeping()
+ startCellChecks()
isRunning = true
refreshTile()
@@ -556,6 +563,47 @@ class ScanForegroundService : Service() {
}
}
+ /**
+ * Fake-cell-tower check every 15 s: reads the cells the phone already sees
+ * (passive, no extra permission beyond location). Probable signs alert like a
+ * device match; weak ones are only written to the match history.
+ */
+ private fun startCellChecks() {
+ cellJob?.cancel()
+ if (!Prefs.categoryEnabled(this, Category.CELL_ANOMALY) || !hasFineLocation()) return
+ val monitor = cellMonitor ?: CellMonitor(this).also { cellMonitor = it }
+ cellJob = serviceScope.launch {
+ while (isActive) {
+ runCatching { monitor.check() }.getOrNull().orEmpty().forEach { onCellAnomaly(it) }
+ delay(CELL_CHECK_MS)
+ }
+ }
+ }
+
+ private fun onCellAnomaly(a: com.rfsentinel.app.detect.CellAnalyzer.Anomaly) {
+ val now = System.currentTimeMillis()
+ if (now - (lastCellAlert[a.key] ?: 0L) < CELL_REPEAT_MS) return
+ lastCellAlert[a.key] = now
+ CellMonitor.lastAnomaly = now to a
+ val hit = Hit(Category.CELL_ANOMALY, a.title, a.confidence, a.detail, "Android cell info (heuristic, not proof)")
+ val loc = lastLocation
+ val tag = Prefs.gpsTaggingEnabled(this)
+ serviceScope.launch {
+ AppDatabase.getInstance(this@ScanForegroundService).detectionDao().insert(
+ DetectionEntity(
+ mac = "CELL " + a.key.substringAfter(':'), label = a.title, source = "CELL", rssi = 0,
+ timestamp = now,
+ latitude = if (tag) loc?.latitude else null, longitude = if (tag) loc?.longitude else null,
+ category = Category.CELL_ANOMALY.name, confidence = a.confidence, evidence = a.detail
+ )
+ )
+ }
+ if (a.confidence >= Prefs.alertThreshold(this)) {
+ NotificationHelper.sendMapAlert(this, "cell:" + a.key, hit, com.rfsentinel.app.ui.DetectionLogActivity::class.java)
+ AlertPlayer.play(this, hit.tier, "Cell network warning")
+ }
+ }
+
private fun updateLocationOnMain() {
android.os.Handler(Looper.getMainLooper()).post { updateLocationUpdates() }
}
@@ -577,6 +625,7 @@ class ScanForegroundService : Service() {
}
serviceScope.cancel()
pipelineThread.quitSafely()
+ cellMonitor?.close()
// Take the final history and trace synchronously, so a scan restarted right
// away (new session, new trace) can't clear or reuse them; write them after.
val history = takeHistory()
diff --git a/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt b/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt
index 397bd42..62a667b 100644
--- a/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt
+++ b/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt
@@ -93,6 +93,16 @@ class SettingsActivity : AppCompatActivity() {
)
binding.intervalInput.setText((Prefs.scanIntervalMs(this) / 1000).toString())
binding.wifiThrottleButton.setOnClickListener { openWifiThrottleSetting() }
+ binding.disable2gButton.setOnClickListener {
+ val opened = runCatching { startActivity(Intent(Settings.ACTION_NETWORK_OPERATOR_SETTINGS)) }.isSuccess ||
+ runCatching { startActivity(Intent(Settings.ACTION_WIRELESS_SETTINGS)) }.isSuccess
+ Toast.makeText(
+ this,
+ if (opened) "Look for \"Allow 2G\" and turn it off (on some phones: SIMs > your SIM)"
+ else "Open Settings > Network > SIMs and turn off \"Allow 2G\"",
+ Toast.LENGTH_LONG
+ ).show()
+ }
updateWifiThrottleHint()
binding.bootSwitch.isChecked = Prefs.autoStartOnBoot(this)
binding.batteryButton.setOnClickListener {
diff --git a/app/src/main/java/com/rfsentinel/app/util/NotificationHelper.kt b/app/src/main/java/com/rfsentinel/app/util/NotificationHelper.kt
index d555964..e725989 100644
--- a/app/src/main/java/com/rfsentinel/app/util/NotificationHelper.kt
+++ b/app/src/main/java/com/rfsentinel/app/util/NotificationHelper.kt
@@ -96,12 +96,15 @@ object NotificationHelper {
* Posts an alert about a mapped place rather than a device (e.g. a known plate
* camera): tapping it opens the map. Sound/vibration/voice are played by the caller.
*/
- fun sendMapAlert(context: Context, key: String, hit: Hit) {
+ fun sendMapAlert(
+ context: Context, key: String, hit: Hit,
+ target: Class<out android.app.Activity> = com.rfsentinel.app.ui.MapActivity::class.java
+ ) {
val nm = context.getSystemService(NotificationManager::class.java)
val discreet = Prefs.discreetMode(context)
val open = PendingIntent.getActivity(
context, key.hashCode(),
- Intent(context, com.rfsentinel.app.ui.MapActivity::class.java).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK),
+ Intent(context, target).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK),
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)
val builder = NotificationCompat.Builder(context, CHANNEL_ALERTS)
diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml
index a24da5b..76215f0 100644
--- a/app/src/main/res/layout/activity_settings.xml
+++ b/app/src/main/res/layout/activity_settings.xml
@@ -137,6 +137,17 @@
android:layout_height="wrap_content"
android:orientation="vertical" />
+ <TextView
+ style="@style/SettingsLabel"
+ android:text="Strongest protection against fake cell towers: turn off &quot;Allow 2G&quot; in your SIM settings (Android 12+). 2G has no network authentication, which is what IMSI catchers exploit." />
+
+ <Button
+ android:id="@+id/disable2gButton"
+ style="@style/Widget.MaterialComponents.Button.TextButton"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Open SIM settings" />
+
<TextView style="@style/SettingsLabel" android:text="Watchlist presets (MAC prefixes)" />
<CheckBox
diff --git a/app/src/test/java/com/rfsentinel/app/detect/CellAnalyzerTest.kt b/app/src/test/java/com/rfsentinel/app/detect/CellAnalyzerTest.kt
new file mode 100644
index 0000000..c633dc5
--- /dev/null
+++ b/app/src/test/java/com/rfsentinel/app/detect/CellAnalyzerTest.kt
@@ -0,0 +1,69 @@
+package com.rfsentinel.app.detect
+
+import com.rfsentinel.app.detect.CellAnalyzer.Cell
+import com.rfsentinel.app.detect.CellAnalyzer.Rat
+import org.junit.Assert.assertEquals
+import org.junit.Assert.assertTrue
+import org.junit.Test
+
+class CellAnalyzerTest {
+
+ // Synthetic operator codes: 999-99 style values are only used where a test code is intended.
+ private fun cell(rat: Rat, reg: Boolean, area: Int = 100, id: Long = 1, mcc: String = "208", mnc: String = "01") =
+ Cell(rat, reg, mcc, mnc, area, id, -80)
+
+ private fun ctx(t: Long, stationary: Boolean? = null, sim: String = "20801", roaming: Boolean = false) =
+ CellAnalyzer.Context(t, sim, roaming, stationary)
+
+ private fun modern(reg: Boolean = true, area: Int = 100, id: Long = 1) = cell(Rat.LTE, reg, area, id)
+
+ @Test
+ fun testNetworkCodeIsStrong() {
+ val a = CellAnalyzer().analyze(listOf(cell(Rat.GSM, true, mcc = "001", mnc = "01")), ctx(0))
+ assertEquals(85, a.single { it.key.startsWith("test-plmn") }.confidence)
+ }
+
+ @Test
+ fun forcedDowngradeToGsmWithLteStillVisible() {
+ val an = CellAnalyzer()
+ assertTrue(an.analyze(listOf(modern(), modern(false, id = 2)), ctx(0)).isEmpty())
+ val a = an.analyze(listOf(cell(Rat.GSM, true, id = 9), modern(false, id = 2)), ctx(30_000))
+ assertEquals(65, a.single { it.key.startsWith("downgrade") }.confidence)
+ }
+
+ @Test
+ fun downgradeWithoutModernCoverageIsWeak() {
+ val an = CellAnalyzer()
+ an.analyze(listOf(modern()), ctx(0))
+ val a = an.analyze(listOf(cell(Rat.GSM, true, id = 9)), ctx(30_000))
+ assertEquals(40, a.single { it.key.startsWith("downgrade") }.confidence)
+ }
+
+ @Test
+ fun areaChangeOnlyCountsWhenStandingStill() {
+ val moving = CellAnalyzer()
+ moving.analyze(listOf(modern(area = 100)), ctx(0, stationary = false))
+ assertTrue(moving.analyze(listOf(modern(area = 200)), ctx(15_000, stationary = false)).none { it.key.startsWith("area") })
+
+ val still = CellAnalyzer()
+ still.analyze(listOf(modern(area = 100)), ctx(0, stationary = true))
+ assertEquals(40, still.analyze(listOf(modern(area = 200)), ctx(15_000, stationary = true)).single { it.key.startsWith("area") }.confidence)
+ }
+
+ @Test
+ fun foreignCountryButNotSharedOrRoaming() {
+ val cells = listOf(cell(Rat.LTE, true, mcc = "262", mnc = "01"))
+ assertEquals(55, CellAnalyzer().analyze(cells, ctx(0)).single { it.key.startsWith("foreign") }.confidence)
+ assertTrue(CellAnalyzer().analyze(cells, ctx(0, roaming = true)).isEmpty())
+ // US networks use several MCCs: 311 with a 310 SIM is normal.
+ assertTrue(CellAnalyzer().analyze(listOf(cell(Rat.LTE, true, mcc = "311", mnc = "480")), ctx(0, sim = "310260")).isEmpty())
+ }
+
+ @Test
+ fun newCellWithNoNeighboursAfterSeveral() {
+ val an = CellAnalyzer()
+ repeat(3) { i -> an.analyze(listOf(modern(), modern(false, id = 2), modern(false, id = 3)), ctx(i * 15_000L)) }
+ val a = an.analyze(listOf(modern(id = 7)), ctx(60_000))
+ assertEquals(35, a.single { it.key.startsWith("isolated") }.confidence)
+ }
+}