From 8bc8f14c64111e3b4bc74360e1ac88f878d8c9fe Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sun, 6 Jul 2014 12:49:57 -0700 Subject: [PATCH] Protect from accessing the ComputerManagerService before initialization has completed --- src/com/limelight/PcView.java | 37 +++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/src/com/limelight/PcView.java b/src/com/limelight/PcView.java index fdd2b085..ef69a888 100644 --- a/src/com/limelight/PcView.java +++ b/src/com/limelight/PcView.java @@ -148,9 +148,16 @@ public class PcView extends Activity { } private void stopComputerUpdates() { - freezeUpdates = true; - managerBinder.stopPolling(); - runningPolling = false; + if (managerBinder != null) { + if (!runningPolling) { + return; + } + + freezeUpdates = true; + + managerBinder.stopPolling(); + runningPolling = false; + } } @Override @@ -229,6 +236,11 @@ public class PcView extends Activity { "You must close the game before pairing.", Toast.LENGTH_LONG).show(); return; } + if (managerBinder == null) { + Toast.makeText(PcView.this, "The ComputerManager service is not running. " + + "Please wait a few seconds or restart the app.", Toast.LENGTH_LONG).show(); + return; + } Toast.makeText(PcView.this, "Pairing...", Toast.LENGTH_SHORT).show(); new Thread(new Runnable() { @@ -330,6 +342,11 @@ public class PcView extends Activity { Toast.makeText(PcView.this, "Computer is offline", Toast.LENGTH_SHORT).show(); return; } + if (managerBinder == null) { + Toast.makeText(PcView.this, "The ComputerManager service is not running. " + + "Please wait a few seconds or restart the app.", Toast.LENGTH_LONG).show(); + return; + } Toast.makeText(PcView.this, "Unpairing...", Toast.LENGTH_SHORT).show(); new Thread(new Runnable() { @@ -387,6 +404,11 @@ public class PcView extends Activity { Toast.makeText(PcView.this, "Computer is offline", Toast.LENGTH_SHORT).show(); return; } + if (managerBinder == null) { + Toast.makeText(PcView.this, "The ComputerManager service is not running. " + + "Please wait a few seconds or restart the app.", Toast.LENGTH_LONG).show(); + return; + } Intent i = new Intent(this, AppView.class); i.putExtra(AppView.NAME_EXTRA, computer.name); @@ -422,9 +444,12 @@ public class PcView extends Activity { return true; case DELETE_ID: - if (managerBinder != null) { - managerBinder.removeComputer(computer.details.name); - } + if (managerBinder == null) { + Toast.makeText(PcView.this, "The ComputerManager service is not running. " + + "Please wait a few seconds or restart the app.", Toast.LENGTH_LONG).show(); + return true; + } + managerBinder.removeComputer(computer.details.name); removeListView(computer.details); return true;