mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 18:13:05 +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/QDebug>
|
||||||
|
#include <QtCore/QDir>
|
||||||
|
#include <QtCore/QFile>
|
||||||
#include <QtCore/QThread>
|
#include <QtCore/QThread>
|
||||||
|
#include <QtCore/QStringList>
|
||||||
|
#include <QtCore/QStandardPaths>
|
||||||
|
#include <QtCore/QTextStream>
|
||||||
|
|
||||||
#include <QtAndroidExtras/QAndroidJniObject>
|
#include <QtAndroidExtras/QAndroidJniObject>
|
||||||
|
|
||||||
#include <android/log.h>
|
#include <android/log.h>
|
||||||
#include <android/asset_manager.h>
|
#include <android/asset_manager.h>
|
||||||
#include <android/asset_manager_jni.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" {
|
extern "C" {
|
||||||
|
|
||||||
JNIEXPORT void Java_io_highfidelity_hifiinterface_InterfaceActivity_nativeOnCreate(JNIEnv* env, jobject obj, jobject instance, jobject asset_mgr) {
|
JNIEXPORT void Java_io_highfidelity_hifiinterface_InterfaceActivity_nativeOnCreate(JNIEnv* env, jobject obj, jobject instance, jobject asset_mgr) {
|
||||||
qDebug() << "nativeOnCreate On thread " << QThread::currentThreadId();
|
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) {
|
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->setObjectName("ChromiumShareContext");
|
||||||
_chromiumShareContext->create(_glWidget->qglContext());
|
_chromiumShareContext->create(_glWidget->qglContext());
|
||||||
_chromiumShareContext->makeCurrent();
|
_chromiumShareContext->makeCurrent();
|
||||||
if (nsightActive()) {
|
qt_gl_set_global_share_context(_chromiumShareContext->getContext());
|
||||||
qt_gl_set_global_share_context(_chromiumShareContext->getContext());
|
|
||||||
}
|
|
||||||
|
|
||||||
_glWidget->makeCurrent();
|
_glWidget->makeCurrent();
|
||||||
gpu::Context::init<gpu::gl::GLBackend>();
|
gpu::Context::init<gpu::gl::GLBackend>();
|
||||||
|
@ -2342,11 +2340,7 @@ void Application::initializeUi() {
|
||||||
offscreenUi->setProxyWindow(_window->windowHandle());
|
offscreenUi->setProxyWindow(_window->windowHandle());
|
||||||
// OffscreenUi is a subclass of OffscreenQmlSurface specifically designed to
|
// OffscreenUi is a subclass of OffscreenQmlSurface specifically designed to
|
||||||
// support the window management and scripting proxies for VR use
|
// support the window management and scripting proxies for VR use
|
||||||
#ifdef Q_OS_ANDROID
|
|
||||||
offscreenUi->createDesktop(PathUtils::qmlBasePath() + "hifi/Desktop.qml");
|
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
|
// FIXME either expose so that dialogs can set this themselves or
|
||||||
// do better detection in the offscreen UI of what has focus
|
// do better detection in the offscreen UI of what has focus
|
||||||
offscreenUi->setNavigationFocused(false);
|
offscreenUi->setNavigationFocused(false);
|
||||||
|
|
|
@ -31,10 +31,6 @@
|
||||||
#include "UserActivityLogger.h"
|
#include "UserActivityLogger.h"
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
|
|
||||||
#if defined(Q_OS_ANDROID)
|
|
||||||
#include <android/log.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAS_BUGSPLAT
|
#ifdef HAS_BUGSPLAT
|
||||||
#include <BugSplat.h>
|
#include <BugSplat.h>
|
||||||
#include <CrashReporter.h>
|
#include <CrashReporter.h>
|
||||||
|
@ -46,90 +42,6 @@ extern "C" {
|
||||||
}
|
}
|
||||||
#endif
|
#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[]) {
|
int main(int argc, const char* argv[]) {
|
||||||
#if HAS_BUGSPLAT
|
#if HAS_BUGSPLAT
|
||||||
static QString BUG_SPLAT_DATABASE = "interface_alpha";
|
static QString BUG_SPLAT_DATABASE = "interface_alpha";
|
||||||
|
@ -193,12 +105,6 @@ int main(int argc, const char* argv[]) {
|
||||||
if (allowMultipleInstances) {
|
if (allowMultipleInstances) {
|
||||||
instanceMightBeRunning = false;
|
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
|
// this needs to be done here in main, as the mechanism for setting the
|
||||||
// scripts directory appears not to work. See the bug report
|
// scripts directory appears not to work. See the bug report
|
||||||
// https://highfidelity.fogbugz.com/f/cases/5759/Issues-changing-scripts-directory-in-ScriptsEngine
|
// https://highfidelity.fogbugz.com/f/cases/5759/Issues-changing-scripts-directory-in-ScriptsEngine
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
#define hifi_OffscreenQmlElement_h
|
#define hifi_OffscreenQmlElement_h
|
||||||
|
|
||||||
#include <QQuickItem>
|
#include <QQuickItem>
|
||||||
|
|
||||||
|
#include <PathUtils.h>
|
||||||
class QQmlContext;
|
class QQmlContext;
|
||||||
|
|
||||||
#define HIFI_QML_DECL \
|
#define HIFI_QML_DECL \
|
||||||
|
@ -40,7 +42,7 @@ public: \
|
||||||
private:
|
private:
|
||||||
|
|
||||||
#define HIFI_QML_DEF(x) \
|
#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; \
|
const QString x::NAME = #x; \
|
||||||
\
|
\
|
||||||
void x::registerType() { \
|
void x::registerType() { \
|
||||||
|
|
|
@ -548,6 +548,7 @@ void OffscreenQmlSurface::render() {
|
||||||
|
|
||||||
PROFILE_RANGE(render_qml_gl, __FUNCTION__)
|
PROFILE_RANGE(render_qml_gl, __FUNCTION__)
|
||||||
_canvas->makeCurrent();
|
_canvas->makeCurrent();
|
||||||
|
|
||||||
_renderControl->sync();
|
_renderControl->sync();
|
||||||
_quickWindow->setRenderTarget(_fbo, QSize(_size.x, _size.y));
|
_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;
|
QQmlContext* targetContext = parent ? QQmlEngine::contextForObject(parent) : _qmlContext;
|
||||||
if (!targetContext) {
|
if (!targetContext) {
|
||||||
targetContext = _qmlContext;
|
targetContext = _qmlContext;
|
||||||
}
|
}
|
||||||
if (_rootItem && forceNewContext) {
|
if (_rootItem && forceNewContext) {
|
||||||
targetContext = new QQmlContext(targetContext);
|
targetContext = new QQmlContext(targetContext);
|
||||||
|
|
Loading…
Reference in a new issue