Skip to content

Commit da074fe

Browse files
committed
remove non events from geode utils
1 parent 25f179b commit da074fe

File tree

2 files changed

+0
-340
lines changed

2 files changed

+0
-340
lines changed

loader/include/Geode/utils/AndroidEvent.hpp

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ namespace geode {
1414
geode::Result<int> getLauncherVersion();
1515
}
1616

17-
geode::Result<int> getConnectedControllerCount();
18-
geode::Result<std::vector<int>> getConnectedDevices();
19-
2017
/**
2118
* Input timestamp (in nanoseconds) sent by the launcher just before the next input event is received
2219
*/
@@ -36,53 +33,6 @@ namespace geode {
3633
ListenerResult handle(std::function<Callback> fn, AndroidInputTimestampEvent* event);
3734
};
3835

39-
class GEODE_DLL AndroidInputDevice final {
40-
private:
41-
int m_deviceId;
42-
jobject m_inputDevice{};
43-
44-
AndroidInputDevice(int deviceId, jobject inputDevice);
45-
46-
public:
47-
static Result<AndroidInputDevice> create(int deviceId);
48-
49-
AndroidInputDevice(const AndroidInputDevice&) = delete;
50-
AndroidInputDevice& operator=(const AndroidInputDevice&) = delete;
51-
52-
AndroidInputDevice(AndroidInputDevice&&);
53-
AndroidInputDevice& operator=(AndroidInputDevice&&);
54-
55-
~AndroidInputDevice();
56-
57-
std::string getDescriptor();
58-
59-
std::string getName();
60-
int getVendorId();
61-
int getProductId();
62-
63-
float getBatteryCapacity();
64-
int getBatteryStatus();
65-
bool hasBattery();
66-
67-
int getSources();
68-
69-
enum class LightType {
70-
None = 0,
71-
PlayerNumber = 1,
72-
Color = 2,
73-
All = 3
74-
};
75-
76-
int getLightCount();
77-
LightType getLightType();
78-
Result<> setLights(LightType type, std::uint32_t color);
79-
80-
int getMotorCount();
81-
Result<> vibrateDevice(long durationMs, int intensity, int motorIdx = -1);
82-
83-
int getDeviceId() const;
84-
};
85-
8636
class GEODE_DLL AndroidInputDeviceInfoEvent final : public Event {
8737
protected:
8838
int m_deviceId;

loader/src/platform/android/util.cpp

Lines changed: 0 additions & 290 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
795505
extern "C"
796506
JNIEXPORT void JNICALL Java_com_geode_launcher_utils_GeodeUtils_setNextInputDevice(JNIEnv*, jobject, jint deviceId, jint eventSource) {
797507
geode::AndroidInputDeviceInfoEvent(deviceId, eventSource).post();

0 commit comments

Comments
 (0)