Skip to content
This repository
Browse code

jni: fix crashes when finding external storage. Regression from jni m…

…erge.
  • Loading branch information...
commit 8bb651f9541ef2a2614d1ab236eb9a8b4816ecb6 1 parent 1350ccb
authored May 14, 2013

Showing 1 changed file with 34 additions and 16 deletions. Show diff stats Hide diff stats

  1. 50  xbmc/android/activity/XBMCApp.cpp
50  xbmc/android/activity/XBMCApp.cpp
@@ -398,18 +398,32 @@ bool CXBMCApp::GetExternalStorage(std::string &path, const std::string &type /*
398 398
   std::string sType;
399 399
   std::string mountedState;
400 400
   bool mounted = false;
401  
-  if (type == "music")
402  
-    sType = "Music"; // Environment.DIRECTORY_MUSIC
403  
-  else if (type == "videos")
404  
-    sType = "Movies"; // Environment.DIRECTORY_MOVIES
405  
-  else if (type == "pictures")
406  
-    sType = "Pictures"; // Environment.DIRECTORY_PICTURES
407  
-  else if (type == "photos")
408  
-    sType = "DCIM"; // Environment.DIRECTORY_DCIM
409  
-  else if (type == "downloads")
410  
-    sType = "Download"; // Environment.DIRECTORY_DOWNLOADS
411  
-
412  
-  path = CJNIEnvironment::getExternalStoragePublicDirectory(sType).getAbsolutePath();
  401
+
  402
+  if(type == "files" || type.empty())
  403
+  {
  404
+    CJNIFile external = CJNIEnvironment::getExternalStorageDirectory();
  405
+    if (external)
  406
+      path = external.getAbsolutePath();
  407
+  }
  408
+  else
  409
+  {
  410
+    if (type == "music")
  411
+      sType = "Music"; // Environment.DIRECTORY_MUSIC
  412
+    else if (type == "videos")
  413
+      sType = "Movies"; // Environment.DIRECTORY_MOVIES
  414
+    else if (type == "pictures")
  415
+      sType = "Pictures"; // Environment.DIRECTORY_PICTURES
  416
+    else if (type == "photos")
  417
+      sType = "DCIM"; // Environment.DIRECTORY_DCIM
  418
+    else if (type == "downloads")
  419
+      sType = "Download"; // Environment.DIRECTORY_DOWNLOADS
  420
+    if (!sType.empty())
  421
+    {
  422
+      CJNIFile external = CJNIEnvironment::getExternalStoragePublicDirectory(sType);
  423
+      if (external)
  424
+        path = external.getAbsolutePath();
  425
+    }
  426
+  }
413 427
   mountedState = CJNIEnvironment::getExternalStorageState();
414 428
   mounted = (mountedState == "mounted" || mountedState == "mounted_ro");
415 429
   return mounted && !path.empty();
@@ -509,11 +523,15 @@ void CXBMCApp::SetupEnv()
509 523
   setenv("XBMC_BIN_HOME", (cacheDir + "/apk/assets").c_str(), 0);
510 524
   setenv("XBMC_HOME", (cacheDir + "/apk/assets").c_str(), 0);
511 525
 
512  
-  std::string externalDir = getExternalFilesDir("").getAbsolutePath();
513  
-  if (!externalDir.size())
514  
-    externalDir = getDir("org.xbmc.xbmc", 1).getAbsolutePath();
  526
+  std::string externalDir;
  527
+  CJNIFile androidPath = getExternalFilesDir("");
  528
+  if (!androidPath)
  529
+    androidPath = getDir("org.xbmc.xbmc", 1);
  530
+
  531
+  if (androidPath)
  532
+    externalDir = androidPath.getAbsolutePath();
515 533
 
516  
-  if (externalDir.size())
  534
+  if (!externalDir.empty())
517 535
     setenv("HOME", externalDir.c_str(), 0);
518 536
   else
519 537
     setenv("HOME", getenv("XBMC_TEMP"), 0);

0 notes on commit 8bb651f

Please sign in to comment.
Something went wrong with that request. Please try again.