代码同步

Signed-off-by: 秦际红 <qinjihong111@huawei.com>
This commit is contained in:
秦际红 2024-11-18 07:00:12 +00:00 committed by Gitee
parent 914e8575d2
commit 2b03acec9e
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
14 changed files with 46 additions and 64 deletions

View File

@ -53,6 +53,7 @@ ohos_shared_library("usbsrv_client") {
]
external_deps = [
"c_utils:utils",
"drivers_interface_usb:usb_idl_headers_1.1",
"hilog:libhilog",
"ipc:ipc_core",
"samgr:samgr_proxy",

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Copyright (c) 2024 Huawei Device Co., Ltd.
* 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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2024 Huawei Device Co., Ltd.
* 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
@ -128,7 +128,7 @@ struct UsbDeviceId {
int32_t vendorId;
};
const std::unordered_map<InterfaceType, std::vector<int32_t>> d_typeMap = {
const std::unordered_map<InterfaceType, std::vector<int32_t>> d_typeMap = {
{InterfaceType::TYPE_INTERFACE, {0, 0, 0}},
{InterfaceType::TYPE_COMMUNICATION, {2, -1, -1}},
{InterfaceType::TYPE_FULL_SPEED_HUB, {9, 0, 0}},
@ -156,7 +156,7 @@ const std::unordered_map<InterfaceType, std::vector<int32_t>> d_typeMap = {
{InterfaceType::TYPE_VENDOR_SPECIFIC, {255, -1, -1}}
};
const std::unordered_map<InterfaceType, std::vector<int32_t>> g_typeMap = {
const std::unordered_map<InterfaceType, std::vector<int32_t>> g_typeMap = {
{InterfaceType::TYPE_AUDIO, {1, -1, -1}},
{InterfaceType::TYPE_COMMUNICATION, {2, -1, -1}},
{InterfaceType::TYPE_HID, {3, -1, -1}},

View File

@ -22,7 +22,6 @@
#include <string>
#include <unistd.h>
#include <unordered_map>
#include "parameters.h"
#include "bundle_mgr_interface.h"
#include "bundle_mgr_proxy.h"
@ -1244,6 +1243,10 @@ int32_t UsbService::GetDeviceInfo(uint8_t busNum, uint8_t devAddr, UsbDevice &de
// LCOV_EXCL_START
int32_t UsbService::GetEdmGlobalPolicy(sptr<IRemoteObject> remote, bool &IsGlobalDisabled)
{
if (remote == nullptr) {
USB_HILOGE(MODULE_USB_SERVICE, "Remote is nullpter.");
return UEC_SERVICE_INVALID_VALUE;
}
MessageParcel data;
MessageParcel reply;
MessageOption option;
@ -1251,10 +1254,6 @@ int32_t UsbService::GetEdmGlobalPolicy(sptr<IRemoteObject> remote, bool &IsGloba
data.WriteInt32(WITHOUT_USERID);
data.WriteString("");
data.WriteInt32(WITHOUT_ADMIN);
if (remote == nullptr) {
USB_HILOGE(MODULE_USB_SERVICE, "Remote is nullpter.");
return UEC_SERVICE_INVALID_VALUE;
}
uint32_t funcCode = (1 << EMD_MASK_CODE) | DISABLE_USB;
int32_t ErrCode = remote->SendRequest(funcCode, data, reply, option);
int32_t ret = ERR_INVALID_VALUE;
@ -1273,6 +1272,10 @@ int32_t UsbService::GetEdmGlobalPolicy(sptr<IRemoteObject> remote, bool &IsGloba
// LCOV_EXCL_START
int32_t UsbService::GetEdmStroageTypePolicy(sptr<IRemoteObject> remote, std::vector<UsbDeviceType> &disableType)
{
if (remote == nullptr) {
USB_HILOGE(MODULE_USB_SERVICE, "Remote is nullpter.");
return UEC_SERVICE_INVALID_VALUE;
}
int32_t stroageDisableType = 0;
MessageParcel data;
MessageParcel reply;
@ -1281,10 +1284,6 @@ int32_t UsbService::GetEdmStroageTypePolicy(sptr<IRemoteObject> remote, std::vec
data.WriteInt32(WITHOUT_USERID);
data.WriteString("");
data.WriteInt32(WITHOUT_ADMIN);
if (remote == nullptr) {
USB_HILOGE(MODULE_USB_SERVICE, "Remote is nullpter.");
return UEC_SERVICE_INVALID_VALUE;
}
uint32_t funcCode = (1 << EMD_MASK_CODE) | USB_STORAGE_DEVICE_ACCESS_POLICY;
int32_t ErrCode = remote->SendRequest(funcCode, data, reply, option);
int32_t ret = ERR_INVALID_VALUE;
@ -1309,6 +1308,10 @@ int32_t UsbService::GetEdmStroageTypePolicy(sptr<IRemoteObject> remote, std::vec
// LCOV_EXCL_START
int32_t UsbService::GetEdmTypePolicy(sptr<IRemoteObject> remote, std::vector<UsbDeviceType> &disableType)
{
if (remote == nullptr) {
USB_HILOGE(MODULE_USB_SERVICE, "Remote is nullpter.");
return UEC_SERVICE_INVALID_VALUE;
}
MessageParcel data;
MessageParcel reply;
MessageOption option;
@ -1316,10 +1319,6 @@ int32_t UsbService::GetEdmTypePolicy(sptr<IRemoteObject> remote, std::vector<Usb
data.WriteInt32(WITHOUT_USERID);
data.WriteString("");
data.WriteInt32(WITHOUT_ADMIN);
if (remote == nullptr) {
USB_HILOGE(MODULE_USB_SERVICE, "Remote is nullpter.");
return UEC_SERVICE_INVALID_VALUE;
}
uint32_t funcCode = (1 << EMD_MASK_CODE) | USB_DEVICE_ACCESS_POLICY;
int32_t ErrCode = remote->SendRequest(funcCode, data, reply, option);
int32_t ret = ERR_INVALID_VALUE;
@ -1351,6 +1350,10 @@ int32_t UsbService::GetEdmTypePolicy(sptr<IRemoteObject> remote, std::vector<Usb
// LCOV_EXCL_START
int32_t UsbService::GetEdmWhiteListPolicy(sptr<IRemoteObject> remote, std::vector<UsbDeviceId> &trustUsbDeviceIds)
{
if (remote == nullptr) {
USB_HILOGE(MODULE_USB_SERVICE, "Remote is nullpter.");
return UEC_SERVICE_INVALID_VALUE;
}
MessageParcel data;
MessageParcel reply;
MessageOption option;
@ -1358,10 +1361,6 @@ int32_t UsbService::GetEdmWhiteListPolicy(sptr<IRemoteObject> remote, std::vecto
data.WriteInt32(WITHOUT_USERID);
data.WriteString("");
data.WriteInt32(WITHOUT_ADMIN);
if (remote == nullptr) {
USB_HILOGE(MODULE_USB_SERVICE, "Remote is nullpter.");
return UEC_SERVICE_INVALID_VALUE;
}
uint32_t funcCode = (1 << EMD_MASK_CODE) | ALLOWED_USB_DEVICES;
int32_t ErrCode = remote->SendRequest(funcCode, data, reply, option);
int32_t ret = ERR_INVALID_VALUE;
@ -1601,6 +1600,7 @@ void UsbService::ExecuteStrategy(UsbDevice *devInfo)
}
return;
}
ret = ExecuteManageInterfaceType(disableType, true);
if (trustUsbDeviceIds.empty()) {
USB_HILOGI(MODULE_USB_SERVICE, "trustUsbDeviceIds is empty, no devices disable");
@ -1953,7 +1953,6 @@ int32_t UsbService::AddRight(const std::string &bundleName, const std::string &d
USB_HILOGI(MODULE_USB_SERVICE, "AddRight done");
return UEC_OK;
}
// LCOV_EXCL_STOP
// LCOV_EXCL_START
@ -1990,6 +1989,11 @@ int UsbService::Dump(int fd, const std::vector<std::u16string> &args)
return UEC_SERVICE_INVALID_VALUE;
}
if (usbHostManager_ == nullptr || usbDeviceManager_ == nullptr) {
USB_HILOGE(MODULE_USB_SERVICE, "usbHostManager_ is nullptr or usbDeviceManager_ is nullptr");
return UEC_SERVICE_INVALID_VALUE;
}
std::vector<std::string> argList;
std::transform(args.begin(), args.end(), std::back_inserter(argList), [](const std::u16string &arg) {
return Str16ToStr8(arg);
@ -2000,10 +2004,6 @@ int UsbService::Dump(int fd, const std::vector<std::u16string> &args)
DumpHelp(fd);
return UEC_SERVICE_INVALID_VALUE;
}
if (usbHostManager_ == nullptr || usbDeviceManager_ == nullptr) {
USB_HILOGE(MODULE_USB_SERVICE, "usbHostManager_ is nullptr or usbDeviceManager_ is nullptr");
return UEC_SERVICE_INVALID_VALUE;
}
if (argList[0] == USB_HOST) {
usbHostManager_->Dump(fd, argList[1]);
} else if (argList[0] == USB_DEVICE) {
@ -2023,15 +2023,15 @@ int UsbService::Dump(int fd, const std::vector<std::u16string> &args)
// LCOV_EXCL_START
void UsbService::DumpHelp(int32_t fd)
{
if (usbDeviceManager_ == nullptr || usbPortManager_ == nullptr) {
USB_HILOGE(MODULE_USB_SERVICE, "usbDeviceManager_ is nullptr or usbPortManager_ is nullptr");
return;
}
dprintf(fd, "Refer to the following usage:\n");
dprintf(fd, "-h: dump help\n");
dprintf(fd, "============= dump the all device ==============\n");
dprintf(fd, "usb_host -a: dump the all device list info\n");
dprintf(fd, "------------------------------------------------\n");
if (usbDeviceManager_ == nullptr || usbPortManager_ == nullptr) {
USB_HILOGE(MODULE_USB_SERVICE, "usbDeviceManager_ is nullptr or usbPortManager_ is nullptr");
return;
}
usbDeviceManager_->GetDumpHelp(fd);
usbPortManager_->GetDumpHelp(fd);
}
@ -2228,7 +2228,7 @@ int32_t UsbService::ManageDeviceImpl(int32_t vendorId, int32_t productId, bool d
uint8_t configIndex = 0;
int32_t ret = usbd_->OpenDevice(dev);
if (ret != UEC_OK) {
USB_HILOGW(MODULE_USB_SERVICE, "ManageGlobalInterfaceImpl open fail ret = %{public}d", ret);
USB_HILOGW(MODULE_USB_SERVICE, "ManageDeviceImpl open fail ret = %{public}d", ret);
return ret;
}
if (usbd_->GetConfig(dev, configIndex)) {
@ -2259,15 +2259,14 @@ int32_t UsbService::ManageDeviceImpl(int32_t vendorId, int32_t productId, bool d
// LCOV_EXCL_START
int32_t UsbService::ManageInterfaceTypeImpl(InterfaceType interfaceType, bool disable)
{
if (CheckUecValue() != UEC_OK) {
return UEC_SERVICE_INVALID_VALUE;
}
auto iterInterface = g_typeMap.find(interfaceType);
if (iterInterface == g_typeMap.end()) {
USB_HILOGE(MODULE_USB_SERVICE, "UsbService::not find interface type");
return UEC_SERVICE_INVALID_VALUE;
}
if (CheckUecValue() != UEC_OK) {
return UEC_SERVICE_INVALID_VALUE;
}
std::map<std::string, UsbDevice *> devices;
usbHostManager_->GetDevices(devices);
for (auto it = devices.begin(); it != devices.end(); ++it) {
@ -2378,9 +2377,6 @@ int32_t UsbService::ClearHalt(uint8_t busNum, uint8_t devAddr, uint8_t interface
// LCOV_EXCL_START
int32_t UsbService::GetInterfaceActiveStatus(uint8_t busNum, uint8_t devAddr, uint8_t interfaceid, bool &unactivated)
{
if (!UsbService::CheckDevicePermission(busNum, devAddr)) {
return UEC_SERVICE_PERMISSION_DENIED;
}
if (PreCallFunction() != UEC_OK) {
USB_HILOGE(MODULE_USB_SERVICE, "PreCallFunction failed");
return UEC_SERVICE_PRE_MANAGE_INTERFACE_FAILED;
@ -2402,9 +2398,6 @@ int32_t UsbService::GetInterfaceActiveStatus(uint8_t busNum, uint8_t devAddr, ui
// LCOV_EXCL_START
int32_t UsbService::GetDeviceSpeed(uint8_t busNum, uint8_t devAddr, uint8_t &speed)
{
if (!UsbService::CheckDevicePermission(busNum, devAddr)) {
return UEC_SERVICE_PERMISSION_DENIED;
}
if (PreCallFunction() != UEC_OK) {
USB_HILOGE(MODULE_USB_SERVICE, "PreCallFunction failed");
return UEC_SERVICE_PRE_MANAGE_INTERFACE_FAILED;

View File

@ -32,10 +32,9 @@ using namespace OHOS::HDI::Usb::V1_0;
namespace OHOS {
namespace USB {
UsbServiceSubscriber::UsbServiceSubscriber() {}
extern sptr<UsbService> g_serviceInstance;
int32_t UsbServiceSubscriber::PortChangedEvent(const PortInfo &info)
{
auto pms = g_serviceInstance;
auto pms = UsbService::GetGlobalInstanc();
if (pms == nullptr) {
USB_HILOGE(MODULE_USB_SERVICE, "failed to GetInstance");
return UEC_SERVICE_GET_USB_SERVICE_FAILED;
@ -69,8 +68,7 @@ int32_t UsbServiceSubscriber::PortChangedEvent(const PortInfo &info)
int32_t UsbServiceSubscriber::DeviceEvent(const USBDeviceInfo &info)
{
int32_t status = info.status;
auto pms = g_serviceInstance;
USB_HILOGE(MODULE_USB_SERVICE, "DeviceEvent =========");
auto pms = UsbService::GetGlobalInstanc();
if (pms == nullptr) {
USB_HILOGE(MODULE_USB_SERVICE, "failed to GetInstance");
return UEC_SERVICE_GET_USB_SERVICE_FAILED;

View File

@ -1179,12 +1179,12 @@ int32_t UsbServerStub::DoManageInterfaceType(MessageParcel &data, MessageParcel
{
int32_t count;
READ_PARCEL_WITH_RET(data, Int32, count, UEC_SERVICE_READ_PARCEL_ERROR);
bool disable = false;
std::vector<UsbDeviceType> disableType;
if (count > MAX_EDM_LIST_SIZE) {
USB_HILOGE(MODULE_USBD, "count:%{public}d", count);
return UEC_SERVICE_READ_PARCEL_ERROR;
}
bool disable = false;
std::vector<UsbDeviceType> disableType;
for (int32_t i = 0; i < count; ++i) {
UsbDeviceType usbDeviceType;
READ_PARCEL_WITH_RET(data, Int32, usbDeviceType.baseClass, UEC_SERVICE_READ_PARCEL_ERROR);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2024 Huawei Device Co., Ltd.
* 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
@ -14,7 +14,6 @@
*/
#include "usbmgrmanagedevice_fuzzer.h"
#include "usb_srv_client.h"
#include "usb_errors.h"

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2024 Huawei Device Co., Ltd.
* 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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2024 Huawei Device Co., Ltd.
* 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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2024 Huawei Device Co., Ltd.
* 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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2024 Huawei Device Co., Ltd.
* 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
@ -34,8 +34,7 @@ namespace USB {
return false;
}
std::vector<UsbDeviceType> disableType;
ret = usbSrvClient.ManageInterfaceType(
disableType, true);
ret = usbSrvClient.ManageInterfaceType(disableType, true);
if (ret == UEC_OK) {
return false;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2024 Huawei Device Co., Ltd.
* 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

View File

@ -14,8 +14,6 @@
*/
#include <csignal>
#include <cstdint>
#include <cstdio>
#include <iostream>
#include <strings.h>
#include <vector>

View File

@ -19,12 +19,6 @@ config("usbsrv_private_config") {
}
ohos_executable("usb_function_test") {
sanitize = {
cfi = true
cfi_cross_dso = true
debug = false
}
branch_protector_ret = "pac_ret"
sources = [
"${usb_manager_path}/test/native/service_unittest/src/usb_common_test.cpp",
"usb_function_test.cpp",