\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
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
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
}\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
\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
//获取天气时间\r
setWeatherAlarm();\r
\r
+\r
//获取定位时间\r
+ needLocateInAfterHeartBeat=true;\r
setLocationAlarm(runtime.getLocationInstance().getWorkingMod());\r
\r
//备份DB数据到sd cache目录,为调试方便\r
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
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
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
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
setLocationAlarm(runtime.getLocationInstance().getWorkingMod());//同时重置alarm并触发定位\r
}\r
this.invokeHandlerServiceChain.processUserRequest(paramIntent, this.connection, this.runtime);\r
- }\r
+// }\r
}\r
}\r
}\r
}\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
public void run() {\r
ReConnectToServer();\r
}\r
- }, 0, 5000); //每5秒重试一次\r
+ }, 0, 20000); //每20秒重试一次\r
}\r
}\r
}\r
\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
}\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
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
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
\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
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
// 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
// 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
// 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