-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathContext.kt
46 lines (39 loc) · 1.68 KB
/
Context.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package org.fossify.phone.extensions
import android.annotation.SuppressLint
import android.content.Context
import android.media.AudioManager
import android.net.Uri
import android.os.PowerManager
import org.fossify.commons.extensions.telecomManager
import org.fossify.phone.helpers.Config
import org.fossify.phone.models.SIMAccount
val Context.config: Config get() = Config.newInstance(applicationContext)
val Context.audioManager: AudioManager get() = getSystemService(Context.AUDIO_SERVICE) as AudioManager
val Context.powerManager: PowerManager get() = getSystemService(Context.POWER_SERVICE) as PowerManager
@SuppressLint("MissingPermission")
fun Context.getAvailableSIMCardLabels(): List<SIMAccount> {
val SIMAccounts = mutableListOf<SIMAccount>()
try {
telecomManager.callCapablePhoneAccounts.forEachIndexed { index, account ->
val phoneAccount = telecomManager.getPhoneAccount(account)
var label = phoneAccount.label.toString()
var address = phoneAccount.address.toString()
if (address.startsWith("tel:") && address.substringAfter("tel:").isNotEmpty()) {
address = Uri.decode(address.substringAfter("tel:"))
label += " ($address)"
}
val SIM = SIMAccount(index + 1, phoneAccount.accountHandle, label, address.substringAfter("tel:"), phoneAccount.highlightColor)
SIMAccounts.add(SIM)
}
} catch (ignored: Exception) {
}
return SIMAccounts
}
@SuppressLint("MissingPermission")
fun Context.areMultipleSIMsAvailable(): Boolean {
return try {
telecomManager.callCapablePhoneAccounts.size > 1
} catch (ignored: Exception) {
false
}
}