diff options
| author | 2017-04-10 11:03:24 -0700 | |
|---|---|---|
| committer | 2017-04-12 07:24:21 -0700 | |
| commit | 43c20cf6d4bd661d85bed76c78953aa656dbcc62 (patch) | |
| tree | d60aad6d6bf330c35ed46a34802f00ced7d6f6d6 | |
| parent | 1f58ad1a2f1a88fb154297080e2b97bbf47f4aa4 (diff) | |
Introduce FILE_ID for TTC fonts and variation fonts.
A single TTC font or variation font can be used for multiple entry
of FontResult. To share the file contents, assign same URI for those.
Bug: 36494487
Test: android.provider.FontsContractTest passes
Change-Id: Ibf24f216179a6481dee1801cd2dfb68c4bb38fac
| -rw-r--r-- | api/current.txt | 1 | ||||
| -rw-r--r-- | api/system-current.txt | 1 | ||||
| -rw-r--r-- | api/test-current.txt | 1 | ||||
| -rw-r--r-- | core/java/android/provider/FontsContract.java | 30 |
4 files changed, 28 insertions, 5 deletions
diff --git a/api/current.txt b/api/current.txt index fada9aad6c05..a669d1d0eb48 100644 --- a/api/current.txt +++ b/api/current.txt @@ -34482,6 +34482,7 @@ package android.provider { public static final class FontsContract.Columns implements android.provider.BaseColumns { ctor public FontsContract.Columns(); + field public static final java.lang.String FILE_ID = "file_id"; field public static final java.lang.String ITALIC = "font_italic"; field public static final java.lang.String RESULT_CODE = "result_code"; field public static final int RESULT_CODE_FONT_NOT_FOUND = 1; // 0x1 diff --git a/api/system-current.txt b/api/system-current.txt index 23dc949a961d..c2ad52f75613 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -37452,6 +37452,7 @@ package android.provider { public static final class FontsContract.Columns implements android.provider.BaseColumns { ctor public FontsContract.Columns(); + field public static final java.lang.String FILE_ID = "file_id"; field public static final java.lang.String ITALIC = "font_italic"; field public static final java.lang.String RESULT_CODE = "result_code"; field public static final int RESULT_CODE_FONT_NOT_FOUND = 1; // 0x1 diff --git a/api/test-current.txt b/api/test-current.txt index 5c8edac69edb..9f99e6bed7ec 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -34623,6 +34623,7 @@ package android.provider { public static final class FontsContract.Columns implements android.provider.BaseColumns { ctor public FontsContract.Columns(); + field public static final java.lang.String FILE_ID = "file_id"; field public static final java.lang.String ITALIC = "font_italic"; field public static final java.lang.String RESULT_CODE = "result_code"; field public static final int RESULT_CODE_FONT_NOT_FOUND = 1; // 0x1 diff --git a/core/java/android/provider/FontsContract.java b/core/java/android/provider/FontsContract.java index 4deb4ab69059..f2aed5d965d1 100644 --- a/core/java/android/provider/FontsContract.java +++ b/core/java/android/provider/FontsContract.java @@ -62,6 +62,15 @@ public class FontsContract { public static final class Columns implements BaseColumns { /** * Constant used to request data from a font provider. The cursor returned from the query + * may populate this column with a long for the font file ID. The client will request a file + * descriptor to "file/FILE_ID" with this ID immediately under the top-level content URI. If + * not present, the client will request a file descriptor to the top-level URI with the + * given base font ID. Note that several results may return the same file ID, e.g. for TTC + * files with different indices. + */ + public static final String FILE_ID = "file_id"; + /** + * Constant used to request data from a font provider. The cursor returned from the query * should have this column populated with an int for the ttc index for the resulting font. */ public static final String TTC_INDEX = "font_ttc_index"; @@ -282,12 +291,16 @@ public class FontsContract { public void getFontFromProvider(FontRequest request, ResultReceiver receiver, String authority) { ArrayList<FontResult> result = null; - Uri uri = new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT) + 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(); try (Cursor cursor = mContext.getContentResolver().query(uri, new String[] { Columns._ID, - Columns.TTC_INDEX, Columns.VARIATION_SETTINGS, Columns.STYLE, - Columns.WEIGHT, Columns.ITALIC, Columns.RESULT_CODE }, + Columns.FILE_ID, Columns.TTC_INDEX, Columns.VARIATION_SETTINGS, + Columns.STYLE, Columns.WEIGHT, Columns.ITALIC, Columns.RESULT_CODE }, "query = ?", new String[] { request.getQuery() }, null);) { // TODO: Should we restrict the amount of fonts that can be returned? // TODO: Write documentation explaining that all results should be from the same family. @@ -296,6 +309,7 @@ public class FontsContract { int resultCode = -1; result = new ArrayList<>(); final int idColumnIndex = cursor.getColumnIndexOrThrow(Columns._ID); + final int fileIdColumnIndex = cursor.getColumnIndex(Columns.FILE_ID); final int ttcIndexColumnIndex = cursor.getColumnIndex(Columns.TTC_INDEX); final int vsColumnIndex = cursor.getColumnIndex(Columns.VARIATION_SETTINGS); final int weightColumnIndex = cursor.getColumnIndex(Columns.WEIGHT); @@ -319,8 +333,14 @@ public class FontsContract { receiver.send(resultCode, null); return; } - long id = cursor.getLong(idColumnIndex); - Uri fileUri = ContentUris.withAppendedId(uri, id); + 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); + } try { ParcelFileDescriptor pfd = mContext.getContentResolver().openFileDescriptor(fileUri, "r"); |