1 /*
2  * Copyright (c) 2021-2022 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 "form_item_info.h"
16 #include "fms_log_wrapper.h"
17 
18 namespace OHOS {
19 namespace AppExecFwk {
20 /**
21  * @brief Get formId_.
22  * @return formId_.
23  */
GetFormId() const24 int64_t FormItemInfo::GetFormId() const
25 {
26     return formId_;
27 }
28 /**
29  * @brief Get packageName_.
30  * @return packageName_.
31  */
GetPackageName() const32 std::string FormItemInfo::GetPackageName() const
33 {
34     return packageName_;
35 }
36 /**
37  * @brief Get providerBundleName_.
38  * @return providerBundleName_.
39  */
GetProviderBundleName() const40 std::string FormItemInfo::GetProviderBundleName() const
41 {
42     return providerBundleName_;
43 }
44 /**
45  * @brief Get hostBundleName_.
46  * @return hostBundleName_.
47  */
GetHostBundleName() const48 std::string FormItemInfo::GetHostBundleName() const
49 {
50     return hostBundleName_;
51 }
52 /**
53  * @brief Get moduleName_.
54  * @return moduleName_.
55  */
GetModuleName() const56 std::string FormItemInfo::GetModuleName() const
57 {
58     return moduleName_;
59 }
60 /**
61  * @brief Get abilityName_.
62  * @return abilityName_.
63  */
GetAbilityName() const64 std::string FormItemInfo::GetAbilityName() const
65 {
66     return abilityName_;
67 }
68 /**
69  * @brief Get formName_.
70  * @return formName_.
71  */
GetFormName() const72 std::string FormItemInfo::GetFormName() const
73 {
74     return formName_;
75 }
76 /**
77  * @brief Get jsComponentName_.
78  * @return jsComponentName_.
79  */
GetJsComponentName() const80 std::string FormItemInfo::GetJsComponentName() const
81 {
82     return jsComponentName_;
83 }
84 /**
85  * @brief Get abilityModuleName_.
86  * @return abilityModuleName_.
87  */
GetAbilityModuleName() const88 std::string FormItemInfo::GetAbilityModuleName() const
89 {
90     return abilityModuleName_;
91 }
92 /**
93  * @brief Get specificationId_.
94  * @return specificationId_.
95  */
GetSpecificationId() const96 int FormItemInfo::GetSpecificationId() const
97 {
98     return specificationId_;
99 }
100 
101 /**
102  * @brief Obtains the updateFlag.
103  * @return Returns updateFlag.
104  */
IsEnableUpdateFlag() const105 bool FormItemInfo::IsEnableUpdateFlag() const
106 {
107     return updateFlag_;
108 }
109 /**
110  * @brief Get updateDuration_.
111  * @return updateDuration_.
112  */
GetUpdateDuration() const113 int FormItemInfo::GetUpdateDuration() const
114 {
115     return updateDuration_;
116 }
117 /**
118  * @brief Get scheduledUpdateTime_.
119  * @return scheduledUpdateTime_.
120  */
GetScheduledUpdateTime() const121 std::string FormItemInfo::GetScheduledUpdateTime() const
122 {
123     return scheduledUpdateTime_;
124 }
125 
126 /**
127  * @brief Get hapSourceDirs_.
128  * @param dirs Hap source dirs.
129  * @return Returns true on success, false on failure.
130  */
GetHapSourceDirs(std::vector<std::string> & dirs) const131 bool FormItemInfo::GetHapSourceDirs(std::vector<std::string> &dirs) const
132 {
133     if (hapSourceDirs_.size() > 0) {
134         dirs.assign(hapSourceDirs_.begin(), hapSourceDirs_.end());
135         return true;
136     }
137     return false;
138 }
139 /**
140  * @brief Set value of hapSourceDirs_.
141  * @param hapSourceDirs Hap source dirs.
142  */
SetHapSourceDirs(const std::vector<std::string> & hapSourceDirs)143 void FormItemInfo::SetHapSourceDirs(const std::vector<std::string> &hapSourceDirs)
144 {
145     hapSourceDirs_ = hapSourceDirs;
146 }
147 /**
148  * @brief Obtains the temporaryFlag.
149  * @return Returns temporaryFlag.
150  */
IsTemporaryForm() const151 bool FormItemInfo::IsTemporaryForm() const
152 {
153     return temporaryFlag_;
154 }
155 
156 /**
157  * @brief Obtains the hap source by ability module name.
158  * @param moduleName ability module name
159  * @return Returns hap source.
160  */
GetHapSourceByModuleName(const std::string & moduleName) const161 std::string FormItemInfo::GetHapSourceByModuleName(const std::string &moduleName) const
162 {
163     auto iter = moduleInfoMap_.find(moduleName);
164     if (iter != moduleInfoMap_.end()) {
165         return iter->second;
166     }
167     return "";
168 }
169 /**
170  * @brief Check if item valid or not.
171  * @return Valid or not
172  */
IsValidItem() const173 bool FormItemInfo::IsValidItem() const
174 {
175     if (providerBundleName_.empty() || moduleName_.empty()
176         || abilityName_.empty() || formName_.empty()) {
177         return false;
178     }
179     return true;
180 }
181 /**
182  * @brief Check if item match or not.
183  * @return Match or not
184  */
IsMatch(const FormRecord & record) const185 bool FormItemInfo::IsMatch(const FormRecord &record) const
186 {
187     HILOG_DEBUG("match data");
188     HILOG_DEBUG("FormRecord.bundleName :%{public}s", record.bundleName.c_str());
189     HILOG_DEBUG("FormRecord.moduleName :%{public}s", record.moduleName.c_str());
190     HILOG_DEBUG("FormRecord.abilityName :%{public}s", record.abilityName.c_str());
191     HILOG_DEBUG("FormRecord.formName :%{public}s", record.formName.c_str());
192     HILOG_DEBUG("FormRecord.specification :%{public}d", record.specification);
193 
194     HILOG_DEBUG("FormItemInfo.providerBundleName_ :%{public}s", providerBundleName_.c_str());
195     HILOG_DEBUG("FormItemInfo.moduleName :%{public}s", moduleName_.c_str());
196     HILOG_DEBUG("FormItemInfo.abilityName :%{public}s", abilityName_.c_str());
197     HILOG_DEBUG("FormItemInfo.formName :%{public}s", formName_.c_str());
198     HILOG_DEBUG("FormItemInfo.specification :%{public}d", specificationId_);
199 
200     return (record.bundleName == providerBundleName_) && (record.moduleName == moduleName_)
201         && (record.abilityName == abilityName_) && (record.formName == formName_)
202         && (record.specification == specificationId_);
203 }
204 /**
205  * @brief Check if form config same or not.
206  * @return Same or not
207  */
IsSameFormConfig(const FormRecord & record) const208 bool FormItemInfo::IsSameFormConfig(const FormRecord &record) const
209 {
210     return (record.bundleName == providerBundleName_) && (record.moduleName == moduleName_)
211         && (record.abilityName == abilityName_) && (record.formName == formName_);
212 }
213 
214 /**
215  * @brief Check if visible notify or not.
216  * @return visible notify or not
217  */
IsFormVisibleNotify() const218 bool FormItemInfo::IsFormVisibleNotify() const
219 {
220     return formVisibleNotify_;
221 }
222 /**
223  * @brief Equal or not.
224  * @param left left string.
225  * @param right right string.
226  * @return Equal or not
227  */
IsEqual(const std::string & left,const std::string & right)228 bool FormItemInfo::IsEqual(const std::string &left, const std::string &right)
229 {
230     return left == right;
231 }
232 /**
233  * @brief Set value of formId_.
234  * @param formId Form Id.
235  */
SetFormId(int64_t formId)236 void FormItemInfo::SetFormId(int64_t formId)
237 {
238     formId_ = formId;
239 }
240 /**
241  * @brief Set value of packageName_.
242  * @param packageName Package name.
243  */
SetPackageName(const std::string & packageName)244 void FormItemInfo::SetPackageName(const std::string &packageName)
245 {
246     packageName_ = packageName;
247 }
248 /**
249  * @brief Set value of providerBundleName_.
250  * @param providerBundleName Provider bundle Name.
251  */
SetProviderBundleName(const std::string & providerBundleName)252 void FormItemInfo::SetProviderBundleName(const std::string &providerBundleName)
253 {
254     providerBundleName_ = providerBundleName;
255 }
256 /**
257  * @brief Set value of hostBundleName_.
258  * @param hostBundleName Host bundle Name.
259  */
SetHostBundleName(const std::string & hostBundleName)260 void FormItemInfo::SetHostBundleName(const std::string &hostBundleName)
261 {
262     hostBundleName_ = hostBundleName;
263 }
264 /**
265  * @brief Set value of moduleName_.
266  * @param moduleName Module Name.
267  */
SetModuleName(const std::string & moduleName)268 void FormItemInfo::SetModuleName(const std::string &moduleName)
269 {
270     moduleName_ = moduleName;
271 }
272 /**
273  * @brief Set value of abilityName_.
274  * @param abilityName Ability name.
275  */
SetAbilityName(const std::string & abilityName)276 void FormItemInfo::SetAbilityName(const std::string &abilityName)
277 {
278     abilityName_ = abilityName;
279 }
280 /**
281  * @brief Set value of formName_.
282  * @param formName Form name.
283  */
SetFormName(const std::string & formName)284 void FormItemInfo::SetFormName(const std::string &formName)
285 {
286     formName_ = formName;
287 }
288 /**
289  * @brief Set value of jsComponentName_.
290  * @param jsComponentName Js component name.
291  */
SetJsComponentName(const std::string & jsComponentName)292 void FormItemInfo::SetJsComponentName(const std::string &jsComponentName)
293 {
294     jsComponentName_ = jsComponentName;
295 }
296 /**
297  * @brief Set value of abilityModuleName_.
298  * @param abilityModuleName ability module name_.
299  */
SetAbilityModuleName(const std::string & abilityModuleName)300 void FormItemInfo::SetAbilityModuleName(const std::string &abilityModuleName)
301 {
302     abilityModuleName_ = abilityModuleName;
303 }
304 /**
305  * @brief Set value of specificationId_.
306  * @param specificationId Specification id.
307  */
SetSpecificationId(const int specificationId)308 void FormItemInfo::SetSpecificationId(const int specificationId)
309 {
310     specificationId_ = specificationId;
311 }
312 /**
313  * @brief Set value of updateFlag_.
314  * @param isEnableUpdateFlag Enable update flag or not.
315  */
SetEnableUpdateFlag(bool isEnableUpdateFlag)316 void FormItemInfo::SetEnableUpdateFlag(bool isEnableUpdateFlag)
317 {
318     updateFlag_ = isEnableUpdateFlag;
319 }
320 /**
321  * @brief Set value of updateDuration_.
322  * @param updateDuration Update duration.
323  */
SetUpdateDuration(int updateDuration)324 void FormItemInfo::SetUpdateDuration(int updateDuration)
325 {
326     updateDuration_ = updateDuration;
327 }
328 /**
329  * @brief Set value of scheduledUpdateTime_.
330  * @param scheduledUpdateTime Scheduled update time.
331  */
SetScheduledUpdateTime(const std::string & scheduledUpdateTime)332 void FormItemInfo::SetScheduledUpdateTime(const std::string &scheduledUpdateTime)
333 {
334     scheduledUpdateTime_ = scheduledUpdateTime;
335 }
336 /**
337  * @brief Add hap source dir.
338  * @param hapSourceDir Hap source dir.
339  */
AddHapSourceDirs(const std::string & hapSourceDir)340 void FormItemInfo::AddHapSourceDirs(const std::string &hapSourceDir)
341 {
342     hapSourceDirs_.emplace_back(hapSourceDir);
343 }
344 /**
345  * @brief Set value of temporaryFlag_.
346  * @param temporaryFlag Temporary flag.
347  */
SetTemporaryFlag(bool temporaryFlag)348 void FormItemInfo::SetTemporaryFlag(bool temporaryFlag)
349 {
350     temporaryFlag_ = temporaryFlag;
351 }
352 /**
353  * @brief Add module info.
354  * @param moduleName Module name.
355  * @param moduleSourceDir Module source dir.
356  */
AddModuleInfo(const std::string & moduleName,const std::string & moduleSourceDir)357 void FormItemInfo::AddModuleInfo(const std::string &moduleName, const std::string &moduleSourceDir)
358 {
359     moduleInfoMap_.emplace(std::make_pair(moduleName, moduleSourceDir));
360 }
361 
AddModulePkgName(const std::string & moduleName,const std::string & packageName)362 void FormItemInfo::AddModulePkgName(const std::string &moduleName, const std::string &packageName)
363 {
364     modulePkgNameMap_.emplace(std::make_pair(moduleName, packageName));
365 }
366 
GetModulePkgNameMap() const367 const std::map<std::string, std::string>& FormItemInfo::GetModulePkgNameMap() const
368 {
369     return modulePkgNameMap_;
370 }
371 
372 /**
373  * @brief Set value of formVisibleNotify_.
374  * @param isFormVisibleNotify visible notify or not.
375  */
SetFormVisibleNotify(bool isFormVisibleNotify)376 void FormItemInfo::SetFormVisibleNotify(bool isFormVisibleNotify)
377 {
378     formVisibleNotify_ = isFormVisibleNotify;
379 }
380 /**
381  * @brief Get formSrc_.
382  * @return formSrc_.
383  */
GetFormSrc() const384 std::string FormItemInfo::GetFormSrc() const
385 {
386     return formSrc_;
387 }
388 /**
389  * @brief Set value of formSrc_.
390  * @param formSrc form src.
391  */
SetFormSrc(const std::string & formSrc)392 void FormItemInfo::SetFormSrc(const std::string &formSrc)
393 {
394     formSrc_ = formSrc;
395 }
396 /**
397  * @brief Get formWindow_.
398  * @return formWindow_.
399  */
GetFormWindow() const400 FormWindow FormItemInfo::GetFormWindow() const
401 {
402     return formWindow_;
403 }
404 /**
405  * @brief Set value of formWindow_.
406  * @param formWindow form window.
407  */
SetFormWindow(const FormWindow & formWindow)408 void FormItemInfo::SetFormWindow(const FormWindow &formWindow)
409 {
410     formWindow_.autoDesignWidth = formWindow.autoDesignWidth;
411     formWindow_.designWidth = formWindow.designWidth;
412 }
413 /**
414  * @brief Get versionCode_.
415  * @return versionCode_.
416  */
GetVersionCode() const417 uint32_t FormItemInfo::GetVersionCode() const
418 {
419     return versionCode_;
420 }
421 /**
422  * @brief Set value of versionCode_.
423  * @param versionCode bundle version code.
424  */
SetVersionCode(const uint32_t versionCode)425 void FormItemInfo::SetVersionCode(const uint32_t versionCode)
426 {
427     versionCode_ = versionCode;
428 }
429 /**
430  * @brief Get versionName_.
431  * @return versionName_.
432  */
GetVersionName() const433 std::string FormItemInfo::GetVersionName() const
434 {
435     return versionName_;
436 }
437 /**
438  * @brief Set value of versionName_.
439  * @param versionName bundle version name.
440  */
SetVersionName(const std::string & versionName)441 void FormItemInfo::SetVersionName(const std::string &versionName)
442 {
443     versionName_ = versionName;
444 }
445 /**
446  * @brief Get compatibleVersion_.
447  * @return compatibleVersion_.
448  */
GetCompatibleVersion() const449 uint32_t FormItemInfo::GetCompatibleVersion() const
450 {
451     return compatibleVersion_;
452 }
453 /**
454  * @brief Set value of compatibleVersion_.
455  * @param compatibleVersion bundle version name.
456  */
SetCompatibleVersion(const uint32_t & compatibleVersion)457 void FormItemInfo::SetCompatibleVersion(const uint32_t &compatibleVersion)
458 {
459     compatibleVersion_ = compatibleVersion;
460 }
461 /**
462  * @brief Get icon_.
463  * @return icon_.
464  */
GetIcon() const465 std::string FormItemInfo::GetIcon() const
466 {
467     return icon_;
468 }
469 /**
470  * @brief Get deviceId_.
471  * @return deviceId_.
472  */
GetDeviceId()473 std::string FormItemInfo::GetDeviceId()
474 {
475     return deviceId_;
476 }
477 
478 /**
479  * @brief Set value of  deviceId_.
480  * @param deviceId.
481  */
SetDeviceId(const std::string & deviceId)482 void FormItemInfo::SetDeviceId(const std::string &deviceId)
483 {
484     deviceId_ = deviceId;
485 }
486 
GetType() const487 FormType FormItemInfo::GetType() const
488 {
489     return type_;
490 }
491 
SetType(const FormType & type)492 void FormItemInfo::SetType(const FormType &type)
493 {
494     type_ = type;
495 }
496 
IsDynamic() const497 bool FormItemInfo::IsDynamic() const
498 {
499     return isDynamic_;
500 }
501 
SetIsDynamic(bool isDynamic)502 void FormItemInfo::SetIsDynamic(bool isDynamic)
503 {
504     isDynamic_ = isDynamic;
505 }
506 
IsTransparencyEnabled() const507 bool FormItemInfo::IsTransparencyEnabled() const
508 {
509     return transparencyEnabled_;
510 }
511 
SetTransparencyEnabled(bool isTransparencyEnabled)512 void FormItemInfo::SetTransparencyEnabled(bool isTransparencyEnabled)
513 {
514     transparencyEnabled_ = isTransparencyEnabled;
515 }
516 
GetPrivacyLevel() const517 int32_t FormItemInfo::GetPrivacyLevel() const
518 {
519     return privacyLevel_;
520 }
521 
SetPrivacyLevel(int32_t level)522 void FormItemInfo::SetPrivacyLevel(int32_t level)
523 {
524     privacyLevel_ = level;
525 }
526 
GetUiSyntax() const527 FormType FormItemInfo::GetUiSyntax() const
528 {
529     return uiSyntax_;
530 }
531 
SetUiSyntax(const FormType & uiSyntax)532 void FormItemInfo::SetUiSyntax(const FormType &uiSyntax)
533 {
534     uiSyntax_ = uiSyntax;
535 }
536 
SetSystemAppFlag(bool isSystemApp)537 void FormItemInfo::SetSystemAppFlag(bool isSystemApp)
538 {
539     isSystemApp_ = isSystemApp;
540 }
541 
GetSystemAppFlag() const542 bool FormItemInfo::GetSystemAppFlag() const
543 {
544     return isSystemApp_;
545 }
546 
SetDataProxyFlag(bool dataProxyEnabled)547 void FormItemInfo::SetDataProxyFlag(bool dataProxyEnabled)
548 {
549     dataProxyEnabled_ = dataProxyEnabled;
550 }
551 
GetDataProxyFlag() const552 bool FormItemInfo::GetDataProxyFlag() const
553 {
554     return dataProxyEnabled_;
555 }
556 
SetProviderUid(int32_t uid)557 void FormItemInfo::SetProviderUid(int32_t uid)
558 {
559     uid_ = uid;
560 }
561 
GetProviderUid() const562 int32_t FormItemInfo::GetProviderUid() const
563 {
564     return uid_;
565 }
566 
SetDescription(const std::string & description)567 void FormItemInfo::SetDescription(const std::string &description)
568 {
569     description_ = description;
570 }
571 
GetDescription() const572 std::string FormItemInfo::GetDescription() const
573 {
574     return description_;
575 }
576 
GetFormLocation() const577 Constants::FormLocation FormItemInfo::GetFormLocation() const
578 {
579     return formLocation_;
580 }
581 
SetFormLocation(Constants::FormLocation formLocation)582 void FormItemInfo::SetFormLocation(Constants::FormLocation formLocation)
583 {
584     formLocation_ = formLocation;
585 }
586 
GetIsThemeForm() const587 bool FormItemInfo::GetIsThemeForm() const
588 {
589     return isThemeForm_;
590 }
591 
SetIsThemeForm(bool isThemeForm)592 void FormItemInfo::SetIsThemeForm(bool isThemeForm)
593 {
594     isThemeForm_ = isThemeForm;
595 }
596 
GetFormBundleType() const597 BundleType FormItemInfo::GetFormBundleType() const
598 {
599     return bundleType_;
600 }
601 
SetFormBundleType(BundleType formBundleType)602 void FormItemInfo::SetFormBundleType(BundleType formBundleType)
603 {
604     bundleType_ = formBundleType;
605 }
606 
IsEnableForm() const607 bool FormItemInfo::IsEnableForm() const
608 {
609     return enableForm_;
610 }
611 
SetEnableForm(bool enableForm)612 void FormItemInfo::SetEnableForm(bool enableForm)
613 {
614     enableForm_ = enableForm;
615 }
616 
GetRenderingMode() const617 Constants::RenderingMode FormItemInfo::GetRenderingMode() const
618 {
619     return renderingMode_;
620 }
621 
SetRenderingMode(Constants::RenderingMode renderingMode)622 void FormItemInfo::SetRenderingMode(Constants::RenderingMode renderingMode)
623 {
624     renderingMode_ = renderingMode;
625 }
626 }  // namespace AppExecFwk
627 }  // namespace OHOS