diff --git a/mobile/android/android-components/components/support/ktx/src/main/java/mozilla/components/support/ktx/android/content/Context.kt b/mobile/android/android-components/components/support/ktx/src/main/java/mozilla/components/support/ktx/android/content/Context.kt index 452f48e866161..75ac2ab19e7a0 100644 --- a/mobile/android/android-components/components/support/ktx/src/main/java/mozilla/components/support/ktx/android/content/Context.kt +++ b/mobile/android/android-components/components/support/ktx/src/main/java/mozilla/components/support/ktx/android/content/Context.kt @@ -80,7 +80,7 @@ fun Context.hasCamera(): Boolean { return try { val cameraManager: CameraManager? = getSystemService() cameraManager?.cameraIdList?.isNotEmpty() ?: false - } catch (e: Exception) { + } catch (_: Throwable) { false } } diff --git a/mobile/android/android-components/components/support/ktx/src/test/java/mozilla/components/support/ktx/android/content/ContextTest.kt b/mobile/android/android-components/components/support/ktx/src/test/java/mozilla/components/support/ktx/android/content/ContextTest.kt index 39d9d55f1ec95..912b1e1774307 100644 --- a/mobile/android/android-components/components/support/ktx/src/test/java/mozilla/components/support/ktx/android/content/ContextTest.kt +++ b/mobile/android/android-components/components/support/ktx/src/test/java/mozilla/components/support/ktx/android/content/ContextTest.kt @@ -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()) + } }