How to access Calendar and Contacts db as normal user?

I have made python scripts to search for text into SMS and Calendar databases.
To display the contacts names in the SMS search results, I also need to access the Contacts DB.
But I noticed the DBs are not readable as normal user:


Is there a way to read these DBs without becoming root?
Thank you by advance


I guess this is related to the fact that contacts cannot be restored after 4.4 upgrade, and android apps cannot access them. Big bug.

I am sorry not being sure to understand what you refer to.
I flashed 4.4 and just copied my DBs from Did the db structure/rights change between 4.3 and 4.4?

Also, I can access Contacts form Android. Is that also abnormal?

I was going to suggest python3-dbus, but I’m not sure that won’t have constraints in a plain script run by user.

If you think it worth, a try, I am open. Go ahead! :–)

I don’t know if it solves your problem, but the user must be in the ‘privileged’ group to read the ‘privileged’ directory. That’s what happens when you do ‘devel-su -p’.
As normal defaultuser, id: uid=100000(defaultuser) gid=100000(defaultuser)
After ‘devel-su -p’: id: uid=100000(defaultuser) gid=996(privileged)

Maybe there is a solution with something like ‘chmod g+s’ on your script but I’m not expert enough to know the details to achieve that.

Oh! I didn’t know the difference between devel-su -p and devel-su. Thanks @phklrz
Changing the rights on the script will not change the user’s right to access the DB, unfortunately.

Running the script as privileged could be a way.
But this increases the number of manipulations (password for devel-su -p) before using the script.

What I don’t understand is:
When I open, e.g., the People app, I can access the contacts DB without password.
How could I imitate this behaviour for a script?

Or can I just change the DB rights to defaultuser instead of privileged?

But this would be stupid and create a security fragility, isn’t it?

To avoid “bricking” issues I experienced several times when SFOS3.4 suddenly became unstable, including when trying to upgrade, I had to do this:

  1. factory reset
  2. flash device with Torronsuo (no device encryption to avoid the fingerprint problem, zero app, zero patch)
  3. multiple system upgrades (OTA method) through all stop releases until
  4. trying to restore data from previous backup (made while OS was still

This is where problems appeared: data restoration failed, contacts and other data became unavailable for most apps, apparently due to undocumented changes in Contacts structure and/or permission management, and/or Sailjail that was not implemented yet in SFOS3.4. Of course I have no clear explanation. Still investigating with my very little knowledge and competence in system behavior. My device is just much less efficient than before, many apps are no longer usable, my contacts are lost,
etc. Sad story.

One way would be to wrap your script in a qml app that has the Calendar permission. The same thing should be able to be accomplished running your script from a desktop file with same perms.

@dcaliste suggested looking at:

I’ll have a look at your script later…

1 Like

It’s not really an answer, for the script scenario, but I had remembed:

I forked it, added


And sqllite searches in contacts and calendar work.


This is a pre-release of the adapted SearchNemo app which you might find meets your needs.

1 Like

@poetaster many warm thanks for having taken time to explore and explain, and even code something.
I am really grateful.

That would be one of my biggest wishes!
But for now, bash and python scripts (and some arduino C) are on the top of my capacities.
I opened the sdk, compiled the example “hello sailors” app but didn’t even find a way to add a text entry dialog.
No idea what qml is, alas, big alas. BTW, I’d give a lot if someone would give me a quick introduction step by step to it: sleep at my home, visit my city, cofees and beers or even pay what I could pay.
Because alone by myself, it is too long, too wide, dunno what rope I should pull!

Back to subject. Great, very great, even with sources! Will try right now!

S…t! I am on armv7 (XA2). 'll try to recompile it…

Edit some hours later:
:partying_face: Miracle, I compiled it for arm7, installed, launched.
Thinking: maybe you meant it as an example / starting point, or?

Because, in actual state, I found the results rather obscure:
-When finding the contact number, it doesn’t display the name and vice versa.
-When finding an event, it doesn’t display the date of it.
-I didn’t achieve to find the text into the messages.
So yes, it finds, but more like “yes man, I found it. Bye” biggrin

Instead, with the scripts, the result is more --human-readable, contextualized.
But again, maybe you thought it as starting point. And I feel having to start writing a poem in martian…

Damn. Had I known you had armv7 I’d have posted an rpm. Ok, but you’ve got this far. I didn’t look at the display attributes, but know it’s focused on text, so it doesn’t really ‘know’ about the structure of calendar entries. That could be extended.

Still, since you’ve gotten this far, it makes more sense to wrap your script. A relatively simple example instructional apps:

The SearchPage.qml of SearchNemo shows how one can get input and pass it to a function. The QML In short:

            SearchField {
                id: searchField
                EnterKey.enabled: true
                EnterKey.iconSource: "image://theme/icon-m-enter-accept"
                EnterKey.onClicked: {


I’ll see if I can find an example that’s a closer fit to your purpose.

Just occured to me. I wouldn’t bother with any of this unless I wanted to share. I’d just use root. As long as your script is just reading, it’s not such a big deal :slight_smile:

Thanks, yeah, @pherjung gave me the link to this python example already.
But when I saw smoke out of my brain, I stopped trying.
Now I domesticated the sdk a bit, I’ll try again.
Thanks for pointing the way to get an input. This helps too.

Hm, yes/no.
Well, things are linged together.
I’d prefer being able to access the DB as user because

  • I’d really like to share my “work”. To bring a brick to the whole thing and to give back, as I benefit from other’s work. (ego also maybe involved :–)
  • I use my XA2 as secondary user (vs Device Owner/defaultuser) 95% of the time. When I very barely need Android, I switch to Device Owner. This way, I am sure Android don’t put its nose in my stuff. (I have no data there). Secondary user has no way to get root access (or I didn’t find the way).

Ah, ok. Well once you get your head around qml → python and back you’ll be really happy :wink:

And if you have a secondary user, you’re really going to want to have a ‘proper’ wrapper to manage permissions, etc.

Let me know if I can help if you get stuck!

1 Like

Hmm…I believe I am stuck!
I found the way to make various text entries in the TextInputPage of the componentsgallery example in the SDK.

       TextField {
            focus: true
            label: "Normal"
            EnterKey.iconSource: "image://theme/icon-m-enter-next"
            EnterKey.onClicked: passwordField.focus = true

            horizontalAlignment: textAlignment
            backgroundStyle: textInputPage.editorStyle

But I don’t understand where the entered text goes, in what variable and how to use what the user entered.
And also how it could be articulated with my python code and where I should put my python code.

Well, lots of very devel-noob questions, I am afraid.

The text is kept in the TextField’s ‘text’ property, which you can use qml’s builtin javascript, or access from the Python type.