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

Centralize JNI util functions in JniReferences and use GetEnvForCurrentThread() everywhere #7345

Merged
merged 1 commit into from
Jun 4, 2021

Conversation

austinh0
Copy link
Contributor

@austinh0 austinh0 commented Jun 3, 2021

Problem

Common code accessing JavaVM and JNIEnv is duplicated in CHIPDeviceController-JNI, AndroidDeviceControllerWrapper, and AndroidKeyValueStoreManager. Before adding more duplication when another JNI file is generated for clusters, we should consolidate these references.

Change overview

  • Move GetEnvForCurrentThread() from AndroidKeyValueStoreManager to JniReferences
  • Change GetEnvForCurrentThread() to attach thread as a daemon, which means we don't have to detach it manually.
  • Move FindMethod() and CallVoidInt() from AndroidDeviceControllerWrapper to JniReferences
  • Everywhere where a JNIEnv is requested, use GetEnvForCurrentThread() to ensure the JNIEnv used won't be null.

Testing

  • Went through commissioning flow on Android CHIPTool
  • Manually created new thread and saw that GetEnvForCurrentThread() invocation attaches to the new thread

@woody-apple
Copy link
Contributor

@woody-apple
Copy link
Contributor

/rebase

@woody-apple woody-apple merged commit aa96ea0 into project-chip:master Jun 4, 2021
nikita-s-wrk pushed a commit to nikita-s-wrk/connectedhomeip that referenced this pull request Sep 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants