3 * Copyright (C) 2012-2013 Team XBMC
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)
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.
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/>.
27 #include <android/native_activity.h>
29 #include "IActivityHandler.h"
30 #include "IInputHandler.h"
36 class CAESinkAUDIOTRACK;
37 typedef struct _JNIEnv JNIEnv;
48 std::string packageName;
49 std::string packageLabel;
53 class CXBMCApp : public IActivityHandler
56 CXBMCApp(ANativeActivity *nativeActivity);
59 bool isValid() { return m_activity != NULL; }
61 ActivityResult onActivate();
70 void onSaveState(void **data, size_t *size);
71 void onConfigurationChanged();
74 void onCreateWindow(ANativeWindow* window);
75 void onResizeWindow();
76 void onDestroyWindow();
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, ...);
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);
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
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();
103 // limit who can access AttachCurrentThread/DetachCurrentThread
104 friend class CAESinkAUDIOTRACK;
105 friend class CAndroidFeatures;
106 friend class CFileAndroidApp;
108 static int AttachCurrentThread(JNIEnv** p_env, void* thr_args = NULL);
109 static int DetachCurrentThread();
111 static int GetMaxSystemVolume(JNIEnv *env);
112 static void SetSystemVolume(JNIEnv *env, float percent);
115 static bool HasLaunchIntent(const std::string &package);
116 bool getWakeLock(JNIEnv *env);
117 void acquireWakeLock();
118 void releaseWakeLock();
122 static ANativeActivity *m_activity;
125 // XBMC_Initialize hasn't been executed yet
127 // XBMC_Initialize has been successfully executed
129 // XBMC is currently rendering
131 // XBMC has stopped rendering because it has lost focus
132 // but it still has an EGLContext
134 // XBMC has been paused/stopped and does not have an
137 // XBMC is being stopped
141 // An error has occured
147 pthread_mutex_t mutex;
153 void setAppState(AppState state);
155 static ANativeWindow* m_window;
157 void XBMC_Pause(bool pause);
159 bool XBMC_DestroyDisplay();
160 bool XBMC_SetupDisplay();