-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1873 from DataDog/jmoskovich/rum-2708/new-refactor
RUM-2708: Refactor and split classes
- Loading branch information
Showing
21 changed files
with
1,117 additions
and
805 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...tlin/com/datadog/android/sessionreplay/internal/recorder/resources/BitmapCachesManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
* This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
* Copyright 2016-Present Datadog, Inc. | ||
*/ | ||
|
||
package com.datadog.android.sessionreplay.internal.recorder.resources | ||
|
||
import android.content.ComponentCallbacks2 | ||
import android.content.Context | ||
import android.graphics.Bitmap | ||
import android.graphics.drawable.Drawable | ||
import androidx.annotation.MainThread | ||
import com.datadog.android.api.InternalLogger | ||
|
||
internal class BitmapCachesManager( | ||
private val resourcesLRUCache: Cache<Drawable, ByteArray>, | ||
private val bitmapPool: BitmapPool, | ||
private val logger: InternalLogger | ||
) { | ||
private var isResourcesCacheRegisteredForCallbacks: Boolean = false | ||
private var isBitmapPoolRegisteredForCallbacks: Boolean = false | ||
|
||
@MainThread | ||
internal fun registerCallbacks(applicationContext: Context) { | ||
registerResourceLruCacheForCallbacks(applicationContext) | ||
registerBitmapPoolForCallbacks(applicationContext) | ||
} | ||
|
||
@MainThread | ||
private fun registerResourceLruCacheForCallbacks(applicationContext: Context) { | ||
if (isResourcesCacheRegisteredForCallbacks) return | ||
|
||
if (resourcesLRUCache is ComponentCallbacks2) { | ||
applicationContext.registerComponentCallbacks(resourcesLRUCache) | ||
isResourcesCacheRegisteredForCallbacks = true | ||
} else { | ||
logger.log( | ||
level = InternalLogger.Level.ERROR, | ||
target = InternalLogger.Target.MAINTAINER, | ||
messageBuilder = { Cache.DOES_NOT_IMPLEMENT_COMPONENTCALLBACKS } | ||
) | ||
} | ||
} | ||
|
||
@MainThread | ||
private fun registerBitmapPoolForCallbacks(applicationContext: Context) { | ||
if (isBitmapPoolRegisteredForCallbacks) return | ||
|
||
applicationContext.registerComponentCallbacks(bitmapPool) | ||
isBitmapPoolRegisteredForCallbacks = true | ||
} | ||
|
||
internal fun putInResourceCache(drawable: Drawable, resourceId: String) { | ||
resourcesLRUCache.put(drawable, resourceId.toByteArray(Charsets.UTF_8)) | ||
} | ||
|
||
internal fun getFromResourceCache(drawable: Drawable): String? { | ||
val resourceId = resourcesLRUCache.get(drawable) ?: return null | ||
return String(resourceId, Charsets.UTF_8) | ||
} | ||
|
||
internal fun putInBitmapPool(bitmap: Bitmap) { | ||
bitmapPool.put(bitmap) | ||
} | ||
|
||
internal fun getBitmapByProperties( | ||
width: Int, | ||
height: Int, | ||
config: Bitmap.Config | ||
): Bitmap? { | ||
return bitmapPool.getBitmapByProperties(width, height, config) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
.../com/datadog/android/sessionreplay/internal/recorder/resources/ResolveResourceCallback.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
* This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
* Copyright 2016-Present Datadog, Inc. | ||
*/ | ||
|
||
package com.datadog.android.sessionreplay.internal.recorder.resources | ||
|
||
internal interface ResolveResourceCallback { | ||
fun onResolved(resourceId: String, resourceData: ByteArray) | ||
fun onFailed() | ||
} |
34 changes: 34 additions & 0 deletions
34
.../datadog/android/sessionreplay/internal/recorder/resources/ResourceItemCreationHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
* This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
* Copyright 2016-Present Datadog, Inc. | ||
*/ | ||
|
||
package com.datadog.android.sessionreplay.internal.recorder.resources | ||
|
||
import androidx.annotation.VisibleForTesting | ||
import com.datadog.android.sessionreplay.internal.async.DataQueueHandler | ||
import java.util.Collections | ||
|
||
internal class ResourceItemCreationHandler( | ||
private val recordedDataQueueHandler: DataQueueHandler, | ||
private val applicationId: String | ||
) { | ||
// resource IDs previously sent in this session - | ||
// optimization to avoid sending the same resource multiple times | ||
// atm this set is unbounded but expected to use relatively little space (~80kb per 1k items) | ||
@VisibleForTesting internal val resourceIdsSeen: MutableSet<String> = | ||
Collections.synchronizedSet(HashSet<String>()) | ||
|
||
internal fun queueItem(resourceId: String, resourceData: ByteArray) { | ||
if (!resourceIdsSeen.contains(resourceId)) { | ||
resourceIdsSeen.add(resourceId) | ||
|
||
recordedDataQueueHandler.addResourceItem( | ||
identifier = resourceId, | ||
resourceData = resourceData, | ||
applicationId = applicationId | ||
) | ||
} | ||
} | ||
} |
Oops, something went wrong.