From: snicker Date: Mon, 6 Apr 2020 15:08:39 +0000 (+0800) Subject: 1、由于系统时间变化会严重影响Timer的使用。因此把所有Timer都改为了 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=af6f3ea83b2184c8a6cc4862fafc87322736e223;p=protocol_srv.git 1、由于系统时间变化会严重影响Timer的使用。因此把所有Timer都改为了 ScheduledThreadPoolExecutor 2、修改ResetStepCount 消息处理,加入打印信息。 --- diff --git a/app/src/main/java/com/enqualcomm/support/CoreService.java b/app/src/main/java/com/enqualcomm/support/CoreService.java index 8ce396bc..3c723b11 100644 --- a/app/src/main/java/com/enqualcomm/support/CoreService.java +++ b/app/src/main/java/com/enqualcomm/support/CoreService.java @@ -72,8 +72,7 @@ import android.os.BatteryManager; import android.telephony.TelephonyManager; import java.util.Random; -import java.util.Timer; -import java.util.TimerTask; +import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; import static android.app.PendingIntent.FLAG_UPDATE_CURRENT; @@ -637,7 +636,7 @@ public class CoreService extends Service { stringBuilder.append(paramInt2); ICLogger.i(stringBuilder.toString()); // if (ACTION_ALARM.equals(paramIntent.getAction())) { - if (ACTION_LOCATION_ALARM.equals(paramIntent.getAction())){ + if (ACTION_LOCATION_ALARM.equals(paramIntent.getAction())) { // if (cmcm_call_eiot_into_powersave_mode() == 1) { @@ -652,7 +651,7 @@ public class CoreService extends Service { // alarmCycle = Config.getAlarmCycle(this); // } AlarmWakeUp.setAlarmWakeUpTime(); - boolean screenon = ((PowerManager)getSystemService(POWER_SERVICE)).isScreenOn(); + boolean screenon = ((PowerManager) getSystemService(POWER_SERVICE)).isScreenOn(); if (!screenon) { SimSignalUtil.send_at_to_update_lbs(this.runtime); } @@ -684,76 +683,75 @@ public class CoreService extends Service { if (Config.LOG_TOFILE) ICLogger.logToFile("alarmCycle", stringBuilder1.toString()); // this.locationClient.triggerLocationProcess(); - } else { + } else if (Constants.SLEEP_ALARM.equals(paramIntent.getAction())) { StringBuilder stringBuilder1; - if (Constants.SLEEP_ALARM.equals(paramIntent.getAction())) { - ICLogger.i("SLEEP_ALARM"); - is_allowed_in_sleep_mode = 1; - if (Config.LOG_TOFILE) ICLogger.logToFile("alarmCycle", "SLEEP_ALARM alarmCycle"); - setSleepAlarm(); - boolean bool = ((PowerManager)getSystemService(POWER_SERVICE)).isScreenOn(); - stringBuilder1 = new StringBuilder(); - stringBuilder1.append("ifOpen = "); - stringBuilder1.append(bool); - ICLogger.i(stringBuilder1.toString()); - if (!bool) { - is_in_sleep_mode = true; - if (this.mKeepAlive != null) - this.mKeepAlive.setSleepMode(true); + ICLogger.i("SLEEP_ALARM"); + is_allowed_in_sleep_mode = 1; + if (Config.LOG_TOFILE) ICLogger.logToFile("alarmCycle", "SLEEP_ALARM alarmCycle"); + setSleepAlarm(); + boolean bool = ((PowerManager) getSystemService(POWER_SERVICE)).isScreenOn(); + stringBuilder1 = new StringBuilder(); + stringBuilder1.append("ifOpen = "); + stringBuilder1.append(bool); + ICLogger.i(stringBuilder1.toString()); + if (!bool) { + is_in_sleep_mode = true; + if (this.mKeepAlive != null) + this.mKeepAlive.setSleepMode(true); // this.connection.close(); - return Service.START_STICKY; - } - } else { - if (Constants.WAKE_ALARM.equals(paramIntent.getAction())) { - if (is_in_sleep_mode) { - is_in_sleep_mode = false; - if (Config.LOG_TOFILE) ICLogger.logToFile("alarmCycle", "WAKE_ALARM alarmCycle"); - if (this.mKeepAlive != null) - this.mKeepAlive.setSleepMode(false); - wakeUpFromSleep(); - } - is_allowed_in_sleep_mode = 1; - setWakeAlarm(); - return Service.START_STICKY; - }else if (HEART_ALARM.equals(paramIntent.getAction())) { - if (this.mKeepAlive != null) { - - if (connection.isServerConnected()&& runtime.isServerProtocolConnected()) { - this.mKeepAlive.onHeartAlarm(this.connection, this.runtime); - }else{ - ICLogger.i("check 发送心跳包时,如果发现服务器没有响应,或者socket连接,则重新尝试连接服务器!"); - connection.disconnectServer(); - this.startConnectionRetryTimer(); - } - setHeartAlarm(); - if (Config.LOG_TOFILE) ICLogger.logToFile("alarmCycle", "HEART_ALARM alarmCycle " ); - return Service.START_STICKY; - } - } else if (STEP_COUNT_ALARM_ACTION.equals(paramIntent.getAction())) { - ICLogger.i("Reset Count At 00:00 "); - //update stepCount and broadcast before reset - this.locationClient.updateStepCount(); - runtime.getContextProxy().brodcastResetStepCount(runtime.getTotalStepCount()); - resetStepCount(); - setCleanStepCountAlarm(); - - return Service.START_STICKY; - }else { - if (ACTION_HEATR_RATE_START.equals(paramIntent.getAction())) { - - //此处消息从timer来 - setHeartRateDetectAlarm(runtime.getPpgTestCycle()); - - }else if(ACTION_SEND_EMEGENCY_LOCATION_STOP.equals(paramIntent.getAction())){ - //stop Emegency location Stop - Config.loadModCycleSettings(runtime); //回复之前的 工作模式即可 - setLocationAlarm(runtime.getLocationInstance().getWorkingMod());//同时重置alarm并触发定位 - } - this.invokeHandlerServiceChain.processUserRequest(paramIntent, this.connection, this.runtime); -// } + return Service.START_STICKY; + } + } else if (Constants.WAKE_ALARM.equals(paramIntent.getAction())) { + if (is_in_sleep_mode) { + is_in_sleep_mode = false; + if (Config.LOG_TOFILE) + ICLogger.logToFile("alarmCycle", "WAKE_ALARM alarmCycle"); + if (this.mKeepAlive != null) + this.mKeepAlive.setSleepMode(false); + wakeUpFromSleep(); + } + is_allowed_in_sleep_mode = 1; + setWakeAlarm(); + return Service.START_STICKY; + } else if (HEART_ALARM.equals(paramIntent.getAction())) { + if (this.mKeepAlive != null) { + + if (connection.isServerConnected() && runtime.isServerProtocolConnected()) { + this.mKeepAlive.onHeartAlarm(this.connection, this.runtime); + } else { + ICLogger.i("check 发送心跳包时,如果发现服务器没有响应,或者socket连接,则重新尝试连接服务器!"); + connection.disconnectServer(); + this.startConnectionRetryTimer(); } + setHeartAlarm(); + if (Config.LOG_TOFILE) + ICLogger.logToFile("alarmCycle", "HEART_ALARM alarmCycle "); + return Service.START_STICKY; } + } else if (STEP_COUNT_ALARM_ACTION.equals(paramIntent.getAction())) { + ICLogger.i("Reset Count At 00:00 "); + //update stepCount and broadcast before reset + this.locationClient.updateStepCount(); + runtime.getContextProxy().brodcastResetStepCount(runtime.getTotalStepCount()); + resetStepCount(); + setCleanStepCountAlarm(); + return Service.START_STICKY; + } else if (ACTION_HEATR_RATE_START.equals(paramIntent.getAction())) { + + //此处消息从timer来 + setHeartRateDetectAlarm(runtime.getPpgTestCycle()); + + + } else if (ACTION_SEND_EMEGENCY_LOCATION_STOP.equals(paramIntent.getAction())) { + //stop Emegency location Stop + Config.loadModCycleSettings(runtime); //回复之前的 工作模式即可 + setLocationAlarm(runtime.getLocationInstance().getWorkingMod());//同时重置alarm并触发定位 + } + + + this.invokeHandlerServiceChain.processUserRequest(paramIntent, this.connection, this.runtime); + } return Service.START_NOT_STICKY; } @@ -866,7 +864,7 @@ public class CoreService extends Service { private static final String TAG = "ICSrv." + CoreService.class.getSimpleName(); - private Timer mTimer_retry_connect=null; + private ScheduledThreadPoolExecutor mTimer_retry_connect=null; private static int retry_connect_count=0; //当前重试次数 private static int retry_connect_max_times=6; //最大重试次数 6次 , 即只重试2分钟,下一次重试将在下一个心跳包时进行。 @@ -886,7 +884,7 @@ public class CoreService extends Service { // if (SimSignalUtil.checkNet(runtime.getContextProxy().context) ) { stopConnectionRetryTimer(); if (mTimer_retry_connect == null) { - mTimer_retry_connect = new Timer(); + mTimer_retry_connect = new ScheduledThreadPoolExecutor(2); } //如果开始进行连接重 // { @@ -894,12 +892,12 @@ public class CoreService extends Service { retry_connect_count=0; KeepAlive.isConnected = false; if (mTimer_retry_connect != null) { - mTimer_retry_connect.schedule(new TimerTask() { + mTimer_retry_connect.scheduleAtFixedRate(new Runnable() { @Override public void run() { ReConnectToServer(); } - }, 5000, 20000); //每次都是断网才需要重连,delay 5秒重连,并且每20秒重试一次 + }, 5000, 20000, TimeUnit.MILLISECONDS); //每次都是断网才需要重连,delay 5秒重连,并且每20秒重试一次 } // } } @@ -948,7 +946,7 @@ public class CoreService extends Service { public void stopConnectionRetryTimer(){ if (mTimer_retry_connect !=null){ - mTimer_retry_connect.cancel(); + mTimer_retry_connect.shutdown(); mTimer_retry_connect.purge(); mTimer_retry_connect = null; } diff --git a/app/src/main/java/com/enqualcomm/support/GPSActivity.java b/app/src/main/java/com/enqualcomm/support/GPSActivity.java index c4a644f0..09c138c6 100644 --- a/app/src/main/java/com/enqualcomm/support/GPSActivity.java +++ b/app/src/main/java/com/enqualcomm/support/GPSActivity.java @@ -3,8 +3,6 @@ package com.enqualcomm.support; import android.graphics.Color; import android.graphics.Rect; import android.os.Bundle; -import android.os.Handler; -import android.os.Message; import android.os.PowerManager; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; @@ -21,9 +19,6 @@ import com.enqualcomm.support.utils.WakeLockUtil; import java.util.ArrayList; import java.util.List; -import java.util.Timer; -import java.util.TimerTask; - public class GPSActivity extends AppCompatActivity implements location_callback { private RecyclerView mRv; @@ -33,40 +28,8 @@ public class GPSActivity extends AppCompatActivity implements location_callback private TextView mHoop; private TextView mSearchCount; private boolean showmessage=false; - private Timer timer; final LocationSnrAdapter adapter = new LocationSnrAdapter(testSnrEntriyDate(null)); -// -// Handler handler=new Handler(new Handler.Callback() { -// @Override -// public boolean handleMessage(Message message) { -// -// -// StringBuilder sb=new StringBuilder(); -// try { -// -// if (showmessage) { -// ICLocation location=CoreService.getInstance().runtime.getLocationInstance(); -// List gpslist =location.getNumSatelliteList(); -// adapter.updateLocationValue(testSnrEntriyDate(gpslist)); -// String fixed=(location.getLocationStat()==ICLocation.LOCATION_STAT.LOCATION_FIXED)? -// "Fixed":(location.getLocationStat()==ICLocation.LOCATION_STAT.LOCATION_OPEN)? -// "Opened":(location.getLocationStat()==ICLocation.LOCATION_STAT.LOCATION_GPS_TIEMOUT)? -// "Timeout":"Closed"; -// String satlites=new StringBuilder().append(location.getLocation().used_gps_numbs).append("/").append(gpslist!=null?location.getNumSatelliteList().size():0).toString(); -// String locationTime=location.getLocationTime(); -// mFix.setText(fixed); -// mStar.setText(satlites); -// mHoop.setText(String.valueOf(location.getLocation().hdop)); -// } -// -// }catch(Exception e){ -// e.printStackTrace(); -// } -// -// -// return false; -// } -// }); + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -144,15 +107,6 @@ public class GPSActivity extends AppCompatActivity implements location_callback @Override protected void onResume() { super.onResume(); -// TimerTask tmt=new TimerTask() { -// @Override -// public void run() { -// handler.sendEmptyMessage(0); -// } -// }; -// timer=new Timer(); -// timer.schedule(tmt,0,2000); -// showmessage=true; NMEAListener.set_callback(this); if (screenOnWakelock==null) screenOnWakelock = WakeLockUtil.getScreenOnWakeLock(this,GPSActivity.class.getSimpleName()); @@ -161,11 +115,6 @@ public class GPSActivity extends AppCompatActivity implements location_callback @Override protected void onPause() { super.onPause(); -// if (timer!=null) { -// timer.cancel(); -// timer.purge(); -// timer = null; -// } showmessage=false; if(screenOnWakelock!=null) { if (screenOnWakelock.isHeld()) { diff --git a/app/src/main/java/com/enqualcomm/support/LocationClient.java b/app/src/main/java/com/enqualcomm/support/LocationClient.java index d2f739f9..b6f0b150 100644 --- a/app/src/main/java/com/enqualcomm/support/LocationClient.java +++ b/app/src/main/java/com/enqualcomm/support/LocationClient.java @@ -33,11 +33,10 @@ import com.enqualcomm.support.utils.SimSignalUtil; import com.enqualcomm.support.bean.Runtime; import com.enqualcomm.support.utils.TimeUtil; -import java.util.Timer; -import java.util.TimerTask; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.LinkedBlockingDeque; +import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.ReentrantLock; @@ -105,7 +104,7 @@ public class LocationClient { private LBSHelper mLbsHelper; - private Timer mTimer=null; + private ScheduledThreadPoolExecutor mTimer=null; private int mPedometer2; @@ -268,17 +267,16 @@ public class LocationClient { timeout=false; startCheckTime= System.currentTimeMillis(); //延时2秒执行发送“读取定位”消息 - if (mTimer==null) mTimer=new Timer(); - mTimer.schedule(new MyTimerTask(), 1000L,1000L); + if (mTimer==null) mTimer=new ScheduledThreadPoolExecutor(2); + mTimer.scheduleAtFixedRate(new Runnable() { + @Override + public void run() { + mhandler.sendEmptyMessage(msgWhat_WaitAndSendLocation); + } + }, 1000L, 1000L,TimeUnit.MILLISECONDS); // AlarmManager alarmManager=(AlarmManager)runtime.getContextProxy().context.getSystemService(Context.ALARM_SERVICE); // AlarmHelper.setAlarm(alarmManager,0,1,); } - class MyTimerTask extends TimerTask { - public void run() { - //发送读取计步消息 - mhandler.sendEmptyMessage(msgWhat_WaitAndSendLocation); - } - }; @@ -344,7 +342,7 @@ public class LocationClient { if ((startCheckTime!=0L)&& (timeCost> 50*1000L)){ //有时timer计数不准,则根据实际时间计算 ICLogger.i("waitAndSendLocation "+timeCost+"> 50000ms timeout"); - timeout=true; + //timeout=true; } // lbs only +timeout, lbs+wifi+gpsNosignal, libs+ , lbs+gps+wifi, Timeout can override wifi and gps @@ -407,7 +405,7 @@ public class LocationClient { if ((startCheckTime!=0L)&& (timeCost> 20*1000L)){ //有时timer计数不准,则根据实际时间计算 ICLogger.i("waitAndSendLocation "+timeCost+"> 20000ms timeout"); - timeout=true; + // timeout=true; } if ((lbs_ok && timeout==true) ||(lbs_ok && wifi_ok )){ @@ -453,7 +451,8 @@ public class LocationClient { public void stopCheckLocationResult(){ ICLogger.i("stopCheckLocationResult!"); if (mTimer!=null){ - mTimer.cancel(); + mTimer.shutdown(); + mTimer.purge(); mTimer=null; } isLocating = false; diff --git a/app/src/main/java/com/enqualcomm/support/MainActivity.java b/app/src/main/java/com/enqualcomm/support/MainActivity.java index ced4dba3..b61ec786 100644 --- a/app/src/main/java/com/enqualcomm/support/MainActivity.java +++ b/app/src/main/java/com/enqualcomm/support/MainActivity.java @@ -24,8 +24,7 @@ import com.ic.jni.ICJniUtils; import com.enqualcomm.support.CoreService; import com.enqualcomm.support.utils.ICLogger; -import java.util.Timer; -import java.util.TimerTask; +import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; import rx.Observable; @@ -37,7 +36,7 @@ public class MainActivity extends AppCompatActivity { TextView tv; private boolean showmessage=false; - private Timer timer; + private ScheduledThreadPoolExecutor timer; Handler handler=new Handler(new Handler.Callback() { @Override public boolean handleMessage(Message message) { @@ -116,14 +115,13 @@ public class MainActivity extends AppCompatActivity { @Override protected void onResume() { super.onResume(); - TimerTask tmt=new TimerTask() { + timer=new ScheduledThreadPoolExecutor(2); + timer.scheduleAtFixedRate(new Runnable() { @Override public void run() { handler.sendEmptyMessage(0); } - }; - timer=new Timer(); - timer.schedule(tmt,0,2000); + }, 0, 2000,TimeUnit.MILLISECONDS); showmessage=true; } @@ -131,7 +129,7 @@ public class MainActivity extends AppCompatActivity { protected void onPause() { super.onPause(); if (timer!=null) { - timer.cancel(); + timer.shutdown(); timer.purge(); timer = null; } diff --git a/app/src/main/java/com/enqualcomm/support/service/HeartRateManager.java b/app/src/main/java/com/enqualcomm/support/service/HeartRateManager.java index b78e8f89..b3a18817 100644 --- a/app/src/main/java/com/enqualcomm/support/service/HeartRateManager.java +++ b/app/src/main/java/com/enqualcomm/support/service/HeartRateManager.java @@ -27,8 +27,8 @@ import com.enqualcomm.support.utils.NettyConnection; import com.enqualcomm.support.utils.SimSignalUtil; import com.enqualcomm.support.utils.TimeUtil; -import java.util.Timer; -import java.util.TimerTask; +import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.concurrent.TimeUnit; import static com.enqualcomm.support.Constants.ACTION_BROADCAST_PPG; import static com.enqualcomm.support.Constants.ACTION_HEATR_RATE_START; @@ -44,9 +44,8 @@ public class HeartRateManager extends AbstractInvokeHandlerService { private Runtime runtime; private NettyConnection connection; - private TimerTaskPPG timerTaskPPG; - private Timer timerPPG; + private ScheduledThreadPoolExecutor timerPPG=null; private static Handler mHandler=null; @@ -134,13 +133,6 @@ public class HeartRateManager extends AbstractInvokeHandlerService { runtime.getContextProxy().context.unregisterReceiver(PPGStartReceiver); } - public class TimerTaskPPG extends TimerTask{ - @Override - public void run() { - doPPGtest(); - } - }; - int PPG; int BPH; int BPL; @@ -234,9 +226,14 @@ public class HeartRateManager extends AbstractInvokeHandlerService { isTimerStarted=true; ICJniUtils.enablePPG(); getPPGWakeLock(); - timerTaskPPG = new TimerTaskPPG(); - timerPPG = new Timer(); - timerPPG.scheduleAtFixedRate(timerTaskPPG,0, 1000); //1 秒更新一次数据 + + timerPPG = new ScheduledThreadPoolExecutor(2); + timerPPG.scheduleAtFixedRate(new Runnable() { + @Override + public void run() { + doPPGtest(); + } + }, 0, 1000, TimeUnit.MILLISECONDS); //1 秒更新一次数据 } } @@ -244,7 +241,8 @@ public class HeartRateManager extends AbstractInvokeHandlerService { public void stopPPG(){ if( isTimerStarted ) { - timerPPG.cancel(); + timerPPG.shutdown(); + timerPPG.purge(); isTimerStarted=false; } ICJniUtils.disablePPG(); diff --git a/app/src/main/java/com/enqualcomm/support/service/KeepAlive.java b/app/src/main/java/com/enqualcomm/support/service/KeepAlive.java index 4ae50ab0..f2e6a751 100644 --- a/app/src/main/java/com/enqualcomm/support/service/KeepAlive.java +++ b/app/src/main/java/com/enqualcomm/support/service/KeepAlive.java @@ -24,18 +24,13 @@ import com.enqualcomm.support.utils.ServiceUtil; import com.enqualcomm.support.bean.Runtime; import com.enqualcomm.support.utils.SimSignalUtil; -import java.util.Timer; -import java.util.TimerTask; +import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; import rx.Observable; import rx.Subscription; import rx.functions.Action1; -import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; -//import static com.eiot.watch_lib.LauncherCtrl.STATUS_BAR_STATE_SERVER_CONNECTED_OFF; -//import static com.eiot.watch_lib.LauncherCtrl.STATUS_BAR_STATE_SERVER_CONNECTED_ON; - public class KeepAlive extends AbstractConnectionService { private static final long HEARTBEAT_TIMEOUT = 660000L; private static String TAG = KeepAlive.class.getSimpleName(); @@ -44,23 +39,9 @@ public class KeepAlive extends AbstractConnectionService { public static boolean isConnected = false; private static boolean isInSleepMode = false; - - private static int mFlag = 30; - + Connection connection; - private int currentReConnectInterval = 11; - - private boolean firstReConnected = true; - - private long idleTimeMillis; - - private int isFirstAsjust; - - private int lastReConnectInterval = -1; - - private int lastReConnectionNumber = -1; - Context mContext; NetworkObservable mNetworkObservable = new NetworkObservable(); @@ -72,14 +53,6 @@ public class KeepAlive extends AbstractConnectionService { private Subscription mSubscription; private int reConnectionNumber; - - private int reCycleTimes; - - private int timeout = 660; - - private int totalAdjustTimes; - - private int whichTimeAdjust; //服务器收到AP03 会返回BP03,如果PB03 规定时间没收到,则认为发送心跳失败,需要重发, private boolean is_heartBeat_send_success=false; @@ -89,30 +62,28 @@ public class KeepAlive extends AbstractConnectionService { //每次retry发送心跳的间隔为20秒 private int heartBeatRetryTimeout=20; //监测 心跳服务器响应的timer - private Timer mTimer_check_server_response=null; - + private ScheduledThreadPoolExecutor scheduled = null; + private Runnable CheckSrvResponseTimerTask=new Runnable() { + @Override + public void run() { + checkSrvResponse(); + } + }; public void startResponseCheckTimer(){ //联网再重试连接服务器 if (SimSignalUtil.checkNet(mRuntime.getContextProxy().context) ) { stopResponseCheckTimer(); - if (mTimer_check_server_response == null) { - mTimer_check_server_response = new Timer(); + if (scheduled == null) { + scheduled = new ScheduledThreadPoolExecutor(2); } - //开始检测重新计数 hearBeatResendCount=0; //如果开始进行连接重 // { // 试,证明网络断开的,那么KeepAlive也需要重连(心跳包) - - if (mTimer_check_server_response != null) { - mTimer_check_server_response.schedule(new TimerTask() { - @Override - public void run() { - checkSrvResponse(); - } - }, heartBeatRetryTimeout*1000, heartBeatRetryTimeout*1000); //delay 3秒先检查一次,然后每5秒重试一次 + if (scheduled != null) { + scheduled.scheduleAtFixedRate(CheckSrvResponseTimerTask , heartBeatRetryTimeout*1000, heartBeatRetryTimeout*1000,TimeUnit.MILLISECONDS); //delay 3秒先检查一次,然后每5秒重试一次 } } } @@ -154,9 +125,10 @@ public class KeepAlive extends AbstractConnectionService { } public void stopResponseCheckTimer(){ - if (mTimer_check_server_response !=null){ - mTimer_check_server_response.cancel(); - mTimer_check_server_response = null; + if (scheduled !=null){ + scheduled.shutdown(); + scheduled.purge(); + scheduled = null; } } @@ -166,21 +138,6 @@ public class KeepAlive extends AbstractConnectionService { ICLogger.i("onAlarmClock"); - long l = SystemClock.elapsedRealtime(); - -// //如果 没有连接成功 或者 时间超过了11分钟 ,则进行重新连接服务 -// if (!isConnected || l - this.idleTimeMillis > 660000L) { -// StringBuilder stringBuilder = new StringBuilder(); -// stringBuilder.append("重连"); -// stringBuilder.append(isConnected); -// ICLogger.i(stringBuilder.toString()); -// if (!isConnected && this.firstReConnected) { -// this.reConnectionNumber++; -// this.firstReConnected = false; -// } -// -// CoreService.getInstance().ReConnectToServer(); -// } } public void onAttach(final Connection connection, final Runtime runtime) { @@ -272,8 +229,8 @@ public class KeepAlive extends AbstractConnectionService { isConnected = true; - this.firstReConnected = true; - this.idleTimeMillis = SystemClock.elapsedRealtime(); +// this.firstReConnected = true; +// this.idleTimeMillis = SystemClock.elapsedRealtime(); return false; } @@ -302,7 +259,7 @@ public class KeepAlive extends AbstractConnectionService { } public boolean onReceive(StringMessage paramStringMessage, Connection paramConnection, Runtime paramRuntime) { - this.idleTimeMillis = SystemClock.elapsedRealtime(); +// this.idleTimeMillis = SystemClock.elapsedRealtime(); if ("heart".equals(paramStringMessage.cmd())) { AlarmWakeUp.isNeedWakeUpAlarm(paramRuntime); return true; diff --git a/app/src/main/java/com/enqualcomm/support/utils/AlarmHelper.java b/app/src/main/java/com/enqualcomm/support/utils/AlarmHelper.java index 1c9dbcde..7a1fca78 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/AlarmHelper.java +++ b/app/src/main/java/com/enqualcomm/support/utils/AlarmHelper.java @@ -62,6 +62,7 @@ public class AlarmHelper { Intent intent = new Intent(context, com.enqualcomm.support.CoreService.class); intent.setAction(paramString); PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); + alarmManager.cancel(pendingIntent); long currentMS = System.currentTimeMillis(); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.HOUR_OF_DAY, hour); @@ -71,7 +72,6 @@ public class AlarmHelper { long targetMS = targetMStmp; if (targetMStmp < currentMS) targetMS = targetMStmp + ONE_DAY; - alarmManager.cancel(pendingIntent); alarmManager.setExact(AlarmManager.RTC_WAKEUP, targetMS, pendingIntent); } diff --git a/app/src/main/java/com/enqualcomm/support/utils/ContextProxy.java b/app/src/main/java/com/enqualcomm/support/utils/ContextProxy.java index d566d2ea..4840c926 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/ContextProxy.java +++ b/app/src/main/java/com/enqualcomm/support/utils/ContextProxy.java @@ -286,6 +286,7 @@ public class ContextProxy { Intent intent = new Intent(); intent.putExtra(PED_TOTAL_KEY, StepCount); intent.setAction(PED_FINISH_ACTION); + ICLogger.i("send broadcast action "+PED_FINISH_ACTION+", key "+PED_TOTAL_KEY+" value "+StepCount); this.context.sendBroadcast(intent); } public void sendBrodcast(String action,Intent intent){ diff --git a/app/src/main/java/com/enqualcomm/support/utils/SimSignalUtil.java b/app/src/main/java/com/enqualcomm/support/utils/SimSignalUtil.java index 613edd57..c5d0a9ea 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/SimSignalUtil.java +++ b/app/src/main/java/com/enqualcomm/support/utils/SimSignalUtil.java @@ -228,7 +228,7 @@ public class SimSignalUtil { intent.putExtra("command", "AT+SFUN=2"); //重新初始化sim卡 intent.putExtra("arg2", ""); ( runtime.getContextProxy()).context.sendBroadcast(intent); - ICLogger.i("send_at_to_update_lbs "); + ICLogger.i("send_at_to_reset_simcard "); } public static void send_at_to_update_lbs(Runtime runtime) {