From 941cd1cb8daf646c63e93da114d8a8231cd0f183 Mon Sep 17 00:00:00 2001 From: D N <4661784+retyui@users.noreply.github.com> Date: Wed, 2 Dec 2026 15:11:17 +0100 Subject: [PATCH 1/2] fix(android): keep cropped images and their Exif data off external storage `createTempFile` picked whichever cache dir had more free space, which in practice means external storage on most devices. A crop inherits the original's Exif data, so GPS coordinates and the device serial ended up in a file in a shared location, readable by any app holding `READ_EXTERNAL_STORAGE` on API <= 29, and left there until the next launch cleaned it up. iOS discards Exif on re-encode, so this was Android-only. Write crops to the internal cache dir, keeping external storage as the fallback it already was when there is no internal one. `cleanTask` already sweeps both dirs, so nothing is left behind. Also stop copying the GPS tags: the crop is a new picture the user may share on its own, and it should not carry where the original was taken. The tags that describe how the image was shot, orientation included, are still carried over. (`TAG_GPS_STATUS` was listed twice; both are gone.) --- .../imageeditor/ImageEditorModuleImpl.kt | 56 ++++--------------- 1 file changed, 10 insertions(+), 46 deletions(-) diff --git a/android/src/main/java/com/reactnativecommunity/imageeditor/ImageEditorModuleImpl.kt b/android/src/main/java/com/reactnativecommunity/imageeditor/ImageEditorModuleImpl.kt index 53a92f3..c24798f 100644 --- a/android/src/main/java/com/reactnativecommunity/imageeditor/ImageEditorModuleImpl.kt +++ b/android/src/main/java/com/reactnativecommunity/imageeditor/ImageEditorModuleImpl.kt @@ -423,6 +423,11 @@ class ImageEditorModuleImpl(private val reactContext: ReactApplicationContext) { ) private const val TEMP_FILE_PREFIX = "ReactNative_cropped_image_" + /** + * Copied onto the cropped JPEG. Geolocation tags are deliberately absent: a crop is a new + * picture the user may share on its own, and it should not carry where the original + * happened to be taken. + */ @SuppressLint("InlinedApi") private val EXIF_ATTRIBUTES = arrayOf( @@ -461,38 +466,6 @@ class ImageEditorModuleImpl(private val reactContext: ReactApplicationContext) { ExifInterface.TAG_F_NUMBER, ExifInterface.TAG_GAIN_CONTROL, ExifInterface.TAG_GAMMA, - ExifInterface.TAG_GPS_ALTITUDE, - ExifInterface.TAG_GPS_ALTITUDE_REF, - ExifInterface.TAG_GPS_AREA_INFORMATION, - ExifInterface.TAG_GPS_DATESTAMP, - ExifInterface.TAG_GPS_DOP, - ExifInterface.TAG_GPS_LATITUDE, - ExifInterface.TAG_GPS_LATITUDE_REF, - ExifInterface.TAG_GPS_LONGITUDE, - ExifInterface.TAG_GPS_LONGITUDE_REF, - ExifInterface.TAG_GPS_STATUS, - ExifInterface.TAG_GPS_DEST_BEARING, - ExifInterface.TAG_GPS_DEST_BEARING_REF, - ExifInterface.TAG_GPS_DEST_DISTANCE, - ExifInterface.TAG_GPS_DEST_DISTANCE_REF, - ExifInterface.TAG_GPS_DEST_LATITUDE, - ExifInterface.TAG_GPS_DEST_LATITUDE_REF, - ExifInterface.TAG_GPS_DEST_LONGITUDE, - ExifInterface.TAG_GPS_DEST_LONGITUDE_REF, - ExifInterface.TAG_GPS_DIFFERENTIAL, - ExifInterface.TAG_GPS_IMG_DIRECTION, - ExifInterface.TAG_GPS_IMG_DIRECTION_REF, - ExifInterface.TAG_GPS_MAP_DATUM, - ExifInterface.TAG_GPS_MEASURE_MODE, - ExifInterface.TAG_GPS_PROCESSING_METHOD, - ExifInterface.TAG_GPS_SATELLITES, - ExifInterface.TAG_GPS_SPEED, - ExifInterface.TAG_GPS_SPEED_REF, - ExifInterface.TAG_GPS_STATUS, - ExifInterface.TAG_GPS_TIMESTAMP, - ExifInterface.TAG_GPS_TRACK, - ExifInterface.TAG_GPS_TRACK_REF, - ExifInterface.TAG_GPS_VERSION_ID, ExifInterface.TAG_IMAGE_DESCRIPTION, ExifInterface.TAG_IMAGE_UNIQUE_ID, ExifInterface.TAG_ISO_SPEED, @@ -664,27 +637,18 @@ class ImageEditorModuleImpl(private val reactContext: ReactApplicationContext) { } /** - * Create a temporary file in the cache directory on either internal or external storage, - * whichever is available and has more free space. + * Create a temporary file in the app's internal cache directory. External storage is only + * a fallback for the rare case where there is no internal cache dir: a crop inherits the + * original's Exif data, and external storage is readable by other apps on API <= 29. * * @param mimeType the MIME type of the file to create (image/ *) */ @Throws(IOException::class) private fun createTempFile(context: Context, mimeType: String?): File { - val externalCacheDir = context.externalCacheDir - val internalCacheDir = context.cacheDir - if (externalCacheDir == null && internalCacheDir == null) { + val cacheDir = context.cacheDir ?: context.externalCacheDir + if (cacheDir == null) { throw IOException("No cache directory available") } - val cacheDir: File? = - if (externalCacheDir == null) { - internalCacheDir - } else if (internalCacheDir == null) { - externalCacheDir - } else { - if (externalCacheDir.freeSpace > internalCacheDir.freeSpace) externalCacheDir - else internalCacheDir - } return File.createTempFile( TEMP_FILE_PREFIX, getFileExtensionForType(mimeType), From 2e8407eb014845afee870776f2e6ba361570a4df Mon Sep 17 00:00:00 2001 From: D N <4661784+retyui@users.noreply.github.com> Date: Thu, 3 Dec 2026 10:34:44 +0100 Subject: [PATCH 2/2] style(android): apply spotless formatting --- .../reactnativecommunity/imageeditor/ImageEditorModuleImpl.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/android/src/main/java/com/reactnativecommunity/imageeditor/ImageEditorModuleImpl.kt b/android/src/main/java/com/reactnativecommunity/imageeditor/ImageEditorModuleImpl.kt index c24798f..8d0cb56 100644 --- a/android/src/main/java/com/reactnativecommunity/imageeditor/ImageEditorModuleImpl.kt +++ b/android/src/main/java/com/reactnativecommunity/imageeditor/ImageEditorModuleImpl.kt @@ -637,8 +637,8 @@ class ImageEditorModuleImpl(private val reactContext: ReactApplicationContext) { } /** - * Create a temporary file in the app's internal cache directory. External storage is only - * a fallback for the rare case where there is no internal cache dir: a crop inherits the + * Create a temporary file in the app's internal cache directory. External storage is only a + * fallback for the rare case where there is no internal cache dir: a crop inherits the * original's Exif data, and external storage is readable by other apps on API <= 29. * * @param mimeType the MIME type of the file to create (image/ *)