From 77d3b1a0c669b5982f7c72271499ee27bb4dc87a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pawe=C5=82=20Olejniczak?=
<58421550+pawel-mudita@users.noreply.github.com>
Date: Mon, 30 Nov 2020 10:12:34 +0100
Subject: [PATCH] [EGD-4506] Add proposal of basic bluetooth settings data flow
(#1090)
---
module-bluetooth/README.md | 27 +++++++
.../bt_messages_class_diagram.puml | 40 +++++++++++
.../bt_messages_class_diagram.svg | 71 +++++++++++++++++++
.../bt_settings_basic_flowchart.puml | 11 +++
.../bt_settings_basic_flowchart.svg | 26 +++++++
.../change_bt_status_flowchart.puml | 45 ++++++++++++
.../change_bt_status_flowchart.svg | 55 ++++++++++++++
...gs_from_db_on_service_start_flowchart.puml | 42 +++++++++++
...ngs_from_db_on_service_start_flowchart.svg | 52 ++++++++++++++
module-bluetooth/service_bt_internals.puml | 13 ++++
module-bluetooth/service_bt_internals.svg | 25 +++++++
11 files changed, 407 insertions(+)
create mode 100644 module-bluetooth/bt_messages_class_diagram.puml
create mode 100644 module-bluetooth/bt_messages_class_diagram.svg
create mode 100644 module-bluetooth/bt_settings_basic_flowchart.puml
create mode 100644 module-bluetooth/bt_settings_basic_flowchart.svg
create mode 100644 module-bluetooth/change_bt_status_flowchart.puml
create mode 100644 module-bluetooth/change_bt_status_flowchart.svg
create mode 100644 module-bluetooth/load_bt_settings_from_db_on_service_start_flowchart.puml
create mode 100644 module-bluetooth/load_bt_settings_from_db_on_service_start_flowchart.svg
create mode 100644 module-bluetooth/service_bt_internals.puml
create mode 100644 module-bluetooth/service_bt_internals.svg
diff --git a/module-bluetooth/README.md b/module-bluetooth/README.md
index 4a861ed4e151d6def273029ff18871119cc77408..802150858ab339cf3d8cadc4fe2ce05d0e9faf82 100644
--- a/module-bluetooth/README.md
+++ b/module-bluetooth/README.md
@@ -18,3 +18,30 @@ It's meant to provide interface layer for service-bluetooth like that:

+# Proposal of Bluetooth settings data flow
+
+The Bluetooth settings related data flow is directed by three main entities:
+1. `ServiceDB` that is responsible for storing data in DB
+2. `ServiceBluetooth` that is responsible for general Bluetooth management, and communication between ServiceDB and ApplicationSettings
+3. `ApplicationSettings` that is responsible for `PurePhone<->User` interactions in this context
+
+
+
+`ServiceBluetooth` communicates with `ServiceDB` via `SettingsAgent`, and uses `BluetoothMessages` for communication with `ApplicationSettings`.
+It contains `BluetoothSettings` object for caching settings received from `ServiceDB` and `ApplicationSettings`.
+`ServiceBluetooth` uses `BluetoothWorker` to control bluetooth stack.
+
+
+
+
+
+When `ServiceBluetooth` is being created, it registers on a value change in *DB* for each variable related to *BluetoothSettings* and binds callback functions for them.
+When *DB* responds with new values of *BluetoothSettiings* - related variables, callback function of each variable stores its value in cache object (*BluetoothSettings*) in `ServiceBluetooth`, then unregisters from changes in *DB*.
+When all variables are loaded from *DB*, then *BluetoothWorker* reloads Bluetooth stack with data from *BluetoothSettings* object.
+
+
+
+
+Flowchart below is an example of scenario, when user opens *BluetoothWindow*, and tries to change some of settings presented there.
+
+
diff --git a/module-bluetooth/bt_messages_class_diagram.puml b/module-bluetooth/bt_messages_class_diagram.puml
new file mode 100644
index 0000000000000000000000000000000000000000..6b307c4fcaacb789bdb20642e2a6f8257069eb90
--- /dev/null
+++ b/module-bluetooth/bt_messages_class_diagram.puml
@@ -0,0 +1,40 @@
+@startuml
+
+title BluetoothMessages - Class Diagram
+
+
+class BluetoothMessage
+
+class RequestBluetoothStatus
+class RequestBondedDevices
+class RequestDeviceName
+
+class ResponseBluetoothStatus
+class ResponseBondedDevices
+class ResponseDeviceName
+class ResponseVisibleDevices
+
+class SetBluetoothStatus
+class SetBondedDevices
+class SetDeviceName
+class SetScanState
+
+BluetoothMessage <|-left- RequestBluetoothStatus: Inheritance
+BluetoothMessage <|-up- RequestBondedDevices: Inheritance
+BluetoothMessage <|-up- RequestDeviceName: Inheritance
+
+
+BluetoothMessage <|-up- ResponseBluetoothStatus: Inheritance
+BluetoothMessage <|-up- ResponseBondedDevices: Inheritance
+BluetoothMessage <|-right- ResponseDeviceName: Inheritance
+BluetoothMessage <|-down- ResponseVisibleDevices: Inheritance
+
+
+BluetoothMessage <|-down- SetBluetoothStatus: Inheritance
+BluetoothMessage <|-down- SetBondedDevices: Inheritance
+BluetoothMessage <|-down- SetDeviceName: Inheritance
+BluetoothMessage <|-down- SetScanState: Inheritance
+
+
+
+@enduml
diff --git a/module-bluetooth/bt_messages_class_diagram.svg b/module-bluetooth/bt_messages_class_diagram.svg
new file mode 100644
index 0000000000000000000000000000000000000000..99a24766ccdb0fe512bff532a97108f8549ddc1a
--- /dev/null
+++ b/module-bluetooth/bt_messages_class_diagram.svg
@@ -0,0 +1,71 @@
+
\ No newline at end of file
diff --git a/module-bluetooth/bt_settings_basic_flowchart.puml b/module-bluetooth/bt_settings_basic_flowchart.puml
new file mode 100644
index 0000000000000000000000000000000000000000..100507c894320e14dcfc5653b40b529bc9a8a3a4
--- /dev/null
+++ b/module-bluetooth/bt_settings_basic_flowchart.puml
@@ -0,0 +1,11 @@
+@startuml
+
+[Service DB] as srvcdb
+[Service Bluetooth] as srvcbt
+[Application Settings] as appstngs
+
+
+srvcdb <-r-> srvcbt : SettingsAgent
+srvcbt <-r-> appstngs : BluetoothMessages
+
+@enduml
diff --git a/module-bluetooth/bt_settings_basic_flowchart.svg b/module-bluetooth/bt_settings_basic_flowchart.svg
new file mode 100644
index 0000000000000000000000000000000000000000..cdf2cef62d09f8762319e2a4add2e2faae5d0dcf
--- /dev/null
+++ b/module-bluetooth/bt_settings_basic_flowchart.svg
@@ -0,0 +1,26 @@
+
diff --git a/module-bluetooth/change_bt_status_flowchart.puml b/module-bluetooth/change_bt_status_flowchart.puml
new file mode 100644
index 0000000000000000000000000000000000000000..01133a240967f166c7705eb2e3de5ed2f0b97cd7
--- /dev/null
+++ b/module-bluetooth/change_bt_status_flowchart.puml
@@ -0,0 +1,45 @@
+@startuml
+
+actor User
+participant "Application Settings" as appstgs
+participant "Bluetooth Window" as btwndw
+participant "Service Bluetooth" as srvbt
+participant "Bluetooth Worker" as btwrkr
+participant "Service DB" as srvdb
+
+ == Change Bluetooth status flow ==
+
+User ->appstgs : Tries to open Bluetooth Window
+activate appstgs
+appstgs -> btwndw : Create Bluetooth Window
+ activate btwndw
+ deactivate appstgs
+btwndw -> srvbt : BluetoothMessage::RequestBluetoothStatus
+ activate srvbt
+ deactivate btwndw
+srvbt -> appstgs : BluetoothMessage::ResponseBluetoothStatus
+activate appstgs
+deactivate srvbt
+appstgs ->o btwndw : Recreate Bluetooth Window with new bluetoothStatus
+deactivate appstgs
+
+User -> btwndw : Changes bluetoothState
+activate btwndw
+btwndw -> srvbt : BluetoothMessage::SetBluetoothStatus
+deactivate btwndw
+activate srvbt
+srvbt -> srvbt : Cache received new value of bluetoothStatus
+srvbt ->o srvdb : Settings::setValue(bluetoothState)
+srvbt ->o srvdb : Settings::setValue(deviceVisibility)
+srvbt -> btwrkr : Pass cached Bluetooth settings
+activate btwrkr
+btwrkr ->o btwrkr : Reload Bluetooth settings
+deactivate btwrkr
+srvbt -> appstgs : BluetoothMessage::ResponseBluetoothStatus
+activate appstgs
+deactivate srvbt
+appstgs ->o btwndw : Recreate Bluetooth Window with new bluetoothStatus
+deactivate appstgs
+deactivate btwndw
+
+@enduml
diff --git a/module-bluetooth/change_bt_status_flowchart.svg b/module-bluetooth/change_bt_status_flowchart.svg
new file mode 100644
index 0000000000000000000000000000000000000000..612e3dd1972eb4e4ccd553906b406a246433a5f5
--- /dev/null
+++ b/module-bluetooth/change_bt_status_flowchart.svg
@@ -0,0 +1,55 @@
+
diff --git a/module-bluetooth/load_bt_settings_from_db_on_service_start_flowchart.puml b/module-bluetooth/load_bt_settings_from_db_on_service_start_flowchart.puml
new file mode 100644
index 0000000000000000000000000000000000000000..cec6b950fc05b58d1672d6b13a01239ad376c2d3
--- /dev/null
+++ b/module-bluetooth/load_bt_settings_from_db_on_service_start_flowchart.puml
@@ -0,0 +1,42 @@
+@startuml
+
+participant "Service DB" as srvdb
+participant "Service Bluetooth" as srvbt
+participant "Bluetooth Worker" as btwrkr
+
+ == Load Bluetooth Settings on startup flow ==
+
+[o->srvbt : need Bluetooth Settings
+activate srvbt
+srvbt -> srvdb : Settings::registerValueChange(bluetoothState)
+ activate srvdb
+srvbt -> srvdb : Settings::registerValueChange(deviceVisibility)
+srvbt -> srvdb : Settings::registerValueChange(deviceName)
+srvbt -> srvdb : Settings::registerValueChange(bondedDevices)
+
+deactivate srvbt
+
+srvbt <- srvdb : activate callback with new value (bluetoothState)
+activate srvbt
+srvbt <- srvdb : activate callback with new value (deviceVisibility)
+srvbt <- srvdb : activate callback with new value (deviceName)
+srvbt <- srvdb : activate callback with new value (bondedDevices)
+deactivate srvdb
+
+srvbt -> srvdb : Settings::unregisterValueChange(bluetoothState)
+ activate srvdb
+srvbt -> srvdb : Settings::unregisterValueChange(deviceVisibility)
+srvbt -> srvdb : Settings::unregisterValueChange(deviceName)
+srvbt -> srvdb : Settings::unregisterValueChange(bondedDevices)
+
+deactivate srvdb
+
+srvbt -> btwrkr : Pass cached Bluetooth settings
+
+deactivate srvbt
+activate btwrkr
+btwrkr -> btwrkr : reload Bluetooth settings
+
+deactivate btwrkr
+
+@enduml
diff --git a/module-bluetooth/load_bt_settings_from_db_on_service_start_flowchart.svg b/module-bluetooth/load_bt_settings_from_db_on_service_start_flowchart.svg
new file mode 100644
index 0000000000000000000000000000000000000000..8cc3420f249ce0b6017e089bf0fe46ed952e99d4
--- /dev/null
+++ b/module-bluetooth/load_bt_settings_from_db_on_service_start_flowchart.svg
@@ -0,0 +1,52 @@
+
diff --git a/module-bluetooth/service_bt_internals.puml b/module-bluetooth/service_bt_internals.puml
new file mode 100644
index 0000000000000000000000000000000000000000..e2c916c136f5fd2d5185b9a3acad43c83a667863
--- /dev/null
+++ b/module-bluetooth/service_bt_internals.puml
@@ -0,0 +1,13 @@
+@startuml
+
+package ServiceBluetooth {
+ object BluetoothSettings {
+ bluetoothState
+ bondedDevices
+ deviceVisibilty
+ deviceName
+}
+ class BluetoothWorker{}
+}
+
+@enduml
diff --git a/module-bluetooth/service_bt_internals.svg b/module-bluetooth/service_bt_internals.svg
new file mode 100644
index 0000000000000000000000000000000000000000..c2a1da4d91cd99d5831fbc29dca606e18b4800c1
--- /dev/null
+++ b/module-bluetooth/service_bt_internals.svg
@@ -0,0 +1,25 @@
+