mirror of
https://github.com/chararomandroid/android_device_samsung_a20
synced 2026-08-23 04:25:33 -04:00
universal7885: Major (de)commonize due to prev commit
This commit is contained in:
parent
e88568c670
commit
07b209df81
31 changed files with 606 additions and 66 deletions
31
universal7885-common/usb/typeb/Android.bp
Normal file
31
universal7885-common/usb/typeb/Android.bp
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
//
|
||||
// Copyright (C) 2017 The LineageOS Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
cc_binary {
|
||||
name: "android.hardware.usb@1.0-service.a10",
|
||||
relative_install_path: "hw",
|
||||
init_rc: ["android.hardware.usb@1.0-service.a10.rc"],
|
||||
srcs: ["service.cpp", "Usb.cpp"],
|
||||
shared_libs: [
|
||||
"libcutils",
|
||||
"libhidlbase",
|
||||
"libhidltransport",
|
||||
"liblog",
|
||||
"libhwbinder",
|
||||
"libutils",
|
||||
"libhardware",
|
||||
"android.hardware.usb@1.0",
|
||||
],
|
||||
proprietary: true,
|
||||
}
|
||||
82
universal7885-common/usb/typeb/Usb.cpp
Normal file
82
universal7885-common/usb/typeb/Usb.cpp
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* Copyright (C) 2017 The LineageOS Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <utils/Errors.h>
|
||||
#include <utils/StrongPointer.h>
|
||||
|
||||
#include "Usb.h"
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace usb {
|
||||
namespace V1_0 {
|
||||
namespace implementation {
|
||||
|
||||
Return<void> Usb::switchRole(const hidl_string &portName,
|
||||
const PortRole &newRole) {
|
||||
(void)portName;
|
||||
(void)newRole;
|
||||
ALOGE("%s: Not supported", __func__);
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<void> Usb::queryPortStatus() {
|
||||
hidl_vec<PortStatus> currentPortStatus;
|
||||
currentPortStatus.resize(1);
|
||||
|
||||
/* this device is not type C and can only be a sink */
|
||||
currentPortStatus[0].portName = "otg_default";
|
||||
currentPortStatus[0].currentDataRole = PortDataRole::DEVICE;
|
||||
currentPortStatus[0].currentPowerRole = PortPowerRole::SINK;
|
||||
currentPortStatus[0].currentMode = PortMode::UFP;
|
||||
currentPortStatus[0].canChangeMode = false;
|
||||
currentPortStatus[0].canChangeDataRole = false;
|
||||
currentPortStatus[0].canChangePowerRole = false;
|
||||
currentPortStatus[0].supportedModes = PortMode::UFP;
|
||||
|
||||
pthread_mutex_lock(&mLock);
|
||||
if (mCallback != NULL) {
|
||||
Return<void> ret =
|
||||
mCallback->notifyPortStatusChange(currentPortStatus, Status::SUCCESS);
|
||||
if (!ret.isOk())
|
||||
ALOGE("queryPortStatus error %s", ret.description().c_str());
|
||||
} else {
|
||||
ALOGI("Notifying userspace skipped. Callback is NULL");
|
||||
}
|
||||
pthread_mutex_unlock(&mLock);
|
||||
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<void> Usb::setCallback(const sp<IUsbCallback> &callback) {
|
||||
pthread_mutex_lock(&mLock);
|
||||
|
||||
mCallback = callback;
|
||||
ALOGI("registering callback");
|
||||
|
||||
pthread_mutex_unlock(&mLock);
|
||||
return Void();
|
||||
}
|
||||
|
||||
} // namespace implementation
|
||||
} // namespace V1_0
|
||||
} // namespace usb
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
52
universal7885-common/usb/typeb/Usb.h
Normal file
52
universal7885-common/usb/typeb/Usb.h
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
#ifndef ANDROID_HARDWARE_USB_V1_0_USB_H
|
||||
#define ANDROID_HARDWARE_USB_V1_0_USB_H
|
||||
|
||||
#include <android/hardware/usb/1.0/IUsb.h>
|
||||
#include <hidl/MQDescriptor.h>
|
||||
#include <hidl/Status.h>
|
||||
#include <utils/Log.h>
|
||||
|
||||
#ifdef LOG_TAG
|
||||
#undef LOG_TAG
|
||||
#endif
|
||||
|
||||
#define LOG_TAG "android.hardware.usb@1.0-service.a10"
|
||||
#define UEVENT_MSG_LEN 2048
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace usb {
|
||||
namespace V1_0 {
|
||||
namespace implementation {
|
||||
|
||||
using ::android::hardware::usb::V1_0::IUsb;
|
||||
using ::android::hardware::usb::V1_0::IUsbCallback;
|
||||
using ::android::hardware::usb::V1_0::PortRole;
|
||||
using ::android::hidl::base::V1_0::IBase;
|
||||
using ::android::hardware::hidl_array;
|
||||
using ::android::hardware::hidl_memory;
|
||||
using ::android::hardware::hidl_string;
|
||||
using ::android::hardware::hidl_vec;
|
||||
using ::android::hardware::Return;
|
||||
using ::android::hardware::Void;
|
||||
using ::android::sp;
|
||||
|
||||
struct Usb : public IUsb {
|
||||
Return<void> switchRole(const hidl_string& portName, const PortRole& role) override;
|
||||
Return<void> setCallback(const sp<IUsbCallback>& callback) override;
|
||||
Return<void> queryPortStatus() override;
|
||||
|
||||
sp<IUsbCallback> mCallback;
|
||||
pthread_mutex_t mLock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
private:
|
||||
pthread_t mPoll;
|
||||
};
|
||||
|
||||
} // namespace implementation
|
||||
} // namespace V1_0
|
||||
} // namespace usb
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
|
||||
#endif // ANDROID_HARDWARE_USB_V1_0_USB_H
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
service usb-hal-1-0 /vendor/bin/hw/android.hardware.usb@1.0-service.a10
|
||||
class hal
|
||||
user system
|
||||
group system
|
||||
49
universal7885-common/usb/typeb/service.cpp
Normal file
49
universal7885-common/usb/typeb/service.cpp
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (C) 2017 The LineageOS jProject
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <hidl/HidlTransportSupport.h>
|
||||
#include "Usb.h"
|
||||
|
||||
using android::sp;
|
||||
|
||||
// libhwbinder:
|
||||
using android::hardware::configureRpcThreadpool;
|
||||
using android::hardware::joinRpcThreadpool;
|
||||
|
||||
// Generated HIDL files
|
||||
using android::hardware::usb::V1_0::IUsb;
|
||||
using android::hardware::usb::V1_0::implementation::Usb;
|
||||
|
||||
using android::status_t;
|
||||
using android::OK;
|
||||
|
||||
int main() {
|
||||
android::sp<IUsb> service = new Usb();
|
||||
|
||||
configureRpcThreadpool(1, true /*callerWillJoin*/);
|
||||
status_t status = service->registerAsService();
|
||||
|
||||
if (status != OK) {
|
||||
ALOGE("Cannot register USB HAL service");
|
||||
return 1;
|
||||
}
|
||||
|
||||
ALOGI("USB HAL Ready.");
|
||||
joinRpcThreadpool();
|
||||
// Under noraml cases, execution will not reach this line.
|
||||
ALOGI("USB HAL failed to join thread pool.");
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -13,10 +13,10 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
cc_binary {
|
||||
name: "android.hardware.usb@1.1-service.typec",
|
||||
name: "android.hardware.usb@1.1-service.exynos7885",
|
||||
relative_install_path: "hw",
|
||||
init_rc: ["android.hardware.usb@1.1-service.typec.rc"],
|
||||
vintf_fragments: ["android.hardware.usb@1.1-service.typec.xml"],
|
||||
init_rc: ["android.hardware.usb@1.1-service.exynos7885.rc"],
|
||||
vintf_fragments: ["android.hardware.usb@1.1-service.exynos7885.xml"],
|
||||
srcs: ["service.cpp", "Usb.cpp"],
|
||||
cflags: [
|
||||
"-Wall",
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
service vendor.usb-hal-1-1 /vendor/bin/hw/android.hardware.usb@1.1-service.typec
|
||||
service vendor.usb-hal-1-1 /vendor/bin/hw/android.hardware.usb@1.1-service.exynos7885
|
||||
interface android.hardware.usb@1.1::IUsb default
|
||||
interface android.hardware.usb@1.0::IUsb default
|
||||
class hal
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#define LOG_TAG "android.hardware.usb@1.1-service.typec"
|
||||
#define LOG_TAG "android.hardware.usb@1.1-service.exynos7885"
|
||||
|
||||
#include <hidl/HidlTransportSupport.h>
|
||||
#include "Usb.h"
|
||||
Loading…
Reference in a new issue