[Android] Allow dumping the room database
Nicolas Pomepuy
git at videolan.org
Tue Aug 9 10:03:54 UTC 2022
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Aug 9 08:10:58 2022 +0200| [e7e77b063108e5115be68c614bb7da32827b1954] | committer: Duncan McNamara
Allow dumping the room database
> https://code.videolan.org/videolan/vlc-android/commit/e7e77b063108e5115be68c614bb7da32827b1954
---
.../main/java/org/videolan/resources/Constants.kt | 4 +++-
.../resources/src/main/res/values/strings.xml | 1 +
.../ui/preferences/PreferencesAdvanced.kt | 18 +++++++++++++++++
.../vlc-android/res/xml/preferences_adv.xml | 6 ++++++
.../vlc/gui/preferences/PreferencesAdvanced.kt | 23 ++++++++++++++++++++++
.../src/org/videolan/vlc/util/FileUtils.kt | 6 ++++--
6 files changed, 55 insertions(+), 3 deletions(-)
diff --git a/application/resources/src/main/java/org/videolan/resources/Constants.kt b/application/resources/src/main/java/org/videolan/resources/Constants.kt
index b1956b270..aeabf3324 100644
--- a/application/resources/src/main/java/org/videolan/resources/Constants.kt
+++ b/application/resources/src/main/java/org/videolan/resources/Constants.kt
@@ -274,4 +274,6 @@ const val MOBILE_MAIN_ACTIVITY = "org.videolan.vlc.gui.MainActivity"
const val MOVIEPEDIA_ACTIVITY = "org.videolan.moviepedia.ui.MoviepediaActivity"
const val TV_AUDIOPLAYER_ACTIVITY = "org.videolan.television.ui.audioplayer.AudioPlayerActivity"
const val MEDIAPARSING_SERVICE = "org.videolan.vlc.MediaParsingService"
-const val TV_ONBOARDING_ACTIVITY = "org.videolan.television.ui.OnboardingActivity"
\ No newline at end of file
+const val TV_ONBOARDING_ACTIVITY = "org.videolan.television.ui.OnboardingActivity"
+
+const val ROOM_DATABASE = "/vlc_database.zip"
\ No newline at end of file
diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index 0cb23f4e4..17c08e24e 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -445,6 +445,7 @@
<string name="auto_rescan">Auto rescan</string>
<string name="auto_rescan_summary">Automatically scan device for new or deleted media at application startup</string>
<string name="dump_media_db">Dump media database</string>
+ <string name="dump_app_db">Dump app database</string>
<string name="dump_media_db_summary">Copy database to internal storage root</string>
<string name="clear_media_db">Clear media database</string>
<string name="clear_media_database_summary">Clears the database to start over</string>
diff --git a/application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesAdvanced.kt b/application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesAdvanced.kt
index 821926e40..350a577dc 100644
--- a/application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesAdvanced.kt
+++ b/application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesAdvanced.kt
@@ -199,6 +199,24 @@ class PreferencesAdvanced : BasePreferenceFragment(), SharedPreferences.OnShared
}
return true
}
+ "dump_app_db" -> {
+ val dst = File(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY + ROOM_DATABASE)
+ launch {
+ if ((activity as FragmentActivity).getWritePermission(Uri.fromFile(dst))) {
+ val copied = withContext(Dispatchers.IO) {
+ val db = File((activity as FragmentActivity).getDir("db", Context.MODE_PRIVATE).parent!! + "/databases")
+
+ val files = db.listFiles()?.map { it.path }?.toTypedArray()
+
+ if (files == null) false else
+ FileUtils.zip(files, dst.path)
+
+ }
+ Toast.makeText(activity, getString(if (copied) R.string.dump_db_succes else R.string.dump_db_failure), Toast.LENGTH_LONG).show()
+ }
+ }
+ return true
+ }
}
return super.onPreferenceTreeClick(preference)
}
diff --git a/application/vlc-android/res/xml/preferences_adv.xml b/application/vlc-android/res/xml/preferences_adv.xml
index 5437bdbb0..dd833ed0e 100644
--- a/application/vlc-android/res/xml/preferences_adv.xml
+++ b/application/vlc-android/res/xml/preferences_adv.xml
@@ -31,6 +31,12 @@
android:summary="@string/dump_media_db_summary"
android:title="@string/dump_media_db"/>
+ <Preference
+ android:enabled="true"
+ android:key="dump_app_db"
+ android:summary="@string/dump_media_db_summary"
+ android:title="@string/dump_app_db"/>
+
<Preference
android:enabled="true"
android:key="clear_media_db"
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesAdvanced.kt b/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesAdvanced.kt
index 63132c412..d5ecc5779 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesAdvanced.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesAdvanced.kt
@@ -195,6 +195,29 @@ class PreferencesAdvanced : BasePreferenceFragment(), SharedPreferences.OnShared
}
return true
}
+ "dump_app_db" -> {
+ val dst = File(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY + ROOM_DATABASE)
+ lifecycleScope.launch {
+ if (getWritePermission(Uri.fromFile(dst))) {
+ val copied = withContext(Dispatchers.IO) {
+ val db = File(requireContext().getDir("db", Context.MODE_PRIVATE).parent!! + "/databases")
+
+ val files = db.listFiles()?.map { it.path }?.toTypedArray()
+
+ if (files == null) false else
+ FileUtils.zip(files, dst.path)
+
+ }
+ if (copied)
+ UiTools.snackerConfirm(requireActivity(), getString(R.string.dump_db_succes), confirmMessage = R.string.share, overAudioPlayer = false) {
+ requireActivity().share(dst)
+ } else {
+ Toast.makeText(context, getString(R.string.dump_db_failure), Toast.LENGTH_LONG).show()
+ }
+ }
+ }
+ return true
+ }
"optional_features" -> {
loadFragment(PreferencesOptional())
return true
diff --git a/application/vlc-android/src/org/videolan/vlc/util/FileUtils.kt b/application/vlc-android/src/org/videolan/vlc/util/FileUtils.kt
index 121b23853..0330f1046 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/FileUtils.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/FileUtils.kt
@@ -481,8 +481,8 @@ object FileUtils {
}
const val BUFFER = 2048
- fun zip(files: Array<String>, zipFileName: String) {
- try {
+ fun zip(files: Array<String>, zipFileName: String):Boolean {
+ return try {
var origin: BufferedInputStream? = null
val dest = FileOutputStream(zipFileName)
val out = ZipOutputStream(BufferedOutputStream(
@@ -505,8 +505,10 @@ object FileUtils {
}
out.close()
+ true
} catch (e: Exception) {
e.printStackTrace()
+ false
}
}
More information about the Android
mailing list