diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index a5d9e0605a..7667bcab39 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -43,6 +43,7 @@ #endif #include "base/display.h" +#include "base/timeutil.h" #include "base/logging.h" #include "base/NativeApp.h" #include "file/vfs.h" @@ -394,6 +395,8 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch const char *fileToLog = 0; const char *stateToLoad = 0; + bool gotBootFilename = false; + // Parse command line LogTypes::LOG_LEVELS logLevel = LogTypes::LINFO; for (int i = 1; i < argc; i++) { @@ -435,18 +438,34 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch break; } } else { - if (boot_filename.empty()) { - ILOG("Boot filename found in args: %s", argv[i]); - boot_filename = argv[i]; -#ifdef _WIN32 - boot_filename = ReplaceAll(boot_filename, "\\", "/"); -#endif - skipLogo = true; + // This parameter should be a boot filename. Only accept it if we + // don't already have one. + if (!gotBootFilename) { + gotBootFilename = true; + ILOG("Boot filename found in args: '%s'", argv[i]); - std::unique_ptr fileLoader(ConstructFileLoader(boot_filename)); - if (!fileLoader->Exists()) { - fprintf(stderr, "File not found: %s\n", boot_filename.c_str()); - exit(1); + bool okToLoad = true; + if (System_GetPropertyBool(SYSPROP_SUPPORTS_PERMISSIONS)) { + PermissionStatus status = System_GetPermissionStatus(SYSTEM_PERMISSION_STORAGE); + if (status != PERMISSION_STATUS_GRANTED) { + ELOG("Storage permission not granted. Launching without argument."); + okToLoad = false; + } else { + ILOG("Storage permission granted."); + } + } + if (okToLoad) { + boot_filename = argv[i]; +#ifdef _WIN32 + boot_filename = ReplaceAll(boot_filename, "\\", "/"); +#endif + skipLogo = true; + + std::unique_ptr fileLoader(ConstructFileLoader(boot_filename)); + if (!fileLoader->Exists()) { + fprintf(stderr, "File not found: %s\n", boot_filename.c_str()); + exit(1); + } } } else { fprintf(stderr, "Can only boot one file"); diff --git a/android/jni/app-android.cpp b/android/jni/app-android.cpp index 41745a5151..197dfec98d 100644 --- a/android/jni/app-android.cpp +++ b/android/jni/app-android.cpp @@ -600,6 +600,9 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeApp_init setCurrentThreadName("androidInit"); + // Makes sure we get early permission grants. + ProcessFrameCommands(env); + ILOG("NativeApp.init() -- begin"); PROFILE_INIT(); diff --git a/android/src/org/ppsspp/ppsspp/NativeActivity.java b/android/src/org/ppsspp/ppsspp/NativeActivity.java index 58e748410f..0f70d98124 100644 --- a/android/src/org/ppsspp/ppsspp/NativeActivity.java +++ b/android/src/org/ppsspp/ppsspp/NativeActivity.java @@ -197,6 +197,8 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C // Let's start out granted if it was granted already. if (this.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { NativeApp.sendMessage("permission_granted", "storage"); + } else { + NativeApp.sendMessage("permission_denied", "storage"); } } }