Show the time APK was last updated for build time in updates menu for android version

This commit is contained in:
UnknownShadow200 2020-08-30 12:39:24 +10:00
parent 1da8872217
commit d1542c4db8
3 changed files with 37 additions and 3 deletions

View file

@ -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 ---------------

View file

@ -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);

View file

@ -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. */