cordova-plugin-mserviceinterface-2.0 1.0.49 → 1.0.50

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.49",
3
+ "version": "1.0.50",
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.49">
5
+ version="1.0.50">
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>
@@ -141,7 +141,20 @@ public class mInterfaceService extends Service implements com.google.android.gms
141
141
  TimerTask setQueueIntervalObj, setTimerIntervelObj;
142
142
  Intent serviceIntent = new Intent(getApplicationContext(), mInterfaceReceiver.class);
143
143
  serviceIntent.setAction("com.example.checkservice");
144
- final PendingIntent pIntent = PendingIntent.getBroadcast(getApplicationContext(), 0,serviceIntent, PendingIntent.FLAG_UPDATE_CURRENT);
144
+ final PendingIntent pIntent;
145
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
146
+ pIntent = PendingIntent.getBroadcast(getApplicationContext(),
147
+ 0,
148
+ serviceIntent,
149
+ PendingIntent.FLAG_IMMUTABLE);
150
+ }
151
+ else
152
+ {
153
+ pIntent = PendingIntent.getBroadcast(getApplicationContext(),
154
+ 0,
155
+ serviceIntent,
156
+ PendingIntent.FLAG_UPDATE_CURRENT);
157
+ }
145
158
  long firstMillis = System.currentTimeMillis();
146
159
  AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
147
160
  alarm.setRepeating(AlarmManager.RTC_WAKEUP, firstMillis,
@@ -159,19 +172,6 @@ public class mInterfaceService extends Service implements com.google.android.gms
159
172
 
160
173
  // App State Info Process //
161
174
  mInterfaceUtil.validateAppStateInfo(getApplicationContext());
162
-
163
- // **** TimeReader Interval Timer ***** //
164
- setTimerIntervel = new Timer();
165
- setTimerIntervelObj = new TimerTask() {
166
- public void run() {
167
- try {
168
- timeReader();
169
- } catch (Exception e) {
170
- e.printStackTrace();
171
- }
172
- }
173
- };
174
- setTimerIntervel.schedule(setTimerIntervelObj, 60000, 60000);
175
175
  if (!isGooglePlayServicesAvailable()) {
176
176
  //need to write location log file...
177
177
  System.out.println("Play services not available..");
@@ -292,30 +292,38 @@ public class mInterfaceService extends Service implements com.google.android.gms
292
292
  }
293
293
 
294
294
  protected void startLocationUpdates() {
295
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
296
- if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
295
+ try {
296
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
297
+ if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
297
298
 
299
+ }
298
300
  }
301
+ PendingResult<Status> pendingResult = LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this, Looper.getMainLooper());
302
+ } catch (Exception e) {
303
+ e.printStackTrace();
299
304
  }
300
- PendingResult<Status> pendingResult = LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this, Looper.getMainLooper());
301
305
  }
302
306
 
303
307
  @Override
304
308
  public void onLocationChanged(Location location) {
305
- if (locationUpdateInd == "true") {
306
- locationUpdateInd = "false";
307
- mCurrentLocation = location;
308
- mLastUpdateTime = DateFormat.getTimeInstance().format(new Date());
309
- String lat = String.valueOf(mCurrentLocation.getLatitude());
310
- String lng = String.valueOf(mCurrentLocation.getLongitude());
311
- if (!isLocationDuplicate(lat, lng)) {
312
- new UpdateLocation(lat, lng).execute("");
313
- if (isConnected()) {
314
- new SendLocation().execute();
309
+ try {
310
+ if (locationUpdateInd == "true") {
311
+ locationUpdateInd = "false";
312
+ mCurrentLocation = location;
313
+ mLastUpdateTime = DateFormat.getTimeInstance().format(new Date());
314
+ String lat = String.valueOf(mCurrentLocation.getLatitude());
315
+ String lng = String.valueOf(mCurrentLocation.getLongitude());
316
+ if (!isLocationDuplicate(lat, lng)) {
317
+ new UpdateLocation(lat, lng).execute("");
318
+ if (isConnected()) {
319
+ new SendLocation().execute();
320
+ }
315
321
  }
322
+ String string = ("Latitude : " + lat + "Longitude : " + lng + "\n");
323
+ System.out.println(string);
316
324
  }
317
- String string = ("Latitude : " + lat + "Longitude : " + lng + "\n");
318
- System.out.println(string);
325
+ } catch (Exception e) {
326
+ e.printStackTrace();
319
327
  }
320
328
  }
321
329
 
@@ -353,8 +361,12 @@ public class mInterfaceService extends Service implements com.google.android.gms
353
361
 
354
362
  @Override
355
363
  public void onConnected(@Nullable Bundle bundle) {
356
- if (mGoogleApiClient.isConnected()) {
357
- startLocationUpdates();
364
+ try {
365
+ if (mGoogleApiClient.isConnected()) {
366
+ startLocationUpdates();
367
+ }
368
+ } catch (Exception e) {
369
+ e.printStackTrace();
358
370
  }
359
371
  }
360
372
 
@@ -459,48 +471,15 @@ public class mInterfaceService extends Service implements com.google.android.gms
459
471
  }
460
472
 
461
473
  private void getPeriodicalLocationUpdates() throws Exception {
462
- locationUpdateInd = "true";
463
- mInterfaceUtil.timerInd = "running";
464
- if (mGoogleApiClient.isConnected()) {
465
- startLocationUpdates();
466
- }
467
- }
468
-
469
- private void timeReader() throws Exception {
470
- File baseDirectory = mInterfaceUtil.rootDirectory;
471
- File exist_time_profile = new File(baseDirectory, mInterfaceUtil.packageName + "/time_profile.txt");
472
- if (exist_time_profile.exists()) {
473
- exist_time_profile.delete();
474
- }
475
- String serverTimeObj;
476
- SimpleDateFormat simpleDateFormat;
477
- StringBuilder timeObj;
478
- String currentLine;
479
- BufferedReader readerObj;
480
- JSONObject serverDateObj;
481
- timeObj = new StringBuilder();
482
- BufferedWriter writerObj;
483
- readerObj = new BufferedReader(new FileReader(new File(mInterfaceUtil.rootDirectory, "/" + mInterfaceUtil.packageName + "/" + "time_profile_encrypted.txt")));
484
- while ((currentLine = readerObj.readLine()) != null) {
485
- timeObj.append(currentLine);
474
+ try {
475
+ locationUpdateInd = "true";
476
+ mInterfaceUtil.timerInd = "running";
477
+ if (mGoogleApiClient.isConnected()) {
478
+ startLocationUpdates();
479
+ }
480
+ } catch (Exception e) {
481
+ e.printStackTrace();
486
482
  }
487
- readerObj.close();
488
- serverDateObj = new JSONObject(decrypt(timeObj.toString()));
489
- serverTimeObj = serverDateObj.optString("serverDate").toString();
490
-
491
- // ******SERVER TIME ******//
492
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy,MM,dd,HH,mm,ss", new mInterfaceUtil().locale);
493
- //String currentDateandTime = sdf.format(new Date());
494
- simpleDateFormat = new SimpleDateFormat("yyyy,MM,dd,HH,mm,ss", new mInterfaceUtil().locale);
495
- Date date = simpleDateFormat.parse(serverTimeObj);
496
- long a = date.getTime() + 60000;
497
- date.setTime(a);
498
- serverTimeObj = simpleDateFormat.format(date);
499
- serverDateObj.put("serverDate", serverTimeObj);
500
- writerObj = new BufferedWriter(new FileWriter(new File(baseDirectory, "/" + mInterfaceUtil.packageName + "/" + "time_profile_encrypted.txt")));
501
- writerObj.write(mInterfaceUtil.encrypt(serverDateObj.toString()));
502
- writerObj.flush();
503
- writerObj.close();
504
483
  }
505
484
 
506
485
  @RequiresApi(api = Build.VERSION_CODES.O)
@@ -647,51 +626,71 @@ public class mInterfaceService extends Service implements com.google.android.gms
647
626
  public void onTaskRemoved(Intent rootIntent) {
648
627
  super.onTaskRemoved(rootIntent);
649
628
 
650
- if (setQueueInterval != null) {
651
- setQueueInterval.cancel();
652
- }
653
- if (setTimerIntervel != null) {
654
- setTimerIntervel.cancel();
629
+ try {
630
+ if (setQueueInterval != null) {
631
+ setQueueInterval.cancel();
632
+ }
633
+ if (setTimerIntervel != null) {
634
+ setTimerIntervel.cancel();
635
+ }
636
+ Intent restartService = new Intent(getApplicationContext(),
637
+ this.getClass());
638
+ restartService.setPackage(getPackageName());
639
+ PendingIntent restartServicePI;
640
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
641
+ restartServicePI = PendingIntent.getService(
642
+ getApplicationContext(), 1, restartService,
643
+ PendingIntent.FLAG_IMMUTABLE);
644
+ }
645
+ else
646
+ {
647
+ restartServicePI = PendingIntent.getService(
648
+ getApplicationContext(), 1, restartService,
649
+ PendingIntent.FLAG_ONE_SHOT);
650
+ }
651
+
652
+ AlarmManager alarmService = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
653
+ alarmService.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 2000, restartServicePI);
654
+ } catch (Exception e) {
655
+ e.printStackTrace();
655
656
  }
656
- Intent restartService = new Intent(getApplicationContext(),
657
- this.getClass());
658
- restartService.setPackage(getPackageName());
659
- PendingIntent restartServicePI = PendingIntent.getService(
660
- getApplicationContext(), 1, restartService,
661
- PendingIntent.FLAG_ONE_SHOT);
662
- AlarmManager alarmService = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
663
- alarmService.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 2000, restartServicePI);
664
657
  }
665
658
 
666
659
  /* WHEN THE RAM IS LOW */
667
660
  @Override
668
661
  public void onLowMemory() {
669
662
  super.onLowMemory();
663
+ try {
664
+ if (setQueueInterval != null) {
665
+ setQueueInterval.cancel();
666
+ }
670
667
 
671
- if (setQueueInterval != null) {
672
- setQueueInterval.cancel();
673
- }
668
+ if (setTimerIntervel != null) {
669
+ setTimerIntervel.cancel();
670
+ }
674
671
 
675
- if (setTimerIntervel != null) {
676
- setTimerIntervel.cancel();
672
+ startService(new Intent(getApplicationContext(), mInterfaceService.class));
673
+ } catch (Exception e) {
674
+ e.printStackTrace();
677
675
  }
678
-
679
- startService(new Intent(getApplicationContext(), mInterfaceService.class));
680
676
  }
681
677
 
682
678
  /* USER CLICK FORCE STOP IN SETTINGS */
683
679
  @Override
684
680
  public void onDestroy() {
685
681
  super.onDestroy();
682
+ try {
683
+ if (setQueueInterval != null) {
684
+ setQueueInterval.cancel();
685
+ }
686
686
 
687
- if (setQueueInterval != null) {
688
- setQueueInterval.cancel();
689
- }
690
-
691
- if (setTimerIntervel != null) {
692
- setTimerIntervel.cancel();
687
+ if (setTimerIntervel != null) {
688
+ setTimerIntervel.cancel();
689
+ }
690
+ startService(new Intent(getApplicationContext(), mInterfaceService.class));
691
+ } catch (Exception e) {
692
+ e.printStackTrace();
693
693
  }
694
- startService(new Intent(getApplicationContext(), mInterfaceService.class));
695
694
  }
696
695
 
697
696
  public boolean isConnected() {