Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ebecd7e8 authored by Seigo Nonaka's avatar Seigo Nonaka
Browse files

Stop fetching font data if the context is restricted.

Bug: 35763094
Test: android.provider.cts.FontsContractTest passes
Change-Id: I6b1a27c2a4898966b558ff98b0023670da6769dc
parent 06426bf6
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -34523,6 +34523,7 @@ package android.provider {
    method public android.provider.FontsContract.FontInfo[] getFonts();
    method public android.provider.FontsContract.FontInfo[] getFonts();
    method public int getStatusCode();
    method public int getStatusCode();
    field public static final int STATUS_OK = 0; // 0x0
    field public static final int STATUS_OK = 0; // 0x0
    field public static final int STATUS_REJECTED = 3; // 0x3
    field public static final int STATUS_UNEXPECTED_DATA_PROVIDED = 2; // 0x2
    field public static final int STATUS_UNEXPECTED_DATA_PROVIDED = 2; // 0x2
    field public static final int STATUS_WRONG_CERTIFICATES = 1; // 0x1
    field public static final int STATUS_WRONG_CERTIFICATES = 1; // 0x1
  }
  }
+1 −0
Original line number Original line Diff line number Diff line
@@ -37512,6 +37512,7 @@ package android.provider {
    method public android.provider.FontsContract.FontInfo[] getFonts();
    method public android.provider.FontsContract.FontInfo[] getFonts();
    method public int getStatusCode();
    method public int getStatusCode();
    field public static final int STATUS_OK = 0; // 0x0
    field public static final int STATUS_OK = 0; // 0x0
    field public static final int STATUS_REJECTED = 3; // 0x3
    field public static final int STATUS_UNEXPECTED_DATA_PROVIDED = 2; // 0x2
    field public static final int STATUS_UNEXPECTED_DATA_PROVIDED = 2; // 0x2
    field public static final int STATUS_WRONG_CERTIFICATES = 1; // 0x1
    field public static final int STATUS_WRONG_CERTIFICATES = 1; // 0x1
  }
  }
+1 −0
Original line number Original line Diff line number Diff line
@@ -34658,6 +34658,7 @@ package android.provider {
    method public android.provider.FontsContract.FontInfo[] getFonts();
    method public android.provider.FontsContract.FontInfo[] getFonts();
    method public int getStatusCode();
    method public int getStatusCode();
    field public static final int STATUS_OK = 0; // 0x0
    field public static final int STATUS_OK = 0; // 0x0
    field public static final int STATUS_REJECTED = 3; // 0x3
    field public static final int STATUS_UNEXPECTED_DATA_PROVIDED = 2; // 0x2
    field public static final int STATUS_UNEXPECTED_DATA_PROVIDED = 2; // 0x2
    field public static final int STATUS_WRONG_CERTIFICATES = 1; // 0x1
    field public static final int STATUS_WRONG_CERTIFICATES = 1; // 0x1
  }
  }
+18 −0
Original line number Original line Diff line number Diff line
@@ -283,6 +283,12 @@ public class FontsContract {
         */
         */
        public static final int STATUS_UNEXPECTED_DATA_PROVIDED = 2;
        public static final int STATUS_UNEXPECTED_DATA_PROVIDED = 2;


        /**
         * Constant represents that the fetching font data was rejected by system. This happens if
         * the passed context is restricted.
         */
        public static final int STATUS_REJECTED = 3;

        /** @hide */
        /** @hide */
        @IntDef({STATUS_OK, STATUS_WRONG_CERTIFICATES, STATUS_UNEXPECTED_DATA_PROVIDED})
        @IntDef({STATUS_OK, STATUS_WRONG_CERTIFICATES, STATUS_UNEXPECTED_DATA_PROVIDED})
        @Retention(RetentionPolicy.SOURCE)
        @Retention(RetentionPolicy.SOURCE)
@@ -555,6 +561,10 @@ public class FontsContract {
    public static @NonNull FontFamilyResult fetchFonts(
    public static @NonNull FontFamilyResult fetchFonts(
            @NonNull Context context, @Nullable CancellationSignal cancellationSignal,
            @NonNull Context context, @Nullable CancellationSignal cancellationSignal,
            @NonNull FontRequest request) throws NameNotFoundException {
            @NonNull FontRequest request) throws NameNotFoundException {
        if (context.isRestricted()) {
            // TODO: Should we allow if the peer process is system or myself?
            return new FontFamilyResult(FontFamilyResult.STATUS_REJECTED, null);
        }
        ProviderInfo providerInfo = getProvider(context.getPackageManager(), request);
        ProviderInfo providerInfo = getProvider(context.getPackageManager(), request);
        if (providerInfo == null) {
        if (providerInfo == null) {
            return new FontFamilyResult(FontFamilyResult.STATUS_WRONG_CERTIFICATES, null);
            return new FontFamilyResult(FontFamilyResult.STATUS_WRONG_CERTIFICATES, null);
@@ -590,6 +600,10 @@ public class FontsContract {
    public static Typeface buildTypeface(@NonNull Context context,
    public static Typeface buildTypeface(@NonNull Context context,
            @Nullable CancellationSignal cancellationSignal, @NonNull FontInfo[] fonts,
            @Nullable CancellationSignal cancellationSignal, @NonNull FontInfo[] fonts,
            int weight, boolean italic, @Nullable String fallbackFontName) {
            int weight, boolean italic, @Nullable String fallbackFontName) {
        if (context.isRestricted()) {
            // TODO: Should we allow if the peer process is system or myself?
            return null;
        }
        final Map<Uri, ByteBuffer> uriBuffer =
        final Map<Uri, ByteBuffer> uriBuffer =
                prepareFontData(context, fonts, cancellationSignal);
                prepareFontData(context, fonts, cancellationSignal);
        return new Typeface.Builder(fonts, uriBuffer)
        return new Typeface.Builder(fonts, uriBuffer)
@@ -613,6 +627,10 @@ public class FontsContract {
     */
     */
    public static Typeface buildTypeface(@NonNull Context context,
    public static Typeface buildTypeface(@NonNull Context context,
            @Nullable CancellationSignal cancellationSignal, @NonNull FontInfo[] fonts) {
            @Nullable CancellationSignal cancellationSignal, @NonNull FontInfo[] fonts) {
        if (context.isRestricted()) {
            // TODO: Should we allow if the peer process is system or myself?
            return null;
        }
        final Map<Uri, ByteBuffer> uriBuffer =
        final Map<Uri, ByteBuffer> uriBuffer =
                prepareFontData(context, fonts, cancellationSignal);
                prepareFontData(context, fonts, cancellationSignal);
        return new Typeface.Builder(fonts, uriBuffer).build();
        return new Typeface.Builder(fonts, uriBuffer).build();