listen to orbot events instead of using intent result to reconnect account
This commit is contained in:
parent
1958cded23
commit
70c10fd0de
|
@ -8,6 +8,8 @@ import android.preference.PreferenceManager;
|
|||
import android.support.v4.content.ContextCompat;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
import eu.siacs.conversations.Config;
|
||||
import eu.siacs.conversations.utils.Compatibility;
|
||||
|
||||
|
@ -19,17 +21,13 @@ public class EventReceiver extends BroadcastReceiver {
|
|||
@Override
|
||||
public void onReceive(final Context context, final Intent originalIntent) {
|
||||
final Intent intentForService = new Intent(context, XmppConnectionService.class);
|
||||
if (originalIntent.getAction() != null) {
|
||||
intentForService.setAction(originalIntent.getAction());
|
||||
final String action = originalIntent.getAction();
|
||||
intentForService.setAction(Strings.isNullOrEmpty(action) ? "other" : action);
|
||||
final Bundle extras = originalIntent.getExtras();
|
||||
if (extras != null) {
|
||||
intentForService.putExtras(extras);
|
||||
}
|
||||
} else {
|
||||
intentForService.setAction("other");
|
||||
}
|
||||
final String action = originalIntent.getAction();
|
||||
if (action.equals("ui") || hasEnabledAccounts(context)) {
|
||||
if ("ui".equals(action) || hasEnabledAccounts(context)) {
|
||||
Compatibility.startService(context, intentForService);
|
||||
} else {
|
||||
Log.d(Config.LOGTAG, "EventReceiver ignored action " + intentForService.getAction());
|
||||
|
|
|
@ -127,6 +127,7 @@ import eu.siacs.conversations.utils.ReplacingTaskManager;
|
|||
import eu.siacs.conversations.utils.Resolver;
|
||||
import eu.siacs.conversations.utils.SerialSingleThreadExecutor;
|
||||
import eu.siacs.conversations.utils.StringUtils;
|
||||
import eu.siacs.conversations.utils.TorServiceUtils;
|
||||
import eu.siacs.conversations.utils.WakeLockHelper;
|
||||
import eu.siacs.conversations.utils.XmppUri;
|
||||
import eu.siacs.conversations.xml.Element;
|
||||
|
@ -652,6 +653,13 @@ public class XmppConnectionService extends Service {
|
|||
final String sessionId = intent.getStringExtra(RtpSessionActivity.EXTRA_SESSION_ID);
|
||||
Log.d(Config.LOGTAG, "received intent to dismiss call with session id " + sessionId);
|
||||
mJingleConnectionManager.rejectRtpSession(sessionId);
|
||||
break;
|
||||
}
|
||||
case TorServiceUtils.ACTION_STATUS:
|
||||
final String status = intent.getStringExtra(TorServiceUtils.EXTRA_STATUS);
|
||||
if ("ON".equals(status)) {
|
||||
handleOrbotStartedEvent();
|
||||
return START_STICKY;
|
||||
}
|
||||
break;
|
||||
case ACTION_END_CALL: {
|
||||
|
@ -787,6 +795,14 @@ public class XmppConnectionService extends Service {
|
|||
return START_STICKY;
|
||||
}
|
||||
|
||||
private void handleOrbotStartedEvent() {
|
||||
for (final Account account : accounts) {
|
||||
if (account.getStatus() == Account.State.TOR_NOT_AVAILABLE) {
|
||||
reconnectAccount(account, true, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean processAccountState(Account account, boolean interactive, boolean isUiAction, boolean isAccountPushed, HashSet<Account> pingCandidates) {
|
||||
boolean pingNow = false;
|
||||
if (account.getStatus().isAttemptReconnect()) {
|
||||
|
@ -1128,15 +1144,16 @@ public class XmppConnectionService extends Service {
|
|||
toggleForegroundService();
|
||||
updateUnreadCountBadge();
|
||||
toggleScreenEventReceiver();
|
||||
final IntentFilter intentFilter = new IntentFilter();
|
||||
intentFilter.addAction(TorServiceUtils.ACTION_STATUS);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
scheduleNextIdlePing();
|
||||
IntentFilter intentFilter = new IntentFilter();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
|
||||
}
|
||||
intentFilter.addAction(NotificationManager.ACTION_INTERRUPTION_FILTER_CHANGED);
|
||||
registerReceiver(this.mInternalEventReceiver, intentFilter);
|
||||
}
|
||||
registerReceiver(this.mInternalEventReceiver, intentFilter);
|
||||
mForceDuringOnCreate.set(false);
|
||||
toggleForegroundService();
|
||||
}
|
||||
|
@ -1192,7 +1209,7 @@ public class XmppConnectionService extends Service {
|
|||
public void onDestroy() {
|
||||
try {
|
||||
unregisterReceiver(this.mInternalEventReceiver);
|
||||
} catch (IllegalArgumentException e) {
|
||||
} catch (final IllegalArgumentException e) {
|
||||
//ignored
|
||||
}
|
||||
destroyed = false;
|
||||
|
@ -2193,7 +2210,7 @@ public class XmppConnectionService extends Service {
|
|||
final Jid jid = Jid.ofEscaped(address);
|
||||
final Account account = new Account(jid, password);
|
||||
account.setOption(Account.OPTION_DISABLED, true);
|
||||
Log.d(Config.LOGTAG,jid.asBareJid().toEscapedString()+": provisioning account");
|
||||
Log.d(Config.LOGTAG, jid.asBareJid().toEscapedString() + ": provisioning account");
|
||||
createAccount(account);
|
||||
}
|
||||
|
||||
|
|
|
@ -89,7 +89,6 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
|
|||
private static final int REQUEST_CHANGE_STATUS = 0xee11;
|
||||
private static final int REQUEST_ORBOT = 0xff22;
|
||||
private final PendingItem<PresenceTemplate> mPendingPresenceTemplate = new PendingItem<>();
|
||||
private final AtomicBoolean mPendingReconnect = new AtomicBoolean(false);
|
||||
private AlertDialog mCaptchaDialog = null;
|
||||
private Jid jidToEdit;
|
||||
private boolean mInitMode = false;
|
||||
|
@ -475,13 +474,6 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
|
|||
Log.d(Config.LOGTAG, "pgp result not ok");
|
||||
}
|
||||
}
|
||||
if (requestCode == REQUEST_ORBOT) {
|
||||
if (xmppConnectionService != null && mAccount != null) {
|
||||
xmppConnectionService.reconnectAccountInBackground(mAccount);
|
||||
} else {
|
||||
mPendingReconnect.set(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -781,11 +773,6 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
|
|||
}
|
||||
|
||||
if (mAccount != null) {
|
||||
|
||||
if (mPendingReconnect.compareAndSet(true, false)) {
|
||||
xmppConnectionService.reconnectAccountInBackground(mAccount);
|
||||
}
|
||||
|
||||
this.mInitMode |= this.mAccount.isOptionSet(Account.OPTION_REGISTER);
|
||||
this.mUsernameMode |= mAccount.isOptionSet(Account.OPTION_MAGIC_CREATE) && mAccount.isOptionSet(Account.OPTION_REGISTER);
|
||||
if (mPendingFingerprintVerificationUri != null) {
|
||||
|
|
|
@ -16,6 +16,9 @@ public class TorServiceUtils {
|
|||
private static final Uri ORBOT_PLAYSTORE_URI = Uri.parse("market://details?id=" + URI_ORBOT);
|
||||
private final static String ACTION_START_TOR = "org.torproject.android.START_TOR";
|
||||
|
||||
public final static String ACTION_STATUS = "org.torproject.android.intent.action.STATUS";
|
||||
public final static String EXTRA_STATUS = "org.torproject.android.intent.extra.STATUS";
|
||||
|
||||
public static boolean isOrbotInstalled(Context context) {
|
||||
try {
|
||||
context.getPackageManager().getPackageInfo(URI_ORBOT, PackageManager.GET_ACTIVITIES);
|
||||
|
|
Loading…
Reference in a new issue