Commit 70e74112 authored by Geoffrey Métais's avatar Geoffrey Métais

Ensure Medialibrary is started only once

(cherry picked from commit 154f0c66)
parent 4a7c26f7
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment