Merge pull request #9266 from JosJuice/android-startup-illegalstate

Android: Fix IllegalStateException on startup
This commit is contained in:
Léo Lam 2020-11-20 22:13:30 +01:00 committed by GitHub
commit 33f15f22e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 14 deletions

View File

@ -39,6 +39,7 @@ public final class DirectoryInitialization
private static final int WiimoteNewVersion = 5; // Last changed in PR 8907 private static final int WiimoteNewVersion = 5; // Last changed in PR 8907
private static volatile DirectoryInitializationState directoryState = private static volatile DirectoryInitializationState directoryState =
DirectoryInitializationState.NOT_YET_INITIALIZED; DirectoryInitializationState.NOT_YET_INITIALIZED;
private static volatile boolean areDirectoriesAvailable = false;
private static String userPath; private static String userPath;
private static String internalPath; private static String internalPath;
private static AtomicBoolean isDolphinDirectoryInitializationRunning = new AtomicBoolean(false); private static AtomicBoolean isDolphinDirectoryInitializationRunning = new AtomicBoolean(false);
@ -74,6 +75,8 @@ public final class DirectoryInitialization
NativeLibrary.Initialize(); NativeLibrary.Initialize();
NativeLibrary.ReportStartToAnalytics(); NativeLibrary.ReportStartToAnalytics();
areDirectoriesAvailable = true;
if (wiimoteIniWritten) if (wiimoteIniWritten)
{ {
// This has to be done after calling NativeLibrary.Initialize(), // This has to be done after calling NativeLibrary.Initialize(),
@ -229,32 +232,22 @@ public final class DirectoryInitialization
public static String getUserDirectory() public static String getUserDirectory()
{ {
if (directoryState == DirectoryInitializationState.NOT_YET_INITIALIZED) if (!areDirectoriesAvailable)
{
throw new IllegalStateException("DirectoryInitialization has to run at least once!");
}
else if (isDolphinDirectoryInitializationRunning.get())
{ {
throw new IllegalStateException( throw new IllegalStateException(
"DirectoryInitialization has to finish running first!"); "DirectoryInitialization must run before accessing the user directory!");
} }
return userPath; return userPath;
} }
public static String getDolphinInternalDirectory() public static String getDolphinInternalDirectory()
{ {
if (directoryState == DirectoryInitializationState.NOT_YET_INITIALIZED) if (!areDirectoriesAvailable)
{
throw new IllegalStateException("DirectoryInitialization has to run at least once!");
}
else if (isDolphinDirectoryInitializationRunning.get())
{ {
throw new IllegalStateException( throw new IllegalStateException(
"DirectoryInitialization has to finish running first!"); "DirectoryInitialization must run before accessing the internal directory!");
} }
return internalPath; return internalPath;
} }
private static void sendBroadcastState(DirectoryInitializationState state, Context context) private static void sendBroadcastState(DirectoryInitializationState state, Context context)