@Override
 protected void tearDown() throws Exception {
   // Delete the temp files
   for (File ref : mReferences.values()) {
     ref.delete();
   }
   mExecutionService.shutdown();
   // Remove the APK.
   mDevice.uninstallPackage(PACKAGE);
   super.tearDown();
 }
  @Override
  protected void setUp() throws Exception {
    super.setUp();
    // Get the device, this gives a handle to run commands and install APKs.
    mDevice = getDevice();
    // Remove any previously installed versions of this APK.
    mDevice.uninstallPackage(PACKAGE);
    // Get the APK from the build.
    File app = mBuild.getTestApp(APK);
    // Get the ABI flag.
    String[] options = {AbiUtils.createAbiFlag(mAbi.getName())};
    // Install the APK on the device.
    mDevice.installPackage(app, false, options);

    final String densityProp;

    if (mDevice.getSerialNumber().startsWith("emulator-")) {
      densityProp = DENSITY_PROP_EMULATOR;
    } else {
      densityProp = DENSITY_PROP_DEVICE;
    }

    final String zip =
        String.format(
            "/%s.zip", getDensityBucket(Integer.parseInt(mDevice.getProperty(densityProp))));
    Log.logAndDisplay(LogLevel.INFO, TAG, "Loading resources from " + zip);

    final InputStream zipStream = this.getClass().getResourceAsStream(zip);
    if (zipStream != null) {
      final ZipInputStream in = new ZipInputStream(zipStream);
      try {
        ZipEntry ze;
        final byte[] buffer = new byte[1024];
        while ((ze = in.getNextEntry()) != null) {
          final String name = ze.getName();
          final File tmp = File.createTempFile("ref_" + name, ".png");
          final FileOutputStream out = new FileOutputStream(tmp);
          int count;
          while ((count = in.read(buffer)) != -1) {
            out.write(buffer, 0, count);
          }
          out.flush();
          out.close();
          mReferences.put(name, tmp);
        }
      } finally {
        in.close();
      }
    }

    mExecutionService = Executors.newFixedThreadPool(2); // 2 worker threads
    mCompletionService = new ExecutorCompletionService<Boolean>(mExecutionService);
  }
Beispiel #3
0
 @Override
 protected void tearDown() throws Exception {
   mDevice.uninstallPackage(PACKAGE);
   super.tearDown();
 }
Beispiel #4
0
 @Override
 protected void tearDown() throws Exception {
   super.tearDown();
   mDevice.uninstallPackage(PACKAGE);
   mReport.throwReportToHost();
 }