android: delay intent handling until storage perm is granted

This commit is contained in:
Flyinghead 2020-09-01 22:03:12 +02:00
parent d7b1ad61f3
commit 734514c1fe
2 changed files with 24 additions and 10 deletions

View File

@ -48,8 +48,10 @@ public abstract class BaseGLActivity extends Activity implements ActivityCompat.
protected Handler handler = new Handler(); protected Handler handler = new Handler();
public static byte[] syms; public static byte[] syms;
private boolean audioPermissionRequested = false; private boolean audioPermissionRequested = false;
private boolean storagePermissionGranted = false;
private boolean paused = true; private boolean paused = true;
private boolean resumedCalled = false; private boolean resumedCalled = false;
private String pendingIntentUrl;
@Override @Override
protected void onCreate(@Nullable Bundle savedInstanceState) { protected void onCreate(@Nullable Bundle savedInstanceState) {
@ -90,7 +92,7 @@ public abstract class BaseGLActivity extends Activity implements ActivityCompat.
setStorageDirectories(); setStorageDirectories();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !storagePermissionGranted) {
ActivityCompat.requestPermissions(this, ActivityCompat.requestPermissions(this,
new String[]{ new String[]{
Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE,
@ -117,7 +119,10 @@ public abstract class BaseGLActivity extends Activity implements ActivityCompat.
+ gameUri.getAuthority() + "/external_files", "/storage")); + gameUri.getAuthority() + "/external_files", "/storage"));
} }
if (gameUri != null) if (gameUri != null)
JNIdc.setGameUri(gameUri.toString()); if (storagePermissionGranted)
JNIdc.setGameUri(gameUri.toString());
else
pendingIntentUrl = gameUri.toString();
} }
} }
} }
@ -292,7 +297,13 @@ public abstract class BaseGLActivity extends Activity implements ActivityCompat.
JNIdc.setupMic(sip); JNIdc.setupMic(sip);
} }
else if (requestCode == STORAGE_PERM_REQUEST) { else if (requestCode == STORAGE_PERM_REQUEST) {
storagePermissionGranted = true;
setStorageDirectories(); setStorageDirectories();
if (pendingIntentUrl != null) {
JNIdc.setGameUri(pendingIntentUrl);
pendingIntentUrl = null;
}
//setup mic //setup mic
if (Emulator.micPluggedIn()) if (Emulator.micPluggedIn())
requestRecordAudioPermission(); requestRecordAudioPermission();

View File

@ -138,11 +138,10 @@ bool egl_makecurrent();
extern int screen_width,screen_height; extern int screen_width,screen_height;
static char gamedisk[256];
float vjoy_pos[15][8]; float vjoy_pos[15][8];
extern bool print_stats; extern bool print_stats;
extern bool game_started;
//stuff for saving prefs //stuff for saving prefs
jobject g_emulator; jobject g_emulator;
@ -245,19 +244,23 @@ JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_setGameUri(JNIEnv *en
{ {
// Get filename string from Java // Get filename string from Java
const char* file_path = env->GetStringUTFChars(fileName, 0); const char* file_path = env->GetStringUTFChars(fileName, 0);
INFO_LOG(BOOT, "Game Disk URI: '%s'", file_path); NOTICE_LOG(BOOT, "Game Disk URI: '%s'", file_path);
strncpy(gamedisk, strlen(file_path) >= 7 && !memcmp(file_path, "file://", 7) ? file_path + 7 : file_path, sizeof(gamedisk)); strncpy(settings.imgread.ImagePath, strlen(file_path) >= 7 && !memcmp(file_path, "file://", 7) ? file_path + 7 : file_path, sizeof(settings.imgread.ImagePath));
gamedisk[sizeof(gamedisk) - 1] = '\0'; settings.imgread.ImagePath[sizeof(settings.imgread.ImagePath) - 1] = '\0';
env->ReleaseStringUTFChars(fileName, file_path); env->ReleaseStringUTFChars(fileName, file_path);
// TODO game paused/settings/...
cfgSetVirtual("config", "image", file_path); if (game_started) {
dc_stop();
gui_state = Main;
game_started = false;
dc_reset(true);
}
} }
} }
//stuff for microphone //stuff for microphone
jobject sipemu; jobject sipemu;
jmethodID getmicdata; jmethodID getmicdata;
extern bool game_started;
//stuff for audio //stuff for audio
#define SAMPLE_COUNT 512 #define SAMPLE_COUNT 512