Merge pull request #9079 from JosJuice/android-permissions-check

Android: Check for granted permission when returning to MainActivity
This commit is contained in:
LC 2020-09-13 10:37:58 -04:00 committed by GitHub
commit a481a52972
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 4 deletions

View File

@ -25,7 +25,7 @@ public class DolphinApplication extends Application
Java_GCAdapter.manager = (UsbManager) getSystemService(Context.USB_SERVICE); Java_GCAdapter.manager = (UsbManager) getSystemService(Context.USB_SERVICE);
Java_WiimoteAdapter.manager = (UsbManager) getSystemService(Context.USB_SERVICE); Java_WiimoteAdapter.manager = (UsbManager) getSystemService(Context.USB_SERVICE);
if (PermissionsHandler.hasWriteAccess(getApplicationContext())) if (DirectoryInitialization.shouldStart(getApplicationContext()))
DirectoryInitialization.start(getApplicationContext()); DirectoryInitialization.start(getApplicationContext());
} }

View File

@ -80,7 +80,16 @@ public final class MainActivity extends AppCompatActivity implements MainView
protected void onResume() protected void onResume()
{ {
super.onResume(); super.onResume();
if (DirectoryInitialization.shouldStart(this))
{
DirectoryInitialization.start(this);
new AfterDirectoryInitializationRunner()
.run(this, false, this::setPlatformTabsAndStartGameFileCacheService);
}
mPresenter.addDirIfNeeded(this); mPresenter.addDirIfNeeded(this);
if (sShouldRescanLibrary) if (sShouldRescanLibrary)
{ {
GameFileCacheService.startRescan(this); GameFileCacheService.startRescan(this);

View File

@ -63,7 +63,15 @@ public final class TvMainActivity extends FragmentActivity implements MainView
protected void onResume() protected void onResume()
{ {
super.onResume(); super.onResume();
if (DirectoryInitialization.shouldStart(this))
{
DirectoryInitialization.start(this);
GameFileCacheService.startLoad(this);
}
mPresenter.addDirIfNeeded(this); mPresenter.addDirIfNeeded(this);
if (sShouldRescanLibrary) if (sShouldRescanLibrary)
{ {
GameFileCacheService.startRescan(this); GameFileCacheService.startRescan(this);

View File

@ -53,6 +53,9 @@ public final class DirectoryInitialization
public static void start(Context context) public static void start(Context context)
{ {
if (!isDolphinDirectoryInitializationRunning.compareAndSet(false, true))
return;
// Can take a few seconds to run, so don't block UI thread. // Can take a few seconds to run, so don't block UI thread.
//noinspection TrivialFunctionalExpressionUsage //noinspection TrivialFunctionalExpressionUsage
((Runnable) () -> init(context)).run(); ((Runnable) () -> init(context)).run();
@ -60,9 +63,6 @@ public final class DirectoryInitialization
private static void init(Context context) private static void init(Context context)
{ {
if (!isDolphinDirectoryInitializationRunning.compareAndSet(false, true))
return;
if (directoryState != DirectoryInitializationState.DOLPHIN_DIRECTORIES_INITIALIZED) if (directoryState != DirectoryInitializationState.DOLPHIN_DIRECTORIES_INITIALIZED)
{ {
if (PermissionsHandler.hasWriteAccess(context)) if (PermissionsHandler.hasWriteAccess(context))
@ -196,6 +196,12 @@ public final class DirectoryInitialization
} }
} }
public static boolean shouldStart(Context context)
{
return !isDolphinDirectoryInitializationRunning.get() &&
getDolphinDirectoriesState(context) == DirectoryInitializationState.NOT_YET_INITIALIZED;
}
public static boolean areDolphinDirectoriesReady() public static boolean areDolphinDirectoriesReady()
{ {
return directoryState == DirectoryInitializationState.DOLPHIN_DIRECTORIES_INITIALIZED; return directoryState == DirectoryInitializationState.DOLPHIN_DIRECTORIES_INITIALIZED;