Skip to content

Commit a7f3a34

Browse files
author
Jim Miller
committed
Fix 5473038: workaround for fd leak in lockscreen
This works around a file descriptor leak in Skia. It also improves view creation time by avoiding re-loading the font every time a DigitalClock is created. Change-Id: I5c46445da36b1e6ba06c8ca340e436835d281180
1 parent f129988 commit a7f3a34

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

core/java/com/android/internal/widget/DigitalClock.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
import android.content.Context;
2323
import android.content.Intent;
2424
import android.content.IntentFilter;
25-
import android.content.res.AssetManager;
26-
import android.content.res.Resources;
2725
import android.database.ContentObserver;
2826
import android.graphics.Typeface;
2927
import android.os.Handler;
@@ -61,6 +59,14 @@ public class DigitalClock extends RelativeLayout {
6159
private final Handler mHandler = new Handler();
6260
private BroadcastReceiver mIntentReceiver;
6361

62+
private static final Typeface sBackgroundFont;
63+
private static final Typeface sForegroundFont;
64+
65+
static {
66+
sBackgroundFont = Typeface.createFromFile(SYSTEM_FONT_TIME_BACKGROUND);
67+
sForegroundFont = Typeface.createFromFile(SYSTEM_FONT_TIME_FOREGROUND);
68+
}
69+
6470
private static class TimeChangedReceiver extends BroadcastReceiver {
6571
private WeakReference<DigitalClock> mClock;
6672
private Context mContext;
@@ -159,13 +165,11 @@ public DigitalClock(Context context, AttributeSet attrs) {
159165
protected void onFinishInflate() {
160166
super.onFinishInflate();
161167

162-
AssetManager assets = mContext.getAssets();
163-
164168
/* The time display consists of two tones. That's why we have two overlapping text views. */
165169
mTimeDisplayBackground = (TextView) findViewById(R.id.timeDisplayBackground);
166-
mTimeDisplayBackground.setTypeface(Typeface.createFromFile(SYSTEM_FONT_TIME_BACKGROUND));
170+
mTimeDisplayBackground.setTypeface(sBackgroundFont);
167171
mTimeDisplayForeground = (TextView) findViewById(R.id.timeDisplayForeground);
168-
mTimeDisplayForeground.setTypeface(Typeface.createFromFile(SYSTEM_FONT_TIME_FOREGROUND));
172+
mTimeDisplayForeground.setTypeface(sForegroundFont);
169173
mAmPm = new AmPm(this, null);
170174
mCalendar = Calendar.getInstance();
171175

0 commit comments

Comments
 (0)