1、Deliver.java中发送Location message时没法送一个delay 5秒钟。
authorsnickersun <snickersun@qq.com>
Wed, 19 Feb 2020 16:29:08 +0000 (00:29 +0800)
committersnickersun <snickersun@qq.com>
Wed, 19 Feb 2020 16:29:08 +0000 (00:29 +0800)
2、KeepAlive.java 中AP00与AP03之间添加 delay 5秒钟。
3、AlarmWakeup.java 启动时的消息修改为HeartBeatAlarm
4、NettyConnection.java 修改Log消息。
5、LocationClient.java添加SkipMoveCheck接口,并在ICSmsManager.java中添加对应SMSCMD
#skipmovecheck#=current
#skipmovecheck#=true
#skipmovecheck#=false
6、CoreService.java 保证每次亮屏的时候都发一次心跳,保证计步等数据快速更新,提高体验。
   网络重试的间隔从5秒改为20秒
   去掉Action_Alarm只保留 Location_Alarm,降低功耗。

app/app.iml
app/src/main/java/com/enqualcomm/support/CoreService.java
app/src/main/java/com/enqualcomm/support/ICSmsManager.java
app/src/main/java/com/enqualcomm/support/LocationClient.java
app/src/main/java/com/enqualcomm/support/service/Deliver.java
app/src/main/java/com/enqualcomm/support/service/KeepAlive.java
app/src/main/java/com/enqualcomm/support/utils/AlarmWakeUp.java
app/src/main/java/com/enqualcomm/support/utils/NettyConnection.java

index e9dfcaa..19e98f4 100644 (file)
@@ -19,7 +19,7 @@
         <option name="ALLOW_USER_CONFIGURATION" value="false" />\r
         <option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />\r
         <option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />\r
-        <option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />\r
+        <option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res;file://$MODULE_DIR$/build/generated/res/resValues/debug" />\r
         <option name="TEST_RES_FOLDERS_RELATIVE_PATH" value="" />\r
         <option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />\r
       </configuration>\r
     <orderEntry type="module" module-name="dNSCache" />\r
     <orderEntry type="module" module-name="dNSCache" />\r
     <orderEntry type="module" module-name="dNSCache" />\r
+    <orderEntry type="module" module-name="dNSCache" />\r
+    <orderEntry type="module" module-name="dNSCache" />\r
   </component>\r
 </module>
\ No newline at end of file
index 095c1c1..2c35f7b 100644 (file)
@@ -110,6 +110,7 @@ public class CoreService extends Service {
 \r
     public static final int interval = 60000;\r
 \r
+    public static boolean needLocateInAfterHeartBeat=false;\r
     private static int is_allowed_in_sleep_mode = 1;\r
 \r
     private static boolean is_in_sleep_mode = false;\r
@@ -291,7 +292,7 @@ public class CoreService extends Service {
                 Logger.i(var3.toString());\r
                 if (CoreService.is_in_sleep_mode) {\r
 \r
-                    /*屏幕亮起时,如果在sleep模式,则唤醒各个进程*/\r
+                    /*屏幕亮起时,如果在sleep模式(夜晚的那个睡眠模式,非系统休眠,暂时没实现,还不会跑到这里),则唤醒各个进程*/\r
                     CoreService.is_in_sleep_mode = false;\r
                     CoreService.is_allowed_in_sleep_mode = 0;\r
                     if (CoreService.this.mKeepAlive != null) {\r
@@ -301,14 +302,23 @@ public class CoreService extends Service {
                     CoreService.this.wakeUpFromSleep();\r
                 }\r
 \r
+\r
+                //为了保证唤醒时各个状态及时更新到服务器,发送一个同步心跳包,这样用户体验更好\r
+                Observable.timer(500L, TimeUnit.MILLISECONDS).subscribe(new Action1<Long>() {\r
+                    public void call(Long param1Long) {\r
+                        connection.send(protocolAPIHelper.genStringMessage("heart",protocolAPIHelper.AP03(runtime)));\r
+                    }\r
+                });\r
+\r
+\r
                 if (CoreService.is_wifi_network_ok) {\r
                     CoreService.is_wifi_network_ok = false;\r
                     /*屏幕亮起时,如果wifi用户设置是开启的,则开启wifi*/\r
-                    Util.turnOnWifiForConnect(CoreService.this.runtime.getContextProxy().context, CoreService.this.runtime);\r
+                    Util.turnOnWifiForConnect(runtime.getContextProxy().context, runtime);\r
                 }\r
-            } else if ("android.intent.action.SCREEN_OFF".equals(param1Intent.getAction()) && Util.isWifiIsOpen(CoreService.this.runtime.getContextProxy().context, CoreService.this.runtime)) {\r
+            } else if ("android.intent.action.SCREEN_OFF".equals(param1Intent.getAction()) && Util.isWifiIsOpen(runtime.getContextProxy().context,runtime)) {\r
                 CoreService.is_wifi_network_ok = true;\r
-                Util.turnOffWifiForSleep(CoreService.this.runtime.getContextProxy().context, CoreService.this.runtime);\r
+                Util.turnOffWifiForSleep(runtime.getContextProxy().context, runtime);\r
             }\r
         }\r
     };\r
@@ -402,8 +412,13 @@ public class CoreService extends Service {
     }\r
     private void wakeUpFromSleep() {\r
         this.startAlarmCount = 0;\r
-        alarmCycle = 1;\r
-        setAlarm(alarmCycle);\r
+//        alarmCycle = 1;\r
+//        setAlarm(alarmCycle);\r
+//        runtime.getLocationInstance().setLocation_cycle(1);\r
+\r
+        //每次唤醒都强制设置一次定位alarm和定位一次。\r
+        setLocationAlarm(runtime.getLocationInstance().getWorkingMod());\r
+\r
         this.runtime.getContextProxy().sendBroadcast(ACTION_EQC_ALARM, this.runtime);\r
         this.connection.open();\r
         checkconnection();\r
@@ -481,7 +496,9 @@ public class CoreService extends Service {
 \r
         this.connectionServiceChain.processAttach(this.connection, this.runtime);\r
         this.invokeHandlerServiceChain.processAttach(this.connection, this.runtime);\r
-        setAlarm(alarmCycle);\r
+//        setAlarm(alarmCycle);\r
+\r
+\r
         if (Config.LOG_TOFILE)  FileOutputUtil.fileOutput(runtime.getCacheDir(), "alarmCycle", "设置闹钟服务  alarmCycle");\r
         this.locationClient = new LocationClient(this.connection, this.runtime);\r
         this.connection.open();\r
@@ -557,7 +574,9 @@ public class CoreService extends Service {
         //获取天气时间\r
         setWeatherAlarm();\r
 \r
+\r
         //获取定位时间\r
+        needLocateInAfterHeartBeat=true;\r
         setLocationAlarm(runtime.getLocationInstance().getWorkingMod());\r
 \r
         //备份DB数据到sd cache目录,为调试方便\r
@@ -576,18 +595,21 @@ public class CoreService extends Service {
             stringBuilder.append(" paramInt2=");\r
             stringBuilder.append(paramInt2);\r
             Logger.i(stringBuilder.toString());\r
-            if (ACTION_ALARM.equals(paramIntent.getAction())) {\r
-                if (cmcm_call_eiot_into_powersave_mode() == 1) {\r
-                    Logger.i("2 into powersave return");\r
-                    return Service.START_NOT_STICKY;\r
-                }\r
+//            if (ACTION_ALARM.equals(paramIntent.getAction())) {\r
+            if (ACTION_LOCATION_ALARM.equals(paramIntent.getAction())){\r
 \r
-                //wakeup后1分钟唤醒一次,5分钟后,心跳改为从配置信息读取的值,默认为3分钟\r
-                if (this.startAlarmCount < 5 && alarmCycle == 1) {\r
-                    this.startAlarmCount++;\r
-                } else {\r
-                    alarmCycle = Config.getAlarmCycle(this);\r
-                }\r
+\r
+//                    if (cmcm_call_eiot_into_powersave_mode() == 1) {\r
+//                        Logger.i("2 into powersave return");\r
+//                        return Service.START_NOT_STICKY;\r
+//                    }\r
+\r
+//                //wakeup后1分钟唤醒一次,5分钟后,心跳改为从配置信息读取的值,默认为3分钟\r
+//                if (this.startAlarmCount < 5 && alarmCycle == 1) {\r
+//                    this.startAlarmCount++;\r
+//                } else {\r
+//                    alarmCycle = Config.getAlarmCycle(this);\r
+//                }\r
                 AlarmWakeUp.setAlarmWakeUpTime();\r
                 boolean screenon = ((PowerManager)getSystemService(POWER_SERVICE)).isScreenOn();\r
                 if (!screenon) {\r
@@ -598,19 +620,29 @@ public class CoreService extends Service {
                     is_wifi_network_ok = true; //如果wifi开启的,则记录wifi状态为开启,以后屏幕开启时,再根据此变量决定是否打开wifi\r
                     Util.turnOffWifiForSleep((this.runtime.getContextProxy()).context, this.runtime);\r
                 }\r
-                setAlarm(alarmCycle);\r
-                if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(runtime.getCacheDir(), "alarmCycle", "ALARM alarmCycle");\r
+//                setAlarm(alarmCycle);\r
+//                if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(runtime.getCacheDir(), "alarmCycle", "ALARM alarmCycle");\r
 \r
                 //发送心跳间隔广播给其他应用\r
                 this.runtime.getContextProxy().sendBroadcast(ACTION_EQC_ALARM, this.runtime);\r
-                this.locationClient.onAlarm(getWakeLock(alarmCycle));\r
+                this.locationClient.onAlarm(getWakeLock(1));\r
                 this.connectionServiceChain.processAlarmClock(this.connection, this.runtime);\r
                 this.invokeHandlerServiceChain.processAlarmClock(this.connection, this.runtime);\r
-                if (SystemClock.elapsedRealtime() - this.mWeatherTime > 60000L && this.mHaveSetWeatherAlarm) {\r
-                    setWeatherAlarm();\r
-                    this.mHaveSetWeatherAlarm = false;\r
-                    return Service.START_NOT_STICKY;\r
-                }\r
+//                if (SystemClock.elapsedRealtime() - this.mWeatherTime > 60000L && this.mHaveSetWeatherAlarm) {\r
+//                    setWeatherAlarm();\r
+//                    this.mHaveSetWeatherAlarm = false;\r
+//                    return Service.START_NOT_STICKY;\r
+//                }\r
+\r
+\r
+                //收到定时定位消息\r
+                setLocationAlarm(runtime.getLocationInstance().getWorkingMod());\r
+                StringBuilder stringBuilder1 = new StringBuilder();\r
+                stringBuilder1.append("LOCATION_ALARM  work mod=");\r
+                stringBuilder1.append(runtime.getLocationInstance().getWorkingMod());\r
+                if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(runtime.getCacheDir(), "alarmCycle", stringBuilder1.toString());\r
+                this.locationClient.triggerLocationProcess();\r
+\r
             } else {\r
                 StringBuilder stringBuilder1;\r
                 if (Constants.SLEEP_ALARM.equals(paramIntent.getAction())) {\r
@@ -642,8 +674,7 @@ public class CoreService extends Service {
                         is_allowed_in_sleep_mode = 1;\r
                         setWakeAlarm();\r
                         return Service.START_STICKY;\r
-                    }\r
-                    if (HEART_ALARM.equals(paramIntent.getAction())) {\r
+                    }else if (HEART_ALARM.equals(paramIntent.getAction())) {\r
                         if (this.mKeepAlive != null) {\r
                             this.mKeepAlive.onHeartAlarm(this.connection, this.runtime);\r
                             setHeartAlarm();\r
@@ -651,39 +682,29 @@ public class CoreService extends Service {
                             return Service.START_STICKY;\r
                         }\r
                     } else {\r
-                        if (WEATHER_ALARM.equals(paramIntent.getAction())) {\r
-//                            this.mSendPairMessage.resetDownLoadConfig();\r
-//                            this.mSendPairMessage.startDownLoad(this.runtime, false);\r
-                            return Service.START_STICKY;\r
-                        }else if (ACTION_ALARM_ADD_DATAPOINTS.equals(paramIntent.getAction())) {\r
-                            setUpLocationDataAlarm(28800000L);\r
-                            if (this.upLoadDataPoints != null) {\r
-                                this.upLoadDataPoints.uploadCurrentLocation();\r
-                                return Service.START_STICKY;\r
-                            }\r
-                            Logger.i("upLoadDataPoints=null");\r
-                            return Service.START_STICKY;\r
-                        }else if (Constants.STWORKMODE_ALARM.equals(paramIntent.getAction())) {\r
-                            if (this.startAlarmCount >= 5) {\r
-                                alarmCycle = paramIntent.getIntExtra("location_cycle", 3);\r
-                                setAlarm(alarmCycle);\r
-                            }\r
-                            stringBuilder1 = new StringBuilder();\r
-                            stringBuilder1.append("STWORKMODE_ALARM  alarmCycle=");\r
-                            stringBuilder1.append(alarmCycle);\r
-                            if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(runtime.getCacheDir(), "alarmCycle", stringBuilder1.toString());\r
-                            return Service.START_STICKY;\r
-                        }else if (ACTION_LOCATION_ALARM.equals(paramIntent.getAction())){\r
-                            //收到定时定位消息\r
-                            setLocationAlarm(runtime.getLocationInstance().getWorkingMod());\r
-                            stringBuilder1 = new StringBuilder();\r
-                            stringBuilder1.append("LOCATION_ALARM  work mod=");\r
-                            stringBuilder1.append(runtime.getLocationInstance().getWorkingMod());\r
-                            if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(runtime.getCacheDir(), "alarmCycle", stringBuilder1.toString());\r
-                            this.locationClient.triggerLocationProcess();\r
-                            return Service.START_STICKY;\r
-\r
-                        }else {\r
+//                        if (WEATHER_ALARM.equals(paramIntent.getAction())) {\r
+////                            this.mSendPairMessage.resetDownLoadConfig();\r
+////                            this.mSendPairMessage.startDownLoad(this.runtime, false);\r
+//                            return Service.START_STICKY;\r
+//                        }else if (ACTION_ALARM_ADD_DATAPOINTS.equals(paramIntent.getAction())) {\r
+//                            setUpLocationDataAlarm(28800000L);\r
+//                            if (this.upLoadDataPoints != null) {\r
+//                                this.upLoadDataPoints.uploadCurrentLocation();\r
+//                                return Service.START_STICKY;\r
+//                            }\r
+//                            Logger.i("upLoadDataPoints=null");\r
+//                            return Service.START_STICKY;\r
+//                        }else if (Constants.STWORKMODE_ALARM.equals(paramIntent.getAction())) {\r
+//                            if (this.startAlarmCount >= 5) {\r
+//                                alarmCycle = paramIntent.getIntExtra("location_cycle", 3);\r
+//                                setAlarm(alarmCycle);\r
+//                            }\r
+//                            stringBuilder1 = new StringBuilder();\r
+//                            stringBuilder1.append("STWORKMODE_ALARM  alarmCycle=");\r
+//                            stringBuilder1.append(alarmCycle);\r
+//                            if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(runtime.getCacheDir(), "alarmCycle", stringBuilder1.toString());\r
+//                            return Service.START_STICKY;\r
+//                        }else {\r
                             if (ACTION_HEATR_RATE_START.equals(paramIntent.getAction())) {\r
 \r
                                 //此处消息从timer来\r
@@ -695,7 +716,7 @@ public class CoreService extends Service {
                                 setLocationAlarm(runtime.getLocationInstance().getWorkingMod());//同时重置alarm并触发定位\r
                             }\r
                             this.invokeHandlerServiceChain.processUserRequest(paramIntent, this.connection, this.runtime);\r
-                        }\r
+//                        }\r
                     }\r
                 }\r
             }\r
@@ -727,7 +748,7 @@ public class CoreService extends Service {
     }\r
     //每一分钟设置一次\r
     public void setAlarm(int paramInt) {\r
-        AlarmHelper.setRealTimeAlarm(runtime.getContextProxy().context,paramInt,ACTION_ALARM);\r
+//        AlarmHelper.setRealTimeAlarm(runtime.getContextProxy().context,paramInt,ACTION_ALARM);\r
     }\r
 \r
     public void setHeartRateDetectAlarm(int heartRateDetectAlarmCycle){\r
@@ -858,7 +879,7 @@ public class CoreService extends Service {
                     public void run() {\r
                         ReConnectToServer();\r
                     }\r
-                }, 0, 5000); //每5秒重试一次\r
+                }, 0, 20000); //每20秒重试一次\r
             }\r
         }\r
     }\r
index e63d891..10fbfd3 100644 (file)
@@ -277,6 +277,23 @@ public class ICSmsManager {
                     sendSMS(phonenumber, "setlocation format error!");\r
                 }\r
 \r
+            }else if (sms.startsWith("#skipmovecheck#=")){\r
+                String tmp[]=sms.split("=");\r
+                if (tmp.length==2) {\r
+                    if (tmp[1].equals("current")) {\r
+                        sendSMS(phonenumber, "SkipMoveCheck "+LocationClient.getSkipMoveCheck()+"!");\r
+                    }else if (tmp[1].equals("true")) {\r
+                        LocationClient.setSkipMoveCheck(true);\r
+                        sendSMS(phonenumber, "set SkipMoveCheck "+LocationClient.getSkipMoveCheck()+" success!");\r
+                    }else if (tmp[1].equals("false")) {\r
+                        LocationClient.setSkipMoveCheck(false);\r
+                        sendSMS(phonenumber, "set SkipMoveCheck "+LocationClient.getSkipMoveCheck()+" success!");\r
+                    }else{\r
+                        sendSMS(phonenumber, "skipmovecheck format error!");\r
+                    }\r
+                }else{\r
+                    sendSMS(phonenumber, "skipmovecheck format error!");\r
+                }\r
             }\r
         }\r
     }\r
index 1c1a410..612d9a8 100644 (file)
@@ -423,8 +423,13 @@ public void updateCellInfo() {
   }\r
 \r
 \r
-\r
-\r
+  private static boolean skipMoveCheck=false;\r
+  public static void setSkipMoveCheck(boolean _skipMoveCheck){\r
+    skipMoveCheck=_skipMoveCheck;\r
+  }\r
+  public static boolean getSkipMoveCheck(){\r
+      return skipMoveCheck;\r
+  }\r
   public void startLocationProcess(int mod){\r
 \r
     updateStepCount();//update StepCount,保证每次定位前,计步数据是最新的。防止丢数据。\r
@@ -435,7 +440,7 @@ public void updateCellInfo() {
     }\r
 \r
     // 不强制定位 且 WorkingMod 不是紧急模式,且 没有移动过\r
-    if ( ( forceLocation != 1 ) &&  ( mod != ICLocation.REALTIME_MOD )&&  ( mod != ICLocation.EMERGNECY_MOD ) && (mod != ICLocation.CUSTOM_MOD) && ( runtime.getLastStepCount() == runtime.getTotalStepCount())  ){\r
+    if ( ( forceLocation != 1 ) &&  ( mod != ICLocation.REALTIME_MOD )&&  ( mod != ICLocation.EMERGNECY_MOD ) && (mod != ICLocation.CUSTOM_MOD) &&  (runtime.getLastStepCount() == runtime.getTotalStepCount()) && (skipMoveCheck ==false  )){\r
       Logger.i("No Move ,skip location!");\r
       return ;\r
     }\r
index a41bcab..2853dff 100644 (file)
@@ -103,20 +103,15 @@ public class Deliver extends AbstractConnectionService {
 \r
   private boolean wifiEnabled;\r
 \r
-\r
+  public static Runnable delaySendMSG;\r
+//  public static boolean sendingMsg=false;\r
   private static Handler mSendMSGHandler=new Handler(new Handler.Callback() {\r
     @Override\r
     public boolean handleMessage(Message message) {\r
 \r
       switch (message.what){\r
         case 1:\r
-\r
-          new Thread(new Runnable() {\r
-            @Override\r
-            public void run() {\r
-              sendThread();\r
-            }\r
-          }).start();\r
+          mSendMSGHandler.post(delaySendMSG);\r
           break;\r
         default:\r
           break;\r
@@ -125,8 +120,30 @@ public class Deliver extends AbstractConnectionService {
     }\r
   });\r
 \r
-  static  {\r
-  \r
+  static {\r
+    delaySendMSG = new Runnable() {\r
+      @Override\r
+      public void run() {\r
+//        if (sendingMsg==true)\r
+//        {\r
+//          Logger.i("Sending MSG in Thread, skip this send Command.");\r
+//          return;\r
+//        }\r
+//        sendingMsg=true;\r
+//        while (getAndSendMsgFromQueue()==true) {\r
+//          try {\r
+//            Thread.sleep(5000);\r
+//          } catch (InterruptedException e) {\r
+//            e.printStackTrace();\r
+//          }\r
+//        }\r
+        if (getAndSendMsgFromQueue()==true){\r
+          mSendMSGHandler.postDelayed(delaySendMSG,5000);\r
+        }\r
+//        sendingMsg=false;\r
+//        Logger.i("exit delaySendMSG!");\r
+      }\r
+    };\r
   }\r
   public Deliver(NettyConnection paramNettyConnection, Runtime paramRuntime) {\r
     connection = paramNettyConnection;\r
@@ -156,46 +173,51 @@ public class Deliver extends AbstractConnectionService {
     mSendMSGHandler.sendEmptyMessage(1);\r
   }\r
 \r
-  public static void sendThread(){\r
+  public static boolean getAndSendMsgFromQueue(){\r
+    boolean ret=false;\r
     if (mRuntime.getUseQueue()) {\r
       Logger.i("queue locked "+mLock.isLocked());\r
-      if(mLock.isLocked()) return;\r
+      if(mLock.isLocked()) return false;\r
       mLock.lock();\r
       try\r
       {\r
         String str;\r
         //如果没有数据从缓存中尝试读取\r
-        if (queue.isEmpty())\r
-          loadMessage2Queue();\r
+//        if (queue.isEmpty())\r
+//          loadMessage2Queue();\r
         if (!queue.isEmpty()) {\r
           StringBuilder stringBuilder = new StringBuilder();\r
           if (checkNetwork()) {\r
             StringMessage stringMessage = queue.poll();\r
-            while (stringMessage != null) {\r
+            if (stringMessage != null) {\r
               String cmd = stringMessage.isFromCache();\r
               stringBuilder.append(cmd);\r
               stringBuilder.append("\n");\r
               if (checkNetwork()) {\r
                 connection.sendMsg(cmd);\r
-                stringMessage = queue.poll();\r
+//                stringMessage = queue.poll();\r
+                ret=true;\r
               } else {\r
                 //已经拿到的缓存,如果刚巧没有网络,就原路放回去\r
                 ServiceUtil.offerQueue(stringMessage,true);\r
-                break;\r
+                ret=false;\r
               }\r
+            }else{\r
+             stringBuilder.append("no message!\n");\r
             }\r
           }\r
           str = stringBuilder.toString();\r
         } else {\r
-          str = null;\r
+          str = "no message!\n";\r
         }\r
-        Logger.i("send cached cmd: \n"+str);\r
+        Logger.i("send cached cmd : \n"+str);\r
+        Logger.i("\n"+queue.size()+" left in Queue!");\r
       }finally {\r
         if(mLock!=null && mLock.isLocked())\r
           mLock.unlock();\r
       }\r
-\r
     }\r
+    return ret;\r
   }\r
   private static void loadMessage2Queue() {\r
     byte b = 0;\r
@@ -248,8 +270,8 @@ public class Deliver extends AbstractConnectionService {
 public static void sendLocationMSG( String Msg){\r
 \r
     if(mRuntime.getUseQueue()){\r
-        ServiceUtil.offerQueue(protocolAPIHelper.genStringMessage("queue",Msg));\r
-        triggerSendThread();\r
+      ServiceUtil.offerQueue(protocolAPIHelper.genStringMessage("queue",Msg));\r
+      triggerSendThread();\r
     }else {\r
       if (connection.isServerConnected() && KeepAlive.isConnected) {\r
         Logger.i(" first send " + Msg);\r
index 844d3a4..b09dcd6 100644 (file)
@@ -9,6 +9,7 @@ import android.util.Log;
 \r
 import com.eiot.watch_lib.LauncherCtrl;\r
 import com.enqualcomm.support.CoreService;\r
+import com.enqualcomm.support.LocationClient;\r
 import com.enqualcomm.support.adapter.protocolAPIHelper;\r
 import com.enqualcomm.support.bean.StringMessage;\r
 import com.enqualcomm.support.service.base.AbstractConnectionService;\r
@@ -146,6 +147,8 @@ public class KeepAlive extends AbstractConnectionService {
     stringBuilder.append(",set KeepAlive isConnected = false");\r
     Logger.i(stringBuilder.toString());\r
     LauncherCtrl.getInstance(this.mContext).setStatusBarIcon("server_connected", STATUS_BAR_STATE_SERVER_CONNECTED_OFF);\r
+//网络断开后,重连成功后发送一个定位\r
+//    CoreService.needLocateInAfterHeartBeat=true;\r
     return false;\r
   }\r
   \r
@@ -161,10 +164,20 @@ public class KeepAlive extends AbstractConnectionService {
 //    if (!connectionError) {\r
     connectionError = false;\r
 \r
+\r
     //发送登录包\r
-    connection.send(protocolAPIHelper.genStringMessage("AP00",protocolAPIHelper.AP00(paramRuntime)));\r
-    //发送心跳包\r
-    connection.send(protocolAPIHelper.genStringMessage("heart",protocolAPIHelper.AP03(paramRuntime)));\r
+    Observable.timer(500L, TimeUnit.MILLISECONDS).subscribe(new Action1<Long>() {\r
+      public void call(Long param1Long) {\r
+        connection.send(protocolAPIHelper.genStringMessage("AP00",protocolAPIHelper.AP00(paramRuntime)));\r
+\r
+      }\r
+    });\r
+     //发送心跳包\r
+    Observable.timer(5500L, TimeUnit.MILLISECONDS).subscribe(new Action1<Long>() {\r
+      public void call(Long param1Long) {\r
+        connection.send(protocolAPIHelper.genStringMessage("heart",protocolAPIHelper.AP03(paramRuntime)));\r
+      }\r
+    });\r
 \r
     isConnected = true;\r
     this.firstReConnected = true;\r
@@ -185,7 +198,7 @@ public class KeepAlive extends AbstractConnectionService {
 //    UpdateHeartBeatTimeout();\r
 //    if (this.reCycleTimes == 0 && this.currentReConnectInterval != 11){\r
 //    paramNettyConnection.send(protocolAPIHelper.genStringMessage("AP00",protocolAPIHelper.AP00(paramRuntime)));\r
-    paramNettyConnection.send(protocolAPIHelper.genStringMessage("heart",protocolAPIHelper.AP03(paramRuntime)));\r
+      paramNettyConnection.send(protocolAPIHelper.genStringMessage("heart",protocolAPIHelper.AP03(paramRuntime)));\r
 \r
     //    }\r
 \r
@@ -204,6 +217,12 @@ public class KeepAlive extends AbstractConnectionService {
 //      Deliver.triggerSendThread(); //链接上就尝试清除 buffer中的数据\r
       CoreService.getInstance().stopConnectionRetryTimer();\r
 \r
+      if (CoreService.needLocateInAfterHeartBeat==true){\r
+        //第一次启动或者系统Close后重连的时候,重置LocationCycle\r
+        CoreService.needLocateInAfterHeartBeat=false;\r
+        LocationClient.setForceLocation(1);\r
+        CoreService.getInstance().setLocationAlarm(paramRuntime.getLocationInstance().getWorkingMod());\r
+      }\r
     }\r
     return false;\r
   }\r
index 56d82a7..0b0a321 100644 (file)
@@ -7,6 +7,7 @@ import android.os.SystemClock;
 import android.util.Log;\r
 \r
 import com.enqualcomm.support.Config;\r
+import com.enqualcomm.support.Constants;\r
 import com.enqualcomm.support.bean.Contact;\r
 import com.enqualcomm.support.bean.Runtime;\r
 import com.enqualcomm.support.CoreService;\r
@@ -16,10 +17,12 @@ public class AlarmWakeUp {
   \r
   public static void isNeedWakeUpAlarm(Runtime runtime) {\r
     long l = SystemClock.elapsedRealtime();\r
-    int i = Config.getAlarmCycle(runtime.getContextProxy().context);\r
-    if (l - lastAlarmTime > ((i + 1) * 60 * 1000)) {\r
+//    int i = Config.getAlarmCycle(runtime.getContextProxy().context);\r
+    int i = Config.getLocationCycle(runtime.getContextProxy().context);\r
+    if (l - lastAlarmTime > ((i + 1) * 60 * 1000)) { //达到cycle时间则唤醒CoreService并发送定位消息\r
       ComponentName componentName = new ComponentName("com.enqualcomm.support", "com.enqualcomm.support.CoreService");\r
-      Intent intent = (new Intent(CoreService.ACTION_ALARM)).setComponent(componentName);\r
+//      Intent intent = (new Intent(CoreService.ACTION_ALARM)).setComponent(componentName);\r
+      Intent intent = (new Intent(Constants.ACTION_LOCATION_ALARM)).setComponent(componentName);\r
       (runtime.getContextProxy()).context.startService(intent);\r
 \r
       StringBuilder stringBuilder = new StringBuilder();\r
index af5d14c..fbad60d 100644 (file)
@@ -56,7 +56,7 @@ public class NettyConnection implements Connection {
                         switch (type){\r
                             case BP00:\r
                                 API.handleBP00(cmd);\r
-                                Logger.i("服务器收到心跳AP00");\r
+                                Logger.i("服务器收到登录包AP00");\r
                                 DeliverCMDMessageToSystem("BP00",cmd);//通知下面线程状态变化\r
                                 break;\r
                             case BP01:\r
@@ -65,7 +65,7 @@ public class NettyConnection implements Connection {
                                 break;\r
                             case BP03:\r
                                 API.handleBP03(cmd);\r
-                                Logger.i("服务器收到心跳AP03");\r
+                                Logger.i("服务器收到心跳包AP03");\r
                                 DeliverCMDMessageToSystem("BP03",cmd);//通知下面线程状态变化\r
                                 break;\r
 \r