From 9ccb2073e001760643ab7cedf13cecae2b65a5c4 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Fri, 21 May 2021 20:01:29 -0300 Subject: [PATCH] Add a FontsProvider that always returns the default font --- .../src/main/AndroidManifest.xml | 6 ++ .../org/microg/gms/fonts/FontsProvider.kt | 97 +++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 play-services-core/src/main/kotlin/org/microg/gms/fonts/FontsProvider.kt diff --git a/play-services-core/src/main/AndroidManifest.xml b/play-services-core/src/main/AndroidManifest.xml index 12c7f6c3..f20594bd 100644 --- a/play-services-core/src/main/AndroidManifest.xml +++ b/play-services-core/src/main/AndroidManifest.xml @@ -464,6 +464,12 @@ android:authorities="com.google.android.gms.chimera" android:exported="true" /> + + + ?, + selection: String?, + selectionArgs: Array?, + sortOrder: String? + ): Cursor { + Log.e(TAG, "query: $uri ${projection?.toList()} $selection") + val cursor = MatrixCursor(COLUMNS) + // We could also return an empty cursor here, but some apps have been reported to crash + // when their expected font is not returned by Google's font provider. + cursor.addRow( + arrayOf( + 1337L, // file_id + 0, // font_ttc_index + null, // font_variation_settings + 400, // font_weight + 0, // font_italic + 0, // result_code: RESULT_CODE_OK + ) + ) + return cursor + } + + override fun insert(uri: Uri, values: ContentValues?): Uri { + Log.d(TAG, "insert: $uri, $values") + return uri + } + + override fun update( + uri: Uri, + values: ContentValues?, + selection: String?, + selectionArgs: Array? + ): Int { + Log.d(TAG, "update: $uri, $values, $selection, $selectionArgs") + return 0 + } + + override fun delete(uri: Uri, selection: String?, selectionArgs: Array?): Int { + Log.d(TAG, "delete: $uri, $selection, $selectionArgs") + return 0 + } + + override fun getType(uri: Uri): String { + Log.d(TAG, "getType: $uri") + return "font/ttf" + } + + override fun openFile(uri: Uri, mode: String): ParcelFileDescriptor? { + Log.d(TAG, "openFile: $uri mode: $mode") + val file = File("/system/fonts/Roboto-Regular.ttf") + return ParcelFileDescriptor.open(file, MODE_READ_ONLY) + } + + companion object { + private const val TAG = "FontsProvider" + private val COLUMNS = arrayOf( + "file_id", + "font_ttc_index", + "font_variation_settings", + "font_weight", + "font_italic", + "result_code" + ) + } +}