From d07fe5bb87b3a68e20484042d3c15fba3c6ccc86 Mon Sep 17 00:00:00 2001 From: Adithya Abraham Philip Date: Fri, 5 Jun 2015 05:39:12 +0530 Subject: added proxy/tor preferences --- .../keychain/ui/SettingsActivity.java | 285 ++++++++++++++++++++- 1 file changed, 284 insertions(+), 1 deletion(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java index 6fc0aaac6..a49eb731d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java @@ -22,6 +22,7 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.preference.CheckBoxPreference; +import android.preference.EditTextPreference; import android.preference.Preference; import android.preference.PreferenceFragment; import android.preference.PreferenceScreen; @@ -33,9 +34,11 @@ import android.widget.LinearLayout; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.compatibility.AppCompatPreferenceActivity; +import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.ui.widget.IntegerListPreference; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Preferences; +import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; import java.util.List; @@ -209,6 +212,285 @@ public class SettingsActivity extends AppCompatPreferenceActivity { } } + public static class ProxyPrefsFragment extends PreferenceFragment { + private CheckBoxPreference mUseTor; + private CheckBoxPreference mUseNormalProxy; + private EditTextPreference mProxyHost; + private EditTextPreference mProxyPort; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // Load the preferences from an XML resource + addPreferencesFromResource(R.xml.proxy_prefs); + + mUseTor = (CheckBoxPreference) findPreference(Constants.Pref.USE_TOR_PROXY); + mUseNormalProxy = (CheckBoxPreference) findPreference(Constants.Pref.USE_NORMAL_PROXY); + mProxyHost = (EditTextPreference) findPreference(Constants.Pref.PROXY_HOST); + mProxyPort = (EditTextPreference) findPreference(Constants.Pref.PROXY_PORT); + + initializeUseTorPref(); + initializeUseNormalProxyPref(); + initialiseEditTextPreferences(); + + if (mUseTor.isChecked()) disableNormalProxyPrefs(); + else if (mUseNormalProxy.isChecked()) disableUseTorPrefs(); + } + + private void initializeUseTorPref() { + mUseTor.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + if ((Boolean)newValue) { + OrbotHelper orbotHelper = new OrbotHelper(ProxyPrefsFragment.this.getActivity()); + boolean installed = orbotHelper.isOrbotInstalled(); + if (!installed) { + Log.d(Constants.TAG, "Prompting to install Tor"); + orbotHelper.promptToInstall(ProxyPrefsFragment.this.getActivity()); + // don't let the user check the box until he's installed orbot + return false; + } else { + disableNormalProxyPrefs(); + // let the enable tor box be checked + return true; + } + } + else { + // we're unchecking Tor, so enable other proxy + enableNormalProxyPrefs(); + return true; + } + } + }); + } + + private void initializeUseNormalProxyPref() { + mUseNormalProxy.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + if ((Boolean) newValue) { + disableUseTorPrefs(); + } else { + enableUseTorPrefs(); + } + return true; + } + }); + } + + private void initialiseEditTextPreferences() { + mProxyHost.setSummary(mProxyHost.getText()); + mProxyPort.setSummary(mProxyPort.getText()); + + mProxyHost.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + if (newValue.equals("")) { + Notify.create( + ProxyPrefsFragment.this.getActivity(), + R.string.pref_proxy_host_err_invalid, + Notify.Style.ERROR + ).show(); + return false; + } else { + mProxyHost.setSummary((CharSequence) newValue); + return true; + } + } + }); + + mProxyPort.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + try { + int port = Integer.parseInt((String) newValue); + if(port < 0 || port > 65535) { + Notify.create( + ProxyPrefsFragment.this.getActivity(), + R.string.pref_proxy_port_err_invalid, + Notify.Style.ERROR + ).show(); + return false; + } + // no issues, save port + mProxyPort.setSummary("" + port); + return true; + } catch (NumberFormatException e) { + Notify.create( + ProxyPrefsFragment.this.getActivity(), + R.string.pref_proxy_port_err_invalid, + Notify.Style.ERROR + ).show(); + return false; + } + } + }); + } + + private void disableNormalProxyPrefs() { + mUseNormalProxy.setChecked(false); + mUseNormalProxy.setEnabled(false); + mProxyHost.setEnabled(false); + mProxyPort.setEnabled(false); + } + + private void enableNormalProxyPrefs() { + mUseNormalProxy.setEnabled(true); + mProxyHost.setEnabled(true); + mProxyPort.setEnabled(true); + } + + private void disableUseTorPrefs() { + mUseTor.setChecked(false); + mUseTor.setEnabled(false); + } + + private void enableUseTorPrefs() { + mUseTor.setEnabled(true); + } + } + + @TargetApi(Build.VERSION_CODES.KITKAT) + public static class ProxyPrefsFragment extends PreferenceFragment { + private CheckBoxPreference mUseTor; + private CheckBoxPreference mUseNormalProxy; + private EditTextPreference mProxyHost; + private EditTextPreference mProxyPort; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // Load the preferences from an XML resource + addPreferencesFromResource(R.xml.proxy_prefs); + + mUseTor = (CheckBoxPreference) findPreference(Constants.Pref.USE_TOR_PROXY); + mUseNormalProxy = (CheckBoxPreference) findPreference(Constants.Pref.USE_NORMAL_PROXY); + mProxyHost = (EditTextPreference) findPreference(Constants.Pref.PROXY_HOST); + mProxyPort = (EditTextPreference) findPreference(Constants.Pref.PROXY_PORT); + + initializeUseTorPref(); + initializeUseNormalProxyPref(); + initialiseEditTextPreferences(); + + if (mUseTor.isChecked()) disableNormalProxyPrefs(); + else if (mUseNormalProxy.isChecked()) disableUseTorPrefs(); + } + + private void initializeUseTorPref() { + mUseTor.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + if ((Boolean)newValue) { + OrbotHelper orbotHelper = new OrbotHelper(ProxyPrefsFragment.this.getActivity()); + boolean installed = orbotHelper.isOrbotInstalled(); + if (!installed) { + Log.d(Constants.TAG, "Prompting to install Tor"); + orbotHelper.promptToInstall(ProxyPrefsFragment.this.getActivity()); + // don't let the user check the box until he's installed orbot + return false; + } else { + disableNormalProxyPrefs(); + // let the enable tor box be checked + return true; + } + } + else { + // we're unchecking Tor, so enable other proxy + enableNormalProxyPrefs(); + return true; + } + } + }); + } + + private void initializeUseNormalProxyPref() { + mUseNormalProxy.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + if ((Boolean) newValue) { + disableUseTorPrefs(); + } else { + enableUseTorPrefs(); + } + return true; + } + }); + } + + private void initialiseEditTextPreferences() { + mProxyHost.setSummary(mProxyHost.getText()); + mProxyPort.setSummary(mProxyPort.getText()); + + mProxyHost.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + if (newValue.equals("")) { + Notify.create( + ProxyPrefsFragment.this.getActivity(), + R.string.pref_proxy_host_err_invalid, + Notify.Style.ERROR + ).show(); + return false; + } else { + mProxyHost.setSummary((CharSequence) newValue); + return true; + } + } + }); + + mProxyPort.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + try { + int port = Integer.parseInt((String) newValue); + if(port < 0 || port > 65535) { + Notify.create( + ProxyPrefsFragment.this.getActivity(), + R.string.pref_proxy_port_err_invalid, + Notify.Style.ERROR + ).show(); + return false; + } + // no issues, save port + mProxyPort.setSummary("" + port); + return true; + } catch (NumberFormatException e) { + Notify.create( + ProxyPrefsFragment.this.getActivity(), + R.string.pref_proxy_port_err_invalid, + Notify.Style.ERROR + ).show(); + return false; + } + } + }); + } + + private void disableNormalProxyPrefs() { + mUseNormalProxy.setChecked(false); + mUseNormalProxy.setEnabled(false); + mProxyHost.setEnabled(false); + mProxyPort.setEnabled(false); + } + + private void enableNormalProxyPrefs() { + mUseNormalProxy.setEnabled(true); + mProxyHost.setEnabled(true); + mProxyPort.setEnabled(true); + } + + private void disableUseTorPrefs() { + mUseTor.setChecked(false); + mUseTor.setEnabled(false); + } + + private void enableUseTorPrefs() { + mUseTor.setEnabled(true); + } + } + protected boolean isValidFragment(String fragmentName) { return AdvancedPrefsFragment.class.getName().equals(fragmentName) || CloudSearchPrefsFragment.class.getName().equals(fragmentName) @@ -270,7 +552,8 @@ public class SettingsActivity extends AppCompatPreferenceActivity { String[] servers = sPreferences.getKeyServers(); String serverSummary = context.getResources().getQuantityString( R.plurals.n_keyservers, servers.length, servers.length); - return serverSummary + "; " + context.getString(R.string.label_preferred) + ": " + sPreferences.getPreferredKeyserver(); + return serverSummary + "; " + context.getString(R.string.label_preferred) + ": " + sPreferences + .getPreferredKeyserver(); } private static void initializeUseDefaultYubiKeyPin(final CheckBoxPreference mUseDefaultYubiKeyPin) { -- cgit v1.2.3 From 3034db0f71f9dd8e2f4d8838c1803952702f7520 Mon Sep 17 00:00:00 2001 From: Adithya Abraham Philip Date: Sat, 6 Jun 2015 15:26:22 +0530 Subject: added proxy type --- .../keychain/ui/SettingsActivity.java | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java index a49eb731d..383a542ff 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java @@ -217,6 +217,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity { private CheckBoxPreference mUseNormalProxy; private EditTextPreference mProxyHost; private EditTextPreference mProxyPort; + private ListPreference mProxyType; @Override public void onCreate(Bundle savedInstanceState) { @@ -229,10 +230,12 @@ public class SettingsActivity extends AppCompatPreferenceActivity { mUseNormalProxy = (CheckBoxPreference) findPreference(Constants.Pref.USE_NORMAL_PROXY); mProxyHost = (EditTextPreference) findPreference(Constants.Pref.PROXY_HOST); mProxyPort = (EditTextPreference) findPreference(Constants.Pref.PROXY_PORT); + mProxyType = (ListPreference) findPreference(Constants.Pref.PROXY_TYPE); initializeUseTorPref(); initializeUseNormalProxyPref(); - initialiseEditTextPreferences(); + initializeEditTextPreferences(); + initializeProxyTypePreference(); if (mUseTor.isChecked()) disableNormalProxyPrefs(); else if (mUseNormalProxy.isChecked()) disableUseTorPrefs(); @@ -279,7 +282,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity { }); } - private void initialiseEditTextPreferences() { + private void initializeEditTextPreferences() { mProxyHost.setSummary(mProxyHost.getText()); mProxyPort.setSummary(mProxyPort.getText()); @@ -328,17 +331,32 @@ public class SettingsActivity extends AppCompatPreferenceActivity { }); } + private void initializeProxyTypePreference() { + mProxyType.setSummary(mProxyType.getEntry()); + + mProxyType.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + CharSequence entry = mProxyType.getEntries()[mProxyType.findIndexOfValue((String) newValue)]; + mProxyType.setSummary(entry); + return true; + } + }); + } + private void disableNormalProxyPrefs() { mUseNormalProxy.setChecked(false); mUseNormalProxy.setEnabled(false); mProxyHost.setEnabled(false); mProxyPort.setEnabled(false); + mProxyType.setEnabled(false); } private void enableNormalProxyPrefs() { mUseNormalProxy.setEnabled(true); mProxyHost.setEnabled(true); mProxyPort.setEnabled(true); + mProxyType.setEnabled(true); } private void disableUseTorPrefs() { -- cgit v1.2.3 From 0883784ce1a2f85100ada0a84c1f604ad458dd96 Mon Sep 17 00:00:00 2001 From: Adithya Abraham Philip Date: Sat, 6 Jun 2015 19:13:16 +0530 Subject: added NetCipher as submodule --- .../main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java index 383a542ff..4dbfe1a97 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java @@ -31,6 +31,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.LinearLayout; +import info.guardianproject.onionkit.ui.OrbotHelper; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.compatibility.AppCompatPreferenceActivity; @@ -38,7 +39,6 @@ import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.ui.widget.IntegerListPreference; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Preferences; -import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; import java.util.List; -- cgit v1.2.3 From 007d02f01b1381d218a248a377e186b4549a5e0e Mon Sep 17 00:00:00 2001 From: Adithya Abraham Philip Date: Sun, 7 Jun 2015 02:19:03 +0530 Subject: added proxy support, silent right now --- .../keychain/ui/CreateYubiKeyImportFragment.java | 3 ++- .../keychain/ui/ImportKeysActivity.java | 31 ++++++++++++++++++++-- .../keychain/ui/ImportKeysListFragment.java | 12 ++++++--- .../ui/adapter/ImportKeysListCloudLoader.java | 8 ++++-- 4 files changed, 46 insertions(+), 8 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java index c64f05687..945d42a24 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java @@ -171,8 +171,9 @@ public class CreateYubiKeyImportFragment } public void refreshSearch() { + // TODO: PHILIP implement proxy in YubiKey parts mListFragment.loadNew(new ImportKeysListFragment.CloudLoaderState("0x" + mNfcFingerprint, - Preferences.getPreferences(getActivity()).getCloudSearchPrefs())); + Preferences.getPreferences(getActivity()).getCloudSearchPrefs()), null); } public void importKey() { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java index bc83b05b0..b2b6c224a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java @@ -26,6 +26,7 @@ import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; +import info.guardianproject.onionkit.ui.OrbotHelper; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.intents.OpenKeychainIntents; @@ -42,6 +43,7 @@ import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.ParcelableFileCache; import org.sufficientlysecure.keychain.util.ParcelableFileCache.IteratorWithSize; +import org.sufficientlysecure.keychain.util.Preferences; import java.io.IOException; import java.util.ArrayList; @@ -87,11 +89,14 @@ public class ImportKeysActivity extends BaseNfcActivity private ArrayList mKeyList; private CryptoOperationHelper mOperationHelper; + private Preferences.ProxyPrefs mProxyPrefs; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + mProxyPrefs = Preferences.getPreferences(this).getProxyPrefs(); + mImportButton = findViewById(R.id.import_import); mImportButton.setOnClickListener(new OnClickListener() { @Override @@ -224,7 +229,7 @@ public class ImportKeysActivity extends BaseNfcActivity Notify.Style.WARN).show(mTopFragment); // we just set the keyserver startCloudFragment(savedInstanceState, null, false, keyserver); - // it's not necessary to set the keyserver for ImportKeysListFragment since + // we don't set the keyserver for ImportKeysListFragment since // it'll be taken care of by ImportKeysCloudFragment when the user clicks // the search button startListFragment(savedInstanceState, null, null, null, null); @@ -347,7 +352,29 @@ public class ImportKeysActivity extends BaseNfcActivity } public void loadCallback(ImportKeysListFragment.LoaderState loaderState) { - mListFragment.loadNew(loaderState); + if (loaderState instanceof ImportKeysListFragment.CloudLoaderState) { + // do the tor check + OrbotHelper helper = new OrbotHelper(this); + // TODO: Add callbacks by modifying OrbotHelper so we know if the user wants to not use Tor + + if(mProxyPrefs.torEnabled && !helper.isOrbotInstalled()) { + helper.promptToInstall(this); + return; + } + if(mProxyPrefs.torEnabled && !helper.isOrbotRunning()) { + helper.requestOrbotStart(this); + return; + } + } + + mListFragment.loadNew(loaderState, mProxyPrefs.proxy); + } + + /** + * disables use of Tor as proxy for this session + */ + private void disableTorForSession() { + mProxyPrefs = new Preferences.ProxyPrefs(false, false, null); } private void handleMessage(Message message) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java index bf7e41045..a5f661fb7 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java @@ -47,6 +47,7 @@ import java.io.ByteArrayInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import java.net.Proxy; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -64,6 +65,7 @@ public class ImportKeysListFragment extends ListFragment implements private ImportKeysAdapter mAdapter; private LoaderState mLoaderState; + private Proxy mProxy; private static final int LOADER_ID_BYTES = 0; private static final int LOADER_ID_CLOUD = 1; @@ -126,6 +128,7 @@ public class ImportKeysListFragment extends ListFragment implements /** * Creates an interactive ImportKeyListFragment which reads keyrings from bytes, or file specified * by dataUri, or searches a keyserver for serverQuery, if parameter is not null, in that order + * Will immediately load data if non-null bytes/dataUri/serverQuery * * @param bytes byte data containing list of keyrings to be imported * @param dataUri file from which keyrings are to be imported @@ -141,7 +144,7 @@ public class ImportKeysListFragment extends ListFragment implements /** * Visually consists of a list of keyrings with checkboxes to specify which are to be imported - * Can immediately load keyrings specified by any of its parameters + * Will immediately load data if non-null bytes/dataUri/serverQuery is supplied * * @param bytes byte data containing list of keyrings to be imported * @param dataUri file from which keyrings are to be imported @@ -183,6 +186,7 @@ public class ImportKeysListFragment extends ListFragment implements static public class CloudLoaderState extends LoaderState { Preferences.CloudSearchPrefs mCloudPrefs; String mServerQuery; + Proxy proxy; CloudLoaderState(String serverQuery, Preferences.CloudSearchPrefs cloudPrefs) { mServerQuery = serverQuery; @@ -258,7 +262,9 @@ public class ImportKeysListFragment extends ListFragment implements mAdapter.notifyDataSetChanged(); } - public void loadNew(LoaderState loaderState) { + public void loadNew(LoaderState loaderState, Proxy proxy) { + mProxy = proxy; + mLoaderState = loaderState; restartLoaders(); @@ -301,7 +307,7 @@ public class ImportKeysListFragment extends ListFragment implements } case LOADER_ID_CLOUD: { CloudLoaderState ls = (CloudLoaderState) mLoaderState; - return new ImportKeysListCloudLoader(getActivity(), ls.mServerQuery, ls.mCloudPrefs); + return new ImportKeysListCloudLoader(getActivity(), ls.mServerQuery, ls.mCloudPrefs, mProxy); } default: diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListCloudLoader.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListCloudLoader.java index af919f3b6..05d5a19ee 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListCloudLoader.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListCloudLoader.java @@ -29,6 +29,7 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Preferences; +import java.net.Proxy; import java.util.ArrayList; public class ImportKeysListCloudLoader @@ -38,15 +39,18 @@ public class ImportKeysListCloudLoader Preferences.CloudSearchPrefs mCloudPrefs; String mServerQuery; + private Proxy mProxy; private ArrayList mEntryList = new ArrayList<>(); private AsyncTaskResultWrapper> mEntryListWrapper; - public ImportKeysListCloudLoader(Context context, String serverQuery, Preferences.CloudSearchPrefs cloudPrefs) { + public ImportKeysListCloudLoader(Context context, String serverQuery, Preferences.CloudSearchPrefs cloudPrefs, + Proxy proxy) { super(context); mContext = context; mServerQuery = serverQuery; mCloudPrefs = cloudPrefs; + mProxy = proxy; } @Override @@ -97,7 +101,7 @@ public class ImportKeysListCloudLoader private void queryServer(boolean enforceFingerprint) { try { ArrayList searchResult - = CloudSearch.search(mServerQuery, mCloudPrefs); + = CloudSearch.search(mServerQuery, mCloudPrefs, mProxy); mEntryList.clear(); // add result to data -- cgit v1.2.3 From 25d07d173c9b4d8da9e1596ea6286047fa8f111e Mon Sep 17 00:00:00 2001 From: Adithya Abraham Philip Date: Sun, 7 Jun 2015 21:40:27 +0530 Subject: fixed prefs --- .../main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java | 3 +++ 1 file changed, 3 insertions(+) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java index 4dbfe1a97..94b854b73 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java @@ -222,6 +222,9 @@ public class SettingsActivity extends AppCompatPreferenceActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + // makes android's preference framework write to our file instead of default + // This allows us to use the "persistent" attribute to simplify code + sPreferences.setPreferenceManagerFileAndMode(getPreferenceManager()); // Load the preferences from an XML resource addPreferencesFromResource(R.xml.proxy_prefs); -- cgit v1.2.3 From 413536c62b39f9c583cf86b4cd9750b088df6563 Mon Sep 17 00:00:00 2001 From: Adithya Abraham Philip Date: Sun, 7 Jun 2015 22:08:08 +0530 Subject: added placeholder proxy to AddKeyServer --- .../ui/adapter/ImportKeysListCloudLoader.java | 3 +-- .../ui/dialog/AddEditKeyserverDialogFragment.java | 27 ++++++++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListCloudLoader.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListCloudLoader.java index 05d5a19ee..3fd517043 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListCloudLoader.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListCloudLoader.java @@ -100,8 +100,7 @@ public class ImportKeysListCloudLoader */ private void queryServer(boolean enforceFingerprint) { try { - ArrayList searchResult - = CloudSearch.search(mServerQuery, mCloudPrefs, mProxy); + ArrayList searchResult = CloudSearch.search(mServerQuery, mCloudPrefs, mProxy); mEntryList.clear(); // add result to data diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/AddEditKeyserverDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/AddEditKeyserverDialogFragment.java index 321242b2f..7377c4060 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/AddEditKeyserverDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/AddEditKeyserverDialogFragment.java @@ -48,11 +48,26 @@ import android.widget.EditText; import android.widget.TextView; import android.widget.TextView.OnEditorActionListener; +import com.squareup.okhttp.OkHttpClient; +import com.squareup.okhttp.Request; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.keyimport.HkpKeyserver; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.TlsHelper; +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; + +import javax.net.ssl.HttpsURLConnection; +import java.io.IOException; +import java.net.*; +import javax.net.ssl.HttpsURLConnection; + public class AddEditKeyserverDialogFragment extends DialogFragment implements OnEditorActionListener { private static final String ARG_MESSENGER = "arg_messenger"; private static final String ARG_ACTION = "arg_dialog_action"; @@ -207,7 +222,8 @@ public class AddEditKeyserverDialogFragment extends DialogFragment implements On // behaviour same for edit and add String keyserverUrl = mKeyserverEditText.getText().toString(); if (mVerifyKeyserverCheckBox.isChecked()) { - verifyConnection(keyserverUrl); + // TODO: PHILIP Implement proxy + verifyConnection(keyserverUrl, null); } else { dismiss(); // return unverified keyserver back to activity @@ -249,7 +265,7 @@ public class AddEditKeyserverDialogFragment extends DialogFragment implements On sendMessageToHandler(MESSAGE_VERIFICATION_FAILED, data); } - public void verifyConnection(String keyserver) { + public void verifyConnection(String keyserver, final Proxy proxy) { new AsyncTask() { ProgressDialog mProgressDialog; @@ -283,10 +299,11 @@ public class AddEditKeyserverDialogFragment extends DialogFragment implements On } URI newKeyserver = new URI(scheme, schemeSpecificPart, fragment); - Log.d(Constants.TAG, "Converted URL" + newKeyserver); + Log.d("Converted URL", newKeyserver.toString()); - // just see if we can get a connection, then immediately close - TlsHelper.openConnection(newKeyserver.toURL()).getInputStream().close(); + OkHttpClient client = HkpKeyserver.getClient(newKeyserver.toURL(), proxy); + TlsHelper.pinCertificateIfNecessary(client, newKeyserver.toURL()); + client.newCall(new Request.Builder().url(newKeyserver.toURL()).build()).execute(); } catch (TlsHelper.TlsHelperException e) { reason = FailureReason.CONNECTION_FAILED; } catch (MalformedURLException | URISyntaxException e) { -- cgit v1.2.3 From dbc3f90360e56538ca9f599241edce9ac81e063c Mon Sep 17 00:00:00 2001 From: Adithya Abraham Philip Date: Mon, 8 Jun 2015 01:56:35 +0530 Subject: fixed Proxy generation, proxy working for for cloud import --- .../sufficientlysecure/keychain/ui/ImportKeysActivity.java | 8 ++++++-- .../keychain/ui/ImportKeysListFragment.java | 5 +++-- .../sufficientlysecure/keychain/ui/SettingsActivity.java | 5 ++++- .../keychain/ui/adapter/ImportKeysListCloudLoader.java | 13 +++++++++---- 4 files changed, 22 insertions(+), 9 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java index b2b6c224a..f78c19d13 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java @@ -43,9 +43,11 @@ import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.ParcelableFileCache; import org.sufficientlysecure.keychain.util.ParcelableFileCache.IteratorWithSize; +import org.sufficientlysecure.keychain.util.ParcelableProxy; import org.sufficientlysecure.keychain.util.Preferences; import java.io.IOException; +import java.net.Proxy; import java.util.ArrayList; public class ImportKeysActivity extends BaseNfcActivity @@ -367,14 +369,14 @@ public class ImportKeysActivity extends BaseNfcActivity } } - mListFragment.loadNew(loaderState, mProxyPrefs.proxy); + mListFragment.loadNew(loaderState, mProxyPrefs.parcelableProxy); } /** * disables use of Tor as proxy for this session */ private void disableTorForSession() { - mProxyPrefs = new Preferences.ProxyPrefs(false, false, null); + mProxyPrefs = new Preferences.ProxyPrefs(false, false, null, -1, null); } private void handleMessage(Message message) { @@ -455,6 +457,8 @@ public class ImportKeysActivity extends BaseNfcActivity ImportKeysListFragment.CloudLoaderState sls = (ImportKeysListFragment.CloudLoaderState) ls; + data.putParcelable(KeychainService.EXTRA_PARCELABLE_PROXY, mProxyPrefs.parcelableProxy); + // get selected key entries ArrayList keys = new ArrayList<>(); { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java index a5f661fb7..23368504b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java @@ -41,6 +41,7 @@ import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListLoader; import org.sufficientlysecure.keychain.util.InputData; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.ParcelableFileCache.IteratorWithSize; +import org.sufficientlysecure.keychain.util.ParcelableProxy; import org.sufficientlysecure.keychain.util.Preferences; import java.io.ByteArrayInputStream; @@ -65,7 +66,7 @@ public class ImportKeysListFragment extends ListFragment implements private ImportKeysAdapter mAdapter; private LoaderState mLoaderState; - private Proxy mProxy; + private ParcelableProxy mProxy; private static final int LOADER_ID_BYTES = 0; private static final int LOADER_ID_CLOUD = 1; @@ -262,7 +263,7 @@ public class ImportKeysListFragment extends ListFragment implements mAdapter.notifyDataSetChanged(); } - public void loadNew(LoaderState loaderState, Proxy proxy) { + public void loadNew(LoaderState loaderState, ParcelableProxy proxy) { mProxy = proxy; mLoaderState = loaderState; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java index 94b854b73..17df91ba6 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java @@ -23,10 +23,13 @@ import android.content.Intent; import android.os.Bundle; import android.preference.CheckBoxPreference; import android.preference.EditTextPreference; +import android.preference.ListPreference; import android.preference.Preference; +import android.preference.PreferenceActivity; import android.preference.PreferenceFragment; import android.preference.PreferenceScreen; import android.support.v7.widget.Toolbar; +import android.text.TextUtils; import android.view.View; import android.view.ViewGroup; import android.widget.LinearLayout; @@ -292,7 +295,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity { mProxyHost.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { - if (newValue.equals("")) { + if (TextUtils.isEmpty((String) newValue)) { Notify.create( ProxyPrefsFragment.this.getActivity(), R.string.pref_proxy_host_err_invalid, diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListCloudLoader.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListCloudLoader.java index 3fd517043..a4f8f22e0 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListCloudLoader.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListCloudLoader.java @@ -27,6 +27,7 @@ import org.sufficientlysecure.keychain.keyimport.Keyserver; import org.sufficientlysecure.keychain.operations.results.GetKeyResult; import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.util.Log; +import org.sufficientlysecure.keychain.util.ParcelableProxy; import org.sufficientlysecure.keychain.util.Preferences; import java.net.Proxy; @@ -39,18 +40,18 @@ public class ImportKeysListCloudLoader Preferences.CloudSearchPrefs mCloudPrefs; String mServerQuery; - private Proxy mProxy; + private ParcelableProxy mParcelableProxy; private ArrayList mEntryList = new ArrayList<>(); private AsyncTaskResultWrapper> mEntryListWrapper; public ImportKeysListCloudLoader(Context context, String serverQuery, Preferences.CloudSearchPrefs cloudPrefs, - Proxy proxy) { + ParcelableProxy proxy) { super(context); mContext = context; mServerQuery = serverQuery; mCloudPrefs = cloudPrefs; - mProxy = proxy; + mParcelableProxy = proxy; } @Override @@ -100,7 +101,11 @@ public class ImportKeysListCloudLoader */ private void queryServer(boolean enforceFingerprint) { try { - ArrayList searchResult = CloudSearch.search(mServerQuery, mCloudPrefs, mProxy); + ArrayList searchResult = CloudSearch.search( + mServerQuery, + mCloudPrefs, + mParcelableProxy.getProxy() + ); mEntryList.clear(); // add result to data -- cgit v1.2.3 From 65ca77c3cbb5b8bece96e16ff4cd5040ad7884a3 Mon Sep 17 00:00:00 2001 From: Adithya Abraham Philip Date: Thu, 11 Jun 2015 01:34:35 +0530 Subject: orbot dialog fragments added --- .../keychain/ui/ImportKeysActivity.java | 40 +- .../keychain/ui/SettingsActivity.java | 419 ++++++++------------- .../keychain/ui/dialog/InstallDialogFragment.java | 143 +++++++ .../ui/dialog/OrbotStartDialogFragment.java | 99 +++++ .../ui/dialog/PreferenceInstallDialogFragment.java | 143 +++++++ 5 files changed, 568 insertions(+), 276 deletions(-) create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/InstallDialogFragment.java create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/OrbotStartDialogFragment.java create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PreferenceInstallDialogFragment.java (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java index f78c19d13..b41ca58b4 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java @@ -20,13 +20,13 @@ package org.sufficientlysecure.keychain.ui; import android.content.Intent; import android.net.Uri; import android.os.Bundle; +import android.os.Handler; import android.os.Message; import android.support.v4.app.Fragment; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; -import info.guardianproject.onionkit.ui.OrbotHelper; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.intents.OpenKeychainIntents; @@ -43,8 +43,8 @@ import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.ParcelableFileCache; import org.sufficientlysecure.keychain.util.ParcelableFileCache.IteratorWithSize; -import org.sufficientlysecure.keychain.util.ParcelableProxy; import org.sufficientlysecure.keychain.util.Preferences; +import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; import java.io.IOException; import java.net.Proxy; @@ -353,18 +353,33 @@ public class ImportKeysActivity extends BaseNfcActivity } } - public void loadCallback(ImportKeysListFragment.LoaderState loaderState) { + public void loadCallback(final ImportKeysListFragment.LoaderState loaderState) { if (loaderState instanceof ImportKeysListFragment.CloudLoaderState) { // do the tor check - OrbotHelper helper = new OrbotHelper(this); - // TODO: Add callbacks by modifying OrbotHelper so we know if the user wants to not use Tor + // this handle will set tor to be ignored whenever a message is received + Handler ignoreTorHandler = new Handler() { + @Override + public void handleMessage(Message msg) { + // disables Tor until Activity is recreated + mProxyPrefs = new Preferences.ProxyPrefs(false, false, null, -1, null); + mListFragment.loadNew(loaderState, mProxyPrefs.parcelableProxy); + } + }; + + if(mProxyPrefs.torEnabled && !OrbotHelper.isOrbotInstalled(this)) { + + OrbotHelper.getInstallDialogFragmentWithThirdButton( + new Messenger(ignoreTorHandler), + R.string.orbot_install_dialog_ignore_tor + ).show(getSupportFragmentManager(), "orbotInstallDialog"); - if(mProxyPrefs.torEnabled && !helper.isOrbotInstalled()) { - helper.promptToInstall(this); return; } - if(mProxyPrefs.torEnabled && !helper.isOrbotRunning()) { - helper.requestOrbotStart(this); + + if(mProxyPrefs.torEnabled && !OrbotHelper.isOrbotRunning()) { + OrbotHelper.getOrbotStartDialogFragment(new Messenger(ignoreTorHandler), + R.string.orbot_install_dialog_ignore_tor) + .show(getSupportFragmentManager(), "orbotStartDialog"); return; } } @@ -372,13 +387,6 @@ public class ImportKeysActivity extends BaseNfcActivity mListFragment.loadNew(loaderState, mProxyPrefs.parcelableProxy); } - /** - * disables use of Tor as proxy for this session - */ - private void disableTorForSession() { - mProxyPrefs = new Preferences.ProxyPrefs(false, false, null, -1, null); - } - private void handleMessage(Message message) { if (message.arg1 == ServiceProgressHandler.MessageStatus.OKAY.ordinal()) { // get returned data bundle diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java index 17df91ba6..6605995eb 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java @@ -18,6 +18,7 @@ package org.sufficientlysecure.keychain.ui; +import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; @@ -34,7 +35,6 @@ import android.view.View; import android.view.ViewGroup; import android.widget.LinearLayout; -import info.guardianproject.onionkit.ui.OrbotHelper; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.compatibility.AppCompatPreferenceActivity; @@ -42,6 +42,7 @@ import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.ui.widget.IntegerListPreference; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Preferences; +import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; import java.util.List; @@ -49,6 +50,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity { public static final String ACTION_PREFS_CLOUD = "org.sufficientlysecure.keychain.ui.PREFS_CLOUD"; public static final String ACTION_PREFS_ADV = "org.sufficientlysecure.keychain.ui.PREFS_ADV"; + public static final String ACTION_PREFS_PROXY = "org.sufficientlysecure.keychain.ui.PREFS_PROXY"; public static final int REQUEST_CODE_KEYSERVER_PREF = 0x00007005; @@ -216,305 +218,202 @@ public class SettingsActivity extends AppCompatPreferenceActivity { } public static class ProxyPrefsFragment extends PreferenceFragment { - private CheckBoxPreference mUseTor; - private CheckBoxPreference mUseNormalProxy; - private EditTextPreference mProxyHost; - private EditTextPreference mProxyPort; - private ListPreference mProxyType; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - // makes android's preference framework write to our file instead of default - // This allows us to use the "persistent" attribute to simplify code - sPreferences.setPreferenceManagerFileAndMode(getPreferenceManager()); - // Load the preferences from an XML resource - addPreferencesFromResource(R.xml.proxy_prefs); + new Initializer(this).initialize(); - mUseTor = (CheckBoxPreference) findPreference(Constants.Pref.USE_TOR_PROXY); - mUseNormalProxy = (CheckBoxPreference) findPreference(Constants.Pref.USE_NORMAL_PROXY); - mProxyHost = (EditTextPreference) findPreference(Constants.Pref.PROXY_HOST); - mProxyPort = (EditTextPreference) findPreference(Constants.Pref.PROXY_PORT); - mProxyType = (ListPreference) findPreference(Constants.Pref.PROXY_TYPE); + } - initializeUseTorPref(); - initializeUseNormalProxyPref(); - initializeEditTextPreferences(); - initializeProxyTypePreference(); + public static class Initializer { + private CheckBoxPreference mUseTor; + private CheckBoxPreference mUseNormalProxy; + private EditTextPreference mProxyHost; + private EditTextPreference mProxyPort; + private ListPreference mProxyType; + private PreferenceActivity mActivity; + private PreferenceFragment mFragment; + + public Initializer(PreferenceFragment fragment) { + mFragment = fragment; + } - if (mUseTor.isChecked()) disableNormalProxyPrefs(); - else if (mUseNormalProxy.isChecked()) disableUseTorPrefs(); - } + public Initializer(PreferenceActivity activity) { + mActivity = activity; + } - private void initializeUseTorPref() { - mUseTor.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - if ((Boolean)newValue) { - OrbotHelper orbotHelper = new OrbotHelper(ProxyPrefsFragment.this.getActivity()); - boolean installed = orbotHelper.isOrbotInstalled(); - if (!installed) { - Log.d(Constants.TAG, "Prompting to install Tor"); - orbotHelper.promptToInstall(ProxyPrefsFragment.this.getActivity()); - // don't let the user check the box until he's installed orbot - return false; - } else { - disableNormalProxyPrefs(); - // let the enable tor box be checked - return true; - } - } - else { - // we're unchecking Tor, so enable other proxy - enableNormalProxyPrefs(); - return true; - } + public Preference automaticallyFindPreference(String key) { + if(mFragment != null) { + return mFragment.findPreference(key); + } else { + return mActivity.findPreference(key); } - }); - } + } - private void initializeUseNormalProxyPref() { - mUseNormalProxy.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - if ((Boolean) newValue) { - disableUseTorPrefs(); - } else { - enableUseTorPrefs(); - } - return true; + public void initialize() { + // makes android's preference framework write to our file instead of default + // This allows us to use the "persistent" attribute to simplify code + if (mFragment != null) { + Preferences.setPreferenceManagerFileAndMode(mFragment.getPreferenceManager()); + // Load the preferences from an XML resource + mFragment.addPreferencesFromResource(R.xml.proxy_prefs); + } + else { + Preferences.setPreferenceManagerFileAndMode(mActivity.getPreferenceManager()); + // Load the preferences from an XML resource + mActivity.addPreferencesFromResource(R.xml.proxy_prefs); } - }); - } - private void initializeEditTextPreferences() { - mProxyHost.setSummary(mProxyHost.getText()); - mProxyPort.setSummary(mProxyPort.getText()); - - mProxyHost.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - if (TextUtils.isEmpty((String) newValue)) { - Notify.create( - ProxyPrefsFragment.this.getActivity(), - R.string.pref_proxy_host_err_invalid, - Notify.Style.ERROR - ).show(); - return false; - } else { - mProxyHost.setSummary((CharSequence) newValue); - return true; + mUseTor = (CheckBoxPreference) automaticallyFindPreference(Constants.Pref.USE_TOR_PROXY); + mUseNormalProxy = (CheckBoxPreference) automaticallyFindPreference(Constants.Pref.USE_NORMAL_PROXY); + mProxyHost = (EditTextPreference) automaticallyFindPreference(Constants.Pref.PROXY_HOST); + mProxyPort = (EditTextPreference) automaticallyFindPreference(Constants.Pref.PROXY_PORT); + mProxyType = (ListPreference) automaticallyFindPreference(Constants.Pref.PROXY_TYPE); + initializeUseTorPref(); + initializeUseNormalProxyPref(); + initializeEditTextPreferences(); + initializeProxyTypePreference(); + + if (mUseTor.isChecked()) disableNormalProxyPrefs(); + else if (mUseNormalProxy.isChecked()) disableUseTorPrefs(); + } + + private void initializeUseTorPref() { + mUseTor.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + Activity activity = mFragment != null ? mFragment.getActivity() : mActivity; + if ((Boolean)newValue) { + boolean installed = OrbotHelper.isOrbotInstalled(activity); + if (!installed) { + Log.d(Constants.TAG, "Prompting to install Tor"); + OrbotHelper.getPreferenceInstallDialogFragment().show(activity.getFragmentManager(), + "installDialog"); + // don't let the user check the box until he's installed orbot + return false; + } else { + disableNormalProxyPrefs(); + // let the enable tor box be checked + return true; + } + } + else { + // we're unchecking Tor, so enable other proxy + enableNormalProxyPrefs(); + return true; + } } - } - }); - - mProxyPort.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - try { - int port = Integer.parseInt((String) newValue); - if(port < 0 || port > 65535) { - Notify.create( - ProxyPrefsFragment.this.getActivity(), - R.string.pref_proxy_port_err_invalid, - Notify.Style.ERROR - ).show(); - return false; + }); + } + + private void initializeUseNormalProxyPref() { + mUseNormalProxy.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + if ((Boolean) newValue) { + disableUseTorPrefs(); + } else { + enableUseTorPrefs(); } - // no issues, save port - mProxyPort.setSummary("" + port); return true; - } catch (NumberFormatException e) { - Notify.create( - ProxyPrefsFragment.this.getActivity(), - R.string.pref_proxy_port_err_invalid, - Notify.Style.ERROR - ).show(); - return false; } - } - }); - } - - private void initializeProxyTypePreference() { - mProxyType.setSummary(mProxyType.getEntry()); - - mProxyType.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - CharSequence entry = mProxyType.getEntries()[mProxyType.findIndexOfValue((String) newValue)]; - mProxyType.setSummary(entry); - return true; - } - }); - } - - private void disableNormalProxyPrefs() { - mUseNormalProxy.setChecked(false); - mUseNormalProxy.setEnabled(false); - mProxyHost.setEnabled(false); - mProxyPort.setEnabled(false); - mProxyType.setEnabled(false); - } - - private void enableNormalProxyPrefs() { - mUseNormalProxy.setEnabled(true); - mProxyHost.setEnabled(true); - mProxyPort.setEnabled(true); - mProxyType.setEnabled(true); - } - - private void disableUseTorPrefs() { - mUseTor.setChecked(false); - mUseTor.setEnabled(false); - } - - private void enableUseTorPrefs() { - mUseTor.setEnabled(true); - } - } - - @TargetApi(Build.VERSION_CODES.KITKAT) - public static class ProxyPrefsFragment extends PreferenceFragment { - private CheckBoxPreference mUseTor; - private CheckBoxPreference mUseNormalProxy; - private EditTextPreference mProxyHost; - private EditTextPreference mProxyPort; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - // Load the preferences from an XML resource - addPreferencesFromResource(R.xml.proxy_prefs); - - mUseTor = (CheckBoxPreference) findPreference(Constants.Pref.USE_TOR_PROXY); - mUseNormalProxy = (CheckBoxPreference) findPreference(Constants.Pref.USE_NORMAL_PROXY); - mProxyHost = (EditTextPreference) findPreference(Constants.Pref.PROXY_HOST); - mProxyPort = (EditTextPreference) findPreference(Constants.Pref.PROXY_PORT); - - initializeUseTorPref(); - initializeUseNormalProxyPref(); - initialiseEditTextPreferences(); + }); + } - if (mUseTor.isChecked()) disableNormalProxyPrefs(); - else if (mUseNormalProxy.isChecked()) disableUseTorPrefs(); - } + private void initializeEditTextPreferences() { + mProxyHost.setSummary(mProxyHost.getText()); + mProxyPort.setSummary(mProxyPort.getText()); - private void initializeUseTorPref() { - mUseTor.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - if ((Boolean)newValue) { - OrbotHelper orbotHelper = new OrbotHelper(ProxyPrefsFragment.this.getActivity()); - boolean installed = orbotHelper.isOrbotInstalled(); - if (!installed) { - Log.d(Constants.TAG, "Prompting to install Tor"); - orbotHelper.promptToInstall(ProxyPrefsFragment.this.getActivity()); - // don't let the user check the box until he's installed orbot + mProxyHost.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + Activity activity = mFragment != null ? mFragment.getActivity() : mActivity; + if (TextUtils.isEmpty((String) newValue)) { + Notify.create( + activity, + R.string.pref_proxy_host_err_invalid, + Notify.Style.ERROR + ).show(); return false; } else { - disableNormalProxyPrefs(); - // let the enable tor box be checked + mProxyHost.setSummary((CharSequence) newValue); return true; } } - else { - // we're unchecking Tor, so enable other proxy - enableNormalProxyPrefs(); - return true; - } - } - }); - } - - private void initializeUseNormalProxyPref() { - mUseNormalProxy.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - if ((Boolean) newValue) { - disableUseTorPrefs(); - } else { - enableUseTorPrefs(); - } - return true; - } - }); - } + }); - private void initialiseEditTextPreferences() { - mProxyHost.setSummary(mProxyHost.getText()); - mProxyPort.setSummary(mProxyPort.getText()); - - mProxyHost.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - if (newValue.equals("")) { - Notify.create( - ProxyPrefsFragment.this.getActivity(), - R.string.pref_proxy_host_err_invalid, - Notify.Style.ERROR - ).show(); - return false; - } else { - mProxyHost.setSummary((CharSequence) newValue); - return true; - } - } - }); - - mProxyPort.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - try { - int port = Integer.parseInt((String) newValue); - if(port < 0 || port > 65535) { + mProxyPort.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + Activity activity = mFragment != null ? mFragment.getActivity() : mActivity; + try { + int port = Integer.parseInt((String) newValue); + if(port < 0 || port > 65535) { + Notify.create( + activity, + R.string.pref_proxy_port_err_invalid, + Notify.Style.ERROR + ).show(); + return false; + } + // no issues, save port + mProxyPort.setSummary("" + port); + return true; + } catch (NumberFormatException e) { Notify.create( - ProxyPrefsFragment.this.getActivity(), + activity, R.string.pref_proxy_port_err_invalid, Notify.Style.ERROR ).show(); return false; } - // no issues, save port - mProxyPort.setSummary("" + port); + } + }); + } + + private void initializeProxyTypePreference() { + mProxyType.setSummary(mProxyType.getEntry()); + + mProxyType.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + CharSequence entry = mProxyType.getEntries()[mProxyType.findIndexOfValue((String) newValue)]; + mProxyType.setSummary(entry); return true; - } catch (NumberFormatException e) { - Notify.create( - ProxyPrefsFragment.this.getActivity(), - R.string.pref_proxy_port_err_invalid, - Notify.Style.ERROR - ).show(); - return false; } - } - }); - } + }); + } - private void disableNormalProxyPrefs() { - mUseNormalProxy.setChecked(false); - mUseNormalProxy.setEnabled(false); - mProxyHost.setEnabled(false); - mProxyPort.setEnabled(false); - } + private void disableNormalProxyPrefs() { + mUseNormalProxy.setChecked(false); + mUseNormalProxy.setEnabled(false); + mProxyHost.setEnabled(false); + mProxyPort.setEnabled(false); + mProxyType.setEnabled(false); + } - private void enableNormalProxyPrefs() { - mUseNormalProxy.setEnabled(true); - mProxyHost.setEnabled(true); - mProxyPort.setEnabled(true); - } + private void enableNormalProxyPrefs() { + mUseNormalProxy.setEnabled(true); + mProxyHost.setEnabled(true); + mProxyPort.setEnabled(true); + mProxyType.setEnabled(true); + } - private void disableUseTorPrefs() { - mUseTor.setChecked(false); - mUseTor.setEnabled(false); - } + private void disableUseTorPrefs() { + mUseTor.setChecked(false); + mUseTor.setEnabled(false); + } - private void enableUseTorPrefs() { - mUseTor.setEnabled(true); + private void enableUseTorPrefs() { + mUseTor.setEnabled(true); + } } + } + @TargetApi(Build.VERSION_CODES.KITKAT) protected boolean isValidFragment(String fragmentName) { return AdvancedPrefsFragment.class.getName().equals(fragmentName) || CloudSearchPrefsFragment.class.getName().equals(fragmentName) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/InstallDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/InstallDialogFragment.java new file mode 100644 index 000000000..01ff4715d --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/InstallDialogFragment.java @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2012-2014 Dominik Schürmann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.sufficientlysecure.keychain.ui.dialog; + +import android.app.Activity; +import android.app.Dialog; +import android.content.DialogInterface; +import android.content.Intent; +import android.net.Uri; +import android.os.Bundle; +import android.os.Message; +import android.os.Messenger; +import android.os.RemoteException; +import android.support.v4.app.DialogFragment; + +import org.sufficientlysecure.keychain.Constants; +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.util.Log; + +public class InstallDialogFragment extends DialogFragment { + private static final String ARG_MESSENGER = "messenger"; + private static final String ARG_TITLE = "title"; + private static final String ARG_MESSAGE = "message"; + private static final String ARG_MIDDLE_BUTTON = "middleButton"; + private static final String ARG_INSTALL_PATH = "installPath"; + private static final String ARG_USE_MIDDLE_BUTTON = "useMiddleButton"; + + public static final String PLAY_STORE_PATH = "market://search?q=pname:"; + + public static final int MESSAGE_MIDDLE_CLICKED = 1; + + /** + * Creates a dialog which prompts the user to install an application. Consists of two default buttons ("Install" + * and "Cancel") and an optional third button. Callbacks are provided only for the middle button, if set. + * + * @param messenger required only for callback from middle button if it has been set + * @param title + * @param message content of dialog + * @param packageToInstall package name of application to install + * @param middleButton if not null, adds a third button to the app with a call back + * @return The dialog to display + */ + public static InstallDialogFragment newInstance(Messenger messenger, int title, int message, + String packageToInstall, int middleButton, boolean useMiddleButton) { + InstallDialogFragment frag = new InstallDialogFragment(); + Bundle args = new Bundle(); + args.putParcelable(ARG_MESSENGER, messenger); + + args.putInt(ARG_TITLE, title); + args.putInt(ARG_MESSAGE, message); + args.putInt(ARG_MIDDLE_BUTTON, middleButton); + args.putString(ARG_INSTALL_PATH, PLAY_STORE_PATH + packageToInstall); + args.putBoolean(ARG_USE_MIDDLE_BUTTON, useMiddleButton); + + frag.setArguments(args); + + return frag; + } + + /** + * To create a DialogFragment with only two buttons + * + * @param title + * @param message + * @param packageToInstall + * @return + */ + public static InstallDialogFragment newInstance(int title, int message, + String packageToInstall) { + return newInstance(null, title, message, packageToInstall, -1, false); + } + + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + final Activity activity = getActivity(); + + final Messenger messenger = getArguments().getParcelable(ARG_MESSENGER); + + final int title = getArguments().getInt(ARG_TITLE); + final int message = getArguments().getInt(ARG_MESSAGE); + final int middleButton = getArguments().getInt(ARG_MIDDLE_BUTTON); + final String installPath = getArguments().getString(ARG_INSTALL_PATH); + final boolean useMiddleButton = getArguments().getBoolean(ARG_USE_MIDDLE_BUTTON); + + CustomAlertDialogBuilder builder = new CustomAlertDialogBuilder(activity); + + builder.setTitle(title).setMessage(message); + + builder.setNegativeButton(R.string.orbot_install_dialog_cancel, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + + } + }); + + builder.setPositiveButton(R.string.orbot_install_dialog_install, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + Uri uri = Uri.parse(installPath); + Intent intent = new Intent(Intent.ACTION_VIEW, uri); + activity.startActivity(intent); + } + } + ); + + if (useMiddleButton) { + builder.setNeutralButton(middleButton, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + Message msg = new Message(); + msg.what=MESSAGE_MIDDLE_CLICKED; + try { + messenger.send(msg); + } catch (RemoteException e) { + Log.w(Constants.TAG, "Exception sending message, Is handler present?", e); + } catch (NullPointerException e) { + Log.w(Constants.TAG, "Messenger is null!", e); + } + } + } + ); + } + + return builder.show(); + } +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/OrbotStartDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/OrbotStartDialogFragment.java new file mode 100644 index 000000000..e9092b14a --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/OrbotStartDialogFragment.java @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2012-2014 Dominik Schürmann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +package org.sufficientlysecure.keychain.ui.dialog; + +import android.app.Dialog; +import android.content.DialogInterface; +import android.os.Bundle; +import android.os.Message; +import android.os.Messenger; +import android.os.RemoteException; +import android.support.v4.app.DialogFragment; +import org.sufficientlysecure.keychain.Constants; +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.util.Log; +import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; + +/** + * displays a dialog asking the user to enable Tor + */ +public class OrbotStartDialogFragment extends DialogFragment { + private static final String ARG_MESSENGER = "messenger"; + private static final String ARG_TITLE = "title"; + private static final String ARG_MESSAGE = "message"; + private static final String ARG_MIDDLE_BUTTON = "middleButton"; + + public static final int MESSAGE_MIDDLE_BUTTON = 1; + + public static OrbotStartDialogFragment newInstance(Messenger messenger, int title, int message, int middleButton) { + Bundle args = new Bundle(); + args.putParcelable(ARG_MESSENGER, messenger); + args.putInt(ARG_TITLE, title); + args.putInt(ARG_MESSAGE, message); + args.putInt(ARG_MIDDLE_BUTTON, middleButton); + + OrbotStartDialogFragment fragment = new OrbotStartDialogFragment(); + fragment.setArguments(args); + + return fragment; + } + + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + + final Messenger messenger = getArguments().getParcelable(ARG_MESSENGER); + int title = getArguments().getInt(ARG_TITLE); + final int message = getArguments().getInt(ARG_MESSAGE); + int middleButton = getArguments().getInt(ARG_MIDDLE_BUTTON); + + CustomAlertDialogBuilder builder = new CustomAlertDialogBuilder(getActivity()); + builder.setTitle(title).setMessage(message); + + builder.setNegativeButton(R.string.orbot_start_dialog_cancel, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + + } + }); + + builder.setPositiveButton(R.string.orbot_start_dialog_start, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + getActivity().startActivityForResult(OrbotHelper.getOrbotStartIntent(), 1); + } + }); + + builder.setNeutralButton(middleButton, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + Message msg = new Message(); + msg.what = MESSAGE_MIDDLE_BUTTON; + try { + messenger.send(msg); + } catch (RemoteException e) { + Log.w(Constants.TAG, "Exception sending message, Is handler present?", e); + } catch (NullPointerException e) { + Log.w(Constants.TAG, "Messenger is null!", e); + } + } + }); + + return builder.show(); + } +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PreferenceInstallDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PreferenceInstallDialogFragment.java new file mode 100644 index 000000000..8236ff9d7 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PreferenceInstallDialogFragment.java @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2012-2014 Dominik Schürmann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.sufficientlysecure.keychain.ui.dialog; + +import android.app.Activity; +import android.app.Dialog; +import android.content.DialogInterface; +import android.content.Intent; +import android.net.Uri; +import android.os.Bundle; +import android.os.Message; +import android.os.Messenger; +import android.os.RemoteException; +import android.app.DialogFragment; +import org.sufficientlysecure.keychain.Constants; +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.util.Log; + +public class PreferenceInstallDialogFragment extends DialogFragment { + private static final String ARG_MESSENGER = "messenger"; + private static final String ARG_TITLE = "title"; + private static final String ARG_MESSAGE = "message"; + private static final String ARG_MIDDLE_BUTTON = "middleButton"; + private static final String ARG_INSTALL_PATH = "installPath"; + private static final String ARG_USE_MIDDLE_BUTTON = "installPath"; + + public static final String PLAY_STORE_PATH = "market://search?q=pname:"; + + public static final int MESSAGE_MIDDLE_CLICKED = 1; + + /** + * Creates a dialog which prompts the user to install an application. Consists of two default buttons ("Install" + * and "Cancel") and an optional third button. Callbacks are provided only for the middle button, if set. + * + * @param messenger required only for callback from middle button if it has been set + * @param title + * @param message content of dialog + * @param packageToInstall package name of application to install + * @param middleButton if not null, adds a third button to the app with a call back + * @return The dialog to display + */ + public static PreferenceInstallDialogFragment newInstance(Messenger messenger, int title, int message, + String packageToInstall, int middleButton, boolean useMiddleButton) { + PreferenceInstallDialogFragment frag = new PreferenceInstallDialogFragment(); + Bundle args = new Bundle(); + args.putParcelable(ARG_MESSENGER, messenger); + + args.putInt(ARG_TITLE, title); + args.putInt(ARG_MESSAGE, message); + args.putInt(ARG_MIDDLE_BUTTON, middleButton); + args.putString(ARG_INSTALL_PATH, PLAY_STORE_PATH + packageToInstall); + args.putBoolean(ARG_USE_MIDDLE_BUTTON, useMiddleButton); + + frag.setArguments(args); + + return frag; + } + + /** + * To create a DialogFragment with only two buttons + * + * @param title + * @param message + * @param packageToInstall + * @return + */ + public static PreferenceInstallDialogFragment newInstance(int title, int message, + String packageToInstall) { + return newInstance(null, title, message, packageToInstall, -1, false); + } + + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + final Activity activity = getActivity(); + + final Messenger messenger = getArguments().getParcelable(ARG_MESSENGER); + + final String title = getArguments().getString(ARG_TITLE); + final String message = getArguments().getString(ARG_MESSAGE); + final String installPath = getArguments().getString(ARG_INSTALL_PATH); + final String middleButton = getArguments().getString(ARG_MIDDLE_BUTTON); + final boolean useMiddleButton = getArguments().getBoolean(ARG_USE_MIDDLE_BUTTON); + + CustomAlertDialogBuilder builder = new CustomAlertDialogBuilder(activity); + + builder.setTitle(title).setMessage(message); + + builder.setNegativeButton(R.string.orbot_install_dialog_cancel, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + + } + }); + + builder.setPositiveButton(R.string.orbot_install_dialog_install, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + Uri uri = Uri.parse(installPath); + Intent intent = new Intent(Intent.ACTION_VIEW, uri); + activity.startActivity(intent); + } + } + ); + + if (useMiddleButton) { + builder.setNeutralButton(middleButton, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + Message msg = new Message(); + msg.what=MESSAGE_MIDDLE_CLICKED; + try { + messenger.send(msg); + } catch (RemoteException e) { + Log.w(Constants.TAG, "Exception sending message, Is handler present?", e); + } catch (NullPointerException e) { + Log.w(Constants.TAG, "Messenger is null!", e); + } + } + } + ); + } + + return builder.show(); + } +} -- cgit v1.2.3 From 79fc0f97eafd6a70bd40bb8cddd50de52ef84f7c Mon Sep 17 00:00:00 2001 From: Adithya Abraham Philip Date: Thu, 11 Jun 2015 05:33:31 +0530 Subject: added proxy to all import operations using KeychainService --- .../keychain/ui/CreateYubiKeyImportFragment.java | 18 +++++++++++-- .../keychain/ui/DecryptFragment.java | 18 +++++++++++-- .../keychain/ui/ImportKeysProxyActivity.java | 30 +++++++++++++++------- .../keychain/ui/KeyListFragment.java | 5 ++-- .../keychain/ui/UploadKeyActivity.java | 16 +++++++++++- .../keychain/ui/ViewKeyActivity.java | 6 +---- 6 files changed, 72 insertions(+), 21 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java index 945d42a24..4d85255ca 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java @@ -41,7 +41,9 @@ import org.sufficientlysecure.keychain.ui.CreateKeyActivity.FragAction; import org.sufficientlysecure.keychain.ui.CreateKeyActivity.NfcListenerFragment; import org.sufficientlysecure.keychain.ui.base.CryptoOperationFragment; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; +import org.sufficientlysecure.keychain.util.ParcelableProxy; import org.sufficientlysecure.keychain.util.Preferences; +import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; public class CreateYubiKeyImportFragment @@ -120,7 +122,19 @@ public class CreateYubiKeyImportFragment mNextButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - importKey(); + + final Preferences.ProxyPrefs proxyPrefs = Preferences.getPreferences(getActivity()).getProxyPrefs(); + Runnable ignoreTor = new Runnable() { + @Override + public void run() { + importKey(new ParcelableProxy(null, -1, null)); + } + }; + + if(OrbotHelper.isOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, proxyPrefs, + getActivity())) { + importKey(proxyPrefs.parcelableProxy); + } } }); } @@ -176,7 +190,7 @@ public class CreateYubiKeyImportFragment Preferences.getPreferences(getActivity()).getCloudSearchPrefs()), null); } - public void importKey() { + public void importKey(ParcelableProxy parcelableProxy) { ArrayList keyList = new ArrayList<>(); keyList.add(new ParcelableKeyRing(mNfcFingerprint, null, null)); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java index 4eb8cd5e8..adb15111d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java @@ -58,7 +58,9 @@ import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils.State; import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.ui.util.Notify.Style; +import org.sufficientlysecure.keychain.util.ParcelableProxy; import org.sufficientlysecure.keychain.util.Preferences; +import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; public abstract class DecryptFragment extends Fragment implements LoaderManager.LoaderCallbacks { @@ -136,7 +138,7 @@ public abstract class DecryptFragment extends Fragment implements LoaderManager. } } - private void lookupUnknownKey(long unknownKeyId) { + private void lookupUnknownKey(long unknownKeyId, ParcelableProxy parcelableProxy) { final ArrayList keyList; final String keyserver; @@ -427,7 +429,19 @@ public abstract class DecryptFragment extends Fragment implements LoaderManager. mSignatureLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - lookupUnknownKey(signatureKeyId); + final Preferences.ProxyPrefs proxyPrefs = Preferences.getPreferences(getActivity()) + .getProxyPrefs(); + Runnable ignoreTor = new Runnable() { + @Override + public void run() { + lookupUnknownKey(signatureKeyId, new ParcelableProxy(null, -1, null)); + } + }; + + if (OrbotHelper.isOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, proxyPrefs, + getActivity())) { + lookupUnknownKey(signatureKeyId, proxyPrefs.parcelableProxy); + } } }); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysProxyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysProxyActivity.java index da713d0d8..1a03b8102 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysProxyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysProxyActivity.java @@ -44,7 +44,9 @@ import org.sufficientlysecure.keychain.service.ImportKeyringParcel; import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper; import org.sufficientlysecure.keychain.util.IntentIntegratorSupportV4; import org.sufficientlysecure.keychain.util.Log; +import org.sufficientlysecure.keychain.util.ParcelableProxy; import org.sufficientlysecure.keychain.util.Preferences; +import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; import java.util.ArrayList; import java.util.Locale; @@ -157,8 +159,7 @@ public class ImportKeysProxyActivity extends FragmentActivity returnResult(intent); return; } - - String fingerprint = uri.getEncodedSchemeSpecificPart().toLowerCase(Locale.ENGLISH); + final String fingerprint = uri.getEncodedSchemeSpecificPart().toLowerCase(Locale.ENGLISH); if (!fingerprint.matches("[a-fA-F0-9]{40}")) { SingletonResult result = new SingletonResult( SingletonResult.RESULT_ERROR, LogType.MSG_WRONG_QR_CODE_FP); @@ -194,23 +195,23 @@ public class ImportKeysProxyActivity extends FragmentActivity } } - public void importKeys(byte[] keyringData) { + public void importKeys(byte[] keyringData, ParcelableProxy parcelableProxy) { ParcelableKeyRing keyEntry = new ParcelableKeyRing(keyringData); ArrayList selectedEntries = new ArrayList<>(); selectedEntries.add(keyEntry); - startImportService(selectedEntries); + startImportService(selectedEntries, parcelableProxy); } - public void importKeys(String fingerprint) { + public void importKeys(String fingerprint, ParcelableProxy parcelableProxy) { ParcelableKeyRing keyEntry = new ParcelableKeyRing(fingerprint, null, null); ArrayList selectedEntries = new ArrayList<>(); selectedEntries.add(keyEntry); - startImportService(selectedEntries); + startImportService(selectedEntries, parcelableProxy); } - private void startImportService(ArrayList keyRings) { + private void startImportService(ArrayList keyRings, ParcelableProxy parcelableProxy) { // search config { @@ -273,8 +274,19 @@ public class ImportKeysProxyActivity extends FragmentActivity // only one message sent during the beam NdefMessage msg = (NdefMessage) rawMsgs[0]; // record 0 contains the MIME type, record 1 is the AAR, if present - byte[] receivedKeyringBytes = msg.getRecords()[0].getPayload(); - importKeys(receivedKeyringBytes); + final byte[] receivedKeyringBytes = msg.getRecords()[0].getPayload(); + final Preferences.ProxyPrefs proxyPrefs = Preferences.getPreferences(this) + .getProxyPrefs(); + Runnable ignoreTor = new Runnable() { + @Override + public void run() { + importKeys(receivedKeyringBytes, new ParcelableProxy(null, -1, null)); + } + }; + + if (OrbotHelper.isOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, proxyPrefs, this)) { + importKeys(receivedKeyringBytes, proxyPrefs.parcelableProxy); + } } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java index e038cf948..76ae147a2 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java @@ -71,16 +71,17 @@ import org.sufficientlysecure.keychain.ui.dialog.DeleteKeyDialogFragment; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.ui.adapter.KeyAdapter; import org.sufficientlysecure.keychain.ui.util.Notify; -import org.sufficientlysecure.keychain.ui.util.Notify.Style; import org.sufficientlysecure.keychain.util.ExportHelper; import org.sufficientlysecure.keychain.util.FabContainer; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Preferences; +import org.sufficientlysecure.keychain.ui.util.Notify.Style; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; +import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; import se.emilsjolander.stickylistheaders.StickyListHeadersAdapter; import se.emilsjolander.stickylistheaders.StickyListHeadersListView; @@ -562,7 +563,7 @@ public class KeyListFragment extends LoaderFragment startActivityForResult(intent, REQUEST_ACTION); } - private void updateAllKeys() { + private void updateAllKeys(ParcelableProxy parcelableProxy) { Activity activity = getActivity(); if (activity == null) { return; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/UploadKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/UploadKeyActivity.java index 8b49f3b96..ee37b4b98 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/UploadKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/UploadKeyActivity.java @@ -37,7 +37,9 @@ import org.sufficientlysecure.keychain.service.ExportKeyringParcel; import org.sufficientlysecure.keychain.ui.base.BaseActivity; import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper; import org.sufficientlysecure.keychain.util.Log; +import org.sufficientlysecure.keychain.util.ParcelableProxy; import org.sufficientlysecure.keychain.util.Preferences; +import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; /** * Sends the selected public key to a keyserver @@ -76,7 +78,19 @@ public class UploadKeyActivity extends BaseActivity mUploadButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - uploadKey(); + final Preferences.ProxyPrefs proxyPrefs = Preferences.getPreferences(UploadKeyActivity.this) + .getProxyPrefs(); + Runnable ignoreTor = new Runnable() { + @Override + public void run() { + uploadKey(proxyPrefs.parcelableProxy); + } + }; + + if (OrbotHelper.isOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, proxyPrefs, + UploadKeyActivity.this)) { + uploadKey(proxyPrefs.parcelableProxy); + } } }); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java index 27832b665..da00748e4 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java @@ -53,6 +53,7 @@ import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast; import com.getbase.floatingactionbutton.FloatingActionButton; +import edu.cmu.cylab.starslinger.exchange.ExchangeActivity; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing; @@ -80,11 +81,6 @@ import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.ui.util.Notify.ActionListener; import org.sufficientlysecure.keychain.ui.util.Notify.Style; import org.sufficientlysecure.keychain.ui.util.QrCodeUtils; -import org.sufficientlysecure.keychain.util.ContactHelper; -import org.sufficientlysecure.keychain.util.ExportHelper; -import org.sufficientlysecure.keychain.util.Log; -import org.sufficientlysecure.keychain.util.NfcHelper; -import org.sufficientlysecure.keychain.util.Preferences; import java.io.IOException; import java.util.ArrayList; -- cgit v1.2.3 From 389fd7d46dcf9e2496fddfd785665a7381ecfca5 Mon Sep 17 00:00:00 2001 From: Adithya Abraham Philip Date: Thu, 11 Jun 2015 05:42:10 +0530 Subject: modify ImportKeysActivity to match new pattern --- .../keychain/ui/ImportKeysActivity.java | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java index b41ca58b4..4b6af6072 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java @@ -357,30 +357,16 @@ public class ImportKeysActivity extends BaseNfcActivity if (loaderState instanceof ImportKeysListFragment.CloudLoaderState) { // do the tor check // this handle will set tor to be ignored whenever a message is received - Handler ignoreTorHandler = new Handler() { + Runnable ignoreTor = new Runnable() { @Override - public void handleMessage(Message msg) { + public void run() { // disables Tor until Activity is recreated mProxyPrefs = new Preferences.ProxyPrefs(false, false, null, -1, null); mListFragment.loadNew(loaderState, mProxyPrefs.parcelableProxy); } }; - - if(mProxyPrefs.torEnabled && !OrbotHelper.isOrbotInstalled(this)) { - - OrbotHelper.getInstallDialogFragmentWithThirdButton( - new Messenger(ignoreTorHandler), - R.string.orbot_install_dialog_ignore_tor - ).show(getSupportFragmentManager(), "orbotInstallDialog"); - - return; - } - - if(mProxyPrefs.torEnabled && !OrbotHelper.isOrbotRunning()) { - OrbotHelper.getOrbotStartDialogFragment(new Messenger(ignoreTorHandler), - R.string.orbot_install_dialog_ignore_tor) - .show(getSupportFragmentManager(), "orbotStartDialog"); - return; + if (OrbotHelper.isOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, mProxyPrefs, this)) { + mListFragment.loadNew(loaderState, mProxyPrefs.parcelableProxy); } } -- cgit v1.2.3 From 592b1285963a90e5b4e47022c5d7dc29c7b951d9 Mon Sep 17 00:00:00 2001 From: Adithya Abraham Philip Date: Thu, 11 Jun 2015 05:58:37 +0530 Subject: added proxy support to keyserver verification --- .../keychain/ui/dialog/AddEditKeyserverDialogFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/AddEditKeyserverDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/AddEditKeyserverDialogFragment.java index 7377c4060..056d82fd3 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/AddEditKeyserverDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/AddEditKeyserverDialogFragment.java @@ -223,7 +223,7 @@ public class AddEditKeyserverDialogFragment extends DialogFragment implements On String keyserverUrl = mKeyserverEditText.getText().toString(); if (mVerifyKeyserverCheckBox.isChecked()) { // TODO: PHILIP Implement proxy - verifyConnection(keyserverUrl, null); + verifyConnection(keyserverUrl); } else { dismiss(); // return unverified keyserver back to activity -- cgit v1.2.3 From ec8c57b7803cf2f4435778cc455d0acc30482c24 Mon Sep 17 00:00:00 2001 From: Adithya Abraham Philip Date: Thu, 11 Jun 2015 08:24:33 +0530 Subject: added proxy support to KeybaseLib --- .../keychain/ui/ImportKeysActivity.java | 5 ++-- .../keychain/ui/ViewKeyTrustFragment.java | 28 +++++++++++++++++++--- 2 files changed, 27 insertions(+), 6 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java index 4b6af6072..b61e94c6d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java @@ -20,7 +20,6 @@ package org.sufficientlysecure.keychain.ui; import android.content.Intent; import android.net.Uri; import android.os.Bundle; -import android.os.Handler; import android.os.Message; import android.support.v4.app.Fragment; import android.view.View; @@ -368,9 +367,9 @@ public class ImportKeysActivity extends BaseNfcActivity if (OrbotHelper.isOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, mProxyPrefs, this)) { mListFragment.loadNew(loaderState, mProxyPrefs.parcelableProxy); } + } else if (loaderState instanceof ImportKeysListFragment.BytesLoaderState) { // must always be true + mListFragment.loadNew(loaderState, mProxyPrefs.parcelableProxy); } - - mListFragment.loadNew(loaderState, mProxyPrefs.parcelableProxy); } private void handleMessage(Message message) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyTrustFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyTrustFragment.java index 6052eec16..32e8b4fc1 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyTrustFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyTrustFragment.java @@ -51,7 +51,11 @@ import org.sufficientlysecure.keychain.service.KeybaseVerificationParcel; import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.util.Log; +import org.sufficientlysecure.keychain.util.ParcelableProxy; +import org.sufficientlysecure.keychain.util.Preferences; +import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; +import java.net.Proxy; import java.util.ArrayList; import java.util.Hashtable; import java.util.List; @@ -197,8 +201,21 @@ public class ViewKeyTrustFragment extends LoaderFragment implements mStartSearch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - mStartSearch.setEnabled(false); - new DescribeKey().execute(fingerprint); + final Preferences.ProxyPrefs proxyPrefs = Preferences.getPreferences(getActivity()).getProxyPrefs(); + + Runnable ignoreTor = new Runnable() { + @Override + public void run() { + mStartSearch.setEnabled(false); + new DescribeKey(proxyPrefs.parcelableProxy).execute(fingerprint); + } + }; + + if (OrbotHelper.isOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, proxyPrefs, + getActivity())) { + mStartSearch.setEnabled(false); + new DescribeKey(proxyPrefs.parcelableProxy).execute(fingerprint); + } } }); } @@ -229,6 +246,11 @@ public class ViewKeyTrustFragment extends LoaderFragment implements // look for evidence from keybase in the background, make tabular version of result // private class DescribeKey extends AsyncTask { + ParcelableProxy mParcelableProxy; + + public DescribeKey(ParcelableProxy parcelableProxy) { + mParcelableProxy = parcelableProxy; + } @Override protected ResultPage doInBackground(String... args) { @@ -237,7 +259,7 @@ public class ViewKeyTrustFragment extends LoaderFragment implements final ArrayList proofList = new ArrayList(); final Hashtable> proofs = new Hashtable>(); try { - User keybaseUser = User.findByFingerprint(fingerprint); + User keybaseUser = User.findByFingerprint(fingerprint, mParcelableProxy.getProxy()); for (Proof proof : keybaseUser.getProofs()) { Integer proofType = proof.getType(); appendIfOK(proofs, proofType, proof); -- cgit v1.2.3 From f8da3d784b5f314f8ab58deab7c0a496dc8b11f3 Mon Sep 17 00:00:00 2001 From: Adithya Abraham Philip Date: Fri, 12 Jun 2015 23:06:35 +0530 Subject: added keyserver/proxy support to certify operation --- .../java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java index 891c2268c..6c57074a7 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java @@ -311,6 +311,11 @@ public class CertifyKeyFragment CertifyActionsParcel actionsParcel = new CertifyActionsParcel(selectedKeyId); actionsParcel.mCertifyActions.addAll(certifyActions); + if (mUploadKeyCheckbox.isChecked()) { + actionsParcel.keyServerUri = Preferences.getPreferences(getActivity()).getPreferredKeyserver(); + actionsParcel.parcelableProxy = mProxyPrefs.parcelableProxy; + } + // cached for next cryptoOperation loop cacheActionsParcel(actionsParcel); -- cgit v1.2.3 From 2402c6d3c72b19b8eded017ff3fbeb83c30ae0a8 Mon Sep 17 00:00:00 2001 From: Adithya Abraham Philip Date: Tue, 16 Jun 2015 14:36:18 +0530 Subject: ensuring code style is preserved --- .../keychain/ui/CreateYubiKeyImportFragment.java | 2 +- .../keychain/ui/ImportKeysActivity.java | 4 ++-- .../keychain/ui/KeyListFragment.java | 18 ++++++++--------- .../keychain/ui/SettingsActivity.java | 12 +++++------ .../keychain/ui/ViewKeyActivity.java | 23 ++++++++++++++-------- .../keychain/ui/ViewKeyTrustFragment.java | 4 ++-- .../ui/adapter/ImportKeysListCloudLoader.java | 1 - .../ui/dialog/AddEditKeyserverDialogFragment.java | 3 +-- .../keychain/ui/dialog/InstallDialogFragment.java | 11 ++++++----- .../ui/dialog/OrbotStartDialogFragment.java | 1 + .../ui/dialog/PreferenceInstallDialogFragment.java | 14 +++++++------ 11 files changed, 49 insertions(+), 44 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java index 4d85255ca..39dea6f0d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java @@ -131,7 +131,7 @@ public class CreateYubiKeyImportFragment } }; - if(OrbotHelper.isOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, proxyPrefs, + if (OrbotHelper.isOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, proxyPrefs, getActivity())) { importKey(proxyPrefs.parcelableProxy); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java index b61e94c6d..e2b90056d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java @@ -46,7 +46,6 @@ import org.sufficientlysecure.keychain.util.Preferences; import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; import java.io.IOException; -import java.net.Proxy; import java.util.ArrayList; public class ImportKeysActivity extends BaseNfcActivity @@ -322,7 +321,8 @@ public class ImportKeysActivity extends BaseNfcActivity * specified in user preferences */ - private void startCloudFragment(Bundle savedInstanceState, String query, boolean disableQueryEdit, String keyserver) { + private void startCloudFragment(Bundle savedInstanceState, String query, boolean disableQueryEdit, String + keyserver) { // However, if we're being restored from a previous state, // then we don't need to do anything and should return or else // we could end up with overlapping fragments. diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java index 76ae147a2..da181711e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java @@ -51,6 +51,8 @@ import android.widget.TextView; import com.getbase.floatingactionbutton.FloatingActionButton; import com.getbase.floatingactionbutton.FloatingActionsMenu; +import se.emilsjolander.stickylistheaders.StickyListHeadersAdapter; +import se.emilsjolander.stickylistheaders.StickyListHeadersListView; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; @@ -81,10 +83,8 @@ import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; -import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; -import se.emilsjolander.stickylistheaders.StickyListHeadersAdapter; -import se.emilsjolander.stickylistheaders.StickyListHeadersListView; - +/** + * Public key list with sticky list headers. It does _not_ exte /** * Public key list with sticky list headers. It does _not_ extend ListFragment because it uses * StickyListHeaders library which does not extend upon ListView. @@ -472,15 +472,13 @@ public class KeyListFragment extends LoaderFragment return true; case R.id.menu_key_list_export: - mExportHelper.showExportKeysDialog(null, Constants.Path.APP_DIR_FILE, true); + ); return true; - case R.id.menu_key_list_update_all_keys: - updateAllKeys(); - return true; + case R.id.menu_key_list_debug +_cons return true; - case R.id.menu_key_list_debug_cons: - consolidate(); + consolidate(case R.id.menu_key_list_debug_cons:); return true; case R.id.menu_key_list_debug_read: diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java index 6605995eb..1b8d71d23 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java @@ -245,7 +245,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity { } public Preference automaticallyFindPreference(String key) { - if(mFragment != null) { + if (mFragment != null) { return mFragment.findPreference(key); } else { return mActivity.findPreference(key); @@ -259,8 +259,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity { Preferences.setPreferenceManagerFileAndMode(mFragment.getPreferenceManager()); // Load the preferences from an XML resource mFragment.addPreferencesFromResource(R.xml.proxy_prefs); - } - else { + } else { Preferences.setPreferenceManagerFileAndMode(mActivity.getPreferenceManager()); // Load the preferences from an XML resource mActivity.addPreferencesFromResource(R.xml.proxy_prefs); @@ -285,7 +284,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Activity activity = mFragment != null ? mFragment.getActivity() : mActivity; - if ((Boolean)newValue) { + if ((Boolean) newValue) { boolean installed = OrbotHelper.isOrbotInstalled(activity); if (!installed) { Log.d(Constants.TAG, "Prompting to install Tor"); @@ -298,8 +297,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity { // let the enable tor box be checked return true; } - } - else { + } else { // we're unchecking Tor, so enable other proxy enableNormalProxyPrefs(); return true; @@ -350,7 +348,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity { Activity activity = mFragment != null ? mFragment.getActivity() : mActivity; try { int port = Integer.parseInt((String) newValue); - if(port < 0 || port > 65535) { + if (port < 0 || port > 65535) { Notify.create( activity, R.string.pref_proxy_port_err_invalid, diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java index da00748e4..ce8935bce 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java @@ -53,7 +53,6 @@ import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast; import com.getbase.floatingactionbutton.FloatingActionButton; -import edu.cmu.cylab.starslinger.exchange.ExchangeActivity; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing; @@ -81,6 +80,13 @@ import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.ui.util.Notify.ActionListener; import org.sufficientlysecure.keychain.ui.util.Notify.Style; import org.sufficientlysecure.keychain.ui.util.QrCodeUtils; +import org.sufficientlysecure.keychain.util.ContactHelper; +import org.sufficientlysecure.keychain.util.ExportHelper; +import org.sufficientlysecure.keychain.util.Log; +import org.sufficientlysecure.keychain.util.NfcHelper; +import org.sufficientlysecure.keychain.util.ParcelableProxy; +import org.sufficientlysecure.keychain.util.Preferences; +import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; import java.io.IOException; import java.util.ArrayList; @@ -460,11 +466,11 @@ public class ViewKeyActivity extends BaseNfcActivity implements HashMap data = providerHelper.getGenericData( baseUri, - new String[] {KeychainContract.Keys.MASTER_KEY_ID, KeychainContract.KeyRings.HAS_SECRET}, - new int[] {ProviderHelper.FIELD_TYPE_INTEGER, ProviderHelper.FIELD_TYPE_INTEGER}); + new String[]{KeychainContract.Keys.MASTER_KEY_ID, KeychainContract.KeyRings.HAS_SECRET}, + new int[]{ProviderHelper.FIELD_TYPE_INTEGER, ProviderHelper.FIELD_TYPE_INTEGER}); exportHelper.showExportKeysDialog( - new long[] {(Long) data.get(KeychainContract.KeyRings.MASTER_KEY_ID)}, + new long[]{(Long) data.get(KeychainContract.KeyRings.MASTER_KEY_ID)}, Constants.Path.APP_DIR_FILE, ((Long) data.get(KeychainContract.KeyRings.HAS_SECRET) != 0) ); } catch (ProviderHelper.NotFoundException e) { @@ -488,7 +494,7 @@ public class ViewKeyActivity extends BaseNfcActivity implements // Create a new Messenger for the communication back Messenger messenger = new Messenger(returnHandler); DeleteKeyDialogFragment deleteKeyDialog = DeleteKeyDialogFragment.newInstance(messenger, - new long[] {mMasterKeyId}); + new long[]{mMasterKeyId}); deleteKeyDialog.show(getSupportFragmentManager(), "deleteKeyDialog"); } @@ -632,7 +638,7 @@ public class ViewKeyActivity extends BaseNfcActivity implements long keyId = new ProviderHelper(this) .getCachedPublicKeyRing(dataUri) .extractOrGetMasterKeyId(); - long[] encryptionKeyIds = new long[] {keyId}; + long[] encryptionKeyIds = new long[]{keyId}; Intent intent; if (text) { intent = new Intent(this, EncryptTextActivity.class); @@ -738,7 +744,7 @@ public class ViewKeyActivity extends BaseNfcActivity implements // These are the rows that we will retrieve. - static final String[] PROJECTION = new String[] { + static final String[] PROJECTION = new String[]{ KeychainContract.KeyRings._ID, KeychainContract.KeyRings.MASTER_KEY_ID, KeychainContract.KeyRings.USER_ID, @@ -826,7 +832,8 @@ public class ViewKeyActivity extends BaseNfcActivity implements AsyncTask photoTask = new AsyncTask() { protected Bitmap doInBackground(Long... mMasterKeyId) { - return ContactHelper.loadPhotoByMasterKeyId(getContentResolver(), mMasterKeyId[0], true); + return ContactHelper.loadPhotoByMasterKeyId(getContentResolver(), + mMasterKeyId[0], true); } protected void onPostExecute(Bitmap photo) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyTrustFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyTrustFragment.java index 32e8b4fc1..f6b580b01 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyTrustFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyTrustFragment.java @@ -55,7 +55,6 @@ import org.sufficientlysecure.keychain.util.ParcelableProxy; import org.sufficientlysecure.keychain.util.Preferences; import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; -import java.net.Proxy; import java.util.ArrayList; import java.util.Hashtable; import java.util.List; @@ -201,7 +200,8 @@ public class ViewKeyTrustFragment extends LoaderFragment implements mStartSearch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - final Preferences.ProxyPrefs proxyPrefs = Preferences.getPreferences(getActivity()).getProxyPrefs(); + final Preferences.ProxyPrefs proxyPrefs = Preferences.getPreferences(getActivity()) + .getProxyPrefs(); Runnable ignoreTor = new Runnable() { @Override diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListCloudLoader.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListCloudLoader.java index a4f8f22e0..c7f69207c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListCloudLoader.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListCloudLoader.java @@ -30,7 +30,6 @@ import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.ParcelableProxy; import org.sufficientlysecure.keychain.util.Preferences; -import java.net.Proxy; import java.util.ArrayList; public class ImportKeysListCloudLoader diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/AddEditKeyserverDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/AddEditKeyserverDialogFragment.java index 056d82fd3..e5ab3a228 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/AddEditKeyserverDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/AddEditKeyserverDialogFragment.java @@ -59,14 +59,13 @@ import org.sufficientlysecure.keychain.util.TlsHelper; import java.io.IOException; import java.net.HttpURLConnection; import java.net.MalformedURLException; +import java.net.Proxy; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import javax.net.ssl.HttpsURLConnection; import java.io.IOException; -import java.net.*; -import javax.net.ssl.HttpsURLConnection; public class AddEditKeyserverDialogFragment extends DialogFragment implements OnEditorActionListener { private static final String ARG_MESSENGER = "arg_messenger"; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/InstallDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/InstallDialogFragment.java index 01ff4715d..7b3f9ad28 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/InstallDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/InstallDialogFragment.java @@ -48,15 +48,16 @@ public class InstallDialogFragment extends DialogFragment { * Creates a dialog which prompts the user to install an application. Consists of two default buttons ("Install" * and "Cancel") and an optional third button. Callbacks are provided only for the middle button, if set. * - * @param messenger required only for callback from middle button if it has been set + * @param messenger required only for callback from middle button if it has been set * @param title - * @param message content of dialog + * @param message content of dialog * @param packageToInstall package name of application to install - * @param middleButton if not null, adds a third button to the app with a call back + * @param middleButton if not null, adds a third button to the app with a call back * @return The dialog to display */ public static InstallDialogFragment newInstance(Messenger messenger, int title, int message, - String packageToInstall, int middleButton, boolean useMiddleButton) { + String packageToInstall, int middleButton, boolean + useMiddleButton) { InstallDialogFragment frag = new InstallDialogFragment(); Bundle args = new Bundle(); args.putParcelable(ARG_MESSENGER, messenger); @@ -125,7 +126,7 @@ public class InstallDialogFragment extends DialogFragment { @Override public void onClick(DialogInterface dialog, int which) { Message msg = new Message(); - msg.what=MESSAGE_MIDDLE_CLICKED; + msg.what = MESSAGE_MIDDLE_CLICKED; try { messenger.send(msg); } catch (RemoteException e) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/OrbotStartDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/OrbotStartDialogFragment.java index e9092b14a..4736eddca 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/OrbotStartDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/OrbotStartDialogFragment.java @@ -25,6 +25,7 @@ import android.os.Message; import android.os.Messenger; import android.os.RemoteException; import android.support.v4.app.DialogFragment; + import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.util.Log; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PreferenceInstallDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PreferenceInstallDialogFragment.java index 8236ff9d7..b9b4da83a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PreferenceInstallDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PreferenceInstallDialogFragment.java @@ -27,6 +27,7 @@ import android.os.Message; import android.os.Messenger; import android.os.RemoteException; import android.app.DialogFragment; + import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.util.Log; @@ -47,15 +48,16 @@ public class PreferenceInstallDialogFragment extends DialogFragment { * Creates a dialog which prompts the user to install an application. Consists of two default buttons ("Install" * and "Cancel") and an optional third button. Callbacks are provided only for the middle button, if set. * - * @param messenger required only for callback from middle button if it has been set + * @param messenger required only for callback from middle button if it has been set * @param title - * @param message content of dialog + * @param message content of dialog * @param packageToInstall package name of application to install - * @param middleButton if not null, adds a third button to the app with a call back + * @param middleButton if not null, adds a third button to the app with a call back * @return The dialog to display */ public static PreferenceInstallDialogFragment newInstance(Messenger messenger, int title, int message, - String packageToInstall, int middleButton, boolean useMiddleButton) { + String packageToInstall, int middleButton, boolean + useMiddleButton) { PreferenceInstallDialogFragment frag = new PreferenceInstallDialogFragment(); Bundle args = new Bundle(); args.putParcelable(ARG_MESSENGER, messenger); @@ -80,7 +82,7 @@ public class PreferenceInstallDialogFragment extends DialogFragment { * @return */ public static PreferenceInstallDialogFragment newInstance(int title, int message, - String packageToInstall) { + String packageToInstall) { return newInstance(null, title, message, packageToInstall, -1, false); } @@ -125,7 +127,7 @@ public class PreferenceInstallDialogFragment extends DialogFragment { @Override public void onClick(DialogInterface dialog, int which) { Message msg = new Message(); - msg.what=MESSAGE_MIDDLE_CLICKED; + msg.what = MESSAGE_MIDDLE_CLICKED; try { messenger.send(msg); } catch (RemoteException e) { -- cgit v1.2.3 From ab5763e2fab5177a7b0c72898381cabf2706cc6c Mon Sep 17 00:00:00 2001 From: Adithya Abraham Philip Date: Tue, 16 Jun 2015 15:00:24 +0530 Subject: added proxy support to YubiKey search --- .../keychain/ui/CreateYubiKeyImportFragment.java | 32 +++++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java index 39dea6f0d..8434eafbf 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java @@ -145,7 +145,18 @@ public class CreateYubiKeyImportFragment view.findViewById(R.id.button_search).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - refreshSearch(); + final Preferences.ProxyPrefs proxyPrefs = Preferences.getPreferences(getActivity()).getProxyPrefs(); + Runnable ignoreTor = new Runnable() { + @Override + public void run() { + refreshSearch(new ParcelableProxy(null, -1, null)); + } + }; + + if (OrbotHelper.isOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, proxyPrefs, + getActivity())) { + refreshSearch(proxyPrefs.parcelableProxy); + } } }); @@ -184,10 +195,10 @@ public class CreateYubiKeyImportFragment } } - public void refreshSearch() { + public void refreshSearch(ParcelableProxy parcelableProxy) { // TODO: PHILIP implement proxy in YubiKey parts mListFragment.loadNew(new ImportKeysListFragment.CloudLoaderState("0x" + mNfcFingerprint, - Preferences.getPreferences(getActivity()).getCloudSearchPrefs()), null); + Preferences.getPreferences(getActivity()).getCloudSearchPrefs()), parcelableProxy); } public void importKey(ParcelableProxy parcelableProxy) { @@ -225,7 +236,20 @@ public class CreateYubiKeyImportFragment public void onNfcPostExecute() throws IOException { setData(); - refreshSearch(); + + Preferences.ProxyPrefs proxyPrefs = Preferences.getPreferences(getActivity()).getProxyPrefs(); + Runnable ignoreTor = new Runnable() { + @Override + public void run() { + refreshSearch(new ParcelableProxy(null, -1, null)); + } + }; + + if (OrbotHelper.isOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, proxyPrefs, + getActivity())) { + refreshSearch(proxyPrefs.parcelableProxy); + } + } @Override -- cgit v1.2.3 From bde187b9bf9bbb334a12b6b18aa843048a926dc8 Mon Sep 17 00:00:00 2001 From: Adithya Abraham Philip Date: Tue, 16 Jun 2015 15:02:04 +0530 Subject: code cleanup --- .../org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java | 2 +- .../java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java index 8434eafbf..93614db56 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java @@ -196,7 +196,7 @@ public class CreateYubiKeyImportFragment } public void refreshSearch(ParcelableProxy parcelableProxy) { - // TODO: PHILIP implement proxy in YubiKey parts + // TODO: PHILIP verify proxy implementation in YubiKey parts mListFragment.loadNew(new ImportKeysListFragment.CloudLoaderState("0x" + mNfcFingerprint, Preferences.getPreferences(getActivity()).getCloudSearchPrefs()), parcelableProxy); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java index 23368504b..55ccc3975 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java @@ -48,7 +48,6 @@ import java.io.ByteArrayInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; -import java.net.Proxy; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -187,7 +186,6 @@ public class ImportKeysListFragment extends ListFragment implements static public class CloudLoaderState extends LoaderState { Preferences.CloudSearchPrefs mCloudPrefs; String mServerQuery; - Proxy proxy; CloudLoaderState(String serverQuery, Preferences.CloudSearchPrefs cloudPrefs) { mServerQuery = serverQuery; -- cgit v1.2.3 From e909d7a4d536caa9beb8f6b7771f9a5082090546 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Wed, 17 Jun 2015 15:22:54 +0200 Subject: Fix crash on settings by adding proxy fragment to isValidFragment --- .../main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java | 1 + 1 file changed, 1 insertion(+) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java index 1b8d71d23..81e4b9eda 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java @@ -415,6 +415,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity { protected boolean isValidFragment(String fragmentName) { return AdvancedPrefsFragment.class.getName().equals(fragmentName) || CloudSearchPrefsFragment.class.getName().equals(fragmentName) + || ProxyPrefsFragment.class.getName().equals(fragmentName) || super.isValidFragment(fragmentName); } -- cgit v1.2.3 From c4198854347ae97edfc4be1517c2720eacc552f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Wed, 17 Jun 2015 15:26:43 +0200 Subject: Cleanup tor code --- .../keychain/ui/CreateYubiKeyImportFragment.java | 2 +- .../sufficientlysecure/keychain/ui/DecryptFragment.java | 2 +- .../keychain/ui/ImportKeysActivity.java | 2 +- .../keychain/ui/ImportKeysProxyActivity.java | 2 +- .../sufficientlysecure/keychain/ui/KeyListFragment.java | 9 ++++----- .../sufficientlysecure/keychain/ui/SettingsActivity.java | 2 +- .../keychain/ui/UploadKeyActivity.java | 2 +- .../sufficientlysecure/keychain/ui/ViewKeyActivity.java | 2 +- .../keychain/ui/ViewKeyTrustFragment.java | 2 +- .../ui/dialog/AddEditKeyserverDialogFragment.java | 16 ++++++++++++++-- .../keychain/ui/dialog/OrbotStartDialogFragment.java | 2 +- 11 files changed, 27 insertions(+), 16 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java index 93614db56..ec74ca7c8 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java @@ -43,7 +43,7 @@ import org.sufficientlysecure.keychain.ui.base.CryptoOperationFragment; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.util.ParcelableProxy; import org.sufficientlysecure.keychain.util.Preferences; -import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; +import org.sufficientlysecure.keychain.util.tor.OrbotHelper; public class CreateYubiKeyImportFragment diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java index adb15111d..e2cc21464 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java @@ -60,7 +60,7 @@ import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.ui.util.Notify.Style; import org.sufficientlysecure.keychain.util.ParcelableProxy; import org.sufficientlysecure.keychain.util.Preferences; -import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; +import org.sufficientlysecure.keychain.util.tor.OrbotHelper; public abstract class DecryptFragment extends Fragment implements LoaderManager.LoaderCallbacks { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java index e2b90056d..c64fc5a2a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java @@ -43,7 +43,7 @@ import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.ParcelableFileCache; import org.sufficientlysecure.keychain.util.ParcelableFileCache.IteratorWithSize; import org.sufficientlysecure.keychain.util.Preferences; -import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; +import org.sufficientlysecure.keychain.util.tor.OrbotHelper; import java.io.IOException; import java.util.ArrayList; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysProxyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysProxyActivity.java index 1a03b8102..358dc108c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysProxyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysProxyActivity.java @@ -46,7 +46,7 @@ import org.sufficientlysecure.keychain.util.IntentIntegratorSupportV4; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.ParcelableProxy; import org.sufficientlysecure.keychain.util.Preferences; -import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; +import org.sufficientlysecure.keychain.util.tor.OrbotHelper; import java.util.ArrayList; import java.util.Locale; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java index da181711e..35f76be5e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java @@ -83,6 +83,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; +import org.sufficientlysecure.keychain.util.tor.OrbotHelper; /** * Public key list with sticky list headers. It does _not_ exte /** @@ -472,13 +473,11 @@ public class KeyListFragment extends LoaderFragment return true; case R.id.menu_key_list_export: - ); + mExportHelper.showExportKeysDialog(null, Constants.Path.APP_DIR_FILE, true); return true; - case R.id.menu_key_list_debug -_cons return true; - - consolidate(case R.id.menu_key_list_debug_cons:); + case R.id.menu_key_list_update_all_keys: + updateAllKeys(); return true; case R.id.menu_key_list_debug_read: diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java index 81e4b9eda..bdf10b065 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java @@ -42,7 +42,7 @@ import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.ui.widget.IntegerListPreference; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Preferences; -import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; +import org.sufficientlysecure.keychain.util.tor.OrbotHelper; import java.util.List; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/UploadKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/UploadKeyActivity.java index ee37b4b98..fc6585bbb 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/UploadKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/UploadKeyActivity.java @@ -39,7 +39,7 @@ import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.ParcelableProxy; import org.sufficientlysecure.keychain.util.Preferences; -import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; +import org.sufficientlysecure.keychain.util.tor.OrbotHelper; /** * Sends the selected public key to a keyserver diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java index ce8935bce..29fbbb3c8 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java @@ -86,7 +86,7 @@ import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.NfcHelper; import org.sufficientlysecure.keychain.util.ParcelableProxy; import org.sufficientlysecure.keychain.util.Preferences; -import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; +import org.sufficientlysecure.keychain.util.tor.OrbotHelper; import java.io.IOException; import java.util.ArrayList; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyTrustFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyTrustFragment.java index f6b580b01..8bcfd6111 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyTrustFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyTrustFragment.java @@ -53,7 +53,7 @@ import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.ParcelableProxy; import org.sufficientlysecure.keychain.util.Preferences; -import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; +import org.sufficientlysecure.keychain.util.tor.OrbotHelper; import java.util.ArrayList; import java.util.Hashtable; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/AddEditKeyserverDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/AddEditKeyserverDialogFragment.java index e5ab3a228..c409cbb7c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/AddEditKeyserverDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/AddEditKeyserverDialogFragment.java @@ -55,6 +55,7 @@ import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.keyimport.HkpKeyserver; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.TlsHelper; +import org.sufficientlysecure.keychain.util.tor.OrbotHelper; import java.io.IOException; import java.net.HttpURLConnection; @@ -221,8 +222,19 @@ public class AddEditKeyserverDialogFragment extends DialogFragment implements On // behaviour same for edit and add String keyserverUrl = mKeyserverEditText.getText().toString(); if (mVerifyKeyserverCheckBox.isChecked()) { - // TODO: PHILIP Implement proxy - verifyConnection(keyserverUrl); + final Preferences.ProxyPrefs proxyPrefs = Preferences.getPreferences(getActivity()) + .getProxyPrefs(); + Runnable ignoreTor = new Runnable() { + @Override + public void run() { + verifyConnection(keyserverUrl, null); + } + }; + + if (OrbotHelper.isOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, proxyPrefs, + getActivity())) { + verifyConnection(keyserverUrl, proxyPrefs.parcelableProxy.getProxy()); + } } else { dismiss(); // return unverified keyserver back to activity diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/OrbotStartDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/OrbotStartDialogFragment.java index 4736eddca..fdbab3b20 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/OrbotStartDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/OrbotStartDialogFragment.java @@ -29,7 +29,7 @@ import android.support.v4.app.DialogFragment; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.util.Log; -import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; +import org.sufficientlysecure.keychain.util.tor.OrbotHelper; /** * displays a dialog asking the user to enable Tor -- cgit v1.2.3 From c74d6fc710119fd6e83840ae883b764bc128944a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Wed, 17 Jun 2015 15:30:35 +0200 Subject: Rename package back to orbot because these are orbot utils --- .../sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java | 2 +- .../main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java | 2 +- .../java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java | 2 +- .../org/sufficientlysecure/keychain/ui/ImportKeysProxyActivity.java | 2 +- .../main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java | 3 --- .../main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java | 2 +- .../java/org/sufficientlysecure/keychain/ui/UploadKeyActivity.java | 2 +- .../main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java | 2 +- .../java/org/sufficientlysecure/keychain/ui/ViewKeyTrustFragment.java | 2 +- .../keychain/ui/dialog/AddEditKeyserverDialogFragment.java | 2 +- .../keychain/ui/dialog/OrbotStartDialogFragment.java | 2 +- 11 files changed, 10 insertions(+), 13 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java index ec74ca7c8..93614db56 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java @@ -43,7 +43,7 @@ import org.sufficientlysecure.keychain.ui.base.CryptoOperationFragment; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.util.ParcelableProxy; import org.sufficientlysecure.keychain.util.Preferences; -import org.sufficientlysecure.keychain.util.tor.OrbotHelper; +import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; public class CreateYubiKeyImportFragment diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java index e2cc21464..adb15111d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java @@ -60,7 +60,7 @@ import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.ui.util.Notify.Style; import org.sufficientlysecure.keychain.util.ParcelableProxy; import org.sufficientlysecure.keychain.util.Preferences; -import org.sufficientlysecure.keychain.util.tor.OrbotHelper; +import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; public abstract class DecryptFragment extends Fragment implements LoaderManager.LoaderCallbacks { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java index c64fc5a2a..e2b90056d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java @@ -43,7 +43,7 @@ import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.ParcelableFileCache; import org.sufficientlysecure.keychain.util.ParcelableFileCache.IteratorWithSize; import org.sufficientlysecure.keychain.util.Preferences; -import org.sufficientlysecure.keychain.util.tor.OrbotHelper; +import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; import java.io.IOException; import java.util.ArrayList; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysProxyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysProxyActivity.java index 358dc108c..1a03b8102 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysProxyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysProxyActivity.java @@ -46,7 +46,7 @@ import org.sufficientlysecure.keychain.util.IntentIntegratorSupportV4; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.ParcelableProxy; import org.sufficientlysecure.keychain.util.Preferences; -import org.sufficientlysecure.keychain.util.tor.OrbotHelper; +import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; import java.util.ArrayList; import java.util.Locale; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java index 35f76be5e..88e7e6025 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java @@ -83,9 +83,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; -import org.sufficientlysecure.keychain.util.tor.OrbotHelper; -/** - * Public key list with sticky list headers. It does _not_ exte /** * Public key list with sticky list headers. It does _not_ extend ListFragment because it uses * StickyListHeaders library which does not extend upon ListView. diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java index bdf10b065..81e4b9eda 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java @@ -42,7 +42,7 @@ import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.ui.widget.IntegerListPreference; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Preferences; -import org.sufficientlysecure.keychain.util.tor.OrbotHelper; +import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; import java.util.List; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/UploadKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/UploadKeyActivity.java index fc6585bbb..ee37b4b98 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/UploadKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/UploadKeyActivity.java @@ -39,7 +39,7 @@ import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.ParcelableProxy; import org.sufficientlysecure.keychain.util.Preferences; -import org.sufficientlysecure.keychain.util.tor.OrbotHelper; +import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; /** * Sends the selected public key to a keyserver diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java index 29fbbb3c8..ce8935bce 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java @@ -86,7 +86,7 @@ import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.NfcHelper; import org.sufficientlysecure.keychain.util.ParcelableProxy; import org.sufficientlysecure.keychain.util.Preferences; -import org.sufficientlysecure.keychain.util.tor.OrbotHelper; +import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; import java.io.IOException; import java.util.ArrayList; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyTrustFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyTrustFragment.java index 8bcfd6111..f6b580b01 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyTrustFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyTrustFragment.java @@ -53,7 +53,7 @@ import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.ParcelableProxy; import org.sufficientlysecure.keychain.util.Preferences; -import org.sufficientlysecure.keychain.util.tor.OrbotHelper; +import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; import java.util.ArrayList; import java.util.Hashtable; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/AddEditKeyserverDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/AddEditKeyserverDialogFragment.java index c409cbb7c..ede4dac4a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/AddEditKeyserverDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/AddEditKeyserverDialogFragment.java @@ -55,7 +55,7 @@ import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.keyimport.HkpKeyserver; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.TlsHelper; -import org.sufficientlysecure.keychain.util.tor.OrbotHelper; +import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; import java.io.IOException; import java.net.HttpURLConnection; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/OrbotStartDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/OrbotStartDialogFragment.java index fdbab3b20..4736eddca 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/OrbotStartDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/OrbotStartDialogFragment.java @@ -29,7 +29,7 @@ import android.support.v4.app.DialogFragment; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.util.Log; -import org.sufficientlysecure.keychain.util.tor.OrbotHelper; +import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; /** * displays a dialog asking the user to enable Tor -- cgit v1.2.3 From ad00a511d631650f8a35be3ccd6df793acaa4dfe Mon Sep 17 00:00:00 2001 From: Adithya Abraham Philip Date: Thu, 18 Jun 2015 15:56:53 +0530 Subject: fixed orbot preference install dialog --- .../keychain/ui/dialog/PreferenceInstallDialogFragment.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PreferenceInstallDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PreferenceInstallDialogFragment.java index b9b4da83a..b025cf5de 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PreferenceInstallDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PreferenceInstallDialogFragment.java @@ -38,7 +38,7 @@ public class PreferenceInstallDialogFragment extends DialogFragment { private static final String ARG_MESSAGE = "message"; private static final String ARG_MIDDLE_BUTTON = "middleButton"; private static final String ARG_INSTALL_PATH = "installPath"; - private static final String ARG_USE_MIDDLE_BUTTON = "installPath"; + private static final String ARG_USE_MIDDLE_BUTTON = "useMiddleButton"; public static final String PLAY_STORE_PATH = "market://search?q=pname:"; @@ -92,10 +92,10 @@ public class PreferenceInstallDialogFragment extends DialogFragment { final Messenger messenger = getArguments().getParcelable(ARG_MESSENGER); - final String title = getArguments().getString(ARG_TITLE); - final String message = getArguments().getString(ARG_MESSAGE); + final int title = getArguments().getInt(ARG_TITLE); + final int message = getArguments().getInt(ARG_MESSAGE); + final int middleButton = getArguments().getInt(ARG_MIDDLE_BUTTON); final String installPath = getArguments().getString(ARG_INSTALL_PATH); - final String middleButton = getArguments().getString(ARG_MIDDLE_BUTTON); final boolean useMiddleButton = getArguments().getBoolean(ARG_USE_MIDDLE_BUTTON); CustomAlertDialogBuilder builder = new CustomAlertDialogBuilder(activity); -- cgit v1.2.3 From 6d9da28ead0319db1bcb65f5e9efed5754326792 Mon Sep 17 00:00:00 2001 From: Adithya Abraham Philip Date: Thu, 18 Jun 2015 16:12:11 +0530 Subject: removed e.printStackTrace from several places --- .../sufficientlysecure/keychain/ui/PassphraseWizardActivity.java | 8 +++++--- .../keychain/ui/widget/PasswordStrengthView.java | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseWizardActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseWizardActivity.java index 2e838535d..ed96156fe 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseWizardActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseWizardActivity.java @@ -43,7 +43,9 @@ import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; +import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.util.Log; import java.io.IOException; import java.io.UnsupportedEncodingException; @@ -207,7 +209,7 @@ public class PassphraseWizardActivity extends FragmentActivity { // transaction.replace(R.id.fragmentContainer, lpf).addToBackStack(null).commit(); } } catch (IOException | FormatException e) { - e.printStackTrace(); + Log.e(Constants.TAG, "Failed to write on NFC tag", e); } } else if (readNFC && AUTHENTICATION.equals(selectedAction)) { @@ -232,7 +234,7 @@ public class PassphraseWizardActivity extends FragmentActivity { } } } catch (IOException | FormatException e) { - e.printStackTrace(); + Log.e(Constants.TAG, "Failed to read NFC tag", e); } } } @@ -263,7 +265,7 @@ public class PassphraseWizardActivity extends FragmentActivity { try { password = readText(ndefRecord); } catch (UnsupportedEncodingException e) { - e.printStackTrace(); + Log.e(Constants.TAG, "Failed to read password from tag", e); } } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/PasswordStrengthView.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/PasswordStrengthView.java index 0ec145657..30bdfb92a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/PasswordStrengthView.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/PasswordStrengthView.java @@ -31,7 +31,9 @@ import android.graphics.Paint; import android.util.AttributeSet; import android.view.View; +import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.util.Log; /** * Created by Matt Allen -- cgit v1.2.3 From 7cf695dbaec89f341c302b1a699714e4ef79ef0d Mon Sep 17 00:00:00 2001 From: Adithya Abraham Philip Date: Thu, 18 Jun 2015 16:33:29 +0530 Subject: reduce code duplication --- .../keychain/ui/dialog/InstallDialogFragment.java | 79 +-------------- .../ui/dialog/PreferenceInstallDialogFragment.java | 81 +-------------- .../ui/util/InstallDialogFragmentHelper.java | 109 +++++++++++++++++++++ 3 files changed, 119 insertions(+), 150 deletions(-) create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/InstallDialogFragmentHelper.java (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/InstallDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/InstallDialogFragment.java index 7b3f9ad28..7bfd940e6 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/InstallDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/InstallDialogFragment.java @@ -17,30 +17,14 @@ package org.sufficientlysecure.keychain.ui.dialog; -import android.app.Activity; import android.app.Dialog; -import android.content.DialogInterface; -import android.content.Intent; -import android.net.Uri; import android.os.Bundle; -import android.os.Message; import android.os.Messenger; -import android.os.RemoteException; import android.support.v4.app.DialogFragment; -import org.sufficientlysecure.keychain.Constants; -import org.sufficientlysecure.keychain.R; -import org.sufficientlysecure.keychain.util.Log; +import org.sufficientlysecure.keychain.ui.util.InstallDialogFragmentHelper; public class InstallDialogFragment extends DialogFragment { - private static final String ARG_MESSENGER = "messenger"; - private static final String ARG_TITLE = "title"; - private static final String ARG_MESSAGE = "message"; - private static final String ARG_MIDDLE_BUTTON = "middleButton"; - private static final String ARG_INSTALL_PATH = "installPath"; - private static final String ARG_USE_MIDDLE_BUTTON = "useMiddleButton"; - - public static final String PLAY_STORE_PATH = "market://search?q=pname:"; public static final int MESSAGE_MIDDLE_CLICKED = 1; @@ -60,13 +44,9 @@ public class InstallDialogFragment extends DialogFragment { useMiddleButton) { InstallDialogFragment frag = new InstallDialogFragment(); Bundle args = new Bundle(); - args.putParcelable(ARG_MESSENGER, messenger); - args.putInt(ARG_TITLE, title); - args.putInt(ARG_MESSAGE, message); - args.putInt(ARG_MIDDLE_BUTTON, middleButton); - args.putString(ARG_INSTALL_PATH, PLAY_STORE_PATH + packageToInstall); - args.putBoolean(ARG_USE_MIDDLE_BUTTON, useMiddleButton); + InstallDialogFragmentHelper.wrapIntoArgs(messenger, title, message, packageToInstall, middleButton, + useMiddleButton, args); frag.setArguments(args); @@ -88,57 +68,8 @@ public class InstallDialogFragment extends DialogFragment { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { - final Activity activity = getActivity(); - - final Messenger messenger = getArguments().getParcelable(ARG_MESSENGER); - - final int title = getArguments().getInt(ARG_TITLE); - final int message = getArguments().getInt(ARG_MESSAGE); - final int middleButton = getArguments().getInt(ARG_MIDDLE_BUTTON); - final String installPath = getArguments().getString(ARG_INSTALL_PATH); - final boolean useMiddleButton = getArguments().getBoolean(ARG_USE_MIDDLE_BUTTON); - - CustomAlertDialogBuilder builder = new CustomAlertDialogBuilder(activity); - - builder.setTitle(title).setMessage(message); - - builder.setNegativeButton(R.string.orbot_install_dialog_cancel, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - - } - }); - - builder.setPositiveButton(R.string.orbot_install_dialog_install, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - Uri uri = Uri.parse(installPath); - Intent intent = new Intent(Intent.ACTION_VIEW, uri); - activity.startActivity(intent); - } - } - ); - - if (useMiddleButton) { - builder.setNeutralButton(middleButton, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - Message msg = new Message(); - msg.what = MESSAGE_MIDDLE_CLICKED; - try { - messenger.send(msg); - } catch (RemoteException e) { - Log.w(Constants.TAG, "Exception sending message, Is handler present?", e); - } catch (NullPointerException e) { - Log.w(Constants.TAG, "Messenger is null!", e); - } - } - } - ); - } - return builder.show(); + return InstallDialogFragmentHelper.getInstallDialogFromArgs(getArguments(), getActivity(), + MESSAGE_MIDDLE_CLICKED); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PreferenceInstallDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PreferenceInstallDialogFragment.java index b025cf5de..afeec285f 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PreferenceInstallDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PreferenceInstallDialogFragment.java @@ -17,30 +17,14 @@ package org.sufficientlysecure.keychain.ui.dialog; -import android.app.Activity; import android.app.Dialog; -import android.content.DialogInterface; -import android.content.Intent; -import android.net.Uri; import android.os.Bundle; -import android.os.Message; import android.os.Messenger; -import android.os.RemoteException; import android.app.DialogFragment; -import org.sufficientlysecure.keychain.Constants; -import org.sufficientlysecure.keychain.R; -import org.sufficientlysecure.keychain.util.Log; +import org.sufficientlysecure.keychain.ui.util.InstallDialogFragmentHelper; public class PreferenceInstallDialogFragment extends DialogFragment { - private static final String ARG_MESSENGER = "messenger"; - private static final String ARG_TITLE = "title"; - private static final String ARG_MESSAGE = "message"; - private static final String ARG_MIDDLE_BUTTON = "middleButton"; - private static final String ARG_INSTALL_PATH = "installPath"; - private static final String ARG_USE_MIDDLE_BUTTON = "useMiddleButton"; - - public static final String PLAY_STORE_PATH = "market://search?q=pname:"; public static final int MESSAGE_MIDDLE_CLICKED = 1; @@ -60,13 +44,9 @@ public class PreferenceInstallDialogFragment extends DialogFragment { useMiddleButton) { PreferenceInstallDialogFragment frag = new PreferenceInstallDialogFragment(); Bundle args = new Bundle(); - args.putParcelable(ARG_MESSENGER, messenger); - args.putInt(ARG_TITLE, title); - args.putInt(ARG_MESSAGE, message); - args.putInt(ARG_MIDDLE_BUTTON, middleButton); - args.putString(ARG_INSTALL_PATH, PLAY_STORE_PATH + packageToInstall); - args.putBoolean(ARG_USE_MIDDLE_BUTTON, useMiddleButton); + InstallDialogFragmentHelper.wrapIntoArgs(messenger, title, message, packageToInstall, middleButton, + useMiddleButton, args); frag.setArguments(args); @@ -88,58 +68,7 @@ public class PreferenceInstallDialogFragment extends DialogFragment { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { - final Activity activity = getActivity(); - - final Messenger messenger = getArguments().getParcelable(ARG_MESSENGER); - - final int title = getArguments().getInt(ARG_TITLE); - final int message = getArguments().getInt(ARG_MESSAGE); - final int middleButton = getArguments().getInt(ARG_MIDDLE_BUTTON); - final String installPath = getArguments().getString(ARG_INSTALL_PATH); - final boolean useMiddleButton = getArguments().getBoolean(ARG_USE_MIDDLE_BUTTON); - - CustomAlertDialogBuilder builder = new CustomAlertDialogBuilder(activity); - - builder.setTitle(title).setMessage(message); - - builder.setNegativeButton(R.string.orbot_install_dialog_cancel, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - - } - }); - - builder.setPositiveButton(R.string.orbot_install_dialog_install, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - Uri uri = Uri.parse(installPath); - Intent intent = new Intent(Intent.ACTION_VIEW, uri); - activity.startActivity(intent); - } - } - ); - - if (useMiddleButton) { - builder.setNeutralButton(middleButton, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - Message msg = new Message(); - msg.what = MESSAGE_MIDDLE_CLICKED; - try { - messenger.send(msg); - } catch (RemoteException e) { - Log.w(Constants.TAG, "Exception sending message, Is handler present?", e); - } catch (NullPointerException e) { - Log.w(Constants.TAG, "Messenger is null!", e); - } - } - } - ); - } - - return builder.show(); + return InstallDialogFragmentHelper.getInstallDialogFromArgs(getArguments(), getActivity(), + MESSAGE_MIDDLE_CLICKED); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/InstallDialogFragmentHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/InstallDialogFragmentHelper.java new file mode 100644 index 000000000..9f96db6d0 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/InstallDialogFragmentHelper.java @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2012-2014 Dominik Schürmann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.sufficientlysecure.keychain.ui.util; + +import android.app.Activity; +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.content.Intent; +import android.net.Uri; +import android.os.Bundle; +import android.os.Message; +import android.os.Messenger; +import android.os.RemoteException; +import org.sufficientlysecure.keychain.Constants; +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.ui.dialog.CustomAlertDialogBuilder; +import org.sufficientlysecure.keychain.util.Log; + +public class InstallDialogFragmentHelper { + private static final String ARG_MESSENGER = "messenger"; + private static final String ARG_TITLE = "title"; + private static final String ARG_MESSAGE = "message"; + private static final String ARG_MIDDLE_BUTTON = "middleButton"; + private static final String ARG_INSTALL_PATH = "installPath"; + private static final String ARG_USE_MIDDLE_BUTTON = "useMiddleButton"; + + private static final String PLAY_STORE_PATH = "market://search?q=pname:"; + + public static void wrapIntoArgs(Messenger messenger, int title, int message, String packageToInstall, + int middleButton, boolean useMiddleButton, Bundle args) { + args.putParcelable(ARG_MESSENGER, messenger); + + args.putInt(ARG_TITLE, title); + args.putInt(ARG_MESSAGE, message); + args.putInt(ARG_MIDDLE_BUTTON, middleButton); + args.putString(ARG_INSTALL_PATH, PLAY_STORE_PATH + packageToInstall); + args.putBoolean(ARG_USE_MIDDLE_BUTTON, useMiddleButton); + } + + public static AlertDialog getInstallDialogFromArgs(Bundle args, final Activity activity, + final int messengerMiddleButtonClicked) { + final Messenger messenger = args.getParcelable(ARG_MESSENGER); + + final int title = args.getInt(ARG_TITLE); + final int message = args.getInt(ARG_MESSAGE); + final int middleButton = args.getInt(ARG_MIDDLE_BUTTON); + final String installPath = args.getString(ARG_INSTALL_PATH); + final boolean useMiddleButton = args.getBoolean(ARG_USE_MIDDLE_BUTTON); + + CustomAlertDialogBuilder builder = new CustomAlertDialogBuilder(activity); + + builder.setTitle(title).setMessage(message); + + builder.setNegativeButton(R.string.orbot_install_dialog_cancel, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + + } + }); + + builder.setPositiveButton(R.string.orbot_install_dialog_install, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + Uri uri = Uri.parse(installPath); + Intent intent = new Intent(Intent.ACTION_VIEW, uri); + activity.startActivity(intent); + } + } + ); + + if (useMiddleButton) { + builder.setNeutralButton(middleButton, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + Message msg = new Message(); + msg.what = messengerMiddleButtonClicked; + try { + messenger.send(msg); + } catch (RemoteException e) { + Log.w(Constants.TAG, "Exception sending message, Is handler present?", e); + } catch (NullPointerException e) { + Log.w(Constants.TAG, "Messenger is null!", e); + } + } + } + ); + } + + return builder.show(); + } +} -- cgit v1.2.3 From c95fa9fdc1d0eefe2b29fc2b1a176fa3a7b3d3b3 Mon Sep 17 00:00:00 2001 From: Adithya Abraham Philip Date: Thu, 18 Jun 2015 16:35:57 +0530 Subject: renamed to clarify necessity for two install dialog fragments --- .../keychain/ui/dialog/InstallDialogFragment.java | 75 ---------------------- .../ui/dialog/SupportInstallDialogFragment.java | 75 ++++++++++++++++++++++ 2 files changed, 75 insertions(+), 75 deletions(-) delete mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/InstallDialogFragment.java create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/SupportInstallDialogFragment.java (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/InstallDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/InstallDialogFragment.java deleted file mode 100644 index 7bfd940e6..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/InstallDialogFragment.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2012-2014 Dominik Schürmann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package org.sufficientlysecure.keychain.ui.dialog; - -import android.app.Dialog; -import android.os.Bundle; -import android.os.Messenger; -import android.support.v4.app.DialogFragment; - -import org.sufficientlysecure.keychain.ui.util.InstallDialogFragmentHelper; - -public class InstallDialogFragment extends DialogFragment { - - public static final int MESSAGE_MIDDLE_CLICKED = 1; - - /** - * Creates a dialog which prompts the user to install an application. Consists of two default buttons ("Install" - * and "Cancel") and an optional third button. Callbacks are provided only for the middle button, if set. - * - * @param messenger required only for callback from middle button if it has been set - * @param title - * @param message content of dialog - * @param packageToInstall package name of application to install - * @param middleButton if not null, adds a third button to the app with a call back - * @return The dialog to display - */ - public static InstallDialogFragment newInstance(Messenger messenger, int title, int message, - String packageToInstall, int middleButton, boolean - useMiddleButton) { - InstallDialogFragment frag = new InstallDialogFragment(); - Bundle args = new Bundle(); - - InstallDialogFragmentHelper.wrapIntoArgs(messenger, title, message, packageToInstall, middleButton, - useMiddleButton, args); - - frag.setArguments(args); - - return frag; - } - - /** - * To create a DialogFragment with only two buttons - * - * @param title - * @param message - * @param packageToInstall - * @return - */ - public static InstallDialogFragment newInstance(int title, int message, - String packageToInstall) { - return newInstance(null, title, message, packageToInstall, -1, false); - } - - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - - return InstallDialogFragmentHelper.getInstallDialogFromArgs(getArguments(), getActivity(), - MESSAGE_MIDDLE_CLICKED); - } -} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/SupportInstallDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/SupportInstallDialogFragment.java new file mode 100644 index 000000000..36ca13247 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/SupportInstallDialogFragment.java @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2012-2014 Dominik Schürmann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.sufficientlysecure.keychain.ui.dialog; + +import android.app.Dialog; +import android.os.Bundle; +import android.os.Messenger; +import android.support.v4.app.DialogFragment; + +import org.sufficientlysecure.keychain.ui.util.InstallDialogFragmentHelper; + +public class SupportInstallDialogFragment extends DialogFragment { + + public static final int MESSAGE_MIDDLE_CLICKED = 1; + + /** + * Creates a dialog which prompts the user to install an application. Consists of two default buttons ("Install" + * and "Cancel") and an optional third button. Callbacks are provided only for the middle button, if set. + * + * @param messenger required only for callback from middle button if it has been set + * @param title + * @param message content of dialog + * @param packageToInstall package name of application to install + * @param middleButton if not null, adds a third button to the app with a call back + * @return The dialog to display + */ + public static SupportInstallDialogFragment newInstance(Messenger messenger, int title, int message, + String packageToInstall, int middleButton, boolean + useMiddleButton) { + SupportInstallDialogFragment frag = new SupportInstallDialogFragment(); + Bundle args = new Bundle(); + + InstallDialogFragmentHelper.wrapIntoArgs(messenger, title, message, packageToInstall, middleButton, + useMiddleButton, args); + + frag.setArguments(args); + + return frag; + } + + /** + * To create a DialogFragment with only two buttons + * + * @param title + * @param message + * @param packageToInstall + * @return + */ + public static SupportInstallDialogFragment newInstance(int title, int message, + String packageToInstall) { + return newInstance(null, title, message, packageToInstall, -1, false); + } + + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + + return InstallDialogFragmentHelper.getInstallDialogFromArgs(getArguments(), getActivity(), + MESSAGE_MIDDLE_CLICKED); + } +} -- cgit v1.2.3 From 4d81a83baab301fafbf8ac0559ddc00341ac760c Mon Sep 17 00:00:00 2001 From: Adithya Abraham Philip Date: Fri, 3 Jul 2015 07:03:16 +0530 Subject: added proxy support to OperationHelper --- .../keychain/ui/CertifyKeyFragment.java | 5 +- .../keychain/ui/CreateYubiKeyImportFragment.java | 6 +- .../keychain/ui/DecryptFragment.java | 7 +- .../keychain/ui/ImportKeysActivity.java | 4 +- .../keychain/ui/ImportKeysProxyActivity.java | 22 ++---- .../keychain/ui/KeyListFragment.java | 2 +- .../keychain/ui/OrbotRequiredDialogActivity.java | 82 ++++++++++++++++++++++ .../keychain/ui/SettingsActivity.java | 2 + .../keychain/ui/UploadKeyActivity.java | 20 +----- .../keychain/ui/ViewKeyTrustFragment.java | 2 +- .../keychain/ui/base/CryptoOperationHelper.java | 52 +++++++++++--- .../ui/dialog/AddEditKeyserverDialogFragment.java | 14 +--- .../ui/dialog/OrbotStartDialogFragment.java | 14 +++- 13 files changed, 158 insertions(+), 74 deletions(-) create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/OrbotRequiredDialogActivity.java (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java index 6c57074a7..ab631c6fe 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java @@ -54,6 +54,7 @@ import org.sufficientlysecure.keychain.ui.base.CachingCryptoOperationFragment; import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.ui.widget.CertifyKeySpinner; import org.sufficientlysecure.keychain.util.Log; +import org.sufficientlysecure.keychain.util.Preferences; import java.util.ArrayList; @@ -312,8 +313,8 @@ public class CertifyKeyFragment actionsParcel.mCertifyActions.addAll(certifyActions); if (mUploadKeyCheckbox.isChecked()) { - actionsParcel.keyServerUri = Preferences.getPreferences(getActivity()).getPreferredKeyserver(); - actionsParcel.parcelableProxy = mProxyPrefs.parcelableProxy; + actionsParcel.keyServerUri = Preferences.getPreferences(getActivity()) + .getPreferredKeyserver(); } // cached for next cryptoOperation loop diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java index 93614db56..13cafc73c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java @@ -131,7 +131,7 @@ public class CreateYubiKeyImportFragment } }; - if (OrbotHelper.isOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, proxyPrefs, + if (OrbotHelper.putOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, proxyPrefs, getActivity())) { importKey(proxyPrefs.parcelableProxy); } @@ -153,7 +153,7 @@ public class CreateYubiKeyImportFragment } }; - if (OrbotHelper.isOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, proxyPrefs, + if (OrbotHelper.putOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, proxyPrefs, getActivity())) { refreshSearch(proxyPrefs.parcelableProxy); } @@ -245,7 +245,7 @@ public class CreateYubiKeyImportFragment } }; - if (OrbotHelper.isOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, proxyPrefs, + if (OrbotHelper.putOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, proxyPrefs, getActivity())) { refreshSearch(proxyPrefs.parcelableProxy); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java index adb15111d..ea736f938 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java @@ -19,15 +19,11 @@ package org.sufficientlysecure.keychain.ui; import java.util.ArrayList; -import android.app.Activity; import android.content.Intent; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; -import android.os.Message; -import android.os.Messenger; import android.support.v4.app.Fragment; -import android.os.Parcelable; import android.support.v4.app.LoaderManager; import android.support.v4.content.CursorLoader; import android.support.v4.content.Loader; @@ -52,7 +48,6 @@ import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.service.ImportKeyringParcel; -import org.sufficientlysecure.keychain.ui.base.CachingCryptoOperationFragment; import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils.State; @@ -438,7 +433,7 @@ public abstract class DecryptFragment extends Fragment implements LoaderManager. } }; - if (OrbotHelper.isOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, proxyPrefs, + if (OrbotHelper.putOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, proxyPrefs, getActivity())) { lookupUnknownKey(signatureKeyId, proxyPrefs.parcelableProxy); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java index e2b90056d..2e8e6f6bd 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java @@ -364,7 +364,7 @@ public class ImportKeysActivity extends BaseNfcActivity mListFragment.loadNew(loaderState, mProxyPrefs.parcelableProxy); } }; - if (OrbotHelper.isOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, mProxyPrefs, this)) { + if (OrbotHelper.putOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, mProxyPrefs, this)) { mListFragment.loadNew(loaderState, mProxyPrefs.parcelableProxy); } } else if (loaderState instanceof ImportKeysListFragment.BytesLoaderState) { // must always be true @@ -450,8 +450,6 @@ public class ImportKeysActivity extends BaseNfcActivity ImportKeysListFragment.CloudLoaderState sls = (ImportKeysListFragment.CloudLoaderState) ls; - data.putParcelable(KeychainService.EXTRA_PARCELABLE_PROXY, mProxyPrefs.parcelableProxy); - // get selected key entries ArrayList keys = new ArrayList<>(); { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysProxyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysProxyActivity.java index 1a03b8102..f45f1b350 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysProxyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysProxyActivity.java @@ -195,23 +195,23 @@ public class ImportKeysProxyActivity extends FragmentActivity } } - public void importKeys(byte[] keyringData, ParcelableProxy parcelableProxy) { + public void importKeys(byte[] keyringData) { ParcelableKeyRing keyEntry = new ParcelableKeyRing(keyringData); ArrayList selectedEntries = new ArrayList<>(); selectedEntries.add(keyEntry); - startImportService(selectedEntries, parcelableProxy); + startImportService(selectedEntries); } - public void importKeys(String fingerprint, ParcelableProxy parcelableProxy) { + public void importKeys(String fingerprint) { ParcelableKeyRing keyEntry = new ParcelableKeyRing(fingerprint, null, null); ArrayList selectedEntries = new ArrayList<>(); selectedEntries.add(keyEntry); - startImportService(selectedEntries, parcelableProxy); + startImportService(selectedEntries); } - private void startImportService(ArrayList keyRings, ParcelableProxy parcelableProxy) { + private void startImportService(ArrayList keyRings) { // search config { @@ -275,18 +275,8 @@ public class ImportKeysProxyActivity extends FragmentActivity NdefMessage msg = (NdefMessage) rawMsgs[0]; // record 0 contains the MIME type, record 1 is the AAR, if present final byte[] receivedKeyringBytes = msg.getRecords()[0].getPayload(); - final Preferences.ProxyPrefs proxyPrefs = Preferences.getPreferences(this) - .getProxyPrefs(); - Runnable ignoreTor = new Runnable() { - @Override - public void run() { - importKeys(receivedKeyringBytes, new ParcelableProxy(null, -1, null)); - } - }; - if (OrbotHelper.isOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, proxyPrefs, this)) { - importKeys(receivedKeyringBytes, proxyPrefs.parcelableProxy); - } + importKeys(receivedKeyringBytes); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java index 88e7e6025..007a67fbf 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java @@ -557,7 +557,7 @@ public class KeyListFragment extends LoaderFragment startActivityForResult(intent, REQUEST_ACTION); } - private void updateAllKeys(ParcelableProxy parcelableProxy) { + private void updateAllKeys() { Activity activity = getActivity(); if (activity == null) { return; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/OrbotRequiredDialogActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/OrbotRequiredDialogActivity.java new file mode 100644 index 000000000..0e73ebf5d --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/OrbotRequiredDialogActivity.java @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2015 Dominik Schürmann + * Copyright (C) 2015 Adithya Abraham Philip + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.sufficientlysecure.keychain.ui; + +import android.content.Intent; +import android.os.Bundle; +import android.support.v4.app.FragmentActivity; +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.compatibility.DialogFragmentWorkaround; +import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; +import org.sufficientlysecure.keychain.util.ParcelableProxy; +import org.sufficientlysecure.keychain.util.Preferences; +import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; + +/** + * Simply encapsulates a dialog. If orbot is not installed, it shows an install dialog, else a dialog to enable orbot. + */ +public class OrbotRequiredDialogActivity extends FragmentActivity { + + // to provide any previous crypto input into which proxy preference is merged + public static final String EXTRA_CRYPTO_INPUT = "extra_crypto_input"; + + public static final String RESULT_CRYPTO_INPUT = "result_crypto_input"; + + private CryptoInputParcel mCryptoInputParcel; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + mCryptoInputParcel = getIntent().getParcelableExtra(EXTRA_CRYPTO_INPUT); + if (mCryptoInputParcel == null) { + mCryptoInputParcel = new CryptoInputParcel(); + } + showDialog(); + } + + /** + * Displays an install or start orbot dialog depending on orbot's presence and state + */ + public void showDialog() { + DialogFragmentWorkaround.INTERFACE.runnableRunDelayed(new Runnable() { + public void run() { + Runnable ignoreTor = new Runnable() { + @Override + public void run() { + Intent intent = new Intent(); + mCryptoInputParcel.addParcelableProxy(ParcelableProxy.getForNoProxy()); + intent.putExtra(RESULT_CRYPTO_INPUT, mCryptoInputParcel); + setResult(RESULT_OK, intent); + finish(); + } + }; + if (OrbotHelper.putOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, + Preferences.getPreferences(OrbotRequiredDialogActivity.this) + .getProxyPrefs(), + OrbotRequiredDialogActivity.this)) { + // no action required after all + Intent intent = new Intent(); + intent.putExtra(RESULT_CRYPTO_INPUT, mCryptoInputParcel); + setResult(RESULT_OK, intent); + finish(); + } + } + }); + } +} \ No newline at end of file diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java index 81e4b9eda..f72a552d5 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java @@ -18,9 +18,11 @@ package org.sufficientlysecure.keychain.ui; +import android.annotation.TargetApi; import android.app.Activity; import android.content.Context; import android.content.Intent; +import android.os.Build; import android.os.Bundle; import android.preference.CheckBoxPreference; import android.preference.EditTextPreference; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/UploadKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/UploadKeyActivity.java index ee37b4b98..fb47db872 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/UploadKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/UploadKeyActivity.java @@ -37,7 +37,6 @@ import org.sufficientlysecure.keychain.service.ExportKeyringParcel; import org.sufficientlysecure.keychain.ui.base.BaseActivity; import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper; import org.sufficientlysecure.keychain.util.Log; -import org.sufficientlysecure.keychain.util.ParcelableProxy; import org.sufficientlysecure.keychain.util.Preferences; import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; @@ -78,19 +77,7 @@ public class UploadKeyActivity extends BaseActivity mUploadButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - final Preferences.ProxyPrefs proxyPrefs = Preferences.getPreferences(UploadKeyActivity.this) - .getProxyPrefs(); - Runnable ignoreTor = new Runnable() { - @Override - public void run() { - uploadKey(proxyPrefs.parcelableProxy); - } - }; - - if (OrbotHelper.isOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, proxyPrefs, - UploadKeyActivity.this)) { - uploadKey(proxyPrefs.parcelableProxy); - } + uploadKey(); } }); @@ -146,8 +133,7 @@ public class UploadKeyActivity extends BaseActivity @Override public void onCryptoOperationSuccess(ExportResult result) { - Toast.makeText(UploadKeyActivity.this, R.string.msg_crt_upload_success, - Toast.LENGTH_SHORT).show(); + result.createNotify(this).show(); } @Override @@ -157,7 +143,7 @@ public class UploadKeyActivity extends BaseActivity @Override public void onCryptoOperationError(ExportResult result) { - // TODO: Implement proper log for key upload then show error + result.createNotify(this).show(); } @Override diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyTrustFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyTrustFragment.java index f6b580b01..40cbba5b3 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyTrustFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyTrustFragment.java @@ -211,7 +211,7 @@ public class ViewKeyTrustFragment extends LoaderFragment implements } }; - if (OrbotHelper.isOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, proxyPrefs, + if (OrbotHelper.putOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, proxyPrefs, getActivity())) { mStartSearch.setEnabled(false); new DescribeKey(proxyPrefs.parcelableProxy).execute(fingerprint); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/CryptoOperationHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/CryptoOperationHelper.java index 240dd0972..484c065c4 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/CryptoOperationHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/CryptoOperationHelper.java @@ -39,6 +39,7 @@ import org.sufficientlysecure.keychain.service.ServiceProgressHandler; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel; import org.sufficientlysecure.keychain.ui.NfcOperationActivity; +import org.sufficientlysecure.keychain.ui.OrbotRequiredDialogActivity; import org.sufficientlysecure.keychain.ui.PassphraseDialogActivity; import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment; import org.sufficientlysecure.keychain.util.Log; @@ -62,6 +63,7 @@ public class CryptoOperationHelper. */ - package org.sufficientlysecure.keychain.ui.dialog; +import android.app.Activity; import android.app.Dialog; import android.content.DialogInterface; import android.os.Bundle; @@ -25,6 +25,7 @@ import android.os.Message; import android.os.Messenger; import android.os.RemoteException; import android.support.v4.app.DialogFragment; +import android.view.ContextThemeWrapper; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; @@ -62,8 +63,15 @@ public class OrbotStartDialogFragment extends DialogFragment { int title = getArguments().getInt(ARG_TITLE); final int message = getArguments().getInt(ARG_MESSAGE); int middleButton = getArguments().getInt(ARG_MIDDLE_BUTTON); + final Activity activity = getActivity(); + + // if the dialog is displayed from the application class, design is missing. + // hack to get holo design (which is not automatically applied due to activity's + // Theme.NoDisplay) + ContextThemeWrapper theme = new ContextThemeWrapper(activity, + R.style.Theme_AppCompat_Light_Dialog); - CustomAlertDialogBuilder builder = new CustomAlertDialogBuilder(getActivity()); + CustomAlertDialogBuilder builder = new CustomAlertDialogBuilder(theme); builder.setTitle(title).setMessage(message); builder.setNegativeButton(R.string.orbot_start_dialog_cancel, new DialogInterface.OnClickListener() { @@ -97,4 +105,4 @@ public class OrbotStartDialogFragment extends DialogFragment { return builder.show(); } -} +} \ No newline at end of file -- cgit v1.2.3 From 89f017aa9c1750de7574865baf29d071ff2862a5 Mon Sep 17 00:00:00 2001 From: Adithya Abraham Philip Date: Fri, 3 Jul 2015 07:18:50 +0530 Subject: reformatted code --- .../org/sufficientlysecure/keychain/ui/KeyListFragment.java | 1 + .../keychain/ui/OrbotRequiredDialogActivity.java | 4 +++- .../sufficientlysecure/keychain/ui/UploadKeyActivity.java | 1 - .../keychain/ui/base/CryptoOperationFragment.java | 2 +- .../keychain/ui/base/CryptoOperationHelper.java | 13 ++++++++----- 5 files changed, 13 insertions(+), 8 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java index 007a67fbf..c5bfdbedf 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java @@ -51,6 +51,7 @@ import android.widget.TextView; import com.getbase.floatingactionbutton.FloatingActionButton; import com.getbase.floatingactionbutton.FloatingActionsMenu; + import se.emilsjolander.stickylistheaders.StickyListHeadersAdapter; import se.emilsjolander.stickylistheaders.StickyListHeadersListView; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/OrbotRequiredDialogActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/OrbotRequiredDialogActivity.java index 0e73ebf5d..b75baceb5 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/OrbotRequiredDialogActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/OrbotRequiredDialogActivity.java @@ -21,6 +21,7 @@ package org.sufficientlysecure.keychain.ui; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.FragmentActivity; + import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.compatibility.DialogFragmentWorkaround; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; @@ -29,7 +30,8 @@ import org.sufficientlysecure.keychain.util.Preferences; import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; /** - * Simply encapsulates a dialog. If orbot is not installed, it shows an install dialog, else a dialog to enable orbot. + * Simply encapsulates a dialog. If orbot is not installed, it shows an install dialog, else a + * dialog to enable orbot. */ public class OrbotRequiredDialogActivity extends FragmentActivity { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/UploadKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/UploadKeyActivity.java index fb47db872..703a85b0f 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/UploadKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/UploadKeyActivity.java @@ -26,7 +26,6 @@ import android.view.View; import android.view.View.OnClickListener; import android.widget.ArrayAdapter; import android.widget.Spinner; -import android.widget.Toast; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/CryptoOperationFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/CryptoOperationFragment.java index 115f52d56..af664fc75 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/CryptoOperationFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/CryptoOperationFragment.java @@ -83,11 +83,11 @@ public abstract class CryptoOperationFragment { - public interface Callback { + public interface Callback { T createOperationInput(); + void onCryptoOperationSuccess(S result); + void onCryptoOperationCancelled(); + void onCryptoOperationError(S result); + boolean onCryptoSetProgress(String msg, int progress, int max); } @@ -124,6 +128,7 @@ public class CryptoOperationHelper Date: Fri, 3 Jul 2015 09:27:46 +0530 Subject: fixed OrbotRequiredDialogActivity not finishing, orbot install dialog style --- .../keychain/ui/CreateYubiKeyImportFragment.java | 16 ++-------- .../keychain/ui/DecryptFragment.java | 16 ++-------- .../keychain/ui/OrbotRequiredDialogActivity.java | 11 +++++-- .../ui/dialog/OrbotStartDialogFragment.java | 21 +++++++++++++ .../ui/dialog/PreferenceInstallDialogFragment.java | 3 +- .../ui/dialog/SupportInstallDialogFragment.java | 3 +- .../ui/util/InstallDialogFragmentHelper.java | 34 +++++++++++++++++++--- 7 files changed, 68 insertions(+), 36 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java index 13cafc73c..9e3dce28f 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java @@ -122,19 +122,7 @@ public class CreateYubiKeyImportFragment mNextButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - - final Preferences.ProxyPrefs proxyPrefs = Preferences.getPreferences(getActivity()).getProxyPrefs(); - Runnable ignoreTor = new Runnable() { - @Override - public void run() { - importKey(new ParcelableProxy(null, -1, null)); - } - }; - - if (OrbotHelper.putOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, proxyPrefs, - getActivity())) { - importKey(proxyPrefs.parcelableProxy); - } + importKey(); } }); } @@ -201,7 +189,7 @@ public class CreateYubiKeyImportFragment Preferences.getPreferences(getActivity()).getCloudSearchPrefs()), parcelableProxy); } - public void importKey(ParcelableProxy parcelableProxy) { + public void importKey() { ArrayList keyList = new ArrayList<>(); keyList.add(new ParcelableKeyRing(mNfcFingerprint, null, null)); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java index ea736f938..afd6b337e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java @@ -133,7 +133,7 @@ public abstract class DecryptFragment extends Fragment implements LoaderManager. } } - private void lookupUnknownKey(long unknownKeyId, ParcelableProxy parcelableProxy) { + private void lookupUnknownKey(long unknownKeyId) { final ArrayList keyList; final String keyserver; @@ -424,19 +424,7 @@ public abstract class DecryptFragment extends Fragment implements LoaderManager. mSignatureLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - final Preferences.ProxyPrefs proxyPrefs = Preferences.getPreferences(getActivity()) - .getProxyPrefs(); - Runnable ignoreTor = new Runnable() { - @Override - public void run() { - lookupUnknownKey(signatureKeyId, new ParcelableProxy(null, -1, null)); - } - }; - - if (OrbotHelper.putOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, proxyPrefs, - getActivity())) { - lookupUnknownKey(signatureKeyId, proxyPrefs.parcelableProxy); - } + lookupUnknownKey(signatureKeyId); } }); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/OrbotRequiredDialogActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/OrbotRequiredDialogActivity.java index b75baceb5..587044659 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/OrbotRequiredDialogActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/OrbotRequiredDialogActivity.java @@ -68,7 +68,15 @@ public class OrbotRequiredDialogActivity extends FragmentActivity { finish(); } }; - if (OrbotHelper.putOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, + + Runnable dialogDismissed = new Runnable() { + @Override + public void run() { + finish(); + } + }; + + if (OrbotHelper.putOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, dialogDismissed, Preferences.getPreferences(OrbotRequiredDialogActivity.this) .getProxyPrefs(), OrbotRequiredDialogActivity.this)) { @@ -76,7 +84,6 @@ public class OrbotRequiredDialogActivity extends FragmentActivity { Intent intent = new Intent(); intent.putExtra(RESULT_CRYPTO_INPUT, mCryptoInputParcel); setResult(RESULT_OK, intent); - finish(); } } }); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/OrbotStartDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/OrbotStartDialogFragment.java index dba04994c..dd7d2256a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/OrbotStartDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/OrbotStartDialogFragment.java @@ -18,6 +18,7 @@ package org.sufficientlysecure.keychain.ui.dialog; import android.app.Activity; +import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; import android.os.Bundle; @@ -42,6 +43,7 @@ public class OrbotStartDialogFragment extends DialogFragment { private static final String ARG_MIDDLE_BUTTON = "middleButton"; public static final int MESSAGE_MIDDLE_BUTTON = 1; + public static final int MESSAGE_DIALOG_DISMISSED = 2; // for either cancel or enable pressed public static OrbotStartDialogFragment newInstance(Messenger messenger, int title, int message, int middleButton) { Bundle args = new Bundle(); @@ -77,6 +79,15 @@ public class OrbotStartDialogFragment extends DialogFragment { builder.setNegativeButton(R.string.orbot_start_dialog_cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { + Message msg = Message.obtain(); + msg.what = MESSAGE_DIALOG_DISMISSED; + try { + messenger.send(msg); + } catch (RemoteException e) { + Log.w(Constants.TAG, "Exception sending message, Is handler present?", e); + } catch (NullPointerException e) { + Log.w(Constants.TAG, "Messenger is null!", e); + } } }); @@ -85,6 +96,16 @@ public class OrbotStartDialogFragment extends DialogFragment { @Override public void onClick(DialogInterface dialog, int which) { getActivity().startActivityForResult(OrbotHelper.getOrbotStartIntent(), 1); + + Message msg = Message.obtain(); + msg.what = MESSAGE_DIALOG_DISMISSED; + try { + messenger.send(msg); + } catch (RemoteException e) { + Log.w(Constants.TAG, "Exception sending message, Is handler present?", e); + } catch (NullPointerException e) { + Log.w(Constants.TAG, "Messenger is null!", e); + } } }); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PreferenceInstallDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PreferenceInstallDialogFragment.java index afeec285f..3f8bce28b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PreferenceInstallDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PreferenceInstallDialogFragment.java @@ -27,6 +27,7 @@ import org.sufficientlysecure.keychain.ui.util.InstallDialogFragmentHelper; public class PreferenceInstallDialogFragment extends DialogFragment { public static final int MESSAGE_MIDDLE_CLICKED = 1; + public static final int MESSAGE_DIALOG_DISMISSED = 2; /** * Creates a dialog which prompts the user to install an application. Consists of two default buttons ("Install" @@ -69,6 +70,6 @@ public class PreferenceInstallDialogFragment extends DialogFragment { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { return InstallDialogFragmentHelper.getInstallDialogFromArgs(getArguments(), getActivity(), - MESSAGE_MIDDLE_CLICKED); + MESSAGE_MIDDLE_CLICKED, MESSAGE_DIALOG_DISMISSED); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/SupportInstallDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/SupportInstallDialogFragment.java index 36ca13247..b2b71b364 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/SupportInstallDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/SupportInstallDialogFragment.java @@ -27,6 +27,7 @@ import org.sufficientlysecure.keychain.ui.util.InstallDialogFragmentHelper; public class SupportInstallDialogFragment extends DialogFragment { public static final int MESSAGE_MIDDLE_CLICKED = 1; + public static final int MESSAGE_DIALOG_DISMISSED = 2; /** * Creates a dialog which prompts the user to install an application. Consists of two default buttons ("Install" @@ -70,6 +71,6 @@ public class SupportInstallDialogFragment extends DialogFragment { public Dialog onCreateDialog(Bundle savedInstanceState) { return InstallDialogFragmentHelper.getInstallDialogFromArgs(getArguments(), getActivity(), - MESSAGE_MIDDLE_CLICKED); + MESSAGE_MIDDLE_CLICKED, MESSAGE_DIALOG_DISMISSED); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/InstallDialogFragmentHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/InstallDialogFragmentHelper.java index 9f96db6d0..f21d69c48 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/InstallDialogFragmentHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/InstallDialogFragmentHelper.java @@ -26,6 +26,8 @@ import android.os.Bundle; import android.os.Message; import android.os.Messenger; import android.os.RemoteException; +import android.view.ContextThemeWrapper; + import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.ui.dialog.CustomAlertDialogBuilder; @@ -53,7 +55,8 @@ public class InstallDialogFragmentHelper { } public static AlertDialog getInstallDialogFromArgs(Bundle args, final Activity activity, - final int messengerMiddleButtonClicked) { + final int messengerMiddleButtonClicked, + final int messengerDialogDimissed) { final Messenger messenger = args.getParcelable(ARG_MESSENGER); final int title = args.getInt(ARG_TITLE); @@ -62,7 +65,12 @@ public class InstallDialogFragmentHelper { final String installPath = args.getString(ARG_INSTALL_PATH); final boolean useMiddleButton = args.getBoolean(ARG_USE_MIDDLE_BUTTON); - CustomAlertDialogBuilder builder = new CustomAlertDialogBuilder(activity); + // if the dialog is displayed from the application class, design is missing. + // hack to get holo design (which is not automatically applied due to activity's + // Theme.NoDisplay) + ContextThemeWrapper theme = new ContextThemeWrapper(activity, + R.style.Theme_AppCompat_Light_Dialog); + CustomAlertDialogBuilder builder = new CustomAlertDialogBuilder(theme); builder.setTitle(title).setMessage(message); @@ -70,7 +78,15 @@ public class InstallDialogFragmentHelper { new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - + Message msg = Message.obtain(); + msg.what = messengerDialogDimissed; + try { + messenger.send(msg); + } catch (RemoteException e) { + Log.w(Constants.TAG, "Exception sending message, Is handler present?", e); + } catch (NullPointerException e) { + Log.w(Constants.TAG, "Messenger is null!", e); + } } }); @@ -81,6 +97,16 @@ public class InstallDialogFragmentHelper { Uri uri = Uri.parse(installPath); Intent intent = new Intent(Intent.ACTION_VIEW, uri); activity.startActivity(intent); + + Message msg = Message.obtain(); + msg.what = messengerDialogDimissed; + try { + messenger.send(msg); + } catch (RemoteException e) { + Log.w(Constants.TAG, "Exception sending message, Is handler present?", e); + } catch (NullPointerException e) { + Log.w(Constants.TAG, "Messenger is null!", e); + } } } ); @@ -90,7 +116,7 @@ public class InstallDialogFragmentHelper { new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - Message msg = new Message(); + Message msg = Message.obtain(); msg.what = messengerMiddleButtonClicked; try { messenger.send(msg); -- cgit v1.2.3 From f30672227640e280f0a73113f5d225c0da649486 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Thu, 2 Jul 2015 17:54:57 +0200 Subject: set data for query intent (fix #1389) --- .../java/org/sufficientlysecure/keychain/ui/DecryptListFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptListFragment.java index 96767463e..db2841488 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptListFragment.java @@ -304,7 +304,7 @@ public class DecryptListFragment } final Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setType(type); + intent.setDataAndType(outputUri, type); final List matches = context.getPackageManager().queryIntentActivities(intent, 0); -- cgit v1.2.3 From 4d8be637de04a37c9fc47e616b41817fd8615094 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Sun, 5 Jul 2015 21:20:24 +0200 Subject: better getActivity and getSystemService null handling in encryptfilesfragment --- .../keychain/ui/EncryptFilesFragment.java | 29 +++++++++++++++------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesFragment.java index 215af5885..b382e31d0 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesFragment.java @@ -35,6 +35,7 @@ import android.graphics.Point; import android.net.Uri; import android.os.Build; import android.os.Bundle; +import android.support.v4.app.FragmentActivity; import android.support.v7.widget.DefaultItemAnimator; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; @@ -388,6 +389,12 @@ public class EncryptFilesFragment @Override public void onCryptoOperationSuccess(final SignEncryptResult result) { + FragmentActivity activity = getActivity(); + if (activity == null) { + // it's gone, there's nothing we can do here + return; + } + if (mDeleteAfterEncrypt) { // TODO make behavior coherent here DeleteFileDialogFragment deleteFileDialog = @@ -400,13 +407,18 @@ public class EncryptFilesFragment // Share encrypted message/file startActivity(sendWithChooserExcludingEncrypt()); } else { + Activity activity = getActivity(); + if (activity == null) { + // it's gone, there's nothing we can do here + return; + } // Save encrypted file - result.createNotify(getActivity()).show(); + result.createNotify(activity).show(); } } }); - deleteFileDialog.show(getActivity().getSupportFragmentManager(), "deleteDialog"); + deleteFileDialog.show(activity.getSupportFragmentManager(), "deleteDialog"); } else { switch (mAfterEncryptAction) { @@ -417,25 +429,24 @@ public class EncryptFilesFragment break; case COPY: - Activity activity = getActivity(); - if (activity == null) { - // it's gone, there's nothing we can do here - return; - } ClipboardManager clipMan = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); + if (clipMan == null) { + Notify.create(activity, R.string.error_clipboard_copy, Style.ERROR).show(); + break; + } ClipData clip = new ClipData(getString(R.string.label_clip_title), // make available as application/pgp-encrypted new String[] { "text/plain" }, new ClipData.Item(mOutputUris.get(0)) ); clipMan.setPrimaryClip(clip); - result.createNotify(getActivity()).show(); + result.createNotify(activity).show(); break; case SAVE: // Encrypted file was saved already, just show notification - result.createNotify(getActivity()).show(); + result.createNotify(activity).show(); break; } } -- cgit v1.2.3 From bd78166c668f979fe0ad4bcdaab13eeea7ca2520 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Sun, 5 Jul 2015 21:21:34 +0200 Subject: don't show notification in MainActivity when state is restored --- .../keychain/ui/MainActivity.java | 31 ++++++++++++---------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MainActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MainActivity.java index ec6fd1bbe..51ed2b012 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MainActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MainActivity.java @@ -128,6 +128,11 @@ public class MainActivity extends BaseNfcActivity implements FabContainer, OnBac getSupportFragmentManager().addOnBackStackChangedListener(this); + // all further initialization steps are saved as instance state + if (savedInstanceState != null) { + return; + } + Intent data = getIntent(); // If we got an EXTRA_RESULT in the intent, show the notification if (data != null && data.hasExtra(OperationResult.EXTRA_RESULT)) { @@ -135,20 +140,18 @@ public class MainActivity extends BaseNfcActivity implements FabContainer, OnBac result.createNotify(this).show(); } - if (savedInstanceState == null) { - // always initialize keys fragment to the bottom of the backstack - onKeysSelected(); - - if (data != null && data.hasExtra(EXTRA_INIT_FRAG)) { - // initialize FragmentLayout with KeyListFragment at first - switch (data.getIntExtra(EXTRA_INIT_FRAG, -1)) { - case ID_ENCRYPT_DECRYPT: - onEnDecryptSelected(); - break; - case ID_APPS: - onAppsSelected(); - break; - } + // always initialize keys fragment to the bottom of the backstack + onKeysSelected(); + + if (data != null && data.hasExtra(EXTRA_INIT_FRAG)) { + // initialize FragmentLayout with KeyListFragment at first + switch (data.getIntExtra(EXTRA_INIT_FRAG, -1)) { + case ID_ENCRYPT_DECRYPT: + onEnDecryptSelected(); + break; + case ID_APPS: + onAppsSelected(); + break; } } -- cgit v1.2.3 From 7e83900d6ccd20ad9ae4f10515989c0d1754bb98 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Sun, 5 Jul 2015 21:49:02 +0200 Subject: make sure clipboard service retrieval is always null-proof --- .../keychain/ui/DisplayTextFragment.java | 21 ++++++++++++++--- .../ui/EncryptDecryptOverviewFragment.java | 3 +-- .../keychain/ui/EncryptTextFragment.java | 27 +++++++++++++++------- .../keychain/ui/ViewKeyAdvShareFragment.java | 15 ++++++++++-- 4 files changed, 51 insertions(+), 15 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DisplayTextFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DisplayTextFragment.java index 7b3af48cc..dc06e9115 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DisplayTextFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DisplayTextFragment.java @@ -17,6 +17,10 @@ package org.sufficientlysecure.keychain.ui; +import android.app.Activity; +import android.content.ClipData; +import android.content.ClipboardManager; +import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; @@ -29,9 +33,9 @@ import android.widget.TextView; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; -import org.sufficientlysecure.keychain.compatibility.ClipboardReflection; import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult; import org.sufficientlysecure.keychain.ui.util.Notify; +import org.sufficientlysecure.keychain.ui.util.Notify.Style; import org.sufficientlysecure.keychain.util.ShareHelper; public class DisplayTextFragment extends DecryptFragment { @@ -80,8 +84,19 @@ public class DisplayTextFragment extends DecryptFragment { } private void copyToClipboard(String text) { - ClipboardReflection.copyToClipboard(getActivity(), text); - Notify.create(getActivity(), R.string.text_copied_to_clipboard, Notify.Style.OK).show(); + Activity activity = getActivity(); + if (activity == null) { + return; + } + + ClipboardManager clipMan = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); + if (clipMan == null) { + Notify.create(activity, R.string.error_clipboard_copy, Style.ERROR).show(); + return; + } + + clipMan.setPrimaryClip(ClipData.newPlainText(Constants.CLIPBOARD_LABEL, text)); + Notify.create(activity, R.string.text_copied_to_clipboard, Style.OK).show(); } @Override diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptDecryptOverviewFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptDecryptOverviewFragment.java index 779b22535..fc72a6c9f 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptDecryptOverviewFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptDecryptOverviewFragment.java @@ -124,8 +124,7 @@ public class EncryptDecryptOverviewFragment extends Fragment { super.onResume(); // get text from clipboard - final CharSequence clipboardText = - ClipboardReflection.getClipboardText(getActivity()); + final CharSequence clipboardText = ClipboardReflection.getClipboardText(getActivity()); // if it's null, nothing to do here /o/ if (clipboardText == null) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextFragment.java index 886c52651..8d3738fbd 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextFragment.java @@ -18,6 +18,9 @@ package org.sufficientlysecure.keychain.ui; import android.app.Activity; +import android.content.ClipData; +import android.content.ClipboardManager; +import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.text.Editable; @@ -33,7 +36,6 @@ import android.widget.TextView; import org.spongycastle.bcpg.CompressionAlgorithmTags; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; -import org.sufficientlysecure.keychain.compatibility.ClipboardReflection; import org.sufficientlysecure.keychain.operations.results.SignEncryptResult; import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.PgpConstants; @@ -265,8 +267,21 @@ public class EncryptTextFragment return data; } - private void copyToClipboard(byte[] resultBytes) { - ClipboardReflection.copyToClipboard(getActivity(), new String(resultBytes)); + private void copyToClipboard(SignEncryptResult result) { + Activity activity = getActivity(); + if (activity == null) { + return; + } + + ClipboardManager clipMan = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); + if (clipMan == null) { + Notify.create(activity, R.string.error_clipboard_copy, Style.ERROR).show(); + return; + } + + ClipData clip = ClipData.newPlainText(Constants.CLIPBOARD_LABEL, new String(result.getResultBytes())); + clipMan.setPrimaryClip(clip); + result.createNotify(activity).show(); } /** @@ -323,11 +338,7 @@ public class EncryptTextFragment startActivity(sendWithChooserExcludingEncrypt(result.getResultBytes())); } else { // Copy to clipboard - copyToClipboard(result.getResultBytes()); - result.createNotify(getActivity()).show(); - // Notify.create(EncryptTextActivity.this, - // R.string.encrypt_sign_clipboard_successful, Notify.Style.OK) - // .show(getSupportFragmentManager().findFragmentById(R.id.encrypt_text_fragment)); + copyToClipboard(result); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java index b44e6dc78..f46b30137 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java @@ -25,6 +25,9 @@ import java.io.OutputStreamWriter; import android.app.Activity; import android.app.ActivityOptions; +import android.content.ClipData; +import android.content.ClipboardManager; +import android.content.Context; import android.content.Intent; import android.database.Cursor; import android.graphics.Bitmap; @@ -49,7 +52,6 @@ import android.widget.TextView; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; -import org.sufficientlysecure.keychain.compatibility.ClipboardReflection; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.KeychainContract; @@ -58,6 +60,7 @@ import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.provider.TemporaryStorageProvider; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.ui.util.Notify; +import org.sufficientlysecure.keychain.ui.util.Notify.Style; import org.sufficientlysecure.keychain.ui.util.QrCodeUtils; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.NfcHelper; @@ -197,7 +200,15 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements } if (toClipboard) { - ClipboardReflection.copyToClipboard(activity, content); + ClipboardManager clipMan = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); + if (clipMan == null) { + Notify.create(activity, R.string.error_clipboard_copy, Style.ERROR); + return; + } + + ClipData clip = ClipData.newPlainText(Constants.CLIPBOARD_LABEL, content); + clipMan.setPrimaryClip(clip); + Notify.create(activity, fingerprintOnly ? R.string.fingerprint_copied_to_clipboard : R.string.key_copied_to_clipboard, Notify.Style.OK).show(); return; -- cgit v1.2.3 From 539379a6297c6064c5a9e2c5450b3050958d15fd Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Mon, 6 Jul 2015 00:10:54 +0200 Subject: some cleanup and documentation --- .../keychain/ui/CreateKeyFinalFragment.java | 15 +++-- .../keychain/ui/ViewKeyYubiKeyFragment.java | 2 +- .../keychain/ui/base/CryptoOperationFragment.java | 75 +++++++++++++--------- .../keychain/ui/base/CryptoOperationHelper.java | 10 --- 4 files changed, 57 insertions(+), 45 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java index 7192b7335..51c1bd079 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java @@ -23,6 +23,7 @@ import android.database.Cursor; import android.net.Uri; import android.os.Bundle; import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentActivity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -385,14 +386,18 @@ public class CreateKeyFinalFragment extends Fragment { } public void handleResult(ExportResult result) { - // TODO: ExportOperation UPLOAD_KEYSERVER needs logs! - // TODO: then merge logs here! - //saveKeyResult.getLog().add(result, 0); + Activity activity = getActivity(); + if (activity == null) { + return; + } + + saveKeyResult.getLog().add(result, 0); Intent data = new Intent(); data.putExtra(OperationResult.EXTRA_RESULT, saveKeyResult); - getActivity().setResult(Activity.RESULT_OK, data); - getActivity().finish(); + activity.setResult(Activity.RESULT_OK, data); + activity.finish(); + } @Override diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyYubiKeyFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyYubiKeyFragment.java index f8c3b59ea..c2158650b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyYubiKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyYubiKeyFragment.java @@ -210,7 +210,7 @@ public class ViewKeyYubiKeyFragment } @Override - protected void onCryptoOperationResult(PromoteKeyResult result) { + public void onCryptoOperationSuccess(PromoteKeyResult result) { result.createNotify(getActivity()).show(); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/CryptoOperationFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/CryptoOperationFragment.java index af664fc75..2ab0d5fac 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/CryptoOperationFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/CryptoOperationFragment.java @@ -20,56 +20,88 @@ package org.sufficientlysecure.keychain.ui.base; import android.content.Intent; import android.os.Parcelable; +import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import org.sufficientlysecure.keychain.operations.results.OperationResult; +import org.sufficientlysecure.keychain.service.KeychainService; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; -/** - * All fragments executing crypto operations need to extend this class. +/** This is a base class for fragments which implement a cryptoOperation. + * + * Subclasses of this class can call the cryptoOperation method to execute an + * operation in KeychainService which takes a parcelable of type T as its input + * and returns an OperationResult of type S as a result. + * + * The input (of type T) is not given directly to the cryptoOperation method, + * but must be provided by the overriden createOperationInput method to be + * available upon request during execution of the cryptoOperation. + * + * After running cryptoOperation, one of the onCryptoOperation*() methods will + * be called, depending on the success status of the operation. The subclass + * must override at least onCryptoOperationSuccess to proceed after a + * successful operation. + * + * @see KeychainService + * */ public abstract class CryptoOperationFragment extends Fragment implements CryptoOperationHelper.Callback { - private CryptoOperationHelper mOperationHelper; + final private CryptoOperationHelper mOperationHelper; public CryptoOperationFragment() { mOperationHelper = new CryptoOperationHelper<>(this, this); } - public void setProgressMessageResource(int id) { - mOperationHelper.setProgressMessageResource(id); - } - - @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { mOperationHelper.handleActivityResult(requestCode, resultCode, data); } - @Override - public abstract T createOperationInput(); - + /** Starts execution of the cryptographic operation. + * + * During this process, the createOperationInput() method will be called, + * this input will be handed to KeychainService, where it is executed in + * the appropriate *Operation class. If the result is a PendingInputResult, + * it is handled accordingly. Otherwise, it is returned in one of the + * onCryptoOperation* callbacks. + */ protected void cryptoOperation() { - cryptoOperation(new CryptoInputParcel()); + mOperationHelper.cryptoOperation(); } protected void cryptoOperation(CryptoInputParcel cryptoInput) { - cryptoOperation(cryptoInput, true); + mOperationHelper.cryptoOperation(cryptoInput); } protected void cryptoOperation(CryptoInputParcel cryptoInput, boolean showProgress) { mOperationHelper.cryptoOperation(cryptoInput, showProgress); } + @Override @Nullable + /** Creates input for the crypto operation. Called internally after the + * crypto operation is started by a call to cryptoOperation(). Silently + * cancels operation if this method returns null. */ + public abstract T createOperationInput(); + + /** Returns false, indicating that we did not handle progress ourselves. */ public boolean onCryptoSetProgress(String msg, int progress, int max) { return false; } + public void setProgressMessageResource(int id) { + mOperationHelper.setProgressMessageResource(id); + } + + @Override + /** Called when the cryptoOperation() was successful. No default behavior + * here, this should always be implemented by a subclass! */ + abstract public void onCryptoOperationSuccess(S result); + @Override public void onCryptoOperationError(S result) { - onCryptoOperationResult(result); result.createNotify(getActivity()).show(); } @@ -77,19 +109,4 @@ public abstract class CryptoOperationFragment callback, int progressMessageString) { mActivity = activity; @@ -96,8 +94,6 @@ public class CryptoOperationHelper callback, int progressMessageString) { mFragment = fragment; @@ -108,8 +104,6 @@ public class CryptoOperationHelper callback) { mFragment = fragment; @@ -178,10 +172,6 @@ public class CryptoOperationHelper Date: Mon, 6 Jul 2015 00:52:53 +0200 Subject: cleanup, NonNull annotation, never return null in PgpDecryptVerify --- .../keychain/ui/base/CryptoOperationHelper.java | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/CryptoOperationHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/CryptoOperationHelper.java index 64e4dec74..8d141ea5d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/CryptoOperationHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/CryptoOperationHelper.java @@ -314,14 +314,6 @@ public class CryptoOperationHelper Date: Mon, 6 Jul 2015 00:59:28 +0200 Subject: forgot a couple lines to commit --- .../keychain/ui/base/CachingCryptoOperationFragment.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/CachingCryptoOperationFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/CachingCryptoOperationFragment.java index 17e4e6ede..95bc4adcb 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/CachingCryptoOperationFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/CachingCryptoOperationFragment.java @@ -31,8 +31,12 @@ public abstract class CachingCryptoOperationFragment