Fix installing dumpstate test data

The dumpstate test data was being copied to
$OUT/data/nativetest/dumpstate_test_fixture, but then
LOCAL_PICKUP_FILES was set to $OUT/data, which pulls in everything
that has been installed to /data.  This results in lots of extra
files in the *tests.zip files.

Copy the test data to the intermediates directory for use with
LOCAL_PICKUP_FILES, and then again again to $OUT/data for use with
adb sync.

Bug: 30564705
Bug: 31807540
Bug: 31997691
Test: mma -j, test data is installed to $OUT/data and intermediates/DATA
Test: adb sync && adb shell /data/nativetest/dumpstate_test/dumpstate_test
Change-Id: Iaa83d96e5d23788b301fed8819a446baf127b58e
diff --git a/cmds/dumpstate/Android.mk b/cmds/dumpstate/Android.mk
index 2b23a3d..178ecdd 100644
--- a/cmds/dumpstate/Android.mk
+++ b/cmds/dumpstate/Android.mk
@@ -152,19 +152,32 @@
 LOCAL_SRC_FILES := \
         tests/dumpstate_test_fixture.cpp
 
-dist_zip_root := $(TARGET_OUT_DATA)
+LOCAL_MODULE_CLASS := NATIVE_TESTS
+
+dumpstate_tests_intermediates := $(local-intermediates-dir)/DATA
 dumpstate_tests_subpath_from_data := nativetest/dumpstate_test_fixture
 dumpstate_tests_root_in_device := /data/$(dumpstate_tests_subpath_from_data)
-dumpstate_tests_root_for_test_zip := $(dist_zip_root)/$(dumpstate_tests_subpath_from_data)
+dumpstate_tests_root_for_test_zip := $(dumpstate_tests_intermediates)/$(dumpstate_tests_subpath_from_data)
 testdata_files := $(call find-subdir-files, testdata/*)
 
+# Copy test data files to intermediates/DATA for use with LOCAL_PICKUP_FILES
 GEN := $(addprefix $(dumpstate_tests_root_for_test_zip)/, $(testdata_files))
 $(GEN): PRIVATE_PATH := $(LOCAL_PATH)
 $(GEN): PRIVATE_CUSTOM_TOOL = cp $< $@
 $(GEN): $(dumpstate_tests_root_for_test_zip)/testdata/% : $(LOCAL_PATH)/testdata/%
 	$(transform-generated-source)
 LOCAL_GENERATED_SOURCES += $(GEN)
-LOCAL_PICKUP_FILES := $(dist_zip_root)
+
+# Copy test data files again to $OUT/data so the tests can be run with adb sync
+# TODO: the build system should do this automatically
+GEN := $(addprefix $(TARGET_OUT_DATA)/$(dumpstate_tests_subpath_from_data)/, $(testdata_files))
+$(GEN): PRIVATE_PATH := $(LOCAL_PATH)
+$(GEN): PRIVATE_CUSTOM_TOOL = cp $< $@
+$(GEN): $(TARGET_OUT_DATA)/$(dumpstate_tests_subpath_from_data)/testdata/% : $(LOCAL_PATH)/testdata/%
+	$(transform-generated-source)
+LOCAL_GENERATED_SOURCES += $(GEN)
+
+LOCAL_PICKUP_FILES := $(dumpstate_tests_intermediates)
 
 include $(BUILD_NATIVE_TEST)