add antioff delay.
authorTrillGates <williamtrillgates@gmail.com>
Sat, 28 Aug 2021 03:14:18 +0000 (11:14 +0800)
committerTrillGates <williamtrillgates@gmail.com>
Sat, 28 Aug 2021 03:14:18 +0000 (11:14 +0800)
app/release/ICSer_V928_2108272218_release.apk [moved from app/release/ICSer_V926_2108272032_release.apk with 77% similarity]
app/release/output.json
app/src/main/java/com/enqualcomm/support/CoreService.java
app/src/main/java/com/enqualcomm/support/ICSmsManager.java
app/src/main/java/com/enqualcomm/support/service/AntiMonitorService.java
app/src/main/java/com/enqualcomm/support/service/PhoneCallListener.java
app/version_code.properties

similarity index 77%
rename from app/release/ICSer_V926_2108272032_release.apk
rename to app/release/ICSer_V928_2108272218_release.apk
index d226349..7696f78 100644 (file)
Binary files a/app/release/ICSer_V926_2108272032_release.apk and b/app/release/ICSer_V928_2108272218_release.apk differ
index df7bcf4..182ce27 100644 (file)
@@ -1 +1 @@
-[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":926,"versionName":"2108272032","enabled":true,"outputFile":"ICSer_V926_2108272032_release.apk","fullName":"release","baseName":"release"},"path":"ICSer_V926_2108272032_release.apk","properties":{}}]
\ No newline at end of file
+[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":928,"versionName":"2108272218","enabled":true,"outputFile":"ICSer_V928_2108272218_release.apk","fullName":"release","baseName":"release"},"path":"ICSer_V928_2108272218_release.apk","properties":{}}]
\ No newline at end of file
index 3df4999..02457ce 100644 (file)
@@ -22,7 +22,6 @@ import android.os.Messenger;
 import android.os.PowerManager;
 import android.os.RemoteException;
 import android.support.annotation.Nullable;
-import android.telephony.TelephonyManager;
 import android.text.TextUtils;
 import android.util.Log;
 import android.widget.Toast;
@@ -757,6 +756,17 @@ public class CoreService extends Service {
         mHandler.post(() -> {
             registerPhoneStateListener();
         });
+        //设置佩戴脱落响应的延时
+        mHandler.post(() -> {
+            String delayTimeStr = Util.getSystemProperties("persist.sys.antiOffDelay", "2");
+            int timeValue;
+            try {
+                timeValue = Integer.parseInt(delayTimeStr);
+            } catch (Exception e) {
+                timeValue = 10;
+            }
+            AntiMonitorService.setAntiOffDelayTime(timeValue * 1000);
+        });
         //add by TrillGates =====end
         server_starting = true;
         String curProcessName = getProcessName(this, android.os.Process.myPid());
@@ -1024,11 +1034,7 @@ public class CoreService extends Service {
     private void registerPhoneStateListener() {
         Context applicationContext = getApplicationContext();
         PhoneCallListener phoneCallListener = new PhoneCallListener(applicationContext);
-        TelephonyManager telephonyManager =
-                (TelephonyManager) applicationContext.getSystemService(TELEPHONY_SERVICE);
-        if (telephonyManager != null) {
-            telephonyManager.listen(phoneCallListener, PhoneCallListener.LISTEN_CALL_STATE);
-        }
+        phoneCallListener.initObserver();
     }
 
     /**
index 15f63a6..227efd2 100644 (file)
@@ -24,6 +24,7 @@ import com.enqualcomm.support.bean.StringMessage;
 import com.enqualcomm.support.provider.ICDatabaseHelper;
 import com.enqualcomm.support.provider.ICGlobalSettingsProvider;
 import com.enqualcomm.support.provider.ICNotificationProvider;
+import com.enqualcomm.support.service.AntiMonitorService;
 import com.enqualcomm.support.service.AudioService;
 import com.enqualcomm.support.service.Deliver;
 import com.enqualcomm.support.service.HeartRateManager;
@@ -1126,6 +1127,19 @@ public class ICSmsManager extends BroadcastReceiver {
                 String cmd = tmp[1];
                 handle_test_cmd(runtime, handler, cmd, "");
             }
+        } else if (sms.startsWith(ENCRYPED_HEADER + "#antioff#=") && sms.endsWith("#")) {
+            //#antioff#=10#
+            sms = sms.replace(ENCRYPED_HEADER + "#antioff#=", "");
+            String value = sms.replace("#", "");
+            try {
+                long delayValue = Integer.parseInt(value) * 1000;
+                AntiMonitorService.setAntiOffDelayTime(delayValue);
+                //设置到配置中
+                Util.setSystemProperties("persist.sys.antiOffDelay", value);
+            } catch (Exception e) {
+                sendSMS(phoneNumber, "设置失败.参考格式:#antioff#=10#");
+            }
+            sendSMS(phoneNumber, "脱落通知延时设置成功.");
         } else {
             return false;
         }
@@ -1184,8 +1198,6 @@ public class ICSmsManager extends BroadcastReceiver {
             }
 
         } else if (cmd.startsWith("airplane")) {
-
-
             if (CoreService.getInstance() != null) {
                 SimSignalUtil.send_at_to_reset_simcard(runtime); //直接下此命令不能实现断网重连,所以干脆采用关闭网络再打开的方式。
                 SimSignalUtil.setAirMode(CoreService.getInstance(), "OpenAirplane");
@@ -1194,7 +1206,6 @@ public class ICSmsManager extends BroadcastReceiver {
                 }
             }
         } else if (cmd.startsWith("testCMDRecords")) {
-
             if (CoreService.getInstance() != null) {
                 StringMessage msg = protocolAPIHelper.getLBSLocationMSG(runtime);
                 runtime.getDbHelper().insertCMDRecord(msg);
index b921c4b..85184c8 100644 (file)
@@ -40,10 +40,10 @@ import static java.lang.Thread.sleep;
 
 
 public class AntiMonitorService extends AbstractInvokeHandlerService
-        implements InputEventReader.InputEventReceiver{
+        implements InputEventReader.InputEventReceiver {
 
 
-    private InputEventReader m_inputEventReader=null;
+    private InputEventReader m_inputEventReader = null;
     private static final String TAG = "AntiMonitorService";
     Context mContext;
 
@@ -72,13 +72,13 @@ public class AntiMonitorService extends AbstractInvokeHandlerService
 
     @Override
     public void onInputEventRecevied(int type, int event) {
-        if(type==EVENT_TYPE_CUT && event >0 ){
+        if (type == EVENT_TYPE_CUT && event > 0) {
             current_cut_status = event;
             cut_status_event_reported++;
             ICLogger.i("近距离 " + current_cut_status + " input event " + cut_status_event_reported + " times !");
             cut_event_receivedTime = System.currentTimeMillis();
             reset_timer_cut();
-        }else if (type==EVENT_TYPE_ANTI && event >0){
+        } else if (type == EVENT_TYPE_ANTI && event > 0) {
             current_anti_status = event;
             ant_status_event_reported++;
             ICLogger.i("近距离 " + current_anti_status + " input event " + ant_status_event_reported + " times !");
@@ -128,7 +128,7 @@ public class AntiMonitorService extends AbstractInvokeHandlerService
             mWakeLock = mPowerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, AntiMonitorService.class.getSimpleName());
         }
 
-        m_inputEventReader=new InputEventReader(this);
+        m_inputEventReader = new InputEventReader(this);
     }
 
     private void play_notify() {
@@ -217,10 +217,8 @@ public class AntiMonitorService extends AbstractInvokeHandlerService
         //current_anti_status == 0 表示佩戴       ==10 表示脱腕
 
         switch (current_anti_status) {
-            case STATUS_WEARED:
-                //佩戴
-            {
-
+            //佩戴
+            case STATUS_WEARED: {
                 Util.setSystemProperties("persist.sys.ic_antioff", "false");
                 mRuntime.Anti_off_flag = 0;
                 broadcast_antioff_event_to_other_application(false);
@@ -234,16 +232,16 @@ public class AntiMonitorService extends AbstractInvokeHandlerService
 //                    StringMessage msg = protocolAPIHelper.getWarningMSG(mRuntime);
 //                    Deliver.sendLocationMSG(msg); //消息很重要,所以利用带buffer的对列来发送!
                 }
-
             }
             break;
             case STATUS_ANTI_OFF: {
+                //做延时发送处理
+                //如果特定的时间内佩戴上了,就不会通知未佩戴的状态
                 //脱腕
                 Util.setSystemProperties("persist.sys.ic_antioff", "true");
                 mRuntime.Anti_off_flag = 1;
                 broadcast_antioff_event_to_other_application(true);
                 if (Config.needBroadcastAntiAlarm) {
-
                     send_anti_event_broadcast(1);
                 }
                 if (mRuntime.setAlarmType(Runtime.AlarmType.ALARM_ANTIOFF)) {
@@ -262,6 +260,8 @@ public class AntiMonitorService extends AbstractInvokeHandlerService
         last_send_antoff_event = current_anti_status;
         ICLogger.i("AntiOff Timeout! send antioff event " + current_anti_status);
     }
+
+
     private void send_cutoff_event() {
         if (last_send_cut_event == current_cut_status) {
             ICLogger.i("剪断状态未变,skip!");
@@ -313,28 +313,37 @@ public class AntiMonitorService extends AbstractInvokeHandlerService
         last_send_cut_event = current_cut_status;
         ICLogger.i("CutOff Timeout! send cutoff event " + current_cut_status);
     }
+
     public boolean CheckAntiByPoling() {
         //检查是否佩戴。佩戴返回true
         //send_antiof_event();
         return false;
     }
 
+    /**
+     * 由短信设置这个数据
+     *
+     * @param time
+     */
+    public static void setAntiOffDelayTime(long time) {
+        antiOffDelayTime = time;
+    }
+
+    public static long antiOffDelayTime = 10 * 1000;
+
 
     //return 0 表示check 结束, 1表示需要继续check  由coreService中 ACTION_CHECK_ANTIOFF_EVENT进行
     public int check_ant_event() {
-
-        long currenttime = System.currentTimeMillis();
-        ICLogger.i("anti_event_receivedTime in " + (currenttime - anti_event_receivedTime)
+        long currentTime = System.currentTimeMillis();
+        ICLogger.i("anti_event_receivedTime in " + (currentTime - anti_event_receivedTime)
                 + "ms ago ,anti_event_count_when_start_timer " + ant_status_event_reported
         );
-
-        if ((currenttime - anti_event_receivedTime) >= 2000) {
+        if ((currentTime - anti_event_receivedTime) >= antiOffDelayTime) {
             send_antiof_event();
-
             ant_status_event_reported = 0;
             return 0;
         } else {
-            long restTimeNeedDelay = (2000 + anti_event_receivedTime - currenttime);
+            long restTimeNeedDelay = (antiOffDelayTime + anti_event_receivedTime - currentTime);
             ICLogger.i("Still need delay " + restTimeNeedDelay + "ms to check anti_event again!");
             setAntiCheckAlarm((int) restTimeNeedDelay);
             return 1;
@@ -360,12 +369,15 @@ public class AntiMonitorService extends AbstractInvokeHandlerService
             return 1;
         }
     }
+
     public void setAntiCheckAlarm(int ms) {
         AlarmHelper.setRealTimeAlarmInMicorSeconds(mRuntime.getContextProxy().context, ms, ACTION_CHECK_ANTIOFF_EVENT);
     }
+
     public void setCutCheckAlarm(int ms) {
         AlarmHelper.setRealTimeAlarmInMicorSeconds(mRuntime.getContextProxy().context, ms, ACTION_CHECK_CUTOFF_EVENT);
     }
+
     private void reset_timer() {
 
         if (1 == ant_status_event_reported) //出现 ant_status_event_reported=0表示 有消息到来,需要开始,
@@ -374,6 +386,7 @@ public class AntiMonitorService extends AbstractInvokeHandlerService
             setAntiCheckAlarm(2000);
         }
     }
+
     private void reset_timer_cut() {
 
         if (1 == cut_status_event_reported) //出现 ant_status_event_reported=0表示 有消息到来,需要开始,
@@ -382,6 +395,7 @@ public class AntiMonitorService extends AbstractInvokeHandlerService
             setCutCheckAlarm(2000);
         }
     }
+
     /**
      * 启动传感器。
      */
@@ -496,7 +510,6 @@ public class AntiMonitorService extends AbstractInvokeHandlerService
     }
 
     public void send_anti_event_broadcast(int antioff) {
-
         ICLogger.i("send_anti_event_broadcast " + antioff);
         Intent intent = new Intent();
         intent.setAction(ACTION_ANTI_OFF0);
@@ -593,14 +606,14 @@ public class AntiMonitorService extends AbstractInvokeHandlerService
         @Override
         public void onSensorChanged(SensorEvent sensorEvent) {
             int event = (int) sensorEvent.values[0];
-            if(event==2 || event == 12){
+            if (event == 2 || event == 12) {
                 current_cut_status = event;
                 cut_status_event_reported++;
                 ICLogger.i("近距离 " + current_cut_status + " sensor event " + cut_status_event_reported + " times !");
                 cut_event_receivedTime = System.currentTimeMillis();
                 reset_timer_cut();
 
-            }else {
+            } else {
                 current_anti_status = event;
                 ant_status_event_reported++;
                 ICLogger.i("近距离 " + current_anti_status + " sensor event " + ant_status_event_reported + " times !");
index 5d0cf36..73d17f6 100644 (file)
@@ -3,12 +3,10 @@ package com.enqualcomm.support.service;
 import android.content.ContentResolver;
 import android.content.ContentValues;
 import android.content.Context;
+import android.database.ContentObserver;
 import android.database.Cursor;
 import android.net.Uri;
 import android.os.SystemClock;
-import android.provider.CallLog;
-import android.telephony.PhoneStateListener;
-import android.telephony.ServiceState;
 import android.util.Log;
 
 import com.enqualcomm.support.provider.ICDatabaseHelper;
@@ -22,27 +20,35 @@ import static com.enqualcomm.support.provider.ICGlobalSettingsProvider.SETTINGS;
  * 监听电话数据库的状态
  * 如果有未接电话,创建通知到通知库里,UI上监听到通知库的变化,就会显示通知了
  */
-public class PhoneCallListener extends PhoneStateListener {
+public class PhoneCallListener {
 
     private static final String TAG = "PhoneCallListener";
     private final Context mContext;
-    private String mLastPhoneNumber;
 
     public PhoneCallListener(Context context) {
         this.mContext = context;
     }
 
-    @Override
-    public void onServiceStateChanged(ServiceState serviceState) {
-        super.onServiceStateChanged(serviceState);
-        Log.d(TAG, "onServiceStateChanged == > " + serviceState);
+    public void initObserver() {
+        //观察电话本的内容变化
+        mContext.getContentResolver().registerContentObserver(Uri.parse("content://call_log/calls"),
+                true, new ContentObserver(null) {
+                    @Override
+                    public void onChange(boolean selfChange) {
+                        ICLogger.d("isSelfChange ==> " + isSelfChange);
+                        if (!isSelfChange) {
+                            Log.d(TAG, "on phone calls change.");
+                            queryCallState();
+                        } else {
+                            isSelfChange = false;
+                        }
+                    }
+                });
     }
 
     private final Object mLock = new Object();
 
-    @Override
     public void onCallStateChanged(int state, String incomingNumber) {
-        super.onCallStateChanged(state, incomingNumber);
         ICLogger.d("state == > " + state + " incomingNumber ==>  " + incomingNumber);
         //挂断的时候,去查询一下是不是未接电话即可
         if (state == CALL_STATE_IDLE) {
@@ -57,14 +63,10 @@ public class PhoneCallListener extends PhoneStateListener {
     }
 
     private void queryCallState() {
-        String[] projection = {
-                CallLog.Calls.NUMBER,
-                CallLog.Calls.TYPE
-        };
         String where = "type=? and is_read=?";
         Cursor c = mContext.getContentResolver().query(
                 Uri.parse("content://call_log/calls"),
-                projection,
+                null,
                 where,
                 new String[]{"3", "0"},
                 null
@@ -79,9 +81,16 @@ public class PhoneCallListener extends PhoneStateListener {
                 //修改顶部的状态
                 updateSettingsState(1);
             }
+            String[] columnNames = c.getColumnNames();
             while (c.moveToNext()) {
-                //创建通知,如果大于1的知,说明有未接电话
-                String phoneNum = c.getString(0);
+                StringBuffer sb = new StringBuffer();
+                for (int i = 0; i < columnNames.length; i++) {
+                    String itemName = columnNames[i];
+                    String itemContent = c.getString(c.getColumnIndex(itemName));
+                    sb.append(itemName + ":" + itemContent + " ");
+                }
+                Log.d(TAG, "item ==> " + sb.toString());
+                String phoneNum = c.getString(c.getColumnIndex("number"));
                 createNotification(phoneNum);
             }
             c.close();
@@ -90,14 +99,16 @@ public class PhoneCallListener extends PhoneStateListener {
         ContentValues updateValues = new ContentValues();
         //更新为已读
         updateValues.put("is_read", 1);
+        isSelfChange = true;
         int update = mContext.getContentResolver().update(Uri.parse("content://call_log/calls"),
                 updateValues,
                 where,
                 new String[]{"3", "0"});
         Log.d(TAG, "update ==> " + update);
-        this.mLastPhoneNumber = null;
     }
 
+    private boolean isSelfChange = false;
+
     private void updateSettingsState(int value) {
         ContentResolver resolver = mContext.getContentResolver();
         ContentValues values = new ContentValues();
index f956531..4b243ba 100644 (file)
@@ -1,2 +1,2 @@
-#Fri Aug 27 20:32:10 CST 2021\r
-VERSION_CODE=926\r
+#Fri Aug 27 22:18:53 CST 2021\r
+VERSION_CODE=928\r