From 74c60bf2fd906d5c706c146cb38cfe4e6fe00620 Mon Sep 17 00:00:00 2001 From: lixiaopeng Date: Tue, 21 Dec 2021 17:20:48 +0800 Subject: [PATCH 1/2] merge tanlu function --- app/build.gradle | 2 +- .../mogo-core-function-main/build.gradle | 2 +- .../module/main/service/MogoMainService.java | 1 - modules/mogo-module-share/build.gradle | 12 +- .../module/share/StrategyShareProvider.kt | 46 +- .../mogo/module/share/bean/BaseRepository.kt | 8 + .../mogo/module/share/bean/BaseResponse.kt | 13 + .../mogo/module/share/bean/CityStrategy.kt | 91 ++++ .../mogo/module/share/bean/InformationBody.kt | 27 ++ .../mogo/module/share/bean/LocationInfo.kt | 56 +++ .../com/mogo/module/share/bean/Results.kt | 3 + .../module/share/bean/StrategyServiceModel.kt | 27 ++ .../mogo/module/share/bean/VoiceCmdData.kt | 1 - .../share/bean/event/GetImageSuccessEvent.kt | 26 ++ .../share/bean/event/LatLngStickyEventBus.kt | 18 + .../share/constant/StrategyShareConst.kt | 42 +- .../java/com/mogo/module/share/net/HttpApi.kt | 16 + .../com/mogo/module/share/net/HttpClient.kt | 100 +++++ .../share/service/CarCorderController.kt | 417 ++++++++++++++++++ .../share/service/CustomStatusHandler.kt | 31 ++ .../mogo/module/share/service/MainService.kt | 360 +++++++++++++++ .../share/service/MainServiceController.kt | 257 +++++++++++ .../mogo/module/share/service/UploadParams.kt | 55 +++ .../mogo/module/share/utils/AnalyticsUtil.kt | 53 +++ .../com/mogo/module/share/utils/FileUtil.kt | 143 ++++++ .../mogo/module/share/utils/LocationUtil.kt | 160 +++++++ .../com/mogo/module/share/utils/PdUtil.kt | 79 ++++ .../share/utils/SharedPreferenceUtil.kt | 50 +++ .../share/utils/StrategyPreferenceUtil.kt | 199 +++++++++ .../mogo/module/share/utils/TaskCoroutines.kt | 20 + .../roadcondition/MogoTanluApiProvider.java | 2 - .../service/CosStatusController.kt | 2 + .../roadcondition/service/MainService.kt | 2 +- settings.gradle | 2 +- 34 files changed, 2305 insertions(+), 18 deletions(-) create mode 100644 modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/BaseRepository.kt create mode 100644 modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/BaseResponse.kt create mode 100644 modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/CityStrategy.kt create mode 100644 modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/InformationBody.kt create mode 100644 modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/LocationInfo.kt create mode 100644 modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/Results.kt create mode 100644 modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/StrategyServiceModel.kt create mode 100644 modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/event/GetImageSuccessEvent.kt create mode 100644 modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/event/LatLngStickyEventBus.kt create mode 100644 modules/mogo-module-share/src/main/java/com/mogo/module/share/net/HttpApi.kt create mode 100644 modules/mogo-module-share/src/main/java/com/mogo/module/share/net/HttpClient.kt create mode 100644 modules/mogo-module-share/src/main/java/com/mogo/module/share/service/CarCorderController.kt create mode 100644 modules/mogo-module-share/src/main/java/com/mogo/module/share/service/CustomStatusHandler.kt create mode 100644 modules/mogo-module-share/src/main/java/com/mogo/module/share/service/MainService.kt create mode 100644 modules/mogo-module-share/src/main/java/com/mogo/module/share/service/MainServiceController.kt create mode 100644 modules/mogo-module-share/src/main/java/com/mogo/module/share/service/UploadParams.kt create mode 100644 modules/mogo-module-share/src/main/java/com/mogo/module/share/utils/AnalyticsUtil.kt create mode 100644 modules/mogo-module-share/src/main/java/com/mogo/module/share/utils/FileUtil.kt create mode 100644 modules/mogo-module-share/src/main/java/com/mogo/module/share/utils/LocationUtil.kt create mode 100644 modules/mogo-module-share/src/main/java/com/mogo/module/share/utils/PdUtil.kt create mode 100644 modules/mogo-module-share/src/main/java/com/mogo/module/share/utils/SharedPreferenceUtil.kt create mode 100644 modules/mogo-module-share/src/main/java/com/mogo/module/share/utils/StrategyPreferenceUtil.kt create mode 100644 modules/mogo-module-share/src/main/java/com/mogo/module/share/utils/TaskCoroutines.kt diff --git a/app/build.gradle b/app/build.gradle index be86273e76..21ca947ac5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -229,7 +229,7 @@ dependencies { implementation project(':modules:mogo-module-service') implementation project(':modules:mogo-module-v2x') implementation project(':modules:mogo-module-share') - implementation project(':modules:tanlulib') +// implementation project(':modules:tanlulib') implementation project(':modules:mogo-module-monitor') implementation project(':modules:mogo-module-extensions') implementation project(':modules:mogo-module-map') diff --git a/core/function-impl/mogo-core-function-main/build.gradle b/core/function-impl/mogo-core-function-main/build.gradle index e7c2452f2c..9ec1305037 100644 --- a/core/function-impl/mogo-core-function-main/build.gradle +++ b/core/function-impl/mogo-core-function-main/build.gradle @@ -103,7 +103,7 @@ dependencies { implementation project(':modules:mogo-module-service') implementation project(':modules:mogo-module-v2x') implementation project(':modules:mogo-module-share') - implementation project(':modules:tanlulib') +// implementation project(':modules:tanlulib') implementation project(':modules:mogo-module-monitor') implementation project(':modules:mogo-module-extensions') implementation project(':modules:mogo-module-map') diff --git a/modules/mogo-module-main/src/main/java/com/mogo/module/main/service/MogoMainService.java b/modules/mogo-module-main/src/main/java/com/mogo/module/main/service/MogoMainService.java index 56bec93b55..7ecc522cca 100644 --- a/modules/mogo-module-main/src/main/java/com/mogo/module/main/service/MogoMainService.java +++ b/modules/mogo-module-main/src/main/java/com/mogo/module/main/service/MogoMainService.java @@ -91,7 +91,6 @@ class MogoMainService extends Service implements IMogoLocationListener { private void startTanluService() { UiThreadHandler.postDelayed(() -> { - Logger.d(TAG, "startTanluService ---------- "); if (mServiceApis != null) { mServiceApis.getTanluApi().startTanluService(); } diff --git a/modules/mogo-module-share/build.gradle b/modules/mogo-module-share/build.gradle index 3eb1ba5945..519c770bcd 100644 --- a/modules/mogo-module-share/build.gradle +++ b/modules/mogo-module-share/build.gradle @@ -46,29 +46,33 @@ dependencies { implementation rootProject.ext.dependencies.androidxrecyclerview implementation rootProject.ext.dependencies.androidxccorektx implementation rootProject.ext.dependencies.androidxconstraintlayout - + implementation rootProject.ext.dependencies.okhttpinterceptor implementation rootProject.ext.dependencies.arouter kapt rootProject.ext.dependencies.aroutercompiler implementation rootProject.ext.dependencies.rxjava implementation rootProject.ext.dependencies.rxandroid implementation rootProject.ext.dependencies.mogoaicloudtanlu + implementation rootProject.ext.dependencies.analytics + implementation rootProject.ext.dependencies.eventbus + implementation rootProject.ext.dependencies.coroutinescore + implementation rootProject.ext.dependencies.coroutinesandroid + implementation rootProject.ext.dependencies.retrofit + implementation rootProject.ext.dependencies.retrofitconvertergson + implementation 'com.zhidaoauto.controller:api:1.0.8' if (Boolean.valueOf(USE_MAVEN_PACKAGE)) { implementation rootProject.ext.dependencies.mogoutils implementation rootProject.ext.dependencies.mogocommons implementation rootProject.ext.dependencies.modulecommon implementation rootProject.ext.dependencies.moduleservice - implementation rootProject.ext.dependencies.mogo_core_utils implementation rootProject.ext.dependencies.mogo_core_data - } else { implementation project(":foudations:mogo-utils") implementation project(":foudations:mogo-commons") implementation project(':modules:mogo-module-common') implementation project(':modules:mogo-module-service') - implementation project(':core:mogo-core-utils') implementation project(':core:mogo-core-data') } diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/StrategyShareProvider.kt b/modules/mogo-module-share/src/main/java/com/mogo/module/share/StrategyShareProvider.kt index e624b17f29..e26b3e6a96 100644 --- a/modules/mogo-module-share/src/main/java/com/mogo/module/share/StrategyShareProvider.kt +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/StrategyShareProvider.kt @@ -3,30 +3,38 @@ package com.mogo.module.share import android.content.Context +import android.util.ArrayMap import com.alibaba.android.arouter.facade.annotation.Route -import com.alibaba.android.arouter.facade.template.IProvider import com.alibaba.android.arouter.launcher.ARouter +import com.mogo.commons.analytics.AnalyticsUtils +import com.mogo.eagle.core.data.constants.MogoServicePaths +import com.mogo.eagle.core.network.utils.GsonUtil +import com.mogo.module.common.MogoApisHandler import com.mogo.module.share.adas.AdasFrontCarDistanceY import com.mogo.module.share.constant.ACCIDENT_STRATEGY_SHARE_PUSH_TYPE import com.mogo.module.share.constant.S_TAG +import com.mogo.module.share.service.MainService.Companion.launchService +import com.mogo.module.share.service.UploadParams import com.mogo.module.share.strategyreceiver.AccidentStrategyReceiver import com.mogo.module.share.strategyreceiver.BlockStrategy import com.mogo.service.IMogoServiceApis -import com.mogo.eagle.core.data.constants.MogoServicePaths -import com.mogo.eagle.core.network.utils.GsonUtil +import com.mogo.service.share.IMogoTanluProvider +import com.mogo.service.share.TanluUploadParams import com.mogo.utils.logger.Logger import org.json.JSONObject /** * 策略上报入口,服务端策略上报Push的接收地,接收后再调用tanlu相关接口进行视频抓取 * - * @author tongchenfei + * @author lixiaopeng */ @Route(path = MogoServicePaths.PATH_STRATEGY_SHARE) -class StrategyShareProvider : IProvider { +class StrategyShareProvider : IMogoTanluProvider { private lateinit var blockStrategy: BlockStrategy + private var mContext: Context? = null override fun init(context: Context) { + mContext = context Logger.d(S_TAG, "策略上报Provider初始化====") val apis = ARouter.getInstance().build(MogoServicePaths.PATH_SERVICE_APIS).navigation(context) as IMogoServiceApis blockStrategy = BlockStrategy(context, apis) @@ -58,5 +66,33 @@ class StrategyShareProvider : IProvider { // } } + /** + * 上传情报 + * + * @param params 情报类型 + */ + override fun uploadRoadCondition(params: TanluUploadParams?) { + if (params != null) { + Logger.d(S_TAG, "uploadRoadCondition: $params") + val properties: MutableMap = ArrayMap() + properties["type"] = params.eventType + properties["from"] = params.fromType + AnalyticsUtils.track("v2x_share_type", properties) + val location = MogoApisHandler.getInstance().apis.mapServiceApi.getSingletonLocationClient(mContext).lastKnowLocation + launchService(mContext!!, UploadParams(params.eventType, + params.fromType, params.duration, params.parentId, + params.location.lat, params.location.lon, location.address, location.bearing, location.adCode, location.cityCode)) + } else { + Logger.e(S_TAG, "params为空,无法上报情报") + } + } + + /** + * 开启探路业务服务 + */ + override fun startTanluService() { + Logger.d(S_TAG, "startTanluService") + launchService(mContext!!, null) + } } \ No newline at end of file diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/BaseRepository.kt b/modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/BaseRepository.kt new file mode 100644 index 0000000000..27fe51ae50 --- /dev/null +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/BaseRepository.kt @@ -0,0 +1,8 @@ +package com.mogo.module.share.bean + +open class BaseRepository { + + suspend fun apiCall(call: suspend () -> BaseResponse): BaseResponse { + return call.invoke() + } +} \ No newline at end of file diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/BaseResponse.kt b/modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/BaseResponse.kt new file mode 100644 index 0000000000..1cb49ca6b1 --- /dev/null +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/BaseResponse.kt @@ -0,0 +1,13 @@ +package com.mogo.module.share.bean + +import com.mogo.module.share.constant.HttpConstant + + +class BaseResponse(val code: Int, val msg: String, val result: T) { + fun isSuccess(baseUrl: String): Boolean { + return when (baseUrl) { + HttpConstant.getNetHost() -> true + else -> false + } + } +} \ No newline at end of file diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/CityStrategy.kt b/modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/CityStrategy.kt new file mode 100644 index 0000000000..983432691a --- /dev/null +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/CityStrategy.kt @@ -0,0 +1,91 @@ +package com.mogo.module.share.bean + +class CityStrategy(video: Video, pic: Pic) { + var video: Video? = video + var pic: Pic? = pic +} + +fun Video.getMaxSpeed(): Int { + return if (maxSpeed == 0) { + -1 + } else { + maxSpeed + } +} + +class Video { + var strategyId: String //策略ID + var reportType: Int //一次性、周期性 + var reportTimeInterval: Int //上传时间间隔 单位:分钟 + var infoTimeout: Int //情报失效时间 单位:分钟 + var minSpeed: Int = -1//最小速度 + var maxSpeed: Int = -1//最大速度 + var strategyType: Int //策略类型:城市、热门区域、非上报区域等 + + constructor( + strategyId: String, + reportType: Int, + reportTimeInterval: Int, + infoTimeout: Int, + minSpeed: Int, + maxSpeed: Int, + strategyType: Int + ) { + this.strategyId = strategyId + this.reportType = reportType + this.reportTimeInterval = reportTimeInterval + this.infoTimeout = infoTimeout + this.minSpeed = minSpeed + this.maxSpeed = maxSpeed + this.strategyType = strategyType + } +} + +fun Pic.getMaxSpeed(): Int { + return if (maxSpeed == 0) { + -1 + } else { + maxSpeed + } +} + + +class Pic { + var strategyId: String //策略ID + var reportType: Int //一次性、周期性 + var reportTimeInterval: Int //上传时间间隔 单位:分钟 + var infoTimeout: Int //情报失效时间 单位:分钟 + var minSpeed: Int = -1 //最小速度 + var maxSpeed: Int = -1 //最大速度 + var strategyType: Int //策略类型:城市、热门区域、非上报区域等 + + constructor( + strategyId: String, + reportType: Int, + reportTimeInterval: Int, + infoTimeout: Int, + minSpeed: Int, + maxSpeed: Int, + strategyType: Int + ) { + this.strategyId = strategyId + this.reportType = reportType + this.reportTimeInterval = reportTimeInterval + this.infoTimeout = infoTimeout + this.minSpeed = minSpeed + this.maxSpeed = maxSpeed + this.strategyType = strategyType + } +} + +class StrategyRequest { + var lon: Double + var lat: Double + var cityCode: String + + constructor(lon: Double, lat: Double, cityCode: String) { + this.lon = lon + this.lat = lat + this.cityCode = cityCode + } +} \ No newline at end of file diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/InformationBody.kt b/modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/InformationBody.kt new file mode 100644 index 0000000000..fea9941f1d --- /dev/null +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/InformationBody.kt @@ -0,0 +1,27 @@ +package com.mogo.module.share.bean + +data class InformationBody( + val data: String, + val addr: String, + val areaCode: String, + val areaName: String, + val cityCode: String, + val cityName: String, + val generateTime: Long, + val lat: Double, + val lon: Double, + val provinceName: String, + val sn: String, + val street: String, + val type: Int, + val uid: Int, + val infoType: Int, + val infoTimeout:Int, + val trafficInfoType:String, // 上报情报类型 + val isShare: Boolean, // 是否分享给附近车机 + val direction: Float, + val poiType: String, //类型分类 + val mainInfoId: Long, //事件id + val speed: Float, //车速 + val fromType: String //上报触发来源 +) \ No newline at end of file diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/LocationInfo.kt b/modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/LocationInfo.kt new file mode 100644 index 0000000000..8966c5038b --- /dev/null +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/LocationInfo.kt @@ -0,0 +1,56 @@ +package com.mogo.module.share.bean + +import com.mogo.eagle.core.data.map.MogoLatLng + +fun LocationInfo.toLatLngPoint(): com.mogo.eagle.core.data.map.MogoLatLng { + return com.mogo.eagle.core.data.map.MogoLatLng(latitude, longitude) +} + +class LocationInfo { + var provinceName: String = "" //省的名称 + var cityName: String = "" //城市的名称 + var cityCode :String = "" //城市编码 + var areaName :String = "" //区县名称 + var areaCode :String = "" //区县编码 + var street :String = "" //街道名称 + var longitude: Double = 0.0 + var latitude: Double = 0.0 + var address: String = "" + var time: Long = 0L + var direction: Float = 0.0f + constructor() + + constructor(longitude: Double, latitude: Double, address: String, time: Long) { + this.longitude = longitude + this.latitude = latitude + this.address = address + this.time = time + } + + constructor( + provinceName: String, + cityName: String, + cityCode: String, + areaName: String, + areaCode: String, + street: String, + longitude: Double, + latitude: Double, + address: String, + time: Long, + direction: Float = 0.0f + ) { + this.provinceName = provinceName + this.cityName = cityName + this.cityCode = cityCode + this.areaName = areaName + this.areaCode = areaCode + this.street = street + this.longitude = longitude + this.latitude = latitude + this.address = address + this.time = time + this.direction = direction + } + +} \ No newline at end of file diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/Results.kt b/modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/Results.kt new file mode 100644 index 0000000000..098ddadb32 --- /dev/null +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/Results.kt @@ -0,0 +1,3 @@ +package com.mogo.module.share.bean + +class Results(var cityStrategy: CityStrategy) \ No newline at end of file diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/StrategyServiceModel.kt b/modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/StrategyServiceModel.kt new file mode 100644 index 0000000000..cbace185d8 --- /dev/null +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/StrategyServiceModel.kt @@ -0,0 +1,27 @@ +package com.mogo.module.share.bean + +import com.google.gson.Gson +import com.mogo.cloud.passport.MoGoAiCloudClientConfig +import com.mogo.module.common.constants.HostConst +import com.mogo.module.share.net.HttpClient +import com.mogo.module.share.utils.LocationUtil + +class StrategyServiceModel : BaseRepository() { + + suspend fun getCityStrategy(): BaseResponse { + return apiCall { + val map = hashMapOf() + map["sn"] = MoGoAiCloudClientConfig.getInstance().getSn() + val locInfo = LocationUtil.getInstance().getLocationInfo() + map["data"] = Gson().toJson( + StrategyRequest( + locInfo.longitude, + locInfo.latitude, + locInfo.cityCode + ) + ) + HttpClient.getInstance(HostConst.GEOFENCE_HOST).getHttpApi().getCityStrategy(map) + } + } + +} \ No newline at end of file diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/VoiceCmdData.kt b/modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/VoiceCmdData.kt index 5532eb7524..33370c5357 100644 --- a/modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/VoiceCmdData.kt +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/VoiceCmdData.kt @@ -1,6 +1,5 @@ package com.mogo.module.share.bean -import com.mogo.module.share.constant.* import com.mogo.module.share.constant.ShareConstants.* diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/event/GetImageSuccessEvent.kt b/modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/event/GetImageSuccessEvent.kt new file mode 100644 index 0000000000..5bf69ce159 --- /dev/null +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/event/GetImageSuccessEvent.kt @@ -0,0 +1,26 @@ +package com.mogo.module.share.bean.event + + +/** + * @description + * + * @author lixiaopeng + * @since 2019-10-13 + */ +class GetImageSuccessEvent { + private var imageUrl: String? = null + private var type: String? = null + + constructor(imageUrl: String?, type: String?) { + this.imageUrl = imageUrl + this.type = type + } + + fun getImageUrl(): String? { + return imageUrl + } + + fun getType(): String? { + return type + } +} \ No newline at end of file diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/event/LatLngStickyEventBus.kt b/modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/event/LatLngStickyEventBus.kt new file mode 100644 index 0000000000..a087c35452 --- /dev/null +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/event/LatLngStickyEventBus.kt @@ -0,0 +1,18 @@ +package com.mogo.module.share.bean.event + +import org.greenrobot.eventbus.EventBus + +class LatLngStickyEventBus { + + companion object { + private var mEventBus = EventBus.builder() + .logNoSubscriberMessages(false) + .sendNoSubscriberEvent(false) + .build() + + fun getInstance(): EventBus { + return mEventBus + } + } + +} \ No newline at end of file diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/constant/StrategyShareConst.kt b/modules/mogo-module-share/src/main/java/com/mogo/module/share/constant/StrategyShareConst.kt index 5866b734f9..aa47aea15f 100644 --- a/modules/mogo-module-share/src/main/java/com/mogo/module/share/constant/StrategyShareConst.kt +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/constant/StrategyShareConst.kt @@ -5,4 +5,44 @@ const val S_TAG = "StrategyShare" /** * 目前两个策略上报(事故,拥堵)都是走的这个push */ -const val ACCIDENT_STRATEGY_SHARE_PUSH_TYPE = 401013 \ No newline at end of file +const val ACCIDENT_STRATEGY_SHARE_PUSH_TYPE = 401013 + +const val TANLU_ROAD_CURRENT = "10015" //实时路况 + +/** + * 默认视频抓取时长,单位是秒 + */ +const val DEFAULT_VIDEO_DURATION = 10 + +/** + * 数据策略:交通事故上报 + */ +const val UPLOAD_FROM_STRATEGY_ACCIDENT_AUTO = "5" + +/** + * 数据策略:已有事件云端校验 + */ +const val UPLOAD_FROM_STRATEGY_CLOUD_CHECK = "4" + +/** + * 数据策略:拥堵自动上报 + */ +const val UPLOAD_FROM_STRATEGY_BLOCK_AUTO = "3" + +/** + * 策略上报集合 + */ +val STRATEGY_UPLOAD_TYPE_ARRAY = arrayOf(UPLOAD_FROM_STRATEGY_BLOCK_AUTO, + UPLOAD_FROM_STRATEGY_CLOUD_CHECK, UPLOAD_FROM_STRATEGY_ACCIDENT_AUTO) + +val AlarmTypePic: Int = 1 //定时任务类型 1照片 +val AlarmTypeVideo: Int = 2 //定时任务类型 2视频 + +val alarmBroadAction: String = "com.zhidao.roadCondition.AlarmBroadCast" //定时广播 +val sendInformationAction: String = "com.zhidao.roadCondition.SendInformation" //主动上报广播 +val customResultAction: String = "com.zhidao.roadCondition.CustomResult" //主动上报结果广播 + +const val INFO_TYPE_IMG = 0 //图片 +const val INFO_TYPE_VIDEO = 1 +const val INFO_TYPE_VOICE = 2 +const val INFO_TYPE_WORD = 3 diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/net/HttpApi.kt b/modules/mogo-module-share/src/main/java/com/mogo/module/share/net/HttpApi.kt new file mode 100644 index 0000000000..bf687dbc40 --- /dev/null +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/net/HttpApi.kt @@ -0,0 +1,16 @@ +package com.mogo.module.share.net + +import com.mogo.module.share.bean.BaseResponse +import com.mogo.module.share.bean.Results +import retrofit2.http.* + +/** + * 接口声明 + */ +interface HttpApi { + //获取城市策略 + @FormUrlEncoded + @POST("yycp-geo-fence-carService/car/carStrategy/no/getCityStrategy/v1") + suspend fun getCityStrategy(@FieldMap cityStrategy: Map): BaseResponse + +} \ No newline at end of file diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/net/HttpClient.kt b/modules/mogo-module-share/src/main/java/com/mogo/module/share/net/HttpClient.kt new file mode 100644 index 0000000000..e89ea83ec9 --- /dev/null +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/net/HttpClient.kt @@ -0,0 +1,100 @@ +package com.mogo.module.share.net + +import com.mogo.commons.AbsMogoApplication +import com.mogo.eagle.core.network.NetConfig +import com.mogo.module.share.constant.HttpConstant +import okhttp3.Cache +import okhttp3.Dns +import okhttp3.OkHttpClient +import okhttp3.logging.HttpLoggingInterceptor +import retrofit2.Retrofit +import retrofit2.converter.gson.GsonConverterFactory +import java.io.File +import java.util.* +import java.util.concurrent.TimeUnit + + +class HttpClient private constructor(baseUrl: String) { + + companion object { + const val DEFAULT_CONNECT_TIME = 30L + const val DEFAULT_WRITE_TIMEOUT = 30L + const val DEFAULT_READ_TIMEOUT = 30L + + private var baseUrlClientMap = HashMap() + + fun getInstance(): HttpClient { + val baseUrl = HttpConstant.getNetHost() + var httpClient = baseUrlClientMap[baseUrl] + if (httpClient == null) { + synchronized(HttpClient::class.java) { + if (httpClient == null) { + httpClient = HttpClient(baseUrl) + baseUrlClientMap[baseUrl] = httpClient!! + } + } + } + return httpClient!! + } + + fun getInstance(baseUrl: String): HttpClient { + var httpClient = baseUrlClientMap[baseUrl] + if (httpClient == null) { + synchronized(HttpClient::class.java) { + if (httpClient == null) { + httpClient = HttpClient(baseUrl) + baseUrlClientMap[baseUrl] = httpClient!! + } + } + } + return httpClient!! + } + + } + + private var retrofit: Retrofit + private var httpApi: HttpApi + + init { + retrofit = Retrofit.Builder() + .client(getOkHttpClient()) + .addConverterFactory(GsonConverterFactory.create()) + .baseUrl(baseUrl) + .build() + httpApi = retrofit.create(HttpApi::class.java) + } + + fun getHttpApi(): HttpApi { + return httpApi + } + + private fun getOkHttpClient(): OkHttpClient { + val builder = OkHttpClient.Builder() + val httpLoggingInterceptor = HttpLoggingInterceptor() + httpLoggingInterceptor.level = HttpLoggingInterceptor.Level.BODY + val cacheFile = File(AbsMogoApplication.getApp().applicationContext.cacheDir, "cache") + val cache = Cache(cacheFile, 1024 * 1024 * 50) + + val httpDns = NetConfig.instance().httpDns + if (httpDns != null) { + builder.dns(Dns { hostname: String? -> + val addresses = httpDns.lookup(hostname) + if (addresses != null && !addresses.isEmpty()) { + return@Dns addresses + } + Dns.SYSTEM.lookup(hostname) + }) + } + + return builder + .addInterceptor(httpLoggingInterceptor) + .cache(cache) + .connectTimeout(DEFAULT_CONNECT_TIME, TimeUnit.SECONDS) + .readTimeout(DEFAULT_READ_TIMEOUT, TimeUnit.SECONDS) + .writeTimeout(DEFAULT_WRITE_TIMEOUT, TimeUnit.SECONDS) + .retryOnConnectionFailure(true) + .build() + + } + +} \ No newline at end of file diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/service/CarCorderController.kt b/modules/mogo-module-share/src/main/java/com/mogo/module/share/service/CarCorderController.kt new file mode 100644 index 0000000000..da8b681487 --- /dev/null +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/service/CarCorderController.kt @@ -0,0 +1,417 @@ +package com.mogo.module.share.service + +import android.text.TextUtils +import android.util.Log +import com.hw.videoprocessor.VideoProcessor +import com.mogo.cloud.network.BaseData +import com.mogo.cloud.passport.MoGoAiCloudClientConfig +import com.mogo.cloud.tanlu.api.ITanluUploadCallback +import com.mogo.cloud.tanlu.api.MogoUploadManager +import com.mogo.cloud.tanlu.bean.UploadInfo +import com.mogo.cloud.tanlu.bean.UploadResult +import com.mogo.commons.AbsMogoApplication +import com.mogo.commons.debug.DebugConfig +import com.mogo.module.share.bean.event.GetImageSuccessEvent +import com.mogo.module.share.bean.event.LatLngStickyEventBus +import com.mogo.module.share.constant.STRATEGY_UPLOAD_TYPE_ARRAY +import com.mogo.module.share.utils.* +import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.getStrategyMaxSpeed +import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.getStrategyMinSpeed +import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.getStrategyType +import com.mogo.utils.NetworkUtils +import com.zhidao.auto.carcorder.callback.TakePhotoCallback +import com.zhidao.auto.carcorder.callback.TakeVideoCallback +import com.zhidao.auto.carcorder.controller.ZdCarCoderController +import java.io.File +import kotlin.math.abs + +/** + * @description 记录仪相关操作 + * + * @author lixiaopeng + * @since 2019-10-30 + */ +object CarCorderController : TakePhotoCallback, TakeVideoCallback { + const val TAG: String = "CarCorderController" + private lateinit var zdCarCoderController: ZdCarCoderController + private var outputVideoPath: String = "" + private var mType: String = "" //1 上报拥堵, 2 封路和查车 + private var mainInfoId: Long = 0 + private var mFromType: String = "" + private var mLongitude: Double = 0.0 + private var mLatitude: Double = 0.0 + private var mSpeed: Float = 0f + + private var mAddress: String = "" + private var mDirection: Float = 0f + private var mAreaCode: String = "" + private var mCityCode: String = "" + + + private var getVideoFailed: (() -> Unit)? = null + + fun getVideoFailed(getVideoFailed: (() -> Unit)) { + this.getVideoFailed = getVideoFailed + } + + fun initCarCorderController() { + try { + zdCarCoderController = + ZdCarCoderController.getInstance(AbsMogoApplication.getApp().applicationContext) + zdCarCoderController.addCallback(this) + zdCarCoderController.addVideoCallback(this) + zdCarCoderController.init() + } catch (e: Exception) { + e.printStackTrace() + } + } + + + fun takePhoto( + photoType: Int, + cameraId: Int, + haveVoice: Boolean, + isCustom: Boolean = false, + type: String, + mainInfoId: Long, + fromType: String, + longitude: Double, + latitude: Double, + speed: Float, + address: String, + direction: Float, + areaCode: String, + cityCode: String + ) { + Log.d(TAG, "takePhoto ---------- type = $type --- mType = $mType ---fromType = $fromType") + this.mType = type + this.mainInfoId = mainInfoId + this.mFromType = fromType + this.mLongitude = longitude + this.mLatitude = latitude + this.mSpeed = speed + this.mAddress = address + this.mDirection = direction + this.mAreaCode = areaCode + this.mCityCode = cityCode + + CustomStatusHandler.offerPhotoStatus(isCustom) + zdCarCoderController.takePhoto(photoType, cameraId, haveVoice) + trackGetPhoto(1) + } + + /** + * @param isCustom: 是否手动上传 + * @param id: 标志是哪一个上传 + */ + fun takeVideo( + cameraId: Int, + duration: Int, + isCustom: Boolean = false, + id: Long = 0L, + type: String, + mainInfoId: Long, + fromType: String, + longitude: Double, + latitude: Double, + speed: Float, + address: String, + direction: Float, + areaCode: String, + cityCode: String + ) { + Log.d(TAG, "takeVideo -------- isCustom = $isCustom ---mFromType = $mFromType ---type = $type ---speed = $speed") + this.mType = type + this.mainInfoId = mainInfoId + this.mFromType = fromType + this.mLongitude = longitude + this.mLatitude = latitude + this.mSpeed = speed + this.mAddress = address + this.mDirection = direction + this.mAreaCode = areaCode + this.mCityCode = cityCode + + if (DebugConfig.getCarMachineType() == 0) { //自研车机 + outputVideoPath = getCompressVideoPath() + CustomStatusHandler.offerVideoStatus(TakeEntity(isCustom, id, fromType)) + zdCarCoderController.takeVideo(cameraId, duration) + trackGetVideo(1) + } else { //比亚迪 + Log.d(TAG, "takeVideo ------ isnet = " + NetworkUtils.isConnected(AbsMogoApplication.getApp().applicationContext)) + getInfo("", mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 1, mFromType, CarCorderController.mainInfoId)?.let { uploadRoadInfo(it) } + + //地图上打点 + taskAsync(3_000) { + try { +// LatLngStickyEventBus.getInstance() +// .postSticky(GetImageSuccessEvent("", mType)) + } catch (e: java.lang.Exception) { + e.printStackTrace() + } + } +// } + } + } + + fun release() { + zdCarCoderController.release() + } + + //拍照失败回调 + override fun onTakePhotoFail(photoType: Int, camera: Int) { + trackGetPhoto(3) + val isCustom = CustomStatusHandler.pollPhotoStatus() + Log.e(TAG, "onTakePhotoFail -----mType = $mType --- isCustom = $isCustom") + //获取图片失败也上报,图片不打点 + if (isCustom) { + getInfo("", mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } + + } + + } + + //拍照成功回调返回图片本地路径 + override fun onTakePhotoSuccess(photoType: Int, camera: Int, photoPath: String?) { + trackGetPhoto(2) + Log.d(TAG, "onTakePhotoSuccess -----mType = $mType --- mainInfoId = $mainInfoId") + val isCustom = CustomStatusHandler.pollPhotoStatus() + + if (!isCustom) { + trackNormalEvent(CarNet_auto_upload, null) + } + + var interceptor = false + if (interceptor) { + return + } + + val minSpeedPic = + getStrategyMinSpeed( + AbsMogoApplication.getApp().applicationContext, + "pic", + getStrategyType("pic") + ) + val maxSpeedPic = + getStrategyMaxSpeed( + AbsMogoApplication.getApp().applicationContext, + "pic", + getStrategyType("pic") + ) + val speed = LocationUtil.getInstance().getSpeed() + + if (!TextUtils.isEmpty(mType)) { + Log.d(TAG, "onTakePhotoSuccess mType != null") + if (photoPath != null) { + getInfo(photoPath, mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } + } + + } else { + Log.d(TAG, "onTakePhotoSuccess mType == null") + Log.d( + TAG, + "onTakePhotoSuccess maxSpeedPic = $maxSpeedPic ---> speed = $speed ---->minSpeedPic= $minSpeedPic" + ) + if (maxSpeedPic == -1) { + if (speed >= (abs(minSpeedPic) / 3.6f)) { + Log.d(TAG, "onTakePhotoSuccess abs =" + (abs(minSpeedPic) / 3.6f)) + if (photoPath != null) { + getInfo(photoPath, mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } + } + } + } + + if (minSpeedPic > 0 && maxSpeedPic > 0) { + Log.d(TAG, "onTakePhotoSuccess minSpeedPic > 0 -- speed = $speed") + if ((speed >= (minSpeedPic / 3.6f)) && speed <= (maxSpeedPic / 3.6f)) { + if (photoPath != null) { + getInfo(photoPath, mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } + } + } + } + } + } + + //获取视频成功 + override fun onTakeVideoSuccess(camera: Int, videoPath: String?) { + val thumbnailPath = + AbsMogoApplication.getApp().applicationContext.filesDir.parent + File.separator + "Thumbnail${System.currentTimeMillis()}.jpg" + val isSuccess = getVideoThumbnail(videoPath!!, thumbnailPath) + Log.d( + TAG, + "getVideo onTakeVideoSuccess===$videoPath -----> isSuccess= $isSuccess ----> mType = $mType --- mainInfoId = $mainInfoId" + ) + + val entity = CustomStatusHandler.pollVideoStatus() + + entity?.let { + if (!entity.isCustom) { + trackNormalEvent(CarNet_auto_upload_video, null) + } + } + + if (isSuccess) { + val minSpeedVideo = getStrategyMinSpeed( + AbsMogoApplication.getApp().applicationContext, "video", + getStrategyType("video") + ) + val maxSpeedVideo = getStrategyMaxSpeed( + AbsMogoApplication.getApp().applicationContext, "video", + getStrategyType("video") + ) + val speed = LocationUtil.getInstance().getSpeed() + + entity?.let { + if (it.isCustom) { + compressVideo(videoPath, thumbnailPath, it) + + } else if (entity.fromType in STRATEGY_UPLOAD_TYPE_ARRAY) { + // 属于策略上报 + compressVideo(videoPath, thumbnailPath, it) + + } else { + Log.d( + TAG, + "onTakeVideoSuccess maxSpeedVideo = $maxSpeedVideo --->speed= $speed + minSpeedVideo = $minSpeedVideo" + ) + if (maxSpeedVideo == -1) { + Log.d(TAG, "onTakeVideoSuccess 111 abs =" + (abs(minSpeedVideo) / 3.6f)) + if (speed >= (abs(minSpeedVideo) / 3.6f)) { + //获取视频以及缩略图成功,开始上报 + compressVideo(videoPath, thumbnailPath, it) + } + } + + if (minSpeedVideo > 0 && maxSpeedVideo > 0) { + Log.d(TAG, "onTakeVideoSuccess minSpeedVideo > 0 -- speed = $speed") + if ((speed >= (minSpeedVideo / 3.6f)) && speed <= (maxSpeedVideo / 3.6f)) { + compressVideo(videoPath, thumbnailPath, it) + } else { + } + } else { + } + } + } + trackGetVideo(2) + } + } + + private var videoAndThumbMap: MutableMap = mutableMapOf() + + //获取视频失败 + override fun onTakeVideoFail(camera: Int) { + getInfo("", mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } + + //地图上打点 + taskAsync(3_000) { + try { + LatLngStickyEventBus.getInstance().postSticky(GetImageSuccessEvent("", mType)) + } catch (e: java.lang.Exception) { + e.printStackTrace() + } + } + } + + /** + * 压缩视频并且上传 + */ + private fun compressVideo(videoPath: String, thumbnailPath: String, entity: TakeEntity) { + Log.d( + TAG, + "outputVideoPath = " + outputVideoPath + ">> videoPath=" + videoPath + " isCustom = ${entity.isCustom}" + ) + val startTime = System.currentTimeMillis() + Thread(Runnable { + try { + VideoProcessor.processor(AbsMogoApplication.getApp().applicationContext) + .input(videoPath) + .output(outputVideoPath) + .removeAudio(true) + .outWidth(1920) + .outHeight(1080) + .bitrate(2000 * 1024) + .frameRate(25) + .process() + Log.d(TAG, "compress cost time =" + (System.currentTimeMillis() - startTime)) + getInfo(outputVideoPath, mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } + //删除压缩前的视频 + deletePicFile(videoPath) + } catch (e: Exception) { + Log.e(TAG, "compressVideo e = $e") + //删除压缩前的视频 + deletePicFile(videoPath) + e.printStackTrace() + } + }).start() + } + + /** + * 上报路况的视频和图片 + */ + private fun uploadRoadInfo(info: UploadInfo) { + MogoUploadManager.getInstance(AbsMogoApplication.getApp().applicationContext).uploadInfo(info, object : ITanluUploadCallback { + override fun onSuccess(result: BaseData) { + if (result.result != null) { + Log.d(TAG, "result =" + result.result); + } + } + + override fun onFailure(code: Int) { + } + + override fun onError(e: Throwable) { + } + }) + } + + private fun getInfo(filePath: String, addr: String, lon: Double, lat: Double, poiType: String, + direction: Float, areaCode: String, cityCode: String, type: Int, fromType: String + , mainInfoId: Long): UploadInfo? { + val info = UploadInfo() + info.filePath = filePath + info.addr = addr + info.longitude = lon + info.latitude = lat + info.poiType = poiType + info.direction = direction + info.areaCode = areaCode + info.cityCode = cityCode + info.sn = MoGoAiCloudClientConfig.getInstance().getSn() + info.type = type //0为图片, 1为视频 + info.fromType = fromType + info.mainInfoId = mainInfoId + info.infoType = 1 + + return info + } + + override fun onTakePhotoCancel(photoType: Int, camera: Int) { + Log.d(TAG, "onTakePhotoCancel -----photoType = $photoType") + } + + override fun onTakeVideoCancel(camera: Int) { + Log.d(TAG, "onTakeVideoCancel -----camera = $camera") + //失败了,传空地址,发起请求 + videoAndThumbMap["video"] = "" + videoAndThumbMap["thumb"] = "" + + getInfo("", mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } + } + + //获取图片 + private fun trackGetPhoto(type: Int) { + trackNormalEvent( + CarNet_Get_Picture, mutableMapOf("type" to type), + AbsMogoApplication.getApp().applicationContext + ) + } + + //获取视频 + private fun trackGetVideo(type: Int) { + trackNormalEvent( + CarNet_Get_Video, mutableMapOf("type" to type), + AbsMogoApplication.getApp().applicationContext + ) + } + +} \ No newline at end of file diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/service/CustomStatusHandler.kt b/modules/mogo-module-share/src/main/java/com/mogo/module/share/service/CustomStatusHandler.kt new file mode 100644 index 0000000000..13393f297a --- /dev/null +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/service/CustomStatusHandler.kt @@ -0,0 +1,31 @@ +package com.mogo.module.share.service + +import java.util.* + +/** + * @author lixiaopeng + * @since 2019-11-25 + * + * 拍照、拍视频手动、被动状态队列 + */ +object CustomStatusHandler { + + private val takePhotoStatusQueue: Queue = ArrayDeque(5) + private val takeVideoStatusQueue: Queue = ArrayDeque(5) + + fun offerPhotoStatus(status: Boolean) { + takePhotoStatusQueue.offer(status) + } + + fun pollPhotoStatus() = takePhotoStatusQueue.poll() ?: false + + fun offerVideoStatus(entity: TakeEntity) { + takeVideoStatusQueue.offer(entity) + } + + fun pollVideoStatus(): TakeEntity? = takeVideoStatusQueue.poll() +} + +class TakeEntity( + var isCustom: Boolean, var id: Long, var fromType: String = "0" +) \ No newline at end of file diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/service/MainService.kt b/modules/mogo-module-share/src/main/java/com/mogo/module/share/service/MainService.kt new file mode 100644 index 0000000000..28bbb797c6 --- /dev/null +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/service/MainService.kt @@ -0,0 +1,360 @@ +package com.mogo.module.share.service + +import android.app.AlarmManager +import android.app.PendingIntent +import android.app.Service +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent +import android.content.IntentFilter +import android.os.IBinder +import android.util.Log +import com.alibaba.android.arouter.launcher.ARouter +import com.elegant.analytics.Analytics +import com.mogo.commons.AbsMogoApplication +import com.mogo.commons.debug.DebugConfig +import com.mogo.module.common.MogoApisHandler +import com.mogo.service.IMogoServiceApis +import com.mogo.eagle.core.data.constants.MogoServicePaths +import com.mogo.module.share.bean.event.GetImageSuccessEvent +import com.mogo.module.share.bean.event.LatLngStickyEventBus +import com.mogo.utils.logger.Logger +import com.mogo.utils.storage.SharedPrefsMgr +import com.zhidao.cosupload.manager.CosUploadManagerImpl +import com.mogo.module.share.BuildConfig +import com.mogo.module.share.constant.* +import com.mogo.module.share.utils.* +import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.clearStrategyType +import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.getStrategyFrequency +import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.getStrategyInterval +import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.getStrategyType +import io.reactivex.Observable +import io.reactivex.android.schedulers.AndroidSchedulers +import org.greenrobot.eventbus.Subscribe +import org.greenrobot.eventbus.ThreadMode +import java.util.concurrent.TimeUnit + + +/** + * 上报流程服务 + */ +class MainService : Service() { + + companion object { + fun launchService(context: Context, params: UploadParams?) { + val intent = Intent(context, MainService::class.java).apply { + Log.e("MainService", "launch type = $params") + putExtra("params", params) + } + context.startService(intent) + } + } + + private lateinit var mainServiceHttpModel: MainServiceController + private var mAlarmManager: AlarmManager = + AbsMogoApplication.getApp().applicationContext.getSystemService(Context.ALARM_SERVICE) as AlarmManager + + //是否已经获取过策略 + var isGetStrategies: Boolean = false + private val TAG: String = this.javaClass.simpleName + + //1是一次性,2是周期性 + private var picType: Int = 0 + private var videoType: Int = 0 + private var shareType: String = "type" + private var fromType: String = "" + private var isCustom: Boolean = false + private var speed: Float = 0f + + private var params: UploadParams? = null + private var mainInfoId: Long = 0 + private var mLongitude: Double = 0.0 + private var mLatitude: Double = 0.0 + private lateinit var serviceApis: IMogoServiceApis + private var mAddress: String = "" + private var mDirection: Float = 0f + private var mAreaCode: String = "" + private var mCityCode: String = "" + private var id: Long = System.currentTimeMillis() + + + override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { + //清理多媒体资源和sp策略数据 + clearStrategyType(this) + //初始化埋点 + Analytics.getInstance().start(this) + //参数说明:appKey: app唯一标识(比如:包名) + CosUploadManagerImpl.getInstance(AbsMogoApplication.getApp().applicationContext) + .init(BuildConfig.APPLICATION_ID, 0) + serviceApis = ARouter.getInstance().build(MogoServicePaths.PATH_SERVICE_APIS).navigation(this) as IMogoServiceApis + if (serviceApis.mapServiceApi.getSingletonLocationClient(this) != null && + serviceApis.mapServiceApi.getSingletonLocationClient(this).lastKnowLocation != null) { + speed = serviceApis.mapServiceApi.getSingletonLocationClient(this).lastKnowLocation.speed + Log.d(TAG, "onStartCommand speed = $speed") + } + + if (intent != null) { + params = intent.getParcelableExtra("params") + params?.let { + shareType = it.eventType + fromType = it.fromType + mainInfoId = it.parentId + mLongitude = it.lon + mLatitude = it.lat + mAddress = it.addr + mDirection = it.direction + mAreaCode = it.areaCode + mCityCode = it.cityCode + + Log.d(TAG, "onStartCommand shareType = $shareType --fromType = $fromType --mainInfoId = $mainInfoId -- mLongitude = $mLongitude --mLatitude = $mLatitude --it.duration = ${it.duration} ") + if (fromType == UPLOAD_FROM_STRATEGY_ACCIDENT_AUTO || fromType == UPLOAD_FROM_STRATEGY_BLOCK_AUTO) { + // 如果是策略上报,isCustom = false + takeVideo(it.duration) + } else { + takeVideo(it.duration, isCustom = true, id = id) + } + } + } else { + Log.e(TAG, "intent == null ") + } + + return super.onStartCommand(intent, flags, startId) + } + + //定时任务回调广播 + private var mAlarmBroadCast: BroadcastReceiver = object : BroadcastReceiver() { + override fun onReceive(p0: Context?, p1: Intent) { + Log.d(TAG, "receive alarm!!!!!!!!!!AlarmType===${p1.getIntExtra("AlarmType", 1)}") + if (p1.action == alarmBroadAction) { + if (p1.getIntExtra("AlarmType", 1) == AlarmTypePic) { + //拍照 + takePhoto(true) + } else { + //录像 + val duration = p1.getIntExtra("duration", 3) + takeVideo(duration, true) + } + } + } + } + + //主动上报图片情报广播 + var mCustomSendBroadCast: BroadcastReceiver = object : BroadcastReceiver() { + override fun onReceive(p0: Context?, p1: Intent) { + val id = p1.getLongExtra("id", 0L) + if (p1.action == sendInformationAction) { + takeVideo(DEFAULT_VIDEO_DURATION, isCustom = true, id = id) + } + } + } + + override fun onBind(intent: Intent?): IBinder? { + return null + } + + + override fun onCreate() { + super.onCreate() + init() + //初始化定位 + LocationUtil.getInstance().initLocation() + + initLocationListener() + LatLngStickyEventBus.getInstance().register(this) + trackNormalEvent(CarNet_MainService_Start, null) + } + + private fun init() { + //初始化拍照sdk + CarCorderController.initCarCorderController() + mainServiceHttpModel = MainServiceController() + registReceiver() +// CosCallbackMapController.init(this) + } + + /** + * 获取图片成功 + */ + @Subscribe(threadMode = ThreadMode.MAIN, sticky = true, priority = 98) + fun getImageEvent(getImageSuccessEvent: GetImageSuccessEvent) { + val info = LocationUtil.getInstance().getLocationInfo() + Log.d("MainService", "getImageEvent long = ${info.longitude} ----> lat= ${info.latitude}") + Log.d( + "MainService", + "getImageEvent url = " + getImageSuccessEvent.getImageUrl() + ">>>>type =" + getImageSuccessEvent.getType() + ) + + if (!DebugConfig.isMapBased()) { + MogoApisHandler.getInstance().apis.statusManagerApi.setUploadingStatus("CARD_TYPE_ROAD_CONDITION", false) + } + } + + + /** + * 初始化定位监听 + */ + private fun initLocationListener() { + val isOpen = SharedPrefsMgr.getInstance(AbsMogoApplication.getApp().applicationContext).getBoolean("KEY_SERVER_REPORTSTRATEGY_SWITCH", false) + Logger.d("EntrancePresenter", " initLocationListener ---- isOpen = $isOpen") + //开始开始监听速度,只要超过一次5公里每小时则即开始获取策略进行本地上报 只有release才加此判断,qa环境方便测试 + LocationUtil.getInstance().setonSpeedlistenner(object : LocationUtil.SpeedListener { + override fun onSpeedGet(speed: Float) { + if (isOpen) { + if (speed > (5 / 3.6f) && !isGetStrategies) { + mainServiceHttpModel.initStrategies { + handleReportStrategy() + } + Log.d("MainService", "initLocationListener more than 5 start upload speed = $speed") + isGetStrategies = true + } + } + } + }) + } + + /** + * 上报策略判断 + */ + private fun handleReportStrategy() { + //1是一次性,2是周期性 + picType = getStrategyFrequency( + AbsMogoApplication.getApp().applicationContext, + "pic", + getStrategyType("pic") + ) + videoType = getStrategyFrequency( + AbsMogoApplication.getApp().applicationContext, + "video", + getStrategyType("video") + ) + Log.d("MainService", "handleReportStrategy picType = $picType ---videoType = $videoType") + shareType = TANLU_ROAD_CURRENT + if (picType == 1) { + takePhoto() + } else if (picType == 2) { + postPhotoAlarmTask(true) + } + + if (videoType == 1) { + takeVideo(DEFAULT_VIDEO_DURATION) + } else if (videoType == 2) { + postVideoAlarmTask(true) + } + } + + private fun registReceiver() { + //注册定时任务回调 + val intentFilter = IntentFilter(alarmBroadAction) + intentFilter.addAction("com.zhidao.sendmessage.test") + intentFilter.addAction("com.zhidao.takevideo.test") + intentFilter.addAction("com.zhidao.takepic.test") + registerReceiver(mAlarmBroadCast, intentFilter) + } + + //获取图片 + private fun takePhoto(isInterval: Boolean = false, isCustom: Boolean = false) { + Log.d("MainService", "takePhoto -----1----->") + //判断是否授权 +// if (isAuthorization(BaseApplication.getAppContext())) { + //目前不支持连拍,只能定时2秒拍一张 第一期每次只拍一张 + Observable.intervalRange(0, 1, 0, 2_000, TimeUnit.MILLISECONDS) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe { + CarCorderController.takePhoto(1, 1, false, isCustom, TANLU_ROAD_CURRENT, mainInfoId, fromType, mLongitude, mLatitude, speed, mAddress, mDirection, mAreaCode, mCityCode) + } +// } + + postPhotoAlarmTask(isInterval) + + this@MainService.isCustom = isCustom + } + + //获取录像 + private fun takeVideo( + duration: Int, + isInterval: Boolean = false, + isCustom: Boolean = false, + id: Long = 0 + ) { + Log.d("MainService", "takeVideo --------1----> fromType = $fromType --isCustom = $isCustom") +// if (isAuthorization(BaseApplication.getAppContext())) { + CarCorderController.takeVideo(1, duration, isCustom, id, shareType, mainInfoId, fromType, mLongitude, mLatitude, speed, mAddress, mDirection, mAreaCode, mCityCode) +// } + postVideoAlarmTask(isInterval) + + this@MainService.isCustom = isCustom + } + + private fun postPhotoAlarmTask(isInterval: Boolean = false) { + if (isInterval) { + trackNormalEvent(CarNet_Create_Task, null) + val intent = Intent() + intent.action = alarmBroadAction + intent.putExtra("number", getLong(PIC_NUMBER, PIC_NUMBER_DEFAULT)) + intent.putExtra("AlarmType", AlarmTypePic) + val pendingIntent = PendingIntent.getBroadcast(this, AlarmTypePic, intent, 0) + Log.d( + "MainService", + "postPhotoAlarmTask time =" + getStrategyInterval( + AbsMogoApplication.getApp().applicationContext, + "pic", + getStrategyType("pic") + ) + ) + + mAlarmManager.setExact( + AlarmManager.RTC, System.currentTimeMillis() + + getStrategyInterval( + AbsMogoApplication.getApp().applicationContext, + "pic", + getStrategyType("pic") + ) + , pendingIntent + ) + } + } + + //开始倒计时任务 + private fun postVideoAlarmTask(isInterval: Boolean = false) { + if (isInterval) { + trackNormalEvent(CarNet_Create_Task, null) + val videoIntent = Intent() + videoIntent.action = alarmBroadAction + videoIntent.putExtra( + "duration", (VIDEO_DURATION_DEFAULT / 1000).toInt() + ) + videoIntent.putExtra("AlarmType", AlarmTypeVideo) + val videoPendingIntent = + PendingIntent.getBroadcast(this, AlarmTypeVideo, videoIntent, 0) + Log.d( + "MainService", + "postVideoAlarmTask time =" + getStrategyInterval( + AbsMogoApplication.getApp().applicationContext, + "video", + getStrategyType("video") + ) + ) + + mAlarmManager.setExact( + AlarmManager.RTC, System.currentTimeMillis() + + getStrategyInterval( + AbsMogoApplication.getApp().applicationContext, + "video", + getStrategyType("video") + ) + , videoPendingIntent + ) + } + } + + override fun onDestroy() { + super.onDestroy() + unregisterReceiver(mAlarmBroadCast) +// unregisterReceiver(mCustomSendBroadCast) + CarCorderController.release() +// CosCallbackMapController.release() + LatLngStickyEventBus.getInstance().unregister(this) + LatLngStickyEventBus.getInstance().removeAllStickyEvents() + trackNormalEvent(CarNet_MainService_Destory, null) + } +} diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/service/MainServiceController.kt b/modules/mogo-module-share/src/main/java/com/mogo/module/share/service/MainServiceController.kt new file mode 100644 index 0000000000..6fc2a6ed67 --- /dev/null +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/service/MainServiceController.kt @@ -0,0 +1,257 @@ +package com.mogo.module.share.service + +import android.util.Log +import com.mogo.commons.AbsMogoApplication +import com.mogo.eagle.core.network.request +import com.mogo.module.share.bean.* +import com.mogo.module.share.utils.CarNet_Get_Strategy +import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.setStrategyFrequency +import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.setStrategyInterval +import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.setStrategyMaxSpeed +import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.setStrategyMinSpeed +import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.setStrategyType +import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.setStrategyValidity +import com.mogo.module.share.utils.trackNormalEvent +import kotlinx.coroutines.launch +import kotlinx.coroutines.runBlocking + +class MainServiceController { + + companion object { + const val TAG = "MainServiceController" + } + + //逆地理编码是否重试 + private var geoRetry = false + private var mFromType: String = "" + private var mPoiType: String = "" + + private val strategyModel by lazy { StrategyServiceModel() } + + fun initStrategies(initFinish: (() -> Unit)? = null) { + request> { + loader { + strategyModel.getCityStrategy() + } + onSuccess { + it.result.let { strategy -> + trackNormalEvent(CarNet_Get_Strategy, null) + Log.d(TAG, "pic =" + strategy.cityStrategy.pic) + Log.d(TAG, "video =" + strategy.cityStrategy.video) + syncStrategiesData(strategy.cityStrategy) + initFinish?.invoke() + } + } + onError { + reInitStrategies() + Log.e(TAG, "initStrategies onError ${it.message}") + } + } + } + + private fun reInitStrategies() = runBlocking { + launch { + initStrategies() + } + } + + /** + * 将数据同步到sharePreference中 + */ + private fun syncStrategiesData(strategy: CityStrategy) { + if (strategy.pic != null && strategy.video!=null) { + setStrategyType(AbsMogoApplication.getApp().applicationContext, strategy.pic!!.strategyType, "pic") + setStrategyType(AbsMogoApplication.getApp().applicationContext, strategy.video!!.strategyType, "video") + setStrategyFrequency( + AbsMogoApplication.getApp().applicationContext, + strategy.pic!!.strategyType, + "pic", + strategy.pic!!.reportType + ) + setStrategyFrequency( + AbsMogoApplication.getApp().applicationContext, + strategy.video!!.strategyType, + "video", + strategy.video!!.reportType + ) + setStrategyInterval( + AbsMogoApplication.getApp().applicationContext, + strategy.pic!!.strategyType, + "pic", + strategy.pic!!.reportTimeInterval * 60 * 1000L + ) + setStrategyInterval( + AbsMogoApplication.getApp().applicationContext, + strategy.video!!.strategyType, + "video", + strategy.video!!.reportTimeInterval * 60 * 1000L + ) + setStrategyValidity( + AbsMogoApplication.getApp().applicationContext, + strategy.pic!!.strategyType, + "pic", + strategy.pic!!.infoTimeout + ) + setStrategyValidity( + AbsMogoApplication.getApp().applicationContext, + strategy.video!!.strategyType, + "video", + strategy.video!!.infoTimeout + ) + setStrategyMaxSpeed( + AbsMogoApplication.getApp().applicationContext, + strategy.pic!!.strategyType, + "pic", + strategy.pic!!.getMaxSpeed() + ) + setStrategyMaxSpeed( + AbsMogoApplication.getApp().applicationContext, + strategy.video!!.strategyType, + "video", + strategy.video!!.getMaxSpeed() + ) + setStrategyMinSpeed( + AbsMogoApplication.getApp().applicationContext, + strategy.pic!!.strategyType, + "pic", + strategy.pic!!.minSpeed + ) + setStrategyMinSpeed( + AbsMogoApplication.getApp().applicationContext, + strategy.video!!.strategyType, + "video", + strategy.video!!.minSpeed + ) + } else { + Log.d(TAG, "strategy Data is null") + } + } + + //上传情报数据 +// fun sendInformationMessage( +// fromType: String, +// type: Int, +// url: Map, +// isCustom: Boolean = false, +// trafficInfoType:String = "", +// isShare:Boolean = false, +// poiType:String, +// mainInfoId:Long, +// speed: Float, +// longitude: Double, +// latitude: Double, +// customSend: ((Boolean) -> Unit)? = null +// ) { +// Log.d(TAG, " sendInformationMessage poiType = $poiType -- fromType = $fromType") +// mFromType = fromType +// mPoiType = poiType +// +// val locationInfo = LocationUtil.getInstance().getLocationInfo() +// if (locationInfo.address.isEmpty()) { +// Log.d(TAG, " sendInformationMessage locationInfo.address = $locationInfo.address") +// trackUploadGeo(1) +// geoLocation(type, url, locationInfo, isCustom,trafficInfoType, isShare, customSend,poiType,mainInfoId,speed, longitude,latitude) +// } else { +// postInformationMessage( +// getInformationBody(type, url, locationInfo, isCustom, trafficInfoType, isShare,poiType,mainInfoId,longitude,latitude, speed, mFromType), +// customSend +// ) +// } +// } + + + //如果address为空则逆地理编码 +// private fun geoLocation( +// type: Int, +// url: Map, +// locationInfo: LocationInfo, +// isCustom: Boolean, +// trafficInfoType:String, +// isShare: Boolean, +// customSend: ((Boolean) -> Unit)? = null, +// poiType: String, +// mainInfoId: Long, +// speed: Float, +// longitude: Double, +// latitude: Double +// ) { +// Log.d(TAG, " geoLocation -- poiType = $poiType") +// LocationUtil.getInstance() +// .geoCodeLocation(locationInfo.toLatLngPoint(), { +// Log.d(TAG, "geoLocation -------start -->") +// postInformationMessage( +// getInformationBody(type, url, locationInfo, isCustom, trafficInfoType, isShare, poiType,mainInfoId,longitude,latitude, speed, mFromType), +// customSend +// ) +// }, { +// //转换失败的情况下再重试一次 +// Log.d(TAG, "geoLocation -------true-->") +// geoRetry = if (!geoRetry) { +// geoLocation(type, url, locationInfo, isCustom, trafficInfoType, isShare, customSend, poiType,mainInfoId,speed, longitude,latitude) +// true +// } else { +// //如果两次都失败,直接上报服务端 +// Log.d(TAG, "geoLocation ---- postInformationMessage ---false-->") +// postInformationMessage( +// getInformationBody(type, url, locationInfo, isCustom, trafficInfoType, isShare, poiType,mainInfoId,longitude,latitude,speed, mFromType), +// customSend +// ) +// false +// } +// }) +// } + + +// private fun postInformationMessage( +// informationBody: InformationBody, +// customSend: ((Boolean) -> Unit)? = null +// ) { +// trackUploadServer(3) +// request> { +// loader { +// strategyModel.uploadInformation(informationBody) +// } +// onSuccess { +// Log.i(TAG, "upload success id = " + it.result.id) +// if (mFromType == "6") { +// sendUgcStatusReceiver(it.result.id, mPoiType, mFromType) +// } +// trackUploadServer(1) +// customSend?.invoke(true) +// } +// onError { +// Log.i(TAG, "$it upload message ${it.message}") +// trackUploadServer(2) +// if (mFromType == "6") { +// sendUgcStatusReceiver(0, mPoiType, mFromType) +// } +// customSend?.invoke(false) +// } +// } +// } + +// private fun sendUgcStatusReceiver(id: Long, type: String?, fromType: String?) { +// Log.d(TAG, "sendUgcStatusReceiver id = $id ---type = $type --fromType = $fromType ") +// val intent = Intent() +// intent.action = "com.v2x.ugc.upload.status" +// intent.putExtra("id", id) +// intent.putExtra("type", type) +// intent.putExtra("fromType", fromType) +// AbsMogoApplication.getApp().applicationContext.sendBroadcast(intent) +// } +// +// //上传服务器 +// private fun trackUploadServer(type: Int) { +// trackNormalEvent( +// CarNet_Servers_Upload, mutableMapOf("type" to type) +// ) +// } +// +// //上传 +// private fun trackUploadGeo(type: Int) { +// trackNormalEvent( +// CarNet_Geo, mutableMapOf("type" to type) +// ) +// } + +} \ No newline at end of file diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/service/UploadParams.kt b/modules/mogo-module-share/src/main/java/com/mogo/module/share/service/UploadParams.kt new file mode 100644 index 0000000000..2aad4ab33c --- /dev/null +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/service/UploadParams.kt @@ -0,0 +1,55 @@ +package com.mogo.module.share.service + +import android.os.Parcel +import android.os.Parcelable + +/** + * 上报参数 + */ +class UploadParams(val eventType: String, val fromType: String, val duration: Int, val parentId: Long, val lat: Double, val lon: Double,val addr:String,val direction:Float,val areaCode:String,val cityCode:String) : Parcelable { + constructor(parcel: Parcel) : this( + parcel.readString()!!, + parcel.readString()!!, + parcel.readInt(), + parcel.readLong(), + parcel.readDouble(), + parcel.readDouble(), + parcel.readString()!!, + parcel.readFloat(), + parcel.readString()!!, + parcel.readString()!! + ) + + override fun writeToParcel(parcel: Parcel, flags: Int) { + parcel.writeString(eventType) + parcel.writeString(fromType) + parcel.writeInt(duration) + parcel.writeLong(parentId) + parcel.writeDouble(lat) + parcel.writeDouble(lon) + parcel.writeString(addr) + parcel.writeFloat(direction) + parcel.writeString(areaCode) + parcel.writeString(cityCode) + } + + + override fun describeContents(): Int { + return 0 + } + + override fun toString(): String { + return "UploadParams(eventType='$eventType', fromType='$fromType', duration=$duration, parentId=$parentId, lat=$lat, lon=$lon, addr='$addr', direction=$direction, areaCode='$areaCode', cityCode='$cityCode')" + } + + + companion object CREATOR : Parcelable.Creator { + override fun createFromParcel(parcel: Parcel): UploadParams { + return UploadParams(parcel) + } + + override fun newArray(size: Int): Array { + return arrayOfNulls(size) + } + } +} \ No newline at end of file diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/utils/AnalyticsUtil.kt b/modules/mogo-module-share/src/main/java/com/mogo/module/share/utils/AnalyticsUtil.kt new file mode 100644 index 0000000000..d107fbb4aa --- /dev/null +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/utils/AnalyticsUtil.kt @@ -0,0 +1,53 @@ +package com.mogo.module.share.utils + +import android.content.Context +import com.elegant.analytics.Analytics +import com.mogo.cloud.passport.MoGoAiCloudClientConfig +import com.mogo.commons.AbsMogoApplication +import com.mogo.commons.network.Utils.getFotaVersion +import java.util.HashMap + +const val CarNet_Alive:String = "CarNet_Alive"//探路日活DAU埋点 +const val CarNet_Scheme_Channel:String = "CarNet_Scheme_Channel"//探路Scheme渠道区分 +const val APPENTER_FRONT:String = "appenterfront"//探路Scheme渠道区分 + +const val CarNet_auto_upload:String = "CarNet_auto_upload"//情报自动上传时间(自动上报图片) +const val CarNet_click:String ="CarNet_click"//用户点击查看大图 +const val CarNet_right_handle:String ="CarNet_right_handle"//用户切换情报-地图切换 +const val CarNet_event_number:String ="CarNet_event_number" //用户获取的信息数量 +const val CarNet_user_upload:String ="CarNet_user_upload" //用户主动上报视频type=1 手动点击 type=2 语音 +const val CarNet_auto_upload_video:String ="CarNet_auto_upload_video"//自动上报视频 +const val CarNet_click_search:String = "CarNet_click_search" //点击地图搜索 +const val CarNet_user_get:String = "CarNet_user_get"//用户查看情报(首页视频/图片,开始播放即算做用户查看)type=1 视频 type=2 图片 +const val CarNet_road_search:String = "CarNet_road_search"//有导航路线时的沿途查询 + +const val CarNet_MainService:String = "CarNet_MainService" //开机 +const val CarNet_MainService_Start:String ="CarNet_MainService_Start" //服务开启 +const val CarNet_MainService_Destory:String ="CarNet_MainService_Destory" //服务销毁 +const val CarNet_Get_Strategy:String = "CarNet_Get_Strategy" //策略拉取成功 +const val CarNet_Create_Task:String = "CarNet_Create_Task" //创建定时任务 +const val CarNet_Get_Picture:String = "CarNet_Get_Picture" //获取图片,type=1 调用, type=2 成功, type=3 失败 +const val CarNet_Get_Video:String = "CarNet_Get_Video" //获取视频,type=1 调用,type=2 成功,type=3 失败 +const val CarNet_Cos_Upload:String = "CarNet_Cos_Upload" //上传COS, type=1 成功, type=2 失败, type=3 开始, type=4 成功返回视频和缩略图,type=5 成功但没有返回全视频和缩略图 +const val CarNet_Servers_Upload:String = "CarNet_Servers_Upload" //上传服务端, type=1 成功,type=2 失败, type=3 开始 +const val CarNet_Voice_Search:String = "CarNet_Voice_Search" //语音搜索路况,type=1 成功,type=2 失败 +const val CarNet_USER_SHOW:String = "CarNet_user_show" //情报展示时长,showtime 加载列表时长 +const val CarNet_USER_LOAD:String = "CarNet_user_load" //情报加载时长,type=1 视频,2图片 +const val CarNet_Geo:String = "CarNet_Geo_Location" //上传服务端, type=1开始 ,type=2 成功, type=3 失败 + + +const val CarNet_live_broadcast = "CarNet_live_broadcast" // 地图页面点击直播(在线可直播车机) +//自定义埋点 +fun trackNormalEvent(event: String, _data: MutableMap?, context: Context = AbsMogoApplication.getApp().applicationContext) { + var data = _data + if (data == null) { + data = HashMap() + } + val localParams = HashMap() + //公共参数 time sn + localParams["time"] = System.currentTimeMillis() + localParams["systemversion"] = getFotaVersion() + localParams["sn"] = MoGoAiCloudClientConfig.getInstance().getSn() + + Analytics.getInstance().track(event, data) +} \ No newline at end of file diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/utils/FileUtil.kt b/modules/mogo-module-share/src/main/java/com/mogo/module/share/utils/FileUtil.kt new file mode 100644 index 0000000000..45bc568d9d --- /dev/null +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/utils/FileUtil.kt @@ -0,0 +1,143 @@ +package com.mogo.module.share.utils + +import android.graphics.Bitmap +import android.media.MediaMetadataRetriever +import android.os.Environment +import okhttp3.MediaType +import okhttp3.MultipartBody +import okhttp3.RequestBody +import java.io.* +import java.text.SimpleDateFormat +import java.util.* + + +//创建文件上传请求体 +fun fileToMultiPart(fileUrl: String): MultipartBody.Part? { + val file = File(fileUrl) + if (file.exists()) { + val requestBody = RequestBody.create(MediaType.parse("image/jpg"), file) + return MultipartBody.Part.createFormData("file", file.name, requestBody) + } + return null +} + +fun deletePicFile(filePath: String?): Boolean { + val file = File(filePath) + if (file.exists()) { + //如果图片地址包含此路径则是C上面的拍照,需要再删除后摄图片 + if (filePath!!.contains("usbotg-1-1.1")) { + //将地址替换成后摄图片地址 + val backFile = + File(filePath.replace("frontPic", "backPic").replace("PhotoFront", "PhotoBack")) + if (backFile.exists()) { + return backFile.delete() + } + return file.delete() + } else + return file.delete() + } + return false +} + +//删除某个目录下所有文件 +fun deleteAllFile(file: File?) { //判断文件不为null或文件目录存在 + if (file == null || !file.exists()) { + return + } + //取得这个目录下的所有子文件对象 + val files: Array = file.listFiles() + //遍历该目录下的文件对象 + for (f in files) { + //判断子目录是否存在子目录,如果是文件则删除 + if (f.isDirectory) { + deleteAllFile(f) + } else { + f.delete() + } + } + //删除空文件夹 for循环已经把上一层节点的目录清空。 +// file.delete() +} + + +//根据本地视频文件生成缩略图文件 +fun getVideoThumbnail(filePath: String, picPath: String): Boolean { + var b: Bitmap? = null + val retriever = MediaMetadataRetriever() + try { + retriever.setDataSource(filePath) + b = retriever.getFrameAtTime(0) + } catch (e: IllegalArgumentException) { + e.printStackTrace() + } catch (e: RuntimeException) { + e.printStackTrace() + } finally { + try { + retriever.release() + } catch (e: RuntimeException) { + e.printStackTrace() + } + } + return bitmapToFile(b, picPath) +} + +//bitmap转为file +fun bitmapToFile(bitmap: Bitmap?, filePath: String): Boolean { + val baos = ByteArrayOutputStream() + bitmap?.compress(Bitmap.CompressFormat.JPEG, 50, baos) + val file = File(filePath) + try { + if (file.exists()) + file.delete() + file.createNewFile() + val fos = FileOutputStream(file) + val ins = ByteArrayInputStream(baos.toByteArray()) + var x = 0 + val b = ByteArray(1024 * 100) + while ({ x = ins.read(b);x }() != -1) { + fos.write(b, 0, x) + } + fos.close() + bitmap?.recycle() + } catch (e: Exception) { + e.printStackTrace() + return false + } + + return true +} + +fun deleteCompressVideoFile(path: String?) { + val file = File(path) + val files = file.listFiles() + for (f in files) { + // /storage/emulated/0/Movies/compress_video_20210202121826.mp4 + if (f.toString().contains("compress_video")) { + f.delete() + } + } +} + + +//获取压缩后的视频路径 +fun getCompressVideoPath(): String { + val moviesDir = Environment.getExternalStoragePublicDirectory( + Environment.DIRECTORY_MOVIES + ) + moviesDir.mkdirs() + + val builder = StringBuilder() + builder.append("compress_video_") + .append(SimpleDateFormat("yyyyMMddHHmmss").format(Date())) + val filePrefix = builder.toString() + val fileExtn = ".mp4" + var destPath = File(moviesDir, filePrefix + fileExtn) + + var fileNo = 0 + while (destPath.exists()) { + fileNo++ + destPath = File(moviesDir, filePrefix + fileNo + fileExtn) + } + + return destPath.absolutePath +} \ No newline at end of file diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/utils/LocationUtil.kt b/modules/mogo-module-share/src/main/java/com/mogo/module/share/utils/LocationUtil.kt new file mode 100644 index 0000000000..1fbbeb8f24 --- /dev/null +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/utils/LocationUtil.kt @@ -0,0 +1,160 @@ +package com.mogo.module.share.utils + +import android.util.Log +import com.mogo.commons.AbsMogoApplication +import com.mogo.eagle.core.data.map.MogoLocation +import com.mogo.map.search.geo.IMogoGeoSearchListener +import com.mogo.map.search.geo.MogoRegeocodeAddress +import com.mogo.map.search.geo.MogoRegeocodeResult +import com.mogo.map.search.geo.query.MogoRegeocodeQuery +import com.mogo.module.common.MogoApisHandler +import com.mogo.module.share.bean.LocationInfo + + +private fun toLocInfo( + address: MogoRegeocodeAddress, + latlngPoint: com.mogo.eagle.core.data.map.MogoLatLng +): LocationInfo { + return LocationInfo( + address.province, + address.city, + address.cityCode, + address.district, + address.adCode, + address.roads[0].name, + latlngPoint.lon, + latlngPoint.lat, + address.formatAddress, + System.currentTimeMillis() + ) +} + +private fun toLocInfo(location: MogoLocation): LocationInfo { + return LocationInfo( + location.province, + location.cityName, + location.cityCode, + location.district, + location.adCode, + location.street, + location.longitude, + location.latitude, + location.address, + location.time, + location.bearing + ) +} + +class LocationUtil private constructor() { + + companion object { + + private const val TAG = "LocationUtil" + private var instance: LocationUtil? = null + + @Synchronized + fun getInstance(): LocationUtil { + if (instance == null) { + instance = LocationUtil() + } + return instance!! + } + } + + interface OnMapLocationChangedListener { + fun onChanged(locationInfo: LocationInfo) + } + + private var listener: OnMapLocationChangedListener? = null + + private var init: Boolean = false + private var mContext = AbsMogoApplication.getApp().applicationContext + private var speedListener: SpeedListener? = null + private var locationInfo: LocationInfo? = null + private var speed: Float = 0.0f + + fun initLocation() { + //初始化client + init = true + MogoApisHandler.getInstance().apis.mapServiceApi.getSingletonLocationClient(mContext).addLocationListener {location-> + if (null != location) { + locationInfo = LocationInfo() + locationInfo!!.longitude = location.longitude + locationInfo!!.latitude = location.latitude + locationInfo!!.address = location.address + locationInfo!!.time = location.time + locationInfo!!.provinceName = location.province + locationInfo!!.cityName = location.cityName + locationInfo!!.cityCode = location.cityCode + locationInfo!!.areaName = location.district + locationInfo!!.areaCode = location.adCode + locationInfo!!.street = location.street + locationInfo!!.direction = location.bearing + listener?.onChanged(locationInfo!!) + speed = location.speed + speedListener?.onSpeedGet(location.speed) + } else { + Log.d(TAG, "定位失败 -> location is null") + } + } + } + + fun getLocationInfo(): LocationInfo { + return if (null != locationInfo) { + locationInfo!! + } else { + val location = MogoApisHandler.getInstance().apis.mapServiceApi.getSingletonLocationClient(mContext).lastKnowLocation + toLocInfo(location) + } + } + + //如果获取到的location address为空可以通过高德逆地理编码获得 + fun geoCodeLocation( + latlngPoint: com.mogo.eagle.core.data.map.MogoLatLng, + locGeoCode: (((locInfo: LocationInfo) -> Unit)), + onError: ((msg: String) -> Unit) + ) { + val geocoderSearch = MogoApisHandler.getInstance().apis.mapServiceApi.getGeoSearch(AbsMogoApplication.getApp().applicationContext) + val regeocodeQuery = MogoRegeocodeQuery() + regeocodeQuery.latlngType = "" + regeocodeQuery.point = latlngPoint + regeocodeQuery.radius = 200 + geocoderSearch.getFromLocationAsyn(regeocodeQuery) + geocoderSearch.setGeoSearchListener(object : IMogoGeoSearchListener { + override fun onRegeocodeSearched(regeocodeResult: MogoRegeocodeResult?) { +// super.onRegeocodeSearched(regeocodeResult) + if( regeocodeResult == null ){ + trackUploadGeo(3) + onError.invoke("geoCode") + } else { + trackUploadGeo(2) + val regeocodeAddress = regeocodeResult.regeocodeAddress + regeocodeAddress?.let { + val locInfo = toLocInfo(regeocodeAddress, latlngPoint) + locGeoCode.invoke(locInfo) + } + } + } + }) + } + + //上传 + private fun trackUploadGeo(type: Int) { + trackNormalEvent( + CarNet_Geo, mutableMapOf("type" to type) + ) + } + + fun getSpeed():Float{ + return speed + } + + fun setonSpeedlistenner(speedListener: SpeedListener) { + this.speedListener = speedListener + } + + interface SpeedListener { + fun onSpeedGet(speed: Float) + } + +} \ No newline at end of file diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/utils/PdUtil.kt b/modules/mogo-module-share/src/main/java/com/mogo/module/share/utils/PdUtil.kt new file mode 100644 index 0000000000..351b509866 --- /dev/null +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/utils/PdUtil.kt @@ -0,0 +1,79 @@ +package com.mogo.module.share.utils + +import android.util.Log +import com.google.gson.JsonArray +import com.google.gson.JsonObject +import com.mogo.cloud.passport.MoGoAiCloudClientConfig +import com.mogo.commons.AbsMogoApplication +import com.mogo.module.share.bean.InformationBody +import com.mogo.module.share.bean.LocationInfo +import com.mogo.module.share.constant.INFO_TYPE_IMG +import com.mogo.module.share.constant.INFO_TYPE_VIDEO +import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.getStrategyType +import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.getStrategyValidity + + +fun getInformationBody( + types: Int, + urls: Map, + locationInfo: LocationInfo, + isCustom: Boolean, + trafficInfoType:String = "", + isShare:Boolean, + poiType: String, + mainInfoId: Long, + longitude: Double, + latitude: Double, + speed: Float, + fromType: String +): InformationBody { + val jsonArray = JsonArray() + val type: Int + type = if (types == INFO_TYPE_VIDEO) { + val videoObject = JsonObject() + videoObject.addProperty("thumbnail", urls["thumb"]) + videoObject.addProperty("url", urls["video"]) + jsonArray.add(videoObject) + INFO_TYPE_VIDEO + } else { + val urlObject = JsonObject() + urlObject.addProperty("url", urls["pic"]) + jsonArray.add(urlObject) + INFO_TYPE_IMG + } + val infoType = if (isCustom) 1 else 0 + Log.d("MainServiceController", "isCustom = $isCustom ---- infoType = $infoType") + return InformationBody( + jsonArray.toString(), + locationInfo.address, + locationInfo.areaCode, + locationInfo.areaName, + locationInfo.cityCode, + locationInfo.cityName, + System.currentTimeMillis(), + if (latitude == 0.0) locationInfo.latitude else latitude, + if (longitude == 0.0) locationInfo.longitude else longitude, + locationInfo.provinceName, + MoGoAiCloudClientConfig.getInstance().getSn(), + locationInfo.street, + type, + 0, + infoType, + getStrategyValidity(AbsMogoApplication.getApp().applicationContext, convertUploadTypeOfSP(type), getStrategyType(convertUploadTypeOfSP(type))), + trafficInfoType, + isShare, + locationInfo.direction, + poiType, + mainInfoId, + speed, + fromType + ) +} + +private fun convertUploadTypeOfSP(type: Int): String { + return when (type) { + INFO_TYPE_IMG -> "pic" + INFO_TYPE_VIDEO -> "video" + else -> "pic" + } +} \ No newline at end of file diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/utils/SharedPreferenceUtil.kt b/modules/mogo-module-share/src/main/java/com/mogo/module/share/utils/SharedPreferenceUtil.kt new file mode 100644 index 0000000000..dd555263d8 --- /dev/null +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/utils/SharedPreferenceUtil.kt @@ -0,0 +1,50 @@ +package com.mogo.module.share.utils + +import android.content.Context +import androidx.core.content.edit +import com.mogo.commons.AbsMogoApplication + +const val FILE_NAME = "settings_data" + +const val PIC_NUMBER = "PIC_NUMBER" //图片拍摄张数 +const val VIDEO_DURATION_DEFAULT = 10_000L //视频拍摄时长 +const val PIC_NUMBER_DEFAULT = 1L //图片拍摄张数 + +fun putLong(key: String, value: Long) { + val sharedPreferences = + AbsMogoApplication.getApp().applicationContext.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE) + sharedPreferences.edit { + putLong(key, value).apply() + } +} + +fun getLong(key: String, defaultValue: Long): Long { + return AbsMogoApplication.getApp().applicationContext.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE) + .getLong(key, defaultValue) +} + +fun putInt(key: String, value: Int) { + val sharedPreferences = + AbsMogoApplication.getApp().applicationContext.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE) + sharedPreferences.edit { + putInt(key, value).apply() + } +} + +fun getInt(key: String, defaultValue: Int): Int { + return AbsMogoApplication.getApp().applicationContext.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE) + .getInt(key, defaultValue) +} + +fun putCommonString(key: String, value: String) { + val sharedPreferences = + AbsMogoApplication.getApp().applicationContext.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE) + sharedPreferences.edit { + putString(key, value).apply() + } +} + +fun getCommonBoolean(key: String, defaultValue: Boolean): Boolean { + return AbsMogoApplication.getApp().applicationContext.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE) + .getBoolean(key, defaultValue) +} \ No newline at end of file diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/utils/StrategyPreferenceUtil.kt b/modules/mogo-module-share/src/main/java/com/mogo/module/share/utils/StrategyPreferenceUtil.kt new file mode 100644 index 0000000000..2ee683b24e --- /dev/null +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/utils/StrategyPreferenceUtil.kt @@ -0,0 +1,199 @@ +package com.mogo.module.share.utils + +import android.content.Context +import android.util.Log +import androidx.core.content.edit +import com.mogo.commons.AbsMogoApplication + +const val STRATEGY_FILE_NAME = "strategy_data" + +const val STRATEGY_TYPE_COPY = "strategy_data_copy" + +/** + * 策略SP存储模式:STRATEGY_TYPE + 策略类型 + 情报类型 + 对应项 + */ +const val STRATEGY_TYPE = "STRATEGY_" + +const val FREQUENCY = "FREQUENCY" +const val DEFAULT_FREQUENCY_PIC = 2 //默认上报类型:周期性上报 +const val DEFAULT_FREQUENCY_VIDEO = 1 //默认上报类型:单次上报 + +const val INTERVAL = "INTERVAL" +const val DEFAULT_INTERVAL_PIC = 600_000L //默认图片定时任务默认间隔 +const val DEFAULT_INTERVAL_VIDEO = 900_000L //默认视频定时任务默认间隔 + +const val VALIDITY = "VALIDITY" +const val DEFAULT_VALIDITY = 4 * 60 //默认情报有效期:4小时 + +const val MAX_SPEED = "MAX_SPEED" +const val MIN_SPEED = "MIN_SPEED" +const val DEFAULT_MAX_SPEED = -1 +const val DEFAULT_MIN_SPEED = -1 + + +class StrategyPreferenceUtil { + companion object { + //保存策略类型,在AccOff的时候清除数据,更新时需要在没有情报上传时操作 + fun setStrategyType(context: Context, strategyType: Int, type: String) { + val sharedPreferences = + context.getSharedPreferences(STRATEGY_TYPE_COPY, Context.MODE_PRIVATE) + sharedPreferences.edit { + putInt(STRATEGY_TYPE + type, strategyType).commit() + } + } + + fun getStrategyType( + type: String, + context: Context = AbsMogoApplication.getApp().applicationContext + ): Int { + return context.getSharedPreferences(STRATEGY_TYPE_COPY, Context.MODE_PRIVATE) + .getInt(STRATEGY_TYPE + type, 1) + } + + fun clearStrategyType(context: Context) { + val sharedPreferences = + context.getSharedPreferences(STRATEGY_TYPE_COPY, Context.MODE_PRIVATE) + sharedPreferences.edit { + clear() + val clearStrategyType = commit() + Log.d(STRATEGY_TYPE_COPY, "clearStrategyType = $clearStrategyType") + } + } + + fun setStrategyFrequency( + context: Context, + strategyType: Int, + infoType: String, + frequency: Int + ) { + val sharedPreferences = + context.getSharedPreferences(STRATEGY_FILE_NAME, Context.MODE_PRIVATE) + sharedPreferences.edit { + putInt( + STRATEGY_TYPE + strategyType + "_" + infoType + FREQUENCY, + frequency + ).commit() + } + } + + fun getStrategyFrequency(context: Context, infoType: String, strategyType: Int = 1): Int { + return context.getSharedPreferences(STRATEGY_FILE_NAME, Context.MODE_PRIVATE) + .getInt( + STRATEGY_TYPE + strategyType + "_" + infoType + FREQUENCY, + convertFrequencyOfInfoType(infoType) + ) + } + + private fun convertFrequencyOfInfoType(infoType: String): Int { + return when (infoType) { + "pic" -> DEFAULT_FREQUENCY_PIC + "video" -> DEFAULT_FREQUENCY_VIDEO + else -> DEFAULT_FREQUENCY_PIC + } + } + + fun setStrategyInterval( + context: Context, + strategyType: Int, + infoType: String, + interval: Long + ) { + val sharedPreferences = + context.getSharedPreferences(STRATEGY_FILE_NAME, Context.MODE_PRIVATE) + sharedPreferences.edit { + putLong( + STRATEGY_TYPE + strategyType + "_" + infoType + INTERVAL, + interval + ).commit() + } + } + + fun getStrategyInterval(context: Context, infoType: String, strategyType: Int = 1): Long { + return context.getSharedPreferences(STRATEGY_FILE_NAME, Context.MODE_PRIVATE) + .getLong( + STRATEGY_TYPE + strategyType + "_" + infoType + INTERVAL, + convertIntervalOfInfoType(infoType) + ) + } + + private fun convertIntervalOfInfoType(infoType: String): Long { + return when (infoType) { + "pic" -> DEFAULT_INTERVAL_PIC + "video" -> DEFAULT_INTERVAL_VIDEO + else -> DEFAULT_INTERVAL_PIC + } + } + + fun setStrategyValidity( + context: Context, + strategyType: Int, + infoType: String, + validity: Int + ) { + val sharedPreferences = + context.getSharedPreferences(STRATEGY_FILE_NAME, Context.MODE_PRIVATE) + sharedPreferences.edit { + putInt( + STRATEGY_TYPE + strategyType + "_" + infoType + VALIDITY, + validity + ).commit() + } + } + + fun getStrategyValidity(context: Context, infoType: String, strategyType: Int = 1): Int { + return context.getSharedPreferences(STRATEGY_FILE_NAME, Context.MODE_PRIVATE) + .getInt( + STRATEGY_TYPE + strategyType + "_" + infoType + VALIDITY, + DEFAULT_VALIDITY + ) + } + + fun setStrategyMaxSpeed( + context: Context, + strategyType: Int, + infoType: String, + maxSpeed: Int + ) { + val sharedPreferences = + context.getSharedPreferences(STRATEGY_FILE_NAME, Context.MODE_PRIVATE) + sharedPreferences.edit { + putInt( + STRATEGY_TYPE + strategyType + "_" + infoType + MAX_SPEED, + maxSpeed + ).commit() + } + } + + fun getStrategyMaxSpeed(context: Context, infoType: String, strategyType: Int = 1): Int { + return context.getSharedPreferences(STRATEGY_FILE_NAME, Context.MODE_PRIVATE) + .getInt( + STRATEGY_TYPE + strategyType + "_" + infoType + MAX_SPEED, + DEFAULT_MAX_SPEED + ) + } + + fun setStrategyMinSpeed( + context: Context, + strategyType: Int, + infoType: String, + minSpeed: Int + ) { + val sharedPreferences = + context.getSharedPreferences(STRATEGY_FILE_NAME, Context.MODE_PRIVATE) + sharedPreferences.edit { + putInt( + STRATEGY_TYPE + strategyType + "_" + infoType + MIN_SPEED, + minSpeed + ).commit() + } + } + + fun getStrategyMinSpeed(context: Context, infoType: String, strategyType: Int = 1): Int { + return context.getSharedPreferences(STRATEGY_FILE_NAME, Context.MODE_PRIVATE) + .getInt( + STRATEGY_TYPE + strategyType + "_" + infoType + MIN_SPEED, + DEFAULT_MIN_SPEED + ) + } + } + } diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/utils/TaskCoroutines.kt b/modules/mogo-module-share/src/main/java/com/mogo/module/share/utils/TaskCoroutines.kt new file mode 100644 index 0000000000..91e42934c3 --- /dev/null +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/utils/TaskCoroutines.kt @@ -0,0 +1,20 @@ +package com.mogo.module.share.utils + +import bolts.Task.delay +import kotlinx.coroutines.* + +@ObsoleteCoroutinesApi +@PublishedApi +internal var ThreadPool = + newFixedThreadPoolContext(Runtime.getRuntime().availableProcessors() * 2, "ThreadPool") + + +/** + * 并发执行,常用于最外层 + * 特点带返回值 + */ +@ObsoleteCoroutinesApi +fun taskAsync(delayTime: Long = 0, job: suspend () -> T) = GlobalScope.async(ThreadPool) { + delay(delayTime) + job() +} \ No newline at end of file diff --git a/modules/tanlulib/src/main/java/com/zhidao/roadcondition/MogoTanluApiProvider.java b/modules/tanlulib/src/main/java/com/zhidao/roadcondition/MogoTanluApiProvider.java index 9212b2821c..4571be473a 100644 --- a/modules/tanlulib/src/main/java/com/zhidao/roadcondition/MogoTanluApiProvider.java +++ b/modules/tanlulib/src/main/java/com/zhidao/roadcondition/MogoTanluApiProvider.java @@ -10,8 +10,6 @@ import com.mogo.module.common.MogoApisHandler; import com.mogo.service.share.IMogoTanluProvider; import com.mogo.service.share.TanluUploadParams; import com.mogo.utils.logger.Logger; -import com.zhidao.roadcondition.service.MainService; -import com.zhidao.roadcondition.service.UploadParams; import java.util.Map; diff --git a/modules/tanlulib/src/main/java/com/zhidao/roadcondition/service/CosStatusController.kt b/modules/tanlulib/src/main/java/com/zhidao/roadcondition/service/CosStatusController.kt index 1f45c255f7..77dd0bc904 100644 --- a/modules/tanlulib/src/main/java/com/zhidao/roadcondition/service/CosStatusController.kt +++ b/modules/tanlulib/src/main/java/com/zhidao/roadcondition/service/CosStatusController.kt @@ -20,6 +20,8 @@ import java.io.File * * @author lixiaopeng * @since 2019-10-30 + * + * */ class CosStatusController : CosStatusCallback { diff --git a/modules/tanlulib/src/main/java/com/zhidao/roadcondition/service/MainService.kt b/modules/tanlulib/src/main/java/com/zhidao/roadcondition/service/MainService.kt index 29b6cb025a..b88439bc3d 100644 --- a/modules/tanlulib/src/main/java/com/zhidao/roadcondition/service/MainService.kt +++ b/modules/tanlulib/src/main/java/com/zhidao/roadcondition/service/MainService.kt @@ -47,7 +47,7 @@ class MainService : Service() { fun launchService(context: Context, params: UploadParams?) { val intent = Intent(context, MainService::class.java).apply { - Log.e("MainService", "launchService type = $params") + Log.e("MainService", "launch type = $params") putExtra("params", params) } context.startService(intent) diff --git a/settings.gradle b/settings.gradle index 3d0e63f5b8..47fd724c0d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -54,7 +54,7 @@ include ':libraries:map-autonavi' include ':libraries:mogo-map' // OLD业务模块 -include ':modules:tanlulib' +//include ':modules:tanlulib' include ':modules:mogo-module-monitor' include ':modules:mogo-module-adas' include ':modules:mogo-module-map' From 63b2631da78b17f639b9a1a302dd884f9aa10109 Mon Sep 17 00:00:00 2001 From: lixiaopeng Date: Wed, 22 Dec 2021 19:02:51 +0800 Subject: [PATCH 2/2] opt tanlu --- app/build.gradle | 1 - app/functions/och.gradle | 40 +++++++++-- .../mogo-core-function-main/build.gradle | 1 - modules.txt | 1 - modules/mogo-module-share/build.gradle | 9 ++- .../src/main/AndroidManifest.xml | 5 ++ .../module/share/MogoTanluApiProvider.java | 66 +++++++++++++++++++ .../module/share/StrategyShareProvider.kt | 33 +--------- .../{BaseDataComapt.kt => BaseDataCompat.kt} | 1 + .../module/share/constant/ShareConstants.java | 1 + .../module/share/net/ShareLsApiService.java | 25 ------- .../share/service/CarCorderController.kt | 54 +++++++-------- .../mogo/module/share/service/MainService.kt | 35 +++++----- .../share/service/MainServiceController.kt | 14 ++-- settings.gradle | 1 - 15 files changed, 167 insertions(+), 120 deletions(-) create mode 100644 modules/mogo-module-share/src/main/java/com/mogo/module/share/MogoTanluApiProvider.java rename modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/{BaseDataComapt.kt => BaseDataCompat.kt} (99%) delete mode 100644 modules/mogo-module-share/src/main/java/com/mogo/module/share/net/ShareLsApiService.java diff --git a/app/build.gradle b/app/build.gradle index 21ca947ac5..40ef85275b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -229,7 +229,6 @@ dependencies { implementation project(':modules:mogo-module-service') implementation project(':modules:mogo-module-v2x') implementation project(':modules:mogo-module-share') -// implementation project(':modules:tanlulib') implementation project(':modules:mogo-module-monitor') implementation project(':modules:mogo-module-extensions') implementation project(':modules:mogo-module-map') diff --git a/app/functions/och.gradle b/app/functions/och.gradle index d1e7d70339..ad51544f40 100644 --- a/app/functions/och.gradle +++ b/app/functions/och.gradle @@ -1,11 +1,39 @@ // 网约车服务:仅小巴车、出租车渠道用 project.dependencies { - f8xxImplementation rootProject.ext.dependencies.mogoochnoop - f80xImplementation rootProject.ext.dependencies.mogoochnoop - f8AmapImplementation rootProject.ext.dependencies.mogoochnoop - - fochtaxiImplementation rootProject.ext.dependencies.mogoochtaxi - fochbusImplementation rootProject.ext.dependencies.mogoochbus + f8xxImplementation (rootProject.ext.dependencies.mogoochnoop){ + exclude group: 'com.mogo.commons' //by group + exclude group: 'com.mogo.map' //by group + exclude group: 'com.mogo.eagle.core' //by group + exclude group: 'com.mogo.eagle.core.function' //by group + } + f80xImplementation (rootProject.ext.dependencies.mogoochnoop){ + exclude group: 'com.mogo.commons' //by group + exclude group: 'com.mogo.module' //by group + exclude group: 'com.mogo.map' //by group + exclude group: 'com.mogo.eagle.core' //by group + exclude group: 'com.mogo.eagle.core.function' //by group + } + f8AmapImplementation (rootProject.ext.dependencies.mogoochnoop){ + exclude group: 'com.mogo.commons' //by group + exclude group: 'com.mogo.module' //by group + exclude group: 'com.mogo.map' //by group + exclude group: 'com.mogo.eagle.core' //by group + exclude group: 'com.mogo.eagle.core.function' //by group + } + fochtaxiImplementation (rootProject.ext.dependencies.mogoochtaxi){ + exclude group: 'com.mogo.commons' //by group + exclude group: 'com.mogo.module' //by group + exclude group: 'com.mogo.map' //by group + exclude group: 'com.mogo.eagle.core' //by group + exclude group: 'com.mogo.eagle.core.function' //by group + } + fochbusImplementation (rootProject.ext.dependencies.mogoochbus){ + exclude group: 'com.mogo.commons' //by group + exclude group: 'com.mogo.module' //by group + exclude group: 'com.mogo.map' //by group + exclude group: 'com.mogo.eagle.core' //by group + exclude group: 'com.mogo.eagle.core.function' //by group + } fPadLenovoImplementation (rootProject.ext.dependencies.mogoochnoop){ exclude group: 'com.mogo.commons' //by group diff --git a/core/function-impl/mogo-core-function-main/build.gradle b/core/function-impl/mogo-core-function-main/build.gradle index 9ec1305037..546975b8d7 100644 --- a/core/function-impl/mogo-core-function-main/build.gradle +++ b/core/function-impl/mogo-core-function-main/build.gradle @@ -103,7 +103,6 @@ dependencies { implementation project(':modules:mogo-module-service') implementation project(':modules:mogo-module-v2x') implementation project(':modules:mogo-module-share') -// implementation project(':modules:tanlulib') implementation project(':modules:mogo-module-monitor') implementation project(':modules:mogo-module-extensions') implementation project(':modules:mogo-module-map') diff --git a/modules.txt b/modules.txt index 483878ba94..5392c18e84 100644 --- a/modules.txt +++ b/modules.txt @@ -39,7 +39,6 @@ :modules:mogo-module-push-base :modules:mogo-module-push-noop :modules:mogo-module-push -:modules:tanlulib :modules:mogo-module-monitor :core:function-impl:mogo-core-function-autopilot :core:function-impl:mogo-core-function-hmi diff --git a/modules/mogo-module-share/build.gradle b/modules/mogo-module-share/build.gradle index 519c770bcd..65fa5fa567 100644 --- a/modules/mogo-module-share/build.gradle +++ b/modules/mogo-module-share/build.gradle @@ -37,6 +37,10 @@ android { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 } + + kotlinOptions { + jvmTarget = "1.8" + } } dependencies { @@ -53,12 +57,13 @@ dependencies { implementation rootProject.ext.dependencies.rxjava implementation rootProject.ext.dependencies.rxandroid implementation rootProject.ext.dependencies.mogoaicloudtanlu + implementation rootProject.ext.dependencies.analytics implementation rootProject.ext.dependencies.eventbus implementation rootProject.ext.dependencies.coroutinescore implementation rootProject.ext.dependencies.coroutinesandroid - implementation rootProject.ext.dependencies.retrofit - implementation rootProject.ext.dependencies.retrofitconvertergson +// implementation rootProject.ext.dependencies.retrofit +// implementation rootProject.ext.dependencies.retrofitconvertergson implementation 'com.zhidaoauto.controller:api:1.0.8' if (Boolean.valueOf(USE_MAVEN_PACKAGE)) { diff --git a/modules/mogo-module-share/src/main/AndroidManifest.xml b/modules/mogo-module-share/src/main/AndroidManifest.xml index 06a62d3d0f..2337826536 100644 --- a/modules/mogo-module-share/src/main/AndroidManifest.xml +++ b/modules/mogo-module-share/src/main/AndroidManifest.xml @@ -3,5 +3,10 @@ + + + diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/MogoTanluApiProvider.java b/modules/mogo-module-share/src/main/java/com/mogo/module/share/MogoTanluApiProvider.java new file mode 100644 index 0000000000..84d747a050 --- /dev/null +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/MogoTanluApiProvider.java @@ -0,0 +1,66 @@ +package com.mogo.module.share; + +import android.content.Context; +import android.util.ArrayMap; + +import com.alibaba.android.arouter.facade.annotation.Route; +import com.mogo.commons.analytics.AnalyticsUtils; +import com.mogo.eagle.core.data.map.MogoLocation; +import com.mogo.module.common.MogoApisHandler; +import com.mogo.module.share.service.MainService; +import com.mogo.module.share.service.UploadParams; +import com.mogo.service.share.IMogoTanluProvider; +import com.mogo.service.share.TanluUploadParams; +import com.mogo.utils.logger.Logger; + +import java.util.Map; + +import static com.mogo.eagle.core.data.constants.MogoServicePaths.PATH_TANLU_API; +import static com.mogo.module.share.constant.StrategyShareConstKt.S_TAG; + +/** + * 探路api + * + * @author tongchenfei + */ +@Route(path = PATH_TANLU_API) +public class MogoTanluApiProvider implements IMogoTanluProvider { + private Context context; + + /** + * 上传情报 + * + * @param params 情报类型 + */ + @Override + public void uploadRoadCondition(TanluUploadParams params) { + if (params != null) { + Logger.d(S_TAG, "uploadRoadCondition: " + params); + Map properties = new ArrayMap<>(); + properties.put("type", params.getEventType()); + properties.put("from", params.getFromType()); + AnalyticsUtils.track("v2x_share_type", properties); + MogoLocation location = MogoApisHandler.getInstance().getApis().getMapServiceApi().getSingletonLocationClient(context).getLastKnowLocation(); + MainService.Companion.launchService(context, new UploadParams(params.getEventType(), + params.getFromType(), params.getDuration(), params.getParentId(), + params.getLocation().lat, params.getLocation().lon, location.getAddress(), location.getBearing(), location.getAdCode(), location.getCityCode())); + } else { + Logger.e(S_TAG, "params为空,无法上报情报"); + } + } + + /** + * 开启探路业务服务 + */ + @Override + public void startTanluService() { + Logger.d(S_TAG, "startTanluService"); + MainService.Companion.launchService(context, null); + } + + @Override + public void init(Context context) { + this.context = context; + Logger.d(S_TAG, "新TanluApi模块 init===="); + } +} diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/StrategyShareProvider.kt b/modules/mogo-module-share/src/main/java/com/mogo/module/share/StrategyShareProvider.kt index e26b3e6a96..ff2b6955a4 100644 --- a/modules/mogo-module-share/src/main/java/com/mogo/module/share/StrategyShareProvider.kt +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/StrategyShareProvider.kt @@ -5,6 +5,7 @@ package com.mogo.module.share import android.content.Context import android.util.ArrayMap import com.alibaba.android.arouter.facade.annotation.Route +import com.alibaba.android.arouter.facade.template.IProvider import com.alibaba.android.arouter.launcher.ARouter import com.mogo.commons.analytics.AnalyticsUtils import com.mogo.eagle.core.data.constants.MogoServicePaths @@ -18,7 +19,6 @@ import com.mogo.module.share.service.UploadParams import com.mogo.module.share.strategyreceiver.AccidentStrategyReceiver import com.mogo.module.share.strategyreceiver.BlockStrategy import com.mogo.service.IMogoServiceApis -import com.mogo.service.share.IMogoTanluProvider import com.mogo.service.share.TanluUploadParams import com.mogo.utils.logger.Logger import org.json.JSONObject @@ -29,7 +29,7 @@ import org.json.JSONObject * @author lixiaopeng */ @Route(path = MogoServicePaths.PATH_STRATEGY_SHARE) -class StrategyShareProvider : IMogoTanluProvider { +class StrategyShareProvider : IProvider { private lateinit var blockStrategy: BlockStrategy private var mContext: Context? = null @@ -66,33 +66,4 @@ class StrategyShareProvider : IMogoTanluProvider { // } } - /** - * 上传情报 - * - * @param params 情报类型 - */ - override fun uploadRoadCondition(params: TanluUploadParams?) { - if (params != null) { - Logger.d(S_TAG, "uploadRoadCondition: $params") - val properties: MutableMap = ArrayMap() - properties["type"] = params.eventType - properties["from"] = params.fromType - AnalyticsUtils.track("v2x_share_type", properties) - val location = MogoApisHandler.getInstance().apis.mapServiceApi.getSingletonLocationClient(mContext).lastKnowLocation - launchService(mContext!!, UploadParams(params.eventType, - params.fromType, params.duration, params.parentId, - params.location.lat, params.location.lon, location.address, location.bearing, location.adCode, location.cityCode)) - } else { - Logger.e(S_TAG, "params为空,无法上报情报") - } - } - - /** - * 开启探路业务服务 - */ - override fun startTanluService() { - Logger.d(S_TAG, "startTanluService") - launchService(mContext!!, null) - } - } \ No newline at end of file diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/BaseDataComapt.kt b/modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/BaseDataCompat.kt similarity index 99% rename from modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/BaseDataComapt.kt rename to modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/BaseDataCompat.kt index b64bb56ffc..3aea267196 100644 --- a/modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/BaseDataComapt.kt +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/BaseDataCompat.kt @@ -2,4 +2,5 @@ package com.mogo.module.share.bean import com.mogo.eagle.core.data.BaseData + data class BaseDataCompat(var result:T?): BaseData() \ No newline at end of file diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/constant/ShareConstants.java b/modules/mogo-module-share/src/main/java/com/mogo/module/share/constant/ShareConstants.java index e9abfd429b..d0736ea534 100644 --- a/modules/mogo-module-share/src/main/java/com/mogo/module/share/constant/ShareConstants.java +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/constant/ShareConstants.java @@ -29,6 +29,7 @@ public class ShareConstants { public static final String TAG = "/tanlu/ui"; public static final String NAVI_INFO = "navi_info"; public static final String MODEL_NAME = "CARD_TYPE_ROAD_CONDITION"; + public static final String TANLU = "TanLu"; /** * 免唤醒词上报拥堵 diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/net/ShareLsApiService.java b/modules/mogo-module-share/src/main/java/com/mogo/module/share/net/ShareLsApiService.java deleted file mode 100644 index 68aca43ab5..0000000000 --- a/modules/mogo-module-share/src/main/java/com/mogo/module/share/net/ShareLsApiService.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.mogo.module.share.net; - -import com.mogo.module.share.bean.BaseDataCompat; -import com.mogo.module.share.bean.RoadInfos; - -import java.util.Map; - -import io.reactivex.Observable; -import retrofit2.http.FieldMap; -import retrofit2.http.FormUrlEncoded; -import retrofit2.http.POST; - -public interface ShareLsApiService { - /** - * 查询(搜索)道路事件信息 - * 接口文档:http://wiki.zhidaohulian.com/pages/viewpage.action?pageId=42305842 - * 文档中有些参数暂时没有用到,包括radius,limit - * - * @return - */ -// @FormUrlEncoded -// @POST("/yycp-launcherSnapshot/launcherSnapshot/searchRoadEventsSync") -// Observable> queryRoadInfos(@FieldMap Map params); - -} diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/service/CarCorderController.kt b/modules/mogo-module-share/src/main/java/com/mogo/module/share/service/CarCorderController.kt index da8b681487..80bc2002e3 100644 --- a/modules/mogo-module-share/src/main/java/com/mogo/module/share/service/CarCorderController.kt +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/service/CarCorderController.kt @@ -1,7 +1,6 @@ package com.mogo.module.share.service import android.text.TextUtils -import android.util.Log import com.hw.videoprocessor.VideoProcessor import com.mogo.cloud.network.BaseData import com.mogo.cloud.passport.MoGoAiCloudClientConfig @@ -14,11 +13,13 @@ import com.mogo.commons.debug.DebugConfig import com.mogo.module.share.bean.event.GetImageSuccessEvent import com.mogo.module.share.bean.event.LatLngStickyEventBus import com.mogo.module.share.constant.STRATEGY_UPLOAD_TYPE_ARRAY +import com.mogo.module.share.constant.ShareConstants.TANLU import com.mogo.module.share.utils.* import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.getStrategyMaxSpeed import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.getStrategyMinSpeed import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.getStrategyType import com.mogo.utils.NetworkUtils +import com.mogo.utils.logger.Logger import com.zhidao.auto.carcorder.callback.TakePhotoCallback import com.zhidao.auto.carcorder.callback.TakeVideoCallback import com.zhidao.auto.carcorder.controller.ZdCarCoderController @@ -32,7 +33,6 @@ import kotlin.math.abs * @since 2019-10-30 */ object CarCorderController : TakePhotoCallback, TakeVideoCallback { - const val TAG: String = "CarCorderController" private lateinit var zdCarCoderController: ZdCarCoderController private var outputVideoPath: String = "" private var mType: String = "" //1 上报拥堵, 2 封路和查车 @@ -83,7 +83,7 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { areaCode: String, cityCode: String ) { - Log.d(TAG, "takePhoto ---------- type = $type --- mType = $mType ---fromType = $fromType") + Logger.d(TANLU, "takePhoto ---------- type = $type --- mType = $mType ---fromType = $fromType") this.mType = type this.mainInfoId = mainInfoId this.mFromType = fromType @@ -120,7 +120,7 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { areaCode: String, cityCode: String ) { - Log.d(TAG, "takeVideo -------- isCustom = $isCustom ---mFromType = $mFromType ---type = $type ---speed = $speed") + Logger.d(TANLU, "takeVideo -------- isCustom = $isCustom ---mFromType = $mFromType ---type = $type ---speed = $speed") this.mType = type this.mainInfoId = mainInfoId this.mFromType = fromType @@ -138,7 +138,7 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { zdCarCoderController.takeVideo(cameraId, duration) trackGetVideo(1) } else { //比亚迪 - Log.d(TAG, "takeVideo ------ isnet = " + NetworkUtils.isConnected(AbsMogoApplication.getApp().applicationContext)) + Logger.d(TANLU, "takeVideo ------ isnet = " + NetworkUtils.isConnected(AbsMogoApplication.getApp().applicationContext)) getInfo("", mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 1, mFromType, CarCorderController.mainInfoId)?.let { uploadRoadInfo(it) } //地图上打点 @@ -162,7 +162,7 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { override fun onTakePhotoFail(photoType: Int, camera: Int) { trackGetPhoto(3) val isCustom = CustomStatusHandler.pollPhotoStatus() - Log.e(TAG, "onTakePhotoFail -----mType = $mType --- isCustom = $isCustom") + Logger.e(TANLU, "onTakePhotoFail -----mType = $mType --- isCustom = $isCustom") //获取图片失败也上报,图片不打点 if (isCustom) { getInfo("", mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } @@ -174,7 +174,7 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { //拍照成功回调返回图片本地路径 override fun onTakePhotoSuccess(photoType: Int, camera: Int, photoPath: String?) { trackGetPhoto(2) - Log.d(TAG, "onTakePhotoSuccess -----mType = $mType --- mainInfoId = $mainInfoId") + Logger.d(TANLU, "onTakePhotoSuccess -----mType = $mType --- mainInfoId = $mainInfoId") val isCustom = CustomStatusHandler.pollPhotoStatus() if (!isCustom) { @@ -201,20 +201,20 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { val speed = LocationUtil.getInstance().getSpeed() if (!TextUtils.isEmpty(mType)) { - Log.d(TAG, "onTakePhotoSuccess mType != null") + Logger.d(TANLU, "onTakePhotoSuccess mType != null") if (photoPath != null) { getInfo(photoPath, mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } } } else { - Log.d(TAG, "onTakePhotoSuccess mType == null") - Log.d( - TAG, + Logger.d(TANLU, "onTakePhotoSuccess mType == null") + Logger.d( + TANLU, "onTakePhotoSuccess maxSpeedPic = $maxSpeedPic ---> speed = $speed ---->minSpeedPic= $minSpeedPic" ) if (maxSpeedPic == -1) { if (speed >= (abs(minSpeedPic) / 3.6f)) { - Log.d(TAG, "onTakePhotoSuccess abs =" + (abs(minSpeedPic) / 3.6f)) + Logger.d(TANLU, "onTakePhotoSuccess abs =" + (abs(minSpeedPic) / 3.6f)) if (photoPath != null) { getInfo(photoPath, mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } } @@ -222,7 +222,7 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { } if (minSpeedPic > 0 && maxSpeedPic > 0) { - Log.d(TAG, "onTakePhotoSuccess minSpeedPic > 0 -- speed = $speed") + Logger.d(TANLU, "onTakePhotoSuccess minSpeedPic > 0 -- speed = $speed") if ((speed >= (minSpeedPic / 3.6f)) && speed <= (maxSpeedPic / 3.6f)) { if (photoPath != null) { getInfo(photoPath, mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } @@ -237,8 +237,8 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { val thumbnailPath = AbsMogoApplication.getApp().applicationContext.filesDir.parent + File.separator + "Thumbnail${System.currentTimeMillis()}.jpg" val isSuccess = getVideoThumbnail(videoPath!!, thumbnailPath) - Log.d( - TAG, + Logger.d( + TANLU, "getVideo onTakeVideoSuccess===$videoPath -----> isSuccess= $isSuccess ----> mType = $mType --- mainInfoId = $mainInfoId" ) @@ -270,12 +270,12 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { compressVideo(videoPath, thumbnailPath, it) } else { - Log.d( - TAG, + Logger.d( + TANLU, "onTakeVideoSuccess maxSpeedVideo = $maxSpeedVideo --->speed= $speed + minSpeedVideo = $minSpeedVideo" ) if (maxSpeedVideo == -1) { - Log.d(TAG, "onTakeVideoSuccess 111 abs =" + (abs(minSpeedVideo) / 3.6f)) + Logger.d(TANLU, "onTakeVideoSuccess 111 abs =" + (abs(minSpeedVideo) / 3.6f)) if (speed >= (abs(minSpeedVideo) / 3.6f)) { //获取视频以及缩略图成功,开始上报 compressVideo(videoPath, thumbnailPath, it) @@ -283,7 +283,7 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { } if (minSpeedVideo > 0 && maxSpeedVideo > 0) { - Log.d(TAG, "onTakeVideoSuccess minSpeedVideo > 0 -- speed = $speed") + Logger.d(TANLU, "onTakeVideoSuccess minSpeedVideo > 0 -- speed = $speed") if ((speed >= (minSpeedVideo / 3.6f)) && speed <= (maxSpeedVideo / 3.6f)) { compressVideo(videoPath, thumbnailPath, it) } else { @@ -316,8 +316,8 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { * 压缩视频并且上传 */ private fun compressVideo(videoPath: String, thumbnailPath: String, entity: TakeEntity) { - Log.d( - TAG, + Logger.d( + TANLU, "outputVideoPath = " + outputVideoPath + ">> videoPath=" + videoPath + " isCustom = ${entity.isCustom}" ) val startTime = System.currentTimeMillis() @@ -332,12 +332,12 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { .bitrate(2000 * 1024) .frameRate(25) .process() - Log.d(TAG, "compress cost time =" + (System.currentTimeMillis() - startTime)) + Logger.d(TANLU, "compress cost time =" + (System.currentTimeMillis() - startTime)) getInfo(outputVideoPath, mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } //删除压缩前的视频 deletePicFile(videoPath) } catch (e: Exception) { - Log.e(TAG, "compressVideo e = $e") + Logger.e(TANLU, "compressVideo e = $e") //删除压缩前的视频 deletePicFile(videoPath) e.printStackTrace() @@ -352,14 +352,16 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { MogoUploadManager.getInstance(AbsMogoApplication.getApp().applicationContext).uploadInfo(info, object : ITanluUploadCallback { override fun onSuccess(result: BaseData) { if (result.result != null) { - Log.d(TAG, "result =" + result.result); + Logger.d(TANLU, "result =" + result.result) } } override fun onFailure(code: Int) { + Logger.e(TANLU, "onFailure code = $code") } override fun onError(e: Throwable) { + Logger.e(TANLU, "onError e = $e") } }) } @@ -386,11 +388,11 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { } override fun onTakePhotoCancel(photoType: Int, camera: Int) { - Log.d(TAG, "onTakePhotoCancel -----photoType = $photoType") + Logger.d(TANLU, "onTakePhotoCancel -----photoType = $photoType") } override fun onTakeVideoCancel(camera: Int) { - Log.d(TAG, "onTakeVideoCancel -----camera = $camera") + Logger.d(TANLU, "onTakeVideoCancel -----camera = $camera") //失败了,传空地址,发起请求 videoAndThumbMap["video"] = "" videoAndThumbMap["thumb"] = "" diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/service/MainService.kt b/modules/mogo-module-share/src/main/java/com/mogo/module/share/service/MainService.kt index 28bbb797c6..2ef1939bd5 100644 --- a/modules/mogo-module-share/src/main/java/com/mogo/module/share/service/MainService.kt +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/service/MainService.kt @@ -8,7 +8,6 @@ import android.content.Context import android.content.Intent import android.content.IntentFilter import android.os.IBinder -import android.util.Log import com.alibaba.android.arouter.launcher.ARouter import com.elegant.analytics.Analytics import com.mogo.commons.AbsMogoApplication @@ -23,6 +22,7 @@ import com.mogo.utils.storage.SharedPrefsMgr import com.zhidao.cosupload.manager.CosUploadManagerImpl import com.mogo.module.share.BuildConfig import com.mogo.module.share.constant.* +import com.mogo.module.share.constant.ShareConstants.TANLU import com.mogo.module.share.utils.* import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.clearStrategyType import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.getStrategyFrequency @@ -43,7 +43,7 @@ class MainService : Service() { companion object { fun launchService(context: Context, params: UploadParams?) { val intent = Intent(context, MainService::class.java).apply { - Log.e("MainService", "launch type = $params") + Logger.d(TANLU, "launch type = $params") putExtra("params", params) } context.startService(intent) @@ -56,8 +56,6 @@ class MainService : Service() { //是否已经获取过策略 var isGetStrategies: Boolean = false - private val TAG: String = this.javaClass.simpleName - //1是一次性,2是周期性 private var picType: Int = 0 private var videoType: Int = 0 @@ -90,7 +88,7 @@ class MainService : Service() { if (serviceApis.mapServiceApi.getSingletonLocationClient(this) != null && serviceApis.mapServiceApi.getSingletonLocationClient(this).lastKnowLocation != null) { speed = serviceApis.mapServiceApi.getSingletonLocationClient(this).lastKnowLocation.speed - Log.d(TAG, "onStartCommand speed = $speed") + Logger.d(TANLU, "onStartCommand speed = $speed") } if (intent != null) { @@ -106,7 +104,7 @@ class MainService : Service() { mAreaCode = it.areaCode mCityCode = it.cityCode - Log.d(TAG, "onStartCommand shareType = $shareType --fromType = $fromType --mainInfoId = $mainInfoId -- mLongitude = $mLongitude --mLatitude = $mLatitude --it.duration = ${it.duration} ") + Logger.d(TANLU, "onStartCommand shareType = $shareType --fromType = $fromType --mainInfoId = $mainInfoId -- mLongitude = $mLongitude --mLatitude = $mLatitude --it.duration = ${it.duration} ") if (fromType == UPLOAD_FROM_STRATEGY_ACCIDENT_AUTO || fromType == UPLOAD_FROM_STRATEGY_BLOCK_AUTO) { // 如果是策略上报,isCustom = false takeVideo(it.duration) @@ -115,7 +113,7 @@ class MainService : Service() { } } } else { - Log.e(TAG, "intent == null ") + Logger.e(TANLU, "intent == null ") } return super.onStartCommand(intent, flags, startId) @@ -124,7 +122,7 @@ class MainService : Service() { //定时任务回调广播 private var mAlarmBroadCast: BroadcastReceiver = object : BroadcastReceiver() { override fun onReceive(p0: Context?, p1: Intent) { - Log.d(TAG, "receive alarm!!!!!!!!!!AlarmType===${p1.getIntExtra("AlarmType", 1)}") + Logger.d(TANLU, "receive alarm!!!!!!!!!!AlarmType===${p1.getIntExtra("AlarmType", 1)}") if (p1.action == alarmBroadAction) { if (p1.getIntExtra("AlarmType", 1) == AlarmTypePic) { //拍照 @@ -178,9 +176,8 @@ class MainService : Service() { @Subscribe(threadMode = ThreadMode.MAIN, sticky = true, priority = 98) fun getImageEvent(getImageSuccessEvent: GetImageSuccessEvent) { val info = LocationUtil.getInstance().getLocationInfo() - Log.d("MainService", "getImageEvent long = ${info.longitude} ----> lat= ${info.latitude}") - Log.d( - "MainService", + Logger.d(TANLU, "getImageEvent long = ${info.longitude} ----> lat= ${info.latitude}") + Logger.d(TANLU, "getImageEvent url = " + getImageSuccessEvent.getImageUrl() + ">>>>type =" + getImageSuccessEvent.getType() ) @@ -195,7 +192,7 @@ class MainService : Service() { */ private fun initLocationListener() { val isOpen = SharedPrefsMgr.getInstance(AbsMogoApplication.getApp().applicationContext).getBoolean("KEY_SERVER_REPORTSTRATEGY_SWITCH", false) - Logger.d("EntrancePresenter", " initLocationListener ---- isOpen = $isOpen") + Logger.d(TANLU, " initLocationListener ---- isOpen = $isOpen") //开始开始监听速度,只要超过一次5公里每小时则即开始获取策略进行本地上报 只有release才加此判断,qa环境方便测试 LocationUtil.getInstance().setonSpeedlistenner(object : LocationUtil.SpeedListener { override fun onSpeedGet(speed: Float) { @@ -204,7 +201,7 @@ class MainService : Service() { mainServiceHttpModel.initStrategies { handleReportStrategy() } - Log.d("MainService", "initLocationListener more than 5 start upload speed = $speed") + Logger.d(TANLU, "initLocationListener more than 5 start upload speed = $speed") isGetStrategies = true } } @@ -227,7 +224,7 @@ class MainService : Service() { "video", getStrategyType("video") ) - Log.d("MainService", "handleReportStrategy picType = $picType ---videoType = $videoType") + Logger.d(TANLU, "handleReportStrategy picType = $picType ---videoType = $videoType") shareType = TANLU_ROAD_CURRENT if (picType == 1) { takePhoto() @@ -253,7 +250,7 @@ class MainService : Service() { //获取图片 private fun takePhoto(isInterval: Boolean = false, isCustom: Boolean = false) { - Log.d("MainService", "takePhoto -----1----->") + Logger.d(TANLU, "takePhoto -----1----->") //判断是否授权 // if (isAuthorization(BaseApplication.getAppContext())) { //目前不支持连拍,只能定时2秒拍一张 第一期每次只拍一张 @@ -276,7 +273,7 @@ class MainService : Service() { isCustom: Boolean = false, id: Long = 0 ) { - Log.d("MainService", "takeVideo --------1----> fromType = $fromType --isCustom = $isCustom") + Logger.d(TANLU, "takeVideo --------1----> fromType = $fromType --isCustom = $isCustom") // if (isAuthorization(BaseApplication.getAppContext())) { CarCorderController.takeVideo(1, duration, isCustom, id, shareType, mainInfoId, fromType, mLongitude, mLatitude, speed, mAddress, mDirection, mAreaCode, mCityCode) // } @@ -293,8 +290,7 @@ class MainService : Service() { intent.putExtra("number", getLong(PIC_NUMBER, PIC_NUMBER_DEFAULT)) intent.putExtra("AlarmType", AlarmTypePic) val pendingIntent = PendingIntent.getBroadcast(this, AlarmTypePic, intent, 0) - Log.d( - "MainService", + Logger.d(TANLU, "postPhotoAlarmTask time =" + getStrategyInterval( AbsMogoApplication.getApp().applicationContext, "pic", @@ -326,8 +322,7 @@ class MainService : Service() { videoIntent.putExtra("AlarmType", AlarmTypeVideo) val videoPendingIntent = PendingIntent.getBroadcast(this, AlarmTypeVideo, videoIntent, 0) - Log.d( - "MainService", + Logger.d(TANLU, "postVideoAlarmTask time =" + getStrategyInterval( AbsMogoApplication.getApp().applicationContext, "video", diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/service/MainServiceController.kt b/modules/mogo-module-share/src/main/java/com/mogo/module/share/service/MainServiceController.kt index 6fc2a6ed67..9b11decda4 100644 --- a/modules/mogo-module-share/src/main/java/com/mogo/module/share/service/MainServiceController.kt +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/service/MainServiceController.kt @@ -1,9 +1,10 @@ package com.mogo.module.share.service -import android.util.Log import com.mogo.commons.AbsMogoApplication import com.mogo.eagle.core.network.request import com.mogo.module.share.bean.* +import com.mogo.module.share.constant.ShareConstants +import com.mogo.module.share.constant.ShareConstants.TANLU import com.mogo.module.share.utils.CarNet_Get_Strategy import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.setStrategyFrequency import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.setStrategyInterval @@ -12,13 +13,14 @@ import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.setStrategyM import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.setStrategyType import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.setStrategyValidity import com.mogo.module.share.utils.trackNormalEvent +import com.mogo.utils.logger.Logger import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking class MainServiceController { companion object { - const val TAG = "MainServiceController" +// const val TAG = "MainServiceController" } //逆地理编码是否重试 @@ -36,15 +38,15 @@ class MainServiceController { onSuccess { it.result.let { strategy -> trackNormalEvent(CarNet_Get_Strategy, null) - Log.d(TAG, "pic =" + strategy.cityStrategy.pic) - Log.d(TAG, "video =" + strategy.cityStrategy.video) + Logger.d(TANLU, "pic =" + strategy.cityStrategy.pic) + Logger.d(TANLU, "video =" + strategy.cityStrategy.video) syncStrategiesData(strategy.cityStrategy) initFinish?.invoke() } } onError { reInitStrategies() - Log.e(TAG, "initStrategies onError ${it.message}") + Logger.e(TANLU, "initStrategies onError ${it.message}") } } } @@ -123,7 +125,7 @@ class MainServiceController { strategy.video!!.minSpeed ) } else { - Log.d(TAG, "strategy Data is null") + Logger.d(TANLU, "strategy Data is null") } } diff --git a/settings.gradle b/settings.gradle index 47fd724c0d..a6b30ee463 100644 --- a/settings.gradle +++ b/settings.gradle @@ -54,7 +54,6 @@ include ':libraries:map-autonavi' include ':libraries:mogo-map' // OLD业务模块 -//include ':modules:tanlulib' include ':modules:mogo-module-monitor' include ':modules:mogo-module-adas' include ':modules:mogo-module-map'