From 928c3f7003a40e2a10996d7963b8ca2ec3e27bb8 Mon Sep 17 00:00:00 2001 From: pppscn <35696959@qq.com> Date: Thu, 27 Jan 2022 13:25:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=9D=A5=E7=94=B5?= =?UTF-8?q?=E8=BD=AC=E5=8F=91=E7=9A=84=E5=8D=A1=E6=A7=BD=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E4=B8=8D=E5=87=86=E7=A1=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 4 +-- .../idormy/sms/forwarder/model/CallInfo.java | 7 +++-- .../receiver/PhoneStateReceiver.java | 29 ++++++++++++++----- .../idormy/sms/forwarder/utils/OSUtil.java | 9 +++++- .../sms/forwarder/utils/PhoneUtils.java | 20 +++++++------ .../idormy/sms/forwarder/utils/SimUtil.java | 2 ++ .../res/mipmap-anydpi-v26/ic_launcher.xml | 5 ++++ app/src/main/res/values-en/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 9 files changed, 56 insertions(+), 22 deletions(-) create mode 100644 app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml diff --git a/app/build.gradle b/app/build.gradle index e63a7500..2f137bfe 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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 } diff --git a/app/src/main/java/com/idormy/sms/forwarder/model/CallInfo.java b/app/src/main/java/com/idormy/sms/forwarder/model/CallInfo.java index 5f9ecc0a..e088c56d 100644 --- a/app/src/main/java/com/idormy/sms/forwarder/model/CallInfo.java +++ b/app/src/main/java/com/idormy/sms/forwarder/model/CallInfo.java @@ -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 + '}'; } diff --git a/app/src/main/java/com/idormy/sms/forwarder/receiver/PhoneStateReceiver.java b/app/src/main/java/com/idormy/sms/forwarder/receiver/PhoneStateReceiver.java index e24f04bf..2b5586bd 100644 --- a/app/src/main/java/com/idormy/sms/forwarder/receiver/PhoneStateReceiver.java +++ b/app/src/main/java/com/idormy/sms/forwarder/receiver/PhoneStateReceiver.java @@ -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); diff --git a/app/src/main/java/com/idormy/sms/forwarder/utils/OSUtil.java b/app/src/main/java/com/idormy/sms/forwarder/utils/OSUtil.java index eba95441..3fabe78e 100644 --- a/app/src/main/java/com/idormy/sms/forwarder/utils/OSUtil.java +++ b/app/src/main/java/com/idormy/sms/forwarder/utils/OSUtil.java @@ -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); } } diff --git a/app/src/main/java/com/idormy/sms/forwarder/utils/PhoneUtils.java b/app/src/main/java/com/idormy/sms/forwarder/utils/PhoneUtils.java index 024a75e4..64de8866 100644 --- a/app/src/main/java/com/idormy/sms/forwarder/utils/PhoneUtils.java +++ b/app/src/main/java/com/idormy/sms/forwarder/utils/PhoneUtils.java @@ -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(); diff --git a/app/src/main/java/com/idormy/sms/forwarder/utils/SimUtil.java b/app/src/main/java/com/idormy/sms/forwarder/utils/SimUtil.java index a725a87a..877d4065 100644 --- a/app/src/main/java/com/idormy/sms/forwarder/utils/SimUtil.java +++ b/app/src/main/java/com/idormy/sms/forwarder/utils/SimUtil.java @@ -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; } diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 00000000..67820c56 --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-en/strings.xml b/app/src/main/res/values-en/strings.xml index c2a20f5e..b322a2a1 100644 --- a/app/src/main/res/values-en/strings.xml +++ b/app/src/main/res/values-en/strings.xml @@ -389,4 +389,5 @@ The APP versions of the sender and the receiver are inconsistent, and cannot be cloned with one click! Failed to get one-click clone information from sender Linkman: + Via Number: diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c970ff5e..da091991 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -388,4 +388,5 @@ 发送端与接收端的APP版本不一致,无法一键克隆! 从发送端获取一键克隆信息失败 联 系 人: + 来源号码: