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 "input_attribute.h" 17 18 namespace OHOS { 19 namespace MiscServices { 20 /*! Constructor 21 */ InputAttribute()22 InputAttribute::InputAttribute() : enterKeyType(0), inputOption(0) 23 { 24 } 25 26 /*! Constructor 27 \param attribute the source attribute copied to this instance 28 */ InputAttribute(const InputAttribute & attribute)29 InputAttribute::InputAttribute(const InputAttribute& attribute) 30 { 31 inputPattern = attribute.inputPattern; 32 enterKeyType = attribute.enterKeyType; 33 inputOption = attribute.inputOption; 34 } 35 36 /*! Destructor 37 */ ~InputAttribute()38 InputAttribute::~InputAttribute() 39 { 40 } 41 42 /*! operator= 43 \param attribute the source attribute copied to this instance 44 \return return this 45 */ operator =(const InputAttribute & attribute)46 InputAttribute& InputAttribute::operator =(const InputAttribute& attribute) 47 { 48 if (this == &attribute) { 49 return *this; 50 } 51 inputPattern = attribute.inputPattern; 52 enterKeyType = attribute.enterKeyType; 53 inputOption = attribute.inputOption; 54 return *this; 55 } 56 57 /*! Write InputAttribute to parcel 58 \param[out] parcel write the data of InputAttribute to this parcel returned to caller 59 \return ErrorCode::NO_ERROR 60 \return ErrorCode::ERROR_NULL_POINTER parcel is null 61 */ Marshalling(OHOS::Parcel & parcel) const62 bool InputAttribute::Marshalling(OHOS::Parcel &parcel) const 63 { 64 if (!(parcel.WriteInt32(inputPattern) 65 && parcel.WriteInt32(enterKeyType) 66 && parcel.WriteInt32(inputOption))) 67 return false; 68 return true; 69 } 70 71 /*! Read InputAttribute from parcel 72 \param parcel read the data of InputAttribute from this parcel 73 \return ErrorCode::NO_ERROR 74 \return ErrorCode::ERROR_NULL_POINTER parcel is null 75 */ Unmarshalling(OHOS::Parcel & parcel)76 InputAttribute *InputAttribute::Unmarshalling(OHOS::Parcel &parcel) 77 { 78 auto info = new InputAttribute(); 79 info->inputPattern = parcel.ReadInt32(); 80 info->enterKeyType = parcel.ReadInt32(); 81 info->inputOption = parcel.ReadInt32(); 82 return info; 83 } 84 85 /*! Get the security flag 86 \return true - It's password EditView. The input method management service should start system 87 security input method engine for this view. 88 \return false - It's an normal view. 89 */ GetSecurityFlag()90 bool InputAttribute::GetSecurityFlag() 91 { 92 if (inputPattern == PATTERN_PASSWORD) { 93 return true; 94 } 95 return false; 96 } 97 98 /*! Set input pattern. 99 \n It's added for Unit test of PerUserSession 100 \param pattern PATTERN_PASSWORD or 0. 101 */ SetInputPattern(int32_t pattern)102 void InputAttribute::SetInputPattern(int32_t pattern) 103 { 104 inputPattern = pattern; 105 } 106 } 107 } 108