Skip to content
This repository was archived by the owner on Aug 2, 2023. It is now read-only.

Commit ce0ca2d

Browse files
committed
Reextract stunnel binary when the app is updated
1 parent f68e45d commit ce0ca2d

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

app/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android {
77
applicationId "link.infra.sslsocks"
88
minSdkVersion 19
99
targetSdkVersion 27
10-
versionCode 13
11-
versionName "0.0.13-beta"
10+
versionCode 14
11+
versionName "0.0.14-beta"
1212
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1313
vectorDrawables.useSupportLibrary = true
1414
}

app/src/main/java/link/infra/sslsocks/service/StunnelProcessManager.java

+18-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package link.infra.sslsocks.service;
22

33
import android.content.Context;
4+
import android.content.SharedPreferences;
45
import android.content.res.AssetManager;
6+
import android.preference.PreferenceManager;
57
import android.util.Log;
68

79
import java.io.BufferedReader;
@@ -14,6 +16,8 @@
1416
import java.io.OutputStream;
1517
import java.util.Scanner;
1618

19+
import link.infra.sslsocks.BuildConfig;
20+
1721
import static link.infra.sslsocks.Constants.CONFIG;
1822
import static link.infra.sslsocks.Constants.DEF_CONFIG;
1923
import static link.infra.sslsocks.Constants.EXECUTABLE;
@@ -24,8 +28,20 @@ public class StunnelProcessManager {
2428
private static final String TAG = StunnelProcessManager.class.getSimpleName();
2529
private Process stunnelProcess;
2630

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+
2742
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)) {
2945
return; // already extracted
3046
}
3147

@@ -88,7 +104,7 @@ public static boolean setupConfig(Context context) {
88104
}
89105
}
90106

91-
public void start(StunnelIntentService context) {
107+
void start(StunnelIntentService context) {
92108
if (isAlive(context) || stunnelProcess != null) {
93109
stop(context);
94110
}

0 commit comments

Comments
 (0)