Exemplo n.º 1
0
MainWindow::MainWindow(mbp::PatcherConfig *pc, QWidget *parent)
    : QWidget(parent), d_ptr(new MainWindowPrivate())
{
    Q_D(MainWindow);

    setWindowIcon(QIcon(QStringLiteral(":/icons/icon.png")));
    setWindowTitle(qApp->applicationName());

    // If we're passed an argument, switch to automatic mode
    if (qApp->arguments().size() > 2) {
        d->autoMode = true;
        d->fileName = qApp->arguments().at(1);
    } else {
        d->autoMode = false;
        d->fileName.clear();
    }

    d->pc = pc;

    addWidgets();
    setWidgetActions();
    populateDevices();
    populateInstallationLocations();
    updateWidgetsVisibility();

    QString lastDeviceId = d->settings.value(
            QStringLiteral("last_device"), QString()).toString();
    for (size_t i = 0; i < d->devices.size(); ++i) {
        if (strcmp(mb_device_id(d->devices[i].get()),
                   lastDeviceId.toUtf8().data()) == 0) {
            d->deviceSel->setCurrentIndex(i);
            break;
        }
    }

    // Create thread
    d->thread = new QThread(this);
    d->task = new PatcherTask();
    d->task->moveToThread(d->thread);

    connect(d->thread, &QThread::finished,
            d->task, &QObject::deleteLater);
    connect(this, &MainWindow::runThread,
            d->task, &PatcherTask::patch);
    connect(d->task, &PatcherTask::finished,
            this, &MainWindow::onPatchingFinished);
    connect(d->task, &PatcherTask::progressUpdated,
            this, &MainWindow::onProgressUpdated);
    connect(d->task, &PatcherTask::filesUpdated,
            this, &MainWindow::onFilesUpdated);
    connect(d->task, &PatcherTask::detailsUpdated,
            this, &MainWindow::onDetailsUpdated);

    d->thread->start();
}
Exemplo n.º 2
0
void MainWindow::closeEvent(QCloseEvent *event)
{
    Q_D(MainWindow);

    if (!d->devices.empty()) {
        int deviceIndex = d->deviceSel->currentIndex();
        const char *id = mb_device_id(d->devices[deviceIndex].get());
        d->settings.setValue(QStringLiteral("last_device"),
                             QString::fromUtf8(id));
    }

    QWidget::closeEvent(event);
}
Exemplo n.º 3
0
void MainWindow::populateDevices()
{
    Q_D(MainWindow);

    // TODO: This shouldn't be done in the GUI thread
    QString path(QString::fromStdString(d->pc->dataDirectory())
            % QStringLiteral("/devices.json"));
    QFile file(path);

    if (file.open(QIODevice::ReadOnly)) {
        QByteArray contents = file.readAll();
        file.close();

        MbDeviceJsonError error;
        Device **devices =
                mb_device_new_list_from_json(contents.data(), &error);

        if (devices) {
            for (Device **iter = devices; *iter; ++iter) {
                if (mb_device_validate(*iter) == 0) {
                    d->deviceSel->addItem(QStringLiteral("%1 - %2")
                            .arg(QString::fromUtf8(mb_device_id(*iter)))
                            .arg(QString::fromUtf8(mb_device_name(*iter))));
                    d->devices.emplace_back(*iter, mb_device_free);
                } else {
                    // Clean up unusable devices
                    mb_device_free(*iter);
                }
            }
            // No need for array anymore
            free(devices);
        } else {
            qWarning("Failed to load devices");
        }
    } else {
        qWarning("%s: Failed to open file: %s",
                 path.toUtf8().data(), file.errorString().toUtf8().data());
    }
}
Exemplo n.º 4
0
TEST(JsonTest, LoadCompleteDefinition)
{
    ScopedDevice sd(sample_complete);

    ASSERT_NE(sd.device, nullptr);

    ASSERT_STREQ(mb_device_id(sd.device), "test");

    const char *codenames[] = { "test1", "test2", "test3", "test4", nullptr };
    ASSERT_TRUE(string_array_eq(mb_device_codenames(sd.device), codenames));

    ASSERT_STREQ(mb_device_name(sd.device), "Test Device");
    ASSERT_STREQ(mb_device_architecture(sd.device), "arm64-v8a");

    uint64_t device_flags = FLAG_HAS_COMBINED_BOOT_AND_RECOVERY;
    ASSERT_EQ(mb_device_flags(sd.device), device_flags);

    const char *base_dirs[] = { "/dev/block/bootdevice/by-name", nullptr };
    ASSERT_TRUE(string_array_eq(mb_device_block_dev_base_dirs(sd.device), base_dirs));

    const char *system_devs[] = {
        "/dev/block/bootdevice/by-name/system",
        "/dev/block/sda1",
        nullptr
    };
    ASSERT_TRUE(string_array_eq(mb_device_system_block_devs(sd.device), system_devs));

    const char *cache_devs[] = {
        "/dev/block/bootdevice/by-name/cache",
        "/dev/block/sda2",
        nullptr
    };
    ASSERT_TRUE(string_array_eq(mb_device_cache_block_devs(sd.device), cache_devs));

    const char *data_devs[] = {
        "/dev/block/bootdevice/by-name/userdata",
        "/dev/block/sda3",
        nullptr
    };
    ASSERT_TRUE(string_array_eq(mb_device_data_block_devs(sd.device), data_devs));

    const char *boot_devs[] = {
        "/dev/block/bootdevice/by-name/boot",
        "/dev/block/sda4",
        nullptr
    };
    ASSERT_TRUE(string_array_eq(mb_device_boot_block_devs(sd.device), boot_devs));

    const char *recovery_devs[] = {
        "/dev/block/bootdevice/by-name/recovery",
        "/dev/block/sda5",
        nullptr
    };
    ASSERT_TRUE(string_array_eq(mb_device_recovery_block_devs(sd.device), recovery_devs));

    const char *extra_devs[] = {
        "/dev/block/bootdevice/by-name/modem",
        "/dev/block/sda6",
        nullptr
    };
    ASSERT_TRUE(string_array_eq(mb_device_extra_block_devs(sd.device), extra_devs));

    /* Boot UI */

    ASSERT_EQ(mb_device_tw_supported(sd.device), true);

    uint64_t flags =
            FLAG_TW_TOUCHSCREEN_SWAP_XY
            | FLAG_TW_TOUCHSCREEN_FLIP_X
            | FLAG_TW_TOUCHSCREEN_FLIP_Y
            | FLAG_TW_GRAPHICS_FORCE_USE_LINELENGTH
            | FLAG_TW_SCREEN_BLANK_ON_BOOT
            | FLAG_TW_BOARD_HAS_FLIPPED_SCREEN
            | FLAG_TW_IGNORE_MAJOR_AXIS_0
            | FLAG_TW_IGNORE_MT_POSITION_0
            | FLAG_TW_IGNORE_ABS_MT_TRACKING_ID
            | FLAG_TW_NEW_ION_HEAP
            | FLAG_TW_NO_SCREEN_BLANK
            | FLAG_TW_NO_SCREEN_TIMEOUT
            | FLAG_TW_ROUND_SCREEN
            | FLAG_TW_NO_CPU_TEMP
            | FLAG_TW_QCOM_RTC_FIX
            | FLAG_TW_HAS_DOWNLOAD_MODE
            | FLAG_TW_PREFER_LCD_BACKLIGHT;
    ASSERT_EQ(mb_device_tw_flags(sd.device), flags);

    ASSERT_EQ(mb_device_tw_pixel_format(sd.device), TW_PIXEL_FORMAT_RGBA_8888);
    ASSERT_EQ(mb_device_tw_force_pixel_format(sd.device), TW_FORCE_PIXEL_FORMAT_RGB_565);
    ASSERT_EQ(mb_device_tw_overscan_percent(sd.device), 10);
    ASSERT_EQ(mb_device_tw_default_x_offset(sd.device), 20);
    ASSERT_EQ(mb_device_tw_default_y_offset(sd.device), 30);
    ASSERT_STREQ(mb_device_tw_brightness_path(sd.device), "/sys/class/backlight");
    ASSERT_STREQ(mb_device_tw_secondary_brightness_path(sd.device), "/sys/class/lcd-backlight");
    ASSERT_EQ(mb_device_tw_max_brightness(sd.device), 255);
    ASSERT_EQ(mb_device_tw_default_brightness(sd.device), 100);
    ASSERT_STREQ(mb_device_tw_battery_path(sd.device), "/sys/class/battery");
    ASSERT_STREQ(mb_device_tw_cpu_temp_path(sd.device), "/sys/class/cputemp");
    ASSERT_STREQ(mb_device_tw_input_blacklist(sd.device), "foo");
    ASSERT_STREQ(mb_device_tw_input_whitelist(sd.device), "bar");

    const char *graphics_backends[] = {
        "overlay_msm_old",
        "fbdev",
        nullptr
    };
    ASSERT_TRUE(string_array_eq(mb_device_tw_graphics_backends(sd.device), graphics_backends));

    ASSERT_STREQ(mb_device_tw_theme(sd.device), "portrait_hdpi");
}