home-assistant / android

:iphone: Home Assistant Companion for Android
https://companion.home-assistant.io/
Apache License 2.0
2.3k stars 636 forks source link

WearOS: Application crashes on startup #2090

Closed vveloso closed 2 years ago

vveloso commented 2 years ago

Home Assistant Android version: 2021.12.3

Android version: 10

Android Wear version: 2.35.0.325323493

Phone model: Huawei P20 Pro

Watch model: LG Watch Urbane

Home Assistant version: 2021.12.7

Last working Home Assistant release (if known): n/a

Description of problem: Android Wear application crashes on launch. Does not get past the splash screen.

Traceback (if applicable, to get the logs you may refer to: https://companion.home-assistant.io/docs/troubleshooting/faqs/#android-crash-logs):

2021-12-30 13:05:26.697 15075-15075/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: io.homeassistant.companion.android, PID: 15075
    java.lang.NumberFormatException: For input string: "public int android.view.ViewConfiguration.getScaledScrollFactor()"
        at java.lang.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1306)
        at java.lang.Float.parseFloat(Float.java:459)
        at io.homeassistant.companion.android.util.RotaryEventDispatcherKt$scrollHandler$1.invoke(RotaryEventDispatcher.kt:29)
        at io.homeassistant.companion.android.util.RotaryEventDispatcherKt$scrollHandler$1.invoke(RotaryEventDispatcher.kt:21)

Full logs: ha-wearos-crash.log

Screenshot of problem: n/a

Additional information:

The Android Wear application was fully configured using the Home Assistant Android application on the phone because my installation uses MFA.

The Home Assistant installation is still in its infancy. Only one light is configured there.

dshokouhi commented 2 years ago

hmm does this watch have a bezel?

vveloso commented 2 years ago

The watch does not have a working/rotary bezel if that's what you mean. See: https://www.lg.com/us/smart-watches/lg-W150-lg-watch-urbane

Daniel Shokouhi @.***> escreveu no dia quinta, 30/12/2021 à(s) 20:21:

hmm does this watch have a bezel?

— Reply to this email directly, view it on GitHub https://github.com/home-assistant/android/issues/2090#issuecomment-1003153005, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGCLQ2RFRR2WPBLNX2AFNLUTSWLJANCNFSM5K7UEPSQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

dshokouhi commented 2 years ago

yup thats what I meant, thanks for the logs :)

dshokouhi commented 2 years ago

if you are willing and able to could you test the debug Wear APK from here?

https://github.com/home-assistant/android/actions/runs/1638577350

just make sure the app doesnt crash and no weird scrolling behavior :) it will install side by side the production version and wont impact it (even if its non-functional in its current state)

vveloso commented 2 years ago

Thank you @dshokouhi. I installed the debug version and can confirm that it started and presented the option to configure an instance. Scrolling behavior looked fine to me.

vveloso commented 2 years ago

One more thing @dshokouhi: I looked at #2092 and it looks like the call to invoke() on the Method instance returned by getDeclaredMethod() is missing. toString() is invoked directly on the Method instance, which will never produce the float value you're looking for.

Take a look at the implementation of ViewConfigurationCompat for an example.

Maybe it is a good idea to use ViewConfigurationCompat::getScaledVerticalScrollFactor instead? 😉

dshokouhi commented 2 years ago

One more thing @dshokouhi: I looked at #2092 and it looks like the call to invoke() on the Method instance returned by getDeclaredMethod() is missing. toString() is invoked directly on the Method instance, which will never produce the float value you're looking for.

Take a look at the implementation of ViewConfigurationCompat for an example.

Maybe it is a good idea to use ViewConfigurationCompat::getScaledVerticalScrollFactor instead? 😉

Many people are using this current workaround while we wait for Google to add native rotary support. As of now this is just temporary and we are even using Google's recommendation here. If you feel it's better feel free to submit a PR, we are open source. For those of us with working bezels the code is working for us as is.

vveloso commented 2 years ago

The root cause is not about rotary bezels, feelings, or whether it is better or worse. It's really a backward compatibility issue.

The vertical scrolling factor reading code, as it is written today, does not work with older Android/Wear versions because the Java reflection API is being used incorrectly. The mistake is easy to overlook but also easy to fix.

I'll submit a PR next week.

Happy new year.

A sexta, 31 de dez de 2021, 17:20, Daniel Shokouhi @.***> escreveu:

One more thing @dshokouhi https://github.com/dshokouhi: I looked at

2092 https://github.com/home-assistant/android/pull/2092 and it looks

like the call to invoke() on the Method instance returned by getDeclaredMethod() https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#getDeclaredMethod-java.lang.String-java.lang.Class...- is missing. toString() is invoked directly on the Method instance, which will never produce the float value you're looking for.

Take a look at the implementation of ViewConfigurationCompat https://android.googlesource.com/platform/frameworks/support/+/refs/heads/oreo-dev/compat/java/android/support/v4/view/ViewConfigurationCompat.java for an example.

Maybe it is a good idea to use ViewConfigurationCompat::getScaledVerticalScrollFactor https://developer.android.com/reference/androidx/core/view/ViewConfigurationCompat#getScaledVerticalScrollFactor(android.view.ViewConfiguration,%20android.content.Context) instead? 😉

Many people are using this current workaround while we wait for Google to add native rotary support. As of now this is just temporary and we are even using Google's recommendation here. If you feel it's better feel free to submit a PR, we are open source. For those of us with working bezels the code is working for us as is.

— Reply to this email directly, view it on GitHub https://github.com/home-assistant/android/issues/2090#issuecomment-1003411509, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGCLQ4JNILAZSIQW5LPE6LUTXJ5LANCNFSM5K7UEPSQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>