diff options
Diffstat (limited to 'main')
m--------- | main/breakpad | 0 | ||||
-rw-r--r-- | main/jni/Android.mk | 13 | ||||
-rw-r--r-- | main/src/main/aidl/de/blinkt/openvpn/core/IOpenVPNServiceInternal.aidl | 2 | ||||
-rw-r--r-- | main/src/main/java/de/blinkt/openvpn/LaunchVPN.java | 177 | ||||
-rw-r--r-- | main/src/main/java/de/blinkt/openvpn/core/ConnectionStatus.java | 1 | ||||
-rw-r--r-- | main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java | 297 | ||||
-rw-r--r-- | main/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java | 9 | ||||
-rw-r--r-- | main/src/main/res/menu/logmenu.xml | 8 | ||||
-rw-r--r-- | main/src/main/res/values-v21/refs.xml | 10 | ||||
-rw-r--r-- | main/src/main/res/values/refs.xml | 10 |
10 files changed, 136 insertions, 391 deletions
diff --git a/main/breakpad b/main/breakpad deleted file mode 160000 -Subproject 7f66deca10f63057b7726f46ae547d5d8779808 diff --git a/main/jni/Android.mk b/main/jni/Android.mk index ae45c10d..32a76dc0 100644 --- a/main/jni/Android.mk +++ b/main/jni/Android.mk @@ -26,7 +26,7 @@ endif ifeq ($(WITH_BREAKPAD),1) - include breakpad/android/google_breakpad/Android.mk + include breakpad/android/google_breakpad/Android.mk endif ifeq ($(WITH_MBEDTLS),1) @@ -60,7 +60,7 @@ include $(BUILD_SHARED_LIBRARY) include $(CLEAR_VARS) LOCAL_LDLIBS := -llog -lz -LOCAL_CFLAGS = +LOCAL_CFLAGS = LOCAL_C_INCLUDES := openssl/include openssl/crypto openssl openssl/crypto/include LOCAL_SRC_FILES:= jbcrypto.cpp LOCAL_MODULE = jbcrypto @@ -73,16 +73,23 @@ LOCAL_LDLIBS := -lz -lc LOCAL_STATIC_LIBRARIES := libssl_static libcrypto_static openvpn LOCAL_SRC_FILES:= minivpn.c dummy.cpp LOCAL_MODULE = nopie_openvpn +# ======= +# LOCAL_SRC_FILES:= # minivpn.c dummy.cpp +# LOCAL_MODULE = nopievpn +# >>>>>>> minivpn.c and dummy.cpp introduce randomness into nopievpn include $(BUILD_EXECUTABLE) include $(CLEAR_VARS) LOCAL_LDLIBS := -lz -lc LOCAL_CFLAGS= -fPIE -pie -LOCAL_CFLAGS = -fPIE LOCAL_LDFLAGS = -fPIE -pie LOCAL_STATIC_LIBRARIES := libssl_static libcrypto_static openvpn LOCAL_SRC_FILES:= minivpn.c dummy.cpp LOCAL_MODULE = pie_openvpn +# ======= +# LOCAL_SRC_FILES:= # minivpn.c dummy.cpp +# LOCAL_MODULE = pievpn +# >>>>>>> minivpn.c and dummy.cpp introduce randomness into nopievpn include $(BUILD_EXECUTABLE) diff --git a/main/src/main/aidl/de/blinkt/openvpn/core/IOpenVPNServiceInternal.aidl b/main/src/main/aidl/de/blinkt/openvpn/core/IOpenVPNServiceInternal.aidl index 3958bcf3..b19cf99e 100644 --- a/main/src/main/aidl/de/blinkt/openvpn/core/IOpenVPNServiceInternal.aidl +++ b/main/src/main/aidl/de/blinkt/openvpn/core/IOpenVPNServiceInternal.aidl @@ -20,4 +20,6 @@ interface IOpenVPNServiceInternal { * @return true if there was a process that has been send a stop signal */ boolean stopVPN(boolean replaceConnection); + + boolean isVpnRunning(); } diff --git a/main/src/main/java/de/blinkt/openvpn/LaunchVPN.java b/main/src/main/java/de/blinkt/openvpn/LaunchVPN.java index 7b5d4e28..4fff3071 100644 --- a/main/src/main/java/de/blinkt/openvpn/LaunchVPN.java +++ b/main/src/main/java/de/blinkt/openvpn/LaunchVPN.java @@ -5,44 +5,27 @@ package de.blinkt.openvpn; -import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.app.Activity; import android.app.AlertDialog; import android.content.ActivityNotFoundException; -import android.content.ComponentName; -import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.content.Intent; -import android.content.ServiceConnection; import android.content.SharedPreferences; import android.net.VpnService; import android.os.Build; import android.os.Bundle; -import android.os.IBinder; -import android.os.RemoteException; -import android.preference.PreferenceManager; -import android.text.InputType; -import android.text.TextUtils; -import android.text.method.PasswordTransformationMethod; -import android.view.View; -import android.widget.CheckBox; -import android.widget.CompoundButton; -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; -import de.blinkt.openvpn.core.OpenVPNStatusService; -import de.blinkt.openvpn.core.PasswordCache; import de.blinkt.openvpn.core.Preferences; import de.blinkt.openvpn.core.ProfileManager; import de.blinkt.openvpn.core.VPNLaunchHelper; import de.blinkt.openvpn.core.VpnStatus; +import se.leap.bitmaskclient.R; /** * This Activity actually handles two stages of a launcher shortcut's life cycle. @@ -75,6 +58,7 @@ public class LaunchVPN extends Activity { public static final String EXTRA_NAME = "de.blinkt.openvpn.shortcutProfileName"; public static final String EXTRA_HIDELOG = "de.blinkt.openvpn.showNoLogWindow"; public static final String CLEARLOG = "clearlogconnect"; + public static final String EXTRA_TEMP_VPN_PROFILE = "se.leap.bitmask.tempVpnProfile"; private static final int START_VPN_PROFILE = 70; @@ -84,42 +68,14 @@ public class LaunchVPN extends Activity { private boolean mhideLog = false; private boolean mCmfixed = false; - private String mTransientAuthPW; - private String mTransientCertOrPCKS12PW; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); - setContentView(R.layout.launchvpn); + startVpnFromIntent(); } - private ServiceConnection mConnection = new ServiceConnection() { - @Override - public void onServiceConnected(ComponentName componentName, IBinder binder) { - 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); - - onActivityResult(START_VPN_PROFILE, Activity.RESULT_OK, null); - - } catch (RemoteException e) { - e.printStackTrace(); - } - - unbindService(this); - } - - @Override - public void onServiceDisconnected(ComponentName componentName) { - - } - }; - protected void startVpnFromIntent() { // Resolve the intent @@ -138,16 +94,12 @@ public class LaunchVPN extends Activity { String shortcutUUID = intent.getStringExtra(EXTRA_KEY); String shortcutName = intent.getStringExtra(EXTRA_NAME); mhideLog = intent.getBooleanExtra(EXTRA_HIDELOG, false); + VpnProfile profileToConnect = (VpnProfile) intent.getExtras().getSerializable(EXTRA_TEMP_VPN_PROFILE); + if (profileToConnect == null) + profileToConnect = ProfileManager.get(this, shortcutUUID); - VpnProfile profileToConnect = ProfileManager.get(this, shortcutUUID); - if (shortcutName != null && profileToConnect == null) { + if (shortcutName != null && profileToConnect == null) profileToConnect = ProfileManager.getInstance(this).getProfileByName(shortcutName); - if (!(new ExternalAppDatabase(this).checkRemoteActionPermission(this))) { - finish(); - return; - } - } - if (profileToConnect == null) { VpnStatus.logError(R.string.shortcut_profile_notfound); @@ -161,108 +113,29 @@ public class LaunchVPN extends Activity { } } - private void askForPW(final int type) { - - final EditText entry = new EditText(this); - - entry.setSingleLine(); - entry.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); - entry.setTransformationMethod(new PasswordTransformationMethod()); - - AlertDialog.Builder dialog = new AlertDialog.Builder(this); - dialog.setTitle(getString(R.string.pw_request_dialog_title, getString(type))); - dialog.setMessage(getString(R.string.pw_request_dialog_prompt, mSelectedProfile.mName)); - - - @SuppressLint("InflateParams") final View userpwlayout = getLayoutInflater().inflate(R.layout.userpass, null, false); - - if (type == R.string.password) { - ((EditText) userpwlayout.findViewById(R.id.username)).setText(mSelectedProfile.mUsername); - ((EditText) userpwlayout.findViewById(R.id.password)).setText(mSelectedProfile.mPassword); - ((CheckBox) userpwlayout.findViewById(R.id.save_password)).setChecked(!TextUtils.isEmpty(mSelectedProfile.mPassword)); - ((CheckBox) userpwlayout.findViewById(R.id.show_password)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if (isChecked) - ((EditText) userpwlayout.findViewById(R.id.password)).setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); - else - ((EditText) userpwlayout.findViewById(R.id.password)).setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); - } - }); - - dialog.setView(userpwlayout); - } else { - dialog.setView(entry); - } - - AlertDialog.Builder builder = dialog.setPositiveButton(android.R.string.ok, - new OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - - if (type == R.string.password) { - mSelectedProfile.mUsername = ((EditText) userpwlayout.findViewById(R.id.username)).getText().toString(); - - String pw = ((EditText) userpwlayout.findViewById(R.id.password)).getText().toString(); - if (((CheckBox) userpwlayout.findViewById(R.id.save_password)).isChecked()) { - mSelectedProfile.mPassword = pw; - } else { - mSelectedProfile.mPassword = null; - mTransientAuthPW = pw; - } - } else { - mTransientCertOrPCKS12PW = entry.getText().toString(); - } - Intent intent = new Intent(LaunchVPN.this, OpenVPNStatusService.class); - bindService(intent, mConnection, Context.BIND_AUTO_CREATE); - } - - }); - dialog.setNegativeButton(android.R.string.cancel, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - VpnStatus.updateStateString("USER_VPN_PASSWORD_CANCELLED", "", R.string.state_user_vpn_password_cancelled, - ConnectionStatus.LEVEL_NOTCONNECTED); - finish(); - } - }); - - dialog.create().show(); - - } - @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); - if (requestCode == START_VPN_PROFILE) { - if (resultCode == Activity.RESULT_OK) { - int needpw = mSelectedProfile.needUserPWInput(mTransientCertOrPCKS12PW, mTransientAuthPW); - if (needpw != 0) { - VpnStatus.updateStateString("USER_VPN_PASSWORD", "", R.string.state_user_vpn_password, - ConnectionStatus.LEVEL_WAITING_FOR_USER_INPUT); - askForPW(needpw); - } else { - SharedPreferences prefs = Preferences.getDefaultSharedPreferences(this); - boolean showLogWindow = prefs.getBoolean("showlogwindow", true); - - if (!mhideLog && showLogWindow) - showLogWindow(); - ProfileManager.updateLRU(this, mSelectedProfile); - VPNLaunchHelper.startOpenVpn(mSelectedProfile, getBaseContext()); - finish(); - } - } else if (resultCode == Activity.RESULT_CANCELED) { - // User does not want us to start, so we just vanish - VpnStatus.updateStateString("USER_VPN_PERMISSION_CANCELLED", "", R.string.state_user_vpn_permission_cancelled, - ConnectionStatus.LEVEL_NOTCONNECTED); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - VpnStatus.logError(R.string.nought_alwayson_warning); + if(requestCode==START_VPN_PROFILE) { + SharedPreferences prefs = Preferences.getDefaultSharedPreferences(this); + boolean showLogWindow = prefs.getBoolean("showlogwindow", true); - finish(); - } + if(!mhideLog && showLogWindow) + showLogWindow(); + ProfileManager.updateLRU(this, mSelectedProfile); + VPNLaunchHelper.startOpenVpn(mSelectedProfile, getBaseContext()); + finish(); + + } else if (resultCode == Activity.RESULT_CANCELED) { + // User does not want us to start, so we just vanish + VpnStatus.updateStateString("USER_VPN_PERMISSION_CANCELLED", "", R.string.state_user_vpn_permission_cancelled, + ConnectionStatus.LEVEL_NOTCONNECTED); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + VpnStatus.logError(R.string.nought_alwayson_warning); + + finish(); } } diff --git a/main/src/main/java/de/blinkt/openvpn/core/ConnectionStatus.java b/main/src/main/java/de/blinkt/openvpn/core/ConnectionStatus.java index 03d842e3..3e6d23f7 100644 --- a/main/src/main/java/de/blinkt/openvpn/core/ConnectionStatus.java +++ b/main/src/main/java/de/blinkt/openvpn/core/ConnectionStatus.java @@ -21,6 +21,7 @@ public enum ConnectionStatus implements Parcelable { LEVEL_START, LEVEL_AUTH_FAILED, LEVEL_WAITING_FOR_USER_INPUT, + LEVEL_BLOCKING, // used for Bitmask's VoidVPN UNKNOWN_LEVEL; @Override 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 12b7fba5..6c312c87 100644 --- a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java +++ b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java @@ -7,15 +7,10 @@ package de.blinkt.openvpn.core; import android.Manifest.permission; import android.annotation.TargetApi; -import android.app.Activity; import android.app.Notification; -import android.app.NotificationManager; -import android.app.PendingIntent; import android.app.UiModeManager; -import android.content.Context; import android.content.Intent; import android.content.IntentFilter; -import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.content.pm.ShortcutManager; import android.content.res.Configuration; @@ -23,14 +18,12 @@ import android.content.res.Resources; import android.net.ConnectivityManager; import android.net.VpnService; import android.os.Build; -import android.os.Bundle; import android.os.Handler; import android.os.Handler.Callback; import android.os.IBinder; import android.os.Message; import android.os.ParcelFileDescriptor; import android.os.RemoteException; -import android.support.annotation.NonNull; import android.support.annotation.RequiresApi; import android.system.OsConstants; import android.text.TextUtils; @@ -39,7 +32,6 @@ import android.widget.Toast; import java.io.IOException; import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.net.Inet6Address; import java.net.InetAddress; import java.net.UnknownHostException; @@ -47,32 +39,27 @@ import java.util.Collection; import java.util.Locale; import java.util.Vector; -import de.blinkt.openvpn.BuildConfig; -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.core.VpnStatus.ByteCountListener; import de.blinkt.openvpn.core.VpnStatus.StateListener; +import se.leap.bitmaskclient.R; +import se.leap.bitmaskclient.VpnNotificationManager; import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_CONNECTED; -import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_CONNECTING_NO_SERVER_REPLY_YET; -import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_START; import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_WAITING_FOR_USER_INPUT; import static de.blinkt.openvpn.core.NetworkSpace.ipAddress; -public class OpenVPNService extends VpnService implements StateListener, Callback, ByteCountListener, IOpenVPNServiceInternal { + +public class OpenVPNService extends VpnService implements StateListener, Callback, ByteCountListener, IOpenVPNServiceInternal, VpnNotificationManager.VpnServiceCallback { public static final String START_SERVICE = "de.blinkt.openvpn.START_SERVICE"; public static final String START_SERVICE_STICKY = "de.blinkt.openvpn.START_SERVICE_STICKY"; public static final String ALWAYS_SHOW_NOTIFICATION = "de.blinkt.openvpn.NOTIFICATION_ALWAYS_VISIBLE"; public static final String DISCONNECT_VPN = "de.blinkt.openvpn.DISCONNECT_VPN"; private static final String PAUSE_VPN = "de.blinkt.openvpn.PAUSE_VPN"; - private static final String RESUME_VPN = "de.blinkt.openvpn.RESUME_VPN"; + private static final String RESUME_VPN = "se.leap.bitmaskclient.RESUME_VPN"; public static final String NOTIFICATION_CHANNEL_BG_ID = "openvpn_bg"; public static final String NOTIFICATION_CHANNEL_NEWSTATUS_ID = "openvpn_newstat"; public static final String VPNSERVICE_TUN = "vpnservice-tun"; - private String lastChannel; private static boolean mNotificationAlwaysVisible = false; private final Vector<String> mDnslist = new Vector<>(); @@ -95,7 +82,7 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac private Handler guiHandler; private Toast mlastToast; private Runnable mOpenVPNThread; - private static Class mNotificationActivityClass; + private VpnNotificationManager notificationManager; private static final int PRIORITY_MIN = -2; private static final int PRIORITY_DEFAULT = 0; @@ -118,6 +105,11 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac public boolean stopVPN(boolean replaceConnection) throws RemoteException { return OpenVPNService.this.stopVPN(replaceConnection); } + + @Override + public boolean isVpnRunning() throws RemoteException { + return OpenVPNService.this.isVpnRunning(); + } }; // From: http://stackoverflow.com/questions/3758606/how-to-convert-byte-size-into-human-readable-format-in-java @@ -197,199 +189,11 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac } } - - private void showNotification(final String msg, String tickerText, @NonNull String channel, long when, ConnectionStatus status) { - NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); - int icon = getIconByConnectionStatus(status); - - android.app.Notification.Builder nbuilder = new Notification.Builder(this); - - int priority; - if (channel.equals(NOTIFICATION_CHANNEL_BG_ID)) - priority = PRIORITY_MIN; - else - priority = PRIORITY_DEFAULT; - - if (mProfile != null) - nbuilder.setContentTitle(getString(R.string.notifcation_title, mProfile.mName)); - else - nbuilder.setContentTitle(getString(R.string.notifcation_title_notconnect)); - - nbuilder.setContentText(msg); - nbuilder.setOnlyAlertOnce(true); - nbuilder.setOngoing(true); - - nbuilder.setSmallIcon(icon); - if (status == LEVEL_WAITING_FOR_USER_INPUT) - nbuilder.setContentIntent(getUserInputIntent(msg)); - else - nbuilder.setContentIntent(getGraphPendingIntent()); - - if (when != 0) - nbuilder.setWhen(when); - - - // Try to set the priority available since API 16 (Jellybean) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) - - jbNotificationExtras(priority, nbuilder); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) - lpNotificationExtras(nbuilder); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - //noinspection NewApi - nbuilder.setChannelId(channel); - if (mProfile != null) - //noinspection NewApi - nbuilder.setShortcutId(mProfile.getUUIDString()); - - } - - if (tickerText != null && !tickerText.equals("")) - nbuilder.setTicker(tickerText); - - @SuppressWarnings("deprecation") - Notification notification = nbuilder.getNotification(); - - int notificationId = channel.hashCode(); - - mNotificationManager.notify(notificationId, notification); - - startForeground(notificationId, notification); - - if (lastChannel != null && !channel.equals(lastChannel)) { - // Cancel old notification - mNotificationManager.cancel(lastChannel.hashCode()); - } - - // Check if running on a TV - if (runningOnAndroidTV() && !(priority < 0)) - guiHandler.post(new Runnable() { - - @Override - public void run() { - - if (mlastToast != null) - mlastToast.cancel(); - String toastText = String.format(Locale.getDefault(), "%s - %s", mProfile.mName, msg); - mlastToast = Toast.makeText(getBaseContext(), toastText, Toast.LENGTH_SHORT); - mlastToast.show(); - } - }); - } - - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - private void lpNotificationExtras(Notification.Builder nbuilder) { - nbuilder.setCategory(Notification.CATEGORY_SERVICE); - nbuilder.setLocalOnly(true); - - } - private boolean runningOnAndroidTV() { UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE); return uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION; } - private int getIconByConnectionStatus(ConnectionStatus level) { - switch (level) { - case LEVEL_CONNECTED: - return R.drawable.ic_stat_vpn; - case LEVEL_AUTH_FAILED: - case LEVEL_NONETWORK: - case LEVEL_NOTCONNECTED: - return R.drawable.ic_stat_vpn_offline; - case LEVEL_CONNECTING_NO_SERVER_REPLY_YET: - case LEVEL_WAITING_FOR_USER_INPUT: - return R.drawable.ic_stat_vpn_outline; - case LEVEL_CONNECTING_SERVER_REPLIED: - return R.drawable.ic_stat_vpn_empty_halo; - case LEVEL_VPNPAUSED: - return android.R.drawable.ic_media_pause; - case UNKNOWN_LEVEL: - default: - return R.drawable.ic_stat_vpn; - - } - } - - @TargetApi(Build.VERSION_CODES.JELLY_BEAN) - private void jbNotificationExtras(int priority, - android.app.Notification.Builder nbuilder) { - try { - if (priority != 0) { - Method setpriority = nbuilder.getClass().getMethod("setPriority", int.class); - setpriority.invoke(nbuilder, priority); - - Method setUsesChronometer = nbuilder.getClass().getMethod("setUsesChronometer", boolean.class); - setUsesChronometer.invoke(nbuilder, true); - - } - - Intent disconnectVPN = new Intent(this, DisconnectVPN.class); - disconnectVPN.setAction(DISCONNECT_VPN); - PendingIntent disconnectPendingIntent = PendingIntent.getActivity(this, 0, disconnectVPN, 0); - - nbuilder.addAction(R.drawable.ic_menu_close_clear_cancel, - getString(R.string.cancel_connection), disconnectPendingIntent); - - Intent pauseVPN = new Intent(this, OpenVPNService.class); - if (mDeviceStateReceiver == null || !mDeviceStateReceiver.isUserPaused()) { - pauseVPN.setAction(PAUSE_VPN); - PendingIntent pauseVPNPending = PendingIntent.getService(this, 0, pauseVPN, 0); - nbuilder.addAction(R.drawable.ic_menu_pause, - getString(R.string.pauseVPN), pauseVPNPending); - - } else { - pauseVPN.setAction(RESUME_VPN); - PendingIntent resumeVPNPending = PendingIntent.getService(this, 0, pauseVPN, 0); - nbuilder.addAction(R.drawable.ic_menu_play, - getString(R.string.resumevpn), resumeVPNPending); - } - - - //ignore exception - } catch (NoSuchMethodException | IllegalArgumentException | - InvocationTargetException | IllegalAccessException e) { - VpnStatus.logException(e); - } - - } - - /** - * Sets the activity which should be opened when tapped on the permanent notification tile. - * - * @param activityClass The activity class to open - */ - public static void setNotificationActivityClass(Class<? extends Activity> activityClass) { - mNotificationActivityClass = activityClass; - } - - PendingIntent getUserInputIntent(String needed) { - Intent intent = new Intent(getApplicationContext(), LaunchVPN.class); - intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); - intent.putExtra("need", needed); - Bundle b = new Bundle(); - b.putString("need", needed); - PendingIntent pIntent = PendingIntent.getActivity(this, 12, intent, 0); - return pIntent; - } - - 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.putExtra("PAGE", "graph"); - intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); - PendingIntent startLW = PendingIntent.getActivity(this, 0, intent, 0); - intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); - return startLW; - - } - synchronized void registerDeviceStateReceiver(OpenVPNManagement magnagement) { // Registers BroadcastReceiver to track network connection changes. IntentFilter filter = new IntentFilter(); @@ -426,6 +230,7 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac } + @Override public void userPause(boolean shouldBePaused) { if (mDeviceStateReceiver != null) mDeviceStateReceiver.userPause(shouldBePaused); @@ -439,6 +244,20 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac return false; } + /** + * used in Bitmask + */ + @Override + public boolean isVpnRunning() { + boolean hasVPNProcessThread = false; + synchronized (mProcessLock) { + hasVPNProcessThread = mProcessThread != null && mProcessThread.isAlive(); + } + + return hasVPNProcessThread; + + } + @Override public int onStartCommand(Intent intent, int flags, int startId) { @@ -470,11 +289,17 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac return START_REDELIVER_INTENT; } + /* TODO: check that for Bitmask */ // Always show notification here to avoid problem with startForeground timeout 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); + notificationManager.buildOpenVpnNotification( + mProfile != null ? mProfile.mName : "", + VpnStatus.getLastCleanLogMessage(this), + VpnStatus.getLastCleanLogMessage(this), + ConnectionStatus.LEVEL_START, + 0, + NOTIFICATION_CHANNEL_NEWSTATUS_ID); if (intent != null && intent.hasExtra(getPackageName() + ".profileUUID")) { String profileUUID = intent.getStringExtra(getPackageName() + ".profileUUID"); @@ -534,6 +359,13 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac } private void startOpenVPN() { + /** + * see change above (l. 292 ff) + */ + VpnStatus.logInfo(R.string.building_configration); + VpnStatus.updateStateString("VPN_GENERATE_CONFIG", "", R.string.building_configration, ConnectionStatus.LEVEL_START); + + try { mProfile.writeConfigFile(this); } catch (IOException e) { @@ -605,7 +437,6 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac ); } - private void stopOldOpenVPNProcess() { if (mManagement != null) { if (mOpenVPNThread != null) @@ -655,6 +486,8 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac @Override public void onCreate() { super.onCreate(); + notificationManager = new VpnNotificationManager(this, this); + notificationManager.createOpenVpnNotificationChannel(); } @Override @@ -671,6 +504,8 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac // Just in case unregister for state VpnStatus.removeStateListener(this); VpnStatus.flushLog(); + notificationManager.deleteNotificationChannel(NOTIFICATION_CHANNEL_BG_ID); + notificationManager.deleteNotificationChannel(NOTIFICATION_CHANNEL_NEWSTATUS_ID); } private String getTunConfigString() { @@ -832,8 +667,6 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac mLocalIPv6 = null; mDomain = null; - builder.setConfigureIntent(getGraphPendingIntent()); - try { //Debug.stopMethodTracing(); ParcelFileDescriptor tun = builder.establish(); @@ -1079,8 +912,13 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac // This also mean we are no longer connected, ignore bytecount messages until next // CONNECTED // Does not work :( - showNotification(VpnStatus.getLastCleanLogMessage(this), - VpnStatus.getLastCleanLogMessage(this), channel, 0, level); + notificationManager.buildOpenVpnNotification( + mProfile.mName, + VpnStatus.getLastCleanLogMessage(this), + VpnStatus.getLastCleanLogMessage(this), + level, + 0, + channel); } } @@ -1105,9 +943,13 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac humanReadableByteCount(diffIn / OpenVPNManagement.mBytecountInterval, true, getResources()), humanReadableByteCount(out, false, getResources()), humanReadableByteCount(diffOut / OpenVPNManagement.mBytecountInterval, true, getResources())); - - - showNotification(netstat, null, NOTIFICATION_CHANNEL_BG_ID, mConnecttime, LEVEL_CONNECTED); + notificationManager.buildOpenVpnNotification( + mProfile.mName, + netstat, + null, + LEVEL_CONNECTED, + mConnecttime, + NOTIFICATION_CHANNEL_BG_ID); } } @@ -1144,6 +986,23 @@ 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); + notificationManager.buildOpenVpnNotification( + mProfile.mName, + getString(resid), + getString(resid), + LEVEL_WAITING_FOR_USER_INPUT, + 0, + NOTIFICATION_CHANNEL_BG_ID); + + } + + @Override + public void onNotificationBuild(int notificationId, Notification notification) { + startForeground(notificationId, notification); + } + + @Override + public void onNotificationStop() { + stopForeground(true); } -} +}
\ No newline at end of file diff --git a/main/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java b/main/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java index e64ce2cd..e8aa0b51 100644 --- a/main/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java +++ b/main/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java @@ -23,6 +23,7 @@ import android.os.Bundle; import android.os.Handler; import android.os.Handler.Callback; import android.os.Message; +import android.preference.Preference; import android.preference.PreferenceManager; import android.support.annotation.Nullable; import android.text.SpannableString; @@ -56,8 +57,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.activities.VPNPreferences; import de.blinkt.openvpn.core.ConnectionStatus; import de.blinkt.openvpn.core.OpenVPNManagement; import de.blinkt.openvpn.core.OpenVPNService; @@ -70,6 +69,8 @@ import de.blinkt.openvpn.core.VpnStatus.StateListener; import static de.blinkt.openvpn.core.OpenVPNService.humanReadableByteCount; +import se.leap.bitmaskclient.Dashboard; + public class LogFragment extends ListFragment implements StateListener, SeekBar.OnSeekBarChangeListener, RadioGroup.OnCheckedChangeListener, VpnStatus.ByteCountListener { private static final String LOGTIMEFORMAT = "logtimeformat"; private static final int START_VPN_CONFIG = 0; @@ -437,7 +438,7 @@ public class LogFragment extends ListFragment implements StateListener, SeekBar. VpnProfile lastConnectedprofile = ProfileManager.get(getActivity(), VpnStatus.getLastConnectedVPNProfile()); if (lastConnectedprofile != null) { - Intent vprefintent = new Intent(getActivity(), VPNPreferences.class) + Intent vprefintent = new Intent(getActivity(), Dashboard.class) .putExtra(VpnProfile.EXTRA_PROFILEUUID, lastConnectedprofile.getUUIDString()); startActivityForResult(vprefintent, START_VPN_CONFIG); } else { @@ -448,7 +449,7 @@ public class LogFragment extends ListFragment implements StateListener, SeekBar. } else if (item.getItemId() == android.R.id.home) { // This is called when the Home (Up) button is pressed // in the Action Bar. - Intent parentActivityIntent = new Intent(getActivity(), MainActivity.class); + Intent parentActivityIntent = new Intent(getActivity(), Dashboard.class); parentActivityIntent.addFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); diff --git a/main/src/main/res/menu/logmenu.xml b/main/src/main/res/menu/logmenu.xml index 90eba679..2709b723 100644 --- a/main/src/main/res/menu/logmenu.xml +++ b/main/src/main/res/menu/logmenu.xml @@ -37,6 +37,8 @@ android:id="@+id/edit_vpn"
android:alphabeticShortcut="e"
android:icon="@drawable/ic_menu_edit"
- android:showAsAction="ifRoom"
- android:title="@string/edit_vpn"/>
-</menu>
\ No newline at end of file + android:showAsAction="withText|ifRoom"
+ android:title="@string/edit_vpn"
+ android:visible="false"/>
+
+</menu>
diff --git a/main/src/main/res/values-v21/refs.xml b/main/src/main/res/values-v21/refs.xml index ae9be13f..1af5ba02 100644 --- a/main/src/main/res/values-v21/refs.xml +++ b/main/src/main/res/values-v21/refs.xml @@ -12,16 +12,16 @@ <drawable name="ic_menu_save">@drawable/ic_check_white_24dp</drawable> <drawable name="ic_menu_view">@drawable/ic_filter_list_white_24dp</drawable> <drawable name="ic_menu_delete">@drawable/ic_delete_white_24dp</drawable> - <drawable name="ic_menu_copy">@drawable/ic_content_copy_white_24dp</drawable> +<!-- <drawable name="ic_menu_copy">@drawable/ic_content_copy_white_24dp</drawable> --> <drawable name="ic_menu_delete_grey">@drawable/ic_delete_grey600_24dp</drawable> <drawable name="ic_menu_edit">@drawable/ic_edit_white_24dp</drawable> - <drawable name="ic_menu_import">@drawable/ic_archive_white_24dp</drawable> +<!-- <drawable name="ic_menu_import">@drawable/ic_archive_white_24dp</drawable> --> <drawable name="vpn_item_edit">@drawable/ic_edit_grey600_24dp</drawable> - <drawable name="ic_menu_add">@drawable/ic_add_circle_outline_white_24dp</drawable> - <drawable name="ic_dialog_alert">@drawable/ic_warning_black_36dp</drawable> + <!--<drawable name="ic_menu_add">@drawable/ic_add_circle_outline_white_24dp</drawable>--> + <!-- <drawable name="ic_dialog_alert">@drawable/ic_warning_black_36dp</drawable> <drawable name="ic_menu_add_grey">@drawable/ic_add_circle_outline_grey600_24dp</drawable> <drawable name="ic_menu_import_grey">@drawable/ic_archive_grey600_24dp</drawable> <drawable name="ic_receipt">@drawable/ic_receipt_white_24dp</drawable> - <drawable name="ic_sort">@drawable/ic_sort_white_24dp</drawable> + <drawable name="ic_sort">@drawable/ic_sort_white_24dp</drawable> --> </resources>
\ No newline at end of file diff --git a/main/src/main/res/values/refs.xml b/main/src/main/res/values/refs.xml index c968b05c..2b00d5b5 100644 --- a/main/src/main/res/values/refs.xml +++ b/main/src/main/res/values/refs.xml @@ -13,15 +13,15 @@ <drawable name="ic_menu_view">@android:drawable/ic_menu_view</drawable> <drawable name="ic_menu_delete">@android:drawable/ic_menu_delete</drawable> <drawable name="ic_menu_edit">@android:drawable/ic_menu_edit</drawable> - <drawable name="ic_menu_import">@drawable/ic_menu_archive</drawable> - <drawable name="vpn_item_edit">@drawable/vpn_item_settings </drawable> + <!--<drawable name="ic_menu_import">@drawable/ic_menu_archive</drawable>--> + <!--<drawable name="vpn_item_edit">@drawable/vpn_item_settings </drawable>--> <drawable name="ic_menu_add">@android:drawable/ic_menu_add</drawable> <drawable name="ic_dialog_alert">@android:drawable/ic_dialog_alert</drawable> <drawable name="ic_menu_add_grey">@android:drawable/ic_menu_add</drawable> - <drawable name="ic_menu_import_grey">@drawable/ic_menu_archive</drawable> + <!--<drawable name="ic_menu_import_grey">@drawable/ic_menu_archive</drawable>--> <drawable name="ic_menu_delete_grey">@android:drawable/ic_menu_delete</drawable> - <drawable name="ic_menu_copy">@drawable/ic_menu_copy_holo_light</drawable> - <drawable name="ic_receipt">@drawable/ic_menu_log</drawable> + <!--<drawable name="ic_menu_copy">@drawable/ic_menu_copy_holo_light</drawable>--> + <!--<drawable name="ic_receipt">@drawable/ic_menu_log</drawable> --> <drawable name="ic_sort">@android:drawable/ic_menu_sort_by_size</drawable> </resources>
\ No newline at end of file |