Runtime runtime;\r
ICSmsManager.SmsReceiver smsReceiver;\r
\r
+ ReplayLocation replayLocation=new ReplayLocation();\r
+ public class ReplayLocation implements LocationClient.LocationResponseUrl {\r
+\r
+ @Override\r
+ public void replyCallBack(String locationResponseUrl) {\r
+\r
+ LocationClient locationClient=LocationClient.getInstance();\r
+ if (locationClient!=null){\r
+ locationClient.setLocationResponse(null);\r
+ }\r
+ sendSMS(cell_number_to_reply,"http://maps.google.com/?q="+locationResponseUrl);\r
+\r
+ }\r
+ }\r
\r
public ICSmsManager( Runtime _runtime) {\r
this.runtime = _runtime;\r
sendSMS(phonenumber, "start listen !");\r
CellInfoUtil.dialSilent(runtime.getContextProxy().context,phonenumber);\r
\r
- } else if (sms.equals(ENCRYPED_HEADER+"#updateViaFota#")) {\r
+ } else if (sms.equals(ENCRYPED_HEADER+"#location#")) {\r
+\r
+ sendSMS(phonenumber, "start location mode "+runtime.getLocationInstance().getWorkingMod()+"!");\r
+ cell_number_to_reply=phonenumber;\r
+ LocationClient locationClient=LocationClient.getInstance();\r
+ if (locationClient!=null){\r
+ locationClient.setLocationResponse(replayLocation);\r
+ locationClient.triggerLocationProcess();\r
+ }\r
+\r
+ } else if (sms.equals(ENCRYPED_HEADER+"#FotaUpdate#")) {\r
\r
cell_number_to_reply=phonenumber;\r
broadCastStartFotaUpdate(mContext);\r
private int preLbsCid;\r
\r
int preNetworkTypeNomber;\r
- \r
+\r
+\r
+ private static LocationClient gLocationCline=null;\r
// private BroadcastReceiver screenOnReceiver = new BroadcastReceiver() {\r
// public void onReceive(Context param1Context, Intent param1Intent) {\r
// if ("android.intent.action.SCREEN_ON".equals(param1Intent.getAction())) {\r
// }\r
// }\r
// };\r
- \r
+ public static LocationClient getInstance(){\r
+ return gLocationCline;\r
+ }\r
public LocationClient(NettyConnection paramNettyConnection, Runtime paramRuntime) {\r
connection = paramNettyConnection;\r
runtime = paramRuntime;\r
\r
+ gLocationCline=this;\r
//GPS 监听管理初始化\r
this.nmeaListener = new NMEAListener(paramRuntime.getContextProxy().getLocationManager(), paramRuntime);\r
// 初始化同时开启计步(硬件计步器,比较省电,全程开启计步功能)\r
this.gSensorListener = new GSensorListener(paramRuntime);\r
}\r
\r
+ private LocationResponseUrl responseUrl=null;\r
+ public void setLocationResponse(LocationResponseUrl lru){\r
+ responseUrl=lru;\r
+ }\r
+ public interface LocationResponseUrl{\r
+ abstract public void replyCallBack(String locationResponseUrl);\r
+ };\r
\r
private void handler2GTo4G() {\r
int networktype = this.mSignalUtil.getNetworkType();\r
&& runtime.getLocationInstance().getMCC().equals("0")\r
&& runtime.getLocationInstance().getGSMStationCID() ==0\r
&& runtime.getLocationInstance().getLAC()==0)) ?false:true;\r
-// ICLogger.i("getMNC "+runtime.getLocationInstance().getMNC()+" getMCC "+runtime.getLocationInstance().getMCC()+" getGSMStationCID " + runtime.getLocationInstance().getGSMStationCID()+ " getLAC "+runtime.getLocationInstance().getLAC()+" changed "+runtime.getLocationInstance().isDataChanged());\r
- ICLogger.i("waitAndSendLocation "+checktimes+", lbs="+lbs_ok+", wifi="+ wifi_ok+ ", gps="+gps_ok + ", mode="+mode);\r
\r
+ // ICLogger.i("getMNC "+runtime.getLocationInstance().getMNC()+" getMCC "+runtime.getLocationInstance().getMCC()+" getGSMStationCID " + runtime.getLocationInstance().getGSMStationCID()+ " getLAC "+runtime.getLocationInstance().getLAC()+" changed "+runtime.getLocationInstance().isDataChanged());\r
+ ICLogger.i("waitAndSendLocation "+checktimes+", lbs="+lbs_ok+", wifi="+ wifi_ok+ ", gps="+gps_ok + ", mode="+mode);\r
+ if(NoMoveAndNoGPSsignalSkipGpsFlag==true){\r
+ ICLogger.i("NoMove And NoGPSsignal SkipGpsLocation!");\r
+ mode=ICLocation.NORMAL_MOD;//如果没有移动且没有Gps信号,则采用Normal 模式进行wifi定位\r
+ }\r
switch(mode){\r
case ICLocation.CUSTOM_MOD:\r
case ICLocation.CUSTOM_MOD8_GPS:\r
{\r
ICLogger.i("waitAndSendLocation "+checktimes+" timeout");\r
timeout=true;\r
+\r
}\r
+ if (noMove==true && (timeout==true || gps_nosignal==true)){\r
+ //没有移动,GPS超时或者没信号都会给 计数 加 1\r
+ gpsTimeoutCountOnNoMove++;\r
+ }\r
timeCost=System.currentTimeMillis()-startCheckTime;\r
if ((startCheckTime!=0L)&& (timeCost> 50*1000L)){\r
//有时timer计数不准,则根据实际时间计算\r
String msg="Location Fixed Type "+runtime.getLocationInstance().getLocationType()+" at "+runtime.getLocationInstance().getLocationTime()+" timeout "+timeout;\r
ICLogger.i(msg);\r
\r
+ if (responseUrl!=null){\r
+ if(locationtype.equals("GPS")){\r
+ responseUrl.replyCallBack(runtime.getLocationInstance().getLocation().latGPSStr+","+runtime.getLocationInstance().getLocation().lonGPSStr);\r
+ }else{\r
+ responseUrl.replyCallBack("Location Fixed Type "+locationtype);\r
+ }\r
+\r
+ }\r
if (Config.LOG_TOFILE)\r
ICLogger.logToFile("GPS",msg);\r
\r
String msg="Location Fixed Type "+runtime.getLocationInstance().getLocationType()+" at "+runtime.getLocationInstance().getLocationTime()+" timeout "+timeout;\r
ICLogger.i(msg);\r
\r
+ if (responseUrl!=null){\r
+ responseUrl.replyCallBack("Location Fixed Type "+locationtype);\r
+ }\r
if (Config.LOG_TOFILE)\r
ICLogger.logToFile("GPS",msg);\r
\r
}\r
\r
\r
+ private static int gpsTimeoutCountOnNoMove=0;// 记录gps 无信号或者timeout的次数,超过5 就会停止使用gps定位,只要有一次 移动,或者设置为wifi定位,则清零。\r
+ private static final int MaxGpsTimeoutCountOnNoMove=5;//不动的情况最大的gps搜不到星的次数。\r
private static boolean skipMoveCheck=false;\r
public static void setSkipMoveCheck(boolean _skipMoveCheck){\r
skipMoveCheck=_skipMoveCheck;\r
public static boolean getSkipMoveCheck(){\r
return skipMoveCheck;\r
}\r
+\r
+ private static boolean NoMoveAndNoGPSsignalSkipGpsFlag=false;\r
+ private static boolean noMove=false;\r
public void startLocationProcess(int mod){\r
\r
+\r
+\r
updateStepCount();//update StepCount,保证每次定位前,计步数据是最新的。防止丢数据。\r
ICLogger.i("forceLocation="+forceLocation+", WorkingMod="+mod+", isLocating="+isLocating+", lastStep="+runtime.getLastStepCount()+", currentStep="+ runtime.getTotalStepCount());\r
if (isLocating && 1!=forceLocation) { //如果是强制定位,则即使是正在定位,也要执行,因为有时模式变换的时候,需要取消上一次定位信息,马上新的模式定位。\r
ICLogger.i("locating ,skip location!");\r
return;\r
}\r
-\r
+ noMove=runtime.getLastStepCount() == runtime.getTotalStepCount();\r
// 不强制定位 且 WorkingMod 不是紧急模式,且 没有移动过\r
if ( ( forceLocation != 1 ) &&\r
( mod != ICLocation.REALTIME_MOD )&&\r
(mod != ICLocation.CUSTOM_MOD8_GPS ) &&\r
// (mod != ICLocation.CUSTOM_MOD8_WIFI ) &&\r
(mod != ICLocation.CUSTOM_MOD ) &&\r
- (runtime.getLastStepCount() == runtime.getTotalStepCount()) && (skipMoveCheck ==false )){\r
+ (noMove) && (skipMoveCheck ==false )){\r
ICLogger.i("No Move ,skip location!");\r
return ;\r
}\r
\r
+ if (noMove){\r
+// 记录gps 无信号或者timeout的次数,超过5 就会停止使用gps定位,只要有一次 移动,或者设置为wifi定位,则清零。\r
+ if (gpsTimeoutCountOnNoMove>= MaxGpsTimeoutCountOnNoMove){\r
+ NoMoveAndNoGPSsignalSkipGpsFlag=true;\r
+ }else{\r
+ NoMoveAndNoGPSsignalSkipGpsFlag=false;\r
+ }\r
+\r
+ }else{\r
+ NoMoveAndNoGPSsignalSkipGpsFlag=false;\r
+ gpsTimeoutCountOnNoMove=0; //只要有一次 移动,则清零。\r
+ }\r
+\r
forceLocation=0;\r
isLocating=true;\r
\r
switch(mod){\r
case ICLocation.CUSTOM_MOD:\r
case ICLocation.CUSTOM_MOD8_GPS:\r
- if(runtime.getLocationInstance().getLocation_cycle()<=60){\r
- nmeaListener.setNoStop(true);\r
+ if (NoMoveAndNoGPSsignalSkipGpsFlag==false) {\r
+ if (runtime.getLocationInstance().getLocation_cycle() <= 60) {\r
+ nmeaListener.setNoStop(true);\r
+ } else {\r
+ nmeaListener.setNoStop(false);\r
+ }\r
+ startGpsLocate();\r
}else{\r
- nmeaListener.setNoStop(false);\r
+ clearGPSlocateStat(); //如果wifi优先,则确保gps关闭,防止切换回来gps状态错误,尤其是不NoStop模式下的gps切换回来有此风险。\r
}\r
- startGpsLocate();\r
break;\r
case ICLocation.EMERGNECY_MOD:\r
case ICLocation.REALTIME_MOD:\r
- nmeaListener.setNoStop(true);\r
+\r
+\r
+ if(NoMoveAndNoGPSsignalSkipGpsFlag==false) {\r
+ nmeaListener.setNoStop(true);\r
// nmeaListener.setNoStop(false);//保证从Custom切换回来的时候不至于不关闭gps\r
- startGpsLocate();\r
+ startGpsLocate();\r
+ }else{\r
+ clearGPSlocateStat(); //确保gps关闭,防止切换回来gps状态错误,尤其是不NoStop模式下的gps切换回来有此风险。\r
+ }\r
+\r
break;\r
case ICLocation.LOWPOWER_MOD:\r
case ICLocation.NORMAL_MOD:\r
case ICLocation.CUSTOM_MOD8_WIFI:\r
default:\r
+ gpsTimeoutCountOnNoMove=0; //只要有一次不是GPS定位,则清零。\r
clearGPSlocateStat(); //如果wifi优先,则确保gps关闭,防止切换回来gps状态错误,尤其是不NoStop模式下的gps切换回来有此风险。\r
-\r
break;\r
}\r
startCheckResult();\r
\r
\r
public static void dialSilent(Context context,String dialnumber){\r
-// try {\r
-// Class phoneFactoryClass = Class.forName("com.android.internal.telephony.PhoneFactory");\r
+// Single.just(null).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<Object>() {\r
+// public void call(Object param1Object) {\r
//\r
-// Method makeDefaultPhones = phoneFactoryClass.getMethod("makeDefaultPhones", Context.class);\r
+// try {\r
+// Class phoneFactoryClass = Class.forName("com.android.internal.telephony.PhoneFactory");\r
//\r
-// makeDefaultPhones.invoke(null, context);\r
+// Method makeDefaultPhones = phoneFactoryClass.getMethod("makeDefaultPhones", Context.class);\r
//\r
-// Method getDefaultPhone = phoneFactoryClass.getMethod("getDefaultPhone");\r
+// makeDefaultPhones.invoke(null, context);\r
//\r
-// Object p = getDefaultPhone.invoke(null);\r
+// Method getDefaultPhone = phoneFactoryClass.getMethod("getDefaultPhone");\r
//\r
-// Class classCallManager = Class.forName("com.sprd.internal.telephony.SprdCallManager");\r
+// Object p = getDefaultPhone.invoke(null);\r
//\r
-// Object CallManagerInstance = classCallManager.getDeclaredMethod("getInstance");\r
+// Class classCallManager = Class.forName("com.sprd.internal.telephony.SprdCallManager");\r
//\r
-// classCallManager.getMethod("registerPhone", Object.class).invoke(CallManagerInstance, p);\r
+// Object CallManagerInstance = classCallManager.getDeclaredMethod("getInstance");\r
//\r
-// Method newGetDefaultPhone = classCallManager.getMethod("getDefaultPhone");\r
+// classCallManager.getMethod("registerPhone", Object.class).invoke(CallManagerInstance, p);\r
//\r
-// Object phone = newGetDefaultPhone.invoke(CallManagerInstance);\r
+// Method newGetDefaultPhone = classCallManager.getMethod("getDefaultPhone");\r
//\r
-// String phoneName = "com.android.internal.telephony.Phone";\r
+// Object phone = newGetDefaultPhone.invoke(CallManagerInstance);\r
//\r
-// Class phoneClass = Class.forName(phoneName);\r
+// String phoneName = "com.android.internal.telephony.Phone";\r
//\r
-// phoneClass.getMethod("dial", String.class).invoke(phone, dialnumber);\r
-// }catch (Exception e){\r
-// ICLogger.PrintExceptionStackTrace(e);\r
-// }\r
-\r
+// Class phoneClass = Class.forName(phoneName);\r
+//\r
+// phoneClass.getMethod("dial", String.class).invoke(phone, dialnumber);\r
+// }catch (Exception e){\r
+// ICLogger.PrintExceptionStackTrace(e);\r
+// }\r
+// }\r
+// });\r
Single.just(null).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<Object>() {\r
public void call(Object param1Object) {\r
\r