diff options
Diffstat (limited to 'src/de')
-rw-r--r-- | src/de/blinkt/openvpn/LaunchVPN.java | 26 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/LogWindow.java | 24 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/VpnProfile.java | 16 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/api/ExternalOpenVPNService.java | 10 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/core/DeviceStateReceiver.java | 8 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/core/OpenVPNThread.java | 22 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/core/OpenVpnManagementThread.java | 34 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/core/OpenVpnService.java | 60 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/core/ProxyDetection.java | 4 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/core/VPNLaunchHelper.java | 12 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/core/VpnStatus.java (renamed from src/de/blinkt/openvpn/core/OpenVPN.java) | 22 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/core/X509Utils.java | 2 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/fragments/SendDumpFragment.java | 4 |
13 files changed, 125 insertions, 119 deletions
diff --git a/src/de/blinkt/openvpn/LaunchVPN.java b/src/de/blinkt/openvpn/LaunchVPN.java index 07cf323c..336de255 100644 --- a/src/de/blinkt/openvpn/LaunchVPN.java +++ b/src/de/blinkt/openvpn/LaunchVPN.java @@ -17,7 +17,6 @@ import android.os.Bundle; import android.os.Parcelable; import android.preference.PreferenceManager; import android.text.InputType; -import android.text.Layout; import android.text.TextUtils; import android.text.method.PasswordTransformationMethod; import android.view.View; @@ -26,11 +25,10 @@ import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.CheckBox; import android.widget.EditText; -import android.widget.LinearLayout; import android.widget.ListView; import android.widget.TextView; -import de.blinkt.openvpn.core.OpenVPN; -import de.blinkt.openvpn.core.OpenVPN.ConnectionStatus; +import de.blinkt.openvpn.core.VpnStatus; +import de.blinkt.openvpn.core.VpnStatus.ConnectionStatus; import de.blinkt.openvpn.core.ProfileManager; import de.blinkt.openvpn.core.VPNLaunchHelper; @@ -104,7 +102,7 @@ public class LaunchVPN extends ListActivity implements OnItemClickListener { profileToConnect = ProfileManager.getInstance(this).getProfileByName(shortcutName); if(profileToConnect ==null) { - OpenVPN.logError(R.string.shortcut_profile_notfound); + VpnStatus.logError(R.string.shortcut_profile_notfound); // show Log window to display error showLogWindow(); finish(); @@ -254,8 +252,8 @@ public class LaunchVPN extends ListActivity implements OnItemClickListener { new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - OpenVPN.updateStateString("USER_VPN_PASSWORD_CANCELLED", "", R.string.state_user_vpn_password_cancelled, - ConnectionStatus.LEVEL_NOTCONNECTED); + VpnStatus.updateStateString("USER_VPN_PASSWORD_CANCELLED", "", R.string.state_user_vpn_password_cancelled, + ConnectionStatus.LEVEL_NOTCONNECTED); finish(); } }); @@ -271,8 +269,8 @@ public class LaunchVPN extends ListActivity implements OnItemClickListener { if(resultCode == Activity.RESULT_OK) { int needpw = mSelectedProfile.needUserPWInput(); if(needpw !=0) { - OpenVPN.updateStateString("USER_VPN_PASSWORD", "", R.string.state_user_vpn_password, - ConnectionStatus.LEVEL_WAITING_FOR_USER_INPUT); + VpnStatus.updateStateString("USER_VPN_PASSWORD", "", R.string.state_user_vpn_password, + ConnectionStatus.LEVEL_WAITING_FOR_USER_INPUT); askForPW(needpw); } else { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); @@ -284,8 +282,8 @@ public class LaunchVPN extends ListActivity implements OnItemClickListener { } } else if (resultCode == Activity.RESULT_CANCELED) { // User does not want us to start, so we just vanish - OpenVPN.updateStateString("USER_VPN_PERMISSION_CANCELLED", "", R.string.state_user_vpn_permission_cancelled, - ConnectionStatus.LEVEL_NOTCONNECTED); + VpnStatus.updateStateString("USER_VPN_PERMISSION_CANCELLED", "", R.string.state_user_vpn_permission_cancelled, + ConnectionStatus.LEVEL_NOTCONNECTED); finish(); } @@ -336,15 +334,15 @@ public class LaunchVPN extends ListActivity implements OnItemClickListener { if (intent != null) { - OpenVPN.updateStateString("USER_VPN_PERMISSION", "", R.string.state_user_vpn_password, - ConnectionStatus.LEVEL_WAITING_FOR_USER_INPUT); + VpnStatus.updateStateString("USER_VPN_PERMISSION", "", R.string.state_user_vpn_password, + ConnectionStatus.LEVEL_WAITING_FOR_USER_INPUT); // Start the query try { startActivityForResult(intent, START_VPN_PROFILE); } catch (ActivityNotFoundException ane) { // Shame on you Sony! At least one user reported that // an official Sony Xperia Arc S image triggers this exception - OpenVPN.logError(R.string.no_vpn_support_image); + VpnStatus.logError(R.string.no_vpn_support_image); showLogWindow(); } } else { diff --git a/src/de/blinkt/openvpn/LogWindow.java b/src/de/blinkt/openvpn/LogWindow.java index 10f3c0ab..7eadfe60 100644 --- a/src/de/blinkt/openvpn/LogWindow.java +++ b/src/de/blinkt/openvpn/LogWindow.java @@ -13,11 +13,11 @@ import android.text.format.DateFormat; import android.view.*; import android.widget.*; import android.widget.AdapterView.OnItemLongClickListener; -import de.blinkt.openvpn.core.OpenVPN; -import de.blinkt.openvpn.core.OpenVPN.ConnectionStatus; -import de.blinkt.openvpn.core.OpenVPN.LogItem; -import de.blinkt.openvpn.core.OpenVPN.LogListener; -import de.blinkt.openvpn.core.OpenVPN.StateListener; +import de.blinkt.openvpn.core.VpnStatus; +import de.blinkt.openvpn.core.VpnStatus.ConnectionStatus; +import de.blinkt.openvpn.core.VpnStatus.LogItem; +import de.blinkt.openvpn.core.VpnStatus.LogListener; +import de.blinkt.openvpn.core.VpnStatus.StateListener; import de.blinkt.openvpn.core.OpenVpnService; import de.blinkt.openvpn.core.OpenVpnService.LocalBinder; import de.blinkt.openvpn.core.ProfileManager; @@ -77,14 +77,14 @@ public class LogWindow extends ListActivity implements StateListener { mHandler = new Handler(this); } - OpenVPN.addLogListener(this); + VpnStatus.addLogListener(this); } private void initLogBuffer() { myEntries.clear(); - Collections.addAll(myEntries, OpenVPN.getlogbuffer()); + Collections.addAll(myEntries, VpnStatus.getlogbuffer()); } String getLogStr() { @@ -224,8 +224,8 @@ public class LogWindow extends ListActivity implements StateListener { void clearLog() { // Actually is probably called from GUI Thread as result of the user // pressing a button. But better safe than sorry - OpenVPN.clearLog(); - OpenVPN.logMessage(0,"","Log cleared."); + VpnStatus.clearLog(); + VpnStatus.logMessage(0, "", "Log cleared."); mHandler.sendEmptyMessage(MESSAGE_CLEARLOG); } @@ -312,7 +312,7 @@ public class LogWindow extends ListActivity implements StateListener { @Override protected void onResume() { super.onResume(); - OpenVPN.addStateListener(this); + VpnStatus.addStateListener(this); Intent intent = new Intent(this, OpenVpnService.class); intent.setAction(OpenVpnService.START_SERVICE); @@ -367,7 +367,7 @@ public class LogWindow extends ListActivity implements StateListener { @Override protected void onStop() { super.onStop(); - OpenVPN.removeStateListener(this); + VpnStatus.removeStateListener(this); unbindService(mConnection); getPreferences(0).edit().putInt(LOGTIMEFORMAT, ladapter.mTimeFormat).apply(); @@ -424,7 +424,7 @@ public class LogWindow extends ListActivity implements StateListener { @Override protected void onDestroy() { - OpenVPN.removeLogListener(ladapter); + VpnStatus.removeLogListener(ladapter); super.onDestroy(); } diff --git a/src/de/blinkt/openvpn/VpnProfile.java b/src/de/blinkt/openvpn/VpnProfile.java index 138386ae..a8c6825f 100644 --- a/src/de/blinkt/openvpn/VpnProfile.java +++ b/src/de/blinkt/openvpn/VpnProfile.java @@ -14,7 +14,7 @@ import android.util.Base64; import android.widget.Toast; import de.blinkt.openvpn.core.NativeUtils; -import de.blinkt.openvpn.core.OpenVPN; +import de.blinkt.openvpn.core.VpnStatus; import de.blinkt.openvpn.core.OpenVpnService; import de.blinkt.openvpn.core.X509Utils; import org.spongycastle.util.io.pem.PemObject; @@ -549,7 +549,7 @@ public class VpnProfile implements Serializable { return getKeyStoreCertificates(context, 5); } - String[] getKeyStoreCertificates(Context context,int tries) { + synchronized String[] getKeyStoreCertificates(Context context,int tries) { PrivateKey privateKey = null; X509Certificate[] cachain; try { @@ -561,7 +561,7 @@ public class VpnProfile implements Serializable { cachain = KeyChain.getCertificateChain(context, mAlias); if (cachain.length <= 1 && !nonNull(mCaFilename)) { - OpenVPN.logMessage(0, "", context.getString(R.string.keychain_nocacert)); + VpnStatus.logMessage(0, "", context.getString(R.string.keychain_nocacert)); } else { StringWriter ksStringWriter = new StringWriter(); @@ -587,7 +587,7 @@ public class VpnProfile implements Serializable { caout= caoutWriter.toString(); } catch (Exception e) { - OpenVPN.logError("Could not read CA certificate" + e.getLocalizedMessage()); + VpnStatus.logError("Could not read CA certificate" + e.getLocalizedMessage()); } } @@ -625,10 +625,10 @@ public class VpnProfile implements Serializable { } catch (IOException e) { e.printStackTrace(); } catch (KeyChainException e) { - OpenVPN.logMessage(0, "", context.getString(R.string.keychain_access)); + VpnStatus.logMessage(0, "", context.getString(R.string.keychain_access)); if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN) { if (!mAlias.matches("^[a-zA-Z0-9]$")) { - OpenVPN.logError(R.string.jelly_keystore_alphanumeric_bug); + VpnStatus.logError(R.string.jelly_keystore_alphanumeric_bug); } } } catch (AssertionError e) { @@ -814,7 +814,7 @@ public class VpnProfile implements Serializable { err = e; } - OpenVPN.logError(R.string.error_rsa_sign, err.getClass().toString(), err.getLocalizedMessage()); + VpnStatus.logError(R.string.error_rsa_sign, err.getClass().toString(), err.getLocalizedMessage()); return null; @@ -852,7 +852,7 @@ public class VpnProfile implements Serializable { } catch (InvalidKeyException e) { err = e; } - OpenVPN.logError(R.string.error_rsa_sign, err.getClass().toString(), err.getLocalizedMessage()); + VpnStatus.logError(R.string.error_rsa_sign, err.getClass().toString(), err.getLocalizedMessage()); return null; diff --git a/src/de/blinkt/openvpn/api/ExternalOpenVPNService.java b/src/de/blinkt/openvpn/api/ExternalOpenVPNService.java index 35374c77..77374355 100644 --- a/src/de/blinkt/openvpn/api/ExternalOpenVPNService.java +++ b/src/de/blinkt/openvpn/api/ExternalOpenVPNService.java @@ -25,9 +25,9 @@ import de.blinkt.openvpn.R; import de.blinkt.openvpn.VpnProfile;
import de.blinkt.openvpn.core.ConfigParser;
import de.blinkt.openvpn.core.ConfigParser.ConfigParseError;
-import de.blinkt.openvpn.core.OpenVPN;
-import de.blinkt.openvpn.core.OpenVPN.ConnectionStatus;
-import de.blinkt.openvpn.core.OpenVPN.StateListener;
+import de.blinkt.openvpn.core.VpnStatus;
+import de.blinkt.openvpn.core.VpnStatus.ConnectionStatus;
+import de.blinkt.openvpn.core.VpnStatus.StateListener;
import de.blinkt.openvpn.core.OpenVpnService;
import de.blinkt.openvpn.core.OpenVpnService.LocalBinder;
import de.blinkt.openvpn.core.ProfileManager;
@@ -65,7 +65,7 @@ public class ExternalOpenVPNService extends Service implements StateListener { @Override
public void onCreate() {
super.onCreate();
- OpenVPN.addStateListener(this);
+ VpnStatus.addStateListener(this);
mExtAppDb = new ExternalAppDatabase(this);
Intent intent = new Intent(getBaseContext(), OpenVpnService.class);
@@ -231,7 +231,7 @@ public class ExternalOpenVPNService extends Service implements StateListener { super.onDestroy();
mCallbacks.kill();
unbindService(mConnection);
- OpenVPN.removeStateListener(this);
+ VpnStatus.removeStateListener(this);
}
class UpdateMessage {
diff --git a/src/de/blinkt/openvpn/core/DeviceStateReceiver.java b/src/de/blinkt/openvpn/core/DeviceStateReceiver.java index 2c1db63c..8a148e10 100644 --- a/src/de/blinkt/openvpn/core/DeviceStateReceiver.java +++ b/src/de/blinkt/openvpn/core/DeviceStateReceiver.java @@ -9,7 +9,7 @@ import android.net.NetworkInfo; import android.net.NetworkInfo.State;
import android.preference.PreferenceManager;
import de.blinkt.openvpn.R;
-import de.blinkt.openvpn.core.OpenVPN.ByteCountListener;
+import de.blinkt.openvpn.core.VpnStatus.ByteCountListener;
import java.util.LinkedList;
@@ -67,7 +67,7 @@ public class DeviceStateReceiver extends BroadcastReceiver implements ByteCountL if (windowtraffic < TRAFFIC_LIMIT) {
screen = connectState.DISCONNECTED;
- OpenVPN.logInfo(R.string.screenoff_pause,
+ VpnStatus.logInfo(R.string.screenoff_pause,
OpenVpnService.humanReadableByteCount(TRAFFIC_LIMIT, false), TRAFFIC_WINDOW);
mManagement.pause(getPauseReason());
@@ -109,7 +109,7 @@ public class DeviceStateReceiver extends BroadcastReceiver implements ByteCountL if (screenOffPause) {
if (!ProfileManager.getLastConnectedVpn().mPersistTun)
- OpenVPN.logError(R.string.screen_nopersistenttun);
+ VpnStatus.logError(R.string.screen_nopersistenttun);
screen = connectState.PENDINGDISCONNECT;
fillTrafficData();
@@ -203,7 +203,7 @@ public class DeviceStateReceiver extends BroadcastReceiver implements ByteCountL if (!netstatestring.equals(lastStateMsg))
- OpenVPN.logInfo(R.string.netstatus, netstatestring);
+ VpnStatus.logInfo(R.string.netstatus, netstatestring);
lastStateMsg = netstatestring;
}
diff --git a/src/de/blinkt/openvpn/core/OpenVPNThread.java b/src/de/blinkt/openvpn/core/OpenVPNThread.java index 100990bb..da6a394a 100644 --- a/src/de/blinkt/openvpn/core/OpenVPNThread.java +++ b/src/de/blinkt/openvpn/core/OpenVPNThread.java @@ -3,8 +3,8 @@ package de.blinkt.openvpn.core; import android.util.Log;
import de.blinkt.openvpn.R;
import de.blinkt.openvpn.VpnProfile;
-import de.blinkt.openvpn.core.OpenVPN.ConnectionStatus;
-import de.blinkt.openvpn.core.OpenVPN.LogItem;
+import de.blinkt.openvpn.core.VpnStatus.ConnectionStatus;
+import de.blinkt.openvpn.core.VpnStatus.LogItem;
import java.io.*;
import java.text.SimpleDateFormat;
@@ -50,26 +50,26 @@ public class OpenVPNThread implements Runnable { if (mProcess!=null)
exitvalue = mProcess.waitFor();
} catch ( IllegalThreadStateException ite) {
- OpenVPN.logError("Illegal Thread state: " + ite.getLocalizedMessage());
+ VpnStatus.logError("Illegal Thread state: " + ite.getLocalizedMessage());
} catch (InterruptedException ie) {
- OpenVPN.logError("InterruptedException: " + ie.getLocalizedMessage());
+ VpnStatus.logError("InterruptedException: " + ie.getLocalizedMessage());
}
if( exitvalue != 0)
- OpenVPN.logError("Process exited with exit value " + exitvalue);
+ VpnStatus.logError("Process exited with exit value " + exitvalue);
- OpenVPN.updateStateString("NOPROCESS","No process running.", R.string.state_noprocess,ConnectionStatus.LEVEL_NOTCONNECTED);
+ VpnStatus.updateStateString("NOPROCESS", "No process running.", R.string.state_noprocess, ConnectionStatus.LEVEL_NOTCONNECTED);
if(mDumpPath!=null) {
try {
BufferedWriter logout = new BufferedWriter(new FileWriter(mDumpPath + ".log"));
SimpleDateFormat timeformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",Locale.GERMAN);
- for(LogItem li :OpenVPN.getlogbuffer()){
+ for(LogItem li : VpnStatus.getlogbuffer()){
String time = timeformat.format(new Date(li.getLogtime()));
logout.write(time +" " + li.getString(mService) + "\n");
}
logout.close();
- OpenVPN.logError(R.string.minidump_generated);
+ VpnStatus.logError(R.string.minidump_generated);
} catch (IOException e) {
- OpenVPN.logError("Writing minidump log: " +e.getLocalizedMessage());
+ VpnStatus.logError("Writing minidump log: " + e.getLocalizedMessage());
}
}
@@ -111,12 +111,12 @@ public class OpenVPNThread implements Runnable { mDumpPath = logline.substring(DUMP_PATH_STRING.length());
- OpenVPN.logMessage(0, "P:", logline);
+ VpnStatus.logMessage(0, "P:", logline);
}
} catch (IOException e) {
- OpenVPN.logMessage(0, "", "Error reading from output of OpenVPN process"+ e.getLocalizedMessage());
+ VpnStatus.logMessage(0, "", "Error reading from output of OpenVPN process" + e.getLocalizedMessage());
e.printStackTrace();
stopProcess();
}
diff --git a/src/de/blinkt/openvpn/core/OpenVpnManagementThread.java b/src/de/blinkt/openvpn/core/OpenVpnManagementThread.java index e2ac1526..7e436f79 100644 --- a/src/de/blinkt/openvpn/core/OpenVpnManagementThread.java +++ b/src/de/blinkt/openvpn/core/OpenVpnManagementThread.java @@ -13,7 +13,7 @@ import org.jetbrains.annotations.NotNull; import de.blinkt.openvpn.R;
import de.blinkt.openvpn.VpnProfile;
-import de.blinkt.openvpn.core.OpenVPN.ConnectionStatus;
+import de.blinkt.openvpn.core.VpnStatus.ConnectionStatus;
import java.io.FileDescriptor;
import java.io.IOException;
@@ -131,7 +131,7 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement { try {
fds = mSocket.getAncillaryFileDescriptors();
} catch (IOException e) {
- OpenVPN.logMessage(0, "", "Error reading fds from socket" + e.getLocalizedMessage());
+ VpnStatus.logMessage(0, "", "Error reading fds from socket" + e.getLocalizedMessage());
e.printStackTrace();
}
if(fds!=null){
@@ -182,7 +182,7 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement { exp.printStackTrace();
Log.d("Openvpn", "Failed to retrieve fd from socket: " + fd);
- OpenVPN.logMessage(0, "", "Failed to retrieve fd from socket: " + exp.getLocalizedMessage());
+ VpnStatus.logMessage(0, "", "Failed to retrieve fd from socket: " + exp.getLocalizedMessage());
}
private String processInput(String pendingInput) {
@@ -228,11 +228,11 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement { // 0 unix time stamp
// 1 log level N,I,E etc.
// 2 log message
- OpenVPN.logMessage(0, "", args[2]);
+ VpnStatus.logMessage(0, "", args[2]);
} else if (cmd.equals("RSA_SIGN")) {
processSignCommand(argument);
} else {
- OpenVPN.logMessage(0, "MGMT:", "Got unrecognized command" + command);
+ VpnStatus.logMessage(0, "MGMT:", "Got unrecognized command" + command);
Log.i(TAG, "Got unrecognized command" + command);
}
} else if (command.startsWith("SUCCESS:")) {
@@ -240,7 +240,7 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement { return;
} else {
Log.i(TAG, "Got unrecognized line from managment" + command);
- OpenVPN.logMessage(0, "MGMT:", "Got unrecognized line from management:" + command);
+ VpnStatus.logMessage(0, "MGMT:", "Got unrecognized line from management:" + command);
}
}
private void handleHold() {
@@ -249,7 +249,7 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement { } else {
mWaitingForRelease=true;
- OpenVPN.updateStatePause(lastPauseReason);
+ VpnStatus.updateStatePause(lastPauseReason);
}
@@ -292,7 +292,7 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement { if(proxyaddr instanceof InetSocketAddress ){
InetSocketAddress isa = (InetSocketAddress) proxyaddr;
- OpenVPN.logInfo(R.string.using_proxy, isa.getHostName(),isa.getPort());
+ VpnStatus.logInfo(R.string.using_proxy, isa.getHostName(), isa.getPort());
String proxycmd = String.format(Locale.ENGLISH,"proxy HTTP %s %d\n", isa.getHostName(),isa.getPort());
managmentCommand(proxycmd);
@@ -305,9 +305,9 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement { String[] args = argument.split(",",3);
String currentstate = args[1];
if(args[2].equals(",,"))
- OpenVPN.updateStateString(currentstate,"");
+ VpnStatus.updateStateString(currentstate, "");
else
- OpenVPN.updateStateString(currentstate,args[2]);
+ VpnStatus.updateStateString(currentstate, args[2]);
}
@@ -317,7 +317,7 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement { long in = Long.parseLong(argument.substring(0, comma));
long out = Long.parseLong(argument.substring(comma+1));
- OpenVPN.updateByteCount(in,out);
+ VpnStatus.updateByteCount(in, out);
}
@@ -373,7 +373,7 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement { if(!extra.equals("tun")) {
// We only support tun
String errmsg = String.format("Devicetype %s requested, but only tun is possible with the Android API, sorry!",extra);
- OpenVPN.logMessage(0, "", errmsg );
+ VpnStatus.logMessage(0, "", errmsg);
return false;
}
@@ -416,7 +416,7 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement { } catch (IOException e) {
exp =e;
}
- OpenVPN.logMessage(0, "", "Could not send fd over socket:" + exp.getLocalizedMessage());
+ VpnStatus.logMessage(0, "", "Could not send fd over socket:" + exp.getLocalizedMessage());
exp.printStackTrace();
return false;
@@ -439,7 +439,7 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement { return;
}
} catch (StringIndexOutOfBoundsException sioob) {
- OpenVPN.logMessage(0, "", "Could not parse management Password command: " + argument);
+ VpnStatus.logMessage(0, "", "Could not parse management Password command: " + argument);
return;
}
@@ -457,7 +457,7 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement { String cmd = String.format("password '%s' %s\n", needed, VpnProfile.openVpnEscape(pw));
managmentCommand(cmd);
} else {
- OpenVPN.logMessage(0, OpenVPN.MANAGMENT_PREFIX, String.format("Openvpn requires Authentication type '%s' but no password/key information available", needed));
+ VpnStatus.logMessage(0, VpnStatus.MANAGMENT_PREFIX, String.format("Openvpn requires Authentication type '%s' but no password/key information available", needed));
}
}
@@ -466,7 +466,7 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement { private void proccessPWFailed(String needed, String args) {
- OpenVPN.updateStateString("AUTH_FAILED", needed + args,R.string.state_auth_failed,ConnectionStatus.LEVEL_AUTH_FAILED);
+ VpnStatus.updateStateString("AUTH_FAILED", needed + args, R.string.state_auth_failed, ConnectionStatus.LEVEL_AUTH_FAILED);
}
@@ -493,7 +493,7 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement { else
// If signalusr1 is called update the state string
// if there is another for stopping
- OpenVPN.updateStatePause(lastPauseReason);
+ VpnStatus.updateStatePause(lastPauseReason);
}
public void reconnect() {
diff --git a/src/de/blinkt/openvpn/core/OpenVpnService.java b/src/de/blinkt/openvpn/core/OpenVpnService.java index e703e579..37c0d94f 100644 --- a/src/de/blinkt/openvpn/core/OpenVpnService.java +++ b/src/de/blinkt/openvpn/core/OpenVpnService.java @@ -17,9 +17,9 @@ import android.preference.PreferenceManager; import de.blinkt.openvpn.LogWindow; import de.blinkt.openvpn.R; import de.blinkt.openvpn.VpnProfile; -import de.blinkt.openvpn.core.OpenVPN.ByteCountListener; -import de.blinkt.openvpn.core.OpenVPN.ConnectionStatus; -import de.blinkt.openvpn.core.OpenVPN.StateListener; +import de.blinkt.openvpn.core.VpnStatus.ByteCountListener; +import de.blinkt.openvpn.core.VpnStatus.ConnectionStatus; +import de.blinkt.openvpn.core.VpnStatus.StateListener; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -27,7 +27,7 @@ import java.util.HashMap; import java.util.Locale; import java.util.Vector; -import static de.blinkt.openvpn.core.OpenVPN.ConnectionStatus.*; +import static de.blinkt.openvpn.core.VpnStatus.ConnectionStatus.*; public class OpenVpnService extends VpnService implements StateListener, Callback, ByteCountListener { public static final String START_SERVICE = "de.blinkt.openvpn.START_SERVICE"; @@ -93,7 +93,7 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac private void endVpnService() { mProcessThread = null; - OpenVPN.removeByteCountListener(this); + VpnStatus.removeByteCountListener(this); unregisterDeviceStateReceiver(); ProfileManager.setConntectedVpnProfileDisconnected(this); if (!mStarting) { @@ -101,7 +101,7 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac if (!mNotificationAlwaysVisible) { stopSelf(); - OpenVPN.removeStateListener(this); + VpnStatus.removeStateListener(this); } } } @@ -235,13 +235,13 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac filter.addAction(Intent.ACTION_SCREEN_ON); mDeviceStateReceiver = new DeviceStateReceiver(magnagement); registerReceiver(mDeviceStateReceiver, filter); - OpenVPN.addByteCountListener(mDeviceStateReceiver); + VpnStatus.addByteCountListener(mDeviceStateReceiver); } synchronized void unregisterDeviceStateReceiver() { if (mDeviceStateReceiver != null) try { - OpenVPN.removeByteCountListener(mDeviceStateReceiver); + VpnStatus.removeByteCountListener(mDeviceStateReceiver); this.unregisterReceiver(mDeviceStateReceiver); } catch (IllegalArgumentException iae) { // I don't know why this happens: @@ -258,8 +258,8 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac if (intent != null && intent.getBooleanExtra(ALWAYS_SHOW_NOTIFICATION, false)) mNotificationAlwaysVisible = true; - OpenVPN.addStateListener(this); - OpenVPN.addByteCountListener(this); + VpnStatus.addStateListener(this); + VpnStatus.addByteCountListener(this); if (intent != null && PAUSE_VPN.equals(intent.getAction())) { if (mDeviceStateReceiver != null) @@ -329,7 +329,7 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac Thread mSocketManagerThread = new Thread(ovpnManagementThread, "OpenVPNManagementThread"); mSocketManagerThread.start(); mManagement = ovpnManagementThread; - OpenVPN.logInfo("started Socket Thread"); + VpnStatus.logInfo("started Socket Thread"); } } @@ -381,7 +381,7 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac this.unregisterReceiver(mDeviceStateReceiver); } // Just in case unregister for state - OpenVPN.removeStateListener(this); + VpnStatus.removeStateListener(this); } @@ -389,7 +389,7 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac Builder builder = new Builder(); if (mLocalIP == null && mLocalIPv6 == null) { - OpenVPN.logMessage(0, "", getString(R.string.opentun_no_ipaddr)); + VpnStatus.logMessage(0, "", getString(R.string.opentun_no_ipaddr)); return null; } @@ -397,7 +397,7 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac try { builder.addAddress(mLocalIP.mIp, mLocalIP.len); } catch (IllegalArgumentException iae) { - OpenVPN.logError(R.string.dns_add_error, mLocalIP, iae.getLocalizedMessage()); + VpnStatus.logError(R.string.dns_add_error, mLocalIP, iae.getLocalizedMessage()); return null; } } @@ -407,7 +407,7 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac try { builder.addAddress(ipv6parts[0], Integer.parseInt(ipv6parts[1])); } catch (IllegalArgumentException iae) { - OpenVPN.logError(R.string.dns_add_error, mLocalIPv6, iae.getLocalizedMessage()); + VpnStatus.logError(R.string.ip_add_error, mLocalIPv6, iae.getLocalizedMessage()); return null; } @@ -418,7 +418,7 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac try { builder.addDnsServer(dns); } catch (IllegalArgumentException iae) { - OpenVPN.logError(R.string.dns_add_error, dns, iae.getLocalizedMessage()); + VpnStatus.logError(R.string.dns_add_error, dns, iae.getLocalizedMessage()); } } @@ -430,7 +430,7 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac try { builder.addRoute(route.mIp, route.len); } catch (IllegalArgumentException ia) { - OpenVPN.logMessage(0, "", getString(R.string.route_rejected) + route + " " + ia.getLocalizedMessage()); + VpnStatus.logMessage(0, "", getString(R.string.route_rejected) + route + " " + ia.getLocalizedMessage()); } } @@ -439,18 +439,18 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac String[] v6parts = v6route.split("/"); builder.addRoute(v6parts[0], Integer.parseInt(v6parts[1])); } catch (IllegalArgumentException ia) { - OpenVPN.logMessage(0, "", getString(R.string.route_rejected) + v6route + " " + ia.getLocalizedMessage()); + VpnStatus.logMessage(0, "", getString(R.string.route_rejected) + v6route + " " + ia.getLocalizedMessage()); } } if (mDomain != null) builder.addSearchDomain(mDomain); - OpenVPN.logInfo(R.string.last_openvpn_tun_config); - OpenVPN.logInfo(R.string.local_ip_info, mLocalIP.mIp, mLocalIP.len, mLocalIPv6, mMtu); - OpenVPN.logInfo(R.string.dns_server_info, joinString(mDnslist), mDomain); - OpenVPN.logInfo(R.string.routes_info, joinString(mRoutes)); - OpenVPN.logInfo(R.string.routes_info6, joinString(mRoutesv6)); + VpnStatus.logInfo(R.string.last_openvpn_tun_config); + VpnStatus.logInfo(R.string.local_ip_info, mLocalIP.mIp, mLocalIP.len, mLocalIPv6, mMtu); + VpnStatus.logInfo(R.string.dns_server_info, joinString(mDnslist), mDomain); + VpnStatus.logInfo(R.string.routes_info, joinString(mRoutes)); + VpnStatus.logInfo(R.string.routes_info6, joinString(mRoutesv6)); String session = mProfile.mName; if (mLocalIP != null && mLocalIPv6 != null) @@ -462,7 +462,7 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac // No DNS Server, log a warning if (mDnslist.size() == 0) - OpenVPN.logInfo(R.string.warn_no_dns); + VpnStatus.logInfo(R.string.warn_no_dns); // Reset information mDnslist.clear(); @@ -477,9 +477,9 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac try { return builder.establish(); } catch (Exception e) { - OpenVPN.logMessage(0, "", getString(R.string.tun_open_error)); - OpenVPN.logMessage(0, "", getString(R.string.error) + e.getLocalizedMessage()); - OpenVPN.logMessage(0, "", getString(R.string.tun_error_helpful)); + VpnStatus.logMessage(0, "", getString(R.string.tun_open_error)); + VpnStatus.logMessage(0, "", getString(R.string.error) + e.getLocalizedMessage()); + VpnStatus.logMessage(0, "", getString(R.string.tun_error_helpful)); return null; } @@ -510,11 +510,11 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac public void addRoute(String dest, String mask) { CIDRIP route = new CIDRIP(dest, mask); if (route.len == 32 && !mask.equals("255.255.255.255")) { - OpenVPN.logMessage(0, "", getString(R.string.route_not_cidr, dest, mask)); + VpnStatus.logMessage(0, "", getString(R.string.route_not_cidr, dest, mask)); } if (route.normalise()) - OpenVPN.logMessage(0, "", getString(R.string.route_not_netip, dest, route.len, route.mIp)); + VpnStatus.logMessage(0, "", getString(R.string.route_not_netip, dest, route.len, route.mIp)); mRoutes.add(route); } @@ -544,7 +544,7 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac else mLocalIP.len = 31; } else { - OpenVPN.logMessage(0, "", getString(R.string.ip_not_cidr, local, netmask, mode)); + VpnStatus.logMessage(0, "", getString(R.string.ip_not_cidr, local, netmask, mode)); } } } diff --git a/src/de/blinkt/openvpn/core/ProxyDetection.java b/src/de/blinkt/openvpn/core/ProxyDetection.java index bc8bf293..4f66c503 100644 --- a/src/de/blinkt/openvpn/core/ProxyDetection.java +++ b/src/de/blinkt/openvpn/core/ProxyDetection.java @@ -27,9 +27,9 @@ public class ProxyDetection { } } catch (MalformedURLException e) { - OpenVPN.logError(R.string.getproxy_error,e.getLocalizedMessage()); + VpnStatus.logError(R.string.getproxy_error, e.getLocalizedMessage()); } catch (URISyntaxException e) { - OpenVPN.logError(R.string.getproxy_error,e.getLocalizedMessage()); + VpnStatus.logError(R.string.getproxy_error, e.getLocalizedMessage()); } return null; } diff --git a/src/de/blinkt/openvpn/core/VPNLaunchHelper.java b/src/de/blinkt/openvpn/core/VPNLaunchHelper.java index 7d14ee6b..f6e8e0e3 100644 --- a/src/de/blinkt/openvpn/core/VPNLaunchHelper.java +++ b/src/de/blinkt/openvpn/core/VPNLaunchHelper.java @@ -26,7 +26,7 @@ public class VPNLaunchHelper { mvpn = context.getAssets().open("minivpn." + Build.CPU_ABI); } catch (IOException errabi) { - OpenVPN.logInfo("Failed getting assets for archicture " + Build.CPU_ABI); + VpnStatus.logInfo("Failed getting assets for archicture " + Build.CPU_ABI); e2=errabi; mvpn = context.getAssets().open("minivpn." + Build.CPU_ABI2); @@ -45,7 +45,7 @@ public class VPNLaunchHelper { fout.close(); if(!mvpnout.setExecutable(true)) { - OpenVPN.logMessage(0, "","Failed to set minivpn executable"); + VpnStatus.logMessage(0, "", "Failed to set minivpn executable"); return false; } @@ -53,8 +53,8 @@ public class VPNLaunchHelper { return true; } catch (IOException e) { if(e2!=null) - OpenVPN.logMessage(0, "",e2.getLocalizedMessage()); - OpenVPN.logMessage(0, "",e.getLocalizedMessage()); + VpnStatus.logMessage(0, "", e2.getLocalizedMessage()); + VpnStatus.logMessage(0, "", e.getLocalizedMessage()); e.printStackTrace(); return false; } @@ -63,10 +63,10 @@ public class VPNLaunchHelper { public static void startOpenVpn(VpnProfile startprofile, Context context) { if(!writeMiniVPN(context)) { - OpenVPN.logMessage(0, "", "Error writing minivpn binary"); + VpnStatus.logMessage(0, "", "Error writing minivpn binary"); return; } - OpenVPN.logMessage(0, "", context.getString(R.string.building_configration)); + VpnStatus.logMessage(0, "", context.getString(R.string.building_configration)); Intent startVPN = startprofile.prepareIntent(context); if(startVPN!=null) diff --git a/src/de/blinkt/openvpn/core/OpenVPN.java b/src/de/blinkt/openvpn/core/VpnStatus.java index af090204..86f0f727 100644 --- a/src/de/blinkt/openvpn/core/OpenVPN.java +++ b/src/de/blinkt/openvpn/core/VpnStatus.java @@ -20,9 +20,10 @@ import java.security.cert.X509Certificate; import java.util.Arrays; import java.util.LinkedList; import java.util.Locale; +import java.util.UnknownFormatConversionException; import java.util.Vector; -public class OpenVPN { +public class VpnStatus { public static LinkedList<LogItem> logbuffer; @@ -61,9 +62,9 @@ public class OpenVPN { static { logbuffer = new LinkedList<LogItem>(); - logListener = new Vector<OpenVPN.LogListener>(); - stateListener = new Vector<OpenVPN.StateListener>(); - byteCountListener = new Vector<OpenVPN.ByteCountListener>(); + logListener = new Vector<VpnStatus.LogListener>(); + stateListener = new Vector<VpnStatus.StateListener>(); + byteCountListener = new Vector<VpnStatus.ByteCountListener>(); logInformation(); } @@ -142,6 +143,7 @@ public class OpenVPN { } public String getString(Context c) { + try { if(mMessage !=null) { return mMessage; } else { @@ -161,6 +163,12 @@ public class OpenVPN { return str; } } + } catch (UnknownFormatConversionException e) { + if (c != null) + throw new UnknownFormatConversionException(e.getLocalizedMessage() + getString(null)); + else + throw e; + } } // The lint is wrong here @@ -304,13 +312,13 @@ public class OpenVPN { public static void updateStatePause(OpenVPNManagement.pauseReason pauseReason) { switch (pauseReason) { case noNetwork: - OpenVPN.updateStateString("NONETWORK", "", R.string.state_nonetwork, ConnectionStatus.LEVEL_NONETWORK); + VpnStatus.updateStateString("NONETWORK", "", R.string.state_nonetwork, ConnectionStatus.LEVEL_NONETWORK); break; case screenOff: - OpenVPN.updateStateString("SCREENOFF", "", R.string.state_screenoff, ConnectionStatus.LEVEL_VPNPAUSED); + VpnStatus.updateStateString("SCREENOFF", "", R.string.state_screenoff, ConnectionStatus.LEVEL_VPNPAUSED); break; case userPause: - OpenVPN.updateStateString("USERPAUSE", "", R.string.state_userpause, ConnectionStatus.LEVEL_VPNPAUSED); + VpnStatus.updateStateString("USERPAUSE", "", R.string.state_userpause, ConnectionStatus.LEVEL_VPNPAUSED); break; } diff --git a/src/de/blinkt/openvpn/core/X509Utils.java b/src/de/blinkt/openvpn/core/X509Utils.java index efdda3ca..f6bd7774 100644 --- a/src/de/blinkt/openvpn/core/X509Utils.java +++ b/src/de/blinkt/openvpn/core/X509Utils.java @@ -67,7 +67,7 @@ public class X509Utils { return getCertificateFriendlyName(cert); } catch (Exception e) { - OpenVPN.logError("Could not read certificate" + e.getLocalizedMessage()); + VpnStatus.logError("Could not read certificate" + e.getLocalizedMessage()); } } return c.getString(R.string.cannotparsecert); diff --git a/src/de/blinkt/openvpn/fragments/SendDumpFragment.java b/src/de/blinkt/openvpn/fragments/SendDumpFragment.java index 020379ef..d43f6427 100644 --- a/src/de/blinkt/openvpn/fragments/SendDumpFragment.java +++ b/src/de/blinkt/openvpn/fragments/SendDumpFragment.java @@ -15,7 +15,7 @@ import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import de.blinkt.openvpn.R; -import de.blinkt.openvpn.core.OpenVPN; +import de.blinkt.openvpn.core.VpnStatus; public class SendDumpFragment extends Fragment { @@ -61,7 +61,7 @@ public class SendDumpFragment extends Fragment { File ldump = getLastestDump(getActivity()); if(ldump==null) { - OpenVPN.logError("No Minidump found!"); + VpnStatus.logError("No Minidump found!"); } uris.add(Uri.parse("content://de.blinkt.openvpn.FileProvider/" + ldump.getName())); |