180922886Sopenharmony_ci/*
280922886Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
380922886Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
480922886Sopenharmony_ci * you may not use this file except in compliance with the License.
580922886Sopenharmony_ci * You may obtain a copy of the License at
680922886Sopenharmony_ci *
780922886Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
880922886Sopenharmony_ci *
980922886Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1080922886Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1180922886Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1280922886Sopenharmony_ci * See the License for the specific language governing permissions and
1380922886Sopenharmony_ci * limitations under the License.
1480922886Sopenharmony_ci */
1580922886Sopenharmony_ci
1680922886Sopenharmony_ci#ifndef OHOS_AVSESSION_RADAR_H
1780922886Sopenharmony_ci#define OHOS_AVSESSION_RADAR_H
1880922886Sopenharmony_ci
1980922886Sopenharmony_ci#include "radar_constants.h"
2080922886Sopenharmony_ci#include "element_name.h"
2180922886Sopenharmony_ci#include <nlohmann/json.hpp>
2280922886Sopenharmony_ci#include <string>
2380922886Sopenharmony_ci#include <algorithm>
2480922886Sopenharmony_ci#include "avsession_descriptor.h"
2580922886Sopenharmony_ci#include "bundle_mgr_proxy.h"
2680922886Sopenharmony_ci#include "bundle_status_callback_host.h"
2780922886Sopenharmony_ci#include "iservice_registry.h"
2880922886Sopenharmony_ci
2980922886Sopenharmony_cinamespace OHOS::AVSession {
3080922886Sopenharmony_cistruct AVSessionRadarInfo {
3180922886Sopenharmony_ci    int32_t bizScene_ { 0 };
3280922886Sopenharmony_ci    int32_t bizStage_ { 0 };
3380922886Sopenharmony_ci    int32_t stageRes_ { 0 };
3480922886Sopenharmony_ci    int32_t bizState_ { 0 };
3580922886Sopenharmony_ci    int32_t triggerMode_ { 0 };
3680922886Sopenharmony_ci    int32_t errorCode_ { 0 };
3780922886Sopenharmony_ci    int32_t isTrust_ { static_cast<int32_t>(TrustStatus::UNKOWN) };
3880922886Sopenharmony_ci    std::string hostPkg_;
3980922886Sopenharmony_ci    std::string toCallPkg_ { CAST_ENGINE_PKG };
4080922886Sopenharmony_ci    std::string func_;
4180922886Sopenharmony_ci    std::string discoveryDeviceList_;
4280922886Sopenharmony_ci    std::string peerUdid_;
4380922886Sopenharmony_ci    std::string peerBtMac_;
4480922886Sopenharmony_ci    std::string peerNetId_;
4580922886Sopenharmony_ci    std::string peerDevType_;
4680922886Sopenharmony_ci    std::string localSessName_;
4780922886Sopenharmony_ci    std::string peerSessName_;
4880922886Sopenharmony_ci    std::string bundleName_;
4980922886Sopenharmony_ci    explicit AVSessionRadarInfo(std::string funcName) : func_(funcName) {}
5080922886Sopenharmony_ci    void CheckTriggerMode()
5180922886Sopenharmony_ci    {
5280922886Sopenharmony_ci        if (bundleName_.empty()) {
5380922886Sopenharmony_ci            triggerMode_ = static_cast<int32_t>(TriggerMode::UNKNOWN);
5480922886Sopenharmony_ci            return;
5580922886Sopenharmony_ci        }
5680922886Sopenharmony_ci        triggerMode_ = (bundleName_.find(MEDIA_CONTROL_PKG) == std::string::npos) ?
5780922886Sopenharmony_ci            static_cast<int32_t>(TriggerMode::APPLICATION) :
5880922886Sopenharmony_ci            static_cast<int32_t>(TriggerMode::MEDIA_CONTROL);
5980922886Sopenharmony_ci    }
6080922886Sopenharmony_ci};
6180922886Sopenharmony_ci
6280922886Sopenharmony_ciclass AVSessionRadar {
6380922886Sopenharmony_cipublic:
6480922886Sopenharmony_ci    static AVSessionRadar &GetInstance();
6580922886Sopenharmony_ci    static std::string GetAnonymousDeviceId(std::string deviceId);
6680922886Sopenharmony_ci    static int32_t GetRadarErrorCode(int32_t err);
6780922886Sopenharmony_ci    void InitBMS();
6880922886Sopenharmony_ci    void GetJsonCastDeviceList(const OutputDeviceInfo &deviceInfo, std::string& deviceList);
6980922886Sopenharmony_ci    void GetPeerInfo(const OutputDeviceInfo &outputDeviceInfo, AVSessionRadarInfo &info);
7080922886Sopenharmony_ci    void GetPeerInfoFromDeviceInfo(const DeviceInfo &deviceInfo, AVSessionRadarInfo &info);
7180922886Sopenharmony_ci
7280922886Sopenharmony_ci    void StartCastDiscoveryBegin(AVSessionRadarInfo &info);
7380922886Sopenharmony_ci    void StartCastDiscoveryEnd(AVSessionRadarInfo &info);
7480922886Sopenharmony_ci    void FailToStartCastDiscovery(AVSessionRadarInfo &info);
7580922886Sopenharmony_ci
7680922886Sopenharmony_ci    void CastDeviceAvailable(const OutputDeviceInfo &castOutputDeviceInfo, AVSessionRadarInfo &info);
7780922886Sopenharmony_ci
7880922886Sopenharmony_ci    void StopCastDiscoveryBegin(AVSessionRadarInfo &info);
7980922886Sopenharmony_ci    void StopCastDiscoveryEnd(AVSessionRadarInfo &info);
8080922886Sopenharmony_ci    void FailToStopCastDiscovery(AVSessionRadarInfo &info);
8180922886Sopenharmony_ci
8280922886Sopenharmony_ci    void StartCastBegin(const OutputDeviceInfo& outputDeviceInfo, AVSessionRadarInfo &info);
8380922886Sopenharmony_ci    void StartCastEnd(const OutputDeviceInfo& outputDeviceInfo, AVSessionRadarInfo &info);
8480922886Sopenharmony_ci    void FailToStartCast(AVSessionRadarInfo &info);
8580922886Sopenharmony_ci    void FailToStartCast(const OutputDeviceInfo& outputDeviceInfo, AVSessionRadarInfo &info);
8680922886Sopenharmony_ci    void StartConnect(AVSessionRadarInfo &info);
8780922886Sopenharmony_ci    void ConnectFinish(const DeviceInfo &deviceInfo, AVSessionRadarInfo &info);
8880922886Sopenharmony_ci
8980922886Sopenharmony_ci    void StartPlayBegin(AVSessionRadarInfo &info);
9080922886Sopenharmony_ci    void StartPlayEnd(AVSessionRadarInfo &info);
9180922886Sopenharmony_ci    void StartPlayFailed(AVSessionRadarInfo &info);
9280922886Sopenharmony_ci    void PlayerStarted(AVSessionRadarInfo &info);
9380922886Sopenharmony_ci
9480922886Sopenharmony_ci    void SendControlCommandBegin(AVSessionRadarInfo &info);
9580922886Sopenharmony_ci    void SendControlCommandEnd(AVSessionRadarInfo &info);
9680922886Sopenharmony_ci    void FailToSendControlCommand(AVSessionRadarInfo &info);
9780922886Sopenharmony_ci    void ControlCommandRespond(AVSessionRadarInfo &info);
9880922886Sopenharmony_ci    void ControlCommandError(AVSessionRadarInfo &info);
9980922886Sopenharmony_ci
10080922886Sopenharmony_ci    void StopCastBegin(const OutputDeviceInfo& outputDeviceInfo, AVSessionRadarInfo &info);
10180922886Sopenharmony_ci    void StopCastEnd(const OutputDeviceInfo& outputDeviceInfo, AVSessionRadarInfo &info);
10280922886Sopenharmony_ci    void StopCastFinish(const DeviceInfo &deviceInfo, AVSessionRadarInfo &info);
10380922886Sopenharmony_ci    void FailToStopCast(AVSessionRadarInfo &info);
10480922886Sopenharmony_ci    void FailToStopCast(const OutputDeviceInfo &outputDeviceInfo, AVSessionRadarInfo &info);
10580922886Sopenharmony_ci
10680922886Sopenharmony_ci    void reset();
10780922886Sopenharmony_ci
10880922886Sopenharmony_ciprivate:
10980922886Sopenharmony_ci    AVSessionRadar() = default;
11080922886Sopenharmony_ci    ~AVSessionRadar() = default;
11180922886Sopenharmony_ci    std::string GetLocalDeviceNetworkId();
11280922886Sopenharmony_ci    std::string GetUdidByNetworkId(const std::string &networkId);
11380922886Sopenharmony_ci    void ReportWithTrustInfo(AVSessionRadarInfo &info);
11480922886Sopenharmony_ci    void ReportWithoutTrustInfo(AVSessionRadarInfo &info);
11580922886Sopenharmony_ci    void ReportHiSysEventBehavior(AVSessionRadarInfo &info);
11680922886Sopenharmony_ci    std::string ConvertHexToString(int32_t hex);
11780922886Sopenharmony_ci    std::string GetLocalDevType();
11880922886Sopenharmony_ci    std::string GetBundleNameFromUid(int32_t uid);
11980922886Sopenharmony_ci
12080922886Sopenharmony_ciprivate:
12180922886Sopenharmony_ci    std::string orgPkg_ { AVSESSION_PKG_NAME };
12280922886Sopenharmony_ci    std::string localUdid_;
12380922886Sopenharmony_ci    std::string localNetId_;
12480922886Sopenharmony_ci    std::string localDevType_;
12580922886Sopenharmony_ci    sptr<AppExecFwk::BundleMgrProxy> bundleMgrProxy_;
12680922886Sopenharmony_ci};
12780922886Sopenharmony_ci} // namespace OHOS::AVSession
12880922886Sopenharmony_ci#endif // OHOS_AVSESSION_RADAR_H