| 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 "qdeviceinfo_win_p.h" |
| 41 | #include "qnetworkinfo_win_p.h" |
| 42 | #include "qscreensaver_win_p.h" |
| 43 | |
| 44 | #include <QtCore/qsettings.h> |
| 45 | |
| 46 | #include <winsock2.h> |
| 47 | #include <qt_windows.h> |
| 48 | #include <vfw.h> |
| 49 | #if !defined(Q_CC_MINGW) || defined(__MINGW64_VERSION_MAJOR) |
| 50 | # include <ws2bth.h> |
| 51 | # include <bthsdpdef.h> |
| 52 | # include <bluetoothapis.h> |
| 53 | #endif |
| 54 | |
| 55 | QT_BEGIN_NAMESPACE |
| 56 | |
| 57 | Q_GLOBAL_STATIC_WITH_ARGS(const QString, REGISTRY_BIOS_PATH, (QLatin1String("HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\BIOS"))) |
| 58 | Q_GLOBAL_STATIC_WITH_ARGS(const QString, REGISTRY_BIOS_PATH2, (QLatin1String("HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\SystemInformation"))) |
| 59 | |
| 60 | Q_GLOBAL_STATIC_WITH_ARGS(const QString, REGISTRY_CURRENT_VERSION_PATH, (QLatin1String("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"))) |
| 61 | Q_GLOBAL_STATIC_WITH_ARGS(const QString, REGISTRY_MANUFACTURER_KEY, (QLatin1String("SystemManufacturer"))) |
| 62 | Q_GLOBAL_STATIC_WITH_ARGS(const QString, REGISTRY_PRODUCTNAME_KEY, (QLatin1String("SystemProductName"))) |
| 63 | Q_GLOBAL_STATIC_WITH_ARGS(const QString, REGISTRY_PRODUCTID_KEY, (QLatin1String("ProductId"))) |
| 64 | Q_GLOBAL_STATIC_WITH_ARGS(const QString, REGISTRY_OSNAME_KEY, (QLatin1String("ProductName"))) |
| 65 | Q_GLOBAL_STATIC_WITH_ARGS(const QString, REGISTRY_BIOSVERSION_KEY, (QLatin1String("BIOSVersion"))) |
| 66 | |
| 67 | QDeviceInfoPrivate::QDeviceInfoPrivate(QDeviceInfo *parent) |
| 68 | : q_ptr(parent) |
| 69 | { |
| 70 | } |
| 71 | |
| 72 | bool QDeviceInfoPrivate::hasFeature(QDeviceInfo::Feature feature) |
| 73 | { |
| 74 | switch (feature) { |
| 75 | #if !defined(Q_CC_MINGW) || defined(__MINGW64_VERSION_MAJOR) |
| 76 | case QDeviceInfo::BluetoothFeature: { |
| 77 | BLUETOOTH_DEVICE_SEARCH_PARAMS searchParameter; |
| 78 | searchParameter.dwSize = sizeof(BLUETOOTH_DEVICE_SEARCH_PARAMS); |
| 79 | searchParameter.fReturnAuthenticated = TRUE; |
| 80 | searchParameter.fReturnRemembered = TRUE; |
| 81 | searchParameter.fReturnUnknown = TRUE; |
| 82 | searchParameter.fReturnConnected = TRUE; |
| 83 | searchParameter.fIssueInquiry = TRUE; |
| 84 | searchParameter.cTimeoutMultiplier = 1; |
| 85 | searchParameter.hRadio = NULL; |
| 86 | |
| 87 | BLUETOOTH_DEVICE_INFO deviceInfo; |
| 88 | HBLUETOOTH_DEVICE_FIND handle = BluetoothFindFirstDevice(&searchParameter, &deviceInfo); |
| 89 | if (handle) { |
| 90 | BluetoothFindDeviceClose(handle); |
| 91 | return true; |
| 92 | } else { |
| 93 | return false; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | case QDeviceInfo::InfraredFeature: { |
| 98 | WSADATA wsaData; |
| 99 | if (0 == WSAStartup(MAKEWORD(1,1), &wsaData)) { |
| 100 | SOCKET irdaSocket = socket(AF_IRDA, SOCK_STREAM, 0); |
| 101 | if (INVALID_SOCKET != irdaSocket) { |
| 102 | closesocket(irdaSocket); |
| 103 | return true; |
| 104 | } |
| 105 | } |
| 106 | return false; |
| 107 | } |
| 108 | |
| 109 | case QDeviceInfo::CameraFeature: { |
| 110 | char name[256]; |
| 111 | char version[256]; |
| 112 | for (WORD i = 0; i < 10; i++) { |
| 113 | if (capGetDriverDescriptionA(i, name, 256, version, 256)) |
| 114 | return true; |
| 115 | } |
| 116 | return false; |
| 117 | } |
| 118 | #else // !defined(Q_CC_MINGW) || defined(__MINGW64_VERSION_MAJOR) |
| 119 | case QDeviceInfo::BluetoothFeature: |
| 120 | case QDeviceInfo::InfraredFeature: |
| 121 | case QDeviceInfo::CameraFeature: |
| 122 | Q_UNIMPLEMENTED(); |
| 123 | return false; |
| 124 | #endif |
| 125 | case QDeviceInfo::WlanFeature: |
| 126 | return QNetworkInfoPrivate::wifiInterfaceCount() > 0; |
| 127 | |
| 128 | case QDeviceInfo::VideoOutFeature: |
| 129 | return (GetSystemMetrics(SM_CMONITORS) > 0); |
| 130 | |
| 131 | // not sure if we can use WDK, thus not implemented as of now |
| 132 | // case QDeviceInfo::MemoryCard: |
| 133 | // case QDeviceInfo::Usb: |
| 134 | |
| 135 | // case QDeviceInfo::Led: |
| 136 | // case QDeviceInfo::Positioning: |
| 137 | // case QDeviceInfo::FmRadio: |
| 138 | // case QDeviceInfo::FmTransmitter: |
| 139 | // case QDeviceInfo::Vibration: |
| 140 | // case QDeviceInfo::Sim: |
| 141 | // case QDeviceInfo::Haptics: |
| 142 | // case QDeviceInfo::Nfc: |
| 143 | default: |
| 144 | return false; |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | int QDeviceInfoPrivate::imeiCount() |
| 149 | { |
| 150 | return -1; |
| 151 | } |
| 152 | |
| 153 | QDeviceInfo::LockTypeFlags QDeviceInfoPrivate::activatedLocks() |
| 154 | { |
| 155 | QDeviceInfo::LockTypeFlags types = QDeviceInfo::NoLock; |
| 156 | |
| 157 | bool value(false); |
| 158 | SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, &value, 0); |
| 159 | if (value) |
| 160 | types |= QDeviceInfo::TouchOrKeyboardLock; |
| 161 | |
| 162 | if (const HDESK desktop = OpenDesktopA(const_cast<char *>("Default"), 0, false, |
| 163 | DESKTOP_SWITCHDESKTOP)) { |
| 164 | if (0 == SwitchDesktop(desktop)) |
| 165 | types |= QDeviceInfo::PinLock; |
| 166 | CloseDesktop(desktop); |
| 167 | } |
| 168 | |
| 169 | return types; |
| 170 | } |
| 171 | |
| 172 | QDeviceInfo::LockTypeFlags QDeviceInfoPrivate::enabledLocks() |
| 173 | { |
| 174 | QDeviceInfo::LockTypeFlags types = QDeviceInfo::PinLock; // We can always lock the computer |
| 175 | |
| 176 | QScreenSaverPrivate screenSaverPrivate(0); |
| 177 | if (screenSaverPrivate.screenSaverEnabled()) |
| 178 | types |= QDeviceInfo::TouchOrKeyboardLock; |
| 179 | |
| 180 | return types; |
| 181 | } |
| 182 | |
| 183 | QDeviceInfo::ThermalState QDeviceInfoPrivate::thermalState() |
| 184 | { |
| 185 | return QDeviceInfo::UnknownThermal; |
| 186 | } |
| 187 | |
| 188 | QString QDeviceInfoPrivate::imei(int /* interfaceNumber */) |
| 189 | { |
| 190 | return QString(); |
| 191 | } |
| 192 | |
| 193 | QString QDeviceInfoPrivate::manufacturer() |
| 194 | { |
| 195 | if (systemManufacturerName.isEmpty()) { |
| 196 | QSettings manufacturerSetting(*REGISTRY_BIOS_PATH(), QSettings::NativeFormat); |
| 197 | systemManufacturerName = manufacturerSetting.value(*REGISTRY_MANUFACTURER_KEY()).toString(); |
| 198 | } |
| 199 | if (systemManufacturerName.isEmpty()) { |
| 200 | QSettings manufacturerSetting2(*REGISTRY_BIOS_PATH2(), QSettings::NativeFormat); |
| 201 | systemManufacturerName = manufacturerSetting2.value(*REGISTRY_MANUFACTURER_KEY()).toString(); |
| 202 | } |
| 203 | return systemManufacturerName; |
| 204 | } |
| 205 | |
| 206 | QString QDeviceInfoPrivate::model() |
| 207 | { |
| 208 | return productName(); |
| 209 | } |
| 210 | |
| 211 | QString QDeviceInfoPrivate::productName() |
| 212 | { |
| 213 | if (systemProductName.isEmpty()) { |
| 214 | QSettings productNameSetting(*REGISTRY_BIOS_PATH(), QSettings::NativeFormat); |
| 215 | systemProductName = productNameSetting.value(*REGISTRY_PRODUCTNAME_KEY()).toString(); |
| 216 | } |
| 217 | if (systemProductName.isEmpty()) { |
| 218 | QSettings productNameSetting2(*REGISTRY_BIOS_PATH2(), QSettings::NativeFormat); |
| 219 | systemProductName = productNameSetting2.value(*REGISTRY_PRODUCTNAME_KEY()).toString(); |
| 220 | } |
| 221 | return systemProductName; |
| 222 | } |
| 223 | |
| 224 | QString QDeviceInfoPrivate::uniqueDeviceID() |
| 225 | { |
| 226 | if (deviceID.isEmpty()) { |
| 227 | QSettings deviceIDSetting(*REGISTRY_CURRENT_VERSION_PATH(), QSettings::NativeFormat); |
| 228 | deviceID = deviceIDSetting.value(*REGISTRY_PRODUCTID_KEY()).toString(); |
| 229 | } |
| 230 | return deviceID; |
| 231 | } |
| 232 | |
| 233 | QString QDeviceInfoPrivate::version(QDeviceInfo::Version type) |
| 234 | { |
| 235 | switch (type) { |
| 236 | case QDeviceInfo::Os: |
| 237 | if (osVersion.isEmpty()) { |
| 238 | OSVERSIONINFOEX versionInfo; |
| 239 | versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); |
| 240 | if (GetVersionEx((_OSVERSIONINFOW*)&versionInfo)) { |
| 241 | osVersion = QString::number(versionInfo.dwMajorVersion) + QLatin1Char('.') + QString::number(versionInfo.dwMinorVersion) + QLatin1Char('.') |
| 242 | + QString::number(versionInfo.dwBuildNumber) + QLatin1Char('.') + QString::number(versionInfo.wServicePackMajor) + QLatin1Char('.') |
| 243 | + QString::number(versionInfo.wServicePackMinor); |
| 244 | } |
| 245 | } |
| 246 | return osVersion; |
| 247 | |
| 248 | case QDeviceInfo::Firmware: |
| 249 | { |
| 250 | QSettings biosVersionSetting(*REGISTRY_BIOS_PATH2(), QSettings::NativeFormat); |
| 251 | return biosVersionSetting.value(*REGISTRY_BIOSVERSION_KEY()).toString(); |
| 252 | } |
| 253 | } |
| 254 | return QString(); |
| 255 | } |
| 256 | |
| 257 | QString QDeviceInfoPrivate::operatingSystemName() |
| 258 | { |
| 259 | QSettings deviceIDSetting(*REGISTRY_CURRENT_VERSION_PATH(), QSettings::NativeFormat); |
| 260 | QString ver = deviceIDSetting.value(*REGISTRY_OSNAME_KEY()).toString(); |
| 261 | |
| 262 | return ver; |
| 263 | } |
| 264 | |
| 265 | QString QDeviceInfoPrivate::boardName() |
| 266 | { |
| 267 | return productName(); |
| 268 | } |
| 269 | |
| 270 | bool QDeviceInfoPrivate::currentBluetoothPowerState() |
| 271 | { |
| 272 | // windows still has fragmented bt API's |
| 273 | return false; |
| 274 | } |
| 275 | |
| 276 | QT_END_NAMESPACE |