Skip to content

Commit

Permalink
FIX: [droid] rework storage provider
Browse files Browse the repository at this point in the history
  • Loading branch information
koying committed May 1, 2015
1 parent d1a2c33 commit c060ef6
Showing 1 changed file with 63 additions and 32 deletions.
95 changes: 63 additions & 32 deletions xbmc/storage/android/AndroidStorageProvider.cpp
Expand Up @@ -29,11 +29,29 @@
#include "filesystem/File.h"
#include "filesystem/Directory.h"

#include "Util.h"
#include "utils/log.h"
#include "utils/RegExp.h"
#include "utils/StringUtils.h"
#include "utils/URIUtils.h"

static const char * typeWL[] = { "vfat", "exfat", "sdcardfs", "fuse", "ntfs", "fat32", "ext3", "ext4", "esdfs" };
static const char * mountWL[] = { "/mnt", "/Removable", "/storage" };
static const char * mountBL[] = {
"/mnt/secure",
"/mnt/shell",
"/mnt/asec",
"/mnt/obb",
"/mnt/media_rw/extSdCard",
"/mnt/media_rw/sdcard",
"/storage/emulated"
};
static const char * deviceWL[] = {
"/dev/block/vold",
"/dev/fuse",
"/mnt/media_rw"
};

CAndroidStorageProvider::CAndroidStorageProvider()
{
m_removableLength = 0;
Expand Down Expand Up @@ -103,9 +121,8 @@ void CAndroidStorageProvider::GetRemovableDrives(VECSOURCES &removableDrives)
// mounted usb disks
char* buf = NULL;
FILE* pipe;
std::map<std::string, std::string> result;
CRegExp reMount;
reMount.RegComp("^(.+?)\\s+(.+?)\\s+(.+?)\\s");
reMount.RegComp("^(.+?)\\s+(.+?)\\s+(.+?)\\s+(.+?)\\s");

/* /proc/mounts is only guaranteed atomic for the current read
* operation, so we need to read it all at once.
Expand Down Expand Up @@ -157,43 +174,57 @@ void CAndroidStorageProvider::GetRemovableDrives(VECSOURCES &removableDrives)
{
if (reMount.RegFind(line) != -1)
{
bool accepted = false;
std::string device = reMount.GetReplaceString("\\1");
std::string deviceStr = reMount.GetReplaceString("\\1");
std::string mountStr = reMount.GetReplaceString("\\2");
std::string fsStr = reMount.GetReplaceString("\\3");
const char* fs = fsStr.c_str();

// Here we choose which filesystems are approved
if (strcmp(fs, "fuseblk") == 0 || strcmp(fs, "vfat") == 0
|| strcmp(fs, "ext2") == 0 || strcmp(fs, "ext3") == 0 || strcmp(fs, "ext4") == 0
|| strcmp(fs, "reiserfs") == 0 || strcmp(fs, "xfs") == 0
|| strcmp(fs, "ntfs-3g") == 0 || strcmp(fs, "iso9660") == 0
|| strcmp(fs, "exfat") == 0
|| strcmp(fs, "fusefs") == 0 || strcmp(fs, "hfs") == 0)
accepted = true;

// Ignore sdcards
if (!StringUtils::StartsWith(device, "/dev/block/vold/") ||
mountStr.find("sdcard") != std::string::npos ||
mountStr.find("secure/asec") != std::string::npos)
accepted = false;

if(accepted)
result[device] = mountStr;
std::string optStr = reMount.GetReplaceString("\\4");

// Blacklist
bool bl_ok = true;

// Reject root only
if (optStr.find("user_id=0") != std::string::npos)
bl_ok = false;

// What mount points are rejected
for (unsigned int i=0; i < ARRAY_SIZE(mountBL); ++i)
if (StringUtils::StartsWithNoCase(mountStr, mountBL[i]))
bl_ok = false;

if (bl_ok)
{
// What filesystems are accepted
bool fsok = false;
for (unsigned int i=0; i < ARRAY_SIZE(typeWL); ++i)
if (StringUtils::EqualsNoCase(fsStr, typeWL[i]))
continue;

// What devices are accepted
bool devok = false;
for (unsigned int i=0; i < ARRAY_SIZE(deviceWL); ++i)
if (StringUtils::StartsWithNoCase(deviceStr, deviceWL[i]))
devok = true;

// What mount points are accepted
bool mountok = false;
for (unsigned int i=0; i < ARRAY_SIZE(mountWL); ++i)
if (StringUtils::StartsWithNoCase(mountStr, mountWL[i]))
mountok = true;

if(devok && (fsok || mountok))
{
CMediaSource share;
share.strPath = unescape(mountStr);
share.strName = URIUtils::GetFileName(mountStr);
share.m_ignore = true;
removableDrives.push_back(share);
}
}
}
line = strtok_r(NULL, "\n", &saveptr);
}
free(buf);
}

for (std::map<std::string, std::string>::const_iterator i = result.begin(); i != result.end(); ++i)
{
CMediaSource share;
share.strPath = unescape(i->second);
share.strName = URIUtils::GetFileName(share.strPath);
share.m_ignore = true;
removableDrives.push_back(share);
}
}

std::vector<std::string> CAndroidStorageProvider::GetDiskUsage()
Expand Down

0 comments on commit c060ef6

Please sign in to comment.