completed system reset.
authorTrillGates <williamtrillgates@gmail.com>
Fri, 9 Apr 2021 02:54:53 +0000 (10:54 +0800)
committerTrillGates <williamtrillgates@gmail.com>
Fri, 9 Apr 2021 02:54:53 +0000 (10:54 +0800)
app/src/main/java/com/ic/protocols/protocol_fzd.java

index f4ba9e3..2f3b729 100644 (file)
@@ -1,6 +1,6 @@
-
 package com.ic.protocols;
 
+import android.Manifest;
 import android.annotation.SuppressLint;
 import android.annotation.TargetApi;
 import android.bluetooth.BluetoothAdapter;
@@ -10,6 +10,8 @@ import android.content.ContentValues;
 import android.content.Context;
 import android.content.Intent;
 import android.content.SharedPreferences;
+import android.content.pm.PackageManager;
+import android.database.Cursor;
 import android.media.Ringtone;
 import android.media.RingtoneManager;
 import android.net.Uri;
@@ -18,6 +20,7 @@ import android.os.Environment;
 import android.os.Handler;
 import android.os.HandlerThread;
 import android.os.RemoteCallbackList;
+import android.support.v4.app.ActivityCompat;
 import android.text.TextUtils;
 
 import com.enqualcomm.support.Config;
@@ -1577,7 +1580,7 @@ public class protocol_fzd {
                 mConnection.DeliverCMDMessageToSystem("CALL", cmd);
                 break;
             case MONITOR:
-                handleMONITOR();
+                handleMONITOR(mRuntime);
                 mConnection.DeliverCMDMessageToSystem("MONITOR", cmd);
                 break;
             case TKQ:
@@ -1638,11 +1641,69 @@ public class protocol_fzd {
                 handleSettings(cmd, data, mRuntime);
                 mConnection.DeliverCMDMessageToSystem("PEDO", cmd);
                 break;
+            case FACTORY:
+                ICLogger.d("收到重置系统指令");
+                handleFACTORY(mRuntime);
+                mConnection.DeliverCMDMessageToSystem("FACTORY", cmd);
+                break;
+            case SLEEPTIME:
+                ICLogger.d("收到服务器发来的翻转检测时间设置");
+                handleSLEEPTIME(cmd, data, mRuntime);
+                mConnection.DeliverCMDMessageToSystem("SLEEPTIME", cmd);
+                break;
+            case REMIND:
+                ICLogger.d("收到闹钟设置指令");
+                handleREMIND(cmd, data, mRuntime);
+                mConnection.DeliverCMDMessageToSystem("REMIND", cmd);
+                break;
         }
         return ret;
 
     }
 
+    /**
+     * 闹钟处理
+     *
+     * @param cmd
+     * @param data
+     * @param mRuntime
+     */
+    private void handleREMIND(String cmd, String data, Runtime mRuntime) {
+
+    }
+
+    /**
+     * 翻转检测时间段设置
+     * <p>
+     * 平台发送: [XT*YYYYYYYYYY*LEN*SLEEPTIME,时间段]
+     * 实例:[XT*5678901234*0014*SLEEPTIME,23:30-7:30]
+     * 终端回复: [XT*YYYYYYYYYY*LEN*SLEEPTIME]
+     * 实例:[XT*5678901234*0009*SLEEPTIME]
+     * 说明: 设置翻滚检测的时间段范围.如果时间段为空,
+     * 即[XT*5678901234*0014*SLEEPTIME,],表示 睡眠翻滚监测功能关。
+     * 在此时间段内,开启翻滚检查,默认开启时翻滚次数为 0,
+     * 在此时间段内累计翻滚次数,并通过心 跳接口上传。翻滚时间段结束,
+     * 则停止翻滚检查,心跳接口的翻滚次数可置 0。
+     *
+     * @param cmd
+     * @param data
+     * @param mRuntime
+     */
+    private void handleSLEEPTIME(String cmd, String data, Runtime mRuntime) {
+        //数据解析,有可能为空的
+        ICLogger.d("sleep_time == > " + data);
+        handleSettings(cmd, data, mRuntime);
+    }
+
+    /**
+     * 工厂重置
+     *
+     * @param mRuntime
+     */
+    private void handleFACTORY(Runtime mRuntime) {
+        mHandler.postDelayed(() -> Util.doMasterClear(mRuntime.getContextProxy().context), 1000);
+    }
+
     /**
      * 设置产生低电报警后是否向中心号码发送短信(0:关闭,1:打开)
      * 设置产生 SOS 报警后是否向 SOS 号码发送短信(0:关闭,1:打开)
@@ -1716,11 +1777,26 @@ public class protocol_fzd {
 
     /**
      * 监听,这里是拨号回主手机。
+     *
+     * @param mRuntime
      */
-    private void handleMONITOR() {
+    private void handleMONITOR(Runtime mRuntime) {
         //获取中心号码
+        Cursor query = mRuntime.getContextProxy().getResolver().query(
+                Uri.parse(FZDSettingsProvider.SETTINGS),
+                null, FZDDatabaseHelper.sKey + "=?",
+                new String[]{cmdMap.get(CMD_TYPE.CENTER)}, null
+        );
+        String targetPhone = null;
+        if (query != null && query.moveToNext()) {
+            targetPhone = query.getString(query.getColumnIndex(FZDDatabaseHelper.sValue));
+            query.close();
+        }
+        ICLogger.d("target number is == > " + targetPhone);
         //进行拨号
-
+        if (targetPhone != null) {
+            doCall(targetPhone, mRuntime);
+        }
     }
 
     /**
@@ -1732,10 +1808,19 @@ public class protocol_fzd {
         ICLogger.d("call ==> " + data);
         ICLogger.d("data == > phone number is ===> " + data);
         //得找到测试指令下发
+        doCall(data, runtime);
+    }
+
+    private void doCall(String data, Runtime runtime) {
         //拨号
         Intent intent = new Intent(Intent.ACTION_CALL);
         intent.setData(Uri.parse("tel:" + data));
         intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        if (ActivityCompat.checkSelfPermission(runtime.getContextProxy().context,
+                Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
+            ICLogger.d("no permission to call...");
+            return;
+        }
         runtime.getContextProxy().context.startActivity(intent);
     }