Merge pull request #5095 from koying/fixdroidappcrash
[vuplus_xbmc] / xbmc / filesystem / AndroidAppDirectory.cpp
1 /*
2  *      Copyright (C) 2012-2013 Team XBMC
3  *      http://xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #include "system.h"
22
23 #if defined(TARGET_ANDROID)
24 #include "AndroidAppDirectory.h"
25 #include "xbmc/android/activity/XBMCApp.h"
26 #include "FileItem.h"
27 #include "File.h"
28 #include "utils/URIUtils.h"
29 #include <vector>
30 #include "utils/log.h"
31 #include "utils/StringUtils.h"
32 #include "URL.h"
33
34 using namespace XFILE;
35 using namespace std;
36
37 CAndroidAppDirectory::CAndroidAppDirectory(void)
38 {
39 }
40
41 CAndroidAppDirectory::~CAndroidAppDirectory(void)
42 {
43 }
44
45 bool CAndroidAppDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items)
46 {
47   CURL url(strPath);
48   CStdString dirname = url.GetFileName();
49   URIUtils::RemoveSlashAtEnd(dirname);
50   CLog::Log(LOGDEBUG, "CAndroidAppDirectory::GetDirectory: %s",dirname.c_str()); 
51   if (dirname == "apps")
52   {
53     vector<androidPackage> applications = CXBMCApp::GetApplications();
54     if (applications.empty())
55     {
56       CLog::Log(LOGERROR, "CAndroidAppDirectory::GetDirectory Application lookup listing failed");
57       return false;
58     }
59     for(std::vector<androidPackage>::iterator i = applications.begin(); i != applications.end(); ++i)
60     {
61       if ((*i).packageName == "org.xbmc.xbmc")
62         continue;
63       CFileItemPtr pItem(new CFileItem((*i).packageName));
64       pItem->m_bIsFolder = false;
65       std::string path = StringUtils::Format("androidapp://%s/%s/%s", url.GetHostName().c_str(), dirname.c_str(), (*i).packageName.c_str());
66       pItem->SetPath(path);
67       pItem->SetLabel((*i).packageLabel);
68       pItem->SetArt("thumb", path+".png");
69       items.Add(pItem);
70     }
71     return true;
72   }
73
74   CLog::Log(LOGERROR, "CAndroidAppDirectory::GetDirectory Failed to open %s",strPath.c_str());
75   return false;
76 }
77
78 bool CAndroidAppDirectory::IsAllowed(const CStdString& strFile) const
79 {
80   // Entries are virtual, so we want them all.
81   return true;
82 }
83
84 #endif