Skip to content

Commit 016a0ea

Browse files
committed
fix: resolve lint missing permission on telephony reads
1 parent f1274e4 commit 016a0ea

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

app/src/main/java/com/appcontrolx/domain/SystemMonitor.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.appcontrolx.domain
22

33
import android.Manifest
4+
import android.annotation.SuppressLint
45
import android.app.ActivityManager
56
import android.app.usage.StorageStatsManager
67
import android.content.Context
@@ -583,7 +584,7 @@ class SystemMonitor @Inject constructor(
583584
val type = if (mobConnected) {
584585
if (hasReadPhoneStatePermission) {
585586
@Suppress("DEPRECATION")
586-
when (telephonyManager.networkType) {
587+
when (getTelephonyNetworkType(telephonyManager)) {
587588
TelephonyManager.NETWORK_TYPE_LTE -> "LTE"
588589
TelephonyManager.NETWORK_TYPE_NR -> "5G"
589590
TelephonyManager.NETWORK_TYPE_HSPAP -> "HSPA+"
@@ -598,7 +599,7 @@ class SystemMonitor @Inject constructor(
598599
} else ""
599600

600601
val sim = if (hasReadPhoneStatePermission) {
601-
telephonyManager.simState == TelephonyManager.SIM_STATE_READY
602+
getTelephonySimState(telephonyManager) == TelephonyManager.SIM_STATE_READY
602603
} else {
603604
false
604605
}
@@ -617,6 +618,16 @@ class SystemMonitor @Inject constructor(
617618
}
618619
}
619620

621+
@SuppressLint("MissingPermission")
622+
private fun getTelephonyNetworkType(telephonyManager: TelephonyManager): Int {
623+
return telephonyManager.networkType
624+
}
625+
626+
@SuppressLint("MissingPermission")
627+
private fun getTelephonySimState(telephonyManager: TelephonyManager): Int {
628+
return telephonyManager.simState
629+
}
630+
620631
private fun getDisplayStats(): DisplayStats {
621632
return try {
622633
val windowManager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager

0 commit comments

Comments
 (0)