package com.enqualcomm.support;\r
\r
+import android.app.AlarmManager;\r
import android.content.BroadcastReceiver;\r
import android.content.Context;\r
import android.content.Intent;\r
import android.os.SystemClock;\r
import android.provider.Settings;\r
\r
+import com.enqualcomm.support.utils.AlarmHelper;\r
import com.ic.jni.ICJniUtils;\r
import com.enqualcomm.support.adapter.LBSHelper;\r
import com.enqualcomm.support.adapter.protocolAPIHelper;\r
public class LocationClient {\r
private static final String TAG = LocationClient.class.getSimpleName();\r
private static final long CHANGENETMODETIME = 43200000L;\r
- \r
+ private static long startCheckTime=0L;\r
private static final int CLOSE_AIRMODE = 0;\r
\r
private static final int IS_GPS = 0;\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
-// LocationClient.this.mSignalUtil.setAirMode("CloseAirplane");\r
+// mSignalUtil.setAirMode("CloseAirplane");\r
// }\r
// }\r
// };\r
\r
}\r
\r
-\r
private void performAlarm(PowerManager.WakeLock paramWakeLock) {\r
if (!runtime.isAirMode) {\r
updateStepCount();//update StepCount\r
}\r
}\r
public void triggerLocationProcess(){\r
- mhandler.sendEmptyMessage(0);\r
+ mhandler.sendEmptyMessage(msgWhat_StartLocationProcess);\r
}\r
\r
public void triggerSOSLocationProcess(){\r
- mhandler.sendEmptyMessage(2);\r
+ mhandler.sendEmptyMessage(msgWhat_StartSOSLocationProcess);\r
}\r
\r
private static int checktimes=0;\r
Settings.Secure.setLocationProviderEnabled(runtime.getContextProxy().getResolver(), GPS_PROVIDER, true);\r
Single.just(null).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<Object>() {\r
public void call(Object param1Object) {\r
- LocationClient.this.nmeaListener.startListen();\r
+ nmeaListener.startListen();\r
}\r
});\r
}\r
public void startCheckResult(){\r
checktimes=0;\r
timeout=false;\r
+ startCheckTime= System.currentTimeMillis();\r
//延时2秒执行发送“读取定位”消息\r
if (mTimer==null) mTimer=new Timer();\r
mTimer.schedule(new MyTimerTask(), 1000L,1000L);\r
+// AlarmManager alarmManager=(AlarmManager)runtime.getContextProxy().context.getSystemService(Context.ALARM_SERVICE);\r
+// AlarmHelper.setAlarm(alarmManager,0,1,);\r
}\r
class MyTimerTask extends TimerTask {\r
public void run() {\r
//发送读取计步消息\r
- LocationClient.this.mhandler.sendEmptyMessage(100);\r
+ mhandler.sendEmptyMessage(msgWhat_WaitAndSendLocation);\r
}\r
};\r
+\r
+\r
+\r
+ private final static int msgWhat_WaitAndSendLocation=100;\r
+ private final static int msgWhat_StartLocationProcess=0;\r
+ private final static int msgWhat_StartSOSLocationProcess=2;\r
Handler mhandler=new Handler(){\r
\r
public void handleMessage(Message msg) {\r
super.handleMessage(msg);\r
- if (msg.what == 100){\r
+ if (msg.what == msgWhat_WaitAndSendLocation){\r
Single.just(null).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<Object>() {\r
- public void call(Object param1Object) { LocationClient.this.waitAndSendLocation(); }\r
+ public void call(Object param1Object) { waitAndSendLocation(); }\r
});\r
- }else if (msg.what == 0){\r
+ }else if (msg.what == msgWhat_StartLocationProcess){\r
startLocationProcess(runtime.getLocationInstance().getWorkingMod());\r
- }else if (msg.what == 2){\r
+ }else if (msg.what == msgWhat_StartSOSLocationProcess){\r
startSOSLocation=true;//启动SOS定位,为了快速响应,只要wifi定位即可。\r
forceLocation=1;\r
startLocationProcess(ICLocation.NORMAL_MOD);\r
}\r
-\r
-\r
}\r
-\r
};\r
\r
\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 lbs="+lbs_ok+", wifi="+ wifi_ok+ ", gps="+gps_ok + ", mode="+mode);\r
+ ICLogger.i("waitAndSendLocation "+checktimes+", lbs="+lbs_ok+", wifi="+ wifi_ok+ ", gps="+gps_ok + ", mode="+mode);\r
\r
switch(mode){\r
case ICLocation.CUSTOM_MOD:\r
\r
\r
//GPS 优先的话多给些时间(10秒)\r
- if (checktimes> 50) timeout=true;\r
-\r
- if ((lbs_ok && timeout==true) ||( gps_ok )||(lbs_ok && gps_ok )||(lbs_ok && ( gps_ok || startSOSLocation==true ) && wifi_ok )||(lbs_ok&&gps_nosignal&&wifi_ok)){\r
-\r
-\r
+ if (checktimes> 50 ||\r
+ ((startCheckTime!=0L)&&(System.currentTimeMillis()-startCheckTime > 50*1000L)) //有时timer计数不准,则根据实际时间计算\r
+ ) timeout=true;\r
+\r
+ // lbs only +timeout, lbs+wifi+gpsNosignal, libs+ , lbs+gps+wifi, Timeout can override wifi and gps\r
+ if ((lbs_ok && timeout==true)\r
+ ||( gps_ok )\r
+ ||(lbs_ok && ( gps_ok || startSOSLocation==true ) )\r
+ ||(lbs_ok && ( gps_ok || startSOSLocation==true ) && wifi_ok )\r
+ ||(lbs_ok&&gps_nosignal&&wifi_ok)\r
+ ){\r
if (startSOSLocation==true){\r
-\r
String AP10_CMD = protocolAPIHelper.AP10(runtime);\r
Deliver.sendLocationMSG(AP10_CMD);\r
startSOSLocation=false;\r
-\r
}else {\r
String AP01_CMD = protocolAPIHelper.AP01(runtime);\r
Deliver.sendLocationMSG(AP01_CMD);\r
}\r
\r
\r
- if (mTimer!=null){\r
- mTimer.cancel();\r
- mTimer=null;\r
- }\r
- isLocating = false;\r
+ stopCheckLocationResult();\r
+\r
String locationtype="LBS";\r
if (gps_ok ){\r
locationtype="GPS";\r
}else if (wifi_ok){\r
locationtype="WiFi";\r
}\r
+\r
runtime.getLocationInstance().setLocationType(locationtype);\r
runtime.getLocationInstance().setLocationTime(TimeUtil.getSystemTime3());\r
+\r
+ String msg="Location Fixed Type "+runtime.getLocationInstance().getLocationType()+" at "+runtime.getLocationInstance().getLocationTime();\r
+ ICLogger.i(msg);\r
+\r
+ if (Config.LOG_TOFILE)\r
+ FileOutputUtil.fileOutput(this.runtime.getCacheDir(),"GPS",msg);\r
+\r
+\r
}else if (timeout==true){\r
+ //timeout + noLBS +noGPS\r
ICLogger.i("timeout no location ");\r
- isLocating = false;\r
- if (mTimer!=null){\r
- mTimer.cancel();\r
- mTimer=null;\r
- }\r
+ stopCheckLocationResult();\r
+ if (Config.LOG_TOFILE)\r
+ FileOutputUtil.fileOutput(this.runtime.getCacheDir(),"GPS","timeout no location ");\r
}\r
break;\r
+\r
+ case ICLocation.NORMAL_MOD:\r
+ case ICLocation.LOWPOWER_MOD:\r
default:\r
//wifi优先的话给20秒时间\r
- if (checktimes> 20) timeout=true;\r
+ if (checktimes> 20 ||\r
+ ((startCheckTime!=0L)&&(System.currentTimeMillis()-startCheckTime > 20*1000L)) //有时timer计数不准,则根据实际时间计算\r
+ ) timeout=true;\r
\r
if ((lbs_ok && timeout==true) ||(lbs_ok && wifi_ok )){\r
\r
- String locationtype="LBS";\r
- if (wifi_ok){\r
- locationtype="WiFi";\r
- }\r
- runtime.getLocationInstance().setLocationType(locationtype);\r
- runtime.getLocationInstance().setLocationTime(TimeUtil.getSystemTime3());\r
\r
if (startSOSLocation==true){\r
String AP10_CMD = protocolAPIHelper.AP10(runtime);\r
Deliver.sendLocationMSG(AP01_CMD);\r
}\r
\r
- if (mTimer!=null){\r
- mTimer.cancel();\r
- mTimer=null;\r
+ stopCheckLocationResult();\r
+\r
+ String locationtype="LBS";\r
+ if (wifi_ok){\r
+ locationtype="WiFi";\r
}\r
- isLocating = false;\r
+ runtime.getLocationInstance().setLocationType(locationtype);\r
+ runtime.getLocationInstance().setLocationTime(TimeUtil.getSystemTime3());\r
+\r
+ String msg="Location Fixed Type "+runtime.getLocationInstance().getLocationType()+" at "+runtime.getLocationInstance().getLocationTime();\r
+ ICLogger.i(msg);\r
\r
+ if (Config.LOG_TOFILE)\r
+ FileOutputUtil.fileOutput(this.runtime.getCacheDir(),"GPS",msg);\r
\r
\r
}else if (timeout==true){\r
ICLogger.i("timeout no location ");\r
- isLocating = false;\r
- if (mTimer!=null){\r
- mTimer.cancel();\r
- mTimer=null;\r
- }\r
+ stopCheckLocationResult();\r
+ if (Config.LOG_TOFILE)\r
+ FileOutputUtil.fileOutput(this.runtime.getCacheDir(),"GPS","timeout no location ");\r
}\r
break;\r
}\r
\r
}\r
\r
+ public void stopCheckLocationResult(){\r
+ ICLogger.i("stopCheckLocationResult!");\r
+ if (mTimer!=null){\r
+ mTimer.cancel();\r
+ mTimer=null;\r
+ }\r
+ isLocating = false;\r
+ startCheckTime=0L;\r
+ }\r
+\r
// public void EqcAlgorithmInterfaceMethod3() {\r
public void stopGpsLocate() {\r
// if (Deliver.is_active_location) {\r
// Deliver.is_active_location = false;\r
// getLocationWakeLock();\r
// }\r
+ ICLogger.i("stopGpsLocate");\r
\r
//防止与工厂测试冲突\r
if (!DeviceInfoUtil.isFactoryTestTopActivity(runtime.getContextProxy().context)) {\r
Settings.Secure.setLocationProviderEnabled(runtime.getContextProxy().getResolver(), GPS_PROVIDER, false);\r
Single.just(null).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<Object>() {\r
public void call(Object param1Object) {\r
- LocationClient.this.nmeaListener.stopListen();\r
+ nmeaListener.stopListen();\r
}\r
});\r
}\r
\r
runtime.setLastStepCount(runtime.getTotalStepCount());\r
updateCellInfo();\r
- startWifiScan();\r
+ startWifiScan();\r
switch(mod){\r
case ICLocation.CUSTOM_MOD:\r
if(runtime.getLocationInstance().getLocation_cycle()<60){\r
\r
public void deinit() {\r
\r
+ ICLogger.i("GPS deinit!");\r
// (runtime.getContextProxy()).context.unregisterReceiver(this.screenOnReceiver);\r
// mLbsHelper.unRegisterWiFiBroadReceiver();\r
// this.executor.execute(new Runnable() {\r
private void notifiSetAirModeMethod() { (new Thread(new Runnable() {\r
public void run() {\r
SystemClock.sleep(3000L);\r
- boolean bool = LocationClient.this.mSignalUtil.IsAirModeOn();\r
+ boolean bool = mSignalUtil.IsAirModeOn();\r
byte b = 1;\r
if (bool != true)\r
b = 0;\r
int numberOfSatellites;\r
Runtime runtime;\r
\r
- private static int MaxFixedTimes=5;\r
+ private static int MaxFixedTimes=3;\r
\r
private static int locationFixedCount=0;\r
\r
\r
public void setNoStop(boolean nostop){\r
noStop=nostop;\r
+ ICLogger.i("setNoStop"+nostop);\r
if (noStop==false){\r
stopListen();\r
}\r
stop(MSG_WHAT_GPS_NOSTAR);\r
}\r
}\r
+ ICLogger.i( sb2.toString());\r
if (Config.LOG_TOFILE)\r
FileOutputUtil.fileOutput(this.runtime.getCacheDir(),"GPS",sb2.toString());\r
\r
只有当前GPS已经定位,且location不为空才给 runtime赋值GPS坐标。\r
延迟MaxFixedTimes秒后才设置runtime的定位标志,以便稳定坐标值。\r
*/\r
+\r
+ //log msg变量\r
+ StringBuffer sb2 = new StringBuffer();\r
+ sb2.append(" gps lat=").append(Lat).append(", gps lon=").append(lon);\r
+\r
+ latitude=Double.valueOf(Lat);\r
+ longitude=Double.valueOf(lon);\r
+ // 转换单位,从分转换到度\r
+\r
+ double intdu= (int)(longitude /100f); //小数转换到分为单位\r
+ double du=(longitude - intdu*100)/60f;\r
+ double last= intdu+du;\r
+ longitude =last;\r
+ intdu= (int)(latitude /100f); //小数转换到分为单位\r
+ du=(latitude - intdu*100)/60f;\r
+ last= intdu+du;\r
+ latitude=last;\r
+\r
+ // 经纬度 保留4位小数点\r
+ DecimalFormat df = new DecimalFormat("#.000000");\r
+ String strLatitude = df.format(latitude);\r
+ String strLongitude = df.format(longitude);\r
+ sb2.append(" real lat=").append(strLatitude).append(" lon=").append(strLongitude);\r
+ ICLogger.i(sb2.toString());\r
+\r
runtime.getLocationInstance().setLocation(Lat,lon);\r
runtime.getLocationInstance().setUsedStarts(Integer.valueOf(usedStarts.trim()));\r
runtime.getLocationInstance().setHod(Float.valueOf(hdop.trim()));\r
}\r
\r
if (!noStop){\r
- NMEAListener.this.stopListen();\r
+ ICLogger.i("handleMessage MSG_WHAT_GPS_TIMEOUT/ MSG_WHAT_GPS_NOSTAR/ MSG_WHAT_GPS_FIXED "+message.what);\r
+\r
+ stopListen();\r
}\r
return true;\r
}\r
//\r
// ICLogger.i("Location " +runtime.getLocationInstance().getLocationStat().name());\r
//发送停止消息\r
- NMEAListener.this.temHandler.sendEmptyMessage(id);\r
- }\r
- private void delaystop(){\r
-\r
- /*\r
- 只有当前GPS已经定位,且location不为空才给 runtime赋值GPS坐标。\r
- 延迟三秒后才设置runtime的定位标志,以便稳定坐标值。\r
- */\r
- //发送停止消息\r
- NMEAListener.this.temHandler.sendEmptyMessageDelayed(MSG_WHAT_GPS_FIXED, 3000L);\r
-\r
+ temHandler.sendEmptyMessage(id);\r
}\r
boolean isFrist = true;\r
\r
//做个热启动\r
return true;//gpsHotStart();\r
}else{\r
+ ICLogger.i(" location listening, skip !");\r
+\r
return true;\r
}\r
}\r
this.locationManager.removeNmeaListener(this);\r
this.locationManager.removeUpdates(this);\r
this.listening = false;\r
+ ICLogger.i("stopListen 定位 ");\r
}\r
\r
public enum GPS_CURRENT_STATUS {\r