@Test public void testGetFontFromProvider_providerDoesntReturnAllFields() { FontRequest request = new FontRequest( AUTHORITY, PACKAGE, MockFontProvider.MANDATORY_FIELDS_ONLY_QUERY, SIGNATURE); FontInfo[] fonts = FontsContractCompat.getFontFromProvider( mContext, request, AUTHORITY, null); assertNotNull(fonts); assertEquals(1, fonts.length); FontInfo font = fonts[0]; assertEquals(0, font.getTtcIndex()); assertEquals(RESULT_CODE_OK, font.getResultCode()); }
@VisibleForTesting @NonNull static FontInfo[] getFontFromProvider(Context context, FontRequest request, String authority, CancellationSignal cancellationSignal) { ArrayList<FontInfo> result = new ArrayList<>(); final Uri uri = new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT) .authority(authority) .build(); final Uri fileBaseUri = new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT) .authority(authority) .appendPath("file") .build(); Cursor cursor = null; try { if (Build.VERSION.SDK_INT > 16) { cursor = context.getContentResolver().query(uri, new String[] { Columns._ID, Columns.FILE_ID, Columns.TTC_INDEX, Columns.VARIATION_SETTINGS, Columns.WEIGHT, Columns.ITALIC, Columns.RESULT_CODE }, "query = ?", new String[] { request.getQuery() }, null, cancellationSignal); } else { cursor = context.getContentResolver().query(uri, new String[] { Columns._ID, Columns.FILE_ID, Columns.TTC_INDEX, Columns.VARIATION_SETTINGS, Columns.WEIGHT, Columns.ITALIC, Columns.RESULT_CODE }, "query = ?", new String[] { request.getQuery() }, null); } if (cursor != null && cursor.getCount() > 0) { final int resultCodeColumnIndex = cursor.getColumnIndex(Columns.RESULT_CODE); result = new ArrayList<>(); final int idColumnIndex = cursor.getColumnIndex(Columns._ID); final int fileIdColumnIndex = cursor.getColumnIndex(Columns.FILE_ID); final int ttcIndexColumnIndex = cursor.getColumnIndex(Columns.TTC_INDEX); final int weightColumnIndex = cursor.getColumnIndex(Columns.WEIGHT); final int italicColumnIndex = cursor.getColumnIndex(Columns.ITALIC); while (cursor.moveToNext()) { int resultCode = resultCodeColumnIndex != -1 ? cursor.getInt(resultCodeColumnIndex) : Columns.RESULT_CODE_OK; final int ttcIndex = ttcIndexColumnIndex != -1 ? cursor.getInt(ttcIndexColumnIndex) : 0; Uri fileUri; if (fileIdColumnIndex == -1) { long id = cursor.getLong(idColumnIndex); fileUri = ContentUris.withAppendedId(uri, id); } else { long id = cursor.getLong(fileIdColumnIndex); fileUri = ContentUris.withAppendedId(fileBaseUri, id); } int weight = weightColumnIndex != -1 ? cursor.getInt(weightColumnIndex) : 400; boolean italic = italicColumnIndex != -1 && cursor.getInt(italicColumnIndex) == 1; result.add(new FontInfo(fileUri, ttcIndex, weight, italic, resultCode)); } } } finally { if (cursor != null) { cursor.close(); } } return result.toArray(new FontInfo[0]); }
FontsContractCompat { @VisibleForTesting @NonNull static FontInfo[] getFontFromProvider(Context context, FontRequest request, String authority, CancellationSignal cancellationSignal) { ArrayList<FontInfo> result = new ArrayList<>(); final Uri uri = new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT) .authority(authority) .build(); final Uri fileBaseUri = new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT) .authority(authority) .appendPath("file") .build(); Cursor cursor = null; try { if (Build.VERSION.SDK_INT > 16) { cursor = context.getContentResolver().query(uri, new String[] { Columns._ID, Columns.FILE_ID, Columns.TTC_INDEX, Columns.VARIATION_SETTINGS, Columns.WEIGHT, Columns.ITALIC, Columns.RESULT_CODE }, "query = ?", new String[] { request.getQuery() }, null, cancellationSignal); } else { cursor = context.getContentResolver().query(uri, new String[] { Columns._ID, Columns.FILE_ID, Columns.TTC_INDEX, Columns.VARIATION_SETTINGS, Columns.WEIGHT, Columns.ITALIC, Columns.RESULT_CODE }, "query = ?", new String[] { request.getQuery() }, null); } if (cursor != null && cursor.getCount() > 0) { final int resultCodeColumnIndex = cursor.getColumnIndex(Columns.RESULT_CODE); result = new ArrayList<>(); final int idColumnIndex = cursor.getColumnIndex(Columns._ID); final int fileIdColumnIndex = cursor.getColumnIndex(Columns.FILE_ID); final int ttcIndexColumnIndex = cursor.getColumnIndex(Columns.TTC_INDEX); final int weightColumnIndex = cursor.getColumnIndex(Columns.WEIGHT); final int italicColumnIndex = cursor.getColumnIndex(Columns.ITALIC); while (cursor.moveToNext()) { int resultCode = resultCodeColumnIndex != -1 ? cursor.getInt(resultCodeColumnIndex) : Columns.RESULT_CODE_OK; final int ttcIndex = ttcIndexColumnIndex != -1 ? cursor.getInt(ttcIndexColumnIndex) : 0; Uri fileUri; if (fileIdColumnIndex == -1) { long id = cursor.getLong(idColumnIndex); fileUri = ContentUris.withAppendedId(uri, id); } else { long id = cursor.getLong(fileIdColumnIndex); fileUri = ContentUris.withAppendedId(fileBaseUri, id); } int weight = weightColumnIndex != -1 ? cursor.getInt(weightColumnIndex) : 400; boolean italic = italicColumnIndex != -1 && cursor.getInt(italicColumnIndex) == 1; result.add(new FontInfo(fileUri, ttcIndex, weight, italic, resultCode)); } } } finally { if (cursor != null) { cursor.close(); } } return result.toArray(new FontInfo[0]); } }
FontsContractCompat { @VisibleForTesting @NonNull static FontInfo[] getFontFromProvider(Context context, FontRequest request, String authority, CancellationSignal cancellationSignal) { ArrayList<FontInfo> result = new ArrayList<>(); final Uri uri = new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT) .authority(authority) .build(); final Uri fileBaseUri = new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT) .authority(authority) .appendPath("file") .build(); Cursor cursor = null; try { if (Build.VERSION.SDK_INT > 16) { cursor = context.getContentResolver().query(uri, new String[] { Columns._ID, Columns.FILE_ID, Columns.TTC_INDEX, Columns.VARIATION_SETTINGS, Columns.WEIGHT, Columns.ITALIC, Columns.RESULT_CODE }, "query = ?", new String[] { request.getQuery() }, null, cancellationSignal); } else { cursor = context.getContentResolver().query(uri, new String[] { Columns._ID, Columns.FILE_ID, Columns.TTC_INDEX, Columns.VARIATION_SETTINGS, Columns.WEIGHT, Columns.ITALIC, Columns.RESULT_CODE }, "query = ?", new String[] { request.getQuery() }, null); } if (cursor != null && cursor.getCount() > 0) { final int resultCodeColumnIndex = cursor.getColumnIndex(Columns.RESULT_CODE); result = new ArrayList<>(); final int idColumnIndex = cursor.getColumnIndex(Columns._ID); final int fileIdColumnIndex = cursor.getColumnIndex(Columns.FILE_ID); final int ttcIndexColumnIndex = cursor.getColumnIndex(Columns.TTC_INDEX); final int weightColumnIndex = cursor.getColumnIndex(Columns.WEIGHT); final int italicColumnIndex = cursor.getColumnIndex(Columns.ITALIC); while (cursor.moveToNext()) { int resultCode = resultCodeColumnIndex != -1 ? cursor.getInt(resultCodeColumnIndex) : Columns.RESULT_CODE_OK; final int ttcIndex = ttcIndexColumnIndex != -1 ? cursor.getInt(ttcIndexColumnIndex) : 0; Uri fileUri; if (fileIdColumnIndex == -1) { long id = cursor.getLong(idColumnIndex); fileUri = ContentUris.withAppendedId(uri, id); } else { long id = cursor.getLong(fileIdColumnIndex); fileUri = ContentUris.withAppendedId(fileBaseUri, id); } int weight = weightColumnIndex != -1 ? cursor.getInt(weightColumnIndex) : 400; boolean italic = italicColumnIndex != -1 && cursor.getInt(italicColumnIndex) == 1; result.add(new FontInfo(fileUri, ttcIndex, weight, italic, resultCode)); } } } finally { if (cursor != null) { cursor.close(); } } return result.toArray(new FontInfo[0]); } private  FontsContractCompat(); }
FontsContractCompat { @VisibleForTesting @NonNull static FontInfo[] getFontFromProvider(Context context, FontRequest request, String authority, CancellationSignal cancellationSignal) { ArrayList<FontInfo> result = new ArrayList<>(); final Uri uri = new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT) .authority(authority) .build(); final Uri fileBaseUri = new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT) .authority(authority) .appendPath("file") .build(); Cursor cursor = null; try { if (Build.VERSION.SDK_INT > 16) { cursor = context.getContentResolver().query(uri, new String[] { Columns._ID, Columns.FILE_ID, Columns.TTC_INDEX, Columns.VARIATION_SETTINGS, Columns.WEIGHT, Columns.ITALIC, Columns.RESULT_CODE }, "query = ?", new String[] { request.getQuery() }, null, cancellationSignal); } else { cursor = context.getContentResolver().query(uri, new String[] { Columns._ID, Columns.FILE_ID, Columns.TTC_INDEX, Columns.VARIATION_SETTINGS, Columns.WEIGHT, Columns.ITALIC, Columns.RESULT_CODE }, "query = ?", new String[] { request.getQuery() }, null); } if (cursor != null && cursor.getCount() > 0) { final int resultCodeColumnIndex = cursor.getColumnIndex(Columns.RESULT_CODE); result = new ArrayList<>(); final int idColumnIndex = cursor.getColumnIndex(Columns._ID); final int fileIdColumnIndex = cursor.getColumnIndex(Columns.FILE_ID); final int ttcIndexColumnIndex = cursor.getColumnIndex(Columns.TTC_INDEX); final int weightColumnIndex = cursor.getColumnIndex(Columns.WEIGHT); final int italicColumnIndex = cursor.getColumnIndex(Columns.ITALIC); while (cursor.moveToNext()) { int resultCode = resultCodeColumnIndex != -1 ? cursor.getInt(resultCodeColumnIndex) : Columns.RESULT_CODE_OK; final int ttcIndex = ttcIndexColumnIndex != -1 ? cursor.getInt(ttcIndexColumnIndex) : 0; Uri fileUri; if (fileIdColumnIndex == -1) { long id = cursor.getLong(idColumnIndex); fileUri = ContentUris.withAppendedId(uri, id); } else { long id = cursor.getLong(fileIdColumnIndex); fileUri = ContentUris.withAppendedId(fileBaseUri, id); } int weight = weightColumnIndex != -1 ? cursor.getInt(weightColumnIndex) : 400; boolean italic = italicColumnIndex != -1 && cursor.getInt(italicColumnIndex) == 1; result.add(new FontInfo(fileUri, ttcIndex, weight, italic, resultCode)); } } } finally { if (cursor != null) { cursor.close(); } } return result.toArray(new FontInfo[0]); } private  FontsContractCompat(); @RestrictTo(LIBRARY_GROUP) static void resetCache(); @RestrictTo(LIBRARY_GROUP) static Typeface getFontSync(final Context context, final FontRequest request,
            final @Nullable ResourcesCompat.FontCallback fontCallback,
            final @Nullable Handler handler, boolean isBlockingFetch, int timeout,
            final int style); static void requestFont(final @NonNull Context context,
            final @NonNull FontRequest request, final @NonNull FontRequestCallback callback,
            final @NonNull Handler handler); @Nullable static Typeface buildTypeface(@NonNull Context context,
            @Nullable CancellationSignal cancellationSignal, @NonNull FontInfo[] fonts); @RestrictTo(LIBRARY_GROUP) @RequiresApi(19) static Map<Uri, ByteBuffer> prepareFontData(Context context, FontInfo[] fonts,
            CancellationSignal cancellationSignal); @NonNull static FontFamilyResult fetchFonts(@NonNull Context context,
            @Nullable CancellationSignal cancellationSignal, @NonNull FontRequest request); @VisibleForTesting @RestrictTo(LIBRARY_GROUP) static @Nullable ProviderInfo getProvider(@NonNull PackageManager packageManager,
            @NonNull FontRequest request, @Nullable Resources resources); }
FontsContractCompat { @VisibleForTesting @NonNull static FontInfo[] getFontFromProvider(Context context, FontRequest request, String authority, CancellationSignal cancellationSignal) { ArrayList<FontInfo> result = new ArrayList<>(); final Uri uri = new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT) .authority(authority) .build(); final Uri fileBaseUri = new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT) .authority(authority) .appendPath("file") .build(); Cursor cursor = null; try { if (Build.VERSION.SDK_INT > 16) { cursor = context.getContentResolver().query(uri, new String[] { Columns._ID, Columns.FILE_ID, Columns.TTC_INDEX, Columns.VARIATION_SETTINGS, Columns.WEIGHT, Columns.ITALIC, Columns.RESULT_CODE }, "query = ?", new String[] { request.getQuery() }, null, cancellationSignal); } else { cursor = context.getContentResolver().query(uri, new String[] { Columns._ID, Columns.FILE_ID, Columns.TTC_INDEX, Columns.VARIATION_SETTINGS, Columns.WEIGHT, Columns.ITALIC, Columns.RESULT_CODE }, "query = ?", new String[] { request.getQuery() }, null); } if (cursor != null && cursor.getCount() > 0) { final int resultCodeColumnIndex = cursor.getColumnIndex(Columns.RESULT_CODE); result = new ArrayList<>(); final int idColumnIndex = cursor.getColumnIndex(Columns._ID); final int fileIdColumnIndex = cursor.getColumnIndex(Columns.FILE_ID); final int ttcIndexColumnIndex = cursor.getColumnIndex(Columns.TTC_INDEX); final int weightColumnIndex = cursor.getColumnIndex(Columns.WEIGHT); final int italicColumnIndex = cursor.getColumnIndex(Columns.ITALIC); while (cursor.moveToNext()) { int resultCode = resultCodeColumnIndex != -1 ? cursor.getInt(resultCodeColumnIndex) : Columns.RESULT_CODE_OK; final int ttcIndex = ttcIndexColumnIndex != -1 ? cursor.getInt(ttcIndexColumnIndex) : 0; Uri fileUri; if (fileIdColumnIndex == -1) { long id = cursor.getLong(idColumnIndex); fileUri = ContentUris.withAppendedId(uri, id); } else { long id = cursor.getLong(fileIdColumnIndex); fileUri = ContentUris.withAppendedId(fileBaseUri, id); } int weight = weightColumnIndex != -1 ? cursor.getInt(weightColumnIndex) : 400; boolean italic = italicColumnIndex != -1 && cursor.getInt(italicColumnIndex) == 1; result.add(new FontInfo(fileUri, ttcIndex, weight, italic, resultCode)); } } } finally { if (cursor != null) { cursor.close(); } } return result.toArray(new FontInfo[0]); } private  FontsContractCompat(); @RestrictTo(LIBRARY_GROUP) static void resetCache(); @RestrictTo(LIBRARY_GROUP) static Typeface getFontSync(final Context context, final FontRequest request,
            final @Nullable ResourcesCompat.FontCallback fontCallback,
            final @Nullable Handler handler, boolean isBlockingFetch, int timeout,
            final int style); static void requestFont(final @NonNull Context context,
            final @NonNull FontRequest request, final @NonNull FontRequestCallback callback,
            final @NonNull Handler handler); @Nullable static Typeface buildTypeface(@NonNull Context context,
            @Nullable CancellationSignal cancellationSignal, @NonNull FontInfo[] fonts); @RestrictTo(LIBRARY_GROUP) @RequiresApi(19) static Map<Uri, ByteBuffer> prepareFontData(Context context, FontInfo[] fonts,
            CancellationSignal cancellationSignal); @NonNull static FontFamilyResult fetchFonts(@NonNull Context context,
            @Nullable CancellationSignal cancellationSignal, @NonNull FontRequest request); @VisibleForTesting @RestrictTo(LIBRARY_GROUP) static @Nullable ProviderInfo getProvider(@NonNull PackageManager packageManager,
            @NonNull FontRequest request, @Nullable Resources resources); @RestrictTo(LIBRARY_GROUP)
    static final String PARCEL_FONT_RESULTS; }