• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 "inner_bundle_clone_info.h"
16 
17 namespace OHOS {
18 namespace AppExecFwk {
19 namespace {
20 const std::string BUNDLE_CLONE_INFO_USER_ID = "userId";
21 const std::string BUNDLE_CLONE_INFO_APP_INDEX = "appIndex";
22 const std::string BUNDLE_CLONE_INFO_UID = "uid";
23 const std::string BUNDLE_CLONE_INFO_GIDS = "gids";
24 const std::string BUNDLE_CLONE_INFO_ENABLE = "enabled";
25 const std::string BUNDLE_CLONE_INFO_DISABLE_ABILITIES = "disabledAbilities";
26 
27 const std::string BUNDLE_CLONE_INFO_ACCESS_TOKEN_ID = "accessTokenId";
28 const std::string BUNDLE_CLONE_INFO_ACCESS_TOKEN_ID_EX = "accessTokenIdEx";
29 const std::string BUNDLE_CLONE_INFO_INSTALL_TIME = "installTime";
30 const std::string BUNDLE_CLONE_INFO_ENCRYPTED_KEY_EXISTED = "encryptedKeyExisted";
31 const std::string BUNDLE_CLONE_INFO_INFO_SET_ENABLED_CALLER = "setEnabledCaller";
32 const std::string BUNDLE_CLONE_INFO_KEY_ID = "keyId";
33 constexpr const char* INNER_BUNDLE_CLONE_INFO_CUR_DYNAMIC_ICON_MODULE = "curDynamicIconModule";
34 } // namespace
35 
to_json(nlohmann::json & jsonObject,const InnerBundleCloneInfo & bundleCloneInfo)36 void to_json(nlohmann::json& jsonObject, const InnerBundleCloneInfo& bundleCloneInfo)
37 {
38     jsonObject = nlohmann::json {
39         {BUNDLE_CLONE_INFO_USER_ID, bundleCloneInfo.userId},
40         {BUNDLE_CLONE_INFO_APP_INDEX, bundleCloneInfo.appIndex},
41         {BUNDLE_CLONE_INFO_UID, bundleCloneInfo.uid},
42         {BUNDLE_CLONE_INFO_GIDS, bundleCloneInfo.gids},
43         {BUNDLE_CLONE_INFO_ENABLE, bundleCloneInfo.enabled},
44         {BUNDLE_CLONE_INFO_DISABLE_ABILITIES, bundleCloneInfo.disabledAbilities},
45         {BUNDLE_CLONE_INFO_ACCESS_TOKEN_ID, bundleCloneInfo.accessTokenId},
46         {BUNDLE_CLONE_INFO_ACCESS_TOKEN_ID_EX, bundleCloneInfo.accessTokenIdEx},
47         {BUNDLE_CLONE_INFO_INSTALL_TIME, bundleCloneInfo.installTime},
48         {BUNDLE_CLONE_INFO_ENCRYPTED_KEY_EXISTED, bundleCloneInfo.encryptedKeyExisted},
49         {BUNDLE_CLONE_INFO_INFO_SET_ENABLED_CALLER, bundleCloneInfo.setEnabledCaller},
50         {BUNDLE_CLONE_INFO_KEY_ID, bundleCloneInfo.keyId},
51         {INNER_BUNDLE_CLONE_INFO_CUR_DYNAMIC_ICON_MODULE, bundleCloneInfo.curDynamicIconModule}
52     };
53 }
54 
from_json(const nlohmann::json & jsonObject,InnerBundleCloneInfo & bundleCloneInfo)55 void from_json(const nlohmann::json& jsonObject, InnerBundleCloneInfo& bundleCloneInfo)
56 {
57     const auto &jsonObjectEnd = jsonObject.end();
58     int32_t parseResult = ERR_OK;
59     GetValueIfFindKey<int32_t>(jsonObject, jsonObjectEnd, BUNDLE_CLONE_INFO_USER_ID,
60         bundleCloneInfo.userId, JsonType::NUMBER, false, parseResult, ArrayType::NOT_ARRAY);
61     GetValueIfFindKey<int32_t>(jsonObject, jsonObjectEnd, BUNDLE_CLONE_INFO_APP_INDEX,
62         bundleCloneInfo.appIndex, JsonType::NUMBER, false, parseResult, ArrayType::NOT_ARRAY);
63     GetValueIfFindKey<int32_t>(jsonObject, jsonObjectEnd, BUNDLE_CLONE_INFO_UID,
64         bundleCloneInfo.uid, JsonType::NUMBER, false, parseResult, ArrayType::NOT_ARRAY);
65     GetValueIfFindKey<std::vector<int32_t>>(jsonObject, jsonObjectEnd, BUNDLE_CLONE_INFO_GIDS,
66         bundleCloneInfo.gids, JsonType::ARRAY, false, parseResult, ArrayType::NUMBER);
67     BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, jsonObjectEnd, BUNDLE_CLONE_INFO_ENABLE,
68         bundleCloneInfo.enabled, false, parseResult);
69     GetValueIfFindKey<std::vector<std::string>>(jsonObject, jsonObjectEnd, BUNDLE_CLONE_INFO_DISABLE_ABILITIES,
70         bundleCloneInfo.disabledAbilities, JsonType::ARRAY, false, parseResult, ArrayType::STRING);
71     GetValueIfFindKey<uint32_t>(jsonObject, jsonObjectEnd, BUNDLE_CLONE_INFO_ACCESS_TOKEN_ID,
72         bundleCloneInfo.accessTokenId, JsonType::NUMBER, false, parseResult, ArrayType::NOT_ARRAY);
73     GetValueIfFindKey<uint64_t>(jsonObject, jsonObjectEnd, BUNDLE_CLONE_INFO_ACCESS_TOKEN_ID_EX,
74         bundleCloneInfo.accessTokenIdEx, JsonType::NUMBER, false, parseResult, ArrayType::NOT_ARRAY);
75     GetValueIfFindKey<int64_t>(jsonObject, jsonObjectEnd, BUNDLE_CLONE_INFO_INSTALL_TIME,
76         bundleCloneInfo.installTime, JsonType::NUMBER, false, parseResult, ArrayType::NOT_ARRAY);
77     BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, jsonObjectEnd, BUNDLE_CLONE_INFO_ENCRYPTED_KEY_EXISTED,
78         bundleCloneInfo.encryptedKeyExisted, false, parseResult);
79     BMSJsonUtil::GetStrValueIfFindKey(jsonObject, jsonObjectEnd, BUNDLE_CLONE_INFO_INFO_SET_ENABLED_CALLER,
80         bundleCloneInfo.setEnabledCaller, false, parseResult);
81     BMSJsonUtil::GetStrValueIfFindKey(jsonObject, jsonObjectEnd, BUNDLE_CLONE_INFO_KEY_ID,
82         bundleCloneInfo.keyId, false, parseResult);
83     BMSJsonUtil::GetStrValueIfFindKey(jsonObject, jsonObjectEnd, INNER_BUNDLE_CLONE_INFO_CUR_DYNAMIC_ICON_MODULE,
84         bundleCloneInfo.curDynamicIconModule, false, parseResult);
85     if (parseResult != ERR_OK) {
86         APP_LOGE("read module bundleCloneInfo from jsonObject error, error code : %{public}d", parseResult);
87     }
88 }
89 } // namespace AppExecFwk
90 } // namespace OHOS