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