1 /*
2 * Copyright (c) 2021 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 "core/common/ace_application_info.h"
17
18 #include <thread>
19
20 #include "base/json/json_util.h"
21 #include "base/log/log.h"
22 #include "base/utils/string_utils.h"
23 #include "core/common/ace_page.h"
24
25 namespace OHOS::Ace {
26
SetPackageName(const std::string & packageName)27 void AceApplicationInfo::SetPackageName(const std::string& packageName)
28 {
29 packageName_ = packageName;
30 }
31
GetPackageName() const32 const std::string& AceApplicationInfo::GetPackageName() const
33 {
34 return packageName_;
35 }
36
GetAbilityName() const37 const std::string& AceApplicationInfo::GetAbilityName() const
38 {
39 return abilityName_;
40 }
41
SetAbilityName(const std::string & abilityName)42 void AceApplicationInfo::SetAbilityName(const std::string& abilityName)
43 {
44 abilityName_ = abilityName;
45 }
SetUid(int32_t uid)46 void AceApplicationInfo::SetUid(int32_t uid)
47 {
48 uid_ = uid;
49 }
50
GetUid() const51 int32_t AceApplicationInfo::GetUid() const
52 {
53 return uid_;
54 }
55
SetProcessName(const std::string & processName)56 void AceApplicationInfo::SetProcessName(const std::string& processName)
57 {
58 processName_ = processName;
59 }
60
GetProcessName() const61 const std::string& AceApplicationInfo::GetProcessName() const
62 {
63 return processName_;
64 }
65
GetUnicodeSetting() const66 std::string AceApplicationInfo::GetUnicodeSetting() const
67 {
68 std::vector<std::string> keyValuePairs;
69 StringUtils::StringSplitter(keywordsAndValues_, ';', keyValuePairs);
70 auto keyValuePairsJson = JsonUtil::Create(true);
71 for (const auto& pair : keyValuePairs) {
72 // [pair] is like "nu=arab" or "nu=" for most occasions, but may be "=" under extreme scenarios
73 std::vector<std::string> res;
74 StringUtils::StringSplitter(pair, '=', res);
75 if (res.size() == 0) {
76 continue;
77 }
78 auto value = (res.size() == 2) ? res[1] : "";
79 keyValuePairsJson->Put(res[0].c_str(), value.c_str());
80 }
81 return keyValuePairsJson->ToString(); // Return a string in json format
82 }
83
84 } // namespace OHOS::Ace
85