@@ -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