react-native-blob-util 0.22.2 → 0.23.2
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/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilConfig.java +2 -0
- package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilReq.java +74 -13
- package/index.d.ts +881 -876
- package/ios/ReactNativeBlobUtil/ReactNativeBlobUtil.mm +30 -9
- package/ios/ReactNativeBlobUtilFS.h +4 -4
- package/ios/ReactNativeBlobUtilFS.mm +115 -99
- package/package.json +1 -1
- package/react-native-blob-util.podspec +1 -1
|
@@ -14,6 +14,7 @@ class ReactNativeBlobUtilConfig {
|
|
|
14
14
|
public ReadableMap addAndroidDownloads;
|
|
15
15
|
public Boolean trusty;
|
|
16
16
|
public Boolean wifiOnly = false;
|
|
17
|
+
public String targetHostIp;
|
|
17
18
|
public String key;
|
|
18
19
|
public String mime;
|
|
19
20
|
public Boolean auto;
|
|
@@ -32,6 +33,7 @@ class ReactNativeBlobUtilConfig {
|
|
|
32
33
|
this.appendExt = options.hasKey("appendExt") ? options.getString("appendExt") : "";
|
|
33
34
|
this.trusty = options.hasKey("trusty") && options.getBoolean("trusty");
|
|
34
35
|
this.wifiOnly = options.hasKey("wifiOnly") && options.getBoolean("wifiOnly");
|
|
36
|
+
this.targetHostIp = options.hasKey("targetHostIp") ? options.getString("targetHostIp") : "";
|
|
35
37
|
if (options.hasKey("addAndroidDownloads")) {
|
|
36
38
|
this.addAndroidDownloads = options.getMap("addAndroidDownloads");
|
|
37
39
|
}
|
|
@@ -11,6 +11,9 @@ import android.net.Network;
|
|
|
11
11
|
import android.net.NetworkCapabilities;
|
|
12
12
|
import android.net.NetworkInfo;
|
|
13
13
|
import android.net.Uri;
|
|
14
|
+
import android.net.LinkProperties;
|
|
15
|
+
import android.net.LinkAddress;
|
|
16
|
+
import java.net.Inet4Address;
|
|
14
17
|
import android.os.Build;
|
|
15
18
|
import android.os.Bundle;
|
|
16
19
|
import android.os.Environment;
|
|
@@ -388,33 +391,43 @@ public class ReactNativeBlobUtilReq extends BroadcastReceiver implements Runnabl
|
|
|
388
391
|
|
|
389
392
|
// wifi only, need ACCESS_NETWORK_STATE permission
|
|
390
393
|
// and API level >= 21
|
|
394
|
+
boolean targetHostIpAvailable = (this.options.targetHostIp != null && !this.options.targetHostIp.isEmpty());
|
|
391
395
|
if (this.options.wifiOnly) {
|
|
392
|
-
|
|
393
396
|
boolean found = false;
|
|
394
397
|
|
|
395
398
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
396
399
|
ConnectivityManager connectivityManager = (ConnectivityManager) ReactNativeBlobUtilImpl.RCTContext.getSystemService(ReactNativeBlobUtilImpl.RCTContext.CONNECTIVITY_SERVICE);
|
|
397
400
|
Network[] networks = connectivityManager.getAllNetworks();
|
|
398
|
-
|
|
401
|
+
Network selectedNetwork;
|
|
402
|
+
|
|
399
403
|
for (Network network : networks) {
|
|
400
404
|
|
|
401
|
-
|
|
402
|
-
NetworkCapabilities caps = connectivityManager.getNetworkCapabilities(network);
|
|
403
|
-
|
|
404
|
-
if (caps == null || netInfo == null) {
|
|
405
|
+
if (!isValidWifiNetwork(connectivityManager, network)) {
|
|
405
406
|
continue;
|
|
406
407
|
}
|
|
407
408
|
|
|
408
|
-
if
|
|
409
|
-
|
|
410
|
-
|
|
409
|
+
// if targetHostIpAvailable does not match, fallback to any wifi
|
|
410
|
+
if (targetHostIpAvailable) {
|
|
411
|
+
String targetHostIp = this.options.targetHostIp;
|
|
411
412
|
|
|
412
|
-
|
|
413
|
+
if (networkMatchesTargetIp(connectivityManager, network, targetHostIp)) {
|
|
414
|
+
clientBuilder.proxy(Proxy.NO_PROXY);
|
|
415
|
+
clientBuilder.socketFactory(network.getSocketFactory());
|
|
416
|
+
found = true;
|
|
417
|
+
break;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// wifiOnly. selects the first interface with wifi transport
|
|
422
|
+
// if targetHostIp is available and it matches, this selection will be overriden
|
|
423
|
+
if (!found) {
|
|
413
424
|
clientBuilder.proxy(Proxy.NO_PROXY);
|
|
414
425
|
clientBuilder.socketFactory(network.getSocketFactory());
|
|
415
426
|
found = true;
|
|
416
|
-
break;
|
|
417
427
|
|
|
428
|
+
if (!targetHostIpAvailable) {
|
|
429
|
+
break;
|
|
430
|
+
}
|
|
418
431
|
}
|
|
419
432
|
}
|
|
420
433
|
|
|
@@ -423,10 +436,12 @@ public class ReactNativeBlobUtilReq extends BroadcastReceiver implements Runnabl
|
|
|
423
436
|
releaseTaskResource();
|
|
424
437
|
return;
|
|
425
438
|
}
|
|
439
|
+
|
|
440
|
+
|
|
426
441
|
} else {
|
|
427
|
-
ReactNativeBlobUtilUtils.emitWarningEvent("ReactNativeBlobUtil: wifiOnly was set, but SDK < 21. wifiOnly was ignored.");
|
|
442
|
+
ReactNativeBlobUtilUtils.emitWarningEvent("ReactNativeBlobUtil: wifiOnly or targetHostIp was set, but SDK < 21. wifiOnly was ignored.");
|
|
428
443
|
}
|
|
429
|
-
}
|
|
444
|
+
}
|
|
430
445
|
|
|
431
446
|
final Request.Builder builder = new Request.Builder();
|
|
432
447
|
try {
|
|
@@ -1011,4 +1026,50 @@ public class ReactNativeBlobUtilReq extends BroadcastReceiver implements Runnabl
|
|
|
1011
1026
|
|
|
1012
1027
|
return client;
|
|
1013
1028
|
}
|
|
1029
|
+
|
|
1030
|
+
/**
|
|
1031
|
+
* Check if a network is a valid connected WiFi network
|
|
1032
|
+
*/
|
|
1033
|
+
private boolean isValidWifiNetwork(ConnectivityManager cm, Network network) {
|
|
1034
|
+
NetworkInfo netInfo = cm.getNetworkInfo(network);
|
|
1035
|
+
NetworkCapabilities caps = cm.getNetworkCapabilities(network);
|
|
1036
|
+
|
|
1037
|
+
if (caps == null || netInfo == null) {
|
|
1038
|
+
return false;
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
if (!netInfo.isConnected()) {
|
|
1042
|
+
return false;
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
return caps.hasTransport(NetworkCapabilities.TRANSPORT_WIFI);
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
/**
|
|
1049
|
+
* Check if a network matches the target host IP address
|
|
1050
|
+
*/
|
|
1051
|
+
private boolean networkMatchesTargetIp(ConnectivityManager cm, Network network, String targetHostIp) {
|
|
1052
|
+
LinkProperties lp = cm.getLinkProperties(network);
|
|
1053
|
+
if (lp == null) return false;
|
|
1054
|
+
|
|
1055
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
1056
|
+
// For Android R and above, use DHCP server address
|
|
1057
|
+
Inet4Address dhcpServer = lp.getDhcpServerAddress();
|
|
1058
|
+
if (dhcpServer != null && dhcpServer.getHostAddress().equals(targetHostIp)) {
|
|
1059
|
+
return true;
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
// Always fall back to linkAddresses check
|
|
1064
|
+
List<LinkAddress> linkAddresses = lp.getLinkAddresses();
|
|
1065
|
+
if (linkAddresses != null && !linkAddresses.isEmpty()) {
|
|
1066
|
+
for (LinkAddress la : linkAddresses) {
|
|
1067
|
+
if (la.getAddress().getHostAddress().equals(targetHostIp)) {
|
|
1068
|
+
return true;
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
return false;
|
|
1074
|
+
}
|
|
1014
1075
|
}
|