• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef ABILITY_DYNAMIC_INSIGHT_H
17 #define ABILITY_DYNAMIC_INSIGHT_H
18 
19 #include <string>
20 
21 #include "insight_intent_execute_param.h"
22 #include "cJSON.h"
23 
24 #define AVSESSION_EXECUTE_INTENT_CODE 72
25 
26 namespace OHOS::AVSession {
27 #define BLUETOOTH_UID 1002
28 
29 enum class StartPlayType {
30     APP = 0,
31     BLUETOOTH = 1,
32 };
33 
34 const std::map<StartPlayType, std::string> StartPlayTypeToString = {
35     {StartPlayType::APP, "app"},
36     {StartPlayType::BLUETOOTH, "bluetooth"},
37 };
38 
39 class StartPlayInfo {
40 public:
41     StartPlayInfo() = default;
42 
43     ~StartPlayInfo() = default;
44 
getBundleName()45     std::string getBundleName() const
46     {
47         return bundleName;
48     }
49 
setBundleName(const std::string & name)50     void setBundleName(const std::string& name)
51     {
52         bundleName = name;
53     }
54 
getDeviceId()55     std::string getDeviceId() const
56     {
57         return deviceId;
58     }
59 
setDeviceId(const std::string & id)60     void setDeviceId(const std::string& id)
61     {
62         deviceId = id;
63     }
64 
startPlayInfoToJson()65     cJSON* startPlayInfoToJson() const
66     {
67         cJSON* j = cJSON_CreateObject();
68         if (j == nullptr) {
69             return nullptr;
70         }
71         cJSON_AddStringToObject(j, "deviceId", deviceId.c_str());
72         cJSON_AddStringToObject(j, "startPlayBundleName", bundleName.c_str());
73         return j;
74     }
75 
76 private:
77     std::string bundleName;
78 
79     std::string deviceId;
80 };
81 class InsightAdapter {
82 public:
83     static InsightAdapter& GetInsightAdapterInstance();
84 
85     ~InsightAdapter();
86 
87     __attribute__((no_sanitize("cfi"))) bool IsSupportPlayIntent(const std::string& bundleName,
88         std::string& supportModule, std::string& profile);
89 
90     bool GetPlayIntentParam(const std::string& bundleName, const std::string& assetId,
91                             AppExecFwk::InsightIntentExecuteParam &executeParam, const StartPlayInfo startPlayInfo = {},
92                             StartPlayType startPlayType = StartPlayType::APP);
93 
94     void SetStartPlayInfoToParam(const StartPlayInfo startPlayInfo, StartPlayType startPlayType,
95         std::shared_ptr<AppExecFwk::WantParams> &wantParam);
96 
97     int32_t StartAVPlayback(AppExecFwk::InsightIntentExecuteParam &executeParam);
98 
99 private:
100     InsightAdapter();
101 
102     bool CheckBundleSupport(std::string& profile);
103 
104     std::shared_ptr<AppExecFwk::WantParams> GetPlayIntentParamWithWantProcess(std::string& insightName,
105     const std::string& assetId, const StartPlayInfo startPlayInfo, StartPlayType startPlayType, bool& res);
106 
107     bool ExecuteIntentFromAVSession(uint64_t key, const sptr<IRemoteObject> &callerToken,
108         AppExecFwk::InsightIntentExecuteParam &param);
109 
110     const int32_t getBundleInfoWithHapModule = 0x00000002;
111 
112     const int32_t startUserId = 100;
113 
114     const int32_t interfaceType = 9;
115 
116     const std::string PLAY_MUSICLIST = "PlayMusicList";
117 
118     const std::string PLAY_AUDIO = "PlayAudio";
119 
120     const std::u16string ABILITY_MANAGER_INTERFACE_TOKEN = u"ohos.aafwk.AbilityManager";
121 };
122 
123 }
124 #endif // ABILITY_DYNAMIC_INSIGHT_H
125 
126