Android系统开发之TimeZoneDetectorService浅析--下

本文详细描述了TimeZoneDetectorService类如何通过TimeZoneDetectorStrategy实现自动时区检测,涉及Geolocation、Manual和Telephony三种更新方式,并着重介绍了doAutoTimeZoneDetection方法的逻辑处理过程。
摘要由CSDN通过智能技术生成

TimeZoneDetectorService类图

在这里插入图片描述

可以看出TimeZoneDetectorService类,其具体实现是由TimeZoneDetectorStrategy类完成的。

在TimeZoneDetectorService类中,三种更新时区的接口分别为:

suggestGeolocationTimeZone()   //更新时区主要有三种方式 ,这是Geolocation方式
+boolean suggestManualTimeZone()  //更新时区主要有三种方式 ,这是手动Manual方式
+void suggestTelephonyTimeZone( //更新时区主要有三种方式 ,这是手动telephony方式

而在TimeZoneDetectorStrategy中,三种更新时区的接口分别为:

void suggestTelephonyTimeZone()//这对应用telephony更新时区
boolean suggestManualTimeZone()//这对应用手动Manual更新时区
+void suggestGeolocationTimeZone()//这对应用Geolocation更新时区

其我们上面提到的doAutoTimeZoneDetection接口,更是关注的重点:

doAutoTimeZoneDetection()//针对三种更新时区的方式来更新时区
private void doAutoTimeZoneDetection(
        @NonNull ConfigurationInternal currentUserConfig, @NonNull String detectionReason) {
    // Use the correct algorithm based on the user's current configuration. If it changes, then
    // detection will be re-run.
    switch (currentUserConfig.getDetectionMode()) {
        case ConfigurationInternal.DETECTION_MODE_MANUAL:
            // No work to do.
            break;
        case ConfigurationInternal.DETECTION_MODE_GEO: {
            boolean isGeoDetectionCertain = doGeolocationTimeZoneDetection(detectionReason);
            // When geolocation detection is uncertain of the time zone, telephony detection
            // can be used if telephony fallback is enabled and supported.
            if (!isGeoDetectionCertain
                    && mTelephonyTimeZoneFallbackEnabled.getValue()
                    && currentUserConfig.isTelephonyFallbackSupported()) {
                doTelephonyTimeZoneDetection(detectionReason + ", telephony fallback mode");
            }
            break;
        }
        case ConfigurationInternal.DETECTION_MODE_TELEPHONY:
            doTelephonyTimeZoneDetection(detectionReason);
            break;
        default:
            Slog.wtf(LOG_TAG, "Unknown detection mode: "
                    + currentUserConfig.getDetectionMode());
    }
}
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hfreeman2008

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值