Skip to content
Snippets Groups Projects
Commit 154f0c66 authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

Ensure Medialibrary is started only once

parent 5f6a9be3
No related branches found
No related tags found
No related merge requests found
Pipeline #10086 passed with stage
in 23 minutes and 44 seconds
......@@ -49,6 +49,7 @@ public class Medialibrary extends AbstractMedialibrary {
public int init(Context context) {
if (context == null) return ML_INIT_FAILED;
if (mIsInitiated) return ML_INIT_ALREADY_INITIALIZED;
sContext = context;
final File extFilesDir = context.getExternalFilesDir(null);
File dbDirectory = context.getDir("db", Context.MODE_PRIVATE);
......@@ -92,6 +93,7 @@ public class Medialibrary extends AbstractMedialibrary {
}
public void start() {
if (isStarted()) return;
nativeStart();
isMedialibraryStarted = true;
synchronized (onMedialibraryReadyListeners) {
......
......@@ -420,9 +420,11 @@ class MediaParsingService : Service(), DevicesDiscoveryCb, CoroutineScope, Lifec
var shouldInit = !dbExists()
val initCode = medialibrary.init(context)
medialibrary.exceptionHandler = exceptionHandler
shouldInit = shouldInit or (initCode == AbstractMedialibrary.ML_INIT_DB_RESET) or (initCode == AbstractMedialibrary.ML_INIT_DB_CORRUPTED)
if (initCode != AbstractMedialibrary.ML_INIT_FAILED) initMedialib(action.parse, context, shouldInit, action.upgrade)
else exitCommand()
if (initCode != AbstractMedialibrary.ML_INIT_ALREADY_INITIALIZED) {
shouldInit = shouldInit or (initCode == AbstractMedialibrary.ML_INIT_DB_RESET) or (initCode == AbstractMedialibrary.ML_INIT_DB_CORRUPTED)
if (initCode != AbstractMedialibrary.ML_INIT_FAILED) initMedialib(action.parse, context, shouldInit, action.upgrade)
else exitCommand()
} else exitCommand()
}
is StartScan -> {
scanActivated = true
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment