cordova-plugin-mserviceinterface-2.0 1.0.61 → 1.0.63

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.
@@ -11,13 +11,13 @@ public class mInterfaceReceiver extends BroadcastReceiver {
11
11
  //constructor
12
12
  }
13
13
 
14
- @ Override
14
+ @Override
15
15
  public void onReceive(Context context, Intent intent) {
16
16
  try {
17
17
  if (intent.getAction().equalsIgnoreCase(Intent.ACTION_BOOT_COMPLETED)) {
18
18
  Intent serviceIntent = new Intent(context, mInterfaceService.class);
19
19
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
20
- context.startForegroundService(serviceIntent);
20
+ context.startService(serviceIntent);
21
21
  } else {
22
22
  context.startService(serviceIntent);
23
23
  }
@@ -26,33 +26,42 @@ public class mInterfaceReceiver extends BroadcastReceiver {
26
26
  if (!isServiceRunning(context) || !isProcessRunning(context)) {
27
27
  Intent serviceIntent = new Intent(context, mInterfaceService.class);
28
28
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
29
- context.startForegroundService(serviceIntent);
29
+ context.startService(serviceIntent);
30
30
  } else {
31
31
  context.startService(serviceIntent);
32
32
  }
33
33
  }
34
34
  }
35
35
 
36
- }catch (Exception e){
36
+ } catch (Exception e) {
37
37
  e.printStackTrace();
38
38
  }
39
39
  }
40
+
40
41
  private boolean isServiceRunning(Context context) {
41
- ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
42
- for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
43
- if (mInterfaceService.class.getName().equals(service.service.getClassName())) {
44
- return true;
42
+ try {
43
+ ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
44
+ for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
45
+ if (mInterfaceService.class.getName().equals(service.service.getClassName())) {
46
+ return true;
47
+ }
45
48
  }
49
+ } catch (SecurityException e) {
50
+ e.printStackTrace();
46
51
  }
47
-
48
52
  return false;
49
53
  }
54
+
50
55
  private boolean isProcessRunning(Context context) {
51
- ActivityManager manager1 = (ActivityManager)context.getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
52
- for (ActivityManager.RunningAppProcessInfo processInfo : manager1.getRunningAppProcesses()) {
53
- if (processInfo.processName.equals(context.getPackageName())) {
54
- return true;
56
+ try {
57
+ ActivityManager manager1 = (ActivityManager) context.getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
58
+ for (ActivityManager.RunningAppProcessInfo processInfo : manager1.getRunningAppProcesses()) {
59
+ if (processInfo.processName.equals(context.getPackageName())) {
60
+ return true;
61
+ }
55
62
  }
63
+ } catch (Exception e) {
64
+ e.printStackTrace();
56
65
  }
57
66
  return false;
58
67
  }
@@ -187,12 +187,6 @@ public class mInterfaceService extends Service implements com.google.android.gms
187
187
  return START_STICKY;
188
188
  }
189
189
 
190
-
191
- private void showToast() {
192
- Handler handler = new Handler(Looper.getMainLooper());
193
- handler.post(() -> Toast.makeText(mInterfaceService.this, "Background service is running!", Toast.LENGTH_SHORT).show());
194
- }
195
-
196
190
  public static void handleAppStateTimer(String status) {
197
191
  try {
198
192
  if (status.equalsIgnoreCase("failure")) {
@@ -224,8 +218,13 @@ public class mInterfaceService extends Service implements com.google.android.gms
224
218
  }
225
219
 
226
220
  private boolean isGooglePlayServicesAvailable() {
227
- int resultCode = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this);
228
- return ConnectionResult.SUCCESS == resultCode;
221
+ try {
222
+ int resultCode = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this);
223
+ return ConnectionResult.SUCCESS == resultCode;
224
+ } catch (Exception e) {
225
+ e.printStackTrace();
226
+ }
227
+ return false;
229
228
  }
230
229
 
231
230
  public void createLocationRequest() {
@@ -245,13 +244,13 @@ public class mInterfaceService extends Service implements com.google.android.gms
245
244
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
246
245
  if (context.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
247
246
  isPermissionGranted = false;
248
- }else{
247
+ } else {
249
248
  isPermissionGranted = true;
250
249
  }
251
- }else{
250
+ } else {
252
251
  isPermissionGranted = true;
253
252
  }
254
- if(isPermissionGranted){
253
+ if (isPermissionGranted) {
255
254
  PendingResult<Status> pendingResult = LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this, Looper.getMainLooper());
256
255
  }
257
256
  } catch (Exception e) {
@@ -626,37 +625,46 @@ public class mInterfaceService extends Service implements com.google.android.gms
626
625
 
627
626
 
628
627
  public boolean isConnected() {
629
- ConnectivityManager online = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
630
- NetworkInfo networkInfo = online.getActiveNetworkInfo();
631
- return networkInfo != null && networkInfo.isConnected();
628
+ try {
629
+ ConnectivityManager online = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
630
+ NetworkInfo networkInfo = online.getActiveNetworkInfo();
631
+ return networkInfo != null && networkInfo.isConnected();
632
+ } catch (Exception e) {
633
+ e.printStackTrace();
634
+ }
635
+ return false;
632
636
  }
633
637
 
634
638
 
635
- public void update() throws IOException, JSONException {
636
- TimerTask timerTask = new TimerTask() {
637
- @Override
638
- public void run() {
639
- try {
640
- getPeriodicalLocationUpdates();
641
- } catch (Exception e) {
642
- e.printStackTrace();
639
+ public void update() {
640
+ try {
641
+ TimerTask timerTask = new TimerTask() {
642
+ @Override
643
+ public void run() {
644
+ try {
645
+ getPeriodicalLocationUpdates();
646
+ } catch (Exception e) {
647
+ e.printStackTrace();
648
+ }
643
649
  }
650
+ };
651
+ String currentLine;
652
+ StringBuilder locConfigObj = new StringBuilder();
653
+ File baseDirectory = mInterfaceUtil.rootDirectory;
654
+ File locConfigFile = new File(baseDirectory, "/" + mInterfaceUtil.packageName + "/location_configuration.txt");
655
+ if (locConfigFile.exists()) {
656
+ BufferedReader readerObj = new BufferedReader(new FileReader(locConfigFile));
657
+ while ((currentLine = readerObj.readLine()) != null) {
658
+ locConfigObj.append(currentLine);
659
+ }
660
+ readerObj.close();
661
+ JSONObject serverDateObj = new JSONObject(decrypt(locConfigObj.toString()));
662
+ setLocationTimeInterval.cancel();
663
+ 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));
644
665
  }
645
- };
646
- String currentLine;
647
- StringBuilder locConfigObj = new StringBuilder();
648
- File baseDirectory = mInterfaceUtil.rootDirectory;
649
- File locConfigFile = new File(baseDirectory, "/" + mInterfaceUtil.packageName + "/location_configuration.txt");
650
- if (locConfigFile.exists()) {
651
- BufferedReader readerObj = new BufferedReader(new FileReader(locConfigFile));
652
- while ((currentLine = readerObj.readLine()) != null) {
653
- locConfigObj.append(currentLine);
654
- }
655
- readerObj.close();
656
- JSONObject serverDateObj = new JSONObject(decrypt(locConfigObj.toString()));
657
- setLocationTimeInterval.cancel();
658
- setLocationTimeInterval = new Timer();
659
- setLocationTimeInterval.schedule(timerTask, (Integer.parseInt(serverDateObj.optString("location_fetch_interval_in_seconds")) * 1000L), (Integer.parseInt(serverDateObj.optString("location_fetch_interval_in_seconds")) * 1000L));
666
+ } catch (Exception e) {
667
+ e.printStackTrace();
660
668
  }
661
669
  }
662
670
 
@@ -222,7 +222,7 @@ public class mInterfaceUtil {
222
222
  String currentLine, lastKnownLocation = "";
223
223
  File locationFile;
224
224
  try {
225
- locationFile = new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/LastKnownLocation_encrypted.txt");
225
+ locationFile = new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/LastKnownLocation_encrypted.txt");
226
226
  if (locationFile.exists() && !locationFile.isDirectory()) {
227
227
  BufferedReader readerObj = new BufferedReader(new FileReader(locationFile));
228
228
  while ((currentLine = readerObj.readLine()) != null) {
@@ -655,6 +655,7 @@ public class mInterfaceUtil {
655
655
  System.out.println("No my accounts file");
656
656
  }
657
657
  } catch (Exception e) {
658
+ callbackContext.error(e.getMessage());
658
659
  System.out.println("out exception : " + e.getMessage());
659
660
  }
660
661
  }
@@ -682,20 +683,24 @@ public class mInterfaceUtil {
682
683
 
683
684
  @TargetApi(Build.VERSION_CODES.KITKAT)
684
685
  public static String getPathToNonPrimaryVolume(Context context, String tag) {
685
- File[] volumes = context.getExternalCacheDirs();
686
- if (volumes != null) {
687
- for (File volume : volumes) {
688
- if (volume != null) {
689
- String path = volume.getAbsolutePath();
690
- if (path != null) {
691
- int index = path.indexOf(tag);
692
- if (index != -1) {
693
- return path.substring(0, index) + tag;
686
+ try {
687
+ File[] volumes = context.getExternalCacheDirs();
688
+ if (volumes != null) {
689
+ for (File volume : volumes) {
690
+ if (volume != null) {
691
+ String path = volume.getAbsolutePath();
692
+ if (path != null) {
693
+ int index = path.indexOf(tag);
694
+ if (index != -1) {
695
+ return path.substring(0, index) + tag;
696
+ }
694
697
  }
695
- }
696
698
 
699
+ }
697
700
  }
698
701
  }
702
+ } catch (Exception e) {
703
+ e.printStackTrace();
699
704
  }
700
705
  return null;
701
706
  }
@@ -775,21 +780,30 @@ public class mInterfaceUtil {
775
780
  }
776
781
 
777
782
  public void deleteFilesFromDirectory() {
778
- File dir = new File(rootDirectory + "/" + mInterfaceUtil.packageName + "/" + "images");
779
- if (dir.isDirectory()) {
780
- if (dir.exists()) {
781
- String[] children = dir.list();
782
- for (int i = 0; i < children.length; i++) {
783
- new File(dir, children[i]).delete();
783
+ try {
784
+ File dir = new File(rootDirectory + "/" + mInterfaceUtil.packageName + "/" + "images");
785
+ if (dir.isDirectory()) {
786
+ if (dir.exists()) {
787
+ String[] children = dir.list();
788
+ for (int i = 0; i < children.length; i++) {
789
+ new File(dir, children[i]).delete();
790
+ }
784
791
  }
785
792
  }
793
+ } catch (Exception e) {
794
+ e.printStackTrace();
786
795
  }
787
796
  }
788
797
 
789
798
  public String convertBitmapToString(Bitmap bitmap) {
790
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
791
- bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
792
- return Base64.encodeToString(outputStream.toByteArray(), Base64.NO_WRAP);
799
+ try {
800
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
801
+ bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
802
+ return Base64.encodeToString(outputStream.toByteArray(), Base64.NO_WRAP);
803
+ } catch (Exception e) {
804
+ e.printStackTrace();
805
+ }
806
+ return "";
793
807
  }
794
808
 
795
809
  public String getFileThumbnail(String filePath, String extension, Context context) {
@@ -1032,9 +1046,13 @@ public class mInterfaceUtil {
1032
1046
  }
1033
1047
 
1034
1048
  private void UpdateProgressBar(CallbackContext callbackContext, int progress) {
1035
- PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, progress);
1036
- pluginResult.setKeepCallback(true); // keep callback
1037
- callbackContext.sendPluginResult(pluginResult);
1049
+ try {
1050
+ PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, progress);
1051
+ pluginResult.setKeepCallback(true); // keep callback
1052
+ callbackContext.sendPluginResult(pluginResult);
1053
+ } catch (Exception e) {
1054
+ e.printStackTrace();
1055
+ }
1038
1056
  }
1039
1057
 
1040
1058
  public String sendFilesToServer(String filePath, String fileName, String requestURL) {
@@ -1219,14 +1237,18 @@ public class mInterfaceUtil {
1219
1237
  }
1220
1238
 
1221
1239
  public void deleteRecursive(File fileOrDirectory) {
1222
- if (fileOrDirectory.isDirectory()) {
1223
- for (File child : fileOrDirectory.listFiles()) {
1224
- System.out.println("Child directory path: " + child);
1225
- deleteRecursive(child);
1240
+ try {
1241
+ if (fileOrDirectory.isDirectory()) {
1242
+ for (File child : fileOrDirectory.listFiles()) {
1243
+ System.out.println("Child directory path: " + child);
1244
+ deleteRecursive(child);
1245
+ }
1226
1246
  }
1227
- }
1228
1247
 
1229
- fileOrDirectory.delete();
1248
+ fileOrDirectory.delete();
1249
+ } catch (Exception e) {
1250
+ throw new RuntimeException(e);
1251
+ }
1230
1252
  }
1231
1253
 
1232
1254
  private static final int BUFFER_SIZE = 6 * 1024;
@@ -1359,7 +1381,7 @@ public class mInterfaceUtil {
1359
1381
  }
1360
1382
  } catch (Exception e) {
1361
1383
  System.out.println(e.getMessage());
1362
- callbackContext.success("");
1384
+ callbackContext.error(e.getMessage());
1363
1385
  }
1364
1386
  }
1365
1387
 
@@ -1679,8 +1701,13 @@ public class mInterfaceUtil {
1679
1701
  }
1680
1702
 
1681
1703
  public static boolean isConnected(Context applicationContext) {
1682
- ConnectivityManager online = (ConnectivityManager) applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE);
1683
- NetworkInfo networkInfo = online.getActiveNetworkInfo();
1684
- return networkInfo != null && networkInfo.isConnected();
1704
+ try {
1705
+ ConnectivityManager online = (ConnectivityManager) applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE);
1706
+ NetworkInfo networkInfo = online.getActiveNetworkInfo();
1707
+ return networkInfo != null && networkInfo.isConnected();
1708
+ } catch (Exception e) {
1709
+ e.printStackTrace();
1710
+ }
1711
+ return false;
1685
1712
  }
1686
1713
  }