OSDN Git Service

Introduce FILE_ID for TTC fonts and variation fonts.
authorSeigo Nonaka <nona@google.com>
Mon, 10 Apr 2017 18:03:24 +0000 (11:03 -0700)
committerSeigo Nonaka <nona@google.com>
Wed, 12 Apr 2017 14:24:21 +0000 (07:24 -0700)
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

api/current.txt
api/system-current.txt
api/test-current.txt
core/java/android/provider/FontsContract.java

index fada9aa..a669d1d 100644 (file)
@@ -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
index 23dc949..c2ad52f 100644 (file)
@@ -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
index 5c8edac..9f99e6b 100644 (file)
@@ -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
index 4deb4ab..f2aed5d 100644 (file)
@@ -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");