Protect from accessing the ComputerManagerService before initialization has completed

This commit is contained in:
Cameron Gutman 2014-07-06 12:49:57 -07:00
parent 09cf5d23ea
commit 8bc8f14c64

View File

@ -148,10 +148,17 @@ public class PcView extends Activity {
}
private void stopComputerUpdates() {
if (managerBinder != null) {
if (!runningPolling) {
return;
}
freezeUpdates = true;
managerBinder.stopPolling();
runningPolling = false;
}
}
@Override
public void onDestroy() {
@ -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;