Merge pull request #4050 from deltachat/adb/issue-4049

garbage-collect storage of deleted webxdc apps
This commit is contained in:
adb
2025-11-28 01:37:31 +01:00
committed by GitHub
4 changed files with 91 additions and 0 deletions
+1
View File
@@ -10,6 +10,7 @@
* Send .webm videos as file, they are not supported by all platforms
* Tweak advanced section and wording of some advanced options
* Fix: avoid crash in push notifications handling
* Fix: clean up web storage of deleted in-chat apps
* Expose new "Multi-device mode" option instead of "Delete from server" for chatmail profiles
* Opened in-chat apps got a 'About Apps' menu item
* Avoid gray avatar on profile creation
+1
View File
@@ -152,6 +152,7 @@ android {
}
dependencies {
implementation 'androidx.concurrent:concurrent-futures:1.3.0'
implementation 'androidx.sharetarget:sharetarget:1.2.0'
implementation 'androidx.webkit:webkit:1.14.0'
implementation 'androidx.multidex:multidex:2.0.1'
@@ -45,6 +45,7 @@ import org.thoughtcrime.securesms.util.DynamicTheme;
import org.thoughtcrime.securesms.util.Prefs;
import org.thoughtcrime.securesms.util.SignalProtocolLoggerProvider;
import org.thoughtcrime.securesms.util.Util;
import org.thoughtcrime.securesms.webxdc.WebxdcGarbageCollectionWorker;
import java.io.File;
import java.util.concurrent.TimeUnit;
@@ -218,6 +219,18 @@ public class ApplicationContext extends MultiDexApplication {
ExistingPeriodicWorkPolicy.KEEP,
fetchWorkRequest);
}
PeriodicWorkRequest webxdcGarbageCollectionRequest = new PeriodicWorkRequest.Builder(
WebxdcGarbageCollectionWorker.class,
PeriodicWorkRequest.MIN_PERIODIC_INTERVAL_MILLIS,
TimeUnit.MILLISECONDS,
PeriodicWorkRequest.MIN_PERIODIC_FLEX_MILLIS,
TimeUnit.MILLISECONDS)
.build();
WorkManager.getInstance(this).enqueueUniquePeriodicWork(
"WebxdcGarbageCollectionWorker",
ExistingPeriodicWorkPolicy.KEEP,
webxdcGarbageCollectionRequest);
}
public JobManager getJobManager() {
@@ -0,0 +1,76 @@
package org.thoughtcrime.securesms.webxdc;
import android.content.Context;
import android.util.Log;
import android.webkit.WebStorage;
import androidx.annotation.NonNull;
import androidx.concurrent.futures.CallbackToFutureAdapter;
import androidx.work.ListenableWorker;
import androidx.work.WorkerParameters;
import chat.delta.rpc.Rpc;
import chat.delta.rpc.RpcException;
import com.google.common.util.concurrent.ListenableFuture;
import java.util.Collections;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.thoughtcrime.securesms.connect.DcHelper;
public class WebxdcGarbageCollectionWorker extends ListenableWorker {
private static final String TAG = WebxdcGarbageCollectionWorker.class.getSimpleName();
private Rpc rpc;
public WebxdcGarbageCollectionWorker(Context context, WorkerParameters params) {
super(context, params);
rpc = DcHelper.getRpc(context);
}
@Override
public @NonNull ListenableFuture<Result> startWork() {
Log.i(TAG, "Running Webxdc storage garbage collection...");
final Pattern WEBXDC_URL_PATTERN =
Pattern.compile("^https?://acc(\\d+)-msg(\\d+)\\.localhost/?");
return CallbackToFutureAdapter.getFuture(completer -> {
WebStorage webStorage = WebStorage.getInstance();
webStorage.getOrigins((origins) -> {
if (origins == null || origins.isEmpty()) {
Log.i(TAG, "Done, no WebView origins found.");
completer.set(Result.success());
return;
}
for (Object key : origins.keySet()) {
String url = (String)key;
Matcher m = WEBXDC_URL_PATTERN.matcher(url);
if (m.matches()) {
int accId = Integer.parseInt(m.group(1));
int msgId = Integer.parseInt(m.group(2));
try {
if (rpc.getExistingMsgIds(accId, Collections.singletonList(msgId)).isEmpty()) {
webStorage.deleteOrigin(url);
Log.i(TAG, String.format("Deleted webxdc origin: %s", url));
} else {
Log.i(TAG, String.format("Existing webxdc origin: %s", url));
}
} catch (RpcException e) {
Log.e(TAG, "error calling rpc.getExistingMsgIds()", e);
completer.set(Result.failure());
return;
}
} else { // old webxdc URL schemes, etc
webStorage.deleteOrigin(url);
Log.i(TAG, String.format("Deleted unknown origin: %s", url));
}
}
Log.i(TAG, "Done running Webxdc storage garbage collection.");
completer.set(Result.success());
});
return "Webxdc Garbage Collector";
});
}
}