From 811118d3ee936dca89ee8c9c7523dc804ad181c8 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Wed, 29 Nov 2023 22:30:22 +0100 Subject: [PATCH] (Android) Added support for launching emulators with scoped storage permissions --- es-app/src/FileData.cpp | 16 +++++++++++----- es-app/src/FileData.h | 2 +- es-core/src/utils/PlatformUtil.cpp | 11 ++++++----- es-core/src/utils/PlatformUtil.h | 1 + 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/es-app/src/FileData.cpp b/es-app/src/FileData.cpp index ffd67f69d..ac3e2710f 100644 --- a/es-app/src/FileData.cpp +++ b/es-app/src/FileData.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT // -// EmulationStation Desktop Edition +// ES-DE // FileData.cpp // // Provides game file data structures and functions to access and sort this information. @@ -951,6 +951,7 @@ void FileData::launchGame() std::string androidPackage; std::string androidActivity; std::string androidAction; + std::string androidFileAsURI; std::vector> androidExtras; #endif @@ -1616,6 +1617,8 @@ void FileData::launchGame() command = Utils::String::replace(command, "%ROMPATH%", Utils::FileSystem::getEscapedPath(getROMDirectory())); #if defined(__ANDROID__) + if (command.find("%ROMURI%") != std::string::npos) + androidFileAsURI = romRaw; command = Utils::String::replace(command, "%ANDROIDPACKAGE%", androidPackage); size_t extraPos {command.find("%EXTRA_")}; @@ -1721,9 +1724,12 @@ void FileData::launchGame() LOG(LogInfo) << "Package: " << androidPackage; LOG(LogInfo) << "Activity: " << (androidActivity == "" ? "" : androidActivity); LOG(LogInfo) << "Action: " << (androidAction == "" ? "" : androidAction); + if (androidFileAsURI != "") { + LOG(LogInfo) << "File (URI): " << androidFileAsURI; + } for (auto& extra : androidExtras) { - LOG(LogDebug) << "Extra name: " << extra.first; - LOG(LogDebug) << "Extra value: " << extra.second; + LOG(LogInfo) << "Extra name: " << extra.first; + LOG(LogInfo) << "Extra value: " << extra.second; } #else LOG(LogInfo) << "Expanded emulator launch command:"; @@ -1748,8 +1754,8 @@ void FileData::launchGame() Utils::String::stringToWideString(command), Utils::String::stringToWideString(startDirectory), runInBackground, hideWindow); #elif defined(__ANDROID__) - returnValue = Utils::Platform::Android::launchGame(androidPackage, androidActivity, - androidAction, androidExtras); + returnValue = Utils::Platform::Android::launchGame( + androidPackage, androidActivity, androidAction, androidFileAsURI, androidExtras); #else returnValue = Utils::Platform::launchGameUnix(command, startDirectory, runInBackground); #endif diff --git a/es-app/src/FileData.h b/es-app/src/FileData.h index 982d73b88..4940d3aa9 100644 --- a/es-app/src/FileData.h +++ b/es-app/src/FileData.h @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT // -// EmulationStation Desktop Edition +// ES-DE // FileData.h // // Provides game file data structures and functions to access and sort this information. diff --git a/es-core/src/utils/PlatformUtil.cpp b/es-core/src/utils/PlatformUtil.cpp index ef55cc6e1..3ad639707 100644 --- a/es-core/src/utils/PlatformUtil.cpp +++ b/es-core/src/utils/PlatformUtil.cpp @@ -403,14 +403,15 @@ namespace Utils int launchGame(const std::string& packageName, const std::string& activity, const std::string& action, + const std::string& fileAsURI, std::vector>& extras) { JNIEnv* jniEnv {reinterpret_cast(SDL_AndroidGetJNIEnv())}; jclass jniClass {jniEnv->FindClass("org/es_de/frontend/MainActivity")}; - jmethodID methodID { - jniEnv->GetStaticMethodID(jniClass, "launchGame", - "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/" - "String;Ljava/util/Vector;Ljava/util/Vector;)Z")}; + jmethodID methodID {jniEnv->GetStaticMethodID( + jniClass, "launchGame", + "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/" + "String;Ljava/util/Vector;Ljava/util/Vector;)Z")}; jclass vectorClass {jniEnv->FindClass("java/util/Vector")}; jmethodID vectorMID {jniEnv->GetMethodID(vectorClass, "", "()V")}; jmethodID addMethodID { @@ -426,7 +427,7 @@ namespace Utils const bool returnValue {static_cast(jniEnv->CallStaticBooleanMethod( jniClass, methodID, jniEnv->NewStringUTF(packageName.c_str()), jniEnv->NewStringUTF(activity.c_str()), jniEnv->NewStringUTF(action.c_str()), - extrasNames, extrasValues))}; + jniEnv->NewStringUTF(fileAsURI.c_str()), extrasNames, extrasValues))}; // jniEnv->DeleteLocalRef(vectorClass); // jniEnv->DeleteLocalRef(jniClass); if (returnValue) diff --git a/es-core/src/utils/PlatformUtil.h b/es-core/src/utils/PlatformUtil.h index 97687f052..ff64bfbd3 100644 --- a/es-core/src/utils/PlatformUtil.h +++ b/es-core/src/utils/PlatformUtil.h @@ -65,6 +65,7 @@ namespace Utils int launchGame(const std::string& packageName, const std::string& activity, const std::string& action, + const std::string& fileAsURI, std::vector>& extras); } // namespace Android #endif