cordova-plugin-mserviceinterface-2.0 1.0.27 → 1.0.28

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.27",
3
+ "version": "1.0.28",
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.27">
5
+ version="1.0.28">
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>
@@ -46,9 +46,10 @@
46
46
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
47
47
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
48
48
  <uses-permission android:name="android.permission.READ_PHONE_STATE" />
49
+ <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
49
50
  </config-file>
50
51
  <config-file target="AndroidManifest.xml" parent="/manifest/application">
51
- <service android:name="com.selfservit.util.mInterfaceService" android:enabled="true" android:exported="true"/>
52
+ <service android:name="com.selfservit.util.mInterfaceService" android:foregroundServiceType="location" android:enabled="true" android:exported="true"/>
52
53
  <service
53
54
  android:name="com.selfservit.util.backgroundNotification"
54
55
  android:permission="android.permission.BIND_JOB_SERVICE"
@@ -86,6 +86,8 @@ import java.io.OutputStreamWriter;
86
86
  import java.net.HttpURLConnection;
87
87
  import java.net.URL;
88
88
  import java.text.SimpleDateFormat;
89
+ import java.util.ArrayList;
90
+ import java.util.Arrays;
89
91
  import java.util.Date;
90
92
  import java.util.List;
91
93
  import java.util.Stack;
@@ -94,6 +96,9 @@ import java.util.regex.Matcher;
94
96
  import java.util.regex.Pattern;
95
97
  import java.util.zip.ZipEntry;
96
98
  import java.util.zip.ZipInputStream;
99
+ import java.util.List;
100
+ import java.util.ArrayList;
101
+ import java.util.Arrays;
97
102
 
98
103
  import static android.app.Activity.RESULT_OK;
99
104
 
@@ -282,6 +287,12 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
282
287
  } else if (action.equals("GetPermissions")) {
283
288
  getPermissions(args, callbackContext);
284
289
  return true;
290
+ } else if (action.equals("GetLocationPermission")) {
291
+ getLocationPermission(args, callbackContext);
292
+ return true;
293
+ } else if (action.equals("CheckLocationPermission")) {
294
+ checkLocationPermission(args, callbackContext);
295
+ return true;
285
296
  } else if (action.equals("AppVersion")) {
286
297
  appVersion(callbackContext);
287
298
  return true;
@@ -943,13 +954,81 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
943
954
  callbackContext.success("file://" + mInterfaceUtil.rootDirectory + "/");
944
955
  }
945
956
 
957
+ private void checkLocationPermission(JSONArray args, CallbackContext callbackContext) {
958
+ boolean permissionGranted = true;
959
+ List<String> list;
960
+ try {
961
+ callback = callbackContext;
962
+ Context context = cordova.getActivity().getApplicationContext();
963
+ if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {
964
+ String[] permissions = args.optJSONObject(0).optString("permissions").split(",");
965
+ list = new ArrayList<String>(Arrays.asList(permissions));
966
+ permissions = list.toArray(new String[0]);
967
+
968
+ for (int i = 0; i < permissions.length; i++) {
969
+ if (ActivityCompat.checkSelfPermission(context, permissions[i]) != PackageManager.PERMISSION_GRANTED) {
970
+ permissionGranted = false;
971
+ }
972
+ };
973
+ if (!permissionGranted) {
974
+ callback.error("failure");
975
+ } else {
976
+ callback.success("success");
977
+ }
978
+ } else {
979
+ callback.success("success");
980
+ }
981
+ } catch (Exception e) {
982
+ e.printStackTrace();
983
+ }
984
+ }
985
+ private void getLocationPermission(JSONArray args, CallbackContext callbackContext) {
986
+ boolean permissionGranted = true;
987
+ List<String> list;
988
+ try {
989
+ callback = callbackContext;
990
+ Context context = cordova.getActivity().getApplicationContext();
991
+ if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {
992
+ String[] permissions = args.optJSONObject(0).optString("permissions").split(",");
993
+ list = new ArrayList<String>(Arrays.asList(permissions));
994
+ permissions = list.toArray(new String[0]);
995
+
996
+ for (int i = 0; i < permissions.length; i++) {
997
+ if (ActivityCompat.checkSelfPermission(context, permissions[i]) != PackageManager.PERMISSION_GRANTED) {
998
+ permissionGranted = false;
999
+ }
1000
+ };
1001
+ if (!permissionGranted) {
1002
+ PermissionHelper.requestPermissions(this, 111, permissions);
1003
+ } else {
1004
+ callback.success("success");
1005
+ }
1006
+ } else {
1007
+ callback.success("success");
1008
+ }
1009
+ } catch (Exception e) {
1010
+ e.printStackTrace();
1011
+ }
1012
+ }
946
1013
  private void getPermissions(JSONArray args, CallbackContext callbackContext) {
1014
+ boolean permissionGranted = true;
1015
+ List<String> list;
947
1016
  try {
948
1017
  callback = callbackContext;
949
1018
  Context context = cordova.getActivity().getApplicationContext();
950
1019
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
951
- String[]permissions = args.optJSONObject(0).optString("permissions").split(",");
952
- if ((ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE)) != PackageManager.PERMISSION_GRANTED || (ActivityCompat.checkSelfPermission(context, Manifest.permission.CAMERA)) != PackageManager.PERMISSION_GRANTED) {
1020
+ String[] permissions = args.optJSONObject(0).optString("permissions").split(",");
1021
+ if (Build.VERSION.SDK_INT != Build.VERSION_CODES.Q) {
1022
+ list = new ArrayList<String>(Arrays.asList(permissions));
1023
+ list.remove("android.permission.ACCESS_BACKGROUND_LOCATION");
1024
+ permissions = list.toArray(new String[0]);
1025
+ };
1026
+ for (int i = 0; i < permissions.length; i++) {
1027
+ if (ActivityCompat.checkSelfPermission(context, permissions[i]) != PackageManager.PERMISSION_GRANTED) {
1028
+ permissionGranted = false;
1029
+ }
1030
+ };
1031
+ if (!permissionGranted) {
953
1032
  PermissionHelper.requestPermissions(this, 1, permissions);
954
1033
  } else {
955
1034
  callback.success("success");
@@ -1757,8 +1836,12 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1757
1836
  public void onRequestPermissionResult(int requestCode, String[] permissions, int[] grantResults) {
1758
1837
  try {
1759
1838
  boolean indicator = true;
1839
+ String failedPermission = "failure";
1760
1840
  for (int i = 0; i < grantResults.length; i++) {
1761
1841
  if (grantResults[i] != 0) {
1842
+ if (permissions[i].equalsIgnoreCase("android.permission.ACCESS_BACKGROUND_LOCATION")) {
1843
+ failedPermission = "background_location";
1844
+ }
1762
1845
  indicator = false;
1763
1846
  break;
1764
1847
  }
@@ -1766,7 +1849,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1766
1849
  if (indicator) {
1767
1850
  callback.success("success");
1768
1851
  } else {
1769
- callback.error("failure");
1852
+ callback.error(failedPermission);
1770
1853
  }
1771
1854
  } catch (Exception e) {
1772
1855
  e.printStackTrace();
@@ -74,6 +74,7 @@
74
74
  - (void)OpenFileWithViewer:(CDVInvokedUrlCommand *)command;
75
75
  - (void)DeviceInfo:(CDVInvokedUrlCommand*)command;
76
76
  -(void)AppVersion:(CDVInvokedUrlCommand*)command;
77
+ -(void)CheckLocationPermission:(CDVInvokedUrlCommand*)command;
77
78
  -(void)GetPermissions:(CDVInvokedUrlCommand*)command;
78
79
  -(void)RemoveFilesFromDirectory;
79
80
  -(void)DespatchQueueMoveToServer;
@@ -967,6 +967,11 @@
967
967
  [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
968
968
  }
969
969
 
970
+ -(void)CheckLocationPermission:(CDVInvokedUrlCommand*)command {
971
+ CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
972
+ [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
973
+ }
974
+
970
975
  - (void)SendLocation {
971
976
  [self.commandDelegate runInBackground:^{
972
977
  @try {