[Android] Advanced option to dump media library

Geoffrey Métais git at videolan.org
Thu Mar 1 15:53:37 CET 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Mar  1 15:53:11 2018 +0100| [a5cadec2f5e3edd2cf76366971ed27e31ae20c91] | committer: Geoffrey Métais

Advanced option to dump media library

> https://code.videolan.org/videolan/vlc-android/commit/a5cadec2f5e3edd2cf76366971ed27e31ae20c91
---

 vlc-android/res/values/strings.xml                 |  2 ++
 vlc-android/res/xml/preferences_adv.xml            |  6 ++++
 .../vlc/gui/preferences/PreferencesAdvanced.java   | 38 +++++++++++++++++++++-
 .../src/org/videolan/vlc/util/FileUtils.java       |  2 +-
 4 files changed, 46 insertions(+), 2 deletions(-)

diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index 3c2fcd918..b51d7ad2f 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -415,6 +415,8 @@
     <string name="save_video_always">Save speed across sessions</string>
     <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_media_db_summary">Copy database to internal storage root</string>
     <string name="clear_media_db">Clear media database</string>
     <string name="clear_media_db_summary">Access Android VLC info to clear data</string>
     <string name="clear_history">Clear search history</string>
diff --git a/vlc-android/res/xml/preferences_adv.xml b/vlc-android/res/xml/preferences_adv.xml
index 48c225a1a..7bf3fe683 100644
--- a/vlc-android/res/xml/preferences_adv.xml
+++ b/vlc-android/res/xml/preferences_adv.xml
@@ -16,6 +16,12 @@
         android:summary="@string/network_caching_summary"
         android:title="@string/network_caching" />
 
+    <Preference
+        android:enabled="true"
+        android:key="dump_media_db"
+        android:summary="@string/dump_media_db_summary"
+        android:title="@string/dump_media_db" />
+
     <Preference
         android:enabled="true"
         android:key="clear_media_db"
diff --git a/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesAdvanced.java b/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesAdvanced.java
index 496dc3941..647f31c3a 100644
--- a/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesAdvanced.java
+++ b/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesAdvanced.java
@@ -24,6 +24,7 @@
 package org.videolan.vlc.gui.preferences;
 
 import android.Manifest;
+import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.SharedPreferences;
@@ -34,15 +35,22 @@ import android.support.v7.app.AlertDialog;
 import android.support.v7.preference.EditTextPreference;
 import android.support.v7.preference.Preference;
 import android.text.TextUtils;
+import android.widget.Toast;
 
 import org.videolan.libvlc.util.AndroidUtil;
+import org.videolan.medialibrary.Medialibrary;
 import org.videolan.vlc.BuildConfig;
 import org.videolan.vlc.R;
 import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.gui.DebugLogActivity;
 import org.videolan.vlc.gui.helpers.UiTools;
+import org.videolan.vlc.util.AndroidDevices;
+import org.videolan.vlc.util.FileUtils;
+import org.videolan.vlc.util.Permissions;
 import org.videolan.vlc.util.VLCInstance;
 
+import java.io.File;
+
 public class PreferencesAdvanced extends BasePreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
     @Override
     protected int getXml() {
@@ -104,7 +112,7 @@ public class PreferencesAdvanced extends BasePreferenceFragment implements Share
                         .setNegativeButton(android.R.string.cancel, null).show();
                 return true;
             case "clear_media_db":
-                Intent i = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
+                final Intent i = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                 i.addCategory(Intent.CATEGORY_DEFAULT);
                 i.setData(Uri.parse("package:" + VLCApplication.getAppContext().getPackageName()));
                 startActivity(i);
@@ -112,6 +120,34 @@ public class PreferencesAdvanced extends BasePreferenceFragment implements Share
             case "quit_app":
                 android.os.Process.killProcess(android.os.Process.myPid());
                 return true;
+            case "dump_media_db":
+                VLCApplication.runBackground(new Runnable() {
+                    @Override
+                    public void run() {
+                        final Runnable dump = new Runnable() {
+                            @Override
+                            public void run() {
+                                final File db = new File(VLCApplication.getAppContext().getDir("db", Context.MODE_PRIVATE)+ Medialibrary.VLC_MEDIA_DB_NAME);
+                                if (FileUtils.copyFile(db, new File(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY+ Medialibrary.VLC_MEDIA_DB_NAME)))
+                                    VLCApplication.runOnMainThread(new Runnable() {
+                                        @Override
+                                        public void run() {
+                                            Toast.makeText(VLCApplication.getAppContext(), "Database dumped on internal storage root", Toast.LENGTH_LONG).show();
+                                        }
+                                    });
+                                else VLCApplication.runOnMainThread(new Runnable() {
+                                    @Override
+                                    public void run() {
+                                        Toast.makeText(VLCApplication.getAppContext(), "Failed to dumped database", Toast.LENGTH_LONG).show();
+                                    }
+                                });
+                            }
+                        };
+                        if (Permissions.canWriteStorage()) dump.run();
+                        else Permissions.askWriteStoragePermission(getActivity(), false, dump);
+                    }
+                });
+                return true;
         }
         return super.onPreferenceTreeClick(preference);
     }
diff --git a/vlc-android/src/org/videolan/vlc/util/FileUtils.java b/vlc-android/src/org/videolan/vlc/util/FileUtils.java
index 3428d4b6e..10fcac1b5 100644
--- a/vlc-android/src/org/videolan/vlc/util/FileUtils.java
+++ b/vlc-android/src/org/videolan/vlc/util/FileUtils.java
@@ -180,7 +180,7 @@ public class FileUtils {
         }
     }
 
-    private static boolean copyFile(File src, File dst){
+    public static boolean copyFile(File src, File dst){
         boolean ret = true;
         if (src.isDirectory()) {
             File[] filesList = src.listFiles();



More information about the Android mailing list