@capgo/capacitor-updater 3.1.0 → 3.3.0

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