Merge pull request #2828 from Tolriq/fix_remoteaccess
[vuplus_xbmc] / xbmc / android / activity / XBMCApp.h
1 #pragma once
2 /*
3  *      Copyright (C) 2012-2013 Team XBMC
4  *      http://www.xbmc.org
5  *
6  *  This Program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2, or (at your option)
9  *  any later version.
10  *
11  *  This Program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with XBMC; see the file COPYING.  If not, see
18  *  <http://www.gnu.org/licenses/>.
19  *
20  */
21
22 #include <math.h>
23 #include <pthread.h>
24 #include <string>
25 #include <vector>
26
27 #include <android/native_activity.h>
28
29 #include "IActivityHandler.h"
30 #include "IInputHandler.h"
31
32 #include "xbmc.h"
33 #include "android/jni/Context.h"
34 #include "android/jni/BroadcastReceiver.h"
35
36 // forward delares
37 class CJNIWakeLock;
38 class CAESinkAUDIOTRACK;
39 typedef struct _JNIEnv JNIEnv;
40
41 struct androidIcon
42 {
43   unsigned int width;
44   unsigned int height;
45   void *pixels;
46 };  
47
48 struct androidPackage
49 {
50   std::string packageName;
51   std::string packageLabel;
52 };
53
54
55 class CXBMCApp : public IActivityHandler, public CJNIContext, public CJNIBroadcastReceiver
56 {
57 public:
58   CXBMCApp(ANativeActivity *nativeActivity);
59   virtual ~CXBMCApp();
60   virtual void onReceive(CJNIIntent intent);
61   virtual void onNewIntent(CJNIIntent intent);
62
63   bool isValid() { return m_activity != NULL; }
64
65   void onStart();
66   void onResume();
67   void onPause();
68   void onStop();
69   void onDestroy();
70
71   void onSaveState(void **data, size_t *size);
72   void onConfigurationChanged();
73   void onLowMemory();
74
75   void onCreateWindow(ANativeWindow* window);
76   void onResizeWindow();
77   void onDestroyWindow();
78   void onGainFocus();
79   void onLostFocus();
80
81
82   static ANativeWindow* GetNativeWindow() { return m_window; };
83   static int SetBuffersGeometry(int width, int height, int format);
84   static int android_printf(const char *format, ...);
85   
86   static int GetBatteryLevel();
87   static bool StartActivity(const std::string &package, const std::string &intent = std::string(), const std::string &dataType = std::string(), const std::string &dataURI = std::string());
88   static bool ListApplications(std::vector <androidPackage> *applications);
89   static bool GetIconSize(const std::string &packageName, int *width, int *height);
90   static bool GetIcon(const std::string &packageName, void* buffer, unsigned int bufSize); 
91
92   /*!
93    * \brief If external storage is available, it returns the path for the external storage (for the specified type)
94    * \param path will contain the path of the external storage (for the specified type)
95    * \param type optional type. Possible values are "", "files", "music", "videos", "pictures", "photos, "downloads"
96    * \return true if external storage is available and a valid path has been stored in the path parameter
97    */
98   static bool GetExternalStorage(std::string &path, const std::string &type = "");
99   static bool GetStorageUsage(const std::string &path, std::string &usage);
100   static int GetMaxSystemVolume();
101
102   static int GetDPI();
103 protected:
104   // limit who can access Volume
105   friend class CAESinkAUDIOTRACK;
106
107   static int GetMaxSystemVolume(JNIEnv *env);
108   static void SetSystemVolume(JNIEnv *env, float percent);
109
110 private:
111   static bool HasLaunchIntent(const std::string &package);
112   bool getWakeLock();
113   std::string GetFilenameFromIntent(const CJNIIntent &intent);
114   void run();
115   void stop();
116   void SetupEnv();
117   static ANativeActivity *m_activity;
118   CJNIWakeLock *m_wakeLock;
119   static int m_batteryLevel;  
120   bool m_firstrun;
121   bool m_exiting;
122   pthread_t m_thread;
123   
124   static ANativeWindow* m_window;
125   
126   void XBMC_Pause(bool pause);
127   void XBMC_Stop();
128   bool XBMC_DestroyDisplay();
129   bool XBMC_SetupDisplay();
130 };