142103316Sopenharmony_ci/*
242103316Sopenharmony_ci * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
342103316Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
442103316Sopenharmony_ci * you may not use this file except in compliance with the License.
542103316Sopenharmony_ci * You may obtain a copy of the License at
642103316Sopenharmony_ci *
742103316Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0
842103316Sopenharmony_ci *
942103316Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1042103316Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1142103316Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1242103316Sopenharmony_ci * See the License for the specific language governing permissions and
1342103316Sopenharmony_ci * limitations under the License.
1442103316Sopenharmony_ci */
1542103316Sopenharmony_ci
1642103316Sopenharmony_ci#include <regex>
1742103316Sopenharmony_ci#include "usb_device_manager.h"
1842103316Sopenharmony_ci#include <hdf_base.h>
1942103316Sopenharmony_ci#include "common_event_data.h"
2042103316Sopenharmony_ci#include "common_event_manager.h"
2142103316Sopenharmony_ci#include "common_event_support.h"
2242103316Sopenharmony_ci#include "hisysevent.h"
2342103316Sopenharmony_ci#include "usb_errors.h"
2442103316Sopenharmony_ci#include "usb_srv_support.h"
2542103316Sopenharmony_ci#include "usbd_type.h"
2642103316Sopenharmony_ci
2742103316Sopenharmony_ciusing namespace OHOS::AAFwk;
2842103316Sopenharmony_ciusing namespace OHOS::EventFwk;
2942103316Sopenharmony_ciusing namespace OHOS::HiviewDFX;
3042103316Sopenharmony_ciusing namespace OHOS::HDI::Usb::V1_0;
3142103316Sopenharmony_ci
3242103316Sopenharmony_cinamespace OHOS {
3342103316Sopenharmony_cinamespace USB {
3442103316Sopenharmony_ciconstexpr int32_t PARAM_COUNT_TWO = 2;
3542103316Sopenharmony_ciconstexpr int32_t PARAM_COUNT_THR = 3;
3642103316Sopenharmony_ciconstexpr uint32_t CMD_INDEX = 1;
3742103316Sopenharmony_ciconstexpr uint32_t PARAM_INDEX = 2;
3842103316Sopenharmony_ciconstexpr uint32_t DELAY_DISCONN_INTERVAL = 1 * 1000;
3942103316Sopenharmony_ciconst std::map<std::string_view, uint32_t> UsbDeviceManager::FUNCTION_MAPPING_N2C = {
4042103316Sopenharmony_ci    {UsbSrvSupport::FUNCTION_NAME_NONE, UsbSrvSupport::FUNCTION_NONE},
4142103316Sopenharmony_ci    {UsbSrvSupport::FUNCTION_NAME_ACM, UsbSrvSupport::FUNCTION_ACM},
4242103316Sopenharmony_ci    {UsbSrvSupport::FUNCTION_NAME_ECM, UsbSrvSupport::FUNCTION_ECM},
4342103316Sopenharmony_ci    {UsbSrvSupport::FUNCTION_NAME_HDC, UsbSrvSupport::FUNCTION_HDC},
4442103316Sopenharmony_ci    {UsbSrvSupport::FUNCTION_NAME_MTP, UsbSrvSupport::FUNCTION_MTP},
4542103316Sopenharmony_ci    {UsbSrvSupport::FUNCTION_NAME_PTP, UsbSrvSupport::FUNCTION_PTP},
4642103316Sopenharmony_ci    {UsbSrvSupport::FUNCTION_NAME_RNDIS, UsbSrvSupport::FUNCTION_RNDIS},
4742103316Sopenharmony_ci    {UsbSrvSupport::FUNCTION_NAME_STORAGE, UsbSrvSupport::FUNCTION_STORAGE},
4842103316Sopenharmony_ci};
4942103316Sopenharmony_ci
5042103316Sopenharmony_ciUsbDeviceManager::UsbDeviceManager()
5142103316Sopenharmony_ci{
5242103316Sopenharmony_ci    USB_HILOGI(MODULE_USB_SERVICE, "UsbDeviceManager::Init start");
5342103316Sopenharmony_ci    usbd_ = IUsbInterface::Get();
5442103316Sopenharmony_ci    if (usbd_ == nullptr) {
5542103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_SERVICE, "UsbDeviceManager::Get inteface failed");
5642103316Sopenharmony_ci    }
5742103316Sopenharmony_ci}
5842103316Sopenharmony_ci
5942103316Sopenharmony_ciint32_t UsbDeviceManager::Init()
6042103316Sopenharmony_ci{
6142103316Sopenharmony_ci    std::shared_ptr<UsbFunctionSwitchWindow> window_ = UsbFunctionSwitchWindow::GetInstance();
6242103316Sopenharmony_ci    if (window_ == nullptr) {
6342103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_SERVICE, "get usb function switch window failed");
6442103316Sopenharmony_ci        return UEC_SERVICE_INNER_ERR;
6542103316Sopenharmony_ci    }
6642103316Sopenharmony_ci
6742103316Sopenharmony_ci    int32_t ret = window_->Init();
6842103316Sopenharmony_ci    if (ret != UEC_OK) {
6942103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_SERVICE, "Init usb function switch window failed");
7042103316Sopenharmony_ci    }
7142103316Sopenharmony_ci    return ret;
7242103316Sopenharmony_ci}
7342103316Sopenharmony_ci
7442103316Sopenharmony_ciint32_t UsbDeviceManager::SetUsbd(const sptr<IUsbInterface> &usbd)
7542103316Sopenharmony_ci{
7642103316Sopenharmony_ci    if (usbd == nullptr) {
7742103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_SERVICE, "UsbDeviceManager usbd is nullptr");
7842103316Sopenharmony_ci        return UEC_SERVICE_INVALID_VALUE;
7942103316Sopenharmony_ci    }
8042103316Sopenharmony_ci    usbd_ = usbd;
8142103316Sopenharmony_ci    return UEC_OK;
8242103316Sopenharmony_ci}
8342103316Sopenharmony_ci
8442103316Sopenharmony_cibool UsbDeviceManager::AreSettableFunctions(int32_t funcs)
8542103316Sopenharmony_ci{
8642103316Sopenharmony_ci    return static_cast<uint32_t>(funcs) == UsbSrvSupport::FUNCTION_NONE ||
8742103316Sopenharmony_ci        ((~functionSettable_ & static_cast<uint32_t>(funcs)) == 0);
8842103316Sopenharmony_ci}
8942103316Sopenharmony_ci
9042103316Sopenharmony_ciuint32_t UsbDeviceManager::ConvertFromString(std::string_view strFun)
9142103316Sopenharmony_ci{
9242103316Sopenharmony_ci    if (strFun == UsbSrvSupport::FUNCTION_NAME_NONE) {
9342103316Sopenharmony_ci        return UsbSrvSupport::FUNCTION_NONE;
9442103316Sopenharmony_ci    }
9542103316Sopenharmony_ci
9642103316Sopenharmony_ci    size_t len = strFun.length();
9742103316Sopenharmony_ci    if (len == 0) {
9842103316Sopenharmony_ci        return UEC_SERVICE_INVALID_VALUE;
9942103316Sopenharmony_ci    }
10042103316Sopenharmony_ci
10142103316Sopenharmony_ci    std::vector<std::string_view> vModeStr;
10242103316Sopenharmony_ci    size_t pos = 0;
10342103316Sopenharmony_ci    while (pos < len) {
10442103316Sopenharmony_ci        size_t findPos = strFun.find(",", pos);
10542103316Sopenharmony_ci        if (findPos == strFun.npos) {
10642103316Sopenharmony_ci            vModeStr.push_back(strFun.substr(pos, len - pos));
10742103316Sopenharmony_ci            break;
10842103316Sopenharmony_ci        }
10942103316Sopenharmony_ci        vModeStr.push_back(strFun.substr(pos, findPos - pos));
11042103316Sopenharmony_ci        pos = findPos + 1;
11142103316Sopenharmony_ci    }
11242103316Sopenharmony_ci
11342103316Sopenharmony_ci    uint32_t ret = 0;
11442103316Sopenharmony_ci    for (auto &&item : vModeStr) {
11542103316Sopenharmony_ci        auto it = FUNCTION_MAPPING_N2C.find(item);
11642103316Sopenharmony_ci        if (it != FUNCTION_MAPPING_N2C.end()) {
11742103316Sopenharmony_ci            ret |= it->second;
11842103316Sopenharmony_ci        } else {
11942103316Sopenharmony_ci            USB_HILOGE(MODULE_USB_SERVICE, "UsbDeviceManager::ConvertFromString Invalid argument of usb function");
12042103316Sopenharmony_ci            return UEC_SERVICE_INVALID_VALUE;
12142103316Sopenharmony_ci        }
12242103316Sopenharmony_ci    }
12342103316Sopenharmony_ci
12442103316Sopenharmony_ci    return ret;
12542103316Sopenharmony_ci}
12642103316Sopenharmony_ci
12742103316Sopenharmony_cistd::string UsbDeviceManager::ConvertToString(uint32_t function)
12842103316Sopenharmony_ci{
12942103316Sopenharmony_ci    std::string stream;
13042103316Sopenharmony_ci    if (function <= UsbSrvSupport::FUNCTION_NONE || function > functionSettable_) {
13142103316Sopenharmony_ci        stream = std::string {UsbSrvSupport::FUNCTION_NAME_NONE};
13242103316Sopenharmony_ci        return stream;
13342103316Sopenharmony_ci    }
13442103316Sopenharmony_ci    bool flag = false;
13542103316Sopenharmony_ci    for (auto it = FUNCTION_MAPPING_N2C.begin(); it != FUNCTION_MAPPING_N2C.end(); ++it) {
13642103316Sopenharmony_ci        if ((function & it->second) != 0) {
13742103316Sopenharmony_ci            if (flag) {
13842103316Sopenharmony_ci                stream += ",";
13942103316Sopenharmony_ci            }
14042103316Sopenharmony_ci            stream += std::string {it->first};
14142103316Sopenharmony_ci            flag = true;
14242103316Sopenharmony_ci        }
14342103316Sopenharmony_ci    }
14442103316Sopenharmony_ci    USB_HILOGI(MODULE_USB_SERVICE, "UsbDeviceManager::ConvertToString success");
14542103316Sopenharmony_ci    return stream;
14642103316Sopenharmony_ci}
14742103316Sopenharmony_ci
14842103316Sopenharmony_civoid UsbDeviceManager::UpdateFunctions(int32_t func)
14942103316Sopenharmony_ci{
15042103316Sopenharmony_ci    ReportFuncChangeSysEvent(currentFunctions_, func);
15142103316Sopenharmony_ci    currentFunctions_ = func;
15242103316Sopenharmony_ci}
15342103316Sopenharmony_ci
15442103316Sopenharmony_ciint32_t UsbDeviceManager::GetCurrentFunctions()
15542103316Sopenharmony_ci{
15642103316Sopenharmony_ci    return currentFunctions_;
15742103316Sopenharmony_ci}
15842103316Sopenharmony_ci
15942103316Sopenharmony_civoid UsbDeviceManager::HandleEvent(int32_t status)
16042103316Sopenharmony_ci{
16142103316Sopenharmony_ci    if (usbd_ == nullptr) {
16242103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_SERVICE, "UsbDeviceManager::usbd_ is nullptr");
16342103316Sopenharmony_ci        return;
16442103316Sopenharmony_ci    }
16542103316Sopenharmony_ci    bool curConnect = false;
16642103316Sopenharmony_ci    switch (status) {
16742103316Sopenharmony_ci        case ACT_UPDEVICE: {
16842103316Sopenharmony_ci            curConnect = true;
16942103316Sopenharmony_ci            gadgetConnected_ = true;
17042103316Sopenharmony_ci            break;
17142103316Sopenharmony_ci        }
17242103316Sopenharmony_ci        case ACT_DOWNDEVICE: {
17342103316Sopenharmony_ci            curConnect = false;
17442103316Sopenharmony_ci            gadgetConnected_ = false;
17542103316Sopenharmony_ci            break;
17642103316Sopenharmony_ci        }
17742103316Sopenharmony_ci        default:
17842103316Sopenharmony_ci            USB_HILOGE(MODULE_USB_SERVICE, "invalid status %{public}d", status);
17942103316Sopenharmony_ci            curConnect = false;
18042103316Sopenharmony_ci    }
18142103316Sopenharmony_ci    delayDisconn_.Unregister(delayDisconnTimerId_);
18242103316Sopenharmony_ci    delayDisconn_.Shutdown();
18342103316Sopenharmony_ci    if (curConnect && (connected_ != curConnect)) {
18442103316Sopenharmony_ci        connected_ = curConnect;
18542103316Sopenharmony_ci        usbd_->GetCurrentFunctions(currentFunctions_);
18642103316Sopenharmony_ci        ProcessFuncChange(connected_, currentFunctions_);
18742103316Sopenharmony_ci    } else if (!curConnect && (connected_ != curConnect)) {
18842103316Sopenharmony_ci        auto task = [&]() {
18942103316Sopenharmony_ci            connected_ = false;
19042103316Sopenharmony_ci            ProcessFuncChange(connected_, currentFunctions_);
19142103316Sopenharmony_ci            return;
19242103316Sopenharmony_ci        };
19342103316Sopenharmony_ci        auto ret = delayDisconn_.Setup();
19442103316Sopenharmony_ci        if (ret != UEC_OK) {
19542103316Sopenharmony_ci            USB_HILOGE(MODULE_USB_SERVICE, "set up timer failed %{public}u", ret);
19642103316Sopenharmony_ci            return;
19742103316Sopenharmony_ci        }
19842103316Sopenharmony_ci        delayDisconnTimerId_ = delayDisconn_.Register(task, DELAY_DISCONN_INTERVAL, true);
19942103316Sopenharmony_ci    } else {
20042103316Sopenharmony_ci        USB_HILOGI(MODULE_USB_SERVICE, "else info cur status %{public}d, bconnected: %{public}d", status, connected_);
20142103316Sopenharmony_ci    }
20242103316Sopenharmony_ci}
20342103316Sopenharmony_ci
20442103316Sopenharmony_civoid UsbDeviceManager::ProcessFuncChange(bool connected, int32_t currentFunc)
20542103316Sopenharmony_ci{
20642103316Sopenharmony_ci    USB_HILOGI(MODULE_USB_SERVICE, "Current Connect %{public}d,bconnected: %{public}d", connected, currentFunc);
20742103316Sopenharmony_ci    Want want;
20842103316Sopenharmony_ci    want.SetAction(CommonEventSupport::COMMON_EVENT_USB_STATE);
20942103316Sopenharmony_ci
21042103316Sopenharmony_ci    want.SetParam(std::string {UsbSrvSupport::CONNECTED}, connected);
21142103316Sopenharmony_ci    uint32_t remainderFunc = static_cast<uint32_t>(currentFunc);
21242103316Sopenharmony_ci    // start from bit 1
21342103316Sopenharmony_ci    uint32_t bit = 1;
21442103316Sopenharmony_ci    while (remainderFunc != 0) {
21542103316Sopenharmony_ci        if (remainderFunc & bit) {
21642103316Sopenharmony_ci            want.SetParam(ConvertToString(bit), true);
21742103316Sopenharmony_ci            // set current bit to zero
21842103316Sopenharmony_ci            remainderFunc &= ~bit;
21942103316Sopenharmony_ci        }
22042103316Sopenharmony_ci        // 1 means to next bit
22142103316Sopenharmony_ci        bit = bit << 1;
22242103316Sopenharmony_ci    }
22342103316Sopenharmony_ci    CommonEventData data(want);
22442103316Sopenharmony_ci    CommonEventPublishInfo publishInfo;
22542103316Sopenharmony_ci    USB_HILOGI(MODULE_SERVICE, "send COMMON_EVENT_USB_STATE broadcast connected:%{public}d, "
22642103316Sopenharmony_ci        "currentFunctions:%{public}d", connected, currentFunc);
22742103316Sopenharmony_ci    CommonEventManager::PublishCommonEvent(data, publishInfo);
22842103316Sopenharmony_ci    ReportDevicePlugSysEvent(currentFunc, connected);
22942103316Sopenharmony_ci    ProcessFunctionSwitchWindow(connected);
23042103316Sopenharmony_ci}
23142103316Sopenharmony_ci
23242103316Sopenharmony_civoid UsbDeviceManager::ProcessFunctionSwitchWindow(bool connected)
23342103316Sopenharmony_ci{
23442103316Sopenharmony_ci    std::shared_ptr<UsbFunctionSwitchWindow> window_ = UsbFunctionSwitchWindow::GetInstance();
23542103316Sopenharmony_ci    if (window_ == nullptr) {
23642103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_SERVICE, "show window: get usb function switch window failed");
23742103316Sopenharmony_ci        return;
23842103316Sopenharmony_ci    }
23942103316Sopenharmony_ci
24042103316Sopenharmony_ci    if (connected) {
24142103316Sopenharmony_ci        USB_HILOGD(MODULE_USB_SERVICE, "start pop up usb service switch window");
24242103316Sopenharmony_ci        if (!window_->PopUpFunctionSwitchWindow()) {
24342103316Sopenharmony_ci            USB_HILOGE(MODULE_USB_SERVICE, "start pop up usb service switch window failed");
24442103316Sopenharmony_ci        }
24542103316Sopenharmony_ci    } else {
24642103316Sopenharmony_ci        USB_HILOGD(MODULE_USB_SERVICE, "start dismiss usb service switch window");
24742103316Sopenharmony_ci        if (!window_->DismissFunctionSwitchWindow()) {
24842103316Sopenharmony_ci            USB_HILOGE(MODULE_USB_SERVICE, "start dismiss usb service switch window failed");
24942103316Sopenharmony_ci        }
25042103316Sopenharmony_ci    }
25142103316Sopenharmony_ci}
25242103316Sopenharmony_ci
25342103316Sopenharmony_civoid UsbDeviceManager::GetDumpHelp(int32_t fd)
25442103316Sopenharmony_ci{
25542103316Sopenharmony_ci    dprintf(fd, "========= dump the all device function =========\n");
25642103316Sopenharmony_ci    dprintf(fd, "usb_device -a:    Query all function\n");
25742103316Sopenharmony_ci    dprintf(fd, "usb_device -f Q:  Query Current function\n");
25842103316Sopenharmony_ci    dprintf(fd, "usb_device -f 0:  Switch to function:none\n");
25942103316Sopenharmony_ci    dprintf(fd, "usb_device -f 1:  Switch to function:acm\n");
26042103316Sopenharmony_ci    dprintf(fd, "usb_device -f 2:  Switch to function:ecm\n");
26142103316Sopenharmony_ci    dprintf(fd, "usb_device -f 3:  Switch to function:acm&ecm\n");
26242103316Sopenharmony_ci    dprintf(fd, "usb_device -f 4:  Switch to function:hdc\n");
26342103316Sopenharmony_ci    dprintf(fd, "usb_device -f 5:  Switch to function:acm&hdc\n");
26442103316Sopenharmony_ci    dprintf(fd, "usb_device -f 6:  Switch to function:ecm&hdc\n");
26542103316Sopenharmony_ci    dprintf(fd, "usb_device -f 32: Switch to function:rndis\n");
26642103316Sopenharmony_ci    dprintf(fd, "usb_device -f 512:Switch to function:storage\n");
26742103316Sopenharmony_ci    dprintf(fd, "usb_device -f 36: Switch to function:rndis&hdc\n");
26842103316Sopenharmony_ci    dprintf(fd, "usb_device -f 516:Switch to function:storage&hdc\n");
26942103316Sopenharmony_ci    dprintf(fd, "------------------------------------------------\n");
27042103316Sopenharmony_ci}
27142103316Sopenharmony_ci
27242103316Sopenharmony_civoid UsbDeviceManager::DumpGetSupportFunc(int32_t fd)
27342103316Sopenharmony_ci{
27442103316Sopenharmony_ci    dprintf(fd, "Usb Device function list info:\n");
27542103316Sopenharmony_ci    dprintf(fd, "current function: %s\n", ConvertToString(currentFunctions_).c_str());
27642103316Sopenharmony_ci    dprintf(fd, "supported functions list: %s\n", ConvertToString(functionSettable_).c_str());
27742103316Sopenharmony_ci}
27842103316Sopenharmony_ci
27942103316Sopenharmony_civoid UsbDeviceManager::DumpSetFunc(int32_t fd, const std::string &args)
28042103316Sopenharmony_ci{
28142103316Sopenharmony_ci    int32_t currentFunction;
28242103316Sopenharmony_ci    int32_t ret;
28342103316Sopenharmony_ci    if (usbd_ == nullptr) {
28442103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_SERVICE, "UsbDeviceManager::DumpSetFunc usbd_ is nullptr");
28542103316Sopenharmony_ci        return;
28642103316Sopenharmony_ci    }
28742103316Sopenharmony_ci    if (args.compare("Q") == 0) {
28842103316Sopenharmony_ci        ret = usbd_->GetCurrentFunctions(currentFunction);
28942103316Sopenharmony_ci        if (ret != UEC_OK) {
29042103316Sopenharmony_ci            dprintf(fd, "GetCurrentFunctions failed: %d\n", __LINE__);
29142103316Sopenharmony_ci            return;
29242103316Sopenharmony_ci        }
29342103316Sopenharmony_ci        dprintf(fd, "current function: %s\n", ConvertToString(currentFunction).c_str());
29442103316Sopenharmony_ci        return;
29542103316Sopenharmony_ci    }
29642103316Sopenharmony_ci    if (!std::regex_match(args, std::regex("^[0-9]+$"))) {
29742103316Sopenharmony_ci        dprintf(fd, "Invalid input, please enter a valid integer\n");
29842103316Sopenharmony_ci        GetDumpHelp(fd);
29942103316Sopenharmony_ci        return;
30042103316Sopenharmony_ci    }
30142103316Sopenharmony_ci    int32_t mode = stoi(args);
30242103316Sopenharmony_ci    ret = usbd_->SetCurrentFunctions(mode);
30342103316Sopenharmony_ci    if (ret != UEC_OK) {
30442103316Sopenharmony_ci        dprintf(fd, "SetCurrentFunctions failed");
30542103316Sopenharmony_ci        return;
30642103316Sopenharmony_ci    }
30742103316Sopenharmony_ci    ret = usbd_->GetCurrentFunctions(currentFunction);
30842103316Sopenharmony_ci    if (ret != UEC_OK) {
30942103316Sopenharmony_ci        dprintf(fd, "GetCurrentFunctions failed: %d\n", __LINE__);
31042103316Sopenharmony_ci        return;
31142103316Sopenharmony_ci    }
31242103316Sopenharmony_ci
31342103316Sopenharmony_ci    dprintf(fd, "current function: %s\n", ConvertToString(currentFunction).c_str());
31442103316Sopenharmony_ci}
31542103316Sopenharmony_ci
31642103316Sopenharmony_civoid UsbDeviceManager::Dump(int32_t fd, const std::vector<std::string> &args)
31742103316Sopenharmony_ci{
31842103316Sopenharmony_ci    if (args.size() < PARAM_COUNT_TWO || args.size() > PARAM_COUNT_THR) {
31942103316Sopenharmony_ci        GetDumpHelp(fd);
32042103316Sopenharmony_ci        return;
32142103316Sopenharmony_ci    }
32242103316Sopenharmony_ci
32342103316Sopenharmony_ci    if (args[CMD_INDEX] == "-a" && args.size() == PARAM_COUNT_TWO) {
32442103316Sopenharmony_ci        DumpGetSupportFunc(fd);
32542103316Sopenharmony_ci    } else if (args[CMD_INDEX] == "-f" && args.size() == PARAM_COUNT_THR) {
32642103316Sopenharmony_ci        DumpSetFunc(fd, args[PARAM_INDEX]);
32742103316Sopenharmony_ci    } else {
32842103316Sopenharmony_ci        dprintf(fd, "func param error, please enter again\n");
32942103316Sopenharmony_ci        GetDumpHelp(fd);
33042103316Sopenharmony_ci    }
33142103316Sopenharmony_ci}
33242103316Sopenharmony_ci
33342103316Sopenharmony_civoid UsbDeviceManager::ReportFuncChangeSysEvent(int32_t currentFunctions, int32_t updateFunctions)
33442103316Sopenharmony_ci{
33542103316Sopenharmony_ci    USB_HILOGI(MODULE_USB_SERVICE, "Device function Indicates the switch point information:");
33642103316Sopenharmony_ci    HiSysEventWrite(HiSysEvent::Domain::USB, "FUNCTION_CHANGED",
33742103316Sopenharmony_ci        HiSysEvent::EventType::BEHAVIOR, "CURRENT_FUNCTION",
33842103316Sopenharmony_ci        currentFunctions_, "UPDATE_FUNCTION", updateFunctions);
33942103316Sopenharmony_ci}
34042103316Sopenharmony_ci
34142103316Sopenharmony_civoid UsbDeviceManager::ReportDevicePlugSysEvent(int32_t currentFunctions, bool connected)
34242103316Sopenharmony_ci{
34342103316Sopenharmony_ci    USB_HILOGI(MODULE_USB_SERVICE, "Device mode Indicates the insertion and removal information:");
34442103316Sopenharmony_ci    HiSysEventWrite(HiSysEvent::Domain::USB, "PLUG_IN_OUT_DEVICE_MODE",
34542103316Sopenharmony_ci        HiSysEvent::EventType::BEHAVIOR, "CURRENT_FUNCTIONS",
34642103316Sopenharmony_ci        currentFunctions, "CONNECTED", connected);
34742103316Sopenharmony_ci}
34842103316Sopenharmony_cibool UsbDeviceManager::IsGadgetConnected(void)
34942103316Sopenharmony_ci{
35042103316Sopenharmony_ci    return gadgetConnected_;
35142103316Sopenharmony_ci}
35242103316Sopenharmony_ci} // namespace USB
35342103316Sopenharmony_ci} // namespace OHOS
354