[android] move the key processor to firmware_manager
All checks were successful
eden-license / license-header (pull_request) Successful in 13s

Signed-off-by: Aleksandr Popovich <popovich@eden-emu.dev>
This commit is contained in:
Aleksandr Popovich 2025-07-12 00:04:58 -04:00
parent 67edb897bf
commit a360f67fad
Signed by: AleksandrPopovich
GPG key ID: B2008BBDA7954884
8 changed files with 616 additions and 555 deletions

View file

@ -15,6 +15,7 @@ import android.view.Surface
import android.view.View import android.view.View
import android.widget.TextView import android.widget.TextView
import androidx.annotation.Keep import androidx.annotation.Keep
import androidx.core.net.toUri
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import net.swiftzer.semver.SemVer import net.swiftzer.semver.SemVer
import java.lang.ref.WeakReference import java.lang.ref.WeakReference
@ -27,6 +28,7 @@ import org.yuzu.yuzu_emu.model.InstallResult
import org.yuzu.yuzu_emu.model.Patch import org.yuzu.yuzu_emu.model.Patch
import org.yuzu.yuzu_emu.model.GameVerificationResult import org.yuzu.yuzu_emu.model.GameVerificationResult
import org.yuzu.yuzu_emu.network.NetPlayManager import org.yuzu.yuzu_emu.network.NetPlayManager
import java.io.File
/** /**
* Class which contains methods that interact * Class which contains methods that interact
@ -102,6 +104,21 @@ object NativeLibrary {
FileUtil.getFilename(Uri.parse(path)) FileUtil.getFilename(Uri.parse(path))
} }
@Keep
@JvmStatic
fun copyFileToStorage(source: String, destdir: String): Boolean {
return FileUtil.copyUriToInternalStorage(
source.toUri(),
destdir
) != null
}
@Keep
@JvmStatic
fun getFileExtension(source: String): String {
return FileUtil.getExtension(source.toUri())
}
external fun setAppDirectory(directory: String) external fun setAppDirectory(directory: String)
/** /**

View file

@ -264,8 +264,6 @@ class DriverFetcherFragment : Fragment() {
} }
releases.add(release) releases.add(release)
println(release.publishTime)
} }
} }

View file

@ -478,7 +478,6 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
} }
private fun startEmulation(programIndex: Int = 0) { private fun startEmulation(programIndex: Int = 0) {
println("PROGRAM INDEX: $programIndex")
if (!NativeLibrary.isRunning() && !NativeLibrary.isPaused()) { if (!NativeLibrary.isRunning() && !NativeLibrary.isPaused()) {
if (!DirectoryInitialization.areDirectoriesReady) { if (!DirectoryInitialization.areDirectoriesReady) {
DirectoryInitialization.start() DirectoryInitialization.start()

View file

@ -337,59 +337,35 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
val getAmiiboKey = registerForActivityResult(ActivityResultContracts.OpenDocument()) { result -> val getAmiiboKey = registerForActivityResult(ActivityResultContracts.OpenDocument()) { result ->
if (result != null) { if (result != null) {
processKey(result, "bin", false) processKey(result, "bin")
} }
} }
fun processKey(result: Uri, extension: String = "keys", check: Boolean = true): Boolean { fun processKey(result: Uri, extension: String = "keys") {
if (FileUtil.getExtension(result) != extension) {
MessageDialogFragment.newInstance(
this,
titleId = R.string.keys_failed,
descriptionId = R.string.error_keys_invalid_filename
).show(supportFragmentManager, MessageDialogFragment.TAG)
return false
}
contentResolver.takePersistableUriPermission( contentResolver.takePersistableUriPermission(
result, Intent.FLAG_GRANT_READ_URI_PERMISSION result, Intent.FLAG_GRANT_READ_URI_PERMISSION
) )
val dstPath = DirectoryInitialization.userDirectory + "/keys/" val resultCode: Int = NativeLibrary.installKeys(result.toString(), extension);
if (FileUtil.copyUriToInternalStorage(
result, dstPath, "" if (resultCode == 0) {
) != null
) {
if (NativeLibrary.reloadKeys()) {
Toast.makeText( Toast.makeText(
applicationContext, R.string.keys_install_success, Toast.LENGTH_SHORT applicationContext, R.string.keys_install_success, Toast.LENGTH_SHORT
).show() ).show()
if (check) {
homeViewModel.setCheckKeys(true)
val firstTimeSetup =
PreferenceManager.getDefaultSharedPreferences(applicationContext)
.getBoolean(Settings.PREF_FIRST_APP_LAUNCH, true)
if (!firstTimeSetup) {
homeViewModel.setCheckFirmware(true)
}
gamesViewModel.reloadGames(true) gamesViewModel.reloadGames(true)
}
return true return
} else {
MessageDialogFragment.newInstance(
this,
titleId = R.string.keys_failed,
descriptionId = R.string.error_keys_failed_init,
helpLinkId = R.string.dumping_keys_quickstart_link
).show(supportFragmentManager, MessageDialogFragment.TAG)
return false
}
} }
return true val resultString: String =
resources.getStringArray(R.array.installKeysResults)[resultCode]
MessageDialogFragment.newInstance(
titleId = R.string.keys_failed,
descriptionString = resultString,
helpLinkId = R.string.keys_missing_help
).show(supportFragmentManager, MessageDialogFragment.TAG)
} }
val getFirmware = registerForActivityResult(ActivityResultContracts.OpenDocument()) { result -> val getFirmware = registerForActivityResult(ActivityResultContracts.OpenDocument()) { result ->
@ -542,7 +518,7 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
addonViewModel.refreshAddons() addonViewModel.refreshAddons()
val separator = System.getProperty("line.separator") ?: "\n" val separator = System.lineSeparator() ?: "\n"
val installResult = StringBuilder() val installResult = StringBuilder()
if (installSuccess > 0) { if (installSuccess > 0) {
installResult.append( installResult.append(

View file

@ -504,6 +504,7 @@
</string-array> </string-array>
<string-array name="installKeysResults"> <string-array name="installKeysResults">
<item>""</item>
<item>""</item> <item>""</item>
<item>@string/error_keys_copy_failed</item> <item>@string/error_keys_copy_failed</item>
<item>@string/error_keys_invalid_filename</item> <item>@string/error_keys_invalid_filename</item>

View file

@ -26,6 +26,9 @@ static jmethodID s_disk_cache_load_progress;
static jmethodID s_on_emulation_started; static jmethodID s_on_emulation_started;
static jmethodID s_on_emulation_stopped; static jmethodID s_on_emulation_stopped;
static jmethodID s_on_program_changed; static jmethodID s_on_program_changed;
static jmethodID s_copy_to_storage;
static jmethodID s_file_exists;
static jmethodID s_file_extension;
static jclass s_game_class; static jclass s_game_class;
static jmethodID s_game_constructor; static jmethodID s_game_constructor;
@ -149,6 +152,18 @@ jmethodID GetDiskCacheLoadProgress() {
return s_disk_cache_load_progress; return s_disk_cache_load_progress;
} }
jmethodID GetCopyToStorage() {
return s_copy_to_storage;
}
jmethodID GetFileExists() {
return s_file_exists;
}
jmethodID GetFileExtension() {
return s_file_extension;
}
jmethodID GetOnEmulationStarted() { jmethodID GetOnEmulationStarted() {
return s_on_emulation_started; return s_on_emulation_started;
} }
@ -426,7 +441,8 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved) {
const jclass game_dir_class = env->FindClass("org/yuzu/yuzu_emu/model/GameDir"); const jclass game_dir_class = env->FindClass("org/yuzu/yuzu_emu/model/GameDir");
s_game_dir_class = reinterpret_cast<jclass>(env->NewGlobalRef(game_dir_class)); s_game_dir_class = reinterpret_cast<jclass>(env->NewGlobalRef(game_dir_class));
s_game_dir_constructor = env->GetMethodID(game_dir_class, "<init>", "(Ljava/lang/String;Z)V"); s_game_dir_constructor = env->GetMethodID(game_dir_class, "<init>",
"(Ljava/lang/String;Z)V");
env->DeleteLocalRef(game_dir_class); env->DeleteLocalRef(game_dir_class);
// Initialize methods // Initialize methods
@ -434,6 +450,12 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved) {
env->GetStaticMethodID(s_native_library_class, "exitEmulationActivity", "(I)V"); env->GetStaticMethodID(s_native_library_class, "exitEmulationActivity", "(I)V");
s_disk_cache_load_progress = s_disk_cache_load_progress =
env->GetStaticMethodID(s_disk_cache_progress_class, "loadProgress", "(III)V"); env->GetStaticMethodID(s_disk_cache_progress_class, "loadProgress", "(III)V");
s_copy_to_storage = env->GetStaticMethodID(s_native_library_class, "copyFileToStorage",
"(Ljava/lang/String;Ljava/lang/String;)Z");
s_file_exists = env->GetStaticMethodID(s_native_library_class, "exists",
"(Ljava/lang/String;)Z");
s_file_extension = env->GetStaticMethodID(s_native_library_class, "getFileExtension",
"(Ljava/lang/String;)Ljava/lang/String;");
s_on_emulation_started = s_on_emulation_started =
env->GetStaticMethodID(s_native_library_class, "onEmulationStarted", "()V"); env->GetStaticMethodID(s_native_library_class, "onEmulationStarted", "()V");
s_on_emulation_stopped = s_on_emulation_stopped =
@ -555,10 +577,12 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved) {
env->GetMethodID(yuzu_input_device_interface, "getName", "()Ljava/lang/String;"); env->GetMethodID(yuzu_input_device_interface, "getName", "()Ljava/lang/String;");
s_yuzu_input_device_get_guid = s_yuzu_input_device_get_guid =
env->GetMethodID(yuzu_input_device_interface, "getGUID", "()Ljava/lang/String;"); env->GetMethodID(yuzu_input_device_interface, "getGUID", "()Ljava/lang/String;");
s_yuzu_input_device_get_port = env->GetMethodID(yuzu_input_device_interface, "getPort", "()I"); s_yuzu_input_device_get_port = env->GetMethodID(yuzu_input_device_interface, "getPort",
"()I");
s_yuzu_input_device_get_supports_vibration = s_yuzu_input_device_get_supports_vibration =
env->GetMethodID(yuzu_input_device_interface, "getSupportsVibration", "()Z"); env->GetMethodID(yuzu_input_device_interface, "getSupportsVibration", "()Z");
s_yuzu_input_device_vibrate = env->GetMethodID(yuzu_input_device_interface, "vibrate", "(F)V"); s_yuzu_input_device_vibrate = env->GetMethodID(yuzu_input_device_interface, "vibrate",
"(F)V");
s_yuzu_input_device_get_axes = s_yuzu_input_device_get_axes =
env->GetMethodID(yuzu_input_device_interface, "getAxes", "()[Ljava/lang/Integer;"); env->GetMethodID(yuzu_input_device_interface, "getAxes", "()[Ljava/lang/Integer;");
s_yuzu_input_device_has_keys = s_yuzu_input_device_has_keys =

View file

@ -39,6 +39,9 @@ jclass GetDiskCacheLoadCallbackStageClass();
jclass GetGameDirClass(); jclass GetGameDirClass();
jmethodID GetGameDirConstructor(); jmethodID GetGameDirConstructor();
jmethodID GetDiskCacheLoadProgress(); jmethodID GetDiskCacheLoadProgress();
jmethodID GetCopyToStorage();
jmethodID GetFileExists();
jmethodID GetFileExtension();
jmethodID GetExitEmulationActivity(); jmethodID GetExitEmulationActivity();
jmethodID GetOnEmulationStarted(); jmethodID GetOnEmulationStarted();

View file

@ -3,6 +3,10 @@
#include "firmware_manager.h" #include "firmware_manager.h"
#include <filesystem> #include <filesystem>
#include <jni.h>
#include <common/android/id_cache.h>
#include <common/android/android_common.h>
#include <common/fs/fs_paths.h>
#include "common/fs/fs.h" #include "common/fs/fs.h"
#include "common/fs/path_util.h" #include "common/fs/path_util.h"
@ -12,12 +16,52 @@
#include "core/crypto/key_manager.h" #include "core/crypto/key_manager.h"
#include "frontend_common/content_manager.h" #include "frontend_common/content_manager.h"
FirmwareManager::KeyInstallResult FirmwareManager::InstallKeys(std::string location, std::string extension) FirmwareManager::KeyInstallResult
{ FirmwareManager::InstallKeys(std::string location, std::string extension) {
LOG_INFO(Frontend, "Installing key files from {}", location); LOG_INFO(Frontend, "Installing key files from {}", location);
const auto keys_dir = Common::FS::GetEdenPath(Common::FS::EdenPath::KeysDir); const auto keys_dir = Common::FS::GetEdenPath(Common::FS::EdenPath::KeysDir);
#ifdef ANDROID
JNIEnv *env = Common::Android::GetEnvForThread();
jstring jsrc = Common::Android::ToJString(env, location);
jclass native = Common::Android::GetNativeLibraryClass();
jmethodID getExtension = Common::Android::GetFileExtension();
jstring jext = static_cast<jstring>(env->CallStaticObjectMethod(
native,
getExtension,
jsrc
));
std::string ext = Common::Android::GetJString(env, jext);
if (ext != extension) {
return ErrorWrongFilename;
}
jmethodID copyToStorage = Common::Android::GetCopyToStorage();
jstring jdest = Common::Android::ToJString(env, keys_dir.string());
jboolean copyResult = env->CallStaticBooleanMethod(
native,
copyToStorage,
jsrc,
jdest
);
if (!copyResult) {
return ErrorFailedCopy;
}
#else
if (!location.ends_with(extension)) {
return ErrorWrongFilename;
}
bool prod_keys_found = false;
const std::filesystem::path prod_key_path = location; const std::filesystem::path prod_key_path = location;
const std::filesystem::path key_source_path = prod_key_path.parent_path(); const std::filesystem::path key_source_path = prod_key_path.parent_path();
@ -25,7 +69,6 @@ FirmwareManager::KeyInstallResult FirmwareManager::InstallKeys(std::string locat
return InvalidDir; return InvalidDir;
} }
bool prod_keys_found = false;
std::vector<std::filesystem::path> source_key_files; std::vector<std::filesystem::path> source_key_files;
if (Common::FS::Exists(prod_key_path)) { if (Common::FS::Exists(prod_key_path)) {
@ -57,6 +100,7 @@ FirmwareManager::KeyInstallResult FirmwareManager::InstallKeys(std::string locat
return ErrorFailedCopy; return ErrorFailedCopy;
} }
} }
#endif
// Reinitialize the key manager // Reinitialize the key manager
Core::Crypto::KeyManager::Instance().ReloadKeys(); Core::Crypto::KeyManager::Instance().ReloadKeys();
@ -65,12 +109,11 @@ FirmwareManager::KeyInstallResult FirmwareManager::InstallKeys(std::string locat
return Success; return Success;
} }
// let the frontend handle checking everything else // Let the frontend handle everything else
return ErrorFailedInit; return ErrorFailedInit;
} }
FirmwareManager::FirmwareCheckResult FirmwareManager::VerifyFirmware(Core::System &system) FirmwareManager::FirmwareCheckResult FirmwareManager::VerifyFirmware(Core::System &system) {
{
if (!CheckFirmwarePresence(system)) { if (!CheckFirmwarePresence(system)) {
return ErrorFirmwareMissing; return ErrorFirmwareMissing;
} else { } else {