Merge "Don't set the time zone under the caller's identity" into jb-mr1-dev

This commit is contained in:
Christopher Tate
2012-08-31 14:47:34 -07:00
committed by Android (Google) Code Review

View File

@ -243,32 +243,39 @@ class AlarmManagerService extends IAlarmManager.Stub {
"android.permission.SET_TIME_ZONE", "android.permission.SET_TIME_ZONE",
"setTimeZone"); "setTimeZone");
if (TextUtils.isEmpty(tz)) return; long oldId = Binder.clearCallingIdentity();
TimeZone zone = TimeZone.getTimeZone(tz); try {
// Prevent reentrant calls from stepping on each other when writing if (TextUtils.isEmpty(tz)) return;
// the time zone property TimeZone zone = TimeZone.getTimeZone(tz);
boolean timeZoneWasChanged = false; // Prevent reentrant calls from stepping on each other when writing
synchronized (this) { // the time zone property
String current = SystemProperties.get(TIMEZONE_PROPERTY); boolean timeZoneWasChanged = false;
if (current == null || !current.equals(zone.getID())) { synchronized (this) {
if (localLOGV) Slog.v(TAG, "timezone changed: " + current + ", new=" + zone.getID()); String current = SystemProperties.get(TIMEZONE_PROPERTY);
timeZoneWasChanged = true; if (current == null || !current.equals(zone.getID())) {
SystemProperties.set(TIMEZONE_PROPERTY, zone.getID()); if (localLOGV) {
Slog.v(TAG, "timezone changed: " + current + ", new=" + zone.getID());
}
timeZoneWasChanged = true;
SystemProperties.set(TIMEZONE_PROPERTY, zone.getID());
}
// Update the kernel timezone information
// Kernel tracks time offsets as 'minutes west of GMT'
int gmtOffset = zone.getOffset(System.currentTimeMillis());
setKernelTimezone(mDescriptor, -(gmtOffset / 60000));
} }
// Update the kernel timezone information TimeZone.setDefault(null);
// Kernel tracks time offsets as 'minutes west of GMT'
int gmtOffset = zone.getOffset(System.currentTimeMillis());
setKernelTimezone(mDescriptor, -(gmtOffset / 60000));
}
TimeZone.setDefault(null); if (timeZoneWasChanged) {
Intent intent = new Intent(Intent.ACTION_TIMEZONE_CHANGED);
if (timeZoneWasChanged) { intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
Intent intent = new Intent(Intent.ACTION_TIMEZONE_CHANGED); intent.putExtra("time-zone", zone.getID());
intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
intent.putExtra("time-zone", zone.getID()); }
mContext.sendBroadcastAsUser(intent, UserHandle.ALL); } finally {
Binder.restoreCallingIdentity(oldId);
} }
} }