-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTypefaceCompatApi26Impl.java
More file actions
255 lines (242 loc) · 11.4 KB
/
TypefaceCompatApi26Impl.java
File metadata and controls
255 lines (242 loc) · 11.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
package android.support.v4.graphics;
import android.content.Context;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.graphics.fonts.FontVariationAxis;
import android.support.v4.content.res.FontResourcesParserCompat;
import android.util.Log;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
public class TypefaceCompatApi26Impl extends TypefaceCompatApi21Impl {
private static final String ABORT_CREATION_METHOD = "abortCreation";
private static final String ADD_FONT_FROM_ASSET_MANAGER_METHOD = "addFontFromAssetManager";
private static final String ADD_FONT_FROM_BUFFER_METHOD = "addFontFromBuffer";
private static final String CREATE_FROM_FAMILIES_WITH_DEFAULT_METHOD = "createFromFamiliesWithDefault";
private static final String FONT_FAMILY_CLASS = "android.graphics.FontFamily";
private static final String FREEZE_METHOD = "freeze";
private static final int RESOLVE_BY_FONT_TABLE = -1;
private static final String TAG = "TypefaceCompatApi26Impl";
private static final Method sAbortCreation;
private static final Method sAddFontFromAssetManager;
private static final Method sAddFontFromBuffer;
private static final Method sCreateFromFamiliesWithDefault;
private static final Class sFontFamily;
private static final Constructor sFontFamilyCtor;
private static final Method sFreeze;
static {
Method method;
Method method2;
Method method3;
Method method4;
Method method5;
Class<?> cls;
Constructor<?> constructor = null;
try {
cls = Class.forName(FONT_FAMILY_CLASS);
Constructor<?> constructor2 = cls.getConstructor(new Class[0]);
method4 = cls.getMethod(ADD_FONT_FROM_ASSET_MANAGER_METHOD, new Class[]{AssetManager.class, String.class, Integer.TYPE, Boolean.TYPE, Integer.TYPE, Integer.TYPE, Integer.TYPE, FontVariationAxis[].class});
method3 = cls.getMethod(ADD_FONT_FROM_BUFFER_METHOD, new Class[]{ByteBuffer.class, Integer.TYPE, FontVariationAxis[].class, Integer.TYPE, Integer.TYPE});
method2 = cls.getMethod(FREEZE_METHOD, new Class[0]);
method = cls.getMethod(ABORT_CREATION_METHOD, new Class[0]);
method5 = Typeface.class.getDeclaredMethod(CREATE_FROM_FAMILIES_WITH_DEFAULT_METHOD, new Class[]{Array.newInstance(cls, 1).getClass(), Integer.TYPE, Integer.TYPE});
method5.setAccessible(true);
constructor = constructor2;
} catch (ClassNotFoundException | NoSuchMethodException e) {
Log.e(TAG, "Unable to collect necessary methods for class " + e.getClass().getName(), e);
cls = null;
method5 = null;
method4 = null;
method3 = null;
method2 = null;
method = null;
}
sFontFamilyCtor = constructor;
sFontFamily = cls;
sAddFontFromAssetManager = method4;
sAddFontFromBuffer = method3;
sFreeze = method2;
sAbortCreation = method;
sCreateFromFamiliesWithDefault = method5;
}
private static boolean isFontFamilyPrivateAPIAvailable() {
if (sAddFontFromAssetManager == null) {
Log.w(TAG, "Unable to collect necessary private methods.Fallback to legacy implementation.");
}
return sAddFontFromAssetManager != null;
}
private static Object newFamily() {
try {
return sFontFamilyCtor.newInstance(new Object[0]);
} catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
throw new RuntimeException(e);
}
}
private static boolean addFontFromAssetManager(Context context, Object obj, String str, int i, int i2, int i3) {
try {
return ((Boolean) sAddFontFromAssetManager.invoke(obj, new Object[]{context.getAssets(), str, 0, false, Integer.valueOf(i), Integer.valueOf(i2), Integer.valueOf(i3), null})).booleanValue();
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
}
private static boolean addFontFromBuffer(Object obj, ByteBuffer byteBuffer, int i, int i2, int i3) {
try {
return ((Boolean) sAddFontFromBuffer.invoke(obj, new Object[]{byteBuffer, Integer.valueOf(i), null, Integer.valueOf(i2), Integer.valueOf(i3)})).booleanValue();
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
}
private static Typeface createFromFamiliesWithDefault(Object obj) {
try {
Object newInstance = Array.newInstance(sFontFamily, 1);
Array.set(newInstance, 0, obj);
return (Typeface) sCreateFromFamiliesWithDefault.invoke((Object) null, new Object[]{newInstance, -1, -1});
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
}
private static boolean freeze(Object obj) {
try {
return ((Boolean) sFreeze.invoke(obj, new Object[0])).booleanValue();
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
}
private static boolean abortCreation(Object obj) {
try {
return ((Boolean) sAbortCreation.invoke(obj, new Object[0])).booleanValue();
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
}
public Typeface createFromFontFamilyFilesResourceEntry(Context context, FontResourcesParserCompat.FontFamilyFilesResourceEntry fontFamilyFilesResourceEntry, Resources resources, int i) {
if (!isFontFamilyPrivateAPIAvailable()) {
return super.createFromFontFamilyFilesResourceEntry(context, fontFamilyFilesResourceEntry, resources, i);
}
Object newFamily = newFamily();
for (FontResourcesParserCompat.FontFileResourceEntry fontFileResourceEntry : fontFamilyFilesResourceEntry.getEntries()) {
if (!addFontFromAssetManager(context, newFamily, fontFileResourceEntry.getFileName(), 0, fontFileResourceEntry.getWeight(), fontFileResourceEntry.isItalic() ? 1 : 0)) {
abortCreation(newFamily);
return null;
}
}
if (!freeze(newFamily)) {
return null;
}
return createFromFamiliesWithDefault(newFamily);
}
/* JADX WARNING: Code restructure failed: missing block: B:17:0x0043, code lost:
r10 = move-exception;
*/
/* JADX WARNING: Code restructure failed: missing block: B:18:0x0044, code lost:
if (r8 != null) goto L_0x0046;
*/
/* JADX WARNING: Code restructure failed: missing block: B:20:?, code lost:
r8.close();
*/
/* JADX WARNING: Code restructure failed: missing block: B:24:0x004e, code lost:
throw r10;
*/
/* Code decompiled incorrectly, please refer to instructions dump. */
public android.graphics.Typeface createFromFontInfo(android.content.Context r8, android.os.CancellationSignal r9, android.support.v4.provider.FontsContractCompat.FontInfo[] r10, int r11) {
/*
r7 = this;
int r0 = r10.length
r1 = 1
r2 = 0
if (r0 >= r1) goto L_0x0006
return r2
L_0x0006:
boolean r0 = isFontFamilyPrivateAPIAvailable()
if (r0 != 0) goto L_0x0050
android.support.v4.provider.FontsContractCompat$FontInfo r10 = r7.findBestInfo(r10, r11)
android.content.ContentResolver r8 = r8.getContentResolver()
android.net.Uri r11 = r10.getUri() // Catch:{ IOException -> 0x004f }
java.lang.String r0 = "r"
android.os.ParcelFileDescriptor r8 = r8.openFileDescriptor(r11, r0, r9) // Catch:{ IOException -> 0x004f }
android.graphics.Typeface$Builder r9 = new android.graphics.Typeface$Builder // Catch:{ all -> 0x0041 }
java.io.FileDescriptor r11 = r8.getFileDescriptor() // Catch:{ all -> 0x0041 }
r9.<init>(r11) // Catch:{ all -> 0x0041 }
int r11 = r10.getWeight() // Catch:{ all -> 0x0041 }
android.graphics.Typeface$Builder r9 = r9.setWeight(r11) // Catch:{ all -> 0x0041 }
boolean r10 = r10.isItalic() // Catch:{ all -> 0x0041 }
android.graphics.Typeface$Builder r9 = r9.setItalic(r10) // Catch:{ all -> 0x0041 }
android.graphics.Typeface r9 = r9.build() // Catch:{ all -> 0x0041 }
if (r8 == 0) goto L_0x0040
r8.close() // Catch:{ IOException -> 0x004f }
L_0x0040:
return r9
L_0x0041:
r9 = move-exception
throw r9 // Catch:{ all -> 0x0043 }
L_0x0043:
r10 = move-exception
if (r8 == 0) goto L_0x004e
r8.close() // Catch:{ all -> 0x004a }
goto L_0x004e
L_0x004a:
r8 = move-exception
r9.addSuppressed(r8) // Catch:{ IOException -> 0x004f }
L_0x004e:
throw r10 // Catch:{ IOException -> 0x004f }
L_0x004f:
return r2
L_0x0050:
java.util.Map r8 = android.support.v4.provider.FontsContractCompat.prepareFontData(r8, r10, r9)
java.lang.Object r9 = newFamily()
int r11 = r10.length
r0 = 0
r3 = 0
L_0x005b:
if (r0 >= r11) goto L_0x0086
r4 = r10[r0]
android.net.Uri r5 = r4.getUri()
java.lang.Object r5 = r8.get(r5)
java.nio.ByteBuffer r5 = (java.nio.ByteBuffer) r5
if (r5 != 0) goto L_0x006c
goto L_0x0083
L_0x006c:
int r3 = r4.getTtcIndex()
int r6 = r4.getWeight()
boolean r4 = r4.isItalic()
boolean r3 = addFontFromBuffer(r9, r5, r3, r6, r4)
if (r3 != 0) goto L_0x0082
abortCreation(r9)
return r2
L_0x0082:
r3 = 1
L_0x0083:
int r0 = r0 + 1
goto L_0x005b
L_0x0086:
if (r3 != 0) goto L_0x008c
abortCreation(r9)
return r2
L_0x008c:
boolean r8 = freeze(r9)
if (r8 != 0) goto L_0x0093
return r2
L_0x0093:
android.graphics.Typeface r8 = createFromFamiliesWithDefault(r9)
return r8
*/
throw new UnsupportedOperationException("Method not decompiled: android.support.v4.graphics.TypefaceCompatApi26Impl.createFromFontInfo(android.content.Context, android.os.CancellationSignal, android.support.v4.provider.FontsContractCompat$FontInfo[], int):android.graphics.Typeface");
}
public Typeface createFromResourcesFontFile(Context context, Resources resources, int i, String str, int i2) {
if (!isFontFamilyPrivateAPIAvailable()) {
return super.createFromResourcesFontFile(context, resources, i, str, i2);
}
Object newFamily = newFamily();
if (!addFontFromAssetManager(context, newFamily, str, 0, -1, -1)) {
abortCreation(newFamily);
return null;
} else if (!freeze(newFamily)) {
return null;
} else {
return createFromFamiliesWithDefault(newFamily);
}
}
}