gator-增加白名单电话10秒自动接听 mqtt_test
authork.liang <liangkang648253071@126.com>
Tue, 8 Mar 2022 08:09:25 +0000 (16:09 +0800)
committerk.liang <liangkang648253071@126.com>
Tue, 8 Mar 2022 08:09:25 +0000 (16:09 +0800)
app/release/output.json
app/src/main/aidl/com/android/internal/telephony/ITelephony.java [new file with mode: 0644]
app/src/main/java/com/enqualcomm/support/service/PhoneCallListener.java
app/src/main/java/com/enqualcomm/support/utils/ProjectUtils.java [new file with mode: 0644]
app/version_code.properties

index e5a35bc..7a336fe 100644 (file)
@@ -1 +1 @@
-[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":1055,"versionName":"2203081057","enabled":true,"outputFile":"ICSer_V1055_2203081057_release.apk","fullName":"release","baseName":"release"},"path":"ICSer_V1055_2203081057_release.apk","properties":{}}]
\ No newline at end of file
+[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":1058,"versionName":"2203081559","enabled":true,"outputFile":"ICSer_V1058_2203081559_release.apk","fullName":"release","baseName":"release"},"path":"ICSer_V1058_2203081559_release.apk","properties":{}}]
\ No newline at end of file
diff --git a/app/src/main/aidl/com/android/internal/telephony/ITelephony.java b/app/src/main/aidl/com/android/internal/telephony/ITelephony.java
new file mode 100644 (file)
index 0000000..085711f
--- /dev/null
@@ -0,0 +1,13 @@
+package com.android.internal.telephony;
+
+/**
+ * @author: k.liang
+ * @date: 2022/3/8
+ */
+interface ITelephony {
+
+    boolean endCall();
+
+    void answerRingingCall();
+
+}
index 84e7a56..2a34713 100644 (file)
@@ -7,17 +7,23 @@ import android.database.ContentObserver;
 import android.database.Cursor;
 import android.media.AudioManager;
 import android.net.Uri;
+import android.os.Handler;
+import android.os.Message;
 import android.os.SystemClock;
 import android.telephony.PhoneStateListener;
 import android.telephony.TelephonyManager;
 import android.text.TextUtils;
 import android.util.Log;
 
+import com.android.internal.telephony.ITelephony;
 import com.enqualcomm.support.provider.ICDatabaseHelper;
 import com.enqualcomm.support.provider.ICNotificationProvider;
 import com.enqualcomm.support.utils.ICLogger;
+import com.enqualcomm.support.utils.ProjectUtils;
 import com.enqualcomm.support.utils.Util;
 
+import java.lang.reflect.Method;
+
 import static com.enqualcomm.support.provider.ICGlobalSettingsProvider.SETTINGS;
 import static com.enqualcomm.support.provider.ICMembersProvider.MEMBERS;
 
@@ -31,6 +37,8 @@ public class PhoneCallListener {
     private final Context mContext;
     private final AudioManager mAudioManager;
 
+    private static final int AUTO_ANSWER_DURATION = 12000;
+
     public PhoneCallListener(Context context) {
         mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
         this.mContext = context;
@@ -40,6 +48,31 @@ public class PhoneCallListener {
             public void onCallStateChanged(int state, String phoneNumber) {
                 ICLogger.d("state == > " + state);
                 ICLogger.d("phoneNumber == > " + phoneNumber);
+                switch (state) {
+                    //待机中
+                    case TelephonyManager.CALL_STATE_IDLE:
+                        if(mHandler != null) {
+                            if (mHandler.hasMessages(0)) {
+                                mHandler.removeMessages(0);
+                            }
+                        }
+                        break;
+                    //通话中
+                    case TelephonyManager.CALL_STATE_OFFHOOK:
+                        break;
+                    //来电响铃中
+                    case TelephonyManager.CALL_STATE_RINGING:
+                        if(phoneNumber != null && isWhitePhoneNumName(phoneNumber)){
+                            if(mHandler != null) {
+                                if (mHandler.hasMessages(0)) {
+                                    mHandler.removeMessages(0);
+                                }
+                                mHandler.sendEmptyMessageDelayed(0,AUTO_ANSWER_DURATION);
+                            }
+                        }
+                        break;
+                }
+
                 if (state == TelephonyManager.CALL_STATE_IDLE) {
                     new Thread(() -> {
                         SystemClock.sleep(2 * 1000);
@@ -53,6 +86,29 @@ public class PhoneCallListener {
         }, PhoneStateListener.LISTEN_CALL_STATE);
     }
 
+    private Handler mHandler = new Handler(){
+        @Override
+        public void handleMessage(Message msg) {
+            super.handleMessage(msg);
+            if(ProjectUtils.isGator()) {
+                ICLogger.d(AUTO_ANSWER_DURATION + "秒自动接听");
+                answerCall();
+            }
+        }
+    };
+
+    public synchronized void answerCall() {
+        try {
+            TelephonyManager mTelephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
+            Method getITelephonyMethod = mTelephonyManager.getClass().getDeclaredMethod("getITelephony");
+            getITelephonyMethod.setAccessible(true);
+            ITelephony iTelephony = (ITelephony) getITelephonyMethod.invoke(mTelephonyManager);
+            iTelephony.answerRingingCall();
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+    }
+
     public void updateVolume(int progress) {
         ICLogger.d("progress ==> " + progress);
         //进行换算
@@ -174,6 +230,18 @@ public class PhoneCallListener {
     }
 
 
+    private boolean isWhitePhoneNumName(String phoneNumber) {
+        Cursor query = mContext.getContentResolver().query(Uri.parse(MEMBERS), null, "phone_num=?", new String[]{phoneNumber}, null);
+        if (query != null) {
+            int count = query.getCount();
+            Log.d(TAG, "count ==> " + count);
+            if(count > 0){
+                return true;
+            }
+        }
+        return false;
+    }
+
     private void createNotification(String phoneNum) {
         Log.d(TAG, "createNotification ===> " + phoneNum);
         //解析一下电话名称
diff --git a/app/src/main/java/com/enqualcomm/support/utils/ProjectUtils.java b/app/src/main/java/com/enqualcomm/support/utils/ProjectUtils.java
new file mode 100644 (file)
index 0000000..3e4bc34
--- /dev/null
@@ -0,0 +1,17 @@
+package com.enqualcomm.support.utils;
+
+/**
+ * @author: k.liang
+ * @date: 2021/12/29
+ */
+public class ProjectUtils {
+
+    public static boolean isGator(){
+        String customName = sysProperties.get("persist.sys.customname"," ");
+        if(customName.contains("Gator")){
+            return true;
+        }
+        return false;
+    }
+
+}
index dff3752..3acb116 100644 (file)
@@ -1,2 +1,2 @@
-#Tue Mar 08 10:57:13 CST 2022\r
-VERSION_CODE=1055\r
+#Tue Mar 08 15:59:24 CST 2022\r
+VERSION_CODE=1058\r