diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4b1e3d3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ + +# Final packages +RPMS/* + +# Binaries are created in the project folder (Sailfish SDK doesn't support shadow building yet) +Switch-My-Slot + +# Something Qt Creator generates +debugsources.list +documentation.list +debugfiles.list +debuglinks.list + +# object files, makefiles, environment-specific Creator settings +*.o +Makefile +*.pro.user +*.pro.user.* diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..df3a1e7 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 - 2021 Shou + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..7388dff --- /dev/null +++ b/README.md @@ -0,0 +1,22 @@ +# Switch My Slot +Switch My Slot is a SailfishOS app that helps you switch between android system A & system B slots if you are dualbooting with Android OS on an Android A/B device. This app saves you from the hassle of needing to use ssh/terminal/twrp while wanting to switch to another Android slot. + +Library used: [bootctl](https://android.googlesource.com/platform/system/extras/+/master/bootctl) + +What is A/B partitioning? + +https://source.android.com/devices/tech/ota/ab + +https://www.xda-developers.com/how-a-b-partitions-and-seamless-updates-affect-custom-development-on-xda/ + +## Requirements +1. Device with A/B partitions +2. Android rom should be compiled along with bootctl module + +[Checkout Android version](https://github.com/shoukolate/Switch-My-Slot-Android) + +[Checkout Ubuntu Touch version](https://github.com/ubports-xiaomi-sdm660/Switch-My-Slot-Ubuntu-Touch) + +

+ +

diff --git a/Screenshots/1.png b/Screenshots/1.png new file mode 100644 index 0000000..3bfd5be Binary files /dev/null and b/Screenshots/1.png differ diff --git a/Switch-My-Slot.desktop b/Switch-My-Slot.desktop new file mode 100644 index 0000000..2177a22 --- /dev/null +++ b/Switch-My-Slot.desktop @@ -0,0 +1,12 @@ +[Desktop Entry] +Type=Application +X-Nemo-Application-Type=silica-qt5 +Icon=Switch-My-Slot +Exec=Switch-My-Slot +Name=Switch My Slot +# translation example: +# your app name in German locale (de) +# +# Remember to comment out the following line, if you do not want to use +# a different app name in German locale (de). +Name[de]=Switch My Slot diff --git a/Switch-My-Slot.pro b/Switch-My-Slot.pro new file mode 100644 index 0000000..2f8889c --- /dev/null +++ b/Switch-My-Slot.pro @@ -0,0 +1,40 @@ +# NOTICE: +# +# Application name defined in TARGET has a corresponding QML filename. +# If name defined in TARGET is changed, the following needs to be done +# to match new name: +# - corresponding QML filename must be changed +# - desktop icon filename must be changed +# - desktop filename must be changed +# - icon definition filename in desktop file must be changed +# - translation filenames have to be changed + +# The name of your application +TARGET = Switch-My-Slot + +CONFIG += sailfishapp + +SOURCES += src/Switch-My-Slot.cpp + +DISTFILES += qml/Switch-My-Slot.qml \ + qml/cover/CoverPage.qml \ + qml/pages/FirstPage.qml \ + qml/pages/logic.py \ + rpm/Switch-My-Slot.changes.in \ + rpm/Switch-My-Slot.changes.run.in \ + rpm/Switch-My-Slot.spec \ + rpm/Switch-My-Slot.yaml \ + translations/*.ts \ + Switch-My-Slot.desktop + +SAILFISHAPP_ICONS = 86x86 108x108 128x128 172x172 + +# to disable building translations every time, comment out the +# following CONFIG line +CONFIG += sailfishapp_i18n + +# German translation is enabled as an example. If you aren't +# planning to localize your app, remember to comment out the +# following TRANSLATIONS line. And also do not forget to +# modify the localized app name in the the .desktop file. +TRANSLATIONS += translations/Switch-My-Slot-de.ts diff --git a/icons/108x108/Switch-My-Slot.png b/icons/108x108/Switch-My-Slot.png new file mode 100644 index 0000000..6b06d95 Binary files /dev/null and b/icons/108x108/Switch-My-Slot.png differ diff --git a/icons/128x128/Switch-My-Slot.png b/icons/128x128/Switch-My-Slot.png new file mode 100644 index 0000000..4a37cdf Binary files /dev/null and b/icons/128x128/Switch-My-Slot.png differ diff --git a/icons/172x172/Switch-My-Slot.png b/icons/172x172/Switch-My-Slot.png new file mode 100644 index 0000000..c27c005 Binary files /dev/null and b/icons/172x172/Switch-My-Slot.png differ diff --git a/icons/86x86/Switch-My-Slot.png b/icons/86x86/Switch-My-Slot.png new file mode 100644 index 0000000..6610751 Binary files /dev/null and b/icons/86x86/Switch-My-Slot.png differ diff --git a/qml/Switch-My-Slot.qml b/qml/Switch-My-Slot.qml new file mode 100644 index 0000000..8fbf79c --- /dev/null +++ b/qml/Switch-My-Slot.qml @@ -0,0 +1,9 @@ +import QtQuick 2.0 +import Sailfish.Silica 1.0 +import "pages" + +ApplicationWindow +{ + initialPage: Component { FirstPage { } } + cover: Qt.resolvedUrl("cover/CoverPage.qml") +} diff --git a/qml/cover/CoverPage.qml b/qml/cover/CoverPage.qml new file mode 100644 index 0000000..04adca3 --- /dev/null +++ b/qml/cover/CoverPage.qml @@ -0,0 +1,10 @@ +import QtQuick 2.0 +import Sailfish.Silica 1.0 + +CoverBackground { + Label { + id: label + anchors.centerIn: parent + text: qsTr("Switch My Slot") + } +} diff --git a/qml/pages/FirstPage.qml b/qml/pages/FirstPage.qml new file mode 100644 index 0000000..fd0eb8b --- /dev/null +++ b/qml/pages/FirstPage.qml @@ -0,0 +1,116 @@ +import QtQuick 2.0 +import Sailfish.Silica 1.0 +import io.thp.pyotherside 1.5 + +Page { + id: page + + SilicaFlickable { + anchors.fill: parent + contentHeight: column.height + Column { + id: column + + width: page.width + spacing: Theme.paddingSmall + PageHeader { + title: qsTr("Switch My Slot") + } + Label { + id: halVersionLabel + x: Theme.horizontalPageMargin + text: qsTr("HAL Version: ") + color: Theme.secondaryHighlightColor + font.pixelSize: 45 + } + Label { + text: qsTr("App Version: v0.3") + x: Theme.horizontalPageMargin + color: Theme.secondaryHighlightColor + } + Label { + id: noOfSlotsLabel + x: Theme.horizontalPageMargin + text: qsTr("Number of slots: ") + color: Theme.secondaryHighlightColor + } + + Label { + id: currentSlotSuffixLabel + x: Theme.horizontalPageMargin + text: qsTr("Current slot suffix: ") + color: Theme.secondaryHighlightColor + } + + Button { + id: switchSlotButton + x: Theme.horizontalPageMargin + anchors.horizontalCenter: parent.horizontalCenter + text: qsTr("Switch slot") + color: Theme.secondaryHighlightColor + onClicked: { + python.switchSlotFunc(); + } + } + + Label { + id: currentSlotLabel + x: Theme.horizontalPageMargin + anchors.horizontalCenter: parent.horizontalCenter + text: qsTr("Current slot: ") + color: Theme.secondaryHighlightColor + } + Label { + x: Theme.horizontalPageMargin + anchors.horizontalCenter: parent.horizontalCenter + text: qsTr("Developed by Shou") + color: Theme.secondaryHighlightColor + font.pixelSize: 45 + } + Label { + id: openRepo + x: Theme.horizontalPageMargin + anchors.horizontalCenter: parent.horizontalCenter + color: Theme.secondaryHighlightColor + font.pixelSize: 45 + text: "Licensed under MIT" + onLinkActivated: Qt.openUrlExternally(link) + } + + Python { + id: python + + Component.onCompleted: { + addImportPath(Qt.resolvedUrl('.')); + setHandler('halVersion', function(halVersion) { + halVersionLabel.text = halVersion; + }); + setHandler('noOfSlots', function(noOfSlots) { + noOfSlotsLabel.text = "Number of slots: " + noOfSlots; + }); + setHandler('currentSlotSuffix', function(currentSlotSuffix) { + currentSlotSuffixLabel.text = "Current slot suffix: " + currentSlotSuffix; + }); + setHandler('currentSlot', function(currentSlot) { + currentSlotLabel.text = "Current slot: " + currentSlot; + }); + importModule('logic', function () {}); + } + + function switchSlotFunc() { + switchSlotButton.enabled = false + currentSlotLabel.text = "Please reboot/ turn off your phone now"; + call('logic.switchSlotFunc', function() {}); + } + + onError: { + console.log('python error: ' + traceback); + } + + onReceived: { + console.log('got message from python: ' + data); + } + } + } + } +} diff --git a/qml/pages/logic.py b/qml/pages/logic.py new file mode 100644 index 0000000..b365660 --- /dev/null +++ b/qml/pages/logic.py @@ -0,0 +1,29 @@ +import pyotherside +import os + +stream = os.popen('/bin/bootctl hal-info') +output = stream.read() +pyotherside.send('halVersion', output) + +stream = os.popen('/bin/bootctl get-number-slots') +output = stream.read() +pyotherside.send('noOfSlots', output) + +stream = os.popen('/bin/bootctl get-current-slot') +output = stream.read() +temp = output + +if temp.__eq__(0): + pyotherside.send('currentSlot', "A") +elif s1.__eq__(1): + pyotherside.send('currentSlot', "B") + +stream = os.popen('/bin/bootctl get-suffix ' + temp) +output = stream.read() +pyotherside.send('currentSlotSuffix', output) + +def switchSlotFunc(): + if temp.__eq__(0): + os.system("/bin/bootctl set-active-boot-slot " + "1") + elif temp.__eq__(1): + os.system("/bin/bootctl set-active-boot-slot " + "0") diff --git a/rpm/Switch-My-Slot.changes.in b/rpm/Switch-My-Slot.changes.in new file mode 100644 index 0000000..e50a85b --- /dev/null +++ b/rpm/Switch-My-Slot.changes.in @@ -0,0 +1,18 @@ +# Rename this file as Switch-My-Slot.changes to include changelog +# entries in your RPM file. +# +# Add new changelog entries following the format below. +# Add newest entries to the top of the list. +# Separate entries from eachother with a blank line. +# +# Alternatively, if your changelog is automatically generated (e.g. with +# the git-change-log command provided with Sailfish OS SDK), create a +# Switch-My-Slot.changes.run script to let mb2 run the required commands for you. + +# * date Author's Name version-release +# - Summary of changes + +* Sun Apr 13 2014 Jack Tar 0.0.1-1 +- Scrubbed the deck +- Hoisted the sails + diff --git a/rpm/Switch-My-Slot.changes.run.in b/rpm/Switch-My-Slot.changes.run.in new file mode 100644 index 0000000..65466ae --- /dev/null +++ b/rpm/Switch-My-Slot.changes.run.in @@ -0,0 +1,25 @@ +#!/bin/bash +# +# Rename this file as Switch-My-Slot.changes.run to let mb2 automatically +# generate changelog from well formatted Git commit messages and tag +# annotations. + +git-change-log + +# Here are some basic examples how to change from the default behavior. Run +# git-change-log --help inside the Sailfish OS SDK chroot or build engine to +# learn all the options git-change-log accepts. + +# Use a subset of tags +#git-change-log --tags refs/tags/my-prefix/* + +# Group entries by minor revision, suppress headlines for patch-level revisions +#git-change-log --dense '/[0-9]+.[0-9+$' + +# Trim very old changes +#git-change-log --since 2014-04-01 +#echo '[ Some changelog entries trimmed for brevity ]' + +# Use the subjects (first lines) of tag annotations when no entry would be +# included for a revision otherwise +#git-change-log --auto-add-annotations diff --git a/rpm/Switch-My-Slot.spec b/rpm/Switch-My-Slot.spec new file mode 100644 index 0000000..2d56428 --- /dev/null +++ b/rpm/Switch-My-Slot.spec @@ -0,0 +1,68 @@ +# +# Do NOT Edit the Auto-generated Part! +# Generated by: spectacle version 0.27 +# + +Name: Switch-My-Slot + +# >> macros +# << macros + +Summary: Switch My Slot +Version: 0.3 +Release: 3 +Group: Qt/Qt +License: MIT +URL: https://github.com/SailfishOS-MI-A2/Switch-My-Slot-SailfishOS +Source0: %{name}-%{version}.tar.bz2 +Source100: Switch-My-Slot.yaml +Requires: sailfishsilica-qt5 >= 0.10.9 +Requires: pyotherside-qml-plugin-python3-qt5 +BuildRequires: pkgconfig(sailfishapp) >= 1.0.2 +BuildRequires: pkgconfig(Qt5Core) +BuildRequires: pkgconfig(Qt5Qml) +BuildRequires: pkgconfig(Qt5Quick) +BuildRequires: desktop-file-utils + +%description +Switch My Slot is a SailfishOS app that helps you switch between android system A & system B slots if you are dualbooting with Android OS on an Android A/B device. This app saves you from the hassle of needing to use ssh/terminal/twrp while wanting to switch to another Android slot. + + +%prep +%setup -q -n %{name}-%{version} + +# >> setup +# << setup + +%build +# >> build pre +# << build pre + +%qmake5 + +make %{?_smp_mflags} + +# >> build post +# << build post + +%install +rm -rf %{buildroot} +# >> install pre +# << install pre +%qmake5_install + +# >> install post +# << install post + +desktop-file-install --delete-original \ + --dir %{buildroot}%{_datadir}/applications \ + %{buildroot}%{_datadir}/applications/*.desktop + +%files +%defattr(-,root,root,-) +%{_bindir} +%{_datadir}/%{name} +%{_datadir}/applications/%{name}.desktop +%{_datadir}/icons/hicolor/*/apps/%{name}.png +# >> files +# << files diff --git a/rpm/Switch-My-Slot.yaml b/rpm/Switch-My-Slot.yaml new file mode 100644 index 0000000..cc6059c --- /dev/null +++ b/rpm/Switch-My-Slot.yaml @@ -0,0 +1,44 @@ +Name: Switch-My-Slot +Summary: Switch My Slot +Version: 0.3 +Release: 3 +# The contents of the Group field should be one of the groups listed here: +# https://github.com/mer-tools/spectacle/blob/master/data/GROUPS +Group: Qt/Qt +URL: https://github.com/SailfishOS-MI-A2/Switch-My-Slot-SailfishOS +License: MIT LICENSE +# This must be generated before uploading a package to a remote build service. +# Usually this line does not need to be modified. +Sources: +- '%{name}-%{version}.tar.bz2' +Description: | + Switch My Slot is a SailfishOS app that helps you switch between android system A & system B slots if you are dualbooting with Android OS on an Android A/B device. This app saves you from the hassle of needing to use ssh/terminal/twrp while wanting to switch to another Android slot. +Configure: none +Builder: qmake5 + +# This section specifies build dependencies that are resolved using pkgconfig. +# This is the preferred way of specifying build dependencies for your package. +PkgConfigBR: + - sailfishapp >= 1.0.2 + - Qt5Core + - Qt5Qml + - Qt5Quick + +# Build dependencies without a pkgconfig setup can be listed here +# PkgBR: +# - package-needed-to-build + +# Runtime dependencies which are not automatically detected +Requires: + - sailfishsilica-qt5 >= 0.10.9 + - pyotherside-qml-plugin-python3-qt5 + +# All installed files +Files: + - '%{_bindir}' + - '%{_datadir}/%{name}' + - '%{_datadir}/applications/%{name}.desktop' + - '%{_datadir}/icons/hicolor/*/apps/%{name}.png' + +# For more information about yaml and what's supported in Sailfish OS +# build system, please see https://wiki.merproject.org/wiki/Spectacle diff --git a/src/Switch-My-Slot.cpp b/src/Switch-My-Slot.cpp new file mode 100644 index 0000000..64ca72a --- /dev/null +++ b/src/Switch-My-Slot.cpp @@ -0,0 +1,17 @@ +#include +#include + +int main(int argc, char *argv[]) +{ + // SailfishApp::main() will display "qml/Switch-My-Slot.qml", if you need more + // control over initialization, you can use: + // + // - SailfishApp::application(int, char *[]) to get the QGuiApplication * + // - SailfishApp::createView() to get a new QQuickView * instance + // - SailfishApp::pathTo(QString) to get a QUrl to a resource file + // - SailfishApp::pathToMainQml() to get a QUrl to the main QML file + // + // To display the view, call "show()" (will show fullscreen on device). + + return SailfishApp::main(argc, argv); +} diff --git a/translations/Switch-My-Slot-de.qm b/translations/Switch-My-Slot-de.qm new file mode 100644 index 0000000..be651ee --- /dev/null +++ b/translations/Switch-My-Slot-de.qm @@ -0,0 +1 @@ +<¸dÊÍ!¿`¡½Ý \ No newline at end of file diff --git a/translations/Switch-My-Slot-de.ts b/translations/Switch-My-Slot-de.ts new file mode 100644 index 0000000..354409a --- /dev/null +++ b/translations/Switch-My-Slot-de.ts @@ -0,0 +1,46 @@ + + + + + CoverPage + + Switch My Slot + + + + + FirstPage + + Switch My Slot + + + + App Version: v0.3 + + + + Number of slots: + + + + Current slot: + + + + HAL Version: + + + + Current slot suffix: + + + + Switch slot + + + + Developed by Shouko + + + + diff --git a/translations/Switch-My-Slot.ts b/translations/Switch-My-Slot.ts new file mode 100644 index 0000000..354409a --- /dev/null +++ b/translations/Switch-My-Slot.ts @@ -0,0 +1,46 @@ + + + + + CoverPage + + Switch My Slot + + + + + FirstPage + + Switch My Slot + + + + App Version: v0.3 + + + + Number of slots: + + + + Current slot: + + + + HAL Version: + + + + Current slot suffix: + + + + Switch slot + + + + Developed by Shouko + + + +