[cosmetics] update date in GPL header
[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
34
35 // forward delares
36 class CAESinkAUDIOTRACK;
37 typedef struct _JNIEnv JNIEnv;
38
39 struct androidIcon
40 {
41   unsigned int width;
42   unsigned int height;
43   void *pixels;
44 };  
45
46 struct androidPackage
47 {
48   std::string packageName;
49   std::string packageLabel;
50 };
51
52
53 class CXBMCApp : public IActivityHandler
54 {
55 public:
56   CXBMCApp(ANativeActivity *nativeActivity);
57   virtual ~CXBMCApp();
58
59   bool isValid() { return m_activity != NULL; }
60
61   ActivityResult onActivate();
62   void onDeactivate();
63
64   void onStart();
65   void onResume();
66   void onPause();
67   void onStop();
68   void onDestroy();
69
70   void onSaveState(void **data, size_t *size);
71   void onConfigurationChanged();
72   void onLowMemory();
73
74   void onCreateWindow(ANativeWindow* window);
75   void onResizeWindow();
76   void onDestroyWindow();
77   void onGainFocus();
78   void onLostFocus();
79
80
81   static ANativeWindow* GetNativeWindow() { return m_window; };
82   static int SetBuffersGeometry(int width, int height, int format);
83   static int android_printf(const char *format, ...);
84   
85   static int GetBatteryLevel();
86   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());
87   static bool ListApplications(std::vector <androidPackage> *applications);
88   static bool GetIconSize(const std::string &packageName, int *width, int *height);
89   static bool GetIcon(const std::string &packageName, void* buffer, unsigned int bufSize); 
90
91   /*!
92    * \brief If external storage is available, it returns the path for the external storage (for the specified type)
93    * \param path will contain the path of the external storage (for the specified type)
94    * \param type optional type. Possible values are "", "files", "music", "videos", "pictures", "photos, "downloads"
95    * \return true if external storage is available and a valid path has been stored in the path parameter
96    */
97   static bool GetExternalStorage(std::string &path, const std::string &type = "");
98   static bool GetStorageUsage(const std::string &path, std::string &usage);
99   static int GetMaxSystemVolume();
100
101   static int GetDPI();
102 protected:
103   // limit who can access AttachCurrentThread/DetachCurrentThread
104   friend class CAESinkAUDIOTRACK;
105   friend class CAndroidFeatures;
106   friend class CFileAndroidApp;
107
108   static int AttachCurrentThread(JNIEnv** p_env, void* thr_args = NULL);
109   static int DetachCurrentThread();
110
111   static int GetMaxSystemVolume(JNIEnv *env);
112   static void SetSystemVolume(JNIEnv *env, float percent);
113
114 private:
115   static bool HasLaunchIntent(const std::string &package);
116   bool getWakeLock(JNIEnv *env);
117   void acquireWakeLock();
118   void releaseWakeLock();
119   void run();
120   void stop();
121
122   static ANativeActivity *m_activity;
123   jobject m_wakeLock;
124   typedef enum {
125     // XBMC_Initialize hasn't been executed yet
126     Uninitialized,
127     // XBMC_Initialize has been successfully executed
128     Initialized,
129     // XBMC is currently rendering
130     Rendering,
131     // XBMC has stopped rendering because it has lost focus
132     // but it still has an EGLContext
133     Unfocused,
134     // XBMC has been paused/stopped and does not have an
135     // EGLContext
136     Paused,
137     // XBMC is being stopped
138     Stopping,
139     // XBMC has stopped
140     Stopped,
141     // An error has occured
142     Error
143   } AppState;
144
145   typedef struct {
146     pthread_t thread;
147     pthread_mutex_t mutex;
148     AppState appState;
149   } State;
150
151   State m_state;
152   
153   void setAppState(AppState state);
154     
155   static ANativeWindow* m_window;
156   
157   void XBMC_Pause(bool pause);
158   void XBMC_Stop();
159   bool XBMC_DestroyDisplay();
160   bool XBMC_SetupDisplay();
161 };