Exemplo n.º 1
0
 private boolean compatIdle() {
   if (null != compatTaskMonitor) {
     return compatTaskMonitor.isIdleNow();
   } else {
     return true;
   }
 }
Exemplo n.º 2
0
  @Override
  public void loopMainThreadUntilIdle() {
    initialize();
    checkState(Looper.myLooper() == mainLooper, "Expecting to be on main thread!");
    do {
      EnumSet<IdleCondition> condChecks = EnumSet.noneOf(IdleCondition.class);
      if (!asyncTaskMonitor.isIdleNow()) {
        asyncTaskMonitor.notifyWhenIdle(
            new SignalingTask<Void>(NO_OP, IdleCondition.ASYNC_TASKS_HAVE_IDLED, generation));

        condChecks.add(IdleCondition.ASYNC_TASKS_HAVE_IDLED);
      }

      if (!compatIdle()) {
        compatTaskMonitor.notifyWhenIdle(
            new SignalingTask<Void>(NO_OP, IdleCondition.COMPAT_TASKS_HAVE_IDLED, generation));
        condChecks.add(IdleCondition.COMPAT_TASKS_HAVE_IDLED);
      }

      if (!idlingResourceRegistry.allResourcesAreIdle()) {
        final IdlingPolicy warning = IdlingPolicies.getDynamicIdlingResourceWarningPolicy();
        final IdlingPolicy error = IdlingPolicies.getDynamicIdlingResourceErrorPolicy();
        final SignalingTask<Void> idleSignal =
            new SignalingTask<Void>(NO_OP, IdleCondition.DYNAMIC_TASKS_HAVE_IDLED, generation);
        idlingResourceRegistry.notifyWhenAllResourcesAreIdle(
            new IdleNotificationCallback() {
              @Override
              public void resourcesStillBusyWarning(List<String> busyResourceNames) {
                warning.handleTimeout(busyResourceNames, "IdlingResources are still busy!");
              }

              @Override
              public void resourcesHaveTimedOut(List<String> busyResourceNames) {
                error.handleTimeout(busyResourceNames, "IdlingResources have timed out!");
                controllerHandler.post(idleSignal);
              }

              @Override
              public void allResourcesIdle() {
                controllerHandler.post(idleSignal);
              }
            });
        condChecks.add(IdleCondition.DYNAMIC_TASKS_HAVE_IDLED);
      }

      try {
        loopUntil(condChecks);
      } finally {
        asyncTaskMonitor.cancelIdleMonitor();
        if (null != compatTaskMonitor) {
          compatTaskMonitor.cancelIdleMonitor();
        }
        idlingResourceRegistry.cancelIdleMonitor();
      }
    } while (!asyncTaskMonitor.isIdleNow()
        || !compatIdle()
        || !idlingResourceRegistry.allResourcesAreIdle());
  }