Skip to content

Commit

Permalink
[Android] CAndroidStorageProvider::GetRemovableDrives() : Fix JNI cal…
Browse files Browse the repository at this point in the history
…l signature for StorageManager.getStorageVolumes.
  • Loading branch information
ksooo committed Apr 7, 2021
1 parent 9c31fd8 commit 90452f1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion tools/depends/target/libandroidjni/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ DEPS= ../../Makefile.include Makefile

# lib name, version
LIBNAME=libandroidjni
VERSION=ee5cc102101d9cb04ab4dbfd7a65db1c52345faf
VERSION=2b24db871a55a72897e3fedc354e1396ad01defd
SOURCE=archive
ARCHIVE=$(VERSION).tar.gz
GIT_BASE_URL=https://github.com/xbmc
Expand Down
17 changes: 15 additions & 2 deletions xbmc/platform/android/storage/AndroidStorageProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <androidjni/Context.h>
#include <androidjni/Environment.h>
#include <androidjni/StorageManager.h>
#include <androidjni/StorageVolume.h>

static const char * typeWL[] = { "vfat", "exfat", "sdcardfs", "fuse", "ntfs", "fat32", "ext3", "ext4", "esdfs", "cifs" };
static const char * mountWL[] = { "/mnt", "/Removable", "/storage" };
Expand Down Expand Up @@ -118,13 +119,13 @@ void CAndroidStorageProvider::GetLocalDrives(VECSOURCES &localDrives)

void CAndroidStorageProvider::GetRemovableDrives(VECSOURCES &removableDrives)
{
// Uses non-public API: be extra carefull
bool inError = false;
VECSOURCES droidDrives;

CJNIStorageManager manager(CJNIContext::getSystemService("storage"));
if (xbmc_jnienv()->ExceptionCheck())
{
xbmc_jnienv()->ExceptionDescribe();
xbmc_jnienv()->ExceptionClear();
inError = true;
}
Expand All @@ -134,25 +135,31 @@ void CAndroidStorageProvider::GetRemovableDrives(VECSOURCES &removableDrives)
CJNIStorageVolumes vols = manager.getStorageVolumes();
if (xbmc_jnienv()->ExceptionCheck())
{
xbmc_jnienv()->ExceptionDescribe();
xbmc_jnienv()->ExceptionClear();
inError = true;
}

if (!inError)
{
for (auto vol : vols)
for (int i = 0; i < vols.size(); ++i)
{
CJNIStorageVolume vol = vols.get(i);
// CLog::Log(LOGDEBUG, "-- Volume: %s(%s) -- %s", vol.getPath().c_str(), vol.getUserLabel().c_str(), vol.getState().c_str());

bool removable = vol.isRemovable();
if (xbmc_jnienv()->ExceptionCheck())
{
xbmc_jnienv()->ExceptionDescribe();
xbmc_jnienv()->ExceptionClear();
inError = true;
break;
}

std::string state = vol.getState();
if (xbmc_jnienv()->ExceptionCheck())
{
xbmc_jnienv()->ExceptionDescribe();
xbmc_jnienv()->ExceptionClear();
inError = true;
break;
Expand All @@ -161,23 +168,29 @@ void CAndroidStorageProvider::GetRemovableDrives(VECSOURCES &removableDrives)
if (removable && state == CJNIEnvironment::MEDIA_MOUNTED)
{
CMediaSource share;

share.strPath = vol.getPath();
if (xbmc_jnienv()->ExceptionCheck())
{
xbmc_jnienv()->ExceptionDescribe();
xbmc_jnienv()->ExceptionClear();
inError = true;
break;
}

share.strName = vol.getUserLabel();
if (xbmc_jnienv()->ExceptionCheck())
{
xbmc_jnienv()->ExceptionDescribe();
xbmc_jnienv()->ExceptionClear();
inError = true;
break;
}

StringUtils::Trim(share.strName);
if (share.strName.empty() || share.strName == "?" || StringUtils::EqualsNoCase(share.strName, "null"))
share.strName = URIUtils::GetFileName(share.strPath);

share.m_ignore = true;
droidDrives.push_back(share);
}
Expand Down

0 comments on commit 90452f1

Please sign in to comment.