[Android] Implement the new clear medialibrary database return value
Nicolas Pomepuy
git at videolan.org
Wed Oct 6 07:04:13 UTC 2021
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Oct 5 13:25:04 2021 +0200| [4b1aacda0f5812b22f2bed19adadb50f6d58d88f] | committer: Nicolas Pomepuy
Implement the new clear medialibrary database return value
> https://code.videolan.org/videolan/vlc-android/commit/4b1aacda0f5812b22f2bed19adadb50f6d58d88f
---
application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt | 4 +++-
medialibrary/jni/AndroidMediaLibrary.cpp | 4 ++--
medialibrary/jni/AndroidMediaLibrary.h | 2 +-
medialibrary/jni/medialibrary.cpp | 2 +-
medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java | 5 +++--
.../src/org/videolan/medialibrary/interfaces/Medialibrary.java | 1 +
6 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt b/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
index 4469ccfac..002e37e6e 100644
--- a/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
+++ b/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
@@ -471,7 +471,9 @@ class MediaParsingService : LifecycleService(), DevicesDiscoveryCb {
val initCode = medialibrary.init(context)
medialibrary.setLibVLCInstance((VLCInstance.getInstance(context) as LibVLC).getInstance())
medialibrary.setDiscoverNetworkEnabled(true)
- if (initCode != Medialibrary.ML_INIT_ALREADY_INITIALIZED) {
+ if (initCode == Medialibrary.ML_INIT_DB_UNRECOVERABLE) {
+ throw IllegalStateException("Medialibrary DB file is corrupted and unrecoverable")
+ } else if (initCode != Medialibrary.ML_INIT_ALREADY_INITIALIZED) {
shouldInit = shouldInit or (initCode == Medialibrary.ML_INIT_DB_RESET) or (initCode == Medialibrary.ML_INIT_DB_CORRUPTED)
if (initCode != Medialibrary.ML_INIT_FAILED) initMedialib(action.parse, context, shouldInit, action.upgrade, action.removeDevices)
else exitCommand()
diff --git a/medialibrary/jni/AndroidMediaLibrary.cpp b/medialibrary/jni/AndroidMediaLibrary.cpp
index 26ed48d6e..708859239 100644
--- a/medialibrary/jni/AndroidMediaLibrary.cpp
+++ b/medialibrary/jni/AndroidMediaLibrary.cpp
@@ -62,9 +62,9 @@ AndroidMediaLibrary::start()
}
-void
+bool
AndroidMediaLibrary::clearDatabase(bool restorePlaylists) {
- p_ml->clearDatabase(restorePlaylists);
+ return p_ml->clearDatabase(restorePlaylists);
}
void
diff --git a/medialibrary/jni/AndroidMediaLibrary.h b/medialibrary/jni/AndroidMediaLibrary.h
index f206300e5..429ffc712 100644
--- a/medialibrary/jni/AndroidMediaLibrary.h
+++ b/medialibrary/jni/AndroidMediaLibrary.h
@@ -35,7 +35,7 @@ public:
bool isDeviceKnown(const std::string& uuid, const std::string& path, bool removable);
bool deleteRemovableDevices();
void addDevice(const std::string& uuid, const std::string& path, bool removable);
- void clearDatabase(bool restorePlaylists);
+ bool clearDatabase(bool restorePlaylists);
std::vector<std::tuple<std::string, std::string, bool>> devices();
bool removeDevice(const std::string& uuid, const std::string& path);
void banFolder(const std::string& path);
diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index 48f8af1bb..c5a12edde 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -1992,7 +1992,7 @@ static JNINativeMethod methods[] = {
{"nativeInit", "(Ljava/lang/String;Ljava/lang/String;)I", (void*)init },
{"nativeStart", "()V", (void*)start },
{"nativeRelease", "()V", (void*)release },
- {"nativeClearDatabase", "(Z)V", (void*)clearDatabase },
+ {"nativeClearDatabase", "(Z)Z", (void*)clearDatabase },
{"nativeAddDevice", "(Ljava/lang/String;Ljava/lang/String;Z)V", (void*)addDevice },
{"nativeIsDeviceKnown", "(Ljava/lang/String;Ljava/lang/String;Z)Z", (void*)isDeviceKnown },
{"nativeDeleteRemovableDevices", "()Z", (void*)deleteRemovableDevices },
diff --git a/medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java b/medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java
index f4910774c..0efc535dd 100644
--- a/medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java
+++ b/medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java
@@ -84,7 +84,8 @@ public class MedialibraryImpl extends Medialibrary {
int initCode = nativeInit(dbDirectory + VLC_MEDIA_DB_NAME, extFilesDir + MEDIALIB_FOLDER_NAME);
if (initCode == ML_INIT_DB_CORRUPTED) {
Log.e(TAG, "Medialib database is corrupted. Clearing it and try to restore playlists");
- nativeClearDatabase(true);
+ if (!nativeClearDatabase(true)) return ML_INIT_DB_UNRECOVERABLE;
+
}
mIsInitiated = initCode != ML_INIT_FAILED;
@@ -595,7 +596,7 @@ public class MedialibraryImpl extends Medialibrary {
private native void nativeStart();
private native void nativeRelease();
- private native void nativeClearDatabase(boolean keepPlaylist);
+ private native boolean nativeClearDatabase(boolean keepPlaylist);
private native void nativeBanFolder(String path);
private native void nativeUnbanFolder(String path);
private native void nativeAddDevice(String uuid, String path, boolean removable);
diff --git a/medialibrary/src/org/videolan/medialibrary/interfaces/Medialibrary.java b/medialibrary/src/org/videolan/medialibrary/interfaces/Medialibrary.java
index 5bd912016..52b39edf6 100644
--- a/medialibrary/src/org/videolan/medialibrary/interfaces/Medialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/interfaces/Medialibrary.java
@@ -86,6 +86,7 @@ abstract public class Medialibrary {
public static final int ML_INIT_FAILED = 2;
public static final int ML_INIT_DB_RESET = 3;
public static final int ML_INIT_DB_CORRUPTED = 4;
+ public static final int ML_INIT_DB_UNRECOVERABLE = 5;
public static final MediaWrapper[] EMPTY_COLLECTION = {};
public static final String VLC_MEDIA_DB_NAME = "/vlc_media.db";
More information about the Android
mailing list