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 namespace OHOS::Ace {
19 
SetPackageName(const std::string & packageName)20 void AceApplicationInfo::SetPackageName(const std::string& packageName)
21 {
22     packageName_ = packageName;
23 }
24 
GetPackageName() const25 const std::string& AceApplicationInfo::GetPackageName() const
26 {
27     return packageName_;
28 }
29 
GetAbilityName() const30 const std::string& AceApplicationInfo::GetAbilityName() const
31 {
32     return abilityName_;
33 }
34 
SetAbilityName(const std::string & abilityName)35 void AceApplicationInfo::SetAbilityName(const std::string& abilityName)
36 {
37     abilityName_ = abilityName;
38 }
SetUid(int32_t uid)39 void AceApplicationInfo::SetUid(int32_t uid)
40 {
41     uid_ = uid;
42 }
43 
GetUid() const44 int32_t AceApplicationInfo::GetUid() const
45 {
46     return uid_;
47 }
48 
SetProcessName(const std::string & processName)49 void AceApplicationInfo::SetProcessName(const std::string& processName)
50 {
51     processName_ = processName;
52 }
53 
GetProcessName() const54 const std::string& AceApplicationInfo::GetProcessName() const
55 {
56     return processName_;
57 }
58 
GetUnicodeSetting() const59 std::string AceApplicationInfo::GetUnicodeSetting() const
60 {
61     std::vector<std::string> keyValuePairs;
62     StringUtils::StringSplitter(keywordsAndValues_, ';', keyValuePairs);
63     auto keyValuePairsJson = JsonUtil::Create(true);
64     for (const auto& pair : keyValuePairs) {
65         // [pair] is like "nu=arab" or "nu=" for most occasions, but may be "=" under extreme scenarios
66         std::vector<std::string> res;
67         StringUtils::StringSplitter(pair, '=', res);
68         if (res.size() == 0) {
69             continue;
70         }
71         auto value = (res.size() == 2) ? res[1] : "";
72         keyValuePairsJson->Put(res[0].c_str(), value.c_str());
73     }
74     return keyValuePairsJson->ToString(); // Return a string in json format
75 }
76 
77 } // namespace OHOS::Ace
78