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

Android - Crash on bluetooth keyboard device connection and disconnection #15903

Closed
ArchangelJTW opened this issue Jun 3, 2024 · 6 comments
Closed

Comments

@ArchangelJTW
Copy link

Describe the bug

App crashes if bluetooth keyboard device is connected or disconnected while it is open.

To Reproduce

Connect or disconnect a bluetooth keyboard device to an Android device with an Avalonia Android App open.

Expected behavior

Avalonia should be able to handle any changes in input on mobile during runtime, such as a bluetooth keyboard being connected or disconnected.

Avalonia version

11.1.0-beta2

OS

Android

Additional context

I'm developing an app that uses a barcode scanner. Barcode scanners for those who don't know typically, and in this case, just function as keyboards (Android even detects it as if it's a keyboard). This one is connected through bluetooth.

If the app is running and the bluetooth scanner is connected or disconnected the app crashes,

I have not been able to get any useful debugging information as of yet.

@maxkatz6
Copy link
Member

maxkatz6 commented Jun 5, 2024

Can you attach any logs related to the crash? Collected from the app or from the logcat.

@ArchangelJTW
Copy link
Author

Can you attach any logs related to the crash? Collected from the app or from the logcat.

I got everything I could from logcat, I see some Avalonia related logs but also included some of the surrounding logs. There appears to be several Avalonia errors related to buffers and window management.

logcat_approx_crash_log.txt

@ArchangelJTW
Copy link
Author

ArchangelJTW commented Jun 10, 2024

@maxkatz6 I've acquired a more useful stack trace through some logging I setup here:

Click To Expand

[6/10/2024 11:35:05 AM] System.NotSupportedException: Unable to activate instance of type Avalonia.Android.AvaloniaView from native handle 0x7fd3a7c794 (key_handle 0x94ae78f).
 ---> System.MissingMethodException: No constructor found for Avalonia.Android.AvaloniaView::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership)
 ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown.
Java.Lang.Error: Exception of type 'Java.Lang.Error' was thrown.

  --- End of managed Java.Lang.Error stack trace ---
java.lang.Error: Java callstack:
    at crc6431345fe65afe8d98.AvaloniaView.n_onVisibilityAggregated(Native Method)
    at crc6431345fe65afe8d98.AvaloniaView.onVisibilityAggregated(AvaloniaView.java:68)
    at android.view.View.dispatchDetachedFromWindow(View.java:18460)
    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3837)
    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3829)
    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3829)
    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3829)
    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3829)
    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3829)
    at android.view.ViewRootImpl.dispatchDetachedFromWindow(ViewRootImpl.java:3975)
    at android.view.ViewRootImpl.doDie(ViewRootImpl.java:6985)
    at android.view.ViewRootImpl.die(ViewRootImpl.java:6958)
    at android.view.WindowManagerGlobal.removeViewLocked(WindowManagerGlobal.java:458)
    at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:396)
    at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:124)
    at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4532)
    at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:4794)
    at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4727)
    at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:69)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1839)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6714)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:503)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911)

  --- End of managed Java.Lang.Error stack trace ---
java.lang.Error: Java callstack:
    at crc6431345fe65afe8d98.AvaloniaView.n_onVisibilityAggregated(Native Method)
    at crc6431345fe65afe8d98.AvaloniaView.onVisibilityAggregated(AvaloniaView.java:68)
    at android.view.View.dispatchDetachedFromWindow(View.java:18460)
    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3837)
    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3829)
    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3829)
    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3829)
    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3829)
    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3829)
    at android.view.ViewRootImpl.dispatchDetachedFromWindow(ViewRootImpl.java:3975)
    at android.view.ViewRootImpl.doDie(ViewRootImpl.java:6985)
    at android.view.ViewRootImpl.die(ViewRootImpl.java:6958)
    at android.view.WindowManagerGlobal.removeViewLocked(WindowManagerGlobal.java:458)
    at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:396)
    at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:124)
    at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4532)
    at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:4794)
    at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4727)
    at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:69)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1839)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6714)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:503)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911)

   --- End of inner exception stack trace ---
   at Java.Interop.TypeManager.CreateProxy(Type type, IntPtr handle, JniHandleOwnership transfer)
   at Java.Interop.TypeManager.CreateInstance(IntPtr handle, JniHandleOwnership transfer, Type targetType)
   --- End of inner exception stack trace ---
   at Java.Interop.TypeManager.CreateInstance(IntPtr handle, JniHandleOwnership transfer, Type targetType)
   at Java.Lang.Object.GetObject(IntPtr handle, JniHandleOwnership transfer, Type type)
   at Java.Lang.Object._GetObject[View](IntPtr handle, JniHandleOwnership transfer)
   at Android.Runtime.DynamicMethodNameCounter.2(IntPtr , IntPtr , Boolean )
[6/10/2024 11:40:13 AM] System.NotSupportedException: Unable to activate instance of type Avalonia.Android.AvaloniaView from native handle 0x7fd3a7c794 (key_handle 0x94ae78f).
 ---> System.MissingMethodException: No constructor found for Avalonia.Android.AvaloniaView::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership)
 ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown.
Java.Lang.Error: Exception of type 'Java.Lang.Error' was thrown.

  --- End of managed Java.Lang.Error stack trace ---
java.lang.Error: Java callstack:
    at crc6431345fe65afe8d98.AvaloniaView.n_onVisibilityAggregated(Native Method)
    at crc6431345fe65afe8d98.AvaloniaView.onVisibilityAggregated(AvaloniaView.java:68)
    at android.view.View.dispatchDetachedFromWindow(View.java:18460)
    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3837)
    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3829)
    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3829)
    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3829)
    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3829)
    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3829)
    at android.view.ViewRootImpl.dispatchDetachedFromWindow(ViewRootImpl.java:3975)
    at android.view.ViewRootImpl.doDie(ViewRootImpl.java:6985)
    at android.view.ViewRootImpl.die(ViewRootImpl.java:6958)
    at android.view.WindowManagerGlobal.removeViewLocked(WindowManagerGlobal.java:458)
    at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:396)
    at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:124)
    at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4532)
    at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:4794)
    at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4727)
    at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:69)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1839)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6714)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:503)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911)

  --- End of managed Java.Lang.Error stack trace ---
java.lang.Error: Java callstack:
    at crc6431345fe65afe8d98.AvaloniaView.n_onVisibilityAggregated(Native Method)
    at crc6431345fe65afe8d98.AvaloniaView.onVisibilityAggregated(AvaloniaView.java:68)
    at android.view.View.dispatchDetachedFromWindow(View.java:18460)
    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3837)
    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3829)
    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3829)
    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3829)
    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3829)
    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3829)
    at android.view.ViewRootImpl.dispatchDetachedFromWindow(ViewRootImpl.java:3975)
    at android.view.ViewRootImpl.doDie(ViewRootImpl.java:6985)
    at android.view.ViewRootImpl.die(ViewRootImpl.java:6958)
    at android.view.WindowManagerGlobal.removeViewLocked(WindowManagerGlobal.java:458)
    at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:396)
    at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:124)
    at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4532)
    at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:4794)
    at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4727)
    at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:69)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1839)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6714)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:503)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911)

   --- End of inner exception stack trace ---
   at Java.Interop.TypeManager.CreateProxy(Type type, IntPtr handle, JniHandleOwnership transfer)
   at Java.Interop.TypeManager.CreateInstance(IntPtr handle, JniHandleOwnership transfer, Type targetType)
   --- End of inner exception stack trace ---
   at Java.Interop.TypeManager.CreateInstance(IntPtr handle, JniHandleOwnership transfer, Type targetType)
   at Java.Lang.Object.GetObject(IntPtr handle, JniHandleOwnership transfer, Type type)
   at Java.Lang.Object._GetObject[View](IntPtr handle, JniHandleOwnership transfer)
   at Android.Runtime.DynamicMethodNameCounter.2(IntPtr , IntPtr , Boolean )
[6/10/2024 12:00:59 PM] System.NotSupportedException: Unable to activate instance of type Avalonia.Android.AvaloniaView from native handle 0x7fd3a7c834 (key_handle 0xf0c5a1c).
 ---> System.MissingMethodException: No constructor found for Avalonia.Android.AvaloniaView::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership)
 ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown.
Java.Lang.Error: Exception of type 'Java.Lang.Error' was thrown.

  --- End of managed Java.Lang.Error stack trace ---
java.lang.Error: Java callstack:
    at crc6431345fe65afe8d98.AvaloniaView.n_onVisibilityAggregated(Native Method)
    at crc6431345fe65afe8d98.AvaloniaView.onVisibilityAggregated(AvaloniaView.java:68)
    at android.view.View.dispatchDetachedFromWindow(View.java:18460)
    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3837)
    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3829)
    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3829)
    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3829)
    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3829)
    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3829)
    at android.view.ViewRootImpl.dispatchDetachedFromWindow(ViewRootImpl.java:3975)
    at android.view.ViewRootImpl.doDie(ViewRootImpl.java:6985)
    at android.view.ViewRootImpl.die(ViewRootImpl.java:6958)
    at android.view.WindowManagerGlobal.removeViewLocked(WindowManagerGlobal.java:458)
    at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:396)
    at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:124)
    at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4532)
    at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:4794)
    at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4727)
    at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:69)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1839)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6714)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:503)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911)

  --- End of managed Java.Lang.Error stack trace ---
java.lang.Error: Java callstack:
    at crc6431345fe65afe8d98.AvaloniaView.n_onVisibilityAggregated(Native Method)
    at crc6431345fe65afe8d98.AvaloniaView.onVisibilityAggregated(AvaloniaView.java:68)
    at android.view.View.dispatchDetachedFromWindow(View.java:18460)
    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3837)
    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3829)
    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3829)
    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3829)
    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3829)
    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3829)
    at android.view.ViewRootImpl.dispatchDetachedFromWindow(ViewRootImpl.java:3975)
    at android.view.ViewRootImpl.doDie(ViewRootImpl.java:6985)
    at android.view.ViewRootImpl.die(ViewRootImpl.java:6958)
    at android.view.WindowManagerGlobal.removeViewLocked(WindowManagerGlobal.java:458)
    at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:396)
    at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:124)
    at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4532)
    at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:4794)
    at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4727)
    at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:69)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1839)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6714)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:503)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911)

   --- End of inner exception stack trace ---
   at Java.Interop.TypeManager.CreateProxy(Type type, IntPtr handle, JniHandleOwnership transfer)
   at Java.Interop.TypeManager.CreateInstance(IntPtr handle, JniHandleOwnership transfer, Type targetType)
   --- End of inner exception stack trace ---
   at Java.Interop.TypeManager.CreateInstance(IntPtr handle, JniHandleOwnership transfer, Type targetType)
   at Java.Lang.Object.GetObject(IntPtr handle, JniHandleOwnership transfer, Type type)
   at Java.Lang.Object._GetObject[View](IntPtr handle, JniHandleOwnership transfer)
   at Android.Runtime.DynamicMethodNameCounter.2(IntPtr , IntPtr , Boolean )

@maxkatz6
Copy link
Member

@ArchangelJTW that's intersting. I wonder if it will be enough to add this new constructor with shared code as the main one: AvaloniaView.
cc @emmauss

@ArchangelJTW
Copy link
Author

I would like to note the issue is still present on nightly 11.1.999

@ArchangelJTW
Copy link
Author

ArchangelJTW commented Jun 14, 2024

According to @workgroupengineering 's research, this was expected behavior without including the flags ConfigChanges.Keyboard | ConfigChanges.KeyboardHidden | ConfigChanges.Navigation to the main activity. Once these were included, the issue no longer persisted. Thank you, @workgroupengineering .

I recommend this information be added somewhere in the android documentation, so it can easily be found, if it is not present already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants