Adding privacy setting support to your Unity Lens

During this latest round of arguing over the inclusion of Amazon search results in the Unity Dash, Alan Bell pointed out the fact that while the default scopes shipped in Ubuntu were made to check the new privacy settings, we didn’t do a very good job of telling third-party developers how to do it.

(Update: I was told a better way of doing this, be sure to read the bottom of the post before implementing it in your own code)

Since I am also a third-party lens developer, I decided to add it to my come of my own code and share how to do it with other lens/scope developers.  It turns out, it’s remarkably easy to do.

Since the privacy setting is stored in DConf, which we can access via the Gio library, we need to include that in our GObject Introspection imports:

from gi.repository import GLib, Unity, Gio

Then, before performing a search, we need to fetch the Unity Lens settings:

lens_settings = Gio.Settings(‘com.canonical.Unity.Lenses’)

The key we are interested in is ‘remote-content-search’, and it can have one of two value, ‘all’ or ‘none’.  Since my locoteams-scope performs only remote searches, by calling the API on, if the user has asked that no remote searches be made, this scope will return without doing anything.

And that’s it!  That’s all you need to do in order to make your lens or scope follow the user’s privacy settings.

Now, before we get to the comments, I’d like to kindly point out that this post is about how to check the privacy setting in your lens or scope.  It is not about whether or not we should be doing remote searches in the dash, or how you would rather the feature be implemented.  If you want to pile on to those argument some more, there are dozens of open threads all over the internet where you can do that.  Please don’t do it here.


I wasn’t aware, but there is a PreferencesManager class in Unity 6 (Ubuntu 12.10) that lets you access the same settings:

You should use this API instead of going directly to GSettings/DConf.

This entry was posted in OpenSource, Programming, Uncategorized, Upstream, Work and tagged , , , , , , , , , , . Bookmark the permalink.

12 Responses to Adding privacy setting support to your Unity Lens

  1. Marcus says:

    This shows that it would have been smarter to have lenses actually run in a sandbox and have the unity process control what a lens can and cannot access, making it more convenient to both users (possibility of per-lens settings) and developers.
    The way that lenses currently work is just wrong by design because users need to trust individual developers (in case of community extensions) to actually honor their privacy, which in the scope of “one hundred scopes” is basically impossible.

    • Alan Bell says:

      There isn’t really an infrastructure in which to sandbox things as untrusted processes, might be nice if there was, but that isn’t the issue here. You are basically right though, having the privacy implementation opt-in for lens authors is really not the opt-in that people are asking for.

      • Michael Hall says:

        We could sandbox them with apparmor, but then it wouldn’t be something the user could easily toggle on or off.

  2. realloc says:

    Thanks for sharing the code.

  3. Randall Ross says:

    Thanks for posting this example and for contributing code rather than contributing “rant” :)
    Now for the million dollar question: Is the locoteams-scope (a.k.a Community Lens) once again usable?

  4. Todor says:

    What file is this, where to find it?

Comments are closed.