一、默认关闭自动更新时区
将自动更新时区开关 def_auto_time_zone 的值设置为 false。
文件路径:platform/frameworks/base/packages/SettingsProvider/res/values/defaults.xml
二、自动更新时区打开,设置默认时区不生效问题
当你 persist.sys.timezone 配置了这个没用,那可能和设备驻留到紧急网络上,会根据网络上报的国家码进行匹配并更新时区
2.1 android10.0(Q) 解决办法
frameworks/opt/telephony/src/java/com/android/internal/telephony/NewNitzStateMachine.java
import java.io.FileDescriptor;
import java.io.PrintWriter;
+
+import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppState;
+import com.android.internal.telephony.uicc.UiccCardApplication;
+
+
@@ -394,6 +399,12 @@ public final class NewNitzStateMachine implements NitzStateMachine {
if (DBG) {
Rlog.d(LOG_TAG, "setAndBroadcastNetworkSetTimeZone: zoneId=" + zoneId);
}
+
+ UiccCardApplication uiccApp = mPhone.getUiccCardApplication();
+ if (uiccApp == null || uiccApp.getState() == AppState.APPSTATE_UNKNOWN) {
+ Rlog.d(LOG_TAG, "Not to set network time zone due to sim absent");
+ return;
+ }
mTimeServiceHelper.setDeviceTimeZone(zoneId);
if (DBG) {
Rlog.d(LOG_TAG,
2.2 android11.0? 解决办法
frameworks/opt/telephony/src/java/com/android/internal/telephony/nitz/TimeServiceHelperImpl.java
+import com.android.internal.telephony.GsmCdmaPhone;
+import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppState;
+import com.android.internal.telephony.uicc.UiccCardApplication;
@@ -40,6 +43,7 @@ import java.util.Objects;
public final class TimeServiceHelperImpl implements TimeServiceHelper {
private final int mSlotIndex;
+ private Phone mPhone;
private final TimeDetector mTimeDetector;
private final TimeZoneDetector mTimeZoneDetector;
@@ -56,6 +60,7 @@ public final class TimeServiceHelperImpl implements TimeServiceHelper {
public TimeServiceHelperImpl(@NonNull Phone phone) {
mSlotIndex = phone.getPhoneId();
+ mPhone = phone;
Context context = Objects.requireNonNull(phone.getContext());
mTimeDetector = Objects.requireNonNull(context.getSystemService(TimeDetector.class));
mTimeZoneDetector =
@@ -79,6 +84,11 @@ public final class TimeServiceHelperImpl implements TimeServiceHelper {
public void maybeSuggestDeviceTimeZone(@NonNull TelephonyTimeZoneSuggestion newSuggestion) {
Objects.requireNonNull(newSuggestion);
+ UiccCardApplication uiccApp = ((GsmCdmaPhone) mPhone).getUiccCardApplication();
+ if (uiccApp == null || uiccApp.getState() == AppState.APPSTATE_UNKNOWN) {
+ mTimeLog.log("Not to set network time zone due to sim absent.");
+ return;
+ }
TelephonyTimeZoneSuggestion oldSuggestion = mLastSuggestedTimeZone;
if (shouldSendNewTimeZoneSuggestion(oldSuggestion, newSuggestion)) {
mTimeZoneLog.log("Suggesting time zone update: " + newSuggestion);
|