diff --git a/app/src/main/java/com/limelight/binding/input/ControllerHandler.java b/app/src/main/java/com/limelight/binding/input/ControllerHandler.java index 70fcf88d..0a2a058a 100644 --- a/app/src/main/java/com/limelight/binding/input/ControllerHandler.java +++ b/app/src/main/java/com/limelight/binding/input/ControllerHandler.java @@ -1482,7 +1482,14 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD // UI thread. try { Thread.sleep(ControllerHandler.MINIMUM_BUTTON_DOWN_TIME_MS); - } catch (InterruptedException ignored) {} + } catch (InterruptedException e) { + e.printStackTrace(); + + // InterruptedException clears the thread's interrupt status. Since we can't + // handle that here, we will re-interrupt the thread to set the interrupt + // status back to true. + Thread.currentThread().interrupt(); + } } switch (keyCode) { @@ -1591,7 +1598,14 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD try { Thread.sleep(EMULATED_SELECT_UP_DELAY_MS); - } catch (InterruptedException ignored) {} + } catch (InterruptedException e) { + e.printStackTrace(); + + // InterruptedException clears the thread's interrupt status. Since we can't + // handle that here, we will re-interrupt the thread to set the interrupt + // status back to true. + Thread.currentThread().interrupt(); + } } } @@ -1609,7 +1623,14 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD try { Thread.sleep(EMULATED_SPECIAL_UP_DELAY_MS); - } catch (InterruptedException ignored) {} + } catch (InterruptedException e) { + e.printStackTrace(); + + // InterruptedException clears the thread's interrupt status. Since we can't + // handle that here, we will re-interrupt the thread to set the interrupt + // status back to true. + Thread.currentThread().interrupt(); + } } } diff --git a/app/src/main/java/com/limelight/binding/input/driver/AbstractXboxController.java b/app/src/main/java/com/limelight/binding/input/driver/AbstractXboxController.java index 01adf7db..0831f785 100644 --- a/app/src/main/java/com/limelight/binding/input/driver/AbstractXboxController.java +++ b/app/src/main/java/com/limelight/binding/input/driver/AbstractXboxController.java @@ -37,7 +37,9 @@ public abstract class AbstractXboxController extends AbstractController { // around when we call notifyDeviceAdded(), we won't be able to claim // the controller number used by the original InputDevice. Thread.sleep(1000); - } catch (InterruptedException e) {} + } catch (InterruptedException e) { + return; + } // Report that we're added _before_ reporting input notifyDeviceAdded(); diff --git a/app/src/main/java/com/limelight/binding/input/touch/AbsoluteTouchContext.java b/app/src/main/java/com/limelight/binding/input/touch/AbsoluteTouchContext.java index f1c5112a..1f365a51 100644 --- a/app/src/main/java/com/limelight/binding/input/touch/AbsoluteTouchContext.java +++ b/app/src/main/java/com/limelight/binding/input/touch/AbsoluteTouchContext.java @@ -116,7 +116,14 @@ public class AbsoluteTouchContext implements TouchContext { try { // FIXME: Sleeping on the main thread sucks Thread.sleep(50); - } catch (InterruptedException ignored) {} + } catch (InterruptedException e) { + e.printStackTrace(); + + // InterruptedException clears the thread's interrupt status. Since we can't + // handle that here, we will re-interrupt the thread to set the interrupt + // status back to true. + Thread.currentThread().interrupt(); + } conn.sendMouseButtonUp(MouseButtonPacket.BUTTON_LEFT); } } diff --git a/app/src/main/java/com/limelight/binding/input/touch/RelativeTouchContext.java b/app/src/main/java/com/limelight/binding/input/touch/RelativeTouchContext.java index b6763815..2ed34c9d 100644 --- a/app/src/main/java/com/limelight/binding/input/touch/RelativeTouchContext.java +++ b/app/src/main/java/com/limelight/binding/input/touch/RelativeTouchContext.java @@ -139,7 +139,14 @@ public class RelativeTouchContext implements TouchContext { // do input detection by polling try { Thread.sleep(100); - } catch (InterruptedException ignored) {} + } catch (InterruptedException e) { + e.printStackTrace(); + + // InterruptedException clears the thread's interrupt status. Since we can't + // handle that here, we will re-interrupt the thread to set the interrupt + // status back to true. + Thread.currentThread().interrupt(); + } // Raise the mouse button conn.sendMouseButtonUp(buttonIndex); diff --git a/app/src/main/java/com/limelight/binding/video/MediaCodecDecoderRenderer.java b/app/src/main/java/com/limelight/binding/video/MediaCodecDecoderRenderer.java index a4ec184f..85a02b61 100644 --- a/app/src/main/java/com/limelight/binding/video/MediaCodecDecoderRenderer.java +++ b/app/src/main/java/com/limelight/binding/video/MediaCodecDecoderRenderer.java @@ -639,7 +639,14 @@ public class MediaCodecDecoderRenderer extends VideoDecoderRenderer implements C // Wait for the renderer thread to shut down try { rendererThread.join(); - } catch (InterruptedException ignored) { } + } catch (InterruptedException e) { + e.printStackTrace(); + + // InterruptedException clears the thread's interrupt status. Since we can't + // handle that here, we will re-interrupt the thread to set the interrupt + // status back to true. + Thread.currentThread().interrupt(); + } } @Override diff --git a/app/src/main/java/com/limelight/computers/ComputerManagerService.java b/app/src/main/java/com/limelight/computers/ComputerManagerService.java index 70e10124..f2663b20 100644 --- a/app/src/main/java/com/limelight/computers/ComputerManagerService.java +++ b/app/src/main/java/com/limelight/computers/ComputerManagerService.java @@ -229,7 +229,13 @@ public class ComputerManagerService extends Service { // Wait for the bind notification discoveryServiceConnection.wait(1000); } - } catch (InterruptedException ignored) { + } catch (InterruptedException e) { + e.printStackTrace(); + + // InterruptedException clears the thread's interrupt status. Since we can't + // handle that here, we will re-interrupt the thread to set the interrupt + // status back to true. + Thread.currentThread().interrupt(); } } } @@ -238,11 +244,18 @@ public class ComputerManagerService extends Service { while (activePolls.get() != 0) { try { Thread.sleep(250); - } catch (InterruptedException ignored) {} + } catch (InterruptedException e) { + e.printStackTrace(); + + // InterruptedException clears the thread's interrupt status. Since we can't + // handle that here, we will re-interrupt the thread to set the interrupt + // status back to true. + Thread.currentThread().interrupt(); + } } } - public boolean addComputerBlocking(ComputerDetails fakeDetails) { + public boolean addComputerBlocking(ComputerDetails fakeDetails) throws InterruptedException { return ComputerManagerService.this.addComputerBlocking(fakeDetails); } @@ -396,9 +409,18 @@ public class ComputerManagerService extends Service { details.ipv6Address = computer.getIpv6Address().getHostAddress(); } - // Kick off a serverinfo poll on this machine - if (!addComputerBlocking(details)) { - LimeLog.warning("Auto-discovered PC failed to respond: "+details); + try { + // Kick off a blocking serverinfo poll on this machine + if (!addComputerBlocking(details)) { + LimeLog.warning("Auto-discovered PC failed to respond: "+details); + } + } catch (InterruptedException e) { + e.printStackTrace(); + + // InterruptedException clears the thread's interrupt status. Since we can't + // handle that here, we will re-interrupt the thread to set the interrupt + // status back to true. + Thread.currentThread().interrupt(); } } @@ -446,28 +468,25 @@ public class ComputerManagerService extends Service { } } - public boolean addComputerBlocking(ComputerDetails fakeDetails) { + public boolean addComputerBlocking(ComputerDetails fakeDetails) throws InterruptedException { // Block while we try to fill the details - try { - // We cannot use runPoll() here because it will attempt to persist the state of the machine - // in the database, which would be bad because we don't have our pinned cert loaded yet. - if (pollComputer(fakeDetails)) { - // See if we have record of this PC to pull its pinned cert - synchronized (pollingTuples) { - for (PollingTuple tuple : pollingTuples) { - if (tuple.computer.uuid.equals(fakeDetails.uuid)) { - fakeDetails.serverCert = tuple.computer.serverCert; - break; - } + + // We cannot use runPoll() here because it will attempt to persist the state of the machine + // in the database, which would be bad because we don't have our pinned cert loaded yet. + if (pollComputer(fakeDetails)) { + // See if we have record of this PC to pull its pinned cert + synchronized (pollingTuples) { + for (PollingTuple tuple : pollingTuples) { + if (tuple.computer.uuid.equals(fakeDetails.uuid)) { + fakeDetails.serverCert = tuple.computer.serverCert; + break; } } - - // Poll again, possibly with the pinned cert, to get accurate pairing information. - // This will insert the host into the database too. - runPoll(fakeDetails, true, 0); } - } catch (InterruptedException e) { - return false; + + // Poll again, possibly with the pinned cert, to get accurate pairing information. + // This will insert the host into the database too. + runPoll(fakeDetails, true, 0); } // If the machine is reachable, it was successful diff --git a/app/src/main/java/com/limelight/grid/assets/CachedAppAssetLoader.java b/app/src/main/java/com/limelight/grid/assets/CachedAppAssetLoader.java index 891f94a1..83253b24 100644 --- a/app/src/main/java/com/limelight/grid/assets/CachedAppAssetLoader.java +++ b/app/src/main/java/com/limelight/grid/assets/CachedAppAssetLoader.java @@ -128,6 +128,13 @@ public class CachedAppAssetLoader { try { Thread.sleep((int) (1000 + (Math.random() * 500))); } catch (InterruptedException e) { + e.printStackTrace(); + + // InterruptedException clears the thread's interrupt status. Since we can't + // handle that here, we will re-interrupt the thread to set the interrupt + // status back to true. + Thread.currentThread().interrupt(); + return null; } } diff --git a/app/src/main/java/com/limelight/preferences/AddComputerManually.java b/app/src/main/java/com/limelight/preferences/AddComputerManually.java index 7a25ba54..51c7edde 100644 --- a/app/src/main/java/com/limelight/preferences/AddComputerManually.java +++ b/app/src/main/java/com/limelight/preferences/AddComputerManually.java @@ -96,7 +96,7 @@ public class AddComputerManually extends Activity { } } - private void doAddPc(String host) { + private void doAddPc(String host) throws InterruptedException { boolean wrongSiteLocal = false; boolean success; int portTestResult; @@ -113,7 +113,10 @@ public class AddComputerManually extends Activity { // https://github.com/square/okhttp/blob/okhttp_27/okhttp/src/main/java/com/squareup/okhttp/HttpUrl.java#L705 e.printStackTrace(); success = false; + } finally { + dialog.dismiss(); } + if (!success){ wrongSiteLocal = isWrongSubnetSiteLocalAddress(host); } @@ -126,8 +129,6 @@ public class AddComputerManually extends Activity { portTestResult = MoonBridge.ML_TEST_RESULT_INCONCLUSIVE; } - dialog.dismiss(); - if (wrongSiteLocal) { Dialog.displayDialog(this, getResources().getString(R.string.conn_error_title), getResources().getString(R.string.addpc_wrong_sitelocal), false); } @@ -162,15 +163,12 @@ public class AddComputerManually extends Activity { @Override public void run() { while (!isInterrupted()) { - String computer; - try { - computer = computersToAdd.take(); + String computer = computersToAdd.take(); + doAddPc(computer); } catch (InterruptedException e) { return; } - - doAddPc(computer); } } }; @@ -184,7 +182,14 @@ public class AddComputerManually extends Activity { try { addThread.join(); - } catch (InterruptedException ignored) {} + } catch (InterruptedException e) { + e.printStackTrace(); + + // InterruptedException clears the thread's interrupt status. Since we can't + // handle that here, we will re-interrupt the thread to set the interrupt + // status back to true. + Thread.currentThread().interrupt(); + } addThread = null; }