mirror of
https://codeberg.org/Starfish/Imagepipe.git
synced 2025-10-05 22:52:39 +02:00
delay deleting data after sharing to allow the target app to fetch images
This commit is contained in:
@@ -52,7 +52,6 @@ import java.util.concurrent.Executors;
|
||||
import android.Manifest;
|
||||
import android.content.pm.PackageManager;
|
||||
|
||||
|
||||
/*
|
||||
* This class provides all the relevant functions and interaction for Imagepipe.
|
||||
*/
|
||||
@@ -2449,6 +2448,7 @@ public class ImageReceiver extends Activity{
|
||||
// build IntentSender for callback after an app was chosen
|
||||
//Intent receiverIntent = new Intent(Intent.EXTRA_CHOSEN_COMPONENT);
|
||||
Intent receiverIntent = new Intent(this,IntentReceiver.class);
|
||||
receiverIntent.putExtra(IntentReceiver.IMAGE_COUNT_EXTRA,i);
|
||||
PendingIntent receiverPendingIntent;
|
||||
if (Build.VERSION.SDK_INT >= 31) {
|
||||
receiverPendingIntent = PendingIntent.getBroadcast(this,0,receiverIntent,PendingIntent.FLAG_CANCEL_CURRENT|PendingIntent.FLAG_IMMUTABLE);
|
||||
@@ -3198,7 +3198,9 @@ public class ImageReceiver extends Activity{
|
||||
i.setDataAndType(uri,ImageWriter.getMimeType(this));
|
||||
i.putExtra(Intent.EXTRA_STREAM, uri);
|
||||
i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
Log.v("Put uri and set flags from local cache folder: "+uri.toString());
|
||||
if (uri!=null){
|
||||
Log.v("Put uri and set flags from local cache folder: "+uri.toString());
|
||||
}
|
||||
} else {
|
||||
// build the intent in the classic way from the media store
|
||||
i.setDataAndType(imageContainer.uri, ImageWriter.getMimeType(this));
|
||||
|
@@ -22,17 +22,36 @@ package de.kaffeemitkoffein.imagepipe;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
public class IntentReceiver extends BroadcastReceiver {
|
||||
|
||||
public final static String IMAGE_COUNT_EXTRA = "IMAGECOUNT";
|
||||
private final static int IMAGE_COUNT_DEFAULT = 1;
|
||||
// empiric: 500 ms delay sufficient for 1 image, 700 ms sufficient for 10 images
|
||||
private static long BASEDELAY_MILLIS = 1500L; // empiric testing shows that 500ms delay are sufficient for a single image
|
||||
private static long DELAY_PER_IMAGE_MILLIS = 30L; // empiric testing shows that 20ms delay per image seem sufficient
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
int count = intent.getIntExtra(IMAGE_COUNT_EXTRA,IMAGE_COUNT_DEFAULT);
|
||||
long delay = BASEDELAY_MILLIS + count * DELAY_PER_IMAGE_MILLIS;
|
||||
Log.v("image count: "+count+", clearing data is delayed by "+delay+" ms to allow target app to handle data.");
|
||||
if (ImagepipePreferences.clearAfterShare(context)){
|
||||
clearPrivateData(context);
|
||||
}
|
||||
// this receiver should never be called on android sdk below 22, but we check anyway
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||
// set the cache value to the file name counter once at least a target component was chosen
|
||||
ImagepipePreferences.setFileNameCounter(context,ImagepipePreferences.getFileCounterCache(context));
|
||||
final Handler handler = new Handler(Looper.getMainLooper());
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
clearPrivateData(context);
|
||||
Log.v("Cleared private data after sharing.");
|
||||
// this receiver should never be called on android sdk below 22, but we check anyway
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||
// set the cache value to the file name counter once at least a target component was chosen
|
||||
ImagepipePreferences.setFileNameCounter(context,ImagepipePreferences.getFileCounterCache(context));
|
||||
}
|
||||
}
|
||||
},delay);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +62,8 @@ public class IntentReceiver extends BroadcastReceiver {
|
||||
ImageReceiver.deleteCacheFile(context);
|
||||
// clear image origin data
|
||||
ImagepipePreferences.resetSavedImageContainer(context);
|
||||
// clear exif container
|
||||
ImagepipePreferences.resetExifData(context);
|
||||
// notify main app to remove volatile data
|
||||
Intent mainAppCall = new Intent(ImageReceiver.ACTION_CLEAR_DATA);
|
||||
context.sendBroadcast(mainAppCall);
|
||||
|
@@ -140,7 +140,6 @@
|
||||
android:summary="@string/preference_clearaftershare_summary"
|
||||
android:defaultValue="false"/>
|
||||
|
||||
|
||||
<Preference
|
||||
android:key="PREF_allowed_tags"
|
||||
android:title="@string/preference_allowed_tags_title"
|
||||
|
Reference in New Issue
Block a user