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 #define LOG_TAG "PreProcessUtils"
16
17 #include "preprocess_utils.h"
18
19 #include "bundle_info.h"
20 #include "dds_trace.h"
21 #include "udmf_radar_reporter.h"
22 #include "accesstoken_kit.h"
23 #include "device_manager_adapter.h"
24 #include "file_mount_manager.h"
25 #include "iservice_registry.h"
26 #include "log_print.h"
27 #include "system_ability_definition.h"
28 #include "udmf_radar_reporter.h"
29 #include "udmf_utils.h"
30 #include "utils/crypto.h"
31 #include "uri_permission_manager_client.h"
32 #include "ipc_skeleton.h"
33 #include "bundle_mgr_interface.h"
34 namespace OHOS {
35 namespace UDMF {
36 using namespace OHOS::DistributedDataDfx;
37 using namespace Security::AccessToken;
38 using namespace OHOS::AppFileService::ModuleRemoteFileShare;
39 using namespace RadarReporter;
40
FillRuntimeInfo(UnifiedData & data,CustomOption & option)41 int32_t PreProcessUtils::FillRuntimeInfo(UnifiedData &data, CustomOption &option)
42 {
43 auto it = UD_INTENTION_MAP.find(option.intention);
44 if (it == UD_INTENTION_MAP.end()) {
45 return E_ERROR;
46 }
47 std::string bundleName = "bundleName";
48 std::string intention = it->second;
49 UnifiedKey key(intention, bundleName, GenerateId());
50 Privilege privilege;
51 privilege.tokenId = option.tokenId;
52
53 Runtime runtime;
54 runtime.key = key;
55 runtime.privileges.emplace_back(privilege);
56 runtime.createTime = GetTimestamp();
57 runtime.sourcePackage = bundleName;
58 runtime.createPackage = bundleName;
59 runtime.recordTotalNum = static_cast<uint32_t>(data.GetRecords().size());
60 runtime.tokenId = option.tokenId;
61 runtime.visibility = option.visibility;
62 runtime.appId = "appId";
63 data.SetRuntime(runtime);
64 return E_OK;
65 }
66
GenerateId()67 std::string PreProcessUtils::GenerateId()
68 {
69 return "1122ac";
70 }
71
GetTimestamp()72 time_t PreProcessUtils::GetTimestamp()
73 {
74 std::chrono::time_point<std::chrono::system_clock, std::chrono::milliseconds> tp =
75 std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::system_clock::now());
76 time_t timestamp = tp.time_since_epoch().count();
77 return timestamp;
78 }
79
GetHapUidByToken(uint32_t tokenId,int & userId)80 int32_t PreProcessUtils::GetHapUidByToken(uint32_t tokenId, int &userId)
81 {
82 return E_OK;
83 }
84
GetHapBundleNameByToken(uint32_t tokenId,std::string & bundleName)85 bool PreProcessUtils::GetHapBundleNameByToken(uint32_t tokenId, std::string &bundleName)
86 {
87 bundleName = "processName";
88 return true;
89 }
90
GetNativeProcessNameByToken(uint32_t tokenId,std::string & processName)91 bool PreProcessUtils::GetNativeProcessNameByToken(uint32_t tokenId, std::string &processName)
92 {
93 processName = "processName";
94 return true;
95 }
96
GetLocalDeviceId()97 std::string PreProcessUtils::GetLocalDeviceId()
98 {
99 return "123";
100 }
101
SetRemoteData(UnifiedData & data)102 void PreProcessUtils::SetRemoteData(UnifiedData &data)
103 {
104 return;
105 }
106
SetRemoteUri(uint32_t tokenId,UnifiedData & data)107 int32_t PreProcessUtils::SetRemoteUri(uint32_t tokenId, UnifiedData &data)
108 {
109 return E_OK;
110 }
111
GetInstIndex(uint32_t tokenId,int32_t & instIndex)112 bool PreProcessUtils::GetInstIndex(uint32_t tokenId, int32_t &instIndex)
113 {
114 return true;
115 }
116
IsNetworkingEnabled()117 bool PreProcessUtils::IsNetworkingEnabled()
118 {
119 return true;
120 }
121
ProcessFileType(std::vector<std::shared_ptr<UnifiedRecord>> records,std::function<bool (std::shared_ptr<Object>)> callback)122 void PreProcessUtils::ProcessFileType(std::vector<std::shared_ptr<UnifiedRecord>> records,
123 std::function<bool(std::shared_ptr<Object>)> callback)
124 {
125 return;
126 }
127
ProcessRecord(std::shared_ptr<UnifiedRecord> record,uint32_t tokenId,bool isLocal,std::vector<std::string> & uris)128 void PreProcessUtils::ProcessRecord(std::shared_ptr<UnifiedRecord> record, uint32_t tokenId,
129 bool isLocal, std::vector<std::string> &uris)
130 {
131 return;
132 }
133
GetHtmlFileUris(uint32_t tokenId,UnifiedData & data,bool isLocal,std::vector<std::string> & uris)134 void PreProcessUtils::GetHtmlFileUris(uint32_t tokenId, UnifiedData &data,
135 bool isLocal, std::vector<std::string> &uris)
136 {
137 return;
138 }
139
ClearHtmlDfsUris(UnifiedData & data)140 void PreProcessUtils::ClearHtmlDfsUris(UnifiedData &data)
141 {
142 return;
143 }
144
ProcessHtmlFileUris(uint32_t tokenId,UnifiedData & data,bool isLocal,std::vector<Uri> & uris)145 void PreProcessUtils::ProcessHtmlFileUris(uint32_t tokenId, UnifiedData &data, bool isLocal, std::vector<Uri> &uris)
146 {
147 return;
148 }
149
SetRecordUid(UnifiedData & data)150 void PreProcessUtils::SetRecordUid(UnifiedData &data)
151 {
152 return;
153 }
154
GetDetailsFromUData(const UnifiedData & data,UDDetails & details)155 bool PreProcessUtils::GetDetailsFromUData(const UnifiedData &data, UDDetails &details)
156 {
157 return true;
158 }
159
GetSummaryFromDetails(const UDDetails & details,Summary & summary)160 Status PreProcessUtils::GetSummaryFromDetails(const UDDetails &details, Summary &summary)
161 {
162 return E_OK;
163 }
164
GetBundleMgr()165 sptr<AppExecFwk::IBundleMgr> PreProcessUtils::GetBundleMgr()
166 {
167 auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
168 if (samgrProxy == nullptr) {
169 ZLOGE("Failed to get system ability mgr.");
170 return nullptr;
171 }
172 auto bundleMgrProxy = samgrProxy->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
173 if (bundleMgrProxy == nullptr) {
174 ZLOGE("Failed to Get BMS SA.");
175 return nullptr;
176 }
177 auto bundleManager = iface_cast<AppExecFwk::IBundleMgr>(bundleMgrProxy);
178 if (bundleManager == nullptr) {
179 ZLOGE("Failed to get bundle manager");
180 return nullptr;
181 }
182 return bundleManager;
183 }
184
GetSpecificBundleName(const std::string & bundleName,int32_t appIndex,std::string & specificBundleName)185 bool PreProcessUtils::GetSpecificBundleName(const std::string &bundleName, int32_t appIndex,
186 std::string &specificBundleName)
187 {
188 return true;
189 }
190
GetSpecificBundleNameByTokenId(uint32_t tokenId,std::string & specificBundleName,std::string & bundleName)191 bool PreProcessUtils::GetSpecificBundleNameByTokenId(uint32_t tokenId, std::string &specificBundleName,
192 std::string &bundleName)
193 {
194 specificBundleName = "specificBundleName";
195 bundleName = "bundleName";
196 return true;
197 }
198 } // namespace UDMF
199 } // namespace OHOS