Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e3a49e5c authored by Neil Fuller's avatar Neil Fuller Committed by Gerrit Code Review
Browse files

Merge "Remove dead code: MccTable.defaultTimeZoneForMcc()"

parents 7cefbca7 37a81ded
Loading
Loading
Loading
Loading
+0 −20
Original line number Diff line number Diff line
@@ -90,26 +90,6 @@ public final class MccTable {
        }
    }

    /**
     * Returns a default time zone ID for the given MCC.
     * @param mcc Mobile Country Code
     * @return default TimeZone ID, or null if not specified
     */
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q,
            publicAlternatives = "There is no alternative for {@code MccTable.defaultTimeZoneForMcc"
                    + "}, but it was included in hidden APIs due to a static analysis false "
                    + "positive and has been made greylist-max-q. Please file a bug if you still "
                    + "require this API.")
    public static String defaultTimeZoneForMcc(int mcc) {
        MccEntry entry = entryForMcc(mcc);
        if (entry == null) {
            return null;
        }
        final String lowerCaseCountryCode = entry.mIso;
        TimeZoneLookupHelper timeZoneLookupHelper = new TimeZoneLookupHelper();
        return timeZoneLookupHelper.lookupDefaultTimeZoneIdByCountry(lowerCaseCountryCode);
    }

    /**
     * Given a GSM Mobile Country Code, returns
     * an ISO two-character country code if available.
+16 −35
Original line number Diff line number Diff line
@@ -69,7 +69,16 @@ public final class TimeServiceHelperImpl implements TimeServiceHelper {

    @Override
    public boolean isTimeZoneSettingInitialized() {
        return isTimeZoneSettingInitializedStatic();
        // timezone.equals("GMT") will be true and only true if the timezone was
        // set to a default value by the system server (when starting, system server
        // sets the persist.sys.timezone to "GMT" if it's not set). "GMT" is not used by
        // any code that sets it explicitly (in case where something sets GMT explicitly,
        // "Etc/GMT" Olsen ID would be used).
        // TODO(b/64056758): Remove "timezone.equals("GMT")" hack when there's a
        // better way of telling if the value has been defaulted.

        String timeZoneId = SystemProperties.get(TIMEZONE_PROPERTY);
        return timeZoneId != null && timeZoneId.length() > 0 && !timeZoneId.equals("GMT");

    }

@@ -84,44 +93,16 @@ public final class TimeServiceHelperImpl implements TimeServiceHelper {

    @Override
    public void setDeviceTimeZone(String zoneId) {
        setDeviceTimeZoneStatic(mContext, zoneId);
        AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
        alarmManager.setTimeZone(zoneId);
        Intent intent = new Intent(TelephonyIntents.ACTION_NETWORK_SET_TIMEZONE);
        intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
        intent.putExtra("time-zone", zoneId);
        mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
    }

    @Override
    public void suggestDeviceTime(PhoneTimeSuggestion phoneTimeSuggestion) {
        mTimeDetector.suggestPhoneTime(phoneTimeSuggestion);
    }

    /**
     * Static implementation of isTimeZoneSettingInitialized() for use from {@link MccTable}. This
     * is a hack to deflake TelephonyTests when running on a device with a real SIM: in that
     * situation real service events may come in while a TelephonyTest is running, leading to flakes
     * as the real / fake instance of TimeServiceHelper is swapped in and out from
     * {@link TelephonyComponentFactory}.
     */
    static boolean isTimeZoneSettingInitializedStatic() {
        // timezone.equals("GMT") will be true and only true if the timezone was
        // set to a default value by the system server (when starting, system server
        // sets the persist.sys.timezone to "GMT" if it's not set). "GMT" is not used by
        // any code that sets it explicitly (in case where something sets GMT explicitly,
        // "Etc/GMT" Olsen ID would be used).
        // TODO(b/64056758): Remove "timezone.equals("GMT")" hack when there's a
        // better way of telling if the value has been defaulted.

        String timeZoneId = SystemProperties.get(TIMEZONE_PROPERTY);
        return timeZoneId != null && timeZoneId.length() > 0 && !timeZoneId.equals("GMT");
    }

    /**
     * Static method for use by MccTable. See {@link #isTimeZoneSettingInitializedStatic()} for
     * explanation.
     */
    static void setDeviceTimeZoneStatic(Context context, String zoneId) {
        AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        alarmManager.setTimeZone(zoneId);
        Intent intent = new Intent(TelephonyIntents.ACTION_NETWORK_SET_TIMEZONE);
        intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
        intent.putExtra("time-zone", zoneId);
        context.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
    }
}
+20 −40
Original line number Diff line number Diff line
@@ -214,7 +214,26 @@ public class TimeZoneLookupHelper {
     */
    @Nullable
    public OffsetResult lookupByNitz(@NonNull NitzData nitzData) {
        return lookupByNitzStatic(nitzData);
        int utcOffsetMillis = nitzData.getLocalOffsetMillis();
        long timeMillis = nitzData.getCurrentTimeInMillis();

        // Android NITZ time zone matching doesn't try to do a precise match using the DST offset
        // supplied by the carrier. It only considers whether or not the carrier suggests local time
        // is DST (if known). NITZ is limited in only being able to express DST offsets in whole
        // hours and the DST info is optional.
        Integer dstAdjustmentMillis = nitzData.getDstAdjustmentMillis();
        Boolean isDst = dstAdjustmentMillis == null ? null : dstAdjustmentMillis != 0;

        OffsetResult match = lookupByInstantOffsetDst(timeMillis, utcOffsetMillis, isDst);
        if (match == null && isDst != null) {
            // This branch is extremely unlikely and could probably be removed. The match above will
            // have searched the entire tzdb for a zone with the same total offset and isDst state.
            // Here we try another match but use "null" for isDst to indicate that only the total
            // offset should be considered. If, by the end of this, there isn't a match then the
            // current offset suggested by the carrier must be highly unusual.
            match = lookupByInstantOffsetDst(timeMillis, utcOffsetMillis, null /* isDst */);
        }
        return match;
    }

    /**
@@ -289,45 +308,6 @@ public class TimeZoneLookupHelper {
        return false;
    }

    /**
     * Returns a time zone ID for the country if possible. For counties that use a single time zone
     * this will provide a good choice. For countries with multiple time zones, a time zone is
     * returned but it may be appropriate for only part of the country. {@code null} can be returned
     * if a problem occurs during lookup, e.g. if the country code is unrecognized, if the country
     * is uninhabited, or if there is a problem with the data.
     */
    @Nullable
    public String lookupDefaultTimeZoneIdByCountry(@NonNull String isoCountryCode) {
        Objects.requireNonNull(isoCountryCode);
        CountryTimeZones countryTimeZones =
                TimeZoneFinder.getInstance().lookupCountryTimeZones(isoCountryCode);
        return countryTimeZones == null ? null : countryTimeZones.getDefaultTimeZoneId();
    }

    @Nullable
    private static OffsetResult lookupByNitzStatic(@NonNull NitzData nitzData) {
        int utcOffsetMillis = nitzData.getLocalOffsetMillis();
        long timeMillis = nitzData.getCurrentTimeInMillis();

        // Android NITZ time zone matching doesn't try to do a precise match using the DST offset
        // supplied by the carrier. It only considers whether or not the carrier suggests local time
        // is DST (if known). NITZ is limited in only being able to express DST offsets in whole
        // hours and the DST info is optional.
        Integer dstAdjustmentMillis = nitzData.getDstAdjustmentMillis();
        Boolean isDst = dstAdjustmentMillis == null ? null : dstAdjustmentMillis != 0;

        OffsetResult match = lookupByInstantOffsetDst(timeMillis, utcOffsetMillis, isDst);
        if (match == null && isDst != null) {
            // This branch is extremely unlikely and could probably be removed. The match above will
            // have searched the entire tzdb for a zone with the same total offset and isDst state.
            // Here we try another match but use "null" for isDst to indicate that only the total
            // offset should be considered. If, by the end of this, there isn't a match then the
            // current offset suggested by the carrier must be highly unusual.
            match = lookupByInstantOffsetDst(timeMillis, utcOffsetMillis, null /* isDst */);
        }
        return match;
    }

    private static OffsetResult lookupByInstantOffsetDst(long timeMillis, int utcOffsetMillis,
            @Nullable Boolean isDst) {

+0 −17
Original line number Diff line number Diff line
@@ -28,23 +28,6 @@ import java.util.Locale;
public class MccTableTest extends AndroidTestCase {
    private final static String LOG_TAG = "GSM";

    @SmallTest
    @Ignore
    public void testTimeZone() throws Exception {
        assertEquals("Europe/Paris", MccTable.defaultTimeZoneForMcc(208));
        assertEquals("Europe/Vienna", MccTable.defaultTimeZoneForMcc(232));
        assertEquals("Africa/Johannesburg", MccTable.defaultTimeZoneForMcc(655));
        assertEquals("Asia/Tokyo", MccTable.defaultTimeZoneForMcc(440));
        assertEquals("Asia/Tokyo", MccTable.defaultTimeZoneForMcc(441));
        assertEquals("Asia/Singapore", MccTable.defaultTimeZoneForMcc(525));
        assertEquals("Europe/Stockholm", MccTable.defaultTimeZoneForMcc(240));

        /* A test for the special handling for MCC 505. http://b/33228250. */
        assertEquals("Australia/Sydney", MccTable.defaultTimeZoneForMcc(505));
        assertEquals(null, MccTable.defaultTimeZoneForMcc(0));    // mcc not defined, hence default
        assertEquals(null, MccTable.defaultTimeZoneForMcc(2000)); // mcc not defined, hence default
    }

    @SmallTest
    @Ignore
    public void testCountryCode() throws Exception {
+0 −8
Original line number Diff line number Diff line
@@ -438,14 +438,6 @@ public class TimeZoneLookupHelperTest {
                mTimeZoneLookupHelper.lookupByCountry("us", NH_WINTER_TIME_MILLIS));
    }

    @Test
    public void testLookupDefaultTimeZoneIdByCountry() {
        assertEquals("Europe/London", mTimeZoneLookupHelper.lookupDefaultTimeZoneIdByCountry("gb"));
        assertEquals("Europe/London", mTimeZoneLookupHelper.lookupDefaultTimeZoneIdByCountry("Gb"));
        assertEquals("Europe/London", mTimeZoneLookupHelper.lookupDefaultTimeZoneIdByCountry("GB"));
        assertEquals("Europe/Berlin", mTimeZoneLookupHelper.lookupDefaultTimeZoneIdByCountry("DE"));
    }

    @Test
    public void testCountryUsesUtc() {
        assertFalse(mTimeZoneLookupHelper.countryUsesUtc("us", NH_SUMMER_TIME_MILLIS));