| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2018 The Qt Company Ltd and/or its subsidiary(-ies). |
| 4 | ** Contact: http://www.qt-project.org/legal |
| 5 | ** |
| 6 | ** This file is part of the QtSystems module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or (at your option) the GNU General |
| 28 | ** Public license version 3 or any later version approved by the KDE Free |
| 29 | ** Qt Foundation. The licenses are as published by the Free Software |
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 | ** included in the packaging of this file. Please review the following |
| 32 | ** information to ensure the GNU General Public License requirements will |
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 | ** |
| 36 | ** $QT_END_LICENSE$ |
| 37 | ** |
| 38 | ****************************************************************************/ |
| 39 | |
| 40 | #include "qofonowrapper_p.h" |
| 41 | |
| 42 | #include <QtCore/qmetaobject.h> |
| 43 | #include <QtDBus/qdbusconnection.h> |
| 44 | #include <QtDBus/qdbusconnectioninterface.h> |
| 45 | #include <QtDBus/qdbusmetatype.h> |
| 46 | #include <QtDBus/qdbusreply.h> |
| 47 | |
| 48 | #if !defined(QT_NO_OFONO) |
| 49 | |
| 50 | QT_BEGIN_NAMESPACE |
| 51 | |
| 52 | Q_GLOBAL_STATIC_WITH_ARGS(const QString, OFONO_SERVICE, (QLatin1String("org.ofono"))) |
| 53 | Q_GLOBAL_STATIC_WITH_ARGS(const QString, OFONO_MANAGER_INTERFACE, (QLatin1String("org.ofono.Manager"))) |
| 54 | Q_GLOBAL_STATIC_WITH_ARGS(const QString, OFONO_MANAGER_PATH, (QLatin1String("/"))) |
| 55 | Q_GLOBAL_STATIC_WITH_ARGS(const QString, OFONO_MODEM_INTERFACE, (QLatin1String("org.ofono.Modem"))) |
| 56 | Q_GLOBAL_STATIC_WITH_ARGS(const QString, OFONO_NETWORK_REGISTRATION_INTERFACE, (QLatin1String("org.ofono.NetworkRegistration"))) |
| 57 | Q_GLOBAL_STATIC_WITH_ARGS(const QString, OFONO_SIM_MANAGER_INTERFACE, (QLatin1String("org.ofono.SimManager"))) |
| 58 | |
| 59 | struct QOfonoProperty |
| 60 | { |
| 61 | QDBusObjectPath path; |
| 62 | QVariantMap properties; |
| 63 | }; |
| 64 | Q_DECLARE_METATYPE(QOfonoProperty) |
| 65 | |
| 66 | typedef QList<QOfonoProperty> QOfonoPropertyMap; |
| 67 | Q_DECLARE_METATYPE(QOfonoPropertyMap) |
| 68 | |
| 69 | QDBusArgument &operator<<(QDBusArgument &argument, const QOfonoProperty &prop) |
| 70 | { |
| 71 | argument.beginStructure(); |
| 72 | argument << prop.path << prop.properties; |
| 73 | argument.endStructure(); |
| 74 | return argument; |
| 75 | } |
| 76 | |
| 77 | const QDBusArgument &operator>>(const QDBusArgument &argument, QOfonoProperty &prop) |
| 78 | { |
| 79 | argument.beginStructure(); |
| 80 | argument >> prop.path >> prop.properties; |
| 81 | argument.endStructure(); |
| 82 | return argument; |
| 83 | } |
| 84 | |
| 85 | /*! |
| 86 | \internal |
| 87 | \class QOfonoWrapper |
| 88 | \brief QOfonoWrapper is a wrapper for OFONO DBus APIs. |
| 89 | */ |
| 90 | |
| 91 | int QOfonoWrapper::available = -1; |
| 92 | |
| 93 | QOfonoWrapper::QOfonoWrapper(QObject *parent) |
| 94 | : QObject(parent) |
| 95 | , watchAllModems(false) |
| 96 | , watchProperties(false) |
| 97 | { |
| 98 | qDBusRegisterMetaType<QOfonoProperty>(); |
| 99 | qDBusRegisterMetaType<QOfonoPropertyMap>(); |
| 100 | } |
| 101 | |
| 102 | /*! |
| 103 | \internal |
| 104 | |
| 105 | Returns true if OFONO is available, or false otherwise. |
| 106 | |
| 107 | Note that it only does the real checking when called for the first time, which might cost some |
| 108 | time. |
| 109 | */ |
| 110 | bool QOfonoWrapper::isOfonoAvailable() |
| 111 | { |
| 112 | // -1: Don't know if OFONO is available or not. |
| 113 | // 0: OFONO is not available. |
| 114 | // 1: OFONO is available. |
| 115 | if (-1 == available) { |
| 116 | if (QDBusConnection::systemBus().isConnected()) { |
| 117 | QDBusReply<bool> reply = QDBusConnection::systemBus().interface()->isServiceRegistered(*OFONO_SERVICE()); |
| 118 | if (reply.isValid()) |
| 119 | available = reply.value(); |
| 120 | else |
| 121 | available = 0; |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | return available; |
| 126 | } |
| 127 | |
| 128 | // Manager Interface |
| 129 | QStringList QOfonoWrapper::allModems() |
| 130 | { |
| 131 | if (watchAllModems) |
| 132 | return allModemPaths; |
| 133 | else |
| 134 | return getAllModems(); |
| 135 | } |
| 136 | |
| 137 | // Network Registration Interface |
| 138 | int QOfonoWrapper::signalStrength(const QString &modemPath) |
| 139 | { |
| 140 | if (watchProperties) |
| 141 | return signalStrengths.value(modemPath); |
| 142 | else |
| 143 | return getSignalStrength(modemPath); |
| 144 | } |
| 145 | |
| 146 | QNetworkInfo::CellDataTechnology QOfonoWrapper::currentCellDataTechnology(const QString &modemPath) |
| 147 | { |
| 148 | if (watchProperties) |
| 149 | return currentCellDataTechnologies.value(modemPath); |
| 150 | else |
| 151 | return getCurrentCellDataTechnology(modemPath); |
| 152 | } |
| 153 | |
| 154 | QNetworkInfo::NetworkStatus QOfonoWrapper::networkStatus(const QString &modemPath) |
| 155 | { |
| 156 | if (watchProperties) |
| 157 | return networkStatuses.value(modemPath); |
| 158 | else |
| 159 | return getNetworkStatus(modemPath); |
| 160 | } |
| 161 | |
| 162 | QString QOfonoWrapper::cellId(const QString &modemPath) |
| 163 | { |
| 164 | if (watchProperties) |
| 165 | return cellIds.value(modemPath); |
| 166 | else |
| 167 | return getCellId(modemPath); |
| 168 | } |
| 169 | |
| 170 | QString QOfonoWrapper::currentMcc(const QString &modemPath) |
| 171 | { |
| 172 | if (watchProperties) |
| 173 | return currentMccs.value(modemPath); |
| 174 | else |
| 175 | return getCurrentMcc(modemPath); |
| 176 | } |
| 177 | |
| 178 | QString QOfonoWrapper::currentMnc(const QString &modemPath) |
| 179 | { |
| 180 | if (watchProperties) |
| 181 | return currentMncs.value(modemPath); |
| 182 | else |
| 183 | return getCurrentMnc(modemPath); |
| 184 | } |
| 185 | |
| 186 | QString QOfonoWrapper::lac(const QString &modemPath) |
| 187 | { |
| 188 | if (watchProperties) |
| 189 | return lacs.value(modemPath); |
| 190 | else |
| 191 | return getLac(modemPath); |
| 192 | } |
| 193 | |
| 194 | QString QOfonoWrapper::operatorName(const QString &modemPath) |
| 195 | { |
| 196 | if (watchProperties) |
| 197 | return operatorNames.value(modemPath); |
| 198 | else |
| 199 | return getOperatorName(modemPath); |
| 200 | } |
| 201 | |
| 202 | QNetworkInfo::NetworkMode QOfonoWrapper::networkMode(const QString& modemPath) |
| 203 | { |
| 204 | return technologyToMode(currentTechnology(modemPath)); |
| 205 | } |
| 206 | |
| 207 | // SIM Manager Interface |
| 208 | QString QOfonoWrapper::homeMcc(const QString &modemPath) |
| 209 | { |
| 210 | QDBusReply<QVariantMap> reply = QDBusConnection::systemBus().call( |
| 211 | QDBusMessage::createMethodCall(*OFONO_SERVICE(), modemPath, *OFONO_SIM_MANAGER_INTERFACE(), QStringLiteral("GetProperties"))); |
| 212 | |
| 213 | return reply.value().value(QStringLiteral("MobileCountryCode")).toString(); |
| 214 | } |
| 215 | |
| 216 | QString QOfonoWrapper::homeMnc(const QString &modemPath) |
| 217 | { |
| 218 | QDBusReply<QVariantMap> reply = QDBusConnection::systemBus().call( |
| 219 | QDBusMessage::createMethodCall(*OFONO_SERVICE(), modemPath, *OFONO_SIM_MANAGER_INTERFACE(), QStringLiteral("GetProperties"))); |
| 220 | |
| 221 | return reply.value().value(QStringLiteral("MobileNetworkCode")).toString(); |
| 222 | } |
| 223 | |
| 224 | QString QOfonoWrapper::imsi(const QString &modemPath) |
| 225 | { |
| 226 | QDBusReply<QVariantMap> reply = QDBusConnection::systemBus().call( |
| 227 | QDBusMessage::createMethodCall(*OFONO_SERVICE(), modemPath, *OFONO_SIM_MANAGER_INTERFACE(), QStringLiteral("GetProperties"))); |
| 228 | |
| 229 | return reply.value().value(QStringLiteral("SubscriberIdentity")).toString(); |
| 230 | } |
| 231 | |
| 232 | // Modem Interface |
| 233 | QString QOfonoWrapper::imei(const QString &modemPath) |
| 234 | { |
| 235 | QDBusReply<QVariantMap> reply = QDBusConnection::systemBus().call( |
| 236 | QDBusMessage::createMethodCall(*OFONO_SERVICE(), modemPath, *OFONO_MODEM_INTERFACE(), QStringLiteral("GetProperties"))); |
| 237 | |
| 238 | return reply.value().value(QStringLiteral("Serial")).toString(); |
| 239 | } |
| 240 | |
| 241 | void QOfonoWrapper::connectNotify(const QMetaMethod &signal) |
| 242 | { |
| 243 | static const QMetaMethod cellIdChangedSignal = QMetaMethod::fromSignal(&QOfonoWrapper::cellIdChanged); |
| 244 | static const QMetaMethod currentCellDataTechnologyChangedSignal = QMetaMethod::fromSignal(&QOfonoWrapper::currentCellDataTechnologyChanged); |
| 245 | static const QMetaMethod currentMobileCountryCodeChangedSignal = QMetaMethod::fromSignal(&QOfonoWrapper::currentMobileCountryCodeChanged); |
| 246 | static const QMetaMethod currentMobileNetworkCodeChangedSignal = QMetaMethod::fromSignal(&QOfonoWrapper::currentMobileNetworkCodeChanged); |
| 247 | static const QMetaMethod currentNetworkModeChangedSignal = QMetaMethod::fromSignal(&QOfonoWrapper::currentNetworkModeChanged); |
| 248 | static const QMetaMethod locationAreaCodeChangedSignal = QMetaMethod::fromSignal(&QOfonoWrapper::locationAreaCodeChanged); |
| 249 | static const QMetaMethod networkInterfaceCountChangedSignal = QMetaMethod::fromSignal(&QOfonoWrapper::networkInterfaceCountChanged); |
| 250 | static const QMetaMethod networkNameChangedSignal = QMetaMethod::fromSignal(&QOfonoWrapper::networkNameChanged); |
| 251 | static const QMetaMethod networkSignalStrengthChangedSignal = QMetaMethod::fromSignal(&QOfonoWrapper::networkSignalStrengthChanged); |
| 252 | static const QMetaMethod networkStatusChangedSignal = QMetaMethod::fromSignal(&QOfonoWrapper::networkStatusChanged); |
| 253 | |
| 254 | if (signal == networkInterfaceCountChangedSignal) { |
| 255 | allModemPaths = getAllModems(); |
| 256 | QDBusConnection::systemBus().connect(*OFONO_SERVICE(), *OFONO_MANAGER_PATH(), *OFONO_MANAGER_INTERFACE(), |
| 257 | QStringLiteral("ModemAdded"), |
| 258 | this, SLOT(onOfonoModemAdded(QDBusObjectPath))); |
| 259 | QDBusConnection::systemBus().connect(*OFONO_SERVICE(), *OFONO_MANAGER_PATH(), *OFONO_MANAGER_INTERFACE(), |
| 260 | QStringLiteral("ModemRemoved"), |
| 261 | this, SLOT(onOfonoModemRemoved(QDBusObjectPath))); |
| 262 | watchAllModems = true; |
| 263 | } else if (signal == currentMobileCountryCodeChangedSignal |
| 264 | || signal == currentMobileNetworkCodeChangedSignal |
| 265 | || signal == currentNetworkModeChangedSignal |
| 266 | || signal == cellIdChangedSignal |
| 267 | || signal == currentCellDataTechnologyChangedSignal |
| 268 | || signal == locationAreaCodeChangedSignal |
| 269 | || signal == networkNameChangedSignal |
| 270 | || signal == networkSignalStrengthChangedSignal |
| 271 | || signal == networkStatusChangedSignal) { |
| 272 | signalStrengths.clear(); |
| 273 | currentCellDataTechnologies.clear(); |
| 274 | networkStatuses.clear(); |
| 275 | cellIds.clear(); |
| 276 | currentMccs.clear(); |
| 277 | currentMncs.clear(); |
| 278 | lacs.clear(); |
| 279 | operatorNames.clear(); |
| 280 | QStringList modems = allModems(); |
| 281 | foreach (const QString &modem, modems) { |
| 282 | signalStrengths[modem] = getSignalStrength(modem); |
| 283 | currentCellDataTechnologies[modem] = getCurrentCellDataTechnology(modem); |
| 284 | networkStatuses[modem] = getNetworkStatus(modem); |
| 285 | cellIds[modem] = getCellId(modem); |
| 286 | currentMccs[modem] = getCurrentMcc(modem); |
| 287 | currentMncs[modem] = getCurrentMnc(modem); |
| 288 | lacs[modem] = getLac(modem); |
| 289 | operatorNames[modem] = getOperatorName(modem); |
| 290 | QDBusConnection::systemBus().connect(*OFONO_SERVICE(), |
| 291 | modem, |
| 292 | *OFONO_NETWORK_REGISTRATION_INTERFACE(), |
| 293 | QStringLiteral("PropertyChanged"), |
| 294 | this, SLOT(onOfonoPropertyChanged(QString,QDBusVariant))); |
| 295 | } |
| 296 | watchProperties = true; |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | void QOfonoWrapper::disconnectNotify(const QMetaMethod &signal) |
| 301 | { |
| 302 | static const QMetaMethod cellIdChangedSignal = QMetaMethod::fromSignal(&QOfonoWrapper::cellIdChanged); |
| 303 | static const QMetaMethod currentCellDataTechnologyChangedSignal = QMetaMethod::fromSignal(&QOfonoWrapper::currentCellDataTechnologyChanged); |
| 304 | static const QMetaMethod currentMobileCountryCodeChangedSignal = QMetaMethod::fromSignal(&QOfonoWrapper::currentMobileCountryCodeChanged); |
| 305 | static const QMetaMethod currentMobileNetworkCodeChangedSignal = QMetaMethod::fromSignal(&QOfonoWrapper::currentMobileNetworkCodeChanged); |
| 306 | static const QMetaMethod currentNetworkModeChangedSignal = QMetaMethod::fromSignal(&QOfonoWrapper::currentNetworkModeChanged); |
| 307 | static const QMetaMethod locationAreaCodeChangedSignal = QMetaMethod::fromSignal(&QOfonoWrapper::locationAreaCodeChanged); |
| 308 | static const QMetaMethod networkInterfaceCountChangedSignal = QMetaMethod::fromSignal(&QOfonoWrapper::networkInterfaceCountChanged); |
| 309 | static const QMetaMethod networkNameChangedSignal = QMetaMethod::fromSignal(&QOfonoWrapper::networkNameChanged); |
| 310 | static const QMetaMethod networkSignalStrengthChangedSignal = QMetaMethod::fromSignal(&QOfonoWrapper::networkSignalStrengthChanged); |
| 311 | static const QMetaMethod networkStatusChangedSignal = QMetaMethod::fromSignal(&QOfonoWrapper::networkStatusChanged); |
| 312 | |
| 313 | if (signal == networkInterfaceCountChangedSignal) { |
| 314 | QDBusConnection::systemBus().disconnect(*OFONO_SERVICE(), *OFONO_MANAGER_PATH(), *OFONO_MANAGER_INTERFACE(), |
| 315 | QStringLiteral("ModemAdded"), |
| 316 | this, SLOT(onOfonoModemAdded(QDBusObjectPath))); |
| 317 | QDBusConnection::systemBus().disconnect(*OFONO_SERVICE(), *OFONO_MANAGER_PATH(), *OFONO_MANAGER_INTERFACE(), |
| 318 | QStringLiteral("ModemRemoved"), |
| 319 | this, SLOT(onOfonoModemRemoved(QDBusObjectPath))); |
| 320 | watchAllModems = false; |
| 321 | } else if (signal == currentMobileCountryCodeChangedSignal |
| 322 | || signal == currentMobileNetworkCodeChangedSignal |
| 323 | || signal == currentNetworkModeChangedSignal |
| 324 | || signal == cellIdChangedSignal |
| 325 | || signal == currentCellDataTechnologyChangedSignal |
| 326 | || signal == locationAreaCodeChangedSignal |
| 327 | || signal == networkNameChangedSignal |
| 328 | || signal == networkSignalStrengthChangedSignal |
| 329 | || signal == networkStatusChangedSignal) { |
| 330 | QStringList modems = allModems(); |
| 331 | foreach (const QString &modem, modems) { |
| 332 | QDBusConnection::systemBus().disconnect(*OFONO_SERVICE(), |
| 333 | modem, |
| 334 | *OFONO_NETWORK_REGISTRATION_INTERFACE(), |
| 335 | QStringLiteral("PropertyChanged"), |
| 336 | this, SLOT(onOfonoPropertyChanged(QString,QDBusVariant))); |
| 337 | } |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | void QOfonoWrapper::onOfonoModemAdded(const QDBusObjectPath &path) |
| 342 | { |
| 343 | allModemPaths.append(path.path()); |
| 344 | emit networkInterfaceCountChanged(QNetworkInfo::GsmMode, allModemPaths.size()); |
| 345 | emit networkInterfaceCountChanged(QNetworkInfo::CdmaMode, allModemPaths.size()); |
| 346 | emit networkInterfaceCountChanged(QNetworkInfo::WcdmaMode, allModemPaths.size()); |
| 347 | emit networkInterfaceCountChanged(QNetworkInfo::LteMode, allModemPaths.size()); |
| 348 | } |
| 349 | |
| 350 | void QOfonoWrapper::onOfonoModemRemoved(const QDBusObjectPath &path) |
| 351 | { |
| 352 | allModemPaths.removeOne(path.path()); |
| 353 | emit networkInterfaceCountChanged(QNetworkInfo::GsmMode, allModemPaths.size()); |
| 354 | emit networkInterfaceCountChanged(QNetworkInfo::CdmaMode, allModemPaths.size()); |
| 355 | emit networkInterfaceCountChanged(QNetworkInfo::WcdmaMode, allModemPaths.size()); |
| 356 | emit networkInterfaceCountChanged(QNetworkInfo::LteMode, allModemPaths.size()); |
| 357 | } |
| 358 | |
| 359 | void QOfonoWrapper::onOfonoPropertyChanged(const QString &property, const QDBusVariant &value) |
| 360 | { |
| 361 | if (!calledFromDBus()) |
| 362 | return; |
| 363 | |
| 364 | int interface = allModems().indexOf(message().path()); |
| 365 | |
| 366 | if (property == QStringLiteral("MobileCountryCode")) |
| 367 | emit currentMobileCountryCodeChanged(interface, value.variant().toString()); |
| 368 | else if (property == QStringLiteral("MobileNetworkCode")) |
| 369 | emit currentMobileNetworkCodeChanged(interface, value.variant().toString()); |
| 370 | else if (property == QStringLiteral("CellId")) |
| 371 | emit cellIdChanged(interface, value.variant().toString()); |
| 372 | else if (property == QStringLiteral("Technology")) |
| 373 | emit currentCellDataTechnologyChanged(interface, technologyStringToEnum(value.variant().toString())); |
| 374 | else if (property == QStringLiteral("LocationAreaCode")) |
| 375 | emit locationAreaCodeChanged(interface, value.variant().toString()); |
| 376 | else if (property == QStringLiteral("Name")) |
| 377 | emit networkNameChanged(technologyToMode(currentTechnology(message().path())), interface, value.variant().toString()); |
| 378 | else if (property == QStringLiteral("Strength")) |
| 379 | emit networkSignalStrengthChanged(technologyToMode(currentTechnology(message().path())), interface, value.variant().toInt()); |
| 380 | else if (property == QStringLiteral("Status")) |
| 381 | emit networkStatusChanged(technologyToMode(currentTechnology(message().path())), interface, statusStringToEnum(value.variant().toString())); |
| 382 | } |
| 383 | |
| 384 | QNetworkInfo::CellDataTechnology QOfonoWrapper::technologyStringToEnum(const QString &technology) |
| 385 | { |
| 386 | if (technology == QStringLiteral("edge")) |
| 387 | return QNetworkInfo::EdgeDataTechnology; |
| 388 | else if (technology == QStringLiteral("umts")) |
| 389 | return QNetworkInfo::UmtsDataTechnology; |
| 390 | else if (technology == QStringLiteral("hspa")) |
| 391 | return QNetworkInfo::HspaDataTechnology; |
| 392 | else |
| 393 | return QNetworkInfo::UnknownDataTechnology; |
| 394 | } |
| 395 | |
| 396 | QNetworkInfo::NetworkMode QOfonoWrapper::technologyToMode(const QString &technology) |
| 397 | { |
| 398 | if (technology == QStringLiteral("lte")) { |
| 399 | return QNetworkInfo::LteMode; |
| 400 | } else if (technology == QStringLiteral("hspa")) { |
| 401 | return QNetworkInfo::WcdmaMode; |
| 402 | } else if (technology == QStringLiteral("gsm") |
| 403 | || technology == QStringLiteral("edge") |
| 404 | || technology == QStringLiteral("umts")) { |
| 405 | return QNetworkInfo::GsmMode; |
| 406 | } else { |
| 407 | return QNetworkInfo::CdmaMode; |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | QNetworkInfo::NetworkStatus QOfonoWrapper::statusStringToEnum(const QString &status) |
| 412 | { |
| 413 | if (status == QStringLiteral("unregistered")) |
| 414 | return QNetworkInfo::NoNetworkAvailable; |
| 415 | else if (status == QStringLiteral("registered")) |
| 416 | return QNetworkInfo::HomeNetwork; |
| 417 | else if (status == QStringLiteral("searching")) |
| 418 | return QNetworkInfo::Searching; |
| 419 | else if (status == QStringLiteral("denied")) |
| 420 | return QNetworkInfo::Denied; |
| 421 | else if (status == QStringLiteral("roaming")) |
| 422 | return QNetworkInfo::Roaming; |
| 423 | else |
| 424 | return QNetworkInfo::UnknownStatus; |
| 425 | } |
| 426 | |
| 427 | QString QOfonoWrapper::currentTechnology(const QString &modemPath) |
| 428 | { |
| 429 | QDBusReply<QVariantMap> reply = QDBusConnection::systemBus().call( |
| 430 | QDBusMessage::createMethodCall(*OFONO_SERVICE(), modemPath, *OFONO_NETWORK_REGISTRATION_INTERFACE(), QStringLiteral("GetProperties"))); |
| 431 | |
| 432 | return reply.value().value(QStringLiteral("Technology")).toString(); |
| 433 | } |
| 434 | |
| 435 | // Manager Interface |
| 436 | QStringList QOfonoWrapper::getAllModems() |
| 437 | { |
| 438 | QDBusReply<QOfonoPropertyMap> reply = QDBusConnection::systemBus().call( |
| 439 | QDBusMessage::createMethodCall(*OFONO_SERVICE(), *OFONO_MANAGER_PATH(), *OFONO_MANAGER_INTERFACE(), QStringLiteral("GetModems"))); |
| 440 | |
| 441 | QStringList modems; |
| 442 | if (reply.isValid()) { |
| 443 | foreach (const QOfonoProperty &property, reply.value()) |
| 444 | modems << property.path.path(); |
| 445 | } |
| 446 | return modems; |
| 447 | } |
| 448 | |
| 449 | // Network Registration Interface |
| 450 | int QOfonoWrapper::getSignalStrength(const QString &modemPath) |
| 451 | { |
| 452 | QDBusReply<QVariantMap> reply = QDBusConnection::systemBus().call( |
| 453 | QDBusMessage::createMethodCall(*OFONO_SERVICE(), modemPath, *OFONO_NETWORK_REGISTRATION_INTERFACE(), QStringLiteral("GetProperties"))); |
| 454 | |
| 455 | return reply.value().value(QStringLiteral("Strength")).toInt(); |
| 456 | } |
| 457 | |
| 458 | QNetworkInfo::CellDataTechnology QOfonoWrapper::getCurrentCellDataTechnology(const QString &modemPath) |
| 459 | { |
| 460 | return technologyStringToEnum(currentTechnology(modemPath)); |
| 461 | } |
| 462 | |
| 463 | QNetworkInfo::NetworkStatus QOfonoWrapper::getNetworkStatus(const QString &modemPath) |
| 464 | { |
| 465 | QDBusReply<QVariantMap> reply = QDBusConnection::systemBus().call( |
| 466 | QDBusMessage::createMethodCall(*OFONO_SERVICE(), modemPath, *OFONO_NETWORK_REGISTRATION_INTERFACE(), QStringLiteral("GetProperties"))); |
| 467 | |
| 468 | return statusStringToEnum(reply.value().value(QStringLiteral("Status")).toString()); |
| 469 | } |
| 470 | |
| 471 | QString QOfonoWrapper::getCellId(const QString &modemPath) |
| 472 | { |
| 473 | QDBusReply<QVariantMap> reply = QDBusConnection::systemBus().call( |
| 474 | QDBusMessage::createMethodCall(*OFONO_SERVICE(), modemPath, *OFONO_NETWORK_REGISTRATION_INTERFACE(), QStringLiteral("GetProperties"))); |
| 475 | |
| 476 | return reply.value().value(QStringLiteral("CellId")).toString(); |
| 477 | } |
| 478 | |
| 479 | QString QOfonoWrapper::getCurrentMcc(const QString &modemPath) |
| 480 | { |
| 481 | QDBusReply<QVariantMap> reply = QDBusConnection::systemBus().call( |
| 482 | QDBusMessage::createMethodCall(*OFONO_SERVICE(), modemPath, *OFONO_NETWORK_REGISTRATION_INTERFACE(), QStringLiteral("GetProperties"))); |
| 483 | |
| 484 | return reply.value().value(QStringLiteral("MobileCountryCode")).toString(); |
| 485 | } |
| 486 | |
| 487 | QString QOfonoWrapper::getCurrentMnc(const QString &modemPath) |
| 488 | { |
| 489 | QDBusReply<QVariantMap> reply = QDBusConnection::systemBus().call( |
| 490 | QDBusMessage::createMethodCall(*OFONO_SERVICE(), modemPath, *OFONO_NETWORK_REGISTRATION_INTERFACE(), QStringLiteral("GetProperties"))); |
| 491 | |
| 492 | return reply.value().value(QStringLiteral("MobileNetworkCode")).toString(); |
| 493 | } |
| 494 | |
| 495 | QString QOfonoWrapper::getLac(const QString &modemPath) |
| 496 | { |
| 497 | QDBusReply<QVariantMap> reply = QDBusConnection::systemBus().call( |
| 498 | QDBusMessage::createMethodCall(*OFONO_SERVICE(), modemPath, *OFONO_NETWORK_REGISTRATION_INTERFACE(), QStringLiteral("GetProperties"))); |
| 499 | |
| 500 | return reply.value().value(QStringLiteral("LocationAreaCode")).toString(); |
| 501 | } |
| 502 | |
| 503 | QString QOfonoWrapper::getOperatorName(const QString &modemPath) |
| 504 | { |
| 505 | QDBusReply<QVariantMap> reply = QDBusConnection::systemBus().call( |
| 506 | QDBusMessage::createMethodCall(*OFONO_SERVICE(), modemPath, *OFONO_NETWORK_REGISTRATION_INTERFACE(), QStringLiteral("GetProperties"))); |
| 507 | |
| 508 | return reply.value().value(QStringLiteral("Name")).toString(); |
| 509 | } |
| 510 | |
| 511 | QT_END_NAMESPACE |
| 512 | |
| 513 | #endif // QT_NO_OFONO |