修改事件上报相关埋点策略,全部移到了IMogoTanluApiProvider里面,之前的视频抓取广播禁用,采用新的IMogoTanluApiProvider里面的upload方法进行视频抓取

This commit is contained in:
tongchenfei
2020-08-12 15:52:14 +08:00
parent 294440bd5d
commit df35571cff
11 changed files with 313 additions and 249 deletions

View File

@@ -35,25 +35,43 @@ const val AUTO_NAVI_END = 9 //结束导航
const val VALUE_DICT_DATA_TYPE = "deva_infomation_type" // dict 数据请求类型:情报类型数据
//上报的类型
//事件类型
const val TANLU_TRAFFIC_CHECK = "10002" //交通检查
const val TANLU_ROAD_CLOSURE = "10003" //封路
const val TANLU_ROAD_WORK = "10006" //施工
const val TANLU_ROAD_CONGESTION = "10007" //拥堵
const val TANLU_ROAD_PONDING = "10008" //积水
const val TANLU_ROAD_HEAVY_FOG = "10010" //大雾
const val TANLU_ROAD_ICING = "10011" //积冰
const val TANLU_ROAD_ACCIDENT = "10013" //事故
const val TANLU_ROAD_CURRENT = "10015" //实时路况
// 上报类型
/**
* 用户手点上报
*/
const val UPLOAD_FROM_USER = 1
/**
* 用户语音上报
*/
const val UPLOAD_FROM_VOICE = 2
/**
* 数据策略:拥堵自动上报
*/
const val UPLOAD_FROM_STRATEGY_BLOCK_AUTO = 3
/**
* 数据策略:已有事件云端校验
*/
const val UPLOAD_FROM_STRATEGY_CLOUD_CHECK = 4
/**
* 数据策略:交通事故上报
*/
const val UPLOAD_FROM_STRATEGY_ACCIDENT_AUTO = 5
/**
* 默认视频抓取时长,单位是秒
*/
const val DEFAULT_VIDEO_DURATION = 10
const val DEF_NEWS_LABEL = "拥堵"
const val DEF_NEWS_VALUE = "traffic_jam"

View File

@@ -12,8 +12,8 @@ class ShareRoadReceiver : BroadcastReceiver() {
Log.d("MainService", "ShareRoadReceiver ------> intent.action = " + intent.action)
if (intent.action == "com.zhidao.share.roadcondition.action") {
var type = intent.getStringExtra("type")
Log.d("MainService", "ShareRoadReceiver type ----> $type")
MainService.launchService(context, type)
Log.e("MainService", "ShareRoadReceiver type ----> $type ----> 此方法已经废弃了,无法调起服务")
// MainService.launchService(context, type)
}
}
}

View File

@@ -36,10 +36,10 @@ import java.util.concurrent.TimeUnit
class MainService : Service() {
companion object {
fun launchService(context: Context, type: String) {
fun launchService(context: Context, params: UploadParams?) {
val intent = Intent(context, MainService::class.java).apply {
putExtra("type", type)
Log.e("MainService", "launchService type = $type")
Log.e("MainService", "launchService type = $params")
putExtra("params", params)
}
context.startService(intent)
}
@@ -47,15 +47,19 @@ class MainService : Service() {
private lateinit var mainServiceHttpModel: MainServiceController
private var mAlarmManager: AlarmManager =
AbsMogoApplication.getApp().applicationContext.getSystemService(Context.ALARM_SERVICE) as AlarmManager
AbsMogoApplication.getApp().applicationContext.getSystemService(Context.ALARM_SERVICE) as AlarmManager
//是否已经获取过策略
var isGetStrategies: Boolean = false
val TAG: String = this.javaClass.simpleName
//1是一次性2是周期性
var picType: Int = 0
var videoType: Int = 0
var shareType: String = "type"
var isCustom: Boolean = false;
var isCustom: Boolean = false
var params: UploadParams? = null
//发送主动上报结果广播给外部
@@ -76,25 +80,22 @@ class MainService : Service() {
// LocationUtil.getInstance().initLocation()
//参数说明appKey: app唯一标识比如包名
CosUploadManagerImpl.getInstance(AbsMogoApplication.getApp().applicationContext)
.init(BuildConfig.APPLICATION_ID, 2)
.init(BuildConfig.APPLICATION_ID, 2)
//初始化语音
VoiceController.initVoice()
if (intent != null) {
shareType = intent.getStringExtra("type")
Log.d(TAG, "onStartCommand shareType = $shareType")
if (shareType.equals(TANLU_ROAD_CONGESTION) || shareType.equals(TANLU_TRAFFIC_CHECK) || shareType.equals(
TANLU_ROAD_CLOSURE
) || shareType.equals(TANLU_ROAD_CURRENT)
|| shareType.equals(TANLU_ROAD_PONDING) || shareType.equals(TANLU_ROAD_ICING) || shareType.equals(
TANLU_ROAD_HEAVY_FOG
)
|| shareType.equals(TANLU_ROAD_ACCIDENT) || shareType.equals(
TANLU_ROAD_WORK
)
) {
params = intent.getParcelableExtra("params")
params?.let {
shareType = it.eventType
Log.d(TAG, "onStartCommand shareType = $shareType")
if (shareType == TANLU_ROAD_CONGESTION || shareType == TANLU_TRAFFIC_CHECK || shareType == TANLU_ROAD_CLOSURE || shareType == TANLU_ROAD_CURRENT
|| shareType == TANLU_ROAD_PONDING || shareType == TANLU_ROAD_ICING || shareType == TANLU_ROAD_HEAVY_FOG
|| shareType == TANLU_ROAD_ACCIDENT || shareType == TANLU_ROAD_WORK
) {
// takePhoto(1, false, true)
takeVideo(10, isCustom = true, id = id)
takeVideo(it.duration, isCustom = true, id = id)
}
}
} else {
Log.e(TAG, "intent == null ")
@@ -193,14 +194,14 @@ class MainService : Service() {
var info = LocationUtil.getInstance().getLocationInfo()
Log.e("MainService", "getImageEvent long = ${info.longitude} ----> lat= ${info.latitude}")
Log.d(
"MainService",
"getImageEvent url = " + getImageSuccessEvent.getImageUrl() + ">>>>type =" + getImageSuccessEvent.getType()
"MainService",
"getImageEvent url = " + getImageSuccessEvent.getImageUrl() + ">>>>type =" + getImageSuccessEvent.getType()
)
sendMarkerInfoReceiver(
info.latitude,
info.longitude,
getImageSuccessEvent.getImageUrl(),
getImageSuccessEvent.getType()
info.latitude,
info.longitude,
getImageSuccessEvent.getImageUrl(),
getImageSuccessEvent.getType()
)
}
@@ -241,14 +242,14 @@ class MainService : Service() {
private fun handleReportStrategy() {
//1是一次性2是周期性
picType = getStrategyFrequency(
AbsMogoApplication.getApp().applicationContext,
"pic",
getStrategyType("pic")
AbsMogoApplication.getApp().applicationContext,
"pic",
getStrategyType("pic")
)
videoType = getStrategyFrequency(
AbsMogoApplication.getApp().applicationContext,
"video",
getStrategyType("video")
AbsMogoApplication.getApp().applicationContext,
"video",
getStrategyType("video")
)
Log.d("MainService", "handleReportStrategy picType = $picType ---videoType = $videoType")
if (picType == 1) {
@@ -284,10 +285,10 @@ class MainService : Service() {
// log(TAG, "takePhoto -----2----->")
//目前不支持连拍只能定时2秒拍一张 第一期每次只拍一张
Observable.intervalRange(0, 1, 0, 2_000, TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(Consumer {
CarCorderController.takePhoto(1, 1, false, isCustom, TANLU_ROAD_CURRENT)
})
.observeOn(AndroidSchedulers.mainThread())
.subscribe(Consumer {
CarCorderController.takePhoto(1, 1, false, isCustom, TANLU_ROAD_CURRENT)
})
// }
postPhotoAlarmTask(isInterval)
@@ -297,15 +298,15 @@ class MainService : Service() {
//获取录像
private fun takeVideo(
duration: Int,
isInterval: Boolean = false,
isCustom: Boolean = false,
id: Long = 0
duration: Int,
isInterval: Boolean = false,
isCustom: Boolean = false,
id: Long = 0
) {
Log.d("MainService", "takeVideo --------1---->")
// if (isAuthorization(BaseApplication.getAppContext())) {
// log(TAG, "takeVideo --------2---->")
CarCorderController.takeVideo(1, duration, isCustom, id, if(isCustom) shareType else TANLU_ROAD_CURRENT)
CarCorderController.takeVideo(1, duration, isCustom, id, if (isCustom) shareType else TANLU_ROAD_CURRENT)
// }
postVideoAlarmTask(isInterval)
@@ -321,22 +322,22 @@ class MainService : Service() {
intent.putExtra("AlarmType", AlarmTypePic)
var 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(
"MainService",
"postPhotoAlarmTask time =" + getStrategyInterval(
AbsMogoApplication.getApp().applicationContext,
"pic",
getStrategyType("pic")
)
, pendingIntent
)
)
mAlarmManager.setExact(
AlarmManager.RTC, System.currentTimeMillis() +
getStrategyInterval(
AbsMogoApplication.getApp().applicationContext,
"pic",
getStrategyType("pic")
)
, pendingIntent
)
}
}
@@ -348,28 +349,28 @@ class MainService : Service() {
val videoIntent = Intent()
videoIntent.action = alarmBroadAction
videoIntent.putExtra(
"duration", (VIDEO_DURATION_DEFAULT / 1000).toInt()
"duration", (VIDEO_DURATION_DEFAULT / 1000).toInt()
)
videoIntent.putExtra("AlarmType", AlarmTypeVideo)
var videoPendingIntent =
PendingIntent.getBroadcast(this, AlarmTypeVideo, videoIntent, 0)
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(
"MainService",
"postVideoAlarmTask time =" + getStrategyInterval(
AbsMogoApplication.getApp().applicationContext,
"video",
getStrategyType("video")
)
, videoPendingIntent
)
)
mAlarmManager.setExact(
AlarmManager.RTC, System.currentTimeMillis() +
getStrategyInterval(
AbsMogoApplication.getApp().applicationContext,
"video",
getStrategyType("video")
)
, videoPendingIntent
)
}
}

View File

@@ -0,0 +1,37 @@
package com.zhidao.roadcondition.service
import android.os.Parcel
import android.os.Parcelable
class UploadParams(val eventType:String,val fromType:String,val duration:Int) : Parcelable {
constructor(parcel: Parcel) : this(
parcel.readString()!!,
parcel.readString()!!,
parcel.readInt())
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeString(eventType)
parcel.writeString(fromType)
parcel.writeInt(duration)
}
override fun describeContents(): Int {
return 0
}
override fun toString(): String {
return "UploadParams(eventType='$eventType', fromType='$fromType', duration=$duration)"
}
companion object CREATOR : Parcelable.Creator<UploadParams> {
override fun createFromParcel(parcel: Parcel): UploadParams {
return UploadParams(parcel)
}
override fun newArray(size: Int): Array<UploadParams?> {
return arrayOfNulls(size)
}
}
}