diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SecurityTokenOperationActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SecurityTokenOperationActivity.java index b767f2465..de4db520f 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SecurityTokenOperationActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SecurityTokenOperationActivity.java @@ -331,12 +331,18 @@ public class SecurityTokenOperationActivity extends BaseSecurityTokenActivity { protected Void doInBackground(Void... params) { // check all 200ms if Security Token has been taken away while (true) { - if (stConnection.isConnected()) { - try { + try { + if (stConnection.isConnected()) { Thread.sleep(200); - } catch (InterruptedException ignored) { + } else { + return null; } - } else { + } catch (InterruptedException ignored) { + // Sleep interrupted; ignore + } catch (SecurityException ignored) { + // In newer version of Android, isConnected() can throw an SecurityException + // when the Tag object becomes "stale"; this simply means the tag has been removed + // (and possibly rediscovered), so we can safely break from here. return null; } }