Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@ private fun getModalHostSize(activity: Activity): Point {
val attrs = intArrayOf(android.R.attr.windowFullscreen)
val theme = activity.theme
val ta = theme.obtainStyledAttributes(attrs)
val windowFullscreen = ta.getBoolean(0, false)
val windowFullscreen = try {
ta.getBoolean(0, false)
} finally {
ta.recycle()
}

// We need to add the status bar height to the height if we have a fullscreen window,
// because Display.getCurrentSizeRange doesn't include it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,15 @@ open class ImageLoader {
@Throws(IOException::class)
private fun readJsDevImage(context: Context, source: String): Drawable {
val threadPolicy = adjustThreadPolicyDebug(context)
val `is` = openStream(context, source)
val bitmap = BitmapFactory.decodeStream(`is`)
restoreThreadPolicyDebug(context, threadPolicy)
return BitmapDrawable(context.resources, bitmap)
try {
val stream = openStream(context, source)
?: throw FileNotFoundException("Could not open image $source")
val bitmap = stream.use(BitmapFactory::decodeStream)
?: throw IOException("Could not decode image $source")
return BitmapDrawable(context.resources, bitmap)
} finally {
restoreThreadPolicyDebug(context, threadPolicy)
}
}

private fun isLocalFile(uri: Uri): Boolean {
Expand Down Expand Up @@ -128,4 +133,4 @@ open class ImageLoader {
return context.contentResolver.openInputStream(Uri.parse(uri))
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.reactnativenavigation.utils

import android.os.StrictMode
import com.reactnativenavigation.BaseTest
import org.junit.Assert.assertEquals
import org.junit.Test
import org.mockito.kotlin.mock

class ImageLoaderTest : BaseTest() {
@Test
fun failedDevImageLoadRestoresThreadPolicy() {
val originalPolicy = StrictMode.ThreadPolicy.Builder()
.detectNetwork()
.penaltyLog()
.build()
StrictMode.setThreadPolicy(originalPolicy)

ImageLoader().loadIcon(
newActivity(),
"content://missing/image",
mock<ImageLoader.ImagesLoadingListener>()
)

assertEquals(originalPolicy.toString(), StrictMode.getThreadPolicy().toString())
}
}