Update USB HAL to V1.3 implementation
Supports to enable/disable USB data signaling Bug: 161414036 Test: Pass USB V1.3 HIDL tests Signed-off-by: Albert Wang <albertccwang@google.com> Change-Id: I85cf5282e487c1695a4cedad00b7fede2c3ad1f8
This commit is contained in:
parent
a36726f4fd
commit
846d053446
|
@ -48,3 +48,11 @@
|
|||
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/vendor/etc/init/android.hardware.vibrator@1.3-service.redfin.rc)
|
||||
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/vendor/bin/hw/android.hardware.vibrator@1.3-service.redfin)
|
||||
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/vendor/etc/vintf/manifest/android.hardware.vibrator@1.3-service.redfin.xml)
|
||||
|
||||
# Update to USB HAL 1.3
|
||||
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/vendor/bin/hw/android.hardware.usb@1.2-service.redfin)
|
||||
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/vendor/etc/init/android.hardware.usb@1.2-service.redfin.rc)
|
||||
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/vendor/etc/vintf/manifest/android.hardware.usb@1.2-service.redfin.xml)
|
||||
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/vendor/bin/hw/android.hardware.usb@1.3-service.redfin)
|
||||
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/vendor/etc/init/android.hardware.usb@1.3-service.redfin.rc)
|
||||
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/vendor/etc/vintf/manifest/android.hardware.usb@1.3-service.redfin.xml)
|
||||
|
|
|
@ -132,7 +132,7 @@ ifeq ($(wildcard vendor/google_devices/redfin/proprietary/device-vendor-redfin.m
|
|||
endif
|
||||
|
||||
PRODUCT_PACKAGES += \
|
||||
android.hardware.usb@1.2-service.redfin
|
||||
android.hardware.usb@1.3-service.redfin
|
||||
|
||||
# Vibrator HAL
|
||||
PRODUCT_PACKAGES += \
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (C) 2020 The Android Open Source Project
|
||||
// Copyright (C) 2021 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
|
@ -18,11 +18,11 @@ package {
|
|||
}
|
||||
|
||||
cc_binary {
|
||||
name: "android.hardware.usb@1.2-service.redfin",
|
||||
name: "android.hardware.usb@1.3-service.redfin",
|
||||
relative_install_path: "hw",
|
||||
init_rc: ["android.hardware.usb@1.2-service.redfin.rc"],
|
||||
init_rc: ["android.hardware.usb@1.3-service.redfin.rc"],
|
||||
vintf_fragments: [
|
||||
"android.hardware.usb@1.2-service.redfin.xml",
|
||||
"android.hardware.usb@1.3-service.redfin.xml",
|
||||
"android.hardware.usb.gadget@1.2-service.redfin.xml",
|
||||
],
|
||||
srcs: ["service.cpp", "Usb.cpp", "UsbGadget.cpp"],
|
||||
|
@ -30,6 +30,7 @@ cc_binary {
|
|||
"android.hardware.usb@1.0",
|
||||
"android.hardware.usb@1.1",
|
||||
"android.hardware.usb@1.2",
|
||||
"android.hardware.usb@1.3",
|
||||
"android.hardware.usb.gadget@1.0",
|
||||
"android.hardware.usb.gadget@1.1",
|
||||
"android.hardware.usb.gadget@1.2",
|
||||
|
|
70
usb/Usb.cpp
70
usb/Usb.cpp
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#define LOG_TAG "android.hardware.usb@1.2-service.redfin"
|
||||
#define LOG_TAG "android.hardware.usb@1.3-service.redfin"
|
||||
|
||||
#include <android-base/logging.h>
|
||||
#include <android-base/properties.h>
|
||||
|
@ -41,9 +41,49 @@ using android::base::GetProperty;
|
|||
namespace android {
|
||||
namespace hardware {
|
||||
namespace usb {
|
||||
namespace V1_2 {
|
||||
namespace V1_3 {
|
||||
namespace implementation {
|
||||
|
||||
Return<bool> Usb::enableUsbDataSignal(bool enable) {
|
||||
bool result = true;
|
||||
|
||||
ALOGI("Userspace turn %s USB data signaling", enable ? "on" : "off");
|
||||
|
||||
if (enable) {
|
||||
if (!WriteStringToFile("1", USB_DATA_PATH)) {
|
||||
ALOGE("Not able to turn on usb connection notification");
|
||||
result = false;
|
||||
}
|
||||
|
||||
if (!WriteStringToFile(kGadgetName, PULLUP_PATH)) {
|
||||
ALOGE("Gadget cannot be pulled up");
|
||||
result = false;
|
||||
}
|
||||
} else {
|
||||
if (!WriteStringToFile("1", ID_PATH)) {
|
||||
ALOGE("Not able to turn off host mode");
|
||||
result = false;
|
||||
}
|
||||
|
||||
if (!WriteStringToFile("0", VBUS_PATH)) {
|
||||
ALOGE("Not able to set Vbus state");
|
||||
result = false;
|
||||
}
|
||||
|
||||
if (!WriteStringToFile("0", USB_DATA_PATH)) {
|
||||
ALOGE("Not able to turn on usb connection notification");
|
||||
result = false;
|
||||
}
|
||||
|
||||
if (!WriteStringToFile("none", PULLUP_PATH)) {
|
||||
ALOGE("Gadget cannot be pulled down");
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Set by the signal handler to destroy the thread
|
||||
volatile bool destroyThread;
|
||||
|
||||
|
@ -52,8 +92,7 @@ constexpr char kDetectedPath[] = "/sys/class/power_supply/usb/moisture_detected"
|
|||
constexpr char kConsole[] = "init.svc.console";
|
||||
constexpr char kDisableContatminantDetection[] = "vendor.usb.contaminantdisable";
|
||||
|
||||
void queryVersionHelper(android::hardware::usb::V1_2::implementation::Usb *usb,
|
||||
hidl_vec<PortStatus> *currentPortStatus_1_2);
|
||||
void queryVersionHelper(implementation::Usb *usb, hidl_vec<PortStatus> *currentPortStatus_1_2);
|
||||
|
||||
int32_t readFile(const std::string &filename, std::string *contents) {
|
||||
FILE *fp;
|
||||
|
@ -104,9 +143,9 @@ Status queryMoistureDetectionStatus(hidl_vec<PortStatus> *currentPortStatus_1_2)
|
|||
|
||||
(*currentPortStatus_1_2)[0].supportedContaminantProtectionModes = 0;
|
||||
(*currentPortStatus_1_2)[0].supportedContaminantProtectionModes |=
|
||||
ContaminantProtectionMode::FORCE_SINK;
|
||||
(*currentPortStatus_1_2)[0].contaminantProtectionStatus = ContaminantProtectionStatus::NONE;
|
||||
(*currentPortStatus_1_2)[0].contaminantDetectionStatus = ContaminantDetectionStatus::DISABLED;
|
||||
V1_2::ContaminantProtectionMode::FORCE_SINK;
|
||||
(*currentPortStatus_1_2)[0].contaminantProtectionStatus = V1_2::ContaminantProtectionStatus::NONE;
|
||||
(*currentPortStatus_1_2)[0].contaminantDetectionStatus = V1_2::ContaminantDetectionStatus::DISABLED;
|
||||
(*currentPortStatus_1_2)[0].supportsEnableContaminantPresenceDetection = true;
|
||||
(*currentPortStatus_1_2)[0].supportsEnableContaminantPresenceProtection = false;
|
||||
|
||||
|
@ -122,12 +161,12 @@ Status queryMoistureDetectionStatus(hidl_vec<PortStatus> *currentPortStatus_1_2)
|
|||
}
|
||||
if (status == "1") {
|
||||
(*currentPortStatus_1_2)[0].contaminantDetectionStatus =
|
||||
ContaminantDetectionStatus::DETECTED;
|
||||
V1_2::ContaminantDetectionStatus::DETECTED;
|
||||
(*currentPortStatus_1_2)[0].contaminantProtectionStatus =
|
||||
ContaminantProtectionStatus::FORCE_SINK;
|
||||
V1_2::ContaminantProtectionStatus::FORCE_SINK;
|
||||
} else
|
||||
(*currentPortStatus_1_2)[0].contaminantDetectionStatus =
|
||||
ContaminantDetectionStatus::NOT_DETECTED;
|
||||
V1_2::ContaminantDetectionStatus::NOT_DETECTED;
|
||||
}
|
||||
|
||||
ALOGI("ContaminantDetectionStatus:%d ContaminantProtectionStatus:%d",
|
||||
|
@ -556,8 +595,7 @@ done:
|
|||
return Status::ERROR;
|
||||
}
|
||||
|
||||
void queryVersionHelper(android::hardware::usb::V1_2::implementation::Usb *usb,
|
||||
hidl_vec<PortStatus> *currentPortStatus_1_2) {
|
||||
void queryVersionHelper(implementation::Usb *usb, hidl_vec<PortStatus> *currentPortStatus_1_2) {
|
||||
hidl_vec<V1_1::PortStatus_1_1> currentPortStatus_1_1;
|
||||
hidl_vec<V1_0::PortStatus> currentPortStatus;
|
||||
Status status;
|
||||
|
@ -608,7 +646,7 @@ Return<void> Usb::queryPortStatus() {
|
|||
|
||||
struct data {
|
||||
int uevent_fd;
|
||||
android::hardware::usb::V1_2::implementation::Usb *usb;
|
||||
android::hardware::usb::V1_3::implementation::Usb *usb;
|
||||
};
|
||||
|
||||
static void uevent_event(uint32_t /*epevents*/, struct data *payload) {
|
||||
|
@ -681,7 +719,7 @@ void *work(void *param) {
|
|||
}
|
||||
|
||||
payload.uevent_fd = uevent_fd;
|
||||
payload.usb = (android::hardware::usb::V1_2::implementation::Usb *)param;
|
||||
payload.usb = (android::hardware::usb::V1_3::implementation::Usb *)param;
|
||||
|
||||
fcntl(uevent_fd, F_SETFL, O_NONBLOCK);
|
||||
|
||||
|
@ -796,7 +834,7 @@ Return<void> Usb::setCallback(const sp<V1_0::IUsbCallback> &callback) {
|
|||
}
|
||||
|
||||
} // namespace implementation
|
||||
} // namespace V1_2
|
||||
} // namespace V1_3
|
||||
} // namespace usb
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
|
|
44
usb/Usb.h
44
usb/Usb.h
|
@ -1,10 +1,26 @@
|
|||
#ifndef ANDROID_HARDWARE_USB_V1_1_USB_H
|
||||
#define ANDROID_HARDWARE_USB_V1_1_USB_H
|
||||
/*
|
||||
* Copyright (C) 2021 The Android Open Source 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.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <android/hardware/usb/1.2/IUsb.h>
|
||||
#include <android-base/file.h>
|
||||
#include <android/hardware/usb/1.2/IUsbCallback.h>
|
||||
#include <android/hardware/usb/1.2/types.h>
|
||||
#include <android/hardware/usb/1.3/IUsb.h>
|
||||
#include <hidl/Status.h>
|
||||
#include <pixelusb/UsbGadgetCommon.h>
|
||||
#include <utils/Log.h>
|
||||
|
||||
#define UEVENT_MSG_LEN 2048
|
||||
|
@ -17,10 +33,11 @@
|
|||
namespace android {
|
||||
namespace hardware {
|
||||
namespace usb {
|
||||
namespace V1_2 {
|
||||
namespace V1_3 {
|
||||
namespace implementation {
|
||||
|
||||
using ::android::sp;
|
||||
using ::android::base::WriteStringToFile;
|
||||
using ::android::hardware::hidl_array;
|
||||
using ::android::hardware::hidl_memory;
|
||||
using ::android::hardware::hidl_string;
|
||||
|
@ -32,21 +49,27 @@ using ::android::hardware::usb::V1_0::PortPowerRole;
|
|||
using ::android::hardware::usb::V1_0::PortRole;
|
||||
using ::android::hardware::usb::V1_0::PortRoleType;
|
||||
using ::android::hardware::usb::V1_0::Status;
|
||||
using ::android::hardware::usb::V1_2::IUsb;
|
||||
using ::android::hardware::usb::V1_2::IUsbCallback;
|
||||
|
||||
using ::android::hardware::usb::V1_1::PortMode_1_1;
|
||||
using ::android::hardware::usb::V1_1::PortStatus_1_1;
|
||||
using ::android::hardware::usb::V1_2::PortStatus;
|
||||
using ::android::hardware::usb::V1_2::IUsbCallback;
|
||||
using ::android::hardware::usb::V1_3::IUsb;
|
||||
using ::android::hidl::base::V1_0::DebugInfo;
|
||||
using ::android::hidl::base::V1_0::IBase;
|
||||
|
||||
enum class HALVersion{
|
||||
V1_0,
|
||||
V1_1,
|
||||
V1_2
|
||||
V1_2,
|
||||
V1_3
|
||||
};
|
||||
|
||||
constexpr char kGadgetName[] = "a600000.dwc3";
|
||||
#define SOC_PATH "/sys/devices/platform/soc/a600000.ssusb/"
|
||||
#define ID_PATH SOC_PATH "id"
|
||||
#define VBUS_PATH SOC_PATH "b_sess"
|
||||
#define USB_DATA_PATH SOC_PATH "usb_data_enabled"
|
||||
|
||||
struct Usb : public IUsb {
|
||||
Usb();
|
||||
|
||||
|
@ -55,6 +78,7 @@ struct Usb : public IUsb {
|
|||
Return<void> queryPortStatus() override;
|
||||
Return<void> enableContaminantPresenceDetection(const hidl_string& portName, bool enable);
|
||||
Return<void> enableContaminantPresenceProtection(const hidl_string& portName, bool enable);
|
||||
Return<bool> enableUsbDataSignal(bool enable) override;
|
||||
|
||||
sp<V1_0::IUsbCallback> mCallback_1_0;
|
||||
// Protects mCallback variable
|
||||
|
@ -73,9 +97,7 @@ struct Usb : public IUsb {
|
|||
};
|
||||
|
||||
} // namespace implementation
|
||||
} // namespace V1_2
|
||||
} // namespace V1_3
|
||||
} // namespace usb
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
|
||||
#endif // ANDROID_HARDWARE_USB_V1_2_USB_H
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
service vendor.usb-hal-1-2 /vendor/bin/hw/android.hardware.usb@1.2-service.redfin
|
||||
class hal
|
||||
user system
|
||||
group system shell mtp
|
||||
|
||||
service init-gadgethal-sh /vendor/bin/init.gadgethal.sh
|
||||
class hal
|
||||
user root
|
||||
disabled
|
||||
oneshot
|
||||
|
||||
on boot
|
||||
chown root system /sys/class/typec/port0/power_role
|
||||
chown root system /sys/class/typec/port0/data_role
|
||||
chown root system /sys/class/typec/port0/port_type
|
||||
chmod 664 /sys/class/typec/port0/power_role
|
||||
chmod 664 /sys/class/typec/port0/data_role
|
||||
chmod 664 /sys/class/typec/port0/port_type
|
|
@ -0,0 +1,26 @@
|
|||
service vendor.usb-hal-1-3 /vendor/bin/hw/android.hardware.usb@1.3-service.redfin
|
||||
class hal
|
||||
user system
|
||||
group system shell mtp
|
||||
|
||||
service init-gadgethal-sh /vendor/bin/init.gadgethal.sh
|
||||
class hal
|
||||
user root
|
||||
disabled
|
||||
oneshot
|
||||
|
||||
on boot
|
||||
chown root system /sys/class/typec/port0/power_role
|
||||
chown root system /sys/class/typec/port0/data_role
|
||||
chown root system /sys/class/typec/port0/port_type
|
||||
chmod 664 /sys/class/typec/port0/power_role
|
||||
chmod 664 /sys/class/typec/port0/data_role
|
||||
chmod 664 /sys/class/typec/port0/port_type
|
||||
|
||||
on post-fs
|
||||
chown root system /sys/devices/platform/soc/a600000.ssusb/id
|
||||
chown root system /sys/devices/platform/soc/a600000.ssusb/b_sess
|
||||
chown root system /sys/devices/platform/soc/a600000.ssusb/usb_data_enabled
|
||||
chmod 664 /sys/devices/platform/soc/a600000.ssusb/id
|
||||
chmod 664 /sys/devices/platform/soc/a600000.ssusb/b_sess
|
||||
chmod 664 /sys/devices/platform/soc/a600000.ssusb/usb_data_enabled
|
|
@ -2,7 +2,7 @@
|
|||
<hal format="hidl">
|
||||
<name>android.hardware.usb</name>
|
||||
<transport>hwbinder</transport>
|
||||
<version>1.2</version>
|
||||
<version>1.3</version>
|
||||
<interface>
|
||||
<name>IUsb</name>
|
||||
<instance>default</instance>
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#define LOG_TAG "android.hardware.usb@1.2-service.redfin"
|
||||
#define LOG_TAG "android.hardware.usb@1.3-service.redfin"
|
||||
|
||||
#include <hidl/HidlTransportSupport.h>
|
||||
#include "Usb.h"
|
||||
|
@ -29,8 +29,8 @@ using android::hardware::joinRpcThreadpool;
|
|||
// Generated HIDL files
|
||||
using android::hardware::usb::gadget::V1_2::IUsbGadget;
|
||||
using android::hardware::usb::gadget::V1_2::implementation::UsbGadget;
|
||||
using android::hardware::usb::V1_2::IUsb;
|
||||
using android::hardware::usb::V1_2::implementation::Usb;
|
||||
using android::hardware::usb::V1_3::IUsb;
|
||||
using android::hardware::usb::V1_3::implementation::Usb;
|
||||
|
||||
using android::OK;
|
||||
using android::status_t;
|
||||
|
|
Loading…
Reference in New Issue