Coverage Report

Created: 2026-06-30 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/connectedhomeip/src/app/clusters/time-synchronization-server/DefaultTimeSyncDelegate.cpp
Line
Count
Source
1
/*
2
 *
3
 *    Copyright (c) 2023 Project CHIP Authors
4
 *    All rights reserved.
5
 *
6
 *    Licensed under the Apache License, Version 2.0 (the "License");
7
 *    you may not use this file except in compliance with the License.
8
 *    You may obtain a copy of the License at
9
 *
10
 *        http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 *    Unless required by applicable law or agreed to in writing, software
13
 *    distributed under the License is distributed on an "AS IS" BASIS,
14
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 *    See the License for the specific language governing permissions and
16
 *    limitations under the License.
17
 */
18
19
#include "DefaultTimeSyncDelegate.h"
20
#include "inet/IPAddress.h"
21
#include <platform/RuntimeOptionsProvider.h>
22
#include <system/SystemClock.h>
23
24
using chip::TimeSyncDataProvider;
25
using namespace chip::app::Clusters::TimeSynchronization;
26
27
bool DefaultTimeSyncDelegate::IsNTPAddressValid(chip::CharSpan ntp)
28
0
{
29
    // placeholder implementation
30
0
    chip::Inet::IPAddress addr;
31
0
    return chip::Inet::IPAddress::FromString(ntp.data(), ntp.size(), addr) && addr.IsIPv6();
32
0
}
33
34
bool DefaultTimeSyncDelegate::IsNTPAddressDomain(chip::CharSpan ntp)
35
0
{
36
    // For now, assume anything that includes a . is a domain name.
37
    // Delegates are free to evaluate this properly if they actually HAVE domain
38
    // name resolution, rather than just implementing a dummy for testing.
39
0
    return !IsNTPAddressValid(ntp) && (memchr(ntp.data(), '.', ntp.size()) != nullptr);
40
0
}
41
42
CHIP_ERROR DefaultTimeSyncDelegate::UpdateTimeFromPlatformSource(chip::Callback::Callback<OnTimeSyncCompletion> * callback)
43
0
{
44
0
    System::Clock::Microseconds64 utcTime;
45
0
    if (chip::app::RuntimeOptionsProvider::Instance().GetSimulateNoInternalTime())
46
0
    {
47
0
        return CHIP_ERROR_NOT_IMPLEMENTED;
48
0
    }
49
0
    if (System::SystemClock().GetClock_RealTime(utcTime) == CHIP_NO_ERROR)
50
0
    {
51
        // Default assumes the time came from NTP. Platforms using other sources should overwrite this
52
        // with their own delegates
53
        // Call the callback right away from within this function
54
0
        callback->mCall(callback->mContext, TimeSourceEnum::kMixedNTP, GranularityEnum::kMillisecondsGranularity);
55
0
        return CHIP_NO_ERROR;
56
0
    }
57
0
    return CHIP_ERROR_NOT_IMPLEMENTED;
58
0
}