diff options
author | Dominik Schürmann <dominik@dominikschuermann.de> | 2016-05-11 16:50:18 +0300 |
---|---|---|
committer | Dominik Schürmann <dominik@dominikschuermann.de> | 2016-05-11 16:50:18 +0300 |
commit | b362668f8144f07b2bd388ccae4d52dca1590396 (patch) | |
tree | b259266ade960e65cc1021669b34b5c326650620 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/orbot/OrbotStatusReceiver.java | |
parent | 39849c2c572e23341d3fda260e72d4fc8367a68d (diff) | |
parent | 26a73724548797cec791ea4b622e5e8baea06980 (diff) | |
download | open-keychain-b362668f8144f07b2bd388ccae4d52dca1590396.tar.gz open-keychain-b362668f8144f07b2bd388ccae4d52dca1590396.tar.bz2 open-keychain-b362668f8144f07b2bd388ccae4d52dca1590396.zip |
Merge pull request #1865 from vanitasvitae/master
Fixed 'Orbot appears not to be running' (#1792)
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/orbot/OrbotStatusReceiver.java')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/orbot/OrbotStatusReceiver.java | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/orbot/OrbotStatusReceiver.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/orbot/OrbotStatusReceiver.java new file mode 100644 index 000000000..29a058f0a --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/orbot/OrbotStatusReceiver.java @@ -0,0 +1,93 @@ +/* + * 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 <http://www.gnu.org/licenses/>. + */ + +package org.sufficientlysecure.keychain.util.orbot; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; + +import org.sufficientlysecure.keychain.Constants; +import org.sufficientlysecure.keychain.util.Log; + +/** + * BroadcastReceiver that receives Orbots status + */ +public class OrbotStatusReceiver extends BroadcastReceiver { + + //TODO: These two Strings are missing in older versions of NetCipher. + //TODO: Once they are present in OrbotHelper (not ProxyHelper) point to OrbotHelpers Strings instead. + public final static String EXTRA_PROXY_PORT_HTTP = "org.torproject.android.intent.extra.HTTP_PROXY_PORT"; + public final static String EXTRA_PROXY_PORT_SOCKS = "org.torproject.android.intent.extra.SOCKS_PROXY_PORT"; + + //Variables representing Orbots status + private boolean torRunning; + private int proxy_port_http; + private int proxy_port_socks; + + private static OrbotStatusReceiver instance; + + public OrbotStatusReceiver() { + instance = this; + } + + public static OrbotStatusReceiver getInstance() { + if(instance == null) { + instance = new OrbotStatusReceiver(); + } + return instance; + } + + + @Override + public void onReceive(Context context, Intent intent) { + if (OrbotHelper.ACTION_STATUS.equals(intent.getAction())) { + Log.i(Constants.TAG, context.getPackageName() + " received intent : " + intent.getAction() + " " + intent.getPackage()); + String status = intent.getStringExtra(OrbotHelper.EXTRA_STATUS) + " (" + intent.getStringExtra(OrbotHelper.EXTRA_PACKAGE_NAME) + ")"; + this.torRunning = (intent.getStringExtra(OrbotHelper.EXTRA_STATUS).equals(OrbotHelper.STATUS_ON)); + + Log.d(Constants.TAG, "Orbot status: "+status); + if(torRunning){ + Bundle extras = intent.getExtras(); + + if (extras.containsKey(EXTRA_PROXY_PORT_HTTP)) { + this.proxy_port_http = extras.getInt(EXTRA_PROXY_PORT_HTTP, -1); + Log.i(Constants.TAG, "Http proxy set to "+proxy_port_http); + } + + if (extras.containsKey(EXTRA_PROXY_PORT_SOCKS)) { + this.proxy_port_socks = extras.getInt(EXTRA_PROXY_PORT_SOCKS, -1); + Log.i(Constants.TAG, "Socks proxy set to "+proxy_port_socks); + } + } + } + } + + public boolean isTorRunning(Context context) { + OrbotHelper.requestStartTor(context); + return this.torRunning; + } + + public int getProxyPortHttp(Context context) { + OrbotHelper.requestStartTor(context); + return this.proxy_port_http; + } + + public int getProxyPortSocks(Context context) { + OrbotHelper.requestStartTor(context); + return this.proxy_port_socks; + } +} |