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
SetUid(int32_t uid)37 void AceApplicationInfo::SetUid(int32_t uid)
38 {
39 uid_ = uid;
40 }
41
GetUid() const42 int32_t AceApplicationInfo::GetUid() const
43 {
44 return uid_;
45 }
46
SetProcessName(const std::string & processName)47 void AceApplicationInfo::SetProcessName(const std::string& processName)
48 {
49 processName_ = processName;
50 }
51
GetProcessName() const52 const std::string& AceApplicationInfo::GetProcessName() const
53 {
54 return processName_;
55 }
56
GetUnicodeSetting() const57 std::string AceApplicationInfo::GetUnicodeSetting() const
58 {
59 std::vector<std::string> keyValuePairs;
60 StringUtils::StringSpliter(keywordsAndValues_, ';', keyValuePairs);
61 auto keyValuePairsJson = JsonUtil::Create(true);
62 for (const auto& pair : keyValuePairs) {
63 // [pair] is like "nu=arab" or "nu=" for most occasions, but may be "=" under extreme scenarios
64 std::vector<std::string> res;
65 StringUtils::StringSpliter(pair, '=', res);
66 if (res.size() == 0) {
67 continue;
68 }
69 auto value = (res.size() == 2) ? res[1] : "";
70 keyValuePairsJson->Put(res[0].c_str(), value.c_str());
71 }
72 return keyValuePairsJson->ToString(); // Return a string in json format
73 }
74
75 } // namespace OHOS::Ace
76