• 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 #ifndef SERVICES_INCLUDE_INPUT_ATTRIBUTE_H
17 #define SERVICES_INCLUDE_INPUT_ATTRIBUTE_H
18 
19 #include <cstdint>
20 #include <sstream>
21 
22 #include "parcel.h"
23 
24 namespace OHOS {
25 namespace MiscServices {
26 enum class CapitalizeMode : int32_t {
27     NONE = 0,
28     SENTENCES,
29     WORDS,
30     CHARACTERS
31 };
32 
33 struct InputAttribute {
34     static const int32_t PATTERN_TEXT = 0x00000001;
35     static const int32_t PATTERN_PASSWORD = 0x00000007;
36     static const int32_t PATTERN_PASSWORD_NUMBER = 0x00000008;
37     static const int32_t PATTERN_PASSWORD_SCREEN_LOCK = 0x00000009;
38     static const int32_t PATTERN_NEWPASSWORD = 0x0000000b;
39     static const int32_t PATTERN_ONE_TIME_CODE = 0x0000000d;
40     int32_t inputPattern = 0;
41     int32_t enterKeyType = 0;
42     int32_t inputOption = 0;
43     bool isTextPreviewSupported { false };
44     std::string bundleName { "" };
45     int32_t immersiveMode = 0;
46     int32_t gradientMode { 0 };
47     int32_t fluidLightMode { 0 };
48     uint32_t windowId = 0; // for transfer
49     uint64_t callingDisplayId = 0;
50     std::u16string placeholder { u"" };
51     std::u16string abilityName { u"" };
52     CapitalizeMode capitalizeMode = CapitalizeMode::NONE;
53     bool needAutoInputNumkey { false }; // number keys need to be automatically handled by imf
54 
GetSecurityFlagInputAttribute55     bool GetSecurityFlag() const
56     {
57         return inputPattern == PATTERN_PASSWORD || inputPattern == PATTERN_PASSWORD_SCREEN_LOCK ||
58             PATTERN_PASSWORD_NUMBER == inputPattern || PATTERN_NEWPASSWORD == inputPattern;
59     }
60 
IsOneTimeCodeFlagInputAttribute61     bool IsOneTimeCodeFlag() const
62     {
63         return inputPattern == PATTERN_ONE_TIME_CODE;
64     }
65 
IsSecurityImeFlagInputAttribute66     bool IsSecurityImeFlag() const
67     {
68         return GetSecurityFlag();
69     }
70 
71     bool operator==(const InputAttribute &info) const
72     {
73         return inputPattern == info.inputPattern && enterKeyType == info.enterKeyType &&
74             inputOption == info.inputOption && isTextPreviewSupported == info.isTextPreviewSupported;
75     }
76 
ToStringInputAttribute77     inline std::string ToString() const
78     {
79         std::stringstream ss;
80         ss << "[" << "inputPattern:" << inputPattern
81         << "enterKeyType:" << enterKeyType << "inputOption:" << inputOption
82         << "isTextPreviewSupported:" << isTextPreviewSupported << "bundleName:" << bundleName
83         << "immersiveMode:" << immersiveMode << "windowId:" << windowId
84         << "callingDisplayId:" << callingDisplayId
85         << "needNumInput: " << needAutoInputNumkey
86         << "]";
87         return ss.str();
88     }
89 };
90 
91 struct InputAttributeInner : public Parcelable {
92     static const int32_t PATTERN_TEXT = 0x00000001;
93     static const int32_t PATTERN_PASSWORD = 0x00000007;
94     static const int32_t PATTERN_PASSWORD_NUMBER = 0x00000008;
95     static const int32_t PATTERN_PASSWORD_SCREEN_LOCK = 0x00000009;
96     static const int32_t PATTERN_NEWPASSWORD = 0x0000000b;
97     int32_t inputPattern = 0;
98     int32_t enterKeyType = 0;
99     int32_t inputOption = 0;
100     bool isTextPreviewSupported { false };
101     std::string bundleName { "" };
102     int32_t immersiveMode = 0;
103     int32_t gradientMode { 0 };
104     int32_t fluidLightMode { 0 };
105     uint32_t windowId = 0; // for transfer
106     uint64_t callingDisplayId = 0;
107     std::u16string placeholder { u"" };
108     std::u16string abilityName { u"" };
109     CapitalizeMode capitalizeMode = CapitalizeMode::NONE;
110     bool needAutoInputNumkey { false }; // number keys need to be automatically handled by imf
111 
ReadFromParcelInputAttributeInner112     bool ReadFromParcel(Parcel &in)
113     {
114         inputPattern = in.ReadInt32();
115         enterKeyType = in.ReadInt32();
116         inputOption = in.ReadInt32();
117         isTextPreviewSupported = in.ReadBool();
118         bundleName = in.ReadString();
119         immersiveMode = in.ReadInt32();
120         windowId = in.ReadUint32();
121         callingDisplayId = in.ReadUint64();
122         placeholder = in.ReadString16();
123         abilityName = in.ReadString16();
124         int32_t readCapitalizeMode = in.ReadInt32();
125         if (readCapitalizeMode < static_cast<int32_t>(CapitalizeMode::NONE) ||
126             readCapitalizeMode > static_cast<int32_t>(CapitalizeMode::CHARACTERS)) {
127             readCapitalizeMode = 0;
128         }
129         capitalizeMode = static_cast<CapitalizeMode>(readCapitalizeMode);
130         needAutoInputNumkey = in.ReadBool();
131         gradientMode = in.ReadInt32();
132         fluidLightMode = in.ReadInt32();
133         return true;
134     }
135 
MarshallingInputAttributeInner136     bool Marshalling(Parcel &out) const
137     {
138         if (!out.WriteInt32(inputPattern)) {
139             return false;
140         }
141         if (!out.WriteInt32(enterKeyType)) {
142             return false;
143         }
144         if (!out.WriteInt32(inputOption)) {
145             return false;
146         }
147         if (!out.WriteBool(isTextPreviewSupported)) {
148             return false;
149         }
150         if (!out.WriteString(bundleName)) {
151             return false;
152         }
153         if (!out.WriteInt32(immersiveMode)) {
154             return false;
155         }
156         if (!out.WriteUint32(windowId)) {
157             return false;
158         }
159         if (!out.WriteUint64(callingDisplayId)) {
160             return false;
161         }
162         auto ret = out.WriteString16(placeholder) && out.WriteString16(abilityName);
163         ret = ret && out.WriteInt32(static_cast<int32_t>(capitalizeMode));
164         ret = ret && out.WriteBool(needAutoInputNumkey);
165         ret = ret && out.WriteInt32(gradientMode);
166         ret = ret && out.WriteInt32(fluidLightMode);
167         return ret;
168     }
169 
UnmarshallingInputAttributeInner170     static InputAttributeInner *Unmarshalling(Parcel &in)
171     {
172         InputAttributeInner *data = new (std::nothrow) InputAttributeInner();
173         if (data && !data->ReadFromParcel(in)) {
174             delete data;
175             data = nullptr;
176         }
177         return data;
178     }
179 
180     bool operator==(const InputAttribute &info) const
181     {
182         return inputPattern == info.inputPattern && enterKeyType == info.enterKeyType &&
183             inputOption == info.inputOption && isTextPreviewSupported == info.isTextPreviewSupported;
184     }
185 
GetSecurityFlagInputAttributeInner186     bool GetSecurityFlag() const
187     {
188         return inputPattern == PATTERN_PASSWORD || inputPattern == PATTERN_PASSWORD_SCREEN_LOCK ||
189             PATTERN_PASSWORD_NUMBER == inputPattern || PATTERN_NEWPASSWORD == inputPattern;
190     }
191 };
192 } // namespace MiscServices
193 } // namespace OHOS
194 
195 #endif // SERVICES_INCLUDE_INPUT_ATTRIBUTE_H
196