@@ -502,296 +502,6 @@ ListenerResult AndroidInputTimestampFilter::handle(std::function<Callback> fn, A
502502 return ListenerResult::Propagate;
503503}
504504
505- geode::Result<int > geode::getConnectedControllerCount () {
506- JniMethodInfo info;
507- if (JniHelper::getStaticMethodInfo (info, " com/geode/launcher/utils/GeodeUtils" , " controllersConnected" , " ()I" )) {
508- auto result = info.env ->CallStaticIntMethod (info.classID , info.methodID );
509- info.env ->DeleteLocalRef (info.classID );
510-
511- return Ok (result);
512- } else {
513- clearJNIException ();
514- }
515-
516- return Err (" method not found" );
517- }
518-
519- geode::Result<std::vector<int >> geode::getConnectedDevices () {
520- JniMethodInfo info;
521- if (JniHelper::getStaticMethodInfo (info, " com/geode/launcher/utils/GeodeUtils" , " getConnectedDevices" , " ()[I" )) {
522- auto resultObject = reinterpret_cast <jintArray>(info.env ->CallStaticObjectMethod (info.classID , info.methodID ));
523- info.env ->DeleteLocalRef (info.classID );
524-
525- auto size = info.env ->GetArrayLength (resultObject);
526- std::vector<int > result (size);
527-
528- info.env ->GetIntArrayRegion (resultObject, 0 , size, result.data ());
529-
530- info.env ->DeleteLocalRef (resultObject);
531-
532- return Ok (result);
533- } else {
534- clearJNIException ();
535- }
536-
537- return Err (" method not found" );
538- }
539-
540- AndroidInputDevice::AndroidInputDevice (int deviceId, jobject inputDevice) : m_deviceId(deviceId), m_inputDevice(inputDevice) {}
541-
542- Result<AndroidInputDevice> AndroidInputDevice::create (int deviceId) {
543- JniMethodInfo info;
544- if (JniHelper::getStaticMethodInfo (info, " com/geode/launcher/utils/GeodeUtils" , " getDevice" , " (I)Landroid/view/InputDevice;" )) {
545- auto result = info.env ->CallStaticObjectMethod (info.classID , info.methodID , deviceId);
546- info.env ->DeleteLocalRef (info.classID );
547-
548- if (result == nullptr ) {
549- return Err (" device does not exist" );
550- }
551-
552- auto newRef = info.env ->NewGlobalRef (result);
553-
554- return Ok (std::move (AndroidInputDevice (deviceId, newRef)));
555- } else {
556- clearJNIException ();
557- }
558-
559- return Err (" method not found" );
560- }
561-
562- AndroidInputDevice::~AndroidInputDevice () {
563- if (!m_inputDevice) {
564- return ;
565- }
566-
567- auto vm = JniHelper::getJavaVM ();
568-
569- JNIEnv* env;
570- if (vm->GetEnv (reinterpret_cast <void **>(&env), JNI_VERSION_1_6) == JNI_OK) {
571- env->DeleteGlobalRef (m_inputDevice);
572- }
573- }
574-
575- std::string AndroidInputDevice::getDescriptor () {
576- JniMethodInfo info;
577- if (JniHelper::getMethodInfo (info, " android/view/InputDevice" , " getDescriptor" , " ()Ljava/lang/String;" )) {
578- auto stringResult = reinterpret_cast <jstring>(info.env ->CallObjectMethod (m_inputDevice, info.methodID ));
579-
580- std::string result = JniHelper::jstring2string (stringResult);
581-
582- info.env ->DeleteLocalRef (stringResult);
583- info.env ->DeleteLocalRef (info.classID );
584-
585- return result;
586- } else {
587- clearJNIException ();
588- }
589-
590- return " " ;
591- }
592-
593- std::string AndroidInputDevice::getName () {
594- JniMethodInfo info;
595- if (JniHelper::getMethodInfo (info, " android/view/InputDevice" , " getName" , " ()Ljava/lang/String;" )) {
596- auto stringResult = reinterpret_cast <jstring>(info.env ->CallObjectMethod (m_inputDevice, info.methodID ));
597-
598- std::string result = JniHelper::jstring2string (stringResult);
599-
600- info.env ->DeleteLocalRef (stringResult);
601- info.env ->DeleteLocalRef (info.classID );
602-
603- return result;
604- } else {
605- clearJNIException ();
606- }
607-
608- return " " ;
609- }
610-
611- int AndroidInputDevice::getVendorId () {
612- JniMethodInfo info;
613- if (JniHelper::getMethodInfo (info, " android/view/InputDevice" , " getVendorId" , " ()I" )) {
614- auto result = info.env ->CallIntMethod (m_inputDevice, info.methodID );
615- info.env ->DeleteLocalRef (info.classID );
616-
617- return result;
618- } else {
619- clearJNIException ();
620- }
621-
622- return 0 ;
623- }
624-
625- int AndroidInputDevice::getProductId () {
626- JniMethodInfo info;
627- if (JniHelper::getMethodInfo (info, " android/view/InputDevice" , " getProductId" , " ()I" )) {
628- auto result = info.env ->CallIntMethod (m_inputDevice, info.methodID );
629- info.env ->DeleteLocalRef (info.classID );
630-
631- return result;
632- } else {
633- clearJNIException ();
634- }
635-
636- return 0 ;
637- }
638-
639- float AndroidInputDevice::getBatteryCapacity () {
640- JniMethodInfo info;
641- if (JniHelper::getStaticMethodInfo (info, " com/geode/launcher/utils/GeodeUtils" , " getDeviceBatteryCapacity" , " (I)F" )) {
642- auto result = info.env ->CallStaticFloatMethod (info.classID , info.methodID , m_deviceId);
643- info.env ->DeleteLocalRef (info.classID );
644-
645- return result;
646- } else {
647- clearJNIException ();
648- }
649-
650- return 0 .0f ;
651- }
652-
653- bool AndroidInputDevice::hasBattery () {
654- JniMethodInfo info;
655- if (JniHelper::getStaticMethodInfo (info, " com/geode/launcher/utils/GeodeUtils" , " deviceHasBattery" , " (I)Z" )) {
656- auto result = info.env ->CallStaticBooleanMethod (info.classID , info.methodID , m_deviceId);
657- info.env ->DeleteLocalRef (info.classID );
658-
659- return result;
660- } else {
661- clearJNIException ();
662- }
663-
664- return false ;
665- }
666-
667- int AndroidInputDevice::getBatteryStatus () {
668- JniMethodInfo info;
669- if (JniHelper::getStaticMethodInfo (info, " com/geode/launcher/utils/GeodeUtils" , " getDeviceBatteryStatus" , " (I)I" )) {
670- auto result = info.env ->CallStaticIntMethod (info.classID , info.methodID , m_deviceId);
671- info.env ->DeleteLocalRef (info.classID );
672-
673- return result;
674- } else {
675- clearJNIException ();
676- }
677-
678- return 0 .0f ;
679- }
680-
681- int AndroidInputDevice::getSources () {
682- JniMethodInfo info;
683- if (JniHelper::getMethodInfo (info, " android/view/InputDevice" , " getSources" , " ()I" )) {
684- auto result = info.env ->CallIntMethod (m_inputDevice, info.methodID );
685- info.env ->DeleteLocalRef (info.classID );
686-
687- return result;
688- } else {
689- clearJNIException ();
690- }
691-
692- return 0 ;
693- }
694-
695- int AndroidInputDevice::getLightCount () {
696- JniMethodInfo info;
697- if (JniHelper::getStaticMethodInfo (info, " com/geode/launcher/utils/GeodeUtils" , " getDeviceLightsCount" , " (I)I" )) {
698- auto result = info.env ->CallStaticIntMethod (info.classID , info.methodID , m_deviceId);
699- info.env ->DeleteLocalRef (info.classID );
700-
701- return result;
702- } else {
703- clearJNIException ();
704- }
705-
706- return 0 ;
707- }
708-
709- AndroidInputDevice::LightType AndroidInputDevice::getLightType () {
710- JniMethodInfo info;
711- if (JniHelper::getStaticMethodInfo (info, " com/geode/launcher/utils/GeodeUtils" , " getLightType" , " (I)I" )) {
712- auto result = info.env ->CallStaticIntMethod (info.classID , info.methodID , m_deviceId);
713- info.env ->DeleteLocalRef (info.classID );
714-
715- return static_cast <LightType>(result);
716- } else {
717- clearJNIException ();
718- }
719-
720- return LightType::None;
721- }
722-
723- Result<> AndroidInputDevice::setLights (LightType type, std::uint32_t color) {
724- JniMethodInfo info;
725- if (JniHelper::getStaticMethodInfo (info, " com/geode/launcher/utils/GeodeUtils" , " setDeviceLightColor" , " (III)Z" )) {
726- auto result = info.env ->CallStaticBooleanMethod (info.classID , info.methodID , m_deviceId, static_cast <jint>(color), static_cast <jint>(type));
727- info.env ->DeleteLocalRef (info.classID );
728-
729- if (!result) {
730- return Err (" call failed" );
731- } else {
732- return Ok ();
733- }
734- } else {
735- clearJNIException ();
736- }
737-
738- return Err (" setDeviceLightColor method not found" );
739- }
740-
741- int AndroidInputDevice::getMotorCount () {
742- JniMethodInfo info;
743- if (JniHelper::getStaticMethodInfo (info, " com/geode/launcher/utils/GeodeUtils" , " getDeviceHapticsCount" , " (I)I" )) {
744- auto result = info.env ->CallStaticIntMethod (info.classID , info.methodID , m_deviceId);
745- info.env ->DeleteLocalRef (info.classID );
746-
747- return result;
748- } else {
749- clearJNIException ();
750- }
751-
752- return 0 ;
753- }
754-
755- Result<> AndroidInputDevice::vibrateDevice (long durationMs, int intensity, int motorIdx) {
756- JniMethodInfo info;
757- if (JniHelper::getStaticMethodInfo (info, " com/geode/launcher/utils/GeodeUtils" , " vibrateDevice" , " (IJII)Z" )) {
758- auto result = info.env ->CallStaticBooleanMethod (info.classID , info.methodID , m_deviceId, durationMs, intensity, motorIdx);
759- info.env ->DeleteLocalRef (info.classID );
760-
761- if (!result) {
762- return Err (" call failed" );
763- } else {
764- return Ok ();
765- }
766- } else {
767- clearJNIException ();
768- }
769-
770- return Err (" vibrateDevice method not found" );
771- }
772-
773- int AndroidInputDevice::getDeviceId () const {
774- return m_deviceId;
775- }
776-
777- AndroidInputDevice::AndroidInputDevice (AndroidInputDevice&& other) {
778- m_deviceId = other.m_deviceId ;
779- m_inputDevice = other.m_inputDevice ;
780-
781- other.m_deviceId = 0 ;
782- other.m_inputDevice = nullptr ;
783- }
784-
785- AndroidInputDevice& AndroidInputDevice::operator =(AndroidInputDevice&& other) {
786- m_deviceId = other.m_deviceId ;
787- m_inputDevice = other.m_inputDevice ;
788-
789- other.m_deviceId = 0 ;
790- other.m_inputDevice = nullptr ;
791-
792- return *this ;
793- }
794-
795505extern " C"
796506JNIEXPORT void JNICALL Java_com_geode_launcher_utils_GeodeUtils_setNextInputDevice (JNIEnv*, jobject, jint deviceId, jint eventSource) {
797507 geode::AndroidInputDeviceInfoEvent (deviceId, eventSource).post ();
0 commit comments