Android - How to import an existing mmssms.db to an Android Virtual Device?

I've finally managed to restore the contents of my previous database on my current device and I will explain how.

The idea was to copy the backup of /data/data/ from my previous installation, to an Android Virtual Device, back it up there using SMS Backup & Restore in XML format, then restore that XML backup on my device. SMS Backup & Restore merged the messages from the backup with the current device's messages so I didn't have to merge the two databases by hand.

In my question, the AVD running 6.0.0 wouldn't read the contents of my database because it was created on CM 13 which is based on Android 6.0.1. But Google doesn't seem to provide an emulator image based on Android 6.0.1, so I still used an AVD running 6.0.0. For performance reasons I've configured it to emulate an Intel Atom (x86) CPU and installed Intel HAXM driver on my PC (I've followed this answer to do that).

The mmssms.db database holds properties about itself, especially version numbers, so I've edited them to make Android believe that it dealt with a database of a version it could deal with. I've opened mmssms.db in SQLite Expert, clicked on the "Database" tab, and in the property list, found the following lines:

  • schema_version
  • user_version

I've downgraded these to 44 and 60, respectively.

Then I transferred my backup of /data/data/ to the AVD using adb push, after making sure that location was already empty there. Using adb shell I've set the owner and group of everything in this directory and its subdirectories to radio, and in the database subdirectory the chmod value to 660.

I've rebooted the device.

I've installed SMS Backup & Restore on the AVD through ADB. (The .apk of that app can be found on an existing device in /data/app on a device where it is already installed. I didn't bother installing Google Play Services on the emulator to get it from the Play Store, but you can do that.)

I've backed up the messages and copied the resulting .xml over to my real device, where I've used SMS Backup & Restore to restore it. Voilà.