From: TrillGates Date: Tue, 8 Mar 2022 02:57:08 +0000 (+0800) Subject: 修改SOS拨号策略. X-Git-Url: http://git.snicker.com.cn/Users/apple/Desktop/static/gitweb.js?a=commitdiff_plain;h=67f7522c1d8d69a9c87aef5a705c5305eccdbc47;p=icsos.git 修改SOS拨号策略. --- diff --git a/.idea/gradle.xml b/.idea/gradle.xml index b617266..cc2be69 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -4,7 +4,7 @@ diff --git a/app/release/ICSOS_V11_2111181038_release.apk b/app/release/ICSOS_V12_2203051026_release.apk similarity index 58% rename from app/release/ICSOS_V11_2111181038_release.apk rename to app/release/ICSOS_V12_2203051026_release.apk index f9f7de5..62f9c90 100644 Binary files a/app/release/ICSOS_V11_2111181038_release.apk and b/app/release/ICSOS_V12_2203051026_release.apk differ diff --git a/app/release/output-metadata.json b/app/release/output-metadata.json index 67b58e0..a0377c9 100644 --- a/app/release/output-metadata.json +++ b/app/release/output-metadata.json @@ -12,7 +12,7 @@ "filters": [], "versionCode": 1, "versionName": "1.0", - "outputFile": "ICSOS_V11_2111181038_release.apk" + "outputFile": "ICSOS_V12_2203051026_release.apk" } ] } \ No newline at end of file diff --git a/app/src/main/java/com/ic/sos/MainActivity.java b/app/src/main/java/com/ic/sos/MainActivity.java index 5d2ce21..3fc267f 100644 --- a/app/src/main/java/com/ic/sos/MainActivity.java +++ b/app/src/main/java/com/ic/sos/MainActivity.java @@ -5,6 +5,8 @@ import android.view.View; import androidx.appcompat.app.AppCompatActivity; +import com.ic.iclooger.ICLogger; + /** * SOS拨号策略: * 影响因素有: @@ -28,6 +30,7 @@ public class MainActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); + ICLogger.d("sos start..."); initView(); sosPresenter = new SOSPresenter(this); //监听状态变化 diff --git a/app/src/main/java/com/ic/sos/SOSPresenter.java b/app/src/main/java/com/ic/sos/SOSPresenter.java index 4cf5feb..bfc4436 100644 --- a/app/src/main/java/com/ic/sos/SOSPresenter.java +++ b/app/src/main/java/com/ic/sos/SOSPresenter.java @@ -1,11 +1,11 @@ package com.ic.sos; +import static android.telephony.TelephonyManager.CALL_STATE_IDLE; + import android.annotation.SuppressLint; -import android.content.BroadcastReceiver; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; -import android.content.IntentFilter; import android.database.ContentObserver; import android.database.Cursor; import android.net.Uri; @@ -22,8 +22,6 @@ import com.ic.iclooger.ICLogger; import java.util.ArrayList; import java.util.List; -import static android.telephony.TelephonyManager.CALL_STATE_IDLE; - public class SOSPresenter { public static final String PATH = "members"; @@ -40,15 +38,11 @@ public class SOSPresenter { private int callDuration; private final Handler handler; private final TelephonyManager telephonyManager; - private final PhoneStateReceiver stateReceiver; + private String targetPhoneNum; public SOSPresenter(Context context) { this.mContext = context; telephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); - IntentFilter intentFilter = new IntentFilter(); - intentFilter.addAction("com.ic.action.PHONE_STATE"); - stateReceiver = new PhoneStateReceiver(); - mContext.registerReceiver(stateReceiver, intentFilter); HandlerThread handlerThread = new HandlerThread("IC:SOS"); handlerThread.start(); handler = new Handler(handlerThread.getLooper()); @@ -61,6 +55,32 @@ public class SOSPresenter { handler.post(this::sosTask); } + private void checkHasRemoteAnswer() { + //hasRemoteAnswer + ICLogger.d("targetPhoneNum ==> " + targetPhoneNum); + String where = "number=?"; + Cursor c = mContext.getContentResolver().query( + Uri.parse("content://call_log/calls"), + null, + where, + new String[]{targetPhoneNum}, + "`_id` desc" + ); + ICLogger.d("where is == > " + where); + if (c != null) { + int count = c.getCount(); + ICLogger.d("int count ==> " + count); + if (c.moveToNext()) { + @SuppressLint("Range") + int duration = c.getInt(c.getColumnIndex("duration")); + ICLogger.d("duration is ==> " + duration); + hasRemoteAnswer = duration > 0; + } + c.close(); + } + } + + /** * 观察SOS号码的变化 */ @@ -74,7 +94,7 @@ public class SOSPresenter { @Override public void onChange(boolean selfChange) { handler.post(() -> { - if (phoneNumList != null && phoneNumList.size() == 0) { + if (phoneNumList != null && phoneNumList.size() != 0) { sosTask(); } }); @@ -84,60 +104,24 @@ public class SOSPresenter { //是否有接听 private boolean hasRemoteAnswer = false; - //通话结束 - public static final int STATE_END = 9; - //正在挂断 - public static final int STATE_HAND_UP_ING = 8; - //正在拨号 - public static final int STATE_CALLING = 5; - //正在通话 - public static final int STATE_TALKING = 2; - //来电 - public static final int STATE_INCOME = 3; - - - private class PhoneStateReceiver extends BroadcastReceiver { - - @Override - public void onReceive(Context context, Intent intent) { - int state = intent.getIntExtra("state", -1); - String callStateLabel = intent.getStringExtra("callStateLabel"); - ICLogger.d("callStateLabel ==> " + callStateLabel); - ICLogger.d("state ==> " + state); - //判断case - switch (state) { - case STATE_END: - ICLogger.d("通话结束"); - //在activity onResume的时候再去检查 - //checkNextCall(); - break; - case STATE_HAND_UP_ING: - ICLogger.d("正在挂断"); - //删除闹钟 - EndCallAlarmUtil.cancelAlarm(context); - break; - case STATE_TALKING: - ICLogger.d("正在通话中..."); - hasRemoteAnswer = true; - break; - case STATE_CALLING: - ICLogger.d("正在呼叫"); - break; - case STATE_INCOME: - ICLogger.d("来电..."); - break; - } - } - } - /** * 根据条件进行下一轮拨号 */ public void checkNextCall() { + //删除闹钟 + EndCallAlarmUtil.cancelAlarm(mContext); + //这个就不切到子线程了,资源耗费不大 + checkHasRemoteAnswer(); + startNextCheck(); + } + + private void startNextCheck() { boolean doCallNext; //是否进行下一个拨号,结合策略和是否有接听 //已经接听了 + ICLogger.d("hasRemoteAnswer ==> " + hasRemoteAnswer); + ICLogger.d("loopTime ==> " + loopTime); //stop,continue,loop if ("continue".equals(callWay)) { //如果拨通了,就不再往下轮询了 @@ -146,7 +130,6 @@ public class SOSPresenter { //是否有拨通hasRemoteAnswer boolean isLastLoop = currentLoopGroupTime >= loopTime; ICLogger.d("isLastOne ==> " + isLastOne); - ICLogger.d("hasRemoteAnswer ==> " + hasRemoteAnswer); //有接听的,拨完这轮,没接听的,一直拨到最后一轮 if (hasRemoteAnswer) { doCallNext = !isLastOne; @@ -280,7 +263,7 @@ public class SOSPresenter { //拨号超时时长(完成) //先监听电话的状态,这个在类创建的时候就已经监听的了 if (phoneNumList.size() > currentCallIndex) { - String targetPhoneNum = phoneNumList.get(currentCallIndex); + targetPhoneNum = phoneNumList.get(currentCallIndex); //开始准备超时 if (callDuration != 0) { //需要按时挂断 @@ -363,7 +346,6 @@ public class SOSPresenter { handler.removeCallbacks(this::doSosCall); hasFirstCall = false; phoneNumList.clear(); - mContext.unregisterReceiver(stateReceiver); mContext.getContentResolver().unregisterContentObserver(contentObserver); } } diff --git a/app/version_code.properties b/app/version_code.properties index 106d6e3..10ee5d8 100644 --- a/app/version_code.properties +++ b/app/version_code.properties @@ -1,2 +1,2 @@ -#Thu Nov 18 10:38:11 CST 2021 -VERSION_CODE=11 +#Sat Mar 05 10:26:09 CST 2022 +VERSION_CODE=12