summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2022-11-01 18:36:03 +0100
committerArne Schwabe <arne@rfc2549.org>2022-11-01 18:37:25 +0100
commit8dd69e81d589d787210a58bff8629eaf068908b6 (patch)
treeeeadaaeb0d1c5a06ad6eaa0ac25d18faeb10b1c8 /main
parentea13917b41ed161f8a385ed438ee8fd3742f557b (diff)
Log reason why a VPN process was started
Diffstat (limited to 'main')
-rw-r--r--main/src/main/java/de/blinkt/openvpn/LaunchVPN.java58
-rw-r--r--main/src/main/java/de/blinkt/openvpn/OnBootReceiver.java2
-rw-r--r--main/src/main/java/de/blinkt/openvpn/VpnProfile.java16
-rw-r--r--main/src/main/java/de/blinkt/openvpn/activities/DisconnectVPN.java3
-rw-r--r--main/src/main/java/de/blinkt/openvpn/api/ExternalOpenVPNService.java4
-rw-r--r--main/src/main/java/de/blinkt/openvpn/api/RemoteAction.java1
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java13
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java4
-rw-r--r--main/src/ui/java/de/blinkt/openvpn/OpenVPNTileService.java1
-rw-r--r--main/src/ui/java/de/blinkt/openvpn/activities/CreateShortcuts.java6
-rw-r--r--main/src/ui/java/de/blinkt/openvpn/fragments/LogFragment.java1
-rw-r--r--main/src/ui/java/de/blinkt/openvpn/fragments/VPNProfileList.java4
12 files changed, 62 insertions, 51 deletions
diff --git a/main/src/main/java/de/blinkt/openvpn/LaunchVPN.java b/main/src/main/java/de/blinkt/openvpn/LaunchVPN.java
index 86eef35a..90ea053a 100644
--- a/main/src/main/java/de/blinkt/openvpn/LaunchVPN.java
+++ b/main/src/main/java/de/blinkt/openvpn/LaunchVPN.java
@@ -73,6 +73,7 @@ public class LaunchVPN extends Activity {
public static final String EXTRA_KEY = "de.blinkt.openvpn.shortcutProfileUUID";
public static final String EXTRA_NAME = "de.blinkt.openvpn.shortcutProfileName";
public static final String EXTRA_HIDELOG = "de.blinkt.openvpn.showNoLogWindow";
+ public static final String EXTRA_START_REASON = "de.blinkt.openvpn.start_reason";
public static final String CLEARLOG = "clearlogconnect";
@@ -85,6 +86,7 @@ public class LaunchVPN extends Activity {
private boolean mCmfixed = false;
private String mTransientAuthPW;
private String mTransientCertOrPCKS12PW;
+ private String mSelectedProfileReason;
@Override
public void onCreate(Bundle icicle) {
@@ -99,7 +101,6 @@ public class LaunchVPN extends Activity {
IServiceStatus service = IServiceStatus.Stub.asInterface(binder);
try {
if (mTransientAuthPW != null)
-
service.setCachedPassword(mSelectedProfile.getUUIDString(), PasswordCache.AUTHPASSWORD, mTransientAuthPW);
if (mTransientCertOrPCKS12PW != null)
service.setCachedPassword(mSelectedProfile.getUUIDString(), PasswordCache.PCKS12ORCERTPASSWORD, mTransientCertOrPCKS12PW);
@@ -126,38 +127,41 @@ public class LaunchVPN extends Activity {
final String action = intent.getAction();
// If the intent is a request to create a shortcut, we'll do that and exit
+ if (!Intent.ACTION_MAIN.equals(action)) {
+ return;
+ }
+ // Check if we need to clear the log
+ if (Preferences.getDefaultSharedPreferences(this).getBoolean(CLEARLOG, true))
+ VpnStatus.clearLog();
- if (Intent.ACTION_MAIN.equals(action)) {
- // Check if we need to clear the log
- if (Preferences.getDefaultSharedPreferences(this).getBoolean(CLEARLOG, true))
- VpnStatus.clearLog();
-
- // we got called to be the starting point, most likely a shortcut
- String shortcutUUID = intent.getStringExtra(EXTRA_KEY);
- String shortcutName = intent.getStringExtra(EXTRA_NAME);
- mhideLog = intent.getBooleanExtra(EXTRA_HIDELOG, false);
+ // we got called to be the starting point, most likely a shortcut
+ String shortcutUUID = intent.getStringExtra(EXTRA_KEY);
+ String shortcutName = intent.getStringExtra(EXTRA_NAME);
+ String startReason = intent.getStringExtra(EXTRA_START_REASON);
+ mhideLog = intent.getBooleanExtra(EXTRA_HIDELOG, false);
- VpnProfile profileToConnect = ProfileManager.get(this, shortcutUUID);
- if (shortcutName != null && profileToConnect == null) {
- profileToConnect = ProfileManager.getInstance(this).getProfileByName(shortcutName);
- if (!(new ExternalAppDatabase(this).checkRemoteActionPermission(this, getCallingPackage()))) {
- finish();
- return;
- }
+ VpnProfile profileToConnect = ProfileManager.get(this, shortcutUUID);
+ if (shortcutName != null && profileToConnect == null) {
+ profileToConnect = ProfileManager.getInstance(this).getProfileByName(shortcutName);
+ if (!(new ExternalAppDatabase(this).checkRemoteActionPermission(this, getCallingPackage()))) {
+ finish();
+ return;
}
+ }
- if (profileToConnect == null) {
- VpnStatus.logError(R.string.shortcut_profile_notfound);
- // show Log window to display error
- showLogWindow();
- finish();
- } else {
- mSelectedProfile = profileToConnect;
- launchVPN();
- }
+ if (profileToConnect == null) {
+ VpnStatus.logError(R.string.shortcut_profile_notfound);
+ // show Log window to display error
+ showLogWindow();
+ finish();
+ } else {
+ mSelectedProfile = profileToConnect;
+ mSelectedProfileReason = startReason;
+ launchVPN();
}
+
}
private void askForPW(final int type) {
@@ -251,7 +255,7 @@ public class LaunchVPN extends Activity {
if (!mhideLog && showLogWindow)
showLogWindow();
ProfileManager.updateLRU(this, mSelectedProfile);
- VPNLaunchHelper.startOpenVpn(mSelectedProfile, getBaseContext());
+ VPNLaunchHelper.startOpenVpn(mSelectedProfile, getBaseContext(), mSelectedProfileReason);
finish();
}
} else if (resultCode == Activity.RESULT_CANCELED) {
diff --git a/main/src/main/java/de/blinkt/openvpn/OnBootReceiver.java b/main/src/main/java/de/blinkt/openvpn/OnBootReceiver.java
index 3facacc5..4827bf10 100644
--- a/main/src/main/java/de/blinkt/openvpn/OnBootReceiver.java
+++ b/main/src/main/java/de/blinkt/openvpn/OnBootReceiver.java
@@ -36,6 +36,6 @@ public class OnBootReceiver extends BroadcastReceiver {
}
void launchVPN(VpnProfile profile, Context context) {
- VPNLaunchHelper.startOpenVpn(profile, context.getApplicationContext());
+ VPNLaunchHelper.startOpenVpn(profile, context.getApplicationContext(), "on Boot receiver");
}
}
diff --git a/main/src/main/java/de/blinkt/openvpn/VpnProfile.java b/main/src/main/java/de/blinkt/openvpn/VpnProfile.java
index 3163bf27..0da09eb0 100644
--- a/main/src/main/java/de/blinkt/openvpn/VpnProfile.java
+++ b/main/src/main/java/de/blinkt/openvpn/VpnProfile.java
@@ -809,18 +809,6 @@ public class VpnProfile implements Serializable, Cloneable {
return parts[0] + " " + netmask;
}
- public Intent prepareStartService(Context context) {
- Intent intent = getStartServiceIntent(context);
-
- // TODO: Handle this?!
-// if (mAuthenticationType == VpnProfile.TYPE_KEYSTORE || mAuthenticationType == VpnProfile.TYPE_USERPASS_KEYSTORE) {
-// if (getKeyStoreCertificates(context) == null)
-// return null;
-// }
-
- return intent;
- }
-
public void writeConfigFileOutput(Context context, OutputStream out) throws IOException {
OutputStreamWriter cfg = new OutputStreamWriter(out);
cfg.write(getConfigFile(context, false));
@@ -828,12 +816,14 @@ public class VpnProfile implements Serializable, Cloneable {
cfg.close();
}
- public Intent getStartServiceIntent(Context context) {
+ public Intent getStartServiceIntent(Context context, String startReason) {
String prefix = context.getPackageName();
Intent intent = new Intent(context, OpenVPNService.class);
intent.putExtra(prefix + ".profileUUID", mUuid.toString());
intent.putExtra(prefix + ".profileVersion", mVersion);
+ if (startReason != null)
+ intent.putExtra(prefix + ".startReason", startReason);
return intent;
}
diff --git a/main/src/main/java/de/blinkt/openvpn/activities/DisconnectVPN.java b/main/src/main/java/de/blinkt/openvpn/activities/DisconnectVPN.java
index 01dacfcd..6cc170fa 100644
--- a/main/src/main/java/de/blinkt/openvpn/activities/DisconnectVPN.java
+++ b/main/src/main/java/de/blinkt/openvpn/activities/DisconnectVPN.java
@@ -27,7 +27,7 @@ import de.blinkt.openvpn.core.VpnStatus;
*/
public class DisconnectVPN extends Activity implements DialogInterface.OnClickListener, DialogInterface.OnCancelListener {
private IOpenVPNServiceInternal mService;
- private ServiceConnection mConnection = new ServiceConnection() {
+ private final ServiceConnection mConnection = new ServiceConnection() {
@@ -86,6 +86,7 @@ public class DisconnectVPN extends Activity implements DialogInterface.OnClickLi
} else if (which == DialogInterface.BUTTON_NEUTRAL) {
Intent intent = new Intent(this, LaunchVPN.class);
intent.putExtra(LaunchVPN.EXTRA_KEY, VpnStatus.getLastConnectedVPNProfile());
+ intent.putExtra(LaunchVPN.EXTRA_START_REASON, "Reconnect button pressed.");
intent.setAction(Intent.ACTION_MAIN);
startActivity(intent);
}
diff --git a/main/src/main/java/de/blinkt/openvpn/api/ExternalOpenVPNService.java b/main/src/main/java/de/blinkt/openvpn/api/ExternalOpenVPNService.java
index 690c349e..8573af79 100644
--- a/main/src/main/java/de/blinkt/openvpn/api/ExternalOpenVPNService.java
+++ b/main/src/main/java/de/blinkt/openvpn/api/ExternalOpenVPNService.java
@@ -139,16 +139,18 @@ public class ExternalOpenVPNService extends Service implements StateListener {
* Check if we need to ask for username/password */
int neddPassword = vp.needUserPWInput(null, null);
+ String startReason = "external OpenVPN service by uid: " + Binder.getCallingUid();
if(vpnPermissionIntent != null || neddPassword != 0){
Intent shortVPNIntent = new Intent(Intent.ACTION_MAIN);
shortVPNIntent.setClass(getBaseContext(), de.blinkt.openvpn.LaunchVPN.class);
shortVPNIntent.putExtra(de.blinkt.openvpn.LaunchVPN.EXTRA_KEY, vp.getUUIDString());
shortVPNIntent.putExtra(de.blinkt.openvpn.LaunchVPN.EXTRA_HIDELOG, true);
+ shortVPNIntent.putExtra(de.blinkt.openvpn.LaunchVPN.EXTRA_START_REASON, startReason);
shortVPNIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(shortVPNIntent);
} else {
- VPNLaunchHelper.startOpenVpn(vp, getBaseContext());
+ VPNLaunchHelper.startOpenVpn(vp, getBaseContext(), startReason);
}
}
diff --git a/main/src/main/java/de/blinkt/openvpn/api/RemoteAction.java b/main/src/main/java/de/blinkt/openvpn/api/RemoteAction.java
index 0554b88c..22110ad0 100644
--- a/main/src/main/java/de/blinkt/openvpn/api/RemoteAction.java
+++ b/main/src/main/java/de/blinkt/openvpn/api/RemoteAction.java
@@ -93,6 +93,7 @@ public class RemoteAction extends Activity {
} else {
Intent startVPN = new Intent(this, LaunchVPN.class);
startVPN.putExtra(LaunchVPN.EXTRA_KEY, profile.getUUID().toString());
+ startVPN.putExtra(LaunchVPN.EXTRA_START_REASON, ".api.ConnectVPN call");
startVPN.setAction(Intent.ACTION_MAIN);
startActivity(startVPN);
}
diff --git a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
index 910dc43e..88c253ec 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
@@ -23,7 +23,6 @@ import android.content.pm.ShortcutManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.net.ConnectivityManager;
-import android.net.IpPrefix;
import android.net.ProxyInfo;
import android.net.Uri;
import android.net.VpnService;
@@ -40,6 +39,7 @@ import android.system.OsConstants;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;
+import android.util.Pair;
import android.widget.Toast;
import androidx.annotation.NonNull;
@@ -519,9 +519,13 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
private VpnProfile fetchVPNProfile(Intent intent)
{
+ String startReason;
if (intent != null && intent.hasExtra(getPackageName() + ".profileUUID")) {
String profileUUID = intent.getStringExtra(getPackageName() + ".profileUUID");
int profileVersion = intent.getIntExtra(getPackageName() + ".profileVersion", 0);
+ startReason = intent.getStringExtra(getPackageName() + ".startReason");
+ if (startReason == null)
+ startReason = "(unknown)";
// Try for 10s to get current version of the profile
mProfile = ProfileManager.get(this, profileUUID, profileVersion, 100);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
@@ -531,10 +535,13 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
} else {
/* The intent is null when we are set as always-on or the service has been restarted. */
mProfile = ProfileManager.getLastConnectedProfile(this);
+ startReason = "Using last connected profile (started with null intent, always-on or restart after crash)";
VpnStatus.logInfo(R.string.service_restarted);
/* Got no profile, just stop */
if (mProfile == null) {
+ startReason = "could not get last connected profile, using default (started with null intent, always-on or restart after crash)";
+
Log.d("OpenVPN", "Got no last connected profile on null intent. Assuming always on.");
mProfile = ProfileManager.getAlwaysOnVPN(this);
@@ -546,6 +553,10 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
/* Do the asynchronous keychain certificate stuff */
mProfile.checkForRestart(this);
}
+ String name = "(null)";
+ if (mProfile != null)
+ name = mProfile.getName();
+ VpnStatus.logDebug(String.format("Fetched VPN profile (%s) triggered by %s", name, startReason));
return mProfile;
}
diff --git a/main/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java b/main/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java
index c859e845..bc04bc5e 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java
@@ -100,8 +100,8 @@ public class VPNLaunchHelper {
}
- public static void startOpenVpn(VpnProfile startprofile, Context context) {
- Intent startVPN = startprofile.prepareStartService(context);
+ public static void startOpenVpn(VpnProfile startprofile, Context context, String startReason) {
+ Intent startVPN = startprofile.getStartServiceIntent(context, startReason);
if (startVPN != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
//noinspection NewApi
diff --git a/main/src/ui/java/de/blinkt/openvpn/OpenVPNTileService.java b/main/src/ui/java/de/blinkt/openvpn/OpenVPNTileService.java
index 1c5dd0e5..9cb69a3d 100644
--- a/main/src/ui/java/de/blinkt/openvpn/OpenVPNTileService.java
+++ b/main/src/ui/java/de/blinkt/openvpn/OpenVPNTileService.java
@@ -88,6 +88,7 @@ public class OpenVPNTileService extends TileService implements VpnStatus.StateLi
Intent startVpnIntent = new Intent(Intent.ACTION_MAIN);
startVpnIntent.setClass(context, LaunchVPN.class);
startVpnIntent.putExtra(LaunchVPN.EXTRA_KEY, profile.getUUIDString());
+ startVpnIntent.putExtra(LaunchVPN.EXTRA_START_REASON, "QuickTile");
startVpnIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startVpnIntent.putExtra(LaunchVPN.EXTRA_HIDELOG, true);
diff --git a/main/src/ui/java/de/blinkt/openvpn/activities/CreateShortcuts.java b/main/src/ui/java/de/blinkt/openvpn/activities/CreateShortcuts.java
index e1cb8862..82455895 100644
--- a/main/src/ui/java/de/blinkt/openvpn/activities/CreateShortcuts.java
+++ b/main/src/ui/java/de/blinkt/openvpn/activities/CreateShortcuts.java
@@ -51,9 +51,6 @@ import java.util.Vector;
public class CreateShortcuts extends ListActivity implements OnItemClickListener {
- private static final int START_VPN_PROFILE= 70;
-
-
private ProfileManager mPM;
private VpnProfile mSelectedProfile;
@@ -128,7 +125,8 @@ public class CreateShortcuts extends ListActivity implements OnItemClickListener
Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
shortcutIntent.setClass(this, LaunchVPN.class);
- shortcutIntent.putExtra(LaunchVPN.EXTRA_KEY,profile.getUUID().toString());
+ shortcutIntent.putExtra(LaunchVPN.EXTRA_KEY, profile.getUUID().toString());
+ shortcutIntent.putExtra(LaunchVPN.EXTRA_START_REASON, "shortcut");
// Then, set up the container intent (the response to the caller)
diff --git a/main/src/ui/java/de/blinkt/openvpn/fragments/LogFragment.java b/main/src/ui/java/de/blinkt/openvpn/fragments/LogFragment.java
index 611e10e9..c5c48b0e 100644
--- a/main/src/ui/java/de/blinkt/openvpn/fragments/LogFragment.java
+++ b/main/src/ui/java/de/blinkt/openvpn/fragments/LogFragment.java
@@ -538,6 +538,7 @@ public class LogFragment extends ListFragment implements StateListener, SeekBar.
(dialog1, which) -> {
Intent intent = new Intent(getActivity(), LaunchVPN.class);
intent.putExtra(LaunchVPN.EXTRA_KEY, profile.getUUIDString());
+ intent.putExtra(LaunchVPN.EXTRA_START_REASON, "restart from logwindow");
intent.setAction(Intent.ACTION_MAIN);
startActivity(intent);
});
diff --git a/main/src/ui/java/de/blinkt/openvpn/fragments/VPNProfileList.java b/main/src/ui/java/de/blinkt/openvpn/fragments/VPNProfileList.java
index 8c84a913..32ae0093 100644
--- a/main/src/ui/java/de/blinkt/openvpn/fragments/VPNProfileList.java
+++ b/main/src/ui/java/de/blinkt/openvpn/fragments/VPNProfileList.java
@@ -239,9 +239,10 @@ public class VPNProfileList extends ListFragment implements OnClickListener, Vpn
@RequiresApi(Build.VERSION_CODES.N_MR1)
ShortcutInfo createShortcut(VpnProfile profile) {
Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
- shortcutIntent.setClass(getActivity(), LaunchVPN.class);
+ shortcutIntent.setClass(requireContext(), LaunchVPN.class);
shortcutIntent.putExtra(LaunchVPN.EXTRA_KEY, profile.getUUID().toString());
shortcutIntent.setAction(Intent.ACTION_MAIN);
+ shortcutIntent.putExtra(LaunchVPN.EXTRA_START_REASON, "shortcut");
shortcutIntent.putExtra("EXTRA_HIDELOG", true);
PersistableBundle versionExtras = new PersistableBundle();
@@ -562,6 +563,7 @@ public class VPNProfileList extends ListFragment implements OnClickListener, Vpn
Intent intent = new Intent(getActivity(), LaunchVPN.class);
intent.putExtra(LaunchVPN.EXTRA_KEY, profile.getUUID().toString());
+ intent.putExtra(LaunchVPN.EXTRA_START_REASON, "main profile list");
intent.setAction(Intent.ACTION_MAIN);
startActivity(intent);
}