-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path0001-DU-Custom-Fonts-1-4.patch
2172 lines (2107 loc) · 93.6 KB
/
0001-DU-Custom-Fonts-1-4.patch
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
From 83ef79f15dabb7a0b8cf3e8178d65da4d09ce38e Mon Sep 17 00:00:00 2001
From: Kyle Harrison <[email protected]>
Date: Sat, 2 Feb 2019 20:52:03 +0000
Subject: [PATCH] DU Custom Fonts [1/4]
Change-Id: I474c04ac714ccbeac8e2b2f50a8ea98926f123d1
---
Android.bp | 1 +
core/java/android/app/ActivityThread.java | 11 +-
core/java/android/content/FontInfo.aidl | 20 +
core/java/android/content/FontInfo.java | 120 +++
core/java/android/content/IFontService.aidl | 40 +
.../java/android/content/pm/ActivityInfo.java | 5 +
.../android/content/res/Configuration.java | 6 +-
core/java/android/os/Process.java | 6 +-
core/java/android/os/ZygoteProcess.java | 9 +-
core/java/android/provider/Settings.java | 14 +
core/java/android/text/FontConfig.java | 18 +-
.../android/internal/os/ZygoteConnection.java | 10 +
core/res/AndroidManifest.xml | 10 +
core/res/res/values/du_arrays.xml | 27 +
core/res/res/values/du_strings.xml | 6 +
core/res/res/values/du_symbols.xml | 3 +
.../java/android/graphics/FontListParser.java | 52 +-
graphics/java/android/graphics/Typeface.java | 300 +++++++-
.../SystemUI/res-keyguard/values/styles.xml | 3 -
.../android/keyguard/KeyguardStatusView.java | 4 +
.../android/systemui/BatteryMeterView.java | 4 +
.../phone/KeyguardBottomAreaView.java | 4 +
.../phone/KeyguardStatusBarView.java | 4 +
.../java/com/android/server/FontService.java | 714 ++++++++++++++++++
.../server/am/ActivityManagerService.java | 23 +-
.../java/com/android/server/SystemServer.java | 7 +
26 files changed, 1358 insertions(+), 63 deletions(-)
create mode 100644 core/java/android/content/FontInfo.aidl
create mode 100644 core/java/android/content/FontInfo.java
create mode 100644 core/java/android/content/IFontService.aidl
create mode 100644 core/res/res/values/du_arrays.xml
create mode 100644 services/core/java/com/android/server/FontService.java
diff --git a/Android.bp b/Android.bp
index 4f59cc260ae..e5bc6fc1cb2 100644
--- a/Android.bp
+++ b/Android.bp
@@ -108,6 +108,7 @@ java_library {
":libbluetooth-binder-aidl",
"core/java/android/content/IClipboard.aidl",
"core/java/android/content/IContentService.aidl",
+ "core/java/android/content/IFontService.aidl",
"core/java/android/content/IIntentReceiver.aidl",
"core/java/android/content/IIntentSender.aidl",
"core/java/android/content/IOnPrimaryClipChangedListener.aidl",
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index 14a622a68fa..e09bf9e2976 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -67,6 +67,7 @@ import android.database.sqlite.SQLiteDebug;
import android.database.sqlite.SQLiteDebug.DbStats;
import android.graphics.Bitmap;
import android.graphics.Canvas;
+import android.graphics.Typeface;
import android.graphics.ImageDecoder;
import android.hardware.display.DisplayManagerGlobal;
import android.net.ConnectivityManager;
@@ -5240,9 +5241,13 @@ public final class ActivityThread extends ClientTransactionHandler {
if (configDiff != 0) {
// Ask text layout engine to free its caches if there is a locale change
boolean hasLocaleConfigChange = ((configDiff & ActivityInfo.CONFIG_LOCALE) != 0);
- if (hasLocaleConfigChange) {
- Canvas.freeTextLayoutCaches();
- if (DEBUG_CONFIGURATION) Slog.v(TAG, "Cleared TextLayout Caches");
+ boolean hasFontConfigChange = ((configDiff & ActivityInfo.CONFIG_THEME_FONT) != 0);
+ if (hasLocaleConfigChange || hasFontConfigChange) {
+ Canvas.freeTextLayoutCaches();
+ if (hasFontConfigChange) {
+ Typeface.recreateDefaults();
+ }
+ if (DEBUG_CONFIGURATION) Slog.v(TAG, "Cleared TextLayout Caches");
}
}
}
diff --git a/core/java/android/content/FontInfo.aidl b/core/java/android/content/FontInfo.aidl
new file mode 100644
index 00000000000..4f6b55e0edb
--- /dev/null
+++ b/core/java/android/content/FontInfo.aidl
@@ -0,0 +1,20 @@
+/**
+ * Copyright (c) 2010, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.content;
+
+parcelable FontInfo;
+
diff --git a/core/java/android/content/FontInfo.java b/core/java/android/content/FontInfo.java
new file mode 100644
index 00000000000..f7c9c526676
--- /dev/null
+++ b/core/java/android/content/FontInfo.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2018 The Dirty Unicorns Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.content;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+import android.text.TextUtils;
+
+public class FontInfo implements Parcelable, Comparable<FontInfo> {
+ public static final String DEFAULT_FONT_PACKAGE = "android";
+ public static final String DEFAULT_FONT_NAME = "Roboto";
+ public static final String DEFAULT_FONT_PATH = "/system/fonts/Roboto-Regular.ttf";
+
+ private static final FontInfo sDefaultInfo = new FontInfo(DEFAULT_FONT_PACKAGE, DEFAULT_FONT_NAME,
+ DEFAULT_FONT_PATH);
+
+ public String packageName;
+ public String fontName;
+ public String previewPath;
+
+ public static FontInfo getDefaultFontInfo() {
+ return new FontInfo(sDefaultInfo);
+ }
+
+ public static final Parcelable.Creator<FontInfo> CREATOR = new Parcelable.Creator<FontInfo>() {
+ public FontInfo createFromParcel(Parcel in) {
+ return new FontInfo(in);
+ }
+
+ public FontInfo[] newArray(int size) {
+ return new FontInfo[size];
+ }
+ };
+
+ public FontInfo() {
+ }
+
+ public FontInfo(String packageName, String fontName, String previewPath) {
+ this.packageName = packageName;
+ this.fontName = fontName;
+ this.previewPath = previewPath;
+ }
+
+ public FontInfo(FontInfo from) {
+ this.packageName = from.packageName;
+ this.fontName = from.fontName;
+ this.previewPath = from.previewPath;
+ }
+
+ public FontInfo(Parcel in) {
+ this.packageName = in.readString();
+ this.fontName = in.readString();
+ this.previewPath = in.readString();
+ }
+
+ public void updateFrom(FontInfo info) {
+ this.packageName = info.packageName;
+ this.fontName = info.fontName;
+ this.previewPath = info.previewPath;
+ }
+
+ public String toDelimitedString() {
+ return this.packageName + "|"
+ + this.fontName + "|"
+ + this.previewPath;
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeString(this.packageName);
+ dest.writeString(this.fontName);
+ dest.writeString(this.previewPath);
+ }
+
+ @Override
+ public String toString() {
+ return "FontInfo{" +
+ "packageName='" + packageName + '\'' +
+ ", fontName='" + fontName + '\'' +
+ ", previewPath='" + previewPath + '\'' +
+ '}';
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null)
+ return false;
+ if (!(obj instanceof FontInfo))
+ return false;
+ FontInfo other = (FontInfo) obj;
+ return TextUtils.equals(this.packageName, other.packageName)
+ && TextUtils.equals(this.fontName, other.fontName)
+ && TextUtils.equals(this.previewPath, other.previewPath);
+ }
+
+ @Override
+ public int compareTo(FontInfo o) {
+ int result = this.fontName.toString().compareToIgnoreCase(o.fontName.toString());
+ return result;
+ }
+}
diff --git a/core/java/android/content/IFontService.aidl b/core/java/android/content/IFontService.aidl
new file mode 100644
index 00000000000..13803b019a6
--- /dev/null
+++ b/core/java/android/content/IFontService.aidl
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2018 The Dirty Unicorns Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.content;
+
+import android.content.FontInfo;
+
+import java.util.Map;
+
+interface IFontService {
+ /**
+ * Apply a specified font pack
+ * @param info the FontInfo object to apply
+ */
+ void applyFont(in FontInfo info);
+
+ /**
+ * @return current FontInfo
+ */
+ FontInfo getFontInfo();
+
+ /**
+ * @return A Map<String, List<FontInfo>> of all the packages that provides fonts
+ * mapped to a list of all the fonts that package provides
+ */
+ Map getAllFonts();
+}
diff --git a/core/java/android/content/pm/ActivityInfo.java b/core/java/android/content/pm/ActivityInfo.java
index 0e91a2927c7..247ff098ab6 100644
--- a/core/java/android/content/pm/ActivityInfo.java
+++ b/core/java/android/content/pm/ActivityInfo.java
@@ -757,6 +757,11 @@ public class ActivityInfo extends ComponentInfo implements Parcelable {
* {@link android.R.attr#configChanges} attribute.
*/
public static final int CONFIG_LAYOUT_DIRECTION = 0x2000;
+ /**
+ * Bit in {@link #configChanges} that indicates a font change occurred
+ * @hide
+ */
+ public static final int CONFIG_THEME_FONT = 0x200000;
/**
* Bit in {@link #configChanges} that indicates that the activity
* can itself handle the change to the display color gamut or dynamic
diff --git a/core/java/android/content/res/Configuration.java b/core/java/android/content/res/Configuration.java
index 193e56ef404..d5660b27daa 100644
--- a/core/java/android/content/res/Configuration.java
+++ b/core/java/android/content/res/Configuration.java
@@ -1222,6 +1222,7 @@ public final class Configuration implements Parcelable, Comparable<Configuration
int changed = 0;
if (delta.fontScale > 0 && fontScale != delta.fontScale) {
changed |= ActivityInfo.CONFIG_FONT_SCALE;
+ changed |= ActivityInfo.CONFIG_THEME_FONT;
fontScale = delta.fontScale;
}
if (delta.mcc != 0 && mcc != delta.mcc) {
@@ -1382,6 +1383,7 @@ public final class Configuration implements Parcelable, Comparable<Configuration
}
if (delta.assetsSeq != ASSETS_SEQ_UNDEFINED && delta.assetsSeq != assetsSeq) {
changed |= ActivityInfo.CONFIG_ASSETS_PATHS;
+ changed |= ActivityInfo.CONFIG_THEME_FONT;
assetsSeq = delta.assetsSeq;
}
if (delta.seq != 0) {
@@ -1450,6 +1452,7 @@ public final class Configuration implements Parcelable, Comparable<Configuration
int changed = 0;
if ((compareUndefined || delta.fontScale > 0) && fontScale != delta.fontScale) {
changed |= ActivityInfo.CONFIG_FONT_SCALE;
+ changed |= ActivityInfo.CONFIG_THEME_FONT;
}
if ((compareUndefined || delta.mcc != 0) && mcc != delta.mcc) {
changed |= ActivityInfo.CONFIG_MCC;
@@ -1539,6 +1542,7 @@ public final class Configuration implements Parcelable, Comparable<Configuration
if ((compareUndefined || delta.assetsSeq != ASSETS_SEQ_UNDEFINED)
&& assetsSeq != delta.assetsSeq) {
changed |= ActivityInfo.CONFIG_ASSETS_PATHS;
+ changed |= ActivityInfo.CONFIG_THEME_FONT;
}
// WindowConfiguration differences aren't considered public...
@@ -1567,7 +1571,7 @@ public final class Configuration implements Parcelable, Comparable<Configuration
// CONFIG_ASSETS_PATHS and CONFIG_FONT_SCALE are higher level configuration changes that
// all resources are subject to change with.
interestingChanges = interestingChanges | ActivityInfo.CONFIG_ASSETS_PATHS
- | ActivityInfo.CONFIG_FONT_SCALE;
+ | ActivityInfo.CONFIG_FONT_SCALE | ActivityInfo.CONFIG_THEME_FONT;
return (configChanges & interestingChanges) != 0;
}
diff --git a/core/java/android/os/Process.java b/core/java/android/os/Process.java
index 1d4d4ce172b..dce481a1ef3 100644
--- a/core/java/android/os/Process.java
+++ b/core/java/android/os/Process.java
@@ -486,10 +486,11 @@ public class Process {
String instructionSet,
String appDataDir,
String invokeWith,
+ boolean refreshTheme,
String[] zygoteArgs) {
return zygoteProcess.start(processClass, niceName, uid, gid, gids,
runtimeFlags, mountExternal, targetSdkVersion, seInfo,
- abi, instructionSet, appDataDir, invokeWith, zygoteArgs);
+ abi, instructionSet, appDataDir, invokeWith, refreshTheme, zygoteArgs);
}
/** @hide */
@@ -503,10 +504,11 @@ public class Process {
String instructionSet,
String appDataDir,
String invokeWith,
+ boolean refreshTheme,
String[] zygoteArgs) {
return WebViewZygote.getProcess().start(processClass, niceName, uid, gid, gids,
runtimeFlags, mountExternal, targetSdkVersion, seInfo,
- abi, instructionSet, appDataDir, invokeWith, zygoteArgs);
+ abi, instructionSet, appDataDir, invokeWith, refreshTheme, zygoteArgs);
}
/**
diff --git a/core/java/android/os/ZygoteProcess.java b/core/java/android/os/ZygoteProcess.java
index 6994033a963..6a67ae8439a 100644
--- a/core/java/android/os/ZygoteProcess.java
+++ b/core/java/android/os/ZygoteProcess.java
@@ -227,11 +227,12 @@ public class ZygoteProcess {
String instructionSet,
String appDataDir,
String invokeWith,
+ boolean refreshTheme,
String[] zygoteArgs) {
try {
return startViaZygote(processClass, niceName, uid, gid, gids,
runtimeFlags, mountExternal, targetSdkVersion, seInfo,
- abi, instructionSet, appDataDir, invokeWith, false /* startChildZygote */,
+ abi, instructionSet, appDataDir, invokeWith, refreshTheme, false /* startChildZygote */,
zygoteArgs);
} catch (ZygoteStartFailedEx ex) {
Log.e(LOG_TAG,
@@ -365,6 +366,7 @@ public class ZygoteProcess {
String instructionSet,
String appDataDir,
String invokeWith,
+ boolean refreshTheme,
boolean startChildZygote,
String[] extraArgs)
throws ZygoteStartFailedEx {
@@ -376,6 +378,9 @@ public class ZygoteProcess {
argsForZygote.add("--setuid=" + uid);
argsForZygote.add("--setgid=" + gid);
argsForZygote.add("--runtime-flags=" + runtimeFlags);
+ if (refreshTheme) {
+ argsForZygote.add("--refresh_theme");
+ }
if (mountExternal == Zygote.MOUNT_EXTERNAL_DEFAULT) {
argsForZygote.add("--mount-external-default");
} else if (mountExternal == Zygote.MOUNT_EXTERNAL_READ) {
@@ -703,7 +708,7 @@ public class ZygoteProcess {
try {
result = startViaZygote(processClass, niceName, uid, gid,
gids, runtimeFlags, 0 /* mountExternal */, 0 /* targetSdkVersion */, seInfo,
- abi, instructionSet, null /* appDataDir */, null /* invokeWith */,
+ abi, instructionSet, null /* appDataDir */, null /* invokeWith */, true,
true /* startChildZygote */, extraArgs);
} catch (ZygoteStartFailedEx ex) {
throw new RuntimeException("Starting child-zygote through Zygote failed", ex);
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 43b6e21b5b2..a27315c8003 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -4357,6 +4357,20 @@ public final class Settings {
}
};
+ /**
+ * Hold current font name and name of the originating package Uses "|" as a delimiter
+ *
+ * @hide
+ */
+ public static final String FONT_INFO = "font_info";
+
+ /**
+ * Hold list of installed font provider packages. Uses "|" as a delimiter
+ *
+ * @hide
+ */
+ public static final String FONT_PACKAGES = "font_packages";
+
/**
* Custom button brightness value for manual mode
*
diff --git a/core/java/android/text/FontConfig.java b/core/java/android/text/FontConfig.java
index 7386e3e8856..83ae5dc2c91 100644
--- a/core/java/android/text/FontConfig.java
+++ b/core/java/android/text/FontConfig.java
@@ -25,17 +25,17 @@ import android.graphics.fonts.FontVariationAxis;
import android.net.Uri;
import java.lang.annotation.Retention;
-
+import java.util.List;
/**
* Font configuration descriptions for System fonts.
* @hide
*/
public final class FontConfig {
- private final @NonNull Family[] mFamilies;
- private final @NonNull Alias[] mAliases;
+ private final @NonNull List<Family> mFamilies;
+ private final @NonNull List<Alias> mAliases;
- public FontConfig(@NonNull Family[] families, @NonNull Alias[] aliases) {
+ public FontConfig(@NonNull List<Family> families, @NonNull List<Alias> aliases) {
mFamilies = families;
mAliases = aliases;
}
@@ -43,14 +43,14 @@ public final class FontConfig {
/**
* Returns the ordered list of families included in the system fonts.
*/
- public @NonNull Family[] getFamilies() {
+ public @NonNull List<Family> getFamilies() {
return mFamilies;
}
/**
* Returns the list of aliases defined for the font families in the system fonts.
*/
- public @NonNull Alias[] getAliases() {
+ public @NonNull List<Alias> getAliases() {
return mAliases;
}
@@ -173,7 +173,7 @@ public final class FontConfig {
* Class that holds information about a Font family.
*/
public static final class Family {
- private final @NonNull String mName;
+ private String mName;
private final @NonNull Font[] mFonts;
private final @NonNull String[] mLanguages;
@@ -221,6 +221,10 @@ public final class FontConfig {
mVariant = variant;
}
+ public void clearName() {
+ mName = null;
+ }
+
/**
* Returns the name given by the system to this font family.
*/
diff --git a/core/java/com/android/internal/os/ZygoteConnection.java b/core/java/com/android/internal/os/ZygoteConnection.java
index f537e3e2897..7db04be0298 100644
--- a/core/java/com/android/internal/os/ZygoteConnection.java
+++ b/core/java/com/android/internal/os/ZygoteConnection.java
@@ -26,6 +26,7 @@ import static com.android.internal.os.ZygoteConnectionConstants.CONNECTION_TIMEO
import static com.android.internal.os.ZygoteConnectionConstants.MAX_ZYGOTE_ARGC;
import static com.android.internal.os.ZygoteConnectionConstants.WRAPPED_PID_TIMEOUT_MILLIS;
+import android.graphics.Typeface;
import android.net.Credentials;
import android.net.LocalSocket;
import android.os.FactoryTest;
@@ -203,6 +204,10 @@ class ZygoteConnection {
}
}
+ if (parsedArgs.refreshTheme) {
+ Typeface.recreateDefaults();
+ }
+
/**
* In order to avoid leaking descriptors to the Zygote child,
* the native code must close the two Zygote socket descriptors
@@ -410,6 +415,9 @@ class ZygoteConnection {
/** from --invoke-with */
String invokeWith;
+ /** from --refresh-theme */
+ boolean refreshTheme;
+
/**
* Any args after and including the first non-option arg
* (or after a '--')
@@ -651,6 +659,8 @@ class ZygoteConnection {
"Invalid log sampling rate: " + rateStr, nfe);
}
expectRuntimeArgs = false;
+ } else if (arg.equals("--refresh_theme")) {
+ refreshTheme = true;
} else {
break;
}
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index d0ae9dbc55a..a552c42ba41 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -605,6 +605,9 @@
<protected-broadcast android:name="android.intent.action.DOCK_IDLE" />
<protected-broadcast android:name="android.intent.action.DOCK_ACTIVE" />
+ <!-- Font service -->
+ <protected-broadcast android:name="com.android.server.ACTION_FONT_CHANGED" />
+
<!-- ====================================================================== -->
<!-- RUNTIME PERMISSIONS -->
<!-- ====================================================================== -->
@@ -3553,6 +3556,13 @@
<permission android:name="android.permission.BIND_PACKAGE_VERIFIER"
android:protectionLevel="signature" />
+ <!-- Allows an application to access the font manager
+ @hide -->
+ <permission android:name="android.permission.ACCESS_FONT_MANAGER"
+ android:label="@string/permlab_accessFontManager"
+ android:description="@string/permdesc_accessFontManager"
+ android:protectionLevel="signatureOrSystem" />
+
<!-- @SystemApi @hide Allows an application to mark other applications as harmful -->
<permission android:name="android.permission.SET_HARMFUL_APP_WARNINGS"
android:protectionLevel="signature|verifier" />
diff --git a/core/res/res/values/du_arrays.xml b/core/res/res/values/du_arrays.xml
new file mode 100644
index 00000000000..5b019c79691
--- /dev/null
+++ b/core/res/res/values/du_arrays.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/* Copyright (c) 2013, The Linux Foundation. All rights reserved.
+** Not a Contribution.
+**
+** Copyright 2012, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+** http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+<resources>
+
+ <!-- System font packages (overlay in vendor) -->
+ <string-array name="config_fontPackages" translatable="false">
+ </string-array>
+
+</resources>
diff --git a/core/res/res/values/du_strings.xml b/core/res/res/values/du_strings.xml
index 416c82a4c2b..3ec57a48f2a 100644
--- a/core/res/res/values/du_strings.xml
+++ b/core/res/res/values/du_strings.xml
@@ -34,4 +34,10 @@
<!-- Vendor mismatched fingerprint warning [CHAR LIMIT=NONE] -->
<string name="system_error_vendorprint">Your vendor image does not match the system. Please flash the <xliff:g id="string">%s</xliff:g> vendor image for your device</string>
+ <!-- Font service -->
+ <!-- [CHAR LIMIT=NONE] Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+ <string name="permlab_accessFontManager">access font manager</string>
+ <!-- [CHAR LIMIT=NONE] Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+ <string name="permdesc_accessFontManager">Allows an application to access the font manager.</string>
+
</resources>
diff --git a/core/res/res/values/du_symbols.xml b/core/res/res/values/du_symbols.xml
index ad562732146..cea04e777be 100644
--- a/core/res/res/values/du_symbols.xml
+++ b/core/res/res/values/du_symbols.xml
@@ -162,4 +162,7 @@
<!-- Whether device has dash charging support -->
<java-symbol type="bool" name="config_hasDashCharger" />
+ <!-- System fonts -->
+ <java-symbol type="array" name="config_fontPackages" />
+
</resources>
diff --git a/graphics/java/android/graphics/FontListParser.java b/graphics/java/android/graphics/FontListParser.java
index 431d0e0eb7b..bf16c30f4b1 100644
--- a/graphics/java/android/graphics/FontListParser.java
+++ b/graphics/java/android/graphics/FontListParser.java
@@ -23,6 +23,9 @@ import android.util.Xml;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
@@ -37,18 +40,39 @@ import java.util.regex.Pattern;
public class FontListParser {
/* Parse fallback list (no names) */
- public static FontConfig parse(InputStream in) throws XmlPullParserException, IOException {
+ public static FontConfig parse(File configFilename, String fontDir) throws XmlPullParserException, IOException {
+ FileInputStream in = null;
+ in = new FileInputStream(configFilename);
+ return FontListParser.parse(in, fontDir);
+ }
+ /* Parse fallback list (no names) */
+ public static FontConfig parse(InputStream in, String fontDir)
+ throws XmlPullParserException, IOException {
+ BufferedInputStream bis = null;
try {
- XmlPullParser parser = Xml.newPullParser();
- parser.setInput(in, null);
- parser.nextTag();
- return readFamilies(parser);
+ // wrap input stream in a BufferedInputStream, if it's not already, for mark support
+ if (!(in instanceof BufferedInputStream)) {
+ bis = new BufferedInputStream(in);
+ } else {
+ bis = (BufferedInputStream) in;
+ }
+ // mark the beginning so we can reset to this position after checking format
+ bis.mark(in.available());
+ return parseNormalFormat(bis, fontDir);
} finally {
- in.close();
+ if (bis != null) bis.close();
}
}
- private static FontConfig readFamilies(XmlPullParser parser)
+ public static FontConfig parseNormalFormat(InputStream in, String dirName)
+ throws XmlPullParserException, IOException {
+ XmlPullParser parser = Xml.newPullParser();
+ parser.setInput(in, null);
+ parser.nextTag();
+ return readFamilies(parser, dirName);
+ }
+
+ private static FontConfig readFamilies(XmlPullParser parser, String dirPath)
throws XmlPullParserException, IOException {
List<FontConfig.Family> families = new ArrayList<>();
List<FontConfig.Alias> aliases = new ArrayList<>();
@@ -58,18 +82,17 @@ public class FontListParser {
if (parser.getEventType() != XmlPullParser.START_TAG) continue;
String tag = parser.getName();
if (tag.equals("family")) {
- families.add(readFamily(parser));
+ families.add(readFamily(parser,dirPath));
} else if (tag.equals("alias")) {
aliases.add(readAlias(parser));
} else {
skip(parser);
}
}
- return new FontConfig(families.toArray(new FontConfig.Family[families.size()]),
- aliases.toArray(new FontConfig.Alias[aliases.size()]));
+ return new FontConfig(families,aliases);
}
- private static FontConfig.Family readFamily(XmlPullParser parser)
+ private static FontConfig.Family readFamily(XmlPullParser parser,String dirPath)
throws XmlPullParserException, IOException {
final String name = parser.getAttributeValue(null, "name");
final String lang = parser.getAttributeValue(null, "lang");
@@ -80,7 +103,7 @@ public class FontListParser {
if (parser.getEventType() != XmlPullParser.START_TAG) continue;
final String tag = parser.getName();
if (tag.equals("font")) {
- fonts.add(readFont(parser));
+ fonts.add(readFont(parser,dirPath));
} else {
skip(parser);
}
@@ -101,7 +124,7 @@ public class FontListParser {
private static final Pattern FILENAME_WHITESPACE_PATTERN =
Pattern.compile("^[ \\n\\r\\t]+|[ \\n\\r\\t]+$");
- private static FontConfig.Font readFont(XmlPullParser parser)
+ private static FontConfig.Font readFont(XmlPullParser parser, String dirPath)
throws XmlPullParserException, IOException {
String indexStr = parser.getAttributeValue(null, "index");
int index = indexStr == null ? 0 : Integer.parseInt(indexStr);
@@ -123,7 +146,8 @@ public class FontListParser {
skip(parser);
}
}
- String sanitizedName = FILENAME_WHITESPACE_PATTERN.matcher(filename).replaceAll("");
+ String sanitizedName = dirPath + File.separatorChar +
+ FILENAME_WHITESPACE_PATTERN.matcher(filename).replaceAll("");
return new FontConfig.Font(sanitizedName, index,
axes.toArray(new FontVariationAxis[axes.size()]), weight, isItalic, fallbackFor);
}
diff --git a/graphics/java/android/graphics/Typeface.java b/graphics/java/android/graphics/Typeface.java
index 18dd97f8ace..8164111473b 100644
--- a/graphics/java/android/graphics/Typeface.java
+++ b/graphics/java/android/graphics/Typeface.java
@@ -31,6 +31,7 @@ import android.net.Uri;
import android.provider.FontRequest;
import android.provider.FontsContract;
import android.text.FontConfig;
+import android.text.FontConfig.Family;
import android.util.ArrayMap;
import android.util.Base64;
import android.util.Log;
@@ -79,19 +80,19 @@ public class Typeface {
Typeface.class.getClassLoader(), nativeGetReleaseFunc(), 64);
/** The default NORMAL typeface object */
- public static final Typeface DEFAULT;
+ public static Typeface DEFAULT;
/**
* The default BOLD typeface object. Note: this may be not actually be
* bold, depending on what fonts are installed. Call getStyle() to know
* for sure.
*/
- public static final Typeface DEFAULT_BOLD;
+ public static Typeface DEFAULT_BOLD;
/** The NORMAL style of the default sans serif typeface. */
- public static final Typeface SANS_SERIF;
+ public static Typeface SANS_SERIF;
/** The NORMAL style of the default serif typeface. */
- public static final Typeface SERIF;
+ public static Typeface SERIF;
/** The NORMAL style of the default monospace typeface. */
- public static final Typeface MONOSPACE;
+ public static Typeface MONOSPACE;
static Typeface[] sDefaults;
@@ -99,9 +100,9 @@ public class Typeface {
* Cache for Typeface objects for style variant. Currently max size is 3.
*/
@GuardedBy("sStyledCacheLock")
- private static final LongSparseArray<SparseArray<Typeface>> sStyledTypefaceCache =
+ private static LongSparseArray<SparseArray<Typeface>> sStyledTypefaceCache =
new LongSparseArray<>(3);
- private static final Object sStyledCacheLock = new Object();
+ private static Object sStyledCacheLock = new Object();
/**
* Cache for Typeface objects for weight variant. Currently max size is 3.
@@ -119,9 +120,14 @@ public class Typeface {
private static final Object sDynamicCacheLock = new Object();
static Typeface sDefaultTypeface;
- static final Map<String, Typeface> sSystemFontMap;
+ static Map<String, Typeface> sSystemFontMap;
+ static FontFamily[] sFallbackFonts;
static final Map<String, FontFamily[]> sSystemFallbackMap;
+ static final String FONTS_CONFIG = "fonts.xml";
+
+ static final String SANS_SERIF_FAMILY_NAME = "sans-serif";
+
/**
* @hide
*/
@@ -152,8 +158,8 @@ public class Typeface {
// Value for weight and italic. Indicates the value is resolved by font metadata.
// Must be the same as the C++ constant in core/jni/android/graphics/FontFamily.cpp
/** @hide */
- public static final int RESOLVE_BY_FONT_TABLE = -1;
- private static final String DEFAULT_FAMILY = "sans-serif";
+ public static int RESOLVE_BY_FONT_TABLE = -1;
+ private static String DEFAULT_FAMILY = "sans-serif";
// Style value for building typeface.
private static final int STYLE_NORMAL = 0;
@@ -162,6 +168,12 @@ public class Typeface {
private int[] mSupportedAxes;
private static final int[] EMPTY_AXES = {};
+ private static Typeface DEFAULT_INTERNAL;
+ private static Typeface DEFAULT_BOLD_INTERNAL;
+ private static Typeface SANS_SERIF_INTERNAL;
+ private static Typeface SERIF_INTERNAL;
+ private static Typeface MONOSPACE_INTERNAL;
+
private static void setDefault(Typeface t) {
sDefaultTypeface = t;
nativeSetDefault(t.native_instance);
@@ -896,17 +908,26 @@ public class Typeface {
for (int i = 0; i < families.length; i++) {
ptrArray[i] = families[i].mNativePtr;
}
- return new Typeface(nativeCreateFromArray(
+ Typeface typeface = new Typeface(nativeCreateFromArray(
ptrArray, RESOLVE_BY_FONT_TABLE, RESOLVE_BY_FONT_TABLE));
+ return typeface;
}
/**
* This method is used by supportlib-v27.
* TODO: Remove private API use in supportlib: http://b/72665240
*/
- private static Typeface createFromFamiliesWithDefault(FontFamily[] families, int weight,
- int italic) {
- return createFromFamiliesWithDefault(families, DEFAULT_FAMILY, weight, italic);
+ private static Typeface createFromFamiliesWithDefault(FontFamily[] families,
+ int weight, int italic) {
+ long[] ptrArray = new long[families.length + sFallbackFonts.length];
+ for (int i = 0; i < families.length; i++) {
+ ptrArray[i] = families[i].mNativePtr;
+ }
+ for (int i = 0; i < sFallbackFonts.length; i++) {
+ ptrArray[i + families.length] = sFallbackFonts[i].mNativePtr;
+ }
+ Typeface typeface = new Typeface(nativeCreateFromArray(ptrArray, weight, italic));
+ return typeface;
}
/**
@@ -950,6 +971,37 @@ public class Typeface {
mWeight = nativeGetWeight(ni);
}
+ private static FontFamily makeFamilyFromParsed(FontConfig.Family family,
+ Map<String, ByteBuffer> bufferForPath) {
+ FontFamily fontFamily = new FontFamily(family.getLanguages(), family.getVariant());
+ for (FontConfig.Font font : family.getFonts()) {
+ String fullPathName = font.getFontName();
+ ByteBuffer fontBuffer = bufferForPath.get(fullPathName);
+ if (fontBuffer == null) {
+ try (FileInputStream file = new FileInputStream(fullPathName)) {
+ FileChannel fileChannel = file.getChannel();
+ long fontSize = fileChannel.size();
+ fontBuffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, fontSize);
+ bufferForPath.put(fullPathName, fontBuffer);
+ } catch (IOException e) {
+ Log.e(TAG, "Error mapping font file " + fullPathName);
+ continue;
+ }
+ }
+ if (!fontFamily.addFontFromBuffer(fontBuffer, font.getTtcIndex(), font.getAxes(),
+ font.getWeight(), font.isItalic() ? STYLE_ITALIC : STYLE_NORMAL)) {
+ Log.e(TAG, "Error creating font " + fullPathName + "#" + font.getTtcIndex());
+ }
+ }
+ if (!fontFamily.freeze()) {
+ // Treat as system error since reaching here means that a system pre-installed font
+ // can't be used by our font stack.
+ Log.e(TAG, "Unable to load Family: " + family.getName() + ":" + family.getLanguages());
+ return null;
+ }
+ return fontFamily;
+ }
+
private static @Nullable ByteBuffer mmap(String fullPath) {
try (FileInputStream file = new FileInputStream(fullPath)) {
final FileChannel fileChannel = file.getChannel();
@@ -967,7 +1019,7 @@ public class Typeface {
final FontFamily family = new FontFamily(languageTags, variant);
for (int i = 0; i < fonts.size(); i++) {
final FontConfig.Font font = fonts.get(i);
- final String fullPath = fontDir + font.getFontName();
+ final String fullPath = font.getFontName();
ByteBuffer buffer = cache.get(fullPath);
if (buffer == null) {
if (cache.containsKey(fullPath)) {
@@ -1057,11 +1109,11 @@ public class Typeface {
public static void buildSystemFallback(String xmlPath, String fontDir,
ArrayMap<String, Typeface> fontMap, ArrayMap<String, FontFamily[]> fallbackMap) {
try {
- final FileInputStream fontsIn = new FileInputStream(xmlPath);
- final FontConfig fontConfig = FontListParser.parse(fontsIn);
+ final InputStream xmlFile = new FileInputStream(xmlPath);
+ final FontConfig fontConfig = FontListParser.parse(xmlFile, fontDir);
final HashMap<String, ByteBuffer> bufferCache = new HashMap<String, ByteBuffer>();
- final FontConfig.Family[] xmlFamilies = fontConfig.getFamilies();
+ final List<FontConfig.Family> xmlFamilies = fontConfig.getFamilies();
final ArrayMap<String, ArrayList<FontFamily>> fallbackListMap = new ArrayMap<>();
// First traverse families which have a 'name' attribute to create fallback map.
@@ -1082,8 +1134,8 @@ public class Typeface {
}
// Then, add fallback fonts to the each fallback map.
- for (int i = 0; i < xmlFamilies.length; i++) {
- final FontConfig.Family xmlFamily = xmlFamilies[i];
+ for (int i = 0; i < xmlFamilies.size(); i++) {
+ final FontConfig.Family xmlFamily = xmlFamilies.get(i);
// The first family (usually the sans-serif family) is always placed immediately
// after the primary family in the fallback.
if (i == 0 || xmlFamily.getName() == null) {
@@ -1128,16 +1180,200 @@ public class Typeface {
}
}
+ private static void addFallbackFontsForFamilyName(FontConfig src,
+ FontConfig dst, String familyName) {
+ for (Family srcFamily : src.getFamilies()) {
+ if (familyName.equals(srcFamily.getName())) {
+ // set the name to null so that it will be added as a fallback
+ srcFamily.clearName();
+ dst.getFamilies().add(srcFamily);
+ return;
+ }
+ }
+ }
+
+ /**
+ * Adds any font families in src that do not exist in dst
+ * @param src Source font config
+ * @param dst Destination font config
+ */
+ private static void addMissingFontFamilies(FontConfig src,
+ FontConfig dst) {
+ final int N = dst.getFamilies().size();
+ // add missing families
+ for (Family srcFamily : src.getFamilies()) {
+ boolean addFamily = true;
+ for (int i = 0; i < N && addFamily; i++) {
+ final Family dstFamily = dst.getFamilies().get(i);
+ final String dstFamilyName = dstFamily.getName();
+ if (dstFamilyName != null && dstFamilyName.equals(srcFamily.getName())) {
+ addFamily = false;
+ break;
+ }
+ }
+ if (addFamily) {
+ dst.getFamilies().add(srcFamily);
+ }
+ }
+ }
+
+ /**
+ * Adds any aliases in src that do not exist in dst
+ * @param src Source font config
+ * @param dst Destination font config
+ */
+ private static void addMissingFontAliases(FontConfig src,
+ FontConfig dst) {
+ final int N = dst.getAliases().size();
+ // add missing aliases
+ for (FontConfig.Alias alias : src.getAliases()) {
+ boolean addAlias = true;
+ for (int i = 0; i < N && addAlias; i++) {
+ final String dstAliasName = dst.getAliases().get(i).getName();
+ if (dstAliasName != null && dstAliasName.equals(alias.getName())) {
+ addAlias = false;
+ break;
+ }
+ }
+ if (addAlias) {
+ dst.getAliases().add(alias);
+ }
+ }