Android13修改系统支持gps同步时间
Android 12以后系统支持使用gps定位(GNSS)数据来同步系统时间,但是系统默认没有打开支持,从framework下的core/res/res/values/config.xml配置中,可以看到系统默认只支持电话信号同步基站时间和网络同步时间。
<!-- Specifies priority of automatic time sources. Suggestions from higher entries in the listtake precedence over lower ones. See com.android.server.timedetector.TimeDetectorStrategy foravailable sources. -->
<string-array name="config_autoTimeSourcesPriority"><item>telephony</item><item>network</item>
</string-array>telephony:使用网络身份和时区 (NITZ) 电话信号。network:使用网络时间协议 (NTP) 时间服务器。
要使用gps(GNSS)时间源同步时间,首先要修改上面的config_autoTimeSourcesPriority,添加GNSS:
<!-- Specifies priority of automatic time sources. Suggestions from higher entries in the listtake precedence over lower ones.See com.android.server.timedetector.TimeDetectorStrategy for available sources. -->
<string-array name="config_autoTimeSourcesPriority"><item>telephony</item><item>network</item><item>gnss</item>
</string-array><!-- Enables the GnssTimeUpdate service. This is the global switch for enabling Gnss time basedsuggestions to TimeDetector service. See also config_autoTimeSourcesPriority. -->
<bool name="config_enableGnssTimeUpdateService">true</bool>同时还需要修改文件里面的 config_enableGnssTimeUpdateService 的值设置为 true。
修改上面的配置以后,机器开机后,当有应用请求了gps定位,获取定位数据以后就会同步机器的时间。
如果需要每次开机都自动通过gps同步一下系统时间,可以修改系统开机完成后,去请求获取一下GPS的定位,代码很简单,直接让AI接一个类和函数,添加到开机广播中去执行就可以了。
