From d1542c4db8a3f2289561c9016cdd39ee585d8553 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 30 Aug 2020 12:39:24 +1000 Subject: [PATCH] Show the time APK was last updated for build time in updates menu for android version --- .../java/com/classicube/MainActivity.java | 14 +++++++++++++ src/Platform.c | 20 ++++++++++++++++++- src/Platform.h | 6 ++++-- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/android/app/src/main/java/com/classicube/MainActivity.java b/android/app/src/main/java/com/classicube/MainActivity.java index 06bd76873..2656cd35d 100644 --- a/android/app/src/main/java/com/classicube/MainActivity.java +++ b/android/app/src/main/java/com/classicube/MainActivity.java @@ -1,4 +1,5 @@ package com.classicube; +import java.io.File; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; @@ -14,6 +15,7 @@ import android.content.Context; import android.content.ClipboardManager; import android.content.DialogInterface; import android.content.Intent; +import android.content.pm.ApplicationInfo; import android.content.res.Configuration; import android.graphics.PixelFormat; import android.net.Uri; @@ -390,6 +392,18 @@ public class MainActivity extends Activity implements SurfaceHolder.Callback2 { public String getExternalAppDir() { return getExternalFilesDir(null).getAbsolutePath(); } + + public long getApkUpdateTime() { + try { + //String name = getPackageName(); + //ApplicationInfo info = getPackageManager().getApplicationInfo(name, 0); + ApplicationInfo info = getApplicationInfo(); + File apkFile = new File(info.sourceDir); + return apkFile.lastModified(); + } catch (Exception ex) { + return 0; + } + } // ====================================== // --------------- WINDOW --------------- diff --git a/src/Platform.c b/src/Platform.c index 756c1b60f..617894cb4 100644 --- a/src/Platform.c +++ b/src/Platform.c @@ -1298,9 +1298,22 @@ cc_result Updater_SetNewBuildTime(cc_uint64 timestamp) { const char* const Updater_D3D9 = NULL; const char* const Updater_OGL = NULL; +#if defined CC_BUILD_WEB +cc_result Updater_GetBuildTime(cc_uint64* t) { return ERR_NOT_SUPPORTED; } +#else +cc_result Updater_GetBuildTime(cc_uint64* t) { + JNIEnv* env; + JavaGetCurrentEnv(env); + + /* https://developer.android.com/reference/java/io/File#lastModified() */ + /* lastModified is returned in milliseconds */ + *t = JavaCallLong(env, "getApkUpdateTime", "()J", NULL) / 1000; + return 0; +} +#endif + cc_bool Updater_Clean(void) { return true; } cc_result Updater_Start(void) { return ERR_NOT_SUPPORTED; } -cc_result Updater_GetBuildTime(cc_uint64* t) { return ERR_NOT_SUPPORTED; } cc_result Updater_MarkExecutable(void) { return 0; } cc_result Updater_SetNewBuildTime(cc_uint64 t) { return ERR_NOT_SUPPORTED; } #elif defined CC_BUILD_POSIX @@ -1900,6 +1913,11 @@ jint JavaCallInt(JNIEnv* env, const char* name, const char* sig, jvalue* args) { return (*env)->CallIntMethodA(env, App_Instance, method, args); } +jlong JavaCallLong(JNIEnv* env, const char* name, const char* sig, jvalue* args) { + jmethodID method = (*env)->GetMethodID(env, App_Class, name, sig); + return (*env)->CallLongMethodA(env, App_Instance, method, args); +} + jfloat JavaCallFloat(JNIEnv* env, const char* name, const char* sig, jvalue* args) { jmethodID method = (*env)->GetMethodID(env, App_Class, name, sig); return (*env)->CallFloatMethodA(env, App_Instance, method, args); diff --git a/src/Platform.h b/src/Platform.h index cf7e9f6a7..c7ea39456 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -245,9 +245,11 @@ jobject JavaMakeString(JNIEnv* env, const String* str); /* Allocates a java byte array from the given block of memory. */ jbyteArray JavaMakeBytes(JNIEnv* env, const cc_uint8* src, cc_uint32 len); /* Calls a method in the activity class that returns nothing. */ -void JavaCallVoid(JNIEnv* env, const char* name, const char* sig, jvalue* args); +void JavaCallVoid(JNIEnv* env, const char* name, const char* sig, jvalue* args); /* Calls a method in the activity class that returns a jint. */ -jint JavaCallInt(JNIEnv* env, const char* name, const char* sig, jvalue* args); +jint JavaCallInt(JNIEnv* env, const char* name, const char* sig, jvalue* args); +/* Calls a method in the activity class that returns a jint. */ +jlong JavaCallLong(JNIEnv* env, const char* name, const char* sig, jvalue* args); /* Calls a method in the activity class that returns a jint. */ jfloat JavaCallFloat(JNIEnv* env, const char* name, const char* sig, jvalue* args); /* Calls a method in the activity class that returns a jobject. */