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

Commit 42e5c2cc authored by Neil Fuller's avatar Neil Fuller
Browse files

Switch MccTable over to using TimeServiceHelper

Switch MccTable over to using TimeServiceHelper; there's
some logic that should be shared or identical for detecting
if the device automatically defaulted the time zone to GMT
on boot. This will slightly alter ServiceStateTracker
behavior (the other user of TimeServiceHelper), which
previously did not check for GMT. This new
behavior looks more correct given bug 64056758.

This commit also switches MccTable over to using
TimeServiceHelper to set the device time zone.

This alters behavior of MccTable and means there will be
an extra broadcast of ACTION_NETWORK_SET_TIMEZONE if MccTable
sets the time zone (which only happens if the device has
no time zone set). Although this MccTable path is not strictly
an NITZ update it's still a "telephony" update so broadly
qualifies as a "network time zone update".

MccTable should probably also call
TimeServiceHelper.isTimeZoneDetectionEnabled() before setting
the device time zone but that change is not being made as
part of this commit.

Test: atest FrameworksTelephonyTests
Bug: 64056758
Bug: 63743683
(cherry picked from commit 92a32ccf)
Merged-In: I1c17dab0c93b5827f33eb34d472453d048880bb7
Change-Id: I1c17dab0c93b5827f33eb34d472453d048880bb7
parent 6f0f602b
Loading
Loading
Loading
Loading
+4 −13
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package com.android.internal.telephony;

import android.app.ActivityManager;
import android.app.AlarmManager;
import android.content.Context;
import android.content.res.Configuration;
import android.net.wifi.WifiManager;
@@ -359,21 +358,13 @@ public final class MccTable {
     * @param mcc Mobile Country Code of the SIM or SIM-like entity (build prop on CDMA)
     */
    private static void setTimezoneFromMccIfNeeded(Context context, int mcc) {
        String timezone = SystemProperties.get(TimeServiceHelper.TIMEZONE_PROPERTY);
        // 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.
        if (timezone == null || timezone.length() == 0 || timezone.equals("GMT")) {
        TimeServiceHelper timeServiceHelper =
                TelephonyComponentFactory.getInstance().makeTimeServiceHelper(context);
        if (!timeServiceHelper.isTimeZoneSettingInitialized()) {
            String zoneId = defaultTimeZoneForMcc(mcc);
            if (zoneId != null && zoneId.length() > 0) {
                // Set time zone based on MCC
                AlarmManager alarm =
                        (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
                alarm.setTimeZone(zoneId);
                timeServiceHelper.setDeviceTimeZone(zoneId);
                Slog.d(LOG_TAG, "timezone set to " + zoneId);
            }
        }
+10 −2
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ public class TimeServiceHelper {
        void onTimeZoneDetectionChange(boolean enabled);
    }

    public static final String TIMEZONE_PROPERTY = "persist.sys.timezone";
    private static final String TIMEZONE_PROPERTY = "persist.sys.timezone";

    private final Context mContext;
    private final ContentResolver mCr;
@@ -94,8 +94,16 @@ public class TimeServiceHelper {
     * Returns true if the device has an explicit time zone set.
     */
    public boolean isTimeZoneSettingInitialized() {
        // 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;
        return timeZoneId != null && timeZoneId.length() > 0 && !timeZoneId.equals("GMT");
    }

    /**