1
1
package link .infra .sslsocks .service ;
2
2
3
3
import android .content .Context ;
4
+ import android .content .SharedPreferences ;
4
5
import android .content .res .AssetManager ;
6
+ import android .preference .PreferenceManager ;
5
7
import android .util .Log ;
6
8
7
9
import java .io .BufferedReader ;
14
16
import java .io .OutputStream ;
15
17
import java .util .Scanner ;
16
18
19
+ import link .infra .sslsocks .BuildConfig ;
20
+
17
21
import static link .infra .sslsocks .Constants .CONFIG ;
18
22
import static link .infra .sslsocks .Constants .DEF_CONFIG ;
19
23
import static link .infra .sslsocks .Constants .EXECUTABLE ;
@@ -24,8 +28,20 @@ public class StunnelProcessManager {
24
28
private static final String TAG = StunnelProcessManager .class .getSimpleName ();
25
29
private Process stunnelProcess ;
26
30
31
+ private static boolean hasBeenUpdated (Context context ) {
32
+ SharedPreferences sharedPreferences = PreferenceManager .getDefaultSharedPreferences (context );
33
+ int versionCode = sharedPreferences .getInt ("VERSION_CODE" , BuildConfig .VERSION_CODE );
34
+
35
+ if (versionCode != BuildConfig .VERSION_CODE ) {
36
+ sharedPreferences .edit ().putInt ("VERSION_CODE" , BuildConfig .VERSION_CODE ).apply ();
37
+ return true ;
38
+ }
39
+ return false ;
40
+ }
41
+
27
42
public static void checkAndExtract (Context context ) {
28
- if (new File (context .getFilesDir ().getPath () + "/" + EXECUTABLE ).exists ()) {
43
+ File currExec = new File (context .getFilesDir ().getPath () + "/" + EXECUTABLE );
44
+ if (currExec .exists () && !hasBeenUpdated (context )) {
29
45
return ; // already extracted
30
46
}
31
47
@@ -88,7 +104,7 @@ public static boolean setupConfig(Context context) {
88
104
}
89
105
}
90
106
91
- public void start (StunnelIntentService context ) {
107
+ void start (StunnelIntentService context ) {
92
108
if (isAlive (context ) || stunnelProcess != null ) {
93
109
stop (context );
94
110
}
0 commit comments