Skip to content

Commit cc1c265

Browse files
committed
save status
1 parent a2f7c82 commit cc1c265

File tree

8 files changed

+72
-23
lines changed

8 files changed

+72
-23
lines changed

app/build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ android {
1010
applicationId "com.proxy.shadowsocksr"
1111
minSdkVersion 17
1212
targetSdkVersion 23
13-
versionCode 4
14-
versionName "1.0.3 Beta"
13+
versionCode 5
14+
versionName "1.0.4 Beta"
1515
}
1616
buildTypes {
1717
debug {
1818
ndk {
1919
moduleName "Jni"
2020
stl "stlport_static"
21-
abiFilters "armeabi-v7a", "arm64-v8a"
21+
abiFilters "armeabi-v7a", "arm64-v8a", "x86_64"
2222
}
2323
minifyEnabled true
2424
shrinkResources true

app/src/main/assets/x86_64/pdnsd

210 KB
Binary file not shown.

app/src/main/assets/x86_64/redsocks

132 KB
Binary file not shown.

app/src/main/assets/x86_64/ss-local

663 KB
Binary file not shown.

app/src/main/assets/x86_64/ss-tunnel

651 KB
Binary file not shown.

app/src/main/assets/x86_64/tun2socks

164 KB
Binary file not shown.

app/src/main/java/com/proxy/shadowsocksr/SSRApplication.java

+39-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package com.proxy.shadowsocksr;
22

33
import android.app.Application;
4+
import android.content.pm.PackageInfo;
5+
import android.content.pm.PackageManager;
6+
import android.widget.Toast;
47

58
import com.orhanobut.hawk.Hawk;
69
import com.orhanobut.hawk.HawkBuilder;
@@ -26,6 +29,18 @@ public void init()
2629
HawkBuilder.EncryptionMethod.NO_ENCRYPTION)//TODO: VER.2.0 local profile encrypt.
2730
.build();
2831

32+
//
33+
int curVewsionCode = -1;
34+
try
35+
{
36+
PackageInfo pi = getPackageManager().getPackageInfo(getPackageName(), 0);
37+
curVewsionCode = pi.versionCode;
38+
}
39+
catch (PackageManager.NameNotFoundException ignored)
40+
{
41+
}
42+
//
43+
2944
boolean isFirstUse = Hawk.get("FirstUse", true);
3045

3146
if (isFirstUse)
@@ -38,7 +53,7 @@ public void init()
3853
"", false,
3954
Consts.defaultTcpProtocol,
4055
Consts.defaultObfsMethod,
41-
false,false);
56+
false, false);
4257
Hawk.put("Sample", dftSSRProfile);
4358

4459
ArrayList<String> svrLst = new ArrayList<>();
@@ -53,6 +68,29 @@ public void init()
5368
Hawk.put("GlobalProfile", global);
5469

5570
Hawk.put("FirstUse", false);
71+
Hawk.put("VersionCode", curVewsionCode);
72+
}
73+
else
74+
{
75+
int old = Hawk.get("VersionCode", -1);
76+
upgradeProfile(old, curVewsionCode);
77+
}
78+
}
79+
80+
private void upgradeProfile(int old, int nevv)
81+
{
82+
if (old == -1 || nevv == -1)
83+
{
84+
//clean all and re init
85+
}
86+
else if (old > nevv)
87+
{
88+
Toast.makeText(SSRApplication.this, "Downgrade is not allowed!", Toast.LENGTH_SHORT)
89+
.show();
90+
}
91+
else if (nevv > old)
92+
{
93+
//upgrade
5694
}
5795
}
5896
}

app/src/main/java/com/proxy/shadowsocksr/SSRVPNService.java

+30-19
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class SSRService extends ISSRService.Stub
122122
{
123123
proxyApps = cp.proxyApps;
124124
}
125+
//
125126
checkDaemonFile();
126127
startRunner();
127128
}
@@ -190,6 +191,13 @@ private void startRunner()
190191
vpnThread = new SSRVPNThread();
191192
vpnThread.start();
192193
//
194+
// Executors.newSingleThreadExecutor().submit(new Runnable()
195+
// {
196+
// @Override public void run()
197+
// {
198+
//
199+
// }
200+
// });
193201
new Thread(new Runnable()
194202
{
195203
@Override public void run()
@@ -270,7 +278,6 @@ private void stopRunner()
270278
vpnThread.stopThread();
271279
vpnThread = null;
272280
}
273-
274281
//reset
275282
killProcesses();
276283

@@ -301,15 +308,12 @@ private void startSSRDaemon()
301308
ssrProfile.remotePort,
302309
ssrProfile.localPort,
303310
ssrProfile.passwd,
304-
ssrProfile.cryptMethod,
305-
10);
311+
ssrProfile.cryptMethod, 10);
306312
ConfFileUtil.writeToFile(ssrconf, new File(Consts.baseDir + "ss-local-vpn.conf"));
307313

308314
StringBuilder sb = new StringBuilder();
309-
sb.append(
310-
Consts.baseDir + "ss-local -V -u -b 127.0.0.1 -t 600 -c " + Consts.baseDir +
311-
"ss-local-vpn.conf -f " + Consts.baseDir +
312-
"ss-local-vpn.pid");
315+
sb.append(Consts.baseDir + "ss-local -V -u -b 127.0.0.1 -t 600 -c " + Consts.baseDir +
316+
"ss-local-vpn.conf -f " + Consts.baseDir + "ss-local-vpn.pid");
313317

314318
//AUTH
315319

@@ -530,13 +534,14 @@ class SSRVPNThread extends Thread
530534
{
531535
try
532536
{
533-
LocalSocket ls = new LocalSocket();
534-
ls.bind(new LocalSocketAddress(Consts.baseDir + "protect_path",
535-
LocalSocketAddress.Namespace.FILESYSTEM));
536-
lss = new LocalServerSocket(ls.getFileDescriptor());
537+
LocalSocket stk = new LocalSocket();
538+
stk.bind(new LocalSocketAddress(Consts.baseDir + "protect_path",
539+
LocalSocketAddress.Namespace.FILESYSTEM));
540+
lss = new LocalServerSocket(stk.getFileDescriptor());
537541
}
538542
catch (IOException e)
539543
{
544+
Log.e("EXCE-BIND ERR", e.getMessage());
540545
return;
541546
}
542547

@@ -547,6 +552,7 @@ class SSRVPNThread extends Thread
547552
try
548553
{
549554
final LocalSocket ls = lss.accept();
555+
550556
exec.execute(new Runnable()
551557
{
552558
@SuppressWarnings("ResultOfMethodCallIgnored") @Override public void run()
@@ -560,10 +566,10 @@ class SSRVPNThread extends Thread
560566

561567
FileDescriptor[] fds = ls.getAncillaryFileDescriptors();
562568

563-
if (fds.length > 0)
569+
if (fds!=null && fds.length > 0)
564570
{
565-
Method getInt = FileDescriptor.class
566-
.getDeclaredMethod("getInt$");
571+
Method getInt = FileDescriptor.class.getDeclaredMethod(
572+
"getInt$");
567573
Integer fd = (Integer) getInt.invoke(fds[0]);
568574
boolean ret = protect(fd);
569575

@@ -573,20 +579,25 @@ class SSRVPNThread extends Thread
573579

574580
is.close();
575581
os.close();
576-
ls.close();
577582
}
578583
}
579584
catch (Exception e)
580585
{
581-
Log.e("EXCE", e.getMessage());
582-
e.printStackTrace();
586+
Log.e("EXCE-internal", e.getMessage());
587+
}
588+
try
589+
{
590+
ls.close();
591+
}
592+
catch (IOException ignored)
593+
{
583594
}
584595
}
585596
});
586597
}
587598
catch (Exception e)
588599
{
589-
Log.e("EXCE","OUT");
600+
Log.e("EXCE-accept", e.getMessage());
590601
return;
591602
}
592603
}
@@ -607,7 +618,7 @@ private void closeServerSocket()
607618
}
608619
}
609620

610-
private void stopThread()
621+
public void stopThread()
611622
{
612623
isRunning = false;
613624
closeServerSocket();

0 commit comments

Comments
 (0)