mirror of
https://github.com/pppscn/SmsForwarder
synced 2025-08-03 09:27: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")
|
@SerializedName("via_number")
|
||||||
var viaNumber: String = "",
|
var viaNumber: String = "",
|
||||||
//卡槽ID: 1=Sim1, 2=Sim2, -1=获取失败
|
//卡槽ID: 0=Sim1, 1=Sim2, -1=获取失败
|
||||||
@SerializedName("sim_id")
|
@SerializedName("sim_id")
|
||||||
var simId: Int = -1,
|
var simId: Int = -1,
|
||||||
) : Serializable {
|
) : Serializable {
|
||||||
@ -35,8 +35,8 @@ data class CallInfo(
|
|||||||
val simImageId: Int
|
val simImageId: Int
|
||||||
get() {
|
get() {
|
||||||
return when (simId) {
|
return when (simId) {
|
||||||
1 -> R.drawable.ic_sim1
|
0 -> R.drawable.ic_sim1
|
||||||
2 -> R.drawable.ic_sim2
|
1 -> R.drawable.ic_sim2
|
||||||
else -> R.drawable.ic_sim
|
else -> R.drawable.ic_sim
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ data class SmsInfo(
|
|||||||
var date: Long = 0L,
|
var date: Long = 0L,
|
||||||
// 短信类型: 1=接收, 2=发送
|
// 短信类型: 1=接收, 2=发送
|
||||||
var type: Int = 1,
|
var type: Int = 1,
|
||||||
// 卡槽ID: 1=Sim1, 2=Sim2, -1=获取失败
|
// 卡槽ID: 0=Sim1, 1=Sim2, -1=获取失败
|
||||||
@SerializedName("sim_id")
|
@SerializedName("sim_id")
|
||||||
var simId: Int = -1,
|
var simId: Int = -1,
|
||||||
) : Serializable {
|
) : Serializable {
|
||||||
@ -25,8 +25,8 @@ data class SmsInfo(
|
|||||||
val simImageId: Int
|
val simImageId: Int
|
||||||
get() {
|
get() {
|
||||||
return when (simId) {
|
return when (simId) {
|
||||||
1 -> R.drawable.ic_sim1
|
0 -> R.drawable.ic_sim1
|
||||||
2 -> R.drawable.ic_sim2
|
1 -> R.drawable.ic_sim2
|
||||||
else -> R.drawable.ic_sim
|
else -> R.drawable.ic_sim
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ class SmsSendFragment : BaseFragment<FragmentClientSmsSendBinding?>(), View.OnCl
|
|||||||
override fun initListeners() {
|
override fun initListeners() {
|
||||||
binding!!.btnSubmit.setOnClickListener(this)
|
binding!!.btnSubmit.setOnClickListener(this)
|
||||||
LiveEventBus.get(EVENT_KEY_SIM_SLOT, Int::class.java).observeSticky(this) { value: Int ->
|
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 ->
|
LiveEventBus.get(EVENT_KEY_PHONE_NUMBERS, String::class.java).observeSticky(this) { value: String ->
|
||||||
binding!!.etPhoneNumbers.setText(value)
|
binding!!.etPhoneNumbers.setText(value)
|
||||||
|
@ -56,6 +56,6 @@ class SmsController {
|
|||||||
|
|
||||||
val limit = smsQueryData.pageSize
|
val limit = smsQueryData.pageSize
|
||||||
val offset = (smsQueryData.pageNum - 1) * limit
|
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() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
|
|
||||||
//纯客户端模式
|
try {
|
||||||
if (SettingUtils.enablePureClientMode) return
|
//纯客户端模式
|
||||||
|
if (SettingUtils.enablePureClientMode) return
|
||||||
|
|
||||||
notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
|
notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
|
||||||
startForeground(FRONT_NOTIFY_ID, createForegroundNotification())
|
startForeground(FRONT_NOTIFY_ID, createForegroundNotification())
|
||||||
isRunning = true
|
|
||||||
|
|
||||||
//开关通知监听服务
|
//开关通知监听服务
|
||||||
if (SettingUtils.enableAppNotify && CommonUtils.isNotificationListenerServiceEnabled(this)) {
|
if (SettingUtils.enableAppNotify && CommonUtils.isNotificationListenerServiceEnabled(this)) {
|
||||||
CommonUtils.toggleNotificationListenerService(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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (frpc in frpcList) {
|
//监听Frpc启动指令
|
||||||
val error = Frpclib.runContent(frpc.uid, frpc.config)
|
LiveEventBus.get(INTENT_FRPC_APPLY_FILE, String::class.java).observeStickyForever(frpcObserver)
|
||||||
if (!TextUtils.isEmpty(error)) {
|
//自启动的Frpc
|
||||||
Log.e(TAG, error)
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
stopForeground(true)
|
try {
|
||||||
compositeDisposable.dispose()
|
stopForeground(true)
|
||||||
isRunning = false
|
compositeDisposable.dispose()
|
||||||
|
isRunning = false
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ import android.text.TextUtils
|
|||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.annotation.RequiresPermission
|
import androidx.annotation.RequiresPermission
|
||||||
import androidx.core.app.ActivityCompat
|
import androidx.core.app.ActivityCompat
|
||||||
|
import com.idormy.sms.forwarder.App
|
||||||
import com.idormy.sms.forwarder.R
|
import com.idormy.sms.forwarder.R
|
||||||
import com.idormy.sms.forwarder.core.Core
|
import com.idormy.sms.forwarder.core.Core
|
||||||
import com.idormy.sms.forwarder.entity.CallInfo
|
import com.idormy.sms.forwarder.entity.CallInfo
|
||||||
@ -32,7 +33,6 @@ import com.xuexiang.xutil.resource.ResUtils
|
|||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
|
||||||
@Suppress("PropertyName")
|
@Suppress("PropertyName")
|
||||||
class PhoneUtils private constructor() {
|
class PhoneUtils private constructor() {
|
||||||
|
|
||||||
@ -86,6 +86,7 @@ class PhoneUtils private constructor() {
|
|||||||
} catch (e: java.lang.Exception) {
|
} catch (e: java.lang.Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
|
Log.e(TAG, infoList.toString())
|
||||||
return infoList
|
return infoList
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,13 +216,15 @@ class PhoneUtils private constructor() {
|
|||||||
val indexDuration = cursor.getColumnIndex(CallLog.Calls.DURATION)
|
val indexDuration = cursor.getColumnIndex(CallLog.Calls.DURATION)
|
||||||
val indexType = cursor.getColumnIndex(CallLog.Calls.TYPE)
|
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
|
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
|
var indexSimId = -1
|
||||||
if (cursor.getColumnIndex("simid") != -1) {
|
if (cursor.getColumnIndex(CallLog.Calls.PHONE_ACCOUNT_ID) != -1
|
||||||
indexSimId = cursor.getColumnIndex("simid")
|
|
||||||
} else if (cursor.getColumnIndex(CallLog.Calls.PHONE_ACCOUNT_ID) != -1
|
|
||||||
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
|
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
|
||||||
) {
|
) {
|
||||||
indexSimId = cursor.getColumnIndex(CallLog.Calls.PHONE_ACCOUNT_ID)
|
indexSimId = cursor.getColumnIndex(CallLog.Calls.PHONE_ACCOUNT_ID)
|
||||||
|
} else if (cursor.getColumnIndex("simid") != -1) {
|
||||||
|
indexSimId = cursor.getColumnIndex("simid")
|
||||||
|
//isSimId = true
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
val callInfo = CallInfo(
|
val callInfo = CallInfo(
|
||||||
@ -231,7 +234,7 @@ class PhoneUtils private constructor() {
|
|||||||
cursor.getInt(indexDuration), //获取通话时长,值为多少秒
|
cursor.getInt(indexDuration), //获取通话时长,值为多少秒
|
||||||
cursor.getInt(indexType), //获取通话类型:1.呼入 2.呼出 3.未接
|
cursor.getInt(indexType), //获取通话类型:1.呼入 2.呼出 3.未接
|
||||||
if (indexViaNumber != -1) cursor.getString(indexViaNumber) else "", //来源号码
|
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())
|
Log.d(TAG, callInfo.toString())
|
||||||
callInfoList.add(callInfo)
|
callInfoList.add(callInfo)
|
||||||
@ -261,14 +264,6 @@ class PhoneUtils private constructor() {
|
|||||||
var selection = "1=1"
|
var selection = "1=1"
|
||||||
val selectionArgs = ArrayList<String>()
|
val selectionArgs = ArrayList<String>()
|
||||||
if (!TextUtils.isEmpty(phoneNumber)) {
|
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 ?"
|
selection += " and replace(replace(" + ContactsContract.CommonDataKinds.Phone.NUMBER + ",' ',''),'-','') like ?"
|
||||||
selectionArgs.add("%$phoneNumber%")
|
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()
|
val smsInfoList: MutableList<SmsInfo> = mutableListOf()
|
||||||
try {
|
try {
|
||||||
var selection = "1=1"
|
var selection = "1=1"
|
||||||
@ -402,6 +397,7 @@ class PhoneUtils private constructor() {
|
|||||||
val indexBody = cursor.getColumnIndex("body")
|
val indexBody = cursor.getColumnIndex("body")
|
||||||
val indexDate = cursor.getColumnIndex("date")
|
val indexDate = cursor.getColumnIndex("date")
|
||||||
val indexType = cursor.getColumnIndex("type")
|
val indexType = cursor.getColumnIndex("type")
|
||||||
|
var isSimId = false
|
||||||
var indexSimId = -1
|
var indexSimId = -1
|
||||||
if (cursor.getColumnIndex("sim_id") != -1) {
|
if (cursor.getColumnIndex("sim_id") != -1) {
|
||||||
indexSimId = cursor.getColumnIndex("sim_id")
|
indexSimId = cursor.getColumnIndex("sim_id")
|
||||||
@ -421,7 +417,7 @@ class PhoneUtils private constructor() {
|
|||||||
// 短信类型: 1=接收, 2=发送
|
// 短信类型: 1=接收, 2=发送
|
||||||
smsInfo.type = cursor.getInt(indexType)
|
smsInfo.type = cursor.getInt(indexType)
|
||||||
// 卡槽id
|
// 卡槽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)
|
smsInfoList.add(smsInfo)
|
||||||
} while (cursor.moveToNext())
|
} while (cursor.moveToNext())
|
||||||
if (!cursor.isClosed) cursor.close()
|
if (!cursor.isClosed) cursor.close()
|
||||||
@ -452,6 +448,36 @@ class PhoneUtils private constructor() {
|
|||||||
XUtil.getContext().startActivity(IntentUtils.getCallIntent(phoneNumber, true))
|
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 {
|
init {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user