Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[droid] add vfs for listing android apps

The hostname/url stuff needs some help for sure.
  • Loading branch information...
commit 5660daa16ebf1783db9b4204d032dc9a3832a515 1 parent 94b7d21
Cory Fields authored
View
86 xbmc/filesystem/AndroidAppDirectory.cpp
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2012 Team XBMC
+ * http://www.xbmc.org
+ *
+ * This Program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This Program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XBMC; see the file COPYING. If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#include "system.h"
+
+#if defined(TARGET_ANDROID)
+#include "AndroidAppDirectory.h"
+#include "xbmc/android/activity/XBMCApp.h"
+#include "FileItem.h"
+#include "File.h"
+#include "utils/URIUtils.h"
+#include <vector>
+#include "utils/log.h"
+#include "URL.h"
+
+using namespace XFILE;
+using namespace std;
+
+CAndroidAppDirectory::CAndroidAppDirectory(void)
+{
+}
+
+CAndroidAppDirectory::~CAndroidAppDirectory(void)
+{
+}
+
+bool CAndroidAppDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items)
+{
+ CURL url(strPath);
+ CStdString dirname = url.GetFileName();
+ URIUtils::RemoveSlashAtEnd(dirname);
+ CLog::Log(LOGDEBUG, "CAndroidAppDirectory::GetDirectory: %s",dirname.c_str());
+ if (dirname == "apps")
+ {
+ vector<androidPackage> applications;
+ CXBMCApp::ListApplications(&applications);
+ if (!applications.size())
+ {
+ CLog::Log(LOGERROR, "CAndroidAppDirectory::GetDirectory Application lookup listing failed");
+ return false;
+ }
+ for(unsigned int i = 0; i < applications.size(); i++)
+ {
+ if (applications[i].packageName == "org.xbmc.xbmc")
+ continue;
+ CFileItemPtr pItem(new CFileItem(applications[i].packageName));
+ pItem->m_bIsFolder = false;
+ CStdString path;
+ path.Format("androidapp://%s/%s/%s", url.GetHostName(), dirname, applications[i].packageName);
+ pItem->SetPath(path);
+ pItem->SetLabel(applications[i].packageLabel);
+ pItem->SetThumbnailImage(path+".png");
+ items.Add(pItem);
+ }
+ return true;
+ }
+
+ CLog::Log(LOGERROR, "CAndroidAppDirectory::GetDirectory Failed to open %s",strPath.c_str());
+ return false;
+}
+
+bool CAndroidAppDirectory::IsAllowed(const CStdString& strFile) const
+{
+ // Entries are virtual, so we want them all.
+ return true;
+}
+
+#endif
View
41 xbmc/filesystem/AndroidAppDirectory.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2012 Team XBMC
+ * http://www.xbmc.org
+ *
+ * This Program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This Program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XBMC; see the file COPYING. If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#pragma once
+#if defined(TARGET_ANDROID)
+#include "IDirectory.h"
+#include "FileItem.h"
+namespace XFILE
+{
+
+class CAndroidAppDirectory :
+ public IDirectory
+{
+public:
+ CAndroidAppDirectory(void);
+ virtual ~CAndroidAppDirectory(void);
+ virtual bool GetDirectory(const CStdString& strPath, CFileItemList &items);
+ virtual bool Exists(const char* strPath) { return true; };
+ virtual bool IsAllowed(const CStdString& strFile) const;
+};
+}
+#endif
+
View
103 xbmc/filesystem/AndroidAppFile.cpp
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2012 Team XBMC
+ * http://www.xbmc.org
+ *
+ * This Program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This Program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XBMC; see the file COPYING. If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#include "system.h"
+
+#if defined(TARGET_ANDROID)
+
+#include "AndroidAppFile.h"
+#include <sys/stat.h>
+#include "Util.h"
+#include "URL.h"
+#include "utils/log.h"
+#include "utils/URIUtils.h"
+#include <jni.h>
+#include "android/activity/XBMCApp.h"
+using namespace XFILE;
+
+CFileAndroidApp::CFileAndroidApp(void)
+{
+ m_iconWidth = 0;
+ m_iconHeight = 0;
+}
+
+CFileAndroidApp::~CFileAndroidApp(void)
+{
+ Close();
+}
+
+bool CFileAndroidApp::Open(const CURL& url)
+{
+
+ m_url = url;
+ m_appname = URIUtils::GetFileName(url.Get());
+ m_appname = m_appname.Left(m_appname.size() - 4);
+
+ return m_appname.size() > 0;
+}
+
+bool CFileAndroidApp::Exists(const CURL& url)
+{
+ return true;
+}
+
+unsigned int CFileAndroidApp::Read(void* lpBuf, int64_t uiBufSize)
+{
+ CXBMCApp::GetIcon(m_appname, lpBuf, uiBufSize);
+ return uiBufSize;
+}
+
+void CFileAndroidApp::Close()
+{
+}
+
+int64_t CFileAndroidApp::GetLength()
+{
+ CXBMCApp::GetIconSize(m_appname, &m_iconWidth, &m_iconHeight);
+ return m_iconWidth * m_iconHeight * 4;
+}
+
+unsigned int CFileAndroidApp::GetIconWidth()
+{
+ return m_iconWidth;
+}
+
+unsigned int CFileAndroidApp::GetIconHeight()
+{
+ return m_iconHeight;
+}
+
+int CFileAndroidApp::GetChunkSize()
+{
+ return 0;
+}
+int CFileAndroidApp::Stat(const CURL& url, struct __stat64* buffer)
+{
+ return 0;
+}
+int CFileAndroidApp::IoControl(EIoControl request, void* param)
+{
+ if(request == IOCTRL_SEEK_POSSIBLE)
+ return 0;
+ return 1;
+}
+#endif
+
View
62 xbmc/filesystem/AndroidAppFile.h
@@ -0,0 +1,62 @@
+#pragma once
+/*
+ * Copyright (C) 2012 Team XBMC
+ * http://www.xbmc.org
+ *
+ * This Program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This Program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XBMC; see the file COPYING. If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#include "system.h"
+
+#if defined(TARGET_ANDROID)
+#include "IFile.h"
+#include "URL.h"
+#include "utils/StdString.h"
+namespace XFILE
+{
+class CFileAndroidApp : public IFile
+{
+public:
+ CFileAndroidApp(void);
+ virtual ~CFileAndroidApp(void);
+ virtual bool Open(const CURL& url);
+ virtual bool Exists(const CURL& url);
+ virtual int Stat(const CURL& url, struct __stat64* buffer);
+
+ virtual unsigned int Read(void* lpBuf, int64_t uiBufSize);
+ virtual void Close();
+ virtual int64_t GetLength();
+ virtual int64_t Seek(int64_t, int) {return -1;};
+ virtual int64_t GetPosition() {return 0;};
+ virtual int GetChunkSize();
+ virtual int IoControl(EIoControl request, void* param);
+ unsigned int GetIconWidth();
+ unsigned int GetIconHeight();
+
+protected:
+ bool IsValidFile(const CURL& url);
+
+private:
+ CURL m_url;
+ CStdString m_appname;
+ int m_iconWidth;
+ int m_iconHeight;
+};
+}
+
+#endif
+
View
6 xbmc/filesystem/DirectoryFactory.cpp
@@ -106,6 +106,9 @@
#ifdef HAVE_LIBBLURAY
#include "BlurayDirectory.h"
#endif
+#if defined(TARGET_ANDROID)
+#include "AndroidAppDirectory.h"
+#endif
using namespace XFILE;
@@ -215,6 +218,9 @@ IDirectory* CDirectoryFactory::Create(const CStdString& strPath)
#ifdef HAVE_LIBBLURAY
if (strProtocol == "bluray") return new CBlurayDirectory();
#endif
+#if defined(TARGET_ANDROID)
+ if (strProtocol == "androidapp") return new CAndroidAppDirectory();
+#endif
}
CLog::Log(LOGWARNING, "%s - Unsupported protocol(%s) in %s", __FUNCTION__, strProtocol.c_str(), url.Get().c_str() );
View
6 xbmc/filesystem/FileFactory.cpp
@@ -71,6 +71,9 @@
#ifdef HAS_FILESYSTEM_AFP
#include "AFPFile.h"
#endif
+#if defined(TARGET_ANDROID)
+#include "AndroidAppFile.h"
+#endif
#include "UPnPFile.h"
#include "PipesManager.h"
#include "PipeFile.h"
@@ -183,6 +186,9 @@ IFile* CFileFactory::CreateLoader(const CURL& url)
#endif
else if (strProtocol == "pipe") return new CPipeFile();
else if (strProtocol == "upnp") return new CUPnPFile();
+#if defined(TARGET_ANDROID)
+ else if (strProtocol == "androidapp") return new CFileAndroidApp();
+#endif
}
CLog::Log(LOGWARNING, "%s - Unsupported protocol(%s) in %s", __FUNCTION__, strProtocol.c_str(), url.Get().c_str() );
View
2  xbmc/filesystem/Makefile.in
@@ -3,6 +3,8 @@ ARCH=@ARCH@
CXXFLAGS+=-D__STDC_FORMAT_MACROS \
SRCS=AddonsDirectory.cpp \
+ AndroidAppFile.cpp \
+ AndroidAppDirectory.cpp \
ASAPFileDirectory.cpp \
CacheStrategy.cpp \
CircularCache.cpp \
Please sign in to comment.
Something went wrong with that request. Please try again.