1 /*
2 * Copyright (c) 2024 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 "pasteboard_info_collector.h"
17
18 #include "device_profile_log.h"
19 #include "nlohmann/json.hpp"
20 #include "parameter.h"
21
22 namespace OHOS {
23 namespace DeviceProfile {
24 namespace {
25 const std::string TAG = "PasteboardInfoCollector";
26 const std::string SERVICE_ID = "pasteboardService";
27 const std::string SERVICE_TYPE = "pasteboardService";
28 const std::string SUPPORT_DISTRIBUTED_PASTEBOARD = "supportDistributedPasteboard";
29 const std::string PASTEBOARD_VERSION = "PasteboardVersionId";
30 constexpr uint32_t FIRST_VERSION = 4;
31
32 const char *DISTRIBUTED_PASTEBOARD_ENABLED_KEY = "persist.pasteboard.distributedPasteboardEnabled";
33 const std::string ENABLED_STATUS = "true";
34 const char* UNDEFINED_VALUE = "undefined";
35 constexpr int CONFIG_LEN = 10;
36 constexpr uint32_t NOT_SUPPORT = 0;
37 constexpr uint32_t SUPPORT = 1;
38 }
39
ConvertToProfileData(ServiceCharacteristicProfile & profile)40 bool PasteboardInfoCollector::ConvertToProfileData(ServiceCharacteristicProfile& profile)
41 {
42 HILOGI("call");
43 profile.SetServiceId(SERVICE_ID);
44 profile.SetServiceType(SERVICE_TYPE);
45 nlohmann::json jsonData;
46 jsonData[SUPPORT_DISTRIBUTED_PASTEBOARD] = GetSupportDistributedPasteboard();
47 jsonData[PASTEBOARD_VERSION] = FIRST_VERSION;
48 profile.SetCharacteristicProfileJson(jsonData.dump());
49 return true;
50 }
51
GetSupportDistributedPasteboard()52 uint32_t PasteboardInfoCollector::GetSupportDistributedPasteboard()
53 {
54 char value[CONFIG_LEN] = { 0 };
55 GetParameter(DISTRIBUTED_PASTEBOARD_ENABLED_KEY, UNDEFINED_VALUE, value, CONFIG_LEN);
56 HILOGI("GetParameter, value = %{public}s.", value);
57 std::string enabledStatus(value);
58 return enabledStatus == ENABLED_STATUS ? SUPPORT : NOT_SUPPORT;
59 }
60 } // namespace DeviceProfile
61 } // OHOS