mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-12-16 04:09:39 +00:00
Merge 01d2d0eea1 into ed2fe134aa
This commit is contained in:
commit
733502365e
@ -6,6 +6,7 @@ import android.content.Context
|
||||
import android.hardware.input.InputManager
|
||||
import android.os.Build
|
||||
import android.os.Handler
|
||||
import android.os.HandlerThread
|
||||
import android.os.Looper
|
||||
import android.os.VibrationEffect
|
||||
import android.os.Vibrator
|
||||
@ -17,7 +18,6 @@ import androidx.annotation.Keep
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import org.dolphinemu.dolphinemu.DolphinApplication
|
||||
import org.dolphinemu.dolphinemu.utils.LooperThread
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
||||
/**
|
||||
@ -26,9 +26,9 @@ import java.util.concurrent.atomic.AtomicBoolean
|
||||
*/
|
||||
object ControllerInterface {
|
||||
private var inputDeviceListener: InputDeviceListener? = null
|
||||
private lateinit var looperThread: LooperThread
|
||||
private var handlerThread: HandlerThread? = null
|
||||
|
||||
private var inputStateUpdatePending = AtomicBoolean(false)
|
||||
private val inputStateUpdatePending = AtomicBoolean(false)
|
||||
private val inputStateVersion = MutableLiveData(0)
|
||||
private val devicesVersion = MutableLiveData(0)
|
||||
|
||||
@ -81,9 +81,7 @@ object ControllerInterface {
|
||||
}
|
||||
|
||||
private external fun dispatchSensorEventNative(
|
||||
deviceQualifier: String,
|
||||
axisName: String,
|
||||
value: Float
|
||||
deviceQualifier: String, axisName: String, value: Float
|
||||
): Boolean
|
||||
|
||||
/**
|
||||
@ -94,9 +92,7 @@ object ControllerInterface {
|
||||
* @param suspended Whether the sensor is now suspended.
|
||||
*/
|
||||
external fun notifySensorSuspendedState(
|
||||
deviceQualifier: String,
|
||||
axisNames: Array<String>,
|
||||
suspended: Boolean
|
||||
deviceQualifier: String, axisNames: Array<String>, suspended: Boolean
|
||||
)
|
||||
|
||||
/**
|
||||
@ -132,15 +128,18 @@ object ControllerInterface {
|
||||
@Keep
|
||||
@JvmStatic
|
||||
private fun registerInputDeviceListener() {
|
||||
looperThread = LooperThread("Hotplug thread")
|
||||
looperThread.start()
|
||||
|
||||
if (inputDeviceListener == null) {
|
||||
handlerThread = HandlerThread("Hotplug thread").apply { start() }
|
||||
val thread = requireNotNull(handlerThread) { "HandlerThread is not available" }
|
||||
|
||||
val im = DolphinApplication.getAppContext()
|
||||
.getSystemService(Context.INPUT_SERVICE) as InputManager?
|
||||
.getSystemService(Context.INPUT_SERVICE) as InputManager
|
||||
val looper = requireNotNull(thread.looper) {
|
||||
"HandlerThread looper is not available"
|
||||
}
|
||||
|
||||
inputDeviceListener = InputDeviceListener()
|
||||
im!!.registerInputDeviceListener(inputDeviceListener, Handler(looperThread.looper))
|
||||
im.registerInputDeviceListener(inputDeviceListener, Handler(looper))
|
||||
}
|
||||
}
|
||||
|
||||
@ -149,10 +148,12 @@ object ControllerInterface {
|
||||
private fun unregisterInputDeviceListener() {
|
||||
if (inputDeviceListener != null) {
|
||||
val im = DolphinApplication.getAppContext()
|
||||
.getSystemService(Context.INPUT_SERVICE) as InputManager?
|
||||
.getSystemService(Context.INPUT_SERVICE) as InputManager
|
||||
|
||||
im!!.unregisterInputDeviceListener(inputDeviceListener)
|
||||
im.unregisterInputDeviceListener(inputDeviceListener)
|
||||
inputDeviceListener = null
|
||||
handlerThread?.quitSafely()
|
||||
handlerThread = null
|
||||
}
|
||||
}
|
||||
|
||||
@ -172,8 +173,9 @@ object ControllerInterface {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
val vibratorManager = DolphinApplication.getAppContext()
|
||||
.getSystemService(Context.VIBRATOR_MANAGER_SERVICE) as VibratorManager?
|
||||
if (vibratorManager != null)
|
||||
if (vibratorManager != null) {
|
||||
return DolphinVibratorManagerPassthrough(vibratorManager)
|
||||
}
|
||||
}
|
||||
val vibrator = DolphinApplication.getAppContext()
|
||||
.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
|
||||
|
||||
@ -1,58 +0,0 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.dolphinemu.dolphinemu.utils;
|
||||
|
||||
import android.os.Looper;
|
||||
|
||||
public class LooperThread extends Thread
|
||||
{
|
||||
private Looper mLooper;
|
||||
|
||||
public LooperThread()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public LooperThread(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
Looper.prepare();
|
||||
|
||||
synchronized (this)
|
||||
{
|
||||
mLooper = Looper.myLooper();
|
||||
notifyAll();
|
||||
}
|
||||
|
||||
Looper.loop();
|
||||
}
|
||||
|
||||
public Looper getLooper()
|
||||
{
|
||||
if (!isAlive())
|
||||
{
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
synchronized (this)
|
||||
{
|
||||
while (mLooper == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
wait();
|
||||
}
|
||||
catch (InterruptedException ignored)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return mLooper;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user