How to Move App Data of TextSecure to New Android Device

This Howto explains how to move application data of Android apps to a new mobile device. It is explained with TextSecure as an example but should work with any other app as well. People who are paranoid in respect to security and those trying to learn something about security should read the Section »Security Considerations« below.

In short the steps are:

  1. Install and initialize the app on the new device.
  2. Create an archive of the data directory (/data/data/…) on the old device.
  3. Copy and extract the archive on the new device.
  4. Change directory owner/group appropriately.

textsecureAbout TextSecure

TextSecure is an excellent application for Android (and iPhone) for secure SMS communication. It encrypts SMS messages such that an eavesdropper cannot read your messages. TextSecure uses public key cryptography to do encryption and authentication. Encryption always involves keys of which the most important and secret one is your personal private key. Thus, you should take care on it!

If you move over to a new mobile device you will either loose all your messages and your keys or you migrate them to the new phone. Of course, I’d prefer the latter. This article specifically deals with TextSecure but the method works for most other apps as well.


In order to successfully accomplish that you need

Screenshot_2014-02-13-15-16-48First install the app for which you want to move the data onto your new device as usual (e.g. with Google Play). Run it once to init all data structures. If you’re asked to enter passwords and so on it really doesn’t matter what you enter. Everything will be overwritten in a few steps.

It is important to know the class name of the app. Go to Settings ->Apps ->Downloaded. Select the appropriate app. It is written directly below the title of the app (see picture). In case of TextSecure it is “org.thoughtcrime.securesms”.

Now connect your old mobile with the USB cable to the computer. On your computer open a shell (or cmd on Windows) and type `adb shell`. You should immediately get a command prompt (~#).

All apps store their application data into a sub folder under /data/data. The sub folder is named exactly as the class name of the app. In case of TextSecure this is /data/data/org.thoughtcrime.securesms.  You can list the directory contents with `ls -l /data/data`. This should show all apps’ data directories.

Change to your SDCard folder; type `cd /sdcard`. Now create an archive containing all data. Type `tar cf appdata.tar /data/data/org.thoughtcrime.securesms`. Obviously, you have to change the directory name appropriately in case you’re backing up the data of a different app. Finally, you’ll find the archive named ‘appdata.tar’ on your SDCard. Copy it to your computer either with `adb pull appdata.tar` or mount your SDCard on your computer as usual.

appdirDisconnect your old mobile and connect the new one. Copy the archive to its SDCard. Run `adb shell`. Now list the directory contents of the app’s data directory with `ls -l /data/data/org.thoughtcrime.securesms`. You should note two important things (see picture): the directory’s owner and group (in this case it is “u0_a24”) and the symbolic link lib which points to somewhere (in this case to “/data/app-lib/org.thoughtcrime.securesms-1”).

Now change to the root directory with `cd /` and extract the archive with `tar xf /sdcard/appdata.tar`. Then we have to modify the owner and group of the extracted data appropriately (to the one which was found above) with the command `chown -R u0_a24:u0_a24 /data/data/org.thoughtcrime.securesms`.

Finally, we probably have to fix the symlink. Change to the directory and list its contents: `cd /data/data/org.thoughtcrime.securesms` and `ls -l`. Now compare the if the symlink `lib` points to somewhere else as listed before. If this is the case remove it (`rm lib`) and recreate it appropriately with `ln -s /data/app-lib/org.thoughtcrime.securesms-1 lib`.

Please don’t C&P these commands from above. Always modify them to your needs! And plz don’t ask me how to root your device. Google it yourself!

Security Considerations

The data of TextSecure contains your private key. As a rule of thumb of security it is a mistake by default to duplicate private keys. Of course, in case of making backups there is room for discussion. But nevertheless, there should be as few copies as possible.

Excercise: How many copies (without the original) did we create (if you followed the steps from above)?

Yes, we created four copies.

  1. Archive on the SDCard of the old device.
  2. Archive copied to the computer.
  3. Archive on the SDcard of the new device.
  4. Extracted copy in the /data directory of the new device.

It is not easy to just delete those files again. First, deletion of a file typically just modifies the meta data of the file system but not the data itself. Thus it is possible to recover the data again using appropriate techniques. To completely erase it we would have to fully overwrite every byte on those partitions and even this is not perfect because, second, there are at least two flash devices involved (the SDCards of the mobiles). They typically use a technique called wear leveling to avoid writing always to the same blocks.

The best way to circumvent all those troubles from above is to simply avoid all the intermediate copies, e.g. through piping the data directly from one device to the other. There are several methods but this is another story for a new article 😉


    • peter on May 17, 2014 at 4:54 pm

    Or just use the built-in backup function.^^

    1. Yes, newer versions of TextSecure have a built-in backup. But there are many other apps which don’t have this functionality.

Comments have been disabled.