• 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 #include "insight_intent_utils.h"
17 
18 #include "bundle_mgr_helper.h"
19 #include "hilog_wrapper.h"
20 #include "if_system_ability_manager.h"
21 #include "in_process_call_wrapper.h"
22 #include "insight_intent_profile.h"
23 #include "iservice_registry.h"
24 #include "module_info.h"
25 #include "os_account_manager_wrapper.h"
26 #include "system_ability_definition.h"
27 
28 namespace OHOS {
29 namespace AbilityRuntime {
GetSrcEntry(const std::string & bundleName,const std::string & moduleName,const std::string & intentName)30 std::string InsightIntentUtils::GetSrcEntry(const std::string &bundleName, const std::string &moduleName,
31     const std::string &intentName)
32 {
33     HILOG_DEBUG("Get srcEntry, bundleName: %{public}s, moduleName: %{public}s, intentName: %{public}s.",
34         bundleName.c_str(), moduleName.c_str(), intentName.c_str());
35     if (bundleName.empty() || moduleName.empty() || intentName.empty()) {
36         HILOG_ERROR("Invalid param.");
37         return std::string("");
38     }
39 
40     auto bundleMgrHelper = DelayedSingleton<AppExecFwk::BundleMgrHelper>::GetInstance();
41     if (bundleMgrHelper == nullptr) {
42         return std::string("");
43     }
44 
45     // Get json profile firstly
46     std::string profile;
47     auto ret = IN_PROCESS_CALL(bundleMgrHelper->GetJsonProfile(AppExecFwk::INTENT_PROFILE, bundleName, moduleName,
48         profile, AppExecFwk::OsAccountManagerWrapper::GetCurrentActiveAccountId()));
49     if (ret != ERR_OK) {
50         HILOG_ERROR("Get json profile failed, error code: %{public}d.", ret);
51         return std::string("");
52     }
53 
54     // Transform json string
55     std::vector<InsightIntentInfo> infos;
56     if (!InsightIntentProfile::TransformTo(profile, infos)) {
57         HILOG_ERROR("Transform profile failed.");
58         return std::string("");
59     }
60 
61     // Get srcEntry when intentName matched
62     std::string srcEntry("");
63     for (const auto &info: infos) {
64         if (info.intentName == intentName) {
65             srcEntry = info.srcEntry;
66         }
67     }
68     HILOG_DEBUG("srcEntry: %{public}s", srcEntry.c_str());
69     return srcEntry;
70 }
71 } // namespace AbilityRuntime
72 } // namespace OHOS
73