mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-24 02:25:19 +00:00
Clear cache on update
This commit is contained in:
parent
c573d5703b
commit
0b0853a223
@ -45,11 +45,13 @@ import org.thoughtcrime.securesms.jobs.PushDecryptJob;
|
||||
import org.thoughtcrime.securesms.jobs.RefreshAttributesJob;
|
||||
import org.thoughtcrime.securesms.notifications.MessageNotifier;
|
||||
import org.thoughtcrime.securesms.service.KeyCachingService;
|
||||
import org.thoughtcrime.securesms.util.FileUtils;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.thoughtcrime.securesms.util.VersionTracker;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
@ -78,6 +80,7 @@ public class DatabaseUpgradeActivity extends BaseActivity {
|
||||
public static final int SQLCIPHER = 334;
|
||||
public static final int SQLCIPHER_COMPLETE = 352;
|
||||
public static final int REMOVE_JOURNAL = 353;
|
||||
public static final int REMOVE_CACHE = 354;
|
||||
|
||||
private static final SortedSet<Integer> UPGRADE_VERSIONS = new TreeSet<Integer>() {{
|
||||
add(NO_MORE_KEY_EXCHANGE_PREFIX_VERSION);
|
||||
@ -97,6 +100,7 @@ public class DatabaseUpgradeActivity extends BaseActivity {
|
||||
add(PERSISTENT_BLOBS);
|
||||
add(SQLCIPHER);
|
||||
add(SQLCIPHER_COMPLETE);
|
||||
add(REMOVE_CACHE);
|
||||
}};
|
||||
|
||||
private MasterSecret masterSecret;
|
||||
@ -290,6 +294,14 @@ public class DatabaseUpgradeActivity extends BaseActivity {
|
||||
if (file != null && file.exists()) file.delete();
|
||||
}
|
||||
|
||||
if (params[0] < REMOVE_CACHE) {
|
||||
try {
|
||||
FileUtils.deleteDirectoryContents(context.getCacheDir());
|
||||
} catch (IOException e) {
|
||||
Log.w(TAG, e);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.thoughtcrime.securesms.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
@ -30,4 +31,27 @@ public class FileUtils {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void deleteDirectoryContents(File directory) throws IOException {
|
||||
if (directory == null || !directory.exists() || !directory.isDirectory()) return;
|
||||
|
||||
File[] files = directory.listFiles();
|
||||
|
||||
if (files != null) {
|
||||
for (File file : files) {
|
||||
if (file.isDirectory()) deleteDirectory(file);
|
||||
else file.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void deleteDirectory(File directory) throws IOException {
|
||||
if (directory == null || !directory.exists() || !directory.isDirectory()) {
|
||||
return;
|
||||
}
|
||||
|
||||
deleteDirectoryContents(directory);
|
||||
|
||||
directory.delete();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user