2 * Copyright (C) 2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
22 #include "PackageManager.h"
23 #include <android/log.h>
25 #include "IntentFilter.h"
26 #include "ClassLoader.h"
27 #include "jutils/jutils-details.hpp"
28 #include "BroadcastReceiver.h"
29 #include "JNIThreading.h"
30 #include "ApplicationInfo.h"
32 #include "ContentResolver.h"
33 #include "BaseColumns.h"
34 #include "MediaStore.h"
35 #include "PowerManager.h"
37 #include "ConnectivityManager.h"
38 #include "AudioManager.h"
40 #include <android/native_activity.h>
44 jhobject CJNIContext::m_context(0);
45 CJNIContext* CJNIContext::m_appInstance(NULL);
47 CJNIContext::CJNIContext(const ANativeActivity *nativeActivity)
49 m_context.reset(nativeActivity->clazz);
50 xbmc_jni_on_load(nativeActivity->vm, nativeActivity->env);
51 PopulateStaticFields();
55 CJNIContext::~CJNIContext()
62 void CJNIContext::PopulateStaticFields()
64 CJNIBaseColumns::PopulateStaticFields();
65 CJNIMediaStoreMediaColumns::PopulateStaticFields();
66 CJNIPowerManager::PopulateStaticFields();
67 CJNIPackageManager::PopulateStaticFields();
68 CJNIMediaStoreMediaColumns::PopulateStaticFields();
69 CJNICursor::PopulateStaticFields();
70 CJNIContentResolver::PopulateStaticFields();
71 CJNIConnectivityManager::PopulateStaticFields();
72 CJNIAudioManager::PopulateStaticFields();
75 CJNIPackageManager CJNIContext::GetPackageManager()
77 return call_method<jhobject>(m_context,
78 "getPackageManager", "()Landroid/content/pm/PackageManager;");
81 void CJNIContext::startActivity(const CJNIIntent &intent)
83 call_method<void>(jhobject(m_context),
84 "startActivity", "(Landroid/content/Intent;)V",
88 int CJNIContext::checkCallingOrSelfPermission(const std::string &permission)
90 return call_method<int>(m_context,
91 "checkCallingOrSelfPermission", "(Ljava/lang/String;)I",
92 jcast<jhstring>(permission));
95 jhobject CJNIContext::getSystemService(const std::string &service)
97 return call_method<jhobject>(m_context,
98 "getSystemService", "(Ljava/lang/String;)Ljava/lang/Object;",
99 jcast<jhstring>(service));
102 CJNIIntent CJNIContext::registerReceiver(const CJNIBroadcastReceiver &receiver, const CJNIIntentFilter &filter)
104 return call_method<jhobject>(m_context,
105 "registerReceiver", "(Landroid/content/BroadcastReceiver;Landroid/content/IntentFilter;)Landroid/content/Intent;",
106 receiver.get_raw(), filter.get_raw());
109 CJNIIntent CJNIContext::registerReceiver(const CJNIIntentFilter &filter)
111 return call_method<jhobject>(m_context,
112 "registerReceiver", "(Landroid/content/BroadcastReceiver;Landroid/content/IntentFilter;)Landroid/content/Intent;",
113 (jobject)NULL, filter.get_raw());
116 void CJNIContext::unregisterReceiver(const CJNIBroadcastReceiver &receiver)
118 call_method<void>(m_context,
119 "unregisterReceiver", "(Landroid/content/BroadcastReceiver;)V",
123 CJNIIntent CJNIContext::sendBroadcast(const CJNIIntent &intent)
125 return call_method<jhobject>(m_context,
126 "sendBroadcast", "(Landroid/content/Intent;)V",
130 CJNIIntent CJNIContext::getIntent()
132 return call_method<jhobject>(m_context,
133 "getIntent", "()Landroid/content/Intent;");
136 CJNIClassLoader CJNIContext::getClassLoader()
138 return call_method<jhobject>(m_context,
139 "getClassLoader", "()Ljava/lang/ClassLoader;");
142 CJNIApplicationInfo CJNIContext::getApplicationInfo()
144 return call_method<jhobject>(m_context,
145 "getApplicationInfo", "()Landroid/content/pm/ApplicationInfo;");
148 std::string CJNIContext::getPackageResourcePath()
150 return jcast<std::string>(call_method<jhstring>(m_context,
151 "getPackageResourcePath", "()Ljava/lang/String;"));
154 CJNIFile CJNIContext::getCacheDir()
156 return call_method<jhobject>(m_context,
157 "getCacheDir", "()Ljava/io/File;");
160 CJNIFile CJNIContext::getDir(const std::string &path, int mode)
162 return call_method<jhobject>(m_context,
163 "getDir", "(Ljava/lang/String;I)Ljava/io/File;",
164 jcast<jhstring>(path), mode);
167 CJNIFile CJNIContext::getExternalFilesDir(const std::string &path)
169 return call_method<jhobject>(m_context,
170 "getExternalFilesDir", "(Ljava/lang/String;)Ljava/io/File;",
171 jcast<jhstring>(path));
174 CJNIContentResolver CJNIContext::getContentResolver()
176 return call_method<jhobject>(m_context,
177 "getContentResolver", "()Landroid/content/ContentResolver;");
180 void CJNIContext::_onNewIntent(JNIEnv *env, jobject context, jobject intent)
185 m_appInstance->onNewIntent(CJNIIntent(jhobject(intent)));