1#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
11// VirtualTouchpadService implements the service side of
12// the Binder interface defined in VirtualTouchpadService.aidl.
13//
14class VirtualTouchpadService : public BnVirtualTouchpadService {
15 public:
16  VirtualTouchpadService(std::unique_ptr<VirtualTouchpad> touchpad)
17      : touchpad_(std::move(touchpad)), client_pid_(0) {}
18  ~VirtualTouchpadService() override;
19
20 protected:
21  // Implements IVirtualTouchpadService.
22  binder::Status attach() override;
23  binder::Status detach() override;
24  binder::Status touch(int touchpad, float x, float y, float pressure) override;
25  binder::Status buttonState(int touchpad, int buttons) override;
26
27  // Implements BBinder::dump().
28  status_t dump(int fd, const Vector<String16>& args) override;
29
30 private:
31  bool CheckPermissions();
32  bool CheckTouchPermission(pid_t* out_pid);
33
34  std::unique_ptr<VirtualTouchpad> touchpad_;
35
36  // Only one client at a time can use the virtual touchpad.
37  pid_t client_pid_;
38
39  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
47