From e787e83e781c999c0555e1db5e99ac5685a84536 Mon Sep 17 00:00:00 2001 From: bt Date: Tue, 26 May 2026 23:13:08 +0200 Subject: Load netmonitor CSV database and show cells descriptions --- app/src/main/AndroidManifest.xml | 4 + app/src/main/java/net/rctt/netmon/CellDbItem.kt | 31 ++++++ app/src/main/java/net/rctt/netmon/CellView.kt | 9 +- app/src/main/java/net/rctt/netmon/MainActivity.kt | 93 ++++++++++++++++-- app/src/main/res/layout/cell_view.xml | 111 ++++++++++++---------- 5 files changed, 186 insertions(+), 62 deletions(-) create mode 100644 app/src/main/java/net/rctt/netmon/CellDbItem.kt (limited to 'app/src') diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f8bbdd0..32d8332 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -5,8 +5,12 @@ + + + + val cellDb = HashMap>() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -40,6 +48,8 @@ class MainActivity : AppCompatActivity() { insets } + loadDb() + cellsList = HashMap() cellsListView = findViewById(R.id.cellsList) @@ -56,13 +66,53 @@ class MainActivity : AppCompatActivity() { }) } + fun loadDb() { + val reader = csvReader { + dialect = CsvDialect(delimiter = ';') + } + + reader.readFromFile(File("/storage/emulated/0/cells.csv")) { rows -> + rows.forEach { + val item = CellDbItem() + item.Type = it.elementAt(0) + item.MCC = it.elementAt(1) + item.MNC = it.elementAt(2) + item.LAC = it.elementAt(3).toInt() + item.CID = it.elementAt(4).toLong() + if (it.elementAt(5) != "") { + item.PSC = it.elementAt(5).toInt() + } + if (it.elementAt(6) != "") { + item.Channel = it.elementAt(6).toInt() + } + item.Latitude = it.elementAt(7).toDouble() + item.Longitude = it.elementAt(8).toDouble() + if (it.elementAt(9) != "") { + item.Accuracy = it.elementAt(9).toInt() + } + item.Description = it.elementAt(10) + + var lac = cellDb[item.LAC] + if (lac == null) { + cellDb[item.LAC] = HashMap() + lac = cellDb[item.LAC] + } + + lac?.set(item.CID, item) + } + } + } + + fun findInDb(lac: Int, cid: Long): CellDbItem? { + return cellDb[lac]?.get(cid) + } + @RequiresPermission(Manifest.permission.ACCESS_FINE_LOCATION) fun refresh() { tel.requestCellInfoUpdate(mainExecutor, object : CellInfoCallback() { @RequiresPermission(Manifest.permission.ACCESS_FINE_LOCATION) override fun onCellInfo(cellList: List) { cellsListView.removeAllViews() - for (cell in cellList) { if (cell == null) { continue @@ -74,35 +124,58 @@ class MainActivity : AppCompatActivity() { } @SuppressLint("SetTextI18n") - fun addCellView(cell :CellInfo){ + fun addCellView(cell: CellInfo) { val id = getCellId(cell) + if (id == 65535 || id == 2147483647) { + return + } + + val lac = getCellLac(cell) + val findInDb = findInDb(lac.toInt(), id.toLong()) + val desc = findInDb?.Description ?: "" + var cellView = cellsList[id] if (cellView == null) { cellView = CellView(this, id) cellsList[id] = cellView + } else { + cellsListView.removeView(cellView) } when (cell) { is CellInfoGsm -> cellView.set(cell) - is CellInfoLte -> cellView.set(cell) - is CellInfoNr -> cellView.set(cell) - is CellInfoTdscdma -> cellView.set(cell) - is CellInfoWcdma -> cellView.set(cell) + is CellInfoLte -> cellView.set(cell) + is CellInfoNr -> cellView.set(cell) + is CellInfoTdscdma -> cellView.set(cell) + is CellInfoWcdma -> cellView.set(cell) } cellView.refresh() + cellView.setDesc(desc) cellsListView.addView(cellView) } } -fun getCellId(cell: CellInfo) : Number { +fun getCellId(cell: CellInfo): Number { when (cell) { is CellInfoGsm -> return cell.cellIdentity.cid - is CellInfoLte -> return cell.cellIdentity.ci - is CellInfoNr -> return (cell.cellIdentity as CellIdentityNr).nci - is CellInfoTdscdma -> return cell.cellIdentity.cid + is CellInfoLte -> return cell.cellIdentity.ci + is CellInfoNr -> return (cell.cellIdentity as CellIdentityNr).nci + is CellInfoTdscdma -> return cell.cellIdentity.cid is CellInfoWcdma -> return cell.cellIdentity.cid } + return 0 +} + +fun getCellLac(cell: CellInfo): Number { + when (cell) { + is CellInfoGsm -> return cell.cellIdentity.lac + is CellInfoLte -> return cell.cellIdentity.tac + is CellInfoNr -> return (cell.cellIdentity as CellIdentityNr).tac + is CellInfoTdscdma -> return cell.cellIdentity.lac + is CellInfoWcdma -> return cell.cellIdentity.lac + } + return 0 } \ No newline at end of file diff --git a/app/src/main/res/layout/cell_view.xml b/app/src/main/res/layout/cell_view.xml index 7361930..916f8cc 100644 --- a/app/src/main/res/layout/cell_view.xml +++ b/app/src/main/res/layout/cell_view.xml @@ -13,73 +13,84 @@ + android:layout_height="match_parent" + android:orientation="vertical"> - - + android:orientation="horizontal"> - + android:layout_marginEnd="10dp" + android:orientation="vertical"> - - - + - + - + - + - + android:orientation="vertical"> + + + + + + + + + + - - + android:layout_height="wrap_content" + android:text="desc" />