bool S60Devices::readWin() { const QString devicesXmlPath = devicesXmlFile(&m_errorString); if (devicesXmlPath.isEmpty()) return false; QFile devicesFile(devicesXmlPath); if (!devicesFile.open(QIODevice::ReadOnly|QIODevice::Text)) { m_errorString = QString::fromLatin1("Could not open the devices file %1: %2").arg(devicesXmlPath, devicesFile.errorString()); return false; } QXmlStreamReader xml(&devicesFile); while (!xml.atEnd()) { xml.readNext(); if (xml.isStartElement() && xml.name() == DEVICES_LIST) { if (xml.attributes().value("version") == "1.0") { // Look for correct device while (!(xml.isEndElement() && xml.name() == DEVICES_LIST) && !xml.atEnd()) { xml.readNext(); if (xml.isStartElement() && xml.name() == DEVICE) { Device device; device.id = xml.attributes().value(DEVICE_ID).toString(); device.name = xml.attributes().value(DEVICE_NAME).toString(); if (xml.attributes().value(DEVICE_DEFAULT).toString() == "yes") device.isDefault = true; else device.isDefault = false; while (!(xml.isEndElement() && xml.name() == DEVICE) && !xml.atEnd()) { xml.readNext(); if (xml.isStartElement() && xml.name() == DEVICE_EPOCROOT) { device.epocRoot = xml.readElementText(); } else if (xml.isStartElement() && xml.name() == DEVICE_TOOLSROOT) { device.toolsRoot = xml.readElementText(); } } if (device.toolsRoot.isEmpty()) device.toolsRoot = device.epocRoot; m_devices.append(device); } } } else { xml.raiseError("Invalid 'devices' element version."); } } } devicesFile.close(); if (xml.hasError()) { m_errorString = QString::fromLatin1("Syntax error in devices file %1: %2"). arg(devicesXmlPath, xml.errorString()); return false; } return true; }
/** * Determine the epoc root for the currently active SDK. */ QString qt_epocRoot() { if (epocRootValue.isEmpty()) { // 1. If environment variable EPOCROOT is set and points to an existent // directory, this is returned. epocRootValue = QString::fromLocal8Bit(qgetenv("EPOCROOT").constData()); checkEpocRootExists(QLatin1String("EPOCROOT environment variable")); if (epocRootValue.isEmpty()) { // 2. The location of devices.xml is specified by a registry key. If this // file exists, it is parsed. QString devicesXmlPath = getDevicesXmlPath(); if (!devicesXmlPath.isEmpty()) { devicesXmlPath += QLatin1String("/devices.xml"); QFile devicesFile(devicesXmlPath); if (devicesFile.open(QIODevice::ReadOnly)) { // 3. If the EPOCDEVICE environment variable is set and a corresponding // entry is found in devices.xml, and its epocroot value points to an // existent directory, it is returned. // 4. If a device element marked as default is found in devices.xml and its // epocroot value points to an existent directory, this is returned. const QString epocDeviceValue = QString::fromLocal8Bit(qgetenv("EPOCDEVICE").constData()); bool epocDeviceFound = false; QXmlStreamReader xml(&devicesFile); while (!xml.atEnd()) { xml.readNext(); if (xml.isStartElement() && xml.name() == QLatin1String("devices")) { if (xml.attributes().value(QLatin1String("version")) == QLatin1String("1.0")) { while (!(xml.isEndElement() && xml.name() == QLatin1String("devices")) && !xml.atEnd()) { xml.readNext(); if (xml.isStartElement() && xml.name() == QLatin1String("device")) { const bool isDefault = xml.attributes().value(QLatin1String("default")) == QLatin1String("yes"); const QString id = xml.attributes().value(QLatin1String("id")).toString(); const QString name = xml.attributes().value(QLatin1String("name")).toString(); const QString alias = xml.attributes().value(QLatin1String("alias")).toString(); bool epocDeviceMatch = QString(id + QLatin1String(":") + name) == epocDeviceValue; if (!alias.isEmpty()) epocDeviceMatch |= alias == epocDeviceValue; epocDeviceFound |= epocDeviceMatch; if((epocDeviceValue.isEmpty() && isDefault) || epocDeviceMatch) { // Found a matching device while (!(xml.isEndElement() && xml.name() == QLatin1String("device")) && !xml.atEnd()) { xml.readNext(); if (xml.isStartElement() && xml.name() == QLatin1String("epocroot")) { epocRootValue = xml.readElementText(); const QString deviceSource = epocDeviceValue.isEmpty() ? QLatin1String("default device") : QString(QLatin1String("EPOCDEVICE (") + epocDeviceValue + QLatin1String(")")); checkEpocRootExists(deviceSource); } } if (epocRootValue.isEmpty()) xml.raiseError(QLatin1String("No epocroot element found")); } } } } else { xml.raiseError(QLatin1String("Invalid 'devices' element version")); } } } if (xml.hasError()) { qWarning("Warning: Error \"%s\" when parsing devices.xml", qPrintable(xml.errorString())); } else { if (epocRootValue.isEmpty()) { if (!epocDeviceValue.isEmpty()) { if (epocDeviceFound) { qWarning("Warning: Missing or invalid epocroot attribute in device '%s' in devices.xml.", qPrintable(epocDeviceValue)); } else { qWarning("Warning: No device matching EPOCDEVICE (%s) in devices.xml.", qPrintable(epocDeviceValue)); } } else { if (epocDeviceFound) { qWarning("Warning: Missing or invalid epocroot attribute in default device in devices.xml."); } else { qWarning("Warning: No default device set in devices.xml."); } } } } } else { qWarning("Warning: Could not open file: '%s'.", qPrintable(devicesXmlPath)); } } } if (epocRootValue.isEmpty()) { // 5. An empty string is returned. qWarning("Warning: failed to resolve epocroot." #ifdef Q_OS_WIN32 "\nEither\n" " 1. Set EPOCROOT environment variable to a valid value.\n" " or 2. Ensure that the HKEY_LOCAL_MACHINE\\" SYMBIAN_SDKS_REG_SUBKEY " registry key is set, and then\n" " a. Set EPOCDEVICE environment variable to a valid device\n" " or b. Specify a default device in the devices.xml file."); #else " Set EPOCROOT environment variable to a valid value."); #endif } else {
void TestRunnerMobile::connectDevice() { #if defined Q_OS_WIN || defined Q_OS_MAC if (!_adbInterface) { _adbInterface = new AdbInterface(); } // Get list of devices QString devicesFullFilename{ _workingFolder + "/devices.txt" }; QString command = _adbInterface->getAdbCommand() + " devices -l > " + devicesFullFilename; appendLog(command); system(command.toStdString().c_str()); if (!QFile::exists(devicesFullFilename)) { QMessageBox::critical(0, "Internal error", "devices.txt not found"); exit (-1); } // Get device IP address QString ifconfigFullFilename{ _workingFolder + "/ifconfig.txt" }; command = _adbInterface->getAdbCommand() + " shell ifconfig > " + ifconfigFullFilename; appendLog(command); system(command.toStdString().c_str()); if (!QFile::exists(ifconfigFullFilename)) { QMessageBox::critical(0, "Internal error", "ifconfig.txt not found"); exit (-1); } // Device should be in second line QFile devicesFile(devicesFullFilename); devicesFile.open(QIODevice::ReadOnly | QIODevice::Text); QString line1 = devicesFile.readLine(); QString line2 = devicesFile.readLine(); const QString DEVICE{ "device" }; const QString MODEL{ "model" }; if (line2.contains("unauthorized")) { QMessageBox::critical(0, "Unauthorized device detected", "Please allow USB debugging on device"); } else if (line2.contains(DEVICE)) { // Make sure only 1 device QString line3 = devicesFile.readLine(); if (line3.contains(DEVICE)) { QMessageBox::critical(0, "Too many devices detected", "Tests will run only if a single device is attached"); } else { // Line looks like this: 988a1b47335239434b device product:dream2qlteue model:SM_G955U1 device:dream2qlteue transport_id:2 QStringList tokens = line2.split(QRegExp("[\r\n\t ]+")); QString deviceID = tokens[0]; // Find the model entry _modelName = "UNKNOWN"; for (int i = 0; i < tokens.size(); ++i) { if (tokens[i].contains(MODEL)) { QString modelID = tokens[i].split(':')[1]; if (modelNames.count(modelID) == 1) { _modelName = modelNames[modelID]; } break; } } _detectedDeviceLabel->setText(_modelName + " [" + deviceID + "]"); _pullFolderButton->setEnabled(true); _folderLineEdit->setEnabled(true); _downloadAPKPushbutton->setEnabled(true); _installAPKPushbutton->setEnabled(true); _runInterfacePushbutton->setEnabled(true); } } #endif }
/** * Determine the epoc root for the currently active SDK. */ QString epocRoot() { if (epocRootValue.isEmpty()) { // 1. If environment variable EPOCROOT is set and points to an existent // directory, this is returned. epocRootValue = qgetenv("EPOCROOT"); checkEpocRootExists("EPOCROOT"); if (epocRootValue.isEmpty()) { // 2. The location of devices.xml is specified by a registry key. If this // file exists, it is parsed. QString devicesXmlPath = getDevicesXmlPath(); if (devicesXmlPath.isEmpty()) { std::cerr << "Error: Symbian SDK registry key not found" << std::endl; } else { devicesXmlPath += "/devices.xml"; QFile devicesFile(devicesXmlPath); if (devicesFile.open(QIODevice::ReadOnly)) { // 3. If the EPOCDEVICE environment variable is set and a corresponding // entry is found in devices.xml, and its epocroot value points to an // existent directory, it is returned. // 4. If a device element marked as default is found in devices.xml and its // epocroot value points to an existent directory, this is returned. const QString epocDeviceValue = qgetenv("EPOCDEVICE"); bool epocDeviceFound = false; QXmlStreamReader xml(&devicesFile); while (!xml.atEnd()) { xml.readNext(); if (xml.isStartElement() && xml.name() == "devices") { if (xml.attributes().value("version") == "1.0") { while (!(xml.isEndElement() && xml.name() == "devices") && !xml.atEnd()) { xml.readNext(); if (xml.isStartElement() && xml.name() == "device") { const bool isDefault = xml.attributes().value("default") == "yes"; const QString id = xml.attributes().value("id").toString(); const QString name = xml.attributes().value("name").toString(); const QString alias = xml.attributes().value("alias").toString(); bool epocDeviceMatch = (id + ":" + name) == epocDeviceValue; if (!alias.isEmpty()) epocDeviceMatch |= alias == epocDeviceValue; epocDeviceFound |= epocDeviceMatch; if((epocDeviceValue.isEmpty() && isDefault) || epocDeviceMatch) { // Found a matching device while (!(xml.isEndElement() && xml.name() == "device") && !xml.atEnd()) { xml.readNext(); if (xml.isStartElement() && xml.name() == "epocroot") { epocRootValue = xml.readElementText(); const QString deviceSource = epocDeviceValue.isEmpty() ? "default device" : "EPOCDEVICE (" + epocDeviceValue + ")"; checkEpocRootExists(deviceSource); } } if (epocRootValue.isEmpty()) xml.raiseError("No epocroot element found"); } } } } else { xml.raiseError("Invalid 'devices' element version"); } } } if (xml.hasError()) { std::cerr << "Error: \"" << xml.errorString() << "\" when parsing devices.xml" << std::endl; } else { if (epocRootValue.isEmpty()) { if (!epocDeviceValue.isEmpty()) { if (epocDeviceFound) { std::cerr << "Error: missing or invalid epocroot attribute " << "in device '" << epocDeviceValue << "'"; } else { std::cerr << "Error: no device matching EPOCDEVICE (" << epocDeviceValue << ")"; } } else { if (epocDeviceFound) { std::cerr << "Error: missing or invalid epocroot attribute " << "in default device"; } else { std::cerr << "Error: no default device"; } } std::cerr << " found in devices.xml file." << std::endl; } } } else { std::cerr << "Error: could not open file " << devicesXmlPath << std::endl; } } } if (epocRootValue.isEmpty()) { // 5. An empty string is returned. std::cerr << "Error: failed to find epoc root" << std::endl << "Either" << std::endl << " 1. Set EPOCROOT environment variable to a valid value" << std::endl << " or 2. Ensure that the HKEY_LOCAL_MACHINE\\" SYMBIAN_SDKS_REG_SUBKEY " registry key is set, and then" << std::endl << " a. Set EPOCDEVICE environment variable to a valid device" << std::endl << " or b. Specify a default device in the devices.xml file." << std::endl; } else { fixEpocRoot(epocRootValue); } } return epocRootValue; }