blob: cf236f992362493bb595e54c4e4da60474513169 [file] [log] [blame]
Alex Vakulenkoe4eec202017-01-27 14:41:04 -08001#ifndef ANDROID_DVR_VIRTUAL_TOUCHPAD_SERVICE_H
2#define ANDROID_DVR_VIRTUAL_TOUCHPAD_SERVICE_H
3
4#include <android/dvr/BnVirtualTouchpadService.h>
5
6#include "VirtualTouchpad.h"
7
8namespace android {
9namespace dvr {
10
Kevin Schoedel43b5b062017-01-19 13:46:17 -050011// VirtualTouchpadService implements the service side of
12// the Binder interface defined in VirtualTouchpadService.aidl.
13//
Alex Vakulenkoe4eec202017-01-27 14:41:04 -080014class VirtualTouchpadService : public BnVirtualTouchpadService {
15 public:
Kevin Schoedelde1cdae2017-03-17 11:07:06 -040016 VirtualTouchpadService(std::unique_ptr<VirtualTouchpad> touchpad)
17 : touchpad_(std::move(touchpad)), client_pid_(0) {}
Kevin Schoedel4b64dd42017-03-07 13:06:25 -050018 ~VirtualTouchpadService() override;
Alex Vakulenkoe4eec202017-01-27 14:41:04 -080019
Alex Vakulenkoe4eec202017-01-27 14:41:04 -080020 protected:
21 // Implements IVirtualTouchpadService.
Kevin Schoedel4b64dd42017-03-07 13:06:25 -050022 binder::Status attach() override;
23 binder::Status detach() override;
Kevin Schoedel3002b8a2017-03-06 14:34:39 -050024 binder::Status touch(int touchpad, float x, float y, float pressure) override;
25 binder::Status buttonState(int touchpad, int buttons) override;
Alex Vakulenkoe4eec202017-01-27 14:41:04 -080026
Kevin Schoedel4b64dd42017-03-07 13:06:25 -050027 // Implements BBinder::dump().
28 status_t dump(int fd, const Vector<String16>& args) override;
29
Alex Vakulenkoe4eec202017-01-27 14:41:04 -080030 private:
Kevin Schoedel4b64dd42017-03-07 13:06:25 -050031 bool CheckPermissions();
32 bool CheckTouchPermission(pid_t* out_pid);
33
Kevin Schoedelde1cdae2017-03-17 11:07:06 -040034 std::unique_ptr<VirtualTouchpad> touchpad_;
Alex Vakulenkoe4eec202017-01-27 14:41:04 -080035
Kevin Schoedel4b64dd42017-03-07 13:06:25 -050036 // Only one client at a time can use the virtual touchpad.
37 pid_t client_pid_;
38
Alex Vakulenkoe4eec202017-01-27 14:41:04 -080039 VirtualTouchpadService(const VirtualTouchpadService&) = delete;
40 void operator=(const VirtualTouchpadService&) = delete;
41};
42
43} // namespace dvr
44} // namespace android
45
46#endif // ANDROID_DVR_VIRTUAL_TOUCHPAD_SERVICE_H