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 "insight_intent_execute_param.h" 20 21 namespace OHOS::AVSession { 22 #define BLUETOOTH_UID 1002 23 24 enum class StartPlayType { 25 APP = 0, 26 BLUETOOTH = 1, 27 }; 28 29 const std::map<StartPlayType, std::string> StartPlayTypeToString = { 30 {StartPlayType::APP, "app"}, 31 {StartPlayType::BLUETOOTH, "bluetooth"}, 32 }; 33 34 class StartPlayInfo { 35 public: 36 StartPlayInfo() = default; 37 38 ~StartPlayInfo() = default; 39 getBundleName()40 std::string getBundleName() const 41 { 42 return bundleName; 43 } 44 setBundleName(const std::string & name)45 void setBundleName(const std::string& name) 46 { 47 bundleName = name; 48 } 49 getDeviceId()50 std::string getDeviceId() const 51 { 52 return deviceId; 53 } 54 setDeviceId(const std::string & id)55 void setDeviceId(const std::string& id) 56 { 57 deviceId = id; 58 } 59 startPlayInfoToJson()60 nlohmann::json startPlayInfoToJson() const 61 { 62 nlohmann::json j; 63 j["deviceId"] = deviceId; 64 j["startPlayBundleName"] = bundleName; 65 return j; 66 } 67 68 private: 69 std::string bundleName; 70 71 std::string deviceId; 72 }; 73 class InsightAdapter { 74 public: 75 static InsightAdapter& GetInsightAdapterInstance(); 76 77 ~InsightAdapter(); 78 79 __attribute__((no_sanitize("cfi"))) bool IsSupportPlayIntent(const std::string& bundleName, 80 std::string& supportModule, std::string& profile); 81 82 bool GetPlayIntentParam(const std::string& bundleName, const std::string& assetId, 83 AppExecFwk::InsightIntentExecuteParam &executeParam, const StartPlayInfo startPlayInfo = {}, 84 StartPlayType startPlayType = StartPlayType::APP); 85 86 void SetStartPlayInfoToParam(const StartPlayInfo startPlayInfo, StartPlayType startPlayType, 87 std::shared_ptr<AppExecFwk::WantParams> &wantParam); 88 89 int32_t StartAVPlayback(AppExecFwk::InsightIntentExecuteParam &executeParam); 90 91 private: 92 InsightAdapter(); 93 94 bool CheckBundleSupport(std::string& profile); 95 96 const int32_t getBundleInfoWithHapModule = 0x00000002; 97 98 const int32_t startUserId = 100; 99 100 const int32_t interfaceType = 9; 101 102 const std::string PLAY_MUSICLIST = "PlayMusicList"; 103 104 const std::string PLAY_AUDIO = "PlayAudio"; 105 }; 106 107 } 108 #endif // ABILITY_DYNAMIC_INSIGHT_H 109 110