mirror of
https://github.com/pppscn/SmsForwarder
synced 2025-08-02 17:07:41 +08:00
优化:统一卡槽ID枚举值( 0=Sim1, 1=Sim2, -1=获取失败)【未做机型适配】
This commit is contained in:
parent
74c25c8991
commit
e941fcf62b
@ -18,7 +18,7 @@ data class CallInfo(
|
||||
//被呼号码
|
||||
@SerializedName("via_number")
|
||||
var viaNumber: String = "",
|
||||
//卡槽ID: 1=Sim1, 2=Sim2, -1=获取失败
|
||||
//卡槽ID: 0=Sim1, 1=Sim2, -1=获取失败
|
||||
@SerializedName("sim_id")
|
||||
var simId: Int = -1,
|
||||
) : Serializable {
|
||||
@ -35,8 +35,8 @@ data class CallInfo(
|
||||
val simImageId: Int
|
||||
get() {
|
||||
return when (simId) {
|
||||
1 -> R.drawable.ic_sim1
|
||||
2 -> R.drawable.ic_sim2
|
||||
0 -> R.drawable.ic_sim1
|
||||
1 -> R.drawable.ic_sim2
|
||||
else -> R.drawable.ic_sim
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ data class SmsInfo(
|
||||
var date: Long = 0L,
|
||||
// 短信类型: 1=接收, 2=发送
|
||||
var type: Int = 1,
|
||||
// 卡槽ID: 1=Sim1, 2=Sim2, -1=获取失败
|
||||
// 卡槽ID: 0=Sim1, 1=Sim2, -1=获取失败
|
||||
@SerializedName("sim_id")
|
||||
var simId: Int = -1,
|
||||
) : Serializable {
|
||||
@ -25,8 +25,8 @@ data class SmsInfo(
|
||||
val simImageId: Int
|
||||
get() {
|
||||
return when (simId) {
|
||||
1 -> R.drawable.ic_sim1
|
||||
2 -> R.drawable.ic_sim2
|
||||
0 -> R.drawable.ic_sim1
|
||||
1 -> R.drawable.ic_sim2
|
||||
else -> R.drawable.ic_sim
|
||||
}
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ class SmsSendFragment : BaseFragment<FragmentClientSmsSendBinding?>(), View.OnCl
|
||||
override fun initListeners() {
|
||||
binding!!.btnSubmit.setOnClickListener(this)
|
||||
LiveEventBus.get(EVENT_KEY_SIM_SLOT, Int::class.java).observeSticky(this) { value: Int ->
|
||||
binding!!.rgSimSlot.check(if (value == 2) R.id.rb_sim_slot_2 else R.id.rb_sim_slot_1)
|
||||
binding!!.rgSimSlot.check(if (value == 1) R.id.rb_sim_slot_2 else R.id.rb_sim_slot_1)
|
||||
}
|
||||
LiveEventBus.get(EVENT_KEY_PHONE_NUMBERS, String::class.java).observeSticky(this) { value: String ->
|
||||
binding!!.etPhoneNumbers.setText(value)
|
||||
|
@ -56,6 +56,6 @@ class SmsController {
|
||||
|
||||
val limit = smsQueryData.pageSize
|
||||
val offset = (smsQueryData.pageNum - 1) * limit
|
||||
return PhoneUtils.getSmsList(smsQueryData.type, limit, offset, smsQueryData.keyword)
|
||||
return PhoneUtils.getSmsInfoList(smsQueryData.type, limit, offset, smsQueryData.keyword)
|
||||
}
|
||||
}
|
@ -73,35 +73,41 @@ class ForegroundService : Service() {
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
|
||||
//纯客户端模式
|
||||
if (SettingUtils.enablePureClientMode) return
|
||||
try {
|
||||
//纯客户端模式
|
||||
if (SettingUtils.enablePureClientMode) return
|
||||
|
||||
notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
|
||||
startForeground(FRONT_NOTIFY_ID, createForegroundNotification())
|
||||
isRunning = true
|
||||
notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
|
||||
startForeground(FRONT_NOTIFY_ID, createForegroundNotification())
|
||||
|
||||
//开关通知监听服务
|
||||
if (SettingUtils.enableAppNotify && CommonUtils.isNotificationListenerServiceEnabled(this)) {
|
||||
CommonUtils.toggleNotificationListenerService(this)
|
||||
}
|
||||
|
||||
//监听Frpc启动指令
|
||||
LiveEventBus.get(INTENT_FRPC_APPLY_FILE, String::class.java).observeStickyForever(frpcObserver)
|
||||
//自启动的Frpc
|
||||
GlobalScope.async(Dispatchers.IO) {
|
||||
val frpcList = AppDatabase.getInstance(App.context).frpcDao().getAutorun()
|
||||
|
||||
if (frpcList.isEmpty()) {
|
||||
Log.d(TAG, "没有自启动的Frpc")
|
||||
return@async
|
||||
//开关通知监听服务
|
||||
if (SettingUtils.enableAppNotify && CommonUtils.isNotificationListenerServiceEnabled(this)) {
|
||||
CommonUtils.toggleNotificationListenerService(this)
|
||||
}
|
||||
|
||||
for (frpc in frpcList) {
|
||||
val error = Frpclib.runContent(frpc.uid, frpc.config)
|
||||
if (!TextUtils.isEmpty(error)) {
|
||||
Log.e(TAG, error)
|
||||
//监听Frpc启动指令
|
||||
LiveEventBus.get(INTENT_FRPC_APPLY_FILE, String::class.java).observeStickyForever(frpcObserver)
|
||||
//自启动的Frpc
|
||||
GlobalScope.async(Dispatchers.IO) {
|
||||
val frpcList = AppDatabase.getInstance(App.context).frpcDao().getAutorun()
|
||||
|
||||
if (frpcList.isEmpty()) {
|
||||
Log.d(TAG, "没有自启动的Frpc")
|
||||
return@async
|
||||
}
|
||||
|
||||
for (frpc in frpcList) {
|
||||
val error = Frpclib.runContent(frpc.uid, frpc.config)
|
||||
if (!TextUtils.isEmpty(error)) {
|
||||
Log.e(TAG, error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
isRunning = true
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
isRunning = false
|
||||
}
|
||||
|
||||
}
|
||||
@ -118,9 +124,13 @@ class ForegroundService : Service() {
|
||||
return
|
||||
}
|
||||
|
||||
stopForeground(true)
|
||||
compositeDisposable.dispose()
|
||||
isRunning = false
|
||||
try {
|
||||
stopForeground(true)
|
||||
compositeDisposable.dispose()
|
||||
isRunning = false
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@ import android.text.TextUtils
|
||||
import android.util.Log
|
||||
import androidx.annotation.RequiresPermission
|
||||
import androidx.core.app.ActivityCompat
|
||||
import com.idormy.sms.forwarder.App
|
||||
import com.idormy.sms.forwarder.R
|
||||
import com.idormy.sms.forwarder.core.Core
|
||||
import com.idormy.sms.forwarder.entity.CallInfo
|
||||
@ -32,7 +33,6 @@ import com.xuexiang.xutil.resource.ResUtils
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
|
||||
@Suppress("PropertyName")
|
||||
class PhoneUtils private constructor() {
|
||||
|
||||
@ -86,6 +86,7 @@ class PhoneUtils private constructor() {
|
||||
} catch (e: java.lang.Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
Log.e(TAG, infoList.toString())
|
||||
return infoList
|
||||
}
|
||||
|
||||
@ -215,13 +216,15 @@ class PhoneUtils private constructor() {
|
||||
val indexDuration = cursor.getColumnIndex(CallLog.Calls.DURATION)
|
||||
val indexType = cursor.getColumnIndex(CallLog.Calls.TYPE)
|
||||
val indexViaNumber = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && cursor.getColumnIndex("via_number") != -1) cursor.getColumnIndex("via_number") else -1
|
||||
var isSimId = false
|
||||
var indexSimId = -1
|
||||
if (cursor.getColumnIndex("simid") != -1) {
|
||||
indexSimId = cursor.getColumnIndex("simid")
|
||||
} else if (cursor.getColumnIndex(CallLog.Calls.PHONE_ACCOUNT_ID) != -1
|
||||
if (cursor.getColumnIndex(CallLog.Calls.PHONE_ACCOUNT_ID) != -1
|
||||
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
|
||||
) {
|
||||
indexSimId = cursor.getColumnIndex(CallLog.Calls.PHONE_ACCOUNT_ID)
|
||||
} else if (cursor.getColumnIndex("simid") != -1) {
|
||||
indexSimId = cursor.getColumnIndex("simid")
|
||||
//isSimId = true
|
||||
}
|
||||
do {
|
||||
val callInfo = CallInfo(
|
||||
@ -231,7 +234,7 @@ class PhoneUtils private constructor() {
|
||||
cursor.getInt(indexDuration), //获取通话时长,值为多少秒
|
||||
cursor.getInt(indexType), //获取通话类型:1.呼入 2.呼出 3.未接
|
||||
if (indexViaNumber != -1) cursor.getString(indexViaNumber) else "", //来源号码
|
||||
if (indexSimId != -1) cursor.getInt(indexSimId) else -1 //卡槽id
|
||||
if (indexSimId != -1) getSimId(cursor.getInt(indexSimId), isSimId) else -1 //卡槽id
|
||||
)
|
||||
Log.d(TAG, callInfo.toString())
|
||||
callInfoList.add(callInfo)
|
||||
@ -261,14 +264,6 @@ class PhoneUtils private constructor() {
|
||||
var selection = "1=1"
|
||||
val selectionArgs = ArrayList<String>()
|
||||
if (!TextUtils.isEmpty(phoneNumber)) {
|
||||
/*selection += " and " + ContactsContract.CommonDataKinds.Phone.NUMBER + " in (?,?,?) "
|
||||
val phone1 = phoneNumber?.subSequence(0, 3).toString() + " " + phoneNumber?.substring(3, 7) +
|
||||
" " + phoneNumber?.substring(7)
|
||||
val phone2 = phoneNumber?.subSequence(0, 3).toString() + "-" + phoneNumber?.substring(3, 7) +
|
||||
"-" + phoneNumber?.substring(7)
|
||||
selectionArgs.add("%$phoneNumber%")
|
||||
selectionArgs.add("%$phone1%")
|
||||
selectionArgs.add("%$phone2%")*/
|
||||
selection += " and replace(replace(" + ContactsContract.CommonDataKinds.Phone.NUMBER + ",' ',''),'-','') like ?"
|
||||
selectionArgs.add("%$phoneNumber%")
|
||||
}
|
||||
@ -360,7 +355,7 @@ class PhoneUtils private constructor() {
|
||||
}
|
||||
|
||||
// 获取用户短信列表
|
||||
fun getSmsList(type: Int, limit: Int, offset: Int, keyword: String): MutableList<SmsInfo> {
|
||||
fun getSmsInfoList(type: Int, limit: Int, offset: Int, keyword: String): MutableList<SmsInfo> {
|
||||
val smsInfoList: MutableList<SmsInfo> = mutableListOf()
|
||||
try {
|
||||
var selection = "1=1"
|
||||
@ -402,6 +397,7 @@ class PhoneUtils private constructor() {
|
||||
val indexBody = cursor.getColumnIndex("body")
|
||||
val indexDate = cursor.getColumnIndex("date")
|
||||
val indexType = cursor.getColumnIndex("type")
|
||||
var isSimId = false
|
||||
var indexSimId = -1
|
||||
if (cursor.getColumnIndex("sim_id") != -1) {
|
||||
indexSimId = cursor.getColumnIndex("sim_id")
|
||||
@ -421,7 +417,7 @@ class PhoneUtils private constructor() {
|
||||
// 短信类型: 1=接收, 2=发送
|
||||
smsInfo.type = cursor.getInt(indexType)
|
||||
// 卡槽id
|
||||
smsInfo.simId = if (indexSimId != -1) cursor.getInt(indexSimId) else -1
|
||||
smsInfo.simId = if (indexSimId != -1) getSimId(cursor.getInt(indexSimId), isSimId) else -1
|
||||
smsInfoList.add(smsInfo)
|
||||
} while (cursor.moveToNext())
|
||||
if (!cursor.isClosed) cursor.close()
|
||||
@ -452,6 +448,36 @@ class PhoneUtils private constructor() {
|
||||
XUtil.getContext().startActivity(IntentUtils.getCallIntent(phoneNumber, true))
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 subscription_id 转成 卡槽ID: 0=Sim1, 1=Sim2, -1=获取失败
|
||||
*
|
||||
* TODO: 这里有坑,每个品牌定制系统的字段不太一样,不一定能获取到卡槽ID
|
||||
* 测试通过:MIUI 测试失败:原生 Android 11(Google Pixel 2 XL)
|
||||
*
|
||||
* @param mId SubscriptionId
|
||||
* @param isSimId 是否已经是SimId无需转换(待做机型兼容)
|
||||
*/
|
||||
private fun getSimId(mId: Int, isSimId: Boolean): Int {
|
||||
Log.i(TAG, "mId = $mId, isSimId = $isSimId")
|
||||
if (isSimId) return mId
|
||||
|
||||
//获取卡槽信息
|
||||
if (App.SimInfoList.isEmpty()) {
|
||||
App.SimInfoList = getSimMultiInfo()
|
||||
}
|
||||
Log.i(TAG, "SimInfoList = " + App.SimInfoList.toString())
|
||||
|
||||
val simSlot = -1
|
||||
if (App.SimInfoList.isEmpty()) return simSlot
|
||||
for (simInfo in App.SimInfoList.values) {
|
||||
if (simInfo.mSubscriptionId == mId && simInfo.mSimSlotIndex != -1) {
|
||||
Log.i(TAG, "simInfo = $simInfo")
|
||||
return simInfo.mSimSlotIndex
|
||||
}
|
||||
}
|
||||
return simSlot
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
init {
|
||||
|
Loading…
x
Reference in New Issue
Block a user