Skip to content
This repository has been archived by the owner on Nov 4, 2023. It is now read-only.

Let apps receive location updates in the background #387

Open
wants to merge 3 commits into
base: xenial
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ pkg_check_modules(QMENUMODEL REQUIRED qmenumodel)
pkg_check_modules(GD3 REQUIRED gnome-desktop-3.0)
pkg_check_modules(UAL REQUIRED ubuntu-app-launch-2)
pkg_check_modules(UBUNTUGESTURES REQUIRED UbuntuGestures)
pkg_check_modules(QTDBUSTEST REQUIRED
libqtdbustest-1
libqtdbusmock-1
)

### Check UbuntuGestures private headers. No pkg-config (.pc) file is provided for them
find_path(UBUNTUGESTUREPRIV
Expand Down Expand Up @@ -183,6 +179,10 @@ add_subdirectory(qml)
# Tests
set(NO_TESTS OFF CACHE BOOL "Disable tests.")
if (NOT NO_TESTS)
pkg_check_modules(QTDBUSTEST REQUIRED
libqtdbustest-1
libqtdbusmock-1
)
include(CTest)
enable_testing()
add_subdirectory(tests)
Expand Down
59 changes: 31 additions & 28 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ Build-Depends:
android-headers,
cmake,
cmake-extras,
dbus-test-runner,
dbus-test-runner <!nocheck>,
debhelper (>= 9),
dh-apparmor,
doxyqml,
doxyqml <!cross>,
g++:native,
gdb,
graphviz,
gsettings-ubuntu-schemas (>= 0.0.2+14.10.20140815),
gdb <!cross>,
graphviz <!cross>,
gsettings-ubuntu-schemas (>= 0.0.2+14.10.20140815) <!nocheck>,
libandroid-properties-dev,
libconnectivity-qt1-dev (>= 0.7.1),
libevdev-dev,
libgeonames-dev (>= 0.2),
libgl1-mesa-dev[!arm64 !armhf] | libgl-dev[!arm64 !armhf],
libgl1-mesa-dri,
libgl1-mesa-dri <!nocheck>,
libgles2-mesa-dev[arm64 armhf],
libglib2.0-dev,
libgnome-desktop-3-dev,
Expand All @@ -29,11 +29,11 @@ Build-Depends:
libpam0g-dev,
libpulse-dev,
libqmenumodel-dev (>= 0.2.12),
libqt5sql5-sqlite,
libqt5sql5-sqlite <!nocheck>,
libqt5svg5-dev,
libqt5xmlpatterns5-dev,
libqtdbusmock1-dev (>= 0.7),
libqtdbustest1-dev,
libqtdbusmock1-dev (>= 0.7) <!nocheck>,
libqtdbustest1-dev <!nocheck>,
libsystemsettings-dev,
libubuntu-app-launch2-dev,
libubuntu-download-manager-common-dev,
Expand All @@ -47,32 +47,32 @@ Build-Depends:
libxcb1-dev[!arm64 !armhf],
libxi-dev[!arm64 !armhf],
pkg-config,
python3-all:any,
python3-setuptools,
qml-module-qt-labs-folderlistmodel,
qml-module-qt-labs-settings,
qml-module-qtmultimedia (>= 5.6),
qml-module-qtqml-statemachine,
qml-module-qtquick-layouts,
qml-module-qtquick-xmllistmodel,
qml-module-qtquick2,
qml-module-qtsysteminfo,
qml-module-qttest,
qml-module-ubuntu-components (>= 1.3.2030) | qml-module-ubuntu-components-gles (>= 1.3.2030),
qml-module-ubuntu-layouts,
qml-module-ubuntu-settings-components,
qml-module-ubuntu-test,
python3-all:any <!nocheck>,
python3-setuptools <!nocheck>,
qml-module-qt-labs-folderlistmodel <!nocheck>,
qml-module-qt-labs-settings <!nocheck>,
qml-module-qtmultimedia (>= 5.6) <!nocheck>,
qml-module-qtqml-statemachine <!nocheck>,
qml-module-qtquick-layouts <!nocheck>,
qml-module-qtquick-xmllistmodel <!nocheck>,
qml-module-qtquick2 <!nocheck>,
qml-module-qtsysteminfo <!nocheck>,
qml-module-qttest <!nocheck>,
qml-module-ubuntu-components (>= 1.3.2030) | qml-module-ubuntu-components-gles (>= 1.3.2030) <!nocheck>,
qml-module-ubuntu-layouts <!nocheck>,
qml-module-ubuntu-settings-components <!nocheck>,
qml-module-ubuntu-test <!nocheck>,
qtbase5-dev (>= 5.6),
qtbase5-dev-tools,
qtbase5-private-dev (>= 5.6),
qtdbustest-runner,
qtdbustest-runner <!nocheck>,
qtdeclarative5-dev (>= 5.6),
qtdeclarative5-dev-tools,
qtdeclarative5-private-dev (>= 5.6),
qtdeclarative5-ubuntu-content1,
ttf-ubuntu-font-family,
ubports-wallpapers,
xvfb,
ttf-ubuntu-font-family <!nocheck>,
ubports-wallpapers <!nocheck>,
xvfb <!nocheck>,
Standards-Version: 3.9.4
Homepage: https://github.com/ubports/unity8
Vcs-Git: https://github.com/ubports/unity8
Expand Down Expand Up @@ -174,6 +174,7 @@ Description: Unity 8 shell (common files)

Package: unity8-autopilot
Architecture: all
Build-Profiles: <!cross>
Depends:
autopilot-qt5 (>= 1.4),
gir1.2-glib-2.0,
Expand All @@ -199,6 +200,7 @@ Description: Test package for Unity 8 shell
Package: unity8-tests
Architecture: any
Multi-Arch: same
Build-Profiles: <!cross>
Pre-Depends:
${misc:Pre-Depends},
Depends:
Expand Down Expand Up @@ -266,6 +268,7 @@ Package: unity8-doc
Section: doc
Architecture: all
Multi-Arch: foreign
Build-Profiles: <!cross>
Depends:
${misc:Depends},
Description: Documentation for Unity8
Expand Down
11 changes: 10 additions & 1 deletion debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ DEB_HOST_ARCH ?= $(shell dpkg-architecture -qDEB_HOST_ARCH)
# Skip tests on the archs they are known to be flaky with current configuration
testskip_architectures := arm64 powerpc ppc64el s390x

ifneq (,$(findstring nocheck,$(DEB_BUILD_OPTIONS)))
CONFIGURE_OPTS += "-DNO_TESTS=ON"
endif

%:
dh $@ --parallel --fail-missing --with python3

override_dh_auto_configure:
# Debian defines CMAKE_INSTALL_LOCALSTATEDIR as /usr/var, which is wrong.
# So until Debian bug 719148 is fixed, do it ourselves.
dh_auto_configure -- -DCMAKE_INSTALL_LOCALSTATEDIR="/var"
dh_auto_configure -- -DCMAKE_INSTALL_LOCALSTATEDIR="/var" $(CONFIGURE_OPTS)

override_dh_auto_build:
# doc is not a default target
Expand All @@ -39,12 +43,17 @@ endif
endif

override_dh_install:
ifeq ($(DEB_BUILD_GNU_TYPE),$(DEB_HOST_GNU_TYPE))
# install autopilot tests
cd tests/autopilot; \
set -ex; for python in $(shell py3versions -r); do \
$$python setup.py install --root=$(CURDIR)/debian/tmp --install-layout=deb; \
done; \
cd $(CURDIR)
else
rm -f debian/tmp/usr/share/unity8/unlock-device
rm -rf debian/tmp/usr/lib/*/unity8/qml/mocks
endif
dh_install -X'*.pyc' --fail-missing

# use private lib directories
Expand Down
1 change: 1 addition & 0 deletions debian/unity8-private.install
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ usr/lib/*/unity8/qml/Greeter
usr/lib/*/unity8/qml/LightDM
usr/lib/*/unity8/qml/Lights
usr/lib/*/unity8/qml/Powerd
usr/lib/*/unity8/qml/ProcessControl
usr/lib/*/unity8/qml/ScreenshotDirectory
usr/lib/*/unity8/qml/SessionBroadcast
usr/lib/*/unity8/qml/UInput
Expand Down
1 change: 1 addition & 0 deletions plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ add_subdirectory(Greeter)
add_subdirectory(LightDM)
add_subdirectory(Lights)
add_subdirectory(Powerd)
add_subdirectory(ProcessControl)
add_subdirectory(ScreenshotDirectory)
add_subdirectory(SessionBroadcast)
add_subdirectory(Ubuntu)
Expand Down
21 changes: 21 additions & 0 deletions plugins/ProcessControl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
add_definitions(-DSM_BUSNAME=sessionBus)

add_library(ProcessControl-qml MODULE
LocationWatcher.cpp
ProcessControl.cpp
plugin.cpp
)

target_link_libraries(ProcessControl-qml
Qt5::DBus Qt5::Qml
)

target_include_directories(ProcessControl-qml PRIVATE ${CMAKE_CURRENT_BINARY_DIR})

add_unity8_plugin(ProcessControl 0.1 ProcessControl TARGETS ProcessControl-qml)

set(DBUS_IFACE_DIR "${CMAKE_INSTALL_PREFIX}/share/dbus-1/interfaces")

install(FILES com.lomiri.ProcessControl.xml
DESTINATION "${DBUS_IFACE_DIR}"
)
99 changes: 99 additions & 0 deletions plugins/ProcessControl/LocationWatcher.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright (C) 2021 UBports Foundation.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Alberto Mardegan <mardy@users.sourceforge.net>
*/

#include "LocationWatcher.h"

#include "ProcessControl.h"

#include <QDBusConnection>
#include <QDebug>
#include <QStringList>
#include <QTimer>

namespace {
const QString locationServiceName = QStringLiteral("com.ubuntu.location.Service");
const QString locationObjectPath = QStringLiteral("/com/ubuntu/location/Service");
const QString propertiesInterface = QStringLiteral("org.freedesktop.DBus.Properties");
const QString methodPropertiesChanged = QStringLiteral("PropertiesChanged");
} // namespace

class LocationWatcherPrivate: public QObject
{
Q_OBJECT

public:
LocationWatcherPrivate(ProcessControl *processControl);

private Q_SLOTS:
void onPropertiesChanged(const QString &interface,
const QVariantMap &changedProps,
const QStringList &invalidatedProps);

private:
friend class LocationWatcher;
ProcessControl *m_processControl;
QDBusConnection m_connection;
QStringList m_clientApplications;
};

LocationWatcherPrivate::LocationWatcherPrivate(ProcessControl *processControl):
QObject(),
m_processControl(processControl),
m_connection(QDBusConnection::systemBus())
{
m_connection.connect(locationServiceName,
locationObjectPath,
propertiesInterface,
methodPropertiesChanged,
this,
SLOT(onPropertiesChanged(QString,QVariantMap,QStringList)));
}

void LocationWatcherPrivate::onPropertiesChanged(const QString &interface,
const QVariantMap &changedProps,
const QStringList &invalidatedProps)
{
Q_UNUSED(interface);
Q_UNUSED(invalidatedProps);

qDebug() << Q_FUNC_INFO << changedProps;
const auto i = changedProps.find(QStringLiteral("ClientApplications"));
if (i != changedProps.end()) {
const QStringList appIds = i.value().toStringList();
qDebug() << "Location clients changed:" << appIds;
/* We need to strip off the version (app IDs are in the form
* "<publisher>_<app-name>_<version>") */
m_clientApplications.clear();
for (const QString &appId: appIds) {
QStringList parts = appId.split('_');
QString versionLessAppId = parts.mid(0, 2).join('_');
m_clientApplications.append(versionLessAppId);
}
m_processControl->setAwakenProcesses(m_clientApplications);
}
}

LocationWatcher::LocationWatcher(ProcessControl *processControl):
QObject(processControl),
d_ptr(new LocationWatcherPrivate(processControl))
{
}

LocationWatcher::~LocationWatcher() = default;

#include "LocationWatcher.moc"
41 changes: 41 additions & 0 deletions plugins/ProcessControl/LocationWatcher.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2021 UBports Foundation.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Alberto Mardegan <mardy@users.sourceforge.net>
*/

#ifndef LOMIRI_LOCATIONWATCHER_H
#define LOMIRI_LOCATIONWATCHER_H

#include <QObject>
#include <QScopedPointer>

class ProcessControl;

class LocationWatcherPrivate;
class LocationWatcher: public QObject
{
Q_OBJECT

public:
explicit LocationWatcher(ProcessControl *processControl);
~LocationWatcher();

private:
Q_DECLARE_PRIVATE(LocationWatcher)
QScopedPointer<LocationWatcherPrivate> d_ptr;
};

#endif // LOMIRI_LOCATIONWATCHER_H
Loading