[droid] add vfs for listing android apps
authorCory Fields <theuni-nospam-@xbmc.org>
Fri, 27 Jul 2012 04:15:42 +0000 (00:15 -0400)
committerCory Fields <theuni-nospam-@xbmc.org>
Wed, 8 Aug 2012 23:14:52 +0000 (19:14 -0400)
The hostname/url stuff needs some help for sure.

xbmc/filesystem/AndroidAppDirectory.cpp [new file with mode: 0644]
xbmc/filesystem/AndroidAppDirectory.h [new file with mode: 0644]
xbmc/filesystem/AndroidAppFile.cpp [new file with mode: 0644]
xbmc/filesystem/AndroidAppFile.h [new file with mode: 0644]
xbmc/filesystem/DirectoryFactory.cpp
xbmc/filesystem/FileFactory.cpp
xbmc/filesystem/Makefile.in

diff --git a/xbmc/filesystem/AndroidAppDirectory.cpp b/xbmc/filesystem/AndroidAppDirectory.cpp
new file mode 100644 (file)
index 0000000..f11286a
--- /dev/null
@@ -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
diff --git a/xbmc/filesystem/AndroidAppDirectory.h b/xbmc/filesystem/AndroidAppDirectory.h
new file mode 100644 (file)
index 0000000..00c5290
--- /dev/null
@@ -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
+
diff --git a/xbmc/filesystem/AndroidAppFile.cpp b/xbmc/filesystem/AndroidAppFile.cpp
new file mode 100644 (file)
index 0000000..c645488
--- /dev/null
@@ -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
+
diff --git a/xbmc/filesystem/AndroidAppFile.h b/xbmc/filesystem/AndroidAppFile.h
new file mode 100644 (file)
index 0000000..a4d4e98
--- /dev/null
@@ -0,0 +1,67 @@
+#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:
+  /*! \brief Currently only used for retrieving App Icons. */
+  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);
+
+  /*! \brief Return 32bit rgba raw bitmap. */
+  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);
+
+  /*! \brief Only valid after GetLength() has been called, usually by Open(). */
+  unsigned int GetIconWidth();
+  /*! \brief Only valid after GetLength() has been called, usually by Open(). */
+  unsigned int GetIconHeight();
+
+protected:
+  bool IsValidFile(const CURL& url);
+
+private:
+  CURL              m_url;
+  CStdString        m_appname;
+  int               m_iconWidth;
+  int               m_iconHeight;
+};
+}
+
+#endif
+
index 01b02be..00eb9a3 100644 (file)
 #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() );
index 4a4b7cb..9be1fb7 100644 (file)
@@ -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() );
index 68a80e5..b7519b7 100644 (file)
@@ -3,6 +3,8 @@ ARCH=@ARCH@
 CXXFLAGS+=-D__STDC_FORMAT_MACROS \
 
 SRCS=AddonsDirectory.cpp \
+     AndroidAppFile.cpp \
+     AndroidAppDirectory.cpp \
      ASAPFileDirectory.cpp \
      CacheStrategy.cpp \
      CircularCache.cpp \