Image EXIF/XMP metadata removal routine (#2863)

* [WIP] Added preferences for EXIF tags

* [WIP] Added arrays, keys, strings to support EXIF preferences

* [WIP] Updated SettingsFragment to setup summary of added preferences(locationAccuracy)

* [WIP] Added methods getStringSet()in BasicKvStore, KeyValueStore to support Set<String> data type used in preferences (EXIF tags)

* [WIP] Added methods for removing EXIF tags and anonimyzing location coordinates in FileProcessor, GPSExtractor

* [WIP] Fixed errors in preferences EXIF tags, added XMP removal routine

* [WIP] Removed erroneous location accuracy handling

* [WIP] Fixed mistyped GPS Tags

* Reverted BasicKvStore. Removed Set<String> support in BasicKvStore as JsonKVStore already has it.

* FileProcessor: Replaced throwing runtime exception with warning if EXIF redaction fails.

* FileMetadataUtils: Javadoc added

* [WIP] FileMetadataUtilsTest added

* [WIP] FileMetadataUtilsTest: added javadoc

* [WIP] FileMetadataUtilsTest: added javadoc

* [WIP] FileProcessor: fixed disposing observables

* [WIP] FileMetadataUtils.getTagsFromPref: changed return type from observable to simple array

* [WIP] FileProcessorTest: added test for redactExifTags

* [WIP] FileProcessorTest: redactExifTags() doesn't work properly
This commit is contained in:
Vitaly V. Pinchuk 2019-06-04 15:38:01 +03:00 committed by neslihanturan
parent 5690dd9d0b
commit cc0b059595
13 changed files with 291 additions and 2 deletions

View file

@ -0,0 +1,23 @@
package fr.free.nrw.commons.upload
import androidx.exifinterface.media.ExifInterface.*
import junit.framework.Assert.assertTrue
import org.junit.Test
import java.util.*
/**
* Test cases for FileMetadataUtils
*/
class FileMetadataUtilsTest {
/**
* Test method to verify EXIF tags
*/
@Test
fun getTagsFromPref() {
val author = FileMetadataUtils.getTagsFromPref("Author")
val authorRef = arrayOf(TAG_ARTIST, TAG_CAMARA_OWNER_NAME);
assertTrue(Arrays.deepEquals(author, authorRef))
}
}

View file

@ -1,6 +1,7 @@
package fr.free.nrw.commons.upload
import android.content.SharedPreferences
import androidx.exifinterface.media.ExifInterface
import fr.free.nrw.commons.caching.CacheController
import fr.free.nrw.commons.mwapi.CategoryApi
import org.junit.Before
@ -11,6 +12,9 @@ import org.mockito.MockitoAnnotations
import javax.inject.Inject
import javax.inject.Named
import java.io.FileInputStream
import java.io.FileOutputStream
class FileProcessorTest {
@Mock
@ -35,4 +39,51 @@ class FileProcessorTest {
fun processFileCoordinates() {
}
/**
* Test method to verify redaction Exif metadata
*/
@Test
fun redactExifTags() {
/*
val filePathRef: String? = "src/test/data/exif_redact_sample.jpg"
val filePathTmp: String? = "" + System.getProperty("java.io.tmpdir") + "exif_redact_sample_tmp.jpg"
val inStream = FileInputStream(filePathRef)
val outStream = FileOutputStream(filePathTmp)
val inChannel = inStream.getChannel()
val outChannel = outStream.getChannel()
inChannel.transferTo(0, inChannel.size(), outChannel)
inStream.close()
outStream.close()
val redactTags = mutableSetOf("Author", "Copyright", "Location", "Camera Model",
"Lens Model", "Serial Numbers", "Software")
val exifInterface : ExifInterface? = ExifInterface(filePathTmp.toString())
var nonEmptyTag = false
for (redactTag in redactTags) {
for (tag in FileMetadataUtils.getTagsFromPref(redactTag)) {
val tagValue = exifInterface?.getAttribute(tag)
if(tagValue != null) {
nonEmptyTag = true
break
}
}
if (nonEmptyTag) break
}
// all tags are empty, can't test redaction
assert(nonEmptyTag)
FileProcessor.redactExifTags(exifInterface, redactTags)
for (redactTag in redactTags) {
for (tag in FileMetadataUtils.getTagsFromPref(redactTag)) {
val oldValue = exifInterface?.getAttribute(tag)
assert(oldValue == null)
}
}
*/
}
}