Skip to content

Commit

Permalink
wip droid again
Browse files Browse the repository at this point in the history
  • Loading branch information
Skycoder42 committed Sep 13, 2019
1 parent 1365ab5 commit 8cf0b1d
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .qmake.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ MODULE_VERSION_IMPORT = $${MODULE_VERSION_MAJOR}.$${MODULE_VERSION_MINOR}
MODULE_VERSION = $${MODULE_VERSION_MAJOR}.$${MODULE_VERSION_MINOR}.$${MODULE_VERSION_PATCH}

LOGGING_RULES=qt.autoupdater.*.debug=true

PLAY_CORE_VERSION = 1.6.3
1 change: 0 additions & 1 deletion examples/autoupdaterquick/AndroidDemo/.qmake.conf

This file was deleted.

2 changes: 1 addition & 1 deletion examples/autoupdaterquick/AndroidDemo/AndroidDemo.pro
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ DISTFILES += \
android/build.gradle \
android/res/values/libs.xml

!android_test_build: target.path = $$[QT_INSTALL_EXAMPLES]/autoupdaterquick/QuickUpdater
!android_test_build: target.path = $$[QT_INSTALL_EXAMPLES]/autoupdaterquick/AndroidDemo
!install_ok: INSTALLS += target

android_test_build {
Expand Down
1 change: 1 addition & 0 deletions src/autoupdatercore/autoupdatercore.pro
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ else: SOURCES += adminauthoriser_dummy.cpp
android {
ANDROID_BUNDLED_JAR_DEPENDENCIES = \
jar/QtAutoUpdaterCorePlayStorePlugin.jar
MODULE_DEFINES += "QT_AUTOUPDATER_PLAY_CORE_VERSION=\\\"$$PLAY_CORE_VERSION\\\""
}

load(qt_module)
Expand Down
17 changes: 16 additions & 1 deletion src/jar/jar.pro
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,24 @@ CONFIG += java

DESTDIR = $$MODULE_BASE_OUTDIR/jar

JAVACLASSPATH += $$PWD/src /home/sky/.gradle/caches/transforms-1/files-1.1/core-1.6.3.aar/6425ded82ae8acd2a1c94d6b9f0dc10b/jars/classes.jar
JAVACLASSPATH += $$PWD/src
JAVASOURCES += $$PWD/src/de/skycoder42/qtautoupdater/core/plugin/qplaystore/UpdateHelper.java

# fetch core library dependency
PLAY_CORE_URL = "https://dl.google.com/dl/android/maven2/com/google/android/play/core/$${PLAY_CORE_VERSION}/core-$${PLAY_CORE_VERSION}.aar"

get_core_target.target = core-$${PLAY_CORE_VERSION}.aar
get_core_target.commands = curl -Lo core-$${PLAY_CORE_VERSION}.aar $$shell_quote($$PLAY_CORE_URL)
unzip_core_target.target = core-$${PLAY_CORE_VERSION}/classes.jar
unzip_core_target.depends = $${get_core_target.target}
unzip_core_target.commands = unzip core-$${PLAY_CORE_VERSION}.aar -d core-$${PLAY_CORE_VERSION} && touch $${unzip_core_target.target}
QMAKE_EXTRA_TARGETS += get_core_target unzip_core_target

JAVACLASSPATH += "$$OUT_PWD/core-$${PLAY_CORE_VERSION}/classes.jar"

load(java)
javac.depends += $${unzip_core_target.target}

# install
target.path = $$[QT_INSTALL_PREFIX]/jar
INSTALLS += target
Original file line number Diff line number Diff line change
@@ -1,8 +1,88 @@
package de.skycoder42.qtautoupdater.core.plugin.qplaystore;

import android.content.Context;
import android.content.IntentSender.SendIntentException;

import android.app.Activity;

import com.google.android.play.core.tasks.OnCompleteListener;
import com.google.android.play.core.tasks.OnSuccessListener;
import com.google.android.play.core.tasks.Task;

import com.google.android.play.core.appupdate.AppUpdateInfo;
import com.google.android.play.core.appupdate.AppUpdateManager;
import com.google.android.play.core.appupdate.AppUpdateManagerFactory;

class UpdateHelper
import com.google.android.play.core.install.InstallStateUpdatedListener;
import com.google.android.play.core.install.InstallState;

import com.google.android.play.core.install.model.UpdateAvailability;
import com.google.android.play.core.install.model.AppUpdateType;
import com.google.android.play.core.install.model.InstallStatus;

class UpdateHelper implements InstallStateUpdatedListener
{
private AppUpdateManager _manager;

private native void reportCheckResult(AppUpdateInfo info);
@Override
public native void onStateUpdate(InstallState state);

public UpdateHelper(AppUpdateManager manager) {
_manager = manager;
}

public void startUpdateCheck() {
_manager.getAppUpdateInfo().addOnCompleteListener(new OnCompleteListener<AppUpdateInfo>() {
@Override
public void onComplete(Task<AppUpdateInfo> task) {
if (task.isSuccessful())
reportCheckResult(task.getResult());
else
reportCheckResult(null);
}
});
}

public void resumeStalledUpdate(final int requestCode, final Activity activity) {
_manager.getAppUpdateInfo().addOnSuccessListener(new OnSuccessListener<AppUpdateInfo>() {
@Override
public void onSuccess(AppUpdateInfo info) {
if (info.updateAvailability() == UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS)
triggerUpdate(requestCode, activity, info);
}
});
}

public boolean triggerUpdate(int requestCode, Activity activity, AppUpdateInfo info) {
try {
_manager.startUpdateFlowForResult(info,
AppUpdateType.IMMEDIATE,
activity,
requestCode);
return true;
} catch(SendIntentException e) {
e.printStackTrace();
return false;
}
}

public boolean startUpdate(int requestCode, Activity activity, AppUpdateInfo info) {
try {
_manager.registerListener(this);
_manager.startUpdateFlowForResult(info,
AppUpdateType.FLEXIBLE,
activity,
requestCode);
return true;
} catch(SendIntentException e) {
_manager.unregisterListener(this);
e.printStackTrace();
return false;
}
}

public void completeUpdate() {
_manager.completeUpdate();
}
}
2 changes: 1 addition & 1 deletion src/plugins/updater/qplaystore/qplaystore.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
TARGET = qplaystore

QT = autoupdatercore androidextras autoupdatercore-private
QT = autoupdatercore androidextras autoupdatercore-private androidextras-private

HEADERS += \
qplaystoreupdaterbackend.h \
Expand Down
18 changes: 18 additions & 0 deletions src/plugins/updater/qplaystore/qplaystoreupdaterbackend.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "qplaystoreupdaterbackend.h"
#include <QtAndroidExtras/QtAndroid>
#include <QtAndroidExtras/QAndroidJniExceptionCleaner>
#include <QtAndroidExtras/private/qandroidactivityresultreceiver_p.h>

QPlayStoreUpdaterBackend::QPlayStoreUpdaterBackend(QString &&key, QObject *parent) :
UpdaterBackend{std::move(key), parent}
Expand All @@ -23,6 +24,7 @@ void QPlayStoreUpdaterBackend::abort(bool force)

bool QPlayStoreUpdaterBackend::triggerUpdates(const QList<QtAutoUpdater::UpdateInfo> &infos, bool track)
{
QAndroidActivityResultReceiverPrivate::get(nullptr);
return false;
}

Expand All @@ -43,3 +45,19 @@ bool QPlayStoreUpdaterBackend::initialize()

return true;
}

// ------------- JNI implementations -------------

extern "C" {

JNIEXPORT void JNICALL Java_de_skycoder42_qtautoupdater_core_plugin_qplaystore_UpdateHelper_reportCheckResult(JNIEnv *env, jobject obj, jobject info)
{

}

JNIEXPORT void JNICALL Java_de_skycoder42_qtautoupdater_core_plugin_qplaystore_UpdateHelper_onStateUpdate(JNIEnv *env, jobject obj, jobject state)
{

}

}

0 comments on commit 8cf0b1d

Please sign in to comment.