• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 #include "key_option.h"
17 #include "config_multimodal.h"
18 #include "mmi_log.h"
19 
20 namespace OHOS {
21 namespace MMI {
22 namespace {
23 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "KeyOption" };
24 constexpr int32_t PRE_KEYS_MAX_SIZE = 4;
25 }
GetPreKeys() const26 std::set<int32_t> KeyOption::GetPreKeys() const
27 {
28     return preKeys_;
29 }
30 
SetPreKeys(const std::set<int32_t> & preKeys)31 void KeyOption::SetPreKeys(const std::set<int32_t> &preKeys)
32 {
33     preKeys_ = preKeys;
34 }
35 
GetFinalKey() const36 int32_t KeyOption::GetFinalKey() const
37 {
38     return finalKey_;
39 }
40 
SetFinalKey(int32_t finalKey)41 void KeyOption::SetFinalKey(int32_t finalKey)
42 {
43     finalKey_ = finalKey;
44 }
45 
IsFinalKeyDown() const46 bool KeyOption::IsFinalKeyDown() const
47 {
48     return isFinalKeyDown_;
49 }
SetFinalKeyDown(bool pressed)50 void KeyOption::SetFinalKeyDown(bool pressed)
51 {
52     isFinalKeyDown_ = pressed;
53 }
54 
GetFinalKeyDownDuration() const55 int32_t KeyOption::GetFinalKeyDownDuration() const
56 {
57     return finalKeyDownDuration_;
58 }
59 
GetFinalKeyUpDelay() const60 int32_t KeyOption::GetFinalKeyUpDelay() const
61 {
62     return finalKeyUpDelay_;
63 }
64 
SetFinalKeyDownDuration(int32_t duration)65 void KeyOption::SetFinalKeyDownDuration(int32_t duration)
66 {
67     finalKeyDownDuration_ = duration;
68 }
69 
SetFinalKeyUpDelay(int32_t delay)70 void KeyOption::SetFinalKeyUpDelay(int32_t delay)
71 {
72     finalKeyUpDelay_ = delay;
73 }
74 
ReadFromParcel(Parcel & in)75 bool KeyOption::ReadFromParcel(Parcel &in)
76 {
77     int32_t preKeysSize;
78     READINT32(in, preKeysSize);
79     if (preKeysSize < 0) {
80         return false;
81     }
82     if (preKeysSize > PRE_KEYS_MAX_SIZE) {
83         MMI_HILOGE("The preKeys size(%{public}d) exceeds maximum allowed size(%{public}d)", preKeysSize,
84             PRE_KEYS_MAX_SIZE);
85         return false;
86     }
87     for (auto i = 0; i < preKeysSize; ++i) {
88         int32_t keyValue;
89         READINT32(in, keyValue);
90         preKeys_.insert(keyValue);
91     }
92     return (
93         in.ReadInt32(finalKey_) &&
94         in.ReadBool(isFinalKeyDown_) &&
95         in.ReadInt32(finalKeyDownDuration_) &&
96         in.ReadInt32(finalKeyUpDelay_)
97     );
98 }
99 
WriteToParcel(Parcel & out) const100 bool KeyOption::WriteToParcel(Parcel &out) const
101 {
102     if (preKeys_.size() > PRE_KEYS_MAX_SIZE) {
103         MMI_HILOGE("The preKeys size(%{public}zu) exceeds maximum allowed size(%{public}d)", preKeys_.size(),
104             PRE_KEYS_MAX_SIZE);
105         return false;
106     }
107     int32_t preKeysSize = static_cast<int32_t>(preKeys_.size());
108     WRITEINT32(out, preKeysSize);
109     for (const auto &i : preKeys_) {
110         WRITEINT32(out, i);
111     }
112     return (
113         out.WriteInt32(finalKey_) &&
114         out.WriteBool(isFinalKeyDown_) &&
115         out.WriteInt32(finalKeyDownDuration_) &&
116         out.WriteInt32(finalKeyUpDelay_)
117     );
118 }
119 } // namespace MMI
120 } // namespace OHOS