Kể từ ngày 27 tháng 3 năm 2025, bạn nên sử dụng android-latest-release
thay vì aosp-main
để xây dựng và đóng góp cho AOSP. Để biết thêm thông tin, hãy xem phần Thay đổi đối với AOSP.
Phát hiện thời gian bên ngoài
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Từ Android 12, Android có thể tuỳ ý sử dụng nguồn thời gian bên ngoài để đề xuất thời gian theo thời gian Unix cho dịch vụ time_detector
.
Tính năng này không được bật theo mặc định trong AOSP.
Nguồn gốc thời gian bên ngoài cho phép nhà sản xuất thiết bị cung cấp các đề xuất hoàn toàn tuỳ chỉnh về thời gian cho Android. Sau khi nhận được đề xuất từ nguồn thời gian bên ngoài, dịch vụ time_detector
sẽ xác định xem có nên cập nhật đồng hồ hệ thống bằng cách sử dụng các quy tắc ưu tiên đã định cấu hình hay không.
Triển khai
Để hỗ trợ tính năng phát hiện thời gian bên ngoài, nhà sản xuất thiết bị phải triển khai một thành phần gửi đề xuất về thời gian bên ngoài đến dịch vụ time_detector
thông qua một lệnh gọi API hệ thống.
Để định cấu hình nguồn bên ngoài, hãy sử dụng tệp cấu hình máy chủ hệ thống core/res/res/values/config.xml
. Thêm giá trị external
vào config_autoTimeSourcesPriority
.
Ví dụ sau đây cho biết Android sẽ ưu tiên cao nhất cho các đề xuất về thời gian bên ngoài khi đặt đồng hồ hệ thống. Nếu không có đề xuất hợp lệ nào về thời gian bên ngoài, thì nguồn gốc tiếp theo (gnss
trong trường hợp này) sẽ được sử dụng.
<string-array name="config_autoTimeSourcesPriority">
<item>external</item>
<item>gnss</item>
</string-array>
Để cung cấp cho hệ thống một đề xuất về thời gian bên ngoài, hãy sử dụng phương thức suggestExternalTime()
trong TimeManager
. Nếu nguồn bên ngoài được định cấu hình bằng config_autoTimeSourcesPriority
trong tệp cấu hình và không có đề xuất thời gian nào có mức độ ưu tiên cao hơn, thì Android sẽ dùng dấu thời gian được truyền đến phương thức này để đặt thời gian bắt đầu của hệ thống Unix hiện tại.
Nội dung và mã mẫu trên trang này phải tuân thủ các giấy phép như mô tả trong phần Giấy phép nội dung. Java và OpenJDK là nhãn hiệu hoặc nhãn hiệu đã đăng ký của Oracle và/hoặc đơn vị liên kết của Oracle.
Cập nhật lần gần đây nhất: 2025-08-27 UTC.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 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."]]