• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #include <securec.h>
16 #include "ability_manager_client.h"
17 #include "bundle_mgr_interface.h"
18 #include "iservice_registry.h"
19 #include "softbus_error_code.h"
20 #include "system_ability_definition.h"
21 
22 using namespace OHOS;
23 
StartAbility(const char * bundleName,const char * abilityName)24 extern "C" int32_t StartAbility(const char *bundleName, const char *abilityName)
25 {
26     OHOS::AAFwk::Want want;
27     want.SetElementName(bundleName, abilityName);
28     return OHOS::AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want);
29 }
30 
GetBundleMgr()31 static sptr<AppExecFwk::IBundleMgr> GetBundleMgr()
32 {
33     sptr<ISystemAbilityManager> systemAbilityManager =
34         SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
35     if (systemAbilityManager == nullptr) {
36         return nullptr;
37     }
38     sptr<IRemoteObject> remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
39     if (remoteObject == nullptr) {
40         return nullptr;
41     }
42     return iface_cast<AppExecFwk::IBundleMgr>(remoteObject);
43 }
44 
ProxyChannelMgrGetAbilityName(char * abilityName,int32_t userId,uint32_t abilityNameLen,std::string bundleName)45 extern "C" int32_t ProxyChannelMgrGetAbilityName(char *abilityName, int32_t userId, uint32_t abilityNameLen,
46     std::string bundleName)
47 {
48     AAFwk::Want want;
49     want.SetElementName(bundleName, "");
50     want.SetAction("action.ohos.pull.listener");
51 
52     std::vector<AppExecFwk::AbilityInfo> abilityInfos;
53     auto bundleMgr = GetBundleMgr();
54     if (bundleMgr == nullptr) {
55         return SOFTBUS_TRANS_GET_BUNDLE_MGR_FAILED;
56     }
57     auto flag = static_cast<int32_t>(AppExecFwk::GetAbilityInfoFlag::GET_ABILITY_INFO_DEFAULT);
58     int32_t ret = bundleMgr->QueryAbilityInfosV9(want, flag, userId, abilityInfos);
59     if (ret != SOFTBUS_OK) {
60         return ret;
61     }
62     if (strcpy_s(abilityName, abilityNameLen, abilityInfos[0].name.c_str()) != EOK) {
63         return SOFTBUS_STRCPY_ERR;
64     }
65     return SOFTBUS_OK;
66 }