Commit 622ca64e authored by MozLando's avatar MozLando
Browse files

Merge #8284

8284: Issue #8009: Handle all throwables in hasCamera check r=Amejia481 a=csadilek

We're seeing some devices that throw `AssertionErrors` here! 馃挴 馃う 

Let's not crash in those cases either and return false:
https://github.com/mozilla-mobile/fenix/issues/13956

Co-authored-by: default avatarChristian Sadilek <christian.sadilek@gmail.com>
parents b117c19d 762c27cb
......@@ -80,7 +80,7 @@ fun Context.hasCamera(): Boolean {
return try {
val cameraManager: CameraManager? = getSystemService()
cameraManager?.cameraIdList?.isNotEmpty() ?: false
} catch (e: Exception) {
} catch (_: Throwable) {
false
}
}
......
......@@ -31,6 +31,7 @@ import org.robolectric.Shadows.shadowOf
import org.robolectric.shadows.ShadowApplication
import org.robolectric.shadows.ShadowCameraCharacteristics
import org.robolectric.shadows.ShadowProcess
import java.lang.AssertionError
import java.lang.IllegalStateException
@RunWith(AndroidJUnit4::class)
......@@ -157,7 +158,18 @@ class ContextTest {
val context = spy(testContext)
val cameraManager: CameraManager = mock()
whenever(context.getSystemService(Context.CAMERA_SERVICE)).thenReturn(cameraManager)
whenever(cameraManager.cameraIdList).thenThrow(IllegalStateException("Test"))
assertFalse(context.hasCamera())
}
@Test
fun `hasCamera returns false if assertion is thrown`() {
val context = spy(testContext)
val cameraManager: CameraManager = mock()
whenever(context.getSystemService(Context.CAMERA_SERVICE)).thenReturn(cameraManager)
whenever(cameraManager.cameraIdList).thenThrow(AssertionError("Test"))
assertFalse(context.hasCamera())
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment