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 --- .idea/.gitignore | 3 + .idea/AndroidProjectSystem.xml | 6 ++ .idea/compiler.xml | 6 ++ .idea/deploymentTargetSelector.xml | 18 ++++ .idea/deviceManager.xml | 13 +++ .idea/dictionaries/project.xml | 8 ++ .idea/gradle.xml | 17 ++++ .idea/misc.xml | 10 +++ .idea/runConfigurations.xml | 17 ++++ .idea/vcs.xml | 6 ++ app/build.gradle.kts | 8 +- 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 ++ gradle/libs.versions.toml | 6 ++ 22 files changed, 315 insertions(+), 16 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/AndroidProjectSystem.xml create mode 100644 .idea/compiler.xml create mode 100644 .idea/deploymentTargetSelector.xml create mode 100644 .idea/deviceManager.xml create mode 100644 .idea/dictionaries/project.xml create mode 100644 .idea/gradle.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/runConfigurations.xml create mode 100644 .idea/vcs.xml 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 diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/AndroidProjectSystem.xml b/.idea/AndroidProjectSystem.xml new file mode 100644 index 0000000..4a53bee --- /dev/null +++ b/.idea/AndroidProjectSystem.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..b86273d --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml new file mode 100644 index 0000000..df74897 --- /dev/null +++ b/.idea/deploymentTargetSelector.xml @@ -0,0 +1,18 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/deviceManager.xml b/.idea/deviceManager.xml new file mode 100644 index 0000000..91f9558 --- /dev/null +++ b/.idea/deviceManager.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/.idea/dictionaries/project.xml b/.idea/dictionaries/project.xml new file mode 100644 index 0000000..ffb84f9 --- /dev/null +++ b/.idea/dictionaries/project.xml @@ -0,0 +1,8 @@ + + + + tdscdma + wcdma + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..cdbc250 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..74dd639 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..16660f1 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 98e6f42..21281d3 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -12,7 +12,7 @@ android { defaultConfig { applicationId = "net.rctt.netmon" - minSdk = 26 + minSdk = 29 targetSdk = 36 versionCode = 1 versionName = "1.0" @@ -33,6 +33,9 @@ android { sourceCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_11 } + buildFeatures { + viewBinding = true + } } dependencies { @@ -41,6 +44,9 @@ dependencies { implementation(libs.material) implementation(libs.androidx.activity) implementation(libs.androidx.constraintlayout) + implementation(libs.androidx.lifecycle.livedata.ktx) + implementation(libs.androidx.lifecycle.viewmodel.ktx) + implementation(libs.androidx.cardview) testImplementation(libs.junit) androidTestImplementation(libs.androidx.junit) androidTestImplementation(libs.androidx.espresso.core) 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 @@ + +