GNSS 시간 감지

Android 12부터 Android는 선택적으로 GNSS(Global Navigation Satellite System)를 사용하여 time_detector 서비스에 Unix epoch 시간을 제안할 수 있습니다. AOSP에서는 기본적으로 활성화되어 있지 않습니다.

GNSS 시간 감지가 활성화되면 gnss_time_update_service 는 GNSS 소스의 위치 업데이트를 수동적으로 수신 대기하고 time_detector 서비스에 GNSS 제안을 제출합니다. time_detector 서비스는 제안과 일치하도록 시스템 시계를 업데이트할지 여부를 결정합니다.

전력 사용에 미치는 영향

AOSP gnss_time_update_service 수동적으로 위치 업데이트를 수신합니다. 즉, GPS를 적극적으로 켜거나 추가 전력을 소비하지 않습니다. 이것은 또한 시스템의 다른 앱이나 서비스가 위치 업데이트를 적극적으로 요청하지 않는 한 gnss_time_update_service 가 위치 업데이트를 받지 않고 GNSS 시간을 제안한다는 것을 의미합니다.

구현

GNSS 시간 감지를 활성화하려면 장치 제조업체가 시스템 서버에서 gnss_time_update_service 를 명시적으로 활성화해야 합니다.

이 기능을 활성화하려면 core/res/res/values/config.xml 파일의 config_enableGnssTimeUpdateServiceconfig_autoTimeSourcesPriority 값을 모두 업데이트해야 합니다. config_enableGnssTimeUpdateService 의 값을 true 로 설정하고 config_autoTimeSourcesPriority 의 항목 목록에 gnss 를 추가합니다. 우선 순위 목록에서 gnss 의 위치는 다른 소스의 제안과 관련하여 GNSS 제안에 부여되는 우선 순위를 결정합니다.

다음은 GNSS 시간 감지가 활성화되고 gnssnetworktelephony 다음 우선 순위 목록에서 세 번째인 core/res/res/values/config.xml 파일의 예입니다.

<!-- Specifies priority of automatic time sources. Suggestions from higher entries in the list
         take precedence over lower ones.
         See com.android.server.timedetector.TimeDetectorStrategy for available sources. -->
    <string-array name="config_autoTimeSourcesPriority">
        <item>network</item>
        <item>telephony</item>
        <item>gnss</item>
    </string-array>

    <!-- Enables the GnssTimeUpdate service. This is the global switch for enabling Gnss time based
         suggestions to TimeDetector service. See also config_autoTimeSourcesPriority. -->
    <bool name="config_enableGnssTimeUpdateService">true</bool>

디버깅 및 테스트

GNSS 시간 감지를 테스트하려면 adb shell cmd location 명령을 사용할 수 있습니다. 이 명령을 사용하여 위치 및 관련 GNSS 시간을 지정할 수 있는 테스트 위치 제공자를 추가합니다. gnss_time_update_service 는 이러한 위치 업데이트를 수신하고 주기적으로 제안합니다.

다음은 adb shell cmd location 명령의 예를 보여줍니다.

# Enable Master Location Switch in the foreground user (usually user 10 on automotive). If you just flashed, this can be done through setup wizard.
adb shell cmd location set-location-enabled true --user 10

# Add GPS test provider (This usually fails the first time. Will throw a SecurityException with "android from <SOME_UID> not allowed to perform MOCK_LOCATION".)
adb shell cmd location providers add-test-provider gps

# Enable mock location permissions for previous UID
adb shell appops set UID_PRINTED_IN_PREVIOUS_ERROR android:mock_location allow

# Add GPS test provider (Should work with no errors.)
adb shell cmd location providers add-test-provider gps

# Enable GPS test provider
adb shell cmd location providers set-test-provider-enabled gps true

# Set location with time (Time can't be lower than the limit set by the lower bound.)
adb shell cmd location providers set-test-provider-location gps --location LATITUDE,LONGITUDE --time TIME