Skip to content

Commit

Permalink
FIX: [droid] proper JNI device listener
Browse files Browse the repository at this point in the history
  • Loading branch information
koying committed Jan 26, 2018
1 parent a7a709c commit f490ed9
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 34 deletions.
2 changes: 1 addition & 1 deletion project/cmake/scripts/android/Install.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ set(package_files strings.xml
src/interfaces/XBMCAudioManagerOnAudioFocusChangeListener.java
src/interfaces/XBMCNsdManagerRegistrationListener.java
src/interfaces/XBMCNsdManagerDiscoveryListener.java
src/interfaces/XBMCInputDeviceListener.java
src/XBMCBroadcastReceiver.java
src/model/TVEpisode.java
src/model/Movie.java
Expand All @@ -61,7 +62,6 @@ set(package_files strings.xml
src/model/Media.java
src/XBMCSearchableActivity.java
src/XBMCRecommendationBuilder.java
src/XBMCInputDeviceListener.java
src/XBMCProperties.java
src/content/XBMCFileContentProvider.java
src/content/XBMCMediaContentProvider.java
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package @APP_PACKAGE@;
package @APP_PACKAGE@.interfaces;

import android.hardware.input.InputManager.InputDeviceListener;
import android.util.Log;
Expand Down
5 changes: 4 additions & 1 deletion xbmc/platform/android/activity/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ set(SOURCES android_main.cpp
JNIXBMCNsdManagerResolveListener.cpp
JNIXBMCJsonHandler.cpp
JNIXBMCFile.cpp
JNIXBMCInputDeviceListener.cpp
XBMCApp.cpp
${NDKROOT}/sources/android/native_app_glue/android_native_app_glue.c
${NDKROOT}/sources/android/cpufeatures/cpu-features.c)
Expand All @@ -42,7 +43,9 @@ set(HEADERS AndroidExtra.h
JNIXBMCNsdManagerResolveListener.h
JNIXBMCJsonHandler.h
JNIXBMCFile.h
XBMCApp.h)
JNIXBMCInputDeviceListener.h
XBMCApp.h
)

core_add_library(platform_android_activity)
target_include_directories(${CORE_LIBRARY}
Expand Down
27 changes: 0 additions & 27 deletions xbmc/platform/android/activity/JNIMainActivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,33 +128,6 @@ void CJNIMainActivity::_onVolumeChanged(JNIEnv *env, jobject context, jint volum
m_appInstance->onVolumeChanged(volume);
}

void CJNIMainActivity::_onInputDeviceAdded(JNIEnv *env, jobject context, jint deviceId)
{
static_cast<void>(env);
static_cast<void>(context);

if (m_appInstance != nullptr)
m_appInstance->onInputDeviceAdded(deviceId);
}

void CJNIMainActivity::_onInputDeviceChanged(JNIEnv *env, jobject context, jint deviceId)
{
static_cast<void>(env);
static_cast<void>(context);

if (m_appInstance != nullptr)
m_appInstance->onInputDeviceChanged(deviceId);
}

void CJNIMainActivity::_onInputDeviceRemoved(JNIEnv *env, jobject context, jint deviceId)
{
static_cast<void>(env);
static_cast<void>(context);

if (m_appInstance != nullptr)
m_appInstance->onInputDeviceRemoved(deviceId);
}

void CJNIMainActivity::_onAudioDeviceAdded(JNIEnv *env, jobject context, jobjectArray devices)
{
static_cast<void>(env);
Expand Down
5 changes: 1 addition & 4 deletions xbmc/platform/android/activity/JNIMainActivity.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <androidjni/Image.h>
#include <androidjni/AudioDeviceInfo.h>

class CJNIMainActivity : public CJNIActivity, public CJNIInputManagerInputDeviceListener
class CJNIMainActivity : public CJNIActivity
{
public:
CJNIMainActivity(const ANativeActivity *nativeActivity);
Expand All @@ -37,9 +37,6 @@ class CJNIMainActivity : public CJNIActivity, public CJNIInputManagerInputDevice
static void _onActivityResult(JNIEnv *env, jobject context, jint requestCode, jint resultCode, jobject resultData);
static void _onVolumeChanged(JNIEnv *env, jobject context, jint volume);
static void _doFrame(JNIEnv *env, jobject context, jlong frameTimeNanos);
static void _onInputDeviceAdded(JNIEnv *env, jobject context, jint deviceId);
static void _onInputDeviceChanged(JNIEnv *env, jobject context, jint deviceId);
static void _onInputDeviceRemoved(JNIEnv *env, jobject context, jint deviceId);
static void _onCaptureAvailable(JNIEnv *env, jobject context, jobject image);
static void _onScreenshotAvailable(JNIEnv *env, jobject context, jobject image);
static void _onVisibleBehindCanceled(JNIEnv *env, jobject context);
Expand Down
90 changes: 90 additions & 0 deletions xbmc/platform/android/activity/JNIXBMCInputDeviceListener.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright (C) 2018 Christian Browet
* http://kodi.tv
*
* 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 <algorithm>

#include "JNIXBMCInputDeviceListener.h"
#include <androidjni/jutils-details.hpp>

#include "CompileInfo.h"

using namespace jni;

static std::string s_className = std::string(CCompileInfo::GetClass()) + "/interfaces/XBMCInputDeviceListener";

CJNIXBMCInputDeviceListener::CJNIXBMCInputDeviceListener()
: CJNIBase()
{
add_instance(m_object, this);
}

CJNIXBMCInputDeviceListener::CJNIXBMCInputDeviceListener(const CJNIXBMCInputDeviceListener& other)
: CJNIBase(other)
{
add_instance(m_object, this);
}

CJNIXBMCInputDeviceListener::~CJNIXBMCInputDeviceListener()
{
remove_instance(this);
}

void CJNIXBMCInputDeviceListener::RegisterNatives(JNIEnv* env)
{
jclass cClass = env->FindClass(s_className.c_str());
if(cClass)
{
JNINativeMethod methods[] =
{
{ "_onInputDeviceAdded", "(I)V", (void*)&CJNIXBMCInputDeviceListener::_onInputDeviceAdded },
{ "_onInputDeviceChanged", "(I)V", (void*)&CJNIXBMCInputDeviceListener::_onInputDeviceChanged },
{ "_onInputDeviceRemoved", "(I)V", (void*)&CJNIXBMCInputDeviceListener::_onInputDeviceRemoved }
};

env->RegisterNatives(cClass, methods, sizeof(methods)/sizeof(methods[0]));
}
}

void CJNIXBMCInputDeviceListener::_onInputDeviceAdded(JNIEnv *env, jobject thiz, jint deviceId)
{
(void)env;

CJNIXBMCInputDeviceListener *inst = find_instance(thiz);
if (inst)
inst->onInputDeviceAdded(deviceId);
}

void CJNIXBMCInputDeviceListener::_onInputDeviceChanged(JNIEnv *env, jobject thiz, jint deviceId)
{
(void)env;

CJNIXBMCInputDeviceListener *inst = find_instance(thiz);
if (inst)
inst->onInputDeviceChanged(deviceId);
}

void CJNIXBMCInputDeviceListener::_onInputDeviceRemoved(JNIEnv *env, jobject thiz, jint deviceId)
{
(void)env;

CJNIXBMCInputDeviceListener *inst = find_instance(thiz);
if (inst)
inst->onInputDeviceRemoved(deviceId);
}
51 changes: 51 additions & 0 deletions xbmc/platform/android/activity/JNIXBMCInputDeviceListener.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#pragma once
/*
* Copyright (C) 2018 Christian Browet
* http://kodi.tv
*
* 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 <androidjni/JNIBase.h>

#include <androidjni/InputManager.h>

namespace jni
{

class CJNIXBMCInputDeviceListener : public CJNIInputManagerInputDeviceListener, public CJNIInterfaceImplem<CJNIXBMCInputDeviceListener>
{
public:
CJNIXBMCInputDeviceListener();
CJNIXBMCInputDeviceListener(const CJNIXBMCInputDeviceListener& other);
CJNIXBMCInputDeviceListener(const jni::jhobject &object) : CJNIBase(object) {}
virtual ~CJNIXBMCInputDeviceListener();

static void RegisterNatives(JNIEnv* env);

// CJNINsdManagerDiscoveryListener interface
public:
void onInputDeviceAdded(int deviceId) = 0;
void onInputDeviceChanged(int deviceId) = 0;
void onInputDeviceRemoved(int deviceId) = 0;

protected:
static void _onInputDeviceAdded(JNIEnv *env, jobject thiz, jint deviceId);
static void _onInputDeviceChanged(JNIEnv *env, jobject thiz, jint deviceId);
static void _onInputDeviceRemoved(JNIEnv *env, jobject thiz, jint deviceId);
};

}
1 change: 1 addition & 0 deletions xbmc/platform/android/activity/XBMCApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ CRect CXBMCApp::m_surface_rect;
CXBMCApp::CXBMCApp(ANativeActivity* nativeActivity)
: CJNIMainActivity(nativeActivity)
, CJNIBroadcastReceiver(CJNIContext::getPackageName() + ".XBMCBroadcastReceiver")
, CJNIXBMCInputDeviceListener()
, m_videosurfaceInUse(false)
{
m_xbmcappinstance = this;
Expand Down
2 changes: 2 additions & 0 deletions xbmc/platform/android/activity/XBMCApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include "JNIXBMCAudioManagerOnAudioFocusChangeListener.h"
#include "JNIXBMCMainView.h"
#include "JNIXBMCMediaSession.h"
#include "JNIXBMCInputDeviceListener.h"
#include "platform/xbmc.h"

// forward delares
Expand Down Expand Up @@ -113,6 +114,7 @@ class CXBMCApp
, public CJNIBroadcastReceiver
, public ANNOUNCEMENT::IAnnouncer
, public CJNISurfaceHolderCallback
, public jni::CJNIXBMCInputDeviceListener
{
public:
CXBMCApp(ANativeActivity *nativeActivity);
Expand Down

0 comments on commit f490ed9

Please sign in to comment.