cordova-plugin-mserviceinterface-2.0 1.0.66 → 1.0.68

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cordova-plugin-mserviceinterface-2.0",
3
- "version": "1.0.66",
3
+ "version": "1.0.68",
4
4
  "description": "This plugin establishes the connection to the native interface and performs the requested task.",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/plugin.xml CHANGED
@@ -2,7 +2,7 @@
2
2
  <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
3
3
  xmlns:android="http://schemas.android.com/apk/res/android"
4
4
  id="cordova-plugin-mserviceinterface-2.0"
5
- version="1.0.66">
5
+ version="1.0.68">
6
6
  <name>mserviceinterface-2.0</name>
7
7
  <description>This plugin establishes the connection to the native interface and performs the requested task.</description>
8
8
  <author>selfservit@gmail.com</author>
@@ -21,6 +21,7 @@ import android.database.Cursor;
21
21
  import android.graphics.Bitmap;
22
22
  import android.graphics.BitmapFactory;
23
23
  import android.graphics.Canvas;
24
+ import android.graphics.Color;
24
25
  import android.graphics.Matrix;
25
26
  import android.graphics.Paint;
26
27
  import android.location.Location;
@@ -82,6 +83,7 @@ import java.io.ByteArrayOutputStream;
82
83
  import java.io.File;
83
84
  import java.io.FileInputStream;
84
85
  import java.io.FileOutputStream;
86
+ import java.io.FileReader;
85
87
  import java.io.IOException;
86
88
  import java.io.InputStream;
87
89
  import java.io.InputStreamReader;
@@ -965,6 +967,20 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
965
967
  callback.sendPluginResult(result);
966
968
  }
967
969
 
970
+ } else if (action.equals("getMyAccountsData")) {
971
+ try {
972
+ String folderPath = mInterfaceUtil.rootDirectory + "/" + args.getJSONObject(0).optString("folderPath");
973
+ ArrayList<JSONObject> dataArray = getJsonDataFromFiles(folderPath);
974
+ JSONArray jsonResult = new JSONArray(dataArray);
975
+ callbackContext.success(jsonResult.toString());
976
+ } catch (Exception e) {
977
+ e.printStackTrace();
978
+ PluginResult result = new PluginResult(PluginResult.Status.ERROR, "getMyAccountsData failed, exception is : "+e.getMessage());
979
+ callback.sendPluginResult(result);
980
+ }
981
+ }else if (action.equals("KillBackgroundExecutions")) {
982
+ callbackContext.success("success");
983
+ return true;
968
984
  }
969
985
  } catch (JSONException e) {
970
986
  System.out.println(" unable to proccess plugin method, exception is : "+e.getMessage());
@@ -972,6 +988,36 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
972
988
  return true;
973
989
  }
974
990
 
991
+ public static ArrayList<JSONObject> getJsonDataFromFiles(String folderPath) {
992
+ ArrayList<JSONObject> dataArray = new ArrayList<>();
993
+ try {
994
+ File folder = new File(folderPath);
995
+ if (folder.exists() && folder.isDirectory()) {
996
+ File[] files = folder.listFiles();
997
+
998
+ if (files != null) {
999
+ for (File file : files) {
1000
+ if (file.isFile() && file.getName().endsWith(".json")) {
1001
+ StringBuilder jsonData = new StringBuilder();
1002
+ try (FileReader reader = new FileReader(file)) {
1003
+ int character;
1004
+ while ((character = reader.read()) != -1) {
1005
+ jsonData.append((char) character);
1006
+ }
1007
+ JSONObject jsonObject = new JSONObject(mInterfaceUtil.decrypt(jsonData.toString()));
1008
+ dataArray.add(jsonObject);
1009
+ } catch (IOException e) {
1010
+ e.printStackTrace();
1011
+ }
1012
+ }
1013
+ }
1014
+ }
1015
+ }
1016
+ } catch (Exception e) {
1017
+ e.printStackTrace();
1018
+ }
1019
+ return dataArray;
1020
+ }
975
1021
  private boolean validateMobileNumber(String mobileNo) {
976
1022
  String regex;
977
1023
  boolean result = false;
@@ -1435,6 +1481,17 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1435
1481
  BitmapFactory.Options bmOptions = new BitmapFactory.Options();
1436
1482
  Bitmap bitmap = BitmapFactory.decodeFile(image.getAbsolutePath(), bmOptions);
1437
1483
 
1484
+ // Ensure the bitmap has an alpha channel (transparency).
1485
+ if (bitmap.getConfig() != Bitmap.Config.ARGB_8888) {
1486
+ Bitmap newBitmap = Bitmap.createBitmap(
1487
+ bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
1488
+ Canvas canvas = new Canvas(newBitmap);
1489
+ canvas.drawColor(Color.TRANSPARENT);
1490
+ canvas.drawBitmap(bitmap, 0, 0, null);
1491
+ bitmap.recycle();
1492
+ bitmap = newBitmap;
1493
+ }
1494
+
1438
1495
  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
1439
1496
  bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
1440
1497
  resultString = Base64.encodeToString(outputStream.toByteArray(), Base64.NO_WRAP);
@@ -1,6 +1,7 @@
1
1
  package com.selfservit.util;
2
2
 
3
3
  import static com.selfservit.util.mInterfaceUtil.decrypt;
4
+ import static com.selfservit.util.mInterfaceUtil.rootDirectory;
4
5
 
5
6
  import android.Manifest;
6
7
  import android.annotation.TargetApi;
@@ -50,6 +51,7 @@ import java.net.HttpURLConnection;
50
51
  import java.net.URL;
51
52
  import java.text.DateFormat;
52
53
  import java.text.SimpleDateFormat;
54
+ import java.util.ArrayList;
53
55
  import java.util.Arrays;
54
56
  import java.util.Date;
55
57
  import java.util.Timer;
@@ -115,7 +117,6 @@ public class mInterfaceService extends Service implements com.google.android.gms
115
117
  }
116
118
  };
117
119
  setQueueToServerInterval.schedule(setQueueIntervalObj, 2000, 2000);
118
-
119
120
  // App State Info Process //
120
121
  mInterfaceUtil.validateAppStateInfo(getApplicationContext());
121
122
  if (!isGooglePlayServicesAvailable()) {
@@ -123,8 +124,8 @@ public class mInterfaceService extends Service implements com.google.android.gms
123
124
  }
124
125
  String currentLine;
125
126
  StringBuilder locConfigObj = new StringBuilder();
126
- File baseDirectory = mInterfaceUtil.rootDirectory;
127
- File locConfigFile = new File(baseDirectory, "/" + mInterfaceUtil.packageName + "/location_configuration.txt");
127
+ File baseDirectory = rootDirectory;
128
+ File locConfigFile = new File(baseDirectory, "/" + mInterfaceUtil.packageName + "/app_controller.json");
128
129
  if (locConfigFile.exists()) {
129
130
  BufferedReader readerObj = new BufferedReader(new FileReader(locConfigFile));
130
131
  while ((currentLine = readerObj.readLine()) != null) {
@@ -132,17 +133,9 @@ public class mInterfaceService extends Service implements com.google.android.gms
132
133
  }
133
134
  readerObj.close();
134
135
  JSONObject serverDateObj = new JSONObject(decrypt(locConfigObj.toString()));
135
-
136
- File locationCheckFile = new File(baseDirectory, "/" + mInterfaceUtil.packageName + "/location_check.txt");
137
- StringBuilder locConfigObj1 = new StringBuilder();
138
- if (locationCheckFile.exists()) {
139
- BufferedReader readerObj1 = new BufferedReader(new FileReader(locationCheckFile));
140
- while ((currentLine = readerObj1.readLine()) != null) {
141
- locConfigObj1.append(currentLine);
142
- }
143
- readerObj1.close();
144
- String locationCheckStr = decrypt(locConfigObj1.toString());
145
- if (locationCheckStr.equals("false")) {
136
+ if (serverDateObj.has("location_check")) {
137
+ boolean locationCheck = serverDateObj.getBoolean("location_check");
138
+ if (!locationCheck) {
146
139
  TimerTask timerTask = new TimerTask() {
147
140
  @Override
148
141
  public void run() {
@@ -156,8 +149,9 @@ public class mInterfaceService extends Service implements com.google.android.gms
156
149
  };
157
150
  if (setLocationTimeInterval == null) {
158
151
  setLocationTimeInterval = new Timer();
159
- setLocationTimeInterval.schedule(timerTask, (Integer.parseInt(serverDateObj.optString("location_fetch_interval_in_seconds")) * 1000L), (Integer.parseInt(serverDateObj.optString("location_fetch_interval_in_seconds")) * 1000L));
160
- MINIMUM_INTERVAL = Long.parseLong(serverDateObj.optString("location_fetch_interval_in_seconds"));
152
+ JSONObject locationConfig = serverDateObj.getJSONObject("location_configuration");
153
+ setLocationTimeInterval.schedule(timerTask, (Integer.parseInt(locationConfig.getString("location_fetch_interval_in_seconds")) * 1000L), (Integer.parseInt(locationConfig.getString("location_fetch_interval_in_seconds")) * 1000L));
154
+ MINIMUM_INTERVAL = Long.parseLong(locationConfig.getString("location_fetch_interval_in_seconds"));
161
155
  createLocationRequest();
162
156
  this.mGoogleApiClient = new GoogleApiClient.Builder(this)
163
157
  .addConnectionCallbacks(this)
@@ -289,9 +283,9 @@ public class mInterfaceService extends Service implements com.google.android.gms
289
283
  String[] lastKnownLocation;
290
284
  boolean result = false;
291
285
  try {
292
- baseDirectory = mInterfaceUtil.rootDirectory;
286
+ baseDirectory = rootDirectory;
293
287
  locationData = new StringBuilder();
294
- File lastKnownLocationFile = new File(baseDirectory, "/" + mInterfaceUtil.packageName + "/LastKnownLocation_encrypted.txt");
288
+ File lastKnownLocationFile = new File(baseDirectory, "/" + mInterfaceUtil.packageName + "/last_known_location.txt");
295
289
  if (lastKnownLocationFile.exists()) {
296
290
  readerObj = new BufferedReader(new FileReader(lastKnownLocationFile));
297
291
  while ((currentLine = readerObj.readLine()) != null) {
@@ -336,30 +330,19 @@ public class mInterfaceService extends Service implements com.google.android.gms
336
330
  String statusIndication = "false";
337
331
  try {
338
332
  String clientID, countryCode, userID, clientUrl;
339
- BufferedReader myAccountsFileReader;
340
- StringBuilder myAccountsFileBuilder;
341
- JSONArray accountsList;
342
- JSONObject currentAccount;
343
- String currentLine;
344
- if (new File(mInterfaceUtil.rootDirectory, "/" + mInterfaceUtil.packageName + "/" + "my_accounts_encrypted.txt").exists()) {
345
- myAccountsFileReader = new BufferedReader(new FileReader(new File(mInterfaceUtil.rootDirectory, "/" + mInterfaceUtil.packageName + "/" + "my_accounts_encrypted.txt")));
346
- myAccountsFileBuilder = new StringBuilder();
347
- while ((currentLine = myAccountsFileReader.readLine()) != null) {
348
- myAccountsFileBuilder.append(currentLine);
349
- }
350
- myAccountsFileReader.close();
351
- accountsList = new JSONArray(decrypt(myAccountsFileBuilder.toString()));
333
+ ArrayList<JSONObject> accountsList;
334
+ if (new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/my_accounts").exists()) {
335
+ accountsList = mInterface.getJsonDataFromFiles(new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/my_accounts").getPath());
352
336
  if (isConnected()) {
353
- for (int index = 0; index < accountsList.length(); index++) {
354
- currentAccount = accountsList.optJSONObject(index);
337
+ for (JSONObject currentAccount : accountsList) {
355
338
  clientID = currentAccount.optString("client_id");
356
339
  countryCode = currentAccount.optString("country_code");
357
340
  userID = currentAccount.optString("user_id");
358
341
  clientUrl = currentAccount.optString("client_url");
359
- File baseDirectory = mInterfaceUtil.rootDirectory;
342
+ File baseDirectory = rootDirectory;
360
343
  File databaseDir = new File(baseDirectory + "/" + mInterfaceUtil.packageName + "/" + clientID + "/" + countryCode + "/database");
361
344
  if (databaseDir.exists()) {
362
- String attachmentsPath = mInterfaceUtil.rootDirectory + "/" + mInterfaceUtil.packageName + "/" + clientID + "/" + countryCode + "/database/attachments";
345
+ String attachmentsPath = rootDirectory + "/" + mInterfaceUtil.packageName + "/" + clientID + "/" + countryCode + "/database/attachments";
363
346
  String queuesPath = baseDirectory + "/" + mInterfaceUtil.packageName + "/" + clientID + "/" + countryCode + "/database/queue";
364
347
  if (new File(attachmentsPath).exists()) {
365
348
  File[] attachmentsFiles = new File(attachmentsPath).listFiles();
@@ -436,10 +419,7 @@ public class mInterfaceService extends Service implements com.google.android.gms
436
419
  @Override
437
420
  protected String doInBackground(String... urls) {
438
421
  String currentLine, clientID, countryCode, clientUrl, deviceID;
439
- BufferedReader myAccountsFileReader;
440
- StringBuilder myAccountsFileBuilder;
441
- JSONArray accountsList;
442
- JSONObject currentAccount;
422
+ ArrayList<JSONObject> accountsList;
443
423
  StringBuilder locationData;
444
424
  BufferedReader readerObj;
445
425
  BufferedWriter writerObj;
@@ -450,30 +430,23 @@ public class mInterfaceService extends Service implements com.google.android.gms
450
430
  URL requestPath;
451
431
 
452
432
  try {
453
- File baseDirectory = mInterfaceUtil.rootDirectory;
454
- if (new File(baseDirectory, "/" + mInterfaceUtil.packageName + "/" + "my_accounts_encrypted.txt").exists()) {
455
- myAccountsFileReader = new BufferedReader(new FileReader(new File(baseDirectory, "/" + mInterfaceUtil.packageName + "/" + "my_accounts_encrypted.txt")));
456
- myAccountsFileBuilder = new StringBuilder();
457
- while ((currentLine = myAccountsFileReader.readLine()) != null) {
458
- myAccountsFileBuilder.append(currentLine);
459
- }
460
- myAccountsFileReader.close();
461
- accountsList = new JSONArray(decrypt(myAccountsFileBuilder.toString()));
433
+ File baseDirectory = rootDirectory;
434
+ if (new File(baseDirectory, "/" + mInterfaceUtil.packageName + "/my_accounts").exists()) {
435
+ accountsList = mInterface.getJsonDataFromFiles(new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/my_accounts").getPath());
462
436
  locationData = new StringBuilder();
463
- readerObj = new BufferedReader(new FileReader(new File(baseDirectory, "/" + mInterfaceUtil.packageName + "/MyLocation_encrypted.txt")));
437
+ readerObj = new BufferedReader(new FileReader(new File(baseDirectory, "/" + mInterfaceUtil.packageName + "/my_location.txt")));
464
438
  while ((currentLine = readerObj.readLine()) != null) {
465
439
  locationData.append(decrypt(currentLine));
466
440
  }
467
441
  readerObj.close();
468
442
  serverData = locationData.toString();
469
443
 
470
- for (int index = 0; index < accountsList.length(); index++) {
471
- currentAccount = accountsList.optJSONObject(index);
444
+ for (JSONObject currentAccount : accountsList) {
472
445
  if (currentAccount.optString("location_update_ind").equals("true")) {
473
- clientID = mInterfaceUtil.clientID;
474
- countryCode = mInterfaceUtil.countryCode;
475
- clientUrl = mInterfaceUtil.clientUrl;
476
- deviceID = mInterfaceUtil.deviceID;
446
+ clientID = currentAccount.optString("client_id");
447
+ countryCode = currentAccount.optString("country_code");
448
+ clientUrl = currentAccount.optString("client_url");
449
+ deviceID = currentAccount.optString("device_id");
477
450
  requestURL = clientUrl + "/common/components/GeoLocation/update_device_location_offline.aspx";
478
451
  /* SEND LOCATION */
479
452
  requestPath = new URL(requestURL);
@@ -491,7 +464,7 @@ public class mInterfaceService extends Service implements com.google.android.gms
491
464
  if (responseCode == HttpURLConnection.HTTP_OK) {
492
465
  /* CLEARING THE LOCATION POINTS */
493
466
  if (serverData != "") {
494
- writerObj = new BufferedWriter(new FileWriter(new File(baseDirectory, "/" + mInterfaceUtil.packageName + "/MyLocation_encrypted.txt")));
467
+ writerObj = new BufferedWriter(new FileWriter(new File(baseDirectory, "/" + mInterfaceUtil.packageName + "/my_location.txt")));
495
468
  writerObj.write("");
496
469
  writerObj.flush();
497
470
  writerObj.close();
@@ -523,17 +496,17 @@ public class mInterfaceService extends Service implements com.google.android.gms
523
496
  @Override
524
497
  protected String doInBackground(String... urls) {
525
498
  File appDirectory,
526
- baseDirectory = mInterfaceUtil.rootDirectory;
499
+ baseDirectory = rootDirectory;
527
500
  FileWriter fileWriterObj;
528
501
  appDirectory = new File(baseDirectory + "/" + mInterfaceUtil.packageName);
529
502
  if (appDirectory.exists()) {
530
503
  try {
531
- fileWriterObj = new FileWriter(new File(baseDirectory, mInterfaceUtil.packageName + "/MyLocation_encrypted.txt"), true);
504
+ fileWriterObj = new FileWriter(new File(baseDirectory, mInterfaceUtil.packageName + "/my_location.txt"), true);
532
505
  fileWriterObj.write(mInterfaceUtil.encrypt(this.objLat + "," + this.objLon + "," + new SimpleDateFormat("yyyyMMddHHmmss", new mInterfaceUtil().locale).format(new Date()) + "\n"));
533
506
  fileWriterObj.flush();
534
507
  fileWriterObj.close();
535
508
 
536
- fileWriterObj = new FileWriter(new File(baseDirectory, mInterfaceUtil.packageName + "/LastKnownLocation_encrypted.txt"), false);
509
+ fileWriterObj = new FileWriter(new File(baseDirectory, mInterfaceUtil.packageName + "/last_known_location.txt"), false);
537
510
  fileWriterObj.write(mInterfaceUtil.encrypt(this.objLat + "," + this.objLon + "," + new SimpleDateFormat("yyyyMMddHHmmss", new mInterfaceUtil().locale).format(new Date())));
538
511
  fileWriterObj.flush();
539
512
  fileWriterObj.close();
@@ -577,7 +550,7 @@ public class mInterfaceService extends Service implements com.google.android.gms
577
550
  } else {
578
551
  restartServicePI = PendingIntent.getService(
579
552
  getApplicationContext(), 1, restartService,
580
- PendingIntent.FLAG_ONE_SHOT);
553
+ PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE);
581
554
  }
582
555
 
583
556
  AlarmManager alarmService = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
@@ -650,8 +623,8 @@ public class mInterfaceService extends Service implements com.google.android.gms
650
623
  };
651
624
  String currentLine;
652
625
  StringBuilder locConfigObj = new StringBuilder();
653
- File baseDirectory = mInterfaceUtil.rootDirectory;
654
- File locConfigFile = new File(baseDirectory, "/" + mInterfaceUtil.packageName + "/location_configuration.txt");
626
+ File baseDirectory = rootDirectory;
627
+ File locConfigFile = new File(baseDirectory, "/" + mInterfaceUtil.packageName + "/app_controller.json");
655
628
  if (locConfigFile.exists()) {
656
629
  BufferedReader readerObj = new BufferedReader(new FileReader(locConfigFile));
657
630
  while ((currentLine = readerObj.readLine()) != null) {
@@ -661,7 +634,9 @@ public class mInterfaceService extends Service implements com.google.android.gms
661
634
  JSONObject serverDateObj = new JSONObject(decrypt(locConfigObj.toString()));
662
635
  setLocationTimeInterval.cancel();
663
636
  setLocationTimeInterval = new Timer();
664
- setLocationTimeInterval.schedule(timerTask, (Integer.parseInt(serverDateObj.optString("location_fetch_interval_in_seconds")) * 1000L), (Integer.parseInt(serverDateObj.optString("location_fetch_interval_in_seconds")) * 1000L));
637
+ JSONObject locationConfig = serverDateObj.getJSONObject("location_configuration");
638
+ setLocationTimeInterval.schedule(timerTask, (Integer.parseInt(locationConfig.getString("location_fetch_interval_in_seconds")) * 1000L), (Integer.parseInt(locationConfig.getString("location_fetch_interval_in_seconds")) * 1000L));
639
+ MINIMUM_INTERVAL = Long.parseLong(locationConfig.getString("location_fetch_interval_in_seconds"));
665
640
  }
666
641
  } catch (Exception e) {
667
642
  e.printStackTrace();
@@ -49,6 +49,7 @@ import java.net.HttpURLConnection;
49
49
  import java.net.URL;
50
50
  import java.nio.charset.StandardCharsets;
51
51
  import java.text.SimpleDateFormat;
52
+ import java.util.ArrayList;
52
53
  import java.util.Arrays;
53
54
  import java.util.Date;
54
55
  import java.util.Locale;
@@ -225,7 +226,7 @@ public class mInterfaceUtil {
225
226
  String currentLine, lastKnownLocation = "";
226
227
  File locationFile;
227
228
  try {
228
- locationFile = new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/LastKnownLocation_encrypted.txt");
229
+ locationFile = new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/last_known_location.txt");
229
230
  if (locationFile.exists() && !locationFile.isDirectory()) {
230
231
  BufferedReader readerObj = new BufferedReader(new FileReader(locationFile));
231
232
  while ((currentLine = readerObj.readLine()) != null) {
@@ -586,19 +587,11 @@ public class mInterfaceUtil {
586
587
  String clientID, countryCode, userID, clientUrl;
587
588
  BufferedReader myAccountsFileReader;
588
589
  StringBuilder myAccountsFileBuilder;
589
- JSONArray accountsList;
590
- JSONObject currentAccount;
590
+ ArrayList<JSONObject> accountsList;
591
591
  String currentLine;
592
- if (new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/" + "my_accounts_encrypted.txt").exists()) {
593
- myAccountsFileReader = new BufferedReader(new FileReader(new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/" + "my_accounts_encrypted.txt")));
594
- myAccountsFileBuilder = new StringBuilder();
595
- while ((currentLine = myAccountsFileReader.readLine()) != null) {
596
- myAccountsFileBuilder.append(currentLine);
597
- }
598
- myAccountsFileReader.close();
599
- accountsList = new JSONArray(decrypt(myAccountsFileBuilder.toString()));
600
- for (int index = 0; index < accountsList.length(); index++) {
601
- currentAccount = accountsList.optJSONObject(index);
592
+ if (new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/my_accounts").exists()) {
593
+ accountsList = mInterface.getJsonDataFromFiles(new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/my_accounts").getPath());
594
+ for (JSONObject currentAccount : accountsList) {
602
595
  clientID = currentAccount.optString("client_id");
603
596
  countryCode = currentAccount.optString("country_code");
604
597
  userID = currentAccount.optString("user_id");
@@ -1433,6 +1426,7 @@ public class mInterfaceUtil {
1433
1426
  jsonObject1 = jsonObject1.put("client_id", clientID);
1434
1427
  jsonObject1 = jsonObject1.put("country_code", countryCode);
1435
1428
  jsonObject1 = jsonObject1.put("purposeCode", "mobile_address_store");
1429
+ jsonObject1 = jsonObject1.put("version", "doubleo");
1436
1430
  System.out.println("data format: " + jsonObject1);
1437
1431
  oStreamObj = new OutputStreamWriter(urlConObj.getOutputStream());
1438
1432
  oStreamObj.write(jsonObject1.toString());
@@ -1445,11 +1439,21 @@ public class mInterfaceUtil {
1445
1439
  }
1446
1440
  responseReaderObj.close();
1447
1441
  urlConObj.disconnect();
1448
- writerObj = new BufferedWriter(new FileWriter(new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/" + clientID + "/" + countryCode + "/" + "client_configuration_encrypted.txt")));
1449
- writerObj.write(encrypt(serverResponseObj.toString()));
1442
+
1443
+ BufferedReader reader = new BufferedReader(new FileReader(new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/" + "my_accounts" + "/" + clientID + "_" + countryCode + ".json")));
1444
+ StringBuilder content = new StringBuilder();
1445
+ String line;
1446
+ while ((line = reader.readLine()) != null) {
1447
+ content.append(line);
1448
+ }
1449
+ reader.close();
1450
+ // Parse the existing data as JSON
1451
+ JSONObject existingData = new JSONObject(decrypt(content.toString()));
1452
+ existingData.put("keys", serverResponseObj.toString());
1453
+ writerObj = new BufferedWriter(new FileWriter(new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/" + "my_accounts" + "/" + clientID + "_" + countryCode + ".json")));
1454
+ writerObj.write(encrypt(existingData.toString()));
1450
1455
  writerObj.flush();
1451
1456
  writerObj.close();
1452
-
1453
1457
  /* App State info DATA REQUEST */
1454
1458
  requestAuthenticationPath = new URL(cvsUrl + "/" + "get_app_state_info.aspx");
1455
1459
  urlConObj = (HttpURLConnection) requestAuthenticationPath.openConnection();
@@ -1537,37 +1541,54 @@ public class mInterfaceUtil {
1537
1541
  }
1538
1542
 
1539
1543
  public static void validateAppStateInfo(Context applicationContext) {
1544
+
1540
1545
  String currentLine;
1541
1546
  try {
1542
- File appStateIndicatorFile = new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/" + clientID + "/" + countryCode + "/" + "app_state_info.txt");
1543
- if (appStateIndicatorFile.exists()) {
1544
- BufferedReader authFileReader = new BufferedReader(new FileReader(appStateIndicatorFile));
1545
- StringBuilder authFileBuilder = new StringBuilder();
1546
- while ((currentLine = authFileReader.readLine()) != null) {
1547
- authFileBuilder.append(currentLine);
1548
- }
1549
- authFileReader.close();
1550
- JSONObject authFileObj = new JSONObject(decrypt(authFileBuilder.toString()));
1551
- long lastModifiedTime = appStateIndicatorFile.lastModified();
1552
- Date date = new Date();
1553
- date.setTime(lastModifiedTime);
1554
- String lastModifiedDate = new SimpleDateFormat("yyyyMMdd", new mInterfaceUtil().locale).format(date);
1555
-
1556
- if (authFileObj.optString("validDevice").equals("nostatus") || !lastModifiedDate.equals(new SimpleDateFormat("yyyyMMdd", new mInterfaceUtil().locale).format(new Date()))) {
1557
- if (isConnected(applicationContext)) {
1558
- new UpdateAppStateInfo().execute();
1547
+ if (new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/my_accounts").exists()) {
1548
+ ArrayList<JSONObject> accountsList = mInterface.getJsonDataFromFiles(new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/my_accounts").getPath());
1549
+ for (JSONObject currentAccount : accountsList) {
1550
+ String clientID = currentAccount.optString("client_id");
1551
+ String countryCode = currentAccount.optString("country_code");
1552
+
1553
+
1554
+ File appStateIndicatorFile = new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/" + clientID + "/" + countryCode + "/" + "app_state_info.txt");
1555
+ if (appStateIndicatorFile.exists()) {
1556
+ BufferedReader authFileReader = new BufferedReader(new FileReader(appStateIndicatorFile));
1557
+ StringBuilder authFileBuilder = new StringBuilder();
1558
+ while ((currentLine = authFileReader.readLine()) != null) {
1559
+ authFileBuilder.append(currentLine);
1560
+ }
1561
+ authFileReader.close();
1562
+ JSONObject authFileObj = new JSONObject(decrypt(authFileBuilder.toString()));
1563
+ long lastModifiedTime = appStateIndicatorFile.lastModified();
1564
+ Date date = new Date();
1565
+ date.setTime(lastModifiedTime);
1566
+ String lastModifiedDate = new SimpleDateFormat("yyyyMMdd", new mInterfaceUtil().locale).format(date);
1567
+
1568
+ if (authFileObj.optString("validDevice").equals("nostatus") || !lastModifiedDate.equals(new SimpleDateFormat("yyyyMMdd", new mInterfaceUtil().locale).format(new Date()))) {
1569
+ if (isConnected(applicationContext)) {
1570
+ UpdateAppStateInfo task = new UpdateAppStateInfo();
1571
+ task.setParam(currentAccount);
1572
+ task.execute();
1573
+ } else {
1574
+ mInterfaceService.handleAppStateTimer("success");
1575
+ }
1576
+ } else {
1577
+ mInterfaceService.handleAppStateTimer("success");
1578
+ }
1559
1579
  } else {
1560
- mInterfaceService.handleAppStateTimer("success");
1580
+ if (isConnected(applicationContext)) {
1581
+ UpdateAppStateInfo task = new UpdateAppStateInfo();
1582
+ task.setParam(currentAccount);
1583
+ task.execute();
1584
+ } else {
1585
+ mInterfaceService.handleAppStateTimer("failure");
1586
+ }
1561
1587
  }
1562
- } else {
1563
- mInterfaceService.handleAppStateTimer("success");
1564
- }
1565
- } else {
1566
- if (isConnected(applicationContext)) {
1567
- new UpdateAppStateInfo().execute();
1568
- } else {
1569
- mInterfaceService.handleAppStateTimer("failure");
1588
+
1570
1589
  }
1590
+ }else {
1591
+ System.out.println("No my accounts file");
1571
1592
  }
1572
1593
  } catch (Exception e) {
1573
1594
  System.out.println(e.getMessage());
@@ -1579,9 +1600,13 @@ public class mInterfaceUtil {
1579
1600
  private static class UpdateAppStateInfo extends AsyncTask<String,
1580
1601
  Void,
1581
1602
  String> {
1603
+ private JSONObject currentAccount;
1604
+ public void setParam(JSONObject currentAccount) {
1605
+ this.currentAccount = currentAccount;
1606
+ }
1582
1607
  @Override
1583
1608
  protected String doInBackground(String... strings) {
1584
- String currentLine;
1609
+ String currentLine,clientUrl,clientID,countryCode,cvsUrl,deviceID,sessionID,userID,localeID;
1585
1610
  URL requestAuthenticationPath,
1586
1611
  requestValidateDevicePath, getKeysPath;
1587
1612
  HttpURLConnection urlConObj;
@@ -1591,6 +1616,15 @@ public class mInterfaceUtil {
1591
1616
  BufferedReader responseReaderObj;
1592
1617
  JSONObject responseDataObj;
1593
1618
  try {
1619
+ clientID = currentAccount.optString("client_id");
1620
+ countryCode = currentAccount.optString("country_code");
1621
+ clientUrl = currentAccount.optString("client_url");
1622
+ cvsUrl = currentAccount.optString("cvs_url");
1623
+ deviceID = currentAccount.optString("device_id");
1624
+ sessionID = currentAccount.optString("session_id");
1625
+ userID = currentAccount.optString("user_id");
1626
+ localeID = currentAccount.optString("locale_id");
1627
+
1594
1628
  getKeysPath = new URL(clientUrl + "/" + "common/components/Keys/" + "RetrieveKey.aspx");
1595
1629
  urlConObj = (HttpURLConnection) getKeysPath.openConnection();
1596
1630
  urlConObj.setDoOutput(true);
@@ -1601,6 +1635,7 @@ public class mInterfaceUtil {
1601
1635
  jsonObject1 = jsonObject1.put("client_id", clientID);
1602
1636
  jsonObject1 = jsonObject1.put("country_code", countryCode);
1603
1637
  jsonObject1 = jsonObject1.put("purposeCode", "mobile_address_store");
1638
+ jsonObject1 = jsonObject1.put("version", "doubleo");
1604
1639
  System.out.println("data format: " + jsonObject1);
1605
1640
  oStreamObj = new OutputStreamWriter(urlConObj.getOutputStream());
1606
1641
  oStreamObj.write(jsonObject1.toString());
@@ -1613,8 +1648,18 @@ public class mInterfaceUtil {
1613
1648
  }
1614
1649
  responseReaderObj.close();
1615
1650
  urlConObj.disconnect();
1616
- writerObj = new BufferedWriter(new FileWriter(new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/" + clientID + "/" + countryCode + "/" + "client_configuration_encrypted.txt")));
1617
- writerObj.write(encrypt(serverResponseObj.toString()));
1651
+ BufferedReader reader = new BufferedReader(new FileReader(new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/" + "my_accounts" + "/" + clientID + "_" + countryCode + "/" + ".json")));
1652
+ StringBuilder content = new StringBuilder();
1653
+ String line;
1654
+ while ((line = reader.readLine()) != null) {
1655
+ content.append(line);
1656
+ }
1657
+ reader.close();
1658
+ // Parse the existing data as JSON
1659
+ JSONObject existingData = new JSONObject(decrypt(content.toString()));
1660
+ existingData.put("keys", serverResponseObj.toString());
1661
+ writerObj = new BufferedWriter(new FileWriter(new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/" + "my_accounts" + "/" + clientID + "_" + countryCode + "/" + ".json")));
1662
+ writerObj.write(encrypt(existingData.toString()));
1618
1663
  writerObj.flush();
1619
1664
  writerObj.close();
1620
1665
  /* App State info DATA REQUEST */
@@ -108,6 +108,7 @@
108
108
  //- (void)triggerAuthenticationServices:(NSString *)clientId countryCode:(NSString *)countryCode userId:(NSString *)userId sessionId:(NSString *)sessionId localeId:(NSString *)localeId deviceID:(NSString *)deviceID clientUrl:(NSString *)clientUrl cvsUrl:(NSString *)cvsUrl authIndFilePath:(NSString *)authIndFilePath;
109
109
  - (void)GetSyncIndicator:(CDVInvokedUrlCommand*)command;
110
110
  - (void)CopyAttachmentFile:(CDVInvokedUrlCommand*)command;
111
+ - (void)getMyAccountsData:(CDVInvokedUrlCommand*)command;
111
112
  @property (strong, nonatomic) CLLocationManager * locationManager;
112
113
  @property (strong, nonatomic) NSMutableArray * coordinatesArray;
113
114
  @property (weak, nonatomic) IBOutlet UIButton *btnGallery;