Loading src/java/com/android/internal/telephony/MccTable.java +2 −2 Original line number Diff line number Diff line Loading @@ -360,11 +360,11 @@ public final class MccTable { private static void setTimezoneFromMccIfNeeded(Context context, int mcc) { // Switch to use the time service helper associated with the NitzStateMachine impl // being used. This logic will be removed once the old implementation is removed. if (!NewTimeServiceHelper.isTimeZoneSettingInitializedStatic()) { if (!TimeServiceHelperImpl.isTimeZoneSettingInitializedStatic()) { String zoneId = defaultTimeZoneForMcc(mcc); if (zoneId != null && zoneId.length() > 0) { // Set time zone based on MCC NewTimeServiceHelper.setDeviceTimeZoneStatic(context, zoneId); TimeServiceHelperImpl.setDeviceTimeZoneStatic(context, zoneId); Slog.d(LOG_TAG, "timezone set to " + zoneId); } } Loading src/java/com/android/internal/telephony/NitzStateMachine.java +33 −14 Original line number Diff line number Diff line Loading @@ -83,8 +83,34 @@ public interface NitzStateMachine { * A proxy over device state that allows things like system properties, system clock * to be faked for tests. */ // Non-final to allow mocking. class DeviceState { interface DeviceState { /** * If time between NITZ updates is less than {@link #getNitzUpdateSpacingMillis()} the * update may be ignored. */ int getNitzUpdateSpacingMillis(); /** * If {@link #getNitzUpdateSpacingMillis()} hasn't been exceeded but update is > * {@link #getNitzUpdateDiffMillis()} do the update */ int getNitzUpdateDiffMillis(); /** * Returns true if the {@code gsm.ignore-nitz} system property is set to "yes". */ boolean getIgnoreNitz(); String getNetworkCountryIsoForPhone(); } /** * The real implementation of {@link DeviceState}. * * {@hide} */ class DeviceStateImpl implements DeviceState { private static final int NITZ_UPDATE_SPACING_DEFAULT = 1000 * 60 * 10; private final int mNitzUpdateSpacing; Loading @@ -95,7 +121,7 @@ public interface NitzStateMachine { private final TelephonyManager mTelephonyManager; private final ContentResolver mCr; public DeviceState(GsmCdmaPhone phone) { public DeviceStateImpl(GsmCdmaPhone phone) { mPhone = phone; Context context = phone.getContext(); Loading @@ -108,31 +134,24 @@ public interface NitzStateMachine { SystemProperties.getInt("ro.nitz_update_diff", NITZ_UPDATE_DIFF_DEFAULT); } /** * If time between NITZ updates is less than {@link #getNitzUpdateSpacingMillis()} the * update may be ignored. */ @Override public int getNitzUpdateSpacingMillis() { return Settings.Global.getInt(mCr, Settings.Global.NITZ_UPDATE_SPACING, mNitzUpdateSpacing); } /** * If {@link #getNitzUpdateSpacingMillis()} hasn't been exceeded but update is > * {@link #getNitzUpdateDiffMillis()} do the update */ @Override public int getNitzUpdateDiffMillis() { return Settings.Global.getInt(mCr, Settings.Global.NITZ_UPDATE_DIFF, mNitzUpdateDiff); } /** * Returns true if the {@code gsm.ignore-nitz} system property is set to "yes". */ @Override public boolean getIgnoreNitz() { String ignoreNitz = SystemProperties.get("gsm.ignore-nitz"); return ignoreNitz != null && ignoreNitz.equals("yes"); } @Override public String getNetworkCountryIsoForPhone() { return mTelephonyManager.getNetworkCountryIsoForPhone(mPhone.getPhoneId()); } Loading src/java/com/android/internal/telephony/NewNitzStateMachine.java→src/java/com/android/internal/telephony/NitzStateMachineImpl.java +7 −7 Original line number Diff line number Diff line Loading @@ -35,7 +35,7 @@ import java.io.PrintWriter; /** * {@hide} */ public final class NewNitzStateMachine implements NitzStateMachine { public final class NitzStateMachineImpl implements NitzStateMachine { private static final String LOG_TAG = ServiceStateTracker.LOG_TAG; private static final boolean DBG = ServiceStateTracker.DBG; Loading Loading @@ -84,21 +84,21 @@ public final class NewNitzStateMachine implements NitzStateMachine { private final LocalLog mTimeZoneLog = new LocalLog(15); private final GsmCdmaPhone mPhone; private final DeviceState mDeviceState; private final NewTimeServiceHelper mTimeServiceHelper; private final TimeServiceHelper mTimeServiceHelper; private final TimeZoneLookupHelper mTimeZoneLookupHelper; /** Wake lock used while setting time of day. */ private final PowerManager.WakeLock mWakeLock; private static final String WAKELOCK_TAG = "NitzStateMachine"; public NewNitzStateMachine(GsmCdmaPhone phone) { public NitzStateMachineImpl(GsmCdmaPhone phone) { this(phone, new NewTimeServiceHelper(phone.getContext()), new DeviceState(phone), new TimeServiceHelperImpl(phone.getContext()), new DeviceStateImpl(phone), new TimeZoneLookupHelper()); } @VisibleForTesting public NewNitzStateMachine(GsmCdmaPhone phone, NewTimeServiceHelper timeServiceHelper, public NitzStateMachineImpl(GsmCdmaPhone phone, TimeServiceHelper timeServiceHelper, DeviceState deviceState, TimeZoneLookupHelper timeZoneLookupHelper) { mPhone = phone; Loading @@ -110,7 +110,7 @@ public final class NewNitzStateMachine implements NitzStateMachine { mDeviceState = deviceState; mTimeZoneLookupHelper = timeZoneLookupHelper; mTimeServiceHelper = timeServiceHelper; mTimeServiceHelper.setListener(new NewTimeServiceHelper.Listener() { mTimeServiceHelper.setListener(new TimeServiceHelper.Listener() { @Override public void onTimeZoneDetectionChange(boolean enabled) { if (enabled) { Loading src/java/com/android/internal/telephony/TelephonyComponentFactory.java +1 −1 Original line number Diff line number Diff line Loading @@ -296,7 +296,7 @@ public class TelephonyComponentFactory { * Returns a new {@link NitzStateMachine} instance. */ public NitzStateMachine makeNitzStateMachine(GsmCdmaPhone phone) { return new NewNitzStateMachine(phone); return new NitzStateMachineImpl(phone); } public SimActivationTracker makeSimActivationTracker(Phone phone) { Loading src/java/com/android/internal/telephony/TimeServiceHelper.java 0 → 100644 +79 −0 Original line number Diff line number Diff line /* * Copyright 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.internal.telephony; import android.app.timedetector.TimeDetector; import android.os.SystemClock; import android.util.TimestampedValue; /** * An interface to various time / time zone detection behaviors that should be centralized into a * new service. */ public interface TimeServiceHelper { /** * Callback interface for automatic detection enable/disable changes. */ interface Listener { /** * Automatic time zone detection has been enabled or disabled. */ void onTimeZoneDetectionChange(boolean enabled); } /** * Sets a listener that will be called when the automatic time / time zone detection setting * changes. */ void setListener(Listener listener); /** * Returns the same value as {@link System#currentTimeMillis()}. */ long currentTimeMillis(); /** * Returns the same value as {@link SystemClock#elapsedRealtime()}. */ long elapsedRealtime(); /** * Returns true if the device has an explicit time zone set. */ boolean isTimeZoneSettingInitialized(); /** * Returns true if automatic time zone detection is enabled in settings. */ boolean isTimeZoneDetectionEnabled(); /** * Set the device time zone and send out a sticky broadcast so the system can * determine if the timezone was set by the carrier. * * @param zoneId timezone set by carrier */ void setDeviceTimeZone(String zoneId); /** * Suggest the time to the {@link TimeDetector}. * * @param signalTimeMillis the signal time as received from the network */ void suggestDeviceTime(TimestampedValue<Long> signalTimeMillis); } Loading
src/java/com/android/internal/telephony/MccTable.java +2 −2 Original line number Diff line number Diff line Loading @@ -360,11 +360,11 @@ public final class MccTable { private static void setTimezoneFromMccIfNeeded(Context context, int mcc) { // Switch to use the time service helper associated with the NitzStateMachine impl // being used. This logic will be removed once the old implementation is removed. if (!NewTimeServiceHelper.isTimeZoneSettingInitializedStatic()) { if (!TimeServiceHelperImpl.isTimeZoneSettingInitializedStatic()) { String zoneId = defaultTimeZoneForMcc(mcc); if (zoneId != null && zoneId.length() > 0) { // Set time zone based on MCC NewTimeServiceHelper.setDeviceTimeZoneStatic(context, zoneId); TimeServiceHelperImpl.setDeviceTimeZoneStatic(context, zoneId); Slog.d(LOG_TAG, "timezone set to " + zoneId); } } Loading
src/java/com/android/internal/telephony/NitzStateMachine.java +33 −14 Original line number Diff line number Diff line Loading @@ -83,8 +83,34 @@ public interface NitzStateMachine { * A proxy over device state that allows things like system properties, system clock * to be faked for tests. */ // Non-final to allow mocking. class DeviceState { interface DeviceState { /** * If time between NITZ updates is less than {@link #getNitzUpdateSpacingMillis()} the * update may be ignored. */ int getNitzUpdateSpacingMillis(); /** * If {@link #getNitzUpdateSpacingMillis()} hasn't been exceeded but update is > * {@link #getNitzUpdateDiffMillis()} do the update */ int getNitzUpdateDiffMillis(); /** * Returns true if the {@code gsm.ignore-nitz} system property is set to "yes". */ boolean getIgnoreNitz(); String getNetworkCountryIsoForPhone(); } /** * The real implementation of {@link DeviceState}. * * {@hide} */ class DeviceStateImpl implements DeviceState { private static final int NITZ_UPDATE_SPACING_DEFAULT = 1000 * 60 * 10; private final int mNitzUpdateSpacing; Loading @@ -95,7 +121,7 @@ public interface NitzStateMachine { private final TelephonyManager mTelephonyManager; private final ContentResolver mCr; public DeviceState(GsmCdmaPhone phone) { public DeviceStateImpl(GsmCdmaPhone phone) { mPhone = phone; Context context = phone.getContext(); Loading @@ -108,31 +134,24 @@ public interface NitzStateMachine { SystemProperties.getInt("ro.nitz_update_diff", NITZ_UPDATE_DIFF_DEFAULT); } /** * If time between NITZ updates is less than {@link #getNitzUpdateSpacingMillis()} the * update may be ignored. */ @Override public int getNitzUpdateSpacingMillis() { return Settings.Global.getInt(mCr, Settings.Global.NITZ_UPDATE_SPACING, mNitzUpdateSpacing); } /** * If {@link #getNitzUpdateSpacingMillis()} hasn't been exceeded but update is > * {@link #getNitzUpdateDiffMillis()} do the update */ @Override public int getNitzUpdateDiffMillis() { return Settings.Global.getInt(mCr, Settings.Global.NITZ_UPDATE_DIFF, mNitzUpdateDiff); } /** * Returns true if the {@code gsm.ignore-nitz} system property is set to "yes". */ @Override public boolean getIgnoreNitz() { String ignoreNitz = SystemProperties.get("gsm.ignore-nitz"); return ignoreNitz != null && ignoreNitz.equals("yes"); } @Override public String getNetworkCountryIsoForPhone() { return mTelephonyManager.getNetworkCountryIsoForPhone(mPhone.getPhoneId()); } Loading
src/java/com/android/internal/telephony/NewNitzStateMachine.java→src/java/com/android/internal/telephony/NitzStateMachineImpl.java +7 −7 Original line number Diff line number Diff line Loading @@ -35,7 +35,7 @@ import java.io.PrintWriter; /** * {@hide} */ public final class NewNitzStateMachine implements NitzStateMachine { public final class NitzStateMachineImpl implements NitzStateMachine { private static final String LOG_TAG = ServiceStateTracker.LOG_TAG; private static final boolean DBG = ServiceStateTracker.DBG; Loading Loading @@ -84,21 +84,21 @@ public final class NewNitzStateMachine implements NitzStateMachine { private final LocalLog mTimeZoneLog = new LocalLog(15); private final GsmCdmaPhone mPhone; private final DeviceState mDeviceState; private final NewTimeServiceHelper mTimeServiceHelper; private final TimeServiceHelper mTimeServiceHelper; private final TimeZoneLookupHelper mTimeZoneLookupHelper; /** Wake lock used while setting time of day. */ private final PowerManager.WakeLock mWakeLock; private static final String WAKELOCK_TAG = "NitzStateMachine"; public NewNitzStateMachine(GsmCdmaPhone phone) { public NitzStateMachineImpl(GsmCdmaPhone phone) { this(phone, new NewTimeServiceHelper(phone.getContext()), new DeviceState(phone), new TimeServiceHelperImpl(phone.getContext()), new DeviceStateImpl(phone), new TimeZoneLookupHelper()); } @VisibleForTesting public NewNitzStateMachine(GsmCdmaPhone phone, NewTimeServiceHelper timeServiceHelper, public NitzStateMachineImpl(GsmCdmaPhone phone, TimeServiceHelper timeServiceHelper, DeviceState deviceState, TimeZoneLookupHelper timeZoneLookupHelper) { mPhone = phone; Loading @@ -110,7 +110,7 @@ public final class NewNitzStateMachine implements NitzStateMachine { mDeviceState = deviceState; mTimeZoneLookupHelper = timeZoneLookupHelper; mTimeServiceHelper = timeServiceHelper; mTimeServiceHelper.setListener(new NewTimeServiceHelper.Listener() { mTimeServiceHelper.setListener(new TimeServiceHelper.Listener() { @Override public void onTimeZoneDetectionChange(boolean enabled) { if (enabled) { Loading
src/java/com/android/internal/telephony/TelephonyComponentFactory.java +1 −1 Original line number Diff line number Diff line Loading @@ -296,7 +296,7 @@ public class TelephonyComponentFactory { * Returns a new {@link NitzStateMachine} instance. */ public NitzStateMachine makeNitzStateMachine(GsmCdmaPhone phone) { return new NewNitzStateMachine(phone); return new NitzStateMachineImpl(phone); } public SimActivationTracker makeSimActivationTracker(Phone phone) { Loading
src/java/com/android/internal/telephony/TimeServiceHelper.java 0 → 100644 +79 −0 Original line number Diff line number Diff line /* * Copyright 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.internal.telephony; import android.app.timedetector.TimeDetector; import android.os.SystemClock; import android.util.TimestampedValue; /** * An interface to various time / time zone detection behaviors that should be centralized into a * new service. */ public interface TimeServiceHelper { /** * Callback interface for automatic detection enable/disable changes. */ interface Listener { /** * Automatic time zone detection has been enabled or disabled. */ void onTimeZoneDetectionChange(boolean enabled); } /** * Sets a listener that will be called when the automatic time / time zone detection setting * changes. */ void setListener(Listener listener); /** * Returns the same value as {@link System#currentTimeMillis()}. */ long currentTimeMillis(); /** * Returns the same value as {@link SystemClock#elapsedRealtime()}. */ long elapsedRealtime(); /** * Returns true if the device has an explicit time zone set. */ boolean isTimeZoneSettingInitialized(); /** * Returns true if automatic time zone detection is enabled in settings. */ boolean isTimeZoneDetectionEnabled(); /** * Set the device time zone and send out a sticky broadcast so the system can * determine if the timezone was set by the carrier. * * @param zoneId timezone set by carrier */ void setDeviceTimeZone(String zoneId); /** * Suggest the time to the {@link TimeDetector}. * * @param signalTimeMillis the signal time as received from the network */ void suggestDeviceTime(TimestampedValue<Long> signalTimeMillis); }