• 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 "mission_option.h"
17 #include "string_ex.h"
18 
19 namespace OHOS {
20 namespace AAFwk {
IsSameWindowMode(const AbilityWindowConfiguration & key) const21 bool MissionOption::IsSameWindowMode(const AbilityWindowConfiguration &key) const
22 {
23     return ((winModeKey == key) ||
24             (winModeKey == AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_PRIMARY &&
25                 key == AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_SECONDARY) ||
26             (key == AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_PRIMARY &&
27                 winModeKey == AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_SECONDARY));
28 }
29 
ReadFromParcel(Parcel & parcel)30 bool MissionOption::ReadFromParcel(Parcel &parcel)
31 {
32     userId = parcel.ReadInt32();
33     missionId = parcel.ReadInt32();
34     winModeKey = static_cast<AbilityWindowConfiguration>(parcel.ReadInt32());
35     displayKey = parcel.ReadInt32();
36 
37     int32_t size = parcel.ReadInt32();
38     for (int32_t i = 0; i < size; i++) {
39         std::string key = Str16ToStr8(parcel.ReadString16());
40         std::string data = Str16ToStr8(parcel.ReadString16());
41         properties_[key] = data;
42     }
43 
44     return true;
45 }
46 
Unmarshalling(Parcel & parcel)47 MissionOption *MissionOption::Unmarshalling(Parcel &parcel)
48 {
49     MissionOption *option = new (std::nothrow) MissionOption();
50     if (option == nullptr) {
51         return nullptr;
52     }
53 
54     if (!option->ReadFromParcel(parcel)) {
55         delete option;
56         option = nullptr;
57     }
58 
59     return option;
60 }
61 
Marshalling(Parcel & parcel) const62 bool MissionOption::Marshalling(Parcel &parcel) const
63 {
64     parcel.WriteInt32(userId);
65     parcel.WriteInt32(missionId);
66     parcel.WriteInt32(static_cast<int32_t>(winModeKey));
67     parcel.WriteInt32(displayKey);
68 
69     parcel.WriteInt32(properties_.size());
70     for (auto pair : properties_) {
71         parcel.WriteString16(Str8ToStr16(pair.first));
72         parcel.WriteString16(Str8ToStr16(pair.second));
73     }
74 
75     return true;
76 }
77 
AddProperty(const std::string & key,const std::string & value)78 void MissionOption::AddProperty(const std::string &key, const std::string &value)
79 {
80     properties_[key] = value;
81 }
82 
GetProperty(const std::string & key,std::string & value)83 void MissionOption::GetProperty(const std::string &key, std::string &value)
84 {
85     auto it = properties_.find(key);
86     if (it == properties_.end()) {
87         value = std::string();
88         return;
89     }
90     value = properties_[key];
91 }
92 
93 }  // namespace AAFwk
94 }  // namespace OHOS