Skip to content

Commit

Permalink
Merge pull request #178 from chenxiaolong/multisim
Browse files Browse the repository at this point in the history
Add SIM slot ID to the filename if there are multiple active SIMs
  • Loading branch information
chenxiaolong authored Nov 28, 2022
2 parents a71e87d + e5fdd8d commit 9a2e73f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<uses-permission android:name="android.permission.VIBRATE" />

Expand Down
5 changes: 4 additions & 1 deletion app/src/main/java/com/chiller3/bcr/Permissions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ object Permissions {
}

val REQUIRED: Array<String> = arrayOf(Manifest.permission.RECORD_AUDIO) + NOTIFICATION
val OPTIONAL: Array<String> = arrayOf(Manifest.permission.READ_CONTACTS)
val OPTIONAL: Array<String> = arrayOf(
Manifest.permission.READ_CONTACTS,
Manifest.permission.READ_PHONE_STATE,
)

private fun isGranted(context: Context, permission: String) =
ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED
Expand Down
22 changes: 22 additions & 0 deletions app/src/main/java/com/chiller3/bcr/RecorderThread.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.chiller3.bcr

import android.Manifest
import android.annotation.SuppressLint
import android.content.Context
import android.content.pm.PackageManager
import android.media.AudioFormat
import android.media.AudioRecord
import android.media.MediaRecorder
Expand All @@ -13,6 +15,8 @@ import android.system.Os
import android.system.OsConstants
import android.telecom.Call
import android.telecom.PhoneAccount
import android.telephony.SubscriptionManager
import android.telephony.TelephonyManager
import android.util.Log
import androidx.core.net.toFile
import androidx.documentfile.provider.DocumentFile
Expand Down Expand Up @@ -121,6 +125,24 @@ class RecorderThread(
}
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R
&& context.checkSelfPermission(Manifest.permission.READ_PHONE_STATE)
== PackageManager.PERMISSION_GRANTED
&& context.packageManager.hasSystemFeature(
PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION)) {
val subscriptionManager = context.getSystemService(SubscriptionManager::class.java)

// Only append SIM slot ID if the device has multiple active SIMs
if (subscriptionManager.activeSubscriptionInfoCount > 1) {
val telephonyManager = context.getSystemService(TelephonyManager::class.java)
val subscriptionId = telephonyManager.getSubscriptionId(details.accountHandle)
val subscriptionInfo = subscriptionManager.getActiveSubscriptionInfo(subscriptionId)

append("_sim")
append(subscriptionInfo.simSlotIndex + 1)
}
}

if (details.handle?.scheme == PhoneAccount.SCHEME_TEL) {
append('_')
append(details.handle.schemeSpecificPart)
Expand Down

0 comments on commit 9a2e73f

Please sign in to comment.