@capgo/capacitor-updater 3.2.0 → 3.3.1
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 +4 -4
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdater.java +209 -212
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +188 -182
- package/ios/Plugin/CapacitorUpdater.swift +63 -26
- package/ios/Plugin/CapacitorUpdaterPlugin.m +1 -0
- package/ios/Plugin/CapacitorUpdaterPlugin.swift +13 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -43,7 +43,7 @@ Create account in [capgo.app](https://capgo.app) and get your [API key](https://
|
|
|
43
43
|
```
|
|
44
44
|
- Add to your main code
|
|
45
45
|
```javascript
|
|
46
|
-
import { CapacitorUpdater } from 'capacitor-updater'
|
|
46
|
+
import { CapacitorUpdater } from '@capgo/capacitor-updater'
|
|
47
47
|
CapacitorUpdater.notifyAppReady()
|
|
48
48
|
// To let auto update know you app boot well.
|
|
49
49
|
```
|
|
@@ -53,7 +53,7 @@ Create account in [capgo.app](https://capgo.app) and get your [API key](https://
|
|
|
53
53
|
- If update fail it will roolback to previous version.
|
|
54
54
|
|
|
55
55
|
See more there in the [Auto update](
|
|
56
|
-
https://
|
|
56
|
+
https://github.com/Cap-go/capacitor-updater/wiki) documentation.
|
|
57
57
|
|
|
58
58
|
|
|
59
59
|
## Manual setup
|
|
@@ -64,7 +64,7 @@ install it when user background the app.
|
|
|
64
64
|
In your main code :
|
|
65
65
|
|
|
66
66
|
```javascript
|
|
67
|
-
import { CapacitorUpdater } from 'capacitor-updater'
|
|
67
|
+
import { CapacitorUpdater } from '@capgo/capacitor-updater'
|
|
68
68
|
import { SplashScreen } from '@capacitor/splash-screen'
|
|
69
69
|
import { App } from '@capacitor/app'
|
|
70
70
|
|
|
@@ -436,7 +436,7 @@ removeAllListeners() => Promise<void>
|
|
|
436
436
|
### Listen to download events
|
|
437
437
|
|
|
438
438
|
```javascript
|
|
439
|
-
import { CapacitorUpdater } from 'capacitor-updater';
|
|
439
|
+
import { CapacitorUpdater } from '@capgo/capacitor-updater';
|
|
440
440
|
|
|
441
441
|
CapacitorUpdater.addListener('download', (info: any) => {
|
|
442
442
|
console.log('download was fired', info.percent);
|
|
@@ -45,187 +45,168 @@ interface Callback {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
public class CapacitorUpdater {
|
|
48
|
-
|
|
48
|
+
static final String AB = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
49
|
+
static SecureRandom rnd = new SecureRandom();
|
|
50
|
+
private final String TAG = "Capacitor-updater";
|
|
51
|
+
private final Context context;
|
|
52
|
+
private final String basePathHot = "versions";
|
|
53
|
+
private final SharedPreferences prefs;
|
|
54
|
+
private final SharedPreferences.Editor editor;
|
|
55
|
+
private String versionBuild = "";
|
|
56
|
+
private String versionCode = "";
|
|
57
|
+
private String versionOs = "";
|
|
58
|
+
|
|
49
59
|
public String appId = "";
|
|
50
60
|
public String deviceID = "";
|
|
51
|
-
|
|
61
|
+
public final String pluginVersion = "3.3.1";
|
|
62
|
+
public String statsUrl = "";
|
|
52
63
|
|
|
64
|
+
public CapacitorUpdater (final Context context) throws PackageManager.NameNotFoundException {
|
|
65
|
+
this.context = context;
|
|
66
|
+
this.prefs = this.context.getSharedPreferences("CapWebViewSettings", Activity.MODE_PRIVATE);
|
|
67
|
+
this.editor = this.prefs.edit();
|
|
68
|
+
this.versionOs = Build.VERSION.RELEASE;
|
|
69
|
+
this.deviceID = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
|
|
70
|
+
final PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
|
|
71
|
+
this.versionBuild = pInfo.versionName;
|
|
72
|
+
this.versionCode = Integer.toString(pInfo.versionCode);
|
|
73
|
+
}
|
|
53
74
|
|
|
54
|
-
private FilenameFilter filter = new FilenameFilter() {
|
|
75
|
+
private final FilenameFilter filter = new FilenameFilter() {
|
|
55
76
|
@Override
|
|
56
|
-
public boolean accept(File f, String name) {
|
|
77
|
+
public boolean accept(final File f, final String name) {
|
|
57
78
|
// ignore directories generated by mac os x
|
|
58
79
|
return !name.startsWith("__MACOSX") && !name.startsWith(".") && !name.startsWith(".DS_Store");
|
|
59
80
|
}
|
|
60
81
|
};
|
|
61
|
-
private final CapacitorUpdaterPlugin plugin;
|
|
62
|
-
private String versionBuild = "";
|
|
63
|
-
private String versionCode = "";
|
|
64
|
-
private String versionOs = "";
|
|
65
|
-
private String TAG = "Capacitor-updater";
|
|
66
|
-
private Context context;
|
|
67
|
-
private String basePathHot = "versions";
|
|
68
|
-
private SharedPreferences prefs;
|
|
69
|
-
private SharedPreferences.Editor editor;
|
|
70
|
-
|
|
71
|
-
static final String AB = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
72
|
-
static SecureRandom rnd = new SecureRandom();
|
|
73
82
|
|
|
74
|
-
private int calcTotalPercent(int percent, int min, int max) {
|
|
83
|
+
private int calcTotalPercent(final int percent, final int min, final int max) {
|
|
75
84
|
return (percent * (max - min)) / 100 + min;
|
|
76
85
|
}
|
|
77
86
|
|
|
78
|
-
|
|
79
|
-
|
|
87
|
+
void notifyDownload(final int percent) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
private String randomString(final int len){
|
|
92
|
+
final StringBuilder sb = new StringBuilder(len);
|
|
80
93
|
for(int i = 0; i < len; i++)
|
|
81
94
|
sb.append(AB.charAt(rnd.nextInt(AB.length())));
|
|
82
95
|
return sb.toString();
|
|
83
96
|
}
|
|
84
|
-
|
|
85
|
-
this.context
|
|
86
|
-
|
|
87
|
-
this.prefs = context.getSharedPreferences("CapWebViewSettings", Activity.MODE_PRIVATE);
|
|
88
|
-
this.editor = prefs.edit();
|
|
89
|
-
this.versionOs = Build.VERSION.RELEASE;
|
|
90
|
-
this.deviceID = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
|
|
91
|
-
PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
|
|
92
|
-
this.versionBuild = pInfo.versionName;
|
|
93
|
-
this.versionCode = Integer.toString(pInfo.versionCode);
|
|
94
|
-
}
|
|
95
|
-
public CapacitorUpdater (Context context, CapacitorUpdaterPlugin plugin) throws PackageManager.NameNotFoundException {
|
|
96
|
-
this.context = context;
|
|
97
|
-
this.plugin = plugin;
|
|
98
|
-
this.prefs = context.getSharedPreferences("CapWebViewSettings", Activity.MODE_PRIVATE);
|
|
99
|
-
this.editor = prefs.edit();
|
|
100
|
-
this.versionOs = Build.VERSION.RELEASE;
|
|
101
|
-
this.deviceID = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
|
|
102
|
-
PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
|
|
103
|
-
this.versionBuild = pInfo.versionName;
|
|
104
|
-
this.versionCode = Integer.toString(pInfo.versionCode);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
private Boolean unzip(String source, String dest) {
|
|
108
|
-
File zipFile = new File(this.context.getFilesDir() + "/" + source);
|
|
109
|
-
File targetDirectory = new File(this.context.getFilesDir() + "/" + dest);
|
|
110
|
-
ZipInputStream zis = null;
|
|
97
|
+
private File unzip(final File zipFile, final String dest) throws IOException {
|
|
98
|
+
final File targetDirectory = new File(this.context.getFilesDir() + "/" + dest);
|
|
99
|
+
final ZipInputStream zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(zipFile)));
|
|
111
100
|
try {
|
|
112
|
-
zis = new ZipInputStream(
|
|
113
|
-
new BufferedInputStream(new FileInputStream(zipFile)));
|
|
114
|
-
} catch (FileNotFoundException e) {
|
|
115
|
-
e.printStackTrace();
|
|
116
|
-
return false;
|
|
117
|
-
}
|
|
118
|
-
try {
|
|
119
|
-
ZipEntry ze;
|
|
120
101
|
int count;
|
|
121
|
-
int
|
|
122
|
-
byte[] buffer = new byte[
|
|
123
|
-
long
|
|
124
|
-
long
|
|
102
|
+
final int bufferSize = 8192;
|
|
103
|
+
final byte[] buffer = new byte[bufferSize];
|
|
104
|
+
final long lengthTotal = zipFile.length();
|
|
105
|
+
long lengthRead = bufferSize;
|
|
125
106
|
int percent = 0;
|
|
126
|
-
this.
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
107
|
+
this.notifyDownload(75);
|
|
108
|
+
|
|
109
|
+
ZipEntry entry;
|
|
110
|
+
while ((entry = zis.getNextEntry()) != null) {
|
|
111
|
+
final File file = new File(targetDirectory, entry.getName());
|
|
112
|
+
final String canonicalPath = file.getCanonicalPath();
|
|
113
|
+
final String canonicalDir = (new File(String.valueOf(targetDirectory))).getCanonicalPath();
|
|
114
|
+
final File dir = entry.isDirectory() ? file : file.getParentFile();
|
|
115
|
+
|
|
132
116
|
if (!canonicalPath.startsWith(canonicalDir)) {
|
|
133
117
|
throw new FileNotFoundException("SecurityException, Failed to ensure directory is the start path : " +
|
|
134
118
|
canonicalDir + " of " + canonicalPath);
|
|
135
119
|
}
|
|
136
|
-
|
|
120
|
+
|
|
121
|
+
if (!dir.isDirectory() && !dir.mkdirs()) {
|
|
137
122
|
throw new FileNotFoundException("Failed to ensure directory: " +
|
|
138
123
|
dir.getAbsolutePath());
|
|
139
|
-
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (entry.isDirectory()) {
|
|
140
127
|
continue;
|
|
141
|
-
|
|
142
|
-
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
try(final FileOutputStream outputStream = new FileOutputStream(file)) {
|
|
143
131
|
while ((count = zis.read(buffer)) != -1)
|
|
144
|
-
|
|
145
|
-
} finally {
|
|
146
|
-
fileOut.close();
|
|
132
|
+
outputStream.write(buffer, 0, count);
|
|
147
133
|
}
|
|
148
|
-
|
|
149
|
-
|
|
134
|
+
|
|
135
|
+
final int newPercent = (int)((lengthRead * 100) / lengthTotal);
|
|
136
|
+
if (lengthTotal > 1 && newPercent != percent) {
|
|
150
137
|
percent = newPercent;
|
|
151
|
-
this.
|
|
138
|
+
this.notifyDownload(this.calcTotalPercent(percent, 75, 90));
|
|
152
139
|
}
|
|
153
|
-
|
|
140
|
+
|
|
141
|
+
lengthRead += entry.getCompressedSize();
|
|
154
142
|
}
|
|
155
|
-
|
|
156
|
-
Log.i(TAG, "unzip error", e);
|
|
157
|
-
return false;
|
|
143
|
+
return targetDirectory;
|
|
158
144
|
} finally {
|
|
159
145
|
try {
|
|
160
146
|
zis.close();
|
|
161
|
-
} catch (IOException e) {
|
|
162
|
-
e.
|
|
163
|
-
return false;
|
|
147
|
+
} catch (final IOException e) {
|
|
148
|
+
Log.e(this.TAG, "Failed to close zip input stream", e);
|
|
164
149
|
}
|
|
165
|
-
return true;
|
|
166
150
|
}
|
|
167
151
|
}
|
|
168
152
|
|
|
169
|
-
private
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
return false;
|
|
153
|
+
private void flattenAssets(final File sourceFile, final String dest) throws IOException {
|
|
154
|
+
if (!sourceFile.exists()) {
|
|
155
|
+
throw new FileNotFoundException("Source file not found: " + sourceFile.getPath());
|
|
173
156
|
}
|
|
174
|
-
File
|
|
175
|
-
|
|
176
|
-
String[]
|
|
177
|
-
if (
|
|
178
|
-
|
|
157
|
+
final File destinationFile = new File(this.context.getFilesDir() + "/" + dest);
|
|
158
|
+
destinationFile.getParentFile().mkdirs();
|
|
159
|
+
final String[] entries = sourceFile.list(this.filter);
|
|
160
|
+
if (entries == null || entries.length == 0) {
|
|
161
|
+
throw new IOException("Source file was not a directory or was empty: " + sourceFile.getPath());
|
|
179
162
|
}
|
|
180
|
-
if (
|
|
181
|
-
File
|
|
182
|
-
|
|
163
|
+
if (entries.length == 1 && !entries[0].equals("index.html")) {
|
|
164
|
+
final File child = new File(sourceFile.getPath() + "/" + entries[0]);
|
|
165
|
+
child.renameTo(destinationFile);
|
|
183
166
|
} else {
|
|
184
|
-
|
|
167
|
+
sourceFile.renameTo(destinationFile);
|
|
185
168
|
}
|
|
186
|
-
|
|
187
|
-
return true;
|
|
169
|
+
sourceFile.delete();
|
|
188
170
|
}
|
|
189
171
|
|
|
190
|
-
private
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
172
|
+
private File downloadFile(final String url, final String dest) throws IOException {
|
|
173
|
+
|
|
174
|
+
final URL u = new URL(url);
|
|
175
|
+
final URLConnection connection = u.openConnection();
|
|
176
|
+
final InputStream is = u.openStream();
|
|
177
|
+
final DataInputStream dis = new DataInputStream(is);
|
|
178
|
+
|
|
179
|
+
final File target = new File(this.context.getFilesDir() + "/" + dest);
|
|
180
|
+
target.getParentFile().mkdirs();
|
|
181
|
+
target.createNewFile();
|
|
182
|
+
final FileOutputStream fos = new FileOutputStream(target);
|
|
183
|
+
|
|
184
|
+
final long totalLength = connection.getContentLength();
|
|
185
|
+
final int bufferSize = 1024;
|
|
186
|
+
final byte[] buffer = new byte[bufferSize];
|
|
187
|
+
int length;
|
|
188
|
+
|
|
189
|
+
int bytesRead = bufferSize;
|
|
190
|
+
int percent = 0;
|
|
191
|
+
this.notifyDownload(10);
|
|
192
|
+
while ((length = dis.read(buffer))>0) {
|
|
193
|
+
fos.write(buffer, 0, length);
|
|
194
|
+
final int newPercent = (int)((bytesRead * 100) / totalLength);
|
|
195
|
+
if (totalLength > 1 && newPercent != percent) {
|
|
196
|
+
percent = newPercent;
|
|
197
|
+
this.notifyDownload(this.calcTotalPercent(percent, 10, 70));
|
|
215
198
|
}
|
|
216
|
-
|
|
217
|
-
Log.e(TAG, "downloadFile error", e);
|
|
218
|
-
return false;
|
|
199
|
+
bytesRead += length;
|
|
219
200
|
}
|
|
220
|
-
return
|
|
201
|
+
return target;
|
|
221
202
|
}
|
|
222
203
|
|
|
223
|
-
private void deleteDirectory(File file) throws IOException {
|
|
204
|
+
private void deleteDirectory(final File file) throws IOException {
|
|
224
205
|
if (file.isDirectory()) {
|
|
225
|
-
File[] entries = file.listFiles();
|
|
206
|
+
final File[] entries = file.listFiles();
|
|
226
207
|
if (entries != null) {
|
|
227
|
-
for (File entry : entries) {
|
|
228
|
-
deleteDirectory(entry);
|
|
208
|
+
for (final File entry : entries) {
|
|
209
|
+
this.deleteDirectory(entry);
|
|
229
210
|
}
|
|
230
211
|
}
|
|
231
212
|
}
|
|
@@ -234,100 +215,92 @@ public class CapacitorUpdater {
|
|
|
234
215
|
}
|
|
235
216
|
}
|
|
236
217
|
|
|
237
|
-
public String download(String url) {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
Boolean flatt = this.flattenAssets(folderNameUnZip, folderName);
|
|
254
|
-
if(!flatt) return "";
|
|
255
|
-
this.plugin.notifyDownload(100);
|
|
256
|
-
return version;
|
|
257
|
-
} catch (Exception e) {
|
|
258
|
-
Log.e(TAG, "updateApp error", e);
|
|
259
|
-
return "";
|
|
260
|
-
}
|
|
218
|
+
public String download(final String url) throws IOException {
|
|
219
|
+
this.notifyDownload(0);
|
|
220
|
+
final String path = this.randomString(10);
|
|
221
|
+
final File zipFile = new File(this.context.getFilesDir() + "/" + path);
|
|
222
|
+
final String folderNameUnZip = this.randomString(10);
|
|
223
|
+
final String version = this.randomString(10);
|
|
224
|
+
final String folderName = this.basePathHot + "/" + version;
|
|
225
|
+
this.notifyDownload(5);
|
|
226
|
+
final File downloaded = this.downloadFile(url, path);
|
|
227
|
+
this.notifyDownload(71);
|
|
228
|
+
final File unzipped = this.unzip(downloaded, folderNameUnZip);
|
|
229
|
+
zipFile.delete();
|
|
230
|
+
this.notifyDownload(91);
|
|
231
|
+
this.flattenAssets(unzipped, folderName);
|
|
232
|
+
this.notifyDownload(100);
|
|
233
|
+
return version;
|
|
261
234
|
}
|
|
262
235
|
|
|
263
236
|
public ArrayList<String> list() {
|
|
264
|
-
ArrayList<String> res = new ArrayList<String>();
|
|
265
|
-
File destHot = new File(this.context.getFilesDir() + "/" + basePathHot);
|
|
266
|
-
Log.i(TAG, "list File : " + destHot.getPath());
|
|
237
|
+
final ArrayList<String> res = new ArrayList<String>();
|
|
238
|
+
final File destHot = new File(this.context.getFilesDir() + "/" + this.basePathHot);
|
|
239
|
+
Log.i(this.TAG, "list File : " + destHot.getPath());
|
|
267
240
|
if (destHot.exists()) {
|
|
268
|
-
for (File i : destHot.listFiles()) {
|
|
241
|
+
for (final File i : destHot.listFiles()) {
|
|
269
242
|
res.add(i.getName());
|
|
270
243
|
}
|
|
271
244
|
} else {
|
|
272
|
-
Log.i(TAG, "No version available" + destHot);
|
|
245
|
+
Log.i(this.TAG, "No version available" + destHot);
|
|
273
246
|
}
|
|
274
247
|
return res;
|
|
275
248
|
}
|
|
276
249
|
|
|
277
|
-
public Boolean delete(String version, String versionName) throws IOException {
|
|
278
|
-
File destHot = new File(this.context.getFilesDir() + "/" + basePathHot + "/" + version);
|
|
250
|
+
public Boolean delete(final String version, final String versionName) throws IOException {
|
|
251
|
+
final File destHot = new File(this.context.getFilesDir() + "/" + this.basePathHot + "/" + version);
|
|
279
252
|
if (destHot.exists()) {
|
|
280
|
-
deleteDirectory(destHot);
|
|
253
|
+
this.deleteDirectory(destHot);
|
|
281
254
|
return true;
|
|
282
255
|
}
|
|
283
|
-
Log.i(TAG, "Directory not removed: " + destHot.getPath());
|
|
256
|
+
Log.i(this.TAG, "Directory not removed: " + destHot.getPath());
|
|
284
257
|
this.sendStats("delete", versionName);
|
|
285
258
|
return false;
|
|
286
259
|
}
|
|
287
260
|
|
|
288
|
-
public Boolean set(String version, String versionName) {
|
|
289
|
-
File destHot = new File(this.context.getFilesDir() + "/" + basePathHot + "/" + version);
|
|
290
|
-
File destIndex = new File(destHot.getPath() + "/index.html");
|
|
261
|
+
public Boolean set(final String version, final String versionName) {
|
|
262
|
+
final File destHot = new File(this.context.getFilesDir() + "/" + this.basePathHot + "/" + version);
|
|
263
|
+
final File destIndex = new File(destHot.getPath() + "/index.html");
|
|
291
264
|
if (destHot.exists() && destIndex.exists()) {
|
|
292
|
-
editor.putString("lastPathHot", destHot.getPath());
|
|
293
|
-
editor.putString("serverBasePath", destHot.getPath());
|
|
294
|
-
editor.putString("versionName", versionName);
|
|
295
|
-
editor.commit();
|
|
296
|
-
sendStats("set", versionName);
|
|
265
|
+
this.editor.putString("lastPathHot", destHot.getPath());
|
|
266
|
+
this.editor.putString("serverBasePath", destHot.getPath());
|
|
267
|
+
this.editor.putString("versionName", versionName);
|
|
268
|
+
this.editor.commit();
|
|
269
|
+
this.sendStats("set", versionName);
|
|
297
270
|
return true;
|
|
298
271
|
}
|
|
299
|
-
sendStats("set_fail", versionName);
|
|
272
|
+
this.sendStats("set_fail", versionName);
|
|
300
273
|
return false;
|
|
301
274
|
}
|
|
302
275
|
|
|
303
|
-
public void getLatest(String url, Callback callback) {
|
|
304
|
-
String deviceID = this.
|
|
305
|
-
String appId = this.
|
|
306
|
-
String versionBuild = this.versionBuild;
|
|
307
|
-
String versionCode = this.versionCode;
|
|
308
|
-
String versionOs = this.versionOs;
|
|
309
|
-
String pluginVersion = this.pluginVersion;
|
|
310
|
-
String versionName = getVersionName().equals("") ? "builtin" : getVersionName();
|
|
311
|
-
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
|
|
276
|
+
public void getLatest(final String url, final Callback callback) {
|
|
277
|
+
final String deviceID = this.getDeviceID();
|
|
278
|
+
final String appId = this.getAppId();
|
|
279
|
+
final String versionBuild = this.versionBuild;
|
|
280
|
+
final String versionCode = this.versionCode;
|
|
281
|
+
final String versionOs = this.versionOs;
|
|
282
|
+
final String pluginVersion = this.pluginVersion;
|
|
283
|
+
final String versionName = this.getVersionName().equals("") ? "builtin" : this.getVersionName();
|
|
284
|
+
final StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
|
|
312
285
|
new Response.Listener<String>() {
|
|
313
286
|
@Override
|
|
314
|
-
public void onResponse(String response) {
|
|
287
|
+
public void onResponse(final String response) {
|
|
315
288
|
try {
|
|
316
|
-
JSONObject jsonObject = new JSONObject(response);
|
|
289
|
+
final JSONObject jsonObject = new JSONObject(response);
|
|
317
290
|
callback.callback(jsonObject);
|
|
318
|
-
} catch (JSONException e) {
|
|
319
|
-
e.
|
|
291
|
+
} catch (final JSONException e) {
|
|
292
|
+
Log.e(CapacitorUpdater.this.TAG, "Error parsing JSON", e);
|
|
320
293
|
}
|
|
321
294
|
}
|
|
322
295
|
}, new Response.ErrorListener() {
|
|
323
296
|
@Override
|
|
324
|
-
public void onErrorResponse(VolleyError error) {
|
|
325
|
-
Log.e(TAG, "Error getting Latest" + error);
|
|
297
|
+
public void onErrorResponse(final VolleyError error) {
|
|
298
|
+
Log.e(CapacitorUpdater.this.TAG, "Error getting Latest" + error);
|
|
326
299
|
}
|
|
327
300
|
}) {
|
|
328
301
|
@Override
|
|
329
302
|
public Map<String, String> getHeaders() throws AuthFailureError {
|
|
330
|
-
Map<String, String> params = new HashMap<String, String>();
|
|
303
|
+
final Map<String, String> params = new HashMap<String, String>();
|
|
331
304
|
params.put("cap_platform", "android");
|
|
332
305
|
params.put("cap_device_id", deviceID);
|
|
333
306
|
params.put("cap_app_id", appId);
|
|
@@ -339,46 +312,46 @@ public class CapacitorUpdater {
|
|
|
339
312
|
return params;
|
|
340
313
|
}
|
|
341
314
|
};
|
|
342
|
-
RequestQueue requestQueue = Volley.newRequestQueue(this.context);
|
|
315
|
+
final RequestQueue requestQueue = Volley.newRequestQueue(this.context);
|
|
343
316
|
requestQueue.add(stringRequest);
|
|
344
317
|
}
|
|
345
318
|
|
|
346
319
|
public String getLastPathHot() {
|
|
347
|
-
return prefs.getString("lastPathHot", "public");
|
|
320
|
+
return this.prefs.getString("lastPathHot", "public");
|
|
348
321
|
}
|
|
349
322
|
|
|
350
323
|
public String getVersionName() {
|
|
351
|
-
return prefs.getString("versionName", "");
|
|
324
|
+
return this.prefs.getString("versionName", "");
|
|
352
325
|
}
|
|
353
326
|
|
|
354
327
|
public void reset() {
|
|
355
|
-
String version = prefs.getString("versionName", "");
|
|
328
|
+
final String version = this.prefs.getString("versionName", "");
|
|
356
329
|
this.sendStats("reset", version);
|
|
357
|
-
editor.putString("lastPathHot", "public");
|
|
358
|
-
editor.putString("serverBasePath", "public");
|
|
359
|
-
editor.putString("versionName", "");
|
|
360
|
-
editor.commit();
|
|
330
|
+
this.editor.putString("lastPathHot", "public");
|
|
331
|
+
this.editor.putString("serverBasePath", "public");
|
|
332
|
+
this.editor.putString("versionName", "");
|
|
333
|
+
this.editor.commit();
|
|
361
334
|
}
|
|
362
335
|
|
|
363
|
-
public void sendStats(String action, String version) {
|
|
364
|
-
if (
|
|
365
|
-
URL url;
|
|
366
|
-
JSONObject json = new JSONObject();
|
|
367
|
-
String jsonString;
|
|
336
|
+
public void sendStats(final String action, final String version) {
|
|
337
|
+
if (this.getStatsUrl() == "") { return; }
|
|
338
|
+
final URL url;
|
|
339
|
+
final JSONObject json = new JSONObject();
|
|
340
|
+
final String jsonString;
|
|
368
341
|
try {
|
|
369
|
-
url = new URL(
|
|
342
|
+
url = new URL(this.getStatsUrl());
|
|
370
343
|
json.put("platform", "android");
|
|
371
344
|
json.put("action", action);
|
|
372
345
|
json.put("version_name", version);
|
|
373
|
-
json.put("device_id", this.
|
|
346
|
+
json.put("device_id", this.getDeviceID());
|
|
374
347
|
json.put("version_build", this.versionBuild);
|
|
375
348
|
json.put("version_code", this.versionCode);
|
|
376
349
|
json.put("version_os", this.versionOs);
|
|
377
350
|
json.put("plugin_version", this.pluginVersion);
|
|
378
|
-
json.put("app_id", this.
|
|
351
|
+
json.put("app_id", this.getAppId());
|
|
379
352
|
jsonString = json.toString();
|
|
380
|
-
} catch (Exception ex) {
|
|
381
|
-
Log.e(TAG, "Error get stats", ex);
|
|
353
|
+
} catch (final Exception ex) {
|
|
354
|
+
Log.e(this.TAG, "Error get stats", ex);
|
|
382
355
|
return;
|
|
383
356
|
}
|
|
384
357
|
new Thread(new Runnable(){
|
|
@@ -393,17 +366,17 @@ public class CapacitorUpdater {
|
|
|
393
366
|
con.setRequestProperty("Content-Length", Integer.toString(jsonString.getBytes().length));
|
|
394
367
|
con.setDoOutput(true);
|
|
395
368
|
con.setConnectTimeout(500);
|
|
396
|
-
DataOutputStream wr = new DataOutputStream (con.getOutputStream());
|
|
369
|
+
final DataOutputStream wr = new DataOutputStream (con.getOutputStream());
|
|
397
370
|
wr.writeBytes(jsonString);
|
|
398
371
|
wr.close();
|
|
399
|
-
int responseCode = con.getResponseCode();
|
|
372
|
+
final int responseCode = con.getResponseCode();
|
|
400
373
|
if (responseCode != 200) {
|
|
401
|
-
Log.e(TAG, "Stats error responseCode: " + responseCode);
|
|
374
|
+
Log.e(CapacitorUpdater.this.TAG, "Stats error responseCode: " + responseCode);
|
|
402
375
|
} else {
|
|
403
|
-
Log.i(TAG, "Stats send for \"" + action + "\", version " + version);
|
|
376
|
+
Log.i(CapacitorUpdater.this.TAG, "Stats send for \"" + action + "\", version " + version);
|
|
404
377
|
}
|
|
405
|
-
} catch (Exception ex) {
|
|
406
|
-
Log.e(TAG, "Error post stats", ex);
|
|
378
|
+
} catch (final Exception ex) {
|
|
379
|
+
Log.e(CapacitorUpdater.this.TAG, "Error post stats", ex);
|
|
407
380
|
} finally {
|
|
408
381
|
if (con != null) {
|
|
409
382
|
con.disconnect();
|
|
@@ -412,4 +385,28 @@ public class CapacitorUpdater {
|
|
|
412
385
|
}
|
|
413
386
|
}).start();
|
|
414
387
|
}
|
|
388
|
+
|
|
389
|
+
public String getStatsUrl() {
|
|
390
|
+
return this.statsUrl;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
public void setStatsUrl(final String statsUrl) {
|
|
394
|
+
this.statsUrl = statsUrl;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
public String getAppId() {
|
|
398
|
+
return this.appId;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
public void setAppId(final String appId) {
|
|
402
|
+
this.appId = appId;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
public String getDeviceID() {
|
|
406
|
+
return this.deviceID;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
public void setDeviceID(final String deviceID) {
|
|
410
|
+
this.deviceID = deviceID;
|
|
411
|
+
}
|
|
415
412
|
}
|