Permalink
Browse files

Merge pull request #10167 from hrydgard/launch-without-permission-fix

Android: Fix #9704 where we'd hang if we lacked permission and got a filename as a command.
  • Loading branch information...
hrydgard committed Nov 21, 2017
2 parents 4628334 + b1fce1c commit d03bd75405b6ee7a7957aa86261971eb338e7d00
Showing with 33 additions and 9 deletions.
  1. +28 −9 UI/NativeApp.cpp
  2. +3 −0 android/jni/app-android.cpp
  3. +2 −0 android/src/org/ppsspp/ppsspp/NativeActivity.java
@@ -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];
// 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]);
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, "\\", "/");
boot_filename = ReplaceAll(boot_filename, "\\", "/");
#endif
skipLogo = true;
skipLogo = true;
std::unique_ptr<FileLoader> fileLoader(ConstructFileLoader(boot_filename));
if (!fileLoader->Exists()) {
fprintf(stderr, "File not found: %s\n", boot_filename.c_str());
exit(1);
std::unique_ptr<FileLoader> 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");
@@ -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();
@@ -197,6 +197,8 @@ public void sendInitialGrants() {
// 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");
}
}
}

0 comments on commit d03bd75

Please sign in to comment.