<p>For starters, <a href="https://en.wikipedia.org/wiki/Data_erasure#Limitations" rel="noreferrer">secure file deletion on flash media</a> is a complex problem, with no quick and easy answers. The paper <a href="https://www.usenix.org/legacy/events/fast11/tech/full_papers/Wei.pdf" rel="noreferrer">Reliably Erasing Data From Flash-Based Solid State Drives</a> gives a good overview of the problems, the potential solutions, and their limitations. They conclude that</p>

<blockquote>
  <p>For sanitizing <em>entire disks</em>, ... software techniques work most, but not
  all, of the time. We found that none of the available software
  techniques for sanitizing <em>individual files</em> were effective. [emphasis added]</p>
</blockquote>

<p><a href="http://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-88r1.pdf" rel="noreferrer">NIST 800-88</a> also has a good overview of the technology trends contributing to the problem, along with some minimum recommendations (appendix A) for Android devices. However they tend to be either whole-disk erasure (factory reset), or rely on cryptographic erasure (CE), rather than being general file erasure methods.</p>

<p>But all is not lost. Even if you can't sanitize individual files, you could hope to wipe all the unallocated space after deleting files. The article <a href="http://arxiv.org/PS_cache/arxiv/pdf/1106/1106.0917v1.pdf" rel="noreferrer">Secure Deletion on Log-structured File Systems</a> (Reardon, et al.) describes a fairly promising way to do that in user-mode software. Android's internal memory uses (always?) a log-structured file system. </p>

<p>This paper's "purging" method does not require kernel-level access, and doesn't seem to require any native code on Android. (Note that the term "purging" is used a little differently in documents like NIST 800-88.) The basic idea is to delete all the sensitive data, then fill in the remaining space on the drive with a junk data file, and finally delete the junk data file.</p>

<p>While that takes more time and effort than just overwriting the deleted files themselves (several times in different patterns), it seems to be very robust even when you have to deal with the possibility of wear-leveling and log-structure FS.</p>

<h1>Caveat and Further Measures</h1>

<p>The main caveat for me is about the conditions mentioned by Reardon et al. in the above paper:</p>

<blockquote>
  <p>Purging will work for any log-structured file system provided both the
  <strong>user’s disk quota is unlimited</strong> and the file system always performs
  garbage collection <strong>to reclaim even a single chunk of memory</strong> before
  declaring that the drive is unwritable. [emphasis mine]</p>
</blockquote>

<p>The second condition seems pretty likely to be fulfilled, but I don't know about the first one. Does Android (or some manufacturers' versions of it) enforce quotas on disk space used by apps? I have not found any info about user quotas, but there are quotas for other niches like browser persistent storage. Does Android reserve some space for system use, or for each app's caching, for example, that can't be used for other things? If so, it should help (albeit with no guarantees) if we begin purging immediately after the sensitive files are deleted, so there is little time for other filesystem activity to stake a claim to the recently freed space.</p>

<p>Maybe we could mitigate these risks by cyclical purging:</p>

<ul>
<li>Determine the remaining space available (call it S) on the relevant partition, e.g. using <code>File.getUsableSpace()</code></li>
<li>Write a series of files to the partition; each one is, say, 20% of the initial S (subject to file size limits).</li>
<li>When we run out of space, delete the first couple of files that we created, then write another file or two as space allows.</li>
<li>Repeat that last step a few times, until you've reached a threshold you're satisfied with. Maybe up to the point where you've written 2*S worth of filler files; tweak that number to balance speed against thoroughness. How much you actually need to do this would be an area for more research.</li>
<li>Delete the remaining filler files.</li>
</ul>

<p>The idea with cyclical purging is that if we run out of quota to overwrite all free space, deleting the filler files just written will free up more quota; and then the way log-structured filesystems allocate new blocks should allow us to continue overwriting the remaining blocks of free space in sequence, rather than rewriting the same space again.</p>

<p>I'm implementing this method in a test app, and will post it when it's working.</p>

<h1>What about FAT-formatted microSD cards?</h1>

<p>Would the same methods work on external storage or microSD cards? FAT is block-structured, so would the purge method apply to FAT-formatted SD cards?</p>

<blockquote>
  <p>On most contemporary flash memory devices, such as CompactFlash and
  Secure Digital cards, [wear leveling] techniques are implemented in
  hardware by a built-in microcontroller. On such devices, wear leveling
  is transparent and most conventional file systems can be used on them
  as-is. (<a href="https://en.wikipedia.org/wiki/Wear_leveling" rel="noreferrer">https://en.wikipedia.org/wiki/Wear_leveling</a>)</p>
</blockquote>

<p>...which suggests to me that even on a FAT-formatted SD card, wear leveling means that the traditional <a href="https://www.cs.auckland.ac.nz/~pgut001/pubs/secure_del.html#epilogue" rel="noreferrer">Gutmann methods</a> would not work (see his "<a href="https://www.cs.auckland.ac.nz/~pgut001/pubs/secure_del.html#epilogue" rel="noreferrer">Even Further Epilogue</a>") and that a method like "purging" would be necessary.</p>

<p>Whether purging is sufficient, depends on your security parameters. Wear leveling seems to imply that a block could potentially be "retired" at any time, in which case there is no way to erase it without bypassing the microcontroller's wear leveling. AFAIK this can't be done in software, even if you had kernel privileges; you'd have to design special hardware.</p>

<p>However, "retiring" a bad block should be a fairly rare event relative to the life of the media, so for many scenarios, a purging method would be secure enough.</p>

<h2>Erasing the traces</h2>

<p>Note that Gutmann's method has an important strength, namely, to erase <a href="https://en.wikipedia.org/wiki/Data_remanence" rel="noreferrer">possible traces of old data</a> on the storage media that could remain even after a block is overwritten with new data. These traces could theoretically be read by a determined attacker with lots of resources. A truly thorough approach to secure deletion would <em>augment</em> a method like Gutmann's with purging, rather than replacing it.</p>

<p>However, on log-structured and wear-leveled filesystems, the much bigger problem is trying to ensure that the sensitive blocks get overwritten at all.</p>

<h1>Do existing apps use these methods?</h1>

<p>I don't have any inside information about apps in the app store, but looking at reviews for apps like <a href="https://play.google.com/store/apps/details?id=com.projectstar.ishredder.android.standard&amp;hl=en#details-reviews" rel="noreferrer">iShredder</a> would suggest that at best, they use methods like Reardon's "purging." For example, they can take <em>several hours</em> to do a single-pass wipe of 32GB of free space.</p>

<p>Also note limitations: The reviews on some of the secure deletion apps say that in some cases, the "deleted" files were still accessible after running the "secure delete" operation. Of course we take these reviews with a grain of salt -- there is a possibility of user error. Nevertheless, I wouldn't assume these apps are effective, without good testing.</p>

<p><a href="https://play.google.com/store/apps/details?id=com.protectstar.ishredder.ent" rel="noreferrer">iShredder 4 Enterprise</a> helpfully names some of the algorithms they use, in their app description:</p>

<blockquote>
  <p>Depending on the edition, the iShredder™ package comes with deletion
  algorithms such as DoD 5220.22-M E, US Air Force (AFSSI-5020), US Army
  AR380-19, DoD 5220.22-M ECE, BSI/VS-ITR TL-03423 Standard,
  BSI-VS-2011, NATO Standard, Gutmann, HMG InfoSec No.5, DoD 5220.22 SSD
  and others.</p>
</blockquote>

<p>This impressive-sounding list gives us some pointers for further research. It's not clear how these methods are used -- singly or in combination -- and in particular whether any of them are represented as being effective on their own. We know that Gutmann's method would not be. Similarly, DoD 5220.22-M, AFSSI-5020, AR380-19, and Infosec No. 5 specify Gutmann-like procedures for overwriting sectors on hard drives, which would not be effective for flash-based media. In fact, "<a href="http://www.destructdata.com/dod-standard/" rel="noreferrer">The U.S. Department of Defense no longer references DoD 5220.22-M as a method for secure HDD erasure</a>", let alone for flash-based media, so this reference is misleading to the uninformed. (The DoD is said to reference <a href="http://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-88r1.pdf" rel="noreferrer">NIST 800-88</a> instead.) "DoD 5220.22 SSD" sounds promising, but I can't find any informative references for it. I haven't chased down the other algorithms listed, but the results so far are not encouraging.</p>
Permanently delete files Android
<p>I found an android app named <a href="https://play.google.com/store/apps/details?id=tk.hasankassem.supererase&amp;hl=en">Super Erase</a> that deletes files and folder permanently from android device so that the file deleted cant be recovered anymore..here is the application i am talking about  ...but i was wondering how to that and i know it is made with android studio ..i tried the regular way to delete <code>file.delete()</code> but still the file can be recovered.can i have any help .</p>