1 /*
2 * Copyright (c) 2023 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 "ipc/code_signature_param.h"
17
18 #include "bundle_constants.h"
19 #include "nlohmann/json.hpp"
20 #include "parcel_macro.h"
21 #include "string_ex.h"
22
23 namespace OHOS {
24 namespace AppExecFwk {
25 namespace {
26 const std::string CODE_SIGNATURE_MODULE_PATH = "modulePath";
27 const std::string CODE_SIGNATURE_CPU_ABI = "cpuAbi";
28 const std::string CODE_SIGNATURE_TARGET_SO_PATH = "targetSoPath";
29 const std::string CODE_SIGNATURE_SIGNATURE_FILE_PATH = "signatureFileDir";
30 const std::string CODE_SIGNATURE_IS_ENTERPRISE_BUNDLE = "isEnterpriseBundle";
31 const std::string CODE_SIGNATURE_APP_IDENTIFIER = "appIdentifier";
32 const std::string CODE_SIGNATURE_IS_PREINSTALLED_BUNDLE = "isPreInstalledBundle";
33 const std::string CODE_SIGNATURE_IS_COMPILE_SDK_OPENHARMONY = "isCompileSdkOpenHarmony";
34 } // namespace
35
ReadFromParcel(Parcel & parcel)36 bool CodeSignatureParam::ReadFromParcel(Parcel &parcel)
37 {
38 modulePath = Str16ToStr8(parcel.ReadString16());
39 cpuAbi = Str16ToStr8(parcel.ReadString16());
40 targetSoPath = Str16ToStr8(parcel.ReadString16());
41 signatureFileDir = Str16ToStr8(parcel.ReadString16());
42 isEnterpriseBundle = parcel.ReadBool();
43 appIdentifier = Str16ToStr8(parcel.ReadString16());
44 isPreInstalledBundle = parcel.ReadBool();
45 isCompileSdkOpenHarmony = parcel.ReadBool();
46 return true;
47 }
48
Marshalling(Parcel & parcel) const49 bool CodeSignatureParam::Marshalling(Parcel &parcel) const
50 {
51 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(modulePath));
52 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(cpuAbi));
53 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(targetSoPath));
54 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(signatureFileDir));
55 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isEnterpriseBundle);
56 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(appIdentifier));
57 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isPreInstalledBundle);
58 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isCompileSdkOpenHarmony);
59 return true;
60 }
61
Unmarshalling(Parcel & parcel)62 CodeSignatureParam *CodeSignatureParam::Unmarshalling(Parcel &parcel)
63 {
64 CodeSignatureParam *info = new (std::nothrow) CodeSignatureParam();
65 if ((info != nullptr) && (!info->ReadFromParcel(parcel))) {
66 APP_LOGE("read from parcel failed");
67 delete info;
68 info = nullptr;
69 }
70 return info;
71 }
72
ToString() const73 std::string CodeSignatureParam::ToString() const
74 {
75 nlohmann::json codeSignatureParamJson = nlohmann::json {
76 { CODE_SIGNATURE_MODULE_PATH, modulePath },
77 { CODE_SIGNATURE_CPU_ABI, cpuAbi },
78 { CODE_SIGNATURE_TARGET_SO_PATH, targetSoPath },
79 { CODE_SIGNATURE_SIGNATURE_FILE_PATH, signatureFileDir },
80 { CODE_SIGNATURE_IS_ENTERPRISE_BUNDLE, isEnterpriseBundle },
81 { CODE_SIGNATURE_APP_IDENTIFIER, appIdentifier },
82 { CODE_SIGNATURE_IS_PREINSTALLED_BUNDLE, isPreInstalledBundle },
83 { CODE_SIGNATURE_IS_COMPILE_SDK_OPENHARMONY, isCompileSdkOpenHarmony },
84 };
85 return codeSignatureParamJson.dump(Constants::DUMP_INDENT);
86 }
87 } // AppExecFwk
88 } // OHOS