Od 27 marca 2025 r. zalecamy używanie android-latest-release
zamiast aosp-main
do kompilowania i wspołtworzenia AOSP. Więcej informacji znajdziesz w artykule o zmianach w AOSP.
Wykrywanie czasu zewnętrznego
Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
Od Androida 12 system może opcjonalnie używać zewnętrznego źródła czasu, aby sugerować czasy epoki uniksowej usłudze time_detector
.
W AOSP ta funkcja nie jest domyślnie włączona.
Zewnętrzne źródło czasu umożliwia producentom urządzeń dostarczanie do Androida w pełni dostosowanych sugestii dotyczących czasu. Po otrzymaniu sugestii z zewnętrznego źródła czasu usługa time_detector
określa, czy zaktualizować zegar systemowy, korzystając ze skonfigurowanych reguł ustalania priorytetów.
Implementacja
Aby obsługiwać wykrywanie czasu zewnętrznego, producenci urządzeń muszą wdrożyć komponent, który przesyła sugestie dotyczące czasu zewnętrznego do usługi time_detector
za pomocą wywołania interfejsu API systemu.
Aby skonfigurować zewnętrzne pochodzenie, użyj pliku konfiguracji serwera systemu core/res/res/values/config.xml
. Dodaj wartość external
do
config_autoTimeSourcesPriority
.
Poniższy przykład pokazuje, że Android ma przyznawać zewnętrznym sugestiom czasu najwyższy priorytet podczas ustawiania zegara systemowego. Jeśli nie ma dostępnej prawidłowej sugestii czasu zewnętrznego, używane jest kolejne źródło, w tym przypadku gnss
.
<string-array name="config_autoTimeSourcesPriority">
<item>external</item>
<item>gnss</item>
</string-array>
Aby przekazać systemowi zewnętrzną sugestię dotyczącą czasu, użyj metody suggestExternalTime()
w TimeManager
. Jeśli zewnętrzne źródło jest skonfigurowane za pomocą config_autoTimeSourcesPriority
w pliku konfiguracyjnym i nie ma dostępnych sugestii czasu o wyższym priorytecie, Android używa sygnatury czasowej przekazanej do tej metody, aby ustawić bieżący czas epoki uniksowej.
Treść strony i umieszczone na niej fragmenty kodu podlegają licencjom opisanym w Licencji na treści. Java i OpenJDK są znakami towarowymi lub zastrzeżonymi znakami towarowymi należącymi do firmy Oracle lub jej podmiotów stowarzyszonych.
Ostatnia aktualizacja: 2025-08-27 UTC.
[[["Łatwo zrozumieć","easyToUnderstand","thumb-up"],["Rozwiązało to mój problem","solvedMyProblem","thumb-up"],["Inne","otherUp","thumb-up"]],[["Brak potrzebnych mi informacji","missingTheInformationINeed","thumb-down"],["Zbyt skomplikowane / zbyt wiele czynności do wykonania","tooComplicatedTooManySteps","thumb-down"],["Nieaktualne treści","outOfDate","thumb-down"],["Problem z tłumaczeniem","translationIssue","thumb-down"],["Problem z przykładami/kodem","samplesCodeIssue","thumb-down"],["Inne","otherDown","thumb-down"]],["Ostatnia aktualizacja: 2025-08-27 UTC."],[],[],null,["From Android 12, Android can optionally use an external\nsource of time to suggest Unix epoch times to the [`time_detector`](/docs/core/connect/time#time_detector-service) service.\nThis isn't enabled by default in AOSP.\n\nThe *external* time origin allows device manufacturers to provide completely\ncustom time suggestions to Android. After receiving suggestions from the\nexternal time origin, the `time_detector` service determines whether to update\nthe system clock using the configured [prioritization rules](/docs/core/connect/time#automatic-time).\n\nImplementation\n\nTo support external time detection, device manufacturers must implement a\ncomponent that submits external time suggestions to the `time_detector` service\nthrough a system API call.\n\nTo configure the external origin, use the `core/res/res/values/config.xml`\nsystem server configuration file. Add the value `external` to\n`config_autoTimeSourcesPriority`.\n\nThe following example tells Android to give external time suggestions the\nhighest priority when setting the system clock. If there is no valid external\ntime suggestion available then the next origin, `gnss` in this case, is used. \n\n \u003cstring-array name=\"config_autoTimeSourcesPriority\"\u003e\n \u003citem\u003eexternal\u003c/item\u003e\n \u003citem\u003egnss\u003c/item\u003e\n \u003c/string-array\u003e\n\nTo provide the system with an external time suggestion, use the\n[`suggestExternalTime()`](https://cs.android.com/android/platform/superproject/+/android-latest-release:frameworks/base/core/java/android/app/time/TimeManager.java?q=%22void%20suggestExternalTime%22) method in `TimeManager`. If the external origin is\nconfigured using `config_autoTimeSourcesPriority` in the configuration file and\nno higher priority time suggestions are available, Android uses the timestamp\npassed to this method to set the current Unix epoch time."]]