• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 constexpr const char* CODE_SIGNATURE_MODULE_PATH = "modulePath";
27 constexpr const char* CODE_SIGNATURE_CPU_ABI = "cpuAbi";
28 constexpr const char* CODE_SIGNATURE_TARGET_SO_PATH = "targetSoPath";
29 constexpr const char* CODE_SIGNATURE_SIGNATURE_FILE_PATH = "signatureFileDir";
30 constexpr const char* CODE_SIGNATURE_IS_ENTERPRISE_BUNDLE = "isEnterpriseBundle";
31 constexpr const char* CODE_SIGNATURE_APP_IDENTIFIER = "appIdentifier";
32 constexpr const char* CODE_SIGNATURE_IS_PREINSTALLED_BUNDLE = "isPreInstalledBundle";
33 constexpr const char* CODE_SIGNATURE_IS_COMPILE_SDK_OPENHARMONY = "isCompileSdkOpenHarmony";
34 constexpr const char* CODE_SIGNATURE_IS_COMPRESS_NATIVE_LIBRARY = "isCompressNativeLibrary";
35 } // namespace
36 
ReadFromParcel(Parcel & parcel)37 bool CodeSignatureParam::ReadFromParcel(Parcel &parcel)
38 {
39     modulePath = Str16ToStr8(parcel.ReadString16());
40     cpuAbi = Str16ToStr8(parcel.ReadString16());
41     targetSoPath = Str16ToStr8(parcel.ReadString16());
42     signatureFileDir = Str16ToStr8(parcel.ReadString16());
43     isEnterpriseBundle = parcel.ReadBool();
44     appIdentifier = Str16ToStr8(parcel.ReadString16());
45     isPreInstalledBundle = parcel.ReadBool();
46     isCompileSdkOpenHarmony = parcel.ReadBool();
47     isCompressNativeLibrary = parcel.ReadBool();
48     return true;
49 }
50 
Marshalling(Parcel & parcel) const51 bool CodeSignatureParam::Marshalling(Parcel &parcel) const
52 {
53     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(modulePath));
54     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(cpuAbi));
55     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(targetSoPath));
56     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(signatureFileDir));
57     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isEnterpriseBundle);
58     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(appIdentifier));
59     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isPreInstalledBundle);
60     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isCompileSdkOpenHarmony);
61     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isCompressNativeLibrary);
62     return true;
63 }
64 
Unmarshalling(Parcel & parcel)65 CodeSignatureParam *CodeSignatureParam::Unmarshalling(Parcel &parcel)
66 {
67     CodeSignatureParam *info = new (std::nothrow) CodeSignatureParam();
68     if ((info != nullptr) && (!info->ReadFromParcel(parcel))) {
69         APP_LOGE("read from parcel failed");
70         delete info;
71         info = nullptr;
72     }
73     return info;
74 }
75 
ToString() const76 std::string CodeSignatureParam::ToString() const
77 {
78     nlohmann::json codeSignatureParamJson = nlohmann::json {
79         { CODE_SIGNATURE_MODULE_PATH, modulePath },
80         { CODE_SIGNATURE_CPU_ABI, cpuAbi },
81         { CODE_SIGNATURE_TARGET_SO_PATH, targetSoPath },
82         { CODE_SIGNATURE_SIGNATURE_FILE_PATH, signatureFileDir },
83         { CODE_SIGNATURE_IS_ENTERPRISE_BUNDLE, isEnterpriseBundle },
84         { CODE_SIGNATURE_APP_IDENTIFIER, appIdentifier },
85         { CODE_SIGNATURE_IS_PREINSTALLED_BUNDLE, isPreInstalledBundle },
86         { CODE_SIGNATURE_IS_COMPILE_SDK_OPENHARMONY, isCompileSdkOpenHarmony },
87         { CODE_SIGNATURE_IS_COMPRESS_NATIVE_LIBRARY, isCompressNativeLibrary },
88     };
89     return codeSignatureParamJson.dump(Constants::DUMP_INDENT);
90 }
91 } // AppExecFwk
92 } // OHOS
93