diff options
author | Martijn Kaijser <martijn@xbmc.org> | 2016-10-30 16:20:55 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-30 16:20:55 +0100 |
commit | a43edb81eebd771d24fcf8431803cf2d77d63a36 (patch) | |
tree | 008430cc6bbdda4ce4a47fde72b7fd6d77919b91 | |
parent | bc895f3a4966a1459f6f64fd3cec6a922fc19312 (diff) | |
parent | 7045c75dd875918f744b0c8ee0807a0327e83e26 (diff) |
Merge pull request #10808 from koying/jnibackports
Bunch of SPMC jni backports
76 files changed, 3102 insertions, 75 deletions
diff --git a/xbmc/platform/android/jni/Activity.cpp b/xbmc/platform/android/jni/Activity.cpp index 2862c4822f..41b4db50c9 100644 --- a/xbmc/platform/android/jni/Activity.cpp +++ b/xbmc/platform/android/jni/Activity.cpp @@ -41,3 +41,11 @@ bool CJNIActivity::moveTaskToBack(bool nonRoot) "moveTaskToBack", "(Z)Z", nonRoot); } + +void CJNIActivity::startActivityForResult(const CJNIIntent &intent, int requestCode) +{ + call_method<void>(jhobject(m_context), + "startActivityForResult", "(Landroid/content/Intent;I)V", + intent.get_raw(), requestCode); +} + diff --git a/xbmc/platform/android/jni/Activity.h b/xbmc/platform/android/jni/Activity.h index 6df9f4aa8c..0181e64796 100644 --- a/xbmc/platform/android/jni/Activity.h +++ b/xbmc/platform/android/jni/Activity.h @@ -21,6 +21,7 @@ #include "JNIBase.h" #include "Context.h" +#include "Intent.h" class CVariant; struct ANativeActivity; @@ -32,6 +33,7 @@ public: ~CJNIActivity(); static bool moveTaskToBack(bool nonRoot); + static void startActivityForResult(const CJNIIntent &intent, int requestCode); private: CJNIActivity(); diff --git a/xbmc/platform/android/jni/ArrayList.cpp b/xbmc/platform/android/jni/ArrayList.cpp new file mode 100644 index 0000000000..90a8cdde59 --- /dev/null +++ b/xbmc/platform/android/jni/ArrayList.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (C) 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 "ArrayList.h" + +#include "jutils/jutils-details.hpp" + +using namespace jni; + +template <typename T> +T CJNIArrayList<T>::get(int index) +{ + return (T)call_method<jhobject>(m_object, + "get", "(I)Ljava/lang/Object;", + index); +} + +template <> +std::string CJNIArrayList<std::string>::get(int index) +{ + return jcast<std::string>(call_method<jhstring>(m_object, + "get", "(I)Ljava/lang/Object;", + index)); +} + + +template <typename T> +int CJNIArrayList<T>::size() +{ + return m_object.get() ? call_method<jint>(m_object, + "size", "()I") : 0; +} + +template class CJNIArrayList<std::string>; diff --git a/xbmc/platform/android/jni/ArrayList.h b/xbmc/platform/android/jni/ArrayList.h new file mode 100644 index 0000000000..a68147a52d --- /dev/null +++ b/xbmc/platform/android/jni/ArrayList.h @@ -0,0 +1,38 @@ +#pragma once +/* + * Copyright (C) 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 "JNIBase.h" + +template <typename T> +class CJNIArrayList : public CJNIBase +{ +public: + CJNIArrayList(const jni::jhobject &object) : CJNIBase(object){}; + ~CJNIArrayList(){}; + + T get(int index); + int size(); + +private: + CJNIArrayList(); +}; + +template <> std::string CJNIArrayList<std::string>::get(int index); diff --git a/xbmc/platform/android/jni/AudioAttributes.cpp b/xbmc/platform/android/jni/AudioAttributes.cpp new file mode 100644 index 0000000000..6fa58098bf --- /dev/null +++ b/xbmc/platform/android/jni/AudioAttributes.cpp @@ -0,0 +1,102 @@ +/* + * Copyright (C) 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 "AudioAttributes.h" +#include "ClassLoader.h" + +#include "JNIBase.h" +#include "jutils/jutils-details.hpp" + +using namespace jni; + +int CJNIAudioAttributes::CONTENT_TYPE_MOVIE = -1; +int CJNIAudioAttributes::CONTENT_TYPE_MUSIC = -1; +int CJNIAudioAttributes::FLAG_HW_AV_SYNC = -1; +int CJNIAudioAttributes::USAGE_MEDIA = -1; + +const char *CJNIAudioAttributes::m_classname = "android/media/AudioAttributes"; +const char *CJNIAudioAttributesBuilder::m_classname = "android/media/AudioAttributes$Builder"; + + +void CJNIAudioAttributes::GetStaticValue(jhclass& c, int& field, char* value) +{ + jfieldID id = get_static_field_id<jclass>(c, value, "I"); + if (id != NULL) + field = get_static_field<int>(c, value); + else + xbmc_jnienv()->ExceptionClear(); +} + + +void CJNIAudioAttributes::PopulateStaticFields() +{ + int sdk = CJNIBase::GetSDKVersion(); + if (sdk >= 21) + { + jhclass c = find_class(m_classname); + if (sdk >= 21) + { + GetStaticValue(c, CJNIAudioAttributes::CONTENT_TYPE_MOVIE, "CONTENT_TYPE_MOVIE"); + GetStaticValue(c, CJNIAudioAttributes::CONTENT_TYPE_MUSIC, "CONTENT_TYPE_MUSIC"); + GetStaticValue(c, CJNIAudioAttributes::FLAG_HW_AV_SYNC, "FLAG_HW_AV_SYNC"); + GetStaticValue(c, CJNIAudioAttributes::USAGE_MEDIA, "USAGE_MEDIA"); + + } + + } +} + + +CJNIAudioAttributesBuilder::CJNIAudioAttributesBuilder() + : CJNIBase(CJNIAudioAttributesBuilder::m_classname) +{ + m_object = new_object(GetClassName()); + m_object.setGlobal(); +} + +CJNIAudioAttributes CJNIAudioAttributesBuilder::build() +{ + return call_method<jhobject>(m_object, + "build", "()Landroid/media/AudioAttributes;"); +} + +CJNIAudioAttributesBuilder CJNIAudioAttributesBuilder::setContentType(int contentType) +{ + return call_method<jhobject>(m_object, + "setContentType", "(I)Landroid/media/AudioAttributes$Builder;", contentType); +} + +CJNIAudioAttributesBuilder CJNIAudioAttributesBuilder::setFlags(int flags) +{ + return call_method<jhobject>(m_object, + "setFlags", "(I)Landroid/media/AudioAttributes$Builder;", flags); +} + +CJNIAudioAttributesBuilder CJNIAudioAttributesBuilder::setLegacyStreamType(int streamType) +{ + return call_method<jhobject>(m_object, + "setLegacyStreamType", "(I)Landroid/media/AudioAttributes$Builder;", streamType); +} + +CJNIAudioAttributesBuilder CJNIAudioAttributesBuilder::setUsage(int usage) +{ + return call_method<jhobject>(m_object, + "setUsage", "(I)Landroid/media/AudioAttributes$Builder;", usage); +} diff --git a/xbmc/platform/android/jni/AudioAttributes.h b/xbmc/platform/android/jni/AudioAttributes.h new file mode 100644 index 0000000000..d3dbfdd294 --- /dev/null +++ b/xbmc/platform/android/jni/AudioAttributes.h @@ -0,0 +1,66 @@ +#pragma once +/* + * Copyright (C) 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 "JNIBase.h" + +namespace jni +{ + +class CJNIAudioAttributes : public CJNIBase +{ +public: + CJNIAudioAttributes(const jni::jhobject &object) : CJNIBase(object) {} + + static void PopulateStaticFields(); + + static int CONTENT_TYPE_MOVIE; + static int CONTENT_TYPE_MUSIC; + + static int FLAG_HW_AV_SYNC; + + static int USAGE_MEDIA; + +protected: + static const char *m_classname; + + static void GetStaticValue(jhclass &c, int &field, char *value); +}; + +class CJNIAudioAttributesBuilder : public CJNIBase +{ +public: + CJNIAudioAttributesBuilder(); + CJNIAudioAttributesBuilder(const jni::jhobject &object) : CJNIBase(object) {} + + CJNIAudioAttributes build(); + + CJNIAudioAttributesBuilder setContentType(int contentType); + CJNIAudioAttributesBuilder setFlags(int flags); + CJNIAudioAttributesBuilder setLegacyStreamType(int streamType); + CJNIAudioAttributesBuilder setUsage(int usage); + +protected: + static const char *m_classname; +}; + + +}; + diff --git a/xbmc/platform/android/jni/AudioDeviceInfo.cpp b/xbmc/platform/android/jni/AudioDeviceInfo.cpp new file mode 100644 index 0000000000..ce7b09ec35 --- /dev/null +++ b/xbmc/platform/android/jni/AudioDeviceInfo.cpp @@ -0,0 +1,153 @@ +/* + * Copyright (C) 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 "AudioDeviceInfo.h" +#include "JNIBase.h" +#include "jutils/jutils-details.hpp" + +using namespace jni; + +int CJNIAudioDeviceInfo::TYPE_AUX_LINE = -1; +int CJNIAudioDeviceInfo::TYPE_BLUETOOTH_A2DP = -1; +int CJNIAudioDeviceInfo::TYPE_BLUETOOTH_SCO = -1; +int CJNIAudioDeviceInfo::TYPE_BUILTIN_EARPIECE = -1; +int CJNIAudioDeviceInfo::TYPE_BUILTIN_MIC = -1; +int CJNIAudioDeviceInfo::TYPE_BUILTIN_SPEAKER = -1; +int CJNIAudioDeviceInfo::TYPE_BUS = -1; +int CJNIAudioDeviceInfo::TYPE_DOCK = -1; +int CJNIAudioDeviceInfo::TYPE_FM = -1; +int CJNIAudioDeviceInfo::TYPE_FM_TUNER = -1; +int CJNIAudioDeviceInfo::TYPE_HDMI = -1; +int CJNIAudioDeviceInfo::TYPE_HDMI_ARC = -1; +int CJNIAudioDeviceInfo::TYPE_IP = -1; +int CJNIAudioDeviceInfo::TYPE_LINE_ANALOG = -1; +int CJNIAudioDeviceInfo::TYPE_LINE_DIGITAL = -1; +int CJNIAudioDeviceInfo::TYPE_TELEPHONY = -1; +int CJNIAudioDeviceInfo::TYPE_TV_TUNER = -1; +int CJNIAudioDeviceInfo::TYPE_UNKNOWN = -1; +int CJNIAudioDeviceInfo::TYPE_USB_ACCESSORY = -1; +int CJNIAudioDeviceInfo::TYPE_USB_DEVICE = -1; +int CJNIAudioDeviceInfo::TYPE_WIRED_HEADPHONES = -1; +int CJNIAudioDeviceInfo::TYPE_WIRED_HEADSET = -1; + +void CJNIAudioDeviceInfo::GetStaticValue(jhclass& c, int& field, const char* value) +{ + jfieldID fid = get_static_field_id<jclass>(c, value, "I"); + if (fid != NULL) + field = get_static_field<int>(c, fid); + else + xbmc_jnienv()->ExceptionClear(); +} + +void CJNIAudioDeviceInfo::PopulateStaticFields() +{ + int sdk = CJNIBase::GetSDKVersion(); + if (sdk >= 23) + { + jhclass c = find_class("android/media/AudioDeviceInfo"); + CJNIAudioDeviceInfo::TYPE_AUX_LINE = get_static_field<int>(c, "TYPE_AUX_LINE"); + CJNIAudioDeviceInfo::TYPE_BLUETOOTH_A2DP = get_static_field<int>(c, "TYPE_BLUETOOTH_A2DP"); + CJNIAudioDeviceInfo::TYPE_BLUETOOTH_SCO = get_static_field<int>(c, "TYPE_BLUETOOTH_SCO"); + CJNIAudioDeviceInfo::TYPE_BUILTIN_EARPIECE = get_static_field<int>(c, "TYPE_BUILTIN_EARPIECE"); + CJNIAudioDeviceInfo::TYPE_BUILTIN_MIC = get_static_field<int>(c, "TYPE_BUILTIN_MIC"); + CJNIAudioDeviceInfo::TYPE_BUILTIN_SPEAKER = get_static_field<int>(c, "TYPE_BUILTIN_SPEAKER"); + CJNIAudioDeviceInfo::TYPE_DOCK = get_static_field<int>(c, "TYPE_DOCK"); + CJNIAudioDeviceInfo::TYPE_FM = get_static_field<int>(c, "TYPE_FM"); + CJNIAudioDeviceInfo::TYPE_FM_TUNER = get_static_field<int>(c, "TYPE_FM_TUNER"); + CJNIAudioDeviceInfo::TYPE_HDMI = get_static_field<int>(c, "TYPE_HDMI"); + CJNIAudioDeviceInfo::TYPE_HDMI_ARC = get_static_field<int>(c, "TYPE_HDMI_ARC"); + CJNIAudioDeviceInfo::TYPE_IP = get_static_field<int>(c, "TYPE_IP"); + CJNIAudioDeviceInfo::TYPE_LINE_ANALOG = get_static_field<int>(c, "TYPE_LINE_ANALOG"); + CJNIAudioDeviceInfo::TYPE_LINE_DIGITAL = get_static_field<int>(c, "TYPE_LINE_DIGITAL"); + CJNIAudioDeviceInfo::TYPE_TELEPHONY = get_static_field<int>(c, "TYPE_TELEPHONY"); + CJNIAudioDeviceInfo::TYPE_TV_TUNER = get_static_field<int>(c, "TYPE_TV_TUNER"); + CJNIAudioDeviceInfo::TYPE_UNKNOWN = get_static_field<int>(c, "TYPE_UNKNOWN"); + CJNIAudioDeviceInfo::TYPE_USB_ACCESSORY = get_static_field<int>(c, "TYPE_USB_ACCESSORY"); + CJNIAudioDeviceInfo::TYPE_USB_DEVICE = get_static_field<int>(c, "TYPE_USB_DEVICE"); + CJNIAudioDeviceInfo::TYPE_WIRED_HEADPHONES = get_static_field<int>(c, "TYPE_WIRED_HEADPHONES"); + CJNIAudioDeviceInfo::TYPE_WIRED_HEADSET = get_static_field<int>(c, "TYPE_WIRED_HEADSET"); + + if (sdk >= 24) + { + GetStaticValue(c, CJNIAudioDeviceInfo::TYPE_BUS, "TYPE_BUS"); + } + } +} + +std::vector<int> CJNIAudioDeviceInfo::getChannelCounts() const +{ + return jcast<std::vector<int>>( + call_method<jhintArray>(m_object, "getChannelCounts", "()[I")); +} + +std::vector<int> CJNIAudioDeviceInfo::getChannelIndexMasks() const +{ + return jcast<std::vector<int>>( + call_method<jhintArray>(m_object, "getChannelIndexMasks", "()[I")); +} + +std::vector<int> CJNIAudioDeviceInfo::getChannelMasks() const +{ + return jcast<std::vector<int>>( + call_method<jhintArray>(m_object, "getChannelMasks", "()[I")); +} + +std::vector<int> CJNIAudioDeviceInfo::getEncodings() const +{ + return jcast<std::vector<int>>( + call_method<jhintArray>(m_object, "getEncodings", "()[I")); +} + +std::vector<int> CJNIAudioDeviceInfo::getSampleRates() const +{ + return jcast<std::vector<int>>( + call_method<jhintArray>(m_object, "getSampleRates", "()[I")); +} + +CJNICharSequence CJNIAudioDeviceInfo::getProductName() const +{ + return call_method<jhobject>(m_object, + "getProductName", "()Ljava/lang/CharSequence;"); +} + +int CJNIAudioDeviceInfo::getId() const +{ + return call_method<jint>(m_object, + "getId", "()I"); + +} + +int CJNIAudioDeviceInfo::getType() const +{ + return call_method<jint>(m_object, + "getType", "()I"); +} + +bool CJNIAudioDeviceInfo::isSink() const +{ + return call_method<jboolean>(m_object, + "isSink", "()Z"); +} + +bool CJNIAudioDeviceInfo::isSource() const +{ + return call_method<jboolean>(m_object, + "isSource", "()Z"); +} diff --git a/xbmc/platform/android/jni/AudioDeviceInfo.h b/xbmc/platform/android/jni/AudioDeviceInfo.h new file mode 100644 index 0000000000..c39e88aca6 --- /dev/null +++ b/xbmc/platform/android/jni/AudioDeviceInfo.h @@ -0,0 +1,76 @@ +#pragma once +/* + * Copyright (C) 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 "JNIBase.h" +#include "jutils/jutils-details.hpp" + +#include "CharSequence.h" + +class CJNIAudioDeviceInfo : public CJNIBase +{ + public: + static void PopulateStaticFields(); + + static int TYPE_AUX_LINE; + static int TYPE_BLUETOOTH_A2DP; + static int TYPE_BLUETOOTH_SCO; + static int TYPE_BUILTIN_EARPIECE; + static int TYPE_BUILTIN_MIC; + static int TYPE_BUILTIN_SPEAKER; + static int TYPE_BUS; + static int TYPE_DOCK; + static int TYPE_FM; + static int TYPE_FM_TUNER; + static int TYPE_HDMI; + static int TYPE_HDMI_ARC; + static int TYPE_IP; + static int TYPE_LINE_ANALOG; + static int TYPE_LINE_DIGITAL; + static int TYPE_TELEPHONY; + static int TYPE_TV_TUNER; + static int TYPE_UNKNOWN; + static int TYPE_USB_ACCESSORY; + static int TYPE_USB_DEVICE; + static int TYPE_WIRED_HEADPHONES; + static int TYPE_WIRED_HEADSET; + + ~CJNIAudioDeviceInfo() {}; + CJNIAudioDeviceInfo(const jni::jhobject &object) : CJNIBase(object) {}; + + std::vector<int> getChannelCounts() const; + std::vector<int> getChannelIndexMasks() const; + std::vector<int> getChannelMasks() const; + std::vector<int> getEncodings() const; + std::vector<int> getSampleRates() const; + + CJNICharSequence getProductName() const; + int getId() const; + int getType() const; + bool isSink() const; + bool isSource() const; + +protected: + CJNIAudioDeviceInfo(); + static void GetStaticValue(jni::jhclass &c, int &field, const char *value); +}; + +typedef std::vector<CJNIAudioDeviceInfo> CJNIAudioDeviceInfos; + diff --git a/xbmc/platform/android/jni/AudioFormat.cpp b/xbmc/platform/android/jni/AudioFormat.cpp index 83aae3478b..357b5c3c43 100644 --- a/xbmc/platform/android/jni/AudioFormat.cpp +++ b/xbmc/platform/android/jni/AudioFormat.cpp @@ -51,6 +51,9 @@ int CJNIAudioFormat::CHANNEL_OUT_BACK_RIGHT = 0x00000080; int CJNIAudioFormat::CHANNEL_INVALID = 0x00000000; +const char *CJNIAudioFormat::m_classname = "android/media/AudioFormat"; +const char *CJNIAudioFormatBuilder::m_classname = "android/media/AudioFormat$Builder"; + void CJNIAudioFormat::GetStaticValue(jhclass& c, int& field, char* value) { jfieldID id = get_static_field_id<jclass>(c, value, "I"); @@ -68,7 +71,7 @@ void CJNIAudioFormat::PopulateStaticFields() int sdk = CJNIBase::GetSDKVersion(); if (sdk >= 3) { - jhclass c = find_class("android/media/AudioFormat"); + jhclass c = find_class(m_classname); CJNIAudioFormat::ENCODING_PCM_16BIT = get_static_field<int>(c, "ENCODING_PCM_16BIT"); if (sdk >= 5) { @@ -116,3 +119,65 @@ void CJNIAudioFormat::PopulateStaticFields() } } +int CJNIAudioFormat::getChannelCount() const +{ + return call_method<int>(m_object, "getChannelCount", "()I"); +} + +int CJNIAudioFormat::getChannelIndexMask() const +{ + return call_method<int>(m_object, "getChannelIndexMask", "()I"); +} + +int CJNIAudioFormat::getChannelMask() const +{ + return call_method<int>(m_object, "getChannelMask", "()I"); +} + +int CJNIAudioFormat::getEncoding() const +{ + return call_method<int>(m_object, "getEncoding", "()I"); +} + +int CJNIAudioFormat::getSampleRate() const +{ + return call_method<int>(m_object, "getSampleRate", "()I"); +} + + +CJNIAudioFormatBuilder::CJNIAudioFormatBuilder() + : CJNIBase(CJNIAudioFormatBuilder::m_classname) +{ + m_object = new_object(GetClassName()); + m_object.setGlobal(); +} + +CJNIAudioFormat CJNIAudioFormatBuilder::build() +{ + return call_method<jhobject>(m_object, + "build", "()Landroid/media/AudioFormat;"); +} + +CJNIAudioFormatBuilder CJNIAudioFormatBuilder::setChannelIndexMask(int channelIndexMask) +{ + return call_method<jhobject>(m_object, + "setChannelIndexMask", "(I)Landroid/media/AudioFormat$Builder;", channelIndexMask); +} + +CJNIAudioFormatBuilder CJNIAudioFormatBuilder::setChannelMask(int channelMask) +{ + return call_method<jhobject>(m_object, + "setChannelMask", "(I)Landroid/media/AudioFormat$Builder;", channelMask); +} + +CJNIAudioFormatBuilder CJNIAudioFormatBuilder::setEncoding(int encoding) +{ + return call_method<jhobject>(m_object, + "setEncoding", "(I)Landroid/media/AudioFormat$Builder;", encoding); +} + +CJNIAudioFormatBuilder CJNIAudioFormatBuilder::setSampleRate(int sampleRate) +{ + return call_method<jhobject>(m_object, + "setSampleRate", "(I)Landroid/media/AudioFormat$Builder;", sampleRate); +} diff --git a/xbmc/platform/android/jni/AudioFormat.h b/xbmc/platform/android/jni/AudioFormat.h index 59755245ed..61efd19701 100644 --- a/xbmc/platform/android/jni/AudioFormat.h +++ b/xbmc/platform/android/jni/AudioFormat.h @@ -19,45 +19,70 @@ * */ -#include "jutils/jutils-details.hpp" +#include "JNIBase.h" namespace jni { -class CJNIAudioFormat +class CJNIAudioFormat : public CJNIBase { - public: - static void PopulateStaticFields(); - - static int ENCODING_PCM_16BIT; - static int ENCODING_PCM_FLOAT; - static int ENCODING_AC3; - static int ENCODING_E_AC3; - static int ENCODING_DTS; - static int ENCODING_DTS_HD; - static int ENCODING_DOLBY_TRUEHD; - static int ENCODING_IEC61937; - - static int CHANNEL_OUT_STEREO; - static int CHANNEL_OUT_5POINT1; - - static int CHANNEL_OUT_FRONT_LEFT; - static int CHANNEL_OUT_FRONT_LEFT_OF_CENTER; - static int CHANNEL_OUT_FRONT_CENTER; - static int CHANNEL_OUT_FRONT_RIGHT_OF_CENTER; - static int CHANNEL_OUT_FRONT_RIGHT; - static int CHANNEL_OUT_LOW_FREQUENCY; - static int CHANNEL_OUT_SIDE_LEFT; - static int CHANNEL_OUT_SIDE_RIGHT; - static int CHANNEL_OUT_BACK_LEFT; - static int CHANNEL_OUT_BACK_CENTER; - static int CHANNEL_OUT_BACK_RIGHT; - - static int CHANNEL_INVALID; +public: + CJNIAudioFormat(const jni::jhobject &object) : CJNIBase(object) {} + + static void PopulateStaticFields(); + + static int ENCODING_PCM_16BIT; + static int ENCODING_PCM_FLOAT; + static int ENCODING_AC3; + static int ENCODING_E_AC3; + static int ENCODING_DTS; + static int ENCODING_DTS_HD; + static int ENCODING_DOLBY_TRUEHD; + static int ENCODING_IEC61937; + + static int CHANNEL_OUT_STEREO; + static int CHANNEL_OUT_5POINT1; + + static int CHANNEL_OUT_FRONT_LEFT; + static int CHANNEL_OUT_FRONT_LEFT_OF_CENTER; + static int CHANNEL_OUT_FRONT_CENTER; + static int CHANNEL_OUT_FRONT_RIGHT_OF_CENTER; + static int CHANNEL_OUT_FRONT_RIGHT; + static int CHANNEL_OUT_LOW_FREQUENCY; + static int CHANNEL_OUT_SIDE_LEFT; + static int CHANNEL_OUT_SIDE_RIGHT; + static int CHANNEL_OUT_BACK_LEFT; + static int CHANNEL_OUT_BACK_CENTER; + static int CHANNEL_OUT_BACK_RIGHT; + + static int CHANNEL_INVALID; + + int getChannelCount() const; + int getChannelIndexMask() const; + int getChannelMask() const; + int getEncoding() const; + int getSampleRate() const; protected: static void GetStaticValue(jhclass &c, int &field, char *value); + static const char *m_classname; }; +class CJNIAudioFormatBuilder : public CJNIBase +{ +public: + CJNIAudioFormatBuilder(); + CJNIAudioFormatBuilder(const jni::jhobject &object) : CJNIBase(object) {} + + CJNIAudioFormat build(); + + CJNIAudioFormatBuilder setChannelIndexMask(int channelIndexMask); + CJNIAudioFormatBuilder setChannelMask(int channelMask); + CJNIAudioFormatBuilder setEncoding(int encoding); + CJNIAudioFormatBuilder setSampleRate(int sampleRate); + +protected: + static const char *m_classname; }; +} diff --git a/xbmc/platform/android/jni/AudioManager.cpp b/xbmc/platform/android/jni/AudioManager.cpp index c848f24d32..7ac818be85 100644 --- a/xbmc/platform/android/jni/AudioManager.cpp +++ b/xbmc/platform/android/jni/AudioManager.cpp @@ -24,7 +24,6 @@ #include "jutils/jutils-details.hpp" -#include "platform/android/activity/JNIMainActivity.h" #include <algorithm> using namespace jni; @@ -33,17 +32,31 @@ int CJNIAudioManager::STREAM_MUSIC(3); int CJNIAudioManager::AUDIOFOCUS_GAIN(0x00000001); int CJNIAudioManager::AUDIOFOCUS_LOSS(0xffffffff); +int CJNIAudioManager::AUDIOFOCUS_GAIN_TRANSIENT(0x00000002); +int CJNIAudioManager::AUDIOFOCUS_LOSS_TRANSIENT(0xfffffffe); int CJNIAudioManager::AUDIOFOCUS_REQUEST_GRANTED(0x00000001); int CJNIAudioManager::AUDIOFOCUS_REQUEST_FAILED(0x00000000); +int CJNIAudioManager::GET_DEVICES_ALL(0x00000003); +int CJNIAudioManager::GET_DEVICES_INPUTS(0x00000001); +int CJNIAudioManager::GET_DEVICES_OUTPUTS(0x00000002); + void CJNIAudioManager::PopulateStaticFields() { jhclass clazz = find_class("android/media/AudioManager"); - STREAM_MUSIC = (get_static_field<int>(clazz, "STREAM_MUSIC")); - AUDIOFOCUS_GAIN = (get_static_field<int>(clazz, "AUDIOFOCUS_GAIN")); - AUDIOFOCUS_LOSS = (get_static_field<int>(clazz, "AUDIOFOCUS_LOSS")); - AUDIOFOCUS_REQUEST_GRANTED = (get_static_field<int>(clazz, "AUDIOFOCUS_REQUEST_GRANTED")); - AUDIOFOCUS_REQUEST_FAILED = (get_static_field<int>(clazz, "AUDIOFOCUS_REQUEST_FAILED")); + STREAM_MUSIC = (get_static_field<int>(clazz, "STREAM_MUSIC")); + AUDIOFOCUS_GAIN = (get_static_field<int>(clazz, "AUDIOFOCUS_GAIN")); + AUDIOFOCUS_LOSS = (get_static_field<int>(clazz, "AUDIOFOCUS_LOSS")); + AUDIOFOCUS_REQUEST_GRANTED = (get_static_field<int>(clazz, "AUDIOFOCUS_REQUEST_GRANTED")); + AUDIOFOCUS_REQUEST_FAILED = (get_static_field<int>(clazz, "AUDIOFOCUS_REQUEST_FAILED")); + + int sdk = CJNIBase::GetSDKVersion(); + if (sdk >= 23) + { + GET_DEVICES_ALL = (get_static_field<int>(clazz, "GET_DEVICES_ALL")); + GET_DEVICES_INPUTS = (get_static_field<int>(clazz, "GET_DEVICES_INPUTS")); + GET_DEVICES_OUTPUTS = (get_static_field<int>(clazz, "GET_DEVICES_OUTPUTS")); + } } int CJNIAudioManager::getStreamMaxVolume() @@ -95,6 +108,12 @@ bool CJNIAudioManager::isWiredHeadsetOn() "()Z"); } +CJNIAudioDeviceInfos CJNIAudioManager::getDevices(int flags) +{ + return jcast<CJNIAudioDeviceInfos>(call_method<jhobjectArray>(m_object, + "getDevices", "(I)[Landroid/media/AudioDeviceInfo;", flags)); +} + ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// CJNIAudioManagerAudioFocusChangeListener* CJNIAudioManagerAudioFocusChangeListener::m_listenerInstance(NULL); @@ -102,14 +121,10 @@ CJNIAudioManagerAudioFocusChangeListener* CJNIAudioManagerAudioFocusChangeListen CJNIAudioManagerAudioFocusChangeListener::CJNIAudioManagerAudioFocusChangeListener() : CJNIBase(CJNIContext::getPackageName() + ".XBMCOnAudioFocusChangeListener") { - CJNIMainActivity *appInstance = CJNIMainActivity::GetAppInstance(); - if (!appInstance) - return; - // Convert "the/class/name" to "the.class.name" as loadClass() expects it. std::string dotClassName = GetClassName(); std::replace(dotClassName.begin(), dotClassName.end(), '/', '.'); - m_object = new_object(appInstance->getClassLoader().loadClass(dotClassName)); + m_object = new_object(CJNIContext::getClassLoader().loadClass(dotClassName)); m_object.setGlobal(); m_listenerInstance = this; diff --git a/xbmc/platform/android/jni/AudioManager.h b/xbmc/platform/android/jni/AudioManager.h index 85d7d104b1..99bfb7cbf2 100644 --- a/xbmc/platform/android/jni/AudioManager.h +++ b/xbmc/platform/android/jni/AudioManager.h @@ -21,6 +21,8 @@ #include "JNIBase.h" +#include "AudioDeviceInfo.h" + class CJNIAudioManagerAudioFocusChangeListener : public CJNIBase { public: @@ -53,14 +55,22 @@ public: int abandonAudioFocus (const CJNIAudioManagerAudioFocusChangeListener &listener); bool isBluetoothA2dpOn(); bool isWiredHeadsetOn(); + + CJNIAudioDeviceInfos getDevices(int flags); static void PopulateStaticFields(); static int STREAM_MUSIC; static int AUDIOFOCUS_GAIN; static int AUDIOFOCUS_LOSS; + static int AUDIOFOCUS_GAIN_TRANSIENT; + static int AUDIOFOCUS_LOSS_TRANSIENT; static int AUDIOFOCUS_REQUEST_GRANTED; static int AUDIOFOCUS_REQUEST_FAILED; + + static int GET_DEVICES_ALL; + static int GET_DEVICES_INPUTS; + static int GET_DEVICES_OUTPUTS; private: CJNIAudioManager(); diff --git a/xbmc/platform/android/jni/AudioTimestamp.cpp b/xbmc/platform/android/jni/AudioTimestamp.cpp new file mode 100644 index 0000000000..44360ddcf3 --- /dev/null +++ b/xbmc/platform/android/jni/AudioTimestamp.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2016 Chris Browet + * + * 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 "AudioTimestamp.h" +#include "jutils/jutils-details.hpp" + +using namespace jni; + +CJNIAudioTimestamp::CJNIAudioTimestamp() : CJNIBase("android.media.AudioTimestamp") +{ + m_object = new_object(GetClassName()); + m_object.setGlobal(); +} + +CJNIAudioTimestamp::CJNIAudioTimestamp(const jhobject &object) : CJNIBase(object) +{ +} + +int64_t CJNIAudioTimestamp::get_framePosition() +{ + return get_field<jlong>(m_object, "framePosition"); +} + +int64_t CJNIAudioTimestamp::get_nanoTime() +{ + return get_field<jlong>(m_object, "nanoTime"); +} diff --git a/xbmc/platform/android/jni/AudioTimestamp.h b/xbmc/platform/android/jni/AudioTimestamp.h new file mode 100644 index 0000000000..e645ba5d72 --- /dev/null +++ b/xbmc/platform/android/jni/AudioTimestamp.h @@ -0,0 +1,34 @@ +#pragma once +/* + * Copyright (C) 2016 Chris Browet + * + * 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 "JNIBase.h" + +class CJNIAudioTimestamp : public CJNIBase +{ +public: + CJNIAudioTimestamp(); + CJNIAudioTimestamp(const jni::jhobject &object); + ~CJNIAudioTimestamp() {}; + + int64_t get_framePosition(); + int64_t get_nanoTime(); + +private: +}; diff --git a/xbmc/platform/android/jni/AudioTrack.cpp b/xbmc/platform/android/jni/AudioTrack.cpp index 619dfc5bfb..aff401e0e3 100644 --- a/xbmc/platform/android/jni/AudioTrack.cpp +++ b/xbmc/platform/android/jni/AudioTrack.cpp @@ -21,6 +21,7 @@ #include "AudioTrack.h" #include "jutils/jutils-details.hpp" #include "AudioFormat.h" +#include "ByteBuffer.h" using namespace jni; @@ -75,9 +76,38 @@ CJNIAudioTrack::CJNIAudioTrack(int streamType, int sampleRateInHz, int channelCo } m_audioFormat = audioFormat; - if (m_audioFormat == CJNIAudioFormat::ENCODING_IEC61937) - m_buffer = jharray(xbmc_jnienv()->NewShortArray(bufferSizeInBytes / sizeof(short))); - else if (m_audioFormat == CJNIAudioFormat::ENCODING_PCM_FLOAT) + if (m_audioFormat == CJNIAudioFormat::ENCODING_PCM_FLOAT) + m_buffer = jharray(xbmc_jnienv()->NewFloatArray(bufferSizeInBytes / sizeof(float))); + else if (m_audioFormat == CJNIAudioFormat::ENCODING_IEC61937) + m_buffer = jharray(xbmc_jnienv()->NewShortArray(bufferSizeInBytes / sizeof(uint16_t))); + else + m_buffer = jharray(xbmc_jnienv()->NewByteArray(bufferSizeInBytes)); + + m_object.setGlobal(); + m_buffer.setGlobal(); +} + +CJNIAudioTrack::CJNIAudioTrack(const CJNIAudioAttributes &attributes, const CJNIAudioFormat &format, int bufferSizeInBytes, int mode, int sessionId) throw(std::invalid_argument) + : CJNIBase("android/media/AudioTrack") +{ + m_object = new_object(GetClassName(), "<init>", "(Landroid/media/AudioAttributes;Landroid/media/AudioFormat;III)V", + attributes.get_raw(), format.get_raw(), bufferSizeInBytes, mode, sessionId); + + /* AudioTrack constructor may throw IllegalArgumentException, pass it to + * caller instead of getting us killed */ + JNIEnv* jenv = xbmc_jnienv(); + jthrowable exception = jenv->ExceptionOccurred(); + if (exception) + { + jenv->ExceptionClear(); + jhclass excClass = find_class(jenv, "java/lang/Throwable"); + jmethodID toStrMethod = get_method_id(jenv, excClass, "toString", "()Ljava/lang/String;"); + jhstring msg = call_method<jhstring>(exception, toStrMethod); + throw std::invalid_argument(jcast<std::string>(msg)); + } + + m_audioFormat = format.getEncoding(); + if (m_audioFormat == CJNIAudioFormat::ENCODING_PCM_FLOAT) m_buffer = jharray(xbmc_jnienv()->NewFloatArray(bufferSizeInBytes / sizeof(float))); else m_buffer = jharray(xbmc_jnienv()->NewByteArray(bufferSizeInBytes)); @@ -119,8 +149,6 @@ void CJNIAudioTrack::flush() void CJNIAudioTrack::release() { call_method<void>(m_object, "release", "()V"); - - JNIEnv* jenv = xbmc_jnienv(); } int CJNIAudioTrack::write(char* audioData, int offsetInBytes, int sizeInBytes) @@ -144,23 +172,40 @@ int CJNIAudioTrack::write(char* audioData, int offsetInBytes, int sizeInBytes) else if (m_audioFormat == CJNIAudioFormat::ENCODING_IEC61937) { if (CJNIBase::GetSDKVersion() >= 23) - written = call_method<int>(m_object, "write", "([SIII)I", m_buffer, (int)(offsetInBytes / sizeof(short)), (int)(sizeInBytes / sizeof(short)), CJNIAudioTrack::WRITE_BLOCKING); + written = call_method<int>(m_object, "write", "([SIII)I", m_buffer, (int)(offsetInBytes / sizeof(uint16_t)), (int)(sizeInBytes / sizeof(uint16_t)), CJNIAudioTrack::WRITE_BLOCKING); else - written = call_method<int>(m_object, "write", "([SII)I", m_buffer, (int)(offsetInBytes / sizeof(short)), (int)(sizeInBytes / sizeof(short))); - written *= sizeof(short); + written = call_method<int>(m_object, "write", "([SII)I", m_buffer, (int)(offsetInBytes / sizeof(uint16_t)), (int)(sizeInBytes / sizeof(uint16_t))); + written *= sizeof(uint16_t); } else { if (CJNIBase::GetSDKVersion() >= 23) - written = call_method<int>(m_object, "write", "([BII)I", m_buffer, offsetInBytes, sizeInBytes, CJNIAudioTrack::WRITE_BLOCKING); + written = call_method<int>(m_object, "write", "([BIII)I", m_buffer, offsetInBytes, sizeInBytes, CJNIAudioTrack::WRITE_BLOCKING); else - written = call_method<int>(m_object, "write", "([BII)I", m_buffer, offsetInBytes, sizeInBytes); + written = call_method<int>(m_object, "write", "([BII)I", m_buffer, offsetInBytes, sizeInBytes); } } return written; } +int CJNIAudioTrack::write(char* audioData, int sizeInBytes, int64_t timestamp) +{ + int written = 0; + JNIEnv* jenv = xbmc_jnienv(); + char* pArray; + + if ((pArray = (char*)jenv->GetPrimitiveArrayCritical(m_buffer, NULL))) + { + memcpy(pArray, audioData, sizeInBytes); + jenv->ReleasePrimitiveArrayCritical(m_buffer, pArray, 0); + CJNIByteBuffer buf = CJNIByteBuffer::wrap(m_buffer); + written = call_method<int>(m_object, "write", "(Ljava/nio/ByteBuffer;IIJ)I", buf.get_raw(), sizeInBytes, CJNIAudioTrack::WRITE_BLOCKING, timestamp); + } + + return written; +} + int CJNIAudioTrack::getState() { return call_method<int>(m_object, "getState", "()I"); @@ -176,6 +221,12 @@ int CJNIAudioTrack::getPlaybackHeadPosition() return call_method<int>(m_object, "getPlaybackHeadPosition", "()I"); } +bool CJNIAudioTrack::getTimestamp(CJNIAudioTimestamp ×tamp) +{ + return call_method<jboolean>(m_object, "getTimestamp", "(Landroid/media/AudioTimestamp;)Z", + timestamp.get_raw()); +} + // Can be used in v23 for comparing with the opened buffer amount int CJNIAudioTrack::getBufferSizeInFrames() { diff --git a/xbmc/platform/android/jni/AudioTrack.h b/xbmc/platform/android/jni/AudioTrack.h index 928a4d2805..cf698c1707 100644 --- a/xbmc/platform/android/jni/AudioTrack.h +++ b/xbmc/platform/android/jni/AudioTrack.h @@ -23,6 +23,9 @@ #include "JNIBase.h" #include "ByteBuffer.h" +#include "AudioTimestamp.h" +#include "AudioFormat.h" +#include "AudioAttributes.h" namespace jni { @@ -34,6 +37,7 @@ class CJNIAudioTrack : public CJNIBase public: CJNIAudioTrack(int streamType, int sampleRateInHz, int channelConfig, int audioFormat, int bufferSizeInBytes, int mode) throw(std::invalid_argument); + CJNIAudioTrack (const CJNIAudioAttributes &attributes, const CJNIAudioFormat &format, int bufferSizeInBytes, int mode, int sessionId) throw(std::invalid_argument); void play(); void pause(); @@ -41,9 +45,11 @@ class CJNIAudioTrack : public CJNIBase void flush(); void release(); int write(char* audioData, int offsetInBytes, int sizeInBytes); + int write(char *audioData, int sizeInBytes, int64_t timestamp); int getState(); int getPlayState(); int getPlaybackHeadPosition(); + bool getTimestamp (CJNIAudioTimestamp ×tamp); int getBufferSizeInFrames(); static int MODE_STREAM; diff --git a/xbmc/platform/android/jni/BroadcastReceiver.cpp b/xbmc/platform/android/jni/BroadcastReceiver.cpp index 922b04fcfb..6e437cad6e 100644 --- a/xbmc/platform/android/jni/BroadcastReceiver.cpp +++ b/xbmc/platform/android/jni/BroadcastReceiver.cpp @@ -25,17 +25,11 @@ #include "ClassLoader.h" #include "jutils/jutils-details.hpp" -#include "platform/android/activity/JNIMainActivity.h" - using namespace jni; CJNIBroadcastReceiver *CJNIBroadcastReceiver::m_receiverInstance(NULL); CJNIBroadcastReceiver::CJNIBroadcastReceiver(const std::string &className) : CJNIBase(className) { - CJNIMainActivity *appInstance = CJNIMainActivity::GetAppInstance(); - if (!appInstance || className.empty()) - return; - // Convert "the/class/name" to "the.class.name" as loadClass() expects it. std::string dotClassName = GetClassName(); for (std::string::iterator it = dotClassName.begin(); it != dotClassName.end(); ++it) @@ -43,7 +37,7 @@ CJNIBroadcastReceiver::CJNIBroadcastReceiver(const std::string &className) : CJN if (*it == '/') *it = '.'; } - m_object = new_object(appInstance->getClassLoader().loadClass(dotClassName)); + m_object = new_object(CJNIContext::getClassLoader().loadClass(dotClassName)); m_receiverInstance = this; m_object.setGlobal(); } diff --git a/xbmc/platform/android/jni/ByteBuffer.cpp b/xbmc/platform/android/jni/ByteBuffer.cpp index 45983c74f9..da12cdff35 100644 --- a/xbmc/platform/android/jni/ByteBuffer.cpp +++ b/xbmc/platform/android/jni/ByteBuffer.cpp @@ -63,6 +63,12 @@ CJNIByteBuffer CJNIByteBuffer::wrap(const std::vector<char> &array) bytearray)); } +CJNIByteBuffer CJNIByteBuffer::wrap(const jharray &array) +{ + return CJNIByteBuffer(call_static_method<jhobject>(m_classname, + "wrap","([B)Ljava/nio/ByteBuffer;", array)); +} + CJNIByteBuffer CJNIByteBuffer::duplicate() { return CJNIByteBuffer(call_method<jhobject>(m_object, diff --git a/xbmc/platform/android/jni/ByteBuffer.h b/xbmc/platform/android/jni/ByteBuffer.h index 83286b3616..42c882b4da 100644 --- a/xbmc/platform/android/jni/ByteBuffer.h +++ b/xbmc/platform/android/jni/ByteBuffer.h @@ -34,6 +34,7 @@ public: static CJNIByteBuffer allocate(int capacity); static CJNIByteBuffer wrap(const std::vector<char> &array, int start, int byteCount); static CJNIByteBuffer wrap(const std::vector<char> &array); + static CJNIByteBuffer wrap(const jni::jharray &array); CJNIByteBuffer duplicate(); diff --git a/xbmc/platform/android/jni/CMakeLists.txt b/xbmc/platform/android/jni/CMakeLists.txt index 834a8abe68..925af81949 100644 --- a/xbmc/platform/android/jni/CMakeLists.txt +++ b/xbmc/platform/android/jni/CMakeLists.txt @@ -61,7 +61,29 @@ set(SOURCES Activity.cpp WifiManager.cpp WifiManagerMulticastLock.cpp Window.cpp - WindowManager.cpp) + WindowManager.cpp + Notification.cpp + Settings.cpp + URIPermission.cpp + DocumentsContract.cpp + Document.cpp + AudioTimestamp.cpp + ArrayList.cpp + RecognizerIntent.cpp + AudioDeviceInfo.cpp + PlaybackParams.cpp + MediaTimestamp.cpp + MediaSync.cpp + AudioAttributes.cpp + Image.cpp + Network.cpp + LinkProperties.cpp + LinkAddress.cpp + RouteInfo.cpp + InetAddress.cpp + NetworkInterface.cpp + ) + set(HEADERS Activity.h ApplicationInfo.h @@ -127,6 +149,26 @@ set(HEADERS Activity.h WifiManagerMulticastLock.h Window.h WindowManager.h + Notification.h + Settings.h + URIPermission.h + DocumentsContract.h + Document.h + AudioTimestamp.h + ArrayList.h + RecognizerIntent.h + AudioDeviceInfo.h + PlaybackParams.h + MediaTimestamp.h + MediaSync.h + AudioAttributes.h + Image.h + Network.h + LinkProperties.h + LinkAddress.h + RouteInfo.h + InetAddress.h + NetworkInterface.h jutils/jutils.hpp jutils/jutils-details.hpp) diff --git a/xbmc/platform/android/jni/ConnectivityManager.cpp b/xbmc/platform/android/jni/ConnectivityManager.cpp index 2acd939cdb..fb15bbf992 100644 --- a/xbmc/platform/android/jni/ConnectivityManager.cpp +++ b/xbmc/platform/android/jni/ConnectivityManager.cpp @@ -19,7 +19,10 @@ */ #include "ConnectivityManager.h" +#include "Network.h" #include "NetworkInfo.h" +#include "LinkProperties.h" + #include "jutils/jutils-details.hpp" using namespace jni; @@ -72,6 +75,12 @@ int CJNIConnectivityManager::getNetworkPreference() "getNetworkPreference", "()I"); } +CJNINetwork CJNIConnectivityManager::getActiveNetwork() +{ + return call_method<jhobject>(m_object, + "getActiveNetwork", "()Landroid/net/Network;"); +} + CJNINetworkInfo CJNIConnectivityManager::getActiveNetworkInfo() { return call_method<jhobject>(m_object, @@ -85,6 +94,27 @@ CJNINetworkInfo CJNIConnectivityManager::getNetworkInfo(int networkType) networkType); } +CJNINetworkInfo CJNIConnectivityManager::getNetworkInfo(const CJNINetwork& network) +{ + return call_method<jhobject>(m_object, + "getNetworkInfo", "(Landroid/net/Network;)Landroid/net/NetworkInfo;", + network.get_raw()); +} + +CJNILinkProperties CJNIConnectivityManager::getLinkProperties(const CJNINetwork& network) +{ + return call_method<jhobject>(m_object, + "getLinkProperties", "(Landroid/net/Network;)Landroid/net/LinkProperties;", + network.get_raw()); +} + +std::vector<CJNINetwork> CJNIConnectivityManager::getAllNetworks() +{ + return jcast<CJNINetworks>(call_method<jhobjectArray>(m_object, + "getAllNetworks", "()[Landroid/net/Network;")); +} + + std::vector<CJNINetworkInfo> CJNIConnectivityManager::getAllNetworkInfo() { JNIEnv *env = xbmc_jnienv(); diff --git a/xbmc/platform/android/jni/ConnectivityManager.h b/xbmc/platform/android/jni/ConnectivityManager.h index 87a9c7bdd7..2b70cbd597 100644 --- a/xbmc/platform/android/jni/ConnectivityManager.h +++ b/xbmc/platform/android/jni/ConnectivityManager.h @@ -24,7 +24,9 @@ #include "JNIBase.h" +class CJNINetwork; class CJNINetworkInfo; +class CJNILinkProperties; class CJNIConnectivityManager : public CJNIBase { @@ -34,8 +36,12 @@ public: bool isNetworkTypeValid(int); void setNetworkPreference(int); int getNetworkPreference(); + CJNINetwork getActiveNetwork(); CJNINetworkInfo getActiveNetworkInfo(); CJNINetworkInfo getNetworkInfo(int); + CJNINetworkInfo getNetworkInfo(const CJNINetwork& network); + CJNILinkProperties getLinkProperties(const CJNINetwork& network); + std::vector<CJNINetwork> getAllNetworks(); std::vector<CJNINetworkInfo> getAllNetworkInfo(); int startUsingNetworkFeature(int, std::string); int stopUsingNetworkFeature(int, std::string); diff --git a/xbmc/platform/android/jni/ContentResolver.cpp b/xbmc/platform/android/jni/ContentResolver.cpp index 16e5c96224..81dbdfbb74 100644 --- a/xbmc/platform/android/jni/ContentResolver.cpp +++ b/xbmc/platform/android/jni/ContentResolver.cpp @@ -47,3 +47,15 @@ CJNICursor CJNIContentResolver::query(const CJNIURI &uri, const std::vector<std: "query","(Landroid/net/Uri;[Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)Landroid/database/Cursor;", uri.get_raw(), jcast<jhobjectArray>(projection), jcast<jhstring>(selection), jcast<jhobjectArray>(selectionArgs), jcast<jhstring>(sortOrder))); } + +void CJNIContentResolver::takePersistableUriPermission(const CJNIURI &uri, int modeFlags) +{ + call_method<void>(m_object, + "takePersistableUriPermission", "(Landroid/net/Uri;I)V", uri.get_raw(), modeFlags); +} + +CJNIList<CJNIURIPermission> CJNIContentResolver::getPersistedUriPermissions() +{ + return call_method<jhobject>(m_object, + "getPersistedUriPermissions", "()Ljava/util/List;"); +} diff --git a/xbmc/platform/android/jni/ContentResolver.h b/xbmc/platform/android/jni/ContentResolver.h index 5f9a1d120a..d4eecba317 100644 --- a/xbmc/platform/android/jni/ContentResolver.h +++ b/xbmc/platform/android/jni/ContentResolver.h @@ -23,6 +23,8 @@ #include <vector> #include "JNIBase.h" +#include "URIPermission.h" +#include "List.h" class CJNICursor; class CJNIURI; @@ -30,9 +32,11 @@ class CJNIURI; class CJNIContentResolver : public CJNIBase { public: - CJNIContentResolver(const jni::jhobject &object) : CJNIBase(object) {}; + CJNIContentResolver(const jni::jhobject &object) : CJNIBase(object) {} CJNICursor query(const CJNIURI &uri, const std::vector<std::string> &projection, const std::string &selection, const std::vector<std::string> &selectionArgs, const std::string &sortOrder); + void takePersistableUriPermission(const CJNIURI &uri, int modeFlags); + CJNIList<CJNIURIPermission> getPersistedUriPermissions(); static void PopulateStaticFields(); static std::string SCHEME_CONTENT; diff --git a/xbmc/platform/android/jni/Context.cpp b/xbmc/platform/android/jni/Context.cpp index 35f988b055..47592a66e4 100644 --- a/xbmc/platform/android/jni/Context.cpp +++ b/xbmc/platform/android/jni/Context.cpp @@ -36,6 +36,7 @@ #include "Cursor.h" #include "ConnectivityManager.h" #include "AudioFormat.h" +#include "AudioAttributes.h" #include "AudioManager.h" #include "AudioTrack.h" #include "Surface.h" @@ -48,6 +49,12 @@ #include "DisplayMetrics.h" #include "Intent.h" #include "KeyEvent.h" +#include "Settings.h" +#include "Environment.h" +#include "Document.h" +#include "RecognizerIntent.h" +#include "AudioDeviceInfo.h" +#include "MediaSync.h" #include <android/native_activity.h> @@ -55,6 +62,8 @@ using namespace jni; jhobject CJNIContext::m_context(0); +std::string CJNIContext::CONNECTIVITY_SERVICE; + CJNIContext::CJNIContext(const ANativeActivity *nativeActivity) { m_context.reset(nativeActivity->clazz); @@ -69,6 +78,9 @@ CJNIContext::~CJNIContext() void CJNIContext::PopulateStaticFields() { + jhclass clazz = find_class("android/content/Context"); + CONNECTIVITY_SERVICE = jcast<std::string>(get_static_field<jhstring>(clazz,"CONNECTIVITY_SERVICE")); + CJNIBaseColumns::PopulateStaticFields(); CJNIMediaStoreMediaColumns::PopulateStaticFields(); CJNIPowerManager::PopulateStaticFields(); @@ -78,6 +90,7 @@ void CJNIContext::PopulateStaticFields() CJNIContentResolver::PopulateStaticFields(); CJNIConnectivityManager::PopulateStaticFields(); CJNIAudioFormat::PopulateStaticFields(); + CJNIAudioAttributes::PopulateStaticFields(); CJNIAudioManager::PopulateStaticFields(); CJNIAudioTrack::PopulateStaticFields(); CJNISurface::PopulateStaticFields(); @@ -90,7 +103,13 @@ void CJNIContext::PopulateStaticFields() CJNIDisplayMetrics::PopulateStaticFields(); CJNIIntent::PopulateStaticFields(); CJNIKeyEvent::PopulateStaticFields(); + CJNISettings::PopulateStaticFields(); + CJNIEnvironment::PopulateStaticFields(); + CJNIDocument::PopulateStaticFields(); + CJNIRecognizerIntent::PopulateStaticFields(); + CJNIAudioDeviceInfo::PopulateStaticFields(); CJNIViewInputDevice::PopulateStaticFields(); + CJNIMediaSync::PopulateStaticFields(); } CJNIPackageManager CJNIContext::GetPackageManager() diff --git a/xbmc/platform/android/jni/Context.h b/xbmc/platform/android/jni/Context.h index ecf187efed..0531859c3d 100644 --- a/xbmc/platform/android/jni/Context.h +++ b/xbmc/platform/android/jni/Context.h @@ -38,6 +38,8 @@ class CJNIContext public: const jni::jhobject& get_raw() const { return m_context; } + static std::string CONNECTIVITY_SERVICE; + static CJNIPackageManager GetPackageManager(); static void startActivity(const CJNIIntent &intent); static jni::jhobject getSystemService(const std::string &service); diff --git a/xbmc/platform/android/jni/Cursor.cpp b/xbmc/platform/android/jni/Cursor.cpp index 7625dbcabd..d7fced3aa5 100644 --- a/xbmc/platform/android/jni/Cursor.cpp +++ b/xbmc/platform/android/jni/Cursor.cpp @@ -149,35 +149,35 @@ std::string CJNICursor::getString(int columnIndex) short CJNICursor::getShort(int columnIndex) { return call_method<jshort>(m_object, - "getShort", "()S", + "getShort", "(I)S", columnIndex); } int CJNICursor::getInt(int columnIndex) { return call_method<jint>(m_object, - "getInt", "()I", + "getInt", "(I)I", columnIndex); } int64_t CJNICursor::getLong(int columnIndex) { return call_method<jlong>(m_object, - "getLong", "()J", + "getLong", "(I)J", columnIndex); } float CJNICursor::getFloat(int columnIndex) { return call_method<jfloat>(m_object, - "getFloat", "()F", + "getFloat", "(I)F", columnIndex); } double CJNICursor::getDouble(int columnIndex) { return call_method<jdouble>(m_object, - "getDouble", "()D", + "getDouble", "(I)D", columnIndex); } diff --git a/xbmc/platform/android/jni/Document.cpp b/xbmc/platform/android/jni/Document.cpp new file mode 100644 index 0000000000..53d4deca30 --- /dev/null +++ b/xbmc/platform/android/jni/Document.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (C) 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 "Document.h" +#include "jutils/jutils-details.hpp" + +using namespace jni; + +std::string CJNIDocument::COLUMN_DISPLAY_NAME; +std::string CJNIDocument::COLUMN_MIME_TYPE; +std::string CJNIDocument::COLUMN_DOCUMENT_ID; +std::string CJNIDocument::COLUMN_SIZE; +std::string CJNIDocument::COLUMN_FLAGS; +std::string CJNIDocument::MIME_TYPE_DIR; + +void CJNIDocument::PopulateStaticFields() +{ + if (CJNIBase::GetSDKVersion() >= 19) + { + jhclass c = find_class("android/provider/DocumentsContract$Document"); + CJNIDocument::COLUMN_DISPLAY_NAME = jcast<std::string>(get_static_field<jhstring>(c,"COLUMN_DISPLAY_NAME")); + CJNIDocument::COLUMN_MIME_TYPE = jcast<std::string>(get_static_field<jhstring>(c,"COLUMN_MIME_TYPE")); + CJNIDocument::COLUMN_DOCUMENT_ID = jcast<std::string>(get_static_field<jhstring>(c,"COLUMN_DOCUMENT_ID")); + CJNIDocument::COLUMN_SIZE = jcast<std::string>(get_static_field<jhstring>(c,"COLUMN_SIZE")); + CJNIDocument::COLUMN_FLAGS = jcast<std::string>(get_static_field<jhstring>(c,"COLUMN_FLAGS")); + CJNIDocument::MIME_TYPE_DIR = jcast<std::string>(get_static_field<jhstring>(c,"MIME_TYPE_DIR")); + } +} diff --git a/xbmc/platform/android/jni/Document.h b/xbmc/platform/android/jni/Document.h new file mode 100644 index 0000000000..58ea43298a --- /dev/null +++ b/xbmc/platform/android/jni/Document.h @@ -0,0 +1,41 @@ +#pragma once +/* + * Copyright (C) 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 "JNIBase.h" + +class CJNIURI; + +class CJNIDocument : public CJNIBase +{ +public: + static void PopulateStaticFields(); + + static std::string COLUMN_DISPLAY_NAME; + static std::string COLUMN_MIME_TYPE; + static std::string COLUMN_DOCUMENT_ID; + static std::string COLUMN_SIZE; + static std::string COLUMN_FLAGS; + static std::string MIME_TYPE_DIR; + +protected: + CJNIDocument(); + ~CJNIDocument(){} +}; diff --git a/xbmc/platform/android/jni/DocumentsContract.cpp b/xbmc/platform/android/jni/DocumentsContract.cpp new file mode 100644 index 0000000000..7a05b1cd96 --- /dev/null +++ b/xbmc/platform/android/jni/DocumentsContract.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (C) 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 "DocumentsContract.h" +#include "URI.h" +#include "jutils/jutils-details.hpp" + +using namespace jni; + +void CJNIDocumentsContract::PopulateStaticFields() +{ +} + +std::string CJNIDocumentsContract::getTreeDocumentId(const CJNIURI &documentUri) +{ + return jcast<std::string>(call_static_method<jhstring>("android/provider/DocumentsContract", + "getTreeDocumentId", "(Landroid/net/Uri;)Ljava/lang/String;", documentUri.get_raw())); +} + +std::string CJNIDocumentsContract::getDocumentId(const CJNIURI &documentUri) +{ + return jcast<std::string>(call_static_method<jhstring>("android/provider/DocumentsContract", + "getDocumentId", "(Landroid/net/Uri;)Ljava/lang/String;", documentUri.get_raw())); +} + +CJNIURI CJNIDocumentsContract::buildChildDocumentsUri(const std::string &authority, const std::string &parentDocumentId) +{ + return (CJNIURI)call_static_method<jhobject>("android/provider/DocumentsContract", + "buildChildDocumentsUri", "(Ljava/lang/String;Ljava/lang/String;)Landroid/net/Uri;", jcast<jhstring>(authority), jcast<jhstring>(parentDocumentId)); +} + +CJNIURI CJNIDocumentsContract::buildChildDocumentsUriUsingTree(const CJNIURI &treeUri, const std::string& parentDocumentId) +{ + return (CJNIURI)call_static_method<jhobject>("android/provider/DocumentsContract", + "buildChildDocumentsUriUsingTree", "(Landroid/net/Uri;Ljava/lang/String;)Landroid/net/Uri;", treeUri.get_raw(), jcast<jhstring>(parentDocumentId)); +} + +CJNIURI CJNIDocumentsContract::buildDocumentUriUsingTree(const CJNIURI &treeUri, const std::string& parentDocumentId) +{ + return (CJNIURI)call_static_method<jhobject>("android/provider/DocumentsContract", + "buildDocumentUriUsingTree", "(Landroid/net/Uri;Ljava/lang/String;)Landroid/net/Uri;", treeUri.get_raw(), jcast<jhstring>(parentDocumentId)); +} diff --git a/xbmc/platform/android/jni/DocumentsContract.h b/xbmc/platform/android/jni/DocumentsContract.h new file mode 100644 index 0000000000..6e9df536af --- /dev/null +++ b/xbmc/platform/android/jni/DocumentsContract.h @@ -0,0 +1,40 @@ +#pragma once +/* + * Copyright (C) 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 "JNIBase.h" + +class CJNIURI; + +class CJNIDocumentsContract : public CJNIBase +{ +public: + static void PopulateStaticFields(); + + static std::string getTreeDocumentId (const CJNIURI& documentUri); + static std::string getDocumentId (const CJNIURI& documentUri); + static CJNIURI buildChildDocumentsUriUsingTree (const CJNIURI& treeUri, const std::string& parentDocumentId); + static CJNIURI buildChildDocumentsUri (const std::string& authority, const std::string& parentDocumentId); + static CJNIURI buildDocumentUriUsingTree (const CJNIURI& treeUri, const std::string& parentDocumentId); + +protected: + CJNIDocumentsContract(); + ~CJNIDocumentsContract(){} +}; diff --git a/xbmc/platform/android/jni/Image.cpp b/xbmc/platform/android/jni/Image.cpp new file mode 100644 index 0000000000..3e9f9f9d3d --- /dev/null +++ b/xbmc/platform/android/jni/Image.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2016 Chris Browet + * 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 "Image.h" +#include "jutils/jutils-details.hpp" + +using namespace jni; + +const CJNIByteBuffer CJNIImagePlane::getBuffer() +{ + return call_method<jhobject>(m_object, + "getBuffer", "()Ljava/nio/ByteBuffer;"); +} + +int CJNIImagePlane::getPixelStride() +{ + return call_method<jint>(m_object, + "getPixelStride", "()I"); +} + +int CJNIImagePlane::getRowStride() +{ + return call_method<jint>(m_object, + "getRowStride", "()I"); +} + +void CJNIImage::close() +{ + call_method<void>(m_object, + "close", "()V"); +} + +int CJNIImage::getFormat() +{ + return call_method<jint>(m_object, + "getFormat", "()I"); +} + +std::vector<CJNIImagePlane> CJNIImage::getPlanes() +{ + return jcast<std::vector<CJNIImagePlane>>(call_method<jhobjectArray>(m_object, + "getPlanes", "()[Landroid/media/Image$Plane;")); +} + +int CJNIImage::getHeight() +{ + return call_method<jint>(m_object, + "getHeight", "()I"); +} + +int CJNIImage::getWidth() +{ + return call_method<jint>(m_object, + "getWidth", "()I"); +} diff --git a/xbmc/platform/android/jni/Image.h b/xbmc/platform/android/jni/Image.h new file mode 100644 index 0000000000..6e3d40f4b1 --- /dev/null +++ b/xbmc/platform/android/jni/Image.h @@ -0,0 +1,59 @@ +#pragma once +/* + * Copyright (C) 2016 Christian Browet + * 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 "JNIBase.h" + +#include "ByteBuffer.h" + +namespace jni +{ + +class CJNIImagePlane : public CJNIBase +{ +public: + CJNIImagePlane(const jni::jhobject &object) : CJNIBase(object) {} + + const CJNIByteBuffer getBuffer(); + int getPixelStride(); + int getRowStride(); + +protected: + CJNIImagePlane(); +}; + +class CJNIImage : public CJNIBase +{ +public: + CJNIImage() : CJNIBase() {} + CJNIImage(const jhobject &object) : CJNIBase(object) {} + ~CJNIImage() {} + + void close(); + int getFormat(); + std::vector<CJNIImagePlane> getPlanes(); + + int getHeight(); + int getWidth(); + +}; + +} + diff --git a/xbmc/platform/android/jni/InetAddress.cpp b/xbmc/platform/android/jni/InetAddress.cpp new file mode 100644 index 0000000000..a07ad0650c --- /dev/null +++ b/xbmc/platform/android/jni/InetAddress.cpp @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2016 Christian Browet + * 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 "InetAddress.h" +#include "jutils/jutils-details.hpp" + +using namespace jni; + +const char* CJNIInetAddress::m_classname = "java/net/InetAddress"; + +CJNIInetAddress CJNIInetAddress::getLocalHost() +{ + return CJNIInetAddress(call_static_method<jhobject>(m_classname, + "getLocalHost", "()Ljava/net/InetAddress;")); +} + +CJNIInetAddress CJNIInetAddress::getLoopbackAddress() +{ + return CJNIInetAddress(call_static_method<jhobject>(m_classname, + "getLoopbackAddress", "()Ljava/net/InetAddress;")); +} + +CJNIInetAddress CJNIInetAddress::getByName(std::string host) +{ + return CJNIInetAddress(call_static_method<jhobject>(m_classname, + "getByName", "(Ljava/lang/String;)Ljava/net/InetAddress;", jcast<jhstring>(host))); +} + +std::vector<char> CJNIInetAddress::getAddress() +{ + JNIEnv *env = xbmc_jnienv(); + jhbyteArray array = call_method<jhbyteArray>(m_object, + "getAddress", "()[B"); + + jsize size = env->GetArrayLength(array.get()); + + std::vector<char> result; + result.resize(size); + env->GetByteArrayRegion(array.get(), 0, size, (jbyte*)result.data()); + + return result; +} + +std::string CJNIInetAddress::getHostAddress() +{ + return jcast<std::string>(call_method<jhstring>(m_object, + "getHostAddress", "()Ljava/lang/String;")); +} + +std::string CJNIInetAddress::getHostName() +{ + return jcast<std::string>(call_method<jhstring>(m_object, + "getHostName", "()Ljava/lang/String;")); +} + +std::string CJNIInetAddress::getCanonicalHostName() +{ + return jcast<std::string>(call_method<jhstring>(m_object, + "getCanonicalHostName", "()Ljava/lang/String;")); +} + +bool CJNIInetAddress::equals(const CJNIInetAddress& other) +{ + return call_method<jboolean>(m_object, + "equals", "(Ljava/lang/Object;)Z", other.get_raw()); +} + +std::string CJNIInetAddress::toString() const +{ + return jcast<std::string>(call_method<jhstring>(m_object, + "toString", "()Ljava/lang/String;")); +} + +int CJNIInetAddress::describeContents() const +{ + return call_method<jint>(m_object, + "describeContents", "()I"); +} + diff --git a/xbmc/platform/android/jni/InetAddress.h b/xbmc/platform/android/jni/InetAddress.h new file mode 100644 index 0000000000..a8fb0f8e78 --- /dev/null +++ b/xbmc/platform/android/jni/InetAddress.h @@ -0,0 +1,50 @@ +#pragma once +/* + * Copyright (C) 2016 Christian Browet + * 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 "JNIBase.h" + +#include <vector> + +class CJNIInetAddress : public CJNIBase +{ +public: + CJNIInetAddress(const jni::jhobject &object) : CJNIBase(object){} + ~CJNIInetAddress(){} + + static CJNIInetAddress getLocalHost(); + static CJNIInetAddress getLoopbackAddress(); + static CJNIInetAddress getByName(std::string host); + + std::vector<char> getAddress(); + std::string getHostAddress(); + std::string getHostName(); + std::string getCanonicalHostName(); + + bool equals(const CJNIInetAddress &other); + std::string toString() const; + int describeContents() const; + +protected: + CJNIInetAddress(); + static const char *m_classname; +}; + +typedef std::vector<CJNIInetAddress> CJNIInetAddresss; diff --git a/xbmc/platform/android/jni/InputManager.cpp b/xbmc/platform/android/jni/InputManager.cpp index 8726f35813..caf0adea2d 100644 --- a/xbmc/platform/android/jni/InputManager.cpp +++ b/xbmc/platform/android/jni/InputManager.cpp @@ -23,7 +23,6 @@ #include "InputManager.h" #include "ClassLoader.h" #include "Context.h" -#include "platform/android/activity/JNIMainActivity.h" #include "jutils/jutils-details.hpp" @@ -36,14 +35,10 @@ CJNIInputManagerInputDeviceListener* CJNIInputManagerInputDeviceListener::m_list CJNIInputManagerInputDeviceListener::CJNIInputManagerInputDeviceListener() : CJNIBase(CJNIContext::getPackageName() + ".XBMCInputDeviceListener") { - CJNIMainActivity *appInstance = CJNIMainActivity::GetAppInstance(); - if (!appInstance) - return; - // Convert "the/class/name" to "the.class.name" as loadClass() expects it. std::string dotClassName = GetClassName(); std::replace(dotClassName.begin(), dotClassName.end(), '/', '.'); - m_object = new_object(appInstance->getClassLoader().loadClass(dotClassName)); + m_object = new_object(CJNIContext::getClassLoader().loadClass(dotClassName)); m_object.setGlobal(); m_listenerInstance = this; diff --git a/xbmc/platform/android/jni/Intent.cpp b/xbmc/platform/android/jni/Intent.cpp index 264a629d8c..2d4d195458 100644 --- a/xbmc/platform/android/jni/Intent.cpp +++ b/xbmc/platform/android/jni/Intent.cpp @@ -21,15 +21,19 @@ #include "Intent.h" #include "jutils/jutils-details.hpp" #include "URI.h" +#include "ArrayList.h" using namespace jni; std::string CJNIIntent::EXTRA_KEY_EVENT; +std::string CJNIIntent::ACTION_OPEN_DOCUMENT_TREE; void CJNIIntent::PopulateStaticFields() { jhclass clazz = find_class("android/content/Intent"); EXTRA_KEY_EVENT = jcast<std::string>(get_static_field<jhstring>(clazz,"EXTRA_KEY_EVENT")); + if (CJNIIntent::GetSDKVersion() >= 21) + ACTION_OPEN_DOCUMENT_TREE = jcast<std::string>(get_static_field<jhstring>(clazz,"ACTION_OPEN_DOCUMENT_TREE")); } CJNIIntent::CJNIIntent(const std::string &action) : CJNIBase("android/content/Intent") @@ -101,10 +105,17 @@ bool CJNIIntent::hasCategory(const std::string &category) const jcast<jhstring>(category)); } +CJNIIntent CJNIIntent::putExtra(const std::string &name, const std::string &value) +{ + return (CJNIIntent)call_method<jhobject>(m_object, + "putExtra", "(Ljava/lang/String;Ljava/lang/String;)Landroid/content/Intent;", + jcast<jhstring>(name), jcast<jhstring>(value)); +} + void CJNIIntent::addFlags(int flags) { call_method<jhobject>(m_object, - "addFlags", "(I;)Landroid/content/Intent;", + "addFlags", "(I)Landroid/content/Intent;", flags); } @@ -169,3 +180,9 @@ CJNIURI CJNIIntent::getData() const return (CJNIURI)call_method<jhobject>(m_object, "getData","()Landroid/net/Uri;"); } + +CJNIArrayList<std::string> CJNIIntent::getStringArrayListExtra(const std::string &key) const +{ + return call_method<jhobject>(m_object, + "getStringArrayListExtra","(Ljava/lang/String;)Ljava/util/ArrayList;", jcast<jhstring>(key)); +} diff --git a/xbmc/platform/android/jni/Intent.h b/xbmc/platform/android/jni/Intent.h index 6855fba284..540425b60c 100644 --- a/xbmc/platform/android/jni/Intent.h +++ b/xbmc/platform/android/jni/Intent.h @@ -20,6 +20,7 @@ */ #include "JNIBase.h" +#include "ArrayList.h" class CJNIURI; class CJNIIntent : public CJNIBase @@ -41,6 +42,8 @@ public: bool hasExtra(const std::string &name) const; bool hasCategory(const std::string &category) const; + CJNIIntent putExtra(const std::string &name, const std::string &value); + void addFlags(int flags); void addCategory(const std::string &category); void setFlags(int flags); @@ -54,7 +57,9 @@ public: void setPackage(const std::string &packageName); void setType(const std::string &type); CJNIURI getData() const; + CJNIArrayList<std::string> getStringArrayListExtra(const std::string &key) const; static void PopulateStaticFields(); static std::string EXTRA_KEY_EVENT; + static std::string ACTION_OPEN_DOCUMENT_TREE; }; diff --git a/xbmc/platform/android/jni/JNIBase.cpp b/xbmc/platform/android/jni/JNIBase.cpp index 78ec6e5557..cccd2f8773 100644 --- a/xbmc/platform/android/jni/JNIBase.cpp +++ b/xbmc/platform/android/jni/JNIBase.cpp @@ -19,11 +19,13 @@ */ #include "JNIBase.h" +#include "jutils/jutils-details.hpp" #include <algorithm> using namespace jni; int CJNIBase::m_sdk_version = -1; +int CJNIBase::RESULT_OK = -1; CJNIBase::CJNIBase(std::string classname) { @@ -53,3 +55,24 @@ int CJNIBase::GetSDKVersion() { return m_sdk_version; } + +const std::string CJNIBase::GetDotClassName() +{ + std::string dotClassName = m_className; + std::replace(dotClassName.begin(), dotClassName.end(), '/', '.'); + return dotClassName; +} + +const std::string CJNIBase::ExceptionToString() +{ + JNIEnv* jenv = xbmc_jnienv(); + jhthrowable exception = (jhthrowable)jenv->ExceptionOccurred(); + if (!exception) + return ""; + + jenv->ExceptionClear(); + jhclass excClass = find_class(jenv, "java/lang/Throwable"); + jmethodID toStrMethod = get_method_id(jenv, excClass, "toString", "()Ljava/lang/String;"); + jhstring msg = call_method<jhstring>(exception, toStrMethod); + return (jcast<std::string>(msg)); +} diff --git a/xbmc/platform/android/jni/JNIBase.h b/xbmc/platform/android/jni/JNIBase.h index f60939333e..0dff3eb9f9 100644 --- a/xbmc/platform/android/jni/JNIBase.h +++ b/xbmc/platform/android/jni/JNIBase.h @@ -31,6 +31,9 @@ public: operator safe_bool_type() const { return !m_object ? 0 : &CJNIBase::non_null_object; } const jni::jhobject& get_raw() const { return m_object; } static int GetSDKVersion(); + const static std::string ExceptionToString(); + + static int RESULT_OK; protected: CJNIBase() {} @@ -38,7 +41,8 @@ protected: CJNIBase(std::string classname); ~CJNIBase(); - const std::string & GetClassName() {return m_className;}; + const std::string & GetClassName() {return m_className;} + const std::string GetDotClassName(); jni::jhobject m_object; diff --git a/xbmc/platform/android/jni/JNIThreading.cpp b/xbmc/platform/android/jni/JNIThreading.cpp index 9f3e58ee91..0cd6ba94c4 100644 --- a/xbmc/platform/android/jni/JNIThreading.cpp +++ b/xbmc/platform/android/jni/JNIThreading.cpp @@ -35,6 +35,8 @@ were renamed to avoid collisions when linking against the originals. */ +#define HAVE_INTTYPES_H 1 + #include <jni.h> #include <pthread.h> #include <stdlib.h> diff --git a/xbmc/platform/android/jni/JNIThreading.h b/xbmc/platform/android/jni/JNIThreading.h index 36cf4535d1..e7fd6a1167 100644 --- a/xbmc/platform/android/jni/JNIThreading.h +++ b/xbmc/platform/android/jni/JNIThreading.h @@ -32,6 +32,7 @@ */ #pragma once +#define HAVE_INTTYPES_H 1 #include <jni.h> diff --git a/xbmc/platform/android/jni/LinkAddress.cpp b/xbmc/platform/android/jni/LinkAddress.cpp new file mode 100644 index 0000000000..daedbf8512 --- /dev/null +++ b/xbmc/platform/android/jni/LinkAddress.cpp @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2016 Christian Browet + * 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 "LinkAddress.h" +#include "InetAddress.h" + +#include "jutils/jutils-details.hpp" + +using namespace jni; + + +CJNIInetAddress CJNILinkAddress::getAddress() +{ + return call_method<jhobject>(m_object, + "getAddress", "()Ljava/net/InetAddress;"); +} + +int CJNILinkAddress::getFlags() +{ + return call_method<jint>(m_object, + "getFlags", "()I"); +} + +int CJNILinkAddress::getPrefixLength() +{ + return call_method<jint>(m_object, + "getPrefixLength", "()I"); +} + +int CJNILinkAddress::getScope() +{ + return call_method<jint>(m_object, + "getScope", "()I"); +} + +bool CJNILinkAddress::equals(const CJNILinkAddress& other) +{ + return call_method<jboolean>(m_object, + "equals", "(Ljava/lang/Object;)Z", other.get_raw()); +} + +std::string CJNILinkAddress::toString() const +{ + return jcast<std::string>(call_method<jhstring>(m_object, + "toString", "()Ljava/lang/String;")); +} + +int CJNILinkAddress::describeContents() const +{ + return call_method<jint>(m_object, + "describeContents", "()I"); +} + diff --git a/xbmc/platform/android/jni/LinkAddress.h b/xbmc/platform/android/jni/LinkAddress.h new file mode 100644 index 0000000000..8336c5b94d --- /dev/null +++ b/xbmc/platform/android/jni/LinkAddress.h @@ -0,0 +1,43 @@ +#pragma once +/* + * Copyright (C) 2016 Christian Browet + * 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 "JNIBase.h" + +class CJNIInetAddress; + +class CJNILinkAddress : public CJNIBase +{ +public: + CJNILinkAddress(const jni::jhobject &object) : CJNIBase(object){} + ~CJNILinkAddress(){} + + CJNIInetAddress getAddress(); + int getFlags(); + int getPrefixLength(); + int getScope(); + + bool equals(const CJNILinkAddress &other); + std::string toString() const; + int describeContents() const; + +protected: + CJNILinkAddress(); +}; diff --git a/xbmc/platform/android/jni/LinkProperties.cpp b/xbmc/platform/android/jni/LinkProperties.cpp new file mode 100644 index 0000000000..3324cbdd77 --- /dev/null +++ b/xbmc/platform/android/jni/LinkProperties.cpp @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2016 Christian Browet + * 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 "LinkProperties.h" +#include "RouteInfo.h" +#include "InetAddress.h" + +#include "jutils/jutils-details.hpp" + +using namespace jni; + +std::string CJNILinkProperties::getDomains() +{ + return jcast<std::string>(call_method<jhstring>(m_object, + "getDomains", "()Ljava/lang/String;")); +} + +std::string CJNILinkProperties::getInterfaceName() +{ + return jcast<std::string>(call_method<jhstring>(m_object, + "getInterfaceName", "()Ljava/lang/String;")); +} + +CJNIList<CJNIRouteInfo> CJNILinkProperties::getRoutes() +{ + return call_method<jhobject>(m_object, + "getRoutes", "()Ljava/util/List;"); +} + +CJNIList<CJNILinkAddress> CJNILinkProperties::getLinkAddresses() +{ + return call_method<jhobject>(m_object, + "getLinkAddresses", "()Ljava/util/List;"); +} + +CJNIList<CJNIInetAddress> CJNILinkProperties::getDnsServers() +{ + return call_method<jhobject>(m_object, + "getDnsServers", "()Ljava/util/List;"); +} + + +bool CJNILinkProperties::equals(const CJNILinkProperties& other) +{ + return call_method<jboolean>(m_object, + "equals", "(Ljava/lang/Object;)Z", other.get_raw()); +} + +std::string CJNILinkProperties::toString() const +{ + return jcast<std::string>(call_method<jhstring>(m_object, + "toString", "()Ljava/lang/String;")); +} + +int CJNILinkProperties::describeContents() const +{ + return call_method<jint>(m_object, + "describeContents", "()I"); +} + diff --git a/xbmc/platform/android/jni/LinkProperties.h b/xbmc/platform/android/jni/LinkProperties.h new file mode 100644 index 0000000000..79297745aa --- /dev/null +++ b/xbmc/platform/android/jni/LinkProperties.h @@ -0,0 +1,49 @@ +#pragma once +/* + * Copyright (C) 2016 Christian Browet + * 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 "JNIBase.h" + +#include "List.h" + +class CJNIRouteInfo; +class CJNILinkAddress; +class CJNIInetAddress; + +class CJNILinkProperties : public CJNIBase +{ +public: + CJNILinkProperties(const jni::jhobject &object) : CJNIBase(object){} + ~CJNILinkProperties(){} + + std::string getDomains(); + std::string getInterfaceName(); + + CJNIList<CJNIRouteInfo> getRoutes(); + CJNIList<CJNILinkAddress> getLinkAddresses(); + CJNIList<CJNIInetAddress> getDnsServers(); + + bool equals(const CJNILinkProperties &other); + std::string toString() const; + int describeContents() const; + +protected: + CJNILinkProperties(); +}; diff --git a/xbmc/platform/android/jni/List.cpp b/xbmc/platform/android/jni/List.cpp index a5b432162a..3867869cd7 100644 --- a/xbmc/platform/android/jni/List.cpp +++ b/xbmc/platform/android/jni/List.cpp @@ -23,6 +23,10 @@ #include "ScanResult.h" #include "WifiConfiguration.h" #include "ApplicationInfo.h" +#include "URIPermission.h" +#include "LinkAddress.h" +#include "RouteInfo.h" +#include "InetAddress.h" #include "jutils/jutils-details.hpp" @@ -47,3 +51,7 @@ template class CJNIList<CJNIScanResult>; template class CJNIList<CJNIWifiConfiguration>; template class CJNIList<CJNIApplicationInfo>; template class CJNIList<CJNIViewInputDeviceMotionRange>; +template class CJNIList<CJNIURIPermission>; +template class CJNIList<CJNILinkAddress>; +template class CJNIList<CJNIRouteInfo>; +template class CJNIList<CJNIInetAddress>; diff --git a/xbmc/platform/android/jni/Makefile.in b/xbmc/platform/android/jni/Makefile.in index 749c2c2f9c..c4d66b5d27 100644 --- a/xbmc/platform/android/jni/Makefile.in +++ b/xbmc/platform/android/jni/Makefile.in @@ -60,8 +60,28 @@ SRCS += Resources.cpp SRCS += PackageItemInfo.cpp SRCS += DisplayMetrics.cpp SRCS += KeyEvent.cpp +SRCS += Notification.cpp +SRCS += Settings.cpp +SRCS += URIPermission.cpp +SRCS += DocumentsContract.cpp +SRCS += Document.cpp +SRCS += AudioTimestamp.cpp +SRCS += ArrayList.cpp +SRCS += RecognizerIntent.cpp +SRCS += AudioDeviceInfo.cpp SRCS += InputManager.cpp SRCS += Os.cpp +SRCS += PlaybackParams.cpp +SRCS += MediaTimestamp.cpp +SRCS += MediaSync.cpp +SRCS += AudioAttributes.cpp +SRCS += Image.cpp +SRCS += Network.cpp +SRCS += LinkProperties.cpp +SRCS += LinkAddress.cpp +SRCS += RouteInfo.cpp +SRCS += InetAddress.cpp +SRCS += NetworkInterface.cpp LIB = jni.a diff --git a/xbmc/platform/android/jni/MediaFormat.cpp b/xbmc/platform/android/jni/MediaFormat.cpp index 09bc55cc0e..eb508542d7 100644 --- a/xbmc/platform/android/jni/MediaFormat.cpp +++ b/xbmc/platform/android/jni/MediaFormat.cpp @@ -40,6 +40,7 @@ std::string CJNIMediaFormat::KEY_IS_ADTS; std::string CJNIMediaFormat::KEY_CHANNEL_MASK; std::string CJNIMediaFormat::KEY_AAC_PROFILE; std::string CJNIMediaFormat::KEY_FLAC_COMPRESSION_LEVEL; +std::string CJNIMediaFormat::KEY_ROTATION; const char *CJNIMediaFormat::m_classname = "android/media/MediaFormat"; void CJNIMediaFormat::PopulateStaticFields() @@ -62,6 +63,11 @@ void CJNIMediaFormat::PopulateStaticFields() KEY_CHANNEL_MASK = jcast<std::string>(get_static_field<jhstring>(clazz, "KEY_CHANNEL_MASK")); KEY_AAC_PROFILE = jcast<std::string>(get_static_field<jhstring>(clazz, "KEY_AAC_PROFILE")); KEY_FLAC_COMPRESSION_LEVEL = jcast<std::string>(get_static_field<jhstring>(clazz, "KEY_FLAC_COMPRESSION_LEVEL")); + + if(GetSDKVersion() >= 23) + { + KEY_ROTATION = jcast<std::string>(get_static_field<jhstring>(clazz, "KEY_ROTATION")); + } } } diff --git a/xbmc/platform/android/jni/MediaFormat.h b/xbmc/platform/android/jni/MediaFormat.h index 8380604d6d..af99ff7407 100644 --- a/xbmc/platform/android/jni/MediaFormat.h +++ b/xbmc/platform/android/jni/MediaFormat.h @@ -60,6 +60,7 @@ public: static std::string KEY_CHANNEL_MASK; static std::string KEY_AAC_PROFILE; static std::string KEY_FLAC_COMPRESSION_LEVEL; + static std::string KEY_ROTATION; private: CJNIMediaFormat(); diff --git a/xbmc/platform/android/jni/MediaSync.cpp b/xbmc/platform/android/jni/MediaSync.cpp new file mode 100644 index 0000000000..df3f640295 --- /dev/null +++ b/xbmc/platform/android/jni/MediaSync.cpp @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2016 Chris Browet + * 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 "MediaSync.h" +#include "jutils/jutils-details.hpp" + +using namespace jni; + +int CJNIMediaSync::MEDIASYNC_ERROR_AUDIOTRACK_FAIL = 0x00000001; +int CJNIMediaSync::MEDIASYNC_ERROR_SURFACE_FAIL = 0x00000002; + +void CJNIMediaSync::PopulateStaticFields() +{ + if (CJNIBase::GetSDKVersion() >= 23) + { + jhclass c = find_class("android/media/MediaSync"); + CJNIMediaSync::MEDIASYNC_ERROR_AUDIOTRACK_FAIL = get_static_field<int>(c, "MEDIASYNC_ERROR_AUDIOTRACK_FAIL"); + CJNIMediaSync::MEDIASYNC_ERROR_SURFACE_FAIL = get_static_field<int>(c, "MEDIASYNC_ERROR_SURFACE_FAIL"); + } +} + +CJNIMediaSync::CJNIMediaSync() + : CJNIBase("android/media/MediaSync") +{ + m_object = new_object(GetClassName()); + + JNIEnv* jenv = xbmc_jnienv(); + jthrowable exception = jenv->ExceptionOccurred(); + if (exception) + { + jenv->ExceptionClear(); + jhclass excClass = find_class(jenv, "java/lang/Throwable"); + jmethodID toStrMethod = get_method_id(jenv, excClass, "toString", "()Ljava/lang/String;"); + jhstring msg = call_method<jhstring>(exception, toStrMethod); + throw std::invalid_argument(jcast<std::string>(msg)); + } + m_object.setGlobal(); +} + +void CJNIMediaSync::flush() +{ + call_method<void>(m_object, "flush", "()V"); +} + +void CJNIMediaSync::release() +{ + call_method<void>(m_object, "release", "()V"); +} + +CJNIMediaTimestamp CJNIMediaSync::getTimestamp() +{ + return call_method<jhobject>(m_object, + "getTimestamp", "()Landroid/media/MediaTimestamp;"); +} + +void CJNIMediaSync::setAudioTrack(const CJNIAudioTrack& audioTrack) +{ + call_method<void>(m_object, + "setAudioTrack", "(Landroid/media/AudioTrack;)V", + audioTrack.get_raw()); +} + +void CJNIMediaSync::queueAudio(uint8_t* audioData, int sizeInBytes, int bufferId, int64_t presentationTimeUs) +{ + CJNIByteBuffer bytebuffer = CJNIByteBuffer::allocateDirect(sizeInBytes); + void *dst_ptr = xbmc_jnienv()->GetDirectBufferAddress(bytebuffer.get_raw()); + memcpy(dst_ptr, audioData, sizeInBytes); + + queueAudio(bytebuffer, bufferId, presentationTimeUs); +} + +void CJNIMediaSync::queueAudio(const CJNIByteBuffer& audioData, int bufferId, int64_t presentationTimeUs) +{ + call_method<void>(m_object, + "queueAudio", "(Ljava/nio/ByteBuffer;IJ)V", + audioData.get_raw(), bufferId, presentationTimeUs); +} + +CJNIPlaybackParams CJNIMediaSync::getPlaybackParams() +{ + return call_method<jhobject>(m_object, + "getPlaybackParams", "()Landroid/media/PlaybackParams;"); +} + +void CJNIMediaSync::setPlaybackParams(const CJNIPlaybackParams& params) +{ + call_method<void>(m_object, + "setPlaybackParams", "(Landroid/media/PlaybackParams;)V", + params.get_raw()); +} + diff --git a/xbmc/platform/android/jni/MediaSync.h b/xbmc/platform/android/jni/MediaSync.h new file mode 100644 index 0000000000..c36a0773a6 --- /dev/null +++ b/xbmc/platform/android/jni/MediaSync.h @@ -0,0 +1,57 @@ +#pragma once +/* + * Copyright (C) 2016 Chris Browet + * 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 <stdexcept> + +#include "JNIBase.h" +#include "ByteBuffer.h" +#include "MediaTimestamp.h" +#include "PlaybackParams.h" +#include "AudioTrack.h" + +namespace jni +{ + +class CJNIMediaSync : public CJNIBase +{ +public: + static int MEDIASYNC_ERROR_AUDIOTRACK_FAIL; + static int MEDIASYNC_ERROR_SURFACE_FAIL; + static void PopulateStaticFields(); + + CJNIMediaSync(); + void flush(); + void release(); + + CJNIMediaTimestamp getTimestamp(); + + void setAudioTrack(const CJNIAudioTrack& audioTrack); + void queueAudio(uint8_t* audioData, int sizeInBytes, int bufferId, int64_t presentationTimeUs); + void queueAudio(const CJNIByteBuffer& audioData, int bufferId, int64_t presentationTimeUs); + + CJNIPlaybackParams getPlaybackParams(); + void setPlaybackParams(const CJNIPlaybackParams& params); + +protected: +}; + +} + diff --git a/xbmc/platform/android/jni/MediaTimestamp.cpp b/xbmc/platform/android/jni/MediaTimestamp.cpp new file mode 100644 index 0000000000..5c5c3257c1 --- /dev/null +++ b/xbmc/platform/android/jni/MediaTimestamp.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2016 Chris Browet + * 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 "MediaTimestamp.h" +#include "jutils/jutils-details.hpp" + +using namespace jni; + +CJNIMediaTimestamp::CJNIMediaTimestamp() + : CJNIBase("android.media.MediaTimestamp") +{ + m_object = new_object(GetClassName()); + m_object.setGlobal(); +} + +CJNIMediaTimestamp::CJNIMediaTimestamp(const jni::jhobject& object) + : CJNIBase(object) +{ +} + +int64_t CJNIMediaTimestamp::getAnchorMediaTimeUs() +{ + return call_method<jlong>(m_object, "getAnchorMediaTimeUs", "()J"); +} + +int64_t CJNIMediaTimestamp::getAnchorSytemNanoTime() +{ + return call_method<jlong>(m_object, "getAnchorSytemNanoTime", "()J"); +} + +float CJNIMediaTimestamp::getMediaClockRate() +{ + return call_method<jfloat>(m_object, "getMediaClockRate", "()F"); +} + diff --git a/xbmc/platform/android/jni/MediaTimestamp.h b/xbmc/platform/android/jni/MediaTimestamp.h new file mode 100644 index 0000000000..911e26f953 --- /dev/null +++ b/xbmc/platform/android/jni/MediaTimestamp.h @@ -0,0 +1,39 @@ +#pragma once +/* + * Copyright (C) 2016 Chris Browet + * 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 "JNIBase.h" + +namespace jni +{ + +class CJNIMediaTimestamp : public CJNIBase +{ +public: + CJNIMediaTimestamp(); + CJNIMediaTimestamp(const jni::jhobject &object); + + int64_t getAnchorMediaTimeUs(); + int64_t getAnchorSytemNanoTime(); + float getMediaClockRate(); +}; + +} + diff --git a/xbmc/platform/android/jni/Network.cpp b/xbmc/platform/android/jni/Network.cpp new file mode 100644 index 0000000000..e2aa62707c --- /dev/null +++ b/xbmc/platform/android/jni/Network.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2016 Christian Browet + * 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 "Network.h" +#include "jutils/jutils-details.hpp" + +using namespace jni; + +bool CJNINetwork::equals(const CJNINetwork& other) +{ + return call_method<jboolean>(m_object, + "equals", "(Ljava/lang/Object;)Z", other.get_raw()); +} + +std::string CJNINetwork::toString() const +{ + return jcast<std::string>(call_method<jhstring>(m_object, + "toString", "()Ljava/lang/String;")); +} + +int CJNINetwork::describeContents() const +{ + return call_method<jint>(m_object, + "describeContents", "()I"); +} + diff --git a/xbmc/platform/android/jni/Network.h b/xbmc/platform/android/jni/Network.h new file mode 100644 index 0000000000..ac5e446001 --- /dev/null +++ b/xbmc/platform/android/jni/Network.h @@ -0,0 +1,38 @@ +#pragma once +/* + * Copyright (C) 2016 Christian Browet + * 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 "JNIBase.h" + +class CJNINetwork : public CJNIBase +{ +public: + CJNINetwork(const jni::jhobject &object) : CJNIBase(object){} + ~CJNINetwork(){} + + bool equals(const CJNINetwork &other); + std::string toString() const; + int describeContents() const; + +protected: + CJNINetwork(); +}; + +typedef std::vector<CJNINetwork> CJNINetworks; diff --git a/xbmc/platform/android/jni/NetworkInterface.cpp b/xbmc/platform/android/jni/NetworkInterface.cpp new file mode 100644 index 0000000000..e4c3a5bb81 --- /dev/null +++ b/xbmc/platform/android/jni/NetworkInterface.cpp @@ -0,0 +1,128 @@ +/* + * Copyright (C) 2016 Christian Browet + * 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 "NetworkInterface.h" +#include "InetAddress.h" + +#include "jutils/jutils-details.hpp" + +using namespace jni; + +const char* CJNINetworkInterface::m_classname = "java/net/NetworkInterface"; + +CJNINetworkInterface CJNINetworkInterface::getByName(const std::string& name) +{ + return CJNINetworkInterface(call_static_method<jhobject>(m_classname, + "getByName", "(Ljava/lang/String;)Ljava/net/NetworkInterface;", jcast<jhstring>(name))); +} + +CJNINetworkInterface CJNINetworkInterface::getByIndex(int index) +{ + return CJNINetworkInterface(call_static_method<jhobject>(m_classname, + "getByIndex", "(I)Ljava/net/NetworkInterface;", index)); +} + +CJNINetworkInterface CJNINetworkInterface::getByInetAddress(const CJNIInetAddress& addr) +{ + return CJNINetworkInterface(call_static_method<jhobject>(m_classname, + "getByInetAddress", "(Ljava/net/InetAddress;)Ljava/net/NetworkInterface;", addr.get_raw())); +} + +std::string CJNINetworkInterface::getName() +{ + return jcast<std::string>(call_method<jhstring>(m_object, + "getName", "()Ljava/lang/String;")); +} + +std::string CJNINetworkInterface::getDisplayName() +{ + return jcast<std::string>(call_method<jhstring>(m_object, + "getDisplayName", "()Ljava/lang/String;")); +} + +std::vector<char> CJNINetworkInterface::getHardwareAddress() +{ + JNIEnv *env = xbmc_jnienv(); + jhbyteArray array = call_method<jhbyteArray>(m_object, + "getHardwareAddress", "()[B"); + + jsize size = env->GetArrayLength(array.get()); + + std::vector<char> result; + result.resize(size); + env->GetByteArrayRegion(array.get(), 0, size, (jbyte*)result.data()); + + return result; +} + +int CJNINetworkInterface::getIndex() +{ + return call_method<jboolean>(m_object, + "getIndex", "()I"); +} + +int CJNINetworkInterface::getMTU() +{ + return call_method<jboolean>(m_object, + "getMTU", "()I"); +} + +bool CJNINetworkInterface::isLoopback() +{ + return call_method<jboolean>(m_object, + "isLoopback", "()Z"); +} + +bool CJNINetworkInterface::isPointToPoint() +{ + return call_method<jboolean>(m_object, + "isPointToPoint", "()Z"); +} + +bool CJNINetworkInterface::isUp() +{ + return call_method<jboolean>(m_object, + "isUp", "()Z"); +} + +bool CJNINetworkInterface::isVirtual() +{ + return call_method<jboolean>(m_object, + "isVirtual", "()Z"); +} + +bool CJNINetworkInterface::supportsMulticast() +{ + return call_method<jboolean>(m_object, + "supportsMulticast", "()Z"); +} + +bool CJNINetworkInterface::equals(const CJNINetworkInterface& other) +{ + return call_method<jboolean>(m_object, + "equals", "(Ljava/lang/Object;)Z", other.get_raw()); +} + +std::string CJNINetworkInterface::toString() const +{ + return jcast<std::string>(call_method<jhstring>(m_object, + "toString", "()Ljava/lang/String;")); +} + diff --git a/xbmc/platform/android/jni/NetworkInterface.h b/xbmc/platform/android/jni/NetworkInterface.h new file mode 100644 index 0000000000..d4b575d1b8 --- /dev/null +++ b/xbmc/platform/android/jni/NetworkInterface.h @@ -0,0 +1,56 @@ +#pragma once +/* + * Copyright (C) 2016 Christian Browet + * 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 "JNIBase.h" + +class CJNIInetAddress; + +class CJNINetworkInterface : public CJNIBase +{ +public: + CJNINetworkInterface(const jni::jhobject &object) : CJNIBase(object){} + ~CJNINetworkInterface(){} + + static CJNINetworkInterface getByName(const std::string& name); + static CJNINetworkInterface getByIndex(int index); + static CJNINetworkInterface getByInetAddress(const CJNIInetAddress& addr); + + std::string getName(); + std::string getDisplayName(); + std::vector<char> getHardwareAddress(); + int getIndex(); + int getMTU(); + + bool isLoopback(); + bool isPointToPoint(); + bool isUp(); + bool isVirtual(); + bool supportsMulticast(); + + bool equals(const CJNINetworkInterface &other); + std::string toString() const; + +protected: + CJNINetworkInterface(); + static const char *m_classname; +}; + +typedef std::vector<CJNINetworkInterface> CJNINetworkInterfaces; diff --git a/xbmc/platform/android/jni/Notification.cpp b/xbmc/platform/android/jni/Notification.cpp new file mode 100644 index 0000000000..dd0ed312b6 --- /dev/null +++ b/xbmc/platform/android/jni/Notification.cpp @@ -0,0 +1,159 @@ +#include "Notification.h" +#include "Activity.h" +#include "ClassLoader.h" + +#include "jutils/jutils-details.hpp" + +#include <string> + + +using namespace jni; + +std::string CJNINotification::CATEGORY_ALARM; +std::string CJNINotification::CATEGORY_CALL; +std::string CJNINotification::CATEGORY_EMAIL; +std::string CJNINotification::CATEGORY_ERROR; +std::string CJNINotification::CATEGORY_EVENT; +std::string CJNINotification::CATEGORY_MESSAGE; +std::string CJNINotification::CATEGORY_PROGRESS; +std::string CJNINotification::CATEGORY_PROMO; +std::string CJNINotification::CATEGORY_RECOMMENDATION; +std::string CJNINotification::CATEGORY_SERVICE; +std::string CJNINotification::CATEGORY_SOCIAL; +std::string CJNINotification::CATEGORY_STATUS; +std::string CJNINotification::CATEGORY_SYSTEM; +std::string CJNINotification::CATEGORY_TRANSPORT; +int CJNINotification::COLOR_DEFAULT; +int CJNINotification::DEFAULT_ALL; +int CJNINotification::DEFAULT_LIGHTS; +int CJNINotification::DEFAULT_SOUND; +int CJNINotification::DEFAULT_VIBRATE; +std::string CJNINotification::EXTRA_BACKGROUND_IMAGE_URI; +std::string CJNINotification::EXTRA_BIG_TEXT; +std::string CJNINotification::EXTRA_COMPACT_ACTIONS; +std::string CJNINotification::EXTRA_INFO_TEXT; +std::string CJNINotification::EXTRA_LARGE_ICON; +std::string CJNINotification::EXTRA_LARGE_ICON_BIG; +std::string CJNINotification::EXTRA_MEDIA_SESSION; +std::string CJNINotification::EXTRA_PEOPLE; +std::string CJNINotification::EXTRA_PICTURE; +std::string CJNINotification::EXTRA_PROGRESS; +std::string CJNINotification::EXTRA_PROGRESS_INDETERMINATE; +std::string CJNINotification::EXTRA_PROGRESS_MAX; +std::string CJNINotification::EXTRA_SHOW_CHRONOMETER; +std::string CJNINotification::EXTRA_SHOW_WHEN; +std::string CJNINotification::EXTRA_SMALL_ICON; +std::string CJNINotification::EXTRA_SUB_TEXT; +std::string CJNINotification::EXTRA_SUMMARY_TEXT; +std::string CJNINotification::EXTRA_TEMPLATE; +std::string CJNINotification::EXTRA_TEXT; +std::string CJNINotification::EXTRA_TEXT_LINES; +std::string CJNINotification::EXTRA_TITLE; +std::string CJNINotification::EXTRA_TITLE_BIG; +int CJNINotification::FLAG_AUTO_CANCEL; +int CJNINotification::FLAG_FOREGROUND_SERVICE; +int CJNINotification::FLAG_GROUP_SUMMARY; +int CJNINotification::FLAG_HIGH_PRIORITY; +int CJNINotification::FLAG_INSISTENT; +int CJNINotification::FLAG_LOCAL_ONLY; +int CJNINotification::FLAG_NO_CLEAR; +int CJNINotification::FLAG_ONGOING_EVENT; +int CJNINotification::FLAG_ONLY_ALERT_ONCE; +int CJNINotification::FLAG_SHOW_LIGHTS; +std::string CJNINotification::INTENT_CATEGORY_NOTIFICATION_PREFERENCES; +int CJNINotification::PRIORITY_DEFAULT; +int CJNINotification::PRIORITY_HIGH; +int CJNINotification::PRIORITY_LOW; +int CJNINotification::PRIORITY_MAX; +int CJNINotification::PRIORITY_MIN; +int CJNINotification::STREAM_DEFAULT; +int CJNINotification::VISIBILITY_PRIVATE; +int CJNINotification::VISIBILITY_PUBLIC; +int CJNINotification::VISIBILITY_SECRET; + +const char *CJNINotification::m_classname = "android/app/Notification"; + +void CJNINotification::PopulateStaticFields() +{ + jhclass clazz = find_class(m_classname); + if(GetSDKVersion() >= 21) + { + CATEGORY_ALARM = jcast<std::string>(get_static_field<jhstring>(clazz, "CATEGORY_ALARM")); + CATEGORY_CALL = jcast<std::string>(get_static_field<jhstring>(clazz, "CATEGORY_CALL")); + CATEGORY_EMAIL = jcast<std::string>(get_static_field<jhstring>(clazz, "CATEGORY_EMAIL")); + CATEGORY_ERROR = jcast<std::string>(get_static_field<jhstring>(clazz, "CATEGORY_ERROR")); + CATEGORY_EVENT = jcast<std::string>(get_static_field<jhstring>(clazz, "CATEGORY_EVENT")); + CATEGORY_MESSAGE = jcast<std::string>(get_static_field<jhstring>(clazz, "CATEGORY_MESSAGE")); + CATEGORY_PROGRESS = jcast<std::string>(get_static_field<jhstring>(clazz, "CATEGORY_PROGRESS")); + CATEGORY_PROMO = jcast<std::string>(get_static_field<jhstring>(clazz, "CATEGORY_PROMO")); + CATEGORY_RECOMMENDATION = jcast<std::string>(get_static_field<jhstring>(clazz, "CATEGORY_RECOMMENDATION")); + CATEGORY_SERVICE = jcast<std::string>(get_static_field<jhstring>(clazz, "CATEGORY_SERVICE")); + CATEGORY_SOCIAL = jcast<std::string>(get_static_field<jhstring>(clazz, "CATEGORY_SOCIAL")); + CATEGORY_STATUS = jcast<std::string>(get_static_field<jhstring>(clazz, "CATEGORY_STATUS")); + CATEGORY_SYSTEM = jcast<std::string>(get_static_field<jhstring>(clazz, "CATEGORY_SYSTEM")); + CATEGORY_TRANSPORT = jcast<std::string>(get_static_field<jhstring>(clazz, "CATEGORY_TRANSPORT")); + COLOR_DEFAULT = (get_static_field<int>(clazz, "COLOR_DEFAULT")); + EXTRA_BACKGROUND_IMAGE_URI = jcast<std::string>(get_static_field<jhstring>(clazz, "EXTRA_BACKGROUND_IMAGE_URI")); + EXTRA_BIG_TEXT = jcast<std::string>(get_static_field<jhstring>(clazz, "EXTRA_BIG_TEXT")); + EXTRA_COMPACT_ACTIONS = jcast<std::string>(get_static_field<jhstring>(clazz, "EXTRA_COMPACT_ACTIONS")); + EXTRA_MEDIA_SESSION = jcast<std::string>(get_static_field<jhstring>(clazz, "EXTRA_MEDIA_SESSION")); + EXTRA_TEMPLATE = jcast<std::string>(get_static_field<jhstring>(clazz, "EXTRA_TEMPLATE")); + INTENT_CATEGORY_NOTIFICATION_PREFERENCES = jcast<std::string>(get_static_field<jhstring>(clazz, "INTENT_CATEGORY_NOTIFICATION_PREFERENCES")); + VISIBILITY_PRIVATE = (get_static_field<int>(clazz, "VISIBILITY_PRIVATE")); + VISIBILITY_PUBLIC = (get_static_field<int>(clazz, "VISIBILITY_PUBLIC")); + VISIBILITY_SECRET = (get_static_field<int>(clazz, "VISIBILITY_SECRET")); + } + if(GetSDKVersion() >= 20) + { + FLAG_GROUP_SUMMARY = (get_static_field<int>(clazz, "FLAG_GROUP_SUMMARY")); + FLAG_LOCAL_ONLY = (get_static_field<int>(clazz, "FLAG_LOCAL_ONLY")); + } + if(GetSDKVersion() >= 19) + { + EXTRA_INFO_TEXT = jcast<std::string>(get_static_field<jhstring>(clazz, "EXTRA_INFO_TEXT")); + EXTRA_LARGE_ICON = jcast<std::string>(get_static_field<jhstring>(clazz, "EXTRA_LARGE_ICON")); + EXTRA_LARGE_ICON_BIG = jcast<std::string>(get_static_field<jhstring>(clazz, "EXTRA_LARGE_ICON_BIG")); + EXTRA_PEOPLE = jcast<std::string>(get_static_field<jhstring>(clazz, "EXTRA_PEOPLE")); + EXTRA_PICTURE = jcast<std::string>(get_static_field<jhstring>(clazz, "EXTRA_PICTURE")); + EXTRA_PROGRESS = jcast<std::string>(get_static_field<jhstring>(clazz, "EXTRA_PROGRESS")); + EXTRA_PROGRESS_INDETERMINATE = jcast<std::string>(get_static_field<jhstring>(clazz, "EXTRA_PROGRESS_INDETERMINATE")); + EXTRA_PROGRESS_MAX = jcast<std::string>(get_static_field<jhstring>(clazz, "EXTRA_PROGRESS_MAX")); + EXTRA_SHOW_CHRONOMETER = jcast<std::string>(get_static_field<jhstring>(clazz, "EXTRA_SHOW_CHRONOMETER")); + EXTRA_SHOW_WHEN = jcast<std::string>(get_static_field<jhstring>(clazz, "EXTRA_SHOW_WHEN")); + EXTRA_SMALL_ICON = jcast<std::string>(get_static_field<jhstring>(clazz, "EXTRA_SMALL_ICON")); + EXTRA_SUB_TEXT = jcast<std::string>(get_static_field<jhstring>(clazz, "EXTRA_SUB_TEXT")); + EXTRA_SUMMARY_TEXT = jcast<std::string>(get_static_field<jhstring>(clazz, "EXTRA_SUMMARY_TEXT")); + EXTRA_TEXT = jcast<std::string>(get_static_field<jhstring>(clazz, "EXTRA_TEXT")); + EXTRA_TEXT_LINES = jcast<std::string>(get_static_field<jhstring>(clazz, "EXTRA_TEXT_LINES")); + EXTRA_TITLE = jcast<std::string>(get_static_field<jhstring>(clazz, "EXTRA_TITLE")); + EXTRA_TITLE_BIG = jcast<std::string>(get_static_field<jhstring>(clazz, "EXTRA_TITLE_BIG")); + } + if(GetSDKVersion() >= 16) + { + PRIORITY_DEFAULT = (get_static_field<int>(clazz, "PRIORITY_DEFAULT")); + PRIORITY_HIGH = (get_static_field<int>(clazz, "PRIORITY_HIGH")); + PRIORITY_LOW = (get_static_field<int>(clazz, "PRIORITY_LOW")); + PRIORITY_MAX = (get_static_field<int>(clazz, "PRIORITY_MAX")); + PRIORITY_MIN = (get_static_field<int>(clazz, "PRIORITY_MIN")); + } + DEFAULT_ALL = (get_static_field<int>(clazz, "DEFAULT_ALL")); + DEFAULT_LIGHTS = (get_static_field<int>(clazz, "DEFAULT_LIGHTS")); + DEFAULT_SOUND = (get_static_field<int>(clazz, "DEFAULT_SOUND")); + DEFAULT_VIBRATE = (get_static_field<int>(clazz, "DEFAULT_VIBRATE")); + FLAG_AUTO_CANCEL = (get_static_field<int>(clazz, "FLAG_AUTO_CANCEL")); + FLAG_FOREGROUND_SERVICE = (get_static_field<int>(clazz, "FLAG_FOREGROUND_SERVICE")); + FLAG_HIGH_PRIORITY = (get_static_field<int>(clazz, "FLAG_HIGH_PRIORITY")); + FLAG_INSISTENT = (get_static_field<int>(clazz, "FLAG_INSISTENT")); + FLAG_NO_CLEAR = (get_static_field<int>(clazz, "FLAG_NO_CLEAR")); + FLAG_ONGOING_EVENT = (get_static_field<int>(clazz, "FLAG_ONGOING_EVENT")); + FLAG_ONLY_ALERT_ONCE = (get_static_field<int>(clazz, "FLAG_ONLY_ALERT_ONCE")); + FLAG_SHOW_LIGHTS = (get_static_field<int>(clazz, "FLAG_SHOW_LIGHTS")); + STREAM_DEFAULT = (get_static_field<int>(clazz, "STREAM_DEFAULT")); +} + +CJNINotification::CJNINotification() +: CJNIBase(CJNINotification::m_classname) +{ + m_object = new_object(CJNIContext::getClassLoader().loadClass(GetDotClassName())); + m_object.setGlobal(); +} diff --git a/xbmc/platform/android/jni/Notification.h b/xbmc/platform/android/jni/Notification.h new file mode 100644 index 0000000000..34255cf3b1 --- /dev/null +++ b/xbmc/platform/android/jni/Notification.h @@ -0,0 +1,96 @@ +#pragma once +/* + * Copyright (C) 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 "JNIBase.h" + +class CJNINotification : public CJNIBase +{ +public: + CJNINotification(const jni::jhobject &object) : CJNIBase(object) {} + CJNINotification(); + + static void PopulateStaticFields(); + + static std::string CATEGORY_ALARM; + static std::string CATEGORY_CALL; + static std::string CATEGORY_EMAIL; + static std::string CATEGORY_ERROR; + static std::string CATEGORY_EVENT; + static std::string CATEGORY_MESSAGE; + static std::string CATEGORY_PROGRESS; + static std::string CATEGORY_PROMO; + static std::string CATEGORY_RECOMMENDATION; + static std::string CATEGORY_SERVICE; + static std::string CATEGORY_SOCIAL; + static std::string CATEGORY_STATUS; + static std::string CATEGORY_SYSTEM; + static std::string CATEGORY_TRANSPORT; + static int COLOR_DEFAULT; + static int DEFAULT_ALL; + static int DEFAULT_LIGHTS; + static int DEFAULT_SOUND; + static int DEFAULT_VIBRATE; + static std::string EXTRA_BACKGROUND_IMAGE_URI; + static std::string EXTRA_BIG_TEXT; + static std::string EXTRA_COMPACT_ACTIONS; + static std::string EXTRA_INFO_TEXT; + static std::string EXTRA_LARGE_ICON; + static std::string EXTRA_LARGE_ICON_BIG; + static std::string EXTRA_MEDIA_SESSION; + static std::string EXTRA_PEOPLE; + static std::string EXTRA_PICTURE; + static std::string EXTRA_PROGRESS; + static std::string EXTRA_PROGRESS_INDETERMINATE; + static std::string EXTRA_PROGRESS_MAX; + static std::string EXTRA_SHOW_CHRONOMETER; + static std::string EXTRA_SHOW_WHEN; + static std::string EXTRA_SMALL_ICON; + static std::string EXTRA_SUB_TEXT; + static std::string EXTRA_SUMMARY_TEXT; + static std::string EXTRA_TEMPLATE; + static std::string EXTRA_TEXT; + static std::string EXTRA_TEXT_LINES; + static std::string EXTRA_TITLE; + static std::string EXTRA_TITLE_BIG; + static int FLAG_AUTO_CANCEL; + static int FLAG_FOREGROUND_SERVICE; + static int FLAG_GROUP_SUMMARY; + static int FLAG_HIGH_PRIORITY; + static int FLAG_INSISTENT; + static int FLAG_LOCAL_ONLY; + static int FLAG_NO_CLEAR; + static int FLAG_ONGOING_EVENT; + static int FLAG_ONLY_ALERT_ONCE; + static int FLAG_SHOW_LIGHTS; + static std::string INTENT_CATEGORY_NOTIFICATION_PREFERENCES; + static int PRIORITY_DEFAULT; + static int PRIORITY_HIGH; + static int PRIORITY_LOW; + static int PRIORITY_MAX; + static int PRIORITY_MIN; + static int STREAM_DEFAULT; + static int VISIBILITY_PRIVATE; + static int VISIBILITY_PUBLIC; + static int VISIBILITY_SECRET; + + static const char *m_classname; +}; + diff --git a/xbmc/platform/android/jni/PackageManager.cpp b/xbmc/platform/android/jni/PackageManager.cpp index b9d510ef5c..a491713c83 100644 --- a/xbmc/platform/android/jni/PackageManager.cpp +++ b/xbmc/platform/android/jni/PackageManager.cpp @@ -36,6 +36,13 @@ void CJNIPackageManager::PopulateStaticFields() GET_ACTIVITIES = (get_static_field<int>(clazz, "GET_ACTIVITIES")); } +bool CJNIPackageManager::hasSystemFeature(const std::string &feature) +{ + return call_method<jboolean>(m_object, + "hasSystemFeature", "(Ljava/lang/String;)Z", + jcast<jhstring>(feature)); +} + CJNIIntent CJNIPackageManager::getLaunchIntentForPackage(const std::string &package) { return call_method<jhobject>(m_object, diff --git a/xbmc/platform/android/jni/PackageManager.h b/xbmc/platform/android/jni/PackageManager.h index bf22c33120..d7c5eebf7a 100644 --- a/xbmc/platform/android/jni/PackageManager.h +++ b/xbmc/platform/android/jni/PackageManager.h @@ -34,6 +34,7 @@ public: CJNIPackageManager(const jni::jhobject &object) : CJNIBase(object) {}; ~CJNIPackageManager() {}; + bool hasSystemFeature(const std::string &feature); CJNIIntent getLaunchIntentForPackage(const std::string &package); CJNIIntent getLeanbackLaunchIntentForPackage(const std::string &package); CJNIDrawable getApplicationIcon(const std::string &package); diff --git a/xbmc/platform/android/jni/PlaybackParams.cpp b/xbmc/platform/android/jni/PlaybackParams.cpp new file mode 100644 index 0000000000..79c9a2bcd4 --- /dev/null +++ b/xbmc/platform/android/jni/PlaybackParams.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2016 Chris Browet + * 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 "PlaybackParams.h" +#include "jutils/jutils-details.hpp" + +using namespace jni; + +CJNIPlaybackParams::CJNIPlaybackParams() + : CJNIBase("android/media/PlaybackParams") +{ + m_object = new_object(GetClassName()); + + JNIEnv* jenv = xbmc_jnienv(); + jthrowable exception = jenv->ExceptionOccurred(); + if (exception) + { + jenv->ExceptionClear(); + jhclass excClass = find_class(jenv, "java/lang/Throwable"); + jmethodID toStrMethod = get_method_id(jenv, excClass, "toString", "()Ljava/lang/String;"); + jhstring msg = call_method<jhstring>(exception, toStrMethod); + throw std::invalid_argument(jcast<std::string>(msg)); + } + m_object.setGlobal(); +} + +CJNIPlaybackParams::CJNIPlaybackParams(const jhobject& object) + : CJNIBase(object) +{ +} + +CJNIPlaybackParams CJNIPlaybackParams::setSpeed(float speed) +{ + return call_method<jhobject>(m_object, + "setSpeed", "(F)Landroid/media/PlaybackParams;", speed); +} + +float CJNIPlaybackParams::getSpeed() +{ + return call_method<jfloat>(m_object, + "getSpeed", "()F"); +} + diff --git a/xbmc/platform/android/jni/PlaybackParams.h b/xbmc/platform/android/jni/PlaybackParams.h new file mode 100644 index 0000000000..a0b31f8550 --- /dev/null +++ b/xbmc/platform/android/jni/PlaybackParams.h @@ -0,0 +1,38 @@ +#pragma once +/* + * Copyright (C) 2016 Chris Browet + * 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 "JNIBase.h" +#include <stdexcept> + +namespace jni +{ + +class CJNIPlaybackParams: public CJNIBase +{ +public: + CJNIPlaybackParams(); + CJNIPlaybackParams(const jni::jhobject &object); + + CJNIPlaybackParams setSpeed(float speed); + float getSpeed(); +}; + +} diff --git a/xbmc/platform/android/jni/RecognizerIntent.cpp b/xbmc/platform/android/jni/RecognizerIntent.cpp new file mode 100644 index 0000000000..21ec65f15b --- /dev/null +++ b/xbmc/platform/android/jni/RecognizerIntent.cpp @@ -0,0 +1,33 @@ +#include "RecognizerIntent.h" +#include "Activity.h" +#include "ClassLoader.h" + +#include "jutils/jutils-details.hpp" + +#include <string> + + +using namespace jni; + +std::string CJNIRecognizerIntent::ACTION_RECOGNIZE_SPEECH; +std::string CJNIRecognizerIntent::EXTRA_RESULTS; +std::string CJNIRecognizerIntent::EXTRA_LANGUAGE_MODEL; +std::string CJNIRecognizerIntent::LANGUAGE_MODEL_FREE_FORM; + +const char *CJNIRecognizerIntent::m_classname = "android/speech/RecognizerIntent"; + +void CJNIRecognizerIntent::PopulateStaticFields() +{ + jhclass clazz = find_class(m_classname); + ACTION_RECOGNIZE_SPEECH = jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_RECOGNIZE_SPEECH")); + EXTRA_RESULTS = jcast<std::string>(get_static_field<jhstring>(clazz, "EXTRA_RESULTS")); + EXTRA_LANGUAGE_MODEL = jcast<std::string>(get_static_field<jhstring>(clazz, "EXTRA_LANGUAGE_MODEL")); + LANGUAGE_MODEL_FREE_FORM = jcast<std::string>(get_static_field<jhstring>(clazz, "LANGUAGE_MODEL_FREE_FORM")); +} + +CJNIRecognizerIntent::CJNIRecognizerIntent() +: CJNIBase(CJNIRecognizerIntent::m_classname) +{ + m_object = new_object(CJNIContext::getClassLoader().loadClass(GetDotClassName())); + m_object.setGlobal(); +} diff --git a/xbmc/platform/android/jni/RecognizerIntent.h b/xbmc/platform/android/jni/RecognizerIntent.h new file mode 100644 index 0000000000..ed87916239 --- /dev/null +++ b/xbmc/platform/android/jni/RecognizerIntent.h @@ -0,0 +1,39 @@ +#pragma once +/* + * Copyright (C) 2016 Christian Browet + * 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 "JNIBase.h" + +class CJNIRecognizerIntent : public CJNIBase +{ +public: + CJNIRecognizerIntent(const jni::jhobject &object) : CJNIBase(object) {} + CJNIRecognizerIntent(); + + static void PopulateStaticFields(); + + static std::string ACTION_RECOGNIZE_SPEECH; + static std::string EXTRA_RESULTS; + static std::string EXTRA_LANGUAGE_MODEL; + static std::string LANGUAGE_MODEL_FREE_FORM; + + static const char *m_classname; +}; + diff --git a/xbmc/platform/android/jni/RouteInfo.cpp b/xbmc/platform/android/jni/RouteInfo.cpp new file mode 100644 index 0000000000..33c160abd7 --- /dev/null +++ b/xbmc/platform/android/jni/RouteInfo.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2016 Christian Browet + * 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 "RouteInfo.h" +#include "InetAddress.h" + +#include "jutils/jutils-details.hpp" + +using namespace jni; + +std::string CJNIRouteInfo::getInterface() +{ + return jcast<std::string>(call_method<jhstring>(m_object, + "getInterface", "()Ljava/lang/String;")); +} + +CJNIInetAddress CJNIRouteInfo::getGateway() +{ + return call_method<jhobject>(m_object, + "getGateway", "()Ljava/net/InetAddress;"); +} + +bool CJNIRouteInfo::isDefaultRoute() +{ + return call_method<jboolean>(m_object, + "isDefaultRoute", "()Z"); +} + +bool CJNIRouteInfo::equals(const CJNIRouteInfo& other) +{ + return call_method<jboolean>(m_object, + "equals", "(Ljava/lang/Object;)Z", other.get_raw()); +} + +std::string CJNIRouteInfo::toString() const +{ + return jcast<std::string>(call_method<jhstring>(m_object, + "toString", "()Ljava/lang/String;")); +} + +int CJNIRouteInfo::describeContents() const +{ + return call_method<jint>(m_object, + "describeContents", "()I"); +} + diff --git a/xbmc/platform/android/jni/RouteInfo.h b/xbmc/platform/android/jni/RouteInfo.h new file mode 100644 index 0000000000..204694ac58 --- /dev/null +++ b/xbmc/platform/android/jni/RouteInfo.h @@ -0,0 +1,42 @@ +#pragma once +/* + * Copyright (C) 2016 Christian Browet + * 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 "JNIBase.h" + +class CJNIInetAddress; + +class CJNIRouteInfo : public CJNIBase +{ +public: + CJNIRouteInfo(const jni::jhobject &object) : CJNIBase(object){} + ~CJNIRouteInfo(){} + + std::string getInterface(); + CJNIInetAddress getGateway(); + bool isDefaultRoute(); + + bool equals(const CJNIRouteInfo &other); + std::string toString() const; + int describeContents() const; + +protected: + CJNIRouteInfo(); +}; diff --git a/xbmc/platform/android/jni/Settings.cpp b/xbmc/platform/android/jni/Settings.cpp new file mode 100644 index 0000000000..0fd0e9ba62 --- /dev/null +++ b/xbmc/platform/android/jni/Settings.cpp @@ -0,0 +1,143 @@ +/* + * Copyright (C) 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 "Settings.h" +#include "JNIBase.h" +#include "jutils/jutils-details.hpp" + +using namespace jni; + +std::string CJNISettings::ACTION_ACCESSIBILITY_SETTINGS; +std::string CJNISettings::ACTION_ADD_ACCOUNT; +std::string CJNISettings::ACTION_AIRPLANE_MODE_SETTINGS; +std::string CJNISettings::ACTION_APN_SETTINGS; +std::string CJNISettings::ACTION_APPLICATION_DETAILS_SETTINGS; +std::string CJNISettings::ACTION_APPLICATION_DEVELOPMENT_SETTINGS; +std::string CJNISettings::ACTION_APPLICATION_SETTINGS; +std::string CJNISettings::ACTION_BLUETOOTH_SETTINGS; +std::string CJNISettings::ACTION_DATA_ROAMING_SETTINGS; +std::string CJNISettings::ACTION_DATE_SETTINGS; +std::string CJNISettings::ACTION_DEVICE_INFO_SETTINGS; +std::string CJNISettings::ACTION_DISPLAY_SETTINGS; +std::string CJNISettings::ACTION_INPUT_METHOD_SETTINGS; +std::string CJNISettings::ACTION_INPUT_METHOD_SUBTYPE_SETTINGS; +std::string CJNISettings::ACTION_INTERNAL_STORAGE_SETTINGS; +std::string CJNISettings::ACTION_LOCALE_SETTINGS; +std::string CJNISettings::ACTION_LOCATION_SOURCE_SETTINGS; +std::string CJNISettings::ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS; +std::string CJNISettings::ACTION_MANAGE_APPLICATIONS_SETTINGS; +std::string CJNISettings::ACTION_MEMORY_CARD_SETTINGS; +std::string CJNISettings::ACTION_NETWORK_OPERATOR_SETTINGS; +std::string CJNISettings::ACTION_NFCSHARING_SETTINGS; +std::string CJNISettings::ACTION_PRIVACY_SETTINGS; +std::string CJNISettings::ACTION_QUICK_LAUNCH_SETTINGS; +std::string CJNISettings::ACTION_SEARCH_SETTINGS; +std::string CJNISettings::ACTION_SECURITY_SETTINGS; +std::string CJNISettings::ACTION_SETTINGS; +std::string CJNISettings::ACTION_SOUND_SETTINGS; +std::string CJNISettings::ACTION_SYNC_SETTINGS; +std::string CJNISettings::ACTION_USER_DICTIONARY_SETTINGS; +std::string CJNISettings::ACTION_WIFI_IP_SETTINGS; +std::string CJNISettings::ACTION_WIFI_SETTINGS; +std::string CJNISettings::ACTION_WIRELESS_SETTINGS; +std::string CJNISettings::AUTHORITY; + +// API 16 +std::string CJNISettings::ACTION_NFC_SETTINGS; +// API 18 +std::string CJNISettings::ACTION_DREAM_SETTINGS; +// API 19 +std::string CJNISettings::ACTION_CAPTIONING_SETTINGS; +std::string CJNISettings::ACTION_NFC_PAYMENT_SETTINGS; +std::string CJNISettings::ACTION_PRINT_SETTINGS; +// API 21 +std::string CJNISettings::ACTION_CAST_SETTINGS; +std::string CJNISettings::ACTION_HOME_SETTINGS; +std::string CJNISettings::ACTION_SHOW_REGULATORY_INFO; +std::string CJNISettings::ACTION_USAGE_ACCESS_SETTINGS; +std::string CJNISettings::ACTION_VOICE_INPUT_SETTINGS; + +void CJNISettings::PopulateStaticFields() +{ + int sdk = CJNIBase::GetSDKVersion(); + + jhclass clazz = find_class("android/provider/Settings"); + ACTION_ACCESSIBILITY_SETTINGS = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_ACCESSIBILITY_SETTINGS"))); + ACTION_ADD_ACCOUNT = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_ADD_ACCOUNT"))); + ACTION_AIRPLANE_MODE_SETTINGS = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_AIRPLANE_MODE_SETTINGS"))); + ACTION_APN_SETTINGS = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_APN_SETTINGS"))); + ACTION_APPLICATION_DETAILS_SETTINGS = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_APPLICATION_DETAILS_SETTINGS"))); + ACTION_APPLICATION_DEVELOPMENT_SETTINGS = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_APPLICATION_DEVELOPMENT_SETTINGS"))); + ACTION_APPLICATION_SETTINGS = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_APPLICATION_SETTINGS"))); + ACTION_BLUETOOTH_SETTINGS = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_BLUETOOTH_SETTINGS"))); + ACTION_DATA_ROAMING_SETTINGS = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_DATA_ROAMING_SETTINGS"))); + ACTION_DATE_SETTINGS = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_DATE_SETTINGS"))); + ACTION_DEVICE_INFO_SETTINGS = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_DEVICE_INFO_SETTINGS"))); + ACTION_DISPLAY_SETTINGS = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_DISPLAY_SETTINGS"))); + ACTION_INPUT_METHOD_SETTINGS = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_INPUT_METHOD_SETTINGS"))); + ACTION_INPUT_METHOD_SUBTYPE_SETTINGS = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_INPUT_METHOD_SUBTYPE_SETTINGS"))); + ACTION_INTERNAL_STORAGE_SETTINGS = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_INTERNAL_STORAGE_SETTINGS"))); + ACTION_LOCALE_SETTINGS = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_LOCALE_SETTINGS"))); + ACTION_LOCATION_SOURCE_SETTINGS = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_LOCATION_SOURCE_SETTINGS"))); + ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS"))); + ACTION_MANAGE_APPLICATIONS_SETTINGS = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_MANAGE_APPLICATIONS_SETTINGS"))); + ACTION_MEMORY_CARD_SETTINGS = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_MEMORY_CARD_SETTINGS"))); + ACTION_NETWORK_OPERATOR_SETTINGS = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_NETWORK_OPERATOR_SETTINGS"))); + ACTION_NFCSHARING_SETTINGS = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_NFCSHARING_SETTINGS"))); + ACTION_PRIVACY_SETTINGS = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_PRIVACY_SETTINGS"))); + ACTION_QUICK_LAUNCH_SETTINGS = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_QUICK_LAUNCH_SETTINGS"))); + ACTION_SEARCH_SETTINGS = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_SEARCH_SETTINGS"))); + ACTION_SECURITY_SETTINGS = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_SECURITY_SETTINGS"))); + ACTION_SETTINGS = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_SETTINGS"))); + ACTION_SOUND_SETTINGS = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_SOUND_SETTINGS"))); + ACTION_SYNC_SETTINGS = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_SYNC_SETTINGS"))); + ACTION_USER_DICTIONARY_SETTINGS = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_USER_DICTIONARY_SETTINGS"))); + ACTION_WIFI_IP_SETTINGS = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_WIFI_IP_SETTINGS"))); + ACTION_WIFI_SETTINGS = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_WIFI_SETTINGS"))); + ACTION_WIRELESS_SETTINGS = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_WIRELESS_SETTINGS"))); + AUTHORITY = (jcast<std::string>(get_static_field<jhstring>(clazz, "AUTHORITY"))); + + if (sdk >= 16) + { + ACTION_NFC_SETTINGS = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_NFC_SETTINGS"))); + } + + if (sdk >= 18) + { + ACTION_DREAM_SETTINGS = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_DREAM_SETTINGS"))); + } + + if (sdk >= 19) + { + ACTION_CAPTIONING_SETTINGS = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_CAPTIONING_SETTINGS"))); + ACTION_NFC_PAYMENT_SETTINGS = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_NFC_PAYMENT_SETTINGS"))); + ACTION_PRINT_SETTINGS = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_PRINT_SETTINGS"))); + } + + if (sdk >= 21) + { + ACTION_CAST_SETTINGS = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_CAST_SETTINGS"))); + ACTION_HOME_SETTINGS = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_HOME_SETTINGS"))); + ACTION_SHOW_REGULATORY_INFO = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_SHOW_REGULATORY_INFO"))); + ACTION_USAGE_ACCESS_SETTINGS = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_USAGE_ACCESS_SETTINGS"))); + ACTION_VOICE_INPUT_SETTINGS = (jcast<std::string>(get_static_field<jhstring>(clazz, "ACTION_VOICE_INPUT_SETTINGS"))); + } +} + diff --git a/xbmc/platform/android/jni/Settings.h b/xbmc/platform/android/jni/Settings.h new file mode 100644 index 0000000000..e9ac433f7c --- /dev/null +++ b/xbmc/platform/android/jni/Settings.h @@ -0,0 +1,84 @@ +#pragma once +/* + * Copyright (C) 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 <string> + +namespace jni +{ + +class CJNISettings +{ + public: + static void PopulateStaticFields(); + + static std::string ACTION_ACCESSIBILITY_SETTINGS; + static std::string ACTION_ADD_ACCOUNT; + static std::string ACTION_AIRPLANE_MODE_SETTINGS; + static std::string ACTION_APN_SETTINGS; + static std::string ACTION_APPLICATION_DETAILS_SETTINGS; + static std::string ACTION_APPLICATION_DEVELOPMENT_SETTINGS; + static std::string ACTION_APPLICATION_SETTINGS; + static std::string ACTION_BLUETOOTH_SETTINGS; + static std::string ACTION_DATA_ROAMING_SETTINGS; + static std::string ACTION_DATE_SETTINGS; + static std::string ACTION_DEVICE_INFO_SETTINGS; + static std::string ACTION_DISPLAY_SETTINGS; + static std::string ACTION_INPUT_METHOD_SETTINGS; + static std::string ACTION_INPUT_METHOD_SUBTYPE_SETTINGS; + static std::string ACTION_INTERNAL_STORAGE_SETTINGS; + static std::string ACTION_LOCALE_SETTINGS; + static std::string ACTION_LOCATION_SOURCE_SETTINGS; + static std::string ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS; + static std::string ACTION_MANAGE_APPLICATIONS_SETTINGS; + static std::string ACTION_MEMORY_CARD_SETTINGS; + static std::string ACTION_NETWORK_OPERATOR_SETTINGS; + static std::string ACTION_NFCSHARING_SETTINGS; + static std::string ACTION_PRIVACY_SETTINGS; + static std::string ACTION_QUICK_LAUNCH_SETTINGS; + static std::string ACTION_SEARCH_SETTINGS; + static std::string ACTION_SECURITY_SETTINGS; + static std::string ACTION_SETTINGS; + static std::string ACTION_SOUND_SETTINGS; + static std::string ACTION_SYNC_SETTINGS; + static std::string ACTION_USER_DICTIONARY_SETTINGS; + static std::string ACTION_WIFI_IP_SETTINGS; + static std::string ACTION_WIFI_SETTINGS; + static std::string ACTION_WIRELESS_SETTINGS; + static std::string AUTHORITY; + + // API 16 + static std::string ACTION_NFC_SETTINGS; + // API 18 + static std::string ACTION_DREAM_SETTINGS; + // API 19 + static std::string ACTION_CAPTIONING_SETTINGS; + static std::string ACTION_NFC_PAYMENT_SETTINGS; + static std::string ACTION_PRINT_SETTINGS; + // API 21 + static std::string ACTION_CAST_SETTINGS; + static std::string ACTION_HOME_SETTINGS; + static std::string ACTION_SHOW_REGULATORY_INFO; + static std::string ACTION_USAGE_ACCESS_SETTINGS; + static std::string ACTION_VOICE_INPUT_SETTINGS; + +}; +} + diff --git a/xbmc/platform/android/jni/System.cpp b/xbmc/platform/android/jni/System.cpp index e9e6cfdfcc..6425a782bd 100644 --- a/xbmc/platform/android/jni/System.cpp +++ b/xbmc/platform/android/jni/System.cpp @@ -50,3 +50,10 @@ std::string CJNISystem::clearProperty(const std::string &property) "clearProperty", "(Ljava/lang/String;)Ljava/lang/String;", jcast<jhstring>(property))); } + +int64_t CJNISystem::nanoTime() +{ + return call_static_method<jlong>("java/lang/System", + "nanoTime", + "()J"); +} diff --git a/xbmc/platform/android/jni/System.h b/xbmc/platform/android/jni/System.h index e8f1a71f7e..7f78c7dcfe 100644 --- a/xbmc/platform/android/jni/System.h +++ b/xbmc/platform/android/jni/System.h @@ -28,6 +28,7 @@ public: static std::string getProperty( const std::string &property, const std::string &defaultValue); static std::string setProperty( const std::string &property, const std::string &defaultValue); static std::string clearProperty(const std::string &property); + static int64_t nanoTime(); private: CJNISystem(); diff --git a/xbmc/platform/android/jni/URIPermission.cpp b/xbmc/platform/android/jni/URIPermission.cpp new file mode 100644 index 0000000000..c56fb2912c --- /dev/null +++ b/xbmc/platform/android/jni/URIPermission.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (C) 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 "URIPermission.h" +#include "jutils/jutils-details.hpp" + +using namespace jni; + +std::string CJNIURIPermission::toString() const +{ + return jcast<std::string>(call_method<jhstring>(m_object, + "toString", "()Ljava/lang/String;")); +} + +CJNIURI CJNIURIPermission::getUri() const +{ + return (CJNIURI)call_method<jhobject>(m_object, + "getUri", "()Landroid/net/Uri;"); +} diff --git a/xbmc/platform/android/jni/URIPermission.h b/xbmc/platform/android/jni/URIPermission.h new file mode 100644 index 0000000000..b2b288056c --- /dev/null +++ b/xbmc/platform/android/jni/URIPermission.h @@ -0,0 +1,37 @@ +#pragma once +/* + * Copyright (C) 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 "JNIBase.h" + +#include "URI.h" + +class CJNIURIPermission : public CJNIBase +{ +public: + CJNIURIPermission(const jni::jhobject &uri) : CJNIBase(uri) {}; + ~CJNIURIPermission() {}; + + std::string toString() const; + CJNIURI getUri() const; + +private: + CJNIURIPermission(); +}; diff --git a/xbmc/platform/android/jni/jutils/jutils-details.hpp b/xbmc/platform/android/jni/jutils/jutils-details.hpp index 7278fdbb12..a6a87afe46 100644 --- a/xbmc/platform/android/jni/jutils/jutils-details.hpp +++ b/xbmc/platform/android/jni/jutils/jutils-details.hpp @@ -47,6 +47,7 @@ */ #pragma once +#define HAVE_INTTYPES_H 1 #include <jni.h> #include <string> @@ -544,6 +545,12 @@ Ret get_field(const char *clsname, const char *name) // Get static field template <typename Ret> +Ret get_static_field(JNIEnv *env, jhclass const &cls, jfieldID fid) +{ + return details::jni_helper<Ret>::get_static_field(env, cls, fid); +} + +template <typename Ret> Ret get_static_field(JNIEnv *env, jhobject const &obj, const char *name, const char *signature) { return details::jni_helper<Ret>::get_static_field(env, get_class(env, obj), get_static_field_id(env, obj, name, signature)); @@ -552,7 +559,7 @@ Ret get_static_field(JNIEnv *env, jhobject const &obj, const char *name, const c template <typename Ret> Ret get_static_field(JNIEnv *env, jhclass const &cls, const char *name, const char *signature) { - return details::jni_helper<Ret>::get_static_field(env, cls, get_static_field_id(env, cls, name, signature)); + return get_static_field<Ret>(env, cls, get_static_field_id(env, cls, name, signature)); } template <typename Ret, typename T> @@ -597,6 +604,13 @@ Ret get_static_field(const char *clsname, const char *name) return get_static_field<Ret>(xbmc_jnienv(), clsname, name); } +template <typename Ret> +Ret get_static_field(jhclass const &cls, jfieldID fid) +{ + return details::jni_helper<Ret>::get_static_field(xbmc_jnienv(), cls, fid); +} + + // Set field template <typename T, typename Arg> diff --git a/xbmc/platform/android/jni/jutils/jutils.hpp b/xbmc/platform/android/jni/jutils/jutils.hpp index 059a2c09bc..50d8d014cb 100644 --- a/xbmc/platform/android/jni/jutils/jutils.hpp +++ b/xbmc/platform/android/jni/jutils/jutils.hpp @@ -48,6 +48,8 @@ #pragma once +#define HAVE_INTTYPES_H 1 + #include <jni.h> #include <string> #include <android/log.h> |