Loading core/java/android/app/ActivityThread.java +2 −0 Original line number Original line Diff line number Diff line Loading @@ -50,6 +50,7 @@ import android.database.sqlite.SQLiteDebug; import android.database.sqlite.SQLiteDebug.DbStats; import android.database.sqlite.SQLiteDebug.DbStats; import android.graphics.Bitmap; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Canvas; import android.graphics.Typeface; import android.hardware.display.DisplayManagerGlobal; import android.hardware.display.DisplayManagerGlobal; import android.net.ConnectivityManager; import android.net.ConnectivityManager; import android.net.IConnectivityManager; import android.net.IConnectivityManager; Loading Loading @@ -5665,6 +5666,7 @@ public final class ActivityThread { } } // Preload fonts resources // Preload fonts resources Typeface.setApplicationContext(appContext); try { try { final ApplicationInfo info = final ApplicationInfo info = getPackageManager().getApplicationInfo( getPackageManager().getApplicationInfo( Loading core/java/android/provider/FontsContract.java +2 −6 Original line number Original line Diff line number Diff line Loading @@ -138,12 +138,8 @@ public class FontsContract { private HandlerThread mThread; private HandlerThread mThread; /** @hide */ /** @hide */ public FontsContract() { public FontsContract(Context context) { // TODO: investigate if the system context is the best option here. ApplicationContext or mContext = context.getApplicationContext(); // the one passed by developer? // TODO: Looks like ActivityThread.currentActivityThread() can return null. Check when it // returns null and check if we need to handle null case. mContext = ActivityThread.currentActivityThread().getSystemContext(); mPackageManager = mContext.getPackageManager(); mPackageManager = mContext.getPackageManager(); } } Loading graphics/java/android/graphics/Typeface.java +19 −5 Original line number Original line Diff line number Diff line Loading @@ -24,6 +24,7 @@ import static android.content.res.FontResourcesParser.FamilyResourceEntry; import android.annotation.IntDef; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.Nullable; import android.content.Context; import android.content.res.AssetManager; import android.content.res.AssetManager; import android.graphics.fonts.FontRequest; import android.graphics.fonts.FontRequest; import android.graphics.fonts.FontResult; import android.graphics.fonts.FontResult; Loading Loading @@ -88,7 +89,7 @@ public class Typeface { @GuardedBy("sLock") @GuardedBy("sLock") private static FontsContract sFontsContract; private static FontsContract sFontsContract; @GuardedBy("sLock") @GuardedBy("sLock") private static Handler mHandler; private static Handler sHandler; /** /** * Cache for Typeface objects dynamically loaded from assets. Currently max size is 16. * Cache for Typeface objects dynamically loaded from assets. Currently max size is 16. Loading Loading @@ -225,6 +226,20 @@ public class Typeface { return null; return null; } } /** * Set the application context so we can generate font requests from the provider. This should * be called from ActivityThread when the application binds, as we preload fonts. * @hide */ public static void setApplicationContext(Context context) { synchronized (sLock) { if (sFontsContract == null) { sFontsContract = new FontsContract(context); sHandler = new Handler(); } } } /** /** * Create a typeface object given a font request. The font will be asynchronously fetched, * Create a typeface object given a font request. The font will be asynchronously fetched, * therefore the result is delivered to the given callback. See {@link FontRequest}. * therefore the result is delivered to the given callback. See {@link FontRequest}. Loading @@ -241,18 +256,17 @@ public class Typeface { Typeface cachedTypeface = findFromCache( Typeface cachedTypeface = findFromCache( request.getProviderAuthority(), request.getQuery()); request.getProviderAuthority(), request.getQuery()); if (cachedTypeface != null) { if (cachedTypeface != null) { mHandler.post(() -> callback.onTypefaceRetrieved(cachedTypeface)); sHandler.post(() -> callback.onTypefaceRetrieved(cachedTypeface)); return; return; } } synchronized (sLock) { synchronized (sLock) { if (sFontsContract == null) { if (sFontsContract == null) { sFontsContract = new FontsContract(); throw new RuntimeException("Context not initialized, can't query provider"); mHandler = new Handler(); } } final ResultReceiver receiver = new ResultReceiver(null) { final ResultReceiver receiver = new ResultReceiver(null) { @Override @Override public void onReceiveResult(int resultCode, Bundle resultData) { public void onReceiveResult(int resultCode, Bundle resultData) { mHandler.post(() -> receiveResult(request, callback, resultCode, resultData)); sHandler.post(() -> receiveResult(request, callback, resultCode, resultData)); } } }; }; sFontsContract.getFont(request, receiver); sFontsContract.getFont(request, receiver); Loading Loading
core/java/android/app/ActivityThread.java +2 −0 Original line number Original line Diff line number Diff line Loading @@ -50,6 +50,7 @@ import android.database.sqlite.SQLiteDebug; import android.database.sqlite.SQLiteDebug.DbStats; import android.database.sqlite.SQLiteDebug.DbStats; import android.graphics.Bitmap; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Canvas; import android.graphics.Typeface; import android.hardware.display.DisplayManagerGlobal; import android.hardware.display.DisplayManagerGlobal; import android.net.ConnectivityManager; import android.net.ConnectivityManager; import android.net.IConnectivityManager; import android.net.IConnectivityManager; Loading Loading @@ -5665,6 +5666,7 @@ public final class ActivityThread { } } // Preload fonts resources // Preload fonts resources Typeface.setApplicationContext(appContext); try { try { final ApplicationInfo info = final ApplicationInfo info = getPackageManager().getApplicationInfo( getPackageManager().getApplicationInfo( Loading
core/java/android/provider/FontsContract.java +2 −6 Original line number Original line Diff line number Diff line Loading @@ -138,12 +138,8 @@ public class FontsContract { private HandlerThread mThread; private HandlerThread mThread; /** @hide */ /** @hide */ public FontsContract() { public FontsContract(Context context) { // TODO: investigate if the system context is the best option here. ApplicationContext or mContext = context.getApplicationContext(); // the one passed by developer? // TODO: Looks like ActivityThread.currentActivityThread() can return null. Check when it // returns null and check if we need to handle null case. mContext = ActivityThread.currentActivityThread().getSystemContext(); mPackageManager = mContext.getPackageManager(); mPackageManager = mContext.getPackageManager(); } } Loading
graphics/java/android/graphics/Typeface.java +19 −5 Original line number Original line Diff line number Diff line Loading @@ -24,6 +24,7 @@ import static android.content.res.FontResourcesParser.FamilyResourceEntry; import android.annotation.IntDef; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.Nullable; import android.content.Context; import android.content.res.AssetManager; import android.content.res.AssetManager; import android.graphics.fonts.FontRequest; import android.graphics.fonts.FontRequest; import android.graphics.fonts.FontResult; import android.graphics.fonts.FontResult; Loading Loading @@ -88,7 +89,7 @@ public class Typeface { @GuardedBy("sLock") @GuardedBy("sLock") private static FontsContract sFontsContract; private static FontsContract sFontsContract; @GuardedBy("sLock") @GuardedBy("sLock") private static Handler mHandler; private static Handler sHandler; /** /** * Cache for Typeface objects dynamically loaded from assets. Currently max size is 16. * Cache for Typeface objects dynamically loaded from assets. Currently max size is 16. Loading Loading @@ -225,6 +226,20 @@ public class Typeface { return null; return null; } } /** * Set the application context so we can generate font requests from the provider. This should * be called from ActivityThread when the application binds, as we preload fonts. * @hide */ public static void setApplicationContext(Context context) { synchronized (sLock) { if (sFontsContract == null) { sFontsContract = new FontsContract(context); sHandler = new Handler(); } } } /** /** * Create a typeface object given a font request. The font will be asynchronously fetched, * Create a typeface object given a font request. The font will be asynchronously fetched, * therefore the result is delivered to the given callback. See {@link FontRequest}. * therefore the result is delivered to the given callback. See {@link FontRequest}. Loading @@ -241,18 +256,17 @@ public class Typeface { Typeface cachedTypeface = findFromCache( Typeface cachedTypeface = findFromCache( request.getProviderAuthority(), request.getQuery()); request.getProviderAuthority(), request.getQuery()); if (cachedTypeface != null) { if (cachedTypeface != null) { mHandler.post(() -> callback.onTypefaceRetrieved(cachedTypeface)); sHandler.post(() -> callback.onTypefaceRetrieved(cachedTypeface)); return; return; } } synchronized (sLock) { synchronized (sLock) { if (sFontsContract == null) { if (sFontsContract == null) { sFontsContract = new FontsContract(); throw new RuntimeException("Context not initialized, can't query provider"); mHandler = new Handler(); } } final ResultReceiver receiver = new ResultReceiver(null) { final ResultReceiver receiver = new ResultReceiver(null) { @Override @Override public void onReceiveResult(int resultCode, Bundle resultData) { public void onReceiveResult(int resultCode, Bundle resultData) { mHandler.post(() -> receiveResult(request, callback, resultCode, resultData)); sHandler.post(() -> receiveResult(request, callback, resultCode, resultData)); } } }; }; sFontsContract.getFont(request, receiver); sFontsContract.getFont(request, receiver); Loading