Fix signal strength and adaptive icon
- Add signalStrength API fallback when allCellInfo returns empty - Create proper adaptive icon with vector foreground - Add logging to TetherStateReceiver for debugging autostart
This commit is contained in:
@@ -132,47 +132,65 @@ class StatusProvider(private val context: Context) {
|
|||||||
context, Manifest.permission.ACCESS_FINE_LOCATION
|
context, Manifest.permission.ACCESS_FINE_LOCATION
|
||||||
) == PackageManager.PERMISSION_GRANTED
|
) == PackageManager.PERMISSION_GRANTED
|
||||||
|
|
||||||
if (!hasLocationPermission) {
|
// Try allCellInfo first (requires location permission)
|
||||||
return Pair(-999, 0)
|
if (hasLocationPermission) {
|
||||||
|
try {
|
||||||
|
val cellInfoList: List<CellInfo>? = telephonyManager.allCellInfo
|
||||||
|
if (!cellInfoList.isNullOrEmpty()) {
|
||||||
|
for (cellInfo in cellInfoList) {
|
||||||
|
if (!cellInfo.isRegistered) continue
|
||||||
|
|
||||||
|
val dbm = when (cellInfo) {
|
||||||
|
is CellInfoLte -> cellInfo.cellSignalStrength.dbm
|
||||||
|
is CellInfoNr -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
|
cellInfo.cellSignalStrength.dbm
|
||||||
|
} else -999
|
||||||
|
is CellInfoGsm -> cellInfo.cellSignalStrength.dbm
|
||||||
|
is CellInfoWcdma -> cellInfo.cellSignalStrength.dbm
|
||||||
|
is CellInfoCdma -> cellInfo.cellSignalStrength.dbm
|
||||||
|
else -> continue
|
||||||
|
}
|
||||||
|
|
||||||
|
val level = when (cellInfo) {
|
||||||
|
is CellInfoLte -> cellInfo.cellSignalStrength.level
|
||||||
|
is CellInfoNr -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
|
cellInfo.cellSignalStrength.level
|
||||||
|
} else 0
|
||||||
|
is CellInfoGsm -> cellInfo.cellSignalStrength.level
|
||||||
|
is CellInfoWcdma -> cellInfo.cellSignalStrength.level
|
||||||
|
is CellInfoCdma -> cellInfo.cellSignalStrength.level
|
||||||
|
else -> continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dbm != -999 && dbm != Int.MAX_VALUE) {
|
||||||
|
return Pair(dbm, level)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e: SecurityException) {
|
||||||
|
// Fall through to signalStrength fallback
|
||||||
|
} catch (e: Exception) {
|
||||||
|
// Fall through to signalStrength fallback
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fallback: use signalStrength API (doesn't require location for basic level)
|
||||||
try {
|
try {
|
||||||
val cellInfoList: List<CellInfo>? = telephonyManager.allCellInfo
|
val signalStrength = telephonyManager.signalStrength
|
||||||
if (cellInfoList.isNullOrEmpty()) {
|
if (signalStrength != null) {
|
||||||
return Pair(-999, 0)
|
val level = signalStrength.level
|
||||||
}
|
// Try to get dBm from the signal strength
|
||||||
|
val dbm = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
for (cellInfo in cellInfoList) {
|
signalStrength.cellSignalStrengths.firstOrNull()?.dbm ?: -999
|
||||||
if (!cellInfo.isRegistered) continue
|
} else {
|
||||||
|
-999
|
||||||
val dbm = when (cellInfo) {
|
|
||||||
is CellInfoLte -> cellInfo.cellSignalStrength.dbm
|
|
||||||
is CellInfoNr -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
||||||
cellInfo.cellSignalStrength.dbm
|
|
||||||
} else -999
|
|
||||||
is CellInfoGsm -> cellInfo.cellSignalStrength.dbm
|
|
||||||
is CellInfoWcdma -> cellInfo.cellSignalStrength.dbm
|
|
||||||
is CellInfoCdma -> cellInfo.cellSignalStrength.dbm
|
|
||||||
else -> continue
|
|
||||||
}
|
}
|
||||||
|
if (level > 0 || dbm != -999) {
|
||||||
val level = when (cellInfo) {
|
return Pair(dbm, level)
|
||||||
is CellInfoLte -> cellInfo.cellSignalStrength.level
|
|
||||||
is CellInfoNr -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
||||||
cellInfo.cellSignalStrength.level
|
|
||||||
} else 0
|
|
||||||
is CellInfoGsm -> cellInfo.cellSignalStrength.level
|
|
||||||
is CellInfoWcdma -> cellInfo.cellSignalStrength.level
|
|
||||||
is CellInfoCdma -> cellInfo.cellSignalStrength.level
|
|
||||||
else -> continue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Pair(dbm, level)
|
|
||||||
}
|
}
|
||||||
} catch (e: SecurityException) {
|
|
||||||
return Pair(-999, 0)
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
return Pair(-999, 0)
|
// Ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
return Pair(-999, 0)
|
return Pair(-999, 0)
|
||||||
|
|||||||
@@ -5,12 +5,14 @@ import android.content.Context
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.ConnectivityManager
|
import android.net.ConnectivityManager
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
import android.util.Log
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import dev.itsh.tetherapi.service.TetherApiService
|
import dev.itsh.tetherapi.service.TetherApiService
|
||||||
|
|
||||||
class TetherStateReceiver : BroadcastReceiver() {
|
class TetherStateReceiver : BroadcastReceiver() {
|
||||||
|
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
|
Log.d(TAG, "Received broadcast: ${intent.action}")
|
||||||
if (intent.action != ACTION_TETHER_STATE_CHANGED) return
|
if (intent.action != ACTION_TETHER_STATE_CHANGED) return
|
||||||
|
|
||||||
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
@@ -21,9 +23,13 @@ class TetherStateReceiver : BroadcastReceiver() {
|
|||||||
val isTethering = isTetherActive(context, intent)
|
val isTethering = isTetherActive(context, intent)
|
||||||
val port = prefs.getInt(PREF_PORT, TetherApiService.DEFAULT_PORT)
|
val port = prefs.getInt(PREF_PORT, TetherApiService.DEFAULT_PORT)
|
||||||
|
|
||||||
|
Log.d(TAG, "Tethering active: $isTethering, service running: ${TetherApiService.isRunning}")
|
||||||
|
|
||||||
if (isTethering && !TetherApiService.isRunning) {
|
if (isTethering && !TetherApiService.isRunning) {
|
||||||
|
Log.d(TAG, "Starting service on port $port")
|
||||||
TetherApiService.start(context, port)
|
TetherApiService.start(context, port)
|
||||||
} else if (!isTethering && TetherApiService.isRunning) {
|
} else if (!isTethering && TetherApiService.isRunning) {
|
||||||
|
Log.d(TAG, "Stopping service")
|
||||||
TetherApiService.stop(context)
|
TetherApiService.stop(context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -54,6 +60,7 @@ class TetherStateReceiver : BroadcastReceiver() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
private const val TAG = "TetherStateReceiver"
|
||||||
const val ACTION_TETHER_STATE_CHANGED = "android.net.conn.TETHER_STATE_CHANGED"
|
const val ACTION_TETHER_STATE_CHANGED = "android.net.conn.TETHER_STATE_CHANGED"
|
||||||
const val PREF_AUTO_START = "auto_start_on_tether"
|
const val PREF_AUTO_START = "auto_start_on_tether"
|
||||||
const val PREF_PORT = "api_port"
|
const val PREF_PORT = "api_port"
|
||||||
|
|||||||
44
app/src/main/res/drawable/ic_launcher_foreground.xml
Normal file
44
app/src/main/res/drawable/ic_launcher_foreground.xml
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="108dp"
|
||||||
|
android:height="108dp"
|
||||||
|
android:viewportWidth="108"
|
||||||
|
android:viewportHeight="108">
|
||||||
|
|
||||||
|
<!-- Phone body -->
|
||||||
|
<path
|
||||||
|
android:fillColor="#1e293b"
|
||||||
|
android:pathData="M15.2,37h18.5c1.8,0 3.4,1.5 3.4,3.4v33.7c0,1.8 -1.5,3.4 -3.4,3.4H15.2c-1.8,0 -3.4,-1.5 -3.4,-3.4V40.4c0,-1.8 1.5,-3.4 3.4,-3.4z"/>
|
||||||
|
<!-- Phone screen -->
|
||||||
|
<path
|
||||||
|
android:fillColor="#ffffff"
|
||||||
|
android:pathData="M17.3,40h14.3c0.7,0 1.3,0.6 1.3,1.3v24.4c0,0.7 -0.6,1.3 -1.3,1.3H17.3c-0.7,0 -1.3,-0.6 -1.3,-1.3V41.3c0,-0.7 0.6,-1.3 1.3,-1.3z"/>
|
||||||
|
<!-- Phone button -->
|
||||||
|
<path
|
||||||
|
android:fillColor="#ffffff"
|
||||||
|
android:pathData="M21.1,66.5h6.7c0.3,0 0.6,0.3 0.6,0.6v1.3c0,0.3 -0.3,0.6 -0.6,0.6h-6.7c-0.3,0 -0.6,-0.3 -0.6,-0.6v-1.3c0,-0.3 0.3,-0.6 0.6,-0.6z"/>
|
||||||
|
|
||||||
|
<!-- Signal bars -->
|
||||||
|
<path
|
||||||
|
android:fillColor="#0ea5e9"
|
||||||
|
android:pathData="M40.5,56.8h4.2c0.4,0 0.8,0.4 0.8,0.8v9.3c0,0.4 -0.4,0.8 -0.8,0.8h-4.2c-0.4,0 -0.8,-0.4 -0.8,-0.8v-9.3c0,-0.4 0.4,-0.8 0.8,-0.8z"/>
|
||||||
|
<path
|
||||||
|
android:fillColor="#0ea5e9"
|
||||||
|
android:pathData="M47.2,51.8h4.2c0.4,0 0.8,0.4 0.8,0.8v14.3c0,0.4 -0.4,0.8 -0.8,0.8h-4.2c-0.4,0 -0.8,-0.4 -0.8,-0.8V52.6c0,-0.4 0.4,-0.8 0.8,-0.8z"/>
|
||||||
|
<path
|
||||||
|
android:fillColor="#0ea5e9"
|
||||||
|
android:pathData="M54,46.8h4.2c0.4,0 0.8,0.4 0.8,0.8v19.3c0,0.4 -0.4,0.8 -0.8,0.8H54c-0.4,0 -0.8,-0.4 -0.8,-0.8V47.6c0,-0.4 0.4,-0.8 0.8,-0.8z"/>
|
||||||
|
|
||||||
|
<!-- Laptop screen -->
|
||||||
|
<path
|
||||||
|
android:fillColor="#1e293b"
|
||||||
|
android:pathData="M65.7,41.3h27c1.3,0 2.5,1.2 2.5,2.5v18.5c0,1.3 -1.2,2.5 -2.5,2.5h-27c-1.3,0 -2.5,-1.2 -2.5,-2.5V43.8c0,-1.3 1.2,-2.5 2.5,-2.5z"/>
|
||||||
|
<!-- Laptop display -->
|
||||||
|
<path
|
||||||
|
android:fillColor="#ffffff"
|
||||||
|
android:pathData="M67.8,43.4h22.8c0.4,0 0.8,0.4 0.8,0.8v13.5c0,0.4 -0.4,0.8 -0.8,0.8H67.8c-0.4,0 -0.8,-0.4 -0.8,-0.8V44.2c0,-0.4 0.4,-0.8 0.8,-0.8z"/>
|
||||||
|
<!-- Laptop base -->
|
||||||
|
<path
|
||||||
|
android:fillColor="#1e293b"
|
||||||
|
android:pathData="M63.2,60.8h32c0.4,0 0.8,0.4 0.8,0.8v2.9c0,0.4 -0.4,0.8 -0.8,0.8h-32c-0.4,0 -0.8,-0.4 -0.8,-0.8v-2.9c0,-0.4 0.4,-0.8 0.8,-0.8z"/>
|
||||||
|
</vector>
|
||||||
5
app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
Normal file
5
app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<background android:drawable="@color/ic_launcher_background"/>
|
||||||
|
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
|
||||||
|
</adaptive-icon>
|
||||||
5
app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
Normal file
5
app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<background android:drawable="@color/ic_launcher_background"/>
|
||||||
|
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
|
||||||
|
</adaptive-icon>
|
||||||
@@ -13,4 +13,5 @@
|
|||||||
<color name="on_error">#FFFFFF</color>
|
<color name="on_error">#FFFFFF</color>
|
||||||
<color name="status_running">#4CAF50</color>
|
<color name="status_running">#4CAF50</color>
|
||||||
<color name="status_stopped">#9E9E9E</color>
|
<color name="status_stopped">#9E9E9E</color>
|
||||||
|
<color name="ic_launcher_background">#FFFFFF</color>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user