Merge "Be more defensive around invalid tzids" am: f60c302dad am: 96c57398b4 am: 29867f046d

Change-Id: I2680523523490f8674c1bd426bd865cb293a087b
This commit is contained in:
Neil Fuller
2020-05-26 11:06:11 +00:00
committed by Automerger Merge Worker
3 changed files with 19 additions and 22 deletions

View File

@@ -36,7 +36,6 @@ import android.util.proto.ProtoOutputStream;
import libcore.timezone.ZoneInfoDb; import libcore.timezone.ZoneInfoDb;
import java.io.IOException;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
@@ -996,12 +995,7 @@ public class AlarmManager {
// Reject this timezone if it isn't an Olson zone we recognize. // Reject this timezone if it isn't an Olson zone we recognize.
if (mTargetSdkVersion >= Build.VERSION_CODES.M) { if (mTargetSdkVersion >= Build.VERSION_CODES.M) {
boolean hasTimeZone = false; boolean hasTimeZone = ZoneInfoDb.getInstance().hasTimeZone(timeZone);
try {
hasTimeZone = ZoneInfoDb.getInstance().hasTimeZone(timeZone);
} catch (IOException ignored) {
}
if (!hasTimeZone) { if (!hasTimeZone) {
throw new IllegalArgumentException("Timezone: " + timeZone + " is not an Olson ID"); throw new IllegalArgumentException("Timezone: " + timeZone + " is not an Olson ID");
} }

View File

@@ -21,7 +21,6 @@ import android.util.TimeFormatException;
import libcore.timezone.ZoneInfoDb; import libcore.timezone.ZoneInfoDb;
import libcore.util.ZoneInfo; import libcore.util.ZoneInfo;
import java.io.IOException;
import java.util.Locale; import java.util.Locale;
import java.util.TimeZone; import java.util.TimeZone;
@@ -1117,7 +1116,6 @@ public class Time {
} }
private static ZoneInfo lookupZoneInfo(String timezoneId) { private static ZoneInfo lookupZoneInfo(String timezoneId) {
try {
ZoneInfo zoneInfo = ZoneInfoDb.getInstance().makeTimeZone(timezoneId); ZoneInfo zoneInfo = ZoneInfoDb.getInstance().makeTimeZone(timezoneId);
if (zoneInfo == null) { if (zoneInfo == null) {
zoneInfo = ZoneInfoDb.getInstance().makeTimeZone("GMT"); zoneInfo = ZoneInfoDb.getInstance().makeTimeZone("GMT");
@@ -1126,10 +1124,6 @@ public class Time {
throw new AssertionError("GMT not found: \"" + timezoneId + "\""); throw new AssertionError("GMT not found: \"" + timezoneId + "\"");
} }
return zoneInfo; return zoneInfo;
} catch (IOException e) {
// This should not ever be thrown.
throw new AssertionError("Error loading timezone: \"" + timezoneId + "\"", e);
}
} }
public void switchTimeZone(String timezone) { public void switchTimeZone(String timezone) {

View File

@@ -180,6 +180,8 @@ import com.android.server.wm.ActivityTaskManagerService;
import com.android.server.wm.WindowManagerGlobalLock; import com.android.server.wm.WindowManagerGlobalLock;
import com.android.server.wm.WindowManagerService; import com.android.server.wm.WindowManagerService;
import libcore.timezone.ZoneInfoDb;
import dalvik.system.VMRuntime; import dalvik.system.VMRuntime;
import com.google.android.startop.iorap.IorapForwardingService; import com.google.android.startop.iorap.IorapForwardingService;
@@ -438,8 +440,9 @@ public final class SystemServer {
// Default the timezone property to GMT if not set. // Default the timezone property to GMT if not set.
// //
String timezoneProperty = SystemProperties.get("persist.sys.timezone"); String timezoneProperty = SystemProperties.get("persist.sys.timezone");
if (timezoneProperty == null || timezoneProperty.isEmpty()) { if (!isValidTimeZoneId(timezoneProperty)) {
Slog.w(TAG, "Timezone not set; setting to GMT."); Slog.w(TAG, "persist.sys.timezone is not valid (" + timezoneProperty
+ "); setting to GMT.");
SystemProperties.set("persist.sys.timezone", "GMT"); SystemProperties.set("persist.sys.timezone", "GMT");
} }
@@ -617,6 +620,12 @@ public final class SystemServer {
throw new RuntimeException("Main thread loop unexpectedly exited"); throw new RuntimeException("Main thread loop unexpectedly exited");
} }
private static boolean isValidTimeZoneId(String timezoneProperty) {
return timezoneProperty != null
&& !timezoneProperty.isEmpty()
&& ZoneInfoDb.getInstance().hasTimeZone(timezoneProperty);
}
private boolean isFirstBootOrUpgrade() { private boolean isFirstBootOrUpgrade() {
return mPackageManagerService.isFirstBoot() || mPackageManagerService.isDeviceUpgrading(); return mPackageManagerService.isFirstBoot() || mPackageManagerService.isDeviceUpgrading();
} }