diff --git a/src/org/thoughtcrime/securesms/DatabaseUpgradeActivity.java b/src/org/thoughtcrime/securesms/DatabaseUpgradeActivity.java index bee3fd17c3..7681733bcd 100644 --- a/src/org/thoughtcrime/securesms/DatabaseUpgradeActivity.java +++ b/src/org/thoughtcrime/securesms/DatabaseUpgradeActivity.java @@ -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 UPGRADE_VERSIONS = new TreeSet() {{ 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; } diff --git a/src/org/thoughtcrime/securesms/util/FileUtils.java b/src/org/thoughtcrime/securesms/util/FileUtils.java index fe94e1fab9..e437edd84c 100644 --- a/src/org/thoughtcrime/securesms/util/FileUtils.java +++ b/src/org/thoughtcrime/securesms/util/FileUtils.java @@ -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(); + } }