mirror of
https://gitee.com/openharmony/usb_usb_manager
synced 2024-11-27 08:51:03 +00:00
commit
2ff6c79dac
@ -71,7 +71,8 @@ public:
|
||||
virtual int32_t AddAccessRight(const std::string &tokenId, const std::string &deviceName) = 0;
|
||||
virtual int32_t ManageGlobalInterface(bool disable) = 0;
|
||||
virtual int32_t ManageDevice(int32_t vendorId, int32_t productId, bool disable) = 0;
|
||||
virtual int32_t ManageInterfaceType(InterfaceType interfaceType, bool disable) = 0;
|
||||
virtual int32_t ManageInterfaceStorage(InterfaceType interfaceType, bool disable) = 0;
|
||||
virtual int32_t ManageInterfaceType(const std::vector<UsbDeviceType> &disableType, bool disable) = 0;
|
||||
virtual int32_t GetDeviceSpeed(uint8_t busNum, uint8_t devAddr, uint8_t &speed) = 0;
|
||||
virtual int32_t GetInterfaceActiveStatus(uint8_t busNum, uint8_t devAddr, uint8_t interfaceid,
|
||||
bool &unactivated) = 0;
|
||||
|
@ -25,6 +25,78 @@ enum InterfaceType {
|
||||
TYPE_PHYSICAL,
|
||||
TYPE_IMAGE,
|
||||
TYPE_PRINTER,
|
||||
TYPE_COMMUNICATION,
|
||||
TYPE_FULL_SPEED_HUB,
|
||||
TYPE_FULL_SPEED_HUB_S,
|
||||
TYPE_FULL_SPEED_HUB_M,
|
||||
TYPE_CDC_DATA,
|
||||
TYPE_SMART_CARD,
|
||||
TYPE_CONTENT_SECURTIY,
|
||||
TYPE_VIDEO,
|
||||
TYPE_PERSONAL_HEALTHCARE,
|
||||
TYPE_AVCONTROL,
|
||||
TYPE_AVV_STREAMING,
|
||||
TYPE_AVA_STREAMING,
|
||||
TYPE_BILLBOARD,
|
||||
TYPE_TYPEC_BRIDGE,
|
||||
TYPE_BDP,
|
||||
TYPE_MCTP_MANA_1,
|
||||
TYPE_MCTP_MANA_2,
|
||||
TYPE_MCTP_HOST_1,
|
||||
TYPE_MCTP_HOST_2,
|
||||
TYPE_I3C,
|
||||
TYPE_DIAGNOSTIC_1,
|
||||
TYPE_DIAGNOSTIC_2,
|
||||
TYPE_DIAGNOSTIC_3,
|
||||
TYPE_DIAGNOSTIC_4,
|
||||
TYPE_DIAGNOSTIC_5,
|
||||
TYPE_DIAGNOSTIC_6,
|
||||
TYPE_DIAGNOSTIC_7,
|
||||
TYPE_DIAGNOSTIC_8,
|
||||
TYPE_DIAGNOSTIC_9,
|
||||
TYPE_DIAGNOSTIC_10,
|
||||
TYPE_DIAGNOSTIC_11,
|
||||
TYPE_DIAGNOSTIC_12,
|
||||
TYPE_DIAGNOSTIC_13,
|
||||
TYPE_DIAGNOSTIC_14,
|
||||
TYPE_WIRLESS_CONTROLLER_1,
|
||||
TYPE_WIRLESS_CONTROLLER_2,
|
||||
TYPE_WIRLESS_CONTROLLER_3,
|
||||
TYPE_WIRLESS_CONTROLLER_4,
|
||||
TYPE_WIRLESS_CONTROLLER_5,
|
||||
TYPE_WIRLESS_CONTROLLER_6,
|
||||
TYPE_WIRLESS_CONTROLLER_7,
|
||||
TYPE_MISCELLANEOUS_1,
|
||||
TYPE_MISCELLANEOUS_2,
|
||||
TYPE_MISCELLANEOUS_3,
|
||||
TYPE_MISCELLANEOUS_4,
|
||||
TYPE_MISCELLANEOUS_5,
|
||||
TYPE_MISCELLANEOUS_6,
|
||||
TYPE_MISCELLANEOUS_7,
|
||||
TYPE_MISCELLANEOUS_8,
|
||||
TYPE_MISCELLANEOUS_9,
|
||||
TYPE_MISCELLANEOUS_10,
|
||||
TYPE_MISCELLANEOUS_11,
|
||||
TYPE_MISCELLANEOUS_12,
|
||||
TYPE_MISCELLANEOUS_13,
|
||||
TYPE_MISCELLANEOUS_14,
|
||||
TYPE_MISCELLANEOUS_15,
|
||||
TYPE_MISCELLANEOUS_16,
|
||||
TYPE_MISCELLANEOUS_17,
|
||||
TYPE_MISCELLANEOUS_18,
|
||||
TYPE_MISCELLANEOUS_19,
|
||||
TYPE_APPLICATION_SPE_1,
|
||||
TYPE_APPLICATION_SPE_2,
|
||||
TYPE_APPLICATION_SPE_3,
|
||||
TYPE_APPLICATION_SPE_4,
|
||||
TYPE_VENDOR_SPECIFIC,
|
||||
};
|
||||
|
||||
struct UsbDeviceType {
|
||||
int32_t baseClass;
|
||||
int32_t subClass;
|
||||
int32_t protocal;
|
||||
bool isDeviceType;
|
||||
};
|
||||
|
||||
struct UsbDeviceId {
|
||||
@ -32,6 +104,79 @@ struct UsbDeviceId {
|
||||
int32_t vendorId;
|
||||
};
|
||||
|
||||
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}},
|
||||
{InterfaceType::TYPE_PHYSICAL, {5, -1, -1}},
|
||||
{InterfaceType::TYPE_IMAGE, {6, 1, 1}},
|
||||
{InterfaceType::TYPE_PRINTER, {7, -1, -1}},
|
||||
{InterfaceType::TYPE_STORAGE, {8, -1, -1}},
|
||||
{InterfaceType::TYPE_FULL_SPEED_HUB, {9, 0, 0}},
|
||||
{InterfaceType::TYPE_FULL_SPEED_HUB_S, {9, 0, 1}},
|
||||
{InterfaceType::TYPE_FULL_SPEED_HUB_M, {9, 0, 2}},
|
||||
{InterfaceType::TYPE_CDC_DATA, {10, -1, -1}},
|
||||
{InterfaceType::TYPE_SMART_CARD, {11, -1, -1}},
|
||||
{InterfaceType::TYPE_CONTENT_SECURTIY, {13, 0, 0}},
|
||||
{InterfaceType::TYPE_VIDEO, {14, -1, -1}},
|
||||
{InterfaceType::TYPE_PERSONAL_HEALTHCARE, {15, -1, -1}},
|
||||
{InterfaceType::TYPE_AVCONTROL, {16, 1, 0}},
|
||||
{InterfaceType::TYPE_AVV_STREAMING, {16, 2, 0}},
|
||||
{InterfaceType::TYPE_AVA_STREAMING, {16, 3, 0}},
|
||||
{InterfaceType::TYPE_BILLBOARD, {17, 0, 0}},
|
||||
{InterfaceType::TYPE_TYPEC_BRIDGE, {18, 0, 0}},
|
||||
{InterfaceType::TYPE_BDP, {19, 0, 0}},
|
||||
{InterfaceType::TYPE_MCTP_MANA_1, {20, 0, 1}},
|
||||
{InterfaceType::TYPE_MCTP_MANA_2, {20, 0, 2}},
|
||||
{InterfaceType::TYPE_MCTP_HOST_1, {20, 1, 1}},
|
||||
{InterfaceType::TYPE_MCTP_HOST_2, {20, 1, 2}},
|
||||
{InterfaceType::TYPE_I3C, {60, 0, 0}},
|
||||
{InterfaceType::TYPE_DIAGNOSTIC_1, {220, 1, 1}},
|
||||
{InterfaceType::TYPE_DIAGNOSTIC_2, {220, 2, 0}},
|
||||
{InterfaceType::TYPE_DIAGNOSTIC_3, {220, 2, 1}},
|
||||
{InterfaceType::TYPE_DIAGNOSTIC_4, {220, 3, 0}},
|
||||
{InterfaceType::TYPE_DIAGNOSTIC_5, {220, 3, 1}},
|
||||
{InterfaceType::TYPE_DIAGNOSTIC_6, {220, 4, 0}},
|
||||
{InterfaceType::TYPE_DIAGNOSTIC_7, {220, 4, 1}},
|
||||
{InterfaceType::TYPE_DIAGNOSTIC_8, {220, 5, 0}},
|
||||
{InterfaceType::TYPE_DIAGNOSTIC_9, {220, 5, 1}},
|
||||
{InterfaceType::TYPE_DIAGNOSTIC_10, {220, 6, 0}},
|
||||
{InterfaceType::TYPE_DIAGNOSTIC_11, {220, 6, 1}},
|
||||
{InterfaceType::TYPE_DIAGNOSTIC_12, {220, 7, 0}},
|
||||
{InterfaceType::TYPE_DIAGNOSTIC_13, {220, 7, 1}},
|
||||
{InterfaceType::TYPE_DIAGNOSTIC_14, {220, 8, 0}},
|
||||
{InterfaceType::TYPE_WIRLESS_CONTROLLER_1, {224, 1, 1}},
|
||||
{InterfaceType::TYPE_WIRLESS_CONTROLLER_2, {224, 1, 2}},
|
||||
{InterfaceType::TYPE_WIRLESS_CONTROLLER_3, {224, 1, 3}},
|
||||
{InterfaceType::TYPE_WIRLESS_CONTROLLER_4, {224, 1, 4}},
|
||||
{InterfaceType::TYPE_WIRLESS_CONTROLLER_5, {224, 2, 1}},
|
||||
{InterfaceType::TYPE_WIRLESS_CONTROLLER_6, {224, 2, 2}},
|
||||
{InterfaceType::TYPE_WIRLESS_CONTROLLER_7, {224, 2, 3}},
|
||||
{InterfaceType::TYPE_MISCELLANEOUS_1, {239, 1, 1}},
|
||||
{InterfaceType::TYPE_MISCELLANEOUS_2, {239, 1, 2}},
|
||||
{InterfaceType::TYPE_MISCELLANEOUS_3, {239, 2, 1}},
|
||||
{InterfaceType::TYPE_MISCELLANEOUS_4, {239, 2, 2}},
|
||||
{InterfaceType::TYPE_MISCELLANEOUS_5, {239, 3, 1}},
|
||||
{InterfaceType::TYPE_MISCELLANEOUS_6, {239, 4, 1}},
|
||||
{InterfaceType::TYPE_MISCELLANEOUS_7, {239, 4, 2}},
|
||||
{InterfaceType::TYPE_MISCELLANEOUS_8, {239, 4, 3}},
|
||||
{InterfaceType::TYPE_MISCELLANEOUS_9, {239, 4, 4}},
|
||||
{InterfaceType::TYPE_MISCELLANEOUS_10, {239, 4, 5}},
|
||||
{InterfaceType::TYPE_MISCELLANEOUS_11, {239, 4, 6}},
|
||||
{InterfaceType::TYPE_MISCELLANEOUS_12, {239, 4, 7}},
|
||||
{InterfaceType::TYPE_MISCELLANEOUS_13, {239, 5, 0}},
|
||||
{InterfaceType::TYPE_MISCELLANEOUS_14, {239, 5, 1}},
|
||||
{InterfaceType::TYPE_MISCELLANEOUS_15, {239, 5, 2}},
|
||||
{InterfaceType::TYPE_MISCELLANEOUS_16, {239, 6, 1}},
|
||||
{InterfaceType::TYPE_MISCELLANEOUS_17, {239, 6, 2}},
|
||||
{InterfaceType::TYPE_MISCELLANEOUS_18, {239, 7, 1}},
|
||||
{InterfaceType::TYPE_MISCELLANEOUS_19, {239, 7, 2}},
|
||||
{InterfaceType::TYPE_APPLICATION_SPE_1, {254, 1, 1}},
|
||||
{InterfaceType::TYPE_APPLICATION_SPE_2, {254, 2, 0}},
|
||||
{InterfaceType::TYPE_APPLICATION_SPE_3, {254, 3, 0}},
|
||||
{InterfaceType::TYPE_APPLICATION_SPE_4, {254, 3, 1}},
|
||||
{InterfaceType::TYPE_VENDOR_SPECIFIC, {255, -1, -1}}
|
||||
};
|
||||
} // namespace USB
|
||||
} // namespace OHOS
|
||||
#endif // USB_INTERFACE_TYPE_H
|
||||
|
@ -90,7 +90,8 @@ public:
|
||||
int32_t AddAccessRight(const std::string &tokenId, const std::string &deviceName);
|
||||
int32_t ManageGlobalInterface(bool disable);
|
||||
int32_t ManageDevice(int32_t vendorId, int32_t productId, bool disable);
|
||||
int32_t ManageInterfaceType(InterfaceType interfaceType, bool disable);
|
||||
int32_t ManageInterfaceStorage(InterfaceType interfaceType, bool disable);
|
||||
int32_t ManageInterfaceType(const std::vector<UsbDeviceType> &disableType, bool disable);
|
||||
private:
|
||||
class UsbSrvDeathRecipient : public IRemoteObject::DeathRecipient {
|
||||
public:
|
||||
|
@ -475,10 +475,20 @@ int32_t UsbSrvClient::ManageDevice(int32_t vendorId, int32_t productId, bool dis
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t UsbSrvClient::ManageInterfaceType(InterfaceType interfaceType, bool disable)
|
||||
int32_t UsbSrvClient::ManageInterfaceStorage(InterfaceType interfaceType, bool disable)
|
||||
{
|
||||
RETURN_IF_WITH_RET(proxy_ == nullptr, UEC_INTERFACE_NO_INIT);
|
||||
int32_t ret = proxy_->ManageInterfaceType(interfaceType, disable);
|
||||
int32_t ret = proxy_->ManageInterfaceStorage(interfaceType, disable);
|
||||
if (ret != UEC_OK) {
|
||||
USB_HILOGE(MODULE_USB_INNERKIT, "failed width ret = %{public}d !", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t UsbSrvClient::ManageInterfaceType(const std::vector<UsbDeviceType> &disableType, bool disable)
|
||||
{
|
||||
RETURN_IF_WITH_RET(proxy_ == nullptr, UEC_INTERFACE_NO_INIT);
|
||||
int32_t ret = proxy_->ManageInterfaceType(disableType, disable);
|
||||
if (ret != UEC_OK) {
|
||||
USB_HILOGE(MODULE_USB_INNERKIT, "failed width ret = %{public}d !", ret);
|
||||
}
|
||||
|
@ -125,7 +125,8 @@ public:
|
||||
void UnLoadSelf(UnLoadSaType type);
|
||||
int32_t ManageGlobalInterface(bool disable) override;
|
||||
int32_t ManageDevice(int32_t vendorId, int32_t productId, bool disable) override;
|
||||
int32_t ManageInterfaceType(InterfaceType interfaceType, bool disable) override;
|
||||
int32_t ManageInterfaceStorage(InterfaceType interfaceType, bool disable) override;
|
||||
int32_t ManageInterfaceType(const std::vector<UsbDeviceType> &disableType, bool disable) override;
|
||||
int32_t GetInterfaceActiveStatus(uint8_t busNum, uint8_t devAddr, uint8_t interfaceid, bool &unactivated) override;
|
||||
int32_t GetDeviceSpeed(uint8_t busNum, uint8_t devAddr, uint8_t &speed) override;
|
||||
private:
|
||||
@ -161,6 +162,7 @@ private:
|
||||
int32_t PreCallFunction();
|
||||
bool IsEdmEnabled();
|
||||
int32_t ExecuteManageDevicePolicy(std::vector<UsbDeviceId> &whiteList);
|
||||
int32_t ExecuteManageInterfaceType(const std::vector<UsbDeviceType> &disableType, bool disable);
|
||||
int32_t GetEdmPolicy(bool &IsGlobalDisabled, std::unordered_map<InterfaceType, bool> &typeDisableMap,
|
||||
std::vector<UsbDeviceId> &trustUsbDeviceId);
|
||||
int32_t GetUsbPolicy(bool &IsGlobalDisabled, std::unordered_map<InterfaceType, bool> &typeDisableMap,
|
||||
|
@ -82,14 +82,6 @@ constexpr int32_t GET_EDM_STORAGE_DISABLE_TYPE = 2;
|
||||
constexpr int32_t RANDOM_VALUE_INDICATE = -1;
|
||||
constexpr int32_t USB_RIGHT_USERID_INVALID = -1;
|
||||
constexpr const char *USB_DEFAULT_TOKEN = "UsbServiceTokenId";
|
||||
std::unordered_map<InterfaceType, std::vector<int32_t>> g_typeMap = {
|
||||
{InterfaceType::TYPE_STORAGE, {8, -1, -1}},
|
||||
{InterfaceType::TYPE_AUDIO, {1, -1, -1}},
|
||||
{InterfaceType::TYPE_HID, {3, -1, -1}},
|
||||
{InterfaceType::TYPE_PHYSICAL, {5, -1, -1}},
|
||||
{InterfaceType::TYPE_IMAGE, {6, 1, 1}},
|
||||
{InterfaceType::TYPE_PRINTER, {7, -1, -1}}
|
||||
};
|
||||
} // namespace
|
||||
auto g_serviceInstance = DelayedSpSingleton<UsbService>::GetInstance();
|
||||
const bool G_REGISTER_RESULT =
|
||||
@ -1167,6 +1159,36 @@ int32_t UsbService::GetUsbPolicy(bool &IsGlobalDisabled, std::unordered_map<Inte
|
||||
return UEC_OK;
|
||||
}
|
||||
|
||||
int32_t UsbService::ExecuteManageInterfaceType(const std::vector<UsbDeviceType> &disableType, bool disable)
|
||||
{
|
||||
int32_t ret = UEC_INTERFACE_NO_MEMORY;
|
||||
std::map<std::string, UsbDevice *>devices;
|
||||
usbHostManager_->GetDevices(devices);
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "list size %{public}zu", devices.size());
|
||||
for (auto dev : disableType) {
|
||||
for (auto& [interfaceTypeValues, typeValues] : g_typeMap) {
|
||||
if ((!dev.isDeviceType) &&
|
||||
(typeValues[0] == dev.baseClass) &&
|
||||
(typeValues[1] == -1 || typeValues[1] == dev.subClass)&&
|
||||
(typeValues[HALF] == -1 || typeValues[HALF] == dev.protocal)) {
|
||||
ret = ManageInterfaceTypeImpl(interfaceTypeValues, disable);
|
||||
} else {
|
||||
USB_HILOGE(MODULE_USB_SERVICE, "ExecuteManageInterfaceType Invalid data");
|
||||
}
|
||||
}
|
||||
if (dev.isDeviceType) {
|
||||
for (auto it = devices.begin(); it != devices.end(); ++it) {
|
||||
ret = ManageDeviceImpl(it->second->GetVendorId(), it->second->GetProductId(), disable);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ret != UEC_OK) {
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "ExecuteManageInterfaceType failed");
|
||||
return UEC_SERVICE_EXECUTE_POLICY_FAILED;
|
||||
}
|
||||
return UEC_OK;
|
||||
}
|
||||
|
||||
int32_t UsbService::ExecuteManageDevicePolicy(std::vector<UsbDeviceId> &whiteList)
|
||||
{
|
||||
std::map<std::string, UsbDevice *> devices;
|
||||
@ -1240,6 +1262,7 @@ void UsbService::ExecuteStrategy(UsbDevice *devInfo)
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "Execute ManageInterfaceType finish");
|
||||
return;
|
||||
}
|
||||
|
||||
if (trustUsbDeviceIds.empty()) {
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "trustUsbDeviceIds is empty, no devices disable");
|
||||
return;
|
||||
@ -1709,7 +1732,7 @@ int32_t UsbService::ManageDevice(int32_t vendorId, int32_t productId, bool disab
|
||||
return ManageDeviceImpl(vendorId, productId, disable);
|
||||
}
|
||||
|
||||
int32_t UsbService::ManageInterfaceType(InterfaceType interfaceType, bool disable)
|
||||
int32_t UsbService::ManageInterfaceStorage(InterfaceType interfaceType, bool disable)
|
||||
{
|
||||
if (PreCallFunction() != UEC_OK) {
|
||||
USB_HILOGE(MODULE_USB_SERVICE, "PreCallFunction failed");
|
||||
@ -1718,6 +1741,15 @@ int32_t UsbService::ManageInterfaceType(InterfaceType interfaceType, bool disabl
|
||||
return ManageInterfaceTypeImpl(interfaceType, disable);
|
||||
}
|
||||
|
||||
int32_t UsbService::ManageInterfaceType(const std::vector<UsbDeviceType> &disableType, bool disable)
|
||||
{
|
||||
if (PreCallFunction() != UEC_OK) {
|
||||
USB_HILOGE(MODULE_USB_SERVICE, "PreCallFunction failed");
|
||||
return UEC_SERVICE_PRE_MANAGE_INTERFACE_FAILED;
|
||||
}
|
||||
return ExecuteManageInterfaceType(disableType, disable);
|
||||
}
|
||||
|
||||
int32_t UsbService::ManageGlobalInterfaceImpl(bool disable)
|
||||
{
|
||||
std::map<std::string, UsbDevice *> devices;
|
||||
|
@ -79,7 +79,8 @@ public:
|
||||
int32_t AddAccessRight(const std::string &tokenId, const std::string &deviceName) override;
|
||||
int32_t ManageGlobalInterface(bool disable) override;
|
||||
int32_t ManageDevice(int32_t vendorId, int32_t productId, bool disable) override;
|
||||
int32_t ManageInterfaceType(InterfaceType interfaceType, bool disable) override;
|
||||
int32_t ManageInterfaceStorage(InterfaceType interfaceType, bool disable) override;
|
||||
int32_t ManageInterfaceType(const std::vector<UsbDeviceType> &disableType, bool disable) override;
|
||||
int32_t GetDeviceSpeed(uint8_t busNum, uint8_t devAddr, uint8_t &speed) override;
|
||||
int32_t GetInterfaceActiveStatus(uint8_t busNum, uint8_t devAddr, uint8_t interfaceid, bool &unactivated) override;
|
||||
private:
|
||||
|
@ -88,7 +88,9 @@ private:
|
||||
|
||||
int32_t DoManageGlobalInterface(MessageParcel &data, MessageParcel &reply, MessageOption &option);
|
||||
int32_t DoManageDevice(MessageParcel &data, MessageParcel &reply, MessageOption &option);
|
||||
int32_t DoManageInterfaceStorage(MessageParcel &data, MessageParcel &reply, MessageOption &option);
|
||||
int32_t DoManageInterfaceType(MessageParcel &data, MessageParcel &reply, MessageOption &option);
|
||||
|
||||
int32_t DoGetDeviceSpeed(MessageParcel &data, MessageParcel &reply, MessageOption &option);
|
||||
int32_t DoGetInterfaceActiveStatus(MessageParcel &data, MessageParcel &reply, MessageOption &option);
|
||||
|
||||
|
@ -55,6 +55,7 @@ namespace USB {
|
||||
USB_FUN_ADD_RIGHT,
|
||||
USB_FUN_DISABLE_GLOBAL_INTERFACE,
|
||||
USB_FUN_DISABLE_DEVICE,
|
||||
USB_FUN_DISABLE_INTERFACE_STORAGE,
|
||||
USB_FUN_DISABLE_INTERFACE_TYPE,
|
||||
USB_FUN_GET_DEVICE_SPEED,
|
||||
USB_FUN_GET_DRIVER_ACTIVE_STATUS,
|
||||
|
@ -1173,7 +1173,7 @@ int32_t UsbServerProxy::ManageDevice(int32_t vendorId, int32_t productId, bool d
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t UsbServerProxy::ManageInterfaceType(InterfaceType interfaceType, bool disable)
|
||||
int32_t UsbServerProxy::ManageInterfaceStorage(InterfaceType interfaceType, bool disable)
|
||||
{
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
RETURN_IF_WITH_RET(remote == nullptr, UEC_INTERFACE_INVALID_VALUE);
|
||||
@ -1187,6 +1187,37 @@ int32_t UsbServerProxy::ManageInterfaceType(InterfaceType interfaceType, bool di
|
||||
WRITE_PARCEL_WITH_RET(data, Int32, ifaceType, UEC_SERVICE_WRITE_PARCEL_ERROR);
|
||||
WRITE_PARCEL_WITH_RET(data, Bool, disable, UEC_SERVICE_WRITE_PARCEL_ERROR);
|
||||
|
||||
MessageOption option;
|
||||
MessageParcel reply;
|
||||
int32_t ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_DISABLE_INTERFACE_STORAGE),
|
||||
data, reply, option);
|
||||
if (ret != UEC_OK) {
|
||||
USB_HILOGE(MODULE_USB_SERVICE, "SendRequest is failed, error code: %{public}d", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t UsbServerProxy::ManageInterfaceType(const std::vector<UsbDeviceType> &disableType, bool disable)
|
||||
{
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
RETURN_IF_WITH_RET(remote == nullptr, UEC_INTERFACE_INVALID_VALUE);
|
||||
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
|
||||
USB_HILOGE(MODULE_USB_SERVICE, "write descriptor failed!");
|
||||
return ERR_ENOUGH_DATA;
|
||||
}
|
||||
int32_t size = (int32_t)disableType.size();
|
||||
WRITE_PARCEL_WITH_RET(data, Int32, size, UEC_SERVICE_WRITE_PARCEL_ERROR);
|
||||
|
||||
for (const auto &type : disableType) {
|
||||
WRITE_PARCEL_WITH_RET(data, Int32, type.baseClass, UEC_SERVICE_WRITE_PARCEL_ERROR);
|
||||
WRITE_PARCEL_WITH_RET(data, Int32, type.subClass, UEC_SERVICE_WRITE_PARCEL_ERROR);
|
||||
WRITE_PARCEL_WITH_RET(data, Int32, type.protocal, UEC_SERVICE_WRITE_PARCEL_ERROR);
|
||||
WRITE_PARCEL_WITH_RET(data, Bool, type.isDeviceType, UEC_SERVICE_WRITE_PARCEL_ERROR);
|
||||
}
|
||||
WRITE_PARCEL_WITH_RET(data, Bool, disable, UEC_SERVICE_WRITE_PARCEL_ERROR);
|
||||
|
||||
MessageOption option;
|
||||
MessageParcel reply;
|
||||
int32_t ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_DISABLE_INTERFACE_TYPE),
|
||||
|
@ -210,6 +210,9 @@ bool UsbServerStub::StubHost(
|
||||
case static_cast<int>(UsbInterfaceCode::USB_FUN_DISABLE_DEVICE):
|
||||
result = DoManageDevice(data, reply, option);
|
||||
return true;
|
||||
case static_cast<int>(UsbInterfaceCode::USB_FUN_DISABLE_INTERFACE_STORAGE):
|
||||
result = DoManageInterfaceStorage(data, reply, option);
|
||||
return true;
|
||||
case static_cast<int>(UsbInterfaceCode::USB_FUN_DISABLE_INTERFACE_TYPE):
|
||||
result = DoManageInterfaceType(data, reply, option);
|
||||
return true;
|
||||
@ -975,13 +978,35 @@ int32_t UsbServerStub::DoManageDevice(MessageParcel &data, MessageParcel &reply,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t UsbServerStub::DoManageInterfaceType(MessageParcel &data, MessageParcel &reply, MessageOption &option)
|
||||
int32_t UsbServerStub::DoManageInterfaceStorage(MessageParcel &data, MessageParcel &reply, MessageOption &option)
|
||||
{
|
||||
int32_t interfaceType = 0;
|
||||
bool disable = false;
|
||||
READ_PARCEL_WITH_RET(data, Int32, interfaceType, UEC_SERVICE_READ_PARCEL_ERROR);
|
||||
READ_PARCEL_WITH_RET(data, Bool, disable, UEC_SERVICE_READ_PARCEL_ERROR);
|
||||
int32_t ret = ManageInterfaceType((InterfaceType)interfaceType, disable);
|
||||
int32_t ret = ManageInterfaceStorage((InterfaceType)interfaceType, disable);
|
||||
if (ret != UEC_OK) {
|
||||
USB_HILOGE(MODULE_USBD, "ret:%{public}d", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t UsbServerStub::DoManageInterfaceType(MessageParcel &data, MessageParcel &reply, MessageOption &option)
|
||||
{
|
||||
int32_t count;
|
||||
READ_PARCEL_WITH_RET(data, Int32, count, 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);
|
||||
READ_PARCEL_WITH_RET(data, Int32, usbDeviceType.subClass, UEC_SERVICE_READ_PARCEL_ERROR);
|
||||
READ_PARCEL_WITH_RET(data, Int32, usbDeviceType.protocal, UEC_SERVICE_READ_PARCEL_ERROR);
|
||||
READ_PARCEL_WITH_RET(data, Bool, usbDeviceType.isDeviceType, UEC_SERVICE_READ_PARCEL_ERROR);
|
||||
disableType.emplace_back(usbDeviceType);
|
||||
}
|
||||
READ_PARCEL_WITH_RET(data, Bool, disable, UEC_SERVICE_READ_PARCEL_ERROR);
|
||||
int32_t ret = ManageInterfaceType(disableType, disable);
|
||||
if (ret != UEC_OK) {
|
||||
USB_HILOGE(MODULE_USBD, "ret:%{public}d", ret);
|
||||
}
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "usb_common_test.h"
|
||||
#include "usb_srv_client.h"
|
||||
#include "usb_errors.h"
|
||||
#include "usb_interface_type.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS;
|
||||
@ -40,13 +41,6 @@ namespace USB {
|
||||
namespace ManageInterface {
|
||||
constexpr int32_t SLEEP_TIME = 3;
|
||||
|
||||
std::unordered_map<InterfaceType, std::vector<int32_t>> typeMapInfo = {
|
||||
{InterfaceType::TYPE_STORAGE, {8, -1, -1}},
|
||||
{InterfaceType::TYPE_AUDIO, {1, -1, -1}},
|
||||
{InterfaceType::TYPE_HID, {3, -1, -1}},
|
||||
{InterfaceType::TYPE_PRINTER, {7, -1, -1}}
|
||||
};
|
||||
|
||||
void UsbManageInterfaceTest::SetUpTestCase(void)
|
||||
{
|
||||
UsbCommonTest::GrantPermissionSysNative();
|
||||
@ -191,20 +185,20 @@ HWTEST_F(UsbManageInterfaceTest, ManageDevice003, TestSize.Level1)
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ManageInterfaceType001
|
||||
* @tc.desc: Test functions toManageInterfaceType(InterfaceType interfaceType, bool disable);
|
||||
* @tc.name: ManageInterfaceStorage001
|
||||
* @tc.desc: Test functions toManageInterfaceStorage(InterfaceType interfaceType, bool disable);
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(UsbManageInterfaceTest, ManageInterfaceType001, TestSize.Level1)
|
||||
HWTEST_F(UsbManageInterfaceTest, ManageInterfaceStorage001, TestSize.Level1)
|
||||
{
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "Case Start : ManageInterfaceType001 : ManageInterfaceType");
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "Case Start : ManageInterfaceStorage001 : ManageInterfaceStorage");
|
||||
auto &client = UsbSrvClient::GetInstance();
|
||||
vector<UsbDevice> devi;
|
||||
auto ret = client.GetDevices(devi);
|
||||
EXPECT_TRUE(ret == 0);
|
||||
InterfaceType interfaceType = InterfaceType::TYPE_HID;
|
||||
if (devi.size() > 0) {
|
||||
for (auto iter = typeMapInfo.begin(); iter != typeMapInfo.end(); iter ++) {
|
||||
for (auto iter = g_typeMap.begin(); iter != g_typeMap.end(); iter ++) {
|
||||
if (devi.at(0).GetClass() == iter->second[0] &&
|
||||
(devi.at(0).GetSubclass() == iter->second[1] || iter->second[1] == -1) &&
|
||||
(devi.at(0).GetProtocol() == iter->second[2] || iter->second[2] == -1)) {
|
||||
@ -212,19 +206,19 @@ HWTEST_F(UsbManageInterfaceTest, ManageInterfaceType001, TestSize.Level1)
|
||||
}
|
||||
}
|
||||
}
|
||||
ret = client.ManageInterfaceType(interfaceType, true);
|
||||
ret = client.ManageInterfaceStorage(interfaceType, true);
|
||||
ASSERT_EQ(ret, 0);
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "Case End : ManageInterfaceType001 : ManageInterfaceType");
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "Case End : ManageInterfaceStorage001 : ManageInterfaceStorage");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ManageInterfaceType002
|
||||
* @tc.desc: Test functions to ManageInterfaceType(InterfaceType interfaceType, bool disable);
|
||||
* @tc.name: ManageInterfaceStorage002
|
||||
* @tc.desc: Test functions to ManageInterfaceStorage(InterfaceType interfaceType, bool disable);
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(UsbManageInterfaceTest, ManageInterfaceType002, TestSize.Level1)
|
||||
HWTEST_F(UsbManageInterfaceTest, ManageInterfaceStorage002, TestSize.Level1)
|
||||
{
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "Case Start : ManageInterfaceType002 : ManageInterfaceType");
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "Case Start : ManageInterfaceStorage002 : ManageInterfaceStorage");
|
||||
UsbCommonTest::GrantPermissionNormalNative();
|
||||
auto &client = UsbSrvClient::GetInstance();
|
||||
vector<UsbDevice> devi;
|
||||
@ -240,18 +234,18 @@ HWTEST_F(UsbManageInterfaceTest, ManageInterfaceType002, TestSize.Level1)
|
||||
}
|
||||
}
|
||||
}
|
||||
ret = client.ManageInterfaceType(interfaceType, true);
|
||||
ret = client.ManageInterfaceStorage(interfaceType, true);
|
||||
ASSERT_NE(ret, 0);
|
||||
UsbCommonTest::GrantPermissionSysNative();
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "Case End : ManageInterfaceType002 : ManageInterfaceType");
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "Case End : ManageInterfaceStorage002 : ManageInterfaceStorage");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ManageInterfaceType003
|
||||
* @tc.desc: Test functions to ManageInterfaceType(InterfaceType interfaceType, bool disable);
|
||||
* @tc.name: ManageInterfaceStorage003
|
||||
* @tc.desc: Test functions to ManageInterfaceStorage(InterfaceType interfaceType, bool disable);
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(UsbManageInterfaceTest, ManageInterfaceType003, TestSize.Level1)
|
||||
HWTEST_F(UsbManageInterfaceTest, ManageInterfaceStorage003, TestSize.Level1)
|
||||
{
|
||||
auto &client = UsbSrvClient::GetInstance();
|
||||
vector<UsbDevice> devi;
|
||||
@ -259,7 +253,7 @@ HWTEST_F(UsbManageInterfaceTest, ManageInterfaceType003, TestSize.Level1)
|
||||
EXPECT_TRUE(ret == 0);
|
||||
InterfaceType interfaceType = InterfaceType::TYPE_HID;
|
||||
if (devi.size() > 0) {
|
||||
for (auto iter = typeMapInfo.begin(); iter != typeMapInfo.end(); iter ++) {
|
||||
for (auto iter = g_typeMap.begin(); iter != g_typeMap.end(); iter ++) {
|
||||
if (devi.at(0).GetClass() == iter->second[0] &&
|
||||
(devi.at(0).GetSubclass() == iter->second[1] || iter->second[1] == -1) &&
|
||||
(devi.at(0).GetProtocol() == iter->second[2] || iter->second[2] == -1)) {
|
||||
@ -267,10 +261,63 @@ HWTEST_F(UsbManageInterfaceTest, ManageInterfaceType003, TestSize.Level1)
|
||||
}
|
||||
}
|
||||
}
|
||||
ret = client.ManageInterfaceType(interfaceType, false);
|
||||
ret = client.ManageInterfaceStorage(interfaceType, false);
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
||||
|
||||
HWTEST_F(UsbManageInterfaceTest, ManageInterfaceType001, TestSize.Level1)
|
||||
{
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "Case Start : ManageInterfaceType001 : ManageInterfaceType");
|
||||
auto &client = UsbSrvClient::GetInstance();
|
||||
vector<UsbDevice> devi;
|
||||
auto ret = client.GetDevices(devi);
|
||||
EXPECT_TRUE(ret == 0);
|
||||
vector<UsbDeviceType> disableType;
|
||||
if (devi.size() > 0) {
|
||||
for (auto iter = g_typeMap.begin(); iter != g_typeMap.end(); iter ++) {
|
||||
if (devi.at(0).GetClass() == iter->second[0] &&
|
||||
(devi.at(0).GetSubclass() == iter->second[1] || iter->second[1] == -1) &&
|
||||
(devi.at(0).GetProtocol() == iter->second[2] || iter->second[2] == -1)) {
|
||||
UsbDeviceType usbDeviceType;
|
||||
usbDeviceType.baseClass = devi.at(0).GetClass();
|
||||
usbDeviceType.subClass = devi.at(0).GetSubclass();
|
||||
usbDeviceType.protocal = devi.at(0).GetProtocol();
|
||||
usbDeviceType.isDevicetype = 0;
|
||||
disableType.emplace_back(usbDeviceType);
|
||||
}
|
||||
}
|
||||
}
|
||||
ret = client.ManageInterfaceType(disableType, true);
|
||||
ASSERT_EQ(ret, 0);
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "Case End : ManageInterfaceType001 : ManageInterfaceType");
|
||||
}
|
||||
|
||||
HWTEST_F(UsbManageInterfaceTest, ManageInterfaceType002, TestSize.Level1)
|
||||
{
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "Case Start : ManageInterfaceType002 : ManageInterfaceType");
|
||||
auto &client = UsbSrvClient::GetInstance();
|
||||
vector<UsbDevice> devi;
|
||||
auto ret = client.GetDevices(devi);
|
||||
EXPECT_TRUE(ret == 0);
|
||||
vector<UsbDeviceType> disableType;
|
||||
if (devi.size() > 0) {
|
||||
for (auto iter = g_typeMap.begin(); iter != g_typeMap.end(); iter ++) {
|
||||
if (devi.at(0).GetClass() == iter->second[0] &&
|
||||
(devi.at(0).GetSubclass() == iter->second[1] || iter->second[1] == -1) &&
|
||||
(devi.at(0).GetProtocol() == iter->second[2] || iter->second[2] == -1)) {
|
||||
UsbDeviceType usbDeviceType;
|
||||
usbDeviceType.baseClass = devi.at(0).GetClass();
|
||||
usbDeviceType.subClass = devi.at(0).GetSubclass();
|
||||
usbDeviceType.protocal = devi.at(0).GetProtocol();
|
||||
usbDeviceType.isDevicetype = 0;
|
||||
disableType.emplace_back(usbDeviceType);
|
||||
}
|
||||
}
|
||||
}
|
||||
ret = client.ManageInterfaceType(disableType, false);
|
||||
ASSERT_EQ(ret, 0);
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "Case End : ManageInterfaceType002 : ManageInterfaceType");
|
||||
}
|
||||
} // ManagerInterface
|
||||
} // USB
|
||||
} // OHOS
|
||||
|
Loading…
Reference in New Issue
Block a user