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

[Bug] The "Notifications" of "Developer Settings" lead to crash, is it normal? #5563

Open
Kobayashi-996 opened this issue Jan 30, 2025 · 3 comments

Comments

@Kobayashi-996
Copy link

Describe the bug

Click this setting and the app crash.

FATAL EXCEPTION: main
Process: com.duckduckgo.mobile.android.debug, PID: 7644
android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:226)
at android.content.res.Resources.getColor(Resources.java:1068)
at android.content.Context.getColor(Context.java:794)
at androidx.core.content.ContextCompat$Api23Impl.getColor(ContextCompat.java:1071)
at androidx.core.content.ContextCompat.getColor(ContextCompat.java:529)
at com.duckduckgo.app.notification.NotificationFactory.createNotification(NotificationFactory.kt:44)
at com.duckduckgo.app.dev.settings.notifications.NotificationViewModel$1.invokeSuspend(NotificationsViewModel.kt:96)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7872)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelled}@6b057af, Dispatchers.Main.immediate]

How to Reproduce

  1. Enter the app
  2. More Options
  3. Settings
  4. Developers Settings
  5. Notifications
    --> Crash
Screen_recording_20250131_000517.online-video-cutter.com.mp4

Expected behavior

Is this behavior normal?

Environment

- DDG App Version: 5.224.0
- Device: Pixel 2 / Pixel 8 pro
- OS: Android 9 / Android 13
Copy link
Contributor

Thank you for opening an Issue in our Repository.
The issue has been forwarded to the team and we'll follow up as soon as we have time to investigate.
As stated in our Contribution Guidelines, requests for feedback should be addressed via the Feedback section in the Android app.

@berk-berber
Copy link

Hello,

This issue arises because @ColorInt is being retrieved using ContextCompat.getColor(), which expects a @ColorRes reference rather than a resolved color integer.

In the ClearDataSpecification class, @ColorInt is already assigned using the following logic, ensuring that the value returned is a direct color integer. However, in the NotificationFactory class, the color is being accessed as if it were a @ColorRes, leading to an incorrect conversion attempt.

Instead of resolving the color again, the existing @ColorInt value can be used directly. The function below retrieves the resolved color integer from an attribute and can be utilized as needed:

@ColorInt
fun Context.getColorFromAttr(
    @AttrRes attrColor: Int,
    typedValue: TypedValue = TypedValue(),
    resolveRefs: Boolean = true,
): Int {
    theme.resolveAttribute(attrColor, typedValue, resolveRefs)
    return typedValue.data
}

By using this approach, we can ensure that colors are correctly handled without redundant lookups or mismatches between @ColorInt and @ColorRes.

@Yair202521
Copy link

U

@Yair202521 Yair202521 mentioned this issue Feb 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants