forked from qt-creator/qt-creator
Android: Add AndroidDeviceManager::createAvd()
The createAvd() command is going to turn off the avd file system watcher during execution, so this needs to be a part of AndroidDeviceManager. Change-Id: Ic8038be53d2be34136649b6b8a44435a4fc87a9f Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -441,6 +441,50 @@ void AndroidDeviceManager::updateDeviceState(const ProjectExplorer::IDevice::Con
|
|||||||
devMgr->setDeviceState(id, IDevice::DeviceConnected);
|
devMgr->setDeviceState(id, IDevice::DeviceConnected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
expected_str<void> AndroidDeviceManager::createAvd(const CreateAvdInfo &info, bool force)
|
||||||
|
{
|
||||||
|
CommandLine cmd(androidConfig().avdManagerToolPath(), {"create", "avd", "-n", info.name});
|
||||||
|
cmd.addArgs({"-k", info.sdkStylePath});
|
||||||
|
if (info.sdcardSize > 0)
|
||||||
|
cmd.addArgs({"-c", QString("%1M").arg(info.sdcardSize)});
|
||||||
|
|
||||||
|
const QString deviceDef = info.deviceDefinition;
|
||||||
|
if (!deviceDef.isEmpty() && deviceDef != "Custom")
|
||||||
|
cmd.addArgs({"-d", deviceDef});
|
||||||
|
|
||||||
|
if (force)
|
||||||
|
cmd.addArg("-f");
|
||||||
|
|
||||||
|
Process process;
|
||||||
|
process.setProcessMode(ProcessMode::Writer);
|
||||||
|
process.setEnvironment(androidConfig().toolsEnvironment());
|
||||||
|
process.setCommand(cmd);
|
||||||
|
process.setWriteData("yes\n"); // yes to "Do you wish to create a custom hardware profile"
|
||||||
|
|
||||||
|
QByteArray buffer;
|
||||||
|
QObject::connect(&process, &Process::readyReadStandardOutput, &process, [&process, &buffer] {
|
||||||
|
// This interaction is needed only if there is no "-d" arg for the avdmanager command.
|
||||||
|
buffer += process.readAllRawStandardOutput();
|
||||||
|
if (buffer.endsWith(QByteArray("]:"))) {
|
||||||
|
// truncate to last line
|
||||||
|
const int index = buffer.lastIndexOf('\n');
|
||||||
|
if (index != -1)
|
||||||
|
buffer = buffer.mid(index);
|
||||||
|
if (buffer.contains("hw.gpu.enabled"))
|
||||||
|
process.write("yes\n");
|
||||||
|
else
|
||||||
|
process.write("\n");
|
||||||
|
buffer.clear();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
process.runBlocking();
|
||||||
|
if (process.result() != ProcessResult::FinishedWithSuccess)
|
||||||
|
return Utils::make_unexpected(process.exitMessage());
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
void AndroidDeviceManager::startAvd(const ProjectExplorer::IDevice::Ptr &device, QWidget *parent)
|
void AndroidDeviceManager::startAvd(const ProjectExplorer::IDevice::Ptr &device, QWidget *parent)
|
||||||
{
|
{
|
||||||
Q_UNUSED(parent)
|
Q_UNUSED(parent)
|
||||||
|
@@ -78,6 +78,7 @@ public:
|
|||||||
IDevice::DeviceState getDeviceState(const QString &serial, IDevice::MachineType type) const;
|
IDevice::DeviceState getDeviceState(const QString &serial, IDevice::MachineType type) const;
|
||||||
void updateDeviceState(const ProjectExplorer::IDevice::ConstPtr &device);
|
void updateDeviceState(const ProjectExplorer::IDevice::ConstPtr &device);
|
||||||
|
|
||||||
|
Utils::expected_str<void> createAvd(const CreateAvdInfo &info, bool force);
|
||||||
void startAvd(const ProjectExplorer::IDevice::Ptr &device, QWidget *parent = nullptr);
|
void startAvd(const ProjectExplorer::IDevice::Ptr &device, QWidget *parent = nullptr);
|
||||||
void eraseAvd(const ProjectExplorer::IDevice::Ptr &device, QWidget *parent = nullptr);
|
void eraseAvd(const ProjectExplorer::IDevice::Ptr &device, QWidget *parent = nullptr);
|
||||||
void setupWifiForDevice(const ProjectExplorer::IDevice::Ptr &device, QWidget *parent = nullptr);
|
void setupWifiForDevice(const ProjectExplorer::IDevice::Ptr &device, QWidget *parent = nullptr);
|
||||||
|
@@ -131,53 +131,18 @@ int AvdDialog::exec()
|
|||||||
return QDialog::Rejected;
|
return QDialog::Rejected;
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandLine cmd(androidConfig().avdManagerToolPath(), {"create", "avd", "-n", name()});
|
const CreateAvdInfo avdInfo{si->sdkStylePath(), si->apiLevel(), name(), abi(),
|
||||||
cmd.addArgs({"-k", si->sdkStylePath()});
|
deviceDefinition(), sdcardSize()};
|
||||||
if (sdcardSize() > 0)
|
const auto result = AndroidDeviceManager::instance()->createAvd(
|
||||||
cmd.addArgs({"-c", QString("%1M").arg(sdcardSize())});
|
avdInfo, m_overwriteCheckBox->isChecked());
|
||||||
|
if (!result) {
|
||||||
const QString deviceDef = deviceDefinition();
|
|
||||||
if (!deviceDef.isEmpty() && deviceDef != "Custom")
|
|
||||||
cmd.addArgs({"-d", deviceDef});
|
|
||||||
|
|
||||||
if (m_overwriteCheckBox->isChecked())
|
|
||||||
cmd.addArg("-f");
|
|
||||||
|
|
||||||
Process process;
|
|
||||||
process.setProcessMode(ProcessMode::Writer);
|
|
||||||
process.setEnvironment(androidConfig().toolsEnvironment());
|
|
||||||
process.setCommand(cmd);
|
|
||||||
process.setWriteData("yes\n"); // yes to "Do you wish to create a custom hardware profile"
|
|
||||||
|
|
||||||
QByteArray buffer;
|
|
||||||
QObject::connect(&process, &Process::readyReadStandardOutput, &process, [&process, &buffer] {
|
|
||||||
// This interaction is needed only if there is no "-d" arg for the avdmanager command.
|
|
||||||
buffer += process.readAllRawStandardOutput();
|
|
||||||
if (buffer.endsWith(QByteArray("]:"))) {
|
|
||||||
// truncate to last line
|
|
||||||
const int index = buffer.lastIndexOf('\n');
|
|
||||||
if (index != -1)
|
|
||||||
buffer = buffer.mid(index);
|
|
||||||
if (buffer.contains("hw.gpu.enabled"))
|
|
||||||
process.write("yes\n");
|
|
||||||
else
|
|
||||||
process.write("\n");
|
|
||||||
buffer.clear();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
using namespace std::chrono_literals;
|
|
||||||
process.runBlocking(10s, EventLoopMode::On);
|
|
||||||
if (process.result() != ProcessResult::FinishedWithSuccess) {
|
|
||||||
QMessageBox::warning(Core::ICore::dialogParent(), Tr::tr("Create new AVD"),
|
QMessageBox::warning(Core::ICore::dialogParent(), Tr::tr("Create new AVD"),
|
||||||
process.exitMessage());
|
result.error());
|
||||||
return QDialog::Rejected;
|
return QDialog::Rejected;
|
||||||
}
|
}
|
||||||
m_createdAvdInfo = {si->sdkStylePath(), si->apiLevel(), name(), abi(), deviceDef,
|
m_createdAvdInfo = avdInfo;
|
||||||
sdcardSize()};
|
|
||||||
AndroidDeviceManager::instance()->updateAvdsList();
|
AndroidDeviceManager::instance()->updateAvdsList();
|
||||||
}
|
}
|
||||||
|
|
||||||
return execResult;
|
return execResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user