1、为了尝试使用EqcIMessage,修改com.ic.protocol 为 com.enqualcomm.support,暂时还是只能用通讯录功能,微聊还不能用。
authorsnickersun <snickersun@qq.com>
Mon, 3 Feb 2020 00:25:26 +0000 (08:25 +0800)
committersnickersun <snickersun@qq.com>
Mon, 3 Feb 2020 00:25:26 +0000 (08:25 +0800)
2、添加协议AP07/BP07,BP28,协议收发的buffer已经完成,发还没有与实际文件关联,收还没有通知到ui
3、把Location发送改到Deliver中,采用Queue,但是目前偶尔会出现lock异常,占资源过多的情况。
4、修复心率测试后releasewakelock失败
5、修复MainActivity退出Launcher会crash的问题。
6、ICSer_V340_202002030355_debug.apk 发出作为调试

34 files changed:
app/src/main/AndroidManifest.xml
app/src/main/java/com/enqualcomm/support/CoreService.java [moved from app/src/main/java/com/ic/protocol/service/protocolMainServer.java with 88% similarity]
app/src/main/java/com/ic/protocol/BootCompleteReceiver.java
app/src/main/java/com/ic/protocol/Config.java
app/src/main/java/com/ic/protocol/CrashHandler.java
app/src/main/java/com/ic/protocol/GSensorListener.java
app/src/main/java/com/ic/protocol/ICApplication.java
app/src/main/java/com/ic/protocol/LocationClient.java
app/src/main/java/com/ic/protocol/MainActivity.java
app/src/main/java/com/ic/protocol/adapter/protocolAPIHelper.java
app/src/main/java/com/ic/protocol/bean/ICLocation.java
app/src/main/java/com/ic/protocol/bean/Runtime.java
app/src/main/java/com/ic/protocol/bean/VoiceContent.java
app/src/main/java/com/ic/protocol/bean/voicePacket.java
app/src/main/java/com/ic/protocol/service/Deliver.java
app/src/main/java/com/ic/protocol/service/HeartRateManager.java
app/src/main/java/com/ic/protocol/service/Initialize.java
app/src/main/java/com/ic/protocol/service/KeepAlive.java
app/src/main/java/com/ic/protocol/service/SendChatMessage.java
app/src/main/java/com/ic/protocol/service/SilentManager.java
app/src/main/java/com/ic/protocol/utils/AlarmHelper.java
app/src/main/java/com/ic/protocol/utils/AlarmWakeUp.java
app/src/main/java/com/ic/protocol/utils/BatteryUtil.java
app/src/main/java/com/ic/protocol/utils/CameraUtil.java
app/src/main/java/com/ic/protocol/utils/ContextProxy.java
app/src/main/java/com/ic/protocol/utils/DBHelper.java
app/src/main/java/com/ic/protocol/utils/DeviceInfoUtil.java
app/src/main/java/com/ic/protocol/utils/FileCache.java
app/src/main/java/com/ic/protocol/utils/Logger.java
app/src/main/java/com/ic/protocol/utils/NettyConnection.java
app/src/main/java/com/ic/protocol/utils/ProcessReceiver.java
app/src/main/java/com/ic/protocol/utils/ServiceUtil.java
app/src/main/java/com/ic/protocol/utils/TimeUtil.java
app/src/main/java/com/ic/protocol/utils/Util.java

index 65ffeaa..e11fe1e 100644 (file)
@@ -5,7 +5,7 @@
     android:screenOrientation="portrait"
     android:supportsRtl="true"
     android:allowBackup="true"
-    package="com.ic.protocol">
+    package="com.enqualcomm.support">
     <!--按用户发送消息-->
     <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS"/>
 
         android:label="@string/app_name"
         android:supportsRtl="true"
         android:theme="@style/AppTheme">
-        <activity android:name=".MainActivity">
+        <activity android:name="com.ic.protocol.MainActivity">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
 
             </intent-filter>
         </activity>
 
-        <service android:name="com.ic.protocol.service.protocolMainServer">   <!--协议通讯服务-->
+        <service android:name="com.enqualcomm.support.CoreService">   <!--协议通讯服务-->
             <intent-filter>
                 <action android:name="com.ic.protocol.startsrv" />
                 <action android:name="com.enqualcomm.support.ACTION_ALARM" />
                 <action android:name="com.enqualcomm.support.HEART_ALARM" />
-
-                <action android:name="com.ic.protocol.startsrv" />
-
             </intent-filter>
         </service>
-        <service android:name="com.ic.protocol.service.protocolMainServer$InnerService"/>
+        <service android:name="com.enqualcomm.support.CoreService$InnerService"/>
 
         <provider
             android:authorities="com.enqualcomm.support"
                 <action android:name="com.enqualcomm.support.CloseUnreadMsg"/>
                 <action android:name="android.intent.action.BATTERY_LOW"/>
                 <action android:name="com.enqualcomm.support.ACTION_MISSED_CALL_GET"/>
-                <action android:name="com.eqc.heartrate.action.SILENT_START" />
+<!--                <action android:name="com.eqc.heartrate.action.SILENT_START" />-->
             </intent-filter>
         </receiver>
 
@@ -1,4 +1,4 @@
-package com.ic.protocol.service;\r
+package com.enqualcomm.support;\r
 \r
 import android.annotation.SuppressLint;\r
 import android.app.AlarmManager;\r
@@ -27,6 +27,14 @@ import com.ic.protocol.adapter.protocolAPIHelper;
 import com.ic.protocol.bean.Runtime;\r
 import com.ic.protocol.bean.StringMessage;\r
 import com.ic.protocol.bean.heartRateStatus;\r
+import com.ic.protocol.service.CheckSIM;\r
+import com.ic.protocol.service.Deliver;\r
+import com.ic.protocol.service.HeartRateManager;\r
+import com.ic.protocol.service.Initialize;\r
+import com.ic.protocol.service.KeepAlive;\r
+import com.ic.protocol.service.SendChatMessage;\r
+import com.ic.protocol.service.SilentManager;\r
+import com.ic.protocol.service.UpLoadDataPoints;\r
 import com.ic.protocol.service.base.AbstractConnectionService;\r
 import com.ic.protocol.service.base.AbstractInvokeHandlerService;\r
 import com.ic.protocol.utils.AlarmHelper;\r
@@ -64,18 +72,21 @@ import static com.ic.protocol.Constants.ACTION_EQC_ALARM;
 import static com.ic.protocol.Constants.ACTION_HEATR_RATE_START;\r
 import static com.ic.protocol.Constants.ACTION_LOCATION_ALARM;\r
 import static com.ic.protocol.Constants.HEART_ALARM;\r
+import static com.ic.protocol.Constants.KEY_SAVE_STEP_COUNT;\r
+import static com.ic.protocol.Constants.KEY_STEP_COUNT;\r
 import static com.ic.protocol.Constants.SLEEP_ALARM;\r
+import static com.ic.protocol.Constants.STEP_COUNT_ALARM_ACTION;\r
 import static com.ic.protocol.Constants.WAKE_ALARM;\r
 import static com.ic.protocol.Constants.WEATHER_ALARM;\r
 import static com.ic.protocol.bean.ICLocation.*;\r
 \r
 \r
-public class protocolMainServer extends Service {\r
+public class CoreService extends Service {\r
 \r
 \r
     private Toastc toast = null;\r
 \r
-    private static protocolMainServer mProtocolServer=null;\r
+    private static CoreService mProtocolServer=null;\r
     private static LBSHelper lbshelper=null;\r
 \r
     public static final String ACTION_ALARM = "com.enqualcomm.support.ACTION_ALARM";\r
@@ -118,7 +129,7 @@ public class protocolMainServer extends Service {
                     if (arrayOfString.length > 4) {\r
                         str = arrayOfString[1];\r
                         String str1 = arrayOfString[3];\r
-                        Context context = (protocolMainServer.this.runtime.getContextProxy()).context;\r
+                        Context context = (CoreService.this.runtime.getContextProxy()).context;\r
                         StringBuilder stringBuilder1 = new StringBuilder();\r
                         stringBuilder1.append("AT lbsInfo LAC== ");\r
                         stringBuilder1.append(Integer.valueOf(str, 16));\r
@@ -141,28 +152,27 @@ public class protocolMainServer extends Service {
             stringBuilder1.append("时间变化");\r
             stringBuilder1.append(param1Intent.getAction());\r
             Logger.i(stringBuilder1.toString());\r
-            protocolMainServer.this.setSleepAlarm();\r
-            protocolMainServer.this.setWakeAlarm();\r
-            protocolMainServer.this.setHeartAlarm();\r
-            protocolMainServer.this.setHeartRateDetectAlarm(3);\r
-            protocolMainServer.this.setWeatherAlarm();\r
-            protocolMainServer.this.setLocationAlarm(runtime.getLocationInstance().getWorkingMod());\r
-            if (protocolMainServer.this.cmcm_call_eiot_into_powersave_mode() == 0)\r
-                AlarmWakeUp.isNeedWakeUpAlarm(protocolMainServer.this.runtime);\r
+            CoreService.this.setSleepAlarm();\r
+            CoreService.this.setWakeAlarm();\r
+            CoreService.this.setHeartAlarm();\r
+            CoreService.this.setHeartRateDetectAlarm(3);\r
+            CoreService.this.setWeatherAlarm();\r
+            CoreService.this.setLocationAlarm(runtime.getLocationInstance().getWorkingMod());\r
+            if (CoreService.this.cmcm_call_eiot_into_powersave_mode() == 0)\r
+                AlarmWakeUp.isNeedWakeUpAlarm(CoreService.this.runtime);\r
         }\r
     };\r
 \r
     private static class ServerHandler implements ConnectionListener {\r
-        private final WeakReference<protocolMainServer> mReference;\r
+        private final WeakReference<CoreService> mReference;\r
 \r
-        ServerHandler(protocolMainServer param1CoreService) { this.mReference = new WeakReference(param1CoreService); }\r
+        ServerHandler(CoreService param1CoreService) { this.mReference = new WeakReference(param1CoreService); }\r
 \r
         public void onConnectionClose() {\r
-            protocolMainServer coreService = (protocolMainServer)this.mReference.get();\r
+            CoreService coreService = (CoreService)this.mReference.get();\r
             if (coreService == null)\r
                 return;\r
             Logger.i("onConnectionClose++ retry to connect again!");\r
-\r
 //            startConnectionRetryTimer();\r
             String ip=Util.parseHostGetIPAddress(coreService.runtime.getHost());\r
             if ( ip !=null && ! ip.equals(coreService.runtime.getSrvIP())){\r
@@ -173,7 +183,7 @@ public class protocolMainServer extends Service {
         }\r
 \r
         public void onConnectionOpen() {\r
-            protocolMainServer coreService = (protocolMainServer)this.mReference.get();\r
+            CoreService coreService = (CoreService)this.mReference.get();\r
             if (coreService == null)\r
                 return;\r
             coreService.connectionServiceChain.processConnectionOpen(coreService.connection, coreService.runtime);\r
@@ -182,7 +192,7 @@ public class protocolMainServer extends Service {
 \r
         public void onReceive(StringMessage param1StringMessage) {\r
 \r
-            protocolMainServer coreService = (protocolMainServer)this.mReference.get();\r
+            CoreService coreService = (CoreService)this.mReference.get();\r
             Logger.i("onReceive " +param1StringMessage.cmd() +" coreService " + coreService  );\r
             if (coreService == null)\r
                 return;\r
@@ -226,22 +236,22 @@ public class protocolMainServer extends Service {
                 if (is_in_sleep_mode) {\r
 \r
                     /*屏幕亮起时,如果在sleep模式,则唤醒各个进程*/\r
-                    protocolMainServer.is_in_sleep_mode=false;\r
-                    protocolMainServer.is_allowed_in_sleep_mode=0;\r
-                    if (protocolMainServer.this.mKeepAlive != null)\r
-                        protocolMainServer.this.mKeepAlive.setSleepMode(false);\r
-                    protocolMainServer.this.wakeUpFromSleep();\r
+                    CoreService.is_in_sleep_mode=false;\r
+                    CoreService.is_allowed_in_sleep_mode=0;\r
+                    if (CoreService.this.mKeepAlive != null)\r
+                        CoreService.this.mKeepAlive.setSleepMode(false);\r
+                    CoreService.this.wakeUpFromSleep();\r
                 }\r
                 if (is_wifi_network_ok) {\r
 \r
                     /*屏幕亮起时,如果wifi开启,则开启wifi*/\r
-                    protocolMainServer.is_in_sleep_mode=false;\r
-                    Util.turnOnWifiForConnect((protocolMainServer.this.runtime.getContextProxy()).context, protocolMainServer.this.runtime);\r
+                    CoreService.is_in_sleep_mode=false;\r
+                    Util.turnOnWifiForConnect((CoreService.this.runtime.getContextProxy()).context, CoreService.this.runtime);\r
                 }\r
-            } else if ("android.intent.action.SCREEN_OFF".equals(param1Intent.getAction()) && Util.isWifiIsOpen((protocolMainServer.this.runtime.getContextProxy()).context, protocolMainServer.this.runtime)) {\r
+            } else if ("android.intent.action.SCREEN_OFF".equals(param1Intent.getAction()) && Util.isWifiIsOpen((CoreService.this.runtime.getContextProxy()).context, CoreService.this.runtime)) {\r
 \r
-                protocolMainServer.is_in_sleep_mode=true;\r
-                Util.turnOffWifiForSleep((protocolMainServer.this.runtime.getContextProxy()).context, protocolMainServer.this.runtime);\r
+                CoreService.is_in_sleep_mode=true;\r
+                Util.turnOffWifiForSleep((CoreService.this.runtime.getContextProxy()).context, CoreService.this.runtime);\r
             }\r
         }\r
     };\r
@@ -255,7 +265,7 @@ public class protocolMainServer extends Service {
         Initialize initialize = new Initialize();\r
         CheckSIM checkSIM = new CheckSIM();\r
         this.mKeepAlive = new KeepAlive();\r
-        this.mDeliver = new Deliver();\r
+        this.mDeliver = new Deliver(this.connection,this.runtime);\r
         initialize.setNext(checkSIM);\r
         checkSIM.setNext(this.mKeepAlive);\r
         this.mKeepAlive.setNext(this.mDeliver);\r
@@ -282,15 +292,15 @@ public class protocolMainServer extends Service {
 \r
 \r
     private void loadStepCount() {\r
-        int i = SharPreferenceUtil.getPrefInt(this, "KEY_STEP_COUNT", 0);\r
-        int j = SharPreferenceUtil.getPrefInt(this, "key_save_step_count", 0);\r
+        int i = SharPreferenceUtil.getPrefInt(this, KEY_STEP_COUNT, 0);\r
+        int j = SharPreferenceUtil.getPrefInt(this, KEY_SAVE_STEP_COUNT, 0);\r
         this.runtime.setSaveStepCount(j);\r
         this.runtime.setTotalStepCount(i);\r
     }\r
 \r
     private void setCleanStepCountAlarm() {\r
         /*一天清零一次 计步*/\r
-        AlarmHelper.setCleanStepCountAlarm(this, 23, 59, "com.enqualcomm.support.ACTION_STEP_COUNT_ALARM");\r
+        AlarmHelper.setCleanStepCountAlarm(this, 23, 59, STEP_COUNT_ALARM_ACTION);\r
     }\r
 \r
     private void setSleepAlarm() {\r
@@ -303,7 +313,7 @@ public class protocolMainServer extends Service {
 //        /*每1 左右 唤醒自己*/\r
 //        Context context=runtime.getContextProxy().context;\r
 //        AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);\r
-//        Intent intent = new Intent(context, com.ic.protocol.service.protocolMainServer.class);\r
+//        Intent intent = new Intent(context, com.enqualcomm.support.CoreService.class);\r
 //        intent.setAction(WAKE_ALARM);\r
 //        PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);\r
 //        alarmManager.cancel(pendingIntent);\r
@@ -333,7 +343,7 @@ public class protocolMainServer extends Service {
     }\r
     private void wakeUpFromSleep() {\r
         this.startAlarmCount = 0;\r
-//        alarmCycle = 1;\r
+        alarmCycle = 1;\r
         setAlarm(alarmCycle);\r
         this.runtime.getContextProxy().sendBroadcast(ACTION_EQC_ALARM, this.runtime);\r
         this.connection.open();\r
@@ -352,7 +362,7 @@ public class protocolMainServer extends Service {
 \r
 \r
     public PowerManager.WakeLock getWakeLock(int paramInt) {\r
-         PowerManager.WakeLock wakeLock = ((PowerManager)(this.runtime.getContextProxy()).context.getSystemService(POWER_SERVICE)).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakelockTag");\r
+         PowerManager.WakeLock wakeLock = ((PowerManager)(this.runtime.getContextProxy()).context.getSystemService(POWER_SERVICE)).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, MY_WAKE_LOCKTAG);\r
 //        wakeLock.acquire(paramInt*60*1000L);\r
         wakeLock.acquire(3000L);\r
         return wakeLock;\r
@@ -370,8 +380,8 @@ public class protocolMainServer extends Service {
 \r
     @Override\r
     public void onCreate() {\r
-        Logger.i("CoreService--onCreate002");\r
-        log("å¼\80å§\8bç\9b\91å\90¬ç½\91ç»\9cå\8d\8fè®®ç\8a¶æ\80\81");\r
+//        Logger.i("CoreService--onCreate002");\r
+        log("å\88\9då§\8bå\8c\96ç½\91ç»\9cå\8d\8fè®®æ\9c\8då\8a¡");\r
         mProtocolServer=this;\r
 \r
         this.runtime = new Runtime();\r
@@ -382,6 +392,7 @@ public class protocolMainServer extends Service {
         this.runtime.setLbsHelper(new LBSHelper(this,this.runtime.getContextProxy().getWifiManager(), this.runtime));\r
         this.runtime.setImeiAndCid(PhoneUtils.getIMEI(this),"");\r
         this.runtime.setHRS(new heartRateStatus());\r
+        this.runtime.setUseQueue(true);\r
         this.connectionServiceChain = getConnectionServiceChain();\r
         this.invokeHandlerServiceChain = getInvokeHandlerServiceChain();\r
         if (cmcm_call_eiot_into_powersave_mode() == 1) {\r
@@ -636,6 +647,9 @@ public class protocolMainServer extends Service {
             case LOWPOWER_MOD:\r
                 cycle=60;\r
                 break;\r
+            case CUSTOM_MOD:\r
+                cycle=runtime.getLocationInstance().getLocation_cycle();\r
+                break;\r
         }\r
 \r
         AlarmHelper.setRealTimeAlarm(runtime.getContextProxy().context,cycle, ACTION_LOCATION_ALARM);\r
@@ -674,7 +688,7 @@ public class protocolMainServer extends Service {
 \r
     public void setUpLocationDataAlarm(long paramLong) {\r
         AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);\r
-        Intent intent = new Intent(this, protocolMainServer.class);\r
+        Intent intent = new Intent(this, CoreService.class);\r
         intent.setAction(ACTION_ALARM_ADD_DATAPOINTS);\r
         PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, FLAG_UPDATE_CURRENT);\r
         alarmManager.cancel(pendingIntent);\r
@@ -699,14 +713,14 @@ public class protocolMainServer extends Service {
     }\r
 \r
     private static class RequestHandler extends Handler {\r
-        private final WeakReference<protocolMainServer> mReference;\r
+        private final WeakReference<CoreService> mReference;\r
 \r
-        RequestHandler(protocolMainServer param1CoreService) {\r
+        RequestHandler(CoreService param1CoreService) {\r
             this.mReference = new WeakReference(param1CoreService);\r
         }\r
 \r
         public void handleMessage(Message param1Message) {\r
-            protocolMainServer coreService = (protocolMainServer)this.mReference.get();\r
+            CoreService coreService = (CoreService)this.mReference.get();\r
             if (coreService == null)\r
                 return;\r
             coreService.invokeHandlerServiceChain.processUserRequest(param1Message, coreService.connection, coreService.runtime);\r
@@ -719,7 +733,7 @@ public class protocolMainServer extends Service {
     }\r
 \r
 \r
-     private static final String TAG = "ICSrv." + protocolMainServer.class.getSimpleName();\r
+     private static final String TAG = "ICSrv." + CoreService.class.getSimpleName();\r
 \r
     private static boolean mLowPowerMode = false;\r
     private static boolean mCallStateIsIdle = true;     // 非通话活动\r
@@ -739,7 +753,7 @@ public class protocolMainServer extends Service {
         Logger.log(TAG,funcName,msg);\r
     }\r
 \r
-    public static protocolMainServer getInstance(){\r
+    public static CoreService getInstance(){\r
         return mProtocolServer;\r
     }\r
 \r
@@ -789,8 +803,8 @@ public class protocolMainServer extends Service {
     public void saveStepCount(){\r
         int i = runtime.getTotalStepCount();\r
         int j = runtime.getSaveStepCount();\r
-        SharPreferenceUtil.setPrefInt(this, "KEY_STEP_COUNT", i);\r
-        SharPreferenceUtil.setPrefInt(this, "key_save_step_count", j);\r
+        SharPreferenceUtil.setPrefInt(this, KEY_STEP_COUNT, i);\r
+        SharPreferenceUtil.setPrefInt(this, KEY_SAVE_STEP_COUNT, j);\r
     }\r
     @Override\r
     public void onDestroy() {\r
index 3a3b621..2d62be3 100644 (file)
@@ -9,7 +9,7 @@ import com.ic.protocol.utils.Logger;
 public class BootCompleteReceiver extends BroadcastReceiver {\r
   public void onReceive(Context paramContext, Intent paramIntent) {\r
     Logger.i("监听到开机广播");\r
-    paramContext.startService(new Intent(paramContext, com.ic.protocol.service.protocolMainServer.class));\r
+    paramContext.startService(new Intent(paramContext, com.enqualcomm.support.CoreService.class));\r
   }\r
 }\r
 \r
index 5c534a6..6b9a326 100644 (file)
@@ -177,7 +177,81 @@ public class Config {
   \r
   private static String make() {\r
     try {\r
-      return (new JSONStringer()).object().key("cmd").value("Init").key("sw_version").value("eiot_V1.0.0").key("protocol_version").value("2.0").key("product").value(2L).key("sim").value(1L).key("connect").value(1L).key("work_mode").value(work_mode).key("phonebook").value(1L).key("wifi").value(2L).key("pedometer").value(1L).key("wechat").value(1L).key("shake").value(1L).key("antioff").value(antioff).key("key_num").value(1L).key("kindness_num").value(0L).key("sos_num").value(0L).key("monitor_num").value(0L).key("other_contact_num").value(30L).key("volume").value(0L).key("ring_vol").value(2L).key("call_vol").value(2L).key("Schedule_powonoff").value(0L).key("temperature").value(0L).key("air_pressure").value(0L).key("dampness").value(0L).key("BT").value("1@4.0").key("TP").value(1L).key("camera").value("1@200").key("T_Card").value(0L).key("NFC").value(0L).key("wireless_charge").value(0L).key("geomagnetic").value(0L).key("gyroscope").value(0L).key("behavior_mode").value(0L).key("LBS").value(1L).key("monitor").value(1L).key("check_bill").value(1L).key("sndrec").value(0L).key("voice_control").value(0L).key("market").value("domestic").key("platform").value("SC9820E").key("LCD").value("OLED@240X206").key("communication_standard").value(1L).key("time_set").value(0L).key("language").value("0@0").key("mcc_mnc").value("46000").key("end_call").value(0L).key("multi_point").value(0L).key("make_call").value(1L).key("search_terminal").value(1L).key("alarm").value(1L).key("silent").value(1L).key("weather").value(1L).key("url_download").value(1L).key("shutdown_hand").value(1L).key("relation").value(0L).key("voice_notice").value(1L).key("q_a").value(1L).key("gps").value(1L).key("gsensor").value(1L).key("reboot").value(1L).key("relatives").value(1L).key("heart_rate").value(heart_rate).key("sedentary_reminder").value(0L).key("fight_mode").value(0L).key("sleep_monitor").value(0L).key("sms_forward").value(0L).key("video_jf").value(1L).key("nickname").value(0L).key("wifi_setting").value(1L).key("yunosuuid").value(0L).key("oss_file").value(0L).key("swReleaseNo").value(sw_release_no).endObject().toString();\r
+      return (new JSONStringer()).object()\r
+              .key("cmd").value("Init")\r
+              .key("sw_version").value("eiot_V1.0.0")\r
+              .key("protocol_version").value("2.0")\r
+              .key("product").value(2L)\r
+              .key("sim").value(1L)\r
+              .key("connect").value(1L)\r
+              .key("work_mode").value(work_mode)\r
+              .key("phonebook").value(1L)\r
+              .key("wifi").value(2L)\r
+              .key("pedometer").value(1L)\r
+              .key("wechat").value(1L)\r
+              .key("shake").value(1L)\r
+              .key("antioff").value(antioff)\r
+              .key("key_num").value(1L)\r
+              .key("kindness_num").value(0L)\r
+              .key("sos_num").value(0L)\r
+              .key("monitor_num").value(0L)\r
+              .key("other_contact_num").value(30L)\r
+              .key("volume").value(0L)\r
+              .key("ring_vol").value(2L)\r
+              .key("call_vol").value(2L)\r
+              .key("Schedule_powonoff").value(0L)\r
+              .key("temperature").value(0L)\r
+              .key("air_pressure").value(0L)\r
+              .key("dampness").value(0L)\r
+              .key("BT").value("1@4.0")\r
+              .key("TP").value(1L)\r
+              .key("camera").value("1@200")\r
+              .key("T_Card").value(0L)\r
+              .key("NFC").value(0L)\r
+              .key("wireless_charge").value(0L)\r
+              .key("geomagnetic").value(0L)\r
+              .key("gyroscope").value(0L)\r
+              .key("behavior_mode").value(0L)\r
+              .key("LBS").value(1L)\r
+              .key("monitor").value(1L)\r
+              .key("check_bill").value(1L)\r
+              .key("sndrec").value(0L)\r
+              .key("voice_control").value(0L)\r
+              .key("market").value("domestic")\r
+              .key("platform").value("SC9820E")\r
+              .key("LCD").value("OLED@240X206")\r
+              .key("communication_standard").value(1L)\r
+              .key("time_set").value(0L)\r
+              .key("language").value("0@0")\r
+              .key("mcc_mnc").value("46000")\r
+              .key("end_call").value(0L)\r
+              .key("multi_point").value(0L)\r
+              .key("make_call").value(1L)\r
+              .key("search_terminal").value(1L)\r
+              .key("alarm").value(1L)\r
+              .key("silent").value(1L)\r
+              .key("weather").value(1L)\r
+              .key("url_download").value(1L)\r
+              .key("shutdown_hand").value(1L)\r
+              .key("relation").value(0L)\r
+              .key("voice_notice").value(1L)\r
+              .key("q_a").value(1L)\r
+              .key("gps").value(1L)\r
+              .key("gsensor").value(1L)\r
+              .key("reboot").value(1L)\r
+              .key("relatives").value(1L)\r
+              .key("heart_rate").value(heart_rate)\r
+              .key("sedentary_reminder").value(0L)\r
+              .key("fight_mode").value(0L)\r
+              .key("sleep_monitor").value(0L)\r
+              .key("sms_forward").value(0L)\r
+              .key("video_jf").value(1L)\r
+              .key("nickname").value(0L)\r
+              .key("wifi_setting").value(1L)\r
+              .key("yunosuuid").value(0L)\r
+              .key("oss_file").value(0L)\r
+              .key("swReleaseNo").value(sw_release_no)\r
+              .endObject().toString();\r
     } catch (JSONException jSONException) {\r
       jSONException.printStackTrace();\r
       return "";\r
index 050bd28..e60e5b7 100644 (file)
@@ -9,6 +9,8 @@ import android.os.Looper;
 import android.util.Log;\r
 import android.widget.Toast;\r
 \r
+import com.enqualcomm.support.R;\r
+\r
 import java.io.File;\r
 import java.io.FileOutputStream;\r
 import java.io.PrintWriter;\r
@@ -190,9 +192,9 @@ public class CrashHandler implements Thread.UncaughtExceptionHandler {
         sb.append("\n\n");\r
 \r
         try {\r
-            String fileName = "EqcLauncher-" + dateFormatDate.format(new Date()) + ".log";\r
-            if (Environment.getExternalStorageState().equals(\r
-                    Environment.MEDIA_MOUNTED)) {\r
+            String fileName = "ICProtocol-" + dateFormatDate.format(new Date()) + ".log";\r
+//            if (Environment.getExternalStorageState().equals(\r
+//                    Environment.MEDIA_MOUNTED)) {\r
                 File dir = new File(Environment.getExternalStorageDirectory().getPath(), "crash");\r
                 String path = dir.getPath();\r
                 if (!dir.exists()) {\r
@@ -201,7 +203,7 @@ public class CrashHandler implements Thread.UncaughtExceptionHandler {
                 FileOutputStream fos = new FileOutputStream(new File(path, fileName), true);\r
                 fos.write(sb.toString().getBytes());\r
                 fos.close();\r
-            }\r
+//            }\r
             return fileName;\r
         } catch (Exception e) {\r
             Log.e(TAG, "an error occured while writing file...," + e);\r
index 17c1c1d..3d66a10 100644 (file)
 package com.ic.protocol;\r
 \r
-import android.content.Context;\r
-import android.hardware.Sensor;\r
-import android.hardware.SensorEvent;\r
-import android.hardware.SensorEventListener;\r
-import android.hardware.SensorManager;\r
+\r
 import android.os.Handler;\r
 import android.os.Message;\r
-import android.os.PowerManager;\r
 \r
 import com.ic.jni.ICJniUtils;\r
 import com.ic.protocol.bean.Runtime;\r
-import com.ic.protocol.service.protocolMainServer;\r
-import com.ic.protocol.utils.CellInfoUtil;\r
+\r
 import com.ic.protocol.utils.FileOutputUtil;\r
 import com.ic.protocol.utils.Logger;\r
 \r
-import java.util.Timer;\r
-import java.util.TimerTask;\r
+/**\r
+ * 由于Gsensor用的硬件计步,只需要保证打开计步器即可\r
+ */\r
+public class GSensorListener  {\r
 \r
-public class GSensorListener implements SensorEventListener {\r
-  private static final String MY_WAKE_LOCKTAG = "MyWakelockTag_GSensorListener";\r
   \r
   public static boolean getStepCountOver = false;\r
   \r
   private int CURRENT_STEP;\r
   \r
-  private int anti_off;\r
-  \r
-  private int haveAddAntiOffCount = -1;\r
-  \r
-  private boolean isFirstSendAntiOff = true;\r
-  \r
-  boolean isReceivedFirstValue;\r
-  \r
-  private Context mContext;\r
-  \r
   Handler mHandler = new Handler() {\r
       public void handleMessage(Message msg) {\r
         super.handleMessage(msg);\r
         if (msg.what != 100)\r
-          return; \r
-        GSensorListener.this.sensorManager.unregisterListener(GSensorListener.this);\r
-        int i = ICJniUtils.getStepCount();//EqcAlgorithmNative.native_EqcAlgorithm_Gsensor_get_step();\r
-//        GSensorListener (GSensorListener.this, i);\r
-        GSensorListener.this.CURRENT_STEP = i;\r
-\r
+          return;\r
+        GSensorListener.this.CURRENT_STEP = ICJniUtils.getStepCount();\r
         StringBuilder stringBuilder1 = new StringBuilder();\r
         stringBuilder1.append("CURRENT_STEP =");\r
         stringBuilder1.append(GSensorListener.this.CURRENT_STEP);\r
         Logger.i(stringBuilder1.toString());\r
-        GSensorListener.this.sendAntiOff(GSensorListener.this.CURRENT_STEP);\r
-//        GSensorListener.access$302(GSensorListener.this, 0);\r
-//          GSensorListener.getStepCountOver=false;\r
-//        EqcAlgorithmNative.native_EqcAlgorithmMethod6(0.0F, 0.0F, 0.0F, GSensorListener.this.CURRENT_STEP);\r
-        Context context = GSensorListener.this.mContext;\r
-        FileOutputUtil.fileOutput(protocolMainServer.getInstance().getRuntime().getCacheDir(), "CURRENT_STEP", stringBuilder1.toString());\r
-//        GSensorListener.access$502(GSensorListener.this, null);\r
-        GSensorListener.this.releaseWakeLock(GSensorListener.this.mWakeLock);\r
+        runtime.setTotalStepCount(CURRENT_STEP);\r
+        GSensorListener.getStepCountOver=false;\r
+        FileOutputUtil.fileOutput(runtime.getCacheDir(), "CURRENT_STEP", stringBuilder1.toString());\r
       }\r
     };\r
+\r
+  private Runtime runtime;\r
   \r
-  private TimerTask mMyTimerTask;\r
-  \r
-  private Timer mTimer;\r
-  \r
-  private PowerManager.WakeLock mWakeLock;\r
-  \r
-  private SensorManager sensorManager;\r
-  \r
-  static  {\r
-  \r
-  }\r
-  \r
-  public GSensorListener(SensorManager paramSensorManager, Context context, Runtime dev) {\r
-    this.sensorManager = paramSensorManager;\r
-    this.mContext = context;\r
+  public GSensorListener( Runtime dev) {\r
+    this.runtime = dev;\r
     ICJniUtils.enablePedometer();\r
   }\r
-  \r
-  private void releaseWakeLock(PowerManager.WakeLock paramWakeLock) {\r
-    if (paramWakeLock == null) {\r
-      Logger.i("Gsensor 没有加锁");\r
-      return;\r
-    }\r
 \r
-\r
-    if (CellInfoUtil.getCellInfoOver) {\r
-      if (paramWakeLock.isHeld()) {\r
-        CellInfoUtil.getCellInfoOver = false;\r
-        getStepCountOver = false;\r
-        paramWakeLock.release();\r
-        return;\r
-      } \r
-    } else {\r
-      getStepCountOver = true;\r
-    } \r
+  public void updateStepCount(){\r
+    getStepCountOver=true;\r
+    mHandler.sendEmptyMessage(100);\r
   }\r
-  \r
-  private void sendAntiOff(int paramInt) {}\r
-  \r
   public int getStepCount() {\r
-    this.CURRENT_STEP=ICJniUtils.getStepCount();\r
     return this.CURRENT_STEP;\r
-\r
   }\r
-  \r
-  public PowerManager.WakeLock getWakeLock() {\r
-   PowerManager.WakeLock wakeLock = ((PowerManager)this.mContext.getSystemService(Context.POWER_SERVICE)).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakelockTag_GSensorListener");\r
-    wakeLock.acquire(60000L);\r
-    return wakeLock;\r
-  }\r
-  \r
-  public void onAccuracyChanged(Sensor paramSensor, int paramInt) {}\r
-  \r
-  public void onSensorChanged(SensorEvent paramSensorEvent) {\r
-    int currentStepCount;\r
-    try {\r
-      float f = paramSensorEvent.values[0];\r
-      currentStepCount = (int)f;\r
-    } catch (Exception e) {\r
-      e.printStackTrace();\r
-      Logger.i("Exception");\r
-      currentStepCount = 0;\r
-    } \r
-    StringBuilder stringBuilder1 = new StringBuilder();\r
-    stringBuilder1.append("count =");\r
-    stringBuilder1.append(currentStepCount);\r
-    Logger.i(stringBuilder1.toString());\r
-    int step = ICJniUtils.getStepCount();//EqcAlgorithmNative.native_EqcAlgorithm_Gsensor_get_step();\r
-    if (step == this.CURRENT_STEP && !this.isReceivedFirstValue) {\r
-      this.isReceivedFirstValue = true;\r
-      return;\r
-    } \r
-    if (this.mTimer != null) {\r
-      this.mTimer.cancel();\r
-      this.mTimer.purge();\r
-      this.mTimer = null;\r
-    }\r
 \r
-//    sendAntiOff(i);\r
-    this.haveAddAntiOffCount = 0;\r
-    this.CURRENT_STEP = step;\r
-//    EqcAlgorithmNative.native_EqcAlgorithmMethod6(0.0F, 0.0F, 0.0F, this.CURRENT_STEP);\r
-\r
-    Context context = this.mContext;\r
-    StringBuilder stringBuilder2 = new StringBuilder();\r
-    stringBuilder2.append("CURRENT_STEP=");\r
-    stringBuilder2.append(this.CURRENT_STEP);\r
-    FileOutputUtil.fileOutput(protocolMainServer.getInstance().getRuntime().getCacheDir(), "CURRENT_STEP", stringBuilder2.toString());\r
-    this.sensorManager.unregisterListener(this);\r
-    releaseWakeLock(this.mWakeLock);\r
-  }\r
-  \r
-  public void startListen(PowerManager.WakeLock paramWakeLock) {\r
-    this.mWakeLock = paramWakeLock;\r
-    if (this.haveAddAntiOffCount == 1)\r
-      sendAntiOff(this.CURRENT_STEP); \r
-    this.haveAddAntiOffCount = 1;\r
-    this.isReceivedFirstValue = false;\r
-    (new Thread(new Runnable() {\r
-          public void run() {\r
-            StringBuilder stringBuilder = new StringBuilder();\r
-            stringBuilder.append("registerListener sensorManager=");\r
-            stringBuilder.append(GSensorListener.this.sensorManager);\r
-            Logger.i(stringBuilder.toString());\r
-            GSensorListener.this.sensorManager.registerListener(GSensorListener.this, GSensorListener.this.sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER), 0);\r
-          }\r
-        })).start();\r
-    if (this.mTimer == null)\r
-      this.mTimer = new Timer(); \r
-    if (this.mMyTimerTask != null)\r
-      this.mMyTimerTask.cancel(); \r
-    class MyTimerTask extends TimerTask {\r
-      public void run() {\r
-        //发送读取计步消息\r
-        GSensorListener.this.mHandler.sendEmptyMessage(100);\r
-      }\r
-    };\r
-    this.mMyTimerTask = new MyTimerTask();\r
-    //延时2秒执行发送“读取计步”消息\r
-    this.mTimer.schedule(this.mMyTimerTask, 2000L);\r
-  }\r
-  \r
-  public void stopListen() {\r
-    this.sensorManager.unregisterListener(this);\r
-    if (this.mTimer != null) {\r
-      this.mTimer.cancel();\r
-      this.mTimer.purge();\r
-      this.mTimer = null;\r
-    } \r
-    releaseWakeLock(this.mWakeLock);\r
-  }\r
 }\r
 \r
index 3c4e37b..e4101eb 100644 (file)
@@ -9,6 +9,8 @@ import android.util.Log;
 import android.util.SparseArray;\r
 \r
 \r
+import com.enqualcomm.support.BuildConfig;\r
+\r
 import java.util.HashMap;\r
 \r
 \r
index b1f506f..6c42132 100644 (file)
@@ -17,13 +17,14 @@ import com.ic.protocol.bean.ICLocation;
 import com.ic.protocol.bean.StringMessage;\r
 import com.ic.protocol.service.Deliver;\r
 import com.ic.protocol.service.KeepAlive;\r
-import com.ic.protocol.service.protocolMainServer;\r
+import com.enqualcomm.support.CoreService;\r
 import com.ic.protocol.utils.CellInfoUtil;\r
 import com.ic.protocol.utils.DeviceInfoUtil;\r
 import com.ic.protocol.utils.FileCache;\r
 import com.ic.protocol.utils.FileOutputUtil;\r
 import com.ic.protocol.utils.Logger;\r
 import com.ic.protocol.utils.NettyConnection;\r
+import com.ic.protocol.utils.ServiceUtil;\r
 import com.ic.protocol.utils.SharPreferenceUtil;\r
 import com.ic.protocol.utils.SimSignalUtil;\r
 import com.ic.protocol.bean.Runtime;\r
@@ -60,30 +61,29 @@ public class LocationClient {
   public static final String LOCATION_CYCLE = "location_cycle";\r
   \r
   public static final String LOCATION_MODE = "location_mode";\r
-  \r
+\r
   private static final int MAX_SIZE = 50;\r
   \r
   private static final int OPEN_AIRMODE = 1;\r
   \r
   private static final int TIME_OUT = 30000;\r
-  \r
+\r
   private static NettyConnection connection;\r
-  \r
-  private static FileCache fileCache;\r
+\r
+\r
   \r
   private static boolean isLocationCallBack = false;\r
-  \r
+\r
   private static boolean linkOK = false;\r
   \r
-  private static ReentrantLock lock = new ReentrantLock();\r
+\r
   \r
   private static boolean mHasWifiResult = true;\r
 \r
-  public static LinkedBlockingDeque<StringMessage> queue = new LinkedBlockingDeque(50);\r
-  \r
+\r
   private static Runtime runtime;\r
   \r
-  private int H12StepCount;\r
+//  private int H12StepCount;\r
   \r
   private boolean batteryLowNotification;\r
   \r
@@ -101,10 +101,7 @@ public class LocationClient {
   \r
   private String mCellInfo;\r
 \r
-  ReentrantLock mLock = new ReentrantLock();\r
 \r
-  Condition mCondition = this.mLock.newCondition();\r
-  \r
   private LBSHelper mLbsHelper;\r
 \r
   private Timer mTimer=null;\r
@@ -112,9 +109,7 @@ public class LocationClient {
   private int mPedometer2;\r
   \r
   private SimSignalUtil mSignalUtil;\r
-  \r
-  private String mWifiInfo;\r
-  \r
+\r
   private NMEAListener nmeaListener;\r
   \r
   private int preLbsCid;\r
@@ -125,34 +120,21 @@ public class LocationClient {
       public void onReceive(Context param1Context, Intent param1Intent) {\r
         if ("android.intent.action.SCREEN_ON".equals(param1Intent.getAction())) {\r
           LocationClient.this.mSignalUtil.setAirMode("CloseAirplane");\r
-//          EqcAlgorithmNative.native_EqcAlgorithmMethod8(0);\r
-        } \r
+        }\r
       }\r
     };\r
   \r
   public LocationClient(NettyConnection paramNettyConnection, Runtime paramRuntime) {\r
     connection = paramNettyConnection;\r
     runtime = paramRuntime;\r
-    fileCache = new FileCache(paramRuntime.getFileDir());\r
+\r
+    //GPS 监听管理初始化\r
     this.nmeaListener = new NMEAListener(paramRuntime.getContextProxy().getLocationManager(), paramRuntime);\r
-    this.gSensorListener = new GSensorListener(paramRuntime.getContextProxy().getSensorManager(), (paramRuntime.getContextProxy()).context, paramRuntime);\r
+    // 初始化同时开启计步(硬件计步器,比较省电,全程开启计步功能)\r
+    this.gSensorListener = new GSensorListener(paramRuntime);\r
   }\r
 \r
-  \r
-  private static int getMinSignalStrength(int paramInt) {\r
-    int b = -105;\r
-    switch (paramInt) {\r
-      case SimSignalUtil.IS_4G:\r
-        b = -100;\r
-        break;\r
-      case SimSignalUtil.IS_2G:\r
-      case SimSignalUtil.IS_3G:\r
-      default:\r
-        break;\r
-    } \r
-    return b;\r
-  }\r
-  \r
+\r
   private void handler2GTo4G() {\r
     int networktype = this.mSignalUtil.getNetworkType();\r
     int singal = runtime.getSignalStrength();\r
@@ -173,88 +155,38 @@ public class LocationClient {
           this.mSignalUtil.changeNetWorkType("2G");\r
           this.haveChanegTo4GTime = currenttime;\r
           return;\r
-        } \r
+        }\r
         return;\r
       case SimSignalUtil.IS_2G:\r
       case SimSignalUtil.IS_3G:\r
         break;\r
-    } \r
+    }\r
     if (this.haveChanegTo4G || currenttime - this.haveChanegTo4GTime > 43200000L) {\r
       this.mSignalUtil.changeNetWorkType("4G");\r
       this.haveChanegTo4G = false;\r
       this.haveChanegTo4GTime = currenttime;\r
-    } \r
+    }\r
   }\r
   //计算运动并发送数据\r
   private void updateStepCount() {\r
-    int i = this.gSensorListener.getStepCount();\r
-    runtime.setTotalStepCount(i);\r
-    this.H12StepCount = DeviceInfoUtil.getStepCount((runtime.getContextProxy()).context);\r
-    if (i != 0 && Math.abs(this.H12StepCount - this.mPedometer2) > 1000) {\r
-//      connection.send(API.H12(runtime, this.H12StepCount));\r
-      Logger.i("StepCount 运动开始后 变化超过1000 ,则发送给服务器!");\r
-    }\r
-  }\r
+    this.gSensorListener.updateStepCount();\r
 \r
+//    this.H12StepCount = DeviceInfoUtil.getStepCount((runtime.getContextProxy()).context);\r
+//    if (i != 0 && Math.abs(this.H12StepCount - this.mPedometer2) > 1000) {\r
+////      connection.send(API.H12(runtime, this.H12StepCount));\r
+//      Logger.i("StepCount 运动开始后 变化超过1000 ,则发送给服务器!");\r
+//    }\r
 \r
-  private static void loadMessage2Queue() {\r
-    byte b = 0;\r
-    while (b < 5) {\r
-      String str = fileCache.load();\r
-      if (str != null) {\r
-        byte b1 = ++b;\r
-        try {\r
-          StringMessage stringMessage = new StringMessage(str);\r
-          if (!queue.offerLast(stringMessage)) {\r
-            fileCache.put(str);\r
-          }\r
-        } catch (Exception e) {\r
-          e.printStackTrace();\r
-        }\r
-      }\r
-    }\r
   }\r
-  \r
-  private void notifiSetAirModeMethod() { (new Thread(new Runnable() {\r
-          public void run() {\r
-            SystemClock.sleep(3000L);\r
-            boolean bool = LocationClient.this.mSignalUtil.IsAirModeOn();\r
-            byte b = 1;\r
-            if (bool != true)\r
-              b = 0; \r
-            StringBuilder stringBuilder = new StringBuilder();\r
-            stringBuilder.append("AirMode==");\r
-            stringBuilder.append(b);\r
-            Logger.i(stringBuilder.toString());\r
-//            EqcAlgorithmNative.native_EqcAlgorithmMethod8(b);\r
-          }\r
-        })).start(); }\r
-  \r
+\r
+\r
   private void performAlarm(PowerManager.WakeLock paramWakeLock) {\r
     if (!runtime.isAirMode) {\r
-        CellInfoUtil.triggerUpdateCellinfo();\r
-       sendBatteryNotification();\r
-//      startLocationProcess();\r
+      updateStepCount();//update StepCount\r
+      CellInfoUtil.triggerUpdateCellinfo();\r
+      sendBatteryNotification();\r
     }\r
   }\r
-\r
-  private void sendBatteryNotification() {\r
-    if (runtime.getHaveBatteryChange() && !runtime.getBatterychanging() && !this.batteryNotification) {\r
-//      connection.send(API.H05(runtime, "2"));\r
-      Logger.i("sendBatteryNotification LevelChanged ");\r
-      this.batteryNotification = true;\r
-    }\r
-    if (runtime.getBatteryLow() && !runtime.getBatterychanging() && !this.batteryLowNotification) {\r
-//      connection.send(API.H05(runtime, "1"));\r
-      Logger.i("sendBatteryNotification Low Battery ");\r
-      this.batteryLowNotification = true;\r
-    }\r
-    if (runtime.getBatterychanging()) {\r
-      this.batteryNotification = false;\r
-      this.batteryLowNotification = false;\r
-    }\r
-  }\r
-\r
   public void triggerLocationProcess(){\r
     mhandler.sendEmptyMessage(0);\r
   }\r
@@ -266,17 +198,14 @@ public class LocationClient {
 \r
   public void startWifiScan(){\r
       Logger.i("开启wifi扫描");\r
-//      runtime.currentWifiInfo = "";\r
       runtime.setWifiinfo("");\r
       mHasWifiResult = false;\r
       this.mLbsHelper.registerBroadReceiver();\r
       this.mLbsHelper.getWifiInfo();\r
       this.mLbsHelper.setOnWiFiInfoListener(new LBSHelper.OnWiFiInfoListener() {\r
           public void getWifiInfoCallBack(String param1String) {\r
-//            LocationClient.access$002(true);\r
               Logger.i("get wifi scan Callback " + param1String);\r
               LocationClient.mHasWifiResult=true;\r
-//              runtime.currentWifiInfo = param1String==null?"":param1String;\r
               runtime.setWifiinfo(param1String==null?"":param1String);\r
           }\r
       });\r
@@ -289,10 +218,6 @@ public class LocationClient {
           public void call(Object param1Object) { LocationClient.this.nmeaListener.startListen(); }\r
         });\r
 \r
-//        Single.just(null).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<Object>() {\r
-//            public void call(Object param1Object) { LocationClient.this.waitAndSendLocation(); }\r
-//        });\r
-\r
   }\r
 \r
   public void startCheckResult(){\r
@@ -313,7 +238,9 @@ public class LocationClient {
         public void handleMessage(Message msg) {\r
           super.handleMessage(msg);\r
           if (msg.what == 100){\r
-            waitAndSendLocation();\r
+            Single.just(null).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<Object>() {\r
+              public void call(Object param1Object) { LocationClient.this.waitAndSendLocation(); }\r
+            });\r
           }else if (msg.what == 0){\r
             startLocationProcess(WorkingMod);\r
           }\r
@@ -322,16 +249,18 @@ public class LocationClient {
         }\r
 \r
   };\r
+\r
+\r
   boolean wifi_ok=false,gps_ok=false,lbs_ok=false,gps_nosignal=false;\r
 \r
   public void waitAndSendLocation(){\r
 \r
-          wifi_ok=false;\r
+\r
+        wifi_ok=false;\r
         gps_ok=false;\r
         lbs_ok=false;\r
         gps_nosignal=false;\r
 \r
-\r
         checktimes++;\r
         int mode=runtime.getLocationInstance().getWorkingMod();\r
         if (runtime.getWifiInfo().length()>0  ) wifi_ok =true;\r
@@ -355,16 +284,9 @@ public class LocationClient {
             if ((lbs_ok && timeout==true) ||(lbs_ok && gps_ok && wifi_ok )||(lbs_ok&&gps_nosignal&&wifi_ok)){\r
 \r
               String AP01_CMD=protocolAPIHelper.AP01(runtime);\r
-              if (connection.isServerConnected() && KeepAlive.isConnected)\r
-              {\r
-                Logger.i("gps first send "+AP01_CMD);\r
-                connection.send(protocolAPIHelper.genStringMessage("AP01", AP01_CMD));\r
-              }else{\r
-                Logger.i("offline skip gps "+AP01_CMD);\r
-                FileOutputUtil.fileOutput(runtime.getCacheDir(),"APILog"," offlineskip  "+AP01_CMD);\r
-              }\r
 \r
-//          triggerSendThread();\r
+              Deliver.sendLocationMSG(AP01_CMD);\r
+\r
               if (mTimer!=null){\r
                 mTimer.cancel();\r
                 mTimer=null;\r
@@ -386,15 +308,8 @@ public class LocationClient {
             if ((lbs_ok && timeout==true) ||(lbs_ok && wifi_ok )){\r
 \r
               String AP01_CMD=protocolAPIHelper.AP01(runtime);\r
-              if (connection.isServerConnected() && KeepAlive.isConnected)\r
-              {\r
-                Logger.i("wifi first send "+AP01_CMD);\r
-                connection.send(protocolAPIHelper.genStringMessage("AP01", AP01_CMD));\r
-              }else{\r
-                Logger.i("offline skip wifi "+AP01_CMD);\r
-                FileOutputUtil.fileOutput(runtime.getCacheDir(),"APILog"," offlineskip  "+AP01_CMD);\r
-              }\r
-//          triggerSendThread();\r
+              Deliver.sendLocationMSG(AP01_CMD);\r
+\r
               if (mTimer!=null){\r
                 mTimer.cancel();\r
                 mTimer=null;\r
@@ -425,53 +340,19 @@ public class LocationClient {
         });\r
   }\r
   \r
-//  public void EqcAlgorithmInterfaceMethod4() {\r
+\r
 public void updateCellInfo() {\r
    this.mLbsHelper.getAttchCellInfo(runtime.getContextProxy().getTelephonyManager());\r
 //    CellInfoUtil.triggerUpdateCellinfo();\r
     CellInfoUtil.setCurrentAttachCellInfo(runtime, getLocationWakeLock());\r
   }\r
-  \r
-//  public void EqcAlgorithmInterfaceMethod5(int paramInt) {\r
+\r
  public void updateSimSignalInfo() {\r
       SimSignalUtil.getInstance((runtime.getContextProxy()).context);\r
   }\r
-  \r
-//  public void EqcAlgorithmInterfaceMethod6(int paramInt) {\r
-  // 飞行模式 1 开启 0 关闭\r
-    public void setAirMode(int paramInt) {\r
-    boolean isAirModeOn = this.mSignalUtil.IsAirModeOn();\r
-    boolean isScreenOn = this.mSignalUtil.isScreenON();\r
-    switch (paramInt) {\r
-\r
-      case 1:\r
-        if (!isAirModeOn && !isScreenOn) {\r
-          this.mSignalUtil.setAirMode("OpenAirplane");\r
-          runtime.isAirMode = true;\r
-          notifiSetAirModeMethod();\r
-\r
-        } \r
-        if (isAirModeOn) {\r
-//          EqcAlgorithmNative.native_EqcAlgorithmMethod8(1);\r
-\r
-        }\r
-          break;\r
-      case 0:\r
 \r
-          if (isAirModeOn) {\r
-              this.mSignalUtil.setAirMode("CloseAirplane");\r
-              runtime.isAirMode = false;\r
-              notifiSetAirModeMethod();\r
-              return;\r
-          }\r
-          break;\r
 \r
-        default:\r
-            break;\r
-    } \r
 \r
-  }\r
-  \r
   public PowerManager.WakeLock getLocationWakeLock() {\r
     PowerManager.WakeLock wakeLock = ((PowerManager)(runtime.getContextProxy()).context.getSystemService(Context.POWER_SERVICE)).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "locationSend");\r
     wakeLock.acquire(1000L);\r
@@ -482,13 +363,11 @@ public void updateCellInfo() {
     //每分钟更新一次数据\r
     runtime.preCellInfo = runtime.getCurrentCellInfo();\r
     runtime.preCdmaInfo = runtime.getCdmaInfo();\r
-    runtime.preTime = TimeUtil.getSystemTime(System.currentTimeMillis() - (protocolMainServer.alarmCycle * 60 * 1000));\r
+    runtime.preTime = TimeUtil.getSystemTime(System.currentTimeMillis() - (CoreService.alarmCycle * 60 * 1000));\r
     StringBuilder stringBuilder = new StringBuilder();\r
     stringBuilder.append("runtime.preCellInfo=");\r
     stringBuilder.append(runtime.preCellInfo);\r
     Logger.i(stringBuilder.toString());\r
-    updateStepCount();//update StepCount\r
-    this.gSensorListener.startListen(paramWakeLock);\r
     performAlarm(paramWakeLock);\r
   }\r
 \r
@@ -497,17 +376,15 @@ public void updateCellInfo() {
 \r
   public void startLocationProcess(int mod){\r
 \r
+    updateStepCount();//update StepCount,保证每次定位前,计步数据是最新的。防止丢数据。\r
     Logger.i("forceLocation="+forceLocation+", WorkingMod="+WorkingMod+", isLocating="+isLocating+", lastStep="+runtime.getLastStepCount()+", currentStep="+ runtime.getTotalStepCount());\r
     if (isLocating ) {\r
       Logger.i("locating ,skip location!");\r
       return;\r
     }\r
 \r
-\r
-\r
     // 不强制定位 且 WorkingMod 不是紧急模式,且 没有移动过\r
     if ( !(( forceLocation == 1 ) ||  ( WorkingMod == 4 )) && ( runtime.getLastStepCount() == runtime.getTotalStepCount())  ){\r
-\r
       Logger.i("No Move ,skip location!");\r
       return ;\r
     }\r
@@ -533,25 +410,15 @@ public void updateCellInfo() {
   private static int WorkingMod=1;\r
   private static int forceLocation=0;\r
   public void onReceive(StringMessage paramStringMessage) {\r
-//    Logger.i("LocationClient onReceive " +paramStringMessage.cmd()+" linkOK "+linkOK );\r
-//    if ("Sport:OK".equals(paramStringMessage.cmd()))\r
-//      this.mPedometer2 = this.H12StepCount;\r
-    Logger.i("LocationClient onReceive " +paramStringMessage.cmd() );\r
 \r
-//    if (linkOK)\r
-//      return;\r
-//    if (paramStringMessage.cmd().startsWith("AP") || paramStringMessage.cmd().startsWith("BP")) {\r
-//      //如果Link:OK 则触发(激活)等待信号的发送线程\r
-////      triggerSendThread();\r
-//    }\r
+    Logger.i("LocationClient onReceive " +paramStringMessage.cmd() );\r
+    Deliver.triggerSendThread();\r
     //响应定位指令\r
     if ("StartLocate".equals(paramStringMessage.cmd())  ){\r
-//      triggerSendThread();\r
       forceLocation=1;\r
       this.startLocationProcess(WorkingMod);\r
     }\r
     if ("setWorkMod".equals(paramStringMessage.cmd())) {\r
-//      triggerSendThread();\r
       int mod = 0;\r
       try\r
       {\r
@@ -565,40 +432,21 @@ public void updateCellInfo() {
       runtime.getLocationInstance().setWorkingMod(mod);\r
 //      runtime.getLocationInstance().setLocation_cycle(3);\r
       Logger.i("Set WorkMODE  "+mod +" and reset Location AlarmCycle");\r
-      protocolMainServer.getInstance().setLocationAlarm(mod);\r
+      CoreService.getInstance().setLocationAlarm(mod);\r
 //      Logger.i("ResartLOCATION_MODE  2");\r
       runtime.getContextProxy().sendBroadcast(LOCATION_MODE,runtime);\r
       forceLocation=1;\r
       this.startLocationProcess(mod);\r
       WorkingMod=mod;\r
-\r
     }\r
-\r
-\r
   }\r
 \r
 \r
-  public void triggerSendThread(){\r
-    this.mLock.lock();\r
-    try {\r
-      linkOK = true;\r
-      this.mCondition.signal();\r
-\r
-    } finally {\r
-      this.mLock.unlock();\r
-    }\r
-  }\r
-  MyThread2 mythread2=null;\r
 \r
   public void start() {\r
 \r
 \r
     this.mSignalUtil = SimSignalUtil.getInstance((runtime.getContextProxy()).context);\r
-    // 开启计步\r
-//    EqcAlgorithmNative.EqcAlgorithmNativeSetInterface(this);\r
-//    EqcAlgorithmNative.native_EqcAlgorithm_Gsensor_eint_work_start();\r
-//    EqcAlgorithmNative.native_EqcAlgorithmMethod2();\r
-    ICJniUtils.enablePedometer();//.enableStepCounter(); //makesure enable stepCounter\r
 \r
     //获取LBS定位服务\r
     this.mLbsHelper = runtime.getLbsHelper();\r
@@ -631,121 +479,90 @@ public void updateCellInfo() {
     intentFilter.addAction("android.intent.action.SCREEN_ON");\r
     (runtime.getContextProxy()).context.registerReceiver(this.screenOnReceiver, intentFilter);\r
 \r
-    /*启动 阻塞队列buffer 发送县城,随时准备发送buffer的message*/\r
-//    if (mythread2 == null)\r
-//      mythread2 = new MyThread2(this.mCondition, this.mLock);\r
-//    mythread2.exitthread=false;\r
-//    mythread2.start();\r
-    this.haveChanegTo4GTime = SystemClock.elapsedRealtime();\r
+\r
+\r
+    //暂时没有处理4G、2G切换问题\r
+//    this.haveChanegTo4GTime = SystemClock.elapsedRealtime();\r
   }\r
   \r
   public void stop() {\r
 \r
-//     mythread2.exitthread=true;\r
-//    if (mythread2 != null){\r
-////      triggerSendThread();\r
-////      mythread2.stop();\r
-//      mythread2=null;\r
-//    }\r
     (runtime.getContextProxy()).context.unregisterReceiver(this.screenOnReceiver);\r
-//    this.executor.execute(new Runnable() {\r
-//          public void run() { LocationClient.AP16Queue(); }\r
-//        });\r
-    this.gSensorListener.stopListen();\r
     mLbsHelper.unRegisterBroadReceiver();\r
+    this.executor.execute(new Runnable() {\r
+      public void run() {\r
+        Deliver.saveQueue();\r
+      }\r
+    });\r
     stopGpsLocate();\r
   }\r
-  \r
-  static class MyThread2 extends Thread {\r
-    Condition condition;\r
-\r
-    boolean isResent = false;\r
-    public boolean exitthread=false;\r
-    ReentrantLock lock;\r
-    \r
-    public MyThread2(Condition param1Condition, ReentrantLock param1ReentrantLock) {\r
-      this.condition = param1Condition;\r
-      this.lock = param1ReentrantLock;\r
-    }\r
-    \r
-    public void run() {\r
-      StringMessage stringMessage = null;\r
 \r
-      while (!exitthread) {\r
 \r
-        //循环发送queue 中的数据\r
 \r
-        try {\r
-          Logger.i("Sending Thread Queue Take ");\r
 \r
-          StringMessage stringMessage1 = (StringMessage)LocationClient.queue.take();\r
-          try {\r
 \r
-            if (runtime.getSignalStrength() + 110 < LocationClient.getMinSignalStrength(SimSignalUtil.getInstance((runtime.getContextProxy()).context).getNetworkType())) {\r
-              Logger.i("Skip Send for SignalStrengh "+(runtime.getSignalStrength() + 110 )+" < "+LocationClient.getMinSignalStrength(SimSignalUtil.getInstance((runtime.getContextProxy()).context).getNetworkType()));\r
-              //如果信号不好,把msg放回去\r
+  private void notifiSetAirModeMethod() { (new Thread(new Runnable() {\r
+    public void run() {\r
+      SystemClock.sleep(3000L);\r
+      boolean bool = LocationClient.this.mSignalUtil.IsAirModeOn();\r
+      byte b = 1;\r
+      if (bool != true)\r
+        b = 0;\r
+      StringBuilder stringBuilder = new StringBuilder();\r
+      stringBuilder.append("AirMode==");\r
+      stringBuilder.append(b);\r
+      Logger.i(stringBuilder.toString());\r
 \r
-              LocationClient.queue.putFirst(stringMessage1);\r
+    }\r
+  })).start(); }\r
 \r
-            } else {\r
 \r
-                stringMessage=stringMessage1;\r
+  private void sendBatteryNotification() {\r
+    if (runtime.getHaveBatteryChange() && !runtime.getBatterychanging() && !this.batteryNotification) {\r
+//      connection.send(API.H05(runtime, "2"));\r
+      Logger.i("sendBatteryNotification LevelChanged ");\r
+      this.batteryNotification = true;\r
+    }\r
+    if (runtime.getBatteryLow() && !runtime.getBatterychanging() && !this.batteryLowNotification) {\r
+//      connection.send(API.H05(runtime, "1"));\r
+      Logger.i("sendBatteryNotification Low Battery ");\r
+      this.batteryLowNotification = true;\r
+    }\r
+    if (runtime.getBatterychanging()) {\r
+      this.batteryNotification = false;\r
+      this.batteryLowNotification = false;\r
+    }\r
+  }\r
+  // 飞行模式 1 开启 0 关闭\r
+  public void setAirMode(int paramInt) {\r
+    boolean isAirModeOn = this.mSignalUtil.IsAirModeOn();\r
+    boolean isScreenOn = this.mSignalUtil.isScreenON();\r
+    switch (paramInt) {\r
 \r
-                Context context = (runtime.getContextProxy()).context;\r
-                StringBuilder stringBuilder = new StringBuilder();\r
-                stringBuilder.append("send=");\r
-                stringBuilder.append(stringMessage.cmd());\r
-                stringBuilder.append(", ");\r
-                stringBuilder.append(stringMessage.isFromCache());\r
-                FileOutputUtil.fileOutput(runtime.getCacheDir(), "MessageInfo", stringBuilder.toString());\r
-                Logger.i(stringBuilder.toString());\r
-              if( connection.isServerConnected() ==false  && !KeepAlive.isConnected  ) {\r
+      case 1:\r
+        if (!isAirModeOn && !isScreenOn) {\r
+          this.mSignalUtil.setAirMode("OpenAirplane");\r
+          runtime.isAirMode = true;\r
+          notifiSetAirModeMethod();\r
 \r
-                Logger.i("Skip Send for connection and KeepAlive both false ");\r
-                //发现连接断开则重试连接\r
-//                protocolMainServer.getInstance().startConnectionRetryTimer();\r
-                //连接断开就把msg放回队列,以便重发\r
-                LocationClient.queue.putFirst(stringMessage1);\r
-              }else{\r
-                //连接状态都正常才发送包\r
-                connection.send(stringMessage);\r
-              }\r
+        }\r
 \r
+        break;\r
+      case 0:\r
 \r
-              this.lock.lock();\r
-              LocationClient.linkOK=false;\r
-              try {\r
-                if (KeepAlive.isConnected) {\r
-                  //如果 服务器连接状态,等30秒,随时等待数据发送\r
-                  Logger.i("KeepAlive.isConnected "+KeepAlive.isConnected+" delay 30000ms");\r
-                  this.condition.await(30000L, TimeUnit.MILLISECONDS);\r
-                } else {\r
-                  //如果服务器断开,等5秒 以便连接后尽快进入下一循环,尽量及时响应\r
-                Logger.i("KeepAlive.isConnected "+KeepAlive.isConnected+ "  , connection isconnected "+connection.isServerConnected()+" delay 5000ms");\r
-\r
-                  this.condition.await(5000L, TimeUnit.MILLISECONDS);\r
-                }\r
-                if (linkOK) {\r
-                  if (stringMessage.all() != null && stringMessage.all()[0].equals("AP16")) {\r
-                    this.isResent = false;\r
-                    Logger.i( " AP16 need wait for wifi scan list");\r
-                    Deliver.releaseWakeLockForGetWifiList();\r
-                  }\r
-                }\r
-              } catch (InterruptedException e) {\r
-                e.printStackTrace();\r
-              }finally{\r
-                this.lock.unlock();\r
-              }\r
-            }\r
-          } catch (Exception e) {\r
-            e.printStackTrace();\r
-          }\r
-        } catch (Exception e) {\r
-          e.printStackTrace();\r
+        if (isAirModeOn) {\r
+          this.mSignalUtil.setAirMode("CloseAirplane");\r
+          runtime.isAirMode = false;\r
+          notifiSetAirModeMethod();\r
+          return;\r
         }\r
-      }//while end\r
+        break;\r
+\r
+      default:\r
+        break;\r
     }\r
+\r
   }\r
+\r
 }\r
 \r
index ab36b24..9f4cb62 100644 (file)
@@ -14,8 +14,9 @@ import android.widget.CompoundButton;
 import android.widget.TextView;
 import android.widget.ToggleButton;
 
+import com.enqualcomm.support.R;
 import com.ic.jni.ICJniUtils;
-import com.ic.protocol.service.protocolMainServer;
+import com.enqualcomm.support.CoreService;
 import com.ic.protocol.utils.Logger;
 
 import java.util.Timer;
@@ -23,6 +24,9 @@ import java.util.TimerTask;
 
 public class MainActivity extends AppCompatActivity {
     TextView tv;
+
+    private boolean showmessage=false;
+    private Timer timer;
     Handler handler=new Handler(new Handler.Callback() {
         @Override
         public boolean handleMessage(Message message) {
@@ -31,25 +35,25 @@ public class MainActivity extends AppCompatActivity {
             StringBuilder sb=new StringBuilder();
             try {
 
+                if (showmessage) {
+                    sb.append("ppg is available ").append(ICJniUtils.isPPGavailable())
+                            .append(", ppg isstarted ").append(ICJniUtils.isPPGStarted())
+                            .append(",ppg ").append(ICJniUtils.getPPG())
+                            .append("weared ").append(ICJniUtils.isWeared())
+                            .append(",spo2 ").append(ICJniUtils.getSPO2())
+                            .append(",bph ").append(ICJniUtils.getHighBloodPressure())
+                            .append(",bpl ").append(ICJniUtils.getLowBloodPressure())
+                            .append("\n");
 
+                    sb.append(CoreService.getInstance().getServerAlive());
+                    tv.setText(sb.toString());
+                }
 
             }catch(Exception e){
                 e.printStackTrace();
             }
 
 
-            sb.append("ppg is available ").append(ICJniUtils.isPPGavailable())
-                    .append(", ppg isstarted ").append(ICJniUtils.isPPGStarted())
-                    .append(",ppg ").append(ICJniUtils.getPPG())
-                    .append("weared ").append(ICJniUtils.isWeared())
-                    .append(",spo2 ").append(ICJniUtils.getSPO2())
-                    .append(",bph ").append(ICJniUtils.getHighBloodPressure())
-                    .append(",bpl ").append(ICJniUtils.getLowBloodPressure())
-                    .append("\n");
-
-            sb.append(protocolMainServer.getInstance().getServerAlive());
-            tv.setText( sb.toString());
-
             return false;
         }
     });
@@ -68,7 +72,7 @@ public class MainActivity extends AppCompatActivity {
 
             @Override
             public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
-                protocolMainServer.getInstance().send_at_to_onoff_simcard(b);
+                CoreService.getInstance().send_at_to_onoff_simcard(b);
             }
         });
         ToggleButton tbtnblood = (ToggleButton)findViewById(R.id.toggleButton2);
@@ -80,7 +84,7 @@ public class MainActivity extends AppCompatActivity {
             }
         });
 
-        startService(new Intent(this,protocolMainServer.class));// protocol service
+        startService(new Intent(this,CoreService.class));// protocol service
 
 //        double longitude=113.878339f;
 //        double latitude=22.580827f;
@@ -94,19 +98,39 @@ public class MainActivity extends AppCompatActivity {
 //        latitude=last;
 //
 //        Logger.i(" lat="+latitude+",lon="+longitude);
+
+
+        TextView tv_version=(TextView)findViewById(R.id.textViewVersion);
+        tv_version.setText(   getVersionName(this));
+
+    }
+
+    @Override
+    protected  void onResume() {
+        super.onResume();
         TimerTask tmt=new TimerTask() {
             @Override
             public void run() {
                 handler.sendEmptyMessage(0);
             }
         };
-        new Timer().schedule(tmt,0,2000);
+        timer=new Timer();
+        timer.schedule(tmt,0,2000);
+        showmessage=true;
+    }
 
-        TextView tv_version=(TextView)findViewById(R.id.textViewVersion);
-        tv_version.setText(   getVersionName(this));
+    @Override
+    protected void onPause() {
+        super.onPause();
+        if (timer!=null) {
+            timer.cancel();
+            timer.purge();
+            timer = null;
+        }
+        showmessage=false;
 
-    }
 
+    }
     /**
      * 得到当前应用版本名称的方法
      *
@@ -130,14 +154,16 @@ public class MainActivity extends AppCompatActivity {
     }
 
 
+
+
     private View.OnClickListener clickListener = new View.OnClickListener() {
         @Override
         public void onClick(View view) {
             switch (view.getId()) {
                 case R.id.btnConnect:
                     //进行连接Socket:这里使用的是,在本地上开启了一个服务器。
-                    stopService(new Intent(MainActivity.this,protocolMainServer.class));// protocol service
-                    startService(new Intent(MainActivity.this,protocolMainServer.class));// protocol service
+                    stopService(new Intent(MainActivity.this,CoreService.class));// protocol service
+                    startService(new Intent(MainActivity.this,CoreService.class));// protocol service
 
 
                     break;
index a289a17..77f5cad 100644 (file)
@@ -5,15 +5,21 @@ import android.util.Log;
 \r
 import com.ic.protocol.Config;\r
 import com.ic.protocol.bean.Contact;\r
+import com.ic.protocol.bean.Content;\r
 import com.ic.protocol.bean.ICLocation;\r
 import com.ic.protocol.bean.Runtime;\r
 import com.ic.protocol.bean.StringMessage;\r
+import com.ic.protocol.bean.VoiceContent;\r
 import com.ic.protocol.bean.voicePacket;\r
-import com.ic.protocol.service.protocolMainServer;\r
+import com.enqualcomm.support.CoreService;\r
+import com.ic.protocol.service.Deliver;\r
 import com.ic.protocol.utils.Connection;\r
 import com.ic.protocol.utils.DBHelper;\r
 import com.ic.protocol.utils.Logger;\r
+import com.ic.protocol.utils.NettyConnection;\r
+import com.ic.protocol.utils.ProcessReceiver;\r
 import com.ic.protocol.utils.SharPreferenceUtil;\r
+import com.ic.protocol.utils.TimeUtil;\r
 import com.ic.protocol.utils.Util;\r
 \r
 import java.util.ArrayList;\r
@@ -305,8 +311,8 @@ public class protocolAPIHelper {
         //示例数据:IWAP03,06000908000102,5555,30#  IWAP03,000000null00000,0,0#\r
         return new StringBuffer(CMDHEADER).append(cmdMap.get(CMD_TYPE.AP03)).append(CMDSPLIT).append(String.format("%03d",abs(ds.getSignalStrength())))\r
                 .append(ds.getGPSLocationStarNums()).append(ds.getBattery()).append("0")\r
-                .append(ds.getProtection()).append(ds.getWorkMode()).append(CMDSPLIT)\r
-                .append(ds.getTotalStepCount()).append(CMDSPLIT).append(0/*rolltime*/).append(CMDEND).toString();\r
+                .append(ds.getProtection()).append(ds.getWorkModeStr()).append(CMDSPLIT)\r
+                .append(ds.getTotalStepCount()).append(CMDSPLIT).append(ds.getRolltimes()).append(CMDEND).toString();\r
     }\r
     //处理 心跳 BP03\r
     public void handleBP03(String cmd){\r
@@ -325,10 +331,10 @@ public class protocolAPIHelper {
          * 00:第一个0:是否需要回复地址信息,0:不回复,1回复.\r
          * HOME|74-DE-2B-44-88-8C|97&HOME1|74-DE-2B-44-88-8C|97&HOME2|74-DE-2B-44-88-8C|97&HOME3|74-DE-2B-44-88-8C|97#\r
          */\r
-        return new StringBuffer(CMDHEADER).append(cmdMap.get(CMD_TYPE.AP10)).append(ds.getShortDate())\r
-                .append(ds.getGPSData()).append(ds.getShortTime()).append(ds.getGPSHeading()).append(String.format("%03d",abs(ds.getSignalStrength())))\r
+        return new StringBuffer(CMDHEADER).append(cmdMap.get(CMD_TYPE.AP10)).append(TimeUtil.getShortDate())\r
+                .append(ds.getGPSData()).append(TimeUtil.getShortTime()).append(ds.getGPSHeading()).append(String.format("%03d",abs(ds.getSignalStrength())))\r
                 .append(ds.getGPSLocationStarNums()).append(ds.getBattery()).append("0")\r
-                .append(ds.getProtection()).append(ds.getWorkMode()).append(CMDSPLIT)\r
+                .append(ds.getProtection()).append(ds.getWorkModeStr()).append(CMDSPLIT)\r
                 .append(ds.getLBSData()).append(CMDSPLIT)\r
                 .append(ds.getAlarmType()).append(CMDSPLIT)\r
                 .append(ds.getLanguage()).append(CMDSPLIT)\r
@@ -343,10 +349,10 @@ public class protocolAPIHelper {
         // 460,0,9520,3671,\r
         // Home|74-DE-2B-44-88-8C|97& Home1|74-DE-2B-44-88-8C|97&Home2|74-DE-2B-44-88-8C|97& Home3|74-DE-2B-44-88-8C|97#\r
 //        IWAP01191230A2232.9807N11404.9355E000.1161320000.0006000910000000,460,00,9520,3671,#\r
-        return new StringBuffer(CMDHEADER).append(cmdMap.get(CMD_TYPE.AP01)).append(ds.getShortDate())\r
-                .append(ds.getGPSData()).append(ds.getShortTime()).append(ds.getGPSHeading()).append(String.format("%03d",abs(ds.getSignalStrength())))\r
+        return new StringBuffer(CMDHEADER).append(cmdMap.get(CMD_TYPE.AP01)).append(TimeUtil.getShortDate())\r
+                .append(ds.getGPSData()).append(TimeUtil.getShortTime()).append(ds.getGPSHeading()).append(String.format("%03d",abs(ds.getSignalStrength())))\r
                 .append(ds.getGPSLocationStarNums()).append(ds.getBattery()).append("0")\r
-                .append(ds.getProtection()).append(ds.getWorkMode()).append(CMDSPLIT)\r
+                .append(ds.getProtection()).append(ds.getWorkModeStr()).append(CMDSPLIT)\r
                 .append(ds.getLBSData()).append(CMDSPLIT).append(ds.getWifiInfo()).append(CMDEND).toString();\r
     }\r
 \r
@@ -648,7 +654,8 @@ public class protocolAPIHelper {
 \r
                }\r
             }\r
-            runtime.getDbHelper().saveContacts(contactArray,false,false,true,false,false);\r
+            contactArray.add(new Contact(Contact.CATEGORY_ADMIN,"GROUP","123"));\r
+            runtime.getDbHelper().saveContacts(contactArray,true,false,true,false,false);\r
 \r
         }else{\r
             Logger.i(" BP14 format error!");\r
@@ -778,6 +785,65 @@ public class protocolAPIHelper {
 \r
 \r
 \r
+    public static byte[] AP07(String  packetTime,int count,int index,int datalen,byte[] amrdata){\r
+//IWAP07,20140818064408,6,1,1024,XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX#\r
+//说明:\r
+//IW:标识符\r
+//AP07 : 命令字符\r
+//20140818064408 :yyyyMMddHHmmss 格式的年月日时分秒,设备录音时间\r
+//6:语音包分包总数\r
+//1 :当前包数,第一包为1,第二包为2,。。。。。。同一个语音包的语音时间相同\r
+//1024 :语音包长度\r
+//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:当前音频数据, 每个音频数据包大小为1024字节,最后一包不足1024的取实际字节数\r
+//语音包上传规则:\r
+//按包次序依次上传,上传后如果没有收到服务器的响应包,则继续上传该语音包。\r
+//收到设备回复确认数据包接收成功状态后,继续开始依次上传下一个数据包。。。。。。\r
+//如果设备回复确认数据包接收失败状态,则重复发送上一个数据包\r
+\r
+\r
+        String sb=new StringBuffer(CMDHEADER).append(cmdMap.get(CMD_TYPE.AP07))\r
+                .append(CMDSPLIT).append(packetTime)\r
+                .append(CMDSPLIT).append(count)\r
+                .append(CMDSPLIT).append(index)\r
+                .append(CMDSPLIT).append(datalen)\r
+                .append(CMDSPLIT).toString();\r
+\r
+        byte[] sentbuf=new byte[sb.length()+datalen+1];\r
+        System.arraycopy(sb.getBytes(),0,sentbuf,0,sb.length());\r
+        System.arraycopy(amrdata,0,sentbuf,sb.length(),datalen);\r
+        sentbuf[sb.length()+datalen]='#';\r
+\r
+        return sentbuf;\r
+\r
+    }\r
+\r
+\r
+    public void handleBP07(String cmd , NettyConnection connection ){\r
+//平台响应:      IWBP07,20140818064408,6,1,1#\r
+//20140818064408:设备语音时间,yyyyMMddHHmmss 格式的年月日时分秒\r
+//6:语音包分包总数\r
+//1:当前设备收到的是第几个包\r
+//1:表示服务器接受数据成功,0表示服务器接受数据失败\r
+        String[] cmdlist=cmd.split(CMDSPLIT);\r
+        if (cmdlist.length==5){\r
+            String time=cmdlist[1];\r
+            int packetCount=Integer.valueOf(cmdlist[2]);\r
+            int packetIndex=Integer.valueOf(cmdlist[3]);\r
+            int receiveSuccess=Integer.valueOf(cmdlist[4]);\r
+            Logger.i("服务器在"+time+" 收到语音 "+packetIndex+"/"+packetCount+" "+ (receiveSuccess==1?"成功":"失敗"));\r
+            if (receiveSuccess == 1){\r
+                //如果服务器接收 语音成功,则设置下一个要发送的语音包Index,当index == packetCount的时候表示所有包发送完毕,停止继续发送\r
+                voicePacket.getInstanceSent().setCurrentIndexToSent(++packetIndex);\r
+            }\r
+            //发送消息,再次检查要发送的语音包,确认其发送完毕\r
+            connection.DeliverCMDMessageToSystem("BP07","SentVoicePacket");\r
+\r
+        }else{\r
+            Logger.i(" BP07 Format error!");\r
+        }\r
+    }\r
+\r
+\r
     public static String AP33(String cmdindex,int workMode){\r
 //IWAP33,080835,1#\r
 //080835:指令流水号\r
@@ -989,7 +1055,7 @@ public static String AP15(String index){
     }\r
 \r
     //处理 BP28 语音消息\r
-    public void handleBP28(Connection connection,String cmd,byte[] bytes) {\r
+    public void handleBP28(Connection connection,String cmd,Runtime runtime,byte[] bytes) {\r
         //log("handleBP28 msg"+cmd);\r
 /**\r
  * IWBP28, D3590D54,XXXX,6,1,1024,XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX#\r
@@ -1039,8 +1105,17 @@ public static String AP15(String index){
                     .append(",packetDatalen = ").append(packetData.length);\r
 \r
             log( stringBuffer.toString());\r
-            voicePacket.getInstance().appendVoice(Name,appendIndex,packetCount,currentId,packetLen,packetData);\r
             connection.send(genStringMessage("AP28",AP28(Name,appendIndex,packetCount,currentId,1)));\r
+            voicePacket.getInstance().appendVoice(Name,appendIndex,packetCount,currentId,packetLen,packetData);\r
+            log("================"+voicePacket.getInstance().toString());\r
+            if (voicePacket.getInstance().isFinished())\r
+            {\r
+                String amrFilepath=Util.saveFile(voicePacket.getInstance().getVoicePacketBytes(),0,voicePacket.getInstance().getVoicePacketLen(),runtime.getCacheDir(),voicePacket.getInstance().getName()+".amr");\r
+                Logger.i("save Amr file to "+amrFilepath);\r
+                voicePacket.getInstance().clearPacket();\r
+                runtime.getDbHelper().insertMessage( VoiceContent.placeHolderIn(Content.CATEGORY_VOICE,"1234567890",amrFilepath));\r
+\r
+            }\r
 \r
         }else{\r
             log("handleBP28","format Error");\r
index 46d487d..c921356 100644 (file)
@@ -33,6 +33,7 @@ public class ICLocation {
     public static final int LOWPOWER_MOD=2;   // location rate 1 time per hour\r
     public static final int EMERGNECY_MOD=3; //location rate 1 time per minutes\r
     public static final int REALTIME_MOD=4; //location rate 1 time per minutes\r
+    public static final int CUSTOM_MOD=5; //location rate 1 time per minutes\r
 \r
 \r
     private int mworkingMod;\r
index f3a9f4d..6d0d964 100644 (file)
@@ -78,19 +78,24 @@ public class Runtime {
   \r
   public String lacByAt;\r
   \r
-  private String latitude;\r
-  \r
+\r
   private LBSHelper lbsHelper;\r
 \r
 \r
   private heartRateStatus HRS=null;\r
 \r
-//  private String location;\r
-  \r
+\r
+  private boolean UseQueue=false;\r
   private boolean lockSimInfo=false;\r
-  \r
-  private String longitude;\r
-  \r
+\r
+\r
+  public void setUseQueue(boolean usequeue){\r
+    UseQueue=usequeue;\r
+  }\r
+\r
+  public boolean getUseQueue(){\r
+    return UseQueue;\r
+  }\r
   private String mccAndMnc;\r
   \r
   private String language="zh-cn";\r
@@ -288,12 +293,10 @@ public class Runtime {
     this.lacByAt = paramString1;\r
     this.cellidByAt = paramString2;\r
   }\r
-  \r
-//  public void setLocation(String paramString) { this.location = paramString; }\r
+\r
   \r
   public void setLockSimInfo(boolean paramBoolean) { this.lockSimInfo = paramBoolean; }\r
-  \r
-  public void setLongitude(String paramString) { this.longitude = paramString; }\r
+\r
   \r
   public void setMccAndMnc(String MccMnc) {\r
     this.mccAndMnc = MccMnc;\r
@@ -321,11 +324,6 @@ public class Runtime {
   \r
   public void setTotalStepCount(int paramInt) { this.totalStepCount = paramInt; }\r
 \r
-\r
-  private final String UserDebug = "userdebug";\r
-  private final String User = "user";\r
-\r
-\r
   private ICLocation gpsp = null;\r
 \r
   private String wifiInfo="";\r
@@ -347,14 +345,6 @@ public class Runtime {
   }\r
 \r
 \r
-  /*\r
-  return UserDebug , User\r
-   */\r
-  public String BuildType() {\r
-    return UserDebug;\r
-  }\r
-\r
-\r
   public String HardwareInfo() {\r
     return "SC9820E C41 V1.0";\r
   }\r
@@ -367,20 +357,24 @@ public class Runtime {
 \r
   /*    AP03 心跳包     */\r
 \r
-\r
+ //暂时没有实现此功能\r
   public String getGPSLocationStarNums() {\r
     return "000";\r
   }\r
 \r
+  //此功能未实现\r
   public String getProtection() {\r
     return "00";\r
   }\r
 \r
-  public String getWorkMode() {\r
-    return "00";\r
-  }\r
+  //\r
+  public String getWorkModeStr() {\r
+    String gpsStr=String.format("%02d",getLocationInstance().getWorkingMod());\r
 \r
+    return gpsStr;\r
+  }\r
 \r
+ //未实现睡眠监测\r
   public String getRolltimes() {\r
     return "00";\r
   }\r
@@ -388,53 +382,7 @@ public class Runtime {
 \r
   /*  AP01 定位       */\r
 \r
-  /* 返回 2位年2位月2位日, 如2019-12-30 返回 191230*/\r
-  public String getShortDate() {\r
-    String DEFAULT_TIME_FORMAT = "yyMMdd";\r
-    SimpleDateFormat dateFormatter = new SimpleDateFormat(DEFAULT_TIME_FORMAT);\r
-    String dateStr = dateFormatter.format(Calendar.getInstance().getTime());//获取当前时间\r
-    return dateStr;\r
-  }\r
-\r
-  public void parseDatetiime(String datetimeStr){\r
 \r
-    SimpleDateFormat dff = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS", Locale.ENGLISH);//输入的被转化的时间格式\r
-    SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//需要转化成的时间格式\r
-    SimpleDateFormat df2 = new SimpleDateFormat("yyyyMMddHHmmssSSS");\r
-    Date date1 = null;\r
-    try {\r
-      date1 = dff.parse(datetimeStr);\r
-    } catch (ParseException e) {\r
-      e.printStackTrace();\r
-    }\r
-    String str1 = df1.format(date1);\r
-    String str2 = df2.format(date1);\r
-\r
-  }\r
-  /*061830: 格林尼治时间06 点18 分30 秒 */\r
-  public String getShortTime(){\r
-    String DEFAULT_TIME_FORMAT = "HHmmss";\r
-    //设置时间的格式\r
-    //                      yyyy-MM-dd 1969-12-31\r
-    //                      yyyy-MM-dd 1970-01-01\r
-    //                yyyy-MM-dd HH:mm 1969-12-31 16:00\r
-    //                yyyy-MM-dd HH:mm 1970-01-01 00:00\r
-    //               yyyy-MM-dd HH:mmZ 1969-12-31 16:00-0800\r
-    //               yyyy-MM-dd HH:mmZ 1970-01-01 00:00+0000\r
-    //        yyyy-MM-dd HH:mm:ss.SSSZ 1969-12-31 16:00:00.000-0800\r
-    //        yyyy-MM-dd HH:mm:ss.SSSZ 1970-01-01 00:00:00.000+0000\r
-    //      yyyy-MM-dd'T'HH:mm:ss.SSSZ 1969-12-31T16:00:00.000-0800\r
-    //      yyyy-MM-dd'T'HH:mm:ss.SSSZ 1970-01-01T00:00:00.000+0000\r
-    //注:HH显示的是24小时制,hh显示的是12小时制\r
-\r
-    SimpleDateFormat dateFormatter = new SimpleDateFormat(DEFAULT_TIME_FORMAT);\r
-    String dateStr = dateFormatter.format(Calendar.getInstance().getTime());//获取当前时间\r
-//        SimpleDateFormat dff = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS", Locale.ENGLISH);//输入的被转化的时间格式\r
-//        SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//需要转化成的时间格式\r
-//        SimpleDateFormat df2 = new SimpleDateFormat("yyyyMMddHHmmssSSS");\r
-\r
-    return dateStr;\r
-  }\r
 \r
   public boolean isGPSFixed(){\r
     return (gpsp.getLocationStat() == ICLocation.LOCATION_STAT.LOCATION_FIXED);\r
index 4930e48..43acfa6 100644 (file)
@@ -12,26 +12,17 @@ public class VoiceContent extends Content {
 \r
   }\r
   \r
-  public static VoiceContent from(VoiceContent _voiceContent, byte[] amrData, File amrFilepath) {\r
-    byte b = amrData[0];\r
-    byte[] arrayOfByte = new byte[b];\r
-    System.arraycopy(amrData, 1, arrayOfByte, 0, b);\r
-    ArrayList arrayList = Util.split(arrayOfByte, (byte)59, 0);\r
-    StringBuilder stringBuilder1 = new StringBuilder();\r
-    stringBuilder1.append(new String((byte[])arrayList.get(1)));\r
-    stringBuilder1.append(new String((byte[])arrayList.get(2)));\r
-    String str2 = stringBuilder1.toString();\r
-    String str3 = new String((byte[])arrayList.get(4));\r
-    int i = amrData.length - 1 - b;\r
-    int j = amrData.length;\r
+  public static VoiceContent from(VoiceContent _voiceContent, byte[] amrData, File amrFilepath,String servertime) {\r
+\r
     StringBuilder stringBuilder2 = new StringBuilder();\r
-    stringBuilder2.append(str3);\r
+//    stringBuilder2.append(str3);\r
     stringBuilder2.append(".amr");\r
-    String str1 = Util.saveFile(amrData, j - i, i, amrFilepath, stringBuilder2.toString());\r
-    i = Util.getDuration(str1);\r
-    _voiceContent.preview = (_voiceContent.content = str1).valueOf(i);\r
+    String str1 = Util.saveFile(amrData, 0, amrData.length, amrFilepath, stringBuilder2.toString());\r
+    int duration = Util.getDuration(str1);\r
+    _voiceContent.content = str1;\r
+    _voiceContent.preview = String.valueOf(duration);\r
     _voiceContent.status = 2;\r
-    _voiceContent.serverTime = str2;\r
+    _voiceContent.serverTime = servertime;\r
     return _voiceContent;\r
   }\r
   \r
index 7036a96..f7169d4 100644 (file)
@@ -1,21 +1,49 @@
 package com.ic.protocol.bean;\r
 \r
 import java.util.ArrayList;\r
+import java.util.Iterator;\r
 \r
 public class voicePacket {\r
 \r
 \r
     private static voicePacket gvoicePacket=null;\r
-\r
-\r
     public static voicePacket getInstance(){\r
         if (gvoicePacket==null)\r
             gvoicePacket=new voicePacket();\r
         return gvoicePacket;\r
     }\r
+    private static voicePacket gvoicepacket_sent=null;\r
+    public static voicePacket getInstanceSent(){\r
+        if (gvoicepacket_sent==null)\r
+            gvoicepacket_sent=new voicePacket();\r
+        return gvoicepacket_sent;\r
+    }\r
+\r
+    String time=null;\r
     String Name=null;\r
     String appendIndex=null;\r
     int packetCount =0;\r
+    int currentIndexToSent=0;// 如果 (currentIndexToSent == (packetCount -1)) 则发送完毕\r
+\r
+    public void setCurrentIndexToSent(int index){\r
+        currentIndexToSent=index;\r
+    }\r
+\r
+    public int getCurrentIndexToSent(){\r
+        return currentIndexToSent;\r
+    }\r
+\r
+    public int getPacketCount(){\r
+        return packetCount;\r
+    }\r
+\r
+\r
+    public void setPacketTime(String _time){\r
+        time=_time;\r
+    }\r
+    public String getPacketTime(){\r
+        return time;\r
+    }\r
     ArrayList<voicepacketItem> packetArray =new ArrayList<voicepacketItem>();\r
     public class voicepacketItem{\r
         int currentId;\r
@@ -26,10 +54,17 @@ public class voicePacket {
             packetData=_packetData;\r
             currentId=_currentId;\r
         }\r
+        public byte[] getPacketData()\r
+        {\r
+            return packetData;\r
+        }\r
+        public int getPacketLen(){\r
+            return packetLen;\r
+        }\r
     }\r
     public boolean appendVoice(String _Name, String _appendIndex,int _packetCount,int _currentId, int _packetLen, byte[] _packetData){\r
         boolean ret=false;\r
-        if (_Name==null|| _appendIndex==null || _Name.isEmpty() || _appendIndex.isEmpty() ){\r
+        if (_Name==null|| _appendIndex==null || _Name.isEmpty()  ){\r
                 return false;\r
         }\r
         if (packetArray.size()==0)\r
@@ -38,7 +73,7 @@ public class voicePacket {
             appendIndex=_appendIndex;\r
             packetCount=_packetCount;\r
         }\r
-        if (_packetCount==packetCount  &&  appendIndex.equals(_appendIndex) && Name.equals(_Name)  ){\r
+        if (_packetCount==packetCount   && Name.equals(_Name)  ){\r
             boolean packetfound=false;\r
             for ( voicepacketItem item: packetArray ) {\r
                 if (item.currentId == _currentId){\r
@@ -65,7 +100,7 @@ public class voicePacket {
     @Override\r
     public String toString(){\r
         StringBuilder stringBuilder=new StringBuilder();\r
-        if (Name==null|| appendIndex==null || Name.isEmpty() || appendIndex.isEmpty() ){\r
+        if (Name==null|| appendIndex==null || Name.isEmpty() ){\r
             return stringBuilder.toString();\r
         }\r
 \r
@@ -89,4 +124,53 @@ public class voicePacket {
         Name=null;\r
         appendIndex=null;\r
     }\r
+\r
+    public int getVoicePacketLen(){\r
+        int len=0;\r
+        if (isFinished()){\r
+           Iterator<voicepacketItem> it= packetArray.iterator();\r
+           while(it.hasNext()){\r
+               len+=it.next().packetLen;\r
+           }\r
+        }\r
+        return len;\r
+    }\r
+    public voicepacketItem getVoicePacketWithIndex(int index){\r
+\r
+            for (int i=0;i< packetArray.size();i++){\r
+                voicepacketItem tmp=packetArray.get(i);\r
+                if (tmp.currentId==index)\r
+                    return tmp;\r
+            }\r
+\r
+            return null;\r
+    }\r
+    public byte[] getVoicePacketBytes(){\r
+        byte[] amrbuf;\r
+        int buflen=getVoicePacketLen();\r
+        if (buflen>0){\r
+            amrbuf=new byte[buflen];\r
+            int index=0;\r
+            for(int i =0;i<packetCount;i++) {\r
+                voicepacketItem tmp=getVoicePacketWithIndex(i);\r
+                if (tmp!=null) {\r
+                    //src - 源数组。\r
+                    //srcPos - 源数组中的起始位置。\r
+                    //dest - 目标数组。\r
+                    //destPos - 目标数据中的起始位置。\r
+                    //length - 要复制的数组元素的数量。\r
+                    System.arraycopy(tmp.packetData,0,amrbuf,index,tmp.packetLen);\r
+                    index+=tmp.packetLen;\r
+                }\r
+            }\r
+            return amrbuf;\r
+        }else{\r
+            return null;\r
+        }\r
+\r
+    }\r
+\r
+    public String getName(){\r
+        return Name;\r
+    }\r
 }\r
index ee5cca0..5883c5a 100644 (file)
@@ -15,19 +15,33 @@ import android.os.Handler;
 import android.os.PowerManager;\r
 import android.os.SystemClock;\r
 import android.text.TextUtils;\r
+\r
+import com.enqualcomm.support.CoreService;\r
+import com.ic.protocol.LocationClient;\r
+import com.ic.protocol.adapter.protocolAPIHelper;\r
 import com.ic.protocol.bean.StringMessage;\r
 import com.ic.protocol.bean.VoiceContent;\r
+import com.ic.protocol.bean.voicePacket;\r
 import com.ic.protocol.service.base.AbstractConnectionService;\r
 import com.ic.protocol.utils.AlarmHelper;\r
+import com.ic.protocol.utils.AlarmWakeUp;\r
 import com.ic.protocol.utils.Connection;\r
 import com.ic.protocol.bean.Runtime;\r
 import com.ic.protocol.utils.DBHelper;\r
+import com.ic.protocol.utils.FileCache;\r
+import com.ic.protocol.utils.FileOutputUtil;\r
 import com.ic.protocol.utils.Logger;\r
+import com.ic.protocol.utils.NettyConnection;\r
 import com.ic.protocol.utils.ServiceUtil;\r
 import com.ic.protocol.utils.SharPreferenceUtil;\r
+import com.ic.protocol.utils.SimSignalUtil;\r
 \r
 import java.util.ArrayList;\r
+import java.util.concurrent.LinkedBlockingDeque;\r
 import java.util.concurrent.TimeUnit;\r
+import java.util.concurrent.locks.Condition;\r
+import java.util.concurrent.locks.ReentrantLock;\r
+\r
 import rx.Observable;\r
 import rx.Subscriber;\r
 import rx.functions.Action1;\r
@@ -35,7 +49,11 @@ import rx.schedulers.Schedulers;
 \r
 import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;\r
 import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;\r
+import static com.ic.protocol.Constants.ACTION_WAKEUP_ALARM;\r
 \r
+/**\r
+ * 负责发送除了login,心跳之外的所有指令\r
+ */\r
 public class Deliver extends AbstractConnectionService {\r
   private static final String RECEIVE_WAKE_LOCKTAG = "ReceiveWakelockTag";\r
   \r
@@ -44,7 +62,18 @@ public class Deliver extends AbstractConnectionService {
   public static boolean haveSendH42 = false;\r
   \r
   private static int isAppSetWifi = 0;\r
-  \r
+\r
+\r
+\r
+  private static ReentrantLock mLock = new ReentrantLock();\r
+  private static ReentrantLock lock = new ReentrantLock();\r
+  private static Condition mCondition = mLock.newCondition();\r
+\r
+  public static LinkedBlockingDeque<StringMessage> queue = new LinkedBlockingDeque(50);\r
+\r
+  private static FileCache fileCache;\r
+  private static NettyConnection connection;\r
+\r
   public static boolean is_active_location = false;\r
   \r
   private PowerManager.WakeLock ReceiveWakeLock;\r
@@ -54,10 +83,10 @@ public class Deliver extends AbstractConnectionService {
   private Runnable delayTh;\r
   \r
   private Connection mConnection;\r
-  \r
+\r
   private ConWifiReceiver mMyWifiReceiver;\r
   \r
-  private Runtime mRuntime;\r
+  private static Runtime mRuntime;\r
   \r
   private final String spilForWifi = "@EQCWIFI@";\r
   \r
@@ -72,14 +101,224 @@ public class Deliver extends AbstractConnectionService {
   static  {\r
   \r
   }\r
-  \r
+  public Deliver(NettyConnection paramNettyConnection, Runtime paramRuntime) {\r
+    connection = paramNettyConnection;\r
+    mRuntime = paramRuntime;\r
+    //把queue 保存在磁盘中的缓存文件\r
+    //此文件只缓存 除了 登录指令AP00,心跳AP03以及voice 分包指令以外的需要上传的指令。初步规划为 定位AP01和心率/血压 APHT\r
+    fileCache = new FileCache(paramRuntime.getFileDir());\r
+    initQueue();\r
+  }\r
+  public static void triggerSendThread(){\r
+    if (mRuntime.getUseQueue()) {\r
+      mLock.lock();\r
+      try {\r
+        mCondition.signal();\r
+\r
+      } finally {\r
+        mLock.unlock();\r
+      }\r
+    }\r
+  }\r
+  MyThread2 mythread2=null;\r
+\r
+  private void initQueue(){\r
+    if (mRuntime.getUseQueue()) {\r
+      /*启动 阻塞队列buffer 发送县城,随时准备发送buffer的message*/\r
+      if (mythread2 == null)\r
+        mythread2 = new MyThread2(this.mCondition, this.mLock);\r
+      mythread2.exitthread=false;\r
+      mythread2.start();\r
+    }\r
+  }\r
+\r
+  private void deInitQueue(){\r
+    if (mRuntime.getUseQueue()) {\r
+      mythread2.exitthread = true;\r
+      if (mythread2 != null) {\r
+//      mythread2.stop();\r
+        mythread2 = null;\r
+      }\r
+    }\r
+  }\r
+  private static void loadMessage2Queue() {\r
+    byte b = 0;\r
+    //一次只处理5条数据\r
+    while (b < 5) {\r
+      String str = fileCache.load();\r
+      if (str != null) {\r
+        byte b1 = ++b;\r
+\r
+        try {\r
+          StringMessage stringMessage = new StringMessage(str);\r
+          //如果在queue中添加失败,则写回cache中\r
+          if (!queue.offerLast(stringMessage)) {\r
+            fileCache.put(str);\r
+          }\r
+        } catch (Exception e) {\r
+          e.printStackTrace();\r
+        }\r
+      }\r
+    }\r
+  }\r
+  public static void saveQueue() {\r
+    lock.lock();\r
+    try {\r
+      String str;\r
+      if (!queue.isEmpty()) {\r
+        StringBuilder stringBuilder = new StringBuilder();\r
+        StringMessage stringMessage = queue.poll();\r
+        while (stringMessage != null) {\r
+            String cmd=stringMessage.isFromCache();\r
+            stringBuilder.append(cmd);\r
+            stringBuilder.append("\n");\r
+            fileCache.put(cmd);\r
+            stringMessage = queue.poll();\r
+        }\r
+        str = stringBuilder.toString();\r
+      } else {\r
+        str = null;\r
+      }\r
+      Logger.i("save queue to cache : \n"+str);\r
+      lock.unlock();\r
+      return;\r
+    } finally {\r
+      lock.unlock();\r
+    }\r
+  }\r
+\r
+\r
+  static class MyThread2 extends Thread {\r
+    Condition condition;\r
+\r
+    boolean isResent = false;\r
+    public boolean exitthread=false;\r
+    ReentrantLock lock;\r
+\r
+    public MyThread2(Condition param1Condition, ReentrantLock param1ReentrantLock) {\r
+      this.condition = param1Condition;\r
+      this.lock = param1ReentrantLock;\r
+    }\r
+\r
+    public void run() {\r
+      StringMessage stringMessage = null;\r
+\r
+      while (!exitthread) {\r
+\r
+        //循环发送queue 中的数据\r
+\r
+        try {\r
+          Logger.i("Sending Thread Queue Take ");\r
+\r
+          StringMessage stringMessage1 = (StringMessage)queue.take();\r
+          try {\r
+\r
+            int signal=mRuntime.getSignalStrength();\r
+            int networkType=SimSignalUtil.getInstance((mRuntime.getContextProxy()).context).getNetworkType();\r
+            if (signal + 110 < getMinSignalStrength(networkType)) {\r
+              Logger.i("Skip Send for SignalStrengh "+(signal + 110 )+" < "+getMinSignalStrength(networkType));\r
+              //如果信号不好,把msg放回去\r
+              queue.putFirst(stringMessage1);\r
+\r
+            } else {\r
+\r
+              stringMessage=stringMessage1;\r
+\r
+              Context context = (mRuntime.getContextProxy()).context;\r
+              StringBuilder stringBuilder = new StringBuilder();\r
+              stringBuilder.append("send=");\r
+              stringBuilder.append(stringMessage.cmd());\r
+              stringBuilder.append(", ");\r
+              stringBuilder.append(stringMessage.isFromCache());\r
+              FileOutputUtil.fileOutput(mRuntime.getCacheDir(), "MessageInfo", stringBuilder.toString());\r
+              Logger.i(stringBuilder.toString());\r
+              if( connection.isServerConnected() ==false  && !KeepAlive.isConnected  ) {\r
+\r
+                Logger.i("Skip Send for connection and KeepAlive both false ");\r
+                //发现连接断开则重试连接\r
+//                CoreService.getInstance().startConnectionRetryTimer();\r
+                //连接断开就把msg放回队列,以便重发\r
+                queue.putFirst(stringMessage1);\r
+              }else{\r
+                //连接状态都正常才发送包\r
+                connection.send(stringMessage);\r
+              }\r
+\r
+\r
+              this.lock.lock();\r
+\r
+              try {\r
+                if (KeepAlive.isConnected) {\r
+                  //如果 服务器连接状态,等30秒,随时等待数据发送\r
+                  Logger.i("KeepAlive.isConnected "+KeepAlive.isConnected+" delay 30000ms");\r
+                  this.condition.await(30000L, TimeUnit.MILLISECONDS);\r
+                } else {\r
+                  //如果服务器断开,等5秒 以便连接后尽快进入下一循环,尽量及时响应\r
+                  Logger.i("KeepAlive.isConnected "+KeepAlive.isConnected+ "  , connection isconnected "+connection.isServerConnected()+" delay 5000ms");\r
+\r
+                  this.condition.await(5000L, TimeUnit.MILLISECONDS);\r
+                }\r
+\r
+\r
+                if (queue.peek() == null) {\r
+                  loadMessage2Queue();\r
+                  this.lock.unlock();\r
+                  continue;\r
+                }\r
+\r
+              } catch (InterruptedException e) {\r
+                e.printStackTrace();\r
+              }finally{\r
+                this.lock.unlock();\r
+              }\r
+            }\r
+          } catch (Exception e) {\r
+            e.printStackTrace();\r
+          }\r
+        } catch (Exception e) {\r
+          e.printStackTrace();\r
+        }\r
+      }//while end\r
+    }\r
+  }\r
+public static void sendLocationMSG( String Msg){\r
+\r
+    if(mRuntime.getUseQueue()){\r
+        ServiceUtil.offerQueue(protocolAPIHelper.genStringMessage("queue",Msg));\r
+        triggerSendThread();\r
+    }else {\r
+      if (connection.isServerConnected() && KeepAlive.isConnected) {\r
+        Logger.i(" first send " + Msg);\r
+        connection.send(protocolAPIHelper.genStringMessage("queue",Msg));\r
+      } else {\r
+        Logger.i("offline skip  " + Msg);\r
+        FileOutputUtil.fileOutput(mRuntime.getCacheDir(), "APILog", " offlineskip  " + Msg);\r
+      }\r
+    }\r
+}\r
+  private static int getMinSignalStrength(int paramInt) {\r
+    int b = -105;\r
+    switch (paramInt) {\r
+      case SimSignalUtil.IS_4G:\r
+        b = -100;\r
+        break;\r
+      case SimSignalUtil.IS_2G:\r
+      case SimSignalUtil.IS_3G:\r
+      default:\r
+        break;\r
+    }\r
+    return b;\r
+  }\r
+\r
   public static PowerManager.WakeLock WakeLockForGetWifiList(Runtime paramRuntime) {\r
-    PowerManager.WakeLock wakeLock = ((PowerManager)(paramRuntime.getContextProxy()).context.getSystemService(Context.POWER_SERVICE)).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "waitForWifiListReply");\r
+    PowerManager.WakeLock wakeLock = ((PowerManager)(paramRuntime.getContextProxy()).context.getSystemService(Context.POWER_SERVICE)).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, RECEIVE_WAKE_LOCKTAG);\r
     wakeLock.acquire(120000L);\r
     return wakeLock;\r
   }\r
   \r
-  private boolean isSilence(Runtime paramRuntime) { return SharPreferenceUtil.getPrefBoolean((paramRuntime.getContextProxy()).context, "KEY_ISSILENCE", false); }\r
+  private boolean isSilence(Runtime paramRuntime) {\r
+    return SharPreferenceUtil.getPrefBoolean((paramRuntime.getContextProxy()).context, "KEY_ISSILENCE", false);\r
+  }\r
   \r
   public static void releaseWakeLockForGetWifiList() {\r
     if (WifiListWakeLock == null) {\r
@@ -93,7 +332,7 @@ public class Deliver extends AbstractConnectionService {
   }\r
   \r
   public PowerManager.WakeLock getWakeLock() {\r
-    PowerManager.WakeLock wakeLock = ((PowerManager)(this.mRuntime.getContextProxy()).context.getSystemService(Context.POWER_SERVICE)).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ReceiveWakelockTag");\r
+    PowerManager.WakeLock wakeLock = ((PowerManager)(this.mRuntime.getContextProxy()).context.getSystemService(Context.POWER_SERVICE)).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, RECEIVE_WAKE_LOCKTAG);\r
     wakeLock.acquire(40000L);\r
     return wakeLock;\r
   }\r
@@ -109,449 +348,63 @@ public class Deliver extends AbstractConnectionService {
   public void onDetach(Connection paramConnection, Runtime paramRuntime) {}\r
   \r
   public boolean onReceive(StringMessage paramStringMessage, Connection paramConnection, final Runtime paramRuntime) {\r
-    StringBuilder stringBuilder4;\r
-    final String number;\r
-    StringBuilder stringBuilder3;\r
-    String[] arrayOfString6;\r
-    final WifiManager wifiManager;\r
-    long l;\r
-    int i=-1;\r
-    StringBuilder stringBuilder2;\r
-    Intent intent;\r
-    String str4;\r
-    String[] arrayOfString5;\r
-    String str3;\r
-    StringBuilder stringBuilder1;\r
-    String[] arrayOfString4;\r
-    String str2;\r
-    String[] arrayOfString2;\r
-    Context context;\r
-    String str1;\r
-    DBHelper dBHelper;\r
-    final String[] passWord;\r
-    String[] arrayOfString1;\r
     this.mConnection = paramConnection;\r
     this.mRuntime = paramRuntime;\r
     String cmd = paramStringMessage.cmd();\r
     Logger.i("Deliver receive cmd "+paramStringMessage.cmd());\r
+    if (cmd.equals("BP07") || cmd.equals("SentVoicePacket")){\r
+    //收到BP07 表示服务器收到一个voicePacket 分包成功,开始检查下一个包是否存在需要发送。\r
+      //收到SentVoicePacket 表示 有一个VoiceMessage要发送,需要开始检查并发送语音分包。\r
+     voicePacket voicepacket= voicePacket.getInstanceSent();\r
+     if (voicepacket.getCurrentIndexToSent() < voicepacket.getPacketCount()){\r
+       Logger.i("voicepacket "+voicepacket.getName()+" "+voicepacket.getPacketTime()+" send "+(voicepacket.getCurrentIndexToSent()+1)+"/"+voicepacket.getPacketCount());\r
+       ((NettyConnection)mConnection).sendMsg(\r
+               protocolAPIHelper.AP07(voicepacket.getPacketTime(),\r
+                       voicepacket.getPacketCount(),\r
+                       voicepacket.getCurrentIndexToSent(),\r
+                       voicepacket.getVoicePacketWithIndex(voicepacket.getCurrentIndexToSent()).getPacketLen(),\r
+                       voicepacket.getVoicePacketWithIndex(voicepacket.getCurrentIndexToSent()).getPacketData())\r
+       );\r
+     }else{\r
+       Logger.i("voicepacket "+voicepacket.getName()+" "+voicepacket.getPacketTime()+" sent Done!");\r
+     }\r
+     return true;\r
+    }\r
 \r
-    if (cmd.startsWith("SmsSet")) {\r
-      arrayOfString4 = cmd.split(":");\r
-      if (arrayOfString4.length > 1) {\r
-//        paramConnection.send(API.H13(paramRuntime, arrayOfString4[1]));\r
-        if ("1".equals(arrayOfString4[1])) {\r
-          int j = paramRuntime.getContextProxy().getTelephonyManager().getCallState();\r
-          if (1 != j && 2 != j && !isSilence(paramRuntime)) {\r
-//            paramRuntime.getContextProxy().startSearchActivity();\r
-            return true;\r
-          } \r
-        } else {\r
-          if ("2".equals(arrayOfString4[1])) {\r
-            Observable.timer(5000L, TimeUnit.MILLISECONDS).subscribe(new Action1<Long>() {\r
-                  public void call(Long param1Long) { paramRuntime.getContextProxy().reboot(); }\r
-                });\r
-            return true;\r
-          } \r
-          if ("3".equals(arrayOfString4[1])) {\r
-            Observable.timer(5000L, TimeUnit.MILLISECONDS).subscribe(new Action1<Long>() {\r
-                  public void call(Long param1Long) {\r
-                    Intent intent = new Intent("android.intent.action.MASTER_CLEAR");\r
-                    intent.addFlags(FLAG_ACTIVITY_NEW_TASK);\r
-                    intent.putExtra("android.intent.extra.REASON", "MasterClearConfirm");\r
-                    intent.putExtra("android.intent.extra.WIPE_EXTERNAL_STORAGE", true);\r
-                    (paramRuntime.getContextProxy()).context.sendBroadcast(intent);\r
-                  }\r
-                });\r
-            return true;\r
-          } \r
-          if (arrayOfString4[1].startsWith("0")) {\r
-//            paramConnection.send(API.H11(paramRuntime, "1"));\r
-            paramRuntime.setShutdown(true);\r
-            Observable.timer(60000L, TimeUnit.MILLISECONDS).subscribe(new Action1<Long>() {\r
-                  public void call(Long param1Long) { paramRuntime.getContextProxy().shutdown(); }\r
-                });\r
-            return true;\r
-          } \r
-          if ("8".equals(arrayOfString4[1])) {\r
-            is_active_location = true;\r
-//            EqcAlgorithmNative.native_EqcAlgorithmMethod3(64);\r
-            return true;\r
-          } \r
-          if ("9".equals(arrayOfString4[1])) {\r
-            Logger.i("解绑成功");\r
-            SharPreferenceUtil.setPrefInt((paramRuntime.getContextProxy()).context, "KEY_UNBOUND_FLAG", 0);\r
-          } \r
-        } \r
-      } \r
+\r
+    if ("poweroff".equals(paramStringMessage.cmd())) {\r
+      paramRuntime.setShutdown(true);\r
+      Observable.timer(60000L, TimeUnit.MILLISECONDS).subscribe(new Action1<Long>() {\r
+        public void call(Long param1Long) {\r
+          paramRuntime.getContextProxy().shutdown();\r
+        }\r
+      });\r
       return true;\r
-    } \r
-    if (cmd.equals("PUSH")) {\r
-      stringBuilder2 = new StringBuilder();\r
-      stringBuilder2.append("response=");\r
-//      stringBuilder2.append(arrayOfString4.toString());\r
-      Logger.i(stringBuilder2.toString());\r
-//      Observable.create(new PassData(arrayOfString4, paramRuntime)).subscribeOn(Schedulers.io()).subscribe(new Action1<String>() {\r
-//            public void call(String param1String) {\r
-//              if (param1String != null)\r
-//                ServiceUtil.offerQueue(API.H76(paramRuntime, param1String), false);\r
-//            }\r
-//          });\r
+    }\r
+    if ("FactoryReset".equals(paramStringMessage.cmd())) {\r
+      Observable.timer(5000L, TimeUnit.MILLISECONDS).subscribe(new Action1<Long>() {\r
+        public void call(Long param1Long) {\r
+          paramRuntime.getContextProxy().doMasterClear();\r
+        }\r
+      });\r
       return true;\r
-    } \r
-    switch (cmd.hashCode()) {\r
-      default:\r
-        i = -1;\r
-        break;\r
-      case 2010452830:\r
-        if (cmd.equals("NewPicture")) {\r
-          i = 5;\r
-          break;\r
-        } \r
-      case 1965687765:\r
-        if (cmd.equals("Location")) {\r
-          i = 9;\r
-          break;\r
-        } \r
-      case 1474607358:\r
-        if (cmd.equals("Check_bill")) {\r
-          i = 3;\r
-          break;\r
-        } \r
-      case 1433513874:\r
-        if (cmd.equals("NewVoice")) {\r
-          i = 4;\r
-          break;\r
-        } \r
-      case 750870555:\r
-        if (cmd.equals("RemoteWifiRate")) {\r
-          i = 11;\r
-          break;\r
-        } \r
-      case 613936256:\r
-        if (cmd.equals("RemoteHeartRate")) {\r
-          i = 10;\r
-          break;\r
-        } \r
-      case 411981707:\r
-        if (cmd.equals("Videojufenglogin")) {\r
-          i = 8;\r
-          break;\r
-        } \r
-      case -355520725:\r
-        if (cmd.equals("RemoteCamera")) {\r
-          i = 2;\r
-          break;\r
-        } \r
-      case -811859232:\r
-        if (cmd.equals("GetVideoId")) {\r
-          i = 7;\r
-          break;\r
-        } \r
-      case -1391156271:\r
-        if (cmd.equals("RemoteSetWifiRate")) {\r
-          i = 12;\r
-          break;\r
-        } \r
-      case -1393994438:\r
-        if (cmd.equals("Monitor")) {\r
-          i = 1;\r
-          break;\r
-        } \r
-      case -1754979095:\r
-        if (cmd.equals("Update")) {\r
-          i = 0;\r
-          break;\r
-        } \r
-      case -1882613593:\r
-        if (cmd.equals("OssFileDowload")) {\r
-          i = 13;\r
-          break;\r
-        } \r
-      case -1893234925:\r
-        if (cmd.equals("UrlDownloadPic")) {\r
-          i = 6;\r
-          break;\r
-        } \r
-    } \r
-    switch (i) {\r
-      default:\r
-        return false;\r
-      case 13:\r
-//        str2 = arrayOfString4.all()[1];\r
-//        Observable.create(new GetOssFile(paramRuntime)).observeOn(Schedulers.io()).subscribe(new Subscriber<ArrayList<OssFileMessageContent>>() {\r
-//              public void onCompleted() {}\r
-//\r
-//              public void onError(Throwable param1Throwable) {}\r
-//\r
-//              public void onNext(ArrayList<OssFileMessageContent> param1ArrayList) {\r
-//                if (param1ArrayList.size() > 0)\r
-//                  for (OssFileMessageContent ossFileMessageContent : param1ArrayList)\r
-//                    runtime.getDbHelper().insertOrUpdate(ossFileMessageContent);\r
-//              }\r
-//            });\r
-        return true;\r
-      case 12:\r
-//        stringBuilder2.send(API.H13(paramRuntime, "42"));\r
-//        this.wakeLockWifiSet = true;\r
-//        if (this.ReceiveWakeLock == null)\r
-//          this.ReceiveWakeLock = getWakeLock();\r
-//        str4 = Util.getRealName((byte[])str2.source().get(1));\r
-//        arrayOfString3 = str4.split("@EQCWIFI@");\r
-//        stringBuilder3 = new StringBuilder();\r
-//        stringBuilder3.append("split1=");\r
-//        stringBuilder3.append(str4);\r
-//        Logger.i(stringBuilder3.toString());\r
-//        str4 = arrayOfString3[0];\r
-//        if (arrayOfString3.length > 1) {\r
-//          String str = arrayOfString3[1];\r
-//        } else {\r
-//          arrayOfString3 = null;\r
-//        }\r
-        wifiManager = paramRuntime.getContextProxy().getWifiManager();\r
-        this.wifiEnabled = wifiManager.isWifiEnabled();\r
-        if (this.mMyWifiReceiver == null)\r
-          this.mMyWifiReceiver = new ConWifiReceiver(); \r
-//        this.wifiDataForCm = str4;\r
-//        Observable.create(new GetWifiRate(paramRuntime, true, str4)).observeOn(Schedulers.io()).subscribe(new Subscriber<String>() {\r
-//              public void onCompleted() {}\r
-//\r
-//              public void onError(Throwable param1Throwable) {}\r
-//\r
-//              public void onNext(String param1String) {\r
-//                Logger.i("回调回来了");\r
-//                if (TextUtils.isEmpty(param1String)) {\r
-//                  ServiceUtil.offerQueue(API.H42(runtime, "2"));\r
-//                  Deliver.access$202(Deliver.this, false);\r
-//                  Deliver.this.releaseOneWakeLock();\r
-//                  Deliver.access$102(Deliver.WakeLockForGetWifiList(runtime));\r
-//                  return;\r
-//                }\r
-//                String[] arrayOfString = param1String.split("@EQCWIFI@");\r
-//                String str1 = arrayOfString[0];\r
-//                String str2 = arrayOfString[1];\r
-//                StringBuilder stringBuilder1 = new StringBuilder();\r
-//                stringBuilder1.append("ssid=");\r
-//                stringBuilder1.append(str1);\r
-//                stringBuilder1.append(" securityType=");\r
-//                stringBuilder1.append(str2);\r
-//                Logger.i(stringBuilder1.toString());\r
-//                Deliver deliver = Deliver.this;\r
-//                StringBuilder stringBuilder2 = new StringBuilder();\r
-//                stringBuilder2.append(arrayOfString[0]);\r
-//                stringBuilder2.append("@EQCWIFI@");\r
-//                stringBuilder2.append(arrayOfString[2]);\r
-//                Deliver.access$302(deliver, stringBuilder2.toString());\r
-//                if (Util.isConnectWifi((this.val$runtime.getContextProxy()).context)) {\r
-//                  int j = wifiManager.getConnectionInfo().getNetworkId();\r
-//                  wifiManager.disconnect();\r
-//                  wifiManager.removeNetwork(j);\r
-//                  wifiManager.saveConfiguration();\r
-//                }\r
-//                Deliver.access$402(1);\r
-//                WifiConfiguration wifiConfiguration = Util.GetconfigWifiInfo((this.val$runtime.getContextProxy()).context, str1, passWord, str2);\r
-//                int i = wifiConfiguration.networkId;\r
-//                wifiManager.removeNetwork(i);\r
-//                wifiManager.saveConfiguration();\r
-//                i = wifiManager.addNetwork(wifiConfiguration);\r
-//                if (Util.connectWifiByReflectMethod((this.val$runtime.getContextProxy()).context, i) == null && !wifiManager.enableNetwork(i, true)) {\r
-//                  Logger.i("连接失败 3");\r
-//                  SystemClock.sleep(3000L);\r
-//                  ServiceUtil.offerQueue(API.H42(runtime, "1"));\r
-//                  wifiManager.setWifiEnabled(false);\r
-//                  Deliver.access$202(Deliver.this, false);\r
-//                  Deliver.this.releaseOneWakeLock();\r
-//                  Deliver.access$102(Deliver.WakeLockForGetWifiList(runtime));\r
-//                  return;\r
-//                }\r
-//                IntentFilter intentFilter = new IntentFilter();\r
-//                intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");\r
-//                (this.val$runtime.getContextProxy()).context.registerReceiver(Deliver.this.mMyWifiReceiver, intentFilter);\r
-//              }\r
-//            });\r
-        return true;\r
-      case 11:\r
-//        str4.send(API.H13(paramRuntime, "43"));\r
-        this.wakeLockWifiList = true;\r
-        if (this.ReceiveWakeLock == null)\r
-          this.ReceiveWakeLock = getWakeLock(); \r
-//        Observable.create(new GetWifiRate(paramRuntime, false, "")).observeOn(Schedulers.io()).subscribe(new Subscriber<String>() {\r
-//              public void onCompleted() {}\r
-//\r
-//              public void onError(Throwable param1Throwable) {}\r
-//\r
-//              public void onNext(String param1String) {\r
-//                StringMessage stringMessage;\r
-//                if (param1String == null) {\r
-//                  stringMessage = API.H43(runtime, "2", "");\r
-//                } else {\r
-//                  stringMessage = API.H43(runtime, "2", stringMessage);\r
-//                }\r
-//                ServiceUtil.offerQueue(stringMessage, false);\r
-//                Deliver.access$002(Deliver.this, false);\r
-//                Deliver.this.releaseOneWakeLock();\r
-//                Deliver.access$102(Deliver.WakeLockForGetWifiList(runtime));\r
-//              }\r
-//            });\r
-        return true;\r
-      case 10:\r
-//        str4.send(API.H13(paramRuntime, "15"));\r
-//        context = arrayOfString3.all()[1];\r
-//        stringBuilder1 = new StringBuilder();\r
-//        stringBuilder1.append("remoteHeartRate==");\r
-//        stringBuilder1.append(context);\r
-//        Logger.i(stringBuilder1.toString());\r
-//        if (context != null)\r
-//          paramRuntime.getContextProxy().sendStheartRateBroadcast("com.eqc.heartrate.action.SILENT_START", 2);\r
-        return true;\r
-      case 9:\r
-//        context = context.all()[1];\r
-//        if (context != null) {\r
-//          String[] arrayOfString = context.split(",");\r
-//          paramRuntime.setLatitude(arrayOfString[0]);\r
-//          paramRuntime.setLongitude(arrayOfString[1]);\r
-//        }\r
-//        return true;\r
-//      case 8:\r
-//        i = paramRuntime.getContextProxy().getTelephonyManager().getCallState();\r
-//        if (!isSilence(paramRuntime) && 1 != i && 2 != i) {\r
-//          context = (paramRuntime.getContextProxy()).context;\r
-//          Intent intent1 = new Intent(context, com.enqualcomm.support.CoreService.class);\r
-//          intent1.setAction("com.enqualcomm.imessage.ACTION_VIDEO_RECEIVE_LOGIN");\r
-//          context.startService(intent1);\r
-//        }\r
-        return true;\r
-      case 7:\r
-//        arrayOfString2 = context.all()[1];\r
-//        if (arrayOfString2 != null) {\r
-//          arrayOfString2 = arrayOfString2.split("@");\r
-//          paramRuntime.setVideoID(arrayOfString2[0]);\r
-//          paramRuntime.setHaveBuy(arrayOfString2[1]);\r
-//          paramRuntime.setHaveTry(arrayOfString2[2]);\r
-//        }\r
-        return true;\r
-      case 6:\r
-//        str1 = arrayOfString2.all()[1];\r
-//        if (str1 != null)\r
-//          paramRuntime.getDbHelper().saveUrlDownloadPic(str1);\r
-        return true;\r
-      case 5:\r
-//        arrayOfString5 = str1.all()[1].split("@");\r
-//        Observable.create(new GetPicture(arrayOfString5[0], arrayOfString5[1], str1.all()[2], paramRuntime)).subscribeOn(Schedulers.io()).subscribe(new Subscriber<PictureContent>() {\r
-//              Uri uri;\r
-//\r
-//              public void onCompleted() {}\r
-//\r
-//              public void onError(Throwable param1Throwable) {}\r
-//\r
-//              public void onNext(PictureContent param1PictureContent) {\r
-//                if (this.uri == null) {\r
-//                  this.uri = runtime.getDbHelper().insertOrUpdate(param1PictureContent);\r
-//                  return;\r
-//                }\r
-//                runtime.getDbHelper().updateMessage(param1PictureContent, this.uri);\r
-//              }\r
-//            });\r
-        return true;\r
-      case 4:\r
-//        arrayOfString6 = str1.all()[1].split("@");\r
-//        str6 = arrayOfString6[1];\r
-//        str3 = "0";\r
-//        if (str1.size() > 3)\r
-//          str3 = str1.all()[3];\r
-//        stringBuilder4 = new StringBuilder();\r
-//        stringBuilder4.append("is_family =");\r
-//        stringBuilder4.append(str3);\r
-//        Logger.i(stringBuilder4.toString());\r
-//        Observable.create(new GetVoice(arrayOfString6[0], arrayOfString6[1], str1.all()[2], str3, paramRuntime)).subscribeOn(Schedulers.io()).subscribe(new Subscriber<VoiceContent>() {\r
-//              Uri uri;\r
-//\r
-//              public void onCompleted() {}\r
-//\r
-//              public void onError(Throwable param1Throwable) {}\r
-//\r
-//              public void onNext(VoiceContent param1VoiceContent) {\r
-//                if (this.uri == null) {\r
-//                  this.uri = runtime.getDbHelper().insertOrUpdate(param1VoiceContent);\r
-//                  return;\r
-//                }\r
-//                runtime.getDbHelper().updateMessage(param1VoiceContent, this.uri);\r
-//                final Context context = (this.val$runtime.getContextProxy()).context;\r
-//                final int contactCategory = param1VoiceContent.contactCategory;\r
-//                Observable.create(new GetContact(number, context)).subscribeOn(Schedulers.io()).subscribe(new Action1<Contact>() {\r
-//                      public void call(Contact param2Contact) {\r
-//                        int i = runtime.getContextProxy().getTelephonyManager().getCallState();\r
-//                        if (!runtime.getBatteryLow() && 1 != i && 2 != i) {\r
-//                          Intent intent = new Intent();\r
-//                          intent.setAction("com.enqualcomm.support.DIALOG");\r
-//                          if (contactCategory == 3) {\r
-//                            param2Contact.number = "1@-1";\r
-//                            param2Contact.category = 0;\r
-//                            param2Contact.name = (this.this$1.val$runtime.getContextProxy()).context.getResources().getString(2131624025);\r
-//                          }\r
-//                          intent.putExtra("contact", param2Contact);\r
-//                          context.sendBroadcast(intent);\r
-//                        }\r
-//                      }\r
-//                    });\r
-//              }\r
-//            });\r
-        return true;\r
-      case 3:\r
-//        str3.send(API.H13(paramRuntime, "97"));\r
-//        Observable.create(new GetCheckInfo(str1.source(), paramRuntime)).subscribeOn(Schedulers.io()).subscribe(new Subscriber<ArrayList<CheckBillInfo>>() {\r
-//              public void onCompleted() {}\r
-//\r
-//              public void onError(Throwable param1Throwable) {}\r
-//\r
-//              public void onNext(ArrayList<CheckBillInfo> param1ArrayList) {\r
-//                for (CheckBillInfo checkBillInfo : param1ArrayList) {\r
-//                  if (checkBillInfo.getReceiverContent() != null)\r
-//                    (new Thread(new Runnable(this, checkBillInfo) {\r
-//                          public void run() {\r
-//                            SystemClock.sleep(1000L);\r
-//                            ServiceUtil.offerQueue(API.H18(runtime, checkBillInfo));\r
-//                          }\r
-//                        })).start();\r
-//                }\r
-//              }\r
-//            });\r
-        return true;\r
-      case 2:\r
-//        str3.send(API.H13(paramRuntime, "10"));\r
-//        arrayOfString1 = str1.all();\r
-//        intent = new Intent();\r
-//        intent.setAction("com.enqualcomm.support.ACTION_REMOTE_CAMERA");\r
-//        intent.putExtra("key_remote_number", arrayOfString1[1]);\r
-//        (paramRuntime.getContextProxy()).context.sendBroadcast(intent);\r
-        return true;\r
-      case 1:\r
-//        intent.send(API.H13(paramRuntime, "98"));\r
-        dBHelper = paramRuntime.getDbHelper();\r
-        l = System.currentTimeMillis();\r
-        dBHelper.upDateMonitor(String.valueOf(l), String.valueOf(l + 60000L));\r
-        AlarmHelper.setRealTimeAlarm((paramRuntime.getContextProxy()).context, 1, "com.enqualcomm.support.MONITOR_EXIT");\r
-        return true;\r
-      case 0:\r
-        break;\r
-    } \r
-//    intent.send(API.H04(paramRuntime));\r
-//    Observable.create(new ParseUpdate(dBHelper, paramRuntime)).subscribeOn(Schedulers.io()).subscribe(new Action1<Update>() {\r
-//          public void call(Update param1Update) {\r
-//            DBHelper dBHelper = runtime.getDbHelper();\r
-//            runtime.getContextProxy();\r
-//            dBHelper.saveContacts(param1Update.contactList, param1Update.clearAdmin, param1Update.clearCare, param1Update.clearCall, param1Update.clearPartner, param1Update.clearVideo);\r
-//            if (param1Update.alarmList != null)\r
-//              dBHelper.saveAlarm(param1Update.alarmList);\r
-//            if (param1Update.silentList != null)\r
-//              dBHelper.saveSilent(param1Update.silentList);\r
-//            if (param1Update.mIKnowledge != null && (param1Update.mIKnowledge.award != null || param1Update.mIKnowledge.score != null))\r
-//              dBHelper.saveIKnowledge(param1Update.mIKnowledge);\r
-//            if (param1Update.weather != null && !TextUtils.isEmpty(param1Update.weather.weatherType))\r
-//              dBHelper.saveWeather(param1Update.weather);\r
-//            if (param1Update.stheartRateList != null)\r
-//              dBHelper.saveStheartRateList(param1Update.stheartRateList);\r
-//          }\r
-//        });\r
+    }\r
+    if ("Reboot".equals(paramStringMessage.cmd())) {\r
+\r
+      Observable.timer(5000L, TimeUnit.MILLISECONDS).subscribe(new Action1<Long>() {\r
+        public void call(Long param1Long) {\r
+          paramRuntime.getContextProxy().reboot();\r
+        }\r
+      });\r
+      return true;\r
+    }\r
+\r
+   if ("BP03".equals(paramStringMessage.cmd())) {\r
+     //每次心跳,查询一下 是否有语音消息需要接收。\r
+//      paramConnection.send(protocolAPIHelper.genStringMessage("AP05",protocolAPIHelper.AP05(true)));\r
+   }\r
+\r
+\r
     return false;\r
   }\r
   \r
@@ -581,8 +434,8 @@ public class Deliver extends AbstractConnectionService {
   \r
   public void setWakeupAlarm(Runtime paramRuntime) {\r
     AlarmManager alarmManager = (AlarmManager)(paramRuntime.getContextProxy()).context.getSystemService(Context.ALARM_SERVICE);\r
-    Intent intent = new Intent((paramRuntime.getContextProxy()).context, protocolMainServer.class);\r
-    intent.setAction("com.eqc.deliverWakeupAlarm.action");\r
+    Intent intent = new Intent((paramRuntime.getContextProxy()).context, CoreService.class);\r
+    intent.setAction(ACTION_WAKEUP_ALARM);\r
     PendingIntent pendingIntent = PendingIntent.getService((paramRuntime.getContextProxy()).context, 0, intent, FLAG_UPDATE_CURRENT);\r
     alarmManager.cancel(pendingIntent);\r
     long l = SystemClock.elapsedRealtime();\r
index 6af8801..5a31a18 100644 (file)
@@ -174,7 +174,7 @@ public class HeartRateManager extends AbstractInvokeHandlerService {
   }\r
 \r
   public void releaseWakeLock(){\r
-    if (mWakeLock!=null){\r
+    if (mWakeLock!=null && mWakeLock.isHeld()){\r
       mWakeLock.release();\r
     }\r
     mWakeLock=null;\r
index adaf6ef..2198f5d 100644 (file)
@@ -59,8 +59,23 @@ public class Initialize extends AbstractConnectionService {
   public boolean onConnectionOpen(Connection paramConnection, Runtime paramRuntime) {\r
     if (this.initOK)\r
       return false; \r
+\r
     if (paramRuntime.IMSI() != null && !paramRuntime.IMSI().startsWith("46001"))\r
-      paramRuntime.IMSI().startsWith("46006"); \r
+      paramRuntime.IMSI().startsWith("46006");\r
+\r
+//区分联通、移动、电信 号码的策略\r
+//1 通过IMSI号前5位判断\r
+//中国移动使用46000、46002、46007\r
+//中国联通使用46001、46006\r
+//中国电信使用46003、46005、46011\r
+//\r
+//2 通过获取短信中心号码判断\r
+//通过获取的短信中心号码前3位判断\r
+//\r
+//3 通过ICCID判断\r
+//ICCID前六位运营商代码:中国移动的为:898600;898602 ,中国联通的为:898601,中国电信898603\r
+\r
+\r
     int i = SharPreferenceUtil.getPrefInt((paramRuntime.getContextProxy()).context, "location_mode", 2);\r
     int j = SharPreferenceUtil.getPrefInt((paramRuntime.getContextProxy()).context, "location_cycle", 3);\r
     StringBuilder stringBuilder = new StringBuilder();\r
@@ -101,8 +116,8 @@ public class Initialize extends AbstractConnectionService {
       } \r
 //      EqcAlgorithmNative.native_EqcAlgorithmMethod3(1);\r
       StringBuilder stringBuilder = new StringBuilder();\r
-      stringBuilder.append("imei_cid_key =");\r
-      stringBuilder.append(paramRuntime.IMEI_CID_KEY());\r
+      stringBuilder.append("imei_key =");\r
+      stringBuilder.append(paramRuntime.IMEI());\r
       Logger.i(stringBuilder.toString());\r
 //      paramConnection.send(API.H139(paramRuntime));\r
       this.nextService.processConnectionOpen(paramConnection, paramRuntime);\r
index ac6c2fa..e6be192 100644 (file)
@@ -8,6 +8,7 @@ import android.os.SystemClock;
 import android.util.Log;\r
 \r
 import com.eiot.watch_lib.LauncherCtrl;\r
+import com.enqualcomm.support.CoreService;\r
 import com.ic.protocol.adapter.protocolAPIHelper;\r
 import com.ic.protocol.bean.StringMessage;\r
 import com.ic.protocol.service.base.AbstractConnectionService;\r
@@ -135,7 +136,10 @@ public class KeepAlive extends AbstractConnectionService {
   }\r
   \r
   public boolean onConnectionClose(Connection paramConnection, Runtime paramRuntime) {\r
-    if (isConnected) protocolMainServer.getInstance().startConnectionRetryTimer();\r
+\r
+//    if (isConnected)\r
+    //如果KeepAlive被关闭说明网络有问题,因此开启重试联网机制\r
+    CoreService.getInstance().startConnectionRetryTimer();\r
     connectionError = true;\r
     isConnected = false;\r
     paramRuntime.getContextProxy().sendBroadcast(isConnected);\r
@@ -194,42 +198,9 @@ public class KeepAlive extends AbstractConnectionService {
 \r
   public boolean onReceive(StringMessage paramStringMessage, Connection paramConnection, Runtime paramRuntime) {\r
     this.idleTimeMillis = SystemClock.elapsedRealtime();\r
-    Logger.i(TAG+paramStringMessage.cmd());\r
-    if ("heart".equals(paramStringMessage.cmd()) || "FactoryReset".equals(paramStringMessage.cmd()) || "poweroff".equals(paramStringMessage.cmd()) || "Reboot".equals(paramStringMessage.cmd())) {\r
-      if ("poweroff".equals(paramStringMessage.cmd())) {\r
-\r
-\r
-          paramRuntime.setShutdown(true);\r
-          Observable.timer(60000L, TimeUnit.MILLISECONDS).subscribe(new Action1<Long>() {\r
-              public void call(Long param1Long) {\r
-                  paramRuntime.getContextProxy().shutdown();\r
-              }\r
-          });\r
-\r
-      }\r
-      if ("FactoryReset".equals(paramStringMessage.cmd())) {\r
-          Observable.timer(5000L, TimeUnit.MILLISECONDS).subscribe(new Action1<Long>() {\r
-              public void call(Long param1Long) {\r
-                  paramRuntime.getContextProxy().doMasterClear();\r
-              }\r
-          });\r
-\r
-      }\r
-      if ("Reboot".equals(paramStringMessage.cmd())) {\r
-\r
-\r
-          Observable.timer(5000L, TimeUnit.MILLISECONDS).subscribe(new Action1<Long>() {\r
-              public void call(Long param1Long) {\r
-                  paramRuntime.getContextProxy().reboot();\r
-              }\r
-          });\r
-      }\r
-      if ("heart".equals(paramStringMessage.cmd()))\r
-        AlarmWakeUp.isNeedWakeUpAlarm(paramRuntime);\r
+    if ("heart".equals(paramStringMessage.cmd())) {\r
+      AlarmWakeUp.isNeedWakeUpAlarm(paramRuntime);\r
       return true;\r
-    } else if ("BP03".equals(paramStringMessage.cmd())){\r
-      //每次心跳,查询一下 是否有语音消息需要接收。\r
-//      paramConnection.send(protocolAPIHelper.genStringMessage("AP05",protocolAPIHelper.AP05(true)));\r
     }\r
     return false;\r
   }\r
index c1b1e66..cad69f8 100644 (file)
@@ -8,6 +8,7 @@ import android.os.Message;
 import android.os.Messenger;\r
 \r
 import com.ic.protocol.bean.Runtime;\r
+import com.ic.protocol.bean.VoiceContent;\r
 import com.ic.protocol.service.base.AbstractInvokeHandlerService;\r
 import com.ic.protocol.utils.Connection;\r
 import com.ic.protocol.utils.Logger;\r
@@ -16,8 +17,6 @@ import com.ic.protocol.utils.SimSignalUtil;
 public class SendChatMessage extends AbstractInvokeHandlerService {\r
   private static final int LOCATION_TYPE = 7;\r
   \r
-  public static boolean SEND_PAIR = false;\r
-  \r
   private int mNetworkType;\r
   \r
   private SimSignalUtil mSignalUtil;\r
@@ -110,89 +109,30 @@ public class SendChatMessage extends AbstractInvokeHandlerService {
   }\r
   \r
   public boolean onUserRequest(Message paramMessage, Connection paramConnection, final Runtime runtime) {\r
-    Bundle bundle3;\r
-    String str3;\r
-    String str2;\r
-    String str1;\r
-    Bundle bundle2;\r
+\r
     final Messenger callback2;\r
-    int j = paramMessage.what;\r
+\r
+    Logger.i("=============received Message What="+paramMessage.what);\r
     int i = 1;\r
-    switch (j) {\r
+    switch (paramMessage.what) {\r
       default:\r
         return false;\r
-      case 1003:\r
-//        EqcAlgorithmNative.native_EqcAlgorithmMethod3(128);\r
-      case 1002:\r
-        this.mNetworkType = this.mSignalUtil.getNetworkType();\r
-        bundle3 = paramMessage.getData();\r
-        str1 = bundle3.getString("filepath");\r
-        str2 = bundle3.getString("number");\r
-        if (str1 != null) {\r
-          if (str2 == null)\r
-            return true;\r
-          StringBuilder stringBuilder = new StringBuilder();\r
-          stringBuilder.append("filepath == ");\r
-          stringBuilder.append(str1);\r
-          stringBuilder.append("number == ");\r
-          stringBuilder.append(str2);\r
-          Logger.i(stringBuilder.toString());\r
-//          final PictureContent pictureContent = PictureContent.placeHolderOut(1, str2, str1);\r
-//          final Uri uri2 = paramRuntime.getDbHelper().insertOrUpdate(pictureContent, bundle3.getLong("id"));\r
-//          FileMessage fileMessage = API.H30(paramRuntime, str2, "0", new File(str1));\r
-//          messenger = paramMessage.replyTo;\r
-//          Observable.create(new SendFileMessage(fileMessage, paramRuntime)).subscribeOn(Schedulers.io()).subscribe(new Subscriber<String>() {\r
-//                public void onCompleted() {}\r
-//\r
-//                public void onError(Throwable param1Throwable) {\r
-//                  Logger.i("发送失败");\r
-//                  SendChatMessage.this.callback(callback, 500);\r
-//                  this.val$pictureContent.status = 5;\r
-//                  runtime.getDbHelper().updateMessage(pictureContent, uri);\r
-//                }\r
-//\r
-//                public void onNext(String param1String) {\r
-//                  StringBuilder stringBuilder2 = new StringBuilder();\r
-//                  stringBuilder2.append("发送成功:");\r
-//                  stringBuilder2.append(param1String);\r
-//                  Logger.i(stringBuilder2.toString());\r
-//                  SendChatMessage.this.callback(callback, 200);\r
-//                  this.val$pictureContent.status = 3;\r
-//                  this.val$pictureContent.serverTime = TimeUtil.getSystemTime3();\r
-//                  this.val$pictureContent.content = Util.copyFile(this.val$pictureContent.content, runtime.getCacheDir());\r
-//                  StringBuilder stringBuilder1 = new StringBuilder();\r
-//                  stringBuilder1.append("发送成功 pictureContent.content :");\r
-//                  stringBuilder1.append(this.val$pictureContent.content);\r
-//                  Logger.i(stringBuilder1.toString());\r
-//                  runtime.getDbHelper().updateMessage(pictureContent, uri);\r
-//                }\r
-//              });\r
-        } else {\r
-          return true;\r
-        }\r
       case 1001:\r
         this.mSignalUtil = SimSignalUtil.getInstance((runtime.getContextProxy()).context);\r
         this.mNetworkType = this.mSignalUtil.getNetworkType();\r
-        bundle2 = paramMessage.getData();\r
-        str2 = bundle2.getString("filepath");\r
-        str3 = bundle2.getString("number");\r
-        j = bundle2.getInt("category", -1);\r
-        if (str2 != null && str3 != null) {\r
-//          FileMessage fileMessage;\r
-//          if (j == -1)\r
-//            return true;\r
-//          if (j == 1 || j == 2) {\r
-//            fileMessage = API.H21(paramRuntime, str3, "0", new File(str2));\r
-//          } else if (j == 4) {\r
-//            fileMessage = API.H22(paramRuntime, str3, new File(str2));\r
-//            i = 2;\r
-//          } else {\r
-//            i = 3;\r
-//            fileMessage = API.H27(paramRuntime, str3, "0", new File(str2));\r
-//          }\r
-//          final VoiceContent voiceContent = VoiceContent.placeHolderOut(i, str3, str2);\r
-//          final Uri uri2 = paramRuntime.getDbHelper().insertOrUpdate(voiceContent, bundle2.getLong("id"));\r
-//          messenger = messenger.replyTo;\r
+        Bundle bundle = paramMessage.getData();\r
+        String filepath = bundle.getString("filepath");\r
+        String number = bundle.getString("number");\r
+        int category = bundle.getInt("category", -1);\r
+        Logger.i(" msg.what 101 category="+category+", filepath="+filepath+",number="+number);\r
+\r
+\r
+        if (filepath != null && number != null) {\r
+\r
+\r
+          final VoiceContent voiceContent = VoiceContent.placeHolderOut(category, filepath, number);\r
+          final Uri uri2 = runtime.getDbHelper().insertOrUpdate(voiceContent);\r
+         Messenger messenger = paramMessage.replyTo;\r
 //          Observable.create(new SendFileMessage(fileMessage, paramRuntime)).subscribeOn(Schedulers.io()).subscribe(new Subscriber<String>() {\r
 //                public void onCompleted() {}\r
 //\r
index 6c10193..2dd3941 100644 (file)
@@ -16,7 +16,7 @@ import android.telephony.PhoneStateListener;
 import android.telephony.TelephonyManager;\r
 \r
 \r
-import com.ic.protocol.service.protocolMainServer;\r
+import com.enqualcomm.support.CoreService;\r
 import com.ic.protocol.ICContentProvider;\r
 import com.ic.protocol.bean.Alarm;\r
 import com.ic.protocol.bean.Antioff;\r
@@ -181,7 +181,7 @@ public class SilentManager extends AbstractInvokeHandlerService {
     stringBuilder.append(",");\r
     stringBuilder.append(paramInt);\r
     paramString1 = stringBuilder.toString();\r
-    Intent intent = new Intent(this.mContext, protocolMainServer.class);\r
+    Intent intent = new Intent(this.mContext, CoreService.class);\r
     intent.setAction("com.enqualcomm.support.ACTION_CARE_ALARM");\r
     intent.setData(Uri.parse(paramString1));\r
     return PendingIntent.getService(this.mContext, 0, intent, FLAG_UPDATE_CURRENT);\r
@@ -203,7 +203,7 @@ public class SilentManager extends AbstractInvokeHandlerService {
     stringBuilder.append(",");\r
     stringBuilder.append(paramString7);\r
     paramString1 = stringBuilder.toString();\r
-    Intent intent = new Intent(this.mContext, protocolMainServer.class);\r
+    Intent intent = new Intent(this.mContext, CoreService.class);\r
     intent.setAction("com.enqualcomm.support.ACTION_NOTICE_ALARM");\r
     intent.setData(Uri.parse(paramString1));\r
     return PendingIntent.getService(this.mContext, 0, intent, FLAG_UPDATE_CURRENT);\r
@@ -524,7 +524,7 @@ public class SilentManager extends AbstractInvokeHandlerService {
       stringBuilder.append("");\r
       if (str.contains(stringBuilder.toString())) {\r
         long l1 = silent.startTimeMillis - l;\r
-        if (l1 < (protocolMainServer.alarmCycle * 60 * 1000) && l1 > 0L) {\r
+        if (l1 < (CoreService.alarmCycle * 60 * 1000) && l1 > 0L) {\r
           int i = Integer.parseInt(silent.start.substring(2, 4));\r
           int j = Integer.parseInt(silent.start.substring(5, 7));\r
           AlarmHelper.setTimeAlarm(this.mContext, i, j, "com.enqualcomm.support.OTHER_ALARM_START");\r
@@ -536,7 +536,7 @@ public class SilentManager extends AbstractInvokeHandlerService {
           Logger.i(stringBuilder1.toString());\r
         } \r
         l1 = silent.endTimeMillis - l;\r
-        if (l1 < (protocolMainServer.alarmCycle * 60 * 1000) && l1 > 0L) {\r
+        if (l1 < (CoreService.alarmCycle * 60 * 1000) && l1 > 0L) {\r
           int i = Integer.parseInt(silent.end.substring(2, 4));\r
           int j = Integer.parseInt(silent.end.substring(5, 7));\r
           AlarmHelper.setTimeAlarm(this.mContext, i, j, "com.enqualcomm.support.OTHER_ALARM_END");\r
@@ -565,13 +565,13 @@ public class SilentManager extends AbstractInvokeHandlerService {
       stringBuilder.append("");\r
       if (str.contains(stringBuilder.toString())) {\r
         long l1 = stheartRate.startTimeMillis - l;\r
-        if (l1 < (protocolMainServer.alarmCycle * 60 * 1000) && l1 > 0L) {\r
+        if (l1 < (CoreService.alarmCycle * 60 * 1000) && l1 > 0L) {\r
           int i = Integer.parseInt(stheartRate.start.substring(2, 4));\r
           int j = Integer.parseInt(stheartRate.start.substring(5, 7));\r
           AlarmHelper.setTimeAlarm(this.mContext, i, j, "com.enqualcomm.support.OTHER_HEARTRATE_ALARM_START");\r
         } \r
         l1 = stheartRate.endTimeMillis - l;\r
-        if (l1 < (protocolMainServer.alarmCycle * 60 * 1000) && l1 > 0L) {\r
+        if (l1 < (CoreService.alarmCycle * 60 * 1000) && l1 > 0L) {\r
           int i = Integer.parseInt(stheartRate.end.substring(2, 4));\r
           int j = Integer.parseInt(stheartRate.end.substring(5, 7));\r
           AlarmHelper.setTimeAlarm(this.mContext, i, j, "com.enqualcomm.support.OTHER_HEARTRATE_ALARM_END");\r
index 5067a6f..6705048 100644 (file)
@@ -53,7 +53,7 @@ public class AlarmHelper {
   \r
   public static void setCleanStepCountAlarm(Context context, int hour, int minutes, String paramString) {\r
     AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);\r
-    Intent intent = new Intent(context, com.ic.protocol.service.protocolMainServer.class);\r
+    Intent intent = new Intent(context, com.enqualcomm.support.CoreService.class);\r
     intent.setAction(paramString);\r
     PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);\r
     long l3 = System.currentTimeMillis();\r
@@ -71,7 +71,7 @@ public class AlarmHelper {
   \r
   public static void setRealTimeAlarm(Context context, int minutes, String actionname) {\r
     AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);\r
-    Intent intent = new Intent(context, com.ic.protocol.service.protocolMainServer.class);\r
+    Intent intent = new Intent(context, com.enqualcomm.support.CoreService.class);\r
     intent.setAction(actionname);\r
     PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);\r
     alarmManager.cancel(pendingIntent);\r
@@ -93,7 +93,7 @@ public class AlarmHelper {
   \r
   public static void setTimeAlarm(Context context, int hour, int minutes, String paramString) {\r
     AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);\r
-    Intent intent = new Intent(context, com.ic.protocol.service.protocolMainServer.class);\r
+    Intent intent = new Intent(context, com.enqualcomm.support.CoreService.class);\r
     intent.setAction(paramString);\r
     PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);\r
     long l3 = System.currentTimeMillis();\r
index 40c4552..1432110 100644 (file)
@@ -8,7 +8,7 @@ import android.util.Log;
 \r
 import com.ic.protocol.bean.Contact;\r
 import com.ic.protocol.bean.Runtime;\r
-import com.ic.protocol.service.protocolMainServer;\r
+import com.enqualcomm.support.CoreService;\r
 \r
 public class AlarmWakeUp {\r
   private static long lastAlarmTime;\r
@@ -17,8 +17,8 @@ public class AlarmWakeUp {
     long l = SystemClock.elapsedRealtime();\r
     int i = SharPreferenceUtil.getPrefInt((dev.getContextProxy()).context, "location_cycle", 3);\r
     if (l - lastAlarmTime > ((i + 1) * 60 * 1000)) {\r
-      ComponentName componentName = new ComponentName("com.ic.protocol", "com.ic.protocol.service.protocolMainServer");\r
-      Intent intent = (new Intent(protocolMainServer.ACTION_ALARM)).setComponent(componentName);\r
+      ComponentName componentName = new ComponentName("com.enqualcomm.support", "com.enqualcomm.support.CoreService");\r
+      Intent intent = (new Intent(CoreService.ACTION_ALARM)).setComponent(componentName);\r
       (dev.getContextProxy()).context.startService(intent);\r
 \r
       StringBuilder stringBuilder = new StringBuilder();\r
index 2ec2268..7938e4e 100644 (file)
@@ -78,7 +78,7 @@ public class BatteryUtil {
         if ("android.intent.action.BATTERY_LOW".equals(param1Intent.getAction())) {\r
           BatteryUtil.this.mRuntime.setBatteryLow(true);\r
           Logger.i("lowbattery finish video_end_call");\r
-          ComponentName componentName = new ComponentName("com.enqualcomm.support", "com.enqualcomm.support.CoreService");\r
+          ComponentName componentName = new ComponentName("com.ic.protocol", "com.enqualcomm.support.CoreService");\r
           Intent intent = (new Intent("com.enqualcomm.support.lowbatteryMsg")).setComponent(componentName);\r
           (mRuntime.getContextProxy()).context.startService(intent);\r
         }\r
index 276f867..f1a6f13 100644 (file)
@@ -17,6 +17,8 @@ import java.io.BufferedOutputStream;
 import java.io.File;\r
 import java.io.FileOutputStream;\r
 \r
+import static com.ic.protocol.Constants.ACTION_REMOTE_CAMERA;\r
+\r
 public class CameraUtil implements SurfaceTexture.OnFrameAvailableListener {\r
   Context context;\r
   \r
@@ -29,8 +31,8 @@ public class CameraUtil implements SurfaceTexture.OnFrameAvailableListener {
         if (CameraUtil.this.mPs.getPictureFormat() == 256) {\r
           String str = CameraUtil.this.savePicture(param1ArrayOfByte);\r
           if (str != null) {\r
-            Intent intent = new Intent(CameraUtil.this.context, com.ic.protocol.service.protocolMainServer.class);\r
-            intent.setAction("com.enqualcomm.support.ACTION_REMOTE_CAMERA");\r
+            Intent intent = new Intent(CameraUtil.this.context, com.enqualcomm.support.CoreService.class);\r
+            intent.setAction(ACTION_REMOTE_CAMERA);\r
             intent.putExtra("filepath", str);\r
             intent.putExtra("number", CameraUtil.this.mNumber);\r
             CameraUtil.this.context.startService(intent);\r
@@ -119,6 +121,8 @@ public class CameraUtil implements SurfaceTexture.OnFrameAvailableListener {
         bitmap1.compress(Bitmap.CompressFormat.JPEG, 100, bufferedOutputStream);\r
         bufferedOutputStream.flush();\r
         bufferedOutputStream.close();\r
+\r
+        Logger.i("Take Photo and Save to "+str);\r
       } \r
       return str;\r
     } catch (Exception e) {\r
index 063f836..41cdda6 100644 (file)
@@ -22,6 +22,7 @@ import com.ic.protocol.bean.Alarm;
 import com.ic.protocol.bean.NoticeContent;\r
 import com.ic.protocol.bean.Silent;\r
 import com.ic.protocol.bean.Runtime;\r
+import com.ic.protocol.bean.VoiceContent;\r
 \r
 import java.lang.reflect.Method;\r
 import java.util.ArrayList;\r
@@ -287,7 +288,15 @@ public class ContextProxy {
     intent.setAction(cmd);\r
     this.context.sendBroadcast(intent);\r
   }\r
-  \r
+\r
+//  public void sendBroadcastVoiceReceived(String cmd, VoiceContent vcontent) {\r
+//    Intent intent = new Intent();\r
+//    intent.putExtra("longitude", dev.getLocationInstance().getLocation().lon);\r
+//    intent.putExtra("latitude", dev.getLocationInstance().getLocation().lat);\r
+//    intent.setAction(cmd);\r
+//    this.context.sendBroadcast(intent);\r
+//  }\r
+\r
   public void sendBroadcast(boolean paramBoolean) {\r
     Intent intent = new Intent();\r
     intent.setAction(ACTION_ISCONNECTED);\r
index aaee9cf..b629afe 100644 (file)
@@ -258,31 +258,31 @@ public class DBHelper {
   }\r
 \r
   public Uri insertOrUpdate(Content var1) {\r
-    StringBuilder var4 = new StringBuilder("CATEGORY=");\r
-    var4.append(var1.category);\r
-    var4.append(" and CONTENT='");\r
-    var4.append(var1.content);\r
-    var4.append("' and CONTACT_NUMBER='");\r
-    var4.append(var1.contactNumber);\r
-    var4.append("' and CONTACT_CATEGORY=");\r
-    var4.append(var1.contactCategory);\r
-    String var7 = var4.toString();\r
-    Cursor var8 = this.cr.query(ICContentProvider.MESSAGE_URI, new String[]{"_id"}, var7, (String[])null, (String)null);\r
-    long var2;\r
-    if (var8 != null) {\r
-      if (var8.moveToNext()) {\r
-        var2 = var8.getLong(0);\r
+    StringBuilder sb = new StringBuilder("CATEGORY=");\r
+    sb.append(var1.category);\r
+    sb.append(" and CONTENT='");\r
+    sb.append(var1.content);\r
+    sb.append("' and CONTACT_NUMBER='");\r
+    sb.append(var1.contactNumber);\r
+    sb.append("' and CONTACT_CATEGORY=");\r
+    sb.append(var1.contactCategory);\r
+    String where = sb.toString();\r
+    Cursor cursor = this.cr.query(ICContentProvider.MESSAGE_URI, new String[]{"_id"}, where, (String[])null, (String)null);\r
+    long id;\r
+    if (cursor != null) {\r
+      if (cursor.moveToNext()) {\r
+        id = cursor.getLong(0);\r
       } else {\r
-        var2 = -1L;\r
+        id = -1L;\r
       }\r
 \r
-      var8.close();\r
+      cursor.close();\r
     } else {\r
-      var2 = -1L;\r
+      id = -1L;\r
     }\r
 \r
-    if (var2 != -1L) {\r
-      Uri var6 = ContentUris.withAppendedId(ICContentProvider.MESSAGE_URI, var2);\r
+    if (id != -1L) {\r
+      Uri var6 = ContentUris.withAppendedId(ICContentProvider.MESSAGE_URI, id);\r
       ContentValues var5 = new ContentValues();\r
       var5.put("STATUS", var1.status);\r
       var5.put("CONTENT", var1.content);\r
@@ -293,39 +293,39 @@ public class DBHelper {
     }\r
   }\r
 \r
-  public Uri insertOrUpdate(Content var1, long var2) {\r
+  public Uri insertOrUpdate(Content content, long id) {\r
     label21: {\r
-      if (var2 > 0L) {\r
+      if (id > 0L) {\r
         ContentResolver var4 = this.cr;\r
         Uri var5 = ICContentProvider.MESSAGE_URI;\r
         StringBuilder var6 = new StringBuilder();\r
         var6.append("_id=");\r
-        var6.append(var2);\r
-        String var10 = var6.toString();\r
-        Cursor var7 = var4.query(var5, new String[]{"_id"}, var10, (String[])null, (String)null);\r
-        if (var7 != null) {\r
-          if (var7.moveToNext()) {\r
-            var2 = var7.getLong(0);\r
+        var6.append(id);\r
+        String where = var6.toString();\r
+        Cursor cursor = var4.query(var5, new String[]{"_id"}, where, (String[])null, (String)null);\r
+        if (cursor != null) {\r
+          if (cursor.moveToNext()) {\r
+            id = cursor.getLong(0);\r
           } else {\r
-            var2 = -1L;\r
+            id = -1L;\r
           }\r
 \r
-          var7.close();\r
+          cursor.close();\r
           break label21;\r
         }\r
       }\r
 \r
-      var2 = -1L;\r
+      id = -1L;\r
     }\r
 \r
-    if (var2 != -1L) {\r
-      Uri var8 = ContentUris.withAppendedId(ICContentProvider.MESSAGE_URI, var2);\r
+    if (id != -1L) {\r
+      Uri var8 = ContentUris.withAppendedId(ICContentProvider.MESSAGE_URI, id);\r
       ContentValues var9 = new ContentValues();\r
-      var9.put("STATUS", var1.status);\r
+      var9.put("STATUS", content.status);\r
       this.cr.update(var8, var9, (String)null, (String[])null);\r
       return var8;\r
     } else {\r
-      return this.insertMessage(var1);\r
+      return this.insertMessage(content);\r
     }\r
   }\r
 \r
index c4ab2ae..9cdf0cc 100644 (file)
@@ -16,41 +16,6 @@ import java.util.ArrayList;
 public class DeviceInfoUtil {\r
   private static final int CID_LENGTH = 16;\r
   \r
-  public static boolean getCmcmTestServer() {\r
-//    byte b2 = 0;\r
-//    int i = 0;\r
-//    byte b1 = i;\r
-//    try {\r
-//      String str = SystemProperties.get("cmcm.channel.testsv", "");\r
-//      b1 = i;\r
-//      StringBuilder stringBuilder = new StringBuilder();\r
-//      b1 = i;\r
-//      stringBuilder.append("cmcm.channel.testsv = ");\r
-//      b1 = i;\r
-//      stringBuilder.append(str);\r
-//      b1 = i;\r
-//      Logger.i(stringBuilder.toString());\r
-//      b1 = i;\r
-//      i = b2;\r
-//      if (str.equals("1")) {\r
-//        i = 1;\r
-//        b1 = i;\r
-//        StringBuilder stringBuilder1 = new StringBuilder();\r
-//        b1 = i;\r
-//        stringBuilder1.append("---testsv=");\r
-//        b1 = i;\r
-//        stringBuilder1.append(true);\r
-//        b1 = i;\r
-//        Logger.i(stringBuilder1.toString());\r
-//        return true;\r
-//      }\r
-//    } catch (Exception exception) {\r
-//      exception.printStackTrace();\r
-//      i = b1;\r
-//    }\r
-    return false;\r
-  }\r
-  \r
   public static String getCurStatus(Context paramContext) {\r
     String str1;\r
     try {\r
@@ -163,13 +128,9 @@ public class DeviceInfoUtil {
   public static String getSystemVersion() {\r
     return Build.VERSION.RELEASE;\r
   }\r
-  \r
-  public static boolean isTopActivity(Context paramContext) {\r
-    ArrayList arrayList = new ArrayList();\r
-    arrayList.add("com.enqualcomm.imessage.ui.chat_huohuotu.ChatHuoHuoTuActivity_");\r
-    arrayList.add("com.enqualcomm.imessage.ui.chat.ChatActivity_");\r
-    return arrayList.contains(((ActivityManager.RunningTaskInfo)((ActivityManager)paramContext.getSystemService(Context.ACTIVITY_SERVICE)).getRunningTasks(1).get(0)).topActivity.getClassName());\r
-  }\r
+\r
+  public static String getSWVersionDisplayName(){ return Build.DISPLAY;}\r
+\r
   \r
   public static void setLockSimInfo(Context paramContext) {\r
     Settings.System.putInt(paramContext.getContentResolver(), "com.eqc.watch.launcher.SimIsBlocked", 1); }\r
index 5f47fd2..3497e49 100644 (file)
@@ -30,12 +30,12 @@ public class FileCache {
       }  \r
   }\r
   \r
-  public FileCache(File paramFile, String paramString) {\r
-    this.file = new File(paramFile, paramString);\r
+  public FileCache(File dir, String filename) {\r
+    this.file = new File(dir, filename);\r
     StringBuilder stringBuilder = new StringBuilder();\r
-    stringBuilder.append(paramString);\r
+    stringBuilder.append(filename);\r
     stringBuilder.append("Index");\r
-    this.indexFile = new File(paramFile, stringBuilder.toString());\r
+    this.indexFile = new File(dir, stringBuilder.toString());\r
     if (this.indexFile.exists())\r
       try {\r
         BufferedSource bufferedSource = Okio.buffer(Okio.source(this.indexFile));\r
index 934036b..38cb45b 100644 (file)
@@ -2,7 +2,7 @@ package com.ic.protocol.utils;
 \r
 import android.util.Log;\r
 \r
-import com.ic.protocol.service.protocolMainServer;\r
+import com.enqualcomm.support.CoreService;\r
 \r
 public class Logger {\r
   private static final boolean DEBUG = true;   //BuildConfig.DEBUG;\r
@@ -68,8 +68,8 @@ public class Logger {
   public static  void log(String TAG, String msg) {\r
     if (DEBUG) {\r
       Log.e(TAG, msg);\r
-      if (protocolMainServer.getInstance()!=null)\r
-          FileOutputUtil.fileOutput(protocolMainServer.getInstance().getRuntime().getCacheDir(),"log",TAG + " "+ msg);\r
+      if (CoreService.getInstance()!=null)\r
+          FileOutputUtil.fileOutput(CoreService.getInstance().getRuntime().getCacheDir(),"log",TAG + " "+ msg);\r
     }\r
 \r
 \r
@@ -78,8 +78,8 @@ public class Logger {
   public static void log(String TAG,String funcName, String msg) {\r
     if (DEBUG) {\r
       Log.e(TAG, "[" + funcName + "]" + msg);\r
-      if (protocolMainServer.getInstance()!=null)\r
-        FileOutputUtil.fileOutput(protocolMainServer.getInstance().getRuntime().getCacheDir(),"log",TAG + " "+ "[" + funcName + "]" + msg);\r
+      if (CoreService.getInstance()!=null)\r
+        FileOutputUtil.fileOutput(CoreService.getInstance().getRuntime().getCacheDir(),"log",TAG + " "+ "[" + funcName + "]" + msg);\r
     }\r
   }\r
 }\r
index 26b1d35..b9b0be2 100644 (file)
@@ -11,7 +11,7 @@ import com.ic.protocol.LocationClient;
 import com.ic.protocol.adapter.protocolAPIHelper;\r
 import com.ic.protocol.bean.StringMessage;\r
 import com.ic.protocol.service.HeartRateManager;\r
-import com.ic.protocol.service.protocolMainServer;\r
+import com.enqualcomm.support.CoreService;\r
 \r
 import java.io.UnsupportedEncodingException;\r
 import java.net.InetAddress;\r
@@ -20,6 +20,7 @@ import java.nio.ByteBuffer;
 import java.util.concurrent.ExecutorService;\r
 import java.util.concurrent.Executors;\r
 \r
+import rx.Subscription;\r
 import rx.android.schedulers.AndroidSchedulers;\r
 import rx.schedulers.Schedulers;\r
 \r
@@ -47,10 +48,10 @@ public class NettyConnection implements Connection {
                 public boolean handleCmd(protocolAPIHelper.CMD_TYPE type, String cmd) {\r
 \r
                     //普通非二进制命令用此函数处理\r
-                        Runtime runtime=protocolMainServer.getInstance().getRuntime();\r
+                        Runtime runtime=CoreService.getInstance().getRuntime();\r
                         boolean ret=true;\r
                         Logger.i("handleCmd "+type.name() + " strLen="+cmd.length());\r
-                        FileOutputUtil.fileOutput(protocolMainServer.getInstance().getRuntime().getCacheDir(),"APILog", " recv " + cmd);\r
+                        FileOutputUtil.fileOutput(CoreService.getInstance().getRuntime().getCacheDir(),"APILog", " recv " + cmd);\r
                         switch (type){\r
                             case BP00:\r
                                 API.handleBP00(cmd);\r
@@ -169,15 +170,16 @@ public class NettyConnection implements Connection {
                 public boolean handleCmd(protocolAPIHelper.CMD_TYPE type, String cmd, byte[] bytes) {\r
 \r
                     //只有需要传递二级制数据的才需要这个函数,目前只有BP28需要\r
+                    Runtime runtime=CoreService.getInstance().getRuntime();\r
                     boolean ret=true;\r
                     Logger.i("handleCmd "+type.name() + " "+cmd+" bytelen="+bytes.length );\r
-                    FileOutputUtil.fileOutput(protocolMainServer.getInstance().getRuntime().getCacheDir(),"APILog", " recv " +new String(bytes));\r
+                    FileOutputUtil.fileOutput(CoreService.getInstance().getRuntime().getCacheDir(),"APILog", " recv " +new String(bytes));\r
                     switch (type) {\r
                         case BP28:\r
-                            API.handleBP28(NettyConnection.this,cmd, bytes);\r
+                            API.handleBP28(NettyConnection.this,cmd, runtime,bytes);\r
                             Logger.i("服务器收到语音BP28");\r
                             DeliverCMDMessageToSystem("BP28", "");//通知下面线程状态变化\r
-\r
+                            break;\r
                     }\r
                     return ret;\r
                 }\r
@@ -285,7 +287,7 @@ public class NettyConnection implements Connection {
     if (!isServerConnected()){\r
 \r
         log("skiped"+cmd);\r
-        FileOutputUtil.fileOutput(protocolMainServer.getInstance().getRuntime().getCacheDir(),"APILog"," skiped " + cmd);\r
+        FileOutputUtil.fileOutput(CoreService.getInstance().getRuntime().getCacheDir(),"APILog"," skiped " + cmd);\r
         return false;\r
     }else{\r
         log("send  "+cmd);\r
@@ -306,13 +308,49 @@ public class NettyConnection implements Connection {
                         }\r
                 );\r
 \r
-        FileOutputUtil.fileOutput(protocolMainServer.getInstance().getRuntime().getCacheDir(),"APILog"," sent " + cmd);\r
+        FileOutputUtil.fileOutput(CoreService.getInstance().getRuntime().getCacheDir(),"APILog"," sent " + cmd);\r
 \r
     }\r
 \r
     return true;\r
   }\r
-\r
+    public boolean sendMsg(byte[]  cmdArray) {\r
+\r
+        if( cmdArray==null || cmdArray.length==0)\r
+        {\r
+            return false;\r
+        }\r
+\r
+\r
+        if (!isServerConnected()){\r
+\r
+            log("skipedBytes "+new String(cmdArray));\r
+            FileOutputUtil.fileOutput(CoreService.getInstance().getRuntime().getCacheDir(),"APILog"," skiped " + new String(cmdArray));\r
+            return false;\r
+        }else{\r
+            log("sendBytes  "+new String(cmdArray));\r
+            //向RxSocket写数据\r
+            //示例数据:IWAP00867155030001063#\r
+            ByteBuffer byteBuffer = ByteBuffer.wrap(cmdArray);\r
+            RxSocket.getInstance().write(byteBuffer)\r
+                    .subscribe(\r
+                            aBoolean -> {\r
+                                log("RxSocket write " + aBoolean);\r
+                            },\r
+                            throwable -> {\r
+                                log("RxSocket write Error : " + throwable.getMessage());\r
+                            },\r
+                            () -> {\r
+                                log("RxSocket write main ");\r
+                            }\r
+                    );\r
+\r
+            FileOutputUtil.fileOutput(CoreService.getInstance().getRuntime().getCacheDir(),"APILog"," sentBytes  " + new String(cmdArray));\r
+\r
+        }\r
+\r
+        return true;\r
+    }\r
   public int getTimeout() { return this.timeout; }\r
 \r
 \r
index e2c0903..f87b565 100644 (file)
@@ -17,7 +17,8 @@ import android.view.MotionEvent;
 import android.view.View;\r
 \r
 \r
-import com.ic.protocol.R;\r
+import com.enqualcomm.support.R;\r
+import com.ic.jni.ICJniUtils;\r
 import com.ic.protocol.bean.Contact;\r
 import com.ic.protocol.service.AudioService;\r
 import com.ic.protocol.service.HeartRateManager;\r
@@ -32,6 +33,10 @@ import rx.schedulers.Schedulers;
 import static android.os.PowerManager.ACQUIRE_CAUSES_WAKEUP;\r
 import static android.os.PowerManager.SCREEN_DIM_WAKE_LOCK;\r
 import static com.ic.protocol.Constants.ACTION_HEATR_RATE_START;\r
+import static com.ic.protocol.Constants.ACTION_REMOTE_CAMERA;\r
+import static com.ic.protocol.Constants.RESUME_ACTION;\r
+import static com.ic.protocol.Constants.SOS_ACTION;\r
+import static com.ic.protocol.Constants.STEP_COUNT_ALARM_ACTION;\r
 \r
 public class ProcessReceiver extends BroadcastReceiver {\r
   private static final int MICRO_CHAT = 2;\r
@@ -322,6 +327,7 @@ public class ProcessReceiver extends BroadcastReceiver {
     this.mNotificationManager.notify(1, notification);\r
   }\r
 \r
+\r
   @Override\r
   public void onReceive(Context paramContext, Intent paramIntent) {\r
     Contact contact;\r
@@ -330,42 +336,37 @@ public class ProcessReceiver extends BroadcastReceiver {
     stringBuilder.append("action==");\r
     stringBuilder.append(str);\r
     Logger.i(stringBuilder.toString());\r
-    if ("com.enqualcomm.support.ACTION_STEP_COUNT_ALARM".equals(str)) {\r
-//      EqcAlgorithmNative.native_EqcAlgorithm_Gsensor_clear_step();\r
-      AlarmHelper.setCleanStepCountAlarm(paramContext, 23, 59, "com.enqualcomm.support.ACTION_STEP_COUNT_ALARM");\r
+    if (STEP_COUNT_ALARM_ACTION.equals(str)) {\r
+      ICJniUtils.resetStepCount();\r
+      AlarmHelper.setCleanStepCountAlarm(paramContext, 23, 59, STEP_COUNT_ALARM_ACTION);\r
       return;\r
     }\r
-    if ("com.enqualcomm.imessage.RESUME_ACTION".equals(str)) {\r
+    if (RESUME_ACTION.equals(str)) {\r
       SharPreferenceUtil.setPrefBoolean(paramContext, "key_is_resume", paramIntent.getBooleanExtra("is_resume", false));\r
       return;\r
     }\r
-    if (ACTION_HEATR_RATE_START.equals(str)) {\r
-//      contact = (Contact)paramIntent.getParcelableExtra("contact");\r
-//      SharPreferenceUtil.getPrefBoolean(paramContext, "key_is_resume", false);\r
-\r
-\r
-    } else if ("com.enqualcomm.imessage.SOS_ACTION".equals(str)) {\r
+    if (SOS_ACTION.equals(str)) {\r
       if (paramIntent.getIntExtra("sos_end", 0) == 0) {\r
-//        EqcAlgorithmNative.native_EqcAlgorithmMethod3(8);\r
-        sendStheartRateBroadcast(paramContext, "com.eqc.heartrate.action.SILENT_START", 3);\r
+        sendStheartRateBroadcast(paramContext, ACTION_HEATR_RATE_START, 3);\r
         return;\r
       }\r
     } else {\r
       String str1;\r
-      if ("com.enqualcomm.support.ACTION_REMOTE_CAMERA".equals(paramIntent.getAction())) {\r
+      if (ACTION_REMOTE_CAMERA.equals(paramIntent.getAction())) {\r
         str1 = paramIntent.getStringExtra("key_remote_number");\r
         (new CameraUtil(paramContext)).getPictur(str1);\r
         return;\r
       }\r
-\r
-\r
     }\r
   }\r
   \r
-  public void sendStheartRateBroadcast(Context paramContext, String paramString, int paramInt) {\r
+  public void sendStheartRateBroadcast(Context paramContext, String actionStr, int paramInt) {\r
     Intent intent = new Intent();\r
-    intent.setAction(paramString);\r
+    intent.setAction(actionStr);\r
     intent.putExtra("stheartRateType", paramInt);\r
     paramContext.sendBroadcast(intent);\r
   }\r
+\r
+\r
+\r
 }\r
index fd6b0ca..b64ce17 100644 (file)
@@ -4,6 +4,7 @@ import android.annotation.SuppressLint;
 \r
 import com.ic.protocol.LocationClient;\r
 import com.ic.protocol.bean.StringMessage;\r
+import com.ic.protocol.service.Deliver;\r
 \r
 import java.util.concurrent.LinkedBlockingDeque;\r
 \r
@@ -34,14 +35,14 @@ public class ServiceUtil {
 \r
   public static void offerQueue(StringMessage paramStringMessage, boolean paramBoolean) {\r
     if (paramBoolean) {\r
-      if (!LocationClient.queue.offerFirst(paramStringMessage)) {\r
-//        LocationClient.saveQueue();\r
-        LocationClient.queue.offerFirst(paramStringMessage);\r
+      if (!Deliver.queue.offerFirst(paramStringMessage)) {\r
+        Deliver.saveQueue();\r
+        Deliver.queue.offerFirst(paramStringMessage);\r
         return;\r
       } \r
-    } else if (!LocationClient.queue.offerLast(paramStringMessage)) {\r
-//      LocationClient.saveQueue();\r
-      LocationClient.queue.offerLast(paramStringMessage);\r
+    } else if (!Deliver.queue.offerLast(paramStringMessage)) {\r
+      Deliver.saveQueue();\r
+      Deliver.queue.offerLast(paramStringMessage);\r
     } \r
   }\r
 \r
index dd64aba..118f24e 100644 (file)
@@ -1,7 +1,10 @@
 package com.ic.protocol.utils;\r
 \r
+import java.text.ParseException;\r
 import java.text.SimpleDateFormat;\r
+import java.util.Calendar;\r
 import java.util.Date;\r
+import java.util.Locale;\r
 \r
 public class TimeUtil {\r
   public static String getLocalTime() { return getLocalTime(System.currentTimeMillis()); }\r
@@ -23,5 +26,56 @@ public class TimeUtil {
   public static String getSystemTime4() { return getSystemTime4(System.currentTimeMillis()); }\r
   \r
   public static String getSystemTime4(long paramLong) { return (new SimpleDateFormat("yyyyMMdd")).format(new Date(paramLong)); }\r
+\r
+\r
+\r
+  public static void parseDatetiime(String datetimeStr){\r
+\r
+    SimpleDateFormat dff = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS", Locale.ENGLISH);//输入的被转化的时间格式\r
+    SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//需要转化成的时间格式\r
+    SimpleDateFormat df2 = new SimpleDateFormat("yyyyMMddHHmmssSSS");\r
+    Date date1 = null;\r
+    try {\r
+      date1 = dff.parse(datetimeStr);\r
+    } catch (ParseException e) {\r
+      e.printStackTrace();\r
+    }\r
+    String str1 = df1.format(date1);\r
+    String str2 = df2.format(date1);\r
+\r
+  }\r
+\r
+  /* 返回 2位年2位月2位日, 如2019-12-30 返回 191230*/\r
+  public static String getShortDate() {\r
+    String DEFAULT_TIME_FORMAT = "yyMMdd";\r
+    SimpleDateFormat dateFormatter = new SimpleDateFormat(DEFAULT_TIME_FORMAT);\r
+    String dateStr = dateFormatter.format(Calendar.getInstance().getTime());//获取当前时间\r
+    return dateStr;\r
+  }\r
+  /*061830: 格林尼治时间06 点18 分30 秒 */\r
+  public static String getShortTime(){\r
+    String DEFAULT_TIME_FORMAT = "HHmmss";\r
+    //设置时间的格式\r
+    //                      yyyy-MM-dd 1969-12-31\r
+    //                      yyyy-MM-dd 1970-01-01\r
+    //                yyyy-MM-dd HH:mm 1969-12-31 16:00\r
+    //                yyyy-MM-dd HH:mm 1970-01-01 00:00\r
+    //               yyyy-MM-dd HH:mmZ 1969-12-31 16:00-0800\r
+    //               yyyy-MM-dd HH:mmZ 1970-01-01 00:00+0000\r
+    //        yyyy-MM-dd HH:mm:ss.SSSZ 1969-12-31 16:00:00.000-0800\r
+    //        yyyy-MM-dd HH:mm:ss.SSSZ 1970-01-01 00:00:00.000+0000\r
+    //      yyyy-MM-dd'T'HH:mm:ss.SSSZ 1969-12-31T16:00:00.000-0800\r
+    //      yyyy-MM-dd'T'HH:mm:ss.SSSZ 1970-01-01T00:00:00.000+0000\r
+    //注:HH显示的是24小时制,hh显示的是12小时制\r
+\r
+    SimpleDateFormat dateFormatter = new SimpleDateFormat(DEFAULT_TIME_FORMAT);\r
+    String dateStr = dateFormatter.format(Calendar.getInstance().getTime());//获取当前时间\r
+//        SimpleDateFormat dff = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS", Locale.ENGLISH);//输入的被转化的时间格式\r
+//        SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//需要转化成的时间格式\r
+//        SimpleDateFormat df2 = new SimpleDateFormat("yyyyMMddHHmmssSSS");\r
+\r
+    return dateStr;\r
+  }\r
+\r
 }\r
 \r
index 4e82099..3d92538 100644 (file)
@@ -14,6 +14,7 @@ import android.os.Build;
 \r
 import java.io.ByteArrayOutputStream;\r
 import java.io.File;\r
+import java.io.FileOutputStream;\r
 import java.io.IOException;\r
 import java.lang.reflect.Method;\r
 import java.net.InetAddress;\r
@@ -68,8 +69,11 @@ public class Util {
   public static String decodeUnicode2Utf8(String unicodestr) {\r
     char aChar;\r
     int len = unicodestr.length();\r
+    //由于协议中Unicode 都是不带\\u 字头的,和网络中常见的不同,直接4个字节代表一个unicode字。\r
+    //如果不是4的整倍数,则证明字符串格式有误,取消转换\r
     if (len%4==0) {\r
 \r
+      //先给每个unicode字符都加上\\u字头,然后再进行转换。\r
       StringBuffer sb = new StringBuffer();\r
       for (int i = 0; i < len; i += 4) {\r
         sb.append("\\u").append(unicodestr.substring(i, i + 4));\r
@@ -410,12 +414,12 @@ public class Util {
     return paramArrayOfByte;\r
   }\r
   \r
-  public static int getDuration(String paramString) {\r
-    if (paramString != null) {\r
+  public static int getDuration(String amrfilePath) {\r
+    if (amrfilePath != null) {\r
       double d1;\r
       MediaPlayer mediaPlayer = new MediaPlayer();\r
       try {\r
-        mediaPlayer.setDataSource(paramString);\r
+        mediaPlayer.setDataSource(amrfilePath);\r
         mediaPlayer.prepare();\r
         int i = mediaPlayer.getDuration();\r
         d1 = i;\r
@@ -487,29 +491,28 @@ public class Util {
   \r
   public static File makeDir(File paramFile, String paramString) {\r
     StringBuilder stringBuilder = new StringBuilder(Integer.toHexString(paramString.hashCode()));\r
-    for (byte b = 2; b < stringBuilder.length(); b += 3)\r
-      stringBuilder.insert(b, "/"); \r
+//    for (byte b = 2; b < stringBuilder.length(); b += 3)\r
+//      stringBuilder.insert(b, "/");\r
     paramFile = new File(paramFile, stringBuilder.toString());\r
     paramFile.mkdirs();\r
     return paramFile;\r
   }\r
   \r
-  public static String saveFile(byte[] paramArrayOfByte, int paramInt1, int paramInt2, File paramFile, String paramString) {\r
+  public static String saveFile(byte[] buf, int start, int size, File dir, String filename) {\r
     StringBuilder stringBuilder = new StringBuilder();\r
     stringBuilder.append(UUID.randomUUID().toString());\r
     stringBuilder.append("_");\r
-    stringBuilder.append(paramString);\r
-    paramString = stringBuilder.toString();\r
-    paramFile = makeDir(paramFile, paramString);\r
+    stringBuilder.append(filename);\r
+    filename = stringBuilder.toString();\r
+    File paramFile = makeDir(dir, filename); //建立以文件名Hash命名的路径\r
     try {\r
-      paramFile = new File(paramFile, paramString);\r
-      BufferedSink bufferedSink = Okio.buffer(Okio.sink(paramFile));\r
-      bufferedSink.write(paramArrayOfByte, paramInt1, paramInt2);\r
-      bufferedSink.close();\r
+      paramFile = new File(paramFile, filename);//在路径下再建立文件\r
+      FileOutputStream fos=new FileOutputStream(paramFile);\r
+      fos.write(buf,start,size);\r
+      fos.close();\r
       return paramFile.getAbsolutePath();\r
     } catch (IOException e) {\r
       e.printStackTrace();\r
-\r
     }\r
     return null;\r
   }\r