Skip to content

Commit 176d105

Browse files
Christopher TateAndroid (Google) Code Review
authored andcommitted
Merge "Don't set the time zone under the caller's identity" into jb-mr1-dev
2 parents 58a2950 + 8977982 commit 176d105

File tree

1 file changed

+31
-24
lines changed

1 file changed

+31
-24
lines changed

services/java/com/android/server/AlarmManagerService.java

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -243,32 +243,39 @@ public void setTimeZone(String tz) {
243243
"android.permission.SET_TIME_ZONE",
244244
"setTimeZone");
245245

246-
if (TextUtils.isEmpty(tz)) return;
247-
TimeZone zone = TimeZone.getTimeZone(tz);
248-
// Prevent reentrant calls from stepping on each other when writing
249-
// the time zone property
250-
boolean timeZoneWasChanged = false;
251-
synchronized (this) {
252-
String current = SystemProperties.get(TIMEZONE_PROPERTY);
253-
if (current == null || !current.equals(zone.getID())) {
254-
if (localLOGV) Slog.v(TAG, "timezone changed: " + current + ", new=" + zone.getID());
255-
timeZoneWasChanged = true;
256-
SystemProperties.set(TIMEZONE_PROPERTY, zone.getID());
246+
long oldId = Binder.clearCallingIdentity();
247+
try {
248+
if (TextUtils.isEmpty(tz)) return;
249+
TimeZone zone = TimeZone.getTimeZone(tz);
250+
// Prevent reentrant calls from stepping on each other when writing
251+
// the time zone property
252+
boolean timeZoneWasChanged = false;
253+
synchronized (this) {
254+
String current = SystemProperties.get(TIMEZONE_PROPERTY);
255+
if (current == null || !current.equals(zone.getID())) {
256+
if (localLOGV) {
257+
Slog.v(TAG, "timezone changed: " + current + ", new=" + zone.getID());
258+
}
259+
timeZoneWasChanged = true;
260+
SystemProperties.set(TIMEZONE_PROPERTY, zone.getID());
261+
}
262+
263+
// Update the kernel timezone information
264+
// Kernel tracks time offsets as 'minutes west of GMT'
265+
int gmtOffset = zone.getOffset(System.currentTimeMillis());
266+
setKernelTimezone(mDescriptor, -(gmtOffset / 60000));
257267
}
258-
259-
// Update the kernel timezone information
260-
// Kernel tracks time offsets as 'minutes west of GMT'
261-
int gmtOffset = zone.getOffset(System.currentTimeMillis());
262-
setKernelTimezone(mDescriptor, -(gmtOffset / 60000));
263-
}
264268

265-
TimeZone.setDefault(null);
266-
267-
if (timeZoneWasChanged) {
268-
Intent intent = new Intent(Intent.ACTION_TIMEZONE_CHANGED);
269-
intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
270-
intent.putExtra("time-zone", zone.getID());
271-
mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
269+
TimeZone.setDefault(null);
270+
271+
if (timeZoneWasChanged) {
272+
Intent intent = new Intent(Intent.ACTION_TIMEZONE_CHANGED);
273+
intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
274+
intent.putExtra("time-zone", zone.getID());
275+
mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
276+
}
277+
} finally {
278+
Binder.restoreCallingIdentity(oldId);
272279
}
273280
}
274281

0 commit comments

Comments
 (0)