@capacitor-plus/android 8.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/LICENSE +21 -0
  2. package/capacitor/build.gradle +94 -0
  3. package/capacitor/lint-baseline.xml +136 -0
  4. package/capacitor/lint.xml +9 -0
  5. package/capacitor/proguard-rules.pro +28 -0
  6. package/capacitor/src/main/AndroidManifest.xml +3 -0
  7. package/capacitor/src/main/assets/native-bridge.js +1029 -0
  8. package/capacitor/src/main/java/com/getcapacitor/AndroidProtocolHandler.java +94 -0
  9. package/capacitor/src/main/java/com/getcapacitor/App.java +61 -0
  10. package/capacitor/src/main/java/com/getcapacitor/AppUUID.java +65 -0
  11. package/capacitor/src/main/java/com/getcapacitor/Bridge.java +1627 -0
  12. package/capacitor/src/main/java/com/getcapacitor/BridgeActivity.java +212 -0
  13. package/capacitor/src/main/java/com/getcapacitor/BridgeWebChromeClient.java +467 -0
  14. package/capacitor/src/main/java/com/getcapacitor/BridgeWebViewClient.java +105 -0
  15. package/capacitor/src/main/java/com/getcapacitor/CapConfig.java +709 -0
  16. package/capacitor/src/main/java/com/getcapacitor/CapacitorWebView.java +57 -0
  17. package/capacitor/src/main/java/com/getcapacitor/FileUtils.java +303 -0
  18. package/capacitor/src/main/java/com/getcapacitor/InvalidPluginException.java +8 -0
  19. package/capacitor/src/main/java/com/getcapacitor/InvalidPluginMethodException.java +16 -0
  20. package/capacitor/src/main/java/com/getcapacitor/JSArray.java +51 -0
  21. package/capacitor/src/main/java/com/getcapacitor/JSExport.java +208 -0
  22. package/capacitor/src/main/java/com/getcapacitor/JSExportException.java +16 -0
  23. package/capacitor/src/main/java/com/getcapacitor/JSInjector.java +127 -0
  24. package/capacitor/src/main/java/com/getcapacitor/JSObject.java +164 -0
  25. package/capacitor/src/main/java/com/getcapacitor/JSValue.java +65 -0
  26. package/capacitor/src/main/java/com/getcapacitor/Logger.java +103 -0
  27. package/capacitor/src/main/java/com/getcapacitor/MessageHandler.java +157 -0
  28. package/capacitor/src/main/java/com/getcapacitor/NativePlugin.java +37 -0
  29. package/capacitor/src/main/java/com/getcapacitor/PermissionState.java +31 -0
  30. package/capacitor/src/main/java/com/getcapacitor/Plugin.java +1050 -0
  31. package/capacitor/src/main/java/com/getcapacitor/PluginCall.java +394 -0
  32. package/capacitor/src/main/java/com/getcapacitor/PluginConfig.java +116 -0
  33. package/capacitor/src/main/java/com/getcapacitor/PluginHandle.java +160 -0
  34. package/capacitor/src/main/java/com/getcapacitor/PluginInvocationException.java +16 -0
  35. package/capacitor/src/main/java/com/getcapacitor/PluginLoadException.java +19 -0
  36. package/capacitor/src/main/java/com/getcapacitor/PluginManager.java +56 -0
  37. package/capacitor/src/main/java/com/getcapacitor/PluginMethod.java +15 -0
  38. package/capacitor/src/main/java/com/getcapacitor/PluginMethodHandle.java +33 -0
  39. package/capacitor/src/main/java/com/getcapacitor/PluginResult.java +84 -0
  40. package/capacitor/src/main/java/com/getcapacitor/ProcessedRoute.java +37 -0
  41. package/capacitor/src/main/java/com/getcapacitor/RouteProcessor.java +8 -0
  42. package/capacitor/src/main/java/com/getcapacitor/ServerPath.java +25 -0
  43. package/capacitor/src/main/java/com/getcapacitor/UriMatcher.java +184 -0
  44. package/capacitor/src/main/java/com/getcapacitor/WebViewListener.java +57 -0
  45. package/capacitor/src/main/java/com/getcapacitor/WebViewLocalServer.java +758 -0
  46. package/capacitor/src/main/java/com/getcapacitor/annotation/ActivityCallback.java +10 -0
  47. package/capacitor/src/main/java/com/getcapacitor/annotation/CapacitorPlugin.java +35 -0
  48. package/capacitor/src/main/java/com/getcapacitor/annotation/Permission.java +22 -0
  49. package/capacitor/src/main/java/com/getcapacitor/annotation/PermissionCallback.java +10 -0
  50. package/capacitor/src/main/java/com/getcapacitor/cordova/CapacitorCordovaCookieManager.java +42 -0
  51. package/capacitor/src/main/java/com/getcapacitor/cordova/MockCordovaInterfaceImpl.java +39 -0
  52. package/capacitor/src/main/java/com/getcapacitor/cordova/MockCordovaWebViewImpl.java +282 -0
  53. package/capacitor/src/main/java/com/getcapacitor/plugin/CapacitorCookieManager.java +239 -0
  54. package/capacitor/src/main/java/com/getcapacitor/plugin/CapacitorCookies.java +119 -0
  55. package/capacitor/src/main/java/com/getcapacitor/plugin/CapacitorHttp.java +119 -0
  56. package/capacitor/src/main/java/com/getcapacitor/plugin/SystemBars.java +220 -0
  57. package/capacitor/src/main/java/com/getcapacitor/plugin/WebView.java +48 -0
  58. package/capacitor/src/main/java/com/getcapacitor/plugin/util/AssetUtil.java +358 -0
  59. package/capacitor/src/main/java/com/getcapacitor/plugin/util/CapacitorHttpUrlConnection.java +473 -0
  60. package/capacitor/src/main/java/com/getcapacitor/plugin/util/HttpRequestHandler.java +465 -0
  61. package/capacitor/src/main/java/com/getcapacitor/plugin/util/ICapacitorHttpUrlConnection.java +15 -0
  62. package/capacitor/src/main/java/com/getcapacitor/plugin/util/MimeType.java +17 -0
  63. package/capacitor/src/main/java/com/getcapacitor/util/HostMask.java +123 -0
  64. package/capacitor/src/main/java/com/getcapacitor/util/InternalUtils.java +27 -0
  65. package/capacitor/src/main/java/com/getcapacitor/util/JSONUtils.java +166 -0
  66. package/capacitor/src/main/java/com/getcapacitor/util/PermissionHelper.java +114 -0
  67. package/capacitor/src/main/java/com/getcapacitor/util/WebColor.java +28 -0
  68. package/capacitor/src/main/res/layout/capacitor_bridge_layout_main.xml +15 -0
  69. package/capacitor/src/main/res/layout/no_webview.xml +14 -0
  70. package/capacitor/src/main/res/values/colors.xml +6 -0
  71. package/capacitor/src/main/res/values/strings.xml +3 -0
  72. package/capacitor/src/main/res/values/styles.xml +6 -0
  73. package/package.json +31 -0
@@ -0,0 +1,709 @@
1
+ package com.getcapacitor;
2
+
3
+ import static com.getcapacitor.Bridge.CAPACITOR_HTTPS_SCHEME;
4
+ import static com.getcapacitor.Bridge.DEFAULT_ANDROID_WEBVIEW_VERSION;
5
+ import static com.getcapacitor.Bridge.DEFAULT_HUAWEI_WEBVIEW_VERSION;
6
+ import static com.getcapacitor.Bridge.MINIMUM_ANDROID_WEBVIEW_VERSION;
7
+ import static com.getcapacitor.Bridge.MINIMUM_HUAWEI_WEBVIEW_VERSION;
8
+ import static com.getcapacitor.FileUtils.readFileFromAssets;
9
+
10
+ import android.content.Context;
11
+ import android.content.pm.ApplicationInfo;
12
+ import android.content.res.AssetManager;
13
+ import androidx.annotation.Nullable;
14
+ import com.getcapacitor.util.JSONUtils;
15
+ import java.io.File;
16
+ import java.io.IOException;
17
+ import java.util.Arrays;
18
+ import java.util.HashMap;
19
+ import java.util.Iterator;
20
+ import java.util.List;
21
+ import java.util.Locale;
22
+ import java.util.Map;
23
+ import org.json.JSONException;
24
+ import org.json.JSONObject;
25
+
26
+ /**
27
+ * Represents the configuration options for Capacitor
28
+ */
29
+ public class CapConfig {
30
+
31
+ private static final String LOG_BEHAVIOR_NONE = "none";
32
+ private static final String LOG_BEHAVIOR_DEBUG = "debug";
33
+ private static final String LOG_BEHAVIOR_PRODUCTION = "production";
34
+
35
+ // Server Config
36
+ private boolean html5mode = true;
37
+ private String serverUrl;
38
+ private String hostname = "localhost";
39
+ private String androidScheme = CAPACITOR_HTTPS_SCHEME;
40
+ private String[] allowNavigation;
41
+
42
+ // Android Config
43
+ private String overriddenUserAgentString;
44
+ private String appendedUserAgentString;
45
+ private String backgroundColor;
46
+ private boolean allowMixedContent = false;
47
+ private boolean captureInput = false;
48
+ private boolean webContentsDebuggingEnabled = false;
49
+ private boolean loggingEnabled = true;
50
+ private boolean initialFocus = true;
51
+ private boolean useLegacyBridge = false;
52
+ private int minWebViewVersion = DEFAULT_ANDROID_WEBVIEW_VERSION;
53
+ private int minHuaweiWebViewVersion = DEFAULT_HUAWEI_WEBVIEW_VERSION;
54
+ private String errorPath;
55
+ private boolean zoomableWebView = false;
56
+ private boolean resolveServiceWorkerRequests = true;
57
+
58
+ // Embedded
59
+ private String startPath;
60
+
61
+ // Plugins
62
+ private Map<String, PluginConfig> pluginsConfiguration = null;
63
+
64
+ // Config Object JSON (legacy)
65
+ private JSONObject configJSON = new JSONObject();
66
+
67
+ /**
68
+ * Constructs an empty config file.
69
+ */
70
+ private CapConfig() {}
71
+
72
+ /**
73
+ * Get an instance of the Config file object.
74
+ * @deprecated use {@link #loadDefault(Context)} to load an instance of the Config object
75
+ * from the capacitor.config.json file, or use the {@link CapConfig.Builder} to construct
76
+ * a CapConfig for embedded use.
77
+ *
78
+ * @param assetManager The AssetManager used to load the config file
79
+ * @param config JSON describing a configuration to use
80
+ */
81
+ @Deprecated
82
+ public CapConfig(AssetManager assetManager, JSONObject config) {
83
+ if (config != null) {
84
+ this.configJSON = config;
85
+ } else {
86
+ // Load the capacitor.config.json
87
+ loadConfigFromAssets(assetManager, null);
88
+ }
89
+
90
+ deserializeConfig(null);
91
+ }
92
+
93
+ /**
94
+ * Constructs a Capacitor Configuration from config.json file.
95
+ *
96
+ * @param context The context.
97
+ * @return A loaded config file, if successful.
98
+ */
99
+ public static CapConfig loadDefault(Context context) {
100
+ CapConfig config = new CapConfig();
101
+
102
+ if (context == null) {
103
+ Logger.error("Capacitor Config could not be created from file. Context must not be null.");
104
+ return config;
105
+ }
106
+
107
+ config.loadConfigFromAssets(context.getAssets(), null);
108
+ config.deserializeConfig(context);
109
+ return config;
110
+ }
111
+
112
+ /**
113
+ * Constructs a Capacitor Configuration from config.json file within the app assets.
114
+ *
115
+ * @param context The context.
116
+ * @param path A path relative to the root assets directory.
117
+ * @return A loaded config file, if successful.
118
+ */
119
+ public static CapConfig loadFromAssets(Context context, String path) {
120
+ CapConfig config = new CapConfig();
121
+
122
+ if (context == null) {
123
+ Logger.error("Capacitor Config could not be created from file. Context must not be null.");
124
+ return config;
125
+ }
126
+
127
+ config.loadConfigFromAssets(context.getAssets(), path);
128
+ config.deserializeConfig(context);
129
+ return config;
130
+ }
131
+
132
+ /**
133
+ * Constructs a Capacitor Configuration from config.json file within the app file-space.
134
+ *
135
+ * @param context The context.
136
+ * @param path A path relative to the root of the app file-space.
137
+ * @return A loaded config file, if successful.
138
+ */
139
+ public static CapConfig loadFromFile(Context context, String path) {
140
+ CapConfig config = new CapConfig();
141
+
142
+ if (context == null) {
143
+ Logger.error("Capacitor Config could not be created from file. Context must not be null.");
144
+ return config;
145
+ }
146
+
147
+ config.loadConfigFromFile(path);
148
+ config.deserializeConfig(context);
149
+ return config;
150
+ }
151
+
152
+ /**
153
+ * Constructs a Capacitor Configuration using ConfigBuilder.
154
+ *
155
+ * @param builder A config builder initialized with values
156
+ */
157
+ private CapConfig(Builder builder) {
158
+ // Server Config
159
+ this.html5mode = builder.html5mode;
160
+ this.serverUrl = builder.serverUrl;
161
+ this.hostname = builder.hostname;
162
+
163
+ if (this.validateScheme(builder.androidScheme)) {
164
+ this.androidScheme = builder.androidScheme;
165
+ }
166
+
167
+ this.allowNavigation = builder.allowNavigation;
168
+
169
+ // Android Config
170
+ this.overriddenUserAgentString = builder.overriddenUserAgentString;
171
+ this.appendedUserAgentString = builder.appendedUserAgentString;
172
+ this.backgroundColor = builder.backgroundColor;
173
+ this.allowMixedContent = builder.allowMixedContent;
174
+ this.captureInput = builder.captureInput;
175
+ this.webContentsDebuggingEnabled = builder.webContentsDebuggingEnabled;
176
+ this.loggingEnabled = builder.loggingEnabled;
177
+ this.initialFocus = builder.initialFocus;
178
+ this.useLegacyBridge = builder.useLegacyBridge;
179
+ this.minWebViewVersion = builder.minWebViewVersion;
180
+ this.minHuaweiWebViewVersion = builder.minHuaweiWebViewVersion;
181
+ this.errorPath = builder.errorPath;
182
+ this.zoomableWebView = builder.zoomableWebView;
183
+ this.resolveServiceWorkerRequests = builder.resolveServiceWorkerRequests;
184
+
185
+ // Embedded
186
+ this.startPath = builder.startPath;
187
+
188
+ // Plugins Config
189
+ this.pluginsConfiguration = builder.pluginsConfiguration;
190
+ }
191
+
192
+ /**
193
+ * Loads a Capacitor Configuration JSON file into a Capacitor Configuration object.
194
+ * An optional path string can be provided to look for the config in a subdirectory path.
195
+ */
196
+ private void loadConfigFromAssets(AssetManager assetManager, String path) {
197
+ if (path == null) {
198
+ path = "";
199
+ } else {
200
+ // Add slash at the end to form a proper file path if going deeper in assets dir
201
+ if (path.charAt(path.length() - 1) != '/') {
202
+ path = path + "/";
203
+ }
204
+ }
205
+
206
+ try {
207
+ String jsonString = readFileFromAssets(assetManager, path + "capacitor.config.json");
208
+ configJSON = new JSONObject(jsonString);
209
+ } catch (IOException ex) {
210
+ Logger.error("Unable to load capacitor.config.json. Run npx cap copy first", ex);
211
+ } catch (JSONException ex) {
212
+ Logger.error("Unable to parse capacitor.config.json. Make sure it's valid json", ex);
213
+ }
214
+ }
215
+
216
+ /**
217
+ * Loads a Capacitor Configuration JSON file into a Capacitor Configuration object.
218
+ * An optional path string can be provided to look for the config in a subdirectory path.
219
+ */
220
+ private void loadConfigFromFile(String path) {
221
+ if (path == null) {
222
+ path = "";
223
+ } else {
224
+ // Add slash at the end to form a proper file path if going deeper in assets dir
225
+ if (path.charAt(path.length() - 1) != '/') {
226
+ path = path + "/";
227
+ }
228
+ }
229
+
230
+ try {
231
+ File configFile = new File(path + "capacitor.config.json");
232
+ String jsonString = FileUtils.readFileFromDisk(configFile);
233
+ configJSON = new JSONObject(jsonString);
234
+ } catch (JSONException ex) {
235
+ Logger.error("Unable to parse capacitor.config.json. Make sure it's valid json", ex);
236
+ } catch (IOException ex) {
237
+ Logger.error("Unable to load capacitor.config.json.", ex);
238
+ }
239
+ }
240
+
241
+ /**
242
+ * Deserializes the config from JSON into a Capacitor Configuration object.
243
+ */
244
+ private void deserializeConfig(@Nullable Context context) {
245
+ boolean isDebug = context != null && (context.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
246
+
247
+ // Server
248
+ html5mode = JSONUtils.getBoolean(configJSON, "server.html5mode", html5mode);
249
+ serverUrl = JSONUtils.getString(configJSON, "server.url", null);
250
+ hostname = JSONUtils.getString(configJSON, "server.hostname", hostname);
251
+ errorPath = JSONUtils.getString(configJSON, "server.errorPath", null);
252
+ startPath = JSONUtils.getString(configJSON, "server.appStartPath", null);
253
+
254
+ String configSchema = JSONUtils.getString(configJSON, "server.androidScheme", androidScheme);
255
+ if (this.validateScheme(configSchema)) {
256
+ androidScheme = configSchema;
257
+ }
258
+
259
+ allowNavigation = JSONUtils.getArray(configJSON, "server.allowNavigation", null);
260
+
261
+ // Android
262
+ overriddenUserAgentString = JSONUtils.getString(
263
+ configJSON,
264
+ "android.overrideUserAgent",
265
+ JSONUtils.getString(configJSON, "overrideUserAgent", null)
266
+ );
267
+ appendedUserAgentString = JSONUtils.getString(
268
+ configJSON,
269
+ "android.appendUserAgent",
270
+ JSONUtils.getString(configJSON, "appendUserAgent", null)
271
+ );
272
+ backgroundColor = JSONUtils.getString(
273
+ configJSON,
274
+ "android.backgroundColor",
275
+ JSONUtils.getString(configJSON, "backgroundColor", null)
276
+ );
277
+ allowMixedContent = JSONUtils.getBoolean(
278
+ configJSON,
279
+ "android.allowMixedContent",
280
+ JSONUtils.getBoolean(configJSON, "allowMixedContent", allowMixedContent)
281
+ );
282
+ minWebViewVersion = JSONUtils.getInt(configJSON, "android.minWebViewVersion", DEFAULT_ANDROID_WEBVIEW_VERSION);
283
+ minHuaweiWebViewVersion = JSONUtils.getInt(configJSON, "android.minHuaweiWebViewVersion", DEFAULT_HUAWEI_WEBVIEW_VERSION);
284
+ captureInput = JSONUtils.getBoolean(configJSON, "android.captureInput", captureInput);
285
+ useLegacyBridge = JSONUtils.getBoolean(configJSON, "android.useLegacyBridge", useLegacyBridge);
286
+ webContentsDebuggingEnabled = JSONUtils.getBoolean(configJSON, "android.webContentsDebuggingEnabled", isDebug);
287
+ zoomableWebView = JSONUtils.getBoolean(configJSON, "android.zoomEnabled", JSONUtils.getBoolean(configJSON, "zoomEnabled", false));
288
+ resolveServiceWorkerRequests = JSONUtils.getBoolean(configJSON, "android.resolveServiceWorkerRequests", true);
289
+
290
+ String logBehavior = JSONUtils.getString(
291
+ configJSON,
292
+ "android.loggingBehavior",
293
+ JSONUtils.getString(configJSON, "loggingBehavior", LOG_BEHAVIOR_DEBUG)
294
+ );
295
+ switch (logBehavior.toLowerCase(Locale.ROOT)) {
296
+ case LOG_BEHAVIOR_PRODUCTION:
297
+ loggingEnabled = true;
298
+ break;
299
+ case LOG_BEHAVIOR_NONE:
300
+ loggingEnabled = false;
301
+ break;
302
+ default: // LOG_BEHAVIOR_DEBUG
303
+ loggingEnabled = isDebug;
304
+ }
305
+
306
+ initialFocus = JSONUtils.getBoolean(
307
+ configJSON,
308
+ "android.initialFocus",
309
+ JSONUtils.getBoolean(configJSON, "initialFocus", initialFocus)
310
+ );
311
+
312
+ // Plugins
313
+ pluginsConfiguration = deserializePluginsConfig(JSONUtils.getObject(configJSON, "plugins"));
314
+ }
315
+
316
+ private boolean validateScheme(String scheme) {
317
+ List<String> invalidSchemes = Arrays.asList("file", "ftp", "ftps", "ws", "wss", "about", "blob", "data");
318
+ if (invalidSchemes.contains(scheme)) {
319
+ Logger.warn(scheme + " is not an allowed scheme. Defaulting to https.");
320
+ return false;
321
+ }
322
+
323
+ // Non-http(s) schemes are not allowed to modify the URL path as of Android Webview 117
324
+ if (!scheme.equals("http") && !scheme.equals("https")) {
325
+ Logger.warn(
326
+ "Using a non-standard scheme: " + scheme + " for Android. This is known to cause issues as of Android Webview 117."
327
+ );
328
+ }
329
+
330
+ return true;
331
+ }
332
+
333
+ public boolean isHTML5Mode() {
334
+ return html5mode;
335
+ }
336
+
337
+ public String getServerUrl() {
338
+ return serverUrl;
339
+ }
340
+
341
+ public String getErrorPath() {
342
+ return errorPath;
343
+ }
344
+
345
+ public String getHostname() {
346
+ return hostname;
347
+ }
348
+
349
+ public String getStartPath() {
350
+ return startPath;
351
+ }
352
+
353
+ public String getAndroidScheme() {
354
+ return androidScheme;
355
+ }
356
+
357
+ public String[] getAllowNavigation() {
358
+ return allowNavigation;
359
+ }
360
+
361
+ public String getOverriddenUserAgentString() {
362
+ return overriddenUserAgentString;
363
+ }
364
+
365
+ public String getAppendedUserAgentString() {
366
+ return appendedUserAgentString;
367
+ }
368
+
369
+ public String getBackgroundColor() {
370
+ return backgroundColor;
371
+ }
372
+
373
+ public boolean isMixedContentAllowed() {
374
+ return allowMixedContent;
375
+ }
376
+
377
+ public boolean isInputCaptured() {
378
+ return captureInput;
379
+ }
380
+
381
+ public boolean isResolveServiceWorkerRequests() {
382
+ return resolveServiceWorkerRequests;
383
+ }
384
+
385
+ public boolean isWebContentsDebuggingEnabled() {
386
+ return webContentsDebuggingEnabled;
387
+ }
388
+
389
+ public boolean isZoomableWebView() {
390
+ return zoomableWebView;
391
+ }
392
+
393
+ public boolean isLoggingEnabled() {
394
+ return loggingEnabled;
395
+ }
396
+
397
+ public boolean isInitialFocus() {
398
+ return initialFocus;
399
+ }
400
+
401
+ public boolean isUsingLegacyBridge() {
402
+ return useLegacyBridge;
403
+ }
404
+
405
+ public int getMinWebViewVersion() {
406
+ if (minWebViewVersion < MINIMUM_ANDROID_WEBVIEW_VERSION) {
407
+ Logger.warn("Specified minimum webview version is too low, defaulting to " + MINIMUM_ANDROID_WEBVIEW_VERSION);
408
+ return MINIMUM_ANDROID_WEBVIEW_VERSION;
409
+ }
410
+
411
+ return minWebViewVersion;
412
+ }
413
+
414
+ public int getMinHuaweiWebViewVersion() {
415
+ if (minHuaweiWebViewVersion < MINIMUM_HUAWEI_WEBVIEW_VERSION) {
416
+ Logger.warn("Specified minimum Huawei webview version is too low, defaulting to " + MINIMUM_HUAWEI_WEBVIEW_VERSION);
417
+ return MINIMUM_HUAWEI_WEBVIEW_VERSION;
418
+ }
419
+
420
+ return minHuaweiWebViewVersion;
421
+ }
422
+
423
+ public PluginConfig getPluginConfiguration(String pluginId) {
424
+ PluginConfig pluginConfig = pluginsConfiguration.get(pluginId);
425
+ if (pluginConfig == null) {
426
+ pluginConfig = new PluginConfig(new JSONObject());
427
+ }
428
+
429
+ return pluginConfig;
430
+ }
431
+
432
+ /**
433
+ * Get a JSON object value from the Capacitor config.
434
+ * @deprecated use {@link PluginConfig#getObject(String)} to access plugin config values.
435
+ * For main Capacitor config values, use the appropriate getter.
436
+ *
437
+ * @param key A key to fetch from the config
438
+ * @return The value from the config, if exists. Null if not
439
+ */
440
+ @Deprecated
441
+ public JSONObject getObject(String key) {
442
+ try {
443
+ return configJSON.getJSONObject(key);
444
+ } catch (Exception ex) {}
445
+ return null;
446
+ }
447
+
448
+ /**
449
+ * Get a string value from the Capacitor config.
450
+ * @deprecated use {@link PluginConfig#getString(String, String)} to access plugin config
451
+ * values. For main Capacitor config values, use the appropriate getter.
452
+ *
453
+ * @param key A key to fetch from the config
454
+ * @return The value from the config, if exists. Null if not
455
+ */
456
+ @Deprecated
457
+ public String getString(String key) {
458
+ return JSONUtils.getString(configJSON, key, null);
459
+ }
460
+
461
+ /**
462
+ * Get a string value from the Capacitor config.
463
+ * @deprecated use {@link PluginConfig#getString(String, String)} to access plugin config
464
+ * values. For main Capacitor config values, use the appropriate getter.
465
+ *
466
+ * @param key A key to fetch from the config
467
+ * @param defaultValue A default value to return if the key does not exist in the config
468
+ * @return The value from the config, if key exists. Default value returned if not
469
+ */
470
+ @Deprecated
471
+ public String getString(String key, String defaultValue) {
472
+ return JSONUtils.getString(configJSON, key, defaultValue);
473
+ }
474
+
475
+ /**
476
+ * Get a boolean value from the Capacitor config.
477
+ * @deprecated use {@link PluginConfig#getBoolean(String, boolean)} to access plugin config
478
+ * values. For main Capacitor config values, use the appropriate getter.
479
+ *
480
+ * @param key A key to fetch from the config
481
+ * @param defaultValue A default value to return if the key does not exist in the config
482
+ * @return The value from the config, if key exists. Default value returned if not
483
+ */
484
+ @Deprecated
485
+ public boolean getBoolean(String key, boolean defaultValue) {
486
+ return JSONUtils.getBoolean(configJSON, key, defaultValue);
487
+ }
488
+
489
+ /**
490
+ * Get an integer value from the Capacitor config.
491
+ * @deprecated use {@link PluginConfig#getInt(String, int)} to access the plugin config
492
+ * values. For main Capacitor config values, use the appropriate getter.
493
+ *
494
+ * @param key A key to fetch from the config
495
+ * @param defaultValue A default value to return if the key does not exist in the config
496
+ * @return The value from the config, if key exists. Default value returned if not
497
+ */
498
+ @Deprecated
499
+ public int getInt(String key, int defaultValue) {
500
+ return JSONUtils.getInt(configJSON, key, defaultValue);
501
+ }
502
+
503
+ /**
504
+ * Get a string array value from the Capacitor config.
505
+ * @deprecated use {@link PluginConfig#getArray(String)} to access the plugin config
506
+ * values. For main Capacitor config values, use the appropriate getter.
507
+ *
508
+ * @param key A key to fetch from the config
509
+ * @return The value from the config, if exists. Null if not
510
+ */
511
+ @Deprecated
512
+ public String[] getArray(String key) {
513
+ return JSONUtils.getArray(configJSON, key, null);
514
+ }
515
+
516
+ /**
517
+ * Get a string array value from the Capacitor config.
518
+ * @deprecated use {@link PluginConfig#getArray(String, String[])} to access the plugin
519
+ * config values. For main Capacitor config values, use the appropriate getter.
520
+ *
521
+ * @param key A key to fetch from the config
522
+ * @param defaultValue A default value to return if the key does not exist in the config
523
+ * @return The value from the config, if key exists. Default value returned if not
524
+ */
525
+ @Deprecated
526
+ public String[] getArray(String key, String[] defaultValue) {
527
+ return JSONUtils.getArray(configJSON, key, defaultValue);
528
+ }
529
+
530
+ private static Map<String, PluginConfig> deserializePluginsConfig(JSONObject pluginsConfig) {
531
+ Map<String, PluginConfig> pluginsMap = new HashMap<>();
532
+
533
+ // return an empty map if there is no pluginsConfig json
534
+ if (pluginsConfig == null) {
535
+ return pluginsMap;
536
+ }
537
+
538
+ Iterator<String> pluginIds = pluginsConfig.keys();
539
+
540
+ while (pluginIds.hasNext()) {
541
+ String pluginId = pluginIds.next();
542
+ JSONObject value = null;
543
+
544
+ try {
545
+ value = pluginsConfig.getJSONObject(pluginId);
546
+ PluginConfig pluginConfig = new PluginConfig(value);
547
+ pluginsMap.put(pluginId, pluginConfig);
548
+ } catch (JSONException e) {
549
+ e.printStackTrace();
550
+ }
551
+ }
552
+
553
+ return pluginsMap;
554
+ }
555
+
556
+ /**
557
+ * Builds a Capacitor Configuration in code
558
+ */
559
+ public static class Builder {
560
+
561
+ private Context context;
562
+
563
+ // Server Config Values
564
+ private boolean html5mode = true;
565
+ private String serverUrl;
566
+ private String errorPath;
567
+ private String hostname = "localhost";
568
+ private String androidScheme = CAPACITOR_HTTPS_SCHEME;
569
+ private String[] allowNavigation;
570
+
571
+ // Android Config Values
572
+ private String overriddenUserAgentString;
573
+ private String appendedUserAgentString;
574
+ private String backgroundColor;
575
+ private boolean allowMixedContent = false;
576
+ private boolean captureInput = false;
577
+ private Boolean webContentsDebuggingEnabled = null;
578
+ private boolean loggingEnabled = true;
579
+ private boolean initialFocus = false;
580
+ private boolean useLegacyBridge = false;
581
+ private int minWebViewVersion = DEFAULT_ANDROID_WEBVIEW_VERSION;
582
+ private int minHuaweiWebViewVersion = DEFAULT_HUAWEI_WEBVIEW_VERSION;
583
+ private boolean zoomableWebView = false;
584
+ private boolean resolveServiceWorkerRequests = true;
585
+
586
+ // Embedded
587
+ private String startPath = null;
588
+
589
+ // Plugins Config Object
590
+ private Map<String, PluginConfig> pluginsConfiguration = new HashMap<>();
591
+
592
+ /**
593
+ * Constructs a new CapConfig Builder.
594
+ *
595
+ * @param context The context
596
+ */
597
+ public Builder(Context context) {
598
+ this.context = context;
599
+ }
600
+
601
+ /**
602
+ * Builds a Capacitor Config from the builder.
603
+ *
604
+ * @return A new Capacitor Config
605
+ */
606
+ public CapConfig create() {
607
+ if (webContentsDebuggingEnabled == null) {
608
+ webContentsDebuggingEnabled = (context.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
609
+ }
610
+
611
+ return new CapConfig(this);
612
+ }
613
+
614
+ public Builder setPluginsConfiguration(JSONObject pluginsConfiguration) {
615
+ this.pluginsConfiguration = deserializePluginsConfig(pluginsConfiguration);
616
+ return this;
617
+ }
618
+
619
+ public Builder setHTML5mode(boolean html5mode) {
620
+ this.html5mode = html5mode;
621
+ return this;
622
+ }
623
+
624
+ public Builder setServerUrl(String serverUrl) {
625
+ this.serverUrl = serverUrl;
626
+ return this;
627
+ }
628
+
629
+ public Builder setErrorPath(String errorPath) {
630
+ this.errorPath = errorPath;
631
+ return this;
632
+ }
633
+
634
+ public Builder setHostname(String hostname) {
635
+ this.hostname = hostname;
636
+ return this;
637
+ }
638
+
639
+ public Builder setStartPath(String path) {
640
+ this.startPath = path;
641
+ return this;
642
+ }
643
+
644
+ public Builder setAndroidScheme(String androidScheme) {
645
+ this.androidScheme = androidScheme;
646
+ return this;
647
+ }
648
+
649
+ public Builder setAllowNavigation(String[] allowNavigation) {
650
+ this.allowNavigation = allowNavigation;
651
+ return this;
652
+ }
653
+
654
+ public Builder setOverriddenUserAgentString(String overriddenUserAgentString) {
655
+ this.overriddenUserAgentString = overriddenUserAgentString;
656
+ return this;
657
+ }
658
+
659
+ public Builder setAppendedUserAgentString(String appendedUserAgentString) {
660
+ this.appendedUserAgentString = appendedUserAgentString;
661
+ return this;
662
+ }
663
+
664
+ public Builder setBackgroundColor(String backgroundColor) {
665
+ this.backgroundColor = backgroundColor;
666
+ return this;
667
+ }
668
+
669
+ public Builder setAllowMixedContent(boolean allowMixedContent) {
670
+ this.allowMixedContent = allowMixedContent;
671
+ return this;
672
+ }
673
+
674
+ public Builder setCaptureInput(boolean captureInput) {
675
+ this.captureInput = captureInput;
676
+ return this;
677
+ }
678
+
679
+ public Builder setUseLegacyBridge(boolean useLegacyBridge) {
680
+ this.useLegacyBridge = useLegacyBridge;
681
+ return this;
682
+ }
683
+
684
+ public Builder setResolveServiceWorkerRequests(boolean resolveServiceWorkerRequests) {
685
+ this.resolveServiceWorkerRequests = resolveServiceWorkerRequests;
686
+ return this;
687
+ }
688
+
689
+ public Builder setWebContentsDebuggingEnabled(boolean webContentsDebuggingEnabled) {
690
+ this.webContentsDebuggingEnabled = webContentsDebuggingEnabled;
691
+ return this;
692
+ }
693
+
694
+ public Builder setZoomableWebView(boolean zoomableWebView) {
695
+ this.zoomableWebView = zoomableWebView;
696
+ return this;
697
+ }
698
+
699
+ public Builder setLoggingEnabled(boolean enabled) {
700
+ this.loggingEnabled = enabled;
701
+ return this;
702
+ }
703
+
704
+ public Builder setInitialFocus(boolean focus) {
705
+ this.initialFocus = focus;
706
+ return this;
707
+ }
708
+ }
709
+ }