1 #ifndef ANDROID_HARDWARE_USB_V1_1_USB_H
2 #define ANDROID_HARDWARE_USB_V1_1_USB_H
3 
4 #include <android/hardware/usb/1.2/IUsb.h>
5 #include <android/hardware/usb/1.2/IUsbCallback.h>
6 #include <android/hardware/usb/1.2/types.h>
7 #include <hidl/Status.h>
8 #include <utils/Log.h>
9 
10 #define UEVENT_MSG_LEN 2048
11 // The type-c stack waits for 4.5 - 5.5 secs before declaring a port non-pd.
12 // The -partner directory would not be created until this is done.
13 // Having a margin of ~3 secs for the directory and other related bookeeping
14 // structures created and uvent fired.
15 #define PORT_TYPE_TIMEOUT 8
16 
17 namespace android {
18 namespace hardware {
19 namespace usb {
20 namespace V1_2 {
21 namespace implementation {
22 
23 using ::android::sp;
24 using ::android::hardware::hidl_array;
25 using ::android::hardware::hidl_memory;
26 using ::android::hardware::hidl_string;
27 using ::android::hardware::hidl_vec;
28 using ::android::hardware::Return;
29 using ::android::hardware::Void;
30 using ::android::hardware::usb::V1_0::PortDataRole;
31 using ::android::hardware::usb::V1_0::PortPowerRole;
32 using ::android::hardware::usb::V1_0::PortRole;
33 using ::android::hardware::usb::V1_0::PortRoleType;
34 using ::android::hardware::usb::V1_0::Status;
35 using ::android::hardware::usb::V1_2::IUsb;
36 using ::android::hardware::usb::V1_2::IUsbCallback;
37 
38 using ::android::hardware::usb::V1_1::PortMode_1_1;
39 using ::android::hardware::usb::V1_1::PortStatus_1_1;
40 using ::android::hardware::usb::V1_2::PortStatus;
41 using ::android::hidl::base::V1_0::DebugInfo;
42 using ::android::hidl::base::V1_0::IBase;
43 
44 enum class HALVersion{
45     V1_0,
46     V1_1,
47     V1_2
48 };
49 
50 struct Usb : public IUsb {
51     Usb();
52 
53     Return<void> switchRole(const hidl_string &portName, const V1_0::PortRole &role) override;
54     Return<void> setCallback(const sp<V1_0::IUsbCallback> &callback) override;
55     Return<void> queryPortStatus() override;
56     Return<void> enableContaminantPresenceDetection(const hidl_string& portName, bool enable);
57     Return<void> enableContaminantPresenceProtection(const hidl_string& portName, bool enable);
58 
59     sp<V1_0::IUsbCallback> mCallback_1_0;
60     // Protects mCallback variable
61     pthread_mutex_t mLock;
62     // Protects roleSwitch operation
63     pthread_mutex_t mRoleSwitchLock;
64     // Threads waiting for the partner to come back wait here
65     pthread_cond_t mPartnerCV;
66     // lock protecting mPartnerCV
67     pthread_mutex_t mPartnerLock;
68     // Variable to signal partner coming back online after type switch
69     bool mPartnerUp;
70 
71   private:
72     pthread_t mPoll;
73 };
74 
75 }  // namespace implementation
76 }  // namespace V1_2
77 }  // namespace usb
78 }  // namespace hardware
79 }  // namespace android
80 
81 #endif  // ANDROID_HARDWARE_USB_V1_2_USB_H
82