summaryrefslogtreecommitdiff
path: root/Source/Android/app/src/main/java/org
diff options
context:
space:
mode:
authorJosJuice <josjuice@gmail.com>2021-03-16 22:58:23 +0100
committerJosJuice <josjuice@gmail.com>2021-03-16 22:58:23 +0100
commitac65c7970cd51bbeeb81ba796210344cae16affc (patch)
treec80da244565dbb76f1c7ef721c33ee943d76cf39 /Source/Android/app/src/main/java/org
parentf44f20560d2f97ab24532842e2595db55576b8e8 (diff)
Android: Fix rescanning on first app launch after cache clear
GameFileCacheService.startRescan (in MainPresenter.onResume) does nothing if called before GameFileCacheService.startLoad. Fixes a 3f71c36 regression where already added games would not show up after app launch under specific circumstances. Unfortunately the loading indicator still doesn't show up during a rescan initiated by app launch, but that would be more annoying to fix, so I will leave it for now.
Diffstat (limited to 'Source/Android/app/src/main/java/org')
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/services/GameFileCacheService.java54
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java4
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainPresenter.java2
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/TvMainActivity.java4
4 files changed, 41 insertions, 23 deletions
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/services/GameFileCacheService.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/services/GameFileCacheService.java
index 0abd072467..6d3ee84e52 100644
--- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/services/GameFileCacheService.java
+++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/services/GameFileCacheService.java
@@ -42,6 +42,7 @@ public final class GameFileCacheService extends IntentService
private static final AtomicReference<GameFile[]> gameFiles =
new AtomicReference<>(new GameFile[]{});
private static final AtomicInteger unhandledIntents = new AtomicInteger(0);
+ private static final AtomicInteger unhandledRescanIntents = new AtomicInteger(0);
public GameFileCacheService()
{
@@ -105,11 +106,22 @@ public final class GameFileCacheService extends IntentService
return new String[]{gameFile.getPath(), secondFile.getPath()};
}
+ /**
+ * Returns true if in the process of either loading the cache or rescanning.
+ */
public static boolean isLoading()
{
return unhandledIntents.get() != 0;
}
+ /**
+ * Returns true if in the process of rescanning.
+ */
+ public static boolean isRescanning()
+ {
+ return unhandledRescanIntents.get() != 0;
+ }
+
private static void startService(Context context, String action)
{
Intent intent = new Intent(context, GameFileCacheService.class);
@@ -137,6 +149,7 @@ public final class GameFileCacheService extends IntentService
public static void startRescan(Context context)
{
unhandledIntents.getAndIncrement();
+ unhandledRescanIntents.getAndIncrement();
new AfterDirectoryInitializationRunner().run(context, false,
() -> startService(context, ACTION_RESCAN));
@@ -173,29 +186,34 @@ public final class GameFileCacheService extends IntentService
}
// Rescan the file system and update the game list cache with the results
- if (ACTION_RESCAN.equals(intent.getAction()) && gameFileCache != null)
+ if (ACTION_RESCAN.equals(intent.getAction()))
{
- synchronized (gameFileCache)
+ if (gameFileCache != null)
{
- boolean changed = gameFileCache.update();
- if (changed)
- {
- updateGameFileArray();
- sendBroadcast(CACHE_UPDATED);
- }
-
- boolean additionalMetadataChanged = gameFileCache.updateAdditionalMetadata();
- if (additionalMetadataChanged)
+ synchronized (gameFileCache)
{
- updateGameFileArray();
- sendBroadcast(CACHE_UPDATED);
- }
-
- if (changed || additionalMetadataChanged)
- {
- gameFileCache.save();
+ boolean changed = gameFileCache.update();
+ if (changed)
+ {
+ updateGameFileArray();
+ sendBroadcast(CACHE_UPDATED);
+ }
+
+ boolean additionalMetadataChanged = gameFileCache.updateAdditionalMetadata();
+ if (additionalMetadataChanged)
+ {
+ updateGameFileArray();
+ sendBroadcast(CACHE_UPDATED);
+ }
+
+ if (changed || additionalMetadataChanged)
+ {
+ gameFileCache.save();
+ }
}
}
+
+ unhandledRescanIntents.decrementAndGet();
}
int intentsLeft = unhandledIntents.decrementAndGet();
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java
index 507f994fed..0418f453de 100644
--- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java
+++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java
@@ -82,8 +82,6 @@ public final class MainActivity extends AppCompatActivity
{
super.onResume();
- mPresenter.onResume();
-
if (DirectoryInitialization.shouldStart(this))
{
DirectoryInitialization.start(this);
@@ -91,6 +89,8 @@ public final class MainActivity extends AppCompatActivity
.run(this, false, this::setPlatformTabsAndStartGameFileCacheService);
}
+ mPresenter.onResume();
+
// In case the user changed a setting that affects how games are displayed,
// such as system language, cover downloading...
forEachPlatformGamesView(PlatformGamesView::refetchMetadata);
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainPresenter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainPresenter.java
index 72c91a5f99..ed02a6f22e 100644
--- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainPresenter.java
+++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainPresenter.java
@@ -132,7 +132,7 @@ public final class MainPresenter
mDirToAdd = null;
}
- if (sShouldRescanLibrary && !GameFileCacheService.isLoading())
+ if (sShouldRescanLibrary && !GameFileCacheService.isRescanning())
{
new AfterDirectoryInitializationRunner().run(mContext, false, () ->
{
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/TvMainActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/TvMainActivity.java
index 7f160df482..b03b894493 100644
--- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/TvMainActivity.java
+++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/TvMainActivity.java
@@ -71,14 +71,14 @@ public final class TvMainActivity extends FragmentActivity
{
super.onResume();
- mPresenter.onResume();
-
if (DirectoryInitialization.shouldStart(this))
{
DirectoryInitialization.start(this);
GameFileCacheService.startLoad(this);
}
+ mPresenter.onResume();
+
// In case the user changed a setting that affects how games are displayed,
// such as system language, cover downloading...
refetchMetadata();