@Test public void testGetProvider_providerNotFound() { PackageManager packageManager = mock(PackageManager.class); when(packageManager.resolveContentProvider(anyString(), anyInt())).thenReturn(null); FontRequest request = new FontRequest(AUTHORITY, PACKAGE, "query", SIGNATURE); try { FontsContractCompat.getProvider(packageManager, request, null); fail(); } catch (NameNotFoundException e) { } }
@VisibleForTesting @RestrictTo(LIBRARY_GROUP) public static @Nullable ProviderInfo getProvider(@NonNull PackageManager packageManager, @NonNull FontRequest request, @Nullable Resources resources) throws PackageManager.NameNotFoundException { String providerAuthority = request.getProviderAuthority(); ProviderInfo info = packageManager.resolveContentProvider(providerAuthority, 0); if (info == null) { throw new PackageManager.NameNotFoundException("No package found for authority: " + providerAuthority); } if (!info.packageName.equals(request.getProviderPackage())) { throw new PackageManager.NameNotFoundException("Found content provider " + providerAuthority + ", but package was not " + request.getProviderPackage()); } List<byte[]> signatures; @SuppressLint("PackageManagerGetSignatures") PackageInfo packageInfo = packageManager.getPackageInfo(info.packageName, PackageManager.GET_SIGNATURES); signatures = convertToByteArrayList(packageInfo.signatures); Collections.sort(signatures, sByteArrayComparator); List<List<byte[]>> requestCertificatesList = getCertificates(request, resources); for (int i = 0; i < requestCertificatesList.size(); ++i) { List<byte[]> requestSignatures = new ArrayList<>(requestCertificatesList.get(i)); Collections.sort(requestSignatures, sByteArrayComparator); if (equalsByteArrayList(signatures, requestSignatures)) { return info; } } return null; }
FontsContractCompat { @VisibleForTesting @RestrictTo(LIBRARY_GROUP) public static @Nullable ProviderInfo getProvider(@NonNull PackageManager packageManager, @NonNull FontRequest request, @Nullable Resources resources) throws PackageManager.NameNotFoundException { String providerAuthority = request.getProviderAuthority(); ProviderInfo info = packageManager.resolveContentProvider(providerAuthority, 0); if (info == null) { throw new PackageManager.NameNotFoundException("No package found for authority: " + providerAuthority); } if (!info.packageName.equals(request.getProviderPackage())) { throw new PackageManager.NameNotFoundException("Found content provider " + providerAuthority + ", but package was not " + request.getProviderPackage()); } List<byte[]> signatures; @SuppressLint("PackageManagerGetSignatures") PackageInfo packageInfo = packageManager.getPackageInfo(info.packageName, PackageManager.GET_SIGNATURES); signatures = convertToByteArrayList(packageInfo.signatures); Collections.sort(signatures, sByteArrayComparator); List<List<byte[]>> requestCertificatesList = getCertificates(request, resources); for (int i = 0; i < requestCertificatesList.size(); ++i) { List<byte[]> requestSignatures = new ArrayList<>(requestCertificatesList.get(i)); Collections.sort(requestSignatures, sByteArrayComparator); if (equalsByteArrayList(signatures, requestSignatures)) { return info; } } return null; } }
FontsContractCompat { @VisibleForTesting @RestrictTo(LIBRARY_GROUP) public static @Nullable ProviderInfo getProvider(@NonNull PackageManager packageManager, @NonNull FontRequest request, @Nullable Resources resources) throws PackageManager.NameNotFoundException { String providerAuthority = request.getProviderAuthority(); ProviderInfo info = packageManager.resolveContentProvider(providerAuthority, 0); if (info == null) { throw new PackageManager.NameNotFoundException("No package found for authority: " + providerAuthority); } if (!info.packageName.equals(request.getProviderPackage())) { throw new PackageManager.NameNotFoundException("Found content provider " + providerAuthority + ", but package was not " + request.getProviderPackage()); } List<byte[]> signatures; @SuppressLint("PackageManagerGetSignatures") PackageInfo packageInfo = packageManager.getPackageInfo(info.packageName, PackageManager.GET_SIGNATURES); signatures = convertToByteArrayList(packageInfo.signatures); Collections.sort(signatures, sByteArrayComparator); List<List<byte[]>> requestCertificatesList = getCertificates(request, resources); for (int i = 0; i < requestCertificatesList.size(); ++i) { List<byte[]> requestSignatures = new ArrayList<>(requestCertificatesList.get(i)); Collections.sort(requestSignatures, sByteArrayComparator); if (equalsByteArrayList(signatures, requestSignatures)) { return info; } } return null; } private  FontsContractCompat(); }
FontsContractCompat { @VisibleForTesting @RestrictTo(LIBRARY_GROUP) public static @Nullable ProviderInfo getProvider(@NonNull PackageManager packageManager, @NonNull FontRequest request, @Nullable Resources resources) throws PackageManager.NameNotFoundException { String providerAuthority = request.getProviderAuthority(); ProviderInfo info = packageManager.resolveContentProvider(providerAuthority, 0); if (info == null) { throw new PackageManager.NameNotFoundException("No package found for authority: " + providerAuthority); } if (!info.packageName.equals(request.getProviderPackage())) { throw new PackageManager.NameNotFoundException("Found content provider " + providerAuthority + ", but package was not " + request.getProviderPackage()); } List<byte[]> signatures; @SuppressLint("PackageManagerGetSignatures") PackageInfo packageInfo = packageManager.getPackageInfo(info.packageName, PackageManager.GET_SIGNATURES); signatures = convertToByteArrayList(packageInfo.signatures); Collections.sort(signatures, sByteArrayComparator); List<List<byte[]>> requestCertificatesList = getCertificates(request, resources); for (int i = 0; i < requestCertificatesList.size(); ++i) { List<byte[]> requestSignatures = new ArrayList<>(requestCertificatesList.get(i)); Collections.sort(requestSignatures, sByteArrayComparator); if (equalsByteArrayList(signatures, requestSignatures)) { return info; } } return null; } 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 @RestrictTo(LIBRARY_GROUP) public static @Nullable ProviderInfo getProvider(@NonNull PackageManager packageManager, @NonNull FontRequest request, @Nullable Resources resources) throws PackageManager.NameNotFoundException { String providerAuthority = request.getProviderAuthority(); ProviderInfo info = packageManager.resolveContentProvider(providerAuthority, 0); if (info == null) { throw new PackageManager.NameNotFoundException("No package found for authority: " + providerAuthority); } if (!info.packageName.equals(request.getProviderPackage())) { throw new PackageManager.NameNotFoundException("Found content provider " + providerAuthority + ", but package was not " + request.getProviderPackage()); } List<byte[]> signatures; @SuppressLint("PackageManagerGetSignatures") PackageInfo packageInfo = packageManager.getPackageInfo(info.packageName, PackageManager.GET_SIGNATURES); signatures = convertToByteArrayList(packageInfo.signatures); Collections.sort(signatures, sByteArrayComparator); List<List<byte[]>> requestCertificatesList = getCertificates(request, resources); for (int i = 0; i < requestCertificatesList.size(); ++i) { List<byte[]> requestSignatures = new ArrayList<>(requestCertificatesList.get(i)); Collections.sort(requestSignatures, sByteArrayComparator); if (equalsByteArrayList(signatures, requestSignatures)) { return info; } } return null; } 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; }