| 1 |
Lomiri Push Service Client Low Level Developer Guide |
| 2 |
==================================================== |
| 3 |
|
| 4 |
:Version: 0.100.3 |
| 5 |
|
| 6 |
.. contents:: |
| 7 |
|
| 8 |
Introduction |
| 9 |
------------ |
| 10 |
|
| 11 |
This document describes how to use the Push Client service from a platform integrator's point of view. |
| 12 |
Application developers are expected to use a much simpler API, in turn based on the lower-level API described here. |
| 13 |
|
| 14 |
The expected audience for this document is, therefore, either platform developers, or application developers who, |
| 15 |
for whatever reason, can't use or prefer not to use the available higher level APIs. |
| 16 |
|
| 17 |
--------- |
| 18 |
|
| 19 |
.. include:: _description.txt |
| 20 |
|
| 21 |
|
| 22 |
The PushNotifications Service |
| 23 |
----------------------------- |
| 24 |
|
| 25 |
:Service: com.lomiri.PushNotifications |
| 26 |
:Object path: /com/lomiri/PushNotifications/QUOTED_PKGNAME |
| 27 |
|
| 28 |
The PushNotifications service handles registering the device with the Push service to enable delivery of messages to |
| 29 |
it. |
| 30 |
|
| 31 |
Each package has to use a separate object path for security reasons, that's why the object path includes QUOTED_PKGNAME. |
| 32 |
For example, in the case of the music application, the package name is ``app.example`` and QUOTED_PKGNAME is ``app_2eexample``. |
| 33 |
Everything that is not a letter or digit has to be quoted as _XX where XX are the hex digits of the character. In practice, |
| 34 |
this means replacing "." with "_2e" and "-" with "_2d" |
| 35 |
|
| 36 |
.. note:: For applications that are not installed as part of click packages, the QUOTED_PKGNAME is "_" and the APP_ID when required is |
| 37 |
_PACKAGENAME. |
| 38 |
|
| 39 |
For example, for lomiri-system-settings: |
| 40 |
|
| 41 |
* QUOTED_PKGNAME is _ |
| 42 |
* APP_ID is _lomiri-system-settings |
| 43 |
|
| 44 |
|
| 45 |
com.lomiri.PushNotifications.Register |
| 46 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 47 |
|
| 48 |
``string Register(string APP_ID)`` |
| 49 |
|
| 50 |
Example:: |
| 51 |
|
| 52 |
$ gdbus call --session --dest com.lomiri.PushNotifications --object-path /com/lomiri/PushNotifications/app_2eexample \ |
| 53 |
--method com.lomiri.PushNotifications.Register app.example_app |
| 54 |
|
| 55 |
('LeA4tRQG9hhEkuhngdouoA==',) |
| 56 |
|
| 57 |
The Register method takes as argument the APP_ID (in the example, |
| 58 |
app.example_app) and returns a token identifying the user and device. |
| 59 |
|
| 60 |
The APP_ID is as described in the `ApplicationId documentation <https://wiki.ubuntu.com/AppStore/Interfaces/ApplicationId>`__ |
| 61 |
except that the version is treated as optional. Therefore both ``app.example_app`` and ``app.example_app_1.3.496`` |
| 62 |
are valid. Keep in mind that while both versioned and unversioned APP_IDs are valid, they are still different and will affect |
| 63 |
which notifications are delivered to the application. Unversioned IDs mean the token will be the same after updates and the application |
| 64 |
will receive old notifications, while versioned IDs mean the app needs to explicitly ask to get older messages delivered. |
| 65 |
|
| 66 |
Register is idempotent, and calling it multiple times returns the same token. |
| 67 |
|
| 68 |
This token is later used by the application server to indicate the recipient of notifications. |
| 69 |
|
| 70 |
.. FIXME crosslink to server app |
| 71 |
|
| 72 |
.. note:: There is currently no way to send a push message to all of a user's devices. The application server has to send to |
| 73 |
each registered device individually instead. |
| 74 |
|
| 75 |
com.lomiri.PushNotifications.Unregister |
| 76 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 77 |
|
| 78 |
``void Unregister(string APP_ID)`` |
| 79 |
|
| 80 |
Example:: |
| 81 |
|
| 82 |
$ gdbus call --session --dest com.lomiri.PushNotifications --object-path /com/lomiri/PushNotifications/app_2eexample \ |
| 83 |
--method com.lomiri.PushNotifications.Unregister app.example_app |
| 84 |
|
| 85 |
The Unregister method invalidates the token obtained via `Register <#com-lomiri-pushnotifications-register>`_ therefore disabling |
| 86 |
reception of push messages. |
| 87 |
|
| 88 |
The method takes as argument the APP_ID (in the example, app.example_app) and returns nothing. |
| 89 |
|
| 90 |
The APP_ID is as described in the `ApplicationId documentation <https://wiki.ubuntu.com/AppStore/Interfaces/ApplicationId>`__ |
| 91 |
except that the version is treated as optional. Therefore both ``app.example_app`` and ``app.example_app_1.3.496`` |
| 92 |
are valid. |
| 93 |
|
| 94 |
The Postal Service |
| 95 |
------------------ |
| 96 |
|
| 97 |
:Service: com.lomiri.Postal |
| 98 |
:Object path: /com/lomiri/Postal/QUOTED_PKGNAME |
| 99 |
|
| 100 |
The Postal service delivers the actual messages to the applications. After the application is registered, the push client will begin |
| 101 |
delivering messages to the device, which will then (possibly) cause specific notifications to be presented to the user (message bubbles, |
| 102 |
sounds, haptic feedbak, etc.) Regardless of whether the user acknowledges those notifications or not, the payload of the push message |
| 103 |
is put in the Postal service for the application to pick up. |
| 104 |
|
| 105 |
Because user response to notifications can cause application activation, apps should check the status of the Postal service every time |
| 106 |
the application activates. |
| 107 |
|
| 108 |
com.lomiri.Postal.Post |
| 109 |
~~~~~~~~~~~~~~~~~~~~~~ |
| 110 |
|
| 111 |
``void Post(string APP_ID, string message)`` |
| 112 |
|
| 113 |
Example:: |
| 114 |
|
| 115 |
gdbus call --session --dest com.lomiri.Postal --object-path /com/lomiri/Postal/app_2eexample \ |
| 116 |
--method com.lomiri.Postal.Post app.example_app \ |
| 117 |
'"{\"message\": \"foobar\", \"notification\":{\"card\": {\"summary\": \"yes\", \"body\": \"hello\", \"popup\": true, \"persist\": true}}}"' |
| 118 |
|
| 119 |
|
| 120 |
The arguments for the Post method are APP_ID (in the example, app.example_app) and a JSON string |
| 121 |
`describing a push message. <#helper-output-format>`__ |
| 122 |
|
| 123 |
Depending on the contents of the push message it may trigger user-facing notifications, and will queue a |
| 124 |
message for the app to get via the `PopAll <#com-lomiri-postal-popalls>`__ method. |
| 125 |
|
| 126 |
The APP_ID is as described in the `ApplicationId documentation <https://wiki.ubuntu.com/AppStore/Interfaces/ApplicationId>`__ |
| 127 |
except that the version is treated as optional. Therefore both ``app.example_app`` and ``app.example_app_1.3.496`` |
| 128 |
are valid. |
| 129 |
|
| 130 |
.. note:: Post is useful as a unified frontend for notifications in Lomiri, since it wraps and abstracts several different APIs. |
| 131 |
|
| 132 |
com.lomiri.Postal.PopAll |
| 133 |
~~~~~~~~~~~~~~~~~~~~~~~~ |
| 134 |
|
| 135 |
``array{string} PopAll(string APP_ID)`` |
| 136 |
|
| 137 |
Example:: |
| 138 |
|
| 139 |
$ gdbus call --session --dest com.lomiri.Postal --object-path /com/lomiri/Postal/app_2eexample \ |
| 140 |
--method com.lomiri.Postal.PopAll app.example_app |
| 141 |
|
| 142 |
(['{"foo": "bar", ....}'],) |
| 143 |
|
| 144 |
The argument for the PopAll method is the APP_ID and it returns a list of strings, each string being a separate postal |
| 145 |
message, the "message" element of a helper's output fed from `Post <#com-lomiri-postal-post>`__ |
| 146 |
or from the Push service, |
| 147 |
|
| 148 |
Post Signal |
| 149 |
~~~~~~~~~~~ |
| 150 |
|
| 151 |
``void Post(string APP_ID)`` |
| 152 |
|
| 153 |
Every time a notification is posted, the postal service will emit the Post signal. Your app can connect to it to react to |
| 154 |
incoming notifications if it's running when they arrive. Remember that on Lomiri, the application lifecycle means |
| 155 |
it will often **not** be running when notifications arrive. If the application is in the foreground when a notification |
| 156 |
arrives, the notification **will not** be presented. |
| 157 |
|
| 158 |
The object path is similar to that of the Postal service methods, containing the QUOTED_PKGNAME. |
| 159 |
|
| 160 |
Persistent Notification Management |
| 161 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 162 |
|
| 163 |
Some notifications are persistent, meaning that, after they are presented, they don't disappear automatically. |
| 164 |
This API allows the app to manage that type of notifications. |
| 165 |
|
| 166 |
On each notification there's an optional ``tag`` field, used for this purpose. |
| 167 |
|
| 168 |
``array(string) ListPersistent(string APP_ID)`` |
| 169 |
|
| 170 |
Returns a list of the tags of notifications with the "persist" element set to true that are visible to the user right now. |
| 171 |
|
| 172 |
``void ClearPersistent(string APP_ID, [tag1, tag2,....])`` |
| 173 |
|
| 174 |
Clears persistent notifications for that app by tag(s). If none given, match all. |
| 175 |
|
| 176 |
``void SetCounter(string APP_ID, int count int, bool visible)`` |
| 177 |
|
| 178 |
Set the counter to the given values. |
| 179 |
|
| 180 |
|
| 181 |
.. include:: _common.txt |