Merge pull request #5095 from koying/fixdroidappcrash
[vuplus_xbmc] / xbmc / filesystem / AndroidAppFile.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
25 #include "AndroidAppFile.h"
26 #include <sys/stat.h>
27 #include "Util.h"
28 #include "URL.h"
29 #include "utils/log.h"
30 #include "utils/URIUtils.h"
31 #include <jni.h>
32 #include "android/activity/XBMCApp.h"
33 using namespace XFILE;
34
35 CFileAndroidApp::CFileAndroidApp(void)
36 {
37   m_iconWidth = 0;
38   m_iconHeight = 0;
39 }
40
41 CFileAndroidApp::~CFileAndroidApp(void)
42 {
43   Close();
44 }
45
46 bool CFileAndroidApp::Open(const CURL& url)
47 {
48   m_url = url;
49   m_appname =  URIUtils::GetFileName(url.Get());
50   m_appname = m_appname.substr(0, m_appname.size() - 4);
51
52   std::vector<androidPackage> applications = CXBMCApp::GetApplications();
53   for(std::vector<androidPackage>::iterator i = applications.begin(); i != applications.end(); ++i)
54   {
55     if ((*i).packageName == m_appname)
56       return true;
57   }
58
59   return false;
60 }
61
62 bool CFileAndroidApp::Exists(const CURL& url)
63 {
64   std::string appname =  URIUtils::GetFileName(url.Get());
65   appname = appname.substr(0, appname.size() - 4);
66
67   std::vector<androidPackage> applications = CXBMCApp::GetApplications();
68   for(std::vector<androidPackage>::iterator i = applications.begin(); i != applications.end(); ++i)
69   {
70     if ((*i).packageName == appname)
71       return true;
72   }
73
74   return false;
75 }
76
77 unsigned int CFileAndroidApp::Read(void* lpBuf, int64_t uiBufSize)
78 {
79   CXBMCApp::GetIcon(m_appname, lpBuf, uiBufSize);
80   return uiBufSize;
81 }
82
83 void CFileAndroidApp::Close()
84 {
85 }
86
87 int64_t CFileAndroidApp::GetLength()
88 {
89   CXBMCApp::GetIconSize(m_appname, &m_iconWidth, &m_iconHeight);
90   return m_iconWidth * m_iconHeight * 4;
91 }
92
93 unsigned int CFileAndroidApp::GetIconWidth()
94 {
95   return m_iconWidth;
96 }
97
98 unsigned int CFileAndroidApp::GetIconHeight()
99 {
100   return m_iconHeight;
101 }
102
103 int CFileAndroidApp::GetChunkSize()
104 {
105   return 0;
106 }
107 int CFileAndroidApp::Stat(const CURL& url, struct __stat64* buffer)
108 {
109   return 0;
110 }
111 int CFileAndroidApp::IoControl(EIoControl request, void* param)
112 {
113   if(request == IOCTRL_SEEK_POSSIBLE)
114     return 0;
115   return 1;
116 }
117 #endif
118