content-hub-service calls ubuntu_app_launch_start_application to both start apps and switch focus to apps that are already running. This has always worked great in the click world. When running in the unity8-session snap it's failing when it's used to switch focus to an existing instance of an app. For example, when address-book-app imports an avatar from gallery-app, it doesn't switch focus back to address-book-app and i see this in the log:
Jan 11 14:53:23 mucho com.ubuntu.content.dbus.Service[2955]: (process:3558): ubuntu-app-launch-WARNING **: Unable to stop app 'gallery-app_gallery-app_12': Unable to get SystemD to stop 'ubuntu-app-launch-application-snap-gallery-app_gallery-app_12-.service': GDBus.Error:org.freedesktop.systemd1.TransactionIsDestructive: Transaction is destructive.
Jan 11 14:53:23 mucho com.ubuntu.content.dbus.Service[2955]: (process:3558): ubuntu-app-launch-WARNING **: Unity didn't respond in 500ms to resume the app
Jan 11 14:53:29 mucho com.ubuntu.content.dbus.Service[2955]: QMap<QString, QString> {anonymous}::info_for_app_id(QString) Failed to create Application for "webbrowser-app"
Jan 11 14:53:29 mucho com.ubuntu.content.dbus.Service[2955]: (process:3558): ubuntu-app-launch-DEBUG: Got 18115 bytes from snapd
Jan 11 14:53:29 mucho com.ubuntu.content.dbus.Service[2955]: (process:3558): ubuntu-app-launch-DEBUG: Got 591 bytes from snapd
Jan 11 14:53:29 mucho com.ubuntu.content.dbus.Service[2955]: (process:3558): ubuntu-app-launch-DEBUG: Application Snap object for AppID 'gallery-app_gallery-app_12'
Jan 11 14:53:29 mucho com.ubuntu.content.dbus.Service[2955]: (process:3558): ubuntu-app-launch-DEBUG: Creating a new SystemD for 'gallery-app_gallery-app_12' instance ''
Jan 11 14:53:29 mucho com.ubuntu.content.dbus.Service[2955]: (process:3558): ubuntu-app-launch-DEBUG: Found 1 instances for AppID 'gallery-app_gallery-app_12'
Jan 11 14:53:29 mucho com.ubuntu.content.dbus.Service[2955]: (process:3558): ubuntu-app-launch-DEBUG: Got 585 bytes from snapd
Jan 11 14:53:29 mucho com.ubuntu.content.dbus.Service[2955]: (process:3558): ubuntu-app-launch-DEBUG: Got 18115 bytes from snapd
Jan 11 14:53:29 mucho com.ubuntu.content.dbus.Service[2955]: (process:3558): ubuntu-app-launch-DEBUG: Got 585 bytes from snapd
Jan 11 14:53:29 mucho com.ubuntu.content.dbus.Service[2955]: (process:3558): ubuntu-app-launch-DEBUG: Application Snap object for AppID 'address-book-app_address-book-app_19'
Jan 11 14:53:29 mucho com.ubuntu.content.dbus.Service[2955]: (process:3558): ubuntu-app-launch-DEBUG: Initializing params for an new instance::SystemD for: address-book-app_address-book-app_19
Jan 11 14:53:29 mucho com.ubuntu.content.dbus.Service[2955]: (process:3558): ubuntu-app-launch-DEBUG: Getting snap specific environment
Jan 11 14:53:29 mucho com.ubuntu.content.dbus.Service[2955]: (process:3558): ubuntu-app-launch-DEBUG: Copying Environment: DISPLAY
Jan 11 14:53:29 mucho com.ubuntu.content.dbus.Service[2955]: (process:3558): ubuntu-app-launch-DEBUG: Unable to copy environment 'DISPLAY'
Jan 11 14:53:29 mucho com.ubuntu.content.dbus.Service[2955]: (process:3558): ubuntu-app-launch-DEBUG: Copying Environment: DBUS_SESSION_BUS_ADDRESS
Jan 11 14:53:29 mucho com.ubuntu.content.dbus.Service[2955]: (process:3558): ubuntu-app-launch-DEBUG: Copying Environment: DBUS_STARTER_BUS_TYPE
Jan 11 14:53:29 mucho com.ubuntu.content.dbus.Service[2955]: (process:3558): ubuntu-app-launch-DEBUG: Copying Environment: DBUS_DEBUG_OUTPUT
Jan 11 14:53:29 mucho com.ubuntu.content.dbus.Service[2955]: (process:3558): ubuntu-app-launch-DEBUG: Copying Environment: DBUS_STARTER_ADDRESS
Jan 11 14:53:29 mucho com.ubuntu.content.dbus.Service[2955]: (process:3558): ubuntu-app-launch-DEBUG: Copying Environment: MIR_SERVER_HOST_SOCKET
Jan 11 14:53:29 mucho com.ubuntu.content.dbus.Service[2955]: (process:3558): ubuntu-app-launch-DEBUG: Copying Environment: MIR_SOCKET
Jan 11 14:53:29 mucho com.ubuntu.content.dbus.Service[2955]: (process:3558): ubuntu-app-launch-DEBUG: Copying Environment: MIR_SERVER_PLATFORM_PATH
Jan 11 14:53:29 mucho com.ubuntu.content.dbus.Service[2955]: (process:3558): ubuntu-app-launch-DEBUG: Copying Environment: MIR_SERVER_PROMPT_FILE
Jan 11 14:53:29 mucho com.ubuntu.content.dbus.Service[2955]: (process:3558): ubuntu-app-launch-DEBUG: Copying Environment: MIR_CLIENT_PLATFORM_PATH
Jan 11 14:53:29 mucho com.ubuntu.content.dbus.Service[2955]: (process:3558): ubuntu-app-launch-DEBUG: Copying Environment: MIR_SERVER_NAME
Jan 11 14:53:29 mucho com.ubuntu.content.dbus.Service[2955]: (process:3558): ubuntu-app-launch-DEBUG: Copying Environment: UBUNTU_APP_LAUNCH_LIBERTINE_LAUNCH
Jan 11 14:53:29 mucho com.ubuntu.content.dbus.Service[2955]: (process:3558): ubuntu-app-launch-DEBUG: Copying Environment: UBUNTU_APP_LAUNCH_LEGACY_ROOT
Jan 11 14:53:29 mucho com.ubuntu.content.dbus.Service[2955]: (process:3558): ubuntu-app-launch-DEBUG: Copying Environment: UBUNTU_APP_LAUNCH_XMIR_PATH
Jan 11 14:53:29 mucho com.ubuntu.content.dbus.Service[2955]: (process:3558): ubuntu-app-launch-DEBUG: Copying Environment: UBUNTU_APP_LAUNCH_DEMANGLER
Jan 11 14:53:29 mucho com.ubuntu.content.dbus.Service[2955]: (process:3558): ubuntu-app-launch-DEBUG: Copying Environment: UBUNTU_APP_LAUNCH_OOM_HELPER
Jan 11 14:53:29 mucho com.ubuntu.content.dbus.Service[2955]: (process:3558): ubuntu-app-launch-DEBUG: Copying Environment: UBUNTU_APP_LAUNCH_SNAPPY_XMIR_HELPER
Jan 11 14:53:29 mucho com.ubuntu.content.dbus.Service[2955]: (process:3558): ubuntu-app-launch-DEBUG: Environment length: 698
Jan 11 14:53:29 mucho com.ubuntu.content.dbus.Service[2955]: (process:3558): ubuntu-app-launch-DEBUG: Creating a new SystemD for 'address-book-app_address-book-app_19' instance ''
Jan 11 14:53:29 mucho com.ubuntu.content.dbus.Service[2955]: (process:3558): ubuntu-app-launch-DEBUG: Asking systemd to start task for: address-book-app_address-book-app_19
Jan 11 14:53:29 mucho com.ubuntu.content.dbus.Service[2955]: (process:3558): ubuntu-app-launch-DEBUG: Started Message Callback: address-book-app_address-book-app_19
Jan 11 14:53:29 mucho com.ubuntu.content.dbus.Service[2955]: (process:3558): ubuntu-app-launch-DEBUG: Remote error: org.freedesktop.systemd1.UnitExists
Jan 11 14:53:29 mucho com.ubuntu.content.dbus.Service[2955]: (process:3558): ubuntu-app-launch-DEBUG: Sending resume request
Jan 11 14:53:29 mucho com.ubuntu.content.dbus.Service[2955]: (process:3558): ubuntu-app-launch-DEBUG: No URIs to send
Jan 11 14:53:29 mucho com.ubuntu.content.dbus.Service[2955]: (process:3558): ubuntu-app-launch-DEBUG: Second Exec complete
I was wrong about content-hub triggering that bug with systemd not cleaning up units. I can actually reproduce it by launching the addressbook, closing it then trying to launch it again.