1 /*
2  * Copyright (c) 2024 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 "multi_app_utils.h"
17 
18 #include "app_mgr_util.h"
19 #include "hilog_tag_wrapper.h"
20 #include "in_process_call_wrapper.h"
21 #include "running_multi_info.h"
22 
23 namespace OHOS {
24 namespace AAFwk {
GetRunningMultiAppIndex(const std::string &bundleName, int32_t uid, int32_t &appIndex)25 void MultiAppUtils::GetRunningMultiAppIndex(const std::string &bundleName, int32_t uid, int32_t &appIndex)
26 {
27     AppExecFwk::RunningMultiAppInfo runningMultiAppInfo;
28     auto appMgr = AppMgrUtil::GetAppMgr();
29     if (appMgr == nullptr) {
30         TAG_LOGW(AAFwkTag::ABILITYMGR, "AppMgrUtil::GetAppMgr failed");
31         return;
32     }
33     auto ret = IN_PROCESS_CALL(appMgr->GetRunningMultiAppInfoByBundleName(bundleName, runningMultiAppInfo));
34     if (ret != ERR_OK) {
35         TAG_LOGW(AAFwkTag::ABILITYMGR, "getAppInfo failed, bundle:%{public}s",
36             bundleName.c_str());
37     }
38     for (auto &item : runningMultiAppInfo.runningAppClones) {
39         if (item.uid == uid) {
40             appIndex = item.appCloneIndex;
41             break;
42         }
43     }
44 }
45 }  // namespace AAFwk
46 }  // namespace OHOS