7

I've downgraded from Cyanogenmod 13 (Android 6.0.1) to Android stock 5.1.1, and kept my previous mmssms.db file, but it is incompatible with older Android versions. I would like to import this database in an Android Virtual Device running Android 6.0, back it up using SMS Save & Restore, then restore the .xml file produced by that app on my device.

However, when I copy my old com.android.providers.telephony directory in the /data/data/ directory of the AVD, neither the Messenger app, nor SMS Backup & Restore see any message. The directory and its contents are owned by the radio user, belong to the radio group, and have chmod set to 771.

How can I check what is preventing the system from accessing my database?

Or how else can I retrieve my sms ?

  • It's possible that CM 13's mmssms.db is not fully compatible with stock 6.0.1. Do you absolutely need to import the messages into 5.1.1, or will accessing them on a PC be sufficient? – Chahk Apr 11 '16 at 13:05
  • I absolutely need to merge the two databases, not just access the old one on a PC. Edit: based on your suggestion that CM 13's mmssms.db in not compatible with Android 6.0.1 stock, I will try installing CM 13 on the AVD. – Cutter Apr 11 '16 at 14:20
  • Any luck with CM13 on the AVD? – Chahk Apr 12 '16 at 13:11
  • Google's emulator is really slow and hangs when I use adb to reboot to recovery/bootloader. Maybe it will work better with a virtual device having an Intel Atom processor; I will try that later today. – Cutter Apr 12 '16 at 14:39
2

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/com.android.providers.telephony 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/com.android.providers.telephony 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à.

0

I had to do an extra step compared to @Cutter answer to get it working with LineageOS 14.1 (original mmssms.db came from Android 5.1).

Change the user_version from 64 to 68:

sqlite3 mmssms.db
PRAGMA user_version;
PRAGMA user_version = 68;
.q

In recovery mode (adb reboot recovery):

adb push mmssms.db /data/user_de/0/com.android.providers.telephony/databases/
adb shell chown radio:radio /data/user_de/0/com.android.providers.telephony/databases/mmssms.db
adb shell chmod 660 /data/user_de/0/com.android.providers.telephony/databases/mmssms.db
adb shell chcon u:object_r:radio_data_file:s0 /data/user_de/0/com.android.providers.telephony/databases/mmssms.db
adb shell ls -alZ /data/user_de/0/com.android.providers.telephony/databases/mmssms.db

The important thing was to additionally change the file SELinux security context with chcon.

And after rebooting the old SMS messages were finally recognized!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.