@capacitor/android 8.3.3 → 9.0.0-alpha.1
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.
- package/capacitor/build.gradle +1 -3
- package/capacitor/proguard-rules.pro +0 -6
- package/capacitor/src/main/java/com/getcapacitor/Bridge.java +80 -101
- package/capacitor/src/main/java/com/getcapacitor/MessageHandler.java +16 -46
- package/capacitor/src/main/java/com/getcapacitor/WebViewLocalServer.java +0 -13
- package/capacitor-cordova/build.gradle +45 -0
- package/capacitor-cordova/proguard-rules.pro +4 -0
- package/capacitor-cordova/src/main/AndroidManifest.xml +3 -0
- package/capacitor-cordova/src/main/java/com/getcapacitor/cordova/CordovaPlugin.java +147 -0
- package/{capacitor → capacitor-cordova}/src/main/java/com/getcapacitor/cordova/MockCordovaInterfaceImpl.java +1 -1
- package/{capacitor → capacitor-cordova}/src/main/java/com/getcapacitor/cordova/MockCordovaWebViewImpl.java +2 -2
- package/package.json +6 -3
- /package/{capacitor → capacitor-cordova}/src/main/java/com/getcapacitor/cordova/CapacitorCordovaCookieManager.java +0 -0
package/capacitor/build.gradle
CHANGED
|
@@ -8,7 +8,6 @@ ext {
|
|
|
8
8
|
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
9
9
|
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.3.0'
|
|
10
10
|
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.7.0'
|
|
11
|
-
cordovaAndroidVersion = project.hasProperty('cordovaAndroidVersion') ? rootProject.ext.cordovaAndroidVersion : '14.0.1'
|
|
12
11
|
}
|
|
13
12
|
|
|
14
13
|
|
|
@@ -87,8 +86,7 @@ dependencies {
|
|
|
87
86
|
testImplementation "junit:junit:$junitVersion"
|
|
88
87
|
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
89
88
|
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
90
|
-
|
|
91
|
-
testImplementation 'org.json:json:20250517'
|
|
89
|
+
testImplementation 'org.json:json:20250517'
|
|
92
90
|
testImplementation 'org.mockito:mockito-core:5.20.0'
|
|
93
91
|
}
|
|
94
92
|
|
|
@@ -35,8 +35,6 @@ import androidx.webkit.WebViewFeature;
|
|
|
35
35
|
import com.getcapacitor.android.R;
|
|
36
36
|
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
37
37
|
import com.getcapacitor.annotation.Permission;
|
|
38
|
-
import com.getcapacitor.cordova.MockCordovaInterfaceImpl;
|
|
39
|
-
import com.getcapacitor.cordova.MockCordovaWebViewImpl;
|
|
40
38
|
import com.getcapacitor.util.HostMask;
|
|
41
39
|
import com.getcapacitor.util.InternalUtils;
|
|
42
40
|
import com.getcapacitor.util.PermissionHelper;
|
|
@@ -53,13 +51,9 @@ import java.util.LinkedList;
|
|
|
53
51
|
import java.util.List;
|
|
54
52
|
import java.util.Map;
|
|
55
53
|
import java.util.Set;
|
|
54
|
+
import java.util.function.Function;
|
|
56
55
|
import java.util.regex.Matcher;
|
|
57
56
|
import java.util.regex.Pattern;
|
|
58
|
-
import org.apache.cordova.ConfigXmlParser;
|
|
59
|
-
import org.apache.cordova.CordovaPreferences;
|
|
60
|
-
import org.apache.cordova.CordovaWebView;
|
|
61
|
-
import org.apache.cordova.PluginEntry;
|
|
62
|
-
import org.apache.cordova.PluginManager;
|
|
63
57
|
import org.json.JSONException;
|
|
64
58
|
|
|
65
59
|
/**
|
|
@@ -125,9 +119,6 @@ public class Bridge {
|
|
|
125
119
|
private Boolean canInjectJS = true;
|
|
126
120
|
// A reference to the main WebView for the app
|
|
127
121
|
private final WebView webView;
|
|
128
|
-
public final MockCordovaInterfaceImpl cordovaInterface;
|
|
129
|
-
private CordovaWebView cordovaWebView;
|
|
130
|
-
private CordovaPreferences preferences;
|
|
131
122
|
private BridgeWebViewClient webViewClient;
|
|
132
123
|
private App app;
|
|
133
124
|
|
|
@@ -147,6 +138,8 @@ public class Bridge {
|
|
|
147
138
|
// A map of Plugin Id's to PluginHandle's
|
|
148
139
|
private Map<String, PluginHandle> plugins = new HashMap<>();
|
|
149
140
|
|
|
141
|
+
private Map<String, MessageHandler.Interceptor> interceptors = new HashMap<>();
|
|
142
|
+
|
|
150
143
|
// Stored plugin calls that we're keeping around to call again someday
|
|
151
144
|
private Map<String, PluginCall> savedCalls = new HashMap<>();
|
|
152
145
|
|
|
@@ -169,26 +162,6 @@ public class Bridge {
|
|
|
169
162
|
// A pre-determined path to load the bridge
|
|
170
163
|
private ServerPath serverPath;
|
|
171
164
|
|
|
172
|
-
/**
|
|
173
|
-
* Create the Bridge with a reference to the main {@link Activity} for the
|
|
174
|
-
* app, and a reference to the {@link WebView} our app will use.
|
|
175
|
-
* @param context
|
|
176
|
-
* @param webView
|
|
177
|
-
* @deprecated Use {@link Bridge.Builder} to create Bridge instances
|
|
178
|
-
*/
|
|
179
|
-
@Deprecated
|
|
180
|
-
public Bridge(
|
|
181
|
-
AppCompatActivity context,
|
|
182
|
-
WebView webView,
|
|
183
|
-
List<Class<? extends Plugin>> initialPlugins,
|
|
184
|
-
MockCordovaInterfaceImpl cordovaInterface,
|
|
185
|
-
PluginManager pluginManager,
|
|
186
|
-
CordovaPreferences preferences,
|
|
187
|
-
CapConfig config
|
|
188
|
-
) {
|
|
189
|
-
this(context, null, null, webView, initialPlugins, new ArrayList<>(), cordovaInterface, pluginManager, preferences, config);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
165
|
private Bridge(
|
|
193
166
|
AppCompatActivity context,
|
|
194
167
|
ServerPath serverPath,
|
|
@@ -196,9 +169,6 @@ public class Bridge {
|
|
|
196
169
|
WebView webView,
|
|
197
170
|
List<Class<? extends Plugin>> initialPlugins,
|
|
198
171
|
List<Plugin> pluginInstances,
|
|
199
|
-
MockCordovaInterfaceImpl cordovaInterface,
|
|
200
|
-
PluginManager pluginManager,
|
|
201
|
-
CordovaPreferences preferences,
|
|
202
172
|
CapConfig config
|
|
203
173
|
) {
|
|
204
174
|
this.app = new App();
|
|
@@ -209,8 +179,6 @@ public class Bridge {
|
|
|
209
179
|
this.webViewClient = new BridgeWebViewClient(this);
|
|
210
180
|
this.initialPlugins = initialPlugins;
|
|
211
181
|
this.pluginInstances = pluginInstances;
|
|
212
|
-
this.cordovaInterface = cordovaInterface;
|
|
213
|
-
this.preferences = preferences;
|
|
214
182
|
|
|
215
183
|
// Start our plugin execution threads and handlers
|
|
216
184
|
handlerThread.start();
|
|
@@ -218,11 +186,10 @@ public class Bridge {
|
|
|
218
186
|
|
|
219
187
|
this.config = config != null ? config : CapConfig.loadDefault(getActivity());
|
|
220
188
|
Logger.init(this.config);
|
|
221
|
-
|
|
222
189
|
// Initialize web view and message handler for it
|
|
223
190
|
this.initWebView();
|
|
224
191
|
this.setAllowedOriginRules();
|
|
225
|
-
this.msgHandler = new MessageHandler(this, webView
|
|
192
|
+
this.msgHandler = new MessageHandler(this, webView);
|
|
226
193
|
|
|
227
194
|
// Grab any intent info that our app was launched with
|
|
228
195
|
Intent intent = context.getIntent();
|
|
@@ -450,12 +417,30 @@ public class Bridge {
|
|
|
450
417
|
return false;
|
|
451
418
|
}
|
|
452
419
|
|
|
420
|
+
private Plugin cordova() {
|
|
421
|
+
PluginHandle handle = getPlugin("__CordovaPlugin");
|
|
422
|
+
if (handle != null) {
|
|
423
|
+
return handle.getInstance();
|
|
424
|
+
}
|
|
425
|
+
return null;
|
|
426
|
+
}
|
|
427
|
+
|
|
453
428
|
public boolean isDeployDisabled() {
|
|
454
|
-
|
|
429
|
+
Plugin cordova = this.cordova();
|
|
430
|
+
if (cordova != null) {
|
|
431
|
+
return cordova.hasPermission("DisableDeploy");
|
|
432
|
+
} else {
|
|
433
|
+
return false;
|
|
434
|
+
}
|
|
455
435
|
}
|
|
456
436
|
|
|
457
437
|
public boolean shouldKeepRunning() {
|
|
458
|
-
|
|
438
|
+
Plugin cordova = this.cordova();
|
|
439
|
+
if (cordova != null) {
|
|
440
|
+
return cordova.hasPermission("KeepRunning");
|
|
441
|
+
} else {
|
|
442
|
+
return false;
|
|
443
|
+
}
|
|
459
444
|
}
|
|
460
445
|
|
|
461
446
|
public void handleAppUrlLoadError(Exception ex) {
|
|
@@ -474,10 +459,6 @@ public class Bridge {
|
|
|
474
459
|
return (getActivity().getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
|
|
475
460
|
}
|
|
476
461
|
|
|
477
|
-
protected void setCordovaWebView(CordovaWebView cordovaWebView) {
|
|
478
|
-
this.cordovaWebView = cordovaWebView;
|
|
479
|
-
}
|
|
480
|
-
|
|
481
462
|
/**
|
|
482
463
|
* Get the Context for the App
|
|
483
464
|
* @return
|
|
@@ -567,6 +548,14 @@ public class Bridge {
|
|
|
567
548
|
return this.config;
|
|
568
549
|
}
|
|
569
550
|
|
|
551
|
+
public MessageHandler.Interceptor getCallInterceptor(String type) {
|
|
552
|
+
return this.interceptors.get(type);
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
public void registerInterceptor(String type, MessageHandler.Interceptor interceptor) {
|
|
556
|
+
this.interceptors.put(type, interceptor);
|
|
557
|
+
}
|
|
558
|
+
|
|
570
559
|
public void reset() {
|
|
571
560
|
savedCalls = new HashMap<>();
|
|
572
561
|
for (PluginHandle handle : this.plugins.values()) {
|
|
@@ -1132,11 +1121,14 @@ public class Bridge {
|
|
|
1132
1121
|
if (plugin == null) {
|
|
1133
1122
|
boolean permissionHandled = false;
|
|
1134
1123
|
Logger.debug("Unable to find a Capacitor plugin to handle permission requestCode, trying Cordova plugins " + requestCode);
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1124
|
+
PluginHandle cordovaHandle = getPlugin("__CordovaPlugin");
|
|
1125
|
+
|
|
1126
|
+
if (cordovaHandle != null) {
|
|
1127
|
+
Plugin cordovaPlugin = cordovaHandle.getInstance();
|
|
1128
|
+
cordovaPlugin.handleRequestPermissionsResult(requestCode, permissions, grantResults);
|
|
1129
|
+
permissionHandled = cordovaPlugin.hasDefinedRequiredPermissions();
|
|
1139
1130
|
}
|
|
1131
|
+
|
|
1140
1132
|
return permissionHandled;
|
|
1141
1133
|
}
|
|
1142
1134
|
|
|
@@ -1271,7 +1263,14 @@ public class Bridge {
|
|
|
1271
1263
|
|
|
1272
1264
|
if (plugin == null || plugin.getInstance() == null) {
|
|
1273
1265
|
Logger.debug("Unable to find a Capacitor plugin to handle requestCode, trying Cordova plugins " + requestCode);
|
|
1274
|
-
|
|
1266
|
+
PluginHandle cordovaHandle = getPlugin("__CordovaPlugin");
|
|
1267
|
+
if (cordovaHandle != null) {
|
|
1268
|
+
Plugin cordovaPlugin = cordovaHandle.getInstance();
|
|
1269
|
+
cordovaPlugin.handleOnActivityResult(requestCode, resultCode, data);
|
|
1270
|
+
// This is a bit hacky but required to return the boolean out of the cordova interface
|
|
1271
|
+
return cordovaPlugin.hasRequiredPermissions();
|
|
1272
|
+
}
|
|
1273
|
+
return false;
|
|
1275
1274
|
}
|
|
1276
1275
|
|
|
1277
1276
|
// deprecated, to be removed
|
|
@@ -1301,10 +1300,6 @@ public class Bridge {
|
|
|
1301
1300
|
for (PluginHandle plugin : plugins.values()) {
|
|
1302
1301
|
plugin.getInstance().handleOnNewIntent(intent);
|
|
1303
1302
|
}
|
|
1304
|
-
|
|
1305
|
-
if (cordovaWebView != null) {
|
|
1306
|
-
cordovaWebView.onNewIntent(intent);
|
|
1307
|
-
}
|
|
1308
1303
|
}
|
|
1309
1304
|
|
|
1310
1305
|
/**
|
|
@@ -1333,10 +1328,6 @@ public class Bridge {
|
|
|
1333
1328
|
for (PluginHandle plugin : plugins.values()) {
|
|
1334
1329
|
plugin.getInstance().handleOnStart();
|
|
1335
1330
|
}
|
|
1336
|
-
|
|
1337
|
-
if (cordovaWebView != null) {
|
|
1338
|
-
cordovaWebView.handleStart();
|
|
1339
|
-
}
|
|
1340
1331
|
}
|
|
1341
1332
|
|
|
1342
1333
|
/**
|
|
@@ -1346,10 +1337,6 @@ public class Bridge {
|
|
|
1346
1337
|
for (PluginHandle plugin : plugins.values()) {
|
|
1347
1338
|
plugin.getInstance().handleOnResume();
|
|
1348
1339
|
}
|
|
1349
|
-
|
|
1350
|
-
if (cordovaWebView != null) {
|
|
1351
|
-
cordovaWebView.handleResume(this.shouldKeepRunning());
|
|
1352
|
-
}
|
|
1353
1340
|
}
|
|
1354
1341
|
|
|
1355
1342
|
/**
|
|
@@ -1359,11 +1346,6 @@ public class Bridge {
|
|
|
1359
1346
|
for (PluginHandle plugin : plugins.values()) {
|
|
1360
1347
|
plugin.getInstance().handleOnPause();
|
|
1361
1348
|
}
|
|
1362
|
-
|
|
1363
|
-
if (cordovaWebView != null) {
|
|
1364
|
-
boolean keepRunning = this.shouldKeepRunning() || cordovaInterface.getActivityResultCallback() != null;
|
|
1365
|
-
cordovaWebView.handlePause(keepRunning);
|
|
1366
|
-
}
|
|
1367
1349
|
}
|
|
1368
1350
|
|
|
1369
1351
|
/**
|
|
@@ -1373,10 +1355,6 @@ public class Bridge {
|
|
|
1373
1355
|
for (PluginHandle plugin : plugins.values()) {
|
|
1374
1356
|
plugin.getInstance().handleOnStop();
|
|
1375
1357
|
}
|
|
1376
|
-
|
|
1377
|
-
if (cordovaWebView != null) {
|
|
1378
|
-
cordovaWebView.handleStop();
|
|
1379
|
-
}
|
|
1380
1358
|
}
|
|
1381
1359
|
|
|
1382
1360
|
/**
|
|
@@ -1388,10 +1366,6 @@ public class Bridge {
|
|
|
1388
1366
|
}
|
|
1389
1367
|
|
|
1390
1368
|
handlerThread.quitSafely();
|
|
1391
|
-
|
|
1392
|
-
if (cordovaWebView != null) {
|
|
1393
|
-
cordovaWebView.handleDestroy();
|
|
1394
|
-
}
|
|
1395
1369
|
}
|
|
1396
1370
|
|
|
1397
1371
|
/**
|
|
@@ -1578,49 +1552,54 @@ public class Bridge {
|
|
|
1578
1552
|
|
|
1579
1553
|
public Bridge create() {
|
|
1580
1554
|
// Cordova initialization
|
|
1581
|
-
ConfigXmlParser parser = new ConfigXmlParser();
|
|
1582
|
-
parser.parse(activity.getApplicationContext());
|
|
1583
|
-
CordovaPreferences preferences = parser.getPreferences();
|
|
1584
|
-
preferences.setPreferencesBundle(activity.getIntent().getExtras());
|
|
1585
|
-
List<PluginEntry> pluginEntries = parser.getPluginEntries();
|
|
1586
|
-
|
|
1587
|
-
MockCordovaInterfaceImpl cordovaInterface = new MockCordovaInterfaceImpl(activity);
|
|
1588
|
-
if (instanceState != null) {
|
|
1589
|
-
cordovaInterface.restoreInstanceState(instanceState);
|
|
1590
|
-
}
|
|
1591
|
-
|
|
1592
1555
|
WebView webView = this.fragment != null ? fragment.getView().findViewById(R.id.webview) : activity.findViewById(R.id.webview);
|
|
1593
|
-
MockCordovaWebViewImpl mockWebView = new MockCordovaWebViewImpl(activity.getApplicationContext());
|
|
1594
|
-
mockWebView.init(cordovaInterface, pluginEntries, preferences, webView);
|
|
1595
|
-
PluginManager pluginManager = mockWebView.getPluginManager();
|
|
1596
|
-
cordovaInterface.onCordovaInit(pluginManager);
|
|
1597
1556
|
|
|
1598
1557
|
// Bridge initialization
|
|
1599
|
-
Bridge bridge = new Bridge(
|
|
1600
|
-
activity,
|
|
1601
|
-
serverPath,
|
|
1602
|
-
fragment,
|
|
1603
|
-
webView,
|
|
1604
|
-
plugins,
|
|
1605
|
-
pluginInstances,
|
|
1606
|
-
cordovaInterface,
|
|
1607
|
-
pluginManager,
|
|
1608
|
-
preferences,
|
|
1609
|
-
config
|
|
1610
|
-
);
|
|
1558
|
+
Bridge bridge = new Bridge(activity, serverPath, fragment, webView, plugins, pluginInstances, config);
|
|
1611
1559
|
|
|
1612
1560
|
if (webView instanceof CapacitorWebView capacitorWebView) {
|
|
1613
1561
|
capacitorWebView.setBridge(bridge);
|
|
1614
1562
|
}
|
|
1615
1563
|
|
|
1616
|
-
bridge.setCordovaWebView(mockWebView);
|
|
1617
1564
|
bridge.setWebViewListeners(webViewListeners);
|
|
1618
1565
|
bridge.setRouteProcessor(routeProcessor);
|
|
1619
1566
|
|
|
1620
1567
|
if (instanceState != null) {
|
|
1568
|
+
PluginHandle maybeCordova = bridge.getPlugin("__CordovaPlugin");
|
|
1569
|
+
if (maybeCordova != null) {
|
|
1570
|
+
maybeCordova.getInstance().restoreState(instanceState);
|
|
1571
|
+
}
|
|
1621
1572
|
bridge.restoreInstanceState(instanceState);
|
|
1622
1573
|
}
|
|
1623
1574
|
|
|
1575
|
+
bridge.registerInterceptor("message", (postData) -> {
|
|
1576
|
+
try {
|
|
1577
|
+
String callbackId = postData.getString("callbackId");
|
|
1578
|
+
String pluginId = postData.getString("pluginId");
|
|
1579
|
+
String methodName = postData.getString("methodName");
|
|
1580
|
+
JSObject methodData = postData.getJSObject("options", new JSObject());
|
|
1581
|
+
|
|
1582
|
+
Logger.verbose(
|
|
1583
|
+
Logger.tags("Plugin"),
|
|
1584
|
+
"To native (Capacitor plugin): callbackId: " +
|
|
1585
|
+
callbackId +
|
|
1586
|
+
", pluginId: " +
|
|
1587
|
+
pluginId +
|
|
1588
|
+
", methodName: " +
|
|
1589
|
+
methodName
|
|
1590
|
+
);
|
|
1591
|
+
|
|
1592
|
+
PluginCall call = new PluginCall(bridge.msgHandler, pluginId, callbackId, methodName, methodData);
|
|
1593
|
+
bridge.callPluginMethod(pluginId, methodName, call);
|
|
1594
|
+
} catch (JSONException e) {
|
|
1595
|
+
Logger.error(e.getMessage());
|
|
1596
|
+
}
|
|
1597
|
+
});
|
|
1598
|
+
|
|
1599
|
+
bridge.registerInterceptor("js.error", (postData) -> {
|
|
1600
|
+
Logger.error("JavaScript Error: " + postData.toString());
|
|
1601
|
+
});
|
|
1602
|
+
|
|
1624
1603
|
return bridge;
|
|
1625
1604
|
}
|
|
1626
1605
|
}
|
|
@@ -5,7 +5,7 @@ import android.webkit.WebView;
|
|
|
5
5
|
import androidx.webkit.JavaScriptReplyProxy;
|
|
6
6
|
import androidx.webkit.WebViewCompat;
|
|
7
7
|
import androidx.webkit.WebViewFeature;
|
|
8
|
-
import
|
|
8
|
+
import java.util.function.Function;
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* MessageHandler handles messages from the WebView, dispatching them
|
|
@@ -13,15 +13,18 @@ import org.apache.cordova.PluginManager;
|
|
|
13
13
|
*/
|
|
14
14
|
public class MessageHandler {
|
|
15
15
|
|
|
16
|
+
@FunctionalInterface
|
|
17
|
+
public interface Interceptor {
|
|
18
|
+
void intercept(JSObject object);
|
|
19
|
+
}
|
|
20
|
+
|
|
16
21
|
private Bridge bridge;
|
|
17
22
|
private WebView webView;
|
|
18
|
-
private PluginManager cordovaPluginManager;
|
|
19
23
|
private JavaScriptReplyProxy javaScriptReplyProxy;
|
|
20
24
|
|
|
21
|
-
public MessageHandler(Bridge bridge, WebView webView
|
|
25
|
+
public MessageHandler(Bridge bridge, WebView webView) {
|
|
22
26
|
this.bridge = bridge;
|
|
23
27
|
this.webView = webView;
|
|
24
|
-
this.cordovaPluginManager = cordovaPluginManager;
|
|
25
28
|
|
|
26
29
|
if (WebViewFeature.isFeatureSupported(WebViewFeature.WEB_MESSAGE_LISTENER) && !bridge.getConfig().isUsingLegacyBridge()) {
|
|
27
30
|
WebViewCompat.WebMessageListener capListener = (view, message, sourceOrigin, isMainFrame, replyProxy) -> {
|
|
@@ -42,6 +45,11 @@ public class MessageHandler {
|
|
|
42
45
|
}
|
|
43
46
|
}
|
|
44
47
|
|
|
48
|
+
@Deprecated
|
|
49
|
+
public MessageHandler(Bridge bridge, WebView webView, Object cordovaPluginManager) {
|
|
50
|
+
this(bridge, webView);
|
|
51
|
+
}
|
|
52
|
+
|
|
45
53
|
/**
|
|
46
54
|
* The main message handler that will be called from JavaScript
|
|
47
55
|
* to send a message to the native bridge.
|
|
@@ -55,43 +63,11 @@ public class MessageHandler {
|
|
|
55
63
|
|
|
56
64
|
String type = postData.getString("type");
|
|
57
65
|
|
|
58
|
-
|
|
59
|
-
boolean isCordovaPlugin = typeIsNotNull && type.equals("cordova");
|
|
60
|
-
boolean isJavaScriptError = typeIsNotNull && type.equals("js.error");
|
|
61
|
-
|
|
62
|
-
String callbackId = postData.getString("callbackId");
|
|
63
|
-
|
|
64
|
-
if (isCordovaPlugin) {
|
|
65
|
-
String service = postData.getString("service");
|
|
66
|
-
String action = postData.getString("action");
|
|
67
|
-
String actionArgs = postData.getString("actionArgs");
|
|
68
|
-
|
|
69
|
-
Logger.verbose(
|
|
70
|
-
Logger.tags("Plugin"),
|
|
71
|
-
"To native (Cordova plugin): callbackId: " +
|
|
72
|
-
callbackId +
|
|
73
|
-
", service: " +
|
|
74
|
-
service +
|
|
75
|
-
", action: " +
|
|
76
|
-
action +
|
|
77
|
-
", actionArgs: " +
|
|
78
|
-
actionArgs
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
this.callCordovaPluginMethod(callbackId, service, action, actionArgs);
|
|
82
|
-
} else if (isJavaScriptError) {
|
|
83
|
-
Logger.error("JavaScript Error: " + jsonStr);
|
|
84
|
-
} else {
|
|
85
|
-
String pluginId = postData.getString("pluginId");
|
|
86
|
-
String methodName = postData.getString("methodName");
|
|
87
|
-
JSObject methodData = postData.getJSObject("options", new JSObject());
|
|
88
|
-
|
|
89
|
-
Logger.verbose(
|
|
90
|
-
Logger.tags("Plugin"),
|
|
91
|
-
"To native (Capacitor plugin): callbackId: " + callbackId + ", pluginId: " + pluginId + ", methodName: " + methodName
|
|
92
|
-
);
|
|
66
|
+
if (type == null) type = "message";
|
|
93
67
|
|
|
94
|
-
|
|
68
|
+
Interceptor interceptor = bridge.getCallInterceptor(type);
|
|
69
|
+
if (interceptor != null) {
|
|
70
|
+
interceptor.intercept(postData);
|
|
95
71
|
}
|
|
96
72
|
} catch (Exception ex) {
|
|
97
73
|
Logger.error("Post message error:", ex);
|
|
@@ -148,10 +124,4 @@ public class MessageHandler {
|
|
|
148
124
|
PluginCall call = new PluginCall(this, pluginId, callbackId, methodName, methodData);
|
|
149
125
|
bridge.callPluginMethod(pluginId, methodName, call);
|
|
150
126
|
}
|
|
151
|
-
|
|
152
|
-
private void callCordovaPluginMethod(String callbackId, String service, String action, String actionArgs) {
|
|
153
|
-
bridge.execute(() -> {
|
|
154
|
-
cordovaPluginManager.exec(service, action, callbackId, actionArgs);
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
127
|
}
|
|
@@ -128,19 +128,6 @@ public class WebViewLocalServer {
|
|
|
128
128
|
return reasonPhrase;
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
/**
|
|
132
|
-
* @deprecated This method may return incorrect headers in concurrent range requests.
|
|
133
|
-
* <p>
|
|
134
|
-
* Use {@link #buildDefaultResponseHeaders()} instead, which returns a copy of the map.
|
|
135
|
-
* </p>
|
|
136
|
-
* This method will be removed in a future major version of Capacitor.
|
|
137
|
-
* </p>
|
|
138
|
-
*/
|
|
139
|
-
@Deprecated(forRemoval = true) // adjust version as appropriate
|
|
140
|
-
public Map<String, String> getResponseHeaders() {
|
|
141
|
-
return responseHeaders;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
131
|
public Map<String, String> buildDefaultResponseHeaders() {
|
|
145
132
|
return new HashMap<>(responseHeaders);
|
|
146
133
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
ext {
|
|
2
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.1'
|
|
3
|
+
cordovaAndroidVersion = project.hasProperty('cordovaAndroidVersion') ? rootProject.ext.cordovaAndroidVersion : '14.0.1'
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
buildscript {
|
|
7
|
+
repositories {
|
|
8
|
+
google()
|
|
9
|
+
mavenCentral()
|
|
10
|
+
}
|
|
11
|
+
dependencies {
|
|
12
|
+
classpath 'com.android.tools.build:gradle:8.13.0'
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
apply plugin: 'com.android.library'
|
|
17
|
+
|
|
18
|
+
android {
|
|
19
|
+
namespace = "com.getcapacitor.cordova"
|
|
20
|
+
compileSdk = project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
|
|
21
|
+
defaultConfig {
|
|
22
|
+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 24
|
|
23
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
|
|
24
|
+
versionCode 1
|
|
25
|
+
versionName "1.0"
|
|
26
|
+
consumerProguardFiles 'proguard-rules.pro'
|
|
27
|
+
}
|
|
28
|
+
compileOptions {
|
|
29
|
+
sourceCompatibility JavaVersion.VERSION_21
|
|
30
|
+
targetCompatibility JavaVersion.VERSION_21
|
|
31
|
+
}
|
|
32
|
+
publishing {
|
|
33
|
+
singleVariant("release")
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
repositories {
|
|
38
|
+
google()
|
|
39
|
+
mavenCentral()
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
dependencies {
|
|
43
|
+
implementation project(':capacitor-android')
|
|
44
|
+
implementation "org.apache.cordova:framework:$cordovaAndroidVersion"
|
|
45
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
package com.getcapacitor.cordova;
|
|
2
|
+
|
|
3
|
+
import android.content.Intent;
|
|
4
|
+
import android.os.Bundle;
|
|
5
|
+
import android.webkit.WebView;
|
|
6
|
+
import com.getcapacitor.Logger;
|
|
7
|
+
import com.getcapacitor.Plugin;
|
|
8
|
+
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
9
|
+
import java.util.List;
|
|
10
|
+
import org.apache.cordova.ConfigXmlParser;
|
|
11
|
+
import org.apache.cordova.CordovaInterface;
|
|
12
|
+
import org.apache.cordova.CordovaPreferences;
|
|
13
|
+
import org.apache.cordova.CordovaWebView;
|
|
14
|
+
import org.apache.cordova.PluginEntry;
|
|
15
|
+
import org.apache.cordova.PluginManager;
|
|
16
|
+
import org.json.JSONException;
|
|
17
|
+
|
|
18
|
+
@CapacitorPlugin(name = "__CordovaPlugin")
|
|
19
|
+
public class CordovaPlugin extends Plugin {
|
|
20
|
+
|
|
21
|
+
private MockCordovaInterfaceImpl cordovaInterface;
|
|
22
|
+
private CordovaWebView webView;
|
|
23
|
+
private CordovaPreferences preferences;
|
|
24
|
+
|
|
25
|
+
private boolean pluginHadActivityResult = false;
|
|
26
|
+
private boolean pluginHadPermissionResult = false;
|
|
27
|
+
|
|
28
|
+
@Override
|
|
29
|
+
public void load() {
|
|
30
|
+
ConfigXmlParser parser = new ConfigXmlParser();
|
|
31
|
+
parser.parse(getActivity().getApplicationContext());
|
|
32
|
+
preferences = parser.getPreferences();
|
|
33
|
+
preferences.setPreferencesBundle(getActivity().getIntent().getExtras());
|
|
34
|
+
List<PluginEntry> pluginEntries = parser.getPluginEntries();
|
|
35
|
+
|
|
36
|
+
cordovaInterface = new MockCordovaInterfaceImpl(getActivity());
|
|
37
|
+
|
|
38
|
+
MockCordovaWebViewImpl mockWebView = new MockCordovaWebViewImpl(getActivity().getApplicationContext());
|
|
39
|
+
mockWebView.init(cordovaInterface, pluginEntries, preferences, bridge.getWebView());
|
|
40
|
+
webView = mockWebView;
|
|
41
|
+
PluginManager pluginManager = mockWebView.getPluginManager();
|
|
42
|
+
cordovaInterface.onCordovaInit(pluginManager);
|
|
43
|
+
|
|
44
|
+
bridge.registerInterceptor("cordova", (postData) -> {
|
|
45
|
+
String callbackId = postData.getString("callbackId");
|
|
46
|
+
|
|
47
|
+
String service = postData.getString("service");
|
|
48
|
+
String action = postData.getString("action");
|
|
49
|
+
String actionArgs = postData.getString("actionArgs");
|
|
50
|
+
|
|
51
|
+
Logger.verbose(
|
|
52
|
+
Logger.tags("Plugin"),
|
|
53
|
+
"To native (Cordova plugin): callbackId: " +
|
|
54
|
+
callbackId +
|
|
55
|
+
", service: " +
|
|
56
|
+
service +
|
|
57
|
+
", action: " +
|
|
58
|
+
action +
|
|
59
|
+
", actionArgs: " +
|
|
60
|
+
actionArgs
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
bridge.execute(() -> {
|
|
64
|
+
pluginManager.exec(service, action, callbackId, actionArgs);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
@Override
|
|
70
|
+
protected void restoreState(Bundle state) {
|
|
71
|
+
if (state != null) {
|
|
72
|
+
cordovaInterface.restoreInstanceState(state);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
@Override
|
|
77
|
+
protected void handleRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
|
78
|
+
try {
|
|
79
|
+
pluginHadPermissionResult = cordovaInterface.handlePermissionResult(requestCode, permissions, grantResults);
|
|
80
|
+
} catch (JSONException e) {
|
|
81
|
+
Logger.debug("Error on Cordova plugin permissions request " + e.getMessage());
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
@Override
|
|
86
|
+
public boolean hasPermission(String permission) {
|
|
87
|
+
if (permission.equals("DisableDeploy")) {
|
|
88
|
+
return preferences.getBoolean(permission, false);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (permission.equals("KeepRunning")) {
|
|
92
|
+
return preferences.getBoolean(permission, true);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
@Override
|
|
99
|
+
public boolean hasDefinedRequiredPermissions() {
|
|
100
|
+
boolean currentPermissionResult = pluginHadPermissionResult;
|
|
101
|
+
pluginHadPermissionResult = false;
|
|
102
|
+
return currentPermissionResult;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
@Override
|
|
106
|
+
protected void handleOnActivityResult(int requestCode, int resultCode, Intent data) {
|
|
107
|
+
pluginHadActivityResult = cordovaInterface.onActivityResult(requestCode, resultCode, data);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
@Override
|
|
111
|
+
public boolean hasRequiredPermissions() {
|
|
112
|
+
boolean currentActivityResult = pluginHadActivityResult;
|
|
113
|
+
pluginHadActivityResult = false;
|
|
114
|
+
return currentActivityResult;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
@Override
|
|
118
|
+
protected void handleOnNewIntent(Intent intent) {
|
|
119
|
+
webView.onNewIntent(intent);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
@Override
|
|
123
|
+
protected void handleOnStart() {
|
|
124
|
+
webView.handleStart();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
@Override
|
|
128
|
+
protected void handleOnResume() {
|
|
129
|
+
webView.handleResume(bridge.shouldKeepRunning());
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
@Override
|
|
133
|
+
protected void handleOnPause() {
|
|
134
|
+
boolean keepRunning = bridge.shouldKeepRunning() || cordovaInterface.getActivityResultCallback() != null;
|
|
135
|
+
webView.handlePause(keepRunning);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
@Override
|
|
139
|
+
protected void handleOnStop() {
|
|
140
|
+
webView.handleStop();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
@Override
|
|
144
|
+
protected void handleOnDestroy() {
|
|
145
|
+
webView.handleDestroy();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -7,7 +7,7 @@ import org.apache.cordova.CordovaInterfaceImpl;
|
|
|
7
7
|
import org.apache.cordova.CordovaPlugin;
|
|
8
8
|
import org.json.JSONException;
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
class MockCordovaInterfaceImpl extends CordovaInterfaceImpl {
|
|
11
11
|
|
|
12
12
|
public MockCordovaInterfaceImpl(AppCompatActivity activity) {
|
|
13
13
|
super(activity, Executors.newCachedThreadPool());
|
|
@@ -20,7 +20,7 @@ import org.apache.cordova.PluginEntry;
|
|
|
20
20
|
import org.apache.cordova.PluginManager;
|
|
21
21
|
import org.apache.cordova.PluginResult;
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
class MockCordovaWebViewImpl implements CordovaWebView {
|
|
24
24
|
|
|
25
25
|
private Context context;
|
|
26
26
|
private PluginManager pluginManager;
|
|
@@ -32,7 +32,7 @@ public class MockCordovaWebViewImpl implements CordovaWebView {
|
|
|
32
32
|
private WebView webView;
|
|
33
33
|
private boolean hasPausedEver;
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
MockCordovaWebViewImpl(Context context) {
|
|
36
36
|
this.context = context;
|
|
37
37
|
}
|
|
38
38
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capacitor/android",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0-alpha.1",
|
|
4
4
|
"description": "Capacitor: Cross-platform apps with JavaScript and the web",
|
|
5
5
|
"homepage": "https://capacitorjs.com",
|
|
6
6
|
"author": "Ionic Team <hi@ionic.io> (https://ionic.io)",
|
|
@@ -17,13 +17,16 @@
|
|
|
17
17
|
"capacitor/lint-baseline.xml",
|
|
18
18
|
"capacitor/lint.xml",
|
|
19
19
|
"capacitor/proguard-rules.pro",
|
|
20
|
-
"capacitor/src/main/"
|
|
20
|
+
"capacitor/src/main/",
|
|
21
|
+
"capacitor-cordova/build.gradle",
|
|
22
|
+
"capacitor-cordova/proguard-rules.pro",
|
|
23
|
+
"capacitor-cordova/src/main/"
|
|
21
24
|
],
|
|
22
25
|
"scripts": {
|
|
23
26
|
"verify": "./gradlew clean lint build test -b capacitor/build.gradle"
|
|
24
27
|
},
|
|
25
28
|
"peerDependencies": {
|
|
26
|
-
"@capacitor/core": "^
|
|
29
|
+
"@capacitor/core": "^9.0.0-alpha.1"
|
|
27
30
|
},
|
|
28
31
|
"publishConfig": {
|
|
29
32
|
"access": "public"
|
|
File without changes
|