@@ -402,59 +402,67 @@ int getActiveRuntimeVirtualManifest(wrap::android::content::Context const &conte
402402 const jni::Array<std::string> projection =
403403 makeArray ({active_runtime::Columns::PACKAGE_NAME, active_runtime::Columns::NATIVE_LIB_DIR,
404404 active_runtime::Columns::SO_FILENAME, active_runtime::Columns::HAS_FUNCTIONS});
405+ static bool hasQueryBroker = false ;
406+ static Json::Value runtimeManifest;
407+ if (!hasQueryBroker) {
408+ // First, try getting the installable broker's provider
409+ systemBroker = false ;
410+ Cursor cursor;
411+ if (!getActiveRuntimeCursor (context, projection, systemBroker, cursor)) {
412+ // OK, try the system broker as a fallback.
413+ systemBroker = true ;
414+ getActiveRuntimeCursor (context, projection, systemBroker, cursor);
415+ }
416+ hasQueryBroker = true ;
405417
406- // First, try getting the installable broker's provider
407- systemBroker = false ;
408- Cursor cursor;
409- if (!getActiveRuntimeCursor (context, projection, systemBroker, cursor)) {
410- // OK, try the system broker as a fallback.
411- systemBroker = true ;
412- getActiveRuntimeCursor (context, projection, systemBroker, cursor);
413- }
414-
415- if (cursor.isNull ()) {
416- // Couldn't find either broker
417- ALOGI (" Could access neither the installable nor system runtime broker." );
418- return -1 ;
419- }
420-
421- cursor.moveToFirst ();
418+ if (cursor.isNull ()) {
419+ // Couldn't find either broker
420+ ALOGI (" Could access neither the installable nor system runtime broker." );
421+ return -1 ;
422+ }
422423
423- do {
424- auto filename = cursor.getString (cursor.getColumnIndex (active_runtime::Columns::SO_FILENAME));
425- auto libDir = cursor.getString (cursor.getColumnIndex (active_runtime::Columns::NATIVE_LIB_DIR));
426- auto packageName = cursor.getString (cursor.getColumnIndex (active_runtime::Columns::PACKAGE_NAME));
427-
428- auto hasFunctions = cursor.getInt (cursor.getColumnIndex (active_runtime::Columns::HAS_FUNCTIONS)) == 1 ;
429- ALOGI (" Got runtime: package: %s, so filename: %s, native lib dir: %s, has functions: %s" , packageName.c_str (),
430- filename.c_str (), libDir.c_str (), (hasFunctions ? " yes" : " no" ));
431-
432- auto lib_path = libDir + " /" + filename;
433- auto *lib = dlopen (lib_path.c_str (), RTLD_LAZY | RTLD_LOCAL);
434- if (lib) {
435- // we found a runtime that we can dlopen, use it.
436- dlclose (lib);
437-
438- Json::Value manifest = makeMinimumVirtualRuntimeManifest (lib_path);
439- if (hasFunctions) {
440- int result = populateRuntimeFunctions (context, systemBroker, packageName, manifest);
441- if (result != 0 ) {
442- ALOGW (" Unable to populate functions from runtime: %s, checking for more records..." , lib_path.c_str ());
443- continue ;
424+ cursor.moveToFirst ();
425+
426+ do {
427+ auto filename = cursor.getString (cursor.getColumnIndex (active_runtime::Columns::SO_FILENAME));
428+ auto libDir = cursor.getString (cursor.getColumnIndex (active_runtime::Columns::NATIVE_LIB_DIR));
429+ auto packageName = cursor.getString (cursor.getColumnIndex (active_runtime::Columns::PACKAGE_NAME));
430+
431+ auto hasFunctions = cursor.getInt (cursor.getColumnIndex (active_runtime::Columns::HAS_FUNCTIONS)) == 1 ;
432+ ALOGI (" Got runtime: package: %s, so filename: %s, native lib dir: %s, has functions: %s" , packageName.c_str (),
433+ filename.c_str (), libDir.c_str (), (hasFunctions ? " yes" : " no" ));
434+
435+ auto lib_path = libDir + " /" + filename;
436+ auto *lib = dlopen (lib_path.c_str (), RTLD_LAZY | RTLD_LOCAL);
437+ if (lib) {
438+ // we found a runtime that we can dlopen, use it.
439+ dlclose (lib);
440+
441+ Json::Value manifest = makeMinimumVirtualRuntimeManifest (lib_path);
442+ if (hasFunctions) {
443+ int result = populateRuntimeFunctions (context, systemBroker, packageName, manifest);
444+ if (result != 0 ) {
445+ ALOGW (" Unable to populate functions from runtime: %s, checking for more records..." , lib_path.c_str ());
446+ continue ;
447+ }
444448 }
449+ runtimeManifest = manifest;
450+ cursor.close ();
451+ virtualManifest = runtimeManifest;
452+ return 0 ;
445453 }
446- virtualManifest = manifest;
447- cursor.close ();
448- return 0 ;
449- }
450- // this runtime was not accessible, see if the broker has more runtimes on
451- // offer.
452- ALOGV (" Unable to open broker provided runtime at %s, checking for more records..." , lib_path.c_str ());
453- } while (cursor.moveToNext ());
454+ // this runtime was not accessible, see if the broker has more runtimes on
455+ // offer.
456+ ALOGV (" Unable to open broker provided runtime at %s, checking for more records..." , lib_path.c_str ());
457+ } while (cursor.moveToNext ());
454458
455- ALOGE (" Unable to open any of the broker provided runtimes." );
456- cursor.close ();
457- return -1 ;
459+ ALOGE (" Unable to open any of the broker provided runtimes." );
460+ cursor.close ();
461+ return -1 ;
462+ }
463+
464+ virtualManifest = runtimeManifest;
465+ return 0 ;
458466}
459467
460468static int populateApiLayerFunctions (wrap::android::content::Context const &context, bool systemBroker,
0 commit comments