1
1
package fr .free .nrw .commons .upload ;
2
2
3
- import android .content .Context ;
4
- import android .net .Uri ;
5
-
6
3
import org .apache .commons .lang3 .StringUtils ;
7
4
8
- import java .io .IOException ;
9
-
10
5
import javax .inject .Inject ;
11
6
import javax .inject .Singleton ;
12
7
23
18
24
19
/**
25
20
* Methods for pre-processing images to be uploaded
26
- */ /*if (dataInBytes[0] == 70 && dataInBytes[1] == 66 && dataInBytes[2] == 77 && dataInBytes[3] == 68) {
27
- Timber.d("Contains FBMD");
28
- return Single.just(ImageUtils.FILE_FBMD);
29
- }*/
21
+ */
30
22
@ Singleton
31
23
public class ImageProcessingService {
32
24
private final FileUtilsWrapper fileUtilsWrapper ;
33
25
private final ImageUtilsWrapper imageUtilsWrapper ;
34
26
private final MediaWikiApi mwApi ;
35
27
private final ReadFBMD readFBMD ;
36
28
private final EXIFReader EXIFReader ;
37
- private final Context context ;
38
29
39
30
@ Inject
40
31
public ImageProcessingService (FileUtilsWrapper fileUtilsWrapper ,
41
32
ImageUtilsWrapper imageUtilsWrapper ,
42
- MediaWikiApi mwApi , ReadFBMD readFBMD , EXIFReader EXIFReader ,
43
- Context context ) {
33
+ MediaWikiApi mwApi , ReadFBMD readFBMD , EXIFReader EXIFReader ) {
44
34
this .fileUtilsWrapper = fileUtilsWrapper ;
45
35
this .imageUtilsWrapper = imageUtilsWrapper ;
46
36
this .mwApi = mwApi ;
47
37
this .readFBMD = readFBMD ;
48
38
this .EXIFReader = EXIFReader ;
49
- this .context = context ;
50
39
}
51
40
52
41
/**
@@ -64,12 +53,11 @@ Single<Integer> validateImage(UploadModel.UploadItem uploadItem, boolean checkTi
64
53
}
65
54
Timber .d ("Checking the validity of image" );
66
55
String filePath = uploadItem .getMediaUri ().getPath ();
67
- Uri contentUri =uploadItem .getContentUri ();
68
56
Single <Integer > duplicateImage = checkDuplicateImage (filePath );
69
57
Single <Integer > wrongGeoLocation = checkImageGeoLocation (uploadItem .getPlace (), filePath );
70
58
Single <Integer > darkImage = checkDarkImage (filePath );
71
59
Single <Integer > itemTitle = checkTitle ? validateItemTitle (uploadItem ) : Single .just (ImageUtils .IMAGE_OK );
72
- Single <Integer > checkFBMD = checkFBMD (context , contentUri );
60
+ Single <Integer > checkFBMD = checkFBMD (filePath );
73
61
Single <Integer > checkEXIF = checkEXIF (filePath );
74
62
75
63
Single <Integer > zipResult = Single .zip (duplicateImage , wrongGeoLocation , darkImage , itemTitle ,
@@ -84,31 +72,21 @@ Single<Integer> validateImage(UploadModel.UploadItem uploadItem, boolean checkTi
84
72
}
85
73
86
74
/**
87
- * Other than the Image quality we need to check that using this Image doesn't violate's facebook's copyright's.
88
- * Whenever a user tries to upload an image that was downloaded from Facebook then we warn the user with a message to stop the upload
89
- * To know whether the Image is downloaded from facebook:
90
- * -We read the metadata of any Image and check for FBMD
91
- * -Facebook downloaded image's contains metadata of the type IPTC
92
- * - From this IPTC metadata we extract a byte array that contains FBMD as it's initials. If the image was downloaded from facebook
93
- * Thus we successfully protect common's from Facebook's copyright violation
75
+ * We want to discourage users from uploading images to Commons that were taken from Facebook.
76
+ * This attempts to detect whether an image was downloaded from Facebook by heuristically
77
+ * searching for metadata that is specific to images that come from Facebook.
94
78
*/
95
-
96
- public Single <Integer > checkFBMD (Context context ,Uri contentUri ) {
97
- try {
98
- return readFBMD .processMetadata (context ,contentUri );
99
- } catch (IOException e ) {
100
- return Single .just (ImageUtils .FILE_FBMD );
101
- }
79
+ private Single <Integer > checkFBMD (String filepath ) {
80
+ return readFBMD .processMetadata (filepath );
102
81
}
103
82
104
83
/**
105
- * To avoid copyright we check for EXIF data in any image.
106
- * Images that are downloaded from internet generally don't have any EXIF data in them
107
- * while images taken via camera or screenshots in phone have EXIF data with them.
108
- * So we check if the image has no EXIF data then we display a warning to the user
109
- * * */
110
-
111
- public Single <Integer > checkEXIF (String filepath ){
84
+ * We try to minimize uploads from the Commons app that might be copyright violations.
85
+ * If an image does not have any Exif metadata, then it was likely downloaded from the internet,
86
+ * and is probably not an original work by the user. We detect these kinds of images by looking
87
+ * for the presence of some basic Exif metadata.
88
+ */
89
+ private Single <Integer > checkEXIF (String filepath ) {
112
90
return EXIFReader .processMetadata (filepath );
113
91
}
114
92
0 commit comments