1 /* 2 * Copyright (C) 2022 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 #ifndef INPUTMETHOD_IMF_INPUT_METHOD_PROPERTY_H 17 #define INPUTMETHOD_IMF_INPUT_METHOD_PROPERTY_H 18 #include <mutex> 19 #include <thread> 20 #include <vector> 21 #include "input_method_status.h" 22 #include "parcel.h" 23 24 namespace OHOS { 25 namespace MiscServices { 26 struct Property : public Parcelable { 27 std::string name; // the bundleName of inputMethod 28 std::string id; // the extensionName of inputMethod 29 std::string label; // the label of inputMethod 30 uint32_t labelId = 0; // the labelId of inputMethod 31 std::string icon; // the icon of inputMethod 32 uint32_t iconId = 0; // the icon id of inputMethod 33 EnabledStatus status { EnabledStatus::DISABLED }; // the enabled status of inputMethod 34 ReadFromParcelProperty35 bool ReadFromParcel(Parcel &in) 36 { 37 name = in.ReadString(); 38 id = in.ReadString(); 39 label = in.ReadString(); 40 labelId = in.ReadUint32(); 41 icon = in.ReadString(); 42 iconId = in.ReadUint32(); 43 status = static_cast<EnabledStatus>(in.ReadInt32()); 44 return true; 45 } 46 MarshallingProperty47 bool Marshalling(Parcel &out) const 48 { 49 if (!out.WriteString(name)) { 50 return false; 51 } 52 if (!out.WriteString(id)) { 53 return false; 54 } 55 if (!out.WriteString(label)) { 56 return false; 57 } 58 if (!out.WriteUint32(labelId)) { 59 return false; 60 } 61 if (!out.WriteString(icon)) { 62 return false; 63 } 64 if (!out.WriteUint32(iconId)) { 65 return false; 66 } 67 if (!out.WriteInt32(static_cast<int32_t>(status))) { 68 return false; 69 } 70 return true; 71 } 72 UnmarshallingProperty73 static Property *Unmarshalling(Parcel &in) 74 { 75 Property *data = new (std::nothrow) Property(); 76 if (data && !data->ReadFromParcel(in)) { 77 delete data; 78 data = nullptr; 79 } 80 return data; 81 } 82 }; 83 84 struct SubProperty : public Parcelable { 85 std::string label; // the label of subtype 86 uint32_t labelId = 0; // the labelId of subtype 87 std::string name; // the bundleName of inputMethod 88 std::string id; // the name of subtype 89 std::string mode; // the mode of subtype, containing "upper" and "lower" 90 std::string locale; // the tongues of subtype, such as "zh_CN", "en_US", etc. 91 std::string language; // the language of subtype 92 std::string icon; // the icon of subtype 93 uint32_t iconId = 0; // the icon id of subtype 94 ReadFromParcelSubProperty95 bool ReadFromParcel(Parcel &in) 96 { 97 label = in.ReadString(); 98 labelId = in.ReadUint32(); 99 name = in.ReadString(); 100 id = in.ReadString(); 101 mode = in.ReadString(); 102 locale = in.ReadString(); 103 language = in.ReadString(); 104 icon = in.ReadString(); 105 iconId = in.ReadUint32(); 106 return true; 107 } 108 MarshallingSubProperty109 bool Marshalling(Parcel &out) const 110 { 111 if (!out.WriteString(label)) { 112 return false; 113 } 114 if (!out.WriteUint32(labelId)) { 115 return false; 116 } 117 if (!out.WriteString(name)) { 118 return false; 119 } 120 if (!out.WriteString(id)) { 121 return false; 122 } 123 if (!out.WriteString(mode)) { 124 return false; 125 } 126 if (!out.WriteString(locale)) { 127 return false; 128 } 129 if (!out.WriteString(language)) { 130 return false; 131 } 132 if (!out.WriteString(icon)) { 133 return false; 134 } 135 if (!out.WriteUint32(iconId)) { 136 return false; 137 } 138 return true; 139 } UnmarshallingSubProperty140 static SubProperty *Unmarshalling(Parcel &in) 141 { 142 SubProperty *data = new (std::nothrow) SubProperty(); 143 if (data && !data->ReadFromParcel(in)) { 144 delete data; 145 data = nullptr; 146 } 147 return data; 148 } 149 }; 150 151 struct FullImeInfo { 152 bool isNewIme { false }; 153 uint32_t tokenId { 0 }; 154 std::string appId; 155 uint32_t versionCode; 156 Property prop; 157 std::vector<SubProperty> subProps; 158 }; 159 160 struct ImeInfo : public FullImeInfo { 161 SubProperty subProp; 162 bool isSpecificSubName { true }; 163 }; 164 165 struct SwitchInfo { 166 std::chrono::system_clock::time_point timestamp{}; 167 std::string bundleName; 168 std::string subName; 169 /* isTmpImeSwitchSubtype:true -- switch subtype of self, switch trigger is current running ime, 170 but not default ime set by user */ 171 bool isTmpImeSwitchSubtype{ false }; 172 bool operator==(const SwitchInfo &info) const 173 { 174 return (timestamp == info.timestamp && bundleName == info.bundleName && subName == info.subName); 175 } 176 }; 177 } // namespace MiscServices 178 } // namespace OHOS 179 180 #endif // INPUTMETHOD_IMF_INPUT_METHOD_PROPERTY_H 181