+static bool api_added(uint8_t old_iface, uint8_t new_iface,
+ enum ofono_api api)
+{
+ if (!has_interface(old_iface, api) &&
+ has_interface(new_iface, api)) {
+ DBG("%s added", api2string(api));
+ return true;
+ }
+
+ return false;
+}
+
+static bool api_removed(uint8_t old_iface, uint8_t new_iface,
+ enum ofono_api api)
+{
+ if (has_interface(old_iface, api) &&
+ !has_interface(new_iface, api)) {
+ DBG("%s removed", api2string(api));
+ return true;
+ }
+
+ return false;
+}
+
+static void modem_update_interfaces(struct modem_data *modem,
+ uint8_t old_ifaces,
+ uint8_t new_ifaces)
+{
+ DBG("%s", modem->path);
+
+ if (api_added(old_ifaces, new_ifaces, OFONO_API_SIM)) {
+ if (!modem->imsi &&
+ !modem->set_powered) {
+ /*
+ * Only use do GetProperties() when
+ * device has not been powered up.
+ */
+ sim_get_properties(modem);
+ }
+ }
+
+ if (api_added(old_ifaces, new_ifaces, OFONO_API_CM)) {
+ if (modem->device) {
+ cm_get_properties(modem);
+ cm_get_contexts(modem);
+ }
+ }
+
+ if (api_added(old_ifaces, new_ifaces, OFONO_API_CDMA_CM)) {
+ if (ready_to_create_device(modem)) {
+ create_device(modem);
+ if (modem->registered)
+ add_cdma_network(modem);
+ }
+
+ if (modem->device)
+ cdma_cm_get_properties(modem);
+ }
+
+ if (api_added(old_ifaces, new_ifaces, OFONO_API_NETREG)) {
+ if (modem->attached)
+ netreg_get_properties(modem);
+ }
+
+ if (api_added(old_ifaces, new_ifaces, OFONO_API_CDMA_NETREG))
+ cdma_netreg_get_properties(modem);
+
+ if (api_removed(old_ifaces, new_ifaces, OFONO_API_CM)) {
+ if (modem->call_get_contexts) {
+ DBG("cancelling pending GetContexts call");
+ dbus_pending_call_cancel(modem->call_get_contexts);
+ dbus_pending_call_unref(modem->call_get_contexts);
+ modem->call_get_contexts = NULL;
+ }
+ remove_all_contexts(modem);
+ }
+
+ if (api_removed(old_ifaces, new_ifaces, OFONO_API_CDMA_CM))
+ remove_all_contexts(modem);
+
+ if (api_removed(old_ifaces, new_ifaces, OFONO_API_NETREG))
+ remove_all_networks(modem);
+
+ if (api_removed(old_ifaces, new_ifaces, OFONO_API_CDMA_NETREG))
+ remove_all_networks(modem);
+}
+
+static gboolean modem_changed(DBusConnection *conn, DBusMessage *message,