Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: enable penalty death on strict mode #2251

Merged
merged 4 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just out of curiosity, what's the VM policy for? emulators or images run in CI??

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No no nothing related to CI..We are just setting in Virtual Machine what actions should be detected.

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
Loading