aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/android/androiddevice.cpp
diff options
context:
space:
mode:
authorJarek Kobus <[email protected]>2024-05-13 19:15:13 +0200
committerJarek Kobus <[email protected]>2024-05-16 09:56:06 +0000
commitbee7cdfd1ecfdc6bf27310e500647d321929f5b6 (patch)
tree951a9215e3d519f6af751902d30c9ff91a345d10 /src/plugins/android/androiddevice.cpp
parent46fb01f785fc2fc7111b7870400768047d89be09 (diff)
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 <[email protected]>
Diffstat (limited to 'src/plugins/android/androiddevice.cpp')
-rw-r--r--src/plugins/android/androiddevice.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/plugins/android/androiddevice.cpp b/src/plugins/android/androiddevice.cpp
index 0242fdeded9..25ea819a422 100644
--- a/src/plugins/android/androiddevice.cpp
+++ b/src/plugins/android/androiddevice.cpp
@@ -441,6 +441,50 @@ void AndroidDeviceManager::updateDeviceState(const ProjectExplorer::IDevice::Con
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)
{
Q_UNUSED(parent)