• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "sender_info.h"
17 
18 #include "hilog_wrapper.h"
19 #include "nlohmann/json.hpp"
20 #include "string_ex.h"
21 
22 #include "ipc_types.h"
23 #include "iremote_object.h"
24 
25 namespace OHOS {
26 namespace AAFwk {
ReadFromParcel(Parcel & parcel)27 bool SenderInfo::ReadFromParcel(Parcel &parcel)
28 {
29     HILOG_INFO("%{public}s:begin.", __func__);
30 
31     code = parcel.ReadInt32();
32     auto wantResquest = parcel.ReadParcelable<Want>();
33     if (wantResquest == nullptr) {
34         HILOG_ERROR("%{public}s:wantResquest is nullptr.", __func__);
35         return false;
36     }
37     want = *wantResquest;
38     resolvedType = Str16ToStr8(parcel.ReadString16());
39     sptr<IRemoteObject> finishedReceiverResquest = parcel.ReadParcelable<IRemoteObject>();
40     if (finishedReceiverResquest != nullptr) {
41         finishedReceiver = iface_cast<IWantReceiver>(finishedReceiverResquest);
42         if (!finishedReceiver) {
43             return false;
44         }
45     } else {
46         HILOG_ERROR("%{public}s:finishedReceiverResquest is nullptr.", __func__);
47     }
48 
49     requiredPermission = Str16ToStr8(parcel.ReadString16());
50     return true;
51 }
52 
Unmarshalling(Parcel & parcel)53 SenderInfo *SenderInfo::Unmarshalling(Parcel &parcel)
54 {
55     HILOG_INFO("%{public}s:begin.", __func__);
56 
57     SenderInfo *info = new (std::nothrow) SenderInfo();
58     if (info == nullptr) {
59         HILOG_ERROR("%{public}s:senderInfo is nullptr.", __func__);
60         return nullptr;
61     }
62 
63     if (!info->ReadFromParcel(parcel)) {
64         HILOG_ERROR("%{public}s:ReadFromParcel failed.", __func__);
65         delete info;
66         info = nullptr;
67     }
68     return info;
69 }
70 
Marshalling(Parcel & parcel) const71 bool SenderInfo::Marshalling(Parcel &parcel) const
72 {
73     HILOG_INFO("%{public}s:begin.", __func__);
74 
75     parcel.WriteInt32(code);
76     parcel.WriteParcelable(&want);
77     parcel.WriteString16(Str8ToStr16(resolvedType));
78     if (finishedReceiver != nullptr) {
79         parcel.WriteParcelable(finishedReceiver->AsObject());
80     } else {
81         parcel.WriteParcelable(nullptr);
82     }
83     parcel.WriteString16(Str8ToStr16(requiredPermission));
84     return true;
85 }
86 }  // namespace AAFwk
87 }  // namespace OHOS