Importing smsmms.db from Android

Hi all,
the 11years old s3 mini of my wife has nearly lost his life due to a broken display. The good information. It still works, shows content and is responsive.
I would like to import the old sms data to here XA2 with Sailfish.
First of all: have I to root the samsung to pull the data with adb? I get an error, that I am not permitted to download this data.
Anyone from you a good hint how to import it to a sailfish device? What I found:
https://michal.hrusecky.net/2014/01/importing-sms-from-android-to-jolla/
Thank you very much and best regards,
Lukas

2 Likes

I think it’s easier read contents via android api with some android application than access that file.
I endup writing my own code in past (5-10 years ago) when i need to import data. But I think there is some tools are already exist for Android now days to get messages out of the phone.

Recently, I have finished my journey exporting SMS/MMS from Android and
importing to my brand new Xperia 10 III. I found the above link from year 2014
is very helpful, but I had to make some adjustments to suit my needs.

I have lost my XA2 few months ago. Fortunately, I had full backup (1 month
old). For 5 months, I’ve used an old Redmi 7a running Android 10. I have
restored backup, but I didn’t want to lose a few months of sms
conversations when used temporary device.

But let’s move to what’s important.

Following the tutorial, I reached wall. For some reason, I couldn’t access
smsmms.db file directly. Instead, I’ve used adb backup feature which creates
backup.db.

adb bakup com.android.providers.telephony

The resulting file can be uncompressed using the following bash trick:

( printf "\x1f\x8b\x08\x00\x00\x00\x00\x00" ; tail -c +25 backup.ab ) | \
  tar xfvz -

Inside you’ll find apps/com.android.providers.telephony/d_f path with three
files inside. Those are also compressed. The one I used was
000000_sms_backup

Used the following command to uncompress:

zlib-flate -uncompress < 000000_sms_backup > sms_backup

But the result was not sqlite db but json file.

I had to create a script (using my poor python skills) to convert json
(sms_backup is json) to csv that could be used by Michal import tool found
in original post. The script is available here:

smsjson2csv.py

Original post mentions that line breaks are not handled, but I needed them. In
order to manage new lines in messages, I have replaced them with <BR> token.
The following patch updates original jollaImport with ability to handle those
tokens.

From 05ce2277dbbe826e70afed9e37b8d4a7e4cd01d4 Mon Sep 17 00:00:00 2001
From: pemekcz <pemekcz@no.email.at.all>
Date: Fri, 9 Dec 2022 01:45:25 +0100
Subject: [PATCH] Convert <BR> token to newline character

<BR> has been used as new line separator during conversion from android
backup. This change reverts <BR> to new line.

Signed-off-by: pemekcz <pemekcz@no.email.at.all>
---
 jollaImport/jollaIm.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/jollaImport/jollaIm.cpp b/jollaImport/jollaIm.cpp
index b927065..0049404 100644
--- a/jollaImport/jollaIm.cpp
+++ b/jollaImport/jollaIm.cpp
@@ -125,7 +125,9 @@ void workMessage(QString* message)
     event.setStartTime(date);
     event.setEndTime(endDate);
     event.setIsRead(true);
-    event.setFreeText(message->section(';', 4));
+    QString body = message->section(';', 4);
+    body.replace(QString("<BR>"), QString("\n"));
+    event.setFreeText(body);

     eventCatcher->reset();
     if(!eventModel->addEvent(event))
-- 
2.35.3

And that’s it. I have compiled the binary copied binary and csv to the device, and voilà.

Hope this will help somebody.

3 Likes