Saturday, 4 September 2010

File Shredder

Flattr this

Today I'll tell you about "FileShredder", a data wiping tool coded by be.

My motivation for developing this one, was just to learn how to make an application from start to finish and publish it. I did all of the development on the emulator. I had dabbled at Android for a bit, but none of the work was aimed at creating something which I would try to publish.

I tried to think of something so simple I could code in an evening or to, because I tend to have somewhat short attention span. :)
I was actually code complete in one 6 hour session, testing and debugging another 6 hours and publishing took perhaps two hours to figure out.

I'll explain the parts of the program.


This is the file system browser. It is very rudimentary and ugly, but it serves its purpose just fine. You can browse the whoe file system and select a file. That's it.
Basically, when you start it, it scans the root directory:

private void ScanDir(File f) {
if(f.isDirectory()) {
File[] files = f.listFiles(new AllFileFilter());
if(files == null) return;
for(int i=0;i<files.length;i++) {

"a" is an ArrayAdapter which server as the adapter for the listview.

Info view

When you click on a file instead of a directory in the previous view, it will launch this activity. It shows information about the file and determines if it can be shred. The application does not not have root permissions to the file system, so there's no way to accidentally the whole system.

If you click Shred, the application will show up a progress dialog and start a background thread to do the actual work. If you mis-click, you pretty much fucked. The file is corrupted pretty much instantaneously.

The worker thread gets a handle to the selected file, determines its size and overwrites it with pseudo-random data. It will try to determine good sized buffer sizes to process the file as fast as possible.

Progress dialog

Now, here I stumbled on some problems. I never did quite read the Android Activity/Intent lifetime documentation properly. Well, I tried but I never understood why they bothered to explain all the boring details so well with pretty diagrams and all :)

I'll explain the causes and fixes in a later blog post, but basically you need to carefully maintain you applications state and response to events such as change in orientation. Many times you do not need to bother, because the default Android behaviour is fine. But with background threads, message handlers and dialogs you might get, ahem, unexpected behaviour :)

Also, I'll promise to tell more about inter thread communication via message handling later. Showing that progress bar is a bit more involved than you might think.


After the file is shredder, the Activitys buttons are modified acordingly and you may now close the activity. You could also just use the Back button of your device, but I added the button for clarity. I actually might remove it in a later version, because it does not sit well with the Android UI style.

Obviously, the file browser could be a lot neater.
It would be nice to be able to shred multiple files at once.
It would be nice to process entire directory trees at once.
However, in my first version I just wanted something I could develop in a day, so I designed accordingly.


Here's a QR tag which you can read with an Android barcode reader. I'm not sure if it works. It would be great if you could report in the comments whether it works for you!

Also, polishing your package for Android Market is a topic of its own. I'll explain the export, key generation and icons later.

No comments:

Post a Comment