From: snickersun Date: Fri, 13 Mar 2020 02:20:06 +0000 (+0800) Subject: release V374 版本 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=a9a8256398454a9934e4489dc636ae4fc1597860;p=protocol_srv.git release V374 版本 1、优化LBS搜索,WIFI和LBS现在都可以快速相应,大概4秒内。 2、GPS和WiFi搜索都添加对工厂测试的支持,工厂测试运行时,就不会对其进行控制,防止冲突。 3、GPS定位优化NMEA 解析,多加了HDOP定位精度日志,以便更好的分析定位情况。 4、优化网络重连机制,延时5秒重连,防止网络切换时新网络还没连接,就停止重连了。并且根据重连的网络是否切换,决定是否需要重新连接网络,防止多次无用重连。造成的频繁登录 5、精简去掉定位时的多重注册,只取有用信息。 6、screenOn时的同步计步信息的心跳包增加服务器响应判断。 --- diff --git a/app/debug/ICSer_V373_2003130743_debug.apk b/app/debug/ICSer_V373_2003130743_debug.apk new file mode 100644 index 00000000..dfef2151 Binary files /dev/null and b/app/debug/ICSer_V373_2003130743_debug.apk differ diff --git a/app/release/ICSer_V374_2003131011_release.apk b/app/release/ICSer_V374_2003131011_release.apk new file mode 100644 index 00000000..d3c557ce Binary files /dev/null and b/app/release/ICSer_V374_2003131011_release.apk differ diff --git a/app/src/main/java/com/enqualcomm/support/CoreService.java b/app/src/main/java/com/enqualcomm/support/CoreService.java index 95cfe5e7..e4d590ea 100644 --- a/app/src/main/java/com/enqualcomm/support/CoreService.java +++ b/app/src/main/java/com/enqualcomm/support/CoreService.java @@ -307,7 +307,13 @@ public class CoreService extends Service { CoreService.this.locationClient.updateStepCount(); Observable.timer(500L, TimeUnit.MILLISECONDS).subscribe(new Action1() { public void call(Long param1Long) { - connection.send(protocolAPIHelper.genStringMessage("heart",protocolAPIHelper.AP03(runtime))); + if (connection.isServerConnected()&& runtime.isServerProtocolConnected()) { + mKeepAlive.onHeartAlarm(connection, runtime); + }else{ + ICLogger.i("check 发送心跳包时,如果发现服务器没有响应,或者socket连接,则重新尝试连接服务器!"); + connection.disconnectServer(); + startConnectionRetryTimer(); + } } }); @@ -509,7 +515,7 @@ public class CoreService extends Service { startService(new Intent(this, InnerService.class)); ReConnectToServer(); - this.locationClient.start(); + this.locationClient.init(); //设置本service为前台运行,不被会被清理 @@ -625,7 +631,7 @@ public class CoreService extends Service { if (!screenon) { SimSignalUtil.send_at_to_update_lbs(this.runtime); } - //这里就是为了省电,如果wifi开启,且屏幕关闭,则wifi也关闭 + //这里就是为了省电,如果wifi开启,且屏幕关闭,则wifi也关闭 ,还有获取wifi消息的时候也和它有关 if (Util.isConnectWifi((this.runtime.getContextProxy()).context) && !screenon) { is_wifi_network_ok = true; //如果wifi开启的,则记录wifi状态为开启,以后屏幕开启时,再根据此变量决定是否打开wifi Util.turnOffWifiForSleep((this.runtime.getContextProxy()).context, this.runtime); @@ -878,7 +884,7 @@ public class CoreService extends Service { public void run() { ReConnectToServer(); } - }, 0, 20000); //每次都是断网才需要重连,所以不需要delay,并且每20秒重试一次 + }, 5000, 20000); //每次都是断网才需要重连,delay 5秒重连,并且每20秒重试一次 } } } @@ -942,7 +948,7 @@ public class CoreService extends Service { saveStepCount(); this.connectionServiceChain.processDetach(this.connection, this.runtime); this.invokeHandlerServiceChain.processDetach(this.connection, this.runtime); - this.locationClient.stop(); + this.locationClient.deinit(); this.connection.close(); unregisterReceiver(this.broadcastReceiver); unregisterReceiver(this.screenOnReceiver); diff --git a/app/src/main/java/com/enqualcomm/support/LocationClient.java b/app/src/main/java/com/enqualcomm/support/LocationClient.java index c7e5c1b4..c2e8bce7 100644 --- a/app/src/main/java/com/enqualcomm/support/LocationClient.java +++ b/app/src/main/java/com/enqualcomm/support/LocationClient.java @@ -115,13 +115,13 @@ public class LocationClient { int preNetworkTypeNomber; - private BroadcastReceiver screenOnReceiver = new BroadcastReceiver() { - public void onReceive(Context param1Context, Intent param1Intent) { - if ("android.intent.action.SCREEN_ON".equals(param1Intent.getAction())) { - LocationClient.this.mSignalUtil.setAirMode("CloseAirplane"); - } - } - }; +// private BroadcastReceiver screenOnReceiver = new BroadcastReceiver() { +// public void onReceive(Context param1Context, Intent param1Intent) { +// if ("android.intent.action.SCREEN_ON".equals(param1Intent.getAction())) { +// LocationClient.this.mSignalUtil.setAirMode("CloseAirplane"); +// } +// } +// }; public LocationClient(NettyConnection paramNettyConnection, Runtime paramRuntime) { connection = paramNettyConnection; @@ -202,8 +202,7 @@ public class LocationClient { ICLogger.i("开启wifi扫描"); runtime.setWifiinfo(""); mHasWifiResult = false; - this.mLbsHelper.registerBroadReceiver(); - this.mLbsHelper.getWifiInfo(); +// this.mLbsHelper.registerWiFiBroadReceiver(); this.mLbsHelper.setOnWiFiInfoListener(new LBSHelper.OnWiFiInfoListener() { public void getWifiInfoCallBack(String param1String) { ICLogger.i("get wifi scan Callback " + param1String); @@ -211,6 +210,7 @@ public class LocationClient { runtime.setWifiinfo(param1String==null?"":param1String); } }); + this.mLbsHelper.getWifiInfo(); } // public void EqcAlgorithmInterfaceMethod2() { public void startGpsLocate() { @@ -302,7 +302,7 @@ public class LocationClient { //GPS 优先的话多给些时间(10秒) if (checktimes> 50) timeout=true; - 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)){ + 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)){ if (startSOSLocation==true){ @@ -409,11 +409,6 @@ public void updateCellInfo() { CellInfoUtil.setCurrentAttachCellInfo(runtime, getLocationWakeLock()); } - public void updateSimSignalInfo() { - SimSignalUtil.getInstance((runtime.getContextProxy()).context); - } - - public PowerManager.WakeLock getLocationWakeLock() { PowerManager.WakeLock wakeLock = ((PowerManager)(runtime.getContextProxy()).context.getSystemService(Context.POWER_SERVICE)).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this.getClass().getSimpleName()); @@ -445,7 +440,7 @@ public void updateCellInfo() { updateStepCount();//update StepCount,保证每次定位前,计步数据是最新的。防止丢数据。 ICLogger.i("forceLocation="+forceLocation+", WorkingMod="+mod+", isLocating="+isLocating+", lastStep="+runtime.getLastStepCount()+", currentStep="+ runtime.getTotalStepCount()); - if (isLocating && 1!=forceLocation) { + if (isLocating && 1!=forceLocation) { //如果是强制定位,则即使是正在定位,也要执行,因为有时模式变换的时候,需要取消上一次定位信息,马上新的模式定位。 ICLogger.i("locating ,skip location!"); return; } @@ -460,8 +455,6 @@ public void updateCellInfo() { isLocating=true; runtime.setLastStepCount(runtime.getTotalStepCount()); - updateSimSignalInfo(); - updateCellInfo(); startWifiScan(); switch(mod){ @@ -516,7 +509,7 @@ public void updateCellInfo() { - public void start() { + public void init() { this.mSignalUtil = SimSignalUtil.getInstance((runtime.getContextProxy()).context); @@ -533,9 +526,9 @@ public void updateCellInfo() { /*注册 亮屏监控*/ - IntentFilter intentFilter = new IntentFilter(); - intentFilter.addAction("android.intent.action.SCREEN_ON"); - (runtime.getContextProxy()).context.registerReceiver(this.screenOnReceiver, intentFilter); +// IntentFilter intentFilter = new IntentFilter(); +// intentFilter.addAction("android.intent.action.SCREEN_ON"); +// (runtime.getContextProxy()).context.registerReceiver(this.screenOnReceiver, intentFilter); @@ -543,10 +536,10 @@ public void updateCellInfo() { // this.haveChanegTo4GTime = SystemClock.elapsedRealtime(); } - public void stop() { + public void deinit() { - (runtime.getContextProxy()).context.unregisterReceiver(this.screenOnReceiver); - mLbsHelper.unRegisterBroadReceiver(); +// (runtime.getContextProxy()).context.unregisterReceiver(this.screenOnReceiver); +// mLbsHelper.unRegisterWiFiBroadReceiver(); // this.executor.execute(new Runnable() { // public void run() { // Deliver.saveQueue(); @@ -599,7 +592,7 @@ public void updateCellInfo() { // 飞行模式 1 开启 0 关闭 public void setAirMode(int paramInt) { boolean isAirModeOn = this.mSignalUtil.IsAirModeOn(); - boolean isScreenOn = this.mSignalUtil.isScreenON(); + boolean isScreenOn = this.mSignalUtil.isScreenON(runtime.getContextProxy().context); switch (paramInt) { case 1: diff --git a/app/src/main/java/com/enqualcomm/support/NMEAListener.java b/app/src/main/java/com/enqualcomm/support/NMEAListener.java index a48517c1..d7ed096e 100644 --- a/app/src/main/java/com/enqualcomm/support/NMEAListener.java +++ b/app/src/main/java/com/enqualcomm/support/NMEAListener.java @@ -23,7 +23,7 @@ import java.util.Iterator; import java.util.List; public class NMEAListener implements NmeaListener, LocationListener { - private boolean listening; + private boolean listening=false; public class GpsSatellitePriv { @@ -131,30 +131,9 @@ public class NMEAListener implements NmeaListener, LocationListener { // if (Config.LOG_TOFILE) // FileOutputUtil.fileOutput(this.runtime.getCacheDir(), "GPS", "GPRMC GPSTime="+utctime+",Lat="+Lat+",Lon="+lon+",fixed="+fixed+",speed="+speed); - StringBuilder sb=new StringBuilder(); - sb.append("GPRMC, location time= " + TimeUtil.getLocalTime() + " ,lon= " + lon + ", lat= " + Lat + ","+fixed+" FixedCount=" + locationFixedCount + ", speed=" + speed); - ICLogger.i(sb.toString()); - if (Config.LOG_TOFILE) - FileOutputUtil.fileOutput(this.runtime.getCacheDir(), "GPS", sb.toString()); - //定位了, - if (fixed.equals("A")) { - locationFixedCount++; - - - - if (speed.trim().isEmpty())speed="0.0"; - runtime.getLocationInstance().setLocation(Lat, lon,Double.valueOf(speed), 0, numSatelliteList.size()); - if (locationFixedCount > MaxFixedTimes) { - /* - 只有当前GPS已经定位,且location不为空才给 runtime赋值GPS坐标。 - 延迟MaxFixedTimes秒后才设置runtime的定位标志,以便稳定坐标值。 - */ - runtime.getLocationInstance().setLocationStat(ICLocation.LOCATION_STAT.LOCATION_FIXED); - ICLogger.i("定位"+locationFixedCount+"次 > "+MaxFixedTimes+", set LOCATION_FIXED "); - if (!noStop) { - stopListen(); - } - } + if (fixed.trim().equals("A")) { + if (speed.trim().isEmpty()) speed = "0.0"; + runtime.getLocationInstance().setSpeed(Float.valueOf(speed)); } }else if (nmeastr.startsWith("$GPGSV,")) { @@ -216,7 +195,7 @@ public class NMEAListener implements NmeaListener, LocationListener { //最后一页,打印搜星情况,并作一些判断。 StringBuilder sb=new StringBuilder(); sb.append("搜索"+searchCout+"次,搜索到卫星个数" + SatlitesCount+", [SNR>0] ="+numSatelliteList.size()); - sb.append(", Max 3 SNR ["); + sb.append(", Max 5 SNR ["); for (int i=0;i MaxFixedTimes) { + /* + 只有当前GPS已经定位,且location不为空才给 runtime赋值GPS坐标。 + 延迟MaxFixedTimes秒后才设置runtime的定位标志,以便稳定坐标值。 + */ + runtime.getLocationInstance().setLocation(Lat,lon); + runtime.getLocationInstance().setUsedStarts(Integer.valueOf(usedStarts.trim())); + runtime.getLocationInstance().setHod(Float.valueOf(hdop.trim())); + runtime.getLocationInstance().setLocationStat(ICLocation.LOCATION_STAT.LOCATION_FIXED); + ICLogger.i("定位"+locationFixedCount+"次 > "+MaxFixedTimes+", set LOCATION_FIXED "); + if (!noStop) { + stopListen(); + } + } + + } }else if (nmeastr.startsWith("$GPGSA,")) { @@ -306,11 +312,14 @@ public class NMEAListener implements NmeaListener, LocationListener { // 字段17:VDOP垂直精度因子(0.5 - 99.9) // 字段18:校验值($与*之间的数异或后的值) - String tmplist[]=nmeastr.split(","); - String locationmod=tmplist[1]; - String fixed=tmplist[2]; -// ICLogger.i("GPGSA locationMode="+locationmod+",fixed="+fixed); - +// String tmplist[]=nmeastr.split(","); +// String locationmod=tmplist[1]; +// String fixed=tmplist[2]; +// String hdop=tmplist[16]; +// if (!fixed.trim().equals("1")){ +// //定位 +// ICLogger.i("GPGSA fixed="+fixed+",hdop="+hdop); +// } } } @@ -350,51 +359,6 @@ public class NMEAListener implements NmeaListener, LocationListener { boolean b3 = locationManager.sendExtraCommand("gps", "delete_aiding_data", bundleHot); return b3; } - private GpsStatus.Listener statusListener = new GpsStatus.Listener() { - public void onGpsStatusChanged(int event) { // GPS状态变化时的回调,如卫星数 - GpsStatus status = locationManager.getGpsStatus(null); //取当前状态 - updateGpsStatus(event, status); //只更新状态 - numberOfSatellites = numSatelliteList.size(); - - switch (event){ - case GpsStatus.GPS_EVENT_SATELLITE_STATUS: - - - - break; - case GpsStatus.GPS_EVENT_FIRST_FIX: - //普通测试,必须定位才算通过 -// +" cost "+status.getTimeToFirstFix()+"ms"); -// 定位算通过 - gpsMode = GPS_CURRENT_STATUS.GPS_FIXED; - - ICLogger.i("GPS_EVENT_FIRST_FIX !"); - // delaystop(); - - break; - case GpsStatus.GPS_EVENT_STARTED: - // tvGps.setText("GPS_EVENT_STARTED"); - gpsMode=GPS_CURRENT_STATUS.GPS_LISTENING; - runtime.getLocationInstance().setLocationStat(ICLocation.LOCATION_STAT.LOCATION_SEARCHING); - - listening=true; - break; - case GpsStatus.GPS_EVENT_STOPPED: - // tvGps.setText("GPS_EVENT_STOPPED"); - gpsMode = GPS_CURRENT_STATUS.GPS_NOSINGAL; -// runtime.getLocationInstance().setLocationStat(ICLocation.LOCATION_STAT.LOCATION_CLOSED); - - listening=false; - break; - default: - break; - } - - - - - } - }; private final int MSG_WHAT_GPS_FIXED=300; @@ -446,70 +410,11 @@ public class NMEAListener implements NmeaListener, LocationListener { } } } - if (max3Satellite.size()>3){ //超过三个,谁小就删掉 - max3Satellite.remove(3); + if (max3Satellite.size()>5){ //超过三个,谁小就删掉 + max3Satellite.remove(5); } } - private int updateGpsStatus(int event, GpsStatus status) { - StringBuilder sb2 = new StringBuilder(""); - float strengh = 0; - searchCout++; - if (status == null) { - sb2.append("搜索"+searchCout+"次,搜到卫星个数:" + 0); - noSignalCount++; - } else if (event == GpsStatus.GPS_EVENT_SATELLITE_STATUS) { - int maxSatellites = status.getMaxSatellites(); - Iterator it = status.getSatellites().iterator(); - numSatelliteList.clear(); - int count = 0; - while (it.hasNext() && count <= maxSatellites) { - GpsSatellite s = it.next(); - float snr = s.getSnr(); - if (snr > 0) {//只有信躁比不为0的时候才算搜到了星 - strengh = snr; -// Toast.makeText(this, "信躁比大于20", Toast.LENGTH_LONG).show(); - //排序取得最大3个SNR - get3MaxSnrSatellite(new GpsSatellitePriv(s.getPrn(),s.getSnr())); - numSatelliteList.add(new GpsSatellitePriv(s.getPrn(),s.getSnr())); - } - - count++; - } - sb2.append("搜索"+searchCout+"次,搜索到卫星个数:"+count+" , (SNR>0):" + numSatelliteList.size()+" \n Max 3 SNRs[ " ); - for (int i=0;i0?(max3Satellite.get(0).getSnr()<20?true:false) : true)){ - noSignalCount++; - } - } - - if(!noStop) { - if (searchCout > SearchTimeout) { - sb2.append(" 搜索" + searchCout + "次未定位,超过" + SearchTimeout + "限制退出GPS定位"); - gpsMode = GPS_CURRENT_STATUS.GPS_TIMEOUT; - runtime.getLocationInstance().setLocationStat(ICLocation.LOCATION_STAT.LOCATION_GPS_TIEMOUT); - - stop(MSG_WHAT_GPS_TIMEOUT); - } - if (noSignalCount > 10) { - sb2.append(" 搜索" + searchCout + "次,超过" + noSignalCount + "次没有收到星,退出GPS定位"); - gpsMode = GPS_CURRENT_STATUS.GPS_NOSINGAL; - runtime.getLocationInstance().setLocationStat(ICLocation.LOCATION_STAT.LOCATION_GPS_TIEMOUT); - - stop(MSG_WHAT_GPS_NOSTAR); - } - } - if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(this.runtime.getCacheDir(),"GPS",sb2.toString()); - ICLogger.i( sb2.toString()); - getBestLocation(locationManager,status); - - return 0; - } //停止定位 private void stop(int id){ @@ -537,96 +442,6 @@ public class NMEAListener implements NmeaListener, LocationListener { } boolean isFrist = true; - /** - * 获取location对象,优先以GPS_PROVIDER获取location对象,当以GPS_PROVIDER获取到的locaiton为null时 - * ,则以NETWORK_PROVIDER获取location对象,这样可保证在室内开启网络连接的状态下获取到的location对象不为空 - * - * @param locationManager - * @return - */ - private void getBestLocation(LocationManager locationManager,GpsStatus status) { - Location location = null; - if (locationManager != null) { - - location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); - if (location == null) { - ICLogger.i(" GPS Provider get failed , get Network Provider!"); - location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); - } - - /* - 只有当前GPS已经定位,且location不为空才给 runtime赋值GPS坐标。 - 延迟三秒后才设置runtime的定位标志,以便稳定坐标值。 - */ -// if (location != null && gpsMode == GPS_CURRENT_STATUS.GPS_FIXED ) { - if (location != null ) { - longitude = location.getLongitude(); - latitude = location.getLatitude(); - - - if (longitude > 0 && latitude > 0 ) { - - //log msg变量 - StringBuffer sb = new StringBuffer(); - // 经纬度 保留6位小数点 - DecimalFormat df = new DecimalFormat("#.000000"); - String strLatitude = df.format(latitude); - String strLongitude = df.format(longitude); - - sb.append(" orig lat=").append(strLatitude).append(", orig lon=").append(strLongitude); - // 转换单位,从度转换到分 - double intfen= ((longitude - (int)longitude))*60; //小数转换到分为单位 -// double miao= (longitude*100 - (int)(longitude*100)); // - double last= ((int)longitude)*100 +intfen; - longitude =last; - intfen= (latitude - (int)latitude)*60;//小数转换到分为单位 -// miao= (latitude*100 - (int)(latitude*100)); - last= ((int)latitude)*100 +intfen; - latitude=last; - - //sucess - long gpsTime = location.getTime(); - - double altitude = location.getAltitude();// 海拔 - - // 速度 - float speed = location.getSpeed();// 速度 单位 m/s - speed = (speed * 60) / 1000; // 单位转换 km/h - // 保留一位小数点 - DecimalFormat dfSpeed = new DecimalFormat("#.0"); - String strSpeed = dfSpeed.format(speed); - speed = Float.parseFloat(strSpeed); - int intSpeed = (int) (speed * 10); - // SimpleLogger.d("intSpeed:"+intSpeed); - - // 经纬度 保留4位小数点 - df = new DecimalFormat("#.0000"); - strLatitude = df.format(latitude); - strLongitude = df.format(longitude); - - locationFixedCount++; - - sb.append(", gps time= "+TimeUtil.getLocalTime(gpsTime)+" ,lon= " + strLongitude + ", lat= " + strLatitude +" FixedCount="+locationFixedCount+", TimeToFirstFix="+status.getTimeToFirstFix()); - ICLogger.i( sb.toString()); - if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(this.runtime.getCacheDir(),"GPS",sb.toString()); - runtime.getLocationInstance().setLocation(latitude,longitude,speed,0,status.getMaxSatellites()); - if (locationFixedCount > MaxFixedTimes ){ - /* - 只有当前GPS已经定位,且location不为空才给 runtime赋值GPS坐标。 - 延迟MaxFixedTimes秒后才设置runtime的定位标志,以便稳定坐标值。 - */ - runtime.getLocationInstance().setLocationStat(ICLocation.LOCATION_STAT.LOCATION_FIXED); - if(!noStop){ - stopListen(); - } - } - } - - } - } - } - - public boolean startListen() { diff --git a/app/src/main/java/com/enqualcomm/support/adapter/LBSHelper.java b/app/src/main/java/com/enqualcomm/support/adapter/LBSHelper.java index c21765e3..cd605851 100644 --- a/app/src/main/java/com/enqualcomm/support/adapter/LBSHelper.java +++ b/app/src/main/java/com/enqualcomm/support/adapter/LBSHelper.java @@ -23,6 +23,7 @@ import android.telephony.gsm.GsmCellLocation; import com.enqualcomm.support.Config; import com.enqualcomm.support.bean.Runtime; +import com.enqualcomm.support.utils.DeviceInfoUtil; import com.enqualcomm.support.utils.FileOutputUtil; import com.enqualcomm.support.utils.ICLogger; import com.enqualcomm.support.utils.SimSignalUtil; @@ -31,8 +32,6 @@ import java.util.Collections; import java.util.Comparator; import java.util.Iterator; import java.util.List; -import java.util.Timer; -import java.util.TimerTask; import static android.net.wifi.WifiManager.WIFI_STATE_DISABLED; import static android.net.wifi.WifiManager.WIFI_STATE_DISABLING; @@ -48,10 +47,9 @@ public class LBSHelper { private Context context; Handler mHandler; private int mLastSignal; - private LBSHelper.OnWiFiInfoListener mListener; - private LBSHelper.MyPhoneStateListener mMyListener; + private LBSHelper.OnWiFiInfoListener mMyWifiListener; + private LBSHelper.MyPhoneStateListener mMyPhoneListener; int mNetworkType; - private static Timer mTimer; public Runtime runtime; private BroadcastReceiver wifiChangedReceiver; private String wifiInfoResult; @@ -63,10 +61,10 @@ public class LBSHelper { this.context = _context; this.runtime = dev; initHelper(); - registerBroadReceiver(); - this.mMyListener = new LBSHelper.MyPhoneStateListener(); +// registerWiFiBroadReceiver(); + this.mMyPhoneListener = new LBSHelper.MyPhoneStateListener(); TelephonyManager tm = ((TelephonyManager) LBSHelper.this.context.getSystemService(Context.TELEPHONY_SERVICE)); - tm.listen(this.mMyListener, LISTEN_SIGNAL_STRENGTHS); + tm.listen(this.mMyPhoneListener, LISTEN_SIGNAL_STRENGTHS); this.mNetworkType = tm.getNetworkType(); } @@ -76,95 +74,33 @@ public class LBSHelper { public void handleMessage(Message msg) { super.handleMessage(msg); if (msg.what == 104) { - LBSHelper.this.wifiManager.setWifiEnabled(false); - if (LBSHelper.this.mListener != null) { - LBSHelper.this.mListener.getWifiInfoCallBack((String) null); + //停止扫描 + StringBuilder sb = LBSHelper.this.handScanResults(); + if (sb == null) { + LBSHelper.this.wifiInfoResult = null; + } else { + LBSHelper.this.wifiInfoResult = sb.toString(); } - - LBSHelper.this.mTimer = null; - } - } - }; - this.wifiChangedReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - -// WIFI_STATE_DISABLING = 0 -// WIFI_STATE_DISABLED = 1 -// WIFI_STATE_ENABLING = 2 -// WIFI_STATE_ENABLED = 3 -// WIFI_STATE_UNKNOWN = 4 - switch (intent.getIntExtra("wifi_state", 0)) { - case WIFI_STATE_ENABLED: - LBSHelper.this.wifiManager.startScan(); - if (LBSHelper.this.mListener == null) { - LBSHelper.this.mMyListener = new MyPhoneStateListener(); - - } - - if (LBSHelper.this.IS_OPEN) { - (new Thread(new Runnable() { - public void run() { - SystemClock.sleep(3000L); - StringBuilder sb = LBSHelper.this.handScanResults(); - if (sb == null) { - LBSHelper.this.wifiInfoResult = null; - } else { - LBSHelper.this.wifiInfoResult = sb.toString(); - } - - LBSHelper.this.mListener.getWifiInfoCallBack(LBSHelper.this.wifiInfoResult); - LBSHelper.this.wifiManager.setWifiEnabled(false); - LBSHelper.this.IS_OPEN = false; - LBSHelper.this.IS_HASOPEN = false; - if (LBSHelper.this.mTimer != null) { - LBSHelper.this.mTimer.cancel(); - LBSHelper.this.mTimer.purge(); - LBSHelper.this.mTimer = null; - } - - } - })).start(); - return; - } else if (LBSHelper.this.IS_HASOPEN) { - if (LBSHelper.this.wifiManager == null) { - if (LBSHelper.this.mListener != null) { - LBSHelper.this.mListener.getWifiInfoCallBack((String) null); - } - - return; + if (LBSHelper.this.mMyWifiListener != null) { + LBSHelper.this.mMyWifiListener.getWifiInfoCallBack(LBSHelper.this.wifiInfoResult); + + if ((runtime.isNoTurnOffWifiOnScreenOff() && !SimSignalUtil.isScreenON(runtime.getContextProxy().context)) || DeviceInfoUtil.isFactoryTestTopActivity(runtime.getContextProxy().context)) + { + //如果 NoTurnOffWifiOnScreenOff 开关 开启,且是屏灭,或者是在工厂测试模式,则原来什么状态就什么状态。 + if (!IS_HASOPEN && IS_OPEN) { + wifiManager.setWifiEnabled(false); + IS_OPEN = false; } - - (new Thread(new Runnable() { - public void run() { - SystemClock.sleep(3000L); - StringBuilder sb = LBSHelper.this.handScanResults(); - if (sb == null) { - LBSHelper.this.wifiInfoResult = null; - } else { - LBSHelper.this.wifiInfoResult = sb.toString(); - } - - LBSHelper.this.mListener.getWifiInfoCallBack(LBSHelper.this.wifiInfoResult); - LBSHelper.this.IS_OPEN = false; - LBSHelper.this.IS_HASOPEN = false; - } - })).start(); - return; - } else if (LBSHelper.this.mListener != null) { - LBSHelper.this.mListener.getWifiInfoCallBack((String) null); + }else if (!SimSignalUtil.isScreenON(runtime.getContextProxy().context) && !runtime.isNoTurnOffWifiOnScreenOff()){ + //如果 NoTurnOffWifiOnScreenOff 开关 关闭,且是屏灭,则关闭wifi省电 + wifiManager.setWifiEnabled(false); + IS_OPEN = false; + IS_HASOPEN=false; } - case WIFI_STATE_DISABLING: - case WIFI_STATE_DISABLED: - case WIFI_STATE_ENABLING: - case WIFI_STATE_UNKNOWN: - return; - default: + } } } }; - - } @@ -207,32 +143,23 @@ public class LBSHelper { }); } - private void startTimer() { - if (this.mTimer == null) { - this.mTimer = new Timer(); - } - - this.mTimer.schedule(new TimerTask() { - @Override - public void run() { - LBSHelper.this.mHandler.sendEmptyMessage(104); - } - }, 10000L); + private void delayedStopScan() { + LBSHelper.this.mHandler.sendEmptyMessageDelayed(104,3000L); } - public void unRegisterBroadReceiver() { - this.context.unregisterReceiver(this.wifiChangedReceiver); - } +// public void unRegisterWiFiBroadReceiver() { +// this.context.unregisterReceiver(this.wifiChangedReceiver); +// } public String getAttchCellInfo(TelephonyManager tm) { return this.getCellInfo(tm); } public String getCellInfo(TelephonyManager telephonyManager) { - int var3 = Build.VERSION.SDK_INT; +// int var3 = Build.VERSION.SDK_INT; int var2 = 0; String var4; - if (var3 > 23) { + if (Build.VERSION.SDK_INT > 23) { var4 = telephonyManager.getSimOperator(); if (var4 == null) { ICLogger.i("operator == null"); @@ -290,9 +217,8 @@ public class LBSHelper { gsmSb.append(mNeighboringCellInfo.getCid()); gsmSb.append("@"); gsmSb.append(mNeighboringCellInfo.getRssi() + 110); - var3 = var2 + 1; - var2 = var3; - if (var3 == 5) { + var2 ++; + if (var2 == 5) { break; } } @@ -339,18 +265,27 @@ public class LBSHelper { } else { this.wifiManager.setWifiEnabled(true); this.IS_OPEN = true; - this.startTimer(); + try { + Thread.sleep(500); + } catch (InterruptedException e) { + e.printStackTrace(); + } } - } + wifiManager.startScan(); + delayedStopScan(); - public void registerBroadReceiver() { - IntentFilter var1 = new IntentFilter(); - var1.addAction("android.net.wifi.WIFI_STATE_CHANGED"); - this.context.registerReceiver(this.wifiChangedReceiver, var1); } - public void setOnWiFiInfoListener(LBSHelper.OnWiFiInfoListener var1) { - this.mListener = var1; +// public void registerWiFiBroadReceiver() { +// IntentFilter filter = new IntentFilter(); +// filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);//监听wifi是开关变化的状态 +// filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);//监听wifiwifi连接状态广播 +// filter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);//监听wifi列表变化(开启一个热点或者关闭一个热点) +// this.context.registerReceiver(this.wifiChangedReceiver, filter); +// } + + public void setOnWiFiInfoListener(LBSHelper.OnWiFiInfoListener wiFiInfoListener) { + this.mMyWifiListener = wiFiInfoListener; } private class MyPhoneStateListener extends PhoneStateListener { diff --git a/app/src/main/java/com/enqualcomm/support/adapter/protocolAPIHelper.java b/app/src/main/java/com/enqualcomm/support/adapter/protocolAPIHelper.java index 0df8f4d6..d4d72fd7 100644 --- a/app/src/main/java/com/enqualcomm/support/adapter/protocolAPIHelper.java +++ b/app/src/main/java/com/enqualcomm/support/adapter/protocolAPIHelper.java @@ -902,17 +902,17 @@ public class protocolAPIHelper { log("work mode "+cmdlist[3]); int mod=Integer.valueOf(cmdlist[3]); - int Cycle=15; + int Cycle=900; switch(mod){ case ICLocation.NORMAL_MOD: - Cycle=15; + Cycle=900; break; case ICLocation.LOWPOWER_MOD: - Cycle=60; + Cycle=3600; break; case ICLocation.EMERGNECY_MOD: case ICLocation.REALTIME_MOD: - Cycle=1; + Cycle=60; break; } 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 3aded226..3b5dff2f 100644 --- a/app/src/main/java/com/enqualcomm/support/bean/ICLocation.java +++ b/app/src/main/java/com/enqualcomm/support/bean/ICLocation.java @@ -10,11 +10,12 @@ public class ICLocation { public class GPS_LocationPoint{ public double lat; public double lon; - public double speed; - public double heading; + public float speed; + public float heading; public int used_gps_numbs; public String latStr; public String lonStr; + public float hdop; } public class LBS_Data{ HashMap wifi_aps=null; @@ -98,7 +99,47 @@ public class ICLocation { return currentLP; } - public void setLocation(double lat,double lon,double speed,double heading,int userdgpsnumbers){ + public void setHod(float _hot){ + currentLP.hdop=_hot; + } + + public float getHdop(){ + return currentLP.hdop; + } + + public void setSpeed( float _speed){ + currentLP.speed=_speed; + } + public float getSpeed(){ + return currentLP.speed; + } + + public void setLocation(double lat,double lon){ + currentLP.lat=lat; + currentLP.lon=lon; + } + public void setLocation(String lat,String lon){ + currentLP.latStr=lat; + currentLP.lonStr=lon; + } + + public void setHeading(float heding){ + currentLP.heading=heding; + } + + public float getheading(){ + return currentLP.heading; + } + + public void setUsedStarts(int starts){ + currentLP.used_gps_numbs=starts; + } + + public int getUsedStarts(){ + return currentLP.used_gps_numbs; + } + + public void setLocation(double lat,double lon,float speed,float heading,int userdgpsnumbers,float hdop){ currentLP.lat=lat; currentLP.lon=lon; currentLP.speed=speed; @@ -106,8 +147,9 @@ public class ICLocation { currentLP.used_gps_numbs = userdgpsnumbers; currentLP.latStr=""; currentLP.lonStr=""; + currentLP.hdop=hdop; } - public void setLocation(String lat,String lon,double speed,double heading,int userdgpsnumbers){ + public void setLocation(String lat,String lon,float speed,float heading,int userdgpsnumbers,float hdop){ currentLP.lat=0; currentLP.lon=0; currentLP.speed=speed; @@ -115,6 +157,7 @@ public class ICLocation { currentLP.used_gps_numbs = userdgpsnumbers; currentLP.latStr=lat; currentLP.lonStr=lon; + currentLP.hdop=99.9f; } public void clearLBSdata(){ 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 7c7e39c3..62649410 100644 --- a/app/src/main/java/com/enqualcomm/support/service/KeepAlive.java +++ b/app/src/main/java/com/enqualcomm/support/service/KeepAlive.java @@ -194,13 +194,13 @@ public class KeepAlive extends AbstractConnectionService { stringBuilder.append(",,first="); stringBuilder.append(this.first); ICLogger.i(stringBuilder.toString()); - if (param1Integer.intValue() > 0) { + if (param1Integer.intValue() > 1) { //返回值大于0 证明是网络连接成功,开始重连服务器 if (this.first) { this.first = false; return; } - ICLogger.i("数据网络连接成功,重新连接网络。"); + ICLogger.i("数据网络连接成功,重新连接服务器。"); CoreService.getInstance().ReConnectToServer(); } } @@ -220,7 +220,7 @@ public class KeepAlive extends AbstractConnectionService { connectionError = true; isConnected = false; paramRuntime.setServerProtocolConnected(false); - paramRuntime.getContextProxy().sendBroadcast(isConnected); + paramRuntime.getContextProxy().sendBroadcast(false); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("onConnectionClose="); stringBuilder.append(",set KeepAlive isConnected = false"); @@ -305,7 +305,7 @@ public class KeepAlive extends AbstractConnectionService { // isConnected = true; is_heartBeat_send_success=true; //广播服务器连接成功的消息 - paramRuntime.getContextProxy().sendBroadcast(isConnected); + paramRuntime.getContextProxy().sendBroadcast(true); LauncherCtrl.getInstance(this.mContext).setStatusBarIcon("server_connected", STATUS_BAR_STATE_SERVER_CONNECTED_ON); // Deliver.triggerSendThread(); //链接上就尝试清除 buffer中的数据 CoreService.getInstance().stopConnectionRetryTimer(); 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 31b8e553..0fd092c0 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/CellInfoUtil.java +++ b/app/src/main/java/com/enqualcomm/support/utils/CellInfoUtil.java @@ -79,6 +79,8 @@ public class CellInfoUtil { public void run() { if (mRuntime !=null) { + + //更新lbs信息 CellInfoUtil.mCellInfo = mRuntime.getLbsHelper().getAttchCellInfo(mRuntime.getContextProxy().getTelephonyManager()); if (mCellInfo != null) { diff --git a/app/src/main/java/com/enqualcomm/support/utils/NetworkObservable.java b/app/src/main/java/com/enqualcomm/support/utils/NetworkObservable.java index 5e137de9..632ded28 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/NetworkObservable.java +++ b/app/src/main/java/com/enqualcomm/support/utils/NetworkObservable.java @@ -5,48 +5,66 @@ package com.enqualcomm.support.utils; import android.content.Intent; import android.content.IntentFilter; import android.net.ConnectivityManager; + import android.net.Network; import android.net.NetworkInfo; import com.enqualcomm.support.service.KeepAlive; import rx.Observable; import rx.subjects.BehaviorSubject; public class NetworkObservable { + static String lastActivType="off"; BroadcastReceiver mNetStateBroadcastReceiver = new BroadcastReceiver() { - public void onReceive(Context var1, Intent var2) { - NetworkInfo networkInfo = ((ConnectivityManager)var1.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo(); - if (networkInfo != null && networkInfo.isAvailable()) { + public void onReceive(Context context, Intent intent) { + NetworkInfo networkInfo = ((ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo(); +// NetworkInfo wifiinfo=((ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE)).getNetworkInfo(ConnectivityManager.TYPE_WIFI); +// NetworkInfo mobileinfo=((ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE)).getNetworkInfo(ConnectivityManager.TYPE_MOBILE); +// ICLogger.i("active network type = "+wifiinfo.getTypeName()+", status="+wifiinfo.getState().name()); +// ICLogger.i("active network type = "+mobileinfo.getTypeName()+", status="+mobileinfo.getState().name()); + if (networkInfo != null && networkInfo.isAvailable()) { + if (lastActivType!=networkInfo.getTypeName()){ + lastActivType=networkInfo.getTypeName(); + active_network_changed=true; + }else{ + active_network_changed=false; + } StringBuilder var4 = new StringBuilder(); - var4.append("BroadcastReceiver---reConnection++ KeepAlive.isConnected="); + + var4.append("BroadcastReceiver---网络连接成功 KeepAlive.isConnected="); var4.append(KeepAlive.isConnected); - var4.append(",network_is_down="); - var4.append(NetworkObservable.this.network_is_down); + var4.append(",active_network_changed="); + var4.append(active_network_changed); var4.append(",network_is_from_no_to_yes="); - var4.append(NetworkObservable.this.network_is_from_no_to_yes); + var4.append(network_is_from_no_to_yes); + var4.append(",network_type=").append(networkInfo.getTypeName()); ICLogger.i(var4.toString()); - if (!KeepAlive.isConnected && !NetworkObservable.this.network_is_from_no_to_yes) { - if (NetworkObservable.this.network_is_down) { - - NetworkObservable.this.objectPublishSubject.onNext(3); - NetworkObservable.this.network_is_down = false; + if (!KeepAlive.isConnected && !network_is_from_no_to_yes) { + //如果serversocket 未连接成功,且之前网络未断开重连 + if (active_network_changed) { + //如果之前一次是网络断开,则重连 + objectPublishSubject.onNext(2); } else { - NetworkObservable.this.objectPublishSubject.onNext(2); - NetworkObservable.this.network_is_down = true; + //如果之前网络正常,则无需重连 + objectPublishSubject.onNext(1); } - } else if (NetworkObservable.this.network_is_from_no_to_yes) { - NetworkObservable.this.objectPublishSubject.onNext(1); + } else if (network_is_from_no_to_yes) { + //如果是断网重连,则证明需要重连 + objectPublishSubject.onNext(3); } else if (KeepAlive.isConnected) { - NetworkObservable.this.network_is_down = false; + //如果网络实际连接的,就无需重连 + active_network_changed = false; } - NetworkObservable.this.network_is_from_no_to_yes = false; + //下次在有新状态,无需重连 + network_is_from_no_to_yes = false; } else { ICLogger.i("网络断开"); - NetworkObservable.this.network_is_from_no_to_yes = true; - NetworkObservable.this.objectPublishSubject.onNext(0); + lastActivType="off"; + network_is_from_no_to_yes = true; //断网了,则下次变化必然是 FromNoToYes,需要重连 所以为 True + objectPublishSubject.onNext(0); //发送断网消息。 } } }; - private boolean network_is_down = false; + private boolean active_network_changed = false; private boolean network_is_from_no_to_yes = true; BehaviorSubject objectPublishSubject = BehaviorSubject.create(); 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 4157b411..68d48b35 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/SimSignalUtil.java +++ b/app/src/main/java/com/enqualcomm/support/utils/SimSignalUtil.java @@ -181,9 +181,9 @@ public class SimSignalUtil { this.mNetworkType = ((TelephonyManager)this.context.getSystemService(Context.TELEPHONY_SERVICE)).getNetworkType(); } - public boolean isScreenON() { + public static boolean isScreenON(Context context) { // If you use less than API20: - PowerManager powerManager = (PowerManager) this.context.getSystemService(POWER_SERVICE); + PowerManager powerManager = (PowerManager) context.getSystemService(POWER_SERVICE); // If the screen is off then the device has been locked boolean lisScreenOn; diff --git a/app/version_code.properties b/app/version_code.properties index efadc263..139e467c 100644 --- a/app/version_code.properties +++ b/app/version_code.properties @@ -1,2 +1,2 @@ -#Wed Mar 11 02:07:29 CST 2020 -VERSION_CODE=373 +#Fri Mar 13 10:11:53 CST 2020 +VERSION_CODE=374