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)22bool ProcessOptions::ReadFromParcel(Parcel &parcel) 23 { 24 processMode = static_cast<ProcessMode>(parcel.ReadInt32()); 25 startupVisibility = static_cast<StartupVisibility>(parcel.ReadInt32()); 26 processName = parcel.ReadString(); 27 return true; 28 } 29 Unmarshalling(Parcel & parcel)30ProcessOptions *ProcessOptions::Unmarshalling(Parcel &parcel) 31 { 32 ProcessOptions *option = new (std::nothrow) ProcessOptions(); 33 if (option == nullptr) { 34 return nullptr; 35 } 36 37 if (!option->ReadFromParcel(parcel)) { 38 delete option; 39 option = nullptr; 40 } 41 42 return option; 43 } 44 Marshalling(Parcel & parcel) const45bool ProcessOptions::Marshalling(Parcel &parcel) const 46 { 47 if (!parcel.WriteInt32(static_cast<int32_t>(processMode))) { 48 TAG_LOGE(AAFwkTag::ABILITYMGR, "Failed to write processMode"); 49 return false; 50 } 51 if (!parcel.WriteInt32(static_cast<int32_t>(startupVisibility))) { 52 TAG_LOGE(AAFwkTag::ABILITYMGR, "Failed to write startupVisibility"); 53 return false; 54 } 55 if (!parcel.WriteString(processName)) { 56 TAG_LOGE(AAFwkTag::ABILITYMGR, "Failed to write processName"); 57 return false; 58 } 59 return true; 60 } 61 ConvertInt32ToProcessMode(int32_t value)62ProcessMode ProcessOptions::ConvertInt32ToProcessMode(int32_t value) 63 { 64 if (value <= static_cast<int32_t>(ProcessMode::UNSPECIFIED) || 65 value >= static_cast<int32_t>(ProcessMode::END)) { 66 return ProcessMode::UNSPECIFIED; 67 } 68 return static_cast<ProcessMode>(value); 69 } 70 ConvertInt32ToStartupVisibility(int32_t value)71StartupVisibility ProcessOptions::ConvertInt32ToStartupVisibility(int32_t value) 72 { 73 if (value <= static_cast<int32_t>(StartupVisibility::UNSPECIFIED) || 74 value >= static_cast<int32_t>(StartupVisibility::END)) { 75 return StartupVisibility::UNSPECIFIED; 76 } 77 return static_cast<StartupVisibility>(value); 78 } 79 IsNewProcessMode(ProcessMode value)80bool ProcessOptions::IsNewProcessMode(ProcessMode value) 81 { 82 return (value == ProcessMode::NEW_PROCESS_ATTACH_TO_PARENT) || 83 (value == ProcessMode::NEW_PROCESS_ATTACH_TO_STATUS_BAR_ITEM); 84 } 85 IsAttachToStatusBarMode(ProcessMode value)86bool ProcessOptions::IsAttachToStatusBarMode(ProcessMode value) 87 { 88 return (value == ProcessMode::NEW_PROCESS_ATTACH_TO_STATUS_BAR_ITEM) || 89 (value == ProcessMode::ATTACH_TO_STATUS_BAR_ITEM); 90 } 91 IsValidProcessMode(ProcessMode value)92bool ProcessOptions::IsValidProcessMode(ProcessMode value) 93 { 94 return (value > ProcessMode::UNSPECIFIED) && (value < ProcessMode::END); 95 } 96 } // namespace AAFwk 97 } // namespace OHOS 98