@capgo/capacitor-updater 6.4.1 → 6.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/android/build.gradle +2 -1
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdater.java +225 -192
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +21 -9
- package/android/src/main/java/ee/forgr/capacitor_updater/DataManager.java +28 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/DownloadService.java +206 -133
- package/dist/docs.json +1 -1
- package/dist/esm/definitions.d.ts +3 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/CapacitorUpdater.swift +22 -16
- package/ios/Plugin/CapacitorUpdaterPlugin.swift +6 -6
- package/package.json +13 -13
package/README.md
CHANGED
|
@@ -591,6 +591,7 @@ setChannel(options: SetChannelOptions) => Promise<ChannelRes>
|
|
|
591
591
|
Sets the channel for this device. The channel has to allow for self assignment for this to work.
|
|
592
592
|
Do not use this method to set the channel at boot when `autoUpdate` is enabled in the {@link PluginsConfig}.
|
|
593
593
|
This method is to set the channel after the app is ready.
|
|
594
|
+
This methods send to Capgo backend a request to link the device ID to the channel. Capgo can accept or refuse depending of the setting of your channel.
|
|
594
595
|
|
|
595
596
|
| Param | Type | Description |
|
|
596
597
|
| ------------- | --------------------------------------------------------------- | -------------------------------------------------------------------------------- |
|
package/android/build.gradle
CHANGED
|
@@ -52,11 +52,12 @@ dependencies {
|
|
|
52
52
|
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
53
53
|
implementation project(':capacitor-android')
|
|
54
54
|
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
55
|
-
|
|
55
|
+
// implementation 'com.android.volley:volley:1.2.1'
|
|
56
56
|
implementation 'io.github.g00fy2:versioncompare:1.5.0'
|
|
57
57
|
implementation 'com.google.code.gson:gson:2.11.0'
|
|
58
58
|
testImplementation "junit:junit:$junitVersion"
|
|
59
59
|
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
60
60
|
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
61
61
|
implementation 'org.brotli:dec:0.1.2'
|
|
62
|
+
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
|
|
62
63
|
}
|
|
@@ -8,6 +8,7 @@ package ee.forgr.capacitor_updater;
|
|
|
8
8
|
|
|
9
9
|
import static android.content.Context.RECEIVER_NOT_EXPORTED;
|
|
10
10
|
|
|
11
|
+
import android.annotation.SuppressLint;
|
|
11
12
|
import android.app.Activity;
|
|
12
13
|
import android.content.BroadcastReceiver;
|
|
13
14
|
import android.content.Context;
|
|
@@ -18,14 +19,6 @@ import android.os.Build;
|
|
|
18
19
|
import android.os.Bundle;
|
|
19
20
|
import android.util.Base64;
|
|
20
21
|
import android.util.Log;
|
|
21
|
-
import com.android.volley.BuildConfig;
|
|
22
|
-
import com.android.volley.DefaultRetryPolicy;
|
|
23
|
-
import com.android.volley.NetworkResponse;
|
|
24
|
-
import com.android.volley.Request;
|
|
25
|
-
import com.android.volley.RequestQueue;
|
|
26
|
-
import com.android.volley.VolleyError;
|
|
27
|
-
import com.android.volley.toolbox.HttpHeaderParser;
|
|
28
|
-
import com.android.volley.toolbox.JsonObjectRequest;
|
|
29
22
|
import com.getcapacitor.JSObject;
|
|
30
23
|
import com.getcapacitor.plugin.WebView;
|
|
31
24
|
import java.io.BufferedInputStream;
|
|
@@ -37,7 +30,6 @@ import java.io.FileOutputStream;
|
|
|
37
30
|
import java.io.FilenameFilter;
|
|
38
31
|
import java.io.IOException;
|
|
39
32
|
import java.io.InputStream;
|
|
40
|
-
import java.io.UnsupportedEncodingException;
|
|
41
33
|
import java.net.URL;
|
|
42
34
|
import java.net.URLConnection;
|
|
43
35
|
import java.security.GeneralSecurityException;
|
|
@@ -54,6 +46,7 @@ import java.util.zip.CRC32;
|
|
|
54
46
|
import java.util.zip.ZipEntry;
|
|
55
47
|
import java.util.zip.ZipInputStream;
|
|
56
48
|
import javax.crypto.SecretKey;
|
|
49
|
+
import okhttp3.*;
|
|
57
50
|
import org.json.JSONArray;
|
|
58
51
|
import org.json.JSONException;
|
|
59
52
|
import org.json.JSONObject;
|
|
@@ -74,7 +67,7 @@ public class CapacitorUpdater {
|
|
|
74
67
|
public SharedPreferences.Editor editor;
|
|
75
68
|
public SharedPreferences prefs;
|
|
76
69
|
|
|
77
|
-
public
|
|
70
|
+
public OkHttpClient client;
|
|
78
71
|
|
|
79
72
|
public File documentsDir;
|
|
80
73
|
public Boolean directUpdate = false;
|
|
@@ -105,7 +98,13 @@ public class CapacitorUpdater {
|
|
|
105
98
|
};
|
|
106
99
|
|
|
107
100
|
private boolean isProd() {
|
|
108
|
-
|
|
101
|
+
try {
|
|
102
|
+
return !Objects.requireNonNull(getClass().getPackage())
|
|
103
|
+
.getName()
|
|
104
|
+
.contains(".debug");
|
|
105
|
+
} catch (Exception e) {
|
|
106
|
+
return true; // Default to production if we can't determine
|
|
107
|
+
}
|
|
109
108
|
}
|
|
110
109
|
|
|
111
110
|
private boolean isEmulator() {
|
|
@@ -252,6 +251,7 @@ public class CapacitorUpdater {
|
|
|
252
251
|
sourceFile.delete();
|
|
253
252
|
}
|
|
254
253
|
|
|
254
|
+
@SuppressLint("UnspecifiedRegisterReceiverFlag")
|
|
255
255
|
public void onResume() {
|
|
256
256
|
IntentFilter filter = new IntentFilter();
|
|
257
257
|
filter.addAction(DownloadService.NOTIFICATION);
|
|
@@ -478,9 +478,15 @@ public class CapacitorUpdater {
|
|
|
478
478
|
intent.putExtra(DownloadService.SESSIONKEY, sessionKey);
|
|
479
479
|
intent.putExtra(DownloadService.CHECKSUM, checksum);
|
|
480
480
|
if (manifest != null) {
|
|
481
|
-
|
|
481
|
+
DataManager.getInstance().setManifest(manifest);
|
|
482
|
+
intent.putExtra(DownloadService.IS_MANIFEST, true);
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
486
|
+
this.activity.startForegroundService(intent);
|
|
487
|
+
} else {
|
|
488
|
+
this.activity.startService(intent);
|
|
482
489
|
}
|
|
483
|
-
this.activity.startService(intent);
|
|
484
490
|
}
|
|
485
491
|
|
|
486
492
|
private void downloadFile(
|
|
@@ -954,36 +960,65 @@ public class CapacitorUpdater {
|
|
|
954
960
|
return json;
|
|
955
961
|
}
|
|
956
962
|
|
|
957
|
-
private
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
963
|
+
private void makeJsonRequest(
|
|
964
|
+
String url,
|
|
965
|
+
JSONObject jsonBody,
|
|
966
|
+
Callback callback
|
|
967
|
+
) {
|
|
968
|
+
MediaType JSON = MediaType.get("application/json; charset=utf-8");
|
|
969
|
+
RequestBody body = RequestBody.create(jsonBody.toString(), JSON);
|
|
970
|
+
|
|
971
|
+
Request request = new Request.Builder().url(url).post(body).build();
|
|
972
|
+
|
|
973
|
+
client
|
|
974
|
+
.newCall(request)
|
|
975
|
+
.enqueue(
|
|
976
|
+
new okhttp3.Callback() {
|
|
977
|
+
@Override
|
|
978
|
+
public void onFailure(Call call, IOException e) {
|
|
979
|
+
JSObject retError = new JSObject();
|
|
980
|
+
retError.put("message", "Request failed: " + e.getMessage());
|
|
981
|
+
retError.put("error", "network_error");
|
|
982
|
+
callback.callback(retError);
|
|
983
|
+
}
|
|
967
984
|
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
985
|
+
@Override
|
|
986
|
+
public void onResponse(Call call, Response response)
|
|
987
|
+
throws IOException {
|
|
988
|
+
try (ResponseBody responseBody = response.body()) {
|
|
989
|
+
if (!response.isSuccessful()) {
|
|
990
|
+
JSObject retError = new JSObject();
|
|
991
|
+
retError.put("message", "Server error: " + response.code());
|
|
992
|
+
retError.put("error", "response_error");
|
|
993
|
+
callback.callback(retError);
|
|
994
|
+
return;
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
String responseData = responseBody.string();
|
|
998
|
+
JSONObject jsonResponse = new JSONObject(responseData);
|
|
999
|
+
JSObject ret = new JSObject();
|
|
1000
|
+
|
|
1001
|
+
Iterator<String> keys = jsonResponse.keys();
|
|
1002
|
+
while (keys.hasNext()) {
|
|
1003
|
+
String key = keys.next();
|
|
1004
|
+
if (jsonResponse.has(key)) {
|
|
1005
|
+
if ("session_key".equals(key)) {
|
|
1006
|
+
ret.put("sessionKey", jsonResponse.get(key));
|
|
1007
|
+
} else {
|
|
1008
|
+
ret.put(key, jsonResponse.get(key));
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
callback.callback(ret);
|
|
1013
|
+
} catch (JSONException e) {
|
|
1014
|
+
JSObject retError = new JSObject();
|
|
1015
|
+
retError.put("message", "JSON parse error: " + e.getMessage());
|
|
1016
|
+
retError.put("error", "parse_error");
|
|
1017
|
+
callback.callback(retError);
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
);
|
|
987
1022
|
}
|
|
988
1023
|
|
|
989
1024
|
public void getLatest(final String updateUrl, final Callback callback) {
|
|
@@ -992,7 +1027,6 @@ public class CapacitorUpdater {
|
|
|
992
1027
|
json = this.createInfoObject();
|
|
993
1028
|
} catch (JSONException e) {
|
|
994
1029
|
Log.e(TAG, "Error getLatest JSONException", e);
|
|
995
|
-
e.printStackTrace();
|
|
996
1030
|
final JSObject retError = new JSObject();
|
|
997
1031
|
retError.put("message", "Cannot get info: " + e);
|
|
998
1032
|
retError.put("error", "json_error");
|
|
@@ -1001,40 +1035,8 @@ public class CapacitorUpdater {
|
|
|
1001
1035
|
}
|
|
1002
1036
|
|
|
1003
1037
|
Log.i(CapacitorUpdater.TAG, "Auto-update parameters: " + json);
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
Request.Method.POST,
|
|
1007
|
-
updateUrl,
|
|
1008
|
-
json,
|
|
1009
|
-
res -> {
|
|
1010
|
-
final JSObject ret = new JSObject();
|
|
1011
|
-
Iterator<String> keys = res.keys();
|
|
1012
|
-
while (keys.hasNext()) {
|
|
1013
|
-
String key = keys.next();
|
|
1014
|
-
if (res.has(key)) {
|
|
1015
|
-
try {
|
|
1016
|
-
if ("session_key".equals(key)) {
|
|
1017
|
-
ret.put("sessionKey", res.get(key));
|
|
1018
|
-
} else {
|
|
1019
|
-
ret.put(key, res.get(key));
|
|
1020
|
-
}
|
|
1021
|
-
} catch (JSONException e) {
|
|
1022
|
-
e.printStackTrace();
|
|
1023
|
-
final JSObject retError = new JSObject();
|
|
1024
|
-
retError.put("message", "Cannot set info: " + e);
|
|
1025
|
-
retError.put("error", "response_error");
|
|
1026
|
-
callback.callback(retError);
|
|
1027
|
-
}
|
|
1028
|
-
}
|
|
1029
|
-
}
|
|
1030
|
-
callback.callback(ret);
|
|
1031
|
-
},
|
|
1032
|
-
error ->
|
|
1033
|
-
callback.callback(
|
|
1034
|
-
CapacitorUpdater.this.createError("Error get latest", error)
|
|
1035
|
-
)
|
|
1036
|
-
);
|
|
1037
|
-
this.requestQueue.add(setRetryPolicy(request));
|
|
1038
|
+
|
|
1039
|
+
makeJsonRequest(updateUrl, json, callback);
|
|
1038
1040
|
}
|
|
1039
1041
|
|
|
1040
1042
|
public void unsetChannel(final Callback callback) {
|
|
@@ -1052,44 +1054,66 @@ public class CapacitorUpdater {
|
|
|
1052
1054
|
json = this.createInfoObject();
|
|
1053
1055
|
} catch (JSONException e) {
|
|
1054
1056
|
Log.e(TAG, "Error unsetChannel JSONException", e);
|
|
1055
|
-
e.printStackTrace();
|
|
1056
1057
|
final JSObject retError = new JSObject();
|
|
1057
1058
|
retError.put("message", "Cannot get info: " + e);
|
|
1058
1059
|
retError.put("error", "json_error");
|
|
1059
1060
|
callback.callback(retError);
|
|
1060
1061
|
return;
|
|
1061
1062
|
}
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1063
|
+
|
|
1064
|
+
Request request = new Request.Builder()
|
|
1065
|
+
.url(channelUrl)
|
|
1066
|
+
.delete(
|
|
1067
|
+
RequestBody.create(json.toString(), MediaType.get("application/json"))
|
|
1068
|
+
)
|
|
1069
|
+
.build();
|
|
1070
|
+
|
|
1071
|
+
client
|
|
1072
|
+
.newCall(request)
|
|
1073
|
+
.enqueue(
|
|
1074
|
+
new okhttp3.Callback() {
|
|
1075
|
+
@Override
|
|
1076
|
+
public void onFailure(Call call, IOException e) {
|
|
1077
|
+
JSObject retError = new JSObject();
|
|
1078
|
+
retError.put("message", "Request failed: " + e.getMessage());
|
|
1079
|
+
retError.put("error", "network_error");
|
|
1080
|
+
callback.callback(retError);
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
@Override
|
|
1084
|
+
public void onResponse(Call call, Response response)
|
|
1085
|
+
throws IOException {
|
|
1086
|
+
try (ResponseBody responseBody = response.body()) {
|
|
1087
|
+
if (!response.isSuccessful()) {
|
|
1088
|
+
JSObject retError = new JSObject();
|
|
1089
|
+
retError.put("message", "Server error: " + response.code());
|
|
1090
|
+
retError.put("error", "response_error");
|
|
1091
|
+
callback.callback(retError);
|
|
1092
|
+
return;
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
String responseData = responseBody.string();
|
|
1096
|
+
JSONObject jsonResponse = new JSONObject(responseData);
|
|
1097
|
+
JSObject ret = new JSObject();
|
|
1098
|
+
|
|
1099
|
+
Iterator<String> keys = jsonResponse.keys();
|
|
1100
|
+
while (keys.hasNext()) {
|
|
1101
|
+
String key = keys.next();
|
|
1102
|
+
if (jsonResponse.has(key)) {
|
|
1103
|
+
ret.put(key, jsonResponse.get(key));
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
Log.i(TAG, "Channel unset");
|
|
1080
1107
|
callback.callback(ret);
|
|
1108
|
+
} catch (JSONException e) {
|
|
1109
|
+
JSObject retError = new JSObject();
|
|
1110
|
+
retError.put("message", "JSON parse error: " + e.getMessage());
|
|
1111
|
+
retError.put("error", "parse_error");
|
|
1112
|
+
callback.callback(retError);
|
|
1081
1113
|
}
|
|
1082
1114
|
}
|
|
1083
1115
|
}
|
|
1084
|
-
|
|
1085
|
-
callback.callback(ret);
|
|
1086
|
-
},
|
|
1087
|
-
error ->
|
|
1088
|
-
callback.callback(
|
|
1089
|
-
CapacitorUpdater.this.createError("Error unset channel", error)
|
|
1090
|
-
)
|
|
1091
|
-
);
|
|
1092
|
-
this.requestQueue.add(setRetryPolicy(request));
|
|
1116
|
+
);
|
|
1093
1117
|
}
|
|
1094
1118
|
|
|
1095
1119
|
public void setChannel(final String channel, final Callback callback) {
|
|
@@ -1108,44 +1132,14 @@ public class CapacitorUpdater {
|
|
|
1108
1132
|
json.put("channel", channel);
|
|
1109
1133
|
} catch (JSONException e) {
|
|
1110
1134
|
Log.e(TAG, "Error setChannel JSONException", e);
|
|
1111
|
-
e.printStackTrace();
|
|
1112
1135
|
final JSObject retError = new JSObject();
|
|
1113
1136
|
retError.put("message", "Cannot get info: " + e);
|
|
1114
1137
|
retError.put("error", "json_error");
|
|
1115
1138
|
callback.callback(retError);
|
|
1116
1139
|
return;
|
|
1117
1140
|
}
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
Request.Method.POST,
|
|
1121
|
-
channelUrl,
|
|
1122
|
-
json,
|
|
1123
|
-
res -> {
|
|
1124
|
-
final JSObject ret = new JSObject();
|
|
1125
|
-
Iterator<String> keys = res.keys();
|
|
1126
|
-
while (keys.hasNext()) {
|
|
1127
|
-
String key = keys.next();
|
|
1128
|
-
if (res.has(key)) {
|
|
1129
|
-
try {
|
|
1130
|
-
ret.put(key, res.get(key));
|
|
1131
|
-
} catch (JSONException e) {
|
|
1132
|
-
e.printStackTrace();
|
|
1133
|
-
final JSObject retError = new JSObject();
|
|
1134
|
-
retError.put("message", "Cannot set channel: " + e);
|
|
1135
|
-
retError.put("error", "response_error");
|
|
1136
|
-
callback.callback(ret);
|
|
1137
|
-
}
|
|
1138
|
-
}
|
|
1139
|
-
}
|
|
1140
|
-
Log.i(TAG, "Channel set to \"" + channel);
|
|
1141
|
-
callback.callback(ret);
|
|
1142
|
-
},
|
|
1143
|
-
error ->
|
|
1144
|
-
callback.callback(
|
|
1145
|
-
CapacitorUpdater.this.createError("Error set channel", error)
|
|
1146
|
-
)
|
|
1147
|
-
);
|
|
1148
|
-
this.requestQueue.add(setRetryPolicy(request));
|
|
1141
|
+
|
|
1142
|
+
makeJsonRequest(channelUrl, json, callback);
|
|
1149
1143
|
}
|
|
1150
1144
|
|
|
1151
1145
|
public void getChannel(final Callback callback) {
|
|
@@ -1163,62 +1157,81 @@ public class CapacitorUpdater {
|
|
|
1163
1157
|
json = this.createInfoObject();
|
|
1164
1158
|
} catch (JSONException e) {
|
|
1165
1159
|
Log.e(TAG, "Error getChannel JSONException", e);
|
|
1166
|
-
e.printStackTrace();
|
|
1167
1160
|
final JSObject retError = new JSObject();
|
|
1168
1161
|
retError.put("message", "Cannot get info: " + e);
|
|
1169
1162
|
retError.put("error", "json_error");
|
|
1170
1163
|
callback.callback(retError);
|
|
1171
1164
|
return;
|
|
1172
1165
|
}
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1166
|
+
|
|
1167
|
+
Request request = new Request.Builder()
|
|
1168
|
+
.url(channelUrl)
|
|
1169
|
+
.put(
|
|
1170
|
+
RequestBody.create(json.toString(), MediaType.get("application/json"))
|
|
1171
|
+
)
|
|
1172
|
+
.build();
|
|
1173
|
+
|
|
1174
|
+
client
|
|
1175
|
+
.newCall(request)
|
|
1176
|
+
.enqueue(
|
|
1177
|
+
new okhttp3.Callback() {
|
|
1178
|
+
@Override
|
|
1179
|
+
public void onFailure(Call call, IOException e) {
|
|
1180
|
+
JSObject retError = new JSObject();
|
|
1181
|
+
retError.put("message", "Request failed: " + e.getMessage());
|
|
1182
|
+
retError.put("error", "network_error");
|
|
1183
|
+
callback.callback(retError);
|
|
1189
1184
|
}
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1185
|
+
|
|
1186
|
+
@Override
|
|
1187
|
+
public void onResponse(Call call, Response response)
|
|
1188
|
+
throws IOException {
|
|
1189
|
+
try (ResponseBody responseBody = response.body()) {
|
|
1190
|
+
if (response.code() == 400) {
|
|
1191
|
+
String data = responseBody.string();
|
|
1192
|
+
if (
|
|
1193
|
+
data.contains("channel_not_found") &&
|
|
1194
|
+
!defaultChannel.isEmpty()
|
|
1195
|
+
) {
|
|
1196
|
+
JSObject ret = new JSObject();
|
|
1197
|
+
ret.put("channel", defaultChannel);
|
|
1198
|
+
ret.put("status", "default");
|
|
1199
|
+
Log.i(TAG, "Channel get to \"" + ret);
|
|
1200
|
+
callback.callback(ret);
|
|
1201
|
+
return;
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
if (!response.isSuccessful()) {
|
|
1206
|
+
JSObject retError = new JSObject();
|
|
1207
|
+
retError.put("message", "Server error: " + response.code());
|
|
1208
|
+
retError.put("error", "response_error");
|
|
1209
|
+
callback.callback(retError);
|
|
1210
|
+
return;
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1213
|
+
String responseData = responseBody.string();
|
|
1214
|
+
JSONObject jsonResponse = new JSONObject(responseData);
|
|
1215
|
+
JSObject ret = new JSObject();
|
|
1216
|
+
|
|
1217
|
+
Iterator<String> keys = jsonResponse.keys();
|
|
1218
|
+
while (keys.hasNext()) {
|
|
1219
|
+
String key = keys.next();
|
|
1220
|
+
if (jsonResponse.has(key)) {
|
|
1221
|
+
ret.put(key, jsonResponse.get(key));
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1208
1224
|
Log.i(TAG, "Channel get to \"" + ret);
|
|
1209
1225
|
callback.callback(ret);
|
|
1210
|
-
|
|
1226
|
+
} catch (JSONException e) {
|
|
1227
|
+
JSObject retError = new JSObject();
|
|
1228
|
+
retError.put("message", "JSON parse error: " + e.getMessage());
|
|
1229
|
+
retError.put("error", "parse_error");
|
|
1230
|
+
callback.callback(retError);
|
|
1211
1231
|
}
|
|
1212
1232
|
}
|
|
1213
|
-
} catch (Throwable t) {
|
|
1214
|
-
// ignore
|
|
1215
1233
|
}
|
|
1216
|
-
|
|
1217
|
-
CapacitorUpdater.this.createError("Error get channel", error)
|
|
1218
|
-
);
|
|
1219
|
-
}
|
|
1220
|
-
);
|
|
1221
|
-
this.requestQueue.add(setRetryPolicy(request));
|
|
1234
|
+
);
|
|
1222
1235
|
}
|
|
1223
1236
|
|
|
1224
1237
|
public void sendStats(final String action) {
|
|
@@ -1246,19 +1259,39 @@ public class CapacitorUpdater {
|
|
|
1246
1259
|
json.put("action", action);
|
|
1247
1260
|
} catch (JSONException e) {
|
|
1248
1261
|
Log.e(TAG, "Error sendStats JSONException", e);
|
|
1249
|
-
e.printStackTrace();
|
|
1250
1262
|
return;
|
|
1251
1263
|
}
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1264
|
+
|
|
1265
|
+
Request request = new Request.Builder()
|
|
1266
|
+
.url(statsUrl)
|
|
1267
|
+
.post(
|
|
1268
|
+
RequestBody.create(json.toString(), MediaType.get("application/json"))
|
|
1269
|
+
)
|
|
1270
|
+
.build();
|
|
1271
|
+
|
|
1272
|
+
client
|
|
1273
|
+
.newCall(request)
|
|
1274
|
+
.enqueue(
|
|
1275
|
+
new okhttp3.Callback() {
|
|
1276
|
+
@Override
|
|
1277
|
+
public void onFailure(Call call, IOException e) {
|
|
1278
|
+
Log.e(TAG, "Failed to send stats: " + e.getMessage());
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1281
|
+
@Override
|
|
1282
|
+
public void onResponse(Call call, Response response)
|
|
1283
|
+
throws IOException {
|
|
1284
|
+
if (response.isSuccessful()) {
|
|
1285
|
+
Log.i(
|
|
1286
|
+
TAG,
|
|
1287
|
+
"Stats send for \"" + action + "\", version " + versionName
|
|
1288
|
+
);
|
|
1289
|
+
} else {
|
|
1290
|
+
Log.e(TAG, "Error sending stats: " + response.code());
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
);
|
|
1262
1295
|
}
|
|
1263
1296
|
|
|
1264
1297
|
public BundleInfo getBundleInfo(final String id) {
|
|
@@ -14,7 +14,6 @@ import android.content.pm.PackageInfo;
|
|
|
14
14
|
import android.content.pm.PackageManager;
|
|
15
15
|
import android.os.Build;
|
|
16
16
|
import android.util.Log;
|
|
17
|
-
import com.android.volley.toolbox.Volley;
|
|
18
17
|
import com.getcapacitor.CapConfig;
|
|
19
18
|
import com.getcapacitor.JSArray;
|
|
20
19
|
import com.getcapacitor.JSObject;
|
|
@@ -32,6 +31,7 @@ import java.net.MalformedURLException;
|
|
|
32
31
|
import java.net.URL;
|
|
33
32
|
import java.text.SimpleDateFormat;
|
|
34
33
|
import java.util.ArrayList;
|
|
34
|
+
import java.util.Arrays;
|
|
35
35
|
import java.util.Date;
|
|
36
36
|
import java.util.Iterator;
|
|
37
37
|
import java.util.List;
|
|
@@ -42,6 +42,8 @@ import java.util.UUID;
|
|
|
42
42
|
import java.util.concurrent.Phaser;
|
|
43
43
|
import java.util.concurrent.TimeUnit;
|
|
44
44
|
import java.util.concurrent.TimeoutException;
|
|
45
|
+
import okhttp3.OkHttpClient;
|
|
46
|
+
import okhttp3.Protocol;
|
|
45
47
|
import org.json.JSONArray;
|
|
46
48
|
import org.json.JSONException;
|
|
47
49
|
|
|
@@ -55,7 +57,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
55
57
|
private static final String channelUrlDefault =
|
|
56
58
|
"https://plugin.capgo.app/channel_self";
|
|
57
59
|
|
|
58
|
-
private final String PLUGIN_VERSION = "6.4
|
|
60
|
+
private final String PLUGIN_VERSION = "6.6.4";
|
|
59
61
|
private static final String DELAY_CONDITION_PREFERENCES = "";
|
|
60
62
|
|
|
61
63
|
private SharedPreferences.Editor editor;
|
|
@@ -136,9 +138,12 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
136
138
|
.getString("version", pInfo.versionName);
|
|
137
139
|
this.implementation.PLUGIN_VERSION = this.PLUGIN_VERSION;
|
|
138
140
|
this.implementation.versionCode = Integer.toString(pInfo.versionCode);
|
|
139
|
-
this.implementation.
|
|
140
|
-
|
|
141
|
-
|
|
141
|
+
this.implementation.client = new OkHttpClient.Builder()
|
|
142
|
+
.protocols(Arrays.asList(Protocol.HTTP_2, Protocol.HTTP_1_1))
|
|
143
|
+
.connectTimeout(this.implementation.timeout, TimeUnit.MILLISECONDS)
|
|
144
|
+
.readTimeout(this.implementation.timeout, TimeUnit.MILLISECONDS)
|
|
145
|
+
.writeTimeout(this.implementation.timeout, TimeUnit.MILLISECONDS)
|
|
146
|
+
.build();
|
|
142
147
|
|
|
143
148
|
this.implementation.directUpdate = this.getConfig()
|
|
144
149
|
.getBoolean("directUpdate", false);
|
|
@@ -224,9 +229,8 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
224
229
|
this.updateUrl = this.getConfig().getString("updateUrl", updateUrlDefault);
|
|
225
230
|
this.autoUpdate = this.getConfig().getBoolean("autoUpdate", true);
|
|
226
231
|
this.appReadyTimeout = this.getConfig().getInt("appReadyTimeout", 10000);
|
|
227
|
-
this.implementation.timeout =
|
|
228
|
-
.getInt("responseTimeout", 20) *
|
|
229
|
-
1000;
|
|
232
|
+
this.implementation.timeout =
|
|
233
|
+
this.getConfig().getInt("responseTimeout", 20) * 1000;
|
|
230
234
|
boolean resetWhenUpdate =
|
|
231
235
|
this.getConfig().getBoolean("resetWhenUpdate", true);
|
|
232
236
|
|
|
@@ -1107,7 +1111,15 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1107
1111
|
Boolean error
|
|
1108
1112
|
) {
|
|
1109
1113
|
if (error) {
|
|
1110
|
-
Log.i(
|
|
1114
|
+
Log.i(
|
|
1115
|
+
CapacitorUpdater.TAG,
|
|
1116
|
+
"endBackGroundTaskWithNotif error: " +
|
|
1117
|
+
error +
|
|
1118
|
+
" current: " +
|
|
1119
|
+
current.getVersionName() +
|
|
1120
|
+
"latestVersionName: " +
|
|
1121
|
+
latestVersionName
|
|
1122
|
+
);
|
|
1111
1123
|
this.implementation.sendStats("download_fail", current.getVersionName());
|
|
1112
1124
|
final JSObject ret = new JSObject();
|
|
1113
1125
|
ret.put("version", latestVersionName);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
package ee.forgr.capacitor_updater;
|
|
2
|
+
|
|
3
|
+
import org.json.JSONArray;
|
|
4
|
+
|
|
5
|
+
public class DataManager {
|
|
6
|
+
|
|
7
|
+
private static DataManager instance;
|
|
8
|
+
private JSONArray currentManifest;
|
|
9
|
+
|
|
10
|
+
private DataManager() {}
|
|
11
|
+
|
|
12
|
+
public static synchronized DataManager getInstance() {
|
|
13
|
+
if (instance == null) {
|
|
14
|
+
instance = new DataManager();
|
|
15
|
+
}
|
|
16
|
+
return instance;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public void setManifest(JSONArray manifest) {
|
|
20
|
+
this.currentManifest = manifest;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public JSONArray getAndClearManifest() {
|
|
24
|
+
JSONArray manifest = this.currentManifest;
|
|
25
|
+
this.currentManifest = null;
|
|
26
|
+
return manifest;
|
|
27
|
+
}
|
|
28
|
+
}
|