Skip to content

Commit 61e2b7d

Browse files
committed
Add (estimated) Carrier Aggregation cells
* Add Carrier Aggregation cell list to model * Add Carrier Aggregation cells API endpoints: * /estimate-ca/all : returns a list of estimated Carrier Aggregation cells - if more than 1 cells have the status connected, return them all as Carrier Aggregation cells - if only a single cell is connected, take the best-RSRQ cell from the available cells (CA estimation) * /estimate-ca/{id} : returns the cell information of a single cell
1 parent cf1e08e commit 61e2b7d

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

app/src/main/java/eu/bschmidt/devicepublisher/api/celldata/routeCellData.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ suspend fun getAvailableCells(viewModel: CellDataViewModel): MutableList<CellDat
3333
return localCellList
3434
}
3535

36+
suspend fun getCACells(viewModel: CellDataViewModel): MutableList<CellData> {
37+
val localCellList: MutableList<CellData> = mutableListOf<CellData>()
38+
localCellList.addAll(viewModel.getCACells().toMutableList())
39+
return localCellList
40+
}
41+
3642
fun Route.routeCellData() {
3743
val viewModel: CellDataViewModel = CellDataViewModel.getInstance()
3844

@@ -75,6 +81,24 @@ fun Route.routeCellData() {
7581
}
7682
}
7783
}
84+
85+
route("/estimate-ca") {
86+
get("/all") {
87+
val cellList = getCACells(viewModel)
88+
call.respond(cellList)
89+
}
90+
get("/cell/{id}") {
91+
val id = call.parameters["id"]?.toIntOrNull()
92+
val cellList = getCACells(viewModel)
93+
if (id != null && id >= 0 && id < cellList.size) {
94+
val someCell: CellData = cellList[id]
95+
call.respond(someCell)
96+
} else {
97+
call.respondText("Cell not found", status = HttpStatusCode.NotFound)
98+
}
99+
}
100+
}
101+
78102

79103
}
80104
}

app/src/main/java/eu/bschmidt/devicepublisher/model/celldata/CellDataViewModel.kt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,21 @@ class CellDataViewModel : ViewModel(), DataViewModelInterface {
5151

5252
private val _coreConnected: MutableList<CellData> = Collections.synchronizedList(mutableListOf<CellData>())
5353
private val _coreAvailable: MutableList<CellData> = Collections.synchronizedList(mutableListOf<CellData>())
54+
private val _coreCA: MutableList<CellData> = Collections.synchronizedList(mutableListOf<CellData>())
5455

5556
private val _connectedCellDataList = MutableLiveData<List<CellData>>()
5657
val connectedCellDataList: LiveData<List<CellData>> get() = _connectedCellDataList
5758

5859
private val _availableCellDataList = MutableLiveData<List<CellData>>()
5960
val availableCellDataList: LiveData<List<CellData>> get() = _availableCellDataList
6061

62+
private val _caCellDataList = MutableLiveData<List<CellData>>()
63+
val caCellDataList: LiveData<List<CellData>> get() = _availableCellDataList
64+
6165
init {
6266
_connectedCellDataList.value = emptyList()
6367
_availableCellDataList.value = emptyList()
68+
_caCellDataList.value = emptyList()
6469
}
6570

6671
/* connected */
@@ -91,6 +96,20 @@ class CellDataViewModel : ViewModel(), DataViewModelInterface {
9196
return _coreAvailable.toMutableList()
9297
}
9398

99+
/* Carrier Aggregation (CA) */
100+
101+
private fun setCACellData(newList: List<CellData>) {
102+
_coreCA.clear()
103+
_coreCA.addAll(newList)
104+
DevPubUtils.dispatchToMainThread {
105+
_caCellDataList.value = _coreCA
106+
}
107+
}
108+
109+
fun getCACells(): List<CellData> {
110+
return _coreCA.toMutableList()
111+
}
112+
94113
/* logic */
95114

96115
private fun checkPhonePermission(context: Context): Boolean {
@@ -142,6 +161,7 @@ class CellDataViewModel : ViewModel(), DataViewModelInterface {
142161

143162
val conList: MutableList<CellData> = mutableListOf<CellData>()
144163
val avaList: MutableList<CellData> = mutableListOf<CellData>()
164+
val caList: MutableList<CellData> = mutableListOf<CellData>()
145165

146166
currentCells.forEach { cell ->
147167
if (cell !is CellLte && cell !is CellNr) {
@@ -186,12 +206,25 @@ class CellDataViewModel : ViewModel(), DataViewModelInterface {
186206
}
187207
if (cell.connectionStatus != NoneConnection()) {
188208
conList.add(cellData)
209+
caList.add(cellData)
189210
} else {
190211
avaList.add(cellData)
191212
}
192213
}
214+
/* If there is one connected cell, take the best-RSRQ cell
215+
as an "estimate" to the potential Carrier Aggregation cells
216+
*/
217+
if (caList.size == 1 && avaList.size >= 1) {
218+
val lowestRsrqCell = avaList
219+
.filter { it.rsrq != null }
220+
.maxByOrNull { it.rsrq!! }
221+
if (lowestRsrqCell != null) {
222+
caList.add(lowestRsrqCell)
223+
}
224+
}
193225
setConnectedCellData(conList)
194226
setAvailableCellData(avaList)
227+
setCACellData(caList)
195228
}
196229

197230
companion object {

0 commit comments

Comments
 (0)