• 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 } // namespace
34 
to_json(nlohmann::json & jsonObject,const InnerBundleCloneInfo & bundleCloneInfo)35 void to_json(nlohmann::json& jsonObject, const InnerBundleCloneInfo& bundleCloneInfo)
36 {
37     jsonObject = nlohmann::json {
38         {BUNDLE_CLONE_INFO_USER_ID, bundleCloneInfo.userId},
39         {BUNDLE_CLONE_INFO_APP_INDEX, bundleCloneInfo.appIndex},
40         {BUNDLE_CLONE_INFO_UID, bundleCloneInfo.uid},
41         {BUNDLE_CLONE_INFO_GIDS, bundleCloneInfo.gids},
42         {BUNDLE_CLONE_INFO_ENABLE, bundleCloneInfo.enabled},
43         {BUNDLE_CLONE_INFO_DISABLE_ABILITIES, bundleCloneInfo.disabledAbilities},
44         {BUNDLE_CLONE_INFO_ACCESS_TOKEN_ID, bundleCloneInfo.accessTokenId},
45         {BUNDLE_CLONE_INFO_ACCESS_TOKEN_ID_EX, bundleCloneInfo.accessTokenIdEx},
46         {BUNDLE_CLONE_INFO_INSTALL_TIME, bundleCloneInfo.installTime},
47         {BUNDLE_CLONE_INFO_ENCRYPTED_KEY_EXISTED, bundleCloneInfo.encryptedKeyExisted},
48         {BUNDLE_CLONE_INFO_INFO_SET_ENABLED_CALLER, bundleCloneInfo.setEnabledCaller},
49         {BUNDLE_CLONE_INFO_KEY_ID, bundleCloneInfo.keyId}
50     };
51 }
52 
from_json(const nlohmann::json & jsonObject,InnerBundleCloneInfo & bundleCloneInfo)53 void from_json(const nlohmann::json& jsonObject, InnerBundleCloneInfo& bundleCloneInfo)
54 {
55     const auto &jsonObjectEnd = jsonObject.end();
56     int32_t parseResult = ERR_OK;
57     GetValueIfFindKey<int32_t>(jsonObject, jsonObjectEnd, BUNDLE_CLONE_INFO_USER_ID,
58         bundleCloneInfo.userId, JsonType::NUMBER, false, parseResult, ArrayType::NOT_ARRAY);
59     GetValueIfFindKey<int32_t>(jsonObject, jsonObjectEnd, BUNDLE_CLONE_INFO_APP_INDEX,
60         bundleCloneInfo.appIndex, JsonType::NUMBER, false, parseResult, ArrayType::NOT_ARRAY);
61     GetValueIfFindKey<int32_t>(jsonObject, jsonObjectEnd, BUNDLE_CLONE_INFO_UID,
62         bundleCloneInfo.uid, JsonType::NUMBER, false, parseResult, ArrayType::NOT_ARRAY);
63     GetValueIfFindKey<std::vector<int32_t>>(jsonObject, jsonObjectEnd, BUNDLE_CLONE_INFO_GIDS,
64         bundleCloneInfo.gids, JsonType::ARRAY, false, parseResult, ArrayType::NUMBER);
65     BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, jsonObjectEnd, BUNDLE_CLONE_INFO_ENABLE,
66         bundleCloneInfo.enabled, false, parseResult);
67     GetValueIfFindKey<std::vector<std::string>>(jsonObject, jsonObjectEnd, BUNDLE_CLONE_INFO_DISABLE_ABILITIES,
68         bundleCloneInfo.disabledAbilities, JsonType::ARRAY, false, parseResult, ArrayType::STRING);
69     GetValueIfFindKey<uint32_t>(jsonObject, jsonObjectEnd, BUNDLE_CLONE_INFO_ACCESS_TOKEN_ID,
70         bundleCloneInfo.accessTokenId, JsonType::NUMBER, false, parseResult, ArrayType::NOT_ARRAY);
71     GetValueIfFindKey<uint64_t>(jsonObject, jsonObjectEnd, BUNDLE_CLONE_INFO_ACCESS_TOKEN_ID_EX,
72         bundleCloneInfo.accessTokenIdEx, JsonType::NUMBER, false, parseResult, ArrayType::NOT_ARRAY);
73     GetValueIfFindKey<int64_t>(jsonObject, jsonObjectEnd, BUNDLE_CLONE_INFO_INSTALL_TIME,
74         bundleCloneInfo.installTime, JsonType::NUMBER, false, parseResult, ArrayType::NOT_ARRAY);
75     BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, jsonObjectEnd, BUNDLE_CLONE_INFO_ENCRYPTED_KEY_EXISTED,
76         bundleCloneInfo.encryptedKeyExisted, false, parseResult);
77     BMSJsonUtil::GetStrValueIfFindKey(jsonObject, jsonObjectEnd, BUNDLE_CLONE_INFO_INFO_SET_ENABLED_CALLER,
78         bundleCloneInfo.setEnabledCaller, false, parseResult);
79     BMSJsonUtil::GetStrValueIfFindKey(jsonObject, jsonObjectEnd, BUNDLE_CLONE_INFO_KEY_ID,
80         bundleCloneInfo.keyId, false, parseResult);
81     if (parseResult != ERR_OK) {
82         APP_LOGE("read module bundleCloneInfo from jsonObject error, error code : %{public}d", parseResult);
83     }
84 }
85 } // namespace AppExecFwk
86 } // namespace OHOS