mirror of
https://github.com/overte-org/overte.git
synced 2025-04-08 07:12:40 +02:00
Cleanup android
This commit is contained in:
parent
fb59a0a56f
commit
b1e95681a9
5 changed files with 99 additions and 104 deletions
|
@ -1,16 +1,106 @@
|
|||
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QFile>
|
||||
#include <QtCore/QThread>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtCore/QStandardPaths>
|
||||
#include <QtCore/QTextStream>
|
||||
|
||||
#include <QtAndroidExtras/QAndroidJniObject>
|
||||
|
||||
#include <android/log.h>
|
||||
#include <android/asset_manager.h>
|
||||
#include <android/asset_manager_jni.h>
|
||||
|
||||
void tempMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString& message) {
|
||||
if (!message.isEmpty()) {
|
||||
const char * local=message.toStdString().c_str();
|
||||
switch (type) {
|
||||
case QtDebugMsg:
|
||||
__android_log_write(ANDROID_LOG_DEBUG,"Interface",local);
|
||||
break;
|
||||
case QtInfoMsg:
|
||||
__android_log_write(ANDROID_LOG_INFO,"Interface",local);
|
||||
break;
|
||||
case QtWarningMsg:
|
||||
__android_log_write(ANDROID_LOG_WARN,"Interface",local);
|
||||
break;
|
||||
case QtCriticalMsg:
|
||||
__android_log_write(ANDROID_LOG_ERROR,"Interface",local);
|
||||
break;
|
||||
case QtFatalMsg:
|
||||
default:
|
||||
__android_log_write(ANDROID_LOG_FATAL,"Interface",local);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void unpackAndroidAssets() {
|
||||
const QString SOURCE_PREFIX { "assets:/" };
|
||||
const QString DEST_PREFIX = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/";
|
||||
QStringList filesToCopy;
|
||||
QString dateStamp;
|
||||
{
|
||||
QFile file("assets:/cache_assets.txt");
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
throw std::runtime_error("Failed to open cache file list");
|
||||
}
|
||||
QTextStream in(&file);
|
||||
dateStamp = DEST_PREFIX + "/" + in.readLine();
|
||||
while (!in.atEnd()) {
|
||||
QString line = in.readLine();
|
||||
filesToCopy << line;
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
qDebug() << "Checking date stamp" << dateStamp;
|
||||
|
||||
if (QFileInfo(dateStamp).exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto rootDir = QDir::root();
|
||||
for (const auto& fileToCopy : filesToCopy) {
|
||||
auto sourceFileName = SOURCE_PREFIX + fileToCopy;
|
||||
auto destFileName = DEST_PREFIX + fileToCopy;
|
||||
auto destFolder = QFileInfo(destFileName).absoluteDir();
|
||||
if (!destFolder.exists()) {
|
||||
qDebug() << "Creating folder" << destFolder.absolutePath();
|
||||
if (!rootDir.mkpath(destFolder.absolutePath())) {
|
||||
throw std::runtime_error("Error creating output path");
|
||||
}
|
||||
}
|
||||
if (QFile::exists(destFileName)) {
|
||||
qDebug() << "Removing old file" << destFileName;
|
||||
if (!QFile::remove(destFileName)) {
|
||||
throw std::runtime_error("Failed to remove existing file");
|
||||
}
|
||||
}
|
||||
|
||||
qDebug() << "Copying from" << sourceFileName << "to" << destFileName;
|
||||
if (!QFile(sourceFileName).copy(destFileName)) {
|
||||
throw std::runtime_error("Failed to unpack cache files");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
qDebug() << "Writing date stamp" << dateStamp;
|
||||
QFile file(dateStamp);
|
||||
if (file.open(QIODevice::ReadWrite)) {
|
||||
QTextStream(&file) << "touch" << endl;
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
JNIEXPORT void Java_io_highfidelity_hifiinterface_InterfaceActivity_nativeOnCreate(JNIEnv* env, jobject obj, jobject instance, jobject asset_mgr) {
|
||||
qDebug() << "nativeOnCreate On thread " << QThread::currentThreadId();
|
||||
auto oldMessageHandler = qInstallMessageHandler(tempMessageHandler);
|
||||
unpackAndroidAssets();
|
||||
qInstallMessageHandler(oldMessageHandler);
|
||||
}
|
||||
|
||||
JNIEXPORT void Java_io_highfidelity_hifiinterface_InterfaceActivity_nativeOnPause(JNIEnv* env, jobject obj) {
|
||||
|
@ -26,3 +116,5 @@ JNIEXPORT void Java_io_highfidelity_hifiinterface_InterfaceActivity_nativeOnExit
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -2206,9 +2206,7 @@ void Application::initializeGL() {
|
|||
_chromiumShareContext->setObjectName("ChromiumShareContext");
|
||||
_chromiumShareContext->create(_glWidget->qglContext());
|
||||
_chromiumShareContext->makeCurrent();
|
||||
if (nsightActive()) {
|
||||
qt_gl_set_global_share_context(_chromiumShareContext->getContext());
|
||||
}
|
||||
qt_gl_set_global_share_context(_chromiumShareContext->getContext());
|
||||
|
||||
_glWidget->makeCurrent();
|
||||
gpu::Context::init<gpu::gl::GLBackend>();
|
||||
|
@ -2342,11 +2340,7 @@ void Application::initializeUi() {
|
|||
offscreenUi->setProxyWindow(_window->windowHandle());
|
||||
// OffscreenUi is a subclass of OffscreenQmlSurface specifically designed to
|
||||
// support the window management and scripting proxies for VR use
|
||||
#ifdef Q_OS_ANDROID
|
||||
offscreenUi->createDesktop(PathUtils::qmlBasePath() + "hifi/Desktop.qml");
|
||||
#else
|
||||
offscreenUi->createDesktop(QString("hifi/Desktop.qml"));
|
||||
#endif
|
||||
// FIXME either expose so that dialogs can set this themselves or
|
||||
// do better detection in the offscreen UI of what has focus
|
||||
offscreenUi->setNavigationFocused(false);
|
||||
|
|
|
@ -31,10 +31,6 @@
|
|||
#include "UserActivityLogger.h"
|
||||
#include "MainWindow.h"
|
||||
|
||||
#if defined(Q_OS_ANDROID)
|
||||
#include <android/log.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAS_BUGSPLAT
|
||||
#include <BugSplat.h>
|
||||
#include <CrashReporter.h>
|
||||
|
@ -46,90 +42,6 @@ extern "C" {
|
|||
}
|
||||
#endif
|
||||
|
||||
#if defined(Q_OS_ANDROID)
|
||||
void tempMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString& message) {
|
||||
if (!message.isEmpty()) {
|
||||
const char * local=message.toStdString().c_str();
|
||||
switch (type) {
|
||||
case QtDebugMsg:
|
||||
__android_log_write(ANDROID_LOG_DEBUG,"Interface",local);
|
||||
break;
|
||||
case QtInfoMsg:
|
||||
__android_log_write(ANDROID_LOG_INFO,"Interface",local);
|
||||
break;
|
||||
case QtWarningMsg:
|
||||
__android_log_write(ANDROID_LOG_WARN,"Interface",local);
|
||||
break;
|
||||
case QtCriticalMsg:
|
||||
__android_log_write(ANDROID_LOG_ERROR,"Interface",local);
|
||||
break;
|
||||
case QtFatalMsg:
|
||||
default:
|
||||
__android_log_write(ANDROID_LOG_FATAL,"Interface",local);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void unpackAndroidAssets() {
|
||||
const QString SOURCE_PREFIX { "assets:/" };
|
||||
const QString DEST_PREFIX = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/";
|
||||
QStringList filesToCopy;
|
||||
QString dateStamp;
|
||||
{
|
||||
QFile file("assets:/cache_assets.txt");
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
throw std::runtime_error("Failed to open cache file list");
|
||||
}
|
||||
QTextStream in(&file);
|
||||
dateStamp = DEST_PREFIX + "/" + in.readLine();
|
||||
while (!in.atEnd()) {
|
||||
QString line = in.readLine();
|
||||
filesToCopy << line;
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
qDebug() << "Checking date stamp" << dateStamp;
|
||||
|
||||
if (QFileInfo(dateStamp).exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto rootDir = QDir::root();
|
||||
for (const auto& fileToCopy : filesToCopy) {
|
||||
auto sourceFileName = SOURCE_PREFIX + fileToCopy;
|
||||
auto destFileName = DEST_PREFIX + fileToCopy;
|
||||
auto destFolder = QFileInfo(destFileName).absoluteDir();
|
||||
if (!destFolder.exists()) {
|
||||
qDebug() << "Creating folder" << destFolder.absolutePath();
|
||||
if (!rootDir.mkpath(destFolder.absolutePath())) {
|
||||
throw std::runtime_error("Error creating output path");
|
||||
}
|
||||
}
|
||||
if (QFile::exists(destFileName)) {
|
||||
qDebug() << "Removing old file" << destFileName;
|
||||
if (!QFile::remove(destFileName)) {
|
||||
throw std::runtime_error("Failed to remove existing file");
|
||||
}
|
||||
}
|
||||
|
||||
qDebug() << "Copying from" << sourceFileName << "to" << destFileName;
|
||||
if (!QFile(sourceFileName).copy(destFileName)) {
|
||||
throw std::runtime_error("Failed to unpack cache files");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
qDebug() << "Writing date stamp" << dateStamp;
|
||||
QFile file(dateStamp);
|
||||
if (file.open(QIODevice::ReadWrite)) {
|
||||
QTextStream(&file) << "touch" << endl;
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
int main(int argc, const char* argv[]) {
|
||||
#if HAS_BUGSPLAT
|
||||
static QString BUG_SPLAT_DATABASE = "interface_alpha";
|
||||
|
@ -193,12 +105,6 @@ int main(int argc, const char* argv[]) {
|
|||
if (allowMultipleInstances) {
|
||||
instanceMightBeRunning = false;
|
||||
}
|
||||
|
||||
#if defined(Q_OS_ANDROID)
|
||||
qInstallMessageHandler(tempMessageHandler);
|
||||
unpackAndroidAssets();
|
||||
#endif
|
||||
|
||||
// this needs to be done here in main, as the mechanism for setting the
|
||||
// scripts directory appears not to work. See the bug report
|
||||
// https://highfidelity.fogbugz.com/f/cases/5759/Issues-changing-scripts-directory-in-ScriptsEngine
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
#define hifi_OffscreenQmlElement_h
|
||||
|
||||
#include <QQuickItem>
|
||||
|
||||
#include <PathUtils.h>
|
||||
class QQmlContext;
|
||||
|
||||
#define HIFI_QML_DECL \
|
||||
|
@ -40,7 +42,7 @@ public: \
|
|||
private:
|
||||
|
||||
#define HIFI_QML_DEF(x) \
|
||||
const QUrl x::QML = QUrl("qrc:///qml/" #x ".qml"); \
|
||||
const QUrl x::QML = QUrl(PathUtils::qmlBasePath() + #x ".qml"); \
|
||||
const QString x::NAME = #x; \
|
||||
\
|
||||
void x::registerType() { \
|
||||
|
|
|
@ -548,6 +548,7 @@ void OffscreenQmlSurface::render() {
|
|||
|
||||
PROFILE_RANGE(render_qml_gl, __FUNCTION__)
|
||||
_canvas->makeCurrent();
|
||||
|
||||
_renderControl->sync();
|
||||
_quickWindow->setRenderTarget(_fbo, QSize(_size.x, _size.y));
|
||||
|
||||
|
@ -840,7 +841,7 @@ QQmlContext* OffscreenQmlSurface::contextForUrl(const QUrl& qmlSource, QQuickIte
|
|||
|
||||
QQmlContext* targetContext = parent ? QQmlEngine::contextForObject(parent) : _qmlContext;
|
||||
if (!targetContext) {
|
||||
targetContext = _qmlContext;
|
||||
targetContext = _qmlContext;
|
||||
}
|
||||
if (_rootItem && forceNewContext) {
|
||||
targetContext = new QQmlContext(targetContext);
|
||||
|
|
Loading…
Reference in a new issue