for edm StorageTypeManage

Signed-off-by: hechaofan <hechaofan3@huawei.com>
This commit is contained in:
hechaofan 2024-09-24 16:27:52 +08:00
parent 0157bacf17
commit 682ba33446
3 changed files with 75 additions and 28 deletions

View File

@ -174,6 +174,7 @@ private:
void ExecuteStrategy(UsbDevice *devInfo);
int32_t GetEdmTypePolicy(sptr<IRemoteObject> remote, std::vector<UsbDeviceType> &disableType);
int32_t GetEdmGlobalPolicy(sptr<IRemoteObject> remote, bool &IsGlobalDisabled);
int32_t GetEdmStroageTypePolicy(sptr<IRemoteObject> remote, std::vector<UsbDeviceType> &disableType);
int32_t GetEdmWhiteListPolicy(sptr<IRemoteObject> remote, std::vector<UsbDeviceId> &trustUsbDeviceId);
int32_t ManageInterface(const HDI::Usb::V1_0::UsbDev &dev, uint8_t interfaceId, bool disable);
void ExecuteManageDeviceType(const std::vector<UsbDeviceType> &disableType, bool disable,

View File

@ -71,12 +71,15 @@ constexpr uint32_t WITHOUT_ADMIN = 1;
constexpr uint32_t EMD_MASK_CODE = 20;
constexpr uint32_t DISABLE_USB = 1043;
constexpr uint32_t ALLOWED_USB_DEVICES = 1044;
constexpr uint32_t USB_STORAGE_DEVICE_ACCESS_POLICY = 1059;
constexpr uint32_t USB_STORAGE_DEVICE_ACCESS_POLICY = 1026;
constexpr uint32_t USB_DEVICE_ACCESS_POLICY = 1059;
constexpr int32_t WHITELIST_POLICY_MAX_DEVICES = 1000;
constexpr uint32_t EDM_SA_TIME_OUT_CODE = 9200007;
constexpr int32_t BASECLASS_INDEX = 0;
constexpr int32_t SUBCLASS_INDEX = 1;
constexpr int32_t PROTOCAL_INDEX = 2;
constexpr int32_t STORAGE_BASE_CLASS = 8;
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";
@ -1246,6 +1249,47 @@ int32_t UsbService::GetEdmGlobalPolicy(sptr<IRemoteObject> remote, bool &IsGloba
}
// LCOV_EXCL_STOP
// LCOV_EXCL_START
int32_t UsbService::GetEdmStroageTypePolicy(sptr<IRemoteObject> remote, std::vector<UsbDeviceType> &disableType)
{
int32_t stroageDisableType = 0;
bool isStorageDisable = false;
MessageParcel data;
MessageParcel reply;
MessageOption option;
data.WriteInterfaceToken(DESCRIPTOR);
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;
bool isSuccess = reply.ReadInt32(ret) && (ret == ERR_OK);
if (!isSuccess) {
USB_HILOGE(MODULE_USB_SERVICE, "GetEdmStroageTypePolicy failed. ErrCode = %{public}d, ret = %{public}d",
ErrCode, ret);
return UEC_SERVICE_EDM_SEND_REQUEST_FAILED;
}
reply.ReadInt32(stroageDisableType);
if (stroageDisableType == GET_EDM_STORAGE_DISABLE_TYPE) {
isStorageDisable = true;
UsbDeviceType usbDeviceType;
usbDeviceType.baseClass = STORAGE_BASE_CLASS;
usbDeviceType.subClass = 0;
usbDeviceType.protocol = 0;
usbDeviceType.isDeviceType = 0;
disableType.emplace_back(usbDeviceType);
}
return UEC_OK;
}
// LCOV_EXCL_STOP
// LCOV_EXCL_START
int32_t UsbService::GetEdmTypePolicy(sptr<IRemoteObject> remote, std::vector<UsbDeviceType> &disableType)
{
@ -1260,7 +1304,7 @@ int32_t UsbService::GetEdmTypePolicy(sptr<IRemoteObject> remote, std::vector<Usb
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;
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;
bool isSuccess = reply.ReadInt32(ret) && (ret == ERR_OK);
@ -1347,6 +1391,11 @@ int32_t UsbService::GetEdmPolicy(bool &IsGlobalDisabled, std::vector<UsbDeviceTy
USB_HILOGE(MODULE_USB_SERVICE, "GetEdmGlobalPolicy failed.");
return ret;
}
ret = GetEdmStroageTypePolicy(remote, disableType);
if (ret != UEC_OK) {
USB_HILOGE(MODULE_USB_SERVICE, "GetEdmStroageTypePolicy failed.");
return ret;
}
ret = GetEdmTypePolicy(remote, disableType);
if (ret != UEC_OK) {
USB_HILOGE(MODULE_USB_SERVICE, "GetEdmTypePolicy failed.");
@ -2051,10 +2100,9 @@ int32_t UsbService::PreCallFunction()
USB_HILOGE(MODULE_USB_SERVICE, "invalid usbRightManager_");
return UEC_SERVICE_INVALID_VALUE;
}
if (!(usbRightManager_->IsSystemAppOrSa())) {
if (!(usbRightManager_->IsSystemAppOrSa() && usbRightManager_->VerifyPermission())) {
return UEC_SERVICE_PERMISSION_DENIED_SYSAPI;
}
if (usbHostManager_ == nullptr) {
USB_HILOGE(MODULE_USB_SERVICE, "invalid usbHostManager_");
return UEC_SERVICE_INVALID_VALUE;
@ -2071,14 +2119,6 @@ int32_t UsbService::PreCallFunction()
// LCOV_EXCL_START
int32_t UsbService::ManageGlobalInterface(bool disable)
{
if (usbRightManager_ == nullptr) {
USB_HILOGE(MODULE_USB_SERVICE, "invalid usbRightManager_");
return UEC_SERVICE_INVALID_VALUE;
}
if (!(usbRightManager_->IsSystemAppOrSa())) {
USB_HILOGW(MODULE_USB_SERVICE, "is not system app");
return UEC_SERVICE_PERMISSION_DENIED_SYSAPI;
}
if (PreCallFunction() != UEC_OK) {
USB_HILOGE(MODULE_USB_SERVICE, "PreCallFunction failed");
return UEC_SERVICE_PRE_MANAGE_INTERFACE_FAILED;
@ -2091,14 +2131,6 @@ int32_t UsbService::ManageGlobalInterface(bool disable)
// LCOV_EXCL_START
int32_t UsbService::ManageDevice(int32_t vendorId, int32_t productId, bool disable)
{
if (usbRightManager_ == nullptr) {
USB_HILOGE(MODULE_USB_SERVICE, "invalid usbRightManager_");
return UEC_SERVICE_INVALID_VALUE;
}
if (!(usbRightManager_->IsSystemAppOrSa())) {
USB_HILOGW(MODULE_USB_SERVICE, "is not system app");
return UEC_SERVICE_PERMISSION_DENIED_SYSAPI;
}
if (PreCallFunction() != UEC_OK) {
USB_HILOGE(MODULE_USB_SERVICE, "PreCallFunction failed");
return UEC_SERVICE_PRE_MANAGE_INTERFACE_FAILED;
@ -2111,14 +2143,6 @@ int32_t UsbService::ManageDevice(int32_t vendorId, int32_t productId, bool disab
// LCOV_EXCL_START
int32_t UsbService::ManageInterfaceType(const std::vector<UsbDeviceType> &disableType, bool disable)
{
if (usbRightManager_ == nullptr) {
USB_HILOGE(MODULE_USB_SERVICE, "invalid usbRightManager_");
return UEC_SERVICE_INVALID_VALUE;
}
if (!(usbRightManager_->IsSystemAppOrSa())) {
USB_HILOGW(MODULE_USB_SERVICE, "is not system app");
return UEC_SERVICE_PERMISSION_DENIED_SYSAPI;
}
if (PreCallFunction() != UEC_OK) {
USB_HILOGE(MODULE_USB_SERVICE, "PreCallFunction failed");
return UEC_SERVICE_PRE_MANAGE_INTERFACE_FAILED;

View File

@ -259,6 +259,28 @@ HWTEST_F(UsbManageInterfaceTest, ManageInterfaceType004, TestSize.Level1)
ASSERT_EQ(ret, 0);
USB_HILOGI(MODULE_USB_SERVICE, "Case End : ManageInterfaceType004 : ManageInterfaceType");
}
HWTEST_F(UsbManageInterfaceTest, ManageInterfaceType005, TestSize.Level1)
{
USB_HILOGI(MODULE_USB_SERVICE, "Case Start : ManageInterfaceType005 : ManageDevice");
UsbCommonTest::GrantPermissionNormalNative();
auto &client = UsbSrvClient::GetInstance();
vector<UsbDevice> devi;
auto ret = client.GetDevices(devi);
EXPECT_TRUE(ret == 0);
vector<UsbDeviceType> disableType;
UsbDeviceType usbDeviceType;
usbDeviceType.baseClass = 8;
usbDeviceType.subClass = 6;
usbDeviceType.protocol = 80;
usbDeviceType.isDeviceType = 0;
disableType.emplace_back(usbDeviceType);
ret = client.ManageInterfaceType(disableType, false);
ASSERT_NE(ret, 0);
UsbCommonTest::GrantPermissionSysNative();
USB_HILOGI(MODULE_USB_SERVICE, "Case End : ManageInterfaceType005 : ManageDevice");
}
} // ManagerInterface
} // USB
} // OHOS