-
-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement Quick Settings tiles to instantly control VoLTE setting
- Loading branch information
1 parent
f506ae0
commit 32aa093
Showing
9 changed files
with
284 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
app/src/main/java/dev/bluehouse/enablevolte/IMSStatusQSTileService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package dev.bluehouse.enablevolte | ||
|
||
import android.service.quicksettings.Tile | ||
import android.service.quicksettings.TileService | ||
import android.util.Log | ||
import java.lang.IllegalStateException | ||
|
||
class SIM1IMSStatusQSTileService : IMSStatusQSTileService(0) | ||
class SIM2IMSStatusQSTileService : IMSStatusQSTileService(1) | ||
|
||
open class IMSStatusQSTileService(private val simSlotIndex: Int) : TileService() { | ||
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) | ||
} | ||
return null | ||
} | ||
private val imsActivated: Boolean? get() { | ||
/* | ||
* true: VoLTE enabled | ||
* false: VoLTE disabled | ||
* null: cannot determine status (Shizuku not running or permission not granted, SIM slot not active, ...) | ||
*/ | ||
val moder = this.moder ?: return null | ||
try { | ||
return moder.isIMSRegistered | ||
} catch (_: IllegalStateException) {} | ||
return null | ||
} | ||
|
||
override fun onTileAdded() { | ||
super.onTileAdded() | ||
if (this.imsActivated == null) { | ||
qsTile.state = Tile.STATE_UNAVAILABLE | ||
} | ||
} | ||
|
||
override fun onStartListening() { | ||
super.onStartListening() | ||
Log.d(TAG, "onStartListening()") | ||
val imsActivated = this.imsActivated | ||
qsTile.state = when (imsActivated) { | ||
true -> Tile.STATE_ACTIVE | ||
false -> Tile.STATE_INACTIVE | ||
null -> Tile.STATE_UNAVAILABLE | ||
} | ||
qsTile.subtitle = getString( | ||
when (imsActivated) { | ||
true -> R.string.registered | ||
false -> R.string.unregistered | ||
null -> R.string.unknown | ||
}, | ||
) | ||
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
app/src/main/java/dev/bluehouse/enablevolte/VoLTEConfigToggleQSTileService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package dev.bluehouse.enablevolte | ||
|
||
import android.service.quicksettings.Tile | ||
import android.service.quicksettings.TileService | ||
import android.telephony.CarrierConfigManager | ||
import android.util.Log | ||
import java.lang.IllegalStateException | ||
|
||
class SIM1VoLTEConfigToggleQSTileService : VoLTEConfigToggleQSTileService(0) | ||
class SIM2VoLTEConfigToggleQSTileService : VoLTEConfigToggleQSTileService(1) | ||
|
||
open class VoLTEConfigToggleQSTileService(private val simSlotIndex: Int) : TileService() { | ||
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) | ||
} | ||
return null | ||
} | ||
private val volteEnabled: Boolean? get() { | ||
/* | ||
* true: VoLTE enabled | ||
* false: VoLTE disabled | ||
* null: cannot determine status (Shizuku not running or permission not granted, SIM slot not active, ...) | ||
*/ | ||
val moder = this.moder ?: return null | ||
try { | ||
return moder.isVoLteConfigEnabled | ||
} catch (_: IllegalStateException) {} | ||
return null | ||
} | ||
|
||
override fun onTileAdded() { | ||
super.onTileAdded() | ||
if (this.volteEnabled == null) { | ||
qsTile.state = Tile.STATE_UNAVAILABLE | ||
} | ||
} | ||
|
||
override fun onStartListening() { | ||
super.onStartListening() | ||
Log.d(TAG, "onStartListening()") | ||
qsTile.state = when (this.volteEnabled) { | ||
true -> Tile.STATE_ACTIVE | ||
false -> Tile.STATE_INACTIVE | ||
null -> Tile.STATE_UNAVAILABLE | ||
} | ||
qsTile.subtitle = getString( | ||
when (this.volteEnabled) { | ||
true -> R.string.enabled | ||
false -> R.string.disabled | ||
null -> R.string.unknown | ||
}, | ||
) | ||
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 | ||
moder.updateCarrierConfig(CarrierConfigManager.KEY_CARRIER_VOLTE_AVAILABLE_BOOL, !volteEnabled) | ||
moder.restartIMSRegistration() | ||
qsTile.state = if (volteEnabled) Tile.STATE_INACTIVE else Tile.STATE_ACTIVE | ||
qsTile.subtitle = getString(if (volteEnabled) R.string.disabled else R.string.enabled) | ||
qsTile.updateTile() | ||
} | ||
|
||
// Called when the user taps on your tile in an active or inactive state. | ||
override fun onClick() { | ||
super.onClick() | ||
if (!isSecure) { | ||
unlockAndRun { toggleVoLTEStatus() } | ||
} else { | ||
toggleVoLTEStatus() | ||
} | ||
} | ||
|
||
// Called when the user removes your tile. | ||
override fun onTileRemoved() { | ||
super.onTileRemoved() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters