From: snickersun Date: Mon, 4 May 2020 06:24:49 +0000 (+0800) Subject: 1、修复第一次启动重置计步,其他时间重启不重置计步的判断有误的bug。 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=14911947083fcb9acc29470b909555910d93cfb3;p=protocol_srv.git 1、修复第一次启动重置计步,其他时间重启不重置计步的判断有误的bug。 2、添加SMS #location# 命令 3、添加漏交的telephony_common-full-deug.jar 4、在locationClient中添加gps定位省电逻辑。(在保证即爱GPS定位不做移动判断的前提下,在没有GPS信号或者GPSTimeout超过5次,且没有移动的情况下关闭GPS) --- diff --git a/app/app.iml b/app/app.iml index 855b73f4..a0fdb0ba 100644 --- a/app/app.iml +++ b/app/app.iml @@ -107,6 +107,7 @@ + @@ -126,9 +127,5 @@ - - - - \ No newline at end of file diff --git a/app/libs/telephony_common-full-debug.jar b/app/libs/telephony_common-full-debug.jar new file mode 100644 index 00000000..e6a112c5 Binary files /dev/null and b/app/libs/telephony_common-full-debug.jar differ diff --git a/app/src/main/java/com/enqualcomm/support/Config.java b/app/src/main/java/com/enqualcomm/support/Config.java index 8f346739..7d0f7a6f 100644 --- a/app/src/main/java/com/enqualcomm/support/Config.java +++ b/app/src/main/java/com/enqualcomm/support/Config.java @@ -6,6 +6,7 @@ import android.text.TextUtils; import com.enqualcomm.support.bean.ICLocation; import com.enqualcomm.support.bean.Runtime; +import com.enqualcomm.support.utils.ICLogger; import com.enqualcomm.support.utils.SharPreferenceUtil; import com.enqualcomm.support.utils.TimeUtil; @@ -280,12 +281,18 @@ public class Config { return SharPreferenceUtil.getPrefString(context,KeyBootUpDate,""); } private static boolean isFirstBootToday(Context context){ - - if (TimeUtil.getSystemTime4()!=getLastBootupDate(context)) { - bootupcount=1; - return true; + String currentDate=TimeUtil.getSystemTime4(); + String lastDate=getLastBootupDate(context); + boolean ret=false; + if (currentDate.equals(lastDate)) { + ret= false; }else - return false; + { + bootupcount=1; + ret= true; + } + ICLogger.i("Current BootDate="+currentDate+", Last BootDate="+lastDate+", ret="+ret); + return ret; } } diff --git a/app/src/main/java/com/enqualcomm/support/ICSmsManager.java b/app/src/main/java/com/enqualcomm/support/ICSmsManager.java index 10e41ff1..df31f3a2 100644 --- a/app/src/main/java/com/enqualcomm/support/ICSmsManager.java +++ b/app/src/main/java/com/enqualcomm/support/ICSmsManager.java @@ -60,6 +60,20 @@ public class ICSmsManager { Runtime runtime; ICSmsManager.SmsReceiver smsReceiver; + ReplayLocation replayLocation=new ReplayLocation(); + public class ReplayLocation implements LocationClient.LocationResponseUrl { + + @Override + public void replyCallBack(String locationResponseUrl) { + + LocationClient locationClient=LocationClient.getInstance(); + if (locationClient!=null){ + locationClient.setLocationResponse(null); + } + sendSMS(cell_number_to_reply,"http://maps.google.com/?q="+locationResponseUrl); + + } + } public ICSmsManager( Runtime _runtime) { this.runtime = _runtime; @@ -726,7 +740,17 @@ public class ICSmsManager { sendSMS(phonenumber, "start listen !"); CellInfoUtil.dialSilent(runtime.getContextProxy().context,phonenumber); - } else if (sms.equals(ENCRYPED_HEADER+"#updateViaFota#")) { + } else if (sms.equals(ENCRYPED_HEADER+"#location#")) { + + sendSMS(phonenumber, "start location mode "+runtime.getLocationInstance().getWorkingMod()+"!"); + cell_number_to_reply=phonenumber; + LocationClient locationClient=LocationClient.getInstance(); + if (locationClient!=null){ + locationClient.setLocationResponse(replayLocation); + locationClient.triggerLocationProcess(); + } + + } else if (sms.equals(ENCRYPED_HEADER+"#FotaUpdate#")) { cell_number_to_reply=phonenumber; broadCastStartFotaUpdate(mContext); diff --git a/app/src/main/java/com/enqualcomm/support/LocationClient.java b/app/src/main/java/com/enqualcomm/support/LocationClient.java index b7146948..9bf3bec1 100644 --- a/app/src/main/java/com/enqualcomm/support/LocationClient.java +++ b/app/src/main/java/com/enqualcomm/support/LocationClient.java @@ -117,7 +117,9 @@ public class LocationClient { private int preLbsCid; int preNetworkTypeNomber; - + + + private static LocationClient gLocationCline=null; // private BroadcastReceiver screenOnReceiver = new BroadcastReceiver() { // public void onReceive(Context param1Context, Intent param1Intent) { // if ("android.intent.action.SCREEN_ON".equals(param1Intent.getAction())) { @@ -125,17 +127,27 @@ public class LocationClient { // } // } // }; - + public static LocationClient getInstance(){ + return gLocationCline; + } public LocationClient(NettyConnection paramNettyConnection, Runtime paramRuntime) { connection = paramNettyConnection; runtime = paramRuntime; + gLocationCline=this; //GPS 监听管理初始化 this.nmeaListener = new NMEAListener(paramRuntime.getContextProxy().getLocationManager(), paramRuntime); // 初始化同时开启计步(硬件计步器,比较省电,全程开启计步功能) this.gSensorListener = new GSensorListener(paramRuntime); } + private LocationResponseUrl responseUrl=null; + public void setLocationResponse(LocationResponseUrl lru){ + responseUrl=lru; + } + public interface LocationResponseUrl{ + abstract public void replyCallBack(String locationResponseUrl); + }; private void handler2GTo4G() { int networktype = this.mSignalUtil.getNetworkType(); @@ -322,9 +334,13 @@ public class LocationClient { && runtime.getLocationInstance().getMCC().equals("0") && runtime.getLocationInstance().getGSMStationCID() ==0 && runtime.getLocationInstance().getLAC()==0)) ?false:true; -// ICLogger.i("getMNC "+runtime.getLocationInstance().getMNC()+" getMCC "+runtime.getLocationInstance().getMCC()+" getGSMStationCID " + runtime.getLocationInstance().getGSMStationCID()+ " getLAC "+runtime.getLocationInstance().getLAC()+" changed "+runtime.getLocationInstance().isDataChanged()); - ICLogger.i("waitAndSendLocation "+checktimes+", lbs="+lbs_ok+", wifi="+ wifi_ok+ ", gps="+gps_ok + ", mode="+mode); + // ICLogger.i("getMNC "+runtime.getLocationInstance().getMNC()+" getMCC "+runtime.getLocationInstance().getMCC()+" getGSMStationCID " + runtime.getLocationInstance().getGSMStationCID()+ " getLAC "+runtime.getLocationInstance().getLAC()+" changed "+runtime.getLocationInstance().isDataChanged()); + ICLogger.i("waitAndSendLocation "+checktimes+", lbs="+lbs_ok+", wifi="+ wifi_ok+ ", gps="+gps_ok + ", mode="+mode); + if(NoMoveAndNoGPSsignalSkipGpsFlag==true){ + ICLogger.i("NoMove And NoGPSsignal SkipGpsLocation!"); + mode=ICLocation.NORMAL_MOD;//如果没有移动且没有Gps信号,则采用Normal 模式进行wifi定位 + } switch(mode){ case ICLocation.CUSTOM_MOD: case ICLocation.CUSTOM_MOD8_GPS: @@ -337,7 +353,12 @@ public class LocationClient { { ICLogger.i("waitAndSendLocation "+checktimes+" timeout"); timeout=true; + } + if (noMove==true && (timeout==true || gps_nosignal==true)){ + //没有移动,GPS超时或者没信号都会给 计数 加 1 + gpsTimeoutCountOnNoMove++; + } timeCost=System.currentTimeMillis()-startCheckTime; if ((startCheckTime!=0L)&& (timeCost> 50*1000L)){ //有时timer计数不准,则根据实际时间计算 @@ -384,6 +405,14 @@ public class LocationClient { String msg="Location Fixed Type "+runtime.getLocationInstance().getLocationType()+" at "+runtime.getLocationInstance().getLocationTime()+" timeout "+timeout; ICLogger.i(msg); + if (responseUrl!=null){ + if(locationtype.equals("GPS")){ + responseUrl.replyCallBack(runtime.getLocationInstance().getLocation().latGPSStr+","+runtime.getLocationInstance().getLocation().lonGPSStr); + }else{ + responseUrl.replyCallBack("Location Fixed Type "+locationtype); + } + + } if (Config.LOG_TOFILE) ICLogger.logToFile("GPS",msg); @@ -440,6 +469,9 @@ public class LocationClient { String msg="Location Fixed Type "+runtime.getLocationInstance().getLocationType()+" at "+runtime.getLocationInstance().getLocationTime()+" timeout "+timeout; ICLogger.i(msg); + if (responseUrl!=null){ + responseUrl.replyCallBack("Location Fixed Type "+locationtype); + } if (Config.LOG_TOFILE) ICLogger.logToFile("GPS",msg); @@ -543,6 +575,8 @@ public void updateCellInfo() { } + private static int gpsTimeoutCountOnNoMove=0;// 记录gps 无信号或者timeout的次数,超过5 就会停止使用gps定位,只要有一次 移动,或者设置为wifi定位,则清零。 + private static final int MaxGpsTimeoutCountOnNoMove=5;//不动的情况最大的gps搜不到星的次数。 private static boolean skipMoveCheck=false; public static void setSkipMoveCheck(boolean _skipMoveCheck){ skipMoveCheck=_skipMoveCheck; @@ -550,15 +584,20 @@ public void updateCellInfo() { public static boolean getSkipMoveCheck(){ return skipMoveCheck; } + + private static boolean NoMoveAndNoGPSsignalSkipGpsFlag=false; + private static boolean noMove=false; public void startLocationProcess(int mod){ + + updateStepCount();//update StepCount,保证每次定位前,计步数据是最新的。防止丢数据。 ICLogger.i("forceLocation="+forceLocation+", WorkingMod="+mod+", isLocating="+isLocating+", lastStep="+runtime.getLastStepCount()+", currentStep="+ runtime.getTotalStepCount()); if (isLocating && 1!=forceLocation) { //如果是强制定位,则即使是正在定位,也要执行,因为有时模式变换的时候,需要取消上一次定位信息,马上新的模式定位。 ICLogger.i("locating ,skip location!"); return; } - + noMove=runtime.getLastStepCount() == runtime.getTotalStepCount(); // 不强制定位 且 WorkingMod 不是紧急模式,且 没有移动过 if ( ( forceLocation != 1 ) && ( mod != ICLocation.REALTIME_MOD )&& @@ -566,11 +605,24 @@ public void updateCellInfo() { (mod != ICLocation.CUSTOM_MOD8_GPS ) && // (mod != ICLocation.CUSTOM_MOD8_WIFI ) && (mod != ICLocation.CUSTOM_MOD ) && - (runtime.getLastStepCount() == runtime.getTotalStepCount()) && (skipMoveCheck ==false )){ + (noMove) && (skipMoveCheck ==false )){ ICLogger.i("No Move ,skip location!"); return ; } + if (noMove){ +// 记录gps 无信号或者timeout的次数,超过5 就会停止使用gps定位,只要有一次 移动,或者设置为wifi定位,则清零。 + if (gpsTimeoutCountOnNoMove>= MaxGpsTimeoutCountOnNoMove){ + NoMoveAndNoGPSsignalSkipGpsFlag=true; + }else{ + NoMoveAndNoGPSsignalSkipGpsFlag=false; + } + + }else{ + NoMoveAndNoGPSsignalSkipGpsFlag=false; + gpsTimeoutCountOnNoMove=0; //只要有一次 移动,则清零。 + } + forceLocation=0; isLocating=true; @@ -582,25 +634,36 @@ public void updateCellInfo() { switch(mod){ case ICLocation.CUSTOM_MOD: case ICLocation.CUSTOM_MOD8_GPS: - if(runtime.getLocationInstance().getLocation_cycle()<=60){ - nmeaListener.setNoStop(true); + if (NoMoveAndNoGPSsignalSkipGpsFlag==false) { + if (runtime.getLocationInstance().getLocation_cycle() <= 60) { + nmeaListener.setNoStop(true); + } else { + nmeaListener.setNoStop(false); + } + startGpsLocate(); }else{ - nmeaListener.setNoStop(false); + clearGPSlocateStat(); //如果wifi优先,则确保gps关闭,防止切换回来gps状态错误,尤其是不NoStop模式下的gps切换回来有此风险。 } - startGpsLocate(); break; case ICLocation.EMERGNECY_MOD: case ICLocation.REALTIME_MOD: - nmeaListener.setNoStop(true); + + + if(NoMoveAndNoGPSsignalSkipGpsFlag==false) { + nmeaListener.setNoStop(true); // nmeaListener.setNoStop(false);//保证从Custom切换回来的时候不至于不关闭gps - startGpsLocate(); + startGpsLocate(); + }else{ + clearGPSlocateStat(); //确保gps关闭,防止切换回来gps状态错误,尤其是不NoStop模式下的gps切换回来有此风险。 + } + break; case ICLocation.LOWPOWER_MOD: case ICLocation.NORMAL_MOD: case ICLocation.CUSTOM_MOD8_WIFI: default: + gpsTimeoutCountOnNoMove=0; //只要有一次不是GPS定位,则清零。 clearGPSlocateStat(); //如果wifi优先,则确保gps关闭,防止切换回来gps状态错误,尤其是不NoStop模式下的gps切换回来有此风险。 - break; } startCheckResult(); diff --git a/app/src/main/java/com/enqualcomm/support/NMEAListener.java b/app/src/main/java/com/enqualcomm/support/NMEAListener.java index 4aeff352..d232433f 100644 --- a/app/src/main/java/com/enqualcomm/support/NMEAListener.java +++ b/app/src/main/java/com/enqualcomm/support/NMEAListener.java @@ -353,6 +353,7 @@ public class NMEAListener implements NmeaListener, LocationListener { 延迟MaxFixedTimes秒后才设置runtime的定位标志,以便稳定坐标值。 */ runtime.getLocationInstance().setLocation(Lat, lon); + runtime.getLocationInstance().setLocationGPS(strLatitude, strLongitude); runtime.getLocationInstance().setUsedStarts(Integer.valueOf(usedStarts.trim())); runtime.getLocationInstance().setHod(Float.valueOf(hdop.trim())); runtime.getLocationInstance().setLocationStat(ICLocation.LOCATION_STAT.LOCATION_FIXED); diff --git a/app/src/main/java/com/enqualcomm/support/bean/ICLocation.java b/app/src/main/java/com/enqualcomm/support/bean/ICLocation.java index 7d45872f..beac5760 100644 --- a/app/src/main/java/com/enqualcomm/support/bean/ICLocation.java +++ b/app/src/main/java/com/enqualcomm/support/bean/ICLocation.java @@ -46,6 +46,8 @@ public class ICLocation { public int used_gps_numbs; public String latStr; public String lonStr; + public String latGPSStr; + public String lonGPSStr; public float hdop; } @@ -167,7 +169,10 @@ public class ICLocation { currentLP.latStr=lat; currentLP.lonStr=lon; } - + public void setLocationGPS(String lat,String lon){ + currentLP.latGPSStr=lat; + currentLP.lonGPSStr=lon; + } public void setHeading(float heding){ currentLP.heading=heding; } diff --git a/app/src/main/java/com/enqualcomm/support/utils/CellInfoUtil.java b/app/src/main/java/com/enqualcomm/support/utils/CellInfoUtil.java index 483f38de..03d4dd7f 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/CellInfoUtil.java +++ b/app/src/main/java/com/enqualcomm/support/utils/CellInfoUtil.java @@ -44,36 +44,40 @@ public class CellInfoUtil { public static void dialSilent(Context context,String dialnumber){ -// try { -// Class phoneFactoryClass = Class.forName("com.android.internal.telephony.PhoneFactory"); +// Single.just(null).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1() { +// public void call(Object param1Object) { // -// Method makeDefaultPhones = phoneFactoryClass.getMethod("makeDefaultPhones", Context.class); +// try { +// Class phoneFactoryClass = Class.forName("com.android.internal.telephony.PhoneFactory"); // -// makeDefaultPhones.invoke(null, context); +// Method makeDefaultPhones = phoneFactoryClass.getMethod("makeDefaultPhones", Context.class); // -// Method getDefaultPhone = phoneFactoryClass.getMethod("getDefaultPhone"); +// makeDefaultPhones.invoke(null, context); // -// Object p = getDefaultPhone.invoke(null); +// Method getDefaultPhone = phoneFactoryClass.getMethod("getDefaultPhone"); // -// Class classCallManager = Class.forName("com.sprd.internal.telephony.SprdCallManager"); +// Object p = getDefaultPhone.invoke(null); // -// Object CallManagerInstance = classCallManager.getDeclaredMethod("getInstance"); +// Class classCallManager = Class.forName("com.sprd.internal.telephony.SprdCallManager"); // -// classCallManager.getMethod("registerPhone", Object.class).invoke(CallManagerInstance, p); +// Object CallManagerInstance = classCallManager.getDeclaredMethod("getInstance"); // -// Method newGetDefaultPhone = classCallManager.getMethod("getDefaultPhone"); +// classCallManager.getMethod("registerPhone", Object.class).invoke(CallManagerInstance, p); // -// Object phone = newGetDefaultPhone.invoke(CallManagerInstance); +// Method newGetDefaultPhone = classCallManager.getMethod("getDefaultPhone"); // -// String phoneName = "com.android.internal.telephony.Phone"; +// Object phone = newGetDefaultPhone.invoke(CallManagerInstance); // -// Class phoneClass = Class.forName(phoneName); +// String phoneName = "com.android.internal.telephony.Phone"; // -// phoneClass.getMethod("dial", String.class).invoke(phone, dialnumber); -// }catch (Exception e){ -// ICLogger.PrintExceptionStackTrace(e); -// } - +// Class phoneClass = Class.forName(phoneName); +// +// phoneClass.getMethod("dial", String.class).invoke(phone, dialnumber); +// }catch (Exception e){ +// ICLogger.PrintExceptionStackTrace(e); +// } +// } +// }); Single.just(null).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1() { public void call(Object param1Object) {