[Android] LibVLC: don't hardcode /data/data, ask android where it is

Sébastien Toque git at videolan.org
Sun May 12 14:39:57 CEST 2013


vlc-ports/android | branch: master | Sébastien Toque <xilasz at gmail.com> | Sat May 11 17:10:57 2013 +0200| [6114c1b4e23e5e2bcc9b26ab14a9625ea413ce71] | committer: Sébastien Toque

LibVLC: don't hardcode /data/data, ask android where it is

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=6114c1b4e23e5e2bcc9b26ab14a9625ea413ce71
---

 vlc-android/src/org/videolan/libvlc/LibVLC.java               |    9 +++++----
 vlc-android/src/org/videolan/libvlc/LibVlcUtil.java           |    5 +++--
 vlc-android/src/org/videolan/vlc/Util.java                    |    5 +++--
 vlc-android/src/org/videolan/vlc/gui/MainActivity.java        |    2 +-
 vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java |    2 +-
 5 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/vlc-android/src/org/videolan/libvlc/LibVLC.java b/vlc-android/src/org/videolan/libvlc/LibVLC.java
index 3a7df39..c1e5c8f 100644
--- a/vlc-android/src/org/videolan/libvlc/LibVLC.java
+++ b/vlc-android/src/org/videolan/libvlc/LibVLC.java
@@ -23,6 +23,7 @@ package org.videolan.libvlc;
 import java.util.ArrayList;
 import java.util.Map;
 
+import android.content.Context;
 import android.os.Build;
 import android.util.Log;
 import android.view.Surface;
@@ -148,11 +149,11 @@ public class LibVLC {
      */
     public native void setSurface(Surface f);
 
-    public static synchronized void restart() {
+    public static synchronized void restart(Context context) {
         if (sInstance != null) {
             try {
                 sInstance.destroy();
-                sInstance.init();
+                sInstance.init(context);
             } catch (LibVlcException lve) {
                 Log.e(TAG, "Unable to reinit libvlc: " + lve);
             }
@@ -217,11 +218,11 @@ public class LibVLC {
     /**
      * Initialize the libVLC class
      */
-    public void init() throws LibVlcException {
+    public void init(Context context) throws LibVlcException {
         Log.v(TAG, "Initializing LibVLC");
         mDebugLogBuffer = new StringBuffer();
         if (!mIsInitialized) {
-            if(!LibVlcUtil.hasCompatibleCPU()) {
+            if(!LibVlcUtil.hasCompatibleCPU(context)) {
                 Log.e(TAG, LibVlcUtil.getErrorMsg());
                 throw new LibVlcException();
             }
diff --git a/vlc-android/src/org/videolan/libvlc/LibVlcUtil.java b/vlc-android/src/org/videolan/libvlc/LibVlcUtil.java
index b44e29a..956a2eb 100644
--- a/vlc-android/src/org/videolan/libvlc/LibVlcUtil.java
+++ b/vlc-android/src/org/videolan/libvlc/LibVlcUtil.java
@@ -29,6 +29,7 @@ import java.io.RandomAccessFile;
 import java.nio.ByteBuffer;
 import java.nio.ByteOrder;
 
+import android.content.Context;
 import android.util.Log;
 
 public class LibVlcUtil {
@@ -65,12 +66,12 @@ public class LibVlcUtil {
         return errorMsg;
     }
 
-    public static boolean hasCompatibleCPU()
+    public static boolean hasCompatibleCPU(Context context)
     {
         // If already checked return cached result
         if(errorMsg != null || isCompatible) return isCompatible;
 
-        ElfData elf = readLib("/data/data/org.videolan.vlc/lib/libvlcjni.so");
+        ElfData elf = readLib(context.getFilesDir().getParent() +"/lib/libvlcjni.so");
         if(elf == null) {
             Log.e(TAG, "WARNING: Unable to read libvlcjni.so; cannot check device ABI!");
             Log.e(TAG, "WARNING: Cannot guarantee correct ABI for this build (may crash)!");
diff --git a/vlc-android/src/org/videolan/vlc/Util.java b/vlc-android/src/org/videolan/vlc/Util.java
index 363af57..a572dd3 100644
--- a/vlc-android/src/org/videolan/vlc/Util.java
+++ b/vlc-android/src/org/videolan/vlc/Util.java
@@ -70,9 +70,10 @@ public class Util {
         LibVLC instance = LibVLC.getExistingInstance();
         if (instance == null) {
             instance = LibVLC.getInstance();
-            SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext());
+            Context context = VLCApplication.getAppContext();
+            SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
             updateLibVlcSettings(pref);
-            instance.init();
+            instance.init(context);
         }
         return instance;
     }
diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index 7db6360..902b48d 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -105,7 +105,7 @@ public class MainActivity extends SherlockFragmentActivity {
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
-        if (!LibVlcUtil.hasCompatibleCPU()) {
+        if (!LibVlcUtil.hasCompatibleCPU(this)) {
             Log.e(TAG, LibVlcUtil.getErrorMsg());
             Intent i = new Intent(this, CompatErrorActivity.class);
             startActivity(i);
diff --git a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
index 1862f50..b06547a 100644
--- a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
@@ -206,7 +206,7 @@ public class PreferencesActivity extends PreferenceActivity implements OnSharedP
                 || key.equalsIgnoreCase("chroma_format")
                 || key.equalsIgnoreCase("enable_verbose_mode")) {
             Util.updateLibVlcSettings(sharedPreferences);
-            LibVLC.restart();
+            LibVLC.restart(this);
         }
     }
 



More information about the Android mailing list