• 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 
16 #include "clone_param.h"
17 
18 #include "nlohmann/json.hpp"
19 #include "string_ex.h"
20 
21 #include "app_log_wrapper.h"
22 #include "parcel_macro.h"
23 #include "ipc_skeleton.h"
24 
25 namespace OHOS {
26 namespace AppExecFwk {
ReadFromParcel(Parcel & parcel)27 bool DestroyAppCloneParam::ReadFromParcel(Parcel &parcel)
28 {
29     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, userId);
30 
31     uint32_t parametersSize;
32     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, parametersSize);
33     CONTAINER_SECURITY_VERIFY(parcel, parametersSize, &parameters);
34     for (uint32_t i = 0; i < parametersSize; ++i) {
35         std::string key = Str16ToStr8(parcel.ReadString16());
36         std::string value = Str16ToStr8(parcel.ReadString16());
37         parameters.emplace(key, value);
38     }
39     return true;
40 }
41 
Unmarshalling(Parcel & parcel)42 DestroyAppCloneParam* DestroyAppCloneParam::Unmarshalling(Parcel &parcel)
43 {
44     DestroyAppCloneParam *info = new (std::nothrow) DestroyAppCloneParam();
45     if (info && !info->ReadFromParcel(parcel)) {
46         APP_LOGW("read from parcel failed");
47         delete info;
48         info = nullptr;
49     }
50     return info;
51 }
52 
Marshalling(Parcel & parcel) const53 bool DestroyAppCloneParam::Marshalling(Parcel &parcel) const
54 {
55     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, userId);
56 
57     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, static_cast<uint32_t>(parameters.size()));
58     for (const auto &parameter : parameters) {
59         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(parameter.first));
60         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(parameter.second));
61     }
62     return true;
63 }
64 }  // namespace AppExecFwk
65 }  // namespace OHOS
66