TP-67636 | Owais | webp image and time from backend changes (#183)

This commit is contained in:
Sayed Owais Ali
2024-06-04 17:03:40 +05:30
committed by GitHub
parent 9089ffdd8e
commit 7bde56da62
9 changed files with 68 additions and 33 deletions

View File

@@ -40,7 +40,7 @@ class AlfredDemoApplication : Application(), Application.ActivityLifecycleCallba
"qa",
"oMv77fgpBg9NFGom0Psizbf7lbrdBVJz"
)
AlfredManager.init(alfredConfig, this)
AlfredManager.init(alfredConfig, this, 27, "Critical Journey is active")
getAlfredCruiseInfo()
// Dumping anr data to click stream

View File

@@ -63,7 +63,9 @@ data class AlfredConfig(
internal var memoryUsageBeforeEventStart: Float? = null,
internal var storageUsageBeforeEventStart: Float? = null,
internal var batteryPercentageBeforeEventStart: Float? = null,
internal var cruiseAttributes: CruiseAttributes = CruiseAttributes()
internal var cruiseAttributes: CruiseAttributes = CruiseAttributes(),
internal var imageType: String = AlfredConstants.IMAGE_TYPE_JPEG,
internal var alfredTimeGap: Long = 0
) {
constructor(
appName: String,
@@ -90,18 +92,18 @@ data class AlfredConfig(
if (setToNext == true) {
this.eventStartRecordingTime = this.nextEventStartRecordingTime
} else {
this.eventStartRecordingTime = System.currentTimeMillis()
this.eventStartRecordingTime = AlfredManager.config.getAlfredCurrentTimeMillis()
}
}
fun setNextEventStartRecordingTime() {
this.nextEventStartRecordingTime = System.currentTimeMillis()
this.nextEventStartRecordingTime = AlfredManager.config.getAlfredCurrentTimeMillis()
}
fun getEventStartRecordingTime(): Long? = this.eventStartRecordingTime
fun setSessionStartRecordingTime() {
this.sessionStartRecordingTime = System.currentTimeMillis()
this.sessionStartRecordingTime = AlfredManager.config.getAlfredCurrentTimeMillis()
}
fun getSessionStartRecordingTime(): Long = this.sessionStartRecordingTime
@@ -138,7 +140,7 @@ data class AlfredConfig(
fun getEnableRecordingStatus(): Boolean = this.enableRecording
fun getEventTimeStamp(): Long = System.currentTimeMillis()
fun getEventTimeStamp(): Long = AlfredManager.config.getAlfredCurrentTimeMillis()
fun setUserId(userId: String?) {
this.userId = userId
@@ -346,4 +348,8 @@ data class AlfredConfig(
fun setLatestScreenshotTimestamp(timestamp: Long) {
this.latestScreenshotTimestamp = timestamp
}
internal fun getAlfredCurrentTimeMillis(): Long {
return System.currentTimeMillis() - alfredTimeGap
}
}

View File

@@ -20,7 +20,8 @@ data class Failure(
@SerializedName("request_url") val requestUrl: String? = "",
@SerializedName("request_method") val requestMethod: String? = "",
@SerializedName("client_ts") val clientTs: Long? = null,
@SerializedName("error_timestamp") val errorTimestamp: Long? = System.currentTimeMillis(),
@SerializedName("error_timestamp")
val errorTimestamp: Long? = AlfredManager.config.getAlfredCurrentTimeMillis(),
@SerializedName("zip_name") val zipName: List<String>? = null,
@SerializedName("error_name") val errorName: String? = "",
@SerializedName("error_status_code") val errorStatusCode: Long? = 0,

View File

@@ -70,7 +70,9 @@ data class BaseAttribute(
@SerializedName("metadata") val metaData: MetaData = MetaData(),
@SerializedName("snapshot_per_second")
val snapshotPerSecond: Int? = AlfredManager.config.getSnapshotPerSecond(),
@SerializedName("phone_number") val phoneNumber: String? = AlfredManager.config.getPhoneNumber()
@SerializedName("phone_number")
val phoneNumber: String? = AlfredManager.config.getPhoneNumber(),
@SerializedName("image_type") val imageType: String? = AlfredManager.config.imageType
)
data class SessionEventAttribute(

View File

@@ -24,7 +24,9 @@ data class Source(
@SerializedName("metrics_config") val metricsConfig: MetricsConfig? = null,
@SerializedName("os_config") val osConfig: OsConfig? = null,
@SerializedName("recordings_config") val recordingsConfig: RecordingsConfig? = null,
@SerializedName("type") val type: String? = null
@SerializedName("type") val type: String? = null,
@SerializedName("image_type") val imageType: String? = null,
@SerializedName("current_time") val currentTime: Long? = null
)
data class RecordingsConfig(

View File

@@ -79,7 +79,10 @@ object AlfredConstants {
const val SENSITIVE_COMPOSE_VIEW_TAG = "sensitive_compose_view"
const val EVENT_DB_NAME = "navi-analytics"
const val ZIP_FILE_EXTENSION = ".zip"
const val IMAGE_FILE_EXTENSION = ".jpeg"
const val IMAGE_FILE_EXTENSION_JPEG = ".jpeg"
const val IMAGE_FILE_EXTENSION_WEBP = ".webp"
const val IMAGE_TYPE_JPEG = "jpeg"
const val IMAGE_TYPE_WEBP = "webp"
const val SYNC_EVENT_TASK = "SyncEventTask"
const val SYNC_FAILURE_TASK = "SyncFailureTask"
const val SYNC_NEGATIVE_CASE_TASK = "SyncNegativeCaseTask"

View File

@@ -41,7 +41,7 @@ internal suspend fun getCruiseConfig(cruiseApiSuccessful: (response: CruiseRespo
errorType = AlfredConstants.API_ERROR,
requestUrl = DEFAULT_CRUISE_CONFIG_URL,
requestMethod = AlfredConstants.GET_METHOD,
errorTimestamp = System.currentTimeMillis(),
errorTimestamp = AlfredManager.config.getAlfredCurrentTimeMillis(),
errorName = AlfredConstants.GET_CRUISE_CONFIG_FAILURE,
errorStatusCode = response.code().toLong(),
errorMessage = response.message()
@@ -109,6 +109,10 @@ private fun setCruiseConfig(cruiseResponse: CruiseResponse) {
AlfredManager.config.setApiMetricsEnableStatus(!api_monitor_status)
}
}
source.imageType?.let { imageType -> AlfredManager.config.imageType = imageType }
source.currentTime?.let { currentTime ->
AlfredManager.config.alfredTimeGap = currentTime - System.currentTimeMillis()
}
}
}
}

View File

@@ -518,7 +518,7 @@ internal fun buildEvent(
screenName: String? = null,
moduleName: String? = null
): AnalyticsEvent {
val timeStamp = System.currentTimeMillis()
val timeStamp = AlfredManager.config.getAlfredCurrentTimeMillis()
val eventData =
EventAttribute(
eventId = UUID.randomUUID().toString(),
@@ -543,7 +543,7 @@ internal fun buildNegativeCaseEvent(
screenName: String? = null,
moduleName: String? = null
): NegativeCase {
val timeStamp = System.currentTimeMillis()
val timeStamp = AlfredManager.config.getAlfredCurrentTimeMillis()
val eventData =
EventAttribute(
eventId = UUID.randomUUID().toString(),
@@ -572,7 +572,7 @@ internal fun buildFailureEvent(
clientTs: Long? = null,
eventIdList: List<String>? = null
): FailureEvent {
val timeStamp = System.currentTimeMillis()
val timeStamp = AlfredManager.config.getAlfredCurrentTimeMillis()
val eventData =
Failure(
errorType = errorType,
@@ -594,7 +594,7 @@ internal fun buildAppPerformanceEvent(
eventType: String,
attribute: HashMap<String, Any>? = null
): ApiMetricHelper {
val timeStamp = System.currentTimeMillis()
val timeStamp = AlfredManager.config.getAlfredCurrentTimeMillis()
val metricData =
MetricAttribute(
eventId = AlfredManager.config.getAlfredEventId(),

View File

@@ -83,28 +83,42 @@ internal fun insertScreenShotPathInDb(
scope.launch(Dispatchers.IO) {
try {
val fileDir = context.filesDir
val currentTime = System.currentTimeMillis()
val currentTime = AlfredManager.config.getAlfredCurrentTimeMillis()
AlfredManager.config.setLatestScreenshotTimestamp(currentTime)
val fileName = currentTime.toString() + AlfredConstants.IMAGE_FILE_EXTENSION
val imageFileExtension =
if (AlfredManager.config.imageType == AlfredConstants.IMAGE_TYPE_WEBP) {
AlfredConstants.IMAGE_FILE_EXTENSION_WEBP
} else {
AlfredConstants.IMAGE_FILE_EXTENSION_JPEG
}
val fileName = currentTime.toString() + imageFileExtension
val path = fileDir.path.plus("/").plus(fileName)
val imageUrl = File(path)
val fos = FileOutputStream(imageUrl)
val videoQuality: Int =
when (AlfredManager.config.getVideoQuality()) {
VideoQuality.HIGH.name -> {
10
if (AlfredManager.config.imageType == AlfredConstants.IMAGE_TYPE_WEBP) {
bitmap?.compress(Bitmap.CompressFormat.WEBP, 0, fos)
} else {
val videoQuality: Int =
when (AlfredManager.config.getVideoQuality()) {
VideoQuality.HIGH.name -> {
10
}
VideoQuality.LOW.name -> {
6
}
VideoQuality.MEDIUM.name -> {
8
}
else -> {
10
}
}
VideoQuality.LOW.name -> {
6
}
VideoQuality.MEDIUM.name -> {
8
}
else -> {
10
}
}
bitmap?.compress(Bitmap.CompressFormat.JPEG, videoQuality, fos)
bitmap?.compress(Bitmap.CompressFormat.JPEG, videoQuality, fos)
}
fos.flush()
fos.close()
if (bottomSheetFlow == false) {
@@ -112,7 +126,10 @@ internal fun insertScreenShotPathInDb(
val screenShotDao = db.screenShotDao()
try {
screenShotDao.insertScreenShotPath(
ScreenShotPathHelper(System.currentTimeMillis(), path)
ScreenShotPathHelper(
AlfredManager.config.getAlfredCurrentTimeMillis(),
path
)
)
ScreenShotStorageHelper.addImage(path)
} catch (e: Exception) {