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 #include "core/common/app_bar_helper.h"
17
18 #include "bundlemgr/bundle_mgr_interface.h"
19 #include "iservice_registry.h"
20 #include "system_ability_definition.h"
21
22 #include "core/components_ng/pattern/ui_extension/ui_extension_model_ng.h"
23
24 namespace OHOS::Ace {
25
CreateUIExtensionNode(const std::string & bundleName,const std::string & abilityName,const std::map<std::string,std::string> & params,std::function<void (int32_t)> && onRelease,std::function<void (int32_t,const std::string &,const std::string &)> && onError)26 RefPtr<NG::FrameNode> AppBarHelper::CreateUIExtensionNode(const std::string& bundleName,
27 const std::string& abilityName, const std::map<std::string, std::string>& params,
28 std::function<void(int32_t)>&& onRelease,
29 std::function<void(int32_t, const std::string&, const std::string&)>&& onError)
30 {
31 return NG::UIExtensionModelNG::Create(bundleName, abilityName, params, std::move(onRelease), std::move(onError));
32 }
33
QueryAppGalleryBundleName()34 std::string AppBarHelper::QueryAppGalleryBundleName()
35 {
36 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
37 CHECK_NULL_RETURN(systemAbilityMgr, "");
38
39 auto bundleObj = systemAbilityMgr->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
40 CHECK_NULL_RETURN(bundleObj, "");
41
42 auto bundleMgr = iface_cast<AppExecFwk::IBundleMgr>(bundleObj);
43 CHECK_NULL_RETURN(bundleMgr, "");
44
45 std::string bundleName = "";
46 auto result = bundleMgr->QueryAppGalleryBundleName(bundleName);
47 if (!result) {
48 LOGE("Query BundleName fail!");
49 } else {
50 LOGI("BundleName: %{public}s", bundleName.c_str());
51 }
52 return bundleName;
53 }
54
55 } // namespace OHOS::Ace