Index: denali.qrc =================================================================== diff -u -r59625af31d9009df82fa48310b54c0f247e829fc -rfcdb1dfa21f3d5c02e549089c19ab7d57b19040c --- denali.qrc (.../denali.qrc) (revision 59625af31d9009df82fa48310b54c0f247e829fc) +++ denali.qrc (.../denali.qrc) (revision fcdb1dfa21f3d5c02e549089c19ab7d57b19040c) @@ -26,6 +26,7 @@ sources/gui/qml/pages/settings/SettingsFactoryReset.qml sources/gui/qml/pages/settings/SettingsDecommission.qml sources/gui/qml/pages/settings/SettingsStartSoftwareUpdate.qml + sources/gui/qml/pages/settings/SettingsFinalizeSoftwareUpdate.qml sources/gui/qml/dialogs/ConfirmDialog.qml Index: sources/device/DeviceController.cpp =================================================================== diff -u -r59625af31d9009df82fa48310b54c0f247e829fc -rfcdb1dfa21f3d5c02e549089c19ab7d57b19040c --- sources/device/DeviceController.cpp (.../DeviceController.cpp) (revision 59625af31d9009df82fa48310b54c0f247e829fc) +++ sources/device/DeviceController.cpp (.../DeviceController.cpp) (revision fcdb1dfa21f3d5c02e549089c19ab7d57b19040c) @@ -1233,3 +1233,56 @@ didAttributeResponse(model.data()); LOG_APPED_UI(model.data().mMessage); } + + +///////////////////////////////////////////// DeviceFinalizeSoftwareUpdate +void DeviceController::onAttributeRequest(const DeviceFinalizeSoftwareUpdateRequestData &vData) +{ + _deviceFinalizeSoftwareUpdateRequest._data = vData; + + // ----- check that script exists. + QString script = Device_FinalizeSoftwareUpdateScriptPath; + DeviceError::Scripts_Error_Enum err = DeviceError::eDevice_OK; + QFileInfo info(script); + if ( ! info.exists () ) { err = DeviceError::eDevice_Scripts_Error_NotFound ;} + if ( ! info.isExecutable() ) { err = DeviceError::eDevice_Scripts_Error_NotExecutable ;} + + if ( checkError(err, _deviceFinalizeSoftwareUpdateResponse, script) ) + return; + + // ----- check if the process is not running + if ( _processFinalizeSoftwareUpdate.state() != QProcess::NotRunning ) { + checkError(DeviceError::eDevice_Scripts_Error_IsRunning, _deviceFinalizeSoftwareUpdateResponse); + return; + } + + // ----- run the process + int timeout_ms = 10000; + TimedProcess *timedProcess = new TimedProcess(&_processFinalizeSoftwareUpdate, script, timeout_ms, { }); + timedProcess->start(); + + MDeviceFinalizeSoftwareUpdateResponse model; + model._data.mAccepted = false; // will indirectly set the property startSoftwareUpdateEnabled + model._data.mMessage = tr("Starting finalization of software update."); + didAttributeResponse(model.data()); +} + +/*! + * \brief DeviceController::onProcessFinalizeSoftwareUpdateExitCode + * \param vExitCode + * \param vStatus + */ +void DeviceController::onProcessFinalizeSoftwareUpdateExitCode(int vExitCode, QProcess::ExitStatus vStatus) +{ + // The Exit code in this script is not used. + // any other checking is done by UI Software at the moment this script is called. + // The only thing matters is the paired device info in text and it will be empty string if error happens. + MDeviceFinalizeSoftwareUpdateResponse model; + QByteArray deviceInfo; + if ( vStatus ) vExitCode = Device::DeviceError::eDevice_Scripts_Error_Status; + else deviceInfo = _processFinalizeSoftwareUpdate.readAll(); + model.fromByteArray( deviceInfo, &vExitCode ); + // DEBUG: qDebug() << model._data.mMessage << deviceInfo; + didAttributeResponse(model.data()); + LOG_APPED_UI(model.data().mMessage); +} Index: sources/device/DeviceError.h =================================================================== diff -u -r59625af31d9009df82fa48310b54c0f247e829fc -rfcdb1dfa21f3d5c02e549089c19ab7d57b19040c --- sources/device/DeviceError.h (.../DeviceError.h) (revision 59625af31d9009df82fa48310b54c0f247e829fc) +++ sources/device/DeviceError.h (.../DeviceError.h) (revision fcdb1dfa21f3d5c02e549089c19ab7d57b19040c) @@ -68,6 +68,7 @@ eDevice_Decommission_Error , eDevice_USBMount_Error , eDevice_StartSoftwareUpdate_Error , + eDevice_FinalizeSoftwareUpdate_Error, eDevice_Error_End Index: sources/device/DeviceGlobals.h =================================================================== diff -u -r59625af31d9009df82fa48310b54c0f247e829fc -rfcdb1dfa21f3d5c02e549089c19ab7d57b19040c --- sources/device/DeviceGlobals.h (.../DeviceGlobals.h) (revision 59625af31d9009df82fa48310b54c0f247e829fc) +++ sources/device/DeviceGlobals.h (.../DeviceGlobals.h) (revision fcdb1dfa21f3d5c02e549089c19ab7d57b19040c) @@ -174,7 +174,9 @@ DEVICE_DEV_PARENT ( Decommission ) \ DEVICE_DEV_PARENT ( USBMount ) \ DEVICE_DEV_PARENT ( StartSoftwareUpdate ) \ + DEVICE_DEV_PARENT ( FinalizeSoftwareUpdate ) \ + #define DEVICE_DEV_INIT_CONNECTIONS_LIST \ DEVICE_DEV_INIT_CONNECTIONS ( Brightness ) \ DEVICE_DEV_INIT_CONNECTIONS ( BluetoothPairedReset ) \ @@ -185,6 +187,7 @@ DEVICE_DEV_INIT_CONNECTIONS ( Decommission ) \ DEVICE_DEV_INIT_CONNECTIONS ( USBMount ) \ DEVICE_DEV_INIT_CONNECTIONS ( StartSoftwareUpdate ) \ + DEVICE_DEV_INIT_CONNECTIONS ( FinalizeSoftwareUpdate ) \ #define DEVICE_DEV_DEFINITION_LIST \ DEVICE_DEV_DEFINITION ( Brightness ) \ @@ -196,6 +199,7 @@ DEVICE_DEV_DEFINITION ( Decommission ) \ DEVICE_DEV_DEFINITION ( USBMount ) \ DEVICE_DEV_DEFINITION ( StartSoftwareUpdate ) \ + DEVICE_DEV_DEFINITION ( FinalizeSoftwareUpdate ) \ @@ -209,6 +213,7 @@ DEVICE_APP_INIT_CONNECTIONS ( FactoryReset ) \ DEVICE_APP_INIT_CONNECTIONS ( Decommission ) \ DEVICE_APP_INIT_CONNECTIONS ( StartSoftwareUpdate ) \ + DEVICE_APP_INIT_CONNECTIONS ( FinalizeSoftwareUpdate ) \ #define DEVICE_APP_BRIDGE_DEFINITION_LIST \ DEVICE_APP_BRIDGE_DEFINITION( Brightness ) \ @@ -220,6 +225,7 @@ DEVICE_APP_BRIDGE_DEFINITION( Decommission ) \ DEVICE_APP_BRIDGE_DEFINITION( USBMount ) \ DEVICE_APP_BRIDGE_DEFINITION( StartSoftwareUpdate ) \ + DEVICE_APP_BRIDGE_DEFINITION( FinalizeSoftwareUpdate ) \ /* ---------------------------- GUI */ #define DEVICE_GUI_BRIDGE_DEFINITION_LIST \ @@ -231,6 +237,7 @@ DEVICE_GUI_BRIDGE_DEFINITION( FactoryReset ) \ DEVICE_GUI_BRIDGE_DEFINITION( Decommission ) \ DEVICE_GUI_BRIDGE_DEFINITION( StartSoftwareUpdate ) \ + DEVICE_GUI_BRIDGE_DEFINITION( FinalizeSoftwareUpdate ) \ #define DEVICE_GUI_INIT_CONNECTIONS_LIST \ DEVICE_GUI_INIT_CONNECTIONS ( Brightness ) \ @@ -241,6 +248,7 @@ DEVICE_GUI_INIT_CONNECTIONS ( FactoryReset ) \ DEVICE_GUI_INIT_CONNECTIONS ( Decommission ) \ DEVICE_GUI_INIT_CONNECTIONS ( StartSoftwareUpdate ) \ + DEVICE_GUI_INIT_CONNECTIONS ( FinalizeSoftwareUpdate ) \ /* ---------------------------- VIEW */ #define DEVICE_VIEW_INIT_CONNECTIONS_LIST \ @@ -252,4 +260,5 @@ DEVICE_VIEW_INIT_CONNECTIONS( FactoryReset ) \ DEVICE_VIEW_INIT_CONNECTIONS( Decommission ) \ DEVICE_VIEW_INIT_CONNECTIONS( StartSoftwareUpdate ) \ + DEVICE_VIEW_INIT_CONNECTIONS( FinalizeSoftwareUpdate ) \ Index: sources/device/DeviceModels.cpp =================================================================== diff -u -r59625af31d9009df82fa48310b54c0f247e829fc -rfcdb1dfa21f3d5c02e549089c19ab7d57b19040c --- sources/device/DeviceModels.cpp (.../DeviceModels.cpp) (revision 59625af31d9009df82fa48310b54c0f247e829fc) +++ sources/device/DeviceModels.cpp (.../DeviceModels.cpp) (revision fcdb1dfa21f3d5c02e549089c19ab7d57b19040c) @@ -314,3 +314,33 @@ lOut: return _data.mAccepted; } + +/*! + * \brief MDeviceFinalizeSoftwareUpdateResponse::fromByteArray + * \details Checks the response and sets up the mode data. + * \param vExitCode - Passed script exit code + * \return true if passed. + */ +bool MDeviceFinalizeSoftwareUpdateResponse::fromByteArray(const QByteArray &vByteArray, int *vExitCode) +{ + // initialize data + int error = 0; + _data.mAccepted = false; + + // check if the vExitCode passed and it has a value other than zero + if ( vExitCode && *vExitCode ){ _data.mReason = Device::DeviceError::eDevice_FinalizeSoftwareUpdate_Error; error = *vExitCode; } + else _data.mReason = Device::DeviceError::eDevice_OK; + + // if vExitCode is not zero go to error since the data is no longer valid + if ( _data.mReason ) goto lError; // non-zero Exit code + + // Now everything is good to extract the data + _data.mAccepted = true; + _data.mMessage = QObject::tr("The Finalize Software Update Command Complete."); goto lOut ; // normal return + +lError: + _data.mMessage = Device::DeviceError::deviceErrorText(static_cast(_data.mReason), error) + "\n" + vByteArray; + +lOut: + return _data.mAccepted; +} Index: sources/device/DeviceModels.h =================================================================== diff -u -r59625af31d9009df82fa48310b54c0f247e829fc -rfcdb1dfa21f3d5c02e549089c19ab7d57b19040c --- sources/device/DeviceModels.h (.../DeviceModels.h) (revision 59625af31d9009df82fa48310b54c0f247e829fc) +++ sources/device/DeviceModels.h (.../DeviceModels.h) (revision fcdb1dfa21f3d5c02e549089c19ab7d57b19040c) @@ -387,7 +387,7 @@ /*! * \brief The MDeviceStartSoftwareUpdateResponse class - * \details The model for the decommission script call returned value / response. + * \details The model for the start software update script call returned value / response. */ class MDeviceStartSoftwareUpdateResponse : public MDeviceResponseBase { public: @@ -398,6 +398,36 @@ Data data ( ) const { return _data; } bool fromByteArray(const QByteArray &vByteArray, int *vExitCode = nullptr) override; }; + + +// ---------- MDeviceFinalizeSoftwareUpdate ---------- // +/*! + * \brief The MDeviceFinalizeSoftwareUpdateRequest class + * \details The model for the decommission script call. + */ +class MDeviceFinalizeSoftwareUpdateRequest : public MDeviceRequestBase { +public: + struct Data { + } _data; + + QString toString() { + return MDeviceRequestBase::toString("FinalizeSoftwareUpdate", { }); + } +}; + +/*! + * \brief The MDeviceFinalizeSoftwareUpdateResponse class + * \details The model for the finalize software update script call returned value / response. + */ +class MDeviceFinalizeSoftwareUpdateResponse : public MDeviceResponseBase { +public: + struct Data : MDeviceResponseBase::Data { + } _data; + QVariantList parameters ( ) const override { return { }; } + QString infoText ( ) const override { return QString("FinalizeSoftwareUpdate"); } + Data data ( ) const { return _data; } + bool fromByteArray(const QByteArray &vByteArray, int *vExitCode = nullptr) override; +}; } typedef Model::MDeviceResponseBase ::Data DeviceResponseBaseData ; @@ -429,3 +459,5 @@ typedef Model::MDeviceStartSoftwareUpdateRequest ::Data DeviceStartSoftwareUpdateRequestData ; typedef Model::MDeviceStartSoftwareUpdateResponse::Data DeviceStartSoftwareUpdateResponseData; +typedef Model::MDeviceFinalizeSoftwareUpdateRequest ::Data DeviceFinalizeSoftwareUpdateRequestData ; +typedef Model::MDeviceFinalizeSoftwareUpdateResponse::Data DeviceFinalizeSoftwareUpdateResponseData; Index: sources/device/DeviceView.cpp =================================================================== diff -u -r59625af31d9009df82fa48310b54c0f247e829fc -rfcdb1dfa21f3d5c02e549089c19ab7d57b19040c --- sources/device/DeviceView.cpp (.../DeviceView.cpp) (revision 59625af31d9009df82fa48310b54c0f247e829fc) +++ sources/device/DeviceView.cpp (.../DeviceView.cpp) (revision fcdb1dfa21f3d5c02e549089c19ab7d57b19040c) @@ -287,7 +287,37 @@ response(true); } +// ================================================= Finalize Software Update +void VDevice::doInitFinalizeSoftwareUpdate() { + // Nothing for now. +} +void VDevice::finalizeSoftwareUpdateRequest(const QString& vCommand) { + Q_UNUSED(vCommand) + + // DEBUG : qDebug() << "HERE Request" << vUpdateFilePath; + + finalizeSoftwareUpdateEnabled(true); + + DeviceFinalizeSoftwareUpdateRequestData data; + emit didAttributeRequest(data); +} + +void VDevice::onAttributeResponse(const DeviceFinalizeSoftwareUpdateResponseData &vData) { + //QDEBUG : qDebug() << "HERE Response " << Q_FUNC_INFO << " accepted: "<< vData.mAccepted << vData.mReason; + // this has to be called to let Gui to set to old value that device controller provided. + status(vData.mMessage); + + accepted(vData.mAccepted); + reason (vData.mReason ); + + finalizeSoftwareUpdateEnabled(isCompleteResponse(vData)); + + // has to be the last one + response(true); +} + + void VDevice::onPOSTOSVersionData(const QString &vOSVersion) { osVersion(vOSVersion); Index: sources/device/DeviceView.h =================================================================== diff -u -r59625af31d9009df82fa48310b54c0f247e829fc -rfcdb1dfa21f3d5c02e549089c19ab7d57b19040c --- sources/device/DeviceView.h (.../DeviceView.h) (revision 59625af31d9009df82fa48310b54c0f247e829fc) +++ sources/device/DeviceView.h (.../DeviceView.h) (revision fcdb1dfa21f3d5c02e549089c19ab7d57b19040c) @@ -63,6 +63,9 @@ ATTRIBUTE ( QString , startSoftwareUpdate , "", StartSoftwareUpdate ) PROPERTY ( bool , startSoftwareUpdateEnabled , true ) + ATTRIBUTE ( QString , finalizeSoftwareUpdate , "", FinalizeSoftwareUpdate ) + PROPERTY ( bool , finalizeSoftwareUpdateEnabled , true ) + VIEW_DEC_CLASS(VDevice) private slots: Index: sources/gui/qml/pages/settings/SettingsFinalizeSoftwareUpdate.qml =================================================================== diff -u --- sources/gui/qml/pages/settings/SettingsFinalizeSoftwareUpdate.qml (revision 0) +++ sources/gui/qml/pages/settings/SettingsFinalizeSoftwareUpdate.qml (revision fcdb1dfa21f3d5c02e549089c19ab7d57b19040c) @@ -0,0 +1,53 @@ +/*! + * + * Copyright (c) 2023-2023 Diality Inc. - All Rights Reserved. + * \copyright + * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN + * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. + * + * \file SettingsFinalizeSoftwareUpdate.qml + * \author (last) Vy Duong + * \date (last) 04-Dec-2023 + * \author (original) Vy Duong + * \date (original) 04-Dec-2023 + * + */ + +// Qt +import QtQuick 2.12 +import Qt.labs.folderlistmodel 2.12 + +// Qml imports +import "qrc:/globals" +import "qrc:/pages" +import "qrc:/components" + +/*! + * \brief SettingsFinalizeSoftwareUpdate is the screen + * which asks for confirmation of performing a finalization of the software update + */ +UserConfirmation { id : _root + message : vDevice.finalizeSoftwareUpdateEnabled ? qsTr("Do you want to perform the %1?").arg(title.toLowerCase()) + : qsTr("Please wait ...") + itemIndex : SettingsStack.FinalizeSoftwareUpdate + notificationText : vDevice.status + + confirmVisible : true + confirmEnabled : vDevice.finalizeSoftwareUpdateEnabled + + backVisible : true + backEnabled : vDevice.finalizeSoftwareUpdateEnabled + + onConfirmClicked : { + _confirmDialog.titleText = _root.title + _confirmDialog.open() + } + + Connections { target: _confirmDialog + function onAccepted() { + if ( _confirmDialog.titleText == _root.title ) { // use the title as the indication of what has been confirmed and if that is related to this function. + vDevice.finalizeSoftwareUpdate = "" + } + } + } +} Index: sources/gui/qml/pages/settings/SettingsStack.qml =================================================================== diff -u -r59625af31d9009df82fa48310b54c0f247e829fc -rfcdb1dfa21f3d5c02e549089c19ab7d57b19040c --- sources/gui/qml/pages/settings/SettingsStack.qml (.../SettingsStack.qml) (revision 59625af31d9009df82fa48310b54c0f247e829fc) +++ sources/gui/qml/pages/settings/SettingsStack.qml (.../SettingsStack.qml) (revision fcdb1dfa21f3d5c02e549089c19ab7d57b19040c) @@ -71,7 +71,7 @@ readonly property bool visibleDeviceConfiguration : onlyManufacturing && loggedIn readonly property bool visibleDeviceRegistration : onlyManufacturing && loggedIn readonly property bool visibleStartSoftwareUpdate : loggedIn - + readonly property bool visibleFinalizeSoftwareUpdate: loggedIn // TODO need to add additional condition ? enum ItemsIndex { Information , VolumeBrightness , @@ -91,7 +91,9 @@ RootSSHAccess , FactoryReset , Decommission , - StartSoftwareUpdate + Information , // place-holder element for "" menu item + StartSoftwareUpdate , + FinalizeSoftwareUpdate } property var itemsText : [ qsTr("Information" ), // Information @@ -112,7 +114,10 @@ qsTr("Enable Root SSH" ), // RootSSHAccess qsTr("Factory Reset" ), // FactoryReset qsTr("Decommissioning" ), // Decommission + qsTr(""), // Added to push the software request and confirm to the next column qsTr("Software Update" ), // Software Update Request + qsTr("Finalize Software Update" ), // Finalize Software Update + ] property var itemsEnabled : [ true , // Information @@ -133,7 +138,10 @@ true , // RootSSHAccess true , // FactoryReset true , // Decommission + false , // place holder true , // Software Update Request + true , // Finalize Software Update + ] property var itemsVisible : [ visibleInformation , // Information @@ -154,7 +162,9 @@ visibleRootSSHAccess , // RootSSHAccess visibleFactoryReset , // FactoryReset visibleDecommission , // Decommission + true , // placeholder visibleStartSoftwareUpdate , // Software update request + visibleFinalizeSoftwareUpdate , // Finalize Software Update ] SettingsHome { id : _settingsHome @@ -253,6 +263,10 @@ push( _serviceStartSoftwareUpdate ) break + case SettingsStack.FinalizeSoftwareUpdate: + push ( _serviceFinalizeSoftwareUpdate ) + break + default: console.debug("Unknown Index", vIndex) break @@ -276,6 +290,7 @@ SettingsFactoryReset { id: _serviceFactoryReset } SettingsDecommission { id: _serviceDecommission } SettingsStartSoftwareUpdate { id: _serviceStartSoftwareUpdate } + SettingsFinalizeSoftwareUpdate { id: _serviceFinalizeSoftwareUpdate} function gotoServiceMode( vservice ) { //DEBUG console.log (" 0 ---------- ", _GuiView.manufactMode, _GuiView.manufactSetup, vservice, stackView.initialItem, stackView.currentItem, stackView.depth) Index: sources/gui/qml/pages/settings/SettingsStartSoftwareUpdate.qml =================================================================== diff -u -rfcd83dda54e97cb982ffa8add6b8f1a4e1643694 -rfcdb1dfa21f3d5c02e549089c19ab7d57b19040c --- sources/gui/qml/pages/settings/SettingsStartSoftwareUpdate.qml (.../SettingsStartSoftwareUpdate.qml) (revision fcd83dda54e97cb982ffa8add6b8f1a4e1643694) +++ sources/gui/qml/pages/settings/SettingsStartSoftwareUpdate.qml (.../SettingsStartSoftwareUpdate.qml) (revision fcdb1dfa21f3d5c02e549089c19ab7d57b19040c) @@ -69,7 +69,7 @@ spacing : 3 // TODO need a CPP Class model for the files, only temp for demo FolderListModel { id : _usbFolder - property string path : "/media/sd-card/updates/" + property string path : "/media/sd-card/cloudsync/" showDirs : false sortField : FolderListModel.Time folder : "file:" + path // TODO need to be in CPP Index: sources/model/MModel.h =================================================================== diff -u -r59625af31d9009df82fa48310b54c0f247e829fc -rfcdb1dfa21f3d5c02e549089c19ab7d57b19040c --- sources/model/MModel.h (.../MModel.h) (revision 59625af31d9009df82fa48310b54c0f247e829fc) +++ sources/model/MModel.h (.../MModel.h) (revision fcdb1dfa21f3d5c02e549089c19ab7d57b19040c) @@ -301,6 +301,8 @@ REGISTER_METATYPE( DeviceUSBMountResponseData ) \ REGISTER_METATYPE( DeviceStartSoftwareUpdateRequestData ) \ REGISTER_METATYPE( DeviceStartSoftwareUpdateResponseData ) \ + REGISTER_METATYPE( DeviceFinalizeSoftwareUpdateRequestData ) \ + REGISTER_METATYPE( DeviceFinalizeSoftwareUpdateResponseData ) \ /* Settings */ \ REGISTER_METATYPE( SettingsData ) \ REGISTER_METATYPE( WifiNetworkData ) \ Index: sources/storage/StorageGlobals.cpp =================================================================== diff -u -r59625af31d9009df82fa48310b54c0f247e829fc -rfcdb1dfa21f3d5c02e549089c19ab7d57b19040c --- sources/storage/StorageGlobals.cpp (.../StorageGlobals.cpp) (revision 59625af31d9009df82fa48310b54c0f247e829fc) +++ sources/storage/StorageGlobals.cpp (.../StorageGlobals.cpp) (revision fcdb1dfa21f3d5c02e549089c19ab7d57b19040c) @@ -204,4 +204,7 @@ // Start Software Update const char *Device_StartSoftwareUpdateScriptPath = "/opt/bin/upgrade_install.sh"; + // Finalize Software Update + const char *Device_FinalizeSoftwareUpdateScriptPath = "/opt/bin/upgrade_complete.sh"; + } Index: sources/storage/StorageGlobals.h =================================================================== diff -u -r59625af31d9009df82fa48310b54c0f247e829fc -rfcdb1dfa21f3d5c02e549089c19ab7d57b19040c --- sources/storage/StorageGlobals.h (.../StorageGlobals.h) (revision 59625af31d9009df82fa48310b54c0f247e829fc) +++ sources/storage/StorageGlobals.h (.../StorageGlobals.h) (revision fcdb1dfa21f3d5c02e549089c19ab7d57b19040c) @@ -144,4 +144,6 @@ // Device Start Software Update extern const char *Device_StartSoftwareUpdateScriptPath; + // Device Finalize Software Update + extern const char *Device_FinalizeSoftwareUpdateScriptPath; }