Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@l8023lxb
Copy link

AccessibilityManager.notifyAccessibilityStateChanged() use post to call listener.onAccessibilityStateChanged(),if post and FlutterEngine.destroy() occur at the same time,it may be post->FlutterEngine.destroy->FlutterJNI.nativePlatformViewId=null->listener.onAccessibilityStateChanged(),and app will crash with FlutterJNI.ensureAttachedToNative as #33511

@auto-assign auto-assign bot requested a review from gaaclarke March 24, 2020 12:30
@jason-simmons
Copy link
Member

jason-simmons commented Mar 24, 2020

Are you seeing the FlutterJNI.setSemanticsEnabled exception (from flutter/flutter#33511) in an app that uses the old version of the Flutter Android embedding (io.flutter.view.FlutterView)?

The new version of the embedding (io.flutter.embedding.android.FlutterView) should handle this correctly. FlutterView.onDestroyView callsFlutterView.detachFromFlutterEngine, which will remove the AccessibilityBridge listener. FlutterView.onDetach will destroy the FlutterEngine and detach FlutterJNI from its native peer.

The implementation of FlutterActivity and FlutterFragment will ensure that onDestroyView is called before onDetach. So the accessibility listener should no longer be invoked by the time FlutterJNI has been detached.

The old io.flutter.view.FlutterView class did not do this correctly. The old class removes the accessibility listener in its override of View.onDetachedFromWindow. This callback will happen after the Activity.onDestroy lifecycle event that triggers FlutterView.destroy and detaches FlutterJNI.
So in the old embedding there is an interval during which the accessibility manager may invoke the accessibility listener while it is still active and holding a detached FlutterJNI.

I have not been able to reproduce this exception locally. But if it affects the old embedding then I'd prefer to patch io.flutter.view.FlutterView.

cc @matthew-carroll

@l8023lxb l8023lxb closed this Mar 25, 2020
@l8023lxb l8023lxb deleted the fix#33511 branch March 25, 2020 03:16
@l8023lxb
Copy link
Author

Are you seeing the FlutterJNI.setSemanticsEnabled exception (from flutter/flutter#33511) in an app that uses the old version of the Flutter Android embedding (io.flutter.view.FlutterView)?

The new version of the embedding (io.flutter.embedding.android.FlutterView) should handle this correctly. FlutterView.onDestroyView callsFlutterView.detachFromFlutterEngine, which will remove the AccessibilityBridge listener. FlutterView.onDetach will destroy the FlutterEngine and detach FlutterJNI from its native peer.

The implementation of FlutterActivity and FlutterFragment will ensure that onDestroyView is called before onDetach. So the accessibility listener should no longer be invoked by the time FlutterJNI has been detached.

The old io.flutter.view.FlutterView class did not do this correctly. The old class removes the accessibility listener in its override of View.onDetachedFromWindow. This callback will happen after the Activity.onDestroy lifecycle event that triggers FlutterView.destroy and detaches FlutterJNI.
So in the old embedding there is an interval during which the accessibility manager may invoke the accessibility listener while it is still active and holding a detached FlutterJNI.

I have not been able to reproduce this exception locally. But if it affects the old embedding then I'd prefer to patch io.flutter.view.FlutterView.

cc @matthew-carroll

yes,i can recurrent this bug locally with Huawei ,and i use v1.7.8 io.flutter.view.FlutterView,
For safety reasons,Huawei will close Accessibility when app quit completely.If phone low memory and try to kill some background app,onAccessibilityStateChanged and FlutterEngine.destroy will occur at the same time ,this will greatly increase the probability of crash

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants