5package io.flutter.embedding.engine.loader;
8import android.content.pm.ApplicationInfo;
9import android.content.pm.PackageManager;
10import android.content.res.XmlResourceParser;
12import androidx.annotation.NonNull;
13import java.io.IOException;
14import org.json.JSONArray;
15import org.xmlpull.v1.XmlPullParserException;
33 private static ApplicationInfo getApplicationInfo(@NonNull Context applicationContext) {
35 return applicationContext
37 .getApplicationInfo(applicationContext.getPackageName(), PackageManager.GET_META_DATA);
38 }
catch (PackageManager.NameNotFoundException
e) {
39 throw new RuntimeException(
e);
43 private static String getString(Bundle metadata, String
key) {
44 if (metadata ==
null) {
47 return metadata.getString(
key,
null);
50 private static boolean getBoolean(Bundle metadata, String
key,
boolean defaultValue) {
51 if (metadata ==
null) {
54 return metadata.getBoolean(
key, defaultValue);
57 private static String getNetworkPolicy(ApplicationInfo appInfo, Context context) {
62 Bundle metadata = appInfo.metaData;
63 if (metadata ==
null) {
68 if (networkSecurityConfigRes <= 0) {
72 JSONArray
output =
new JSONArray();
74 XmlResourceParser xrp = context.getResources().getXml(networkSecurityConfigRes);
76 int eventType = xrp.getEventType();
77 while (eventType != XmlResourceParser.END_DOCUMENT) {
78 if (eventType == XmlResourceParser.START_TAG) {
79 if (xrp.getName().equals(
"domain-config")) {
80 parseDomainConfig(xrp,
output,
false);
83 eventType = xrp.next();
85 }
catch (IOException | XmlPullParserException
e) {
91 private static void parseDomainConfig(
92 XmlResourceParser xrp, JSONArray
output,
boolean inheritedCleartextPermitted)
93 throws IOException, XmlPullParserException {
94 boolean cleartextTrafficPermitted =
95 xrp.getAttributeBooleanValue(
96 null,
"cleartextTrafficPermitted", inheritedCleartextPermitted);
98 int eventType = xrp.next();
99 if (eventType == XmlResourceParser.START_TAG) {
100 if (xrp.getName().equals(
"domain")) {
102 parseDomain(xrp,
output, cleartextTrafficPermitted);
103 }
else if (xrp.getName().equals(
"domain-config")) {
104 parseDomainConfig(xrp,
output, cleartextTrafficPermitted);
108 }
else if (eventType == XmlResourceParser.END_TAG) {
114 private static void skipTag(XmlResourceParser xrp)
throws IOException, XmlPullParserException {
115 String
name = xrp.getName();
116 int eventType = xrp.getEventType();
117 while (eventType != XmlResourceParser.END_TAG || xrp.getName() !=
name) {
118 eventType = xrp.next();
122 private static void parseDomain(
123 XmlResourceParser xrp, JSONArray
output,
boolean cleartextPermitted)
124 throws IOException, XmlPullParserException {
125 boolean includeSubDomains = xrp.getAttributeBooleanValue(
null,
"includeSubdomains",
false);
127 if (xrp.getEventType() != XmlResourceParser.TEXT) {
128 throw new IllegalStateException(
"Expected text");
130 String domain = xrp.getText().trim();
131 JSONArray outputArray =
new JSONArray();
132 outputArray.put(domain);
133 outputArray.put(includeSubDomains);
134 outputArray.put(cleartextPermitted);
137 if (xrp.getEventType() != XmlResourceParser.END_TAG) {
138 throw new IllegalStateException(
"Expected end of domain tag");
148 ApplicationInfo appInfo = getApplicationInfo(applicationContext);
154 getNetworkPolicy(appInfo, applicationContext),
155 appInfo.nativeLibraryDir,
static final String PUBLIC_AUTOMATICALLY_REGISTER_PLUGINS_METADATA_KEY
static final String PUBLIC_AOT_SHARED_LIBRARY_NAME
static final String PUBLIC_VM_SNAPSHOT_DATA_KEY
static final String PUBLIC_FLUTTER_ASSETS_DIR_KEY
static final String PUBLIC_ISOLATE_SNAPSHOT_DATA_KEY
static final String NETWORK_POLICY_METADATA_KEY
static FlutterApplicationInfo load(@NonNull Context applicationContext)
static final String VM_SNAPSHOT_DATA_KEY
static final String ISOLATE_SNAPSHOT_DATA_KEY
static final String AOT_SHARED_LIBRARY_NAME
static final String AUTOMATICALLY_REGISTER_PLUGINS_KEY
static final String FLUTTER_ASSETS_DIR_KEY
DEF_SWITCHES_START aot vmservice shared library name