Skip to content

Commit b7e0aa4

Browse files
intervigiliumSubinsmani
authored andcommitted
pixys/interfaces: Add basic USB HAL that reports no status change
Change-Id: I38bfe869f9b1b66db0e13249f65e438878d06eff
1 parent 216a90d commit b7e0aa4

File tree

5 files changed

+229
-0
lines changed

5 files changed

+229
-0
lines changed

usb/1.0-basic/Android.bp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//
2+
// Copyright (C) 2017-2018 The LineageOS Project
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
cc_binary {
17+
18+
relative_install_path: "hw",
19+
init_rc: ["[email protected]"],
20+
srcs: ["service.cpp", "Usb.cpp"],
21+
shared_libs: [
22+
"libbase",
23+
"libcutils",
24+
"libhidlbase",
25+
"libhidltransport",
26+
"libhwbinder",
27+
"libutils",
28+
"libhardware",
29+
30+
],
31+
proprietary: true,
32+
}

usb/1.0-basic/Usb.cpp

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright (C) 2017-2018 The LineageOS Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#include <pthread.h>
17+
#include <stdio.h>
18+
#include <sys/types.h>
19+
#include <unistd.h>
20+
21+
#include <android-base/logging.h>
22+
#include <utils/Errors.h>
23+
#include <utils/StrongPointer.h>
24+
25+
#include "Usb.h"
26+
27+
namespace android {
28+
namespace hardware {
29+
namespace usb {
30+
namespace V1_0 {
31+
namespace implementation {
32+
33+
Return<void> Usb::switchRole(const hidl_string &portName __unused,
34+
const PortRole &newRole __unused) {
35+
LOG(ERROR) << __func__ << ": Not supported";
36+
return Void();
37+
}
38+
39+
Return<void> Usb::queryPortStatus() {
40+
hidl_vec<PortStatus> currentPortStatus;
41+
currentPortStatus.resize(1);
42+
43+
currentPortStatus[0].portName = "otg_default";
44+
currentPortStatus[0].currentDataRole = PortDataRole::DEVICE;
45+
currentPortStatus[0].currentPowerRole = PortPowerRole::SINK;
46+
currentPortStatus[0].currentMode = PortMode::UFP;
47+
currentPortStatus[0].canChangeMode = false;
48+
currentPortStatus[0].canChangeDataRole = false;
49+
currentPortStatus[0].canChangePowerRole = false;
50+
currentPortStatus[0].supportedModes = PortMode::UFP;
51+
52+
pthread_mutex_lock(&mLock);
53+
if (mCallback != NULL) {
54+
Return<void> ret =
55+
mCallback->notifyPortStatusChange(currentPortStatus, Status::SUCCESS);
56+
if (!ret.isOk()) {
57+
LOG(ERROR) << "queryPortStatus error " << ret.description();
58+
}
59+
} else {
60+
LOG(INFO) << "Notifying userspace skipped. Callback is NULL";
61+
}
62+
pthread_mutex_unlock(&mLock);
63+
64+
return Void();
65+
}
66+
67+
Return<void> Usb::setCallback(const sp<IUsbCallback> &callback) {
68+
pthread_mutex_lock(&mLock);
69+
70+
mCallback = callback;
71+
LOG(INFO) << "registering callback";
72+
73+
pthread_mutex_unlock(&mLock);
74+
return Void();
75+
}
76+
77+
} // namespace implementation
78+
} // namespace V1_0
79+
} // namespace usb
80+
} // namespace hardware
81+
} // namespace android

usb/1.0-basic/Usb.h

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (C) 2017-2018 The LineageOS Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef ANDROID_HARDWARE_USB_V1_0_USB_H
18+
#define ANDROID_HARDWARE_USB_V1_0_USB_H
19+
20+
#include <android/hardware/usb/1.0/IUsb.h>
21+
#include <hidl/MQDescriptor.h>
22+
#include <hidl/Status.h>
23+
#include <utils/Log.h>
24+
25+
#ifdef LOG_TAG
26+
#undef LOG_TAG
27+
#endif
28+
29+
#define LOG_TAG "[email protected]"
30+
#define UEVENT_MSG_LEN 2048
31+
32+
namespace android {
33+
namespace hardware {
34+
namespace usb {
35+
namespace V1_0 {
36+
namespace implementation {
37+
38+
using ::android::hardware::usb::V1_0::IUsb;
39+
using ::android::hardware::usb::V1_0::IUsbCallback;
40+
using ::android::hardware::usb::V1_0::PortRole;
41+
using ::android::hidl::base::V1_0::IBase;
42+
using ::android::hardware::hidl_array;
43+
using ::android::hardware::hidl_memory;
44+
using ::android::hardware::hidl_string;
45+
using ::android::hardware::hidl_vec;
46+
using ::android::hardware::Return;
47+
using ::android::hardware::Void;
48+
using ::android::sp;
49+
50+
struct Usb : public IUsb {
51+
Return<void> switchRole(const hidl_string& portName, const PortRole& role) override;
52+
Return<void> setCallback(const sp<IUsbCallback>& callback) override;
53+
Return<void> queryPortStatus() override;
54+
55+
sp<IUsbCallback> mCallback;
56+
pthread_mutex_t mLock = PTHREAD_MUTEX_INITIALIZER;
57+
};
58+
59+
} // namespace implementation
60+
} // namespace V1_0
61+
} // namespace usb
62+
} // namespace hardware
63+
} // namespace android
64+
65+
#endif // ANDROID_HARDWARE_USB_V1_0_USB_H

usb/1.0-basic/[email protected]

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
service usb-hal-1-0 /vendor/bin/hw/[email protected]
2+
class hal
3+
user system
4+
group system

usb/1.0-basic/service.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (C) 2017-2018 The LineageOS Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include <android-base/logging.h>
18+
#include <hidl/HidlTransportSupport.h>
19+
#include "Usb.h"
20+
21+
using android::sp;
22+
23+
// libhwbinder:
24+
using android::hardware::configureRpcThreadpool;
25+
using android::hardware::joinRpcThreadpool;
26+
27+
// Generated HIDL files
28+
using android::hardware::usb::V1_0::IUsb;
29+
using android::hardware::usb::V1_0::implementation::Usb;
30+
31+
int main() {
32+
android::sp<IUsb> service = new Usb();
33+
34+
configureRpcThreadpool(1, true /*callerWillJoin*/);
35+
android::status_t status = service->registerAsService();
36+
37+
if (status != android::OK) {
38+
LOG(ERROR) << "Cannot register USB HAL service";
39+
return 1;
40+
}
41+
42+
LOG(INFO) << "USB HAL Ready.";
43+
joinRpcThreadpool();
44+
// Under normal cases, execution will not reach this line.
45+
LOG(ERROR) << "USB HAL failed to join thread pool.";
46+
return 1;
47+
}

0 commit comments

Comments
 (0)