diff options
author | Parménides GV <parmegv@sdf.org> | 2013-12-17 11:36:51 +0100 |
---|---|---|
committer | Sean Leonard <meanderingcode@aetherislands.net> | 2014-02-04 16:56:39 -0800 |
commit | d13aadfae85e2d269f3826ed772b42f6b99065bf (patch) | |
tree | 54c98ad06975d3e2091dd4bdb2a74b1374b58e3b /src/se/leap/openvpn | |
parent | d246e4e0b571874de0927cacf72fb193baabdca9 (diff) |
More unused classes wiped.
Diffstat (limited to 'src/se/leap/openvpn')
-rw-r--r-- | src/se/leap/openvpn/ConfigConverter.java | 454 | ||||
-rw-r--r-- | src/se/leap/openvpn/OnBootReceiver.java | 33 | ||||
-rw-r--r-- | src/se/leap/openvpn/OpenVpnPreferencesFragment.java | 52 | ||||
-rw-r--r-- | src/se/leap/openvpn/Settings_Obscure.java | 116 | ||||
-rw-r--r-- | src/se/leap/openvpn/Settings_Routing.java | 73 | ||||
-rw-r--r-- | src/se/leap/openvpn/ShowConfigFragment.java | 67 |
6 files changed, 0 insertions, 795 deletions
diff --git a/src/se/leap/openvpn/ConfigConverter.java b/src/se/leap/openvpn/ConfigConverter.java deleted file mode 100644 index 3c6bf91e..00000000 --- a/src/se/leap/openvpn/ConfigConverter.java +++ /dev/null @@ -1,454 +0,0 @@ - -package se.leap.openvpn; - -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.List; -import java.util.Vector; - -import se.leap.bitmaskclient.R; - -import android.app.Activity; -import android.app.AlertDialog; -import android.app.AlertDialog.Builder; -import android.app.ListActivity; -import android.content.ActivityNotFoundException; -import android.content.Intent; -import android.os.Bundle; -import android.os.Environment; -import android.security.KeyChain; -import android.security.KeyChainAliasCallback; -import android.util.Base64; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.view.View; -import android.widget.ArrayAdapter; -import android.widget.CheckBox; -import se.leap.openvpn.ConfigParser.ConfigParseError; - -public class ConfigConverter extends ListActivity { - - public static final String IMPORT_PROFILE = "se.leap.openvpn.IMPORT_PROFILE"; - - private VpnProfile mResult; - private ArrayAdapter<String> mArrayAdapter; - - private List<String> mPathsegments; - - private String mAliasName=null; - - private int RESULT_INSTALLPKCS12 = 7; - - private String mPossibleName=null; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.config_converter); - } - - - - @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 onActivityResult(int requestCode, int resultCode, Intent data) { - if(requestCode==RESULT_INSTALLPKCS12) { - if(resultCode==Activity.RESULT_OK) { - showCertDialog(); - } - } - - super.onActivityResult(requestCode, resultCode, data); - } - - private void saveProfile() { - Intent result = new Intent(); - ProfileManager vpl = ProfileManager.getInstance(this); - - if(((CheckBox)findViewById(R.id.correcttls)).isChecked() && isOldCNFormat()) { - convertTLSRemote(); - } - - setUniqueProfileName(vpl); - vpl.addProfile(mResult); - vpl.saveProfile(this, mResult); - vpl.saveProfileList(this); - result.putExtra(VpnProfile.EXTRA_PROFILEUUID,mResult.getUUID().toString()); - setResult(Activity.RESULT_OK, result); - finish(); - } - - - - private void convertTLSRemote() { - if(mResult.mRemoteCN.startsWith("/")) - mResult.mRemoteCN = mResult.mRemoteCN.substring(1); - mResult.mRemoteCN = mResult.mRemoteCN.replace("/", ", "); - } - - 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(pkcs12datastr!=null && pkcs12datastr.startsWith(VpnProfile.INLINE_TAG)) { - Intent inkeyintent = KeyChain.createInstallIntent(); - - pkcs12datastr= pkcs12datastr.substring(VpnProfile.INLINE_TAG.length()); - - - 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(mResult.mPKCS12Filename!=null && mResult.mPKCS12Filename.startsWith(VpnProfile.INLINE_TAG)) { - 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 void setUniqueProfileName(ProfileManager vpl) { - int i=0; - - String newname = mPossibleName; - - while(vpl.getProfileByName(newname)!=null) { - i++; - if(i==1) - newname = getString(R.string.converted_profile); - else - newname = getString(R.string.converted_profile_i,i); - } - - mResult.mName=newname; - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - MenuInflater inflater = getMenuInflater(); - inflater.inflate(R.menu.import_menu, menu); - return true; - } - - private String embedFile(String filename) { - return embedFile(filename, false); - } - - private String embedFile(String filename, boolean base64encode) - { - if(filename==null) - return null; - - // Already embedded, nothing to do - if(filename.startsWith(VpnProfile.INLINE_TAG)) - return filename; - - File possibleFile = findFile(filename); - if(possibleFile==null) - return filename; - else - return readFileContent(possibleFile,base64encode); - - } - - private File findFile(String filename) { - File foundfile =findFileRaw(filename); - - if (foundfile==null && filename!=null && !filename.equals("")) - log(R.string.import_could_not_open,filename); - - return foundfile; - } - - - - 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("/"); - - Vector<File> dirlist = new Vector<File>(); - - for(int i=mPathsegments.size()-1;i >=0 ;i--){ - String path = ""; - for (int j = 0;j<=i;j++) { - path += "/" + mPathsegments.get(j); - } - 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.INLINE_TAG + data; - - } - - - private byte[] readBytesFromFile(File file) throws IOException { - InputStream input = new FileInputStream(file); - - long len= file.length(); - - - // 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; - } - - 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); - mResult.mClientCertFilename = embedFile(mResult.mClientCertFilename); - mResult.mClientKeyFilename = embedFile(mResult.mClientKeyFilename); - mResult.mTLSAuthFilename = embedFile(mResult.mTLSAuthFilename); - mResult.mPKCS12Filename = embedFile(mResult.mPKCS12Filename,true); - - - if(mResult.mUsername == null && mResult.mPassword != null ){ - String data =embedFile(mResult.mPassword); - ConfigParser.useEmbbedUserAuth(mResult, data); - } - } - - - @Override - protected void onStart() { - super.onStart(); - - mArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1); - getListView().setAdapter(mArrayAdapter); - 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 { - if(data.getScheme().equals("file")) { - mPossibleName = data.getLastPathSegment(); - if(mPossibleName!=null){ - mPossibleName =mPossibleName.replace(".ovpn", ""); - mPossibleName =mPossibleName.replace(".conf", ""); - } - } - InputStream is = getContentResolver().openInputStream(data); - mPathsegments = data.getPathSegments(); - - doImport(is); - } catch (FileNotFoundException e) { - log(R.string.import_content_resolve_error); - } - } - } - - return; - } - - private void log(String logmessage) { - mArrayAdapter.add(logmessage); - } - - private void doImport(InputStream is) { - ConfigParser cp = new ConfigParser(); - try { - InputStreamReader isr = new InputStreamReader(is); - - cp.parseConfig(isr); - VpnProfile vp = cp.convertProfile(); - mResult = vp; - embedFiles(); - displayWarnings(); - 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); - } - - if (isOldCNFormat()) - findViewById(R.id.correcttls).setVisibility(View.VISIBLE); - } - - private boolean isOldCNFormat() { - return mResult.mCheckRemoteCN && mResult.mRemoteCN.contains("/") && ! mResult.mRemoteCN.contains("_"); - } - - private void log(int ressourceId, Object... formatArgs) { - log(getString(ressourceId,formatArgs)); - } -} diff --git a/src/se/leap/openvpn/OnBootReceiver.java b/src/se/leap/openvpn/OnBootReceiver.java deleted file mode 100644 index d97097c3..00000000 --- a/src/se/leap/openvpn/OnBootReceiver.java +++ /dev/null @@ -1,33 +0,0 @@ -package se.leap.openvpn; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; - - -public class OnBootReceiver extends BroadcastReceiver { - - // Debug: am broadcast -a android.intent.action.BOOT_COMPLETED - @Override - public void onReceive(Context context, Intent intent) { - - final String action = intent.getAction(); - - if(Intent.ACTION_BOOT_COMPLETED.equals(action)) { - VpnProfile bootProfile = ProfileManager.getOnBootProfile(context); - if(bootProfile != null) { - lauchVPN(bootProfile, context); - } - } - } - - void lauchVPN(VpnProfile profile,Context context) { - Intent startVpnIntent = new Intent(Intent.ACTION_MAIN); - startVpnIntent.setClass(context, LaunchVPN.class); - startVpnIntent.putExtra(LaunchVPN.EXTRA_KEY,profile.getUUIDString()); - startVpnIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - startVpnIntent.putExtra(LaunchVPN.EXTRA_HIDELOG, true); - - context.startActivity(startVpnIntent); - } -} diff --git a/src/se/leap/openvpn/OpenVpnPreferencesFragment.java b/src/se/leap/openvpn/OpenVpnPreferencesFragment.java deleted file mode 100644 index 190a48fe..00000000 --- a/src/se/leap/openvpn/OpenVpnPreferencesFragment.java +++ /dev/null @@ -1,52 +0,0 @@ -package se.leap.openvpn;
-
-import android.os.Bundle;
-import android.preference.PreferenceFragment;
-import se.leap.bitmaskclient.R;
-
-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 onStop() {
- // TODO Auto-generated method stub
- super.onStop();
- }
-
- @Override
- public void onSaveInstanceState (Bundle outState) {
- super.onSaveInstanceState(outState);
- saveSettings();
- outState.putString(VpnProfile.EXTRA_PROFILEUUID, mProfile.getUUIDString());
- }
-}
diff --git a/src/se/leap/openvpn/Settings_Obscure.java b/src/se/leap/openvpn/Settings_Obscure.java deleted file mode 100644 index 6ba98606..00000000 --- a/src/se/leap/openvpn/Settings_Obscure.java +++ /dev/null @@ -1,116 +0,0 @@ -package se.leap.openvpn; - -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"); - mLogverbosity = (ListPreference) findPreference("verblevel"); - mPersistent = (CheckBoxPreference) findPreference("usePersistTun"); - mConnectretrymax = (ListPreference) findPreference("connectretrymax"); - mConnectretry = (EditTextPreference) findPreference("connectretry"); - - mLogverbosity.setOnPreferenceChangeListener(this); - mLogverbosity.setSummary("%s"); - - 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); - - mLogverbosity.setValue(mProfile.mVerb); - onPreferenceChange(mLogverbosity, mProfile.mVerb); - - 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.mVerb = mLogverbosity.getValue(); - mProfile.mConnectRetryMax = mConnectretrymax.getValue(); - mProfile.mPersistTun = mPersistent.isChecked(); - mProfile.mConnectRetry = mConnectretry.getText(); - } - - - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - if(preference==mLogverbosity) { - // Catch old version problem - if(newValue==null){ - newValue="1"; - } - mLogverbosity.setDefaultValue(newValue); - //This is idiotic. - int i =Integer.parseInt((String) newValue); - - // verb >= 5 is not supported by the chooser - if(i < mLogverbosity.getEntries().length ) - mLogverbosity.setSummary(mLogverbosity.getEntries()[i]); - else - mLogverbosity.setSummary(String.format("debug verbosity: %d",i)); - } else 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/src/se/leap/openvpn/Settings_Routing.java b/src/se/leap/openvpn/Settings_Routing.java deleted file mode 100644 index 3cbdac0f..00000000 --- a/src/se/leap/openvpn/Settings_Routing.java +++ /dev/null @@ -1,73 +0,0 @@ -package se.leap.openvpn; -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; - - @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"); - mRouteNoPull = (CheckBoxPreference) findPreference("routenopull"); - - 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); - - mRouteNoPull.setChecked(mProfile.mRoutenopull); - - // 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(); - } - - @Override - public boolean onPreferenceChange(Preference preference, - Object newValue) { - if( preference == mCustomRoutes || preference == mCustomRoutesv6 ) - preference.setSummary((String)newValue); - - saveSettings(); - return true; - } - - -}
\ No newline at end of file diff --git a/src/se/leap/openvpn/ShowConfigFragment.java b/src/se/leap/openvpn/ShowConfigFragment.java deleted file mode 100644 index 194f87d4..00000000 --- a/src/se/leap/openvpn/ShowConfigFragment.java +++ /dev/null @@ -1,67 +0,0 @@ -package se.leap.openvpn; - -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; - - -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"); - VpnProfile vp = ProfileManager.get(profileUUID); - View v=inflater.inflate(R.layout.viewconfig, container,false); - 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 { - String cfg=vp.getConfigFile(getActivity()); - configtext= cfg; - cv.setText(cfg); - } - return v; - }; - - @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); - } - } -} |