From 2937bc975848e7979287e7067f4fff10bbfe4988 Mon Sep 17 00:00:00 2001 From: bt Date: Sun, 3 May 2026 03:27:18 +0200 Subject: Basic current cell info view --- app/src/main/AndroidManifest.xml | 11 +-- app/src/main/java/net/rctt/netmon/MainActivity.kt | 104 ++++++++++++++++++++++ app/src/main/res/layout/activity_main.xml | 63 ++++++++++--- app/src/main/res/values-land/dimens.xml | 3 + app/src/main/res/values-w1240dp/dimens.xml | 3 + app/src/main/res/values-w600dp/dimens.xml | 3 + app/src/main/res/values-w820dp/dimens.xml | 6 ++ app/src/main/res/values/dimens.xml | 8 ++ app/src/main/res/values/strings.xml | 3 + app/src/main/res/values/themes.xml | 9 ++ 10 files changed, 198 insertions(+), 15 deletions(-) create mode 100644 app/src/main/res/values-land/dimens.xml create mode 100644 app/src/main/res/values-w1240dp/dimens.xml create mode 100644 app/src/main/res/values-w600dp/dimens.xml create mode 100644 app/src/main/res/values-w820dp/dimens.xml create mode 100644 app/src/main/res/values/dimens.xml (limited to 'app/src') diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 87305ab..d036883 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,8 @@ - + + + + + android:theme="@style/Theme.Netmon"> + android:exported="true"> - diff --git a/app/src/main/java/net/rctt/netmon/MainActivity.kt b/app/src/main/java/net/rctt/netmon/MainActivity.kt index 53c6f05..7111922 100644 --- a/app/src/main/java/net/rctt/netmon/MainActivity.kt +++ b/app/src/main/java/net/rctt/netmon/MainActivity.kt @@ -1,12 +1,34 @@ package net.rctt.netmon +import android.Manifest +import android.annotation.SuppressLint import android.os.Bundle +import android.os.Handler +import android.os.Looper +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 android.util.Log +import android.widget.LinearLayout +import android.widget.TextView import androidx.activity.enableEdgeToEdge +import androidx.annotation.RequiresPermission import androidx.appcompat.app.AppCompatActivity +import androidx.core.content.ContextCompat import androidx.core.view.ViewCompat import androidx.core.view.WindowInsetsCompat +import java.text.SimpleDateFormat +import java.util.Date class MainActivity : AppCompatActivity() { + lateinit var statusView: LinearLayout + lateinit var cellView: LinearLayout + + lateinit var tel: TelephonyManager + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) enableEdgeToEdge() @@ -16,5 +38,87 @@ class MainActivity : AppCompatActivity() { v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom) insets } + + statusView = findViewById(R.id.statusView) + cellView = findViewById(R.id.cellView) + + val pLoc = ContextCompat.checkSelfPermission(applicationContext, Manifest.permission.ACCESS_FINE_LOCATION) + if (pLoc == -1) { + log("Location permission required") + } else { + log("Ready") + tel = getSystemService(TELEPHONY_SERVICE) as TelephonyManager + + val mainHandler = Handler(Looper.getMainLooper()) + + mainHandler.post(object : Runnable { + @RequiresPermission(Manifest.permission.ACCESS_FINE_LOCATION) + override fun run() { + refresh() + mainHandler.postDelayed(this, 1000) + } + }) + } + } + + @RequiresPermission(Manifest.permission.ACCESS_FINE_LOCATION) + fun refresh() { + log("refreshing") + + val cellList = tel.allCellInfo + cellView.removeAllViews() + for (cell in cellList) { + when (cell) { + is CellInfoGsm -> { + logDetected("GSM") + } + is CellInfoLte -> { + val id = cell.cellIdentity + if (id.ci == 2147483647) { + continue + } + + logDetected("LTE") + logCell("CID: ${id.ci}") + logCell("PCI: ${id.pci}") + logCell("TAC: ${id.tac}") + logCell("EARFCN ${id.earfcn}") + logCell("BANDWIDTH: ${id.bandwidth}") + logCell("RSRP: ${cell.cellSignalStrength.rsrp}") + logCell("DBM: ${cell.cellSignalStrength.dbm}") + logCell("STATUS: ${cell.cellConnectionStatus}") + logCell("") + } + is CellInfoNr -> { + logDetected("NR") + } + is CellInfoTdscdma -> { + logDetected("TDSCDMA") + } + is CellInfoWcdma -> { + logDetected("WCDMA") + } + } + } + } + + @SuppressLint("SimpleDateFormat", "SetTextI18n") + fun log(text: String) { + val sdf = SimpleDateFormat("hh:mm:ss") + val date = sdf.format(Date()) + val msg = TextView(this) + msg.text = "$date $text" + statusView.addView(msg) + } + + fun logDetected(text: String) { + log("detected $text cell") + } + + fun logCell(text: String) { + val msg = TextView(this) + msg.text = text + cellView.addView(msg) + Log.d("NETMON", text) } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 25a2ae6..e7c0e2c 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -7,13 +7,56 @@ android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> - - - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-land/dimens.xml b/app/src/main/res/values-land/dimens.xml new file mode 100644 index 0000000..22d7f00 --- /dev/null +++ b/app/src/main/res/values-land/dimens.xml @@ -0,0 +1,3 @@ + + 48dp + \ No newline at end of file diff --git a/app/src/main/res/values-w1240dp/dimens.xml b/app/src/main/res/values-w1240dp/dimens.xml new file mode 100644 index 0000000..d73f4a3 --- /dev/null +++ b/app/src/main/res/values-w1240dp/dimens.xml @@ -0,0 +1,3 @@ + + 200dp + \ No newline at end of file diff --git a/app/src/main/res/values-w600dp/dimens.xml b/app/src/main/res/values-w600dp/dimens.xml new file mode 100644 index 0000000..22d7f00 --- /dev/null +++ b/app/src/main/res/values-w600dp/dimens.xml @@ -0,0 +1,3 @@ + + 48dp + \ No newline at end of file diff --git a/app/src/main/res/values-w820dp/dimens.xml b/app/src/main/res/values-w820dp/dimens.xml new file mode 100644 index 0000000..9309de9 --- /dev/null +++ b/app/src/main/res/values-w820dp/dimens.xml @@ -0,0 +1,6 @@ + + + 64dp + \ No newline at end of file diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml new file mode 100644 index 0000000..0a87b6e --- /dev/null +++ b/app/src/main/res/values/dimens.xml @@ -0,0 +1,8 @@ + + + 16dp + 16dp + 16dp + 16dp + 8dp + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1d0121e..2c29dfa 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,3 +1,6 @@ netmon + MainActivity2 + Tab 1 + Tab 2 \ No newline at end of file diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 9b8da79..8c1e2ef 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -6,4 +6,13 @@ + +