Skip to content

Commit c77d617

Browse files
committed
Loader: Remove overengineered virtual manifest builder on Android
1 parent 296daf4 commit c77d617

File tree

1 file changed

+12
-27
lines changed

1 file changed

+12
-27
lines changed

src/loader/android_utilities.cpp

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -185,30 +185,15 @@ static constexpr auto ABI = "x86_64";
185185
#error "Unknown ABI!"
186186
#endif
187187

188-
/// Helper class to generate the jsoncpp object corresponding to a synthetic runtime manifest.
189-
class JsonManifestBuilder {
190-
public:
191-
JsonManifestBuilder(const std::string &libraryPathParent, const std::string &libraryPath);
192-
JsonManifestBuilder &function(const std::string &functionName, const std::string &symbolName);
188+
static inline Json::Value makeMinimumVirtualRuntimeManifest(const std::string &libraryPath) {
189+
Json::Value root_node(Json::objectValue);
193190

194-
Json::Value build() const { return root_node; }
195-
196-
private:
197-
Json::Value root_node;
198-
};
199-
200-
inline JsonManifestBuilder::JsonManifestBuilder(const std::string &libraryPathParent, const std::string &libraryPath)
201-
: root_node(Json::objectValue) {
202191
root_node["file_format_version"] = "1.0.0";
203192
root_node["instance_extensions"] = Json::Value(Json::arrayValue);
204193
root_node["functions"] = Json::Value(Json::objectValue);
205-
root_node[libraryPathParent] = Json::objectValue;
206-
root_node[libraryPathParent]["library_path"] = libraryPath;
207-
}
208-
209-
inline JsonManifestBuilder &JsonManifestBuilder::function(const std::string &functionName, const std::string &symbolName) {
210-
root_node["functions"][functionName] = symbolName;
211-
return *this;
194+
root_node["runtime"] = Json::objectValue;
195+
root_node["runtime"]["library_path"] = libraryPath;
196+
return root_node;
212197
}
213198

214199
static constexpr const char *getBrokerTypeName(bool systemBroker) { return systemBroker ? "system" : "installable"; }
@@ -259,9 +244,9 @@ static bool getCursor(wrap::android::content::Context const &context, jni::Array
259244
return true;
260245
}
261246

262-
static int populateFunctions(wrap::android::content::Context const &context, bool systemBroker, const std::string &packageName,
263-
JsonManifestBuilder &builder) {
264-
jni::Array<std::string> projection = makeArray({functions::Columns::FUNCTION_NAME, functions::Columns::SYMBOL_NAME});
247+
static int populateRuntimeFunctions(wrap::android::content::Context const &context, bool systemBroker,
248+
const std::string &packageName, Json::Value &manifest) {
249+
const jni::Array<std::string> projection = makeArray({functions::Columns::FUNCTION_NAME, functions::Columns::SYMBOL_NAME});
265250

266251
auto uri = functions::makeRuntimeContentUri(systemBroker, XR_VERSION_MAJOR(XR_CURRENT_API_VERSION), packageName, ABI);
267252
ALOGI("populateFunctions: Querying URI: %s", uri.toString().c_str());
@@ -273,7 +258,7 @@ static int populateFunctions(wrap::android::content::Context const &context, boo
273258
auto functionIndex = cursor.getColumnIndex(functions::Columns::FUNCTION_NAME);
274259
auto symbolIndex = cursor.getColumnIndex(functions::Columns::SYMBOL_NAME);
275260
while (cursor.moveToNext()) {
276-
builder.function(cursor.getString(functionIndex), cursor.getString(symbolIndex));
261+
manifest["functions"][cursor.getString(functionIndex)] = cursor.getString(symbolIndex);
277262
}
278263

279264
cursor.close();
@@ -324,15 +309,15 @@ int getActiveRuntimeVirtualManifest(wrap::android::content::Context const &conte
324309
// we found a runtime that we can dlopen, use it.
325310
dlclose(lib);
326311

327-
JsonManifestBuilder builder{"runtime", lib_path};
312+
Json::Value manifest = makeMinimumVirtualRuntimeManifest(lib_path);
328313
if (hasFunctions) {
329-
int result = populateFunctions(context, systemBroker, packageName, builder);
314+
int result = populateRuntimeFunctions(context, systemBroker, packageName, manifest);
330315
if (result != 0) {
331316
ALOGW("Unable to populate functions from runtime: %s, checking for more records...", lib_path.c_str());
332317
continue;
333318
}
334319
}
335-
virtualManifest = builder.build();
320+
virtualManifest = manifest;
336321
cursor.close();
337322
return 0;
338323
}

0 commit comments

Comments
 (0)