• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     std::vector<uint8_t> photoBlobData;
36     resultSet->GetColumnIndex(ContactData::BLOB_DATA, index);
37     resultSet->GetBlob(index, photoBlobData);
38     bytes_.assign(reinterpret_cast<const char *>(photoBlobData.data()), photoBlobData.size());
39     return TELEPHONY_SUCCESS;
40 }
41 
InitPhotoData(std::string & format,std::string & hexBytes)42 void VCardPhotoData::InitPhotoData(std::string &format, std::string &hexBytes)
43 {
44     format_ = format;
45     bytes_ = hexBytes;
46 }
47 
SetFormat(std::string & format)48 void VCardPhotoData::SetFormat(std::string &format)
49 {
50     format_ = format;
51 }
SetHexBytes(std::string & hexBytes)52 void VCardPhotoData::SetHexBytes(std::string &hexBytes)
53 {
54     hexBytes_ = hexBytes;
55 }
GetFormat()56 std::string VCardPhotoData::GetFormat()
57 {
58     return format_;
59 }
GetHexBytes()60 std::string VCardPhotoData::GetHexBytes()
61 {
62     return hexBytes_;
63 }
64 
GetBytes()65 std::string VCardPhotoData::GetBytes()
66 {
67     return bytes_;
68 }
69 
SetBytes(const std::string & bytes)70 void VCardPhotoData::SetBytes(const std::string &bytes)
71 {
72     bytes_ = bytes;
73 }
74 
75 } // namespace Telephony
76 } // namespace OHOS
77