void AndroidSettingsWidget::browseSDKLocation()
{
    Utils::FileName dir = Utils::FileName::fromString(QFileDialog::getExistingDirectory(this, tr("Select Android SDK folder")));
    if (!checkSDK(dir))
        return;
    m_ui->SDKLocationLineEdit->setText(dir.toUserOutput());
    sdkLocationEditingFinished();
}
void AndroidSettingsWidget::sdkLocationEditingFinished()
{
    Utils::FileName location = Utils::FileName::fromUserInput(m_ui->SDKLocationLineEdit->text());
    if (!checkSDK(location)) {
        m_ui->AVDManagerFrame->setEnabled(false);
        return;
    }
    m_androidConfig.sdkLocation = location;
    saveSettings(true);
    m_AVDModel.setAvdList(AndroidConfigurations::instance().androidVirtualDevices());
    m_ui->AVDManagerFrame->setEnabled(true);
}
void AndroidSettingsWidget::initGui()
{
    m_ui->setupUi(this);
    if (checkSDK(m_androidConfig.sdkLocation))
        m_ui->SDKLocationLineEdit->setText(m_androidConfig.sdkLocation.toUserOutput());
    else
        m_androidConfig.sdkLocation.clear();
    if (checkNDK(m_androidConfig.ndkLocation))
        m_ui->NDKLocationLineEdit->setText(m_androidConfig.ndkLocation.toUserOutput());
    else
        m_androidConfig.ndkLocation.clear();
    m_ui->AntLocationLineEdit->setText(m_androidConfig.antLocation.toUserOutput());
    m_ui->OpenJDKLocationLineEdit->setText(m_androidConfig.openJDKLocation.toUserOutput());
    m_ui->DataPartitionSizeSpinBox->setValue(m_androidConfig.partitionSize);
    m_ui->CreateKitCheckBox->setChecked(m_androidConfig.automaticKitCreation);
    m_ui->AVDTableView->setModel(&m_AVDModel);
    m_AVDModel.setAvdList(AndroidConfigurations::instance().androidVirtualDevices());
    m_ui->AVDTableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
    m_ui->AVDTableView->horizontalHeader()->setResizeMode(1, QHeaderView::ResizeToContents);
}
Beispiel #4
0
int main(int argc, char *argv[])
{
    QCoreApplication::setOrganizationName("Bracia");
    QCoreApplication::setApplicationName("QtADB");
    QCoreApplication::setApplicationVersion("0.8.94_cwm_edition");
    QCoreApplication::setOrganizationDomain("http://qtadb.com");
    Application a(argc, argv);
    QPixmap pixmap(":icons/splash.png");
    QSplashScreen splash(pixmap);
    splash.setMask(pixmap.mask());
    splash.show();
    qInstallMsgHandler(myMessageHandler);
    a.loadTranslations(":/lang");
    a.loadTranslations(qApp->applicationDirPath());
    a.setQuitOnLastWindowClosed(true);
    qDebug()<<"app version: "<<QCoreApplication::applicationVersion();
#ifdef Q_WS_WIN
    switch(QSysInfo::windowsVersion())
    {
    case QSysInfo::WV_XP:qDebug()<<"system: Windows XP "<<QProcessEnvironment::systemEnvironment().value("PROCESSOR_ARCHITECTURE");
        break;
    case QSysInfo::WV_VISTA:qDebug()<<"system: Windows Vista "<<QProcessEnvironment::systemEnvironment().value("PROCESSOR_ARCHITECTURE");
        break;
    case QSysInfo::WV_WINDOWS7:qDebug()<<"system: Windows 7 "<<QProcessEnvironment::systemEnvironment().value("PROCESSOR_ARCHITECTURE");
        break;
    default:
        qDebug()<<"system: "<<QSysInfo::windowsVersion()<<" "<<QProcessEnvironment::systemEnvironment().value("PROCESSOR_ARCHITECTURE");
    }
#endif
//    qDebug()<<"system: "<<QSysInfo::windowsVersion();
//    qDebug()<<"bits: "<<QSysInfo::WordSize;
    QSettings settings;
    QString sdk;
    sdk = settings.value("sdkPath").toString();

    QString locale = QLocale::system().name().left(2);

    QString lang = settings.value("Language", locale).toString();
    bool langSet = false;

    if (!Application::availableLanguagesRes().contains(lang))
        lang = "en";
    foreach (QString avail, Application::availableLanguagesRes())
    {
        if (avail == lang)
        {
            langSet = true;
            Application::setLanguage(lang, "res");
        }
    }

    foreach (QString avail, Application::availableLanguagesDir())
    {
        if ((avail == lang) && (langSet == false))
        {
            Application::setLanguage(lang, "dir");
        }
    }

    bool sdkOk = false;
    do{
        QString tmp;
        if (sdk.isEmpty())
        {
            QDir checkSDK(QDir::currentPath());
            QFileInfoList list=checkSDK.entryInfoList();
            while(list.length()>0)
            {
                tmp = list.takeFirst().fileName();
                if (tmp.contains("adb"))
                {
                    sdk = QDir::currentPath();
                    sdk.append("/");
                    sdkOk=true;
                    break;
                }
            }
        }
        if (sdk.isEmpty())
        {
            sdk=QFileDialog::getExistingDirectory(NULL,QObject::tr("Choose path to dir with adb and aapt binaries"),"/");
            if (!sdk.isEmpty())
                sdk.append("/");
        }
        if (!sdk.isEmpty())
        {
            QDir checkSDK(sdk);
            QFileInfoList list=checkSDK.entryInfoList();
            while(list.length()>0)
            {
                tmp = list.takeFirst().fileName();
                if (tmp.contains("adb"))
                {
                    sdkOk=true;
                    break;
                }
            }
        }
        if (!sdkOk)
        {
            sdk.clear();
            QMessageBox *msgBox = new QMessageBox(QMessageBox::Critical, QObject::tr("Error:"), QObject::tr("There is no adb binary in here!"));
            QPushButton *choosePathMsg = msgBox->addButton(QObject::tr("Choose path"), QMessageBox::AcceptRole);
            QPushButton *closeMsg = msgBox->addButton(QObject::tr("Close"), QMessageBox::RejectRole);

            msgBox->exec();

            if (msgBox->clickedButton() == choosePathMsg)
            {
                continue;
            }
            else
            {
                break;
            }
            delete closeMsg;
            delete choosePathMsg;
            delete msgBox;
        }
        else break;
    }while(true);
    if (sdkOk){
        settings.setValue("sdkPath", sdk);
        QProcess proces;
//        adbd cannot run as root in production builds
        proces.setProcessChannelMode(QProcess::MergedChannels);
        proces.start("\"" + sdk + "\"adb version");
        proces.waitForFinished(-1);
        QString tmp = proces.readAll();
        qDebug()<<"adb version - "<<tmp;
        if (proces.exitCode() != 0)
        {
            qDebug()<<"adb error - "<<proces.errorString();
            QMessageBox *msgBox = new QMessageBox(QMessageBox::Critical, QObject::tr("Error:"), QObject::tr("It seems that adb is not working properly!"), QMessageBox::Ok);
            msgBox->exec();
            delete msgBox;
            return 1;
        }
//        adbd cannot run as root in production builds
        proces.setProcessChannelMode(QProcess::MergedChannels);
        proces.start("\"" + sdk + "\"adb root");
        proces.waitForFinished(-1);
        tmp = proces.readAll();
        qDebug()<<"adb root - "<<tmp;

        if (tmp.contains("adbd cannot run as root in production builds") && !settings.value("disableProductionBuildsMessage",false).toBool())
        {
            QMessageBox *msgBox2 = new QMessageBox(QMessageBox::Critical, QObject::tr("Error:"),
                                                   QObject::tr("adbd cannot run as root in production builds so you can't do anything with /system/ partition. Run anyway?\n(press save to run QtADB and disable this message.)"),
                                                   QMessageBox::Yes | QMessageBox::No | QMessageBox::Save);
            int button = msgBox2->exec();
            if ( button == QMessageBox::No)
            {
                delete msgBox2;
                return 0;
            }
            if ( button == QMessageBox::Save)
            {
                settings.setValue("disableProductionBuildsMessage",true);
            }
        }
        //        QtADB run with limited functionality, ro
                proces.setProcessChannelMode(QProcess::MergedChannels);
                proces.start("\"" + sdk + "\"adb shell su -c 'getprop ro.secure'");
                proces.waitForFinished(-1);
                tmp = proces.readLine();
                if (tmp.contains("su: not found"))
                {
                    proces.start("\"" + sdk + "\"adb shell getprop ro.secure");
                    proces.waitForFinished(-1);
                    tmp = proces.readLine();
                }
                if (tmp.contains("1") && !settings.value("disableSecureModeMessage",false).toBool())
                {
                    QMessageBox *msgBox2 = new QMessageBox(QMessageBox::Information, QObject::tr("Secure Mode:"),
                                                           QObject::tr("adbd runs in Secure Mode on this phone.\nYou need to install new kernel with \"ro.secure\" property set to \"0\". Till then QtADB will have very limited functionality.\n\nRun anyway?\n(press save to run QtADB and disable this message.)"),
                                                           QMessageBox::Yes | QMessageBox::No | QMessageBox::Save);
                    int button = msgBox2->exec();
                    if ( button == QMessageBox::No)
                    {
                        delete msgBox2;
                        return 0;
                    }
                    if ( button == QMessageBox::Save)
                    {
                        settings.setValue("disableSecureModeMessage",true);
                    }
                    qDebug()<<"getprop ro.secure - "<<tmp;
                }
        QStringList args = qApp->arguments();
        if (args.count() > 1)
        {
            QDir dir;
            if (args.at(1).endsWith(".apk"))
            {
                App *app = NULL;
                app = FileWidget::getAppInfo(args.at(1));
                appInfo *appInfoDialog = new appInfo(app);
                dir.rmdir(QDir::currentPath()+"/tmp/");
                return appInfoDialog->exec();
            }
            if (args.at(1) == "-install")
            {
                QList<App> appList;
                App *app = NULL;
                for (int i = 2; i < args.count(); i++)
                {
                    if (args.at(i).endsWith(".apk"))
                    {
                        QString fileName = args.at(i);
                        app = FileWidget::getAppInfo(fileName);
                        if (app != NULL)
                            appList.append(*app);
                    }
                }
                dir.rmdir(QDir::currentPath()+"/tmp/");
                appDialog *appDialogInstall = new appDialog(appList, appDialog::Install, appDialog::None);
                return appDialogInstall->exec();
            }
            else if (args.at(1) == "-logcat")
            {
                LogcatDialog *logcat = new LogcatDialog;
                return logcat->exec();
            }
        }
        MainWindow w;
        w.show();

        splash.finish(&w);

        return a.exec();
    }
    else{
        return 0;
    }
}