Skip to content

Commit 213911b

Browse files
committed
🐞 fix(android): 支持 RN 0.65 版本
1. 修复编译不通过的问题 2. 添加 ACCESS_NETWORK_STATE 权限解决开启 VPN 时闪退的问题 3. 移除 armeabi,mips 相关的资源、库 4. 添加 libovpnexec.so 库
1 parent c95c435 commit 213911b

19 files changed

+26
-20
lines changed

android/src/main/AndroidManifest.xml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
package="com.norcod.rnovpn">
33

44
<uses-permission android:name="com.android.vending.BILLING" />
5+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
56
<uses-permission android:name="android.permission.WAKE_LOCK" />
67
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
78

-5.26 KB
Binary file not shown.
-5.36 KB
Binary file not shown.
-5.26 KB
Binary file not shown.
-5.36 KB
Binary file not shown.

android/src/main/java/de/blinkt/openvpn/core/NetworkSpace.java

+18-14
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
import com.norcod.rnovpn.BuildConfig;
1212

13-
import junit.framework.Assert;
14-
1513
import java.math.BigInteger;
1614
import java.net.Inet6Address;
1715
import java.util.Collection;
@@ -22,6 +20,12 @@
2220

2321
public class NetworkSpace {
2422

23+
static void assertTrue(boolean f)
24+
{
25+
if (!f)
26+
throw new IllegalStateException();
27+
}
28+
2529
static class ipAddress implements Comparable<ipAddress> {
2630
private BigInteger netAddress;
2731
public int networkMask;
@@ -141,22 +145,22 @@ public ipAddress[] split() {
141145
ipAddress firstHalf = new ipAddress(getFirstAddress(), networkMask + 1, included, isV4);
142146
ipAddress secondHalf = new ipAddress(firstHalf.getLastAddress().add(BigInteger.ONE), networkMask + 1, included, isV4);
143147
if (BuildConfig.DEBUG)
144-
Assert.assertTrue(secondHalf.getLastAddress().equals(getLastAddress()));
148+
assertTrue(secondHalf.getLastAddress().equals(getLastAddress()));
145149
return new ipAddress[]{firstHalf, secondHalf};
146150
}
147151

148152
String getIPv4Address() {
149153
if (BuildConfig.DEBUG) {
150-
Assert.assertTrue(isV4);
151-
Assert.assertTrue(netAddress.longValue() <= 0xffffffffl);
152-
Assert.assertTrue(netAddress.longValue() >= 0);
154+
assertTrue(isV4);
155+
assertTrue(netAddress.longValue() <= 0xffffffffl);
156+
assertTrue(netAddress.longValue() >= 0);
153157
}
154158
long ip = netAddress.longValue();
155159
return String.format(Locale.US, "%d.%d.%d.%d", (ip >> 24) % 256, (ip >> 16) % 256, (ip >> 8) % 256, ip % 256);
156160
}
157161

158162
String getIPv6Address() {
159-
if (BuildConfig.DEBUG) Assert.assertTrue(!isV4);
163+
if (BuildConfig.DEBUG) assertTrue(!isV4);
160164
BigInteger r = netAddress;
161165

162166
String ipv6str = null;
@@ -247,7 +251,7 @@ TreeSet<ipAddress> generateIPList() {
247251
// Check if it and the next of it are compatible
248252
ipAddress nextNet = networks.poll();
249253

250-
if (BuildConfig.DEBUG) Assert.assertNotNull(currentNet);
254+
if (BuildConfig.DEBUG) assertTrue(currentNet!=null);
251255
if (nextNet == null || currentNet.getLastAddress().compareTo(nextNet.getFirstAddress()) == -1) {
252256
// Everything good, no overlapping nothing to do
253257
ipsDone.add(currentNet);
@@ -273,7 +277,7 @@ TreeSet<ipAddress> generateIPList() {
273277

274278
if (newNets[0].getLastAddress().equals(currentNet.getLastAddress())) {
275279
if (BuildConfig.DEBUG)
276-
Assert.assertEquals(newNets[0].networkMask, currentNet.networkMask);
280+
assertTrue(newNets[0].networkMask == currentNet.networkMask);
277281
// Don't add the lower half that would conflict with currentNet
278282
} else {
279283
if (!networks.contains(newNets[0]))
@@ -283,9 +287,9 @@ TreeSet<ipAddress> generateIPList() {
283287
}
284288
} else {
285289
if (BuildConfig.DEBUG) {
286-
Assert.assertTrue(currentNet.networkMask < nextNet.networkMask);
287-
Assert.assertTrue(nextNet.getFirstAddress().compareTo(currentNet.getFirstAddress()) == 1);
288-
Assert.assertTrue(currentNet.getLastAddress().compareTo(nextNet.getLastAddress()) != -1);
290+
assertTrue(currentNet.networkMask < nextNet.networkMask);
291+
assertTrue(nextNet.getFirstAddress().compareTo(currentNet.getFirstAddress()) == 1);
292+
assertTrue(currentNet.getLastAddress().compareTo(nextNet.getLastAddress()) != -1);
289293
}
290294
// This network is bigger than the next and last ip of current >= next
291295

@@ -300,8 +304,8 @@ TreeSet<ipAddress> generateIPList() {
300304

301305
if (newNets[1].networkMask == nextNet.networkMask) {
302306
if (BuildConfig.DEBUG) {
303-
Assert.assertTrue(newNets[1].getFirstAddress().equals(nextNet.getFirstAddress()));
304-
Assert.assertTrue(newNets[1].getLastAddress().equals(currentNet.getLastAddress()));
307+
assertTrue(newNets[1].getFirstAddress().equals(nextNet.getFirstAddress()));
308+
assertTrue(newNets[1].getLastAddress().equals(currentNet.getLastAddress()));
305309
// split second equal the next network, do not add it
306310
}
307311
networks.add(nextNet);

android/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,8 @@ private void startOpenVPN() {
452452
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
453453

454454
mOvpn3 = prefs.getBoolean("ovpn3", false);
455-
if (!"ovpn3".equals(BuildConfig.FLAVOR))
456-
mOvpn3 = false;
455+
// if (!"ovpn3".equals(BuildConfig.FLAVOR))
456+
// mOvpn3 = false;
457457

458458
// Open the Management Interface
459459
if (!mOvpn3) {

android/src/main/java/de/blinkt/openvpn/core/OpenVpnManagementThread.java

-3
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
import com.norcod.rnovpn.BuildConfig;
1919
import com.norcod.rnovpn.R;
2020

21-
import junit.framework.Assert;
22-
2321
import java.io.FileDescriptor;
2422
import java.io.IOException;
2523
import java.io.InputStream;
@@ -413,7 +411,6 @@ private void processNeedCommand(String argument) {
413411
*/
414412

415413
if (routeparts.length == 5) {
416-
if (BuildConfig.DEBUG) Assert.assertEquals("dev", routeparts[3]);
417414
mOpenVPNService.addRoute(routeparts[0], routeparts[1], routeparts[2], routeparts[4]);
418415
} else if (routeparts.length >= 3) {
419416
mOpenVPNService.addRoute(routeparts[0], routeparts[1], routeparts[2], null);

android/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,18 @@ public class VPNLaunchHelper {
2929

3030

3131
private static String writeMiniVPN(Context context) {
32+
String nativeAPI = NativeUtils.getNativeAPI();
33+
/* Q does not allow executing binaries written in temp directory anymore */
34+
// compileSdkVersion < Build.VERSION_CODES.P
35+
if (Build.VERSION.SDK_INT >= 28)
36+
return new File(context.getApplicationInfo().nativeLibraryDir, "libovpnexec.so").getPath();
3237
String[] abis;
3338
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
3439
abis = getSupportedABIsLollipop();
3540
else
3641
//noinspection deprecation
3742
abis = new String[]{Build.CPU_ABI, Build.CPU_ABI2};
3843

39-
String nativeAPI = NativeUtils.getNativeAPI();
4044
if (!nativeAPI.equals(abis[0])) {
4145
VpnStatus.logWarning(R.string.abi_mismatch, Arrays.toString(abis), nativeAPI);
4246
abis = new String[] {nativeAPI};
Binary file not shown.
Binary file not shown.
-13.4 KB
Binary file not shown.
-1.45 MB
Binary file not shown.
-13.4 KB
Binary file not shown.
-5.52 KB
Binary file not shown.
-2.83 MB
Binary file not shown.
-69.6 KB
Binary file not shown.
5.48 KB
Binary file not shown.
6.09 KB
Binary file not shown.

0 commit comments

Comments
 (0)