From 42c8114866eb3e9d8c13638e96a05e99a8f1ecb8 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Tue, 13 Apr 2021 11:19:08 +0200 Subject: [PATCH] [utilities] Add operation to reset aliendalvik. JB#24058 Stop alien, remove the /home/.android directory (saving any packaged apks to be reinstalled afterwards), then restart it. Re-install any store packaged apks. If alien has been uninstalled but /home/.android is still present, then this option can be used to remove all that residual data. Also removed obsolete tracker reset service workaround that hasn't been used for a long time. --- plugin/utiltools.cpp | 10 +++++ plugin/utiltools.h | 5 +++ qml/ActionList.qml | 3 +- qml/plugins/ResetAlien.qml | 26 +++++++++++++ rpm/sailfish-utilities.spec | 1 - tools/CMakeLists.txt | 8 +--- tools/reset_aliendalvik.sh | 54 ++++++++++++++++++++++++++ tools/sailfish_tools_system_action.cpp | 5 ++- tools/tracker-reindex.service.in | 5 --- 9 files changed, 102 insertions(+), 15 deletions(-) create mode 100644 qml/plugins/ResetAlien.qml create mode 100644 tools/reset_aliendalvik.sh delete mode 100644 tools/tracker-reindex.service.in diff --git a/plugin/utiltools.cpp b/plugin/utiltools.cpp index 1a6857d..afa269d 100644 --- a/plugin/utiltools.cpp +++ b/plugin/utiltools.cpp @@ -35,6 +35,16 @@ void UtilTools::restartLipstick(QJSValue successCallback, QJSValue errorCallback execute(SystemTool, QStringList("restart_lipstick"), successCallback, errorCallback); } +void UtilTools::resetAliendalvik(QJSValue successCallback, QJSValue errorCallback) +{ + execute(SystemTool, QStringList("reset_aliendalvik"), successCallback, errorCallback); +} + +bool UtilTools::dirExists(const QString &path) +{ + return QDir(path).exists(); +} + void UtilTools::handleProcessExit(int exitCode, QProcess::ExitStatus status) { QProcess *process = qobject_cast(sender()); diff --git a/plugin/utiltools.h b/plugin/utiltools.h index f2342a3..33f783a 100644 --- a/plugin/utiltools.h +++ b/plugin/utiltools.h @@ -24,6 +24,11 @@ class UtilTools: public QObject Q_INVOKABLE void restartLipstick(QJSValue successCallback = QJSValue::UndefinedValue, QJSValue errorCallback = QJSValue::UndefinedValue); + Q_INVOKABLE void resetAliendalvik(QJSValue successCallback = QJSValue::UndefinedValue, + QJSValue errorCallback = QJSValue::UndefinedValue); + + Q_INVOKABLE bool dirExists(const QString &path); + private slots: void handleProcessExit(int exitCode, QProcess::ExitStatus status); diff --git a/qml/ActionList.qml b/qml/ActionList.qml index bbf5b3b..bdc6da0 100644 --- a/qml/ActionList.qml +++ b/qml/ActionList.qml @@ -29,7 +29,8 @@ Column { plugins.append(info) } var names = [ "RestartNetwork", "RestartUI", - "CleanPackageCache", "CleanTracker" ] + "CleanPackageCache", "CleanTracker", + "ResetAlien" ] for (var i = 0; i < names.length; ++i) justLoad(names[i]) } diff --git a/qml/plugins/ResetAlien.qml b/qml/plugins/ResetAlien.qml new file mode 100644 index 0000000..fa92fa1 --- /dev/null +++ b/qml/plugins/ResetAlien.qml @@ -0,0 +1,26 @@ +import QtQuick 2.0 +import Sailfish.Silica 1.0 +import Sailfish.Utilities 1.0 + +ActionItem { + visible: UtilTools.dirExists("/home/.android") + //% "Androidâ„¢ App Support" + title: qsTrId("sailfish-tools-he-android_app_support") + //% "Reset" + actionName: qsTrId("sailfish-tools-bt-reset") + //% "Completely reset Android App support, removing " + //% "all settings, apps and app data. Android data in " + //% "your home directory will not be removed, and any " + //% "Android apps installed from the Jolla store will " + //% "be reinstalled. You can also use this utility to clean " + //% "your Android data from your device after uninstalling " + //% "Android App Support. + description: qsTrId("sailfish-utilities-me-clean_aas_desc") + //% "Resetting Androidâ„¢ App Support" + remorseText: qsTrId("sailfish-utilities-me-clean_aas_remorse") + deviceLockRequired: false + + function action(on_reply, on_error) { + UtilTools.resetAliendalvik(on_reply, on_error) + } +} diff --git a/rpm/sailfish-utilities.spec b/rpm/sailfish-utilities.spec index a3b8343..e2e7e89 100644 --- a/rpm/sailfish-utilities.spec +++ b/rpm/sailfish-utilities.spec @@ -64,7 +64,6 @@ rm -rf %{buildroot} %{_datadir}/translations/settings-sailfish_utilities_eng_en.qm %dir %{_libdir}/qt5/qml/Sailfish/Utilities %{_libdir}/qt5/qml/Sailfish/Utilities/* -%{_userunitdir}/tracker-reindex.service %files ts-devel %defattr(-,root,root,-) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index f94c39b..001ab88 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -4,13 +4,6 @@ set(CMAKE_CXX_FLAGS configure_file(config.hpp.in config.hpp @ONLY) add_executable(sailfish_tools_system_action sailfish_tools_system_action.cpp) -configure_file(tracker-reindex.service.in tracker-reindex.service @ONLY) - -install(FILES - tracker-reindex.service - DESTINATION lib/systemd/user - ) - install(TARGETS sailfish_tools_system_action DESTINATION bin @@ -22,5 +15,6 @@ install(PROGRAMS restart_network.sh restart_lipstick.sh tracker_reindex.sh + reset_aliendalvik.sh DESTINATION share/sailfish-utilities ) diff --git a/tools/reset_aliendalvik.sh b/tools/reset_aliendalvik.sh new file mode 100644 index 0000000..52d27ec --- /dev/null +++ b/tools/reset_aliendalvik.sh @@ -0,0 +1,54 @@ +#!/bin/sh + +# Stop aliendalvik if running +if systemctl is-active --quiet aliendalvik + systemctl stop aliendalvik || : +fi +if systemctl is-active --quiet apkd + systemctl stop apkd || : +fi + +# Remove all launchers +rm -f /home/*/.local/share/applications/apkd_launcher_*.desktop || : +rm -f /home/*/.local/share/applications/apkd_handler_*.desktop || : +update-desktop-database + +if [ -f /opt/alien/system.img ]; then + # If alien installed, wipe /data, but keep any apps from the store + if [ -d /home/.android/data/aas-staging/app/packaged ]; then + # alien8 + mv /home/.android/data/aas-staging/app/packaged /home/.android + rm -rf /home/.android/data + mkdir -p /home/.android/data/aas-staging/app/ + mv /home/.android/packaged /home/.android/data/aas-staging/app/ + elif [ -d /home/.android/data/app/packaged ]; then + # alien4 + systemctl stop alien-settings + mv /home/.android/data/app/packaged /home/.android + rm -rf /home/.android/data + mkdir -p /home/.android/data/app/ + mv /home/.android/packaged /home/.android/data/app/ + /usr/bin/add-oneshot --now alien-create-build-prop + systemctl-user start alien-pre-start.service + else + # neither packaged dir is available, cleanup anyway + rm -rf /home/.android/data + fi + + # Start aliendalvik + systemctl start apkd + systemctl start aliendalvik + + sleep 5 + for apk in /home/.android/data/app/packaged/*.apk; do + /usr/bin/apkd-harbour-rpm-post $apk + done + for apk in /home/.android/data/aas-staging/app/packaged/*.apk; do + /usr/bin/apkd-harbour-rpm-post $apk + done +else + # Just cleanup all data + rm -rf /home/.android +fi + + diff --git a/tools/sailfish_tools_system_action.cpp b/tools/sailfish_tools_system_action.cpp index 0592a26..df1d29d 100644 --- a/tools/sailfish_tools_system_action.cpp +++ b/tools/sailfish_tools_system_action.cpp @@ -66,11 +66,14 @@ std::map actions = { }}, { "tracker_reindex", [](action_ctx const *) { return execute_own_utility("tracker_reindex.sh"); + }}, + { "reset_aliendalvik", [](action_ctx const *) { + return execute_own_utility("reset_aliendalvik.sh"); }} }; std::set root_actions = { - "repair_rpm_db", "restart_network" + "repair_rpm_db", "restart_network", "reset_aliendalvik" }; class BecomeRoot diff --git a/tools/tracker-reindex.service.in b/tools/tracker-reindex.service.in deleted file mode 100644 index 7323f09..0000000 --- a/tools/tracker-reindex.service.in +++ /dev/null @@ -1,5 +0,0 @@ -[Unit] -Description=Tracker database cleanup and reindexing - -[Service] -ExecStart=@DEPLOYMENT_PATH@/tracker_reindex.sh