/** Ensure that the flasher instance limiting machinery is working as expected. */
  public void testUnlimitedFlashLimit() throws Exception {
    final DeviceFlashPreparer dfp = mDeviceFlashPreparer;
    try {
      Thread waiter =
          new Thread() {
            @Override
            public void run() {
              dfp.takeFlashingPermit();
              dfp.returnFlashingPermit();
            }
          };
      dfp.setConcurrentFlashSettings(null, null, true);
      // take a permit; the next attempt to take the permit should proceed without blocking
      dfp.takeFlashingPermit();
      assertNull("Flash lock is non-null", dfp.getConcurrentFlashLock());

      waiter.start();
      RunUtil.getDefault().sleep(100); // Thread start should take <100ms
      Thread.State waiterState = waiter.getState();
      assertTrue(
          "Invalid state: waiter thread hasn't started",
          waiter.isAlive() || Thread.State.TERMINATED.equals(waiterState));
      assertNull("Flash lock is non-null", dfp.getConcurrentFlashLock());

      dfp.returnFlashingPermit();
      RunUtil.getDefault().sleep(100); // Thread start should take <100ms
      assertNull("Flash lock is non-null", dfp.getConcurrentFlashLock());

      waiter.join(1000);
      assertFalse("waiter thread has not returned", waiter.isAlive());
    } finally {
      // Attempt to reset concurrent flash settings to defaults
      dfp.setConcurrentFlashSettings(null, null, true);
    }
  }
Example #2
0
 private static String threadStatusToJavaThreadState(int status) {
   switch (status) {
     case ThreadReference.THREAD_STATUS_MONITOR:
       return Thread.State.BLOCKED.name();
     case ThreadReference.THREAD_STATUS_NOT_STARTED:
       return Thread.State.NEW.name();
     case ThreadReference.THREAD_STATUS_RUNNING:
       return Thread.State.RUNNABLE.name();
     case ThreadReference.THREAD_STATUS_SLEEPING:
       return Thread.State.TIMED_WAITING.name();
     case ThreadReference.THREAD_STATUS_WAIT:
       return Thread.State.WAITING.name();
     case ThreadReference.THREAD_STATUS_ZOMBIE:
       return Thread.State.TERMINATED.name();
     case ThreadReference.THREAD_STATUS_UNKNOWN:
       return "unknown";
     default:
       return "undefined";
   }
 }