summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2014-05-19 17:44:25 +0200
committerParménides GV <parmegv@sdf.org>2014-05-19 17:44:25 +0200
commitbaad99940a0bfa2e4c27a9cbc0f478e94b6d20ff (patch)
tree3332b0f32843652ec4a76bd32497d5593b81965b
parenta7f8db4fdb308f2fcd1cc1c5013ac930cc063ec1 (diff)
Copy necessary activities and fragments.
Now we need to decide what's our relationship with LogWindow and LaunchVPN, refactor its classes and fix ours so that we use the currently supported methods.
-rw-r--r--app/src/main/java/de/blinkt/openvpn/activities/ConfigConverter.java639
-rw-r--r--app/src/main/java/de/blinkt/openvpn/activities/CreateShortcuts.java154
-rw-r--r--app/src/main/java/de/blinkt/openvpn/activities/FileSelect.java220
-rw-r--r--app/src/main/java/de/blinkt/openvpn/activities/MainActivity.java103
-rw-r--r--app/src/main/java/de/blinkt/openvpn/activities/VPNPreferences.java165
-rw-r--r--app/src/main/java/de/blinkt/openvpn/fragments/AboutFragment.java297
-rw-r--r--app/src/main/java/de/blinkt/openvpn/fragments/FaqFragment.java36
-rw-r--r--app/src/main/java/de/blinkt/openvpn/fragments/FileSelectionFragment.java256
-rw-r--r--app/src/main/java/de/blinkt/openvpn/fragments/InlineFileTab.java66
-rw-r--r--app/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java2
-rw-r--r--app/src/main/java/de/blinkt/openvpn/fragments/OpenVpnPreferencesFragment.java48
-rw-r--r--app/src/main/java/de/blinkt/openvpn/fragments/SendDumpFragment.java94
-rw-r--r--app/src/main/java/de/blinkt/openvpn/fragments/Settings_Authentication.java214
-rw-r--r--app/src/main/java/de/blinkt/openvpn/fragments/Settings_Basic.java360
-rw-r--r--app/src/main/java/de/blinkt/openvpn/fragments/Settings_IP.java130
-rw-r--r--app/src/main/java/de/blinkt/openvpn/fragments/Settings_Obscure.java93
-rw-r--r--app/src/main/java/de/blinkt/openvpn/fragments/Settings_Routing.java88
-rw-r--r--app/src/main/java/de/blinkt/openvpn/fragments/ShowConfigFragment.java89
-rw-r--r--app/src/main/java/de/blinkt/openvpn/fragments/Utils.java221
-rw-r--r--app/src/main/java/de/blinkt/openvpn/fragments/VPNProfileList.java346
-rw-r--r--app/src/main/java/de/blinkt/openvpn/views/FileSelectLayout.java158
-rw-r--r--app/src/main/java/de/blinkt/openvpn/views/RemoteCNPreference.java141
-rw-r--r--app/src/main/java/de/blinkt/openvpn/views/SeekBarTicks.java69
-rw-r--r--app/src/main/res/layout/log_window.xml7
-rw-r--r--build.gradle23
25 files changed, 32 insertions, 3987 deletions
diff --git a/app/src/main/java/de/blinkt/openvpn/activities/ConfigConverter.java b/app/src/main/java/de/blinkt/openvpn/activities/ConfigConverter.java
deleted file mode 100644
index 2cb79e05..00000000
--- a/app/src/main/java/de/blinkt/openvpn/activities/ConfigConverter.java
+++ /dev/null
@@ -1,639 +0,0 @@
-
-package de.blinkt.openvpn.activities;
-
-import android.app.Activity;
-import android.app.AlertDialog;
-import android.app.AlertDialog.Builder;
-import android.content.ActivityNotFoundException;
-import android.content.Intent;
-import android.database.Cursor;
-import android.os.Bundle;
-import android.os.Environment;
-import android.provider.OpenableColumns;
-import android.security.KeyChain;
-import android.security.KeyChainAliasCallback;
-import android.text.TextUtils;
-import android.util.Base64;
-import android.view.Menu;
-import android.view.MenuInflater;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.CheckBox;
-import android.widget.LinearLayout;
-import android.widget.TextView;
-
-import junit.framework.Assert;
-
-import org.jetbrains.annotations.NotNull;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Vector;
-
-import se.leap.bitmaskclient.R;
-import de.blinkt.openvpn.VpnProfile;
-import de.blinkt.openvpn.core.ConfigParser;
-import de.blinkt.openvpn.core.ConfigParser.ConfigParseError;
-import de.blinkt.openvpn.core.ProfileManager;
-import de.blinkt.openvpn.fragments.Utils;
-import de.blinkt.openvpn.views.FileSelectLayout;
-
-import static de.blinkt.openvpn.views.FileSelectLayout.FileSelectCallback;
-
-public class ConfigConverter extends Activity implements FileSelectCallback {
-
- public static final String IMPORT_PROFILE = "de.blinkt.openvpn.IMPORT_PROFILE";
- private static final int RESULT_INSTALLPKCS12 = 7;
- private static final int CHOOSE_FILE_OFFSET = 1000;
- public static final String VPNPROFILE = "vpnProfile";
-
- private VpnProfile mResult;
-
- private transient List<String> mPathsegments;
-
- private String mAliasName = null;
-
-
- private Map<Utils.FileType, FileSelectLayout> fileSelectMap = new HashMap<Utils.FileType, FileSelectLayout>();
- private String mEmbeddedPwFile;
- private Vector<String> mLogEntries = new Vector<String>();
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- if (item.getItemId() == R.id.cancel) {
- setResult(Activity.RESULT_CANCELED);
- finish();
- } else if (item.getItemId() == R.id.ok) {
- if (mResult == null) {
- log("Importing the config had error, cannot save it");
- return true;
- }
-
- Intent in = installPKCS12();
-
- if (in != null)
- startActivityForResult(in, RESULT_INSTALLPKCS12);
- else
- saveProfile();
-
- return true;
- }
-
- return super.onOptionsItemSelected(item);
-
- }
-
- @Override
- protected void onSaveInstanceState(@NotNull Bundle outState) {
- super.onSaveInstanceState(outState);
- if (mResult != null)
- outState.putSerializable(VPNPROFILE, mResult);
- outState.putString("mAliasName", mAliasName);
-
-
-
- String[] logentries = mLogEntries.toArray(new String[mLogEntries.size()]);
-
- outState.putStringArray("logentries", logentries);
-
- int[] fileselects = new int[fileSelectMap.size()];
- int k = 0;
- for (Utils.FileType key : fileSelectMap.keySet()) {
- fileselects[k] = key.getValue();
- k++;
- }
- outState.putIntArray("fileselects", fileselects);
- outState.putString("pwfile",mEmbeddedPwFile);
- }
-
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent result) {
- if (requestCode == RESULT_INSTALLPKCS12 && resultCode == Activity.RESULT_OK) {
- showCertDialog();
- }
-
- if (resultCode == Activity.RESULT_OK && requestCode >= CHOOSE_FILE_OFFSET) {
- Utils.FileType type = Utils.FileType.getFileTypeByValue(requestCode - CHOOSE_FILE_OFFSET);
-
-
- FileSelectLayout fs = fileSelectMap.get(type);
- fs.parseResponse(result, this);
-
- String data = fs.getData();
-
- switch (type) {
- case USERPW_FILE:
- mEmbeddedPwFile = data;
- break;
- case PKCS12:
- mResult.mPKCS12Filename = data;
- break;
- case TLS_AUTH_FILE:
- mResult.mTLSAuthFilename = data;
- break;
- case CA_CERTIFICATE:
- mResult.mCaFilename = data;
- break;
- case CLIENT_CERTIFICATE:
- mResult.mClientCertFilename = data;
- break;
- case KEYFILE:
- mResult.mClientKeyFilename = data;
- break;
- default:
- Assert.fail();
- }
- }
-
- super.onActivityResult(requestCode, resultCode, result);
- }
-
- private void saveProfile() {
- Intent result = new Intent();
- ProfileManager vpl = ProfileManager.getInstance(this);
-
- if (!TextUtils.isEmpty(mEmbeddedPwFile))
- ConfigParser.useEmbbedUserAuth(mResult, mEmbeddedPwFile);
-
- vpl.addProfile(mResult);
- vpl.saveProfile(this, mResult);
- vpl.saveProfileList(this);
- result.putExtra(VpnProfile.EXTRA_PROFILEUUID, mResult.getUUID().toString());
- setResult(Activity.RESULT_OK, result);
- finish();
- }
-
- public void showCertDialog() {
- try {
- KeyChain.choosePrivateKeyAlias(this,
- new KeyChainAliasCallback() {
-
- public void alias(String alias) {
- // Credential alias selected. Remember the alias selection for future use.
- mResult.mAlias = alias;
- saveProfile();
- }
-
-
- },
- new String[]{"RSA"}, // List of acceptable key types. null for any
- null, // issuer, null for any
- mResult.mServerName, // host name of server requesting the cert, null if unavailable
- -1, // port of server requesting the cert, -1 if unavailable
- mAliasName); // alias to preselect, null if unavailable
- } catch (ActivityNotFoundException anf) {
- Builder ab = new AlertDialog.Builder(this);
- ab.setTitle(R.string.broken_image_cert_title);
- ab.setMessage(R.string.broken_image_cert);
- ab.setPositiveButton(android.R.string.ok, null);
- ab.show();
- }
- }
-
-
- private Intent installPKCS12() {
-
- if (!((CheckBox) findViewById(R.id.importpkcs12)).isChecked()) {
- setAuthTypeToEmbeddedPKCS12();
- return null;
-
- }
- String pkcs12datastr = mResult.mPKCS12Filename;
- if (VpnProfile.isEmbedded(pkcs12datastr)) {
- Intent inkeyIntent = KeyChain.createInstallIntent();
-
- pkcs12datastr = VpnProfile.getEmbeddedContent(pkcs12datastr);
-
-
- byte[] pkcs12data = Base64.decode(pkcs12datastr, Base64.DEFAULT);
-
-
- inkeyIntent.putExtra(KeyChain.EXTRA_PKCS12, pkcs12data);
-
- if (mAliasName.equals(""))
- mAliasName = null;
-
- if (mAliasName != null) {
- inkeyIntent.putExtra(KeyChain.EXTRA_NAME, mAliasName);
- }
- return inkeyIntent;
-
- }
- return null;
- }
-
-
- private void setAuthTypeToEmbeddedPKCS12() {
- if (VpnProfile.isEmbedded(mResult.mPKCS12Filename)) {
- if (mResult.mAuthenticationType == VpnProfile.TYPE_USERPASS_KEYSTORE)
- mResult.mAuthenticationType = VpnProfile.TYPE_USERPASS_PKCS12;
-
- if (mResult.mAuthenticationType == VpnProfile.TYPE_KEYSTORE)
- mResult.mAuthenticationType = VpnProfile.TYPE_PKCS12;
-
- }
- }
-
-
- private String getUniqueProfileName(String possibleName) {
-
- int i = 0;
-
- ProfileManager vpl = ProfileManager.getInstance(this);
-
- String newname = possibleName;
-
- // Default to
- if (mResult.mName != null && !ConfigParser.CONVERTED_PROFILE.equals(mResult.mName))
- newname = mResult.mName;
-
- while (newname == null || vpl.getProfileByName(newname) != null) {
- i++;
- if (i == 1)
- newname = getString(R.string.converted_profile);
- else
- newname = getString(R.string.converted_profile_i, i);
- }
-
- return newname;
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- MenuInflater inflater = getMenuInflater();
- inflater.inflate(R.menu.import_menu, menu);
- return true;
- }
-
- private String embedFile(String filename, Utils.FileType type) {
- if (filename == null)
- return null;
-
- // Already embedded, nothing to do
- if (VpnProfile.isEmbedded(filename))
- return filename;
-
- File possibleFile = findFile(filename, type);
- if (possibleFile == null)
- return filename;
- else
- return readFileContent(possibleFile, type == Utils.FileType.PKCS12);
-
- }
-
- private File findFile(String filename, Utils.FileType fileType) {
- File foundfile = findFileRaw(filename);
-
- if (foundfile == null && filename != null && !filename.equals("")) {
- log(R.string.import_could_not_open, filename);
- addFileSelectDialog(fileType);
- }
-
-
- return foundfile;
- }
-
- private void addFileSelectDialog(Utils.FileType type) {
- int titleRes = 0;
- String value = null;
- switch (type) {
- case KEYFILE:
- titleRes = R.string.client_key_title;
- if (mResult != null)
- value = mResult.mClientKeyFilename;
- break;
- case CLIENT_CERTIFICATE:
- titleRes = R.string.client_certificate_title;
- if (mResult != null)
- value = mResult.mClientCertFilename;
- break;
- case CA_CERTIFICATE:
- titleRes = R.string.ca_title;
- if (mResult != null)
- value = mResult.mCaFilename;
- break;
- case TLS_AUTH_FILE:
- titleRes = R.string.tls_auth_file;
- if (mResult != null)
- value = mResult.mTLSAuthFilename;
- break;
- case PKCS12:
- titleRes = R.string.client_pkcs12_title;
- if (mResult != null)
- value = mResult.mPKCS12Filename;
- break;
-
- case USERPW_FILE:
- titleRes = R.string.userpw_file;
- value = mEmbeddedPwFile;
- break;
-
- }
-
- boolean isCert = type == Utils.FileType.CA_CERTIFICATE || type == Utils.FileType.CLIENT_CERTIFICATE;
- FileSelectLayout fl = new FileSelectLayout(this, getString(titleRes), isCert);
- fileSelectMap.put(type, fl);
- fl.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
-
- ((LinearLayout) findViewById(R.id.config_convert_root)).addView(fl, 2);
- findViewById(R.id.files_missing_hint).setVisibility(View.VISIBLE);
- fl.setData(value, this);
- int i = getFileLayoutOffset(type);
- fl.setCaller(this, i, type);
-
- }
-
- private int getFileLayoutOffset(Utils.FileType type) {
- return CHOOSE_FILE_OFFSET + type.getValue();
- }
-
-
- private File findFileRaw(String filename) {
- if (filename == null || filename.equals(""))
- return null;
-
- // Try diffent path relative to /mnt/sdcard
- File sdcard = Environment.getExternalStorageDirectory();
- File root = new File("/");
-
- HashSet<File> dirlist = new HashSet<File>();
-
- for (int i = mPathsegments.size() - 1; i >= 0; i--) {
- String path = "";
- for (int j = 0; j <= i; j++) {
- path += "/" + mPathsegments.get(j);
- }
- // Do a little hackish dance for the Android File Importer
- // /document/primary:ovpn/openvpn-imt.conf
-
-
- if (path.indexOf(':') != -1 && path.indexOf('/') > path.indexOf(':')) {
- String possibleDir = path.substring(path.indexOf(':') + 1, path.length());
- possibleDir = possibleDir.substring(0, possibleDir.lastIndexOf('/'));
-
-
- dirlist.add(new File(sdcard, possibleDir));
-
- }
- dirlist.add(new File(path));
-
-
- }
- dirlist.add(sdcard);
- dirlist.add(root);
-
-
- String[] fileparts = filename.split("/");
- for (File rootdir : dirlist) {
- String suffix = "";
- for (int i = fileparts.length - 1; i >= 0; i--) {
- if (i == fileparts.length - 1)
- suffix = fileparts[i];
- else
- suffix = fileparts[i] + "/" + suffix;
-
- File possibleFile = new File(rootdir, suffix);
- if (!possibleFile.canRead())
- continue;
-
- // read the file inline
- return possibleFile;
-
- }
- }
- return null;
- }
-
- String readFileContent(File possibleFile, boolean base64encode) {
- byte[] filedata;
- try {
- filedata = readBytesFromFile(possibleFile);
- } catch (IOException e) {
- log(e.getLocalizedMessage());
- return null;
- }
-
- String data;
- if (base64encode) {
- data = Base64.encodeToString(filedata, Base64.DEFAULT);
- } else {
- data = new String(filedata);
-
- }
-
- return VpnProfile.DISPLAYNAME_TAG + possibleFile.getName() + VpnProfile.INLINE_TAG + data;
-
- }
-
-
- private byte[] readBytesFromFile(File file) throws IOException {
- InputStream input = new FileInputStream(file);
-
- long len = file.length();
- if (len > VpnProfile.MAX_EMBED_FILE_SIZE)
- throw new IOException("File size of file to import too large.");
-
- // Create the byte array to hold the data
- byte[] bytes = new byte[(int) len];
-
- // Read in the bytes
- int offset = 0;
- int bytesRead;
- while (offset < bytes.length
- && (bytesRead = input.read(bytes, offset, bytes.length - offset)) >= 0) {
- offset += bytesRead;
- }
-
- input.close();
- return bytes;
- }
-
- void embedFiles() {
- // This where I would like to have a c++ style
- // void embedFile(std::string & option)
-
- if (mResult.mPKCS12Filename != null) {
- File pkcs12file = findFileRaw(mResult.mPKCS12Filename);
- if (pkcs12file != null) {
- mAliasName = pkcs12file.getName().replace(".p12", "");
- } else {
- mAliasName = "Imported PKCS12";
- }
- }
-
-
- mResult.mCaFilename = embedFile(mResult.mCaFilename, Utils.FileType.CA_CERTIFICATE);
- mResult.mClientCertFilename = embedFile(mResult.mClientCertFilename, Utils.FileType.CLIENT_CERTIFICATE);
- mResult.mClientKeyFilename = embedFile(mResult.mClientKeyFilename, Utils.FileType.KEYFILE);
- mResult.mTLSAuthFilename = embedFile(mResult.mTLSAuthFilename, Utils.FileType.TLS_AUTH_FILE);
- mResult.mPKCS12Filename = embedFile(mResult.mPKCS12Filename, Utils.FileType.PKCS12);
- mEmbeddedPwFile = embedFile(mResult.mPassword, Utils.FileType.USERPW_FILE);
- }
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
-
- setContentView(R.layout.config_converter);
- super.onCreate(savedInstanceState);
-
- if (savedInstanceState != null && savedInstanceState.containsKey(VPNPROFILE)) {
- mResult = (VpnProfile) savedInstanceState.getSerializable(VPNPROFILE);
- mAliasName = savedInstanceState.getString("mAliasName");
- mEmbeddedPwFile = savedInstanceState.getString("pwfile");
-
- if (savedInstanceState.containsKey("logentries")) {
- //noinspection ConstantConditions
- for (String logItem : savedInstanceState.getStringArray("logentries"))
- log(logItem);
- }
- if (savedInstanceState.containsKey("fileselects")) {
- //noinspection ConstantConditions
- for (int k : savedInstanceState.getIntArray("fileselects")) {
- addFileSelectDialog(Utils.FileType.getFileTypeByValue(k));
- }
- }
- return;
- }
-
-
- final android.content.Intent intent = getIntent();
-
- if (intent != null) {
- final android.net.Uri data = intent.getData();
- if (data != null) {
- //log(R.string.import_experimental);
- log(R.string.importing_config, data.toString());
- try {
- String possibleName = null;
- if ((data.getScheme() != null && data.getScheme().equals("file")) ||
- (data.getLastPathSegment() != null &&
- (data.getLastPathSegment().endsWith(".ovpn") ||
- data.getLastPathSegment().endsWith(".conf")))
- ) {
- possibleName = data.getLastPathSegment();
- if (possibleName.lastIndexOf('/') != -1)
- possibleName = possibleName.substring(possibleName.lastIndexOf('/') + 1);
-
- }
- InputStream is = getContentResolver().openInputStream(data);
- mPathsegments = data.getPathSegments();
-
- Cursor cursor = null;
- if (data!=null)
- cursor = getContentResolver().query(data, null, null, null, null);
-
-
- try {
-
-
- if (cursor!=null && cursor.moveToFirst()) {
- int columnIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
-
- if (columnIndex != -1) {
- String displayName = cursor.getString(columnIndex);
- if (displayName != null)
- possibleName = displayName;
- }
- columnIndex = cursor.getColumnIndex("mime_type");
- if (columnIndex != -1) {
- log("Opening Mime TYPE: " + cursor.getString(columnIndex));
- }
- }
- } finally {
- if(cursor!=null)
- cursor.close();
- }
- if (possibleName != null) {
- possibleName = possibleName.replace(".ovpn", "");
- possibleName = possibleName.replace(".conf", "");
- }
-
- doImport(is, possibleName);
-
- } catch (FileNotFoundException e) {
- log(R.string.import_content_resolve_error);
- }
- }
-
- // We parsed the intent, relay on saved instance for restoring
- setIntent(null);
- }
-
-
- }
-
-
- @Override
- protected void onStart() {
- super.onStart();
-
-
- }
-
- private void log(String logmessage) {
- mLogEntries.add(logmessage);
- TextView tv = new TextView(this);
- tv.setText(logmessage);
- LinearLayout logLayout = (LinearLayout) findViewById(R.id.config_convert_root);
- logLayout.addView(tv);
- }
-
- private void doImport(InputStream is, String newName) {
- ConfigParser cp = new ConfigParser();
- try {
- InputStreamReader isr = new InputStreamReader(is);
-
- cp.parseConfig(isr);
- mResult = cp.convertProfile();
- embedFiles();
- displayWarnings();
- mResult.mName = getUniqueProfileName(newName);
-
- log(R.string.import_done);
- return;
-
- } catch (IOException e) {
- log(R.string.error_reading_config_file);
- log(e.getLocalizedMessage());
- } catch (ConfigParseError e) {
- log(R.string.error_reading_config_file);
- log(e.getLocalizedMessage());
- }
- mResult = null;
-
- }
-
- private void displayWarnings() {
- if (mResult.mUseCustomConfig) {
- log(R.string.import_warning_custom_options);
- String copt = mResult.mCustomConfigOptions;
- if (copt.startsWith("#")) {
- int until = copt.indexOf('\n');
- copt = copt.substring(until + 1);
- }
-
- log(copt);
- }
-
- if (mResult.mAuthenticationType == VpnProfile.TYPE_KEYSTORE ||
- mResult.mAuthenticationType == VpnProfile.TYPE_USERPASS_KEYSTORE) {
- findViewById(R.id.importpkcs12).setVisibility(View.VISIBLE);
- }
-
- }
-
- private void log(int ressourceId, Object... formatArgs) {
- log(getString(ressourceId, formatArgs));
- }
-
-
-}
diff --git a/app/src/main/java/de/blinkt/openvpn/activities/CreateShortcuts.java b/app/src/main/java/de/blinkt/openvpn/activities/CreateShortcuts.java
deleted file mode 100644
index 590b7150..00000000
--- a/app/src/main/java/de/blinkt/openvpn/activities/CreateShortcuts.java
+++ /dev/null
@@ -1,154 +0,0 @@
-package de.blinkt.openvpn.activities;
-
-import android.app.ListActivity;
-import android.content.Intent;
-import android.os.Bundle;
-import android.os.Parcelable;
-import android.view.View;
-import android.widget.AdapterView;
-import android.widget.AdapterView.OnItemClickListener;
-import android.widget.ArrayAdapter;
-import android.widget.ListView;
-import android.widget.TextView;
-import de.blinkt.openvpn.LaunchVPN;
-import se.leap.bitmaskclient.R;
-import de.blinkt.openvpn.VpnProfile;
-import de.blinkt.openvpn.core.ProfileManager;
-
-import java.util.Collection;
-import java.util.Vector;
-
-/**
- * This Activity actually handles two stages of a launcher shortcut's life cycle.
- *
- * 1. Your application offers to provide shortcuts to the launcher. When
- * the user installs a shortcut, an activity within your application
- * generates the actual shortcut and returns it to the launcher, where it
- * is shown to the user as an icon.
- *
- * 2. Any time the user clicks on an installed shortcut, an intent is sent.
- * Typically this would then be handled as necessary by an activity within
- * your application.
- *
- * We handle stage 1 (creating a shortcut) by simply sending back the information (in the form
- * of an {@link android.content.Intent} that the launcher will use to create the shortcut.
- *
- * You can also implement this in an interactive way, by having your activity actually present
- * UI for the user to select the specific nature of the shortcut, such as a contact, picture, URL,
- * media item, or action.
- *
- * We handle stage 2 (responding to a shortcut) in this sample by simply displaying the contents
- * of the incoming {@link android.content.Intent}.
- *
- * In a real application, you would probably use the shortcut intent to display specific content
- * or start a particular operation.
- */
-public class CreateShortcuts extends ListActivity implements OnItemClickListener {
-
-
- private static final int START_VPN_PROFILE= 70;
-
-
- private ProfileManager mPM;
- private VpnProfile mSelectedProfile;
-
- @Override
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
-
- mPM =ProfileManager.getInstance(this);
-
- }
-
- @Override
- protected void onStart() {
- super.onStart();
- // Resolve the intent
-
- createListView();
- }
-
- private void createListView() {
- ListView lv = getListView();
- //lv.setTextFilterEnabled(true);
-
- Collection<VpnProfile> vpnList = mPM.getProfiles();
-
- Vector<String> vpnNames=new Vector<String>();
- for (VpnProfile vpnProfile : vpnList) {
- vpnNames.add(vpnProfile.mName);
- }
-
-
-
- ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,vpnNames);
- lv.setAdapter(adapter);
-
- lv.setOnItemClickListener(this);
- }
-
- /**
- * This function creates a shortcut and returns it to the caller. There are actually two
- * intents that you will send back.
- *
- * The first intent serves as a container for the shortcut and is returned to the launcher by
- * setResult(). This intent must contain three fields:
- *
- * <ul>
- * <li>{@link android.content.Intent#EXTRA_SHORTCUT_INTENT} The shortcut intent.</li>
- * <li>{@link android.content.Intent#EXTRA_SHORTCUT_NAME} The text that will be displayed with
- * the shortcut.</li>
- * <li>{@link android.content.Intent#EXTRA_SHORTCUT_ICON} The shortcut's icon, if provided as a
- * bitmap, <i>or</i> {@link android.content.Intent#EXTRA_SHORTCUT_ICON_RESOURCE} if provided as
- * a drawable resource.</li>
- * </ul>
- *
- * If you use a simple drawable resource, note that you must wrapper it using
- * {@link android.content.Intent.ShortcutIconResource}, as shown below. This is required so
- * that the launcher can access resources that are stored in your application's .apk file. If
- * you return a bitmap, such as a thumbnail, you can simply put the bitmap into the extras
- * bundle using {@link android.content.Intent#EXTRA_SHORTCUT_ICON}.
- *
- * The shortcut intent can be any intent that you wish the launcher to send, when the user
- * clicks on the shortcut. Typically this will be {@link android.content.Intent#ACTION_VIEW}
- * with an appropriate Uri for your content, but any Intent will work here as long as it
- * triggers the desired action within your Activity.
- * @param profile
- */
- private void setupShortcut(VpnProfile profile) {
- // First, set up the shortcut intent. For this example, we simply create an intent that
- // will bring us directly back to this activity. A more typical implementation would use a
- // data Uri in order to display a more specific result, or a custom action in order to
- // launch a specific operation.
-
- Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
- shortcutIntent.setClass(this, LaunchVPN.class);
- shortcutIntent.putExtra(LaunchVPN.EXTRA_KEY,profile.getUUID().toString());
-
- // Then, set up the container intent (the response to the caller)
-
- Intent intent = new Intent();
- intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
- intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, profile.getName());
- Parcelable iconResource = Intent.ShortcutIconResource.fromContext(
- this, R.drawable.icon);
- intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
-
- // Now, return the result to the launcher
-
- setResult(RESULT_OK, intent);
- }
-
-
- @Override
- public void onItemClick(AdapterView<?> parent, View view, int position,
- long id) {
- String profileName = ((TextView) view).getText().toString();
-
- VpnProfile profile = mPM.getProfileByName(profileName);
-
- setupShortcut(profile);
- finish();
- }
-
-}
diff --git a/app/src/main/java/de/blinkt/openvpn/activities/FileSelect.java b/app/src/main/java/de/blinkt/openvpn/activities/FileSelect.java
deleted file mode 100644
index a30b694c..00000000
--- a/app/src/main/java/de/blinkt/openvpn/activities/FileSelect.java
+++ /dev/null
@@ -1,220 +0,0 @@
-package de.blinkt.openvpn.activities;
-
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-
-import android.app.ActionBar;
-import android.app.ActionBar.Tab;
-import android.app.Activity;
-import android.app.AlertDialog;
-import android.app.AlertDialog.Builder;
-import android.app.Fragment;
-import android.app.FragmentTransaction;
-import android.content.Intent;
-import android.os.Bundle;
-import android.os.Environment;
-import android.util.Base64;
-
-import se.leap.bitmaskclient.R;
-import de.blinkt.openvpn.VpnProfile;
-import de.blinkt.openvpn.fragments.FileSelectionFragment;
-import de.blinkt.openvpn.fragments.InlineFileTab;
-
-public class FileSelect extends Activity {
- public static final String RESULT_DATA = "RESULT_PATH";
- public static final String START_DATA = "START_DATA";
- public static final String WINDOW_TITLE = "WINDOW_TILE";
- public static final String NO_INLINE_SELECTION = "de.blinkt.openvpn.NO_INLINE_SELECTION";
- public static final String SHOW_CLEAR_BUTTON = "de.blinkt.openvpn.SHOW_CLEAR_BUTTON";
- public static final String DO_BASE64_ENCODE = "de.blinkt.openvpn.BASE64ENCODE";
-
- private FileSelectionFragment mFSFragment;
- private InlineFileTab mInlineFragment;
- private String mData;
- private Tab inlineFileTab;
- private Tab fileExplorerTab;
- private boolean mNoInline;
- private boolean mShowClear;
- private boolean mBase64Encode;
-
-
- public void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.file_dialog);
-
- mData = getIntent().getStringExtra(START_DATA);
- if(mData==null)
- mData=Environment.getExternalStorageDirectory().getPath();
-
- String title = getIntent().getStringExtra(WINDOW_TITLE);
- int titleId = getIntent().getIntExtra(WINDOW_TITLE, 0);
- if(titleId!=0)
- title =getString(titleId);
- if(title!=null)
- setTitle(title);
-
- mNoInline = getIntent().getBooleanExtra(NO_INLINE_SELECTION, false);
- mShowClear = getIntent().getBooleanExtra(SHOW_CLEAR_BUTTON, false);
- mBase64Encode = getIntent().getBooleanExtra(DO_BASE64_ENCODE, false);
-
- ActionBar bar = getActionBar();
- bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
- fileExplorerTab = bar.newTab().setText(R.string.file_explorer_tab);
- inlineFileTab = bar.newTab().setText(R.string.inline_file_tab);
-
- mFSFragment = new FileSelectionFragment();
- fileExplorerTab.setTabListener(new MyTabsListener<FileSelectionFragment>(this, mFSFragment));
- bar.addTab(fileExplorerTab);
-
- if(!mNoInline) {
- mInlineFragment = new InlineFileTab();
- inlineFileTab.setTabListener(new MyTabsListener<InlineFileTab>(this, mInlineFragment));
- bar.addTab(inlineFileTab);
- } else {
- mFSFragment.setNoInLine();
- }
-
-
- }
-
- public boolean showClear() {
- if(mData == null || mData.equals(""))
- return false;
- else
- return mShowClear;
- }
-
- protected class MyTabsListener<T extends Fragment> implements ActionBar.TabListener
- {
- private Fragment mFragment;
- private boolean mAdded=false;
-
- public MyTabsListener( Activity activity, Fragment fragment){
- this.mFragment = fragment;
- }
-
- public void onTabSelected(Tab tab, FragmentTransaction ft) {
- // Check if the fragment is already initialized
- if (!mAdded) {
- // If not, instantiate and add it to the activity
- ft.add(android.R.id.content, mFragment);
- mAdded =true;
- } else {
- // If it exists, simply attach it in order to show it
- ft.attach(mFragment);
- }
- }
-
- @Override
- public void onTabUnselected(Tab tab, FragmentTransaction ft) {
- ft.detach(mFragment);
- }
-
- @Override
- public void onTabReselected(Tab tab, FragmentTransaction ft) {
-
- }
- }
-
- public void importFile(String path) {
- File ifile = new File(path);
- Exception fe = null;
- try {
-
- String data = "";
-
- byte[] fileData = readBytesFromFile(ifile) ;
- if(mBase64Encode)
- data += Base64.encodeToString(fileData, Base64.DEFAULT);
- else
- data += new String(fileData);
-
- mData =data;
-
- /*
- mInlineFragment.setData(data);
- getActionBar().selectTab(inlineFileTab); */
- saveInlineData(ifile.getName(), data);
- } catch (FileNotFoundException e) {
- fe = e;
- } catch (IOException e) {
- fe =e;
- }
- if(fe!=null) {
- Builder ab = new AlertDialog.Builder(this);
- ab.setTitle(R.string.error_importing_file);
- ab.setMessage(getString(R.string.import_error_message) + "\n" + fe.getLocalizedMessage());
- ab.setPositiveButton(android.R.string.ok, null);
- ab.show();
- }
- }
-
- static private byte[] readBytesFromFile(File file) throws IOException {
- InputStream input = new FileInputStream(file);
-
- long len= file.length();
- if (len > VpnProfile.MAX_EMBED_FILE_SIZE)
- throw new IOException("selected file size too big to embed into profile");
-
- // Create the byte array to hold the data
- byte[] bytes = new byte[(int) len];
-
- // Read in the bytes
- int offset = 0;
- int bytesRead = 0;
- while (offset < bytes.length
- && (bytesRead=input.read(bytes, offset, bytes.length-offset)) >= 0) {
- offset += bytesRead;
- }
-
- input.close();
- return bytes;
- }
-
-
- public void setFile(String path) {
- Intent intent = new Intent();
- intent.putExtra(RESULT_DATA, path);
- setResult(Activity.RESULT_OK,intent);
- finish();
- }
-
- public String getSelectPath() {
- if(VpnProfile.isEmbedded(mData))
- return mData;
- else
- return Environment.getExternalStorageDirectory().getPath();
- }
-
- public CharSequence getInlineData() {
- if(VpnProfile.isEmbedded(mData))
- return VpnProfile.getEmbeddedContent(mData);
- else
- return "";
- }
-
- public void clearData() {
- Intent intent = new Intent();
- intent.putExtra(RESULT_DATA, (String)null);
- setResult(Activity.RESULT_OK,intent);
- finish();
-
- }
-
- public void saveInlineData(String fileName, String string) {
- Intent intent = new Intent();
-
- if(fileName==null)
- intent.putExtra(RESULT_DATA, VpnProfile.INLINE_TAG + string);
- else
- intent.putExtra(RESULT_DATA,VpnProfile.DISPLAYNAME_TAG + fileName + VpnProfile.INLINE_TAG + string);
- setResult(Activity.RESULT_OK, intent);
- finish();
-
- }
-}
diff --git a/app/src/main/java/de/blinkt/openvpn/activities/MainActivity.java b/app/src/main/java/de/blinkt/openvpn/activities/MainActivity.java
deleted file mode 100644
index 26cd0269..00000000
--- a/app/src/main/java/de/blinkt/openvpn/activities/MainActivity.java
+++ /dev/null
@@ -1,103 +0,0 @@
-package de.blinkt.openvpn.activities;
-
-import android.app.ActionBar;
-import android.app.ActionBar.Tab;
-import android.app.Activity;
-import android.app.Fragment;
-import android.app.FragmentTransaction;
-import android.content.Intent;
-
-import se.leap.bitmaskclient.R;
-import de.blinkt.openvpn.fragments.*;
-
-
-public class MainActivity extends Activity {
-
- protected void onCreate(android.os.Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- ActionBar bar = getActionBar();
- bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
-
- Tab vpnListTab = bar.newTab().setText(R.string.vpn_list_title);
- Tab generalTab = bar.newTab().setText(R.string.generalsettings);
- Tab faqtab = bar.newTab().setText(R.string.faq);
- Tab abouttab = bar.newTab().setText(R.string.about);
-
- vpnListTab.setTabListener(new TabListener<VPNProfileList>("profiles", VPNProfileList.class));
- generalTab.setTabListener(new TabListener<GeneralSettings>("settings", GeneralSettings.class));
- faqtab.setTabListener(new TabListener<FaqFragment>("faq", FaqFragment.class));
- abouttab.setTabListener(new TabListener<AboutFragment>("about", AboutFragment.class));
-
- bar.addTab(vpnListTab);
- bar.addTab(generalTab);
- bar.addTab(faqtab);
- bar.addTab(abouttab);
-
- if (false) {
- Tab logtab = bar.newTab().setText("Log");
- logtab.setTabListener(new TabListener<LogFragment>("log", LogFragment.class));
- bar.addTab(logtab);
- }
-
- if(SendDumpFragment.getLastestDump(this)!=null) {
- Tab sendDump = bar.newTab().setText(R.string.crashdump);
- sendDump.setTabListener(new TabListener<SendDumpFragment>("crashdump",SendDumpFragment.class));
- bar.addTab(sendDump);
- }
-
- }
-
- protected class TabListener<T extends Fragment> implements ActionBar.TabListener
- {
- private Fragment mFragment;
- private String mTag;
- private Class<T> mClass;
-
- public TabListener(String tag, Class<T> clz) {
- mTag = tag;
- mClass = clz;
-
- // Check to see if we already have a fragment for this tab, probably
- // from a previously saved state. If so, deactivate it, because our
- // initial state is that a tab isn't shown.
- mFragment = getFragmentManager().findFragmentByTag(mTag);
- if (mFragment != null && !mFragment.isDetached()) {
- FragmentTransaction ft = getFragmentManager().beginTransaction();
- ft.detach(mFragment);
- ft.commit();
- }
- }
-
- public void onTabSelected(Tab tab, FragmentTransaction ft) {
- if (mFragment == null) {
- mFragment = Fragment.instantiate(MainActivity.this, mClass.getName());
- ft.add(android.R.id.content, mFragment, mTag);
- } else {
- ft.attach(mFragment);
- }
- }
-
- public void onTabUnselected(Tab tab, FragmentTransaction ft) {
- if (mFragment != null) {
- ft.detach(mFragment);
- }
- }
-
-
- @Override
- public void onTabReselected(Tab tab, FragmentTransaction ft) {
-
- }
- }
-
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
-
- System.out.println(data);
-
-
- }
-
-
-}
diff --git a/app/src/main/java/de/blinkt/openvpn/activities/VPNPreferences.java b/app/src/main/java/de/blinkt/openvpn/activities/VPNPreferences.java
deleted file mode 100644
index 1ee9a5f4..00000000
--- a/app/src/main/java/de/blinkt/openvpn/activities/VPNPreferences.java
+++ /dev/null
@@ -1,165 +0,0 @@
-package de.blinkt.openvpn.activities;
-
-import java.util.List;
-
-import android.annotation.TargetApi;
-import android.app.AlertDialog;
-import android.app.Fragment;
-import android.content.DialogInterface;
-import android.content.Intent;
-import android.os.Build;
-import android.os.Bundle;
-import android.preference.PreferenceActivity;
-import android.preference.PreferenceFragment;
-import android.view.Menu;
-import android.view.MenuItem;
-
-import se.leap.bitmaskclient.R;
-import de.blinkt.openvpn.VpnProfile;
-import de.blinkt.openvpn.core.ProfileManager;
-import de.blinkt.openvpn.fragments.Settings_Authentication;
-import de.blinkt.openvpn.fragments.Settings_Basic;
-import de.blinkt.openvpn.fragments.Settings_IP;
-import de.blinkt.openvpn.fragments.Settings_Obscure;
-import de.blinkt.openvpn.fragments.Settings_Routing;
-import de.blinkt.openvpn.fragments.ShowConfigFragment;
-import de.blinkt.openvpn.fragments.VPNProfileList;
-
-
-public class VPNPreferences extends PreferenceActivity {
-
- static final Class validFragments[] = new Class[] {
- Settings_Authentication.class, Settings_Basic.class, Settings_IP.class,
- Settings_Obscure.class, Settings_Routing.class, ShowConfigFragment.class
- };
-
- private String mProfileUUID;
- private VpnProfile mProfile;
-
- public VPNPreferences() {
- super();
- }
-
-
- @TargetApi(Build.VERSION_CODES.KITKAT)
- @Override
- protected boolean isValidFragment(String fragmentName) {
- for (Class c: validFragments)
- if (c.getName().equals(fragmentName))
- return true;
- return false;
-
- }
-
- @Override
- protected void onStop() {
- super.onStop();
- }
-
- @Override
- protected void onSaveInstanceState(Bundle outState) {
- outState.putString(getIntent().getStringExtra(getPackageName() + ".profileUUID"),mProfileUUID);
- super.onSaveInstanceState(outState);
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- Intent intent = getIntent();
-
-
- if(intent!=null) {
- String profileUUID = intent.getStringExtra(getPackageName() + ".profileUUID");
- if(profileUUID==null) {
- Bundle initialArguments = getIntent().getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
- profileUUID = initialArguments.getString(getPackageName() + ".profileUUID");
- }
- if(profileUUID!=null){
-
- mProfileUUID = profileUUID;
- mProfile = ProfileManager.get(this,mProfileUUID);
-
- }
- }
- // When a profile is deleted from a category fragment in hadset mod we need to finish
- // this activity as well when returning
- if (mProfile==null || mProfile.profileDleted) {
- setResult(VPNProfileList.RESULT_VPN_DELETED);
- finish();
- }
- }
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- mProfileUUID = getIntent().getStringExtra(getPackageName() + ".profileUUID");
- if(savedInstanceState!=null){
- String savedUUID = savedInstanceState.getString(getPackageName() + ".profileUUID");
- if(savedUUID!=null)
- mProfileUUID=savedUUID;
- }
-
- mProfile = ProfileManager.get(this,mProfileUUID);
- if(mProfile!=null) {
- setTitle(getString(R.string.edit_profile_title, mProfile.getName()));
- }
- super.onCreate(savedInstanceState);
- }
-
-
-
- @Override
- public void onBuildHeaders(List<Header> target) {
- loadHeadersFromResource(R.xml.vpn_headers, target);
- for (Header header : target) {
- if(header.fragmentArguments==null)
- header.fragmentArguments = new Bundle();
- header.fragmentArguments.putString(getPackageName() + ".profileUUID",mProfileUUID);
- }
- }
-
- @Override
- public void onBackPressed() {
- setResult(RESULT_OK, getIntent());
- super.onBackPressed();
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- if(item.getItemId() == R.id.remove_vpn)
- askProfileRemoval();
- return super.onOptionsItemSelected(item);
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
-
- getMenuInflater().inflate(R.menu.vpnpreferences_menu, menu);
-
- return super.onCreateOptionsMenu(menu);
- }
-
- private void askProfileRemoval() {
- AlertDialog.Builder dialog = new AlertDialog.Builder(this);
- dialog.setTitle("Confirm deletion");
- dialog.setMessage(getString(R.string.remove_vpn_query, mProfile.mName));
-
- dialog.setPositiveButton(android.R.string.yes,
- new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- removeProfile(mProfile);
- }
-
- });
- dialog.setNegativeButton(android.R.string.no,null);
- dialog.create().show();
- }
-
- protected void removeProfile(VpnProfile profile) {
- ProfileManager.getInstance(this).removeProfile(this,profile);
- setResult(VPNProfileList.RESULT_VPN_DELETED);
- finish();
-
- }
-}
-
diff --git a/app/src/main/java/de/blinkt/openvpn/fragments/AboutFragment.java b/app/src/main/java/de/blinkt/openvpn/fragments/AboutFragment.java
deleted file mode 100644
index f878e4fb..00000000
--- a/app/src/main/java/de/blinkt/openvpn/fragments/AboutFragment.java
+++ /dev/null
@@ -1,297 +0,0 @@
-package de.blinkt.openvpn.fragments;
-
-import android.app.Fragment;
-import android.app.PendingIntent;
-import android.content.*;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager.NameNotFoundException;
-import android.os.Bundle;
-import android.os.IBinder;
-import android.os.RemoteException;
-import android.text.Html;
-import android.text.SpannableString;
-import android.text.Spanned;
-import android.text.TextUtils;
-import android.text.method.LinkMovementMethod;
-import android.text.style.ClickableSpan;
-import android.util.Log;
-import android.util.Pair;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.webkit.WebView;
-import android.widget.TextView;
-import com.android.vending.billing.IInAppBillingService;
-import se.leap.bitmaskclient.R;
-import de.blinkt.openvpn.core.VpnStatus;
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import java.util.*;
-
-public class AboutFragment extends Fragment implements View.OnClickListener {
-
- public static final String INAPPITEM_TYPE_INAPP = "inapp";
- public static final String RESPONSE_CODE = "RESPONSE_CODE";
- private static final int DONATION_CODE = 12;
- private static final int BILLING_RESPONSE_RESULT_OK = 0;
- private static final String RESPONSE_BUY_INTENT = "BUY_INTENT";
- private static final String[] donationSkus = { "donation1eur", "donation2eur", "donation5eur", "donation10eur",
- "donation1337eur","donation23eur","donation25eur",};
- IInAppBillingService mService;
- Hashtable<View, String> viewToProduct = new Hashtable<View, String>();
- ServiceConnection mServiceConn = new ServiceConnection() {
- @Override
- public void onServiceDisconnected(ComponentName name) {
- mService = null;
- }
-
- @Override
- public void onServiceConnected(ComponentName name,
- IBinder service) {
- mService = IInAppBillingService.Stub.asInterface(service);
- initGooglePlayDonation();
-
- }
- };
-
- private void initGooglePlayDonation() {
- new Thread("queryGMSInApp") {
- @Override
- public void run() {
- initGMSDonateOptions();
- }
- }.start();
- }
-
- private TextView gmsTextView;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- getActivity().bindService(new
- Intent("com.android.vending.billing.InAppBillingService.BIND"),
- mServiceConn, Context.BIND_AUTO_CREATE);
-
- }
-
- @Override
- public void onDestroy() {
- super.onDestroy();
- if (mServiceConn != null) {
- getActivity().unbindService(mServiceConn);
- }
-
- }
-
- private void initGMSDonateOptions() {
- try {
- int billingSupported = mService.isBillingSupported(3, getActivity().getPackageName(), INAPPITEM_TYPE_INAPP);
- if (billingSupported != BILLING_RESPONSE_RESULT_OK) {
- Log.i("OpenVPN", "Play store billing not supported");
- return;
- }
-
- ArrayList skuList = new ArrayList();
- Collections.addAll(skuList, donationSkus);
- Bundle querySkus = new Bundle();
- querySkus.putStringArrayList("ITEM_ID_LIST", skuList);
-
- Bundle ownedItems = mService.getPurchases(3, getActivity().getPackageName(), INAPPITEM_TYPE_INAPP, null);
-
-
- if (ownedItems.getInt(RESPONSE_CODE) != BILLING_RESPONSE_RESULT_OK)
- return;
-
- final ArrayList<String> ownedSkus = ownedItems.getStringArrayList("INAPP_PURCHASE_ITEM_LIST");
-
- Bundle skuDetails = mService.getSkuDetails(3, getActivity().getPackageName(), INAPPITEM_TYPE_INAPP, querySkus);
-
-
- if (skuDetails.getInt(RESPONSE_CODE) != BILLING_RESPONSE_RESULT_OK)
- return;
-
- final ArrayList<String> responseList = skuDetails.getStringArrayList("DETAILS_LIST");
-
- if (getActivity() != null) {
- getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
- createPlayBuyOptions(ownedSkus, responseList);
-
- }
- });
- }
-
- } catch (RemoteException e) {
- VpnStatus.logException(e);
- }
- }
-
- private static class SkuResponse {
- String title;
- String price;
-
- SkuResponse(String p, String t)
- {
- title=t;
- price=p;
- }
- }
-
-
-
- private void createPlayBuyOptions(ArrayList<String> ownedSkus, ArrayList<String> responseList) {
- try {
- Vector<Pair<String,String>> gdonation = new Vector<Pair<String, String>>();
-
- gdonation.add(new Pair<String, String>(getString(R.string.donatePlayStore),null));
- HashMap<String, SkuResponse> responseMap = new HashMap<String, SkuResponse>();
- for (String thisResponse : responseList) {
- JSONObject object = new JSONObject(thisResponse);
- responseMap.put(
- object.getString("productId"),
- new SkuResponse(
- object.getString("price"),
- object.getString("title")));
-
- }
- for (String sku: donationSkus)
- if (responseMap.containsKey(sku))
- gdonation.add(getSkuTitle(sku,
- responseMap.get(sku).title, responseMap.get(sku).price, ownedSkus));
-
- String gmsTextString="";
- for(int i=0;i<gdonation.size();i++) {
- if(i==1)
- gmsTextString+= " ";
- else if(i>1)
- gmsTextString+= ", ";
- gmsTextString+=gdonation.elementAt(i).first;
- }
- SpannableString gmsText = new SpannableString(gmsTextString);
-
-
- int lStart = 0;
- int lEnd=0;
- for(Pair<String, String> item:gdonation){
- lEnd = lStart + item.first.length();
- if (item.second!=null) {
- final String mSku = item.second;
- ClickableSpan cspan = new ClickableSpan()
- {
- @Override
- public void onClick(View widget) {
- triggerBuy(mSku);
- }
- };
- gmsText.setSpan(cspan,lStart,lEnd,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
- }
- lStart = lEnd+2; // Account for ", " between items
- }
-
- if(gmsTextView !=null) {
- gmsTextView.setText(gmsText);
- gmsTextView.setMovementMethod(LinkMovementMethod.getInstance());
- gmsTextView.setVisibility(View.VISIBLE);
- }
-
- } catch (JSONException e) {
- VpnStatus.logException("Parsing Play Store IAP",e);
- }
-
- }
-
- private Pair<String,String> getSkuTitle(final String sku, String title, String price, ArrayList<String> ownedSkus) {
- String text;
- if (ownedSkus.contains(sku))
- return new Pair<String,String>(getString(R.string.thanks_for_donation, price),null);
-
- if (price.contains("€")|| price.contains("\u20ac")) {
- text= title;
- } else {
- text = String.format(Locale.getDefault(), "%s (%s)", title, price);
- }
- //return text;
- return new Pair<String,String>(price, sku);
-
- }
-
- private void triggerBuy(String sku) {
- try {
- Bundle buyBundle
- = mService.getBuyIntent(3, getActivity().getPackageName(),
- sku, INAPPITEM_TYPE_INAPP, "Thanks for the donation! :)");
-
-
- if (buyBundle.getInt(RESPONSE_CODE) == BILLING_RESPONSE_RESULT_OK) {
- PendingIntent buyIntent = buyBundle.getParcelable(RESPONSE_BUY_INTENT);
- getActivity().startIntentSenderForResult(buyIntent.getIntentSender(), DONATION_CODE, new Intent(),
- 0, 0, 0);
- }
-
- } catch (RemoteException e) {
- VpnStatus.logException(e);
- } catch (IntentSender.SendIntentException e) {
- VpnStatus.logException(e);
- }
- }
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- View v = inflater.inflate(R.layout.about, container, false);
- TextView ver = (TextView) v.findViewById(R.id.version);
-
- String version;
- String name = "Openvpn";
- try {
- PackageInfo packageinfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
- version = packageinfo.versionName;
- name = getString(R.string.app);
- } catch (NameNotFoundException e) {
- version = "error fetching version";
- }
-
-
- ver.setText(getString(R.string.version_info, name, version));
-
- TextView paypal = (TextView) v.findViewById(R.id.donatestring);
-
- String donatetext = getActivity().getString(R.string.donatewithpaypal);
- Spanned htmltext = Html.fromHtml(donatetext);
- paypal.setText(htmltext);
- paypal.setMovementMethod(LinkMovementMethod.getInstance());
- gmsTextView = (TextView) v.findViewById(R.id.donategms);
- /* recreating view without onCreate/onDestroy cycle */
- if (mService!=null)
- initGooglePlayDonation();
-
- TextView translation = (TextView) v.findViewById(R.id.translation);
-
- // Don't print a text for myself
- if (getString(R.string.translationby).contains("Arne Schwabe"))
- translation.setText("");
- else
- translation.setText(R.string.translationby);
-
- WebView wv = (WebView)v.findViewById(R.id.webView);
- wv.loadUrl("file:///android_asset/full_licenses.html");
-
- return v;
- }
-
-
- @Override
- public void onActivityCreated(Bundle savedInstanceState) {
- super.onActivityCreated(savedInstanceState);
- if (mService!=null)
- initGooglePlayDonation();
- }
-
-
- @Override
- public void onClick(View v) {
-
- }
-}
diff --git a/app/src/main/java/de/blinkt/openvpn/fragments/FaqFragment.java b/app/src/main/java/de/blinkt/openvpn/fragments/FaqFragment.java
deleted file mode 100644
index ef57a395..00000000
--- a/app/src/main/java/de/blinkt/openvpn/fragments/FaqFragment.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package de.blinkt.openvpn.fragments;
-
-import android.app.Fragment;
-import android.os.Bundle;
-import android.text.Html;
-import android.text.method.LinkMovementMethod;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.TextView;
-import se.leap.bitmaskclient.R;
-
-public class FaqFragment extends Fragment {
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- View v= inflater.inflate(R.layout.faq, container, false);
-
- insertHtmlEntry(v,R.id.broken_images_faq,R.string.broken_images_faq);
- insertHtmlEntry(v,R.id.faq_howto,R.string.faq_howto);
- insertHtmlEntry(v, R.id.baterry_consumption, R.string.baterry_consumption);
- insertHtmlEntry(v, R.id.faq_tethering, R.string.faq_tethering);
- insertHtmlEntry(v, R.id.faq_vpndialog43, R.string.faq_vpndialog43);
- insertHtmlEntry(v, R.id.faq_system_dialog_xposed, R.string.faq_system_dialog_xposed);
- return v;
- }
-
- private void insertHtmlEntry (View v, int viewId, int stringId) {
- TextView faqitem = (TextView) v.findViewById(viewId);
- faqitem.setText(Html.fromHtml(getActivity().getString(stringId)));
- faqitem.setMovementMethod(LinkMovementMethod.getInstance());
-
- }
-
-}
diff --git a/app/src/main/java/de/blinkt/openvpn/fragments/FileSelectionFragment.java b/app/src/main/java/de/blinkt/openvpn/fragments/FileSelectionFragment.java
deleted file mode 100644
index 271af173..00000000
--- a/app/src/main/java/de/blinkt/openvpn/fragments/FileSelectionFragment.java
+++ /dev/null
@@ -1,256 +0,0 @@
-package de.blinkt.openvpn.fragments;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.TreeMap;
-
-import android.app.AlertDialog;
-import android.app.ListFragment;
-import android.os.Bundle;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.view.ViewGroup;
-import android.widget.Button;
-import android.widget.CheckBox;
-import android.widget.ListView;
-import android.widget.SimpleAdapter;
-import android.widget.TextView;
-import de.blinkt.openvpn.activities.FileSelect;
-import se.leap.bitmaskclient.R;
-
-public class FileSelectionFragment extends ListFragment {
-
- private static final String ITEM_KEY = "key";
- private static final String ITEM_IMAGE = "image";
- private static final String ROOT = "/";
-
-
- private List<String> path = null;
- private TextView myPath;
- private ArrayList<HashMap<String, Object>> mList;
-
- private Button selectButton;
-
-
- private String parentPath;
- private String currentPath = ROOT;
-
-
- private String[] formatFilter = null;
-
- private File selectedFile;
- private HashMap<String, Integer> lastPositions = new HashMap<String, Integer>();
- private String mStartPath;
- private CheckBox mInlineImport;
- private Button mClearButton;
- private boolean mHideImport=false;
-
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- View v = inflater.inflate(R.layout.file_dialog_main, container,false);
-
- myPath = (TextView) v.findViewById(R.id.path);
-
- mInlineImport = (CheckBox) v.findViewById(R.id.doinline);
-
- if(mHideImport) {
- mInlineImport.setVisibility(View.GONE);
- mInlineImport.setChecked(false);
- }
-
-
-
- selectButton = (Button) v.findViewById(R.id.fdButtonSelect);
- selectButton.setEnabled(false);
- selectButton.setOnClickListener(new OnClickListener() {
-
- @Override
- public void onClick(View v) {
- if (selectedFile != null) {
- if(mInlineImport.isChecked())
-
- ((FileSelect) getActivity()).importFile(selectedFile.getPath());
- else
- ((FileSelect) getActivity()).setFile(selectedFile.getPath());
- }
- }
- });
-
- mClearButton = (Button) v.findViewById(R.id.fdClear);
- mClearButton.setOnClickListener(new OnClickListener() {
-
- @Override
- public void onClick(View v) {
- ((FileSelect) getActivity()).clearData();
- }
- });
- if(!((FileSelect) getActivity()).showClear()) {
- mClearButton.setVisibility(View.GONE);
- mClearButton.setEnabled(false);
- }
-
- return v;
- }
-
- @Override
- public void onActivityCreated(Bundle savedInstanceState) {
- super.onActivityCreated(savedInstanceState);
-
- mStartPath = ((FileSelect) getActivity()).getSelectPath();
- getDir(mStartPath);
- }
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- }
-
- private void getDir(String dirPath) {
-
- boolean useAutoSelection = dirPath.length() < currentPath.length();
-
- Integer position = lastPositions.get(parentPath);
-
- getDirImpl(dirPath);
-
- if (position != null && useAutoSelection) {
- getListView().setSelection(position);
- }
-
- }
-
- /**
- * Monta a estrutura de arquivos e diretorios filhos do diretorio fornecido.
- *
- * @param dirPath
- * Diretorio pai.
- */
- private void getDirImpl(final String dirPath) {
-
- currentPath = dirPath;
-
- final List<String> item = new ArrayList<String>();
- path = new ArrayList<String>();
- mList = new ArrayList<HashMap<String, Object>>();
-
- File f = new File(currentPath);
- File[] files = f.listFiles();
- if (files == null) {
- currentPath = ROOT;
- f = new File(currentPath);
- files = f.listFiles();
- }
-
- myPath.setText(getText(R.string.location) + ": " + currentPath);
-
- if (!currentPath.equals(ROOT)) {
-
- item.add(ROOT);
- addItem(ROOT, R.drawable.ic_root_folder_am);
- path.add(ROOT);
-
- item.add("../");
- addItem("../", R.drawable.ic_root_folder_am);
- path.add(f.getParent());
- parentPath = f.getParent();
-
- }
-
- TreeMap<String, String> dirsMap = new TreeMap<String, String>();
- TreeMap<String, String> dirsPathMap = new TreeMap<String, String>();
- TreeMap<String, String> filesMap = new TreeMap<String, String>();
- TreeMap<String, String> filesPathMap = new TreeMap<String, String>();
- for (File file : files) {
- if (file.isDirectory()) {
- String dirName = file.getName();
- dirsMap.put(dirName, dirName);
- dirsPathMap.put(dirName, file.getPath());
- } else {
- final String fileName = file.getName();
- final String fileNameLwr = fileName.toLowerCase(Locale.getDefault());
- // se ha um filtro de formatos, utiliza-o
- if (formatFilter != null) {
- boolean contains = false;
- for (String aFormatFilter : formatFilter) {
- final String formatLwr = aFormatFilter.toLowerCase(Locale.getDefault());
- if (fileNameLwr.endsWith(formatLwr)) {
- contains = true;
- break;
- }
- }
- if (contains) {
- filesMap.put(fileName, fileName);
- filesPathMap.put(fileName, file.getPath());
- }
- // senao, adiciona todos os arquivos
- } else {
- filesMap.put(fileName, fileName);
- filesPathMap.put(fileName, file.getPath());
- }
- }
- }
- item.addAll(dirsMap.tailMap("").values());
- item.addAll(filesMap.tailMap("").values());
- path.addAll(dirsPathMap.tailMap("").values());
- path.addAll(filesPathMap.tailMap("").values());
-
- SimpleAdapter fileList = new SimpleAdapter(getActivity(), mList, R.layout.file_dialog_row, new String[] {
- ITEM_KEY, ITEM_IMAGE }, new int[] { R.id.fdrowtext, R.id.fdrowimage });
-
- for (String dir : dirsMap.tailMap("").values()) {
- addItem(dir, R.drawable.ic_root_folder_am);
- }
-
- for (String file : filesMap.tailMap("").values()) {
- addItem(file, R.drawable.ic_doc_generic_am);
- }
-
- fileList.notifyDataSetChanged();
-
- setListAdapter(fileList);
-
- }
-
- private void addItem(String fileName, int imageId) {
- HashMap<String, Object> item = new HashMap<String, Object>();
- item.put(ITEM_KEY, fileName);
- item.put(ITEM_IMAGE, imageId);
- mList.add(item);
- }
-
-
- @Override
- public void onListItemClick(ListView l, View v, int position, long id) {
-
- File file = new File(path.get(position));
-
- if (file.isDirectory()) {
- selectButton.setEnabled(false);
-
- if (file.canRead()) {
- lastPositions.put(currentPath, position);
- getDir(path.get(position));
- } else {
- new AlertDialog.Builder(getActivity()).setIcon(R.drawable.icon)
- .setTitle("[" + file.getName() + "] " + getText(R.string.cant_read_folder))
- .setPositiveButton("OK", null).show();
- }
- } else {
- selectedFile = file;
- v.setSelected(true);
- selectButton.setEnabled(true);
- }
- }
-
- public void setNoInLine() {
- mHideImport=true;
-
- }
-
-}
diff --git a/app/src/main/java/de/blinkt/openvpn/fragments/InlineFileTab.java b/app/src/main/java/de/blinkt/openvpn/fragments/InlineFileTab.java
deleted file mode 100644
index f0aa4fe2..00000000
--- a/app/src/main/java/de/blinkt/openvpn/fragments/InlineFileTab.java
+++ /dev/null
@@ -1,66 +0,0 @@
-package de.blinkt.openvpn.fragments;
-
-import android.app.Fragment;
-import android.os.Bundle;
-import android.view.LayoutInflater;
-import android.view.Menu;
-import android.view.MenuInflater;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.EditText;
-import de.blinkt.openvpn.activities.FileSelect;
-import se.leap.bitmaskclient.R;
-
-public class InlineFileTab extends Fragment
-{
-
- private static final int MENU_SAVE = 0;
- private EditText mInlineData;
-
- @Override
- public void onActivityCreated(Bundle savedInstanceState) {
- super.onActivityCreated(savedInstanceState);
- mInlineData.setText(((FileSelect)getActivity()).getInlineData());
- }
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState)
- {
-
- View v = inflater.inflate(R.layout.file_dialog_inline, container, false);
- mInlineData =(EditText) v.findViewById(R.id.inlineFileData);
- return v;
- }
-
- public void setData(String data) {
- if(mInlineData!=null)
- mInlineData.setText(data);
-
- }
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setHasOptionsMenu(true);
- }
-
- @Override
- public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
- menu.add(0, MENU_SAVE, 0, "Use inline data")
- .setIcon(android.R.drawable.ic_menu_save)
- .setAlphabeticShortcut('u')
- .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM
- | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- if(item.getItemId()==MENU_SAVE){
- ((FileSelect)getActivity()).saveInlineData(null, mInlineData.getText().toString());
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
-
-} \ No newline at end of file
diff --git a/app/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java b/app/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java
index 386e3133..fe7a8bd3 100644
--- a/app/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java
+++ b/app/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java
@@ -1,5 +1,7 @@
package de.blinkt.openvpn.fragments;
+import se.leap.bitmaskclient.R;
+
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
diff --git a/app/src/main/java/de/blinkt/openvpn/fragments/OpenVpnPreferencesFragment.java b/app/src/main/java/de/blinkt/openvpn/fragments/OpenVpnPreferencesFragment.java
deleted file mode 100644
index 4a6f19b5..00000000
--- a/app/src/main/java/de/blinkt/openvpn/fragments/OpenVpnPreferencesFragment.java
+++ /dev/null
@@ -1,48 +0,0 @@
-package de.blinkt.openvpn.fragments;
-
-import android.os.Bundle;
-import android.preference.PreferenceFragment;
-import se.leap.bitmaskclient.R;
-import de.blinkt.openvpn.VpnProfile;
-import de.blinkt.openvpn.core.ProfileManager;
-
-public abstract class OpenVpnPreferencesFragment extends PreferenceFragment {
-
- protected VpnProfile mProfile;
-
- protected abstract void loadSettings();
- protected abstract void saveSettings();
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- String profileUUID = getArguments().getString(getActivity().getPackageName() + ".profileUUID");
- mProfile = ProfileManager.get(getActivity(),profileUUID);
- getActivity().setTitle(getString(R.string.edit_profile_title, mProfile.getName()));
-
- }
-
- @Override
- public void onPause() {
- super.onPause();
- saveSettings();
- }
-
- @Override
- public void onActivityCreated(Bundle savedInstanceState) {
- super.onActivityCreated(savedInstanceState);
- if(savedInstanceState!=null) {
- String profileUUID=savedInstanceState.getString(VpnProfile.EXTRA_PROFILEUUID);
- mProfile = ProfileManager.get(getActivity(),profileUUID);
- loadSettings();
- }
- }
-
- @Override
- public void onSaveInstanceState (Bundle outState) {
- super.onSaveInstanceState(outState);
- saveSettings();
- outState.putString(VpnProfile.EXTRA_PROFILEUUID, mProfile.getUUIDString());
- }
-}
diff --git a/app/src/main/java/de/blinkt/openvpn/fragments/SendDumpFragment.java b/app/src/main/java/de/blinkt/openvpn/fragments/SendDumpFragment.java
deleted file mode 100644
index fd01b89f..00000000
--- a/app/src/main/java/de/blinkt/openvpn/fragments/SendDumpFragment.java
+++ /dev/null
@@ -1,94 +0,0 @@
-package de.blinkt.openvpn.fragments;
-
-import java.io.File;
-import java.util.ArrayList;
-
-import android.app.Fragment;
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager.NameNotFoundException;
-import android.net.Uri;
-import android.os.Bundle;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.view.ViewGroup;
-import se.leap.bitmaskclient.R;
-import de.blinkt.openvpn.core.VpnStatus;
-
-public class SendDumpFragment extends Fragment {
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
-
- View v = inflater.inflate(R.layout.fragment_senddump, container, false);
- v.findViewById(R.id.senddump).setOnClickListener(new OnClickListener() {
-
- @Override
- public void onClick(View v) {
- emailMiniDumps();
- }
- });
- return v;
- }
-
- public void emailMiniDumps()
- {
- //need to "send multiple" to get more than one attachment
- final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
- emailIntent.setType("*/*");
- emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
- new String[]{"Arne Schwabe <arne@rfc2549.org>"});
-
- String version;
- String name="ics-openvpn";
- try {
- PackageInfo packageinfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
- version = packageinfo.versionName;
- name = packageinfo.applicationInfo.name;
- } catch (NameNotFoundException e) {
- version = "error fetching version";
- }
-
-
- emailIntent.putExtra(Intent.EXTRA_SUBJECT, String.format("%s %s Minidump",name,version));
-
- emailIntent.putExtra(Intent.EXTRA_TEXT, "Please describe the issue you have experienced");
-
- ArrayList<Uri> uris = new ArrayList<Uri>();
-
- File ldump = getLastestDump(getActivity());
- if(ldump==null) {
- VpnStatus.logError("No Minidump found!");
- }
-
- uris.add(Uri.parse("content://de.blinkt.openvpn.FileProvider/" + ldump.getName()));
- uris.add(Uri.parse("content://de.blinkt.openvpn.FileProvider/" + ldump.getName() + ".log"));
-
- emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
- emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
- startActivity(emailIntent);
- }
-
- static public File getLastestDump(Context c) {
- long newestDumpTime=0;
- File newestDumpFile=null;
-
- for(File f:c.getCacheDir().listFiles()) {
- if(!f.getName().endsWith(".dmp"))
- continue;
-
- if (newestDumpTime < f.lastModified()) {
- newestDumpTime = f.lastModified();
- newestDumpFile=f;
- }
- }
- // Ignore old dumps
- //if(System.currentTimeMillis() - 48 * 60 * 1000 > newestDumpTime )
- //return null;
-
- return newestDumpFile;
- }
-}
diff --git a/app/src/main/java/de/blinkt/openvpn/fragments/Settings_Authentication.java b/app/src/main/java/de/blinkt/openvpn/fragments/Settings_Authentication.java
deleted file mode 100644
index 9bd3bf54..00000000
--- a/app/src/main/java/de/blinkt/openvpn/fragments/Settings_Authentication.java
+++ /dev/null
@@ -1,214 +0,0 @@
-package de.blinkt.openvpn.fragments;
-
-import android.app.Activity;
-import android.content.Intent;
-import android.os.Build;
-import android.os.Bundle;
-import android.preference.CheckBoxPreference;
-import android.preference.EditTextPreference;
-import android.preference.ListPreference;
-import android.preference.Preference;
-import android.preference.Preference.OnPreferenceChangeListener;
-import android.preference.Preference.OnPreferenceClickListener;
-import android.preference.SwitchPreference;
-import android.util.Pair;
-import de.blinkt.openvpn.activities.FileSelect;
-import se.leap.bitmaskclient.R;
-import de.blinkt.openvpn.core.VpnStatus;
-import de.blinkt.openvpn.views.RemoteCNPreference;
-import de.blinkt.openvpn.VpnProfile;
-
-import java.io.IOException;
-
-
-public class Settings_Authentication extends OpenVpnPreferencesFragment implements OnPreferenceChangeListener, OnPreferenceClickListener {
- private static final int SELECT_TLS_FILE = 23223232;
- private static final int SELECT_TLS_FILE_KITKAT = SELECT_TLS_FILE +1;
- private CheckBoxPreference mExpectTLSCert;
- private CheckBoxPreference mCheckRemoteCN;
- private RemoteCNPreference mRemoteCN;
- private ListPreference mTLSAuthDirection;
- private Preference mTLSAuthFile;
- private SwitchPreference mUseTLSAuth;
- private EditTextPreference mCipher;
- private String mTlsAuthFileData;
- private EditTextPreference mAuth;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- // Load the preferences from an XML resource
- addPreferencesFromResource(R.xml.vpn_authentification);
-
- mExpectTLSCert = (CheckBoxPreference) findPreference("remoteServerTLS");
- mCheckRemoteCN = (CheckBoxPreference) findPreference("checkRemoteCN");
- mRemoteCN = (RemoteCNPreference) findPreference("remotecn");
- mRemoteCN.setOnPreferenceChangeListener(this);
-
- mUseTLSAuth = (SwitchPreference) findPreference("useTLSAuth" );
- mTLSAuthFile = findPreference("tlsAuthFile");
- mTLSAuthDirection = (ListPreference) findPreference("tls_direction");
-
-
- mTLSAuthFile.setOnPreferenceClickListener(this);
-
- mCipher =(EditTextPreference) findPreference("cipher");
- mCipher.setOnPreferenceChangeListener(this);
-
- mAuth =(EditTextPreference) findPreference("auth");
- mAuth.setOnPreferenceChangeListener(this);
-
- loadSettings();
-
- }
-
- @Override
- protected void loadSettings() {
-
- mExpectTLSCert.setChecked(mProfile.mExpectTLSCert);
- mCheckRemoteCN.setChecked(mProfile.mCheckRemoteCN);
- mRemoteCN.setDN(mProfile.mRemoteCN);
- mRemoteCN.setAuthType(mProfile.mX509AuthType);
- onPreferenceChange(mRemoteCN,
- new Pair<Integer, String>(mProfile.mX509AuthType, mProfile.mRemoteCN));
-
- mUseTLSAuth.setChecked(mProfile.mUseTLSAuth);
- mTlsAuthFileData= mProfile.mTLSAuthFilename;
- setTlsAuthSummary(mTlsAuthFileData);
- mTLSAuthDirection.setValue(mProfile.mTLSAuthDirection);
- mCipher.setText(mProfile.mCipher);
- onPreferenceChange(mCipher, mProfile.mCipher);
- mAuth.setText(mProfile.mAuth);
- onPreferenceChange(mAuth, mProfile.mAuth);
-
- if (mProfile.mAuthenticationType == VpnProfile.TYPE_STATICKEYS) {
- mExpectTLSCert.setEnabled(false);
- mCheckRemoteCN.setEnabled(false);
- mUseTLSAuth.setChecked(true);
- } else {
- mExpectTLSCert.setEnabled(true);
- mCheckRemoteCN.setEnabled(true);
-
- }
- }
-
- @Override
- protected void saveSettings() {
- mProfile.mExpectTLSCert=mExpectTLSCert.isChecked();
- mProfile.mCheckRemoteCN=mCheckRemoteCN.isChecked();
- mProfile.mRemoteCN=mRemoteCN.getCNText();
- mProfile.mX509AuthType=mRemoteCN.getAuthtype();
-
- mProfile.mUseTLSAuth = mUseTLSAuth.isChecked();
- mProfile.mTLSAuthFilename = mTlsAuthFileData;
-
- if(mTLSAuthDirection.getValue()==null)
- mProfile.mTLSAuthDirection=null;
- else
- mProfile.mTLSAuthDirection = mTLSAuthDirection.getValue();
-
- if(mCipher.getText()==null)
- mProfile.mCipher=null;
- else
- mProfile.mCipher = mCipher.getText();
-
- if(mAuth.getText()==null)
- mProfile.mAuth = null;
- else
- mProfile.mAuth = mAuth.getText();
-
- }
-
-
-
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- if(preference==mRemoteCN) {
- @SuppressWarnings("unchecked")
- int authtype = ((Pair<Integer, String>) newValue).first;
- @SuppressWarnings("unchecked")
- String dn = ((Pair<Integer, String>) newValue).second;
-
- if ("".equals(dn))
- preference.setSummary(getX509String(VpnProfile.X509_VERIFY_TLSREMOTE_RDN, mProfile.mServerName));
- else
- preference.setSummary(getX509String(authtype,dn));
-
- } else if (preference == mCipher || preference == mAuth) {
- preference.setSummary((CharSequence) newValue);
- }
- return true;
- }
- private CharSequence getX509String(int authtype, String dn) {
- String ret ="";
- switch (authtype) {
- case VpnProfile.X509_VERIFY_TLSREMOTE:
- case VpnProfile.X509_VERIFY_TLSREMOTE_COMPAT_NOREMAPPING:
- ret+="tls-remote ";
- break;
-
- case VpnProfile.X509_VERIFY_TLSREMOTE_DN:
- ret="dn: ";
- break;
-
- case VpnProfile.X509_VERIFY_TLSREMOTE_RDN:
- ret="rdn: ";
- break;
-
- case VpnProfile.X509_VERIFY_TLSREMOTE_RDN_PREFIX:
- ret="rdn prefix: ";
- break;
- }
- return ret + dn;
- }
-
- void startFileDialog() {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- Intent startFC = Utils.getFilePickerIntent (getActivity(), Utils.FileType.TLS_AUTH_FILE);
- startActivityForResult(startFC, SELECT_TLS_FILE_KITKAT);
- } else {
- Intent startFC = new Intent(getActivity(), FileSelect.class);
- startFC.putExtra(FileSelect.START_DATA, mTlsAuthFileData);
- startFC.putExtra(FileSelect.WINDOW_TITLE, R.string.tls_auth_file);
- startActivityForResult(startFC, SELECT_TLS_FILE);
- }
- }
-
- @Override
- public boolean onPreferenceClick(Preference preference) {
- startFileDialog();
- return true;
-
- }
-
- @Override
- public void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- if(requestCode==SELECT_TLS_FILE && resultCode == Activity.RESULT_OK){
- String result = data.getStringExtra(FileSelect.RESULT_DATA);
- mTlsAuthFileData=result;
- setTlsAuthSummary(result);
- } else if (requestCode == SELECT_TLS_FILE_KITKAT && resultCode == Activity.RESULT_OK) {
- try {
- mTlsAuthFileData= Utils.getFilePickerResult(Utils.FileType.TLS_AUTH_FILE,data,getActivity());
- setTlsAuthSummary(mTlsAuthFileData);
- } catch (IOException e) {
- VpnStatus.logException(e);
- } catch (SecurityException se) {
- VpnStatus.logException(se);
- }
- }
- }
-
- private void setTlsAuthSummary(String result) {
- if(result==null)
- result = getString(R.string.no_certificate);
- if(result.startsWith(VpnProfile.INLINE_TAG))
- mTLSAuthFile.setSummary(R.string.inline_file_data);
- else if (result.startsWith(VpnProfile.DISPLAYNAME_TAG))
- mExpectTLSCert.setSummary(getString(R.string.imported_from_file, VpnProfile.getDisplayName(result)));
- else
- mTLSAuthFile.setSummary(result);
- }
-} \ No newline at end of file
diff --git a/app/src/main/java/de/blinkt/openvpn/fragments/Settings_Basic.java b/app/src/main/java/de/blinkt/openvpn/fragments/Settings_Basic.java
deleted file mode 100644
index 203d6c5c..00000000
--- a/app/src/main/java/de/blinkt/openvpn/fragments/Settings_Basic.java
+++ /dev/null
@@ -1,360 +0,0 @@
-package de.blinkt.openvpn.fragments;
-
-import android.annotation.TargetApi;
-import android.app.Activity;
-import android.app.AlertDialog;
-import android.app.AlertDialog.Builder;
-import android.app.Fragment;
-import android.content.ActivityNotFoundException;
-import android.content.Intent;
-import android.os.Build;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.Handler.Callback;
-import android.os.Message;
-import android.security.KeyChain;
-import android.security.KeyChainAliasCallback;
-import android.security.KeyChainException;
-import android.util.SparseArray;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.AdapterView;
-import android.widget.AdapterView.OnItemSelectedListener;
-import android.widget.CheckBox;
-import android.widget.EditText;
-import android.widget.Spinner;
-import android.widget.TextView;
-import android.widget.ToggleButton;
-import de.blinkt.openvpn.views.FileSelectLayout;
-import se.leap.bitmaskclient.R;
-import de.blinkt.openvpn.VpnProfile;
-import se.leap.bitmaskclient.R.id;
-import de.blinkt.openvpn.core.ProfileManager;
-import de.blinkt.openvpn.core.X509Utils;
-
-import java.security.cert.X509Certificate;
-
-public class Settings_Basic extends Fragment implements View.OnClickListener, OnItemSelectedListener, Callback, FileSelectLayout.FileSelectCallback {
- private static final int CHOOSE_FILE_OFFSET = 1000;
- private static final int UPDATE_ALIAS = 20;
-
- private TextView mServerAddress;
- private TextView mServerPort;
- private FileSelectLayout mClientCert;
- private FileSelectLayout mCaCert;
- private FileSelectLayout mClientKey;
- private TextView mAliasName;
- private TextView mAliasCertificate;
- private CheckBox mUseLzo;
- private ToggleButton mTcpUdp;
- private Spinner mType;
- private FileSelectLayout mpkcs12;
- private TextView mPKCS12Password;
- private Handler mHandler;
- private EditText mUserName;
- private EditText mPassword;
- private View mView;
- private VpnProfile mProfile;
- private EditText mProfileName;
- private EditText mKeyPassword;
-
- private SparseArray<FileSelectLayout> fileselects = new SparseArray<FileSelectLayout>();
-
-
-
- private void addFileSelectLayout (FileSelectLayout fsl, Utils.FileType type) {
- int i = fileselects.size() + CHOOSE_FILE_OFFSET;
- fileselects.put(i, fsl);
- fsl.setCaller(this, i, type);
- }
-
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- String profileUuid = getArguments().getString(getActivity().getPackageName() + ".profileUUID");
- mProfile=ProfileManager.get(getActivity(),profileUuid);
- getActivity().setTitle(getString(R.string.edit_profile_title, mProfile.getName()));
- }
-
-
- private void setKeystoreCertficate()
- {
- new Thread() {
- public void run() {
- String certstr="";
- try {
- X509Certificate cert = KeyChain.getCertificateChain(getActivity(), mProfile.mAlias)[0];
-
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
- {
- if (isInHardwareKeystore())
- certstr+=getString(R.string.hwkeychain);
- }
- }
-
- certstr+=X509Utils.getCertificateFriendlyName(cert);
- } catch (Exception e) {
- certstr="Could not get certificate from Keystore: " +e.getLocalizedMessage();
- }
-
- final String certStringCopy=certstr;
- getActivity().runOnUiThread(new Runnable() {
-
- @Override
- public void run() {
- mAliasCertificate.setText(certStringCopy);
- }
- });
-
- }
- }.start();
- }
-
- @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
- private boolean isInHardwareKeystore() throws KeyChainException, InterruptedException {
- String algorithm = KeyChain.getPrivateKey(getActivity(), mProfile.mAlias).getAlgorithm();
- return KeyChain.isBoundKeyAlgorithm(algorithm);
- }
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
-
-
- mView = inflater.inflate(R.layout.basic_settings,container,false);
-
- mProfileName = (EditText) mView.findViewById(R.id.profilename);
- mServerAddress = (TextView) mView.findViewById(R.id.address);
- mServerPort = (TextView) mView.findViewById(R.id.port);
- mClientCert = (FileSelectLayout) mView.findViewById(R.id.certselect);
- mClientKey = (FileSelectLayout) mView.findViewById(R.id.keyselect);
- mCaCert = (FileSelectLayout) mView.findViewById(R.id.caselect);
- mpkcs12 = (FileSelectLayout) mView.findViewById(R.id.pkcs12select);
- mUseLzo = (CheckBox) mView.findViewById(R.id.lzo);
- mTcpUdp = (ToggleButton) mView.findViewById(id.tcpudp);
- mType = (Spinner) mView.findViewById(R.id.type);
- mPKCS12Password = (TextView) mView.findViewById(R.id.pkcs12password);
- mAliasName = (TextView) mView.findViewById(R.id.aliasname);
- mAliasCertificate = (TextView) mView.findViewById(id.alias_certificate);
-
- mUserName = (EditText) mView.findViewById(R.id.auth_username);
- mPassword = (EditText) mView.findViewById(R.id.auth_password);
- mKeyPassword = (EditText) mView.findViewById(R.id.key_password);
-
- addFileSelectLayout(mCaCert, Utils.FileType.CA_CERTIFICATE);
- addFileSelectLayout(mClientCert, Utils.FileType.CLIENT_CERTIFICATE);
- addFileSelectLayout(mClientKey, Utils.FileType.KEYFILE);
- addFileSelectLayout(mpkcs12, Utils.FileType.PKCS12);
- mCaCert.setShowClear();
-
- mType.setOnItemSelectedListener(this);
-
- mView.findViewById(R.id.select_keystore_button).setOnClickListener(this);
-
-
- if (mHandler == null) {
- mHandler = new Handler(this);
- }
-
- return mView;
- }
-
-
- @Override
- public void onStart() {
- super.onStart();
- String profileUuid =getArguments().getString(getActivity().getPackageName() + ".profileUUID");
- mProfile=ProfileManager.get(getActivity(),profileUuid);
- loadPreferences();
-
- }
-
- @Override
- public void onActivityResult(int request, int result, Intent data) {
- if (result == Activity.RESULT_OK && request >= CHOOSE_FILE_OFFSET) {
-
- FileSelectLayout fsl = fileselects.get(request);
- fsl.parseResponse(data, getActivity());
-
- savePreferences();
-
- // Private key files may result in showing/hiding the private key password dialog
- if(fsl==mClientKey) {
- changeType(mType.getSelectedItemPosition());
- }
- }
-
- }
-
-
- @Override
- public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
- if (parent == mType) {
- changeType(position);
- }
- }
- @Override
- public void onPause() {
- super.onPause();
- savePreferences();
- }
-
-
-
- private void changeType(int type){
- // hide everything
- mView.findViewById(R.id.pkcs12).setVisibility(View.GONE);
- mView.findViewById(R.id.certs).setVisibility(View.GONE);
- mView.findViewById(R.id.statickeys).setVisibility(View.GONE);
- mView.findViewById(R.id.keystore).setVisibility(View.GONE);
- mView.findViewById(R.id.cacert).setVisibility(View.GONE);
- mView.findViewById(R.id.userpassword).setVisibility(View.GONE);
- mView.findViewById(R.id.key_password_layout).setVisibility(View.GONE);
-
- // Fall through are by design
- switch(type) {
- case VpnProfile.TYPE_USERPASS_CERTIFICATES:
- mView.findViewById(R.id.userpassword).setVisibility(View.VISIBLE);
- case VpnProfile.TYPE_CERTIFICATES:
- mView.findViewById(R.id.certs).setVisibility(View.VISIBLE);
- mView.findViewById(R.id.cacert).setVisibility(View.VISIBLE);
- if(mProfile.requireTLSKeyPassword())
- mView.findViewById(R.id.key_password_layout).setVisibility(View.VISIBLE);
- break;
-
- case VpnProfile.TYPE_USERPASS_PKCS12:
- mView.findViewById(R.id.userpassword).setVisibility(View.VISIBLE);
- case VpnProfile.TYPE_PKCS12:
- mView.findViewById(R.id.pkcs12).setVisibility(View.VISIBLE);
- break;
-
- case VpnProfile.TYPE_STATICKEYS:
- mView.findViewById(R.id.statickeys).setVisibility(View.VISIBLE);
- break;
-
- case VpnProfile.TYPE_USERPASS_KEYSTORE:
- mView.findViewById(R.id.userpassword).setVisibility(View.VISIBLE);
- case VpnProfile.TYPE_KEYSTORE:
- mView.findViewById(R.id.keystore).setVisibility(View.VISIBLE);
- mView.findViewById(R.id.cacert).setVisibility(View.VISIBLE);
- break;
-
- case VpnProfile.TYPE_USERPASS:
- mView.findViewById(R.id.userpassword).setVisibility(View.VISIBLE);
- mView.findViewById(R.id.cacert).setVisibility(View.VISIBLE);
- break;
- }
-
-
- }
-
- private void loadPreferences() {
- mProfileName.setText(mProfile.mName);
- mClientCert.setData(mProfile.mClientCertFilename, getActivity());
- mClientKey.setData(mProfile.mClientKeyFilename, getActivity());
- mCaCert.setData(mProfile.mCaFilename, getActivity());
-
- mUseLzo.setChecked(mProfile.mUseLzo);
- mServerPort.setText(mProfile.mServerPort);
- mServerAddress.setText(mProfile.mServerName);
- mTcpUdp.setChecked(mProfile.mUseUdp);
- mType.setSelection(mProfile.mAuthenticationType);
- mpkcs12.setData(mProfile.mPKCS12Filename, getActivity());
- mPKCS12Password.setText(mProfile.mPKCS12Password);
- mUserName.setText(mProfile.mUsername);
- mPassword.setText(mProfile.mPassword);
- mKeyPassword.setText(mProfile.mKeyPassword);
-
- setAlias();
-
- }
-
- void savePreferences() {
-
- mProfile.mName = mProfileName.getText().toString();
- mProfile.mCaFilename = mCaCert.getData();
- mProfile.mClientCertFilename = mClientCert.getData();
- mProfile.mClientKeyFilename = mClientKey.getData();
-
- mProfile.mUseLzo = mUseLzo.isChecked();
- mProfile.mServerPort =mServerPort.getText().toString();
- mProfile.mServerName = mServerAddress.getText().toString();
- mProfile.mUseUdp = mTcpUdp.isChecked();
-
- mProfile.mAuthenticationType = mType.getSelectedItemPosition();
- mProfile.mPKCS12Filename = mpkcs12.getData();
- mProfile.mPKCS12Password = mPKCS12Password.getText().toString();
-
- mProfile.mPassword = mPassword.getText().toString();
- mProfile.mUsername = mUserName.getText().toString();
- mProfile.mKeyPassword = mKeyPassword.getText().toString();
-
- }
-
-
- private void setAlias() {
- if(mProfile.mAlias == null) {
- mAliasName.setText(R.string.client_no_certificate);
- mAliasCertificate.setText("");
- } else {
- mAliasCertificate.setText("Loading certificate from Keystore...");
- mAliasName.setText(mProfile.mAlias);
- setKeystoreCertficate();
- }
- }
-
- public void showCertDialog () {
- try {
- KeyChain.choosePrivateKeyAlias(getActivity(),
- new KeyChainAliasCallback() {
-
- public void alias(String alias) {
- // Credential alias selected. Remember the alias selection for future use.
- mProfile.mAlias=alias;
- mHandler.sendEmptyMessage(UPDATE_ALIAS);
- }
-
-
- },
- new String[] {"RSA"}, // List of acceptable key types. null for any
- null, // issuer, null for any
- mProfile.mServerName, // host name of server requesting the cert, null if unavailable
- -1, // port of server requesting the cert, -1 if unavailable
- mProfile.mAlias); // alias to preselect, null if unavailable
- } catch (ActivityNotFoundException anf) {
- Builder ab = new AlertDialog.Builder(getActivity());
- ab.setTitle(R.string.broken_image_cert_title);
- ab.setMessage(R.string.broken_image_cert);
- ab.setPositiveButton(android.R.string.ok, null);
- ab.show();
- }
- }
-
- @Override
- public void onClick(View v) {
- if (v == mView.findViewById(R.id.select_keystore_button)) {
- showCertDialog();
- }
- }
-
- @Override
- public void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- savePreferences();
- if(mProfile!=null) {
- outState.putString(getActivity().getPackageName() + "profileUUID", mProfile.getUUID().toString());
- }
- }
-
- @Override
- public void onNothingSelected(AdapterView<?> parent) {
- }
-
-
- @Override
- public boolean handleMessage(Message msg) {
- setAlias();
- return true;
- }
-
-
-}
diff --git a/app/src/main/java/de/blinkt/openvpn/fragments/Settings_IP.java b/app/src/main/java/de/blinkt/openvpn/fragments/Settings_IP.java
deleted file mode 100644
index 81988012..00000000
--- a/app/src/main/java/de/blinkt/openvpn/fragments/Settings_IP.java
+++ /dev/null
@@ -1,130 +0,0 @@
-package de.blinkt.openvpn.fragments;
-import android.os.Bundle;
-import android.preference.CheckBoxPreference;
-import android.preference.EditTextPreference;
-import android.preference.Preference;
-import android.preference.Preference.OnPreferenceChangeListener;
-import android.preference.PreferenceManager;
-import android.preference.SwitchPreference;
-import se.leap.bitmaskclient.R;
-import de.blinkt.openvpn.VpnProfile;
-
-public class Settings_IP extends OpenVpnPreferencesFragment implements OnPreferenceChangeListener {
- private EditTextPreference mIPv4;
- private EditTextPreference mIPv6;
- private SwitchPreference mUsePull;
- private CheckBoxPreference mOverrideDNS;
- private EditTextPreference mSearchdomain;
- private EditTextPreference mDNS1;
- private EditTextPreference mDNS2;
- private CheckBoxPreference mNobind;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
-
- // Make sure default values are applied. In a real app, you would
- // want this in a shared function that is used to retrieve the
- // SharedPreferences wherever they are needed.
- PreferenceManager.setDefaultValues(getActivity(),
- R.xml.vpn_ipsettings, false);
-
- // Load the preferences from an XML resource
- addPreferencesFromResource(R.xml.vpn_ipsettings);
- mIPv4 = (EditTextPreference) findPreference("ipv4_address");
- mIPv6 = (EditTextPreference) findPreference("ipv6_address");
- mUsePull = (SwitchPreference) findPreference("usePull");
- mOverrideDNS = (CheckBoxPreference) findPreference("overrideDNS");
- mSearchdomain =(EditTextPreference) findPreference("searchdomain");
- mDNS1 = (EditTextPreference) findPreference("dns1");
- mDNS2 = (EditTextPreference) findPreference("dns2");
- mNobind = (CheckBoxPreference) findPreference("nobind");
-
- mIPv4.setOnPreferenceChangeListener(this);
- mIPv6.setOnPreferenceChangeListener(this);
- mDNS1.setOnPreferenceChangeListener(this);
- mDNS2.setOnPreferenceChangeListener(this);
- mUsePull.setOnPreferenceChangeListener(this);
- mOverrideDNS.setOnPreferenceChangeListener(this);
- mSearchdomain.setOnPreferenceChangeListener(this);
-
- loadSettings();
- }
-
- @Override
- protected void loadSettings() {
-
- mUsePull.setChecked(mProfile.mUsePull);
- mIPv4.setText(mProfile.mIPv4Address);
- mIPv6.setText(mProfile.mIPv6Address);
- mDNS1.setText(mProfile.mDNS1);
- mDNS2.setText(mProfile.mDNS2);
- mOverrideDNS.setChecked(mProfile.mOverrideDNS);
- mSearchdomain.setText(mProfile.mSearchDomain);
- mNobind.setChecked(mProfile.mNobind);
- if (mProfile.mAuthenticationType == VpnProfile.TYPE_STATICKEYS)
- mUsePull.setChecked(false);
-
- // Sets Summary
- onPreferenceChange(mIPv4, mIPv4.getText());
- onPreferenceChange(mIPv6, mIPv6.getText());
- onPreferenceChange(mDNS1, mDNS1.getText());
- onPreferenceChange(mDNS2, mDNS2.getText());
- onPreferenceChange(mSearchdomain, mSearchdomain.getText());
-
- setDNSState();
- }
-
-
- @Override
- protected void saveSettings() {
- mProfile.mUsePull = mUsePull.isChecked();
- mProfile.mIPv4Address = mIPv4.getText();
- mProfile.mIPv6Address = mIPv6.getText();
- mProfile.mDNS1 = mDNS1.getText();
- mProfile.mDNS2 = mDNS2.getText();
- mProfile.mOverrideDNS = mOverrideDNS.isChecked();
- mProfile.mSearchDomain = mSearchdomain.getText();
- mProfile.mNobind = mNobind.isChecked();
-
- }
-
- @Override
- public boolean onPreferenceChange(Preference preference,
- Object newValue) {
- if(preference==mIPv4 || preference == mIPv6
- || preference==mDNS1 || preference == mDNS2
- || preference == mSearchdomain
- )
-
- preference.setSummary((String)newValue);
-
- if(preference== mUsePull || preference == mOverrideDNS)
- if(preference==mOverrideDNS) {
- // Set so the function gets the right value
- mOverrideDNS.setChecked((Boolean) newValue);
- }
- setDNSState();
-
- saveSettings();
- return true;
- }
-
- private void setDNSState() {
- boolean enabled;
- mOverrideDNS.setEnabled(mUsePull.isChecked());
- if(!mUsePull.isChecked())
- enabled =true;
- else
- enabled = mOverrideDNS.isChecked();
-
- mDNS1.setEnabled(enabled);
- mDNS2.setEnabled(enabled);
- mSearchdomain.setEnabled(enabled);
-
-
- }
-
-
- } \ No newline at end of file
diff --git a/app/src/main/java/de/blinkt/openvpn/fragments/Settings_Obscure.java b/app/src/main/java/de/blinkt/openvpn/fragments/Settings_Obscure.java
deleted file mode 100644
index 4507d691..00000000
--- a/app/src/main/java/de/blinkt/openvpn/fragments/Settings_Obscure.java
+++ /dev/null
@@ -1,93 +0,0 @@
-package de.blinkt.openvpn.fragments;
-
-import android.os.Bundle;
-import android.preference.CheckBoxPreference;
-import android.preference.EditTextPreference;
-import android.preference.ListPreference;
-import android.preference.Preference;
-import android.preference.Preference.OnPreferenceChangeListener;
-import se.leap.bitmaskclient.R;
-
-public class Settings_Obscure extends OpenVpnPreferencesFragment implements OnPreferenceChangeListener {
- private CheckBoxPreference mUseRandomHostName;
- private CheckBoxPreference mUseFloat;
- private CheckBoxPreference mUseCustomConfig;
- private EditTextPreference mCustomConfig;
- private ListPreference mLogverbosity;
- private CheckBoxPreference mPersistent;
- private ListPreference mConnectretrymax;
- private EditTextPreference mConnectretry;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- // Load the preferences from an XML resource
- addPreferencesFromResource(R.xml.vpn_obscure);
-
- mUseRandomHostName = (CheckBoxPreference) findPreference("useRandomHostname");
- mUseFloat = (CheckBoxPreference) findPreference("useFloat");
- mUseCustomConfig = (CheckBoxPreference) findPreference("enableCustomOptions");
- mCustomConfig = (EditTextPreference) findPreference("customOptions");
- mPersistent = (CheckBoxPreference) findPreference("usePersistTun");
- mConnectretrymax = (ListPreference) findPreference("connectretrymax");
- mConnectretry = (EditTextPreference) findPreference("connectretry");
-
- mConnectretrymax.setOnPreferenceChangeListener(this);
- mConnectretrymax.setSummary("%s");
-
- mConnectretry.setOnPreferenceChangeListener(this);
-
-
- loadSettings();
-
- }
-
- protected void loadSettings() {
- mUseRandomHostName.setChecked(mProfile.mUseRandomHostname);
- mUseFloat.setChecked(mProfile.mUseFloat);
- mUseCustomConfig.setChecked(mProfile.mUseCustomConfig);
- mCustomConfig.setText(mProfile.mCustomConfigOptions);
- mPersistent.setChecked(mProfile.mPersistTun);
-
- mConnectretrymax.setValue(mProfile.mConnectRetryMax);
- onPreferenceChange(mConnectretrymax, mProfile.mConnectRetryMax);
-
- mConnectretry.setText(mProfile.mConnectRetry);
- onPreferenceChange(mConnectretry, mProfile.mConnectRetry);
- }
-
-
- protected void saveSettings() {
- mProfile.mUseRandomHostname = mUseRandomHostName.isChecked();
- mProfile.mUseFloat = mUseFloat.isChecked();
- mProfile.mUseCustomConfig = mUseCustomConfig.isChecked();
- mProfile.mCustomConfigOptions = mCustomConfig.getText();
- mProfile.mConnectRetryMax = mConnectretrymax.getValue();
- mProfile.mPersistTun = mPersistent.isChecked();
- mProfile.mConnectRetry = mConnectretry.getText();
- }
-
-
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- if (preference == mConnectretrymax) {
- if(newValue==null) {
- newValue="5";
- }
- mConnectretrymax.setDefaultValue(newValue);
-
- for(int i=0;i<mConnectretrymax.getEntryValues().length;i++){
- if(mConnectretrymax.getEntryValues().equals(newValue))
- mConnectretrymax.setSummary(mConnectretrymax.getEntries()[i]);
- }
-
- } else if (preference == mConnectretry) {
- if(newValue==null || newValue=="")
- newValue="5";
- mConnectretry.setSummary(String.format("%s s" , newValue));
- }
-
- return true;
- }
-
-} \ No newline at end of file
diff --git a/app/src/main/java/de/blinkt/openvpn/fragments/Settings_Routing.java b/app/src/main/java/de/blinkt/openvpn/fragments/Settings_Routing.java
deleted file mode 100644
index 8163a745..00000000
--- a/app/src/main/java/de/blinkt/openvpn/fragments/Settings_Routing.java
+++ /dev/null
@@ -1,88 +0,0 @@
-package de.blinkt.openvpn.fragments;
-import android.os.Bundle;
-import android.preference.CheckBoxPreference;
-import android.preference.EditTextPreference;
-import android.preference.Preference;
-import android.preference.Preference.OnPreferenceChangeListener;
-import se.leap.bitmaskclient.R;
-
-
-public class Settings_Routing extends OpenVpnPreferencesFragment implements OnPreferenceChangeListener {
- private EditTextPreference mCustomRoutes;
- private CheckBoxPreference mUseDefaultRoute;
- private EditTextPreference mCustomRoutesv6;
- private CheckBoxPreference mUseDefaultRoutev6;
- private CheckBoxPreference mRouteNoPull;
- private CheckBoxPreference mLocalVPNAccess;
- private EditTextPreference mExcludedRoutes;
- private EditTextPreference mExcludedRoutesv6;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- // Load the preferences from an XML resource
- addPreferencesFromResource(R.xml.vpn_routing);
- mCustomRoutes = (EditTextPreference) findPreference("customRoutes");
- mUseDefaultRoute = (CheckBoxPreference) findPreference("useDefaultRoute");
- mCustomRoutesv6 = (EditTextPreference) findPreference("customRoutesv6");
- mUseDefaultRoutev6 = (CheckBoxPreference) findPreference("useDefaultRoutev6");
- mExcludedRoutes = (EditTextPreference) findPreference("excludedRoutes");
- mExcludedRoutesv6 = (EditTextPreference) findPreference("excludedRoutesv6");
-
- mRouteNoPull = (CheckBoxPreference) findPreference("routenopull");
- mLocalVPNAccess = (CheckBoxPreference) findPreference("unblockLocal");
-
- mCustomRoutes.setOnPreferenceChangeListener(this);
- mCustomRoutesv6.setOnPreferenceChangeListener(this);
-
- loadSettings();
- }
-
- @Override
- protected void loadSettings() {
-
- mUseDefaultRoute.setChecked(mProfile.mUseDefaultRoute);
- mUseDefaultRoutev6.setChecked(mProfile.mUseDefaultRoutev6);
-
- mCustomRoutes.setText(mProfile.mCustomRoutes);
- mCustomRoutesv6.setText(mProfile.mCustomRoutesv6);
-
- mExcludedRoutes.setText(mProfile.mExcludedRoutes);
- mExcludedRoutes.setText(mProfile.mExcludedRoutesv6);
-
- mRouteNoPull.setChecked(mProfile.mRoutenopull);
- mLocalVPNAccess.setChecked(mProfile.mAllowLocalLAN);
-
- // Sets Summary
- onPreferenceChange(mCustomRoutes, mCustomRoutes.getText());
- onPreferenceChange(mCustomRoutesv6, mCustomRoutesv6.getText());
- mRouteNoPull.setEnabled(mProfile.mUsePull);
- }
-
-
- @Override
- protected void saveSettings() {
- mProfile.mUseDefaultRoute = mUseDefaultRoute.isChecked();
- mProfile.mUseDefaultRoutev6 = mUseDefaultRoutev6.isChecked();
- mProfile.mCustomRoutes = mCustomRoutes.getText();
- mProfile.mCustomRoutesv6 = mCustomRoutesv6.getText();
- mProfile.mRoutenopull = mRouteNoPull.isChecked();
- mProfile.mAllowLocalLAN =mLocalVPNAccess.isChecked();
- mProfile.mExcludedRoutes = mExcludedRoutes.getText();
- mProfile.mExcludedRoutesv6 = mExcludedRoutesv6.getText();
- }
-
- @Override
- public boolean onPreferenceChange(Preference preference,
- Object newValue) {
- if( preference == mCustomRoutes || preference == mCustomRoutesv6
- || preference == mExcludedRoutes || preference == mExcludedRoutesv6)
- preference.setSummary((String)newValue);
-
- saveSettings();
- return true;
- }
-
-
-} \ No newline at end of file
diff --git a/app/src/main/java/de/blinkt/openvpn/fragments/ShowConfigFragment.java b/app/src/main/java/de/blinkt/openvpn/fragments/ShowConfigFragment.java
deleted file mode 100644
index 0cf2bbb7..00000000
--- a/app/src/main/java/de/blinkt/openvpn/fragments/ShowConfigFragment.java
+++ /dev/null
@@ -1,89 +0,0 @@
-package de.blinkt.openvpn.fragments;
-
-import android.app.Fragment;
-import android.content.Intent;
-import android.os.Bundle;
-import android.view.LayoutInflater;
-import android.view.Menu;
-import android.view.MenuInflater;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.TextView;
-import se.leap.bitmaskclient.R;
-import de.blinkt.openvpn.VpnProfile;
-import de.blinkt.openvpn.core.ProfileManager;
-
-
-public class ShowConfigFragment extends Fragment {
- private String configtext;
- public android.view.View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
- {
- String profileUUID = getArguments().getString(getActivity().getPackageName() + ".profileUUID");
- final VpnProfile vp = ProfileManager.get(getActivity(),profileUUID);
- View v=inflater.inflate(R.layout.viewconfig, container,false);
- final TextView cv = (TextView) v.findViewById(R.id.configview);
-
- int check=vp.checkProfile(getActivity());
- if(check!=R.string.no_error_found) {
- cv.setText(check);
- configtext = getString(check);
- }
- else {
- // Run in own Thread since Keystore does not like to be queried from the main thread
-
- cv.setText("Generating config...");
- startGenConfig(vp, cv);
- }
- return v;
- }
-
- private void startGenConfig(final VpnProfile vp, final TextView cv) {
-
- new Thread() {
- public void run() {
- final String cfg=vp.getConfigFile(getActivity(),false);
- configtext= cfg;
- getActivity().runOnUiThread(new Runnable() {
-
- @Override
- public void run() {
- cv.setText(cfg);
- }
- });
-
-
- }
- }.start();
- }
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setHasOptionsMenu(true);
- }
-
- @Override
- public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
- inflater.inflate(R.menu.configmenu, menu);
- }
-
- private void shareConfig() {
- Intent shareIntent = new Intent(Intent.ACTION_SEND);
- shareIntent.putExtra(Intent.EXTRA_TEXT, configtext);
- shareIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.export_config_title));
- shareIntent.setType("text/plain");
- startActivity(Intent.createChooser(shareIntent, "Export Configfile"));
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- final int itemId = item.getItemId();
- if (itemId == R.id.sendConfig) {
- shareConfig();
- return true;
- } else {
- return super.onOptionsItemSelected(item);
- }
- }
-}
diff --git a/app/src/main/java/de/blinkt/openvpn/fragments/Utils.java b/app/src/main/java/de/blinkt/openvpn/fragments/Utils.java
deleted file mode 100644
index f7038877..00000000
--- a/app/src/main/java/de/blinkt/openvpn/fragments/Utils.java
+++ /dev/null
@@ -1,221 +0,0 @@
-package de.blinkt.openvpn.fragments;
-
-import android.annotation.TargetApi;
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.database.Cursor;
-import android.net.Uri;
-import android.os.Build;
-import android.provider.OpenableColumns;
-import android.util.Base64;
-import android.util.Log;
-import android.webkit.MimeTypeMap;
-import de.blinkt.openvpn.VpnProfile;
-import junit.framework.Assert;
-
-import java.io.*;
-import java.util.List;
-import java.util.TreeSet;
-import java.util.Vector;
-
-public class Utils {
-
-
- @TargetApi(Build.VERSION_CODES.KITKAT)
- public static Intent getFilePickerIntent(Context c, FileType fileType) {
- Intent i = new Intent(Intent.ACTION_GET_CONTENT);
- i.addCategory(Intent.CATEGORY_OPENABLE);
- TreeSet<String> supportedMimeTypes = new TreeSet<String>();
- Vector<String> extensions = new Vector<String>();
-
- switch (fileType) {
- case PKCS12:
- i.setType("application/x-pkcs12");
- supportedMimeTypes.add("application/x-pkcs12");
- extensions.add("p12");
- extensions.add("pfx");
- break;
- case CLIENT_CERTIFICATE:
- case CA_CERTIFICATE:
- i.setType("application/x-pem-file");
- supportedMimeTypes.add("application/x-x509-ca-cert");
- supportedMimeTypes.add("application/x-x509-user-cert");
- supportedMimeTypes.add("application/x-pem-file");
- supportedMimeTypes.add("text/plain");
-
- extensions.add("pem");
- extensions.add("crt");
- break;
- case KEYFILE:
- i.setType("application/x-pem-file");
- supportedMimeTypes.add("application/x-pem-file");
- supportedMimeTypes.add("application/pkcs8");
-
- // Google drive ....
- supportedMimeTypes.add("application/x-iwork-keynote-sffkey");
- extensions.add("key");
- break;
-
- case TLS_AUTH_FILE:
- i.setType("text/plain");
-
- // Backup ....
- supportedMimeTypes.add("application/pkcs8");
- // Google Drive is kind of crazy .....
- supportedMimeTypes.add("application/x-iwork-keynote-sffkey");
-
- extensions.add("txt");
- extensions.add("key");
- break;
-
- case OVPN_CONFIG:
- i.setType("application/x-openvpn-profile");
- supportedMimeTypes.add("application/x-openvpn-profile");
- supportedMimeTypes.add("application/openvpn-profile");
- supportedMimeTypes.add("application/ovpn");
- supportedMimeTypes.add("text/plain");
- extensions.add("ovpn");
- extensions.add("conf");
- break;
-
- case USERPW_FILE:
- i.setType("text/plain");
- supportedMimeTypes.add("text/plain");
- break;
- }
-
- MimeTypeMap mtm = MimeTypeMap.getSingleton();
-
- for (String ext : extensions) {
- String mimeType = mtm.getMimeTypeFromExtension(ext);
- if (mimeType != null)
- supportedMimeTypes.add(mimeType);
- }
-
- // Always add this as fallback
- supportedMimeTypes.add("application/octet-stream");
-
- i.putExtra(Intent.EXTRA_MIME_TYPES, supportedMimeTypes.toArray(new String[supportedMimeTypes.size()]));
-
-
- /* Samsung has decided to do something strange, on stock Android GET_CONTENT opens the document UI */
- /* fist try with documentsui */
- i.setPackage("com.android.documentsui");
-
- //noinspection ConstantConditions
- if (true || !isIntentAvailable(c,i)) {
- i.setAction(Intent.ACTION_OPEN_DOCUMENT);
- i.setPackage(null);
- }
-
- return i;
- }
-
-
- public static boolean isIntentAvailable(Context context, Intent i) {
- final PackageManager packageManager = context.getPackageManager();
- List<ResolveInfo> list =
- packageManager.queryIntentActivities(i,
- PackageManager.MATCH_DEFAULT_ONLY);
- return list.size() > 0;
- }
-
-
- public enum FileType {
- PKCS12(0),
- CLIENT_CERTIFICATE(1),
- CA_CERTIFICATE(2),
- OVPN_CONFIG(3),
- KEYFILE(4),
- TLS_AUTH_FILE(5),
- USERPW_FILE(6);
-
- private int value;
-
- FileType(int i) {
- value = i;
- }
-
- public static FileType getFileTypeByValue(int value) {
- switch (value) {
- case 0:
- return PKCS12;
- case 1:
- return CLIENT_CERTIFICATE;
- case 2:
- return CA_CERTIFICATE;
- case 3:
- return OVPN_CONFIG;
- case 4:
- return KEYFILE;
- case 5:
- return TLS_AUTH_FILE;
- case 6:
- return USERPW_FILE;
- default:
- return null;
- }
- }
-
- public int getValue() {
- return value;
- }
- }
-
- static private byte[] readBytesFromStream(InputStream input) throws IOException {
-
- ByteArrayOutputStream buffer = new ByteArrayOutputStream();
-
- int nRead;
- byte[] data = new byte[16384];
-
- while ((nRead = input.read(data, 0, data.length)) != -1) {
- buffer.write(data, 0, nRead);
- }
-
- buffer.flush();
- input.close();
- return buffer.toByteArray();
- }
-
- public static String getFilePickerResult(FileType ft, Intent result, Context c) throws IOException, SecurityException {
-
- Uri uri = result.getData();
- if (uri == null)
- return null;
-
- byte[] fileData = readBytesFromStream(c.getContentResolver().openInputStream(uri));
- String newData = null;
-
- Cursor cursor = c.getContentResolver().query(uri, null, null, null, null);
-
- String prefix = "";
- try {
- if (cursor!=null && cursor.moveToFirst()) {
- int cidx = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
- if (cidx != -1) {
- String displayName = cursor.getString(cidx);
-
- if (!displayName.contains(VpnProfile.INLINE_TAG) && !displayName.contains(VpnProfile.DISPLAYNAME_TAG))
- prefix = VpnProfile.DISPLAYNAME_TAG + displayName;
- }
- }
- } finally {
- if(cursor!=null)
- cursor.close();
- }
-
- switch (ft) {
- case PKCS12:
- newData = Base64.encodeToString(fileData, Base64.DEFAULT);
- break;
- default:
- newData = new String(fileData, "UTF-8");
- break;
- }
-
- return prefix + VpnProfile.INLINE_TAG + newData;
- }
-}
diff --git a/app/src/main/java/de/blinkt/openvpn/fragments/VPNProfileList.java b/app/src/main/java/de/blinkt/openvpn/fragments/VPNProfileList.java
deleted file mode 100644
index 693a7e71..00000000
--- a/app/src/main/java/de/blinkt/openvpn/fragments/VPNProfileList.java
+++ /dev/null
@@ -1,346 +0,0 @@
-package de.blinkt.openvpn.fragments;
-
-import android.annotation.TargetApi;
-import android.app.Activity;
-import android.app.AlertDialog;
-import android.app.ListFragment;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.Intent;
-import android.graphics.drawable.Drawable;
-import android.net.Uri;
-import android.os.Build;
-import android.os.Bundle;
-import android.text.Html;
-import android.text.Html.ImageGetter;
-import android.view.*;
-import android.view.View.OnClickListener;
-import android.webkit.MimeTypeMap;
-import android.widget.ArrayAdapter;
-import android.widget.EditText;
-import android.widget.TextView;
-import android.widget.Toast;
-import de.blinkt.openvpn.*;
-import de.blinkt.openvpn.activities.ConfigConverter;
-import de.blinkt.openvpn.activities.FileSelect;
-import de.blinkt.openvpn.activities.VPNPreferences;
-import de.blinkt.openvpn.core.ProfileManager;
-
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.TreeSet;
-
-public class VPNProfileList extends ListFragment {
-
- public final static int RESULT_VPN_DELETED = Activity.RESULT_FIRST_USER;
-
- private static final int MENU_ADD_PROFILE = Menu.FIRST;
-
- private static final int START_VPN_CONFIG = 92;
- private static final int SELECT_PROFILE = 43;
- private static final int IMPORT_PROFILE = 231;
- private static final int FILE_PICKER_RESULT = 392;
-
- private static final int MENU_IMPORT_PROFILE = Menu.FIRST +1;
-
-
- class VPNArrayAdapter extends ArrayAdapter<VpnProfile> {
-
- public VPNArrayAdapter(Context context, int resource,
- int textViewResourceId) {
- super(context, resource, textViewResourceId);
- }
-
- @Override
- public View getView(final int position, View convertView, ViewGroup parent) {
- View v = super.getView(position, convertView, parent);
-
- View titleview = v.findViewById(R.id.vpn_list_item_left);
- titleview.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- VpnProfile profile =(VpnProfile) getListAdapter().getItem(position);
- startVPN(profile);
- }
- });
-
- View settingsview = v.findViewById(R.id.quickedit_settings);
- settingsview.setOnClickListener(new OnClickListener() {
-
- @Override
- public void onClick(View v) {
- VpnProfile editProfile = (VpnProfile) getListAdapter().getItem(position);
- editVPN(editProfile);
-
- }
- });
-
- return v;
- }
- }
-
-
-
-
-
-
-
-
- private ArrayAdapter<VpnProfile> mArrayadapter;
-
- protected VpnProfile mEditProfile=null;
-
-
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setHasOptionsMenu(true);
-
- }
-
-
- class MiniImageGetter implements ImageGetter {
-
-
- @Override
- public Drawable getDrawable(String source) {
- Drawable d=null;
- if ("ic_menu_add".equals(source))
- d = getActivity().getResources().getDrawable(android.R.drawable.ic_menu_add);
- else if("ic_menu_archive".equals(source))
- d = getActivity().getResources().getDrawable(R.drawable.ic_menu_archive);
-
-
-
- if(d!=null) {
- d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
- return d;
- }else{
- return null;
- }
- }
- }
-
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- View v = inflater.inflate(R.layout.vpn_profile_list, container,false);
-
- TextView newvpntext = (TextView) v.findViewById(R.id.add_new_vpn_hint);
- TextView importvpntext = (TextView) v.findViewById(R.id.import_vpn_hint);
-
-
-
- newvpntext.setText(Html.fromHtml(getString(R.string.add_new_vpn_hint),new MiniImageGetter(),null));
- importvpntext.setText(Html.fromHtml(getString(R.string.vpn_import_hint),new MiniImageGetter(),null));
-
-
-
- return v;
-
- }
-
- @Override
- public void onActivityCreated(Bundle savedInstanceState) {
- super.onActivityCreated(savedInstanceState);
- setListAdapter();
- }
-
- static class VpnProfileNameComparator implements Comparator<VpnProfile> {
-
- @Override
- public int compare(VpnProfile lhs, VpnProfile rhs) {
- if (lhs == rhs)
- // Catches also both null
- return 0;
-
- if (lhs == null)
- return -1;
- if (rhs == null)
- return 1;
-
- if (lhs.mName == null)
- return -1;
- if (rhs.mName == null)
- return 1;
-
- return lhs.mName.compareTo(rhs.mName);
- }
-
- }
-
- private void setListAdapter() {
- mArrayadapter = new VPNArrayAdapter(getActivity(),R.layout.vpn_list_item,R.id.vpn_item_title);
- Collection<VpnProfile> allvpn = getPM().getProfiles();
-
- TreeSet<VpnProfile> sortedset = new TreeSet<VpnProfile>(new VpnProfileNameComparator());
- sortedset.addAll(allvpn);
- mArrayadapter.addAll(sortedset);
-
- setListAdapter(mArrayadapter);
- }
-
-
-
- @Override
- public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
- menu.add(0, MENU_ADD_PROFILE, 0 , R.string.menu_add_profile)
- .setIcon(android.R.drawable.ic_menu_add)
- .setAlphabeticShortcut('a')
- .setTitleCondensed(getActivity().getString(R.string.add))
- .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
-
- menu.add(0, MENU_IMPORT_PROFILE, 0, R.string.menu_import)
- .setIcon(R.drawable.ic_menu_archive)
- .setAlphabeticShortcut('i')
- .setTitleCondensed(getActivity().getString(R.string.menu_import_short))
- .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT );
- }
-
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- final int itemId = item.getItemId();
- if (itemId == MENU_ADD_PROFILE) {
- onAddProfileClicked();
- return true;
- } else if (itemId == MENU_IMPORT_PROFILE) {
- if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
- startFilePicker();
- else
- startImportConfig();
-
- return true;
- } else {
- return super.onOptionsItemSelected(item);
- }
- }
-
- @TargetApi(Build.VERSION_CODES.KITKAT)
- private void startFilePicker() {
- Intent i = Utils.getFilePickerIntent(getActivity(), Utils.FileType.OVPN_CONFIG);
- startActivityForResult(i, FILE_PICKER_RESULT);
- }
-
- private void startImportConfig() {
- Intent intent = new Intent(getActivity(),FileSelect.class);
- intent.putExtra(FileSelect.NO_INLINE_SELECTION, true);
- intent.putExtra(FileSelect.WINDOW_TITLE, R.string.import_configuration_file);
- startActivityForResult(intent, SELECT_PROFILE);
- }
-
-
-
-
-
- private void onAddProfileClicked() {
- Context context = getActivity();
- if (context != null) {
- final EditText entry = new EditText(context);
- entry.setSingleLine();
-
- AlertDialog.Builder dialog = new AlertDialog.Builder(context);
- dialog.setTitle(R.string.menu_add_profile);
- dialog.setMessage(R.string.add_profile_name_prompt);
- dialog.setView(entry);
-
-
- dialog.setPositiveButton(android.R.string.ok,
- new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- String name = entry.getText().toString();
- if (getPM().getProfileByName(name)==null) {
- VpnProfile profile = new VpnProfile(name);
- addProfile(profile);
- editVPN(profile);
- } else {
- Toast.makeText(getActivity(), R.string.duplicate_profile_name, Toast.LENGTH_LONG).show();
- }
- }
-
-
- });
- dialog.setNegativeButton(android.R.string.cancel, null);
- dialog.create().show();
- }
-
- }
-
- private void addProfile(VpnProfile profile) {
- getPM().addProfile(profile);
- getPM().saveProfileList(getActivity());
- getPM().saveProfile(getActivity(),profile);
- mArrayadapter.add(profile);
- }
-
- private ProfileManager getPM() {
- return ProfileManager.getInstance(getActivity());
- }
-
-
- @Override
- public void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
-
- if(resultCode == RESULT_VPN_DELETED){
- if(mArrayadapter != null && mEditProfile !=null)
- mArrayadapter.remove(mEditProfile);
- }
-
- if(resultCode != Activity.RESULT_OK)
- return;
-
- if (requestCode == START_VPN_CONFIG) {
- String configuredVPN = data.getStringExtra(VpnProfile.EXTRA_PROFILEUUID);
-
- VpnProfile profile = ProfileManager.get(getActivity(),configuredVPN);
- getPM().saveProfile(getActivity(), profile);
- // Name could be modified, reset List adapter
- setListAdapter();
-
- } else if(requestCode== SELECT_PROFILE) {
- String fileData = data.getStringExtra(FileSelect.RESULT_DATA);
- Uri uri = new Uri.Builder().path(fileData).scheme("file").build();
-
- startConfigImport(uri);
- } else if(requestCode == IMPORT_PROFILE) {
- String profileUUID = data.getStringExtra(VpnProfile.EXTRA_PROFILEUUID);
- mArrayadapter.add(ProfileManager.get(getActivity(), profileUUID));
- } else if(requestCode == FILE_PICKER_RESULT) {
- if (data != null) {
- Uri uri = data.getData();
- startConfigImport(uri);
- }
- }
-
- }
-
- private void startConfigImport(Uri uri) {
- Intent startImport = new Intent(getActivity(),ConfigConverter.class);
- startImport.setAction(ConfigConverter.IMPORT_PROFILE);
- startImport.setData(uri);
- startActivityForResult(startImport, IMPORT_PROFILE);
- }
-
-
- private void editVPN(VpnProfile profile) {
- mEditProfile =profile;
- Intent vprefintent = new Intent(getActivity(),VPNPreferences.class)
- .putExtra(getActivity().getPackageName() + ".profileUUID", profile.getUUID().toString());
-
- startActivityForResult(vprefintent,START_VPN_CONFIG);
- }
-
- private void startVPN(VpnProfile profile) {
-
- getPM().saveProfile(getActivity(), profile);
-
- Intent intent = new Intent(getActivity(),LaunchVPN.class);
- intent.putExtra(LaunchVPN.EXTRA_KEY, profile.getUUID().toString());
- intent.setAction(Intent.ACTION_MAIN);
- startActivity(intent);
- }
-}
diff --git a/app/src/main/java/de/blinkt/openvpn/views/FileSelectLayout.java b/app/src/main/java/de/blinkt/openvpn/views/FileSelectLayout.java
deleted file mode 100644
index 06dbec22..00000000
--- a/app/src/main/java/de/blinkt/openvpn/views/FileSelectLayout.java
+++ /dev/null
@@ -1,158 +0,0 @@
-package de.blinkt.openvpn.views;
-
-import se.leap.bitmaskclient.R;
-import de.blinkt.openvpn.VpnProfile;
-import de.blinkt.openvpn.activities.FileSelect;
-import de.blinkt.openvpn.core.VpnStatus;
-import de.blinkt.openvpn.core.X509Utils;
-import android.content.Context;
-import android.content.Intent;
-import android.content.res.TypedArray;
-import android.util.AttributeSet;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.Button;
-import android.widget.LinearLayout;
-import android.widget.TextView;
-import de.blinkt.openvpn.fragments.Utils;
-
-import java.io.*;
-
-import static android.os.Build.*;
-
-
-public class FileSelectLayout extends LinearLayout implements OnClickListener {
-
- public void parseResponse(Intent data, Context c) {
- if (VERSION.SDK_INT < VERSION_CODES.KITKAT) {
- String fileData = data.getStringExtra(FileSelect.RESULT_DATA);
- setData(fileData, c);
- } else if (data != null) {
- try {
- String newData = Utils.getFilePickerResult(fileType, data, c);
- if (newData!=null)
- setData(newData, c);
-
- } catch (IOException e) {
- VpnStatus.logException(e);
- } catch (SecurityException e) {
- VpnStatus.logException(e);
- }
-
-
- }
- }
-
- public interface FileSelectCallback {
-
- String getString(int res);
-
- void startActivityForResult(Intent startFC, int mTaskId);
- }
-
- private boolean mIsCertificate;
- private TextView mDataView;
- private String mData;
- private FileSelectCallback mFragment;
- private int mTaskId;
- private Button mSelectButton;
- private Utils.FileType fileType;
- private String mTitle;
- private boolean mShowClear;
- private TextView mDataDetails;
-
- public FileSelectLayout(Context context, AttributeSet attrset) {
- super(context, attrset);
-
- TypedArray ta = context.obtainStyledAttributes(attrset, R.styleable.FileSelectLayout);
-
- setupViews(ta.getString(R.styleable.FileSelectLayout_title), ta.getBoolean(R.styleable.FileSelectLayout_certificate, true));
-
- ta.recycle();
- }
-
- public FileSelectLayout (Context context, String title, boolean isCerticate)
- {
- super(context);
-
- setupViews(title, isCerticate);
-
- }
-
- private void setupViews(String title, boolean isCertificate) {
- inflate(getContext(), R.layout.file_select, this);
-
- mTitle = title;
- mIsCertificate = isCertificate;
-
- TextView tview = (TextView) findViewById(R.id.file_title);
- tview.setText(mTitle);
-
- mDataView = (TextView) findViewById(R.id.file_selected_item);
- mDataDetails = (TextView) findViewById(R.id.file_selected_description);
- mSelectButton = (Button) findViewById(R.id.file_select_button);
- mSelectButton.setOnClickListener(this);
- }
-
-
- public void setCaller(FileSelectCallback fragment, int i, Utils.FileType ft) {
- mTaskId = i;
- mFragment = fragment;
- fileType = ft;
- }
-
- public void getCertificateFileDialog() {
- Intent startFC = new Intent(getContext(), FileSelect.class);
- startFC.putExtra(FileSelect.START_DATA, mData);
- startFC.putExtra(FileSelect.WINDOW_TITLE, mTitle);
- if (fileType == Utils.FileType.PKCS12)
- startFC.putExtra(FileSelect.DO_BASE64_ENCODE, true);
- if (mShowClear)
- startFC.putExtra(FileSelect.SHOW_CLEAR_BUTTON, true);
-
- mFragment.startActivityForResult(startFC, mTaskId);
- }
-
-
- public String getData() {
- return mData;
- }
-
- public void setData(String data, Context c) {
- mData = data;
- if (data == null) {
- mDataView.setText(c.getString(R.string.no_data));
- mDataDetails.setText("");
- } else {
- if (mData.startsWith(VpnProfile.DISPLAYNAME_TAG)) {
- mDataView.setText(c.getString(R.string.imported_from_file, VpnProfile.getDisplayName(mData)));
- } else if (mData.startsWith(VpnProfile.INLINE_TAG))
- mDataView.setText(R.string.inline_file_data);
- else
- mDataView.setText(data);
- if (mIsCertificate)
- mDataDetails.setText(X509Utils.getCertificateFriendlyName(c, data));
- }
-
- }
-
- @Override
- public void onClick(View v) {
- if (v == mSelectButton) {
- if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
- Intent startFilePicker = Utils.getFilePickerIntent(getContext(),fileType);
- mFragment.startActivityForResult(startFilePicker, mTaskId);
- } else {
- getCertificateFileDialog();
- }
- }
- }
-
-
-
-
- public void setShowClear() {
- mShowClear = true;
- }
-
-}
diff --git a/app/src/main/java/de/blinkt/openvpn/views/RemoteCNPreference.java b/app/src/main/java/de/blinkt/openvpn/views/RemoteCNPreference.java
deleted file mode 100644
index b24e6f8f..00000000
--- a/app/src/main/java/de/blinkt/openvpn/views/RemoteCNPreference.java
+++ /dev/null
@@ -1,141 +0,0 @@
-package de.blinkt.openvpn.views;
-
-import android.content.Context;
-import android.preference.DialogPreference;
-import android.util.AttributeSet;
-import android.util.Pair;
-import android.view.View;
-import android.widget.ArrayAdapter;
-import android.widget.EditText;
-import android.widget.Spinner;
-import android.widget.TextView;
-
-import se.leap.bitmaskclient.R;
-import de.blinkt.openvpn.VpnProfile;
-
-public class RemoteCNPreference extends DialogPreference {
-
-
- private Spinner mSpinner;
- private EditText mEditText;
- private int mDNType;
- private String mDn;
- private TextView mRemoteTLSNote;
- //private ScrollView mScrollView;
-
- public RemoteCNPreference(Context context, AttributeSet attrs) {
- super(context, attrs);
- setDialogLayoutResource(R.layout.tlsremote);
-
- }
-
- @Override
- protected void onBindDialogView(View view) {
-
- super.onBindDialogView(view);
-
- mEditText = (EditText) view.findViewById(R.id.tlsremotecn);
- mSpinner = (Spinner) view.findViewById(R.id.x509verifytype);
- mRemoteTLSNote = (TextView) view.findViewById(R.id.tlsremotenote);
- //mScrollView = (ScrollView) view.findViewById(R.id.tlsremotescroll);
- if(mDn!=null)
- mEditText.setText(mDn);
-
- populateSpinner();
-
- }
-
-
-
- public String getCNText() {
- return mDn;
- }
-
- public int getAuthtype() {
- return mDNType;
- }
-
- public void setDN(String dn) {
- mDn = dn;
- if(mEditText!=null)
- mEditText.setText(dn);
- }
-
- public void setAuthType(int x509authtype) {
- mDNType = x509authtype;
- if (mSpinner!=null)
- populateSpinner();
- }
-
- @Override
- protected void onDialogClosed(boolean positiveResult) {
- super.onDialogClosed(positiveResult);
-
- if (positiveResult) {
- String dn = mEditText.getText().toString();
- int authtype = getAuthTypeFromSpinner();
- if (callChangeListener(new Pair<Integer, String>(authtype, dn))) {
- mDn = dn;
- mDNType = authtype;
- }
- }
- }
-
- private void populateSpinner() {
- ArrayAdapter<String> authtypes = new ArrayAdapter<String>(getContext(), android.R.layout.simple_spinner_item);
- authtypes.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
-
- authtypes.add(getContext().getString(R.string.complete_dn));
- authtypes.add(getContext().getString(R.string.rdn));
- authtypes.add(getContext().getString(R.string.rdn_prefix));
- if ((mDNType == VpnProfile.X509_VERIFY_TLSREMOTE || mDNType == VpnProfile.X509_VERIFY_TLSREMOTE_COMPAT_NOREMAPPING)
- && !(mDn==null || "".equals(mDn))) {
- authtypes.add(getContext().getString(R.string.tls_remote_deprecated));
- mRemoteTLSNote.setVisibility(View.VISIBLE);
- } else {
- mRemoteTLSNote.setVisibility(View.GONE);
- }
- mSpinner.setAdapter(authtypes);
- mSpinner.setSelection(getSpinnerPositionFromAuthTYPE());
- }
-
- private int getSpinnerPositionFromAuthTYPE() {
- switch (mDNType) {
- case VpnProfile.X509_VERIFY_TLSREMOTE_DN:
- return 0;
- case VpnProfile.X509_VERIFY_TLSREMOTE_RDN:
- return 1;
- case VpnProfile.X509_VERIFY_TLSREMOTE_RDN_PREFIX:
- return 2;
- case VpnProfile.X509_VERIFY_TLSREMOTE_COMPAT_NOREMAPPING:
- case VpnProfile.X509_VERIFY_TLSREMOTE:
- if (mDn==null || "".equals(mDn))
- return 1;
- else
- return 3;
-
-
- default:
- return 0;
- }
- }
-
- private int getAuthTypeFromSpinner() {
- int pos = mSpinner.getSelectedItemPosition();
- switch (pos) {
- case 0:
- return VpnProfile.X509_VERIFY_TLSREMOTE_DN;
- case 1:
- return VpnProfile.X509_VERIFY_TLSREMOTE_RDN;
- case 2:
- return VpnProfile.X509_VERIFY_TLSREMOTE_RDN_PREFIX;
- case 3:
- // This is the tls-remote entry, only visible if mDntype is a
- // tls-remote type
- return mDNType;
- default:
- return VpnProfile.X509_VERIFY_TLSREMOTE;
- }
- }
-
-}
diff --git a/app/src/main/java/de/blinkt/openvpn/views/SeekBarTicks.java b/app/src/main/java/de/blinkt/openvpn/views/SeekBarTicks.java
deleted file mode 100644
index 88e8e164..00000000
--- a/app/src/main/java/de/blinkt/openvpn/views/SeekBarTicks.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package de.blinkt.openvpn.views;
-
-import android.content.Context;
-import android.content.res.TypedArray;
-import android.graphics.Canvas;
-import android.graphics.Paint;
-import android.graphics.drawable.Drawable;
-import android.util.AttributeSet;
-import android.util.TypedValue;
-import android.view.ViewConfiguration;
-import android.widget.SeekBar;
-
-public class SeekBarTicks extends SeekBar {
- private Paint mTickPaint;
- private float mTickHeight;
-
- private float tickHeightRatio = 0.6f;
-
- public SeekBarTicks(Context context, AttributeSet attrs) {
- super (context, attrs);
-
- initTicks (context, attrs, android.R.attr.seekBarStyle);
- }
-
-
- public SeekBarTicks(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
-
- initTicks (context, attrs, defStyle);
-
- /*mTickHeight = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
- tickHeightDP,
- ctx.getResources().getDisplayMetrics()); */
- }
-
- private void initTicks(Context context, AttributeSet attrs, int defStyle) {
- TypedArray a = context.obtainStyledAttributes(attrs,
- new int[] { android.R.attr.secondaryProgress }, defStyle, 0);
-
-
- int tickColor = a.getColor(0, android.R.color.black);
- mTickPaint = new Paint();
- mTickPaint.setColor( context.getResources().getColor(tickColor));
- a.recycle();
- }
-
-
- @Override
- protected synchronized void onDraw(Canvas canvas) {
- drawTicks(canvas);
- super.onDraw(canvas);
- }
-
- private void drawTicks(Canvas canvas) {
-
- final int available = getWidth() - getPaddingLeft() - getPaddingRight();
- final int availableHeight = getHeight() - getPaddingBottom() - getPaddingTop();
-
- int extrapadding = (int) ((availableHeight- (availableHeight * tickHeightRatio))/2);
-
- int tickSpacing = available / (getMax() );
-
- for (int i = 1; i < getMax(); i++) {
- final float x = getPaddingLeft() + i * tickSpacing;
-
- canvas.drawLine(x, getPaddingTop()+extrapadding, x, getHeight()-getPaddingBottom()-extrapadding, mTickPaint);
- }
- }
-}
diff --git a/app/src/main/res/layout/log_window.xml b/app/src/main/res/layout/log_window.xml
new file mode 100644
index 00000000..56c3e349
--- /dev/null
+++ b/app/src/main/res/layout/log_window.xml
@@ -0,0 +1,7 @@
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:id="@+id/container"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ tools:context=".LogWindow"
+ tools:ignore="MergeRootFrame" /> \ No newline at end of file
diff --git a/build.gradle b/build.gradle
index 4e853f4f..a0895556 100644
--- a/build.gradle
+++ b/build.gradle
@@ -44,6 +44,9 @@ task copyIcsOpenVPNClasses( type: Copy ) {
include '**/*.java'
include '**/*.aidl'
include '**/strings.xml'
+ exclude '**/activities/'
+ exclude '**/fragments/'
+ exclude '**/views/'
rename 'strings.xml', 'strings-icsopenvpn.xml'
filter {
@@ -64,6 +67,26 @@ task copyIcsOpenVPNClasses( type: Copy ) {
include '**/ic_stat_vpn_outline.png'
include '**/ic_stat_vpn_empty_halo.png'
} into 'app'
+
+ from ('ics-openvpn/main') {
+ include '**/DisconnectVPN.java'
+ include '**/LogWindow.java'
+ include '**/LogFragment.java'
+ include '**/log_window.xml'
+ filter {
+ line -> line.replaceAll('de.blinkt.openvpn.R', 'se.leap.bitmaskclient.R')
+ }
+ filter {
+ line -> line.replaceAll('de.blinkt.openvpn.BuildConfig', 'se.leap.bitmaskclient.BuildConfig')
+ }
+ filter {
+ line -> line.replace('package de.blinkt.openvpn;', 'package de.blinkt.openvpn;\n\nimport se.leap.bitmaskclient.R;')
+ }
+ filter {
+ line -> line.replace('package de.blinkt.openvpn.fragments;', 'package de.blinkt.openvpn.fragments;\n\nimport se.leap.bitmaskclient.R;')
+ }
+
+ } into 'app'
}
def processFileInplace(file, Closure processText) {