aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/OrbotRequiredDialogActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/OrbotRequiredDialogActivity.java')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/OrbotRequiredDialogActivity.java60
1 files changed, 58 insertions, 2 deletions
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 d1c247a76..d12b3fc22 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/OrbotRequiredDialogActivity.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/OrbotRequiredDialogActivity.java
@@ -18,12 +18,20 @@
package org.sufficientlysecure.keychain.ui;
+import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.os.Messenger;
+import android.os.RemoteException;
import android.support.v4.app.FragmentActivity;
+import org.sufficientlysecure.keychain.Constants;
+import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.compatibility.DialogFragmentWorkaround;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
+import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.ParcelableProxy;
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
@@ -34,8 +42,14 @@ import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
public class OrbotRequiredDialogActivity extends FragmentActivity
implements OrbotHelper.DialogActions {
+ public static final int MESSAGE_ORBOT_STARTED = 1;
+ public static final int MESSAGE_ORBOT_IGNORE = 2;
+ public static final int MESSAGE_DIALOG_CANCEL = 3;
+
// if suppplied and true will start Orbot directly without showing dialog
public static final String EXTRA_START_ORBOT = "start_orbot";
+ // used for communicating results when triggered from a service
+ public static final String EXTRA_MESSENGER = "messenger";
// to provide any previous crypto input into which proxy preference is merged
public static final String EXTRA_CRYPTO_INPUT = "extra_crypto_input";
@@ -43,6 +57,9 @@ public class OrbotRequiredDialogActivity extends FragmentActivity
public static final String RESULT_CRYPTO_INPUT = "result_crypto_input";
private CryptoInputParcel mCryptoInputParcel;
+ private Messenger mMessenger;
+
+ private ProgressDialog mShowOrbotProgressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -54,9 +71,15 @@ public class OrbotRequiredDialogActivity extends FragmentActivity
mCryptoInputParcel = new CryptoInputParcel();
}
+ mMessenger = getIntent().getParcelableExtra(EXTRA_MESSENGER);
+
boolean startOrbotDirect = getIntent().getBooleanExtra(EXTRA_START_ORBOT, false);
if (startOrbotDirect) {
- OrbotHelper.bestPossibleOrbotStart(this, this);
+ mShowOrbotProgressDialog = new ProgressDialog(this);
+ mShowOrbotProgressDialog.setTitle(R.string.progress_starting_orbot);
+ mShowOrbotProgressDialog.setCancelable(false);
+ mShowOrbotProgressDialog.show();
+ OrbotHelper.bestPossibleOrbotStart(this, this, false);
} else {
showDialog();
}
@@ -84,13 +107,32 @@ public class OrbotRequiredDialogActivity extends FragmentActivity
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case OrbotHelper.START_TOR_RESULT: {
- onOrbotStarted(); // assumption that orbot was started, no way to tell for sure
+ dismissOrbotProgressDialog();
+ // unfortunately, this result is returned immediately and not when Orbot is started
+ // 10s is approximately the longest time Orbot has taken to start
+ new Handler().postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ onOrbotStarted(); // assumption that orbot was started
+ }
+ }, 10000);
}
}
}
+ /**
+ * for when Orbot is started without showing the dialog by the EXTRA_START_ORBOT intent extra
+ */
+ private void dismissOrbotProgressDialog() {
+ if (mShowOrbotProgressDialog != null) {
+ mShowOrbotProgressDialog.dismiss();
+ }
+ }
+
@Override
public void onOrbotStarted() {
+ dismissOrbotProgressDialog();
+ sendMessage(MESSAGE_ORBOT_STARTED);
Intent intent = new Intent();
// send back unmodified CryptoInputParcel for a retry
intent.putExtra(RESULT_CRYPTO_INPUT, mCryptoInputParcel);
@@ -100,6 +142,7 @@ public class OrbotRequiredDialogActivity extends FragmentActivity
@Override
public void onNeutralButton() {
+ sendMessage(MESSAGE_ORBOT_IGNORE);
Intent intent = new Intent();
mCryptoInputParcel.addParcelableProxy(ParcelableProxy.getForNoProxy());
intent.putExtra(RESULT_CRYPTO_INPUT, mCryptoInputParcel);
@@ -109,6 +152,19 @@ public class OrbotRequiredDialogActivity extends FragmentActivity
@Override
public void onCancel() {
+ sendMessage(MESSAGE_DIALOG_CANCEL);
finish();
}
+
+ private void sendMessage(int what) {
+ if (mMessenger != null) {
+ Message msg = Message.obtain();
+ msg.what = what;
+ try {
+ mMessenger.send(msg);
+ } catch (RemoteException e) {
+ Log.e(Constants.TAG, "Could not deliver message", e);
+ }
+ }
+ }
} \ No newline at end of file