diff --git a/Corona-Warn-App/src/deviceForTesters/res/layout/fragment_test_appconfig.xml b/Corona-Warn-App/src/deviceForTesters/res/layout/fragment_test_appconfig.xml index 3ee3624e066e0db6bbea840ab21aa0498b8bf968..6727ba4838a99fcfa548f7958fb6a17381a11007 100644 --- a/Corona-Warn-App/src/deviceForTesters/res/layout/fragment_test_appconfig.xml +++ b/Corona-Warn-App/src/deviceForTesters/res/layout/fragment_test_appconfig.xml @@ -14,7 +14,7 @@ android:paddingBottom="32dp"> <LinearLayout - style="@style/card" + style="@style/Card" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="@dimen/spacing_tiny" @@ -74,7 +74,7 @@ </LinearLayout> <LinearLayout - style="@style/card" + style="@style/Card" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="@dimen/spacing_tiny" @@ -93,7 +93,7 @@ </LinearLayout> <LinearLayout - style="@style/card" + style="@style/Card" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="@dimen/spacing_tiny" @@ -109,4 +109,4 @@ </LinearLayout> </LinearLayout> -</androidx.core.widget.NestedScrollView> \ No newline at end of file +</androidx.core.widget.NestedScrollView> diff --git a/Corona-Warn-App/src/deviceForTesters/res/layout/fragment_test_contact_diary.xml b/Corona-Warn-App/src/deviceForTesters/res/layout/fragment_test_contact_diary.xml index 704e37bb51eab365abdf769250bfc4635a1bfa3b..248f44fa2b398f89f1a4a9b01e3de69116927664 100644 --- a/Corona-Warn-App/src/deviceForTesters/res/layout/fragment_test_contact_diary.xml +++ b/Corona-Warn-App/src/deviceForTesters/res/layout/fragment_test_contact_diary.xml @@ -15,7 +15,7 @@ android:paddingBottom="32dp"> <androidx.constraintlayout.widget.ConstraintLayout - style="@style/card" + style="@style/Card" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="@dimen/spacing_tiny" @@ -76,7 +76,7 @@ <androidx.constraintlayout.widget.ConstraintLayout - style="@style/card" + style="@style/Card" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="@dimen/spacing_tiny"> @@ -196,7 +196,7 @@ </androidx.constraintlayout.widget.ConstraintLayout> <androidx.constraintlayout.widget.ConstraintLayout - style="@style/card" + style="@style/Card" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="@dimen/spacing_tiny"> @@ -223,4 +223,4 @@ </androidx.constraintlayout.widget.ConstraintLayout> </LinearLayout> -</androidx.core.widget.NestedScrollView> \ No newline at end of file +</androidx.core.widget.NestedScrollView> diff --git a/Corona-Warn-App/src/deviceForTesters/res/layout/fragment_test_debugoptions.xml b/Corona-Warn-App/src/deviceForTesters/res/layout/fragment_test_debugoptions.xml index bd1eeb247b6ff2ef4c04476c71df6cdda8331671..92afdbf89c73d87c4cff4ea27b794c145db9a5c9 100644 --- a/Corona-Warn-App/src/deviceForTesters/res/layout/fragment_test_debugoptions.xml +++ b/Corona-Warn-App/src/deviceForTesters/res/layout/fragment_test_debugoptions.xml @@ -17,7 +17,7 @@ <androidx.constraintlayout.widget.ConstraintLayout android:id="@+id/debug_container" - style="@style/card" + style="@style/Card" android:layout_margin="@dimen/spacing_tiny" android:layout_width="match_parent" android:layout_height="wrap_content"> @@ -57,7 +57,7 @@ <androidx.constraintlayout.widget.ConstraintLayout android:id="@+id/environment_container" - style="@style/card" + style="@style/Card" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="@dimen/spacing_tiny"> diff --git a/Corona-Warn-App/src/deviceForTesters/res/layout/fragment_test_deviceinfo.xml b/Corona-Warn-App/src/deviceForTesters/res/layout/fragment_test_deviceinfo.xml index f7d6edb921beddf7576b23566c92329b50ee9472..4bdea42d327f82034846f46e5535f53d7f1b7af4 100644 --- a/Corona-Warn-App/src/deviceForTesters/res/layout/fragment_test_deviceinfo.xml +++ b/Corona-Warn-App/src/deviceForTesters/res/layout/fragment_test_deviceinfo.xml @@ -16,7 +16,7 @@ android:orientation="vertical"> <androidx.constraintlayout.widget.ConstraintLayout android:id="@+id/gms_container" - style="@style/card" + style="@style/Card" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="@dimen/spacing_tiny"> @@ -57,7 +57,7 @@ <androidx.constraintlayout.widget.ConstraintLayout android:id="@+id/tracing_container" - style="@style/card" + style="@style/Card" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="@dimen/spacing_tiny"> diff --git a/Corona-Warn-App/src/deviceForTesters/res/layout/fragment_test_keydownload.xml b/Corona-Warn-App/src/deviceForTesters/res/layout/fragment_test_keydownload.xml index 7c160bde79a9c55807e3402cc0fae18afca6accd..8140fa2cbc54b5dadbd4998342ed00092755ae04 100644 --- a/Corona-Warn-App/src/deviceForTesters/res/layout/fragment_test_keydownload.xml +++ b/Corona-Warn-App/src/deviceForTesters/res/layout/fragment_test_keydownload.xml @@ -15,7 +15,7 @@ android:paddingBottom="32dp"> <androidx.constraintlayout.widget.ConstraintLayout - style="@style/card" + style="@style/Card" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="@dimen/spacing_tiny" @@ -85,4 +85,4 @@ android:layout_height="match_parent" /> </LinearLayout> -</androidx.core.widget.NestedScrollView> \ No newline at end of file +</androidx.core.widget.NestedScrollView> diff --git a/Corona-Warn-App/src/deviceForTesters/res/layout/fragment_test_risk_level_calculation.xml b/Corona-Warn-App/src/deviceForTesters/res/layout/fragment_test_risk_level_calculation.xml index 53f6d063c81c02e75a511b14d16a688096eddbac..d91080a772c9a4a9c1b7b8324ab773d993999a74 100644 --- a/Corona-Warn-App/src/deviceForTesters/res/layout/fragment_test_risk_level_calculation.xml +++ b/Corona-Warn-App/src/deviceForTesters/res/layout/fragment_test_risk_level_calculation.xml @@ -16,7 +16,7 @@ <LinearLayout android:id="@+id/environment_container" - style="@style/card" + style="@style/Card" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> diff --git a/Corona-Warn-App/src/deviceForTesters/res/layout/fragment_test_submission.xml b/Corona-Warn-App/src/deviceForTesters/res/layout/fragment_test_submission.xml index e7ee015dbe4e09484590e7910a9e8df7cc2bdff2..2bcf0b827e69d49351dce960a513fc6e08de3661 100644 --- a/Corona-Warn-App/src/deviceForTesters/res/layout/fragment_test_submission.xml +++ b/Corona-Warn-App/src/deviceForTesters/res/layout/fragment_test_submission.xml @@ -15,7 +15,7 @@ android:paddingBottom="32dp"> <androidx.constraintlayout.widget.ConstraintLayout - style="@style/card" + style="@style/Card" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="@dimen/spacing_tiny" @@ -67,7 +67,7 @@ <androidx.constraintlayout.widget.ConstraintLayout android:id="@+id/tek_history" - style="@style/card" + style="@style/Card" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="@dimen/spacing_tiny"> @@ -140,4 +140,4 @@ </androidx.constraintlayout.widget.ConstraintLayout> </LinearLayout> -</androidx.core.widget.NestedScrollView> \ No newline at end of file +</androidx.core.widget.NestedScrollView> diff --git a/Corona-Warn-App/src/deviceForTesters/res/layout/fragment_test_task_controller.xml b/Corona-Warn-App/src/deviceForTesters/res/layout/fragment_test_task_controller.xml index 78caeca3b37a62175a5ee21233ffd72ce5d39e26..190f14bca25945809f47729f536dd068e7650cc1 100644 --- a/Corona-Warn-App/src/deviceForTesters/res/layout/fragment_test_task_controller.xml +++ b/Corona-Warn-App/src/deviceForTesters/res/layout/fragment_test_task_controller.xml @@ -15,7 +15,7 @@ android:orientation="vertical"> <LinearLayout - style="@style/card" + style="@style/Card" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="@dimen/spacing_tiny" @@ -40,7 +40,7 @@ </LinearLayout> <androidx.constraintlayout.widget.ConstraintLayout - style="@style/card" + style="@style/Card" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="@dimen/spacing_tiny" @@ -92,7 +92,7 @@ android:layout_height="wrap_content" /> <LinearLayout - style="@style/card" + style="@style/Card" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="@dimen/spacing_tiny" @@ -115,4 +115,4 @@ </LinearLayout> </LinearLayout> -</androidx.core.widget.NestedScrollView> \ No newline at end of file +</androidx.core.widget.NestedScrollView> diff --git a/Corona-Warn-App/src/deviceForTesters/res/layout/view_crashreport_list_item.xml b/Corona-Warn-App/src/deviceForTesters/res/layout/view_crashreport_list_item.xml index f1dac5d2ecef56a0ba2020c2b910abf063e6d5cc..a301fc4ec15a1ed76dc32162324ebe40725e5777 100644 --- a/Corona-Warn-App/src/deviceForTesters/res/layout/view_crashreport_list_item.xml +++ b/Corona-Warn-App/src/deviceForTesters/res/layout/view_crashreport_list_item.xml @@ -25,7 +25,7 @@ android:paddingBottom="2dp"> <androidx.constraintlayout.widget.ConstraintLayout - style="@style/card" + style="@style/Card" android:layout_width="390dp" android:layout_height="wrap_content" android:layout_margin="@dimen/spacing_tiny" @@ -71,4 +71,4 @@ </androidx.constraintlayout.widget.ConstraintLayout> </LinearLayout> -</layout> \ No newline at end of file +</layout> diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/util/CWADebug.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/util/CWADebug.kt index 4b959e3f8f1c67e3e60cc1ba19b0b47f610daa50..15f4ffa545e810b2f56e68134bf624d9e9a60c47 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/util/CWADebug.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/util/CWADebug.kt @@ -2,9 +2,11 @@ package de.rki.coronawarnapp.util import android.app.Application import android.os.Build +import androidx.annotation.VisibleForTesting import de.rki.coronawarnapp.BuildConfig import de.rki.coronawarnapp.bugreporting.debuglog.DebugLogger import de.rki.coronawarnapp.util.debug.FileLogger +import de.rki.coronawarnapp.util.debug.UncaughtExceptionLogger import de.rki.coronawarnapp.util.di.ApplicationComponent import timber.log.Timber @@ -21,6 +23,8 @@ object CWADebug { fileLogger = FileLogger(application) } + setupExceptionHandler() + DebugLogger.init(application) logDeviceInfos() @@ -57,4 +61,12 @@ object CWADebug { Timber.i("CWA flavor: %s (%s)", BuildConfig.FLAVOR, BuildConfig.BUILD_TYPE) Timber.i("Build.FINGERPRINT: %s", Build.FINGERPRINT) } + + /** + * Allow internal logging via `DebugLogger` to log stacktraces for uncaught exceptions. + */ + @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) + internal fun setupExceptionHandler() { + UncaughtExceptionLogger.wrapCurrentHandler() + } } diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/util/debug/UncaughtExceptionLogger.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/util/debug/UncaughtExceptionLogger.kt new file mode 100644 index 0000000000000000000000000000000000000000..a9887e63f59b9bb5d4a46bc13a98d66633147442 --- /dev/null +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/util/debug/UncaughtExceptionLogger.kt @@ -0,0 +1,23 @@ +package de.rki.coronawarnapp.util.debug + +import timber.log.Timber + +class UncaughtExceptionLogger( + private val wrappedHandler: Thread.UncaughtExceptionHandler? +) : Thread.UncaughtExceptionHandler { + + init { + Timber.v("Wrapping exception handler: %s", wrappedHandler) + } + + override fun uncaughtException(thread: Thread, error: Throwable) { + Timber.tag(thread.name).e(error, "Uncaught exception!") + wrappedHandler?.uncaughtException(thread, error) + } + + companion object { + fun wrapCurrentHandler() = UncaughtExceptionLogger(Thread.getDefaultUncaughtExceptionHandler()).also { + Thread.setDefaultUncaughtExceptionHandler(it) + } + } +} diff --git a/Corona-Warn-App/src/main/res/drawable/grey_card_ripple.xml b/Corona-Warn-App/src/main/res/drawable/grey_card_ripple.xml new file mode 100644 index 0000000000000000000000000000000000000000..cf1bad719e5d29aede7c5d50f930012ddf6ea83c --- /dev/null +++ b/Corona-Warn-App/src/main/res/drawable/grey_card_ripple.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="utf-8"?> +<ripple xmlns:android="http://schemas.android.com/apk/res/android" + android:color="?android:attr/colorControlHighlight"> + <item android:id="@android:id/mask"> + <shape android:shape="rectangle"> + <solid android:color="@color/colorSurface2Pressed" /> + <corners android:radius="@dimen/radius_card" /> + </shape> + </item> + <item> + <shape android:shape="rectangle"> + <corners android:radius="@dimen/radius_card" /> + <solid android:color="@color/colorSurface2" /> + </shape> + </item> +</ripple> diff --git a/Corona-Warn-App/src/main/res/layout/contact_diary_privacy_card.xml b/Corona-Warn-App/src/main/res/layout/contact_diary_privacy_card.xml index 5494b6376cbcc4849280fc4cb0a82d40bdf94c0b..3d9a24832fae9c75df5bab8289d225ef167001c7 100644 --- a/Corona-Warn-App/src/main/res/layout/contact_diary_privacy_card.xml +++ b/Corona-Warn-App/src/main/res/layout/contact_diary_privacy_card.xml @@ -4,7 +4,7 @@ <androidx.constraintlayout.widget.ConstraintLayout android:id="@+id/contact_diary_privacy_card" - style="@style/cardGrey" + style="@style/GreyCard" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="@dimen/spacing_normal" diff --git a/Corona-Warn-App/src/main/res/layout/fragment_submission_dispatcher.xml b/Corona-Warn-App/src/main/res/layout/fragment_submission_dispatcher.xml index 186e1d64d369380f89004207a9f5fad4df1f1ba5..218e142611efdb45c2ea6b7d148b98c8e324f838 100644 --- a/Corona-Warn-App/src/main/res/layout/fragment_submission_dispatcher.xml +++ b/Corona-Warn-App/src/main/res/layout/fragment_submission_dispatcher.xml @@ -85,7 +85,6 @@ app:layout_constraintStart_toStartOf="@+id/guideline_card_start" app:layout_constraintTop_toBottomOf="@+id/submission_dispatcher_needs_testing_text" /> - <TextView android:id="@+id/submission_dispatcher_already_positive_text" style="@style/headline6" diff --git a/Corona-Warn-App/src/main/res/layout/include_16_years.xml b/Corona-Warn-App/src/main/res/layout/include_16_years.xml index 005f767b150f8402339ff512583f5dff2cd10659..1019f8d929de461f53a8e6b2c0620798c8695411 100644 --- a/Corona-Warn-App/src/main/res/layout/include_16_years.xml +++ b/Corona-Warn-App/src/main/res/layout/include_16_years.xml @@ -4,7 +4,7 @@ <androidx.constraintlayout.widget.ConstraintLayout android:id="@+id/sixteen_years" - style="@style/card" + style="@style/Card" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="@dimen/spacing_small" @@ -40,4 +40,4 @@ app:layout_constraintTop_toBottomOf="@+id/sixteen_years_headline" /> </androidx.constraintlayout.widget.ConstraintLayout> -</layout> \ No newline at end of file +</layout> diff --git a/Corona-Warn-App/src/main/res/layout/include_dispatcher_card.xml b/Corona-Warn-App/src/main/res/layout/include_dispatcher_card.xml index 8c05e3387ddfc17261b839fd3d34e496073a851d..c5da5315daa951ae9073dc4b5a3cc783e98efd00 100644 --- a/Corona-Warn-App/src/main/res/layout/include_dispatcher_card.xml +++ b/Corona-Warn-App/src/main/res/layout/include_dispatcher_card.xml @@ -22,8 +22,7 @@ <androidx.constraintlayout.widget.ConstraintLayout android:id="@+id/dispatcher_card" - style="@style/cardGrey" - android:foreground="?selectableItemBackground" + style="@style/GreyCard.Ripple" android:layout_width="match_parent" android:layout_height="wrap_content" android:focusable="true" diff --git a/Corona-Warn-App/src/main/res/layout/include_privacy_card.xml b/Corona-Warn-App/src/main/res/layout/include_privacy_card.xml index 7b45ae30428ef6ebd4e85867e854b3978f41421b..b9679f833f9347aa22194713154f9af69daf63c9 100644 --- a/Corona-Warn-App/src/main/res/layout/include_privacy_card.xml +++ b/Corona-Warn-App/src/main/res/layout/include_privacy_card.xml @@ -4,7 +4,7 @@ <androidx.constraintlayout.widget.ConstraintLayout android:id="@+id/privacy_card" - style="@style/cardGrey" + style="@style/GreyCard" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="@dimen/spacing_normal" @@ -35,4 +35,4 @@ app:layout_constraintTop_toBottomOf="@+id/privacy_card_title" /> </androidx.constraintlayout.widget.ConstraintLayout> -</layout> \ No newline at end of file +</layout> diff --git a/Corona-Warn-App/src/main/res/layout/include_privacy_card_no_consent.xml b/Corona-Warn-App/src/main/res/layout/include_privacy_card_no_consent.xml index caba912eba6ec348434a0ed5f7ad1ad6451c9d92..7fc07916734d6ca6c76ced7e8e78bd562b21bded 100644 --- a/Corona-Warn-App/src/main/res/layout/include_privacy_card_no_consent.xml +++ b/Corona-Warn-App/src/main/res/layout/include_privacy_card_no_consent.xml @@ -4,7 +4,7 @@ <androidx.constraintlayout.widget.ConstraintLayout android:id="@+id/privacy_card" - style="@style/cardGrey" + style="@style/GreyCard" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="@dimen/spacing_normal" @@ -61,4 +61,4 @@ </androidx.constraintlayout.widget.ConstraintLayout> -</layout> \ No newline at end of file +</layout> diff --git a/Corona-Warn-App/src/main/res/layout/include_submission_consent_body.xml b/Corona-Warn-App/src/main/res/layout/include_submission_consent_body.xml index 1923dfa1812b0c7c427bb0bd360258a5081ae878..1575d3be951000b21f4c356737e595b72a1d397e 100644 --- a/Corona-Warn-App/src/main/res/layout/include_submission_consent_body.xml +++ b/Corona-Warn-App/src/main/res/layout/include_submission_consent_body.xml @@ -16,7 +16,7 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="@id/submission_consent_your_consent_subsection_headline" app:layout_constraintBottom_toBottomOf="@id/submission_consent_your_consent_subsection_third_point" - style="@style/cardGrey" /> + style="@style/GreyCard" /> <TextView android:id="@+id/submission_consent_your_consent_subsection_headline" diff --git a/Corona-Warn-App/src/main/res/layout/include_submission_country_no_selection.xml b/Corona-Warn-App/src/main/res/layout/include_submission_country_no_selection.xml index d091312130aa876230d07a49e6aa47a938a36853..f1738b390fb565cf7ed7d23029862877c22bb6b8 100644 --- a/Corona-Warn-App/src/main/res/layout/include_submission_country_no_selection.xml +++ b/Corona-Warn-App/src/main/res/layout/include_submission_country_no_selection.xml @@ -13,7 +13,7 @@ <androidx.constraintlayout.widget.ConstraintLayout android:id="@+id/submission_country_no_selection_container" - style="@style/cardGrey" + style="@style/GreyCard" android:layout_width="match_parent" android:layout_height="wrap_content" android:backgroundTint="@{FormatterSubmissionHelper.formatCountrySelectCardColor(active)}" @@ -36,4 +36,4 @@ <include layout="@layout/merge_guidelines_side" /> </androidx.constraintlayout.widget.ConstraintLayout> -</layout> \ No newline at end of file +</layout> diff --git a/Corona-Warn-App/src/main/res/layout/include_submission_country_selector.xml b/Corona-Warn-App/src/main/res/layout/include_submission_country_selector.xml index b6ad8ae72f26f168cfdf4a2826a75188b13d24ca..b083159cb27e52665c8df74144c4c52e73cf5393 100644 --- a/Corona-Warn-App/src/main/res/layout/include_submission_country_selector.xml +++ b/Corona-Warn-App/src/main/res/layout/include_submission_country_selector.xml @@ -21,7 +21,7 @@ </data> <androidx.constraintlayout.widget.ConstraintLayout - style="@style/cardGrey" + style="@style/GreyCard" android:layout_width="match_parent" android:layout_height="wrap_content" android:backgroundTint="@{FormatterSubmissionHelper.formatCountrySelectCardColor(active)}" @@ -58,4 +58,4 @@ <include layout="@layout/merge_guidelines_side" /> </androidx.constraintlayout.widget.ConstraintLayout> -</layout> \ No newline at end of file +</layout> diff --git a/Corona-Warn-App/src/main/res/values/styles.xml b/Corona-Warn-App/src/main/res/values/styles.xml index c275b3fc175fd007c6c640d0476254bf5a05f509..e1dfb49017256d8bdfeaf777a9b0d3037b4498aa 100644 --- a/Corona-Warn-App/src/main/res/values/styles.xml +++ b/Corona-Warn-App/src/main/res/values/styles.xml @@ -175,16 +175,26 @@ <!-- #################################### Card ###################################### --> - <style name="card"> + <style name="Card"> <item name="android:padding">@dimen/card_padding</item> <item name="android:background">@drawable/card</item> <item name="android:elevation">@dimen/elevation_strong</item> </style> - <style name="cardNoPadding" parent="card"> + <style name="Card.NoPadding"> <item name="android:padding">@dimen/no_padding</item> </style> + <style name="GreyCard" parent="Card.NoPadding"> + <item name="android:tint">@color/card_dark</item> + <item name="android:elevation">0dp</item> + <item name="android:backgroundTint">@color/colorSurface2</item> + </style> + + <style name="GreyCard.Ripple"> + <item name="android:background">@drawable/grey_card_ripple</item> + </style> + <style name="cardTracing"> <item name="android:padding">@dimen/card_padding</item> <item name="android:background">@drawable/card</item> @@ -208,12 +218,6 @@ <item name="android:background">@drawable/card</item> </style> - <style name="cardGrey" parent="cardNoPadding"> - <item name="android:tint">@color/card_dark</item> - <item name="android:elevation">0dp</item> - <item name="android:backgroundTint">@color/colorSurface2</item> - </style> - <!-- #################################### Grey Body Background ###################################### --> diff --git a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/util/debug/UncaughtExceptionLoggerTest.kt b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/util/debug/UncaughtExceptionLoggerTest.kt new file mode 100644 index 0000000000000000000000000000000000000000..bc8edc659f6d6178b5b84b73397ed4404bff0ce0 --- /dev/null +++ b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/util/debug/UncaughtExceptionLoggerTest.kt @@ -0,0 +1,63 @@ +package de.rki.coronawarnapp.util.debug + +import io.kotest.matchers.shouldBe +import io.mockk.Runs +import io.mockk.every +import io.mockk.just +import io.mockk.mockk +import io.mockk.verify +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +import testhelpers.BaseTest + +class UncaughtExceptionLoggerTest : BaseTest() { + + var originalHandler: Thread.UncaughtExceptionHandler? = null + + @BeforeEach + fun setup() { + originalHandler = Thread.getDefaultUncaughtExceptionHandler() + } + + @AfterEach + fun teardown() { + Thread.setDefaultUncaughtExceptionHandler(originalHandler) + } + + @Test + fun `we wrap and call through to the original handler`() { + val wrappedHandler = mockk<Thread.UncaughtExceptionHandler>() + every { wrappedHandler.uncaughtException(any(), any()) } just Runs + + val instance = UncaughtExceptionLogger(wrappedHandler) + val testException = NotImplementedError() + instance.uncaughtException(Thread.currentThread(), testException) + + verify { wrappedHandler.uncaughtException(Thread.currentThread(), testException) } + } + + @Test + fun `auto setup replaces the current handler`() { + val wrappedHandler = mockk<Thread.UncaughtExceptionHandler>() + every { wrappedHandler.uncaughtException(any(), any()) } just Runs + + Thread.setDefaultUncaughtExceptionHandler(wrappedHandler) + Thread.getDefaultUncaughtExceptionHandler() shouldBe wrappedHandler + + val ourHandler = UncaughtExceptionLogger.wrapCurrentHandler() + Thread.getDefaultUncaughtExceptionHandler() shouldBe ourHandler + } + + @Test + fun `null handlers would be okay`() { + Thread.setDefaultUncaughtExceptionHandler(null) + Thread.getDefaultUncaughtExceptionHandler() shouldBe null + + val ourHandler = UncaughtExceptionLogger.wrapCurrentHandler() + Thread.getDefaultUncaughtExceptionHandler() shouldBe ourHandler + + val instance = UncaughtExceptionLogger(null) + instance.uncaughtException(Thread.currentThread(), NotImplementedError()) + } +}