Merge pull request #10781 from hrydgard/preserve-config

Android: Reload the config after getting storage permission, and ask immediately.
This commit is contained in:
Henrik Rydgård 2018-03-24 14:18:37 +01:00 committed by GitHub
commit 8fe5223dd0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 27 deletions

View file

@ -929,7 +929,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.
}
@ -1089,7 +1089,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...
@ -1130,21 +1130,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());

View file

@ -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);
}

View file

@ -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());
}

View file

@ -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,