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

Commit 78b90b3a authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Remove broadcast of NETWORK_SET_TIMEZONE intent"

parents ea4916da 9a812912
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -633,10 +633,9 @@

    <protected-broadcast android:name="android.intent.action.DEVICE_CUSTOMIZATION_READY" />

    <!-- NETWORK_SET_TIME / NETWORK_SET_TIMEZONE moved from com.android.phone to system server.
         They should ultimately be removed. -->
    <!-- NETWORK_SET_TIME moved from com.android.phone to system server. It should ultimately be
         removed. -->
    <protected-broadcast android:name="android.intent.action.NETWORK_SET_TIME" />
    <protected-broadcast android:name="android.intent.action.NETWORK_SET_TIMEZONE" />

    <!-- For tether entitlement recheck-->
    <protected-broadcast
+1 −13
Original line number Diff line number Diff line
@@ -20,13 +20,9 @@ import android.annotation.Nullable;
import android.app.AlarmManager;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.provider.Settings;

import com.android.internal.telephony.TelephonyIntents;

/**
 * The real implementation of {@link TimeZoneDetectorStrategy.Callback}.
 */
@@ -66,16 +62,8 @@ public final class TimeZoneDetectorCallbackImpl implements TimeZoneDetectorStrat
    }

    @Override
    public void setDeviceTimeZone(String zoneId, boolean sendNetworkBroadcast) {
    public void setDeviceTimeZone(String zoneId) {
        AlarmManager alarmManager = mContext.getSystemService(AlarmManager.class);
        alarmManager.setTimeZone(zoneId);

        if (sendNetworkBroadcast) {
            // TODO Nothing in the platform appears to listen for this. Remove it.
            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);
        }
    }
}
+2 −4
Original line number Diff line number Diff line
@@ -86,7 +86,7 @@ public class TimeZoneDetectorStrategy {
        /**
         * Sets the device's time zone.
         */
        void setDeviceTimeZone(@NonNull String zoneId, boolean sendNetworkBroadcast);
        void setDeviceTimeZone(@NonNull String zoneId);
    }

    private static final String LOG_TAG = "TimeZoneDetectorStrategy";
@@ -333,7 +333,6 @@ public class TimeZoneDetectorStrategy {
        Objects.requireNonNull(newZoneId);
        Objects.requireNonNull(cause);

        boolean sendNetworkBroadcast = (origin == ORIGIN_PHONE);
        boolean isOriginAutomatic = isOriginAutomatic(origin);
        if (isOriginAutomatic) {
            if (!mCallback.isAutoTimeZoneDetectionEnabled()) {
@@ -373,12 +372,11 @@ public class TimeZoneDetectorStrategy {
            return;
        }

        mCallback.setDeviceTimeZone(newZoneId, sendNetworkBroadcast);
        mCallback.setDeviceTimeZone(newZoneId);
        String msg = "Set device time zone."
                + " origin=" + origin
                + ", currentZoneId=" + currentZoneId
                + ", newZoneId=" + newZoneId
                + ", sendNetworkBroadcast" + sendNetworkBroadcast
                + ", cause=" + cause;
        if (DBG) {
            Slog.d(LOG_TAG, msg);
+13 −53
Original line number Diff line number Diff line
@@ -50,7 +50,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Objects;

/**
 * White-box unit tests for {@link TimeZoneDetectorStrategy}.
@@ -445,8 +444,7 @@ public class TimeZoneDetectorStrategyTest {
    static class FakeTimeZoneDetectorStrategyCallback implements TimeZoneDetectorStrategy.Callback {

        private boolean mAutoTimeZoneDetectionEnabled;
        private TestState<TimeZoneChange> mTimeZoneChanges = new TestState<>();
        private String mTimeZoneId;
        private TestState<String> mTimeZoneId = new TestState<>();

        @Override
        public boolean isAutoTimeZoneDetectionEnabled() {
@@ -460,13 +458,12 @@ public class TimeZoneDetectorStrategyTest {

        @Override
        public String getDeviceTimeZone() {
            return mTimeZoneId;
            return mTimeZoneId.getLatest();
        }

        @Override
        public void setDeviceTimeZone(String zoneId, boolean withNetworkBroadcast) {
            mTimeZoneId = zoneId;
            mTimeZoneChanges.set(new TimeZoneChange(zoneId, withNetworkBroadcast));
        public void setDeviceTimeZone(String zoneId) {
            mTimeZoneId.set(zoneId);
        }

        void initializeAutoTimeZoneDetection(boolean enabled) {
@@ -474,7 +471,7 @@ public class TimeZoneDetectorStrategyTest {
        }

        void initializeTimeZone(String zoneId) {
            mTimeZoneId = zoneId;
            mTimeZoneId.init(zoneId);
        }

        void setAutoTimeZoneDetectionEnabled(boolean enabled) {
@@ -482,46 +479,17 @@ public class TimeZoneDetectorStrategyTest {
        }

        void assertTimeZoneNotSet() {
            mTimeZoneChanges.assertHasNotBeenSet();
            mTimeZoneId.assertHasNotBeenSet();
        }

        void assertTimeZoneSet(String timeZoneId, boolean withNetworkBroadcast) {
            mTimeZoneChanges.assertHasBeenSet();
            mTimeZoneChanges.assertChangeCount(1);
            TimeZoneChange expectedChange = new TimeZoneChange(timeZoneId, withNetworkBroadcast);
            mTimeZoneChanges.assertLatestEquals(expectedChange);
        void assertTimeZoneSet(String timeZoneId) {
            mTimeZoneId.assertHasBeenSet();
            mTimeZoneId.assertChangeCount(1);
            mTimeZoneId.assertLatestEquals(timeZoneId);
        }

        void commitAllChanges() {
            mTimeZoneChanges.commitLatest();
        }
    }

    private static class TimeZoneChange {
        private final String mTimeZoneId;
        private final boolean mWithNetworkBroadcast;

        private TimeZoneChange(String timeZoneId, boolean withNetworkBroadcast) {
            mTimeZoneId = timeZoneId;
            mWithNetworkBroadcast = withNetworkBroadcast;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) {
                return true;
            }
            if (o == null || getClass() != o.getClass()) {
                return false;
            }
            TimeZoneChange that = (TimeZoneChange) o;
            return mWithNetworkBroadcast == that.mWithNetworkBroadcast
                    && mTimeZoneId.equals(that.mTimeZoneId);
        }

        @Override
        public int hashCode() {
            return Objects.hash(mTimeZoneId, mWithNetworkBroadcast);
            mTimeZoneId.commitLatest();
        }
    }

@@ -614,21 +582,13 @@ public class TimeZoneDetectorStrategyTest {
        }

        Script verifyTimeZoneSetAndReset(PhoneTimeZoneSuggestion suggestion) {
            // Phone suggestions should cause a TelephonyIntents.ACTION_NETWORK_SET_TIMEZONE
            // broadcast.
            boolean withNetworkBroadcast = true;
            mFakeTimeZoneDetectorStrategyCallback.assertTimeZoneSet(
                    suggestion.getZoneId(), withNetworkBroadcast);
            mFakeTimeZoneDetectorStrategyCallback.assertTimeZoneSet(suggestion.getZoneId());
            mFakeTimeZoneDetectorStrategyCallback.commitAllChanges();
            return this;
        }

        Script verifyTimeZoneSetAndReset(ManualTimeZoneSuggestion suggestion) {
            // Manual suggestions should not cause a TelephonyIntents.ACTION_NETWORK_SET_TIMEZONE
            // broadcast.
            boolean withNetworkBroadcast = false;
            mFakeTimeZoneDetectorStrategyCallback.assertTimeZoneSet(
                    suggestion.getZoneId(), withNetworkBroadcast);
            mFakeTimeZoneDetectorStrategyCallback.assertTimeZoneSet(suggestion.getZoneId());
            mFakeTimeZoneDetectorStrategyCallback.commitAllChanges();
            return this;
        }
+0 −19
Original line number Diff line number Diff line
@@ -240,25 +240,6 @@ public class TelephonyIntents {
     */
    public static final String ACTION_NETWORK_SET_TIME = "android.intent.action.NETWORK_SET_TIME";


    /**
     * Broadcast Action: The timezone was set by the carrier (typically by the NITZ string).
     * This is a sticky broadcast.
     * The intent will have the following extra values:</p>
     * <ul>
     *   <li><em>time-zone</em> - The java.util.TimeZone.getID() value identifying the new time
     *          zone.</li>
     * </ul>
     *
     * <p class="note">
     * Requires the READ_PHONE_STATE permission.
     *
     * <p class="note">This is a protected intent that can only be sent
     * by the system.
     */
    public static final String ACTION_NETWORK_SET_TIMEZONE
            = "android.intent.action.NETWORK_SET_TIMEZONE";

    /**
     * <p>Broadcast Action: It indicates the Emergency callback mode blocks datacall/sms
     * <p class="note">.