From c5560825980e7e2926e50253fc46ffd31dc84ac4 Mon Sep 17 00:00:00 2001 From: fanhuitong <981964879@qq.com> Date: Thu, 24 Nov 2022 09:38:05 +0800 Subject: [PATCH] =?UTF-8?q?version:2.2=20fix:=E4=BC=98=E5=8C=96=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E8=AF=B7=E6=B1=82=20update:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 4 +- .../com/fuying/sn/manager/AmapManager.java | 174 +----------------- .../sn/network/NetInterfaceManager.java | 14 ++ .../com/fuying/sn/service/StepService.java | 5 +- .../fuying/sn/service/main/MainService.java | 4 +- .../com/fuying/sn/tpush/MessageReceiver.java | 2 +- 6 files changed, 27 insertions(+), 176 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index de8cf2b..acfc2f1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -73,8 +73,8 @@ android { official { flavorDimensions "default" - versionCode 11 - versionName "2.0" + versionCode 13 + versionName "2.2" } } diff --git a/app/src/main/java/com/fuying/sn/manager/AmapManager.java b/app/src/main/java/com/fuying/sn/manager/AmapManager.java index 6813638..1ee6885 100644 --- a/app/src/main/java/com/fuying/sn/manager/AmapManager.java +++ b/app/src/main/java/com/fuying/sn/manager/AmapManager.java @@ -2,6 +2,7 @@ package com.fuying.sn.manager; import android.annotation.SuppressLint; import android.content.Context; +import android.provider.Settings; import android.util.Log; import com.baidu.location.BDAbstractLocationListener; @@ -16,12 +17,12 @@ public class AmapManager { private static AmapManager sInstance; private Context mContext; @SuppressLint("StaticFieldLeak") -// public static AMapLocationClient locationClient = null; private LocationClient mLocationClient = null; private LocationClientOption mOption; private AmapManager(Context context) { this.mContext = context; + Settings.Secure.putString(mContext.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "+gps"); initAmap(); } @@ -45,13 +46,13 @@ public class AmapManager { if (mLocationClient == null) { mLocationClient = new LocationClient(mContext); } + Settings.Secure.putString(mContext.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "+gps"); mLocationClient.setLocOption(getDefaultLocationClientOption()); mLocationClient.registerLocationListener(mListener); mLocationClient.stop(); mLocationClient.start(); } - public LocationClient getLocationClient() { if (mLocationClient == null) { initAmap(); @@ -76,7 +77,7 @@ public class AmapManager { mOption.setIsNeedLocationDescribe(true); // 可选,默认false,设置是否需要位置语义化结果,可以在BDLocation mOption.setIsNeedLocationPoiList(true); // 可选,默认false,设置是否需要POI结果,可以在BDLocation mOption.SetIgnoreCacheException(false); // 可选,默认false,设置是否收集CRASH信息,默认收集 - mOption.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy); // 可选,默认高精度,设置定位模式,高精度,低功耗,仅设备,模糊 + mOption.setLocationMode(LocationClientOption.LocationMode.Battery_Saving); // 可选,默认高精度,设置定位模式,高精度,低功耗,仅设备,模糊 mOption.setIsNeedAltitude(false); // 可选,默认false,设置定位时是否需要海拔信息,默认不需要,除基础定位版本都可用 // 可选,设置首次定位时选择定位速度优先还是定位准确性优先,默认为速度优先 // mOption.setFirstLocType(LocationClientOption.FirstLocType.SPEED_IN_FIRST_LOC); @@ -125,115 +126,11 @@ public class AmapManager { default: } } -// if (null != location && location.getLocType() != BDLocation.TypeServerError) { -// StringBuffer sb = new StringBuffer(256); -// sb.append("time : "); -// /** -// * 时间也可以使用systemClock.elapsedRealtime()方法 获取的是自从开机以来,每次回调的时间; -// * location.getTime() 是指服务端出本次结果的时间,如果位置不发生变化,则时间不变 -// */ -// sb.append(location.getTime()); -// sb.append("\nsysTime : "); -// sb.append(SystemClock.elapsedRealtime()); -// sb.append("\nlocType : ");// 定位类型 -// sb.append(location.getLocType()); -// sb.append("\nlocType description : ");// *****对应的定位类型说明***** -// sb.append(location.getLocTypeDescription()); -// sb.append("\nlatitude : ");// 纬度 -// sb.append(location.getLatitude()); -// sb.append("\nlongtitude : ");// 经度 -// sb.append(location.getLongitude()); -// sb.append("\nradius : ");// 半径 -// sb.append(location.getRadius()); -// sb.append("\nCountryCode : ");// 国家码 -// sb.append(location.getCountryCode()); -// sb.append("\nProvince : ");// 获取省份 -// sb.append(location.getProvince()); -// sb.append("\nCountry : ");// 国家名称 -// sb.append(location.getCountry()); -// sb.append("\ncitycode : ");// 城市编码 -// sb.append(location.getCityCode()); -// sb.append("\ncity : ");// 城市 -// sb.append(location.getCity()); -// sb.append("\nDistrict : ");// 区 -// sb.append(location.getDistrict()); -// sb.append("\nTown : ");// 获取镇信息 -// sb.append(location.getTown()); -// sb.append("\nStreet : ");// 街道 -// sb.append(location.getStreet()); -// sb.append("\naddr : ");// 地址信息 -// sb.append(location.getAddrStr()); -// sb.append("\nStreetNumber : ");// 获取街道号码 -// sb.append(location.getStreetNumber()); -// sb.append("\nUserIndoorState: ");// *****返回用户室内外判断结果***** -// sb.append(location.getUserIndoorState()); -// sb.append("\nDirection(not all devices have value): "); -// sb.append(location.getDirection());// 方向 -// sb.append("\nlocationdescribe: "); -// sb.append(location.getLocationDescribe());// 位置语义化信息 -// sb.append("\nPoi: ");// POI信息 -// if (location.getPoiList() != null && !location.getPoiList().isEmpty()) { -// for (int i = 0; i < location.getPoiList().size(); i++) { -// Poi poi = (Poi) location.getPoiList().get(i); -// sb.append("poiName:"); -// sb.append(poi.getName() + ", "); -// sb.append("poiTag:"); -// sb.append(poi.getTags() + "\n"); -// } -// } -// if (location.getPoiRegion() != null) { -// sb.append("PoiRegion: ");// 返回定位位置相对poi的位置关系,仅在开发者设置需要POI信息时才会返回,在网络不通或无法获取时有可能返回null -// PoiRegion poiRegion = location.getPoiRegion(); -// sb.append("DerectionDesc:"); // 获取POIREGION的位置关系,ex:"内" -// sb.append(poiRegion.getDerectionDesc() + "; "); -// sb.append("Name:"); // 获取POIREGION的名字字符串 -// sb.append(poiRegion.getName() + "; "); -// sb.append("Tags:"); // 获取POIREGION的类型 -// sb.append(poiRegion.getTags() + "; "); -// sb.append("\nSDK版本: "); -// } -//// int permission = checkPermission(getApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION); -//// sb.append("\npermsission: " + permission); -//// sb.append(locationService.getSDKVersion()); // 获取SDK版本 -// if (location.getLocType() == BDLocation.TypeGpsLocation) {// GPS定位结果 -// sb.append("\nspeed : "); -// sb.append(location.getSpeed());// 速度 单位:km/h -// sb.append("\nsatellite : "); -// sb.append(location.getSatelliteNumber());// 卫星数目 -// sb.append("\nheight : "); -// sb.append(location.getAltitude());// 海拔高度 单位:米 -// sb.append("\ngps status : "); -// sb.append(location.getGpsAccuracyStatus());// *****gps质量判断***** -// sb.append("\ndescribe : "); -// sb.append("gps定位成功"); -// } else if (location.getLocType() == BDLocation.TypeNetWorkLocation) {// 网络定位结果 -// // 运营商信息 -// if (location.hasAltitude()) {// *****如果有海拔高度***** -// sb.append("\nheight : "); -// sb.append(location.getAltitude());// 单位:米 -// } -// sb.append("\noperationers : ");// 运营商信息 -// sb.append(location.getOperators()); -// sb.append("\ndescribe : "); -// sb.append("网络定位成功"); -// } else if (location.getLocType() == BDLocation.TypeOffLineLocation) {// 离线定位结果 -// sb.append("\ndescribe : "); -// sb.append("离线定位成功,离线定位结果也是有效的"); -// } else if (location.getLocType() == BDLocation.TypeServerError) { -// sb.append("\ndescribe : "); -// sb.append("服务端网络定位失败,可以反馈IMEI号和大体定位时间到loc-bugs@baidu.com,会有人追查原因"); -// } else if (location.getLocType() == BDLocation.TypeNetWorkException) { -// sb.append("\ndescribe : "); -// sb.append("网络不同导致定位失败,请检查网络是否通畅"); -// } else if (location.getLocType() == BDLocation.TypeCriteriaException) { -// sb.append("\ndescribe : "); -// sb.append("无法获取有效定位依据导致定位失败,一般是由于手机的原因,处于飞行模式下一般会造成这种结果,可以试着重启手机"); -// } -//// logMsg(sb.toString(), tag); -// Log.e(TAG, "onReceiveLocation: " + sb); -// } Log.e(TAG, "AmapAddress: " + (String) SPUtils.get(mContext, "AmapAddress", "-")); Log.e(TAG, "AmapError: " + (String) SPUtils.get(mContext, "AmapError", "-")); + Settings.Secure.putString(mContext.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "-network"); + Settings.Secure.putString(mContext.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "-gps"); + Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.ASSISTED_GPS_ENABLED, 0); } @Override @@ -292,63 +189,6 @@ public class AmapManager { Log.e(TAG, "onLocationChanged: " + "定位失败"); SPUtils.put(mContext, "AmapError", sb); Log.e(TAG, "onLocDiagnosticMessage: " + sb); -// logMsg(sb.toString(), tag); } }; - -// public AMapLocationClient getLocationClient() { -// if (null == locationClient) { -// initAmap(); -// } -// return locationClient; -// } - -// public void initAmap() { -// locationClient = new AMapLocationClient(mContext); -// AMapLocationClientOption option = new AMapLocationClientOption(); -// option.setLocationPurpose(AMapLocationClientOption.AMapLocationPurpose.SignIn); -// option.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy); -// option.setNeedAddress(true); -// //获取一次定位结果: -// //该方法默认为false。 -// option.setOnceLocation(true); -// //获取最近3s内精度最高的一次定位结果: -// //设置setOnceLocationLatest(boolean b)接口为true,启动定位时SDK会返回最近3s内精度最高的一次定位结果。 -// // 如果设置其为true,setOnceLocation(boolean b)接口也会被设置为true,反之不会,默认为false。 -// option.setOnceLocationLatest(true); -// locationClient.setLocationOption(option); -// //设置定位模式为AMapLocationMode.Hight_Accuracy,高精度模式。 -// //设置定位监听 -// locationClient.setLocationListener(new AMapLocationListener() { -// -// @Override -// public void onLocationChanged(AMapLocation aMapLocation) { -// StringBuilder sb = new StringBuilder(); -// //errCode等于0代表定位成功,其他的为定位失败,具体的可以参照官网定位错误码说明 -// if (aMapLocation.getErrorCode() == 0) { -// Log.e(TAG, "onLocationChanged: " + "定位成功"); -// Log.e(TAG, "onLocationChanged: " + aMapLocation.getAddress()); -// sb.append(aMapLocation.getAddress()).append("\n"); -// SPUtils.put(mContext, "AmapAddress", aMapLocation.getAddress()); -// SPUtils.put(mContext, "longitude", aMapLocation.getLongitude()); -// SPUtils.put(mContext, "latitude", aMapLocation.getLatitude()); -// SPUtils.put(mContext, "AmapError", ""); -// } else { -// //定位失败 -// sb.append("定位失败" + "\n"); -// Log.e(TAG, "onLocationChanged: " + "定位失败"); -// SPUtils.put(mContext, "AmapError", String.valueOf(aMapLocation.getErrorInfo())); -// } -// Log.e(TAG, (String) SPUtils.get(mContext, "AmapAddress", "-")); -// Log.e(TAG, (String) SPUtils.get(mContext, "AmapError", "-")); -// Log.e(TAG, "amap: " + sb.toString()); -// } -// }); -// //设置场景模式后最好调用一次stop,再调用start以保证场景模式生效 -// locationClient.stopLocation(); -// locationClient.startLocation(); -// Log.e(TAG, "initAmap: " + "startLocation"); -// } - - } diff --git a/app/src/main/java/com/fuying/sn/network/NetInterfaceManager.java b/app/src/main/java/com/fuying/sn/network/NetInterfaceManager.java index 4d3e4c1..52948ee 100644 --- a/app/src/main/java/com/fuying/sn/network/NetInterfaceManager.java +++ b/app/src/main/java/com/fuying/sn/network/NetInterfaceManager.java @@ -1941,6 +1941,17 @@ public class NetInterfaceManager { Log.e(TAG, "updateAdminInfo: getHardware = " + hardware); Log.e(TAG, "updateAdminInfo: software = " + software); } + JsonObject nowJson = new JsonObject(); + nowJson.addProperty("address", addr); + nowJson.addProperty("machine", machine); + nowJson.addProperty("hardware", hardware); + nowJson.addProperty("software", software); + String string = GsonUtils.toJSONString(nowJson); + String oldString = mMMKV.decodeString(UrlAddress.UPDATE_SNINFO, ""); + if (oldString.equals(string)) { + Log.e(TAG, "updateAdminInfo: skip"); + return; + } getUpdateAdminSnControl().sendAdminSn( Utils.getSerial(), addr, @@ -1957,6 +1968,9 @@ public class NetInterfaceManager { @Override public void onNext(@NonNull BaseResponse baseResponse) { + if (baseResponse.code == 200) { + mMMKV.encode(UrlAddress.UPDATE_SNINFO, string); + } Log.e("updateAdminInfo", "onNext: " + baseResponse); } diff --git a/app/src/main/java/com/fuying/sn/service/StepService.java b/app/src/main/java/com/fuying/sn/service/StepService.java index 9346c46..64290b6 100644 --- a/app/src/main/java/com/fuying/sn/service/StepService.java +++ b/app/src/main/java/com/fuying/sn/service/StepService.java @@ -192,7 +192,6 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus // client.close(); // initSocketClient(); mHandler.postDelayed(heartBeatRunnable, HEART_BEAT_RATE);//开启心跳检测 - } @Override @@ -202,7 +201,6 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus // client.close(); // initSocketClient(); mHandler.postDelayed(heartBeatRunnable, HEART_BEAT_RATE);//开启心跳检测 - } }; connect(); @@ -225,7 +223,6 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus } } }.start(); - } /** @@ -279,7 +276,7 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus } // -------------------------------------websocket心跳检测------------------------------------------------ - private static final long HEART_BEAT_RATE = 30 * 1000;//每隔50秒进行一次对长连接的心跳检测 + private static final long HEART_BEAT_RATE = 60 * 1000;//每隔50秒进行一次对长连接的心跳检测 private Handler mHandler = new Handler(); private Runnable heartBeatRunnable = new Runnable() { @Override diff --git a/app/src/main/java/com/fuying/sn/service/main/MainService.java b/app/src/main/java/com/fuying/sn/service/main/MainService.java index 2a36a0c..6b99905 100644 --- a/app/src/main/java/com/fuying/sn/service/main/MainService.java +++ b/app/src/main/java/com/fuying/sn/service/main/MainService.java @@ -260,7 +260,7 @@ public class MainService extends Service implements MainSContact.MainView, Netwo @Override public void onReceiveLocation(BDLocation bdLocation) { Log.e("initConfig", "onReceiveLocation: "); - NetInterfaceManager.getInstance().updateAdminInfo(); +// NetInterfaceManager.getInstance().updateAdminInfo(); } }); } @@ -531,7 +531,7 @@ public class MainService extends Service implements MainSContact.MainView, Netwo }); mPresenter.getSnInfo(); NetInterfaceManager.getInstance().SendAppInstallInfo(); - NetInterfaceManager.getInstance().updateAdminInfo(); +// NetInterfaceManager.getInstance().updateAdminInfo(); startService(); } diff --git a/app/src/main/java/com/fuying/sn/tpush/MessageReceiver.java b/app/src/main/java/com/fuying/sn/tpush/MessageReceiver.java index a925e29..476022b 100644 --- a/app/src/main/java/com/fuying/sn/tpush/MessageReceiver.java +++ b/app/src/main/java/com/fuying/sn/tpush/MessageReceiver.java @@ -873,7 +873,7 @@ public class MessageReceiver extends XGPushBaseReceiver { } synchronized private void sendStartTime(Context context, String jsonString) { - NetInterfaceManager.getInstance().updateAdminInfo(); +// NetInterfaceManager.getInstance().updateAdminInfo(); NetInterfaceManager.getInstance().sendRunningApp(); NetInterfaceManager.getInstance().SendAppInstallInfo(); if (JGYUtils.getInstance().isScreenOn()) {