summaryrefslogtreecommitdiff
path: root/core/java/android/net/SntpClient.java
Commit message (Collapse)AuthorAgeFilesLines
* Add the ability to configure NTP port for testsNeil Fuller2022-03-171-3/+6
| | | | | | | | | | | | | | | | | | | | | | | | | Add the ability to configure NTP port for tests via the command line and the associated plumbing / knock-ons. In-progress CTS tests will run a fake NTP server on the device itself. Binding to NTP's default port of 123 is restricted. Therefore, we need to be able to override the port for tests. adb shell cmd network_time_update_service set_server_config --port 9999 adb shell dumpsys network_time_update_service <observe port value> adb shell cmd network_time_update_service force_refresh <observe false> adb shell cmd network_time_update_service set_server_config adb shell dumpsys network_time_update_service <observe port value> adb shell cmd network_time_update_service force_refresh <observe true> Bug: 213393821 Test: See above Change-Id: I21e8b735fab268df0d617848b8a562f86560ad16
* Fix SntpClient 2036 issue (2/2)Neil Fuller2021-10-191-84/+92
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix issue with SntpClient after the end of NTP era 0 (2036). This is the second of two commits. This commit makes the actual fixes and makes tests pass. Before this change SntpClient converted to Unix epoch times too eagerly. NTP 64-bit timestamps are lossy: they only hold the number of seconds / factions of seconds in the NTP era and the era is not transmitted. The existing code assumed the era was always era 0, which ends in 2036. As explained at https://www.eecis.udel.edu/~mills/y2k.html, the lossiness of the type is not an issue providing that the maths is implemented carefully: the NTP timestamps are only ever subtracted from each other, are always assumed to be in the same or adjacent NTP eras, and are used to calculate offsets that are applied to client Unix epoch times. This commit: + Switches to use a dedicated Timestamp64 type, avoiding the use of the Unix epoch. + Switches to use a dedicated Duration64 type for holding the 32-bit signed difference between two Timestamp64 instances. + Simplifies the readTimeStamp() and writeTimeStamp() methods. + Adds missing validation covered by a TODO. The code was randomizing the lower bits of the client transmit timestamp, but then not checking the result as it should, presumably because it was difficult to know what value was sent. Easily fixed with a dedicated type. + Stops randomizing the lower bits of various other timestamps unnecessarily. + Fixes some naming to add clarity. Bug: 199481251 Test: atest core/tests/coretests/src/android/net/sntp/Timestamp64Test.java Test: atest core/tests/coretests/src/android/net/sntp/Duration64Test.java Test: atest core/tests/coretests/src/android/net/SntpClientTest.java Merged-In: I6d3584f318b0ef6ceab42bb88f20c73b0ad006cb Change-Id: I6d3584f318b0ef6ceab42bb88f20c73b0ad006cb
* Fix SntpClient 2036 issue (1/2)Neil Fuller2021-10-191-27/+72
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix issue with SntpClient after the end of NTP era 0 (2036). This commit is 1/2. It makes some refactoring changes, lint fixes, adds tests and introduces types that will be used in 2/2. Some of the added tests fail and demonstrate the issue being fixed with the current implementation. ----- Failures that demonstrate the bug: android.net.SntpClientTest#testRequestTime_era1ClientEra1Server STACKTRACE: junit.framework.AssertionFailedError: expected=5, actual=-4294967295995, allowedSlop=1 at junit.framework.Assert.fail(Assert.java:50) at junit.framework.Assert.assertTrue(Assert.java:20) at android.net.SntpClientTest.assertNearlyEquals(SntpClientTest.java:502) at android.net.SntpClientTest.checkRequestTimeCalcs(SntpClientTest.java:215) at android.net.SntpClientTest.testRequestTime_era1ClientEra1Server(SntpClientTest.java:201) android.net.SntpClientTest#testRequestTime_era0ClientEra1Server: FAILED (145ms) STACKTRACE: junit.framework.AssertionFailedError: expected=1139293696005, actual=-3155673599995, allowedSlop=1 at junit.framework.Assert.fail(Assert.java:50) at junit.framework.Assert.assertTrue(Assert.java:20) at android.net.SntpClientTest.assertNearlyEquals(SntpClientTest.java:502) at android.net.SntpClientTest.checkRequestTimeCalcs(SntpClientTest.java:215) at android.net.SntpClientTest.testRequestTime_era0ClientEra1Server(SntpClientTest.java:174) android.net.SntpClientTest#testNonMatchingOriginateTime: FAILED (116ms) STACKTRACE: junit.framework.AssertionFailedError at junit.framework.Assert.fail(Assert.java:48) at junit.framework.Assert.assertTrue(Assert.java:20) at junit.framework.Assert.assertFalse(Assert.java:34) at junit.framework.Assert.assertFalse(Assert.java:41) at android.net.SntpClientTest.testNonMatchingOriginateTime(SntpClientTest.java:384) ------ This commit: + Introduces a dedicated Timestamp64 type + test for holding NTP timestamps. + Introduces a dedicated Duration64 type + test for holding the 32-bit signed difference between two Timestamp64 instances. + Fixes some naming to add clarity / addresses lint issues. + Adjusts tests Tests are NOT expected to pass with just this commit. See 2/2. Bug: 199481251 Test: atest core/tests/coretests/src/android/net/sntp/Timestamp64Test.java Test: atest core/tests/coretests/src/android/net/sntp/Duration64Test.java Test: atest core/tests/coretests/src/android/net/SntpClientTest.java Merged-In: Ifdaada39298b05c48a3207fe6c0fad71c8a0a252 Change-Id: Ifdaada39298b05c48a3207fe6c0fad71c8a0a252
* Merge "Change the logic of getting ntp server"Dan Zhang2020-07-291-9/+19
|\
| * Change the logic of getting ntp serverKyeongkab.Nam2020-02-171-9/+19
| | | | | | | | | | | | | | | | | | Changed to refer multiple addresses as a fail-safe and added to check reference timestamp of ntp packet. Bug: 139905217 Test: sync time by NTP after AC off/on. Change-Id: I5ae5eca85ca679eded9d7878fb07a7b7617b2596
* | Update language to comply with Android's inclusive language guidanceChiachang Wang2020-07-281-1/+1
|/ | | | | | | | | See https://source.android.com/setup/contribute/respectful-code for reference. Bug: 161896447 Test: m Change-Id: I6c3c03c0c2d1302af6d5245486823c13a3432900
* Use new UnsupportedAppUsage annotation.Artur Satayev2020-01-081-1/+1
| | | | | | | | | Existing annotations in libcore/ and frameworks/ will deleted after the migration. This also means that any java library that compiles @UnsupportedAppUsage requires a direct dependency on "unsupportedappusage" java_library. Bug: 145132366 Test: m && diff unsupportedappusage_index.csv Change-Id: I0c336de56bc4a041dc97ff9b7927f62f0b44b457 Merged-In: I0c336de56bc4a041dc97ff9b7927f62f0b44b457
* Add @UnsupportedAppUsage annotations for greylist.Artur Satayev2019-11-081-0/+4
| | | | | | | | | | | | go/cleanup-greylist-txt These have already been greylisted, however due to bugs/omissions in the tooling have been kept in go/greylist-txt instead of being annotated in the code. Bug: 137350495 Test: m Change-Id: Id6c1f5e403a0e66edb1102ee45f3bf19f244fb09 Merged-In: Id6c1f5e403a0e66edb1102ee45f3bf19f244fb09
* Move TrafficStats tags for the network stack constantsChalard Jean2019-04-171-1/+4
| | | | | | | | | | | | As per API council feedback, these constants should live in a place that is private to the network stack, only with a range defined in system API. Bug: 129433383 Test: m Change-Id: I84a90f84a9af6fef4667ee4d512ebd0413222086 Merged-In: I4882686a86e7c6d42f4b0619b921d02619ed6d4c Merged-In: I9b648ed6c687d56db61a54570c7880c51c1bae51
* Remove ResolveUtil from frameworks/base callersErik Kline2018-08-281-6/+3
| | | | | | | | | | | | | | | | | | | | Use the Private DNS bypass logic that was moved into Network. Once all callers of ResolvUtil are updated to use this interface ResolvUtil can be deleted. Test: as follows - built, flashed, booted - runtest frameworks-net passes - connection to captive portal network detects portal correctly and the login activity functions as expected Bug: 64133961 Bug: 72345192 Bug: 73872000 Bug: 78548486 Change-Id: If11ef2b5ffdc729f8449cf18dccd5f1eccbc51e6
* Add @UnsupportedAppUsage annotationsMathew Inwood2018-08-141-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For packages: android.net.wimax android.net.wifi.p2p.nsd android.net.wifi.p2p android.net.wifi.hotspot2.pps android.net.wifi.hotspot2.omadm android.net.wifi.hotspot2 android.net.wifi.aware android.net.wifi android.net.util android.net.sip android.net.rtp android.net.nsd android.net.metrics android.net.lowpan android.net.http android.net.captiveportal android.net This is an automatically generated CL. See go/UnsupportedAppUsage for more details. Exempted-From-Owner-Approval: Mechanical changes to the codebase which have been approved by Android API council and announced on android-eng@ Bug: 110868826 Test: m Change-Id: Ie25423113ee1a8071cd5039382c00de6ce0af7fd Merged-In: I520be7a4c79e68310c12e4f55bf66acaa94145a1
* Fixup SntpClient to bypass Private DNSErik Kline2018-05-241-0/+4
| | | | | | | | | | | | | | | | | NTP may be necessary in order to validate Private DNS certificates, so it should be allowed to bypass Private DNS. Test: as follows - built, flashed, booted - tcpdump for port 53; adb shell am restart queries for the NTP hostname appear in the clear - runtest frameworks-net passes Bug: 64133961 Bug: 80118648 Merged-In: I4655e3ce5691098c73bf070b8a9e4759485bb17a Merged-In: I327b816a9f472e94328232157a3b8887d17b0baf Change-Id: Id9ceb3fcaaffb48cbbd4cd381d48cae991572c9e (cherry picked from commit 7eccfeb9ca60aa6e09afbdf3a4435cb2f0d12987)
* Allow specifying a network for SNTP time syncKurt Marcinkiewicz2018-05-161-4/+12
| | | | | | | | | | | | | | | | | | | Permits syncing over a specific network instead of the default for the process. This was causing an issue with Android Wear devices paired with iOS where the default network is bluetooth (see b/32663274). This CL is in support of ag/3776564 Bug: 32663274 Test: adb shell am instrument -e class android.net.SntpClientTest -w \ com.android.frameworks.coretests/android.support.test.runner.AndroidJUnitRunner (cherry-pick of pi-dev Ic9fc169cf75457810d4992121d85d7642e350b90) Merged-In: I339c77063c72a9d76a5c4cb17052e20fb6e045a6 Merged-In: I8dfd1cad99c63efdc14c174c19f094a61cdfc44f Change-Id: I44df66688292b144ec7dfcdd9ae5d82489f82774
* StrictMode to detect untagged network traffic.Jeff Sharkey2017-01-191-0/+2
| | | | | | | | | | | | | | | Network usage is tracked by the kernel at the UID level, which is granular enough for normal apps, but large components (such as the system server) are impossible to debug without adding additional socket tagging to help identify subsystems within a UID. To help ensure that system components tag all their network traffic, this change offers a new StrictMode option to detect and report untagged sockets. Test: builds, boots, all common traffic tagged Bug: 30943431, 30414041 Change-Id: I825c7941076054732264690247de2863342638e2
* Switch over to new "time.android.com" NTP pool.Jeff Sharkey2016-12-021-2/+4
| | | | | | | | Also add logging to measure success/failure details. Test: builds, boots, and NTP fix obtained Bug: 32969463 Change-Id: I66a8a78480e087acdcf8a11e79f80b7a7a4969c9
* Incorrect time used in some NTP server responsesJerry Wong2015-10-171-17/+78
| | | | | | | | | | | | | | | | | | | | | | | Per RFC 4330, a NTP server response should be discarded when: - the stratum is 0 (unspecified), or - the leap indicator is 3 (unsync'ed), or - the mode is not 4 (server) / 5 (broadcast), or - the transmitted time is 0. Update SntpClient so that such responses would be discarded. Additionally: - make some variables suitably "final" - enable logging - add alternate requestTime() for testing - add some miniscule test coverage Cherry-picked from Jerry Wong's https://partner-android-review.googlesource.com/#/c/460074 Bug: 24719581 Change-Id: Id11a79a6e53ce95500ed4b4d691a29c260666f6c
* Remove unused imports from frameworks/base.John Spurlock2013-11-201-1/+0
| | | | Change-Id: Ia1f99bd2c1105b0b0f70aa614f1f4a67b2840906
* Remove the deprecated things from Config.java. These haven't been working ↵Joe Onorato2011-04-071-4/+3
| | | | | | since before 1.0. Change-Id: Ic2e8fa68797ea9d486f4117f3d82c98233cdab1e
* Avoid leaking sockets.Nick Kralevich2010-12-131-2/+6
| | | | | | | | | | | When a DNS lookup fails, we end up creating a datagram socket but never properly close it. This wastes limited valuable file descriptors and causes CTS test failures. Generally, we should ensure that sockets or files are opened in a try block, and closed in a finally block. Bug: 3276283 Change-Id: I3432f3bc061268c7367948230f6edbdfcec55892
* Trim throttle logs.Robert Greenwalt2010-04-221-4/+4
| | | | | | | Removing unwanted sntp logging and throttle logging. bug:2614927 Change-Id: Ic0b1c3502ebbc1f04130d09d715591af6513f439
* Fix SntpClient to give accurate time info.Robert Greenwalt2010-04-151-4/+13
| | | | | | | | | Old calc was off by 2x and was affected by the user-settable system clock. The error came because it was calculating the offset between our clock and the NTP clock and the algebra had two factors of the offset instead of the desired 1. bug:2600010 Change-Id: I0856091d32b50e6909e4889fb98df819e0aeabbe
* auto import from //depot/cupcake/@135843The Android Open Source Project2009-03-031-0/+201
|
* auto import from //depot/cupcake/@135843The Android Open Source Project2009-03-031-201/+0
|
* Initial ContributionThe Android Open Source Project2008-10-211-0/+201