forrestguice / SuntimesWidget

Android app (and widget collection) that displays sunlight and moonlight times.
GNU General Public License v3.0
348 stars 61 forks source link

Compatibility issue when calling method #620

Closed PSDroid2022 closed 2 years ago

PSDroid2022 commented 2 years ago

We confirm a compatibility issue which might threaten the robustness of your app and give a detailed suggestion for you.

In ''com.forrestguice.suntimeswidget.alarmclock.ui.AlarmClockActivity", you invoke the API "<android.view.View: void setBackgroundTintList(android.content.res.ColorStateList)>" in "initViews" method as shown in following. But actually, this API is introduced in API level 21( https://developer.android.google.cn/reference/android/view/View?hl=en#setBackgroundTintList(android.content.res.ColorStateList)).

protected void initViews(Context context)
    {
...

        if (Build.VERSION.SDK_INT <= 19) {    // override ripple fallback
            addButton.setBackgroundTintList(SuntimesUtils.colorStateList(colorAlarmEnabled, colorDisabled, colorPressed));
            addButton.setRippleColor(Color.TRANSPARENT);
        }

...
    }

So when the app try to invoke this API on devices after API level 16~19, your app will run with an unpredictable results. So we suggest you add an "if(SDK_INT >=21)" to fix this potential issue.

Android device

forrestguice commented 2 years ago

Are you certain? addButton is a FloatingActionButton(https://developer.android.com/reference/android/support/design/widget/FloatingActionButton.html) from the support library, not just just some View. The main point of using these support library classes is that they provide backward compatibility for older devices.

Problems like these are typically detected at release time. The app cannot be built without completing lintVitalRelease, which will fail with the message "NewAPI". Furthermore, these lines are regularly tested and no problem is detected; my primary test device runs api19.

What method are you using to find these problems? It seems like maybe a false positive, but I'd like to better understand.

PSDroid2022 commented 2 years ago

1.It seems that FloatingActionButton.setBackgroundTintList(@Nullable ColorStateList tint) no longer changes background color because of issues ( https://code.google.com/p/android/issues/detail?id=201873). (https://stackoverflow.com/questions/31662907/setting-the-background-color-of-floatingactionbutton-with-setbackgroundtintlist)

  1. It seems that using "ViewCompat.setBackgroundTintList(button, tint)" is a much better choice before API 19. ( https://stackoverflow.com/questions/33638873/android-setbackgroundtintlist-on-pre-lollipop-devices)
forrestguice commented 2 years ago

I do understand there is a bug and that the function no longer works on newer devices.. However look at the quoted code; its a cludge that is only run for api <= 19. Those lines are working as intended. I don't see any reason to be chasing non-existent issues.

PSDroid2022 commented 2 years ago

Ok, I understand , and it will be dead codes since it no longer works.