-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[WIP] Implements of in-app EXIF and location anonymization #1712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
f117b3f
build.gradle: add ExifInterface support library
ilgazer 827f3e0
FileProcessor: implement methods for EXIF and location anonymization
ilgazer 8c1430e
MultipleShareActivity: upload anonymized photo and coords
ilgazer ad312b4
preferences: add global options for anonymization
ilgazer 35ce75a
strings.xml:added strings
ilgazer fe3b4f6
ShareActivity: upload anonymized photo and coords
ilgazer 7c988db
resolved merge conflicts.
ilgazer daf170f
Revert "strings.xml:added strings" as it had whitespace issues
ilgazer 5f8a2f1
strings.xml:added strings for anonymization prefs
ilgazer 4a39818
Merge branch 'master' into master
ilgazer 8e42038
strings.xml:remove duplicate string
ilgazer 78f5e9f
preferences.xml:fixed merge errors
ilgazer 671782c
Merge branch 'master' into master
ilgazer 40b02a6
strings.xml:fixed merge errors
ilgazer 86e43d7
prefs: Migrate new preferences to LongTitle versions.
ilgazer fcf368c
Merge branch 'master' into master
ilgazer eaed89d
Implement wholesale XMP Data removal. Implement better system for mat…
ilgazer eff6b95
SettingsActivityTest: Implemented support for preferences of type Set
ilgazer f10cd68
Merge branch 'master' into master
ilgazer a790ec4
Merge branch 'master' into master
ilgazer bc0157b
Added default value for location preference.
ilgazer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
.../java/fr/free/nrw/commons/ui/LongTitlePreferences/LongTitleMultiSelectListPreference.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package fr.free.nrw.commons.ui.LongTitlePreferences; | ||
|
|
||
| import android.content.Context; | ||
| import android.preference.MultiSelectListPreference; | ||
| import android.util.AttributeSet; | ||
| import android.view.View; | ||
| import android.widget.TextView; | ||
|
|
||
| /** | ||
| * Created by Ilgaz Er on 7/31/2018. | ||
| */ | ||
| public class LongTitleMultiSelectListPreference extends MultiSelectListPreference { | ||
| public LongTitleMultiSelectListPreference(Context context, AttributeSet attrs) { | ||
| super(context, attrs); | ||
| } | ||
|
|
||
| public LongTitleMultiSelectListPreference(Context context) { | ||
| super(context); | ||
| } | ||
|
|
||
| @Override | ||
| protected void onBindView(View view) { | ||
| super.onBindView(view); | ||
|
|
||
| TextView title = view.findViewById(android.R.id.title); | ||
| if (title != null) { | ||
| title.setSingleLine(false); | ||
| } | ||
| } | ||
| } | ||
102 changes: 102 additions & 0 deletions
102
app/src/main/java/fr/free/nrw/commons/upload/FileMetadataUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| package fr.free.nrw.commons.upload; | ||
|
|
||
| import java.io.BufferedInputStream; | ||
| import java.io.BufferedOutputStream; | ||
| import java.io.File; | ||
| import java.io.FileInputStream; | ||
| import java.io.FileOutputStream; | ||
| import java.io.IOException; | ||
|
|
||
| import io.reactivex.Observable; | ||
| import timber.log.Timber; | ||
|
|
||
| import static android.support.media.ExifInterface.*; | ||
| import static fr.free.nrw.commons.Utils.checkNotNull; | ||
|
|
||
| public class FileMetadataUtils { | ||
|
|
||
|
|
||
| public static Observable<String> getTagsFromPref(String pref) { | ||
| Timber.d("Retuning tags for pref:" + pref); | ||
| switch (pref) { | ||
| case "Author": | ||
| return Observable.fromArray(TAG_ARTIST, TAG_CAMARA_OWNER_NAME); | ||
| case "Copyright": | ||
| return Observable.fromArray(TAG_COPYRIGHT); | ||
| case "Camera Model": | ||
| return Observable.fromArray(TAG_MAKE, TAG_MODEL); | ||
| case "Lens Model": | ||
| return Observable.fromArray(TAG_LENS_MAKE, TAG_LENS_MODEL, TAG_LENS_SPECIFICATION); | ||
| case "Serial Numbers": | ||
| return Observable.fromArray(TAG_BODY_SERIAL_NUMBER, TAG_LENS_SERIAL_NUMBER); | ||
| case "Software": | ||
| return Observable.fromArray(TAG_SOFTWARE); | ||
| default: | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Removes all XMP data from the input file and writes the rest of the image to a new file. | ||
| * | ||
| * This works by black magic. Pleae read the JPEG section of the XMP Spesification Part 3 before making changes. | ||
| * https://wwwimages2.adobe.com/content/dam/acom/en/devnet/xmp/pdfs/XMP%20SDK%20Release%20cc-2016-08/XMPSpecificationPart3.pdf | ||
| * | ||
| * @param inputPath the path of the input file | ||
| * @param outputPath the path of the new file | ||
| */ | ||
| public static void removeXmpAndWriteToFile(String inputPath, String outputPath) { | ||
| try (BufferedInputStream is = new BufferedInputStream(new FileInputStream(inputPath)); | ||
| BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputPath))) { | ||
| int next = 0; | ||
| while (next != -1) { | ||
| next = is.read(); | ||
| //Detect first byte of FF E1, the code of APP1 marker | ||
| if (next == 0xFF) { | ||
| next = is.read(); | ||
| if (next == 0xE1) { | ||
| Timber.i("Found FF E1"); | ||
| //2 bytes that contain the length of the APP1 section. | ||
| byte Lp1 = (byte) is.read(); | ||
| byte Lp2 = (byte) is.read(); | ||
| Timber.i(Integer.toHexString(Lp1)); | ||
| Timber.i(Integer.toHexString(Lp2)); | ||
| //The identifier of the APP1 section, we find out if this section contains XMP data or not. | ||
| byte[] namespace = new byte[28]; | ||
| if (is.read(namespace, 0, 28) != 28) | ||
| throw new IOException("Wrong amount of bytes read."); | ||
| Timber.i(new String(namespace, "UTF-8")); | ||
| if (new String(namespace, "UTF-8").equals("http://ns.adobe.com/xap/1.0/")) { | ||
| Timber.i("Found XMP marker"); | ||
| while (next != 0xFF) { | ||
| if (next == -1) | ||
| throw new IOException("Unexpected end of file."); | ||
| next = is.read(); | ||
| } | ||
| //FF means the start of the next marker. | ||
| // This means the XMP section is finished and that we should resume copying. | ||
| outputStream.write(0xFF); | ||
| } else { | ||
| //Write everything back to the output file as we want to leave non-XMP APP1 sections as-is. | ||
| Timber.i("Not XMP marker"); | ||
| outputStream.write(0xFF); | ||
| outputStream.write(0xE1); | ||
| outputStream.write(Lp1); | ||
| outputStream.write(Lp2); | ||
| outputStream.write(namespace); | ||
| } | ||
| } else { | ||
| outputStream.write(0xFF); | ||
| outputStream.write(next); | ||
| } | ||
| } else { | ||
| outputStream.write(next); | ||
| } | ||
| } | ||
| } catch (IOException e) { | ||
| Timber.e(e); | ||
| } | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove author tags, I know Android Studio automatically adds them, but our code style discourages them. :)