From fb152087773fba8c1f4a14bf78be186afe92157e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 24 Mar 2018 12:51:54 +0100 Subject: [PATCH] Android: Reload the config after getting storage permission, and ask immediately. Should help #10670 --- Core/Config.cpp | 12 ++++++------ UI/NativeApp.cpp | 24 ++++++++++++++++++++---- android/jni/app-android.cpp | 4 +--- ext/native/base/NativeApp.h | 14 -------------- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/Core/Config.cpp b/Core/Config.cpp index cf38a3c788..dfb2515cc7 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -920,7 +920,7 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) { IniFile iniFile; if (!iniFile.Load(iniFilename_)) { - ERROR_LOG(LOADER, "Failed to read %s. Setting config to default.", iniFilename_.c_str()); + ERROR_LOG(LOADER, "Failed to read '%s'. Setting config to default.", iniFilename_.c_str()); // Continue anyway to initialize the config. } @@ -1080,7 +1080,7 @@ void Config::Save() { CleanRecent(); IniFile iniFile; if (!iniFile.Load(iniFilename_.c_str())) { - ERROR_LOG(LOADER, "Error saving config - can't read ini %s", iniFilename_.c_str()); + ERROR_LOG(LOADER, "Error saving config - can't read ini '%s'", iniFilename_.c_str()); } // Need to do this somewhere... @@ -1121,21 +1121,21 @@ void Config::Save() { LogManager::GetInstance()->SaveConfig(log); if (!iniFile.Save(iniFilename_.c_str())) { - ERROR_LOG(LOADER, "Error saving config - can't write ini %s", iniFilename_.c_str()); + ERROR_LOG(LOADER, "Error saving config - can't write ini '%s'", iniFilename_.c_str()); System_SendMessage("toast", "Failed to save settings!\nCheck permissions, or try to restart the device."); return; } - INFO_LOG(LOADER, "Config saved: %s", iniFilename_.c_str()); + INFO_LOG(LOADER, "Config saved: '%s'", iniFilename_.c_str()); if (!bGameSpecific) //otherwise we already did this in saveGameConfig() { IniFile controllerIniFile; if (!controllerIniFile.Load(controllerIniFilename_.c_str())) { - ERROR_LOG(LOADER, "Error saving config - can't read ini %s", controllerIniFilename_.c_str()); + ERROR_LOG(LOADER, "Error saving config - can't read ini '%s'", controllerIniFilename_.c_str()); } KeyMap::SaveToIni(controllerIniFile); if (!controllerIniFile.Save(controllerIniFilename_.c_str())) { - ERROR_LOG(LOADER, "Error saving config - can't write ini %s", controllerIniFilename_.c_str()); + ERROR_LOG(LOADER, "Error saving config - can't write ini '%s'", controllerIniFilename_.c_str()); return; } INFO_LOG(LOADER, "Controller config saved: %s", controllerIniFilename_.c_str()); diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 9d50409539..6f5dcf48b6 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -138,6 +138,8 @@ static bool isOuya; static bool resized = false; static bool restarting = false; +static bool askedForStoragePermission = false; + struct PendingMessage { std::string msg; std::string value; @@ -369,6 +371,9 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch g_Config.AddSearchPath(user_data_path); g_Config.AddSearchPath(g_Config.memStickDirectory + "PSP/SYSTEM/"); g_Config.SetDefaultPath(g_Config.memStickDirectory + "PSP/SYSTEM/"); + + // Note that if we don't have storage permission here, loading the config will + // fail and it will be set to the default. Later, we load again when we get permission. g_Config.Load(); g_Config.externalDirectory = external_dir; #endif @@ -384,6 +389,8 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch File::CreateDir((g_Config.memStickDirectory + "PSP/GAME").c_str()); #endif + + const char *fileToLog = 0; const char *stateToLoad = 0; @@ -510,6 +517,13 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch else i18nrepo.LoadIni(g_Config.sLanguageIni, langOverridePath); + if (System_GetPropertyBool(SYSPROP_SUPPORTS_PERMISSIONS)) { + if (System_GetPermissionStatus(SYSTEM_PERMISSION_STORAGE) != PERMISSION_STATUS_GRANTED) { + System_AskForPermission(SYSTEM_PERMISSION_STORAGE); + } + } + + I18NCategory *des = GetI18NCategory("DesktopUI"); // Note to translators: do not translate this/add this to PPSSPP-lang's files. // It's intended to be custom for every user. @@ -925,6 +939,12 @@ void HandleGlobalMessage(const std::string &msg, const std::string &value) { Core_SetPowerSaving(value != "false"); } + if (msg == "permission_granted" && value == "storage") { + // We must have failed to load the config before, so load it now to avoid overwriting the old config + // with a freshly generated one. + ILOG("Reloading config after storage permission grant."); + g_Config.Load(); + } } void NativeUpdate() { @@ -1130,10 +1150,6 @@ void NativeShutdown() { // I think we handle most globals correctly or correct-enough now. } -void NativePermissionStatus(SystemPermission permission, PermissionStatus status) { - // TODO: Send this through the screen system? Nicer than listening to string messages -} - void PushNewGpsData(float latitude, float longitude, float altitude, float speed, float bearing, long long time) { GPS::setGpsData(latitude, longitude, altitude, speed, bearing, time); } diff --git a/android/jni/app-android.cpp b/android/jni/app-android.cpp index 335230f3ef..62dea04754 100644 --- a/android/jni/app-android.cpp +++ b/android/jni/app-android.cpp @@ -791,19 +791,17 @@ extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_sendMessage(JNIEnv *env ILOG("STORAGE PERMISSION: PENDING"); // TODO: Add support for other permissions permissions[SYSTEM_PERMISSION_STORAGE] = PERMISSION_STATUS_PENDING; - NativePermissionStatus(SYSTEM_PERMISSION_STORAGE, PERMISSION_STATUS_PENDING); } else if (msg == "permission_denied") { ILOG("STORAGE PERMISSION: DENIED"); permissions[SYSTEM_PERMISSION_STORAGE] = PERMISSION_STATUS_DENIED; - NativePermissionStatus(SYSTEM_PERMISSION_STORAGE, PERMISSION_STATUS_PENDING); } else if (msg == "permission_granted") { ILOG("STORAGE PERMISSION: GRANTED"); permissions[SYSTEM_PERMISSION_STORAGE] = PERMISSION_STATUS_GRANTED; - NativePermissionStatus(SYSTEM_PERMISSION_STORAGE, PERMISSION_STATUS_PENDING); } else if (msg == "sustained_perf_supported") { sustainedPerfSupported = true; } + // Ensures that the receiver can handle it on a sensible thread. NativeMessageReceived(msg.c_str(), prm.c_str()); } diff --git a/ext/native/base/NativeApp.h b/ext/native/base/NativeApp.h index dd07afb996..36ef2d3d8b 100644 --- a/ext/native/base/NativeApp.h +++ b/ext/native/base/NativeApp.h @@ -97,25 +97,11 @@ void NativeSetMixer(void* mixer); void NativeShutdownGraphics(); void NativeShutdown(); -// Called on app.onCreate and app.onDestroy (?). Tells the app to save/restore -// light state. If app was fully rebooted between these calls, it's okay if some minor -// state is lost (position in level) but the level currently playihg, or the song -// currently being edited, or whatever, should be restored properly. In this case, -// firstTime will be set so that appropriate action can be taken (or not taken when -// it's not set). -// -// Note that NativeRestore is always called on bootup. -void NativeRestoreState(bool firstTime); // onCreate -void NativeSaveState(); // onDestroy - -void NativePermissionStatus(SystemPermission permission, PermissionStatus status); - // Calls back into Java / SDL // These APIs must be implemented by every port (for example app-android.cpp, SDLMain.cpp). // You are free to call these. void SystemToast(const char *text); void ShowKeyboard(); -void ShowAd(int x, int y, bool center_x); // Vibrate either takes a number of milliseconds to vibrate unconditionally, // or you can specify these constants for "standard" feedback. On Android,