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 "process_options.h"
17
18 #include "hilog_tag_wrapper.h"
19
20 namespace OHOS {
21 namespace AAFwk {
ReadFromParcel(Parcel & parcel)22 bool ProcessOptions::ReadFromParcel(Parcel &parcel)
23 {
24 processMode = static_cast<ProcessMode>(parcel.ReadInt32());
25 startupVisibility = static_cast<StartupVisibility>(parcel.ReadInt32());
26 processName = parcel.ReadString();
27 isRestartKeepAlive = parcel.ReadBool();
28 isStartFromNDK = parcel.ReadBool();
29 return true;
30 }
31
Unmarshalling(Parcel & parcel)32 ProcessOptions *ProcessOptions::Unmarshalling(Parcel &parcel)
33 {
34 ProcessOptions *option = new (std::nothrow) ProcessOptions();
35 if (option == nullptr) {
36 return nullptr;
37 }
38
39 if (!option->ReadFromParcel(parcel)) {
40 delete option;
41 option = nullptr;
42 }
43
44 return option;
45 }
46
Marshalling(Parcel & parcel) const47 bool ProcessOptions::Marshalling(Parcel &parcel) const
48 {
49 if (!parcel.WriteInt32(static_cast<int32_t>(processMode))) {
50 TAG_LOGE(AAFwkTag::ABILITYMGR, "ProcessMode write failed");
51 return false;
52 }
53 if (!parcel.WriteInt32(static_cast<int32_t>(startupVisibility))) {
54 TAG_LOGE(AAFwkTag::ABILITYMGR, "StartupVisibility write failed");
55 return false;
56 }
57 if (!parcel.WriteString(processName)) {
58 TAG_LOGE(AAFwkTag::ABILITYMGR, "ProcessName write failed");
59 return false;
60 }
61 if (!parcel.WriteBool(isRestartKeepAlive)) {
62 TAG_LOGE(AAFwkTag::ABILITYMGR, "isRestartKeepAlive write failed");
63 return false;
64 }
65 if (!parcel.WriteBool(isStartFromNDK)) {
66 TAG_LOGE(AAFwkTag::ABILITYMGR, "isStartFromNDK write failed");
67 return false;
68 }
69 return true;
70 }
71
ConvertInt32ToProcessMode(int32_t value)72 ProcessMode ProcessOptions::ConvertInt32ToProcessMode(int32_t value)
73 {
74 if (value <= static_cast<int32_t>(ProcessMode::UNSPECIFIED) ||
75 value >= static_cast<int32_t>(ProcessMode::END)) {
76 return ProcessMode::UNSPECIFIED;
77 }
78 return static_cast<ProcessMode>(value);
79 }
80
ConvertInt32ToStartupVisibility(int32_t value)81 StartupVisibility ProcessOptions::ConvertInt32ToStartupVisibility(int32_t value)
82 {
83 if (value <= static_cast<int32_t>(StartupVisibility::UNSPECIFIED) ||
84 value >= static_cast<int32_t>(StartupVisibility::END)) {
85 return StartupVisibility::UNSPECIFIED;
86 }
87 return static_cast<StartupVisibility>(value);
88 }
89
IsNewProcessMode(ProcessMode value)90 bool ProcessOptions::IsNewProcessMode(ProcessMode value)
91 {
92 return (value == ProcessMode::NEW_PROCESS_ATTACH_TO_PARENT) ||
93 (value == ProcessMode::NEW_PROCESS_ATTACH_TO_STATUS_BAR_ITEM);
94 }
95
IsAttachToStatusBarMode(ProcessMode value)96 bool ProcessOptions::IsAttachToStatusBarMode(ProcessMode value)
97 {
98 return (value == ProcessMode::NEW_PROCESS_ATTACH_TO_STATUS_BAR_ITEM) ||
99 (value == ProcessMode::ATTACH_TO_STATUS_BAR_ITEM);
100 }
101
IsValidProcessMode(ProcessMode value)102 bool ProcessOptions::IsValidProcessMode(ProcessMode value)
103 {
104 return (value > ProcessMode::UNSPECIFIED) && (value < ProcessMode::END);
105 }
106
IsNoAttachmentMode(ProcessMode value)107 bool ProcessOptions::IsNoAttachmentMode(ProcessMode value)
108 {
109 return (value == ProcessMode::NO_ATTACHMENT);
110 }
111
IsAttachToStatusBarItemMode(ProcessMode value)112 bool ProcessOptions::IsAttachToStatusBarItemMode(ProcessMode value)
113 {
114 return (value == ProcessMode::ATTACH_TO_STATUS_BAR_ITEM);
115 }
116
IsNewHiddenProcessMode(ProcessMode value)117 bool ProcessOptions::IsNewHiddenProcessMode(ProcessMode value)
118 {
119 return (value == ProcessMode::NEW_HIDDEN_PROCESS);
120 }
121 } // namespace AAFwk
122 } // namespace OHOS
123