mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
garbage-collect storage of deleted webxdc apps
This commit is contained in:
@@ -9,6 +9,7 @@ import android.net.LinkProperties;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
import android.webkit.WebStorage;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatDelegate;
|
||||
@@ -48,6 +49,8 @@ import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import chat.delta.rpc.Rpc;
|
||||
import chat.delta.rpc.RpcException;
|
||||
@@ -218,6 +221,44 @@ public class ApplicationContext extends MultiDexApplication {
|
||||
ExistingPeriodicWorkPolicy.KEEP,
|
||||
fetchWorkRequest);
|
||||
}
|
||||
|
||||
Util.runOnBackground(() -> {
|
||||
final Pattern WEBXDC_URL_PATTERN =
|
||||
Pattern.compile("^https?://acc(\\d+)-msg(\\d+)\\.localhost/?");
|
||||
while (true) {
|
||||
Log.i(TAG, "Running Webxdc storage garbage collection...");
|
||||
WebStorage webStorage = WebStorage.getInstance();
|
||||
webStorage.getOrigins((origins) -> {
|
||||
if (origins == null || origins.isEmpty()) {
|
||||
Log.i(TAG, "Done, no WebView origins found.");
|
||||
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 {
|
||||
rpc.getMessage(accId, msgId);
|
||||
Log.i(TAG, String.format("Existing webxdc origin: %s", url));
|
||||
} catch (RpcException ignore) {
|
||||
// msg doesn't exist anymore, clean storage
|
||||
webStorage.deleteOrigin(url);
|
||||
Log.i(TAG, String.format("Deleted webxdc origin: %s", url));
|
||||
}
|
||||
} 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.");
|
||||
});
|
||||
Util.sleep(60*60*1000); // 1h
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public JobManager getJobManager() {
|
||||
|
||||
Reference in New Issue
Block a user