| | | |
Offset 1, 56 lines modified | Offset 1, 59 lines modified |
| |
1 | package·com.android.textclassifier; | 1 | package·com.android.textclassifier.common; |
| |
2 | import·java.util.Iterator; | 2 | import·java.util.Iterator; |
| 3 | import·com.google.common.collect.ImmutableList$Builder; |
3 | import·java.util.Arrays; | 4 | import·java.util.Arrays; |
4 | import·java.util.Locale; | 5 | import·java.util.Locale; |
5 | import·android.os.LocaleList; | 6 | import·android.os.LocaleList; |
6 | import·com.google.common.collect.UnmodifiableIterator; | 7 | import·com.google.common.collect.UnmodifiableIterator; |
7 | import·com.android.textclassifier.common.ModelType; | |
8 | import·com.android.textclassifier.utils.IndentingPrintWriter; | 8 | import·com.android.textclassifier.utils.IndentingPrintWriter; |
9 | import·com.google.common.collect.ImmutableList$Builder; | |
10 | import·com.android.textclassifier.downloader.ModelDownloadManager; | |
11 | import·java.util.Collection; | 9 | import·java.util.Collection; |
12 | import·java.util.List; | |
13 | import·android.content.res.AssetManager; | 10 | import·android.content.res.AssetManager; |
| 11 | import·com.google.common.collect.ImmutableList; |
14 | import·com.google.common.base.Supplier; | 12 | import·com.google.common.base.Supplier; |
15 | import·java.util.Objects; | 13 | import·java.util.Objects; |
16 | import·com.android.textclassifier.common.TextClassifierSettings; | |
17 | import·android.content.Context; | 14 | import·android.content.Context; |
18 | import·com.google.common.collect.ImmutableList; | 15 | import·java.util.List; |
19 | import·java.io.File; | 16 | import·java.io.File; |
| |
20 | public·final·class·ModelFileManager | 17 | public·final·class·ModelFileManager |
21 | { | 18 | { |
22 | ····private·static·final·File·CONFIG_UPDATER_DIR; | 19 | ····private·static·final·File·CONFIG_UPDATER_DIR; |
23 | ····private·ImmutableList·modelFileListers; | 20 | ····private·final·List·modelFileListers; |
24 | ···· | 21 | ···· |
25 | ····static·{ | 22 | ····static·{ |
26 | ········CONFIG_UPDATER_DIR·=·new·File("/data/misc/textclassifier/"); | 23 | ········CONFIG_UPDATER_DIR·=·new·File("/data/misc/textclassifier/"); |
27 | ····} | 24 | ····} |
28 | ···· | 25 | ···· |
29 | ····public·ModelFileManager(final·Context·obj,·final·TextClassifierSettings·obj2)·{ | 26 | ····public·ModelFileManager(final·Context·obj,·final·TextClassifierSettings·obj2)·{ |
30 | ········Objects.requireNonNull(obj); | 27 | ········Objects.requireNonNull(obj); |
31 | ········Objects.requireNonNull(obj2); | 28 | ········Objects.requireNonNull(obj2); |
32 | ········final·AssetManager·assets·=·obj.getAssets(); | 29 | ········final·AssetManager·assets·=·obj.getAssets(); |
| 30 | ········final·File·file·=·new·File(obj.getFilesDir(),·"textclassifier/downloads/models/"); |
| 31 | ········final·ModelFileManager$$ExternalSyntheticLambda0·modelFileManager$$ExternalSyntheticLambda0·=·new·ModelFileManager$$ExternalSyntheticLambda0(obj2,·0); |
| 32 | ········final·String·s·=·"annotator"; |
| 33 | ········final·ModelFileManager$RegularFilePatternMatchLister·modelFileManager$RegularFilePatternMatchLister·=·new·ModelFileManager$RegularFilePatternMatchLister(s,·file,·"annotator\\.(.*)\\.model",·(Supplier)modelFileManager$$ExternalSyntheticLambda0); |
33 | ········final·File·config_UPDATER_DIR·=·ModelFileManager.CONFIG_UPDATER_DIR; | 34 | ········final·File·config_UPDATER_DIR·=·ModelFileManager.CONFIG_UPDATER_DIR; |
34 | ········this.modelFileListers·=·ImmutableList.of((Object)new·ModelFileManager$RegularFileFullMatchLister("annotator",·new·File(config_UPDATER_DIR,·"textclassifier.model"),·(Supplier)ModelFileManager$$ExternalSyntheticLambda1.INSTANCE),·(Object)new·ModelFileManager$AssetFilePatternMatchLister(assets,·"annotator",·"textclassifier",·"annotator\\.(.*)\\.model",·(Supplier)ModelFileManager$$ExternalSyntheticLambda1.INSTANCE$com$android$textclassifier$ModelFileManager$$InternalSyntheticLambda$0$e4c34939fcd29e34f05d4d76a3a7f6e0e1f6e6772b8219f6e11ffc0de333b42d$1),·(Object)new·ModelFileManager$RegularFileFullMatchLister("actions_suggestions",·new·File(config_UPDATER_DIR,·"actions_suggestions.model"),·(Supplier)ModelFileManager$$ExternalSyntheticLambda1.INSTANCE$com$android$textclassifier$ModelFileManager$$InternalSyntheticLambda$0$e4c34939fcd29e34f05d4d76a3a7f6e0e1f6e6772b8219f6e11ffc0de333b42d$2),·(Object)new·ModelFileManager$AssetFilePatternMatchLister(assets,·"actions_suggestions",·"textclassifier",·"actions_suggestions\\.([·...·truncated·by·diffoscope;·len:·843,·SHA:·6221d587e2e6f625bbb41cb05a82aefe6eb036af3910d9ff81ad90c565cd460b·...·]); | 35 | ········final·ModelFileManager$RegularFileFullMatchLister·modelFileManager$RegularFileFullMatchLister·=·new·ModelFileManager$RegularFileFullMatchLister(s,·new·File(config_UPDATER_DIR,·"textclassifier.model"),·(Supplier)ModelFileManager$$ExternalSyntheticLambda1.INSTANCE); |
| 36 | ········final·ModelFileManager$AssetFilePatternMatchLister·modelFileManager$AssetFilePatternMatchLister·=·new·ModelFileManager$AssetFilePatternMatchLister(assets,·"annotator",·"textclassifier",·"annotator\\.(.*)\\.model",·(Supplier)ModelFileManager$$ExternalSyntheticLambda1.INSTANCE$com$android$textclassifier$common$ModelFileManager$$InternalSyntheticLambda$0$1c7e7c3032d1ec6edd7b6fdf660f74197c48510ed1a7487232b5b7130d777c16$2); |
| 37 | ········final·ModelFileManager$$ExternalSyntheticLambda0·modelFileManager$$ExternalSyntheticLambda2·=·new·ModelFileManager$$ExternalSyntheticLambda0(obj2,·2); |
| 38 | ········final·String·s2·=·"actions_suggestions"; |
| 39 | ········final·ModelFileManager$RegularFilePatternMatchLister·modelFileManager$RegularFilePatternMatchLister2·=·new·ModelFileManager$RegularFilePatternMatchLister(s2,·file,·"actions_suggestions\\.(.*)\\.model",·(Supplier)modelFileManager$$ExternalSyntheticLambda2); |
| 40 | ········final·ModelFileManager$RegularFileFullMatchLister·modelFileManager$RegularFileFullMatchLister2·=·new·ModelFileManager$RegularFileFullMatchLister(s2,·new·File(config_UPDATER_DIR,·"actions_suggestions.model"),·(Supplier)ModelFileManager$$ExternalSyntheticLambda1.INSTANCE$com$android$textclassifier$common$ModelFileManager$$InternalSyntheticLambda$0$1c7e7c3032d1ec6edd7b6fdf660f74197c48510ed1a7487232b5b7130d777c16$4); |
| 41 | ········final·ModelFileManager$AssetFilePatternMatchLister·modelFileManager$AssetFilePatternMatchLister2·=·new·ModelFileManager$AssetFilePatternMatchLister(assets,·"actions_suggestions",·"textclassifier",·"actions_suggestions\\.(.*)\\.model",·(Supplier)ModelFileManager$$ExternalSyntheticLambda1.INSTANCE$com$android$textclassifier$common$ModelFileManager$$InternalSyntheticLambda$0$1c7e7c3032d1ec6edd7b6fdf660f74197c48510ed1a7487232b5b7130d777c16$5); |
| 42 | ········final·ModelFileManager$$ExternalSyntheticLambda0·modelFileManager$$ExternalSyntheticLambda3·=·new·ModelFileManager$$ExternalSyntheticLambda0(obj2,·3); |
| 43 | ········final·String·s3·=·"lang_id"; |
| 44 | ········this.modelFileListers·=·(List)ImmutableList.of((Object)modelFileManager$RegularFilePatternMatchLister,·(Object)modelFileManager$RegularFileFullMatchLister,·(Object)modelFileManager$AssetFilePatternMatchLister,·(Object)modelFileManager$RegularFilePatternMatchLister2,·(Object)modelFileManager$RegularFileFullMatchLister2,·(Object)modelFileManager$AssetFilePatternMatchLister2,·(Object)new·ModelFileManager$RegularFilePatternMatchLister(s3,·file,·"lang_id\\.(.*)\\.model",·(Supplier)modelFileManager$$ExternalSyntheticLambda3),·(Object)new·ModelFileManager$RegularFileFullMatchLister(s3,·new·File(config_UPDATER_DIR,·"lang_id.model"),·(Supplier)ModelFileManager$$ExternalSyntheticLambda1.INSTANCE$com$android$textclassifier$common$ModelFileManager$$InternalSyntheticLambda$0$1c7e7c3032d1ec6edd7b6fdf660f74197c48510ed1a7487232b5b7130d777c16$7),·(Object)new·ModelFileManager$AssetFilePatternMatchLister(assets,·"lang_id",·"textclassifier",·"lang_id.model",·(Supplier)ModelFileManager$$ExternalSyntheticLambda1.INSTANCE$com$android$textclassifier$common$ModelFileManager$$InternalSyntheticLambda$0$1c7e7c3032d1ec6edd7b6fdf660f74197c48510ed1a7487232b5b7130d777c16$8)); |
35 | ····} | 45 | ····} |
36 | ···· | 46 | ···· |
37 | ····public·ModelFileManager(final·Context·context,·final·List·list)·{ | 47 | ····public·ModelFileManager(final·Context·context,·final·List·list)·{ |
| 48 | ········new·File(context.getFilesDir(),·"textclassifier/downloads/models/"); |
38 | ········this.modelFileListers·=·ImmutableList.copyOf((Collection)list); | 49 | ········this.modelFileListers·=·(List)ImmutableList.copyOf((Collection)list); |
39 | ····} | |
40 | ···· | |
41 | ····public·void·addModelDownloaderModels(final·ModelDownloadManager·modelDownloadManager,·final·TextClassifierSettings·textClassifierSettings)·{ | |
42 | ········final·int·$r8$clinit·=·ImmutableList.$r8$clinit; | |
43 | ········final·ImmutableList$Builder·immutableList$Builder·=·new·ImmutableList$Builder(); | |
44 | ········immutableList$Builder.addAll((Iterable)this.modelFileListers); | |
45 | ········immutableList$Builder.add((Object)new·ModelFileManager$$ExternalSyntheticLambda0(textClassifierSettings,·modelDownloadManager)); | |
46 | ········this.modelFileListers·=·immutableList$Builder.build(); | |
47 | ····} | 50 | ····} |
48 | ···· | 51 | ···· |
49 | ····public·void·dump(final·IndentingPrintWriter·indentingPrintWriter)·{ | 52 | ····public·void·dump(final·IndentingPrintWriter·indentingPrintWriter)·{ |
50 | ········indentingPrintWriter.println("ModelFileManager:"); | 53 | ········indentingPrintWriter.println("ModelFileManager:"); |
51 | ········indentingPrintWriter.increaseIndent(); | 54 | ········indentingPrintWriter.increaseIndent(); |
52 | ········for·(final·String·str·:·ModelType.VALUES)·{ | 55 | ········for·(final·String·str·:·ModelType.VALUES)·{ |
53 | ············final·StringBuilder·sb·=·new·StringBuilder(); | 56 | ············final·StringBuilder·sb·=·new·StringBuilder(); |
Offset 64, 74 lines modified | Offset 67, 66 lines modified |
64 | ············} | 67 | ············} |
65 | ············indentingPrintWriter.decreaseIndent(); | 68 | ············indentingPrintWriter.decreaseIndent(); |
66 | ········} | 69 | ········} |
67 | ········indentingPrintWriter.decreaseIndent(); | 70 | ········indentingPrintWriter.decreaseIndent(); |
68 | ····} | 71 | ····} |
69 | ···· | 72 | ···· |
70 | ····public·ModelFileManager$ModelFile·findBestModelFile(final·String·s,·final·LocaleList·list)·{ | 73 | ····public·ModelFileManager$ModelFile·findBestModelFile(final·String·s,·final·LocaleList·list)·{ |
71 | ········Locale·locale; | |
72 | ········if·(list·!=·null)·{ | |
73 | ············locale·=·list.get(0); | 74 | ········String·ranges; |
| 75 | ········if·(list·!=·null·&&·!list.isEmpty())·{ |
| 76 | ············ranges·=·list.toLanguageTags(); |
74 | ········} | 77 | ········} |
75 | ········else·{ | 78 | ········else·{ |
76 | ············locale·=·Locale.getDefault(); | 79 | ············ranges·=·LocaleList.getDefault().toLanguageTags(); |
77 | ········} | 80 | ········} |
78 | ········final·String·lookupTag·=·Locale.lookupTag(Locale.LanguageRange.parse(LocaleList.getDefault().toLanguageTags()),·(Collection<String>)ImmutableList.of((Object)locale.getLanguage())); | |
79 | ········final·boolean·b·=·true; | |
80 | ········final·boolean·b2·=·lookupTag·==·null·&&·b; | |
81 | ········final·List<Locale.LanguageRange>·parse·=·Locale.LanguageRange.parse(locale.toLanguageTag()); | 81 | ········final·List<Locale.LanguageRange>·parse·=·Locale.LanguageRange.parse(ranges); |
82 | ········ModelFileManager$ModelFile·modelFileManager$ModelFile·=·null; | 82 | ········ModelFileManager$ModelFile·modelFileManager$ModelFile·=·null; |
83 | ········for·(final·ModelFileManager$ModelFile·obj·:·this.listModelFiles(s))·{ | 83 | ········for·(final·ModelFileManager$ModelFile·obj·:·this.listModelFiles(s))·{ |
84 | ············if·(b2·&&·!obj.languageIndependent)·{ | |
85 | ················continue; | |
86 | ············} | |
87 | ············Objects.requireNonNull(obj); | 84 | ············Objects.requireNonNull(obj); |
88 | ············Objects.requireNonNull(parse); | 85 | ············Objects.requireNonNull(parse); |
| 86 | ············final·boolean·languageIndependent·=·obj.languageIndependent; |
| 87 | ············boolean·b·=·false; |
| 88 | ············final·boolean·b2·=·true; |
89 | ············boolean·b3·=·false; | 89 | ············boolean·b3·=·false; |
90 | ············Label_0199:·{ | 90 | ············Label_0154:·{ |
91 | ················if·(!obj.languageIndependent)·{ | 91 | ················if·(!languageIndependent)·{ |
92 | ····················if·(Locale.lookupTag(parse,·Arrays.asList(obj.supportedLocales.toLanguageTags().split(",")))·==·null)·{ | 92 | ····················if·(Locale.lookupTag(parse,·Arrays.asList(obj.supportedLocales.toLanguageTags().split(",")))·==·null)·{ |
93 | ························b3·=·false; | 93 | ························b3·=·false; |
94 | ························break·Label_0199; | 94 | ························break·Label_0154; |
95 | ····················} | 95 | ····················} |
96 | ················} | 96 | ················} |
97 | ················b3·=·b; | 97 | ················b3·=·b2; |
98 | ············} | |
99 | ············if·(!b3)·{ | |
100 | ················continue; | |
101 | ············} | 98 | ············} |
| 99 | ············if·(b3)·{ |
102 | ············boolean·b4·=·false; | |
103 | ············Label_0291:·{ | |
104 | ················Label_0278:·{ | 100 | ················Label_0237:·{ |
105 | ····················if·(modelFileManager$ModelFile·!=·null)·{ | 101 | ····················if·(modelFileManager$ModelFile·!=·null)·{ |
106 | ························final·boolean·languageIndependent·=·obj.languageIndependent; | 102 | ························final·boolean·languageIndependent2·=·obj.languageIndependent; |
107 | ························if·(languageIndependent·||·!modelFileManager$ModelFile.languageIndependent)·{ | 103 | ························if·(languageIndependent2·||·!modelFileManager$ModelFile.languageIndependent)·{ |
108 | ····························if·(!languageIndependent·||·modelFileManager$ModelFile.languageIndependent)·{ | 104 | ····························if·(languageIndependent2·&&·!modelFileManager$ModelFile.languageIndependent)·{ |
| 105 | ································break·Label_0237; |
| 106 | ····························} |
109 | ································if·(obj.version·>·modelFileManager$ModelFile.version)·{ | 107 | ····························if·(obj.version·<=·modelFileManager$ModelFile.version)·{ |
110 | ····································break·Label_0278; | 108 | ································break·Label_0237; |
111 | ································} | |
112 | ····························} | 109 | ····························} |
113 | ····························b4·=·false; | |
114 | ····························break·Label_0291; | |
115 | ························} | 110 | ························} |
116 | ····················} | 111 | ····················} |
| 112 | ····················b·=·b2; |
117 | ················} | 113 | ················} |
118 | ················b4·=·b; | |
119 | ············} | |
120 | ············if·(!b4)·{ | 114 | ················if·(!b)·{ |
121 | ················continue; | 115 | ····················continue; |
| 116 | ················} |
| 117 | ················modelFileManager$ModelFile·=·obj; |
122 | ············} | 118 | ············} |
123 | ············modelFileManager$ModelFile·=·obj; | |
124 | ········} | 119 | ········} |
125 | ········return·modelFileManager$ModelFile; | 120 | ········return·modelFileManager$ModelFile; |
126 | ····} | 121 | ····} |
127 | ···· | 122 | ···· |
128 | ····public·ImmutableList·listModelFiles(final·String·obj)·{ | 123 | ····public·ImmutableList·listModelFiles(final·String·obj)·{ |
129 | ········Objects.requireNonNull(obj); | 124 | ········Objects.requireNonNull(obj); |
130 | ········final·ImmutableList$Builder·immutableList$Builder·=·new·ImmutableList$Builder(); | 125 | ········final·ImmutableList$Builder·immutableList$Builder·=·new·ImmutableList$Builder(); |
131 | ········final·UnmodifiableIterator·iterator·=·this.modelFileListers.iterator(); | 126 | ········final·Iterator<ModelFileManager$ModelFileLister>·iterator·=·this.modelFileListers.iterator(); |
132 | ········while·(((Iterator)iterator).hasNext())·{ | 127 | ········while·(iterator.hasNext())·{ |
133 | ············immutableList$Builder.addAll((Iterable)((ModelFileManager$ModelFileLister)((Iterator<ModelFileManager$ModelFileLister>)iterator).next()).list(obj)); | 128 | ············immutableList$Builder.addAll((Iterable)((ModelFileManager$ModelFileLister)iterator.next()).list(obj)); |
134 | ········} | 129 | ········} |
135 | ········return·immutableList$Builder.build(); | 130 | ········return·immutableList$Builder.build(); |
136 | ····} | 131 | ····} |
137 | } | 132 | } |