修复:来电转发的卡槽信息不准确

pull/115/head
pppscn 3 years ago
parent 5c8d19f93c
commit 928c3f7003

@ -53,8 +53,8 @@ android {
signingConfig signingConfigs.release
}
debug {
minifyEnabled true
shrinkResources true
//minifyEnabled true
//shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.debug
}

@ -11,17 +11,19 @@ public class CallInfo {
public Long dateLong; //获取通话日期
public int duration;//获取通话时长,值为多少秒
public int type; //获取通话类型1.呼入 2.呼出 3.未接
public int subscriptionId;
public String viaNumber; //来源号码
public int subscriptionId; //卡槽id
public CallInfo() {
}
public CallInfo(String name, String number, Long dateLong, int duration, int type, int subscriptionId) {
public CallInfo(String name, String number, Long dateLong, int duration, int type, String viaNumber, int subscriptionId) {
this.name = name;
this.number = number;
this.dateLong = dateLong;
this.duration = duration;
this.type = type;
this.viaNumber = viaNumber;
this.subscriptionId = subscriptionId;
}
@ -34,6 +36,7 @@ public class CallInfo {
", dateLong=" + dateLong +
", duration=" + duration +
", type=" + type +
", viaNumber=" + viaNumber +
", subscriptionId=" + subscriptionId +
'}';
}

@ -25,6 +25,7 @@ import java.util.Date;
import java.util.List;
import java.util.Locale;
@SuppressWarnings("CommentedOutCode")
public class PhoneStateReceiver extends BroadcastReceiver {
private static final String TAG = "PhoneStateReceiver";
private TelephonyManager mTelephonyManager;
@ -36,6 +37,13 @@ public class PhoneStateReceiver extends BroadcastReceiver {
}
String action = intent.getAction();
//Bundle bundle = intent.getExtras();
//if (bundle != null) {
// for (String key : bundle.keySet()) {
// Log.e(TAG, key + " : " + (bundle.get(key) != null ? bundle.get(key) : "NULL"));
// }
//}
if (TelephonyManager.ACTION_PHONE_STATE_CHANGED.equals(action)) {
//获取来电号码
String phoneNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
@ -77,15 +85,18 @@ public class PhoneStateReceiver extends BroadcastReceiver {
CallInfo callInfo = PhoneUtils.getLastCallInfo(phoneNumber);
if (callInfo == null) return;
if ((callInfo.getType() == 1 && !SettingUtil.getSwitchCallType1())
|| (callInfo.getType() == 2 && !SettingUtil.getSwitchCallType2())
|| (callInfo.getType() == 3 && !SettingUtil.getSwitchCallType3())) {
int type = callInfo.getType();
if ((type == 1 && !SettingUtil.getSwitchCallType1())
|| (type == 2 && !SettingUtil.getSwitchCallType2())
|| (type == 3 && !SettingUtil.getSwitchCallType3())) {
Log.w(TAG, "Call record forwarding of this type is not enabled, no processing will be done!");
return;
}
Log.d(TAG, callInfo.toString());
String name = callInfo.getName();
Log.d(TAG, "getSubscriptionId = " + callInfo.getSubscriptionId());
String viaNumber = callInfo.getViaNumber(); //来源号码
Log.d(TAG, "getSubscriptionId = " + callInfo.getSubscriptionId()); //TODO:这里的SubscriptionId跟短信的不一样
int simId = SimUtil.getSimIdBySubscriptionId(callInfo.getSubscriptionId());
String simInfo = simId == 2 ? SettingUtil.getAddExtraSim2() : SettingUtil.getAddExtraSim1(); //自定义备注优先
simInfo = "SIM" + simId + "_" + simInfo;
@ -110,19 +121,21 @@ public class PhoneStateReceiver extends BroadcastReceiver {
}
SettingUtil.setPrevNoticeHash(phoneNumber, currHash);
SmsVo smsVo = new SmsVo(phoneNumber, getTypeText(context, callInfo.getType(), name), new Date(), simInfo);
SmsVo smsVo = new SmsVo(phoneNumber, getTypeText(context, type, name, viaNumber), new Date(), simInfo);
Log.d(TAG, "send_msg" + smsVo.toString());
SendUtil.send_msg(context, smsVo, simId, "call");
//SmsHubApi
if (SettingUtil.getSwitchEnableSmsHubApi()) {
SmsHubActionHandler.putData(new SmsHubVo(SmsHubVo.Type.phone, simId, getTypeText(context, callInfo.getType(), name), phoneNumber));
SmsHubActionHandler.putData(new SmsHubVo(SmsHubVo.Type.phone, simId, getTypeText(context, type, name, viaNumber), phoneNumber));
}
}
//获取通话类型1.呼入 2.呼出 3.未接
private String getTypeText(Context context, int type, String name) {
String str = context.getString(R.string.linkman) + name + "\n" + context.getString(R.string.mandatory_type);
private String getTypeText(Context context, int type, String name, String viaNumber) {
String str = context.getString(R.string.linkman) + name + "\n";
if (!TextUtils.isEmpty(viaNumber)) str += context.getString(R.string.via_number) + viaNumber + "\n";
str += context.getString(R.string.mandatory_type);
if (type == 3) return str + context.getString(R.string.received_call);
if (type == 2) return str + context.getString(R.string.local_outgoing_call);
return str + context.getString(R.string.missed_call);

@ -3,6 +3,8 @@ package com.idormy.sms.forwarder.utils;
import android.os.Environment;
import android.text.TextUtils;
import com.alibaba.fastjson.util.IOUtils;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@ -27,18 +29,23 @@ public class OSUtil {
*/
@SuppressWarnings("unused")
public static boolean isMIUI() {
File file = new File(Environment.getRootDirectory(), "build.prop");
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
String KEY_MIUI_VERSION_CODE = "ro.miui.ui.version.code";
String KEY_MIUI_VERSION_NAME = "ro.miui.ui.version.name";
String KEY_MIUI_INTERNAL_STORAGE = "ro.miui.internal.storage";
Properties prop = new Properties();
prop.load(new FileInputStream(new File(Environment.getRootDirectory(), "build.prop")));
prop.load(fis);
return prop.getProperty(KEY_MIUI_VERSION_CODE, null) != null
|| prop.getProperty(KEY_MIUI_VERSION_NAME, null) != null
|| prop.getProperty(KEY_MIUI_INTERNAL_STORAGE, null) != null;
} catch (final IOException e) {
return false;
} finally {
IOUtils.close(fis);
}
}

@ -33,10 +33,10 @@ import java.util.UUID;
@SuppressWarnings({"deprecation", "rawtypes", "unchecked", "CommentedOutCode", "SynchronizeOnNonFinalField", "unused", "SameReturnValue"})
public class PhoneUtils {
private static final String TAG = "PhoneUtils";
static Boolean hasInit = false;
@SuppressLint("StaticFieldLeak")
static Context context;
private static final String TAG = "PhoneUtils";
/**
*
@ -539,16 +539,17 @@ public class PhoneUtils {
}
try {
String[] columns = {CallLog.Calls.CACHED_NAME// 通话记录的联系人
, CallLog.Calls.NUMBER// 通话记录的电话号码
, CallLog.Calls.DATE// 通话记录的日期
, CallLog.Calls.DURATION// 通话时长
, CallLog.Calls.TYPE// 通话类型
, CallLog.Calls.PHONE_ACCOUNT_ID
String[] columns = {CallLog.Calls.CACHED_NAME, //通话记录的联系人
CallLog.Calls.NUMBER, //通话记录的电话号码
CallLog.Calls.DATE, //通话记录的日期
CallLog.Calls.DURATION, //通话时长
CallLog.Calls.TYPE, //通话类型
(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N ? CallLog.Calls.VIA_NUMBER : ""), //来源号码
"simid" //卡槽ID
};
CallInfo callInfo;
Cursor cursor = context.getContentResolver().query(CallLog.Calls.CONTENT_URI, null,
Cursor cursor = context.getContentResolver().query(CallLog.Calls.CONTENT_URI, columns,
CallLog.Calls.NUMBER + " like ?",
new String[]{phoneNumber + "%"}, CallLog.Calls.DEFAULT_SORT_ORDER);
Log.i(TAG, "cursor count:" + cursor.getCount());
@ -561,7 +562,8 @@ public class PhoneUtils {
cursor.getLong(cursor.getColumnIndex(CallLog.Calls.DATE)), //获取通话日期
cursor.getInt(cursor.getColumnIndex(CallLog.Calls.DURATION)),//获取通话时长,值为多少秒
cursor.getInt(cursor.getColumnIndex(CallLog.Calls.TYPE)), //获取通话类型1.呼入2.呼出3.未接
cursor.getInt(cursor.getColumnIndex(CallLog.Calls.PHONE_ACCOUNT_ID))
(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N ? cursor.getString(cursor.getColumnIndex(CallLog.Calls.VIA_NUMBER)) : null), //来源号码
cursor.getInt(cursor.getColumnIndex("simid")) //卡槽id
);
Log.d(TAG, callInfo.toString());
cursor.close();

@ -41,7 +41,9 @@ public class SimUtil {
//通过SubscriptionId获取卡槽信息ID
public static int getSimIdBySubscriptionId(int subscriptionId) {
try {
Log.d(TAG, MyApplication.SimInfoList.toString());
for (PhoneUtils.SimInfo simInfo : MyApplication.SimInfoList) {
Log.d(TAG, simInfo.toString());
if (simInfo.mSubscriptionId == subscriptionId) {
return simInfo.mSimSlotIndex + 1;
}

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>

@ -389,4 +389,5 @@
<string name="tips_versions_inconsistent">The APP versions of the sender and the receiver are inconsistent, and cannot be cloned with one click!</string>
<string name="tips_get_info_failed">Failed to get one-click clone information from sender</string>
<string name="linkman">Linkman:</string>
<string name="via_number">Via Number:</string>
</resources>

@ -388,4 +388,5 @@
<string name="tips_versions_inconsistent">发送端与接收端的APP版本不一致无法一键克隆</string>
<string name="tips_get_info_failed">从发送端获取一键克隆信息失败</string>
<string name="linkman">联 系 人:</string>
<string name="via_number">来源号码:</string>
</resources>

Loading…
Cancel
Save