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