Exemplo n.º 1
0
        @Override
        public void onReceive(Context context, Intent intent) {

          String action = intent.getStringExtra("action");
          if (action == null || action.equals("")) {
            return;
          } else if (action.equals("left")) {
            Participant p = poll.getParticipants().get(intent.getStringExtra("id"));
            if (p != null) {
              if (AbstractAction.this instanceof SetupRoundAction) {
                poll.getCompletelyExcludedParticipants().put(p.getUniqueId(), p);
                // notify exclusion
                LocalBroadcastManager.getInstance(AndroidApplication.getInstance())
                    .sendBroadcast(
                        new Intent(BroadcastIntentTypes.proofVerificationFailed)
                            .putExtra("type", 2)
                            .putExtra("participant", p.getIdentification()));
                Log.w(
                    TAG,
                    "Participant "
                        + p.getIdentification()
                        + " ("
                        + p.getUniqueId()
                        + ") went out of the network before submitting the setup value, so he was completely excluded (also from recovery).");
              } else {
                poll.getExcludedParticipants().put(p.getUniqueId(), p);
                // notify exclusion
                LocalBroadcastManager.getInstance(AndroidApplication.getInstance())
                    .sendBroadcast(
                        new Intent(BroadcastIntentTypes.proofVerificationFailed)
                            .putExtra("type", 3)
                            .putExtra("participant", p.getIdentification()));
                Log.w(
                    TAG,
                    "Participant "
                        + p.getIdentification()
                        + " ("
                        + p.getUniqueId()
                        + ") was added to excluded list since he went out of the network.");
              }
            }
          }

          if (readyToGoToNextState() && !actionTerminated) {
            goToNextState();
          }
        }
Exemplo n.º 2
0
 /**
  * Indicate if conditions to go to next step are fulfilled
  *
  * @return true if conditions are fulfilled, false otherwise
  */
 protected boolean readyToGoToNextState() {
   Collection<Participant> activeParticipants = new ArrayList<Participant>();
   for (Participant p : poll.getParticipants().values()) {
     activeParticipants.add(p);
   }
   activeParticipants.removeAll(poll.getExcludedParticipants().values());
   activeParticipants.removeAll(poll.getCompletelyExcludedParticipants().values());
   for (Participant p : activeParticipants) {
     if (!this.messagesReceived.containsKey(p.getUniqueId())) {
       Log.w(
           TAG,
           "Message from " + p.getUniqueId() + " (" + p.getIdentification() + ") not received");
       return false;
     }
   }
   return true;
 }