Glide clearDiskCache() must be run on background thread

STACK_TRACE_HASH=d9392158
java.lang.RuntimeException: Unable to start receiver org.fdroid.fdroid.receiver.DeviceStorageReceiver: java.lang.IllegalArgumentException: You must call this method on a background thread
	at android.app.ActivityThread.handleReceiver(ActivityThread.java:3426)
	at android.app.ActivityThread.access$1200(ActivityThread.java:200)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1667)
	at android.os.Handler.dispatchMessage(Handler.java:106)
	at android.os.Looper.loop(Looper.java:193)
	at android.app.ActivityThread.main(ActivityThread.java:6718)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:491)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.IllegalArgumentException: You must call this method on a background thread
	at com.bumptech.glide.util.Util.assertBackgroundThread(Util.java:173)
	at com.bumptech.glide.Glide.clearDiskCache(Glide.java:730)
	at org.fdroid.fdroid.receiver.DeviceStorageReceiver.onReceive(DeviceStorageReceiver.java:26)
	at android.app.ActivityThread.handleReceiver(ActivityThread.java:3417)
	... 8 more
java.lang.IllegalArgumentException: You must call this method on a background thread
	at com.bumptech.glide.util.Util.assertBackgroundThread(Util.java:173)
	at com.bumptech.glide.Glide.clearDiskCache(Glide.java:730)
	at org.fdroid.fdroid.receiver.DeviceStorageReceiver.onReceive(DeviceStorageReceiver.java:26)
	at android.app.ActivityThread.handleReceiver(ActivityThread.java:3417)
	at android.app.ActivityThread.access$1200(ActivityThread.java:200)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1667)
	at android.os.Handler.dispatchMessage(Handler.java:106)
	at android.os.Looper.loop(Looper.java:193)
	at android.app.ActivityThread.main(ActivityThread.java:6718)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:491)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
This commit is contained in:
Hans-Christoph Steiner
2022-01-24 16:10:51 +01:00
parent ace6785373
commit e8871677d7
2 changed files with 3 additions and 3 deletions

View File

@@ -5,6 +5,8 @@ import android.content.Intent;
import android.os.Process;
import android.util.Log;
import com.bumptech.glide.Glide;
import org.apache.commons.io.FileUtils;
import java.io.File;
@@ -28,6 +30,7 @@ public class DeleteCacheService extends JobIntentService {
protected void onHandleWork(@NonNull Intent intent) {
Process.setThreadPriority(Process.THREAD_PRIORITY_LOWEST);
Log.w(TAG, "Deleting all cached contents!");
Glide.get(this).clearDiskCache();
try {
File cacheDir = getCacheDir();
FileUtils.deleteDirectory(cacheDir);

View File

@@ -4,8 +4,6 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import com.bumptech.glide.Glide;
import org.fdroid.fdroid.DeleteCacheService;
import org.fdroid.fdroid.Utils;
import org.fdroid.fdroid.work.CleanCacheWorker;
@@ -23,7 +21,6 @@ public class DeviceStorageReceiver extends BroadcastReceiver {
CleanCacheWorker.force(context);
if (percentageFree <= 2) {
DeleteCacheService.deleteAll(context);
Glide.get(context).clearDiskCache();
}
}
}