Merge "Remove broadcast of NETWORK_SET_TIMEZONE intent" am: 78b90b3a76

am: 1f641b3630

Change-Id: I4d0c201fc6af3826a4427da5bc162c10bef50641
This commit is contained in:
Neil Fuller
2019-12-10 09:07:13 -08:00
committed by android-build-merger
5 changed files with 18 additions and 92 deletions

View File

@@ -633,10 +633,9 @@
<protected-broadcast android:name="android.intent.action.DEVICE_CUSTOMIZATION_READY" /> <protected-broadcast android:name="android.intent.action.DEVICE_CUSTOMIZATION_READY" />
<!-- NETWORK_SET_TIME / NETWORK_SET_TIMEZONE moved from com.android.phone to system server. <!-- NETWORK_SET_TIME moved from com.android.phone to system server. It should ultimately be
They should ultimately be removed. --> removed. -->
<protected-broadcast android:name="android.intent.action.NETWORK_SET_TIME" /> <protected-broadcast android:name="android.intent.action.NETWORK_SET_TIME" />
<protected-broadcast android:name="android.intent.action.NETWORK_SET_TIMEZONE" />
<!-- For tether entitlement recheck--> <!-- For tether entitlement recheck-->
<protected-broadcast <protected-broadcast

View File

@@ -20,13 +20,9 @@ import android.annotation.Nullable;
import android.app.AlarmManager; import android.app.AlarmManager;
import android.content.ContentResolver; import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.os.SystemProperties; import android.os.SystemProperties;
import android.os.UserHandle;
import android.provider.Settings; import android.provider.Settings;
import com.android.internal.telephony.TelephonyIntents;
/** /**
* The real implementation of {@link TimeZoneDetectorStrategy.Callback}. * The real implementation of {@link TimeZoneDetectorStrategy.Callback}.
*/ */
@@ -66,16 +62,8 @@ public final class TimeZoneDetectorCallbackImpl implements TimeZoneDetectorStrat
} }
@Override @Override
public void setDeviceTimeZone(String zoneId, boolean sendNetworkBroadcast) { public void setDeviceTimeZone(String zoneId) {
AlarmManager alarmManager = mContext.getSystemService(AlarmManager.class); AlarmManager alarmManager = mContext.getSystemService(AlarmManager.class);
alarmManager.setTimeZone(zoneId); 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);
}
} }
} }

View File

@@ -86,7 +86,7 @@ public class TimeZoneDetectorStrategy {
/** /**
* Sets the device's time zone. * 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"; private static final String LOG_TAG = "TimeZoneDetectorStrategy";
@@ -333,7 +333,6 @@ public class TimeZoneDetectorStrategy {
Objects.requireNonNull(newZoneId); Objects.requireNonNull(newZoneId);
Objects.requireNonNull(cause); Objects.requireNonNull(cause);
boolean sendNetworkBroadcast = (origin == ORIGIN_PHONE);
boolean isOriginAutomatic = isOriginAutomatic(origin); boolean isOriginAutomatic = isOriginAutomatic(origin);
if (isOriginAutomatic) { if (isOriginAutomatic) {
if (!mCallback.isAutoTimeZoneDetectionEnabled()) { if (!mCallback.isAutoTimeZoneDetectionEnabled()) {
@@ -373,12 +372,11 @@ public class TimeZoneDetectorStrategy {
return; return;
} }
mCallback.setDeviceTimeZone(newZoneId, sendNetworkBroadcast); mCallback.setDeviceTimeZone(newZoneId);
String msg = "Set device time zone." String msg = "Set device time zone."
+ " origin=" + origin + " origin=" + origin
+ ", currentZoneId=" + currentZoneId + ", currentZoneId=" + currentZoneId
+ ", newZoneId=" + newZoneId + ", newZoneId=" + newZoneId
+ ", sendNetworkBroadcast" + sendNetworkBroadcast
+ ", cause=" + cause; + ", cause=" + cause;
if (DBG) { if (DBG) {
Slog.d(LOG_TAG, msg); Slog.d(LOG_TAG, msg);

View File

@@ -50,7 +50,6 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Objects;
/** /**
* White-box unit tests for {@link TimeZoneDetectorStrategy}. * White-box unit tests for {@link TimeZoneDetectorStrategy}.
@@ -445,8 +444,7 @@ public class TimeZoneDetectorStrategyTest {
static class FakeTimeZoneDetectorStrategyCallback implements TimeZoneDetectorStrategy.Callback { static class FakeTimeZoneDetectorStrategyCallback implements TimeZoneDetectorStrategy.Callback {
private boolean mAutoTimeZoneDetectionEnabled; private boolean mAutoTimeZoneDetectionEnabled;
private TestState<TimeZoneChange> mTimeZoneChanges = new TestState<>(); private TestState<String> mTimeZoneId = new TestState<>();
private String mTimeZoneId;
@Override @Override
public boolean isAutoTimeZoneDetectionEnabled() { public boolean isAutoTimeZoneDetectionEnabled() {
@@ -460,13 +458,12 @@ public class TimeZoneDetectorStrategyTest {
@Override @Override
public String getDeviceTimeZone() { public String getDeviceTimeZone() {
return mTimeZoneId; return mTimeZoneId.getLatest();
} }
@Override @Override
public void setDeviceTimeZone(String zoneId, boolean withNetworkBroadcast) { public void setDeviceTimeZone(String zoneId) {
mTimeZoneId = zoneId; mTimeZoneId.set(zoneId);
mTimeZoneChanges.set(new TimeZoneChange(zoneId, withNetworkBroadcast));
} }
void initializeAutoTimeZoneDetection(boolean enabled) { void initializeAutoTimeZoneDetection(boolean enabled) {
@@ -474,7 +471,7 @@ public class TimeZoneDetectorStrategyTest {
} }
void initializeTimeZone(String zoneId) { void initializeTimeZone(String zoneId) {
mTimeZoneId = zoneId; mTimeZoneId.init(zoneId);
} }
void setAutoTimeZoneDetectionEnabled(boolean enabled) { void setAutoTimeZoneDetectionEnabled(boolean enabled) {
@@ -482,46 +479,17 @@ public class TimeZoneDetectorStrategyTest {
} }
void assertTimeZoneNotSet() { void assertTimeZoneNotSet() {
mTimeZoneChanges.assertHasNotBeenSet(); mTimeZoneId.assertHasNotBeenSet();
} }
void assertTimeZoneSet(String timeZoneId, boolean withNetworkBroadcast) { void assertTimeZoneSet(String timeZoneId) {
mTimeZoneChanges.assertHasBeenSet(); mTimeZoneId.assertHasBeenSet();
mTimeZoneChanges.assertChangeCount(1); mTimeZoneId.assertChangeCount(1);
TimeZoneChange expectedChange = new TimeZoneChange(timeZoneId, withNetworkBroadcast); mTimeZoneId.assertLatestEquals(timeZoneId);
mTimeZoneChanges.assertLatestEquals(expectedChange);
} }
void commitAllChanges() { void commitAllChanges() {
mTimeZoneChanges.commitLatest(); mTimeZoneId.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);
} }
} }
@@ -614,21 +582,13 @@ public class TimeZoneDetectorStrategyTest {
} }
Script verifyTimeZoneSetAndReset(PhoneTimeZoneSuggestion suggestion) { Script verifyTimeZoneSetAndReset(PhoneTimeZoneSuggestion suggestion) {
// Phone suggestions should cause a TelephonyIntents.ACTION_NETWORK_SET_TIMEZONE mFakeTimeZoneDetectorStrategyCallback.assertTimeZoneSet(suggestion.getZoneId());
// broadcast.
boolean withNetworkBroadcast = true;
mFakeTimeZoneDetectorStrategyCallback.assertTimeZoneSet(
suggestion.getZoneId(), withNetworkBroadcast);
mFakeTimeZoneDetectorStrategyCallback.commitAllChanges(); mFakeTimeZoneDetectorStrategyCallback.commitAllChanges();
return this; return this;
} }
Script verifyTimeZoneSetAndReset(ManualTimeZoneSuggestion suggestion) { Script verifyTimeZoneSetAndReset(ManualTimeZoneSuggestion suggestion) {
// Manual suggestions should not cause a TelephonyIntents.ACTION_NETWORK_SET_TIMEZONE mFakeTimeZoneDetectorStrategyCallback.assertTimeZoneSet(suggestion.getZoneId());
// broadcast.
boolean withNetworkBroadcast = false;
mFakeTimeZoneDetectorStrategyCallback.assertTimeZoneSet(
suggestion.getZoneId(), withNetworkBroadcast);
mFakeTimeZoneDetectorStrategyCallback.commitAllChanges(); mFakeTimeZoneDetectorStrategyCallback.commitAllChanges();
return this; return this;
} }

View File

@@ -240,25 +240,6 @@ public class TelephonyIntents {
*/ */
public static final String ACTION_NETWORK_SET_TIME = "android.intent.action.NETWORK_SET_TIME"; 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>Broadcast Action: It indicates the Emergency callback mode blocks datacall/sms
* <p class="note">. * <p class="note">.