diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..09e1d5f5 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "scrambler"] + path = scrambler + url = https://gitlab.com/artectrex/scrambler.git diff --git a/app/build.gradle b/app/build.gradle index b2715169..152626c1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -200,6 +200,7 @@ dependencies { implementation 'info.androidhive:imagefilters:1.0.7' implementation 'com.github.yalantis:ucrop:2.2.8-native' + implementation project(path: ':scrambler') implementation('com.github.bumptech.glide:glide:4.14.2') { exclude group: "com.android.support" diff --git a/app/src/main/java/org/pixeldroid/app/postCreation/PostCreationViewModel.kt b/app/src/main/java/org/pixeldroid/app/postCreation/PostCreationViewModel.kt index 3ab8e944..ef754972 100644 --- a/app/src/main/java/org/pixeldroid/app/postCreation/PostCreationViewModel.kt +++ b/app/src/main/java/org/pixeldroid/app/postCreation/PostCreationViewModel.kt @@ -13,6 +13,7 @@ import androidx.core.net.toUri import androidx.lifecycle.* import androidx.preference.PreferenceManager import com.arthenica.ffmpegkit.FFmpegKit +import com.jarsilio.android.scrambler.exceptions.UnsupportedFileFormatException import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers import io.reactivex.rxjava3.disposables.Disposable import io.reactivex.rxjava3.schedulers.Schedulers @@ -30,6 +31,7 @@ import org.pixeldroid.app.utils.PixelDroidApplication import org.pixeldroid.app.utils.api.objects.Attachment import org.pixeldroid.app.utils.db.entities.InstanceDatabaseEntity import org.pixeldroid.app.utils.di.PixelfedAPIHolder +import org.pixeldroid.app.utils.fileExtension import org.pixeldroid.app.utils.getMimeType import retrofit2.HttpException import java.io.File @@ -37,6 +39,7 @@ import java.io.FileNotFoundException import java.io.IOException import javax.inject.Inject import kotlin.math.ceil +import com.jarsilio.android.scrambler.stripMetadata // Models the UI state for the PostCreationActivity data class PostCreationActivityUiState( @@ -233,6 +236,7 @@ class PostCreationViewModel(application: Application, clipdata: ClipData? = null * Keeps track of them in the [PhotoData.progress] (for the upload progress), and the * [PhotoData.uploadId] (for the list of ids of the uploads). */ + @OptIn(ExperimentalUnsignedTypes::class) fun upload() { _uiState.update { currentUiState -> currentUiState.copy( @@ -247,21 +251,40 @@ class PostCreationViewModel(application: Application, clipdata: ClipData? = null } for (data: PhotoData in getPhotoData().value ?: emptyList()) { - val imageUri = data.imageUri - val imageInputStream = try { - getApplication().contentResolver.openInputStream(imageUri)!! + val extension = data.imageUri.fileExtension(getApplication().contentResolver) + + val strippedImage = File.createTempFile("temp_img", ".$extension", getApplication().cacheDir) + + val (strippedOrNot, size) = try { + stripMetadata(data.imageUri, strippedImage, getApplication().contentResolver) + Pair(strippedImage.inputStream(), strippedImage.length()) } catch (e: FileNotFoundException){ + strippedImage.delete() _uiState.update { currentUiState -> currentUiState.copy( userMessage = getApplication().getString(R.string.file_not_found, - imageUri) + data.imageUri) ) } return + } catch (e: UnsupportedFileFormatException){ + strippedImage.delete() + val imageInputStream = try { + getApplication().contentResolver.openInputStream(data.imageUri)!! + } catch (e: FileNotFoundException){ + _uiState.update { currentUiState -> + currentUiState.copy( + userMessage = getApplication().getString(R.string.file_not_found, + data.imageUri) + ) + } + return + } + Pair(imageInputStream, data.size) } - val type = imageUri.getMimeType(getApplication().contentResolver) - val imagePart = ProgressRequestBody(imageInputStream, data.size, type) + val type = data.imageUri.getMimeType(getApplication().contentResolver) + val imagePart = ProgressRequestBody(strippedOrNot, size, type) val requestBody = MultipartBody.Builder() .setType(MultipartBody.FORM) .addFormDataPart("file", System.currentTimeMillis().toString(), imagePart) @@ -303,11 +326,13 @@ class PostCreationViewModel(application: Application, clipdata: ClipData? = null uploadErrorExplanationVisible = e is HttpException, ) } + strippedImage.delete() e.printStackTrace() postSub?.dispose() sub.dispose() }, { + strippedImage.delete() data.progress = 100 if (getPhotoData().value!!.all { it.progress == 100 && it.uploadId != null }) { _uiState.update { currentUiState -> diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index e470ce24..3cb4cadb 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -6,6 +6,9 @@ + + + @@ -65,6 +68,9 @@ + + + @@ -77,6 +83,14 @@ + + + + + + + + @@ -187,6 +201,14 @@ + + + + + + + + @@ -327,6 +349,14 @@ + + + + + + + + @@ -349,6 +379,14 @@ + + + + + + + + @@ -512,6 +550,14 @@ + + + + + + + + @@ -568,6 +614,14 @@ + + + + + + + + @@ -616,6 +670,14 @@ + + + + + + + + @@ -672,6 +734,14 @@ + + + + + + + + @@ -723,6 +793,14 @@ + + + + + + + + @@ -774,6 +852,14 @@ + + + + + + + + @@ -825,6 +911,14 @@ + + + + + + + + @@ -949,6 +1043,9 @@ + + + @@ -1056,6 +1153,9 @@ + + + @@ -1068,6 +1168,14 @@ + + + + + + + + @@ -1117,6 +1225,14 @@ + + + + + + + + @@ -1168,6 +1284,14 @@ + + + + + + + + @@ -1255,6 +1379,11 @@ + + + + + @@ -1264,6 +1393,9 @@ + + + @@ -1348,6 +1480,9 @@ + + + @@ -1401,6 +1536,14 @@ + + + + + + + + @@ -1770,6 +1913,11 @@ + + + + + @@ -1778,6 +1926,14 @@ + + + + + + + + @@ -1949,6 +2105,9 @@ + + + @@ -2364,6 +2523,14 @@ + + + + + + + + @@ -2420,6 +2587,14 @@ + + + + + + + + @@ -2476,6 +2651,14 @@ + + + + + + + + @@ -2612,6 +2795,14 @@ + + + + + + + + @@ -2668,6 +2859,14 @@ + + + + + + + + @@ -2772,6 +2971,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + @@ -2828,6 +3051,14 @@ + + + + + + + + @@ -2884,6 +3115,14 @@ + + + + + + + + @@ -2940,6 +3179,14 @@ + + + + + + + + @@ -2996,6 +3243,14 @@ + + + + + + + + @@ -3052,6 +3307,14 @@ + + + + + + + + @@ -3108,6 +3371,14 @@ + + + + + + + + @@ -3164,6 +3435,14 @@ + + + + + + + + @@ -3212,6 +3491,14 @@ + + + + + + + + @@ -3276,6 +3563,14 @@ + + + + + + + + @@ -3332,6 +3627,14 @@ + + + + + + + + @@ -3388,6 +3691,14 @@ + + + + + + + + @@ -3444,6 +3755,14 @@ + + + + + + + + @@ -3500,6 +3819,14 @@ + + + + + + + + @@ -3556,6 +3883,14 @@ + + + + + + + + @@ -3612,6 +3947,14 @@ + + + + + + + + @@ -3692,6 +4035,14 @@ + + + + + + + + @@ -3748,6 +4099,14 @@ + + + + + + + + @@ -3772,6 +4131,14 @@ + + + + + + + + @@ -3828,6 +4195,14 @@ + + + + + + + + @@ -3908,6 +4283,14 @@ + + + + + + + + @@ -3924,6 +4307,22 @@ + + + + + + + + + + + + + + + + @@ -3940,6 +4339,22 @@ + + + + + + + + + + + + + + + + @@ -3956,6 +4371,22 @@ + + + + + + + + + + + + + + + + @@ -4012,6 +4443,14 @@ + + + + + + + + @@ -4028,6 +4467,22 @@ + + + + + + + + + + + + + + + + @@ -4044,6 +4499,22 @@ + + + + + + + + + + + + + + + + @@ -4060,6 +4531,22 @@ + + + + + + + + + + + + + + + + @@ -4076,6 +4563,22 @@ + + + + + + + + + + + + + + + + @@ -4132,6 +4635,14 @@ + + + + + + + + @@ -4188,6 +4699,14 @@ + + + + + + + + @@ -4244,6 +4763,14 @@ + + + + + + + + @@ -4300,6 +4827,14 @@ + + + + + + + + @@ -4356,6 +4891,14 @@ + + + + + + + + @@ -4412,6 +4955,14 @@ + + + + + + + + @@ -4468,6 +5019,14 @@ + + + + + + + + @@ -4524,6 +5083,14 @@ + + + + + + + + @@ -4606,6 +5173,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -5485,6 +6105,22 @@ + + + + + + + + + + + + + + + + @@ -5517,6 +6153,14 @@ + + + + + + + + @@ -5819,6 +6463,22 @@ + + + + + + + + + + + + + + + + @@ -6384,6 +7044,9 @@ + + + @@ -6797,6 +7460,14 @@ + + + + + + + + @@ -6805,6 +7476,14 @@ + + + + + + + + @@ -7225,6 +7904,19 @@ + + + + + + + + + + + + + @@ -7410,6 +8102,14 @@ + + + + + + + + @@ -8255,6 +8955,11 @@ + + + + + @@ -8839,6 +9544,11 @@ + + + + + diff --git a/scrambler b/scrambler new file mode 160000 index 00000000..961934d4 --- /dev/null +++ b/scrambler @@ -0,0 +1 @@ +Subproject commit 961934d4c4ff8127e89a16ec1169b5bff7136820 diff --git a/settings.gradle b/settings.gradle index 34852a76..754d9b25 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1,4 @@ rootProject.name='PixelDroid' include ':app' +include ':scrambler' +project(':scrambler').projectDir = new File(rootDir, 'scrambler/scrambler/')