From 7d6245721d3a62d194ac4de96b28069f7f9a2d6a Mon Sep 17 00:00:00 2001 From: Kyujin Cho Date: Fri, 16 Feb 2024 18:21:55 +0900 Subject: [PATCH] fix app crashing --- .../enablevolte/IMSStatusQSTileService.kt | 25 +++++++----------- .../java/dev/bluehouse/enablevolte/Utils.kt | 2 +- .../VoLTEConfigToggleQSTileService.kt | 26 +++++++------------ .../dev/bluehouse/enablevolte/pages/Config.kt | 3 --- 4 files changed, 20 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/dev/bluehouse/enablevolte/IMSStatusQSTileService.kt b/app/src/main/java/dev/bluehouse/enablevolte/IMSStatusQSTileService.kt index 819535e..0685ea2 100644 --- a/app/src/main/java/dev/bluehouse/enablevolte/IMSStatusQSTileService.kt +++ b/app/src/main/java/dev/bluehouse/enablevolte/IMSStatusQSTileService.kt @@ -9,16 +9,19 @@ class SIM1IMSStatusQSTileService : IMSStatusQSTileService(0) class SIM2IMSStatusQSTileService : IMSStatusQSTileService(1) open class IMSStatusQSTileService(private val simSlotIndex: Int) : TileService() { - val TAG = "SIM${simSlotIndex}IMSStatusQSTileService" + private val TAG = "SIM${simSlotIndex}IMSStatusQSTileService" private val moder: SubscriptionModer? get() { val carrierModer = CarrierModer(this.applicationContext) - if (checkShizukuPermission(0) == ShizukuStatus.GRANTED && carrierModer.deviceSupportsIMS) { - val subscriptions = carrierModer.subscriptions - val sub = carrierModer.getActiveSubscriptionInfoForSimSlotIndex(this.simSlotIndex) ?: return null - return SubscriptionModer(sub.subscriptionId) - } + try { + if (checkShizukuPermission(0) == ShizukuStatus.GRANTED && carrierModer.deviceSupportsIMS) { + carrierModer.subscriptions + val sub = carrierModer.getActiveSubscriptionInfoForSimSlotIndex(this.simSlotIndex) + ?: return null + return SubscriptionModer(sub.subscriptionId) + } + } catch (_: IllegalStateException) {} return null } private val imsActivated: Boolean? get() { @@ -59,14 +62,4 @@ open class IMSStatusQSTileService(private val simSlotIndex: Int) : TileService() ) qsTile.updateTile() } - - // Called when your app can no longer update your tile. - override fun onStopListening() { - super.onStopListening() - } - - // Called when the user removes your tile. - override fun onTileRemoved() { - super.onTileRemoved() - } } diff --git a/app/src/main/java/dev/bluehouse/enablevolte/Utils.kt b/app/src/main/java/dev/bluehouse/enablevolte/Utils.kt index 97ae7d1..359dd5d 100644 --- a/app/src/main/java/dev/bluehouse/enablevolte/Utils.kt +++ b/app/src/main/java/dev/bluehouse/enablevolte/Utils.kt @@ -33,7 +33,7 @@ fun checkShizukuPermission(code: Int): ShizukuStatus { } val SubscriptionInfo.uniqueName: String - get() = "${this.displayName} (SIM ${this.simSlotIndex+1})" + get() = "${this.displayName} (SIM ${this.simSlotIndex + 1})" fun getLatestAppVersion(handler: (String) -> Unit) { "https://api.github.com/repos/kyujin-cho/pixel-volte-patch/releases" diff --git a/app/src/main/java/dev/bluehouse/enablevolte/VoLTEConfigToggleQSTileService.kt b/app/src/main/java/dev/bluehouse/enablevolte/VoLTEConfigToggleQSTileService.kt index 2c6e21a..6c736be 100644 --- a/app/src/main/java/dev/bluehouse/enablevolte/VoLTEConfigToggleQSTileService.kt +++ b/app/src/main/java/dev/bluehouse/enablevolte/VoLTEConfigToggleQSTileService.kt @@ -10,18 +10,22 @@ class SIM1VoLTEConfigToggleQSTileService : VoLTEConfigToggleQSTileService(0) class SIM2VoLTEConfigToggleQSTileService : VoLTEConfigToggleQSTileService(1) open class VoLTEConfigToggleQSTileService(private val simSlotIndex: Int) : TileService() { - val TAG = "SIM${simSlotIndex}VoLTEConfigToggleQSTileService" + private val TAG = "SIM${simSlotIndex}VoLTEConfigToggleQSTileService" private val moder: SubscriptionModer? get() { val carrierModer = CarrierModer(this.applicationContext) - if (checkShizukuPermission(0) == ShizukuStatus.GRANTED && carrierModer.deviceSupportsIMS) { - val subscriptions = carrierModer.subscriptions - val sub = carrierModer.getActiveSubscriptionInfoForSimSlotIndex(this.simSlotIndex) ?: return null - return SubscriptionModer(sub.subscriptionId) - } + try { + if (checkShizukuPermission(0) == ShizukuStatus.GRANTED && carrierModer.deviceSupportsIMS) { + carrierModer.subscriptions + val sub = carrierModer.getActiveSubscriptionInfoForSimSlotIndex(this.simSlotIndex) + ?: return null + return SubscriptionModer(sub.subscriptionId) + } + } catch (_: IllegalStateException) {} return null } + private val volteEnabled: Boolean? get() { /* * true: VoLTE enabled @@ -60,11 +64,6 @@ open class VoLTEConfigToggleQSTileService(private val simSlotIndex: Int) : TileS qsTile.updateTile() } - // Called when your app can no longer update your tile. - override fun onStopListening() { - super.onStopListening() - } - private fun toggleVoLTEStatus() { val moder = this.moder ?: return val volteEnabled = this.volteEnabled ?: return @@ -84,9 +83,4 @@ open class VoLTEConfigToggleQSTileService(private val simSlotIndex: Int) : TileS toggleVoLTEStatus() } } - - // Called when the user removes your tile. - override fun onTileRemoved() { - super.onTileRemoved() - } } diff --git a/app/src/main/java/dev/bluehouse/enablevolte/pages/Config.kt b/app/src/main/java/dev/bluehouse/enablevolte/pages/Config.kt index c22386f..baed722 100644 --- a/app/src/main/java/dev/bluehouse/enablevolte/pages/Config.kt +++ b/app/src/main/java/dev/bluehouse/enablevolte/pages/Config.kt @@ -2,7 +2,6 @@ package dev.bluehouse.enablevolte.pages import android.app.StatusBarManager import android.content.ComponentName -import android.content.Context import android.graphics.drawable.Icon import android.os.Build import android.os.Build.VERSION @@ -29,7 +28,6 @@ import dev.bluehouse.enablevolte.BooleanPropertyView import dev.bluehouse.enablevolte.CarrierModer import dev.bluehouse.enablevolte.ClickablePropertyView import dev.bluehouse.enablevolte.HeaderText -import dev.bluehouse.enablevolte.IMSStatusQSTileService import dev.bluehouse.enablevolte.InfiniteLoadingDialog import dev.bluehouse.enablevolte.KeyValueEditView import dev.bluehouse.enablevolte.R @@ -37,7 +35,6 @@ import dev.bluehouse.enablevolte.ShizukuStatus import dev.bluehouse.enablevolte.SubscriptionModer import dev.bluehouse.enablevolte.UserAgentPropertyView import dev.bluehouse.enablevolte.ValueType -import dev.bluehouse.enablevolte.VoLTEConfigToggleQSTileService import dev.bluehouse.enablevolte.checkShizukuPermission import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch