Loading services/vr/virtual_touchpad/Android.mk +29 −1 Original line number Original line Diff line number Diff line Loading @@ -6,13 +6,14 @@ include $(CLEAR_VARS) src := \ src := \ EvdevInjector.cpp \ EvdevInjector.cpp \ VirtualTouchpad.cpp VirtualTouchpadEvdev.cpp shared_libs := \ shared_libs := \ libbase libbase include $(CLEAR_VARS) include $(CLEAR_VARS) LOCAL_SRC_FILES := $(src) LOCAL_SRC_FILES := $(src) LOCAL_C_INCLUDES := $(LOCAL_PATH)/include LOCAL_SHARED_LIBRARIES := $(shared_libs) LOCAL_SHARED_LIBRARIES := $(shared_libs) LOCAL_CPPFLAGS += -std=c++11 LOCAL_CPPFLAGS += -std=c++11 LOCAL_CFLAGS += -DLOG_TAG=\"VrVirtualTouchpad\" LOCAL_CFLAGS += -DLOG_TAG=\"VrVirtualTouchpad\" Loading @@ -29,11 +30,13 @@ test_src_files := \ static_libs := \ static_libs := \ libbase \ libbase \ libcutils \ libcutils \ libutils \ libvirtualtouchpad libvirtualtouchpad $(foreach file,$(test_src_files), \ $(foreach file,$(test_src_files), \ $(eval include $(CLEAR_VARS)) \ $(eval include $(CLEAR_VARS)) \ $(eval LOCAL_SRC_FILES := $(file)) \ $(eval LOCAL_SRC_FILES := $(file)) \ $(eval LOCAL_C_INCLUDES := $(LOCAL_PATH)/include) \ $(eval LOCAL_STATIC_LIBRARIES := $(static_libs)) \ $(eval LOCAL_STATIC_LIBRARIES := $(static_libs)) \ $(eval LOCAL_SHARED_LIBRARIES := $(shared_libs)) \ $(eval LOCAL_SHARED_LIBRARIES := $(shared_libs)) \ $(eval LOCAL_CPPFLAGS += -std=c++11) \ $(eval LOCAL_CPPFLAGS += -std=c++11) \ Loading Loading @@ -63,6 +66,7 @@ shared_libs := \ include $(CLEAR_VARS) include $(CLEAR_VARS) LOCAL_SRC_FILES := $(src) LOCAL_SRC_FILES := $(src) LOCAL_C_INCLUDES := $(LOCAL_PATH)/include LOCAL_STATIC_LIBRARIES := $(static_libs) LOCAL_STATIC_LIBRARIES := $(static_libs) LOCAL_SHARED_LIBRARIES := $(shared_libs) LOCAL_SHARED_LIBRARIES := $(shared_libs) LOCAL_CPPFLAGS += -std=c++11 LOCAL_CPPFLAGS += -std=c++11 Loading @@ -74,3 +78,27 @@ LOCAL_INIT_RC := virtual_touchpad.rc LOCAL_MULTILIB := 64 LOCAL_MULTILIB := 64 LOCAL_CXX_STL := libc++_static LOCAL_CXX_STL := libc++_static include $(BUILD_EXECUTABLE) include $(BUILD_EXECUTABLE) # Touchpad client library. src := \ VirtualTouchpadClient.cpp \ aidl/android/dvr/VirtualTouchpadService.aidl shared_libs := \ libbase \ libbinder \ libutils include $(CLEAR_VARS) LOCAL_SRC_FILES := $(src) LOCAL_C_INCLUDES := $(LOCAL_PATH)/include LOCAL_SHARED_LIBRARIES := $(shared_libs) LOCAL_CPPFLAGS += -std=c++11 LOCAL_CFLAGS += -DLOG_TAG=\"VirtualTouchpadClient\" LOCAL_LDLIBS := -llog LOCAL_MODULE := libvirtualtouchpadclient LOCAL_MODULE_TAGS := optional LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include include $(BUILD_STATIC_LIBRARY) services/vr/virtual_touchpad/VirtualTouchpadClient.cpp 0 → 100644 +52 −0 Original line number Original line Diff line number Diff line #include "VirtualTouchpadClient.h" #include <android/dvr/IVirtualTouchpadService.h> #include <binder/IServiceManager.h> namespace android { namespace dvr { namespace { class VirtualTouchpadClientImpl : public VirtualTouchpadClient { public: VirtualTouchpadClientImpl(sp<IVirtualTouchpadService> service) : service_(service) {} ~VirtualTouchpadClientImpl() {} status_t Touch(float x, float y, float pressure) override { if (service_ == nullptr) { return NO_INIT; } return service_->touch(x, y, pressure).transactionError(); } status_t ButtonState(int buttons) override { if (service_ == nullptr) { return NO_INIT; } return service_->buttonState(buttons).transactionError(); } private: sp<IVirtualTouchpadService> service_; }; } // anonymous namespace sp<VirtualTouchpad> VirtualTouchpadClient::Create() { sp<IServiceManager> sm = defaultServiceManager(); if (sm == nullptr) { ALOGE("no service manager"); return sp<VirtualTouchpad>(); } sp<IVirtualTouchpadService> service = interface_cast<IVirtualTouchpadService>( sm->getService(IVirtualTouchpadService::SERVICE_NAME())); if (service == nullptr) { ALOGE("failed to get service"); return sp<VirtualTouchpad>(); } return new VirtualTouchpadClientImpl(service); } } // namespace dvr } // namespace android services/vr/virtual_touchpad/VirtualTouchpad.cpp→services/vr/virtual_touchpad/VirtualTouchpadEvdev.cpp +14 −4 Original line number Original line Diff line number Diff line #include "VirtualTouchpad.h" #include "VirtualTouchpadEvdev.h" #include <android/input.h> #include <android/input.h> #include <inttypes.h> #include <inttypes.h> Loading Loading @@ -30,7 +30,17 @@ static constexpr int32_t kSlots = 2; } // anonymous namespace } // anonymous namespace int VirtualTouchpad::Initialize() { sp<VirtualTouchpad> VirtualTouchpadEvdev::Create() { VirtualTouchpadEvdev* const touchpad = new VirtualTouchpadEvdev(); const status_t status = touchpad->Initialize(); if (status) { ALOGE("initialization failed: %d", status); return sp<VirtualTouchpad>(); } return sp<VirtualTouchpad>(touchpad); } int VirtualTouchpadEvdev::Initialize() { if (!injector_) { if (!injector_) { owned_injector_.reset(new EvdevInjector()); owned_injector_.reset(new EvdevInjector()); injector_ = owned_injector_.get(); injector_ = owned_injector_.get(); Loading @@ -46,7 +56,7 @@ int VirtualTouchpad::Initialize() { return injector_->GetError(); return injector_->GetError(); } } int VirtualTouchpad::Touch(float x, float y, float pressure) { int VirtualTouchpadEvdev::Touch(float x, float y, float pressure) { if ((x < 0.0f) || (x >= 1.0f) || (y < 0.0f) || (y >= 1.0f)) { if ((x < 0.0f) || (x >= 1.0f) || (y < 0.0f) || (y >= 1.0f)) { return EINVAL; return EINVAL; } } Loading Loading @@ -91,7 +101,7 @@ int VirtualTouchpad::Touch(float x, float y, float pressure) { return injector_->GetError(); return injector_->GetError(); } } int VirtualTouchpad::ButtonState(int buttons) { int VirtualTouchpadEvdev::ButtonState(int buttons) { const int changes = last_motion_event_buttons_ ^ buttons; const int changes = last_motion_event_buttons_ ^ buttons; if (!changes) { if (!changes) { return 0; return 0; Loading services/vr/virtual_touchpad/VirtualTouchpad.h→services/vr/virtual_touchpad/VirtualTouchpadEvdev.h +59 −0 Original line number Original line Diff line number Diff line #ifndef ANDROID_DVR_VIRTUAL_TOUCHPAD_H #ifndef ANDROID_DVR_VIRTUAL_TOUCHPAD_EVDEV_H #define ANDROID_DVR_VIRTUAL_TOUCHPAD_H #define ANDROID_DVR_VIRTUAL_TOUCHPAD_EVDEV_H #include <memory> #include <memory> #include "VirtualTouchpad.h" #include "EvdevInjector.h" #include "EvdevInjector.h" namespace android { namespace android { Loading @@ -10,40 +11,21 @@ namespace dvr { class EvdevInjector; class EvdevInjector; // Provides a virtual touchpad for injecting events into the input system. // VirtualTouchpadEvdev implements a VirtualTouchpad by injecting evdev events. // // class VirtualTouchpad { class VirtualTouchpadEvdev : public VirtualTouchpad { public: public: VirtualTouchpad() {} static sp<VirtualTouchpad> Create(); ~VirtualTouchpad() {} // |Intialize()| must be called once on a VirtualTouchpad before // VirtualTouchpad implementation: // and other public method. Returns zero on success. status_t Touch(float x, float y, float pressure) override; int Initialize(); status_t ButtonState(int buttons) override; // Generate a simulated touch event. // // @param x Horizontal touch position. // @param y Vertical touch position. // Values must be in the range [0.0, 1.0). // @param pressure Touch pressure. // Positive values represent contact; use 1.0f if contact // is binary. Use 0.0f for no contact. // @returns Zero on success. // int Touch(float x, float y, float pressure); // Generate a simulated touchpad button state. // // @param buttons A union of MotionEvent BUTTON_* values. // @returns Zero on success. // // Currently only BUTTON_BACK is supported, as the implementation // restricts itself to operations actually required by VrWindowManager. // int ButtonState(int buttons); protected: protected: VirtualTouchpadEvdev() {} ~VirtualTouchpadEvdev() {} status_t Initialize(); // Must be called only between construction and Initialize(). // Must be called only between construction and Initialize(). inline void SetEvdevInjectorForTesting(EvdevInjector* injector) { inline void SetEvdevInjectorForTesting(EvdevInjector* injector) { injector_ = injector; injector_ = injector; Loading @@ -67,11 +49,11 @@ class VirtualTouchpad { // Previous injected button state, to detect changes. // Previous injected button state, to detect changes. int32_t last_motion_event_buttons_ = 0; int32_t last_motion_event_buttons_ = 0; VirtualTouchpad(const VirtualTouchpad&) = delete; VirtualTouchpadEvdev(const VirtualTouchpadEvdev&) = delete; void operator=(const VirtualTouchpad&) = delete; void operator=(const VirtualTouchpadEvdev&) = delete; }; }; } // namespace dvr } // namespace dvr } // namespace android } // namespace android #endif // ANDROID_DVR_VIRTUAL_TOUCHPAD_H #endif // ANDROID_DVR_VIRTUAL_TOUCHPAD_EVDEV_H services/vr/virtual_touchpad/VirtualTouchpadService.cpp +4 −8 Original line number Original line Diff line number Diff line Loading @@ -8,19 +8,15 @@ namespace android { namespace android { namespace dvr { namespace dvr { int VirtualTouchpadService::Initialize() { return touchpad_.Initialize(); } binder::Status VirtualTouchpadService::touch(float x, float y, float pressure) { binder::Status VirtualTouchpadService::touch(float x, float y, float pressure) { const int error = touchpad_.Touch(x, y, pressure); const status_t error = touchpad_->Touch(x, y, pressure); return error ? binder::Status::fromServiceSpecificError(error) return error ? binder::Status::fromStatusT(error) : binder::Status::ok(); : binder::Status::ok(); } } binder::Status VirtualTouchpadService::buttonState(int buttons) { binder::Status VirtualTouchpadService::buttonState(int buttons) { const int error = touchpad_.ButtonState(buttons); const status_t error = touchpad_->ButtonState(buttons); return error ? binder::Status::fromServiceSpecificError(error) return error ? binder::Status::fromStatusT(error) : binder::Status::ok(); : binder::Status::ok(); } } Loading Loading
services/vr/virtual_touchpad/Android.mk +29 −1 Original line number Original line Diff line number Diff line Loading @@ -6,13 +6,14 @@ include $(CLEAR_VARS) src := \ src := \ EvdevInjector.cpp \ EvdevInjector.cpp \ VirtualTouchpad.cpp VirtualTouchpadEvdev.cpp shared_libs := \ shared_libs := \ libbase libbase include $(CLEAR_VARS) include $(CLEAR_VARS) LOCAL_SRC_FILES := $(src) LOCAL_SRC_FILES := $(src) LOCAL_C_INCLUDES := $(LOCAL_PATH)/include LOCAL_SHARED_LIBRARIES := $(shared_libs) LOCAL_SHARED_LIBRARIES := $(shared_libs) LOCAL_CPPFLAGS += -std=c++11 LOCAL_CPPFLAGS += -std=c++11 LOCAL_CFLAGS += -DLOG_TAG=\"VrVirtualTouchpad\" LOCAL_CFLAGS += -DLOG_TAG=\"VrVirtualTouchpad\" Loading @@ -29,11 +30,13 @@ test_src_files := \ static_libs := \ static_libs := \ libbase \ libbase \ libcutils \ libcutils \ libutils \ libvirtualtouchpad libvirtualtouchpad $(foreach file,$(test_src_files), \ $(foreach file,$(test_src_files), \ $(eval include $(CLEAR_VARS)) \ $(eval include $(CLEAR_VARS)) \ $(eval LOCAL_SRC_FILES := $(file)) \ $(eval LOCAL_SRC_FILES := $(file)) \ $(eval LOCAL_C_INCLUDES := $(LOCAL_PATH)/include) \ $(eval LOCAL_STATIC_LIBRARIES := $(static_libs)) \ $(eval LOCAL_STATIC_LIBRARIES := $(static_libs)) \ $(eval LOCAL_SHARED_LIBRARIES := $(shared_libs)) \ $(eval LOCAL_SHARED_LIBRARIES := $(shared_libs)) \ $(eval LOCAL_CPPFLAGS += -std=c++11) \ $(eval LOCAL_CPPFLAGS += -std=c++11) \ Loading Loading @@ -63,6 +66,7 @@ shared_libs := \ include $(CLEAR_VARS) include $(CLEAR_VARS) LOCAL_SRC_FILES := $(src) LOCAL_SRC_FILES := $(src) LOCAL_C_INCLUDES := $(LOCAL_PATH)/include LOCAL_STATIC_LIBRARIES := $(static_libs) LOCAL_STATIC_LIBRARIES := $(static_libs) LOCAL_SHARED_LIBRARIES := $(shared_libs) LOCAL_SHARED_LIBRARIES := $(shared_libs) LOCAL_CPPFLAGS += -std=c++11 LOCAL_CPPFLAGS += -std=c++11 Loading @@ -74,3 +78,27 @@ LOCAL_INIT_RC := virtual_touchpad.rc LOCAL_MULTILIB := 64 LOCAL_MULTILIB := 64 LOCAL_CXX_STL := libc++_static LOCAL_CXX_STL := libc++_static include $(BUILD_EXECUTABLE) include $(BUILD_EXECUTABLE) # Touchpad client library. src := \ VirtualTouchpadClient.cpp \ aidl/android/dvr/VirtualTouchpadService.aidl shared_libs := \ libbase \ libbinder \ libutils include $(CLEAR_VARS) LOCAL_SRC_FILES := $(src) LOCAL_C_INCLUDES := $(LOCAL_PATH)/include LOCAL_SHARED_LIBRARIES := $(shared_libs) LOCAL_CPPFLAGS += -std=c++11 LOCAL_CFLAGS += -DLOG_TAG=\"VirtualTouchpadClient\" LOCAL_LDLIBS := -llog LOCAL_MODULE := libvirtualtouchpadclient LOCAL_MODULE_TAGS := optional LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include include $(BUILD_STATIC_LIBRARY)
services/vr/virtual_touchpad/VirtualTouchpadClient.cpp 0 → 100644 +52 −0 Original line number Original line Diff line number Diff line #include "VirtualTouchpadClient.h" #include <android/dvr/IVirtualTouchpadService.h> #include <binder/IServiceManager.h> namespace android { namespace dvr { namespace { class VirtualTouchpadClientImpl : public VirtualTouchpadClient { public: VirtualTouchpadClientImpl(sp<IVirtualTouchpadService> service) : service_(service) {} ~VirtualTouchpadClientImpl() {} status_t Touch(float x, float y, float pressure) override { if (service_ == nullptr) { return NO_INIT; } return service_->touch(x, y, pressure).transactionError(); } status_t ButtonState(int buttons) override { if (service_ == nullptr) { return NO_INIT; } return service_->buttonState(buttons).transactionError(); } private: sp<IVirtualTouchpadService> service_; }; } // anonymous namespace sp<VirtualTouchpad> VirtualTouchpadClient::Create() { sp<IServiceManager> sm = defaultServiceManager(); if (sm == nullptr) { ALOGE("no service manager"); return sp<VirtualTouchpad>(); } sp<IVirtualTouchpadService> service = interface_cast<IVirtualTouchpadService>( sm->getService(IVirtualTouchpadService::SERVICE_NAME())); if (service == nullptr) { ALOGE("failed to get service"); return sp<VirtualTouchpad>(); } return new VirtualTouchpadClientImpl(service); } } // namespace dvr } // namespace android
services/vr/virtual_touchpad/VirtualTouchpad.cpp→services/vr/virtual_touchpad/VirtualTouchpadEvdev.cpp +14 −4 Original line number Original line Diff line number Diff line #include "VirtualTouchpad.h" #include "VirtualTouchpadEvdev.h" #include <android/input.h> #include <android/input.h> #include <inttypes.h> #include <inttypes.h> Loading Loading @@ -30,7 +30,17 @@ static constexpr int32_t kSlots = 2; } // anonymous namespace } // anonymous namespace int VirtualTouchpad::Initialize() { sp<VirtualTouchpad> VirtualTouchpadEvdev::Create() { VirtualTouchpadEvdev* const touchpad = new VirtualTouchpadEvdev(); const status_t status = touchpad->Initialize(); if (status) { ALOGE("initialization failed: %d", status); return sp<VirtualTouchpad>(); } return sp<VirtualTouchpad>(touchpad); } int VirtualTouchpadEvdev::Initialize() { if (!injector_) { if (!injector_) { owned_injector_.reset(new EvdevInjector()); owned_injector_.reset(new EvdevInjector()); injector_ = owned_injector_.get(); injector_ = owned_injector_.get(); Loading @@ -46,7 +56,7 @@ int VirtualTouchpad::Initialize() { return injector_->GetError(); return injector_->GetError(); } } int VirtualTouchpad::Touch(float x, float y, float pressure) { int VirtualTouchpadEvdev::Touch(float x, float y, float pressure) { if ((x < 0.0f) || (x >= 1.0f) || (y < 0.0f) || (y >= 1.0f)) { if ((x < 0.0f) || (x >= 1.0f) || (y < 0.0f) || (y >= 1.0f)) { return EINVAL; return EINVAL; } } Loading Loading @@ -91,7 +101,7 @@ int VirtualTouchpad::Touch(float x, float y, float pressure) { return injector_->GetError(); return injector_->GetError(); } } int VirtualTouchpad::ButtonState(int buttons) { int VirtualTouchpadEvdev::ButtonState(int buttons) { const int changes = last_motion_event_buttons_ ^ buttons; const int changes = last_motion_event_buttons_ ^ buttons; if (!changes) { if (!changes) { return 0; return 0; Loading
services/vr/virtual_touchpad/VirtualTouchpad.h→services/vr/virtual_touchpad/VirtualTouchpadEvdev.h +59 −0 Original line number Original line Diff line number Diff line #ifndef ANDROID_DVR_VIRTUAL_TOUCHPAD_H #ifndef ANDROID_DVR_VIRTUAL_TOUCHPAD_EVDEV_H #define ANDROID_DVR_VIRTUAL_TOUCHPAD_H #define ANDROID_DVR_VIRTUAL_TOUCHPAD_EVDEV_H #include <memory> #include <memory> #include "VirtualTouchpad.h" #include "EvdevInjector.h" #include "EvdevInjector.h" namespace android { namespace android { Loading @@ -10,40 +11,21 @@ namespace dvr { class EvdevInjector; class EvdevInjector; // Provides a virtual touchpad for injecting events into the input system. // VirtualTouchpadEvdev implements a VirtualTouchpad by injecting evdev events. // // class VirtualTouchpad { class VirtualTouchpadEvdev : public VirtualTouchpad { public: public: VirtualTouchpad() {} static sp<VirtualTouchpad> Create(); ~VirtualTouchpad() {} // |Intialize()| must be called once on a VirtualTouchpad before // VirtualTouchpad implementation: // and other public method. Returns zero on success. status_t Touch(float x, float y, float pressure) override; int Initialize(); status_t ButtonState(int buttons) override; // Generate a simulated touch event. // // @param x Horizontal touch position. // @param y Vertical touch position. // Values must be in the range [0.0, 1.0). // @param pressure Touch pressure. // Positive values represent contact; use 1.0f if contact // is binary. Use 0.0f for no contact. // @returns Zero on success. // int Touch(float x, float y, float pressure); // Generate a simulated touchpad button state. // // @param buttons A union of MotionEvent BUTTON_* values. // @returns Zero on success. // // Currently only BUTTON_BACK is supported, as the implementation // restricts itself to operations actually required by VrWindowManager. // int ButtonState(int buttons); protected: protected: VirtualTouchpadEvdev() {} ~VirtualTouchpadEvdev() {} status_t Initialize(); // Must be called only between construction and Initialize(). // Must be called only between construction and Initialize(). inline void SetEvdevInjectorForTesting(EvdevInjector* injector) { inline void SetEvdevInjectorForTesting(EvdevInjector* injector) { injector_ = injector; injector_ = injector; Loading @@ -67,11 +49,11 @@ class VirtualTouchpad { // Previous injected button state, to detect changes. // Previous injected button state, to detect changes. int32_t last_motion_event_buttons_ = 0; int32_t last_motion_event_buttons_ = 0; VirtualTouchpad(const VirtualTouchpad&) = delete; VirtualTouchpadEvdev(const VirtualTouchpadEvdev&) = delete; void operator=(const VirtualTouchpad&) = delete; void operator=(const VirtualTouchpadEvdev&) = delete; }; }; } // namespace dvr } // namespace dvr } // namespace android } // namespace android #endif // ANDROID_DVR_VIRTUAL_TOUCHPAD_H #endif // ANDROID_DVR_VIRTUAL_TOUCHPAD_EVDEV_H
services/vr/virtual_touchpad/VirtualTouchpadService.cpp +4 −8 Original line number Original line Diff line number Diff line Loading @@ -8,19 +8,15 @@ namespace android { namespace android { namespace dvr { namespace dvr { int VirtualTouchpadService::Initialize() { return touchpad_.Initialize(); } binder::Status VirtualTouchpadService::touch(float x, float y, float pressure) { binder::Status VirtualTouchpadService::touch(float x, float y, float pressure) { const int error = touchpad_.Touch(x, y, pressure); const status_t error = touchpad_->Touch(x, y, pressure); return error ? binder::Status::fromServiceSpecificError(error) return error ? binder::Status::fromStatusT(error) : binder::Status::ok(); : binder::Status::ok(); } } binder::Status VirtualTouchpadService::buttonState(int buttons) { binder::Status VirtualTouchpadService::buttonState(int buttons) { const int error = touchpad_.ButtonState(buttons); const status_t error = touchpad_->ButtonState(buttons); return error ? binder::Status::fromServiceSpecificError(error) return error ? binder::Status::fromStatusT(error) : binder::Status::ok(); : binder::Status::ok(); } } Loading