summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main/src/main/AndroidManifest.xml4
-rw-r--r--main/src/main/aidl/de/blinkt/openvpn/core/IStatusCallbacks.aidl2
-rw-r--r--main/src/main/java/de/blinkt/openvpn/LaunchVPN.java4
-rw-r--r--main/src/main/java/de/blinkt/openvpn/api/ExternalOpenVPNService.java3
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/CredentialsPopup.java47
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java52
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/OpenVPNStatusService.java11
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/PasswordDialogFragment.java91
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/StatusListener.java5
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/VpnStatus.java28
-rw-r--r--main/src/skeleton/AndroidManifest.xml13
-rw-r--r--main/src/skeleton/java/de/blinkt/openvpn/activities/MainActivity.java14
-rw-r--r--main/src/skeleton/java/de/blinkt/openvpn/activities/NotImplemented.java (renamed from main/src/skeleton/java/de/blinkt/openvpn/activities/LogWindow.java)2
-rw-r--r--main/src/ui/java/de/blinkt/openvpn/OpenVPNTileService.java3
-rw-r--r--main/src/ui/java/de/blinkt/openvpn/activities/CredentialsPopup.kt29
-rw-r--r--main/src/ui/java/de/blinkt/openvpn/fragments/LogFragment.java3
-rw-r--r--main/src/ui/java/de/blinkt/openvpn/fragments/PasswordDialogFragment.kt99
-rw-r--r--main/src/ui/java/de/blinkt/openvpn/fragments/VPNProfileList.java14
18 files changed, 222 insertions, 202 deletions
diff --git a/main/src/main/AndroidManifest.xml b/main/src/main/AndroidManifest.xml
index 8df4ed79..cfa99452 100644
--- a/main/src/main/AndroidManifest.xml
+++ b/main/src/main/AndroidManifest.xml
@@ -19,7 +19,9 @@
android:supportsRtl="true"
android:theme="@style/blinkt"
tools:ignore="UnusedAttribute">
- <activity android:name=".core.CredentialsPopup"></activity>
+ <activity
+ android:name=".core.CredentialsPopup"
+ android:theme="@style/blinkt.dialog" />
<meta-data
android:name="android.content.APP_RESTRICTIONS"
diff --git a/main/src/main/aidl/de/blinkt/openvpn/core/IStatusCallbacks.aidl b/main/src/main/aidl/de/blinkt/openvpn/core/IStatusCallbacks.aidl
index 75860b81..286a5040 100644
--- a/main/src/main/aidl/de/blinkt/openvpn/core/IStatusCallbacks.aidl
+++ b/main/src/main/aidl/de/blinkt/openvpn/core/IStatusCallbacks.aidl
@@ -16,7 +16,7 @@ interface IStatusCallbacks {
*/
oneway void newLogItem(in LogItem item);
- oneway void updateStateString(in String state, in String msg, in int resid, in ConnectionStatus level);
+ oneway void updateStateString(in String state, in String msg, in int resid, in ConnectionStatus level, in Intent intent);
oneway void updateByteCount(long inBytes, long outBytes);
diff --git a/main/src/main/java/de/blinkt/openvpn/LaunchVPN.java b/main/src/main/java/de/blinkt/openvpn/LaunchVPN.java
index a6878d92..7bc0b7ed 100644
--- a/main/src/main/java/de/blinkt/openvpn/LaunchVPN.java
+++ b/main/src/main/java/de/blinkt/openvpn/LaunchVPN.java
@@ -33,7 +33,6 @@ import android.widget.EditText;
import java.io.IOException;
-import de.blinkt.openvpn.activities.LogWindow;
import de.blinkt.openvpn.api.ExternalAppDatabase;
import de.blinkt.openvpn.core.ConnectionStatus;
import de.blinkt.openvpn.core.IServiceStatus;
@@ -268,7 +267,8 @@ public class LaunchVPN extends Activity {
void showLogWindow() {
- Intent startLW = new Intent(getBaseContext(), LogWindow.class);
+ Intent startLW = new Intent();
+ startLW.setComponent(new ComponentName(this, getPackageName() + ".activities.LogWindow"));
startLW.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(startLW);
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 f370f606..1b8512f9 100644
--- a/main/src/main/java/de/blinkt/openvpn/api/ExternalOpenVPNService.java
+++ b/main/src/main/java/de/blinkt/openvpn/api/ExternalOpenVPNService.java
@@ -6,6 +6,7 @@
package de.blinkt.openvpn.api;
import android.annotation.TargetApi;
+import android.app.PendingIntent;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
@@ -340,7 +341,7 @@ public class ExternalOpenVPNService extends Service implements StateListener {
}
@Override
- public void updateState(String state, String logmessage, int resid, ConnectionStatus level) {
+ public void updateState(String state, String logmessage, int resid, ConnectionStatus level, Intent intent) {
mMostRecentState = new UpdateMessage(state, logmessage, level);
if (ProfileManager.getLastConnectedVpn() != null)
mMostRecentState.vpnUUID = ProfileManager.getLastConnectedVpn().getUUIDString();
diff --git a/main/src/main/java/de/blinkt/openvpn/core/CredentialsPopup.java b/main/src/main/java/de/blinkt/openvpn/core/CredentialsPopup.java
deleted file mode 100644
index dcb3255a..00000000
--- a/main/src/main/java/de/blinkt/openvpn/core/CredentialsPopup.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (c) 2012-2019 Arne Schwabe
- * Distributed under the GNU GPL v2 with additional terms. For full terms see the file doc/LICENSE.txt
- */
-
-package de.blinkt.openvpn.core;
-
-import android.app.*;
-import android.content.*;
-import android.os.Bundle;
-import android.os.IBinder;
-import android.os.RemoteException;
-import android.text.InputType;
-import android.widget.EditText;
-import de.blinkt.openvpn.R;
-
-public class CredentialsPopup extends Activity {
- public static final String EXTRA_CHALLENGE_TXT = "de.blinkt.openvpn.core.CR_TEXT_CHALLENGE";
-
-
-
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- // Get the alarm ID from the intent extra data
- Intent intent = getIntent();
- Bundle extras = intent.getExtras();
- if (extras == null) {
- finish();
- return;
- }
- String challenge = extras.getString(EXTRA_CHALLENGE_TXT, "(empty challenge text)");
-
- showPwDialog(challenge);
- }
-
-
-
-
- private void showPwDialog(String challenge) {
- DialogFragment frag = PasswordDialogFragment.newInstance(challenge);
- FragmentTransaction ft = getFragmentManager().beginTransaction();
- frag.show(ft, "dialog");
- }
-}
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 a2126861..d4148361 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
@@ -12,6 +12,7 @@ import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.UiModeManager;
+import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
@@ -53,7 +54,6 @@ import de.blinkt.openvpn.LaunchVPN;
import de.blinkt.openvpn.R;
import de.blinkt.openvpn.VpnProfile;
import de.blinkt.openvpn.activities.DisconnectVPN;
-import de.blinkt.openvpn.activities.MainActivity;
import de.blinkt.openvpn.api.ExternalAppDatabase;
import de.blinkt.openvpn.core.VpnStatus.ByteCountListener;
import de.blinkt.openvpn.core.VpnStatus.StateListener;
@@ -75,6 +75,9 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
public final static String ORBOT_PACKAGE_NAME = "org.torproject.android";
private static final String PAUSE_VPN = "de.blinkt.openvpn.PAUSE_VPN";
private static final String RESUME_VPN = "de.blinkt.openvpn.RESUME_VPN";
+
+ public static final String EXTRA_CHALLENGE_TXT = "de.blinkt.openvpn.core.CR_TEXT_CHALLENGE";
+
private static final int PRIORITY_MIN = -2;
private static final int PRIORITY_DEFAULT = 0;
private static final int PRIORITY_MAX = 2;
@@ -136,7 +139,6 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
private Handler guiHandler;
private Toast mlastToast;
private Runnable mOpenVPNThread;
- private PendingIntent mSSOPendingIntent = null;
// From: http://stackoverflow.com/questions/3758606/how-to-convert-byte-size-into-human-readable-format-in-java
public static String humanReadableByteCount(long bytes, boolean speed, Resources res) {
@@ -245,7 +247,8 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
}
}
- private void showNotification(final String msg, String tickerText, @NonNull String channel, long when, ConnectionStatus status) {
+ private void showNotification(final String msg, String tickerText, @NonNull String channel,
+ long when, ConnectionStatus status, Intent intent) {
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
int icon = getIconByConnectionStatus(status);
@@ -270,14 +273,11 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
nbuilder.setSmallIcon(icon);
if (status == LEVEL_WAITING_FOR_USER_INPUT) {
- if (mSSOPendingIntent != null) {
- nbuilder.setContentIntent(mSSOPendingIntent);
- } else {
- nbuilder.setContentIntent(getUserInputIntent(msg));
- }
- }
- else
+ PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
+ nbuilder.setContentIntent(pIntent);
+ } else {
nbuilder.setContentIntent(getGraphPendingIntent());
+ }
if (when != 0)
nbuilder.setWhen(when);
@@ -425,11 +425,11 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
PendingIntent getGraphPendingIntent() {
// Let the configure Button show the Log
- Class activityClass = MainActivity.class;
- if (mNotificationActivityClass != null) {
- activityClass = mNotificationActivityClass;
- }
- Intent intent = new Intent(getBaseContext(), activityClass);
+
+
+ Intent intent = new Intent();
+ intent.setComponent(new ComponentName(this, getPackageName() + ".activities.MainActivity"));
+
intent.putExtra("PAGE", "graph");
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
PendingIntent startLW = PendingIntent.getActivity(this, 0, intent, 0);
@@ -522,7 +522,7 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
VpnStatus.logInfo(R.string.building_configration);
VpnStatus.updateStateString("VPN_GENERATE_CONFIG", "", R.string.building_configration, ConnectionStatus.LEVEL_START);
showNotification(VpnStatus.getLastCleanLogMessage(this),
- VpnStatus.getLastCleanLogMessage(this), NOTIFICATION_CHANNEL_NEWSTATUS_ID, 0, ConnectionStatus.LEVEL_START);
+ VpnStatus.getLastCleanLogMessage(this), NOTIFICATION_CHANNEL_NEWSTATUS_ID, 0, ConnectionStatus.LEVEL_START, null);
if (intent != null && intent.hasExtra(getPackageName() + ".profileUUID")) {
String profileUUID = intent.getStringExtra(getPackageName() + ".profileUUID");
@@ -1153,7 +1153,7 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
}
@Override
- public void updateState(String state, String logmessage, int resid, ConnectionStatus level) {
+ public void updateState(String state, String logmessage, int resid, ConnectionStatus level, Intent intent) {
// If the process is not running, ignore any state,
// Notification should be invisible in this state
@@ -1179,7 +1179,7 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
// CONNECTED
// Does not work :(
showNotification(VpnStatus.getLastCleanLogMessage(this),
- VpnStatus.getLastCleanLogMessage(this), channel, 0, level);
+ VpnStatus.getLastCleanLogMessage(this), channel, 0, level, intent);
}
}
@@ -1206,7 +1206,7 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
humanReadableByteCount(diffOut / OpenVPNManagement.mBytecountInterval, true, getResources()));
- showNotification(netstat, null, NOTIFICATION_CHANNEL_BG_ID, mConnecttime, LEVEL_CONNECTED);
+ showNotification(netstat, null, NOTIFICATION_CHANNEL_BG_ID, mConnecttime, LEVEL_CONNECTED, null);
}
}
@@ -1243,7 +1243,7 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
public void requestInputFromUser(int resid, String needed) {
VpnStatus.updateStateString("NEED", "need " + needed, resid, LEVEL_WAITING_FOR_USER_INPUT);
- showNotification(getString(resid), getString(resid), NOTIFICATION_CHANNEL_NEWSTATUS_ID, 0, LEVEL_WAITING_FOR_USER_INPUT);
+ showNotification(getString(resid), getString(resid), NOTIFICATION_CHANNEL_NEWSTATUS_ID, 0, LEVEL_WAITING_FOR_USER_INPUT, null);
}
@@ -1280,8 +1280,10 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
nbuilder.setContentTitle(getString(reason));
nbuilder.setContentText(challenge);
- intent = new Intent(this, CredentialsPopup.class);
- intent.putExtra(CredentialsPopup.EXTRA_CHALLENGE_TXT, challenge);
+ intent = new Intent();
+ intent.setComponent(new ComponentName(this, getPackageName() + ".activities.CredentialsPopup"));
+
+ intent.putExtra(EXTRA_CHALLENGE_TXT, challenge);
} else {
VpnStatus.logError("Unknown SSO method found: " + method);
@@ -1290,9 +1292,9 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
// updateStateString trigger the notification of the VPN to be refreshed, save this intent
// to have that notification also this intent to be set
- mSSOPendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
- VpnStatus.updateStateString("USER_INPUT", "waiting for user input", reason, LEVEL_WAITING_FOR_USER_INPUT);
- nbuilder.setContentIntent(mSSOPendingIntent);
+ PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
+ VpnStatus.updateStateString("USER_INPUT", "waiting for user input", reason, LEVEL_WAITING_FOR_USER_INPUT, intent);
+ nbuilder.setContentIntent(pIntent);
// Try to set the priority available since API 16 (Jellybean)
diff --git a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNStatusService.java b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNStatusService.java
index 8a82813f..faae9327 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNStatusService.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNStatusService.java
@@ -5,6 +5,7 @@
package de.blinkt.openvpn.core;
+import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.os.Build;
@@ -147,21 +148,23 @@ public class OpenVPNStatusService extends Service implements VpnStatus.LogListen
public String state;
public String logmessage;
public ConnectionStatus level;
+ public Intent intent;
int resId;
- UpdateMessage(String state, String logmessage, int resId, ConnectionStatus level) {
+ UpdateMessage(String state, String logmessage, int resId, ConnectionStatus level, Intent intent) {
this.state = state;
this.resId = resId;
this.logmessage = logmessage;
this.level = level;
+ this.intent = intent;
}
}
@Override
- public void updateState(String state, String logmessage, int localizedResId, ConnectionStatus level) {
+ public void updateState(String state, String logmessage, int localizedResId, ConnectionStatus level, Intent intent) {
- mLastUpdateMessage = new UpdateMessage(state, logmessage, localizedResId, level);
+ mLastUpdateMessage = new UpdateMessage(state, logmessage, localizedResId, level, intent);
Message msg = mHandler.obtainMessage(SEND_NEW_STATE, mLastUpdateMessage);
msg.sendToTarget();
}
@@ -227,6 +230,6 @@ public class OpenVPNStatusService extends Service implements VpnStatus.LogListen
private static void sendUpdate(IStatusCallbacks broadcastItem,
UpdateMessage um) throws RemoteException {
- broadcastItem.updateStateString(um.state, um.logmessage, um.resId, um.level);
+ broadcastItem.updateStateString(um.state, um.logmessage, um.resId, um.level, um.intent);
}
} \ No newline at end of file
diff --git a/main/src/main/java/de/blinkt/openvpn/core/PasswordDialogFragment.java b/main/src/main/java/de/blinkt/openvpn/core/PasswordDialogFragment.java
deleted file mode 100644
index 230dfad7..00000000
--- a/main/src/main/java/de/blinkt/openvpn/core/PasswordDialogFragment.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright (c) 2012-2019 Arne Schwabe
- * Distributed under the GNU GPL v2 with additional terms. For full terms see the file doc/LICENSE.txt
- */
-
-package de.blinkt.openvpn.core;
-
-import android.app.AlertDialog;
-import android.app.Dialog;
-import android.app.DialogFragment;
-import android.content.ComponentName;
-import android.content.Intent;
-import android.content.ServiceConnection;
-import android.os.Bundle;
-import android.os.IBinder;
-import android.os.RemoteException;
-import android.text.InputType;
-import android.widget.EditText;
-
-
-public class PasswordDialogFragment extends DialogFragment {
-
- private IOpenVPNServiceInternal mService;
- private ServiceConnection mConnection = new ServiceConnection() {
-
-
- @Override
- public void onServiceConnected(ComponentName className,
- IBinder service) {
-
- mService = IOpenVPNServiceInternal.Stub.asInterface(service);
- }
-
- @Override
- public void onServiceDisconnected(ComponentName arg0) {
- mService = null;
- }
-
- };
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- Intent intent = new Intent(getActivity(), OpenVPNService.class);
- intent.setAction(OpenVPNService.START_SERVICE);
- getActivity().bindService(intent, mConnection, 0);
- }
-
- @Override
- public void onDestroy() {
- super.onDestroy();
- getActivity().unbindService(mConnection);
- }
-
- static PasswordDialogFragment newInstance(String title) {
- PasswordDialogFragment frag = new PasswordDialogFragment();
- Bundle args = new Bundle();
- args.putString("title", title);
- frag.setArguments(args);
- return frag;
- }
-
- @Override
- public Dialog onCreateDialog(Bundle savedInstanceState) {
- String title = getArguments().getString("title");
-
- final EditText input = new EditText(getActivity());
- input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
-
-
- return new AlertDialog.Builder(getActivity())
- .setIcon(android.R.drawable.ic_dialog_alert)
- .setTitle(title)
- .setView(input)
- .setPositiveButton(android.R.string.ok, (dialogInterface, i) -> {
- if (mService != null) {
- try {
- mService.challengeResponse(input.getText().toString());
- getActivity().finish();
- } catch (RemoteException e) {
- VpnStatus.logException(e);
- e.printStackTrace();
- }
- }
- })
- .setNegativeButton(android.R.string.cancel,
- (dialog, whichButton) -> getActivity().finish()
- )
- .create();
- }
-} \ No newline at end of file
diff --git a/main/src/main/java/de/blinkt/openvpn/core/StatusListener.java b/main/src/main/java/de/blinkt/openvpn/core/StatusListener.java
index bb8572c9..2a1166ce 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/StatusListener.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/StatusListener.java
@@ -5,6 +5,7 @@
package de.blinkt.openvpn.core;
+import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -35,8 +36,8 @@ public class StatusListener implements VpnStatus.LogListener {
@Override
public void updateStateString(String state, String msg, int resid, ConnectionStatus
- level) throws RemoteException {
- VpnStatus.updateStateString(state, msg, resid, level);
+ level, Intent intent) throws RemoteException {
+ VpnStatus.updateStateString(state, msg, resid, level, intent);
}
@Override
diff --git a/main/src/main/java/de/blinkt/openvpn/core/VpnStatus.java b/main/src/main/java/de/blinkt/openvpn/core/VpnStatus.java
index c8e98b6d..4d286b81 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/VpnStatus.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/VpnStatus.java
@@ -5,7 +5,9 @@
package de.blinkt.openvpn.core;
+import android.app.PendingIntent;
import android.content.Context;
+import android.content.Intent;
import android.os.Build;
import android.os.HandlerThread;
import android.os.Message;
@@ -15,14 +17,9 @@ import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.LinkedList;
import java.util.Locale;
-import java.util.Queue;
import java.util.Vector;
-import java.util.concurrent.ConcurrentLinkedQueue;
-import android.util.Log;
-import de.blinkt.openvpn.BuildConfig;
import de.blinkt.openvpn.R;
-import de.blinkt.openvpn.VpnProfile;
public class VpnStatus {
@@ -39,6 +36,8 @@ public class VpnStatus {
private static int mLastStateresid = R.string.state_noprocess;
+ private static Intent mLastIntent = null;
+
private static HandlerThread mHandlerThread;
private static String mLastConnectedVPNUUID;
@@ -48,6 +47,7 @@ public class VpnStatus {
public static TrafficHistory trafficHistory;
+
public static void logException(LogLevel ll, String context, Exception e) {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
@@ -216,7 +216,7 @@ public class VpnStatus {
}
public interface StateListener {
- void updateState(String state, String logmessage, int localizedResId, ConnectionStatus level);
+ void updateState(String state, String logmessage, int localizedResId, ConnectionStatus level, Intent Intent);
void setConnectedVPN(String uuid);
}
@@ -272,7 +272,7 @@ public class VpnStatus {
if (!stateListener.contains(sl)) {
stateListener.add(sl);
if (mLaststate != null)
- sl.updateState(mLaststate, mLaststatemsg, mLastStateresid, mLastLevel);
+ sl.updateState(mLaststate, mLaststatemsg, mLastStateresid, mLastLevel, mLastIntent);
}
}
@@ -366,12 +366,21 @@ public class VpnStatus {
}
static void updateStateString(String state, String msg) {
+ // We want to skip announcing that we are trying to get the configuration since
+ // this is just polling until the user input has finished.be
+ if (mLastLevel == ConnectionStatus.LEVEL_WAITING_FOR_USER_INPUT && state.equals("GET_CONFIG"))
+ return;
int rid = getLocalizedState(state);
ConnectionStatus level = getLevel(state);
updateStateString(state, msg, rid, level);
}
- public synchronized static void updateStateString(String state, String msg, int resid, ConnectionStatus level) {
+ public synchronized static void updateStateString(String state, String msg, int resid, ConnectionStatus level)
+ {
+ updateStateString(state, msg, resid, level, null);
+ }
+
+ public synchronized static void updateStateString(String state, String msg, int resid, ConnectionStatus level, Intent intent) {
// Workound for OpenVPN doing AUTH and wait and being connected
// Simply ignore these state
if (mLastLevel == ConnectionStatus.LEVEL_CONNECTED &&
@@ -384,10 +393,11 @@ public class VpnStatus {
mLaststatemsg = msg;
mLastStateresid = resid;
mLastLevel = level;
+ mLastIntent = intent;
for (StateListener sl : stateListener) {
- sl.updateState(state, msg, resid, level);
+ sl.updateState(state, msg, resid, level, intent);
}
//newLogItem(new LogItem((LogLevel.DEBUG), String.format("New OpenVPN Status (%s->%s): %s",state,level.toString(),msg)));
}
diff --git a/main/src/skeleton/AndroidManifest.xml b/main/src/skeleton/AndroidManifest.xml
index 916da0e2..054d61e7 100644
--- a/main/src/skeleton/AndroidManifest.xml
+++ b/main/src/skeleton/AndroidManifest.xml
@@ -9,8 +9,19 @@
<application tools:ignore="AllowBackup,GoogleAppIndexingWarning">
<activity
- android:name=".activities.MainActivity"
+ android:name=".activities.NotImplemented"
tools:ignore="ExportedActivity" />
+
+ <activity-alias
+ android:name=".activities.LogWindow"
+ android:targetActivity=".activities.NotImplemented"
+ />
+
+ <activity-alias
+ android:name=".activities.Req"
+ android:targetActivity=".activities.NotImplemented"
+ />
+
</application>
</manifest>
diff --git a/main/src/skeleton/java/de/blinkt/openvpn/activities/MainActivity.java b/main/src/skeleton/java/de/blinkt/openvpn/activities/MainActivity.java
deleted file mode 100644
index d3c79d51..00000000
--- a/main/src/skeleton/java/de/blinkt/openvpn/activities/MainActivity.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package de.blinkt.openvpn.activities;
-
-import android.app.Activity;
-import android.os.Bundle;
-import android.widget.Toast;
-
-public class MainActivity extends Activity {
- @Override
- protected void onCreate( Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- Toast.makeText(this, "Not implemented", Toast.LENGTH_LONG).show();
- finish();
- }
-} \ No newline at end of file
diff --git a/main/src/skeleton/java/de/blinkt/openvpn/activities/LogWindow.java b/main/src/skeleton/java/de/blinkt/openvpn/activities/NotImplemented.java
index 9fd3ba49..3abe826f 100644
--- a/main/src/skeleton/java/de/blinkt/openvpn/activities/LogWindow.java
+++ b/main/src/skeleton/java/de/blinkt/openvpn/activities/NotImplemented.java
@@ -4,7 +4,7 @@ import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;
-public class LogWindow extends Activity {
+public class NotImplemented extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
diff --git a/main/src/ui/java/de/blinkt/openvpn/OpenVPNTileService.java b/main/src/ui/java/de/blinkt/openvpn/OpenVPNTileService.java
index ce14cc98..c9ce9745 100644
--- a/main/src/ui/java/de/blinkt/openvpn/OpenVPNTileService.java
+++ b/main/src/ui/java/de/blinkt/openvpn/OpenVPNTileService.java
@@ -7,6 +7,7 @@ package de.blinkt.openvpn;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
+import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -111,7 +112,7 @@ public class OpenVPNTileService extends TileService implements VpnStatus.StateLi
}
@Override
- public void updateState(String state, String logmessage, int localizedResId, ConnectionStatus level) {
+ public void updateState(String state, String logmessage, int localizedResId, ConnectionStatus level, Intent intent) {
VpnProfile vpn;
Tile t = getQsTile();
if (level == ConnectionStatus.LEVEL_AUTH_FAILED || level == ConnectionStatus.LEVEL_NOTCONNECTED) {
diff --git a/main/src/ui/java/de/blinkt/openvpn/activities/CredentialsPopup.kt b/main/src/ui/java/de/blinkt/openvpn/activities/CredentialsPopup.kt
new file mode 100644
index 00000000..f5d836b9
--- /dev/null
+++ b/main/src/ui/java/de/blinkt/openvpn/activities/CredentialsPopup.kt
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2012-2019 Arne Schwabe
+ * Distributed under the GNU GPL v2 with additional terms. For full terms see the file doc/LICENSE.txt
+ */
+package de.blinkt.openvpn.activities
+
+import android.content.Intent
+import android.os.Bundle
+import androidx.appcompat.app.AppCompatActivity
+import androidx.fragment.app.DialogFragment
+import de.blinkt.openvpn.core.PasswordDialogFragment.Companion.newInstance
+
+class CredentialsPopup : AppCompatActivity() {
+ public override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ // Get the alarm ID from the intent extra data
+ val intent = intent
+ showPwDialog(intent)
+ }
+
+ private fun showPwDialog(intent: Intent) {
+ val frag: DialogFragment? = newInstance(intent, true)
+ if (frag == null) {
+ finish()
+ return
+ }
+ frag.show(supportFragmentManager, "dialog")
+ }
+} \ No newline at end of file
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 994d6e95..64eb720d 100644
--- a/main/src/ui/java/de/blinkt/openvpn/fragments/LogFragment.java
+++ b/main/src/ui/java/de/blinkt/openvpn/fragments/LogFragment.java
@@ -9,6 +9,7 @@ import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.app.Activity;
+import android.app.PendingIntent;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
@@ -650,7 +651,7 @@ public class LogFragment extends ListFragment implements StateListener, SeekBar.
@Override
- public void updateState(final String status, final String logMessage, final int resId, final ConnectionStatus level) {
+ public void updateState(final String status, final String logMessage, final int resId, final ConnectionStatus level, Intent intent) {
if (isAdded()) {
final String cleanLogMessage = VpnStatus.getLastCleanLogMessage(getActivity());
diff --git a/main/src/ui/java/de/blinkt/openvpn/fragments/PasswordDialogFragment.kt b/main/src/ui/java/de/blinkt/openvpn/fragments/PasswordDialogFragment.kt
new file mode 100644
index 00000000..eedb2e59
--- /dev/null
+++ b/main/src/ui/java/de/blinkt/openvpn/fragments/PasswordDialogFragment.kt
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2012-2019 Arne Schwabe
+ * Distributed under the GNU GPL v2 with additional terms. For full terms see the file doc/LICENSE.txt
+ */
+package de.blinkt.openvpn.core
+
+import android.app.AlertDialog
+import android.app.Dialog
+import android.content.ComponentName
+import android.content.DialogInterface
+import android.content.Intent
+import android.content.ServiceConnection
+import android.os.Bundle
+import android.os.IBinder
+import android.os.RemoteException
+import android.text.InputType
+import android.widget.EditText
+import androidx.fragment.app.DialogFragment
+import de.blinkt.openvpn.R
+import de.blinkt.openvpn.core.OpenVPNService.EXTRA_CHALLENGE_TXT
+
+class PasswordDialogFragment : DialogFragment() {
+ private var mService: IOpenVPNServiceInternal? = null
+ private val mConnection: ServiceConnection = object : ServiceConnection {
+ override fun onServiceConnected(className: ComponentName,
+ service: IBinder) {
+ mService = IOpenVPNServiceInternal.Stub.asInterface(service)
+ }
+
+ override fun onServiceDisconnected(arg0: ComponentName) {
+ mService = null
+ }
+ }
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ val intent = Intent(activity, OpenVPNService::class.java)
+ intent.action = OpenVPNService.START_SERVICE
+ requireActivity().bindService(intent, mConnection, 0)
+ }
+
+ override fun onDestroy() {
+ super.onDestroy()
+ requireActivity().unbindService(mConnection)
+ }
+
+ override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
+ val title = requireArguments().getString("title")
+ val echo = requireArguments().getBoolean("echo")
+ val finish = requireArguments().getBoolean("finish")
+ val input = EditText(activity)
+ if (!echo)
+ input.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD
+
+ return AlertDialog.Builder(activity)
+ .setTitle("Challenge/Response Authentification")
+ .setMessage(title)
+ .setView(input)
+ .setPositiveButton(android.R.string.ok) { _, _ ->
+ try {
+ mService?.challengeResponse(input.text.toString())
+ if (finish) requireActivity().finish()
+ } catch (e: RemoteException) {
+ VpnStatus.logException(e)
+ e.printStackTrace()
+ }
+ }
+ .setNegativeButton(R.string.cancel
+ ) { _, _ -> if (finish) requireActivity().finish() }
+ .create()
+ }
+
+ companion object {
+ fun newInstance(intent: Intent, finish: Boolean): PasswordDialogFragment? {
+ val extras = intent.extras ?: return null
+ val challenge = extras.getString(EXTRA_CHALLENGE_TXT, "R,E:(empty challenge text)")
+ val message = challenge.split(":", limit = 2)[1]
+ val flagsStr = challenge.split(":", limit = 2)[0]
+ val flags = flagsStr.split(",")
+ var echo = false
+ var response = false
+ for (flag in flags) {
+ if (flag == "R") response = true
+ else if (flag == "E") echo = true
+ }
+ if (!response) {
+ VpnStatus.logError("Error unrecognised challenge from Server: $challenge")
+ return null
+ }
+ val frag = PasswordDialogFragment()
+ val args = Bundle()
+ args.putString("title", message)
+ args.putBoolean("echo", echo)
+ args.putBoolean("finish", finish)
+ frag.arguments = args
+ return frag
+ }
+ }
+} \ No newline at end of file
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 eb81e62e..f3164bd3 100644
--- a/main/src/ui/java/de/blinkt/openvpn/fragments/VPNProfileList.java
+++ b/main/src/ui/java/de/blinkt/openvpn/fragments/VPNProfileList.java
@@ -53,10 +53,12 @@ import de.blinkt.openvpn.activities.DisconnectVPN;
import de.blinkt.openvpn.activities.FileSelect;
import de.blinkt.openvpn.activities.VPNPreferences;
import de.blinkt.openvpn.core.ConnectionStatus;
+import de.blinkt.openvpn.core.PasswordDialogFragment;
import de.blinkt.openvpn.core.Preferences;
import de.blinkt.openvpn.core.ProfileManager;
import de.blinkt.openvpn.core.VpnStatus;
+import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_WAITING_FOR_USER_INPUT;
import static de.blinkt.openvpn.core.OpenVPNService.DISCONNECT_VPN;
@@ -80,13 +82,23 @@ public class VPNProfileList extends ListFragment implements OnClickListener, Vpn
private ArrayAdapter<VpnProfile> mArrayadapter;
@Override
- public void updateState(String state, String logmessage, final int localizedResId, ConnectionStatus level) {
+ public void updateState(String state, String logmessage, final int localizedResId, ConnectionStatus level, Intent intent) {
requireActivity().runOnUiThread(() -> {
mLastStatusMessage = VpnStatus.getLastCleanLogMessage(getActivity());
mArrayadapter.notifyDataSetChanged();
+ showUserRequestDialogIfNeeded(level, intent);
});
}
+ private void showUserRequestDialogIfNeeded(ConnectionStatus level, Intent intent) {
+ if (level == LEVEL_WAITING_FOR_USER_INPUT) {
+ PasswordDialogFragment pwInputFrag = PasswordDialogFragment.Companion.newInstance(intent, false);
+
+ pwInputFrag.show(requireFragmentManager(), "dialog");
+
+ }
+ }
+
@Override
public void setConnectedVPN(String uuid) {
}