From 8aefca0bdda8ad06a9ec8b810148c97279d9b62b Mon Sep 17 00:00:00 2001
From: Admin <Dana_Lee1016@126.com>
Date: 星期一, 22 二月 2021 14:57:17 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 lib/src/main/java/com/anyun/exam/lib/Upgrade.java       |    9 +++-
 lib/src/main/cpp/native-lib.h                           |    1 
 lib/src/main/cpp/native-lib.cpp                         |   31 +++++++++++++++
 lib/src/main/cpp/rtk_platform/platform.cpp              |   13 +++++-
 lib/src/main/java/com/anyun/exam/lib/RemoteService.java |    7 +++
 5 files changed, 56 insertions(+), 5 deletions(-)

diff --git a/lib/src/main/cpp/native-lib.cpp b/lib/src/main/cpp/native-lib.cpp
index 6284991..7c14d93 100644
--- a/lib/src/main/cpp/native-lib.cpp
+++ b/lib/src/main/cpp/native-lib.cpp
@@ -288,6 +288,37 @@
     }
 }
 
+void GetUpgrade(int province, int city)
+{
+    JNIEnv *env;
+    bool ready_in_java_env = false;
+
+    if (sg_jvm->GetEnv((void **)&env, JNI_VERSION_1_6) != JNI_OK) {
+        // Attach涓荤嚎绋�
+        if (sg_jvm->AttachCurrentThread(&env, NULL) != JNI_OK) {
+            LOGE("%s: AttachCurrentThread() failed", __FUNCTION__);
+            return;
+        }
+    } else {
+        ready_in_java_env = true;
+    }
+
+    jclass cls = env->GetObjectClass(sg_obj);
+    jmethodID fun = env->GetMethodID(cls, "GetUpgrade", "(II)V");
+
+    env->CallVoidMethod(sg_obj, fun, province, city);
+
+    env->DeleteLocalRef(cls);
+
+    if (!ready_in_java_env) {
+        //Detach涓荤嚎绋�
+        if (sg_jvm->DetachCurrentThread() != JNI_OK) {
+            LOGE("%s: DetachCurrentThread() failed", __FUNCTION__);
+        }
+    }
+}
+
+
 void SendToBluetooth(const uint8_t *data, int length)
 {
     JNIEnv *env;
diff --git a/lib/src/main/cpp/native-lib.h b/lib/src/main/cpp/native-lib.h
index 456f068..0b8d382 100644
--- a/lib/src/main/cpp/native-lib.h
+++ b/lib/src/main/cpp/native-lib.h
@@ -28,6 +28,7 @@
 int PlayTTS(const char *string, void (*callback)(int));
 int PlayTTS(std::string &tts, void (*callback)(int));
 void PlayRing(void);
+void GetUpgrade(int province, int city);
 void SendToBluetooth(const uint8_t *data, int length);
 void ConnectToBluetooth(const char *addr, const char *pin);
 void DisconnectBluetooth(void);
diff --git a/lib/src/main/cpp/rtk_platform/platform.cpp b/lib/src/main/cpp/rtk_platform/platform.cpp
index 3068568..ec41199 100644
--- a/lib/src/main/cpp/rtk_platform/platform.cpp
+++ b/lib/src/main/cpp/rtk_platform/platform.cpp
@@ -203,6 +203,7 @@
     eventQueue = NULL;
 
     memset(&platformStatus, 0, sizeof(platformStatus));
+    memset(&deviceInfo, 0, sizeof(deviceInfo));
 
     sem_init(&sem_status_changed, 0, 0);
 
@@ -225,19 +226,27 @@
 
 void ConfigPlatform(const rtk_platform_cfg_t *p)
 {
-    DEBUG("閰嶇疆RTK骞冲彴璧勮 sn %s device_model %s, imei %s, phone %02X%02X%02X%02X%02X%02X%02X%02X", p->device_sn, p->device_model, p->imei, p->phone[0],
+    DEBUG("閰嶇疆RTK骞冲彴璧勮 sn %s device_model %s, imei %s, phone %02X%02X%02X%02X%02X%02X%02X%02X, province %d city %d",
+            p->device_sn, p->device_model, p->imei, p->phone[0],
           p->phone[1],
           p->phone[2],
           p->phone[3],
           p->phone[4],
           p->phone[5],
           p->phone[6],
-          p->phone[7]);
+          p->phone[7],
+          p->province,
+          p->city);
 
     AppTimer_delete(ReqRtkPlatformConfigTimeout);
 
     strcpy(exceptSocket.domain_name, p->domain_name);
     exceptSocket.port = p->port;
+
+    if (deviceInfo.province != p->province || deviceInfo.city != p->city) {
+        GetUpgrade(p->province, p->city);
+    }
+
     deviceInfo.province = p->province;
     deviceInfo.city = p->city;
     strcpy((char *)deviceInfo.device_model, p->device_model);
diff --git a/lib/src/main/java/com/anyun/exam/lib/RemoteService.java b/lib/src/main/java/com/anyun/exam/lib/RemoteService.java
index b0c25da..83052a5 100644
--- a/lib/src/main/java/com/anyun/exam/lib/RemoteService.java
+++ b/lib/src/main/java/com/anyun/exam/lib/RemoteService.java
@@ -133,7 +133,6 @@
 //        new Thread(new AutoUpdateMcuThread(this)).start();
 
         upgrade = Upgrade.getInstance(getApplicationContext());
-        upgrade.CheckUpgrade();
 
         ringUri = GetRingIndex(this, "Antimony");
 //        PlayRing(this, ringUri);
@@ -429,6 +428,12 @@
         }
     }
 
+    public void GetUpgrade(int province, int city) {
+        if (upgrade != null) {
+            upgrade.CheckUpgrade(province, city);
+        }
+    }
+
     public void ConnectBluetooth(String name, String pin) {
         if (mBluetooth != null && mChatService != null) {
             Log.d(TAG, "鎵ц钃濈墮杩炴帴璇锋眰 " + name);
diff --git a/lib/src/main/java/com/anyun/exam/lib/Upgrade.java b/lib/src/main/java/com/anyun/exam/lib/Upgrade.java
index 985096d..8883f57 100644
--- a/lib/src/main/java/com/anyun/exam/lib/Upgrade.java
+++ b/lib/src/main/java/com/anyun/exam/lib/Upgrade.java
@@ -31,6 +31,9 @@
     private static final String newProgramIndUrl = "http://upgrade.safeluck.com/ftp/aykj4/aks3.json";
     private static Upgrade instance = null;
     private Context context;
+    private int province;
+    private int city;
+
     private DownloadManagerUtil downloadManagerUtil = null;
     private InstallUtil installUtil = null;
     private static final String SAVE_FILE_NAME = "aks3.apk";
@@ -219,7 +222,7 @@
             String result = CheckNewVersion(newProgramIndUrl);
 
             if (result != null) {
-                DfuFileInfo dfuFileInfo = parseJson(result, 53, 100);
+                DfuFileInfo dfuFileInfo = parseJson(result, province, city);
                 if (dfuFileInfo != null && dfuFileInfo.getValid()) {
                     if (dfuFileInfo.getAppVerCode() > 0 && dfuFileInfo.getAppUrl() != null) {
                         if (installUtil.getVerCode() < dfuFileInfo.getAppVerCode()) {
@@ -248,7 +251,9 @@
         }
     };
 
-    public void CheckUpgrade() {
+    public void CheckUpgrade(int province, int city) {
+        this.province = province;
+        this.city = city;
         handlerCheckNewVersion.removeCallbacks(runnableCheckNewVersion);
         handlerCheckNewVersion.postDelayed(runnableCheckNewVersion, 100);
     }

--
Gitblit v1.8.0