1 /*
2  * Copyright (C) 2023 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 #include "vcard_photo_data.h"
16 
17 #include "telephony_errors.h"
18 
19 namespace OHOS {
20 namespace Telephony {
21 
BuildValuesBucket(OHOS::DataShare::DataShareValuesBucket & valuesBucket)22 int32_t VCardPhotoData::BuildValuesBucket(OHOS::DataShare::DataShareValuesBucket &valuesBucket)
23 {
24     valuesBucket.Put(ContactData::TYPE_ID, TypeId::PHOTO);
25     valuesBucket.Put(ContactData::BLOB_DATA, std::vector<uint8_t>(bytes_.begin(), bytes_.end()));
26     return TELEPHONY_SUCCESS;
27 }
28 
BuildData(std::shared_ptr<DataShare::DataShareResultSet> resultSet)29 int32_t VCardPhotoData::BuildData(std::shared_ptr<DataShare::DataShareResultSet> resultSet)
30 {
31     if (resultSet == nullptr) {
32         return TELEPHONY_ERROR;
33     }
34     int32_t index;
35     resultSet->GetColumnIndex(ContactData::DETAIL_INFO, index);
36     resultSet->GetString(index, bytes_);
37     return TELEPHONY_SUCCESS;
38 }
39 
InitPhotoData(std::string & format,std::string & hexBytes)40 void VCardPhotoData::InitPhotoData(std::string &format, std::string &hexBytes)
41 {
42     format_ = format;
43     bytes_ = hexBytes;
44 }
45 
SetFormat(std::string & format)46 void VCardPhotoData::SetFormat(std::string &format)
47 {
48     format_ = format;
49 }
SetHexBytes(std::string & hexBytes)50 void VCardPhotoData::SetHexBytes(std::string &hexBytes)
51 {
52     hexBytes_ = hexBytes;
53 }
GetFormat()54 std::string VCardPhotoData::GetFormat()
55 {
56     return format_;
57 }
GetHexBytes()58 std::string VCardPhotoData::GetHexBytes()
59 {
60     return hexBytes_;
61 }
62 
GetBytes()63 std::string VCardPhotoData::GetBytes()
64 {
65     return bytes_;
66 }
67 
SetBytes(const std::string & bytes)68 void VCardPhotoData::SetBytes(const std::string &bytes)
69 {
70     bytes_ = bytes;
71 }
72 
73 } // namespace Telephony
74 } // namespace OHOS
75