Skip to content

Commit

Permalink
Reextract stunnel binary when the app is updated
Browse files Browse the repository at this point in the history
  • Loading branch information
comp500 committed Jun 4, 2019
1 parent f68e45d commit ce0ca2d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "link.infra.sslsocks"
minSdkVersion 19
targetSdkVersion 27
versionCode 13
versionName "0.0.13-beta"
versionCode 14
versionName "0.0.14-beta"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package link.infra.sslsocks.service;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.AssetManager;
import android.preference.PreferenceManager;
import android.util.Log;

import java.io.BufferedReader;
Expand All @@ -14,6 +16,8 @@
import java.io.OutputStream;
import java.util.Scanner;

import link.infra.sslsocks.BuildConfig;

import static link.infra.sslsocks.Constants.CONFIG;
import static link.infra.sslsocks.Constants.DEF_CONFIG;
import static link.infra.sslsocks.Constants.EXECUTABLE;
Expand All @@ -24,8 +28,20 @@ public class StunnelProcessManager {
private static final String TAG = StunnelProcessManager.class.getSimpleName();
private Process stunnelProcess;

private static boolean hasBeenUpdated(Context context) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
int versionCode = sharedPreferences.getInt("VERSION_CODE", BuildConfig.VERSION_CODE);

if (versionCode != BuildConfig.VERSION_CODE) {
sharedPreferences.edit().putInt("VERSION_CODE", BuildConfig.VERSION_CODE).apply();
return true;
}
return false;
}

public static void checkAndExtract(Context context) {
if (new File(context.getFilesDir().getPath() + "/" + EXECUTABLE).exists()) {
File currExec = new File(context.getFilesDir().getPath() + "/" + EXECUTABLE);
if (currExec.exists() && !hasBeenUpdated(context)) {
return; // already extracted
}

Expand Down Expand Up @@ -88,7 +104,7 @@ public static boolean setupConfig(Context context) {
}
}

public void start(StunnelIntentService context) {
void start(StunnelIntentService context) {
if (isAlive(context) || stunnelProcess != null) {
stop(context);
}
Expand Down

0 comments on commit ce0ca2d

Please sign in to comment.