Skip to content

Commit

Permalink
chore: enable penalty death on strict mode (#2251)
Browse files Browse the repository at this point in the history
Co-authored-by: Alexandre Ferris <[email protected]>
  • Loading branch information
ohassine and alexandreferris authored Sep 21, 2023
1 parent 13d5576 commit 1277cd7
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 21 deletions.
39 changes: 20 additions & 19 deletions app/src/main/kotlin/com/wire/android/WireApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -106,24 +106,24 @@ class WireApplication : Application(), Configuration.Provider {
}

private fun enableStrictMode() {
if (!BuildConfig.DEBUG) return

StrictMode.setThreadPolicy(
StrictMode.ThreadPolicy.Builder()
.detectDiskReads()
.detectDiskWrites()
.penaltyLog()
// .penaltyDeath() TODO: add it later after fixing reported violations
.build()
)
StrictMode.setVmPolicy(
StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects()
.detectLeakedClosableObjects()
.penaltyLog()
// .penaltyDeath() TODO: add it later after fixing reported violations
.build()
)
if (BuildConfig.DEBUG) {
StrictMode.setThreadPolicy(
StrictMode.ThreadPolicy.Builder()
.detectDiskReads()
.detectDiskWrites()
.penaltyLog()
.penaltyDeath()
.build()
)
StrictMode.setVmPolicy(
StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects()
.detectLeakedClosableObjects()
.penaltyLog()
// .penaltyDeath() TODO: add it later after fixing reported violations
.build()
)
}
}

private fun initializeApplicationLoggingFrameworks() {
Expand Down Expand Up @@ -199,7 +199,8 @@ class WireApplication : Application(), Configuration.Provider {
TRIM_MEMORY_UNKNOWN(-1);

companion object {
fun byLevel(value: Int) = values().firstOrNull { it.level == value } ?: TRIM_MEMORY_UNKNOWN
fun byLevel(value: Int) =
values().firstOrNull { it.level == value } ?: TRIM_MEMORY_UNKNOWN
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

package com.wire.android.ui.common.imagepreview

import android.graphics.Bitmap
import android.net.Uri
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
Expand All @@ -29,6 +30,9 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
import androidx.compose.runtime.produceState
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.geometry.toRect
Expand All @@ -44,6 +48,19 @@ import androidx.constraintlayout.compose.ConstraintLayout
import coil.compose.rememberAsyncImagePainter
import com.wire.android.ui.common.dimensions
import com.wire.android.util.toBitmap
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

@Composable
private fun loadBitMap(imageUri: Uri): State<Bitmap?> {
val coroutineScope = rememberCoroutineScope()
val context = LocalContext.current
return produceState<Bitmap?>(initialValue = null, imageUri) {
coroutineScope.launch(Dispatchers.IO) {
value = imageUri.toBitmap(context)
}
}
}

@Composable
fun BulletHoleImagePreview(
Expand All @@ -67,7 +84,7 @@ fun BulletHoleImagePreview(
}
) {
Image(
painter = rememberAsyncImagePainter(imageUri.toBitmap(LocalContext.current)),
painter = rememberAsyncImagePainter(loadBitMap(imageUri).value),
contentScale = ContentScale.Crop,
contentDescription = contentDescription,
modifier = Modifier.fillMaxSize(),
Expand Down Expand Up @@ -97,7 +114,11 @@ fun BulletHoleImagePreview(
@Suppress("MagicNumber")
class BulletHoleShape : Shape {

override fun createOutline(size: Size, layoutDirection: LayoutDirection, density: Density): Outline {
override fun createOutline(
size: Size,
layoutDirection: LayoutDirection,
density: Density
): Outline {
return Outline.Generic(
drawBulletHolePath(size)
)
Expand Down

0 comments on commit 1277cd7

Please sign in to comment.