HomePhabricator
Diffusion Comm 0c43681bcf2e

Introduce utility function to temporarily attach thread to JVM

Description

Introduce utility function to temporarily attach thread to JVM

Summary: This differential introduces utility function to run a block of code on an auxiliary thread if native api needs to be available. Auxiliary threads are not by default attached to JVM, so we cannot call for instance CommSecureStore or PlatformSpecificTools from them. This function allows to temporarily attach a thread to JVM and execute block of code represented by lambda. Once the block is done thread is detached from JVM. Attaching thread is fast operation according to documentation.

Test Plan: Write a noop function in SQLiteQueryEXecutor that accesses some native Android API. Schedule it on databaseThread in CommCoreModule. Build Android app, run it and see that it crashes with error "Unable to retrieve JNI Environment. Is the thread attached?". Now re-implement this function to use run_with_native_accessible. Build and run the app. It should not crash.

Reviewers: tomek, jon

Reviewed By: tomek

Subscribers: ashoat, atul, abosh

Differential Revision: https://phab.comm.dev/D4957

Details

Provenance
marcinAuthored on Aug 26 2022, 1:31 AM
Reviewer
tomek
Differential Revision
D4957: Introduce utility function to temporarily attach thread to JVM
Parents
rCOMM0dbcf0262f50: Check for the case of database encrypted with key that is lost
Branches
Unknown
Tags
Unknown