updater_sample: update tools

- Allow gen_update_config.py to use ota_from_target_files from
  $ANDROID_BUILD_TOP/build/make/tools/releasetools/
- tests/res/raw/ota_002_package.zip re-generated using functions from
  $ANDROID_BUILD_TOP/build/make/tools/releasetools/test_ota_from_target_files.py
- sample app tests updated

Test: ./tools/gen_update_config_test.py
Change-Id: I5c492ec22782ba54fe481f592a44e797c695684e
Signed-off-by: Zhomart Mukhamejanov <zhomart@google.com>
diff --git a/updater_sample/tests/src/com/example/android/systemupdatersample/util/FileDownloaderTest.java b/updater_sample/tests/src/com/example/android/systemupdatersample/util/FileDownloaderTest.java
index 80506ee..009610e 100644
--- a/updater_sample/tests/src/com/example/android/systemupdatersample/util/FileDownloaderTest.java
+++ b/updater_sample/tests/src/com/example/android/systemupdatersample/util/FileDownloaderTest.java
@@ -70,11 +70,11 @@
                 .toFile();
         Files.deleteIfExists(outFile.toPath());
         // download a chunk of ota.zip
-        FileDownloader downloader = new FileDownloader(url, 160, 8, outFile);
+        FileDownloader downloader = new FileDownloader(url, 1674, 12, outFile);
         downloader.download();
         String downloadedContent = String.join("\n", Files.readAllLines(outFile.toPath()));
         // archive contains text files with uppercase filenames
-        assertEquals("CARE_MAP", downloadedContent);
+        assertEquals("CARE_MAP-TXT", downloadedContent);
     }
 
 }
diff --git a/updater_sample/tests/src/com/example/android/systemupdatersample/util/PayloadSpecsTest.java b/updater_sample/tests/src/com/example/android/systemupdatersample/util/PayloadSpecsTest.java
index 2912e20..d9e5465 100644
--- a/updater_sample/tests/src/com/example/android/systemupdatersample/util/PayloadSpecsTest.java
+++ b/updater_sample/tests/src/com/example/android/systemupdatersample/util/PayloadSpecsTest.java
@@ -17,8 +17,6 @@
 package com.example.android.systemupdatersample.util;
 
 import static com.example.android.systemupdatersample.util.PackageFiles.PAYLOAD_BINARY_FILE_NAME;
-import static com.example.android.systemupdatersample.util.PackageFiles
-        .PAYLOAD_PROPERTIES_FILE_NAME;
 
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
@@ -29,6 +27,7 @@
 import android.support.test.runner.AndroidJUnit4;
 
 import com.example.android.systemupdatersample.PayloadSpec;
+import com.example.android.systemupdatersample.tests.R;
 import com.google.common.base.Charsets;
 import com.google.common.io.Files;
 
@@ -39,12 +38,8 @@
 import org.junit.runner.RunWith;
 
 import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.util.zip.CRC32;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipOutputStream;
+import java.nio.file.Paths;
 
 /**
  * Tests if PayloadSpecs parses update package zip file correctly.
@@ -54,12 +49,11 @@
 public class PayloadSpecsTest {
 
     private static final String PROPERTIES_CONTENTS = "k1=val1\nkey2=val2";
-    private static final String PAYLOAD_CONTENTS    = "hello\nworld";
-    private static final int PAYLOAD_SIZE           = PAYLOAD_CONTENTS.length();
 
     private File mTestDir;
 
     private Context mTargetContext;
+    private Context mTestContext;
 
     @Rule
     public final ExpectedException thrown = ExpectedException.none();
@@ -67,21 +61,30 @@
     @Before
     public void setUp() {
         mTargetContext = InstrumentationRegistry.getTargetContext();
+        mTestContext = InstrumentationRegistry.getContext();
 
         mTestDir = mTargetContext.getFilesDir();
     }
 
     @Test
     public void forNonStreaming_works() throws Exception {
-        File packageFile = createMockZipFile();
+        // Prepare the target file
+        File packageFile = Paths
+                .get(mTargetContext.getCacheDir().getAbsolutePath(), "ota.zip")
+                .toFile();
+        java.nio.file.Files.deleteIfExists(packageFile.toPath());
+        java.nio.file.Files.copy(mTestContext.getResources().openRawResource(R.raw.ota_002_package),
+                packageFile.toPath());
         PayloadSpec spec = PayloadSpecs.forNonStreaming(packageFile);
 
         assertEquals("correct url", "file://" + packageFile.getAbsolutePath(), spec.getUrl());
         assertEquals("correct payload offset",
                 30 + PAYLOAD_BINARY_FILE_NAME.length(), spec.getOffset());
-        assertEquals("correct payload size", PAYLOAD_SIZE, spec.getSize());
-        assertArrayEquals("correct properties",
-                new String[]{"k1=val1", "key2=val2"}, spec.getProperties().toArray(new String[0]));
+        assertEquals("correct payload size", 1392, spec.getSize());
+        assertEquals(4, spec.getProperties().size());
+        assertEquals(
+                "FILE_HASH=sEAK/NMbU7GGe01xt55FsPafIPk8IYyBOAd6SiDpiMs=",
+                spec.getProperties().get(0));
     }
 
     @Test
@@ -105,33 +108,6 @@
                 new String[]{"k1=val1", "key2=val2"}, spec.getProperties().toArray(new String[0]));
     }
 
-    /**
-     * Creates package zip file that contains payload.bin and payload_properties.txt
-     */
-    private File createMockZipFile() throws IOException {
-        File testFile = new File(mTestDir, "test.zip");
-        try (ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(testFile))) {
-            // Add payload.bin entry.
-            ZipEntry entry = new ZipEntry(PAYLOAD_BINARY_FILE_NAME);
-            entry.setMethod(ZipEntry.STORED);
-            entry.setCompressedSize(PAYLOAD_SIZE);
-            entry.setSize(PAYLOAD_SIZE);
-            CRC32 crc = new CRC32();
-            crc.update(PAYLOAD_CONTENTS.getBytes(StandardCharsets.UTF_8));
-            entry.setCrc(crc.getValue());
-            zos.putNextEntry(entry);
-            zos.write(PAYLOAD_CONTENTS.getBytes(StandardCharsets.UTF_8));
-            zos.closeEntry();
-
-            // Add payload properties entry.
-            ZipEntry propertiesEntry = new ZipEntry(PAYLOAD_PROPERTIES_FILE_NAME);
-            zos.putNextEntry(propertiesEntry);
-            zos.write(PROPERTIES_CONTENTS.getBytes(StandardCharsets.UTF_8));
-            zos.closeEntry();
-        }
-        return testFile;
-    }
-
     private File createMockPropertiesFile() throws IOException {
         File propertiesFile = new File(mTestDir, PackageFiles.PAYLOAD_PROPERTIES_FILE_NAME);
         Files.asCharSink(propertiesFile, Charsets.UTF_8).write(PROPERTIES_CONTENTS);