[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

@ -202,8 +202,8 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
showNegativeButton = true, showNegativeButton = true,
positiveAction = { positiveAction = {
PreferenceManager.getDefaultSharedPreferences(applicationContext).edit() { PreferenceManager.getDefaultSharedPreferences(applicationContext).edit() {
putBoolean(Settings.PREF_SHOULD_SHOW_PRE_ALPHA_WARNING, false) putBoolean(Settings.PREF_SHOULD_SHOW_PRE_ALPHA_WARNING, false)
} }
}).show(supportFragmentManager, MessageDialogFragment.TAG) }).show(supportFragmentManager, MessageDialogFragment.TAG)
} }
} }
@ -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, ""
) != null
) {
if (NativeLibrary.reloadKeys()) {
Toast.makeText(
applicationContext, R.string.keys_install_success, Toast.LENGTH_SHORT
).show()
if (check) { if (resultCode == 0) {
homeViewModel.setCheckKeys(true) Toast.makeText(
applicationContext, R.string.keys_install_success, Toast.LENGTH_SHORT
).show()
val firstTimeSetup = gamesViewModel.reloadGames(true)
PreferenceManager.getDefaultSharedPreferences(applicationContext)
.getBoolean(Settings.PREF_FIRST_APP_LAUNCH, true)
if (!firstTimeSetup) {
homeViewModel.setCheckFirmware(true)
}
gamesViewModel.reloadGames(true) return
}
return true
} 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>

File diff suppressed because it is too large Load diff

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 {