-
-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Quick Settings tiles to instantly control VoLTE setting (#253)
- Loading branch information
1 parent
e3a03f4
commit 4090fa6
Showing
9 changed files
with
285 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
78 changes: 78 additions & 0 deletions
78
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,78 @@ | ||
package dev.bluehouse.enablevolte | ||
|
||
import android.service.quicksettings.Tile | ||
import android.service.quicksettings.TileService | ||
import org.lsposed.hiddenapibypass.HiddenApiBypass | ||
import java.lang.IllegalStateException | ||
|
||
class SIM1IMSStatusQSTileService : IMSStatusQSTileService(0) | ||
class SIM2IMSStatusQSTileService : IMSStatusQSTileService(1) | ||
|
||
open class IMSStatusQSTileService(private val simSlotIndex: Int) : TileService() { | ||
private val TAG = "SIM${simSlotIndex}IMSStatusQSTileService" | ||
|
||
init { | ||
HiddenApiBypass.addHiddenApiExemptions("L") | ||
HiddenApiBypass.addHiddenApiExemptions("I") | ||
} | ||
|
||
private val moder: SubscriptionModer? get() { | ||
val carrierModer = CarrierModer(this.applicationContext) | ||
|
||
try { | ||
if (checkShizukuPermission(0) == ShizukuStatus.GRANTED && carrierModer.deviceSupportsIMS) { | ||
val sub = carrierModer.getActiveSubscriptionInfoForSimSlotIndex(this.simSlotIndex) | ||
?: return null | ||
return SubscriptionModer(sub.subscriptionId) | ||
} | ||
} catch (_: IllegalStateException) {} | ||
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 | ||
} | ||
} | ||
|
||
private fun refreshStatus() { | ||
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() | ||
} | ||
|
||
override fun onStartListening() { | ||
super.onStartListening() | ||
this.refreshStatus() | ||
} | ||
|
||
override fun onClick() { | ||
super.onClick() | ||
moder?.restartIMSRegistration() | ||
this.refreshStatus() | ||
} | ||
} |
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
90 changes: 90 additions & 0 deletions
90
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,90 @@ | ||
package dev.bluehouse.enablevolte | ||
|
||
import android.service.quicksettings.Tile | ||
import android.service.quicksettings.TileService | ||
import android.telephony.CarrierConfigManager | ||
import org.lsposed.hiddenapibypass.HiddenApiBypass | ||
import java.lang.IllegalStateException | ||
|
||
class SIM1VoLTEConfigToggleQSTileService : VoLTEConfigToggleQSTileService(0) | ||
class SIM2VoLTEConfigToggleQSTileService : VoLTEConfigToggleQSTileService(1) | ||
|
||
open class VoLTEConfigToggleQSTileService(private val simSlotIndex: Int) : TileService() { | ||
private val TAG = "SIM${simSlotIndex}VoLTEConfigToggleQSTileService" | ||
|
||
init { | ||
HiddenApiBypass.addHiddenApiExemptions("L") | ||
HiddenApiBypass.addHiddenApiExemptions("I") | ||
} | ||
|
||
private val moder: SubscriptionModer? get() { | ||
val carrierModer = CarrierModer(this.applicationContext) | ||
|
||
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 | ||
* 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() | ||
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() | ||
} | ||
|
||
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 (isLocked) { | ||
unlockAndRun { toggleVoLTEStatus() } | ||
} else { | ||
toggleVoLTEStatus() | ||
} | ||
} | ||
} |
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