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"
33 #include "android/jni/Context.h"
34 #include "android/jni/BroadcastReceiver.h"
35 #include "threads/Event.h"
39 class CAESinkAUDIOTRACK;
40 typedef struct _JNIEnv JNIEnv;
51 std::string packageName;
52 std::string packageLabel;
56 class CXBMCApp : public IActivityHandler, public CJNIContext, public CJNIBroadcastReceiver
59 CXBMCApp(ANativeActivity *nativeActivity);
61 virtual void onReceive(CJNIIntent intent);
62 virtual void onNewIntent(CJNIIntent intent);
64 bool isValid() { return m_activity != NULL; }
72 void onSaveState(void **data, size_t *size);
73 void onConfigurationChanged();
76 void onCreateWindow(ANativeWindow* window);
77 void onResizeWindow();
78 void onDestroyWindow();
83 static const ANativeWindow** GetNativeWindow(int timeout);
84 static int SetBuffersGeometry(int width, int height, int format);
85 static int android_printf(const char *format, ...);
87 static int GetBatteryLevel();
88 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());
89 static std::vector <androidPackage> GetApplications();
90 static bool GetIconSize(const std::string &packageName, int *width, int *height);
91 static bool GetIcon(const std::string &packageName, void* buffer, unsigned int bufSize);
94 * \brief If external storage is available, it returns the path for the external storage (for the specified type)
95 * \param path will contain the path of the external storage (for the specified type)
96 * \param type optional type. Possible values are "", "files", "music", "videos", "pictures", "photos, "downloads"
97 * \return true if external storage is available and a valid path has been stored in the path parameter
99 static bool GetExternalStorage(std::string &path, const std::string &type = "");
100 static bool GetStorageUsage(const std::string &path, std::string &usage);
101 static int GetMaxSystemVolume();
102 static int GetSystemVolume();
103 static void SetSystemVolume(int val);
107 // limit who can access Volume
108 friend class CAESinkAUDIOTRACK;
110 static int GetMaxSystemVolume(JNIEnv *env);
111 static void SetSystemVolume(JNIEnv *env, float percent);
114 static bool HasLaunchIntent(const std::string &package);
116 std::string GetFilenameFromIntent(const CJNIIntent &intent);
120 static ANativeActivity *m_activity;
121 CJNIWakeLock *m_wakeLock;
122 static int m_batteryLevel;
123 static int m_initialVolume;
127 static CCriticalSection m_applicationsMutex;
128 static std::vector<androidPackage> m_applications;
130 static ANativeWindow* m_window;
131 static CEvent m_windowCreated;
133 void XBMC_Pause(bool pause);
135 bool XBMC_DestroyDisplay();
136 bool XBMC_SetupDisplay();