-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Android: Call UICommon::Init at app start instead of emulation start #8190
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
47e1108
Android: Add helper class AfterDirectoryInitializationRunner
JosJuice 9f3f45a
Android: Call UICommon::Init at app start instead of emulation start
JosJuice c677268
Android: Don't use GameFile/GameFileCache before UICommon::Init
JosJuice f79ca65
UICommon: Remove Android hacks from GameFile
JosJuice File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...app/src/main/java/org/dolphinemu/dolphinemu/utils/AfterDirectoryInitializationRunner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.dolphinemu.dolphinemu.utils; | ||
|
||
import android.content.Context; | ||
import android.content.IntentFilter; | ||
import android.support.v4.content.LocalBroadcastManager; | ||
|
||
public class AfterDirectoryInitializationRunner | ||
{ | ||
private DirectoryStateReceiver directoryStateReceiver; | ||
|
||
/** | ||
* Executes a Runnable after directory initialization has finished. | ||
* | ||
* If this is called when directory initialization already is done, | ||
* the Runnable will be executed immediately. If this is called before | ||
* directory initialization is done, the Runnable will be executed | ||
* after directory initialization finishes successfully, or never | ||
* in case directory initialization doesn't finish successfully. | ||
* | ||
* Calling this function multiple times per object is not supported. | ||
*/ | ||
public void run(Context context, Runnable runnable) | ||
{ | ||
if (!DirectoryInitialization.areDolphinDirectoriesReady()) | ||
{ | ||
// Wait for directories to get initialized | ||
IntentFilter statusIntentFilter = new IntentFilter( | ||
DirectoryInitialization.BROADCAST_ACTION); | ||
|
||
directoryStateReceiver = new DirectoryStateReceiver(directoryInitializationState -> | ||
{ | ||
if (directoryInitializationState == | ||
DirectoryInitialization.DirectoryInitializationState.DOLPHIN_DIRECTORIES_INITIALIZED) | ||
{ | ||
LocalBroadcastManager.getInstance(context).unregisterReceiver(directoryStateReceiver); | ||
directoryStateReceiver = null; | ||
runnable.run(); | ||
} | ||
}); | ||
// Registers the DirectoryStateReceiver and its intent filters | ||
LocalBroadcastManager.getInstance(context).registerReceiver( | ||
directoryStateReceiver, | ||
statusIntentFilter); | ||
} | ||
else | ||
{ | ||
runnable.run(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a 1:1 thing? It feels like it would just be a list of receivers, each notified in turn when something happens.
If it is indeed a list, I'd expect any older invocations to still be alive; rendering the last paragraph of the comment above slightly fuzzy.
Unless we want it to be like that; then we're probably supposed to call
unregisterReceiver
in casedirectoryStateReceiver
is notnull
....not that it matters too much, since you keep creating new instances in the places where it is used; so they'd likely end up running anyways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was assuming that the old
directoryStateReceiver
would get deallocated once we create a newdirectoryStateReceiver
, but I suppose that might not be true since theLocalBroadcastManager
keeps a reference to it... Since I'm not entirely sure how it works, I think I'll just change the comment to say that multiple calls is not a supported use case, because that's how I've been thinking of it while writing the code.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I'll just delete the part of the comment that mentions multiple calls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know, but if it works anything close to C# wrt the GC, it should still be referenced by the
LocalBroadcastManager
(and the closure itself should still be referencing the passedrunnable
, keeping it alive as well)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Disregard my previous comment – I've realized that multiple calls should not be encouraged, because if old
DirectoryStateReceiver
s indeed are kept around (which is likely), the way we do unregistration means that newer calls will get dropped rather than old calls. I will make the comment say that multiple calls is not a supported use case.