1 /*
2 * Copyright (c) 2021-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
16 #include "target_info.h"
17 #include "app_domain_verify_hilog.h"
18 #include "app_domain_verify_parcel_util.h"
19 namespace OHOS::AppDomainVerify {
20
Marshalling(Parcel & parcel) const21 bool TargetInfo::Marshalling(Parcel& parcel) const
22 {
23 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, targetType);
24 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &targetWant);
25 return true;
26 }
Unmarshalling(Parcel & parcel)27 TargetInfo* TargetInfo::Unmarshalling(Parcel& parcel)
28 {
29 auto* targetInfo = new (std::nothrow) TargetInfo();
30 if ((targetInfo != nullptr) && (!targetInfo->ReadFromParcel(parcel))) {
31 APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MODULE_COMMON, "failed to read from parcel");
32 delete targetInfo;
33 targetInfo = nullptr;
34 }
35 return targetInfo;
36 }
ReadFromParcel(Parcel & parcel)37 bool TargetInfo::ReadFromParcel(Parcel& parcel)
38 {
39 uint32_t type = 0;
40 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, type);
41 targetType = static_cast<TargetType>(type);
42 std::unique_ptr<OHOS::AAFwk::Want> w(parcel.ReadParcelable<OHOS::AAFwk::Want>());
43 OHOS::AAFwk::Want want;
44 if (!w) {
45 APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "read parcelable want failed.");
46 return false;
47 }
48 targetWant = *w;
49 return true;
50 }
51 }