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