cordova-plugin-mserviceinterface-2.0 1.0.62 → 1.0.64
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 +1 -1
- package/plugin.xml +1 -1
- package/src/android/backgroundNotification.java +84 -84
- package/src/android/mInterface.java +1442 -1438
- package/src/android/mInterfaceReceiver.java +22 -13
- package/src/android/mInterfaceService.java +45 -37
- package/src/android/mInterfaceUtil.java +174 -56
|
@@ -11,13 +11,13 @@ public class mInterfaceReceiver extends BroadcastReceiver {
|
|
|
11
11
|
//constructor
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
@
|
|
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.
|
|
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.
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
228
|
-
|
|
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
|
-
|
|
630
|
-
|
|
631
|
-
|
|
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()
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
e
|
|
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
|
-
|
|
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
|
|
|
@@ -5,6 +5,7 @@ import static com.selfservit.util.mInterface.pathComponent;
|
|
|
5
5
|
import android.annotation.TargetApi;
|
|
6
6
|
import android.app.Activity;
|
|
7
7
|
import android.content.Context;
|
|
8
|
+
import android.content.SharedPreferences;
|
|
8
9
|
import android.database.Cursor;
|
|
9
10
|
import android.graphics.Bitmap;
|
|
10
11
|
import android.graphics.BitmapFactory;
|
|
@@ -85,6 +86,8 @@ public class mInterfaceUtil {
|
|
|
85
86
|
public static String deviceID = "";
|
|
86
87
|
public static String timerInd = "";
|
|
87
88
|
|
|
89
|
+
private static final String PREFS_NAME = "app_prefs";
|
|
90
|
+
private static final String KEY_FIRST_LAUNCH = "first_launch";
|
|
88
91
|
public static String decrypt(String encryptedText) {
|
|
89
92
|
String decryptedText = "";
|
|
90
93
|
try {
|
|
@@ -157,7 +160,7 @@ public class mInterfaceUtil {
|
|
|
157
160
|
output.write(data, 0, count);
|
|
158
161
|
}
|
|
159
162
|
} catch (Exception e) {
|
|
160
|
-
callbackContext.error("
|
|
163
|
+
callbackContext.error("DownloadChatAttachment failed, Exception is : " + e.getMessage());
|
|
161
164
|
}
|
|
162
165
|
if (thumbnailInd.equalsIgnoreCase("true")) {
|
|
163
166
|
return filePath;
|
|
@@ -182,7 +185,7 @@ public class mInterfaceUtil {
|
|
|
182
185
|
String thumbnail = getFileThumbnail(filePath, extension, context);
|
|
183
186
|
callbackContext.success(thumbnail);
|
|
184
187
|
} else {
|
|
185
|
-
callbackContext.error("Failure");
|
|
188
|
+
callbackContext.error("DownloadChatAttachment: Failure");
|
|
186
189
|
}
|
|
187
190
|
} else {
|
|
188
191
|
callbackContext.success("success");
|
|
@@ -209,7 +212,7 @@ public class mInterfaceUtil {
|
|
|
209
212
|
byte[] cipherText = android.util.Base64.encode(cipher.doFinal(plainText.getBytes(StandardCharsets.UTF_8)), 0);
|
|
210
213
|
encryptedText = new String(cipherText);
|
|
211
214
|
} catch (Exception E) {
|
|
212
|
-
System.out.println("decrypt Exception : " + E.getMessage());
|
|
215
|
+
System.out.println("Failed to decrypt: Exception : " + E.getMessage());
|
|
213
216
|
}
|
|
214
217
|
return encryptedText;
|
|
215
218
|
}
|
|
@@ -222,7 +225,7 @@ public class mInterfaceUtil {
|
|
|
222
225
|
String currentLine, lastKnownLocation = "";
|
|
223
226
|
File locationFile;
|
|
224
227
|
try {
|
|
225
|
-
|
|
228
|
+
locationFile = new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/LastKnownLocation_encrypted.txt");
|
|
226
229
|
if (locationFile.exists() && !locationFile.isDirectory()) {
|
|
227
230
|
BufferedReader readerObj = new BufferedReader(new FileReader(locationFile));
|
|
228
231
|
while ((currentLine = readerObj.readLine()) != null) {
|
|
@@ -299,10 +302,10 @@ public class mInterfaceUtil {
|
|
|
299
302
|
if (filePath.exists()) {
|
|
300
303
|
filePath.delete();
|
|
301
304
|
} else {
|
|
302
|
-
callbackContext.error("No file
|
|
305
|
+
callbackContext.error("No file available & File not deleted for " + str);
|
|
303
306
|
}
|
|
304
307
|
} catch (Exception e) {
|
|
305
|
-
callbackContext.error(e.getMessage());
|
|
308
|
+
callbackContext.error("deleteMultipleFiles failed: Exception is : "+e.getMessage());
|
|
306
309
|
}
|
|
307
310
|
}
|
|
308
311
|
|
|
@@ -349,7 +352,7 @@ public class mInterfaceUtil {
|
|
|
349
352
|
}
|
|
350
353
|
callbackContext.success("success");
|
|
351
354
|
} catch (Exception e) {
|
|
352
|
-
callbackContext.error(e.getMessage());
|
|
355
|
+
callbackContext.error("copyConfigFile failed, Exception is" + e.getMessage());
|
|
353
356
|
}
|
|
354
357
|
}
|
|
355
358
|
|
|
@@ -395,7 +398,7 @@ public class mInterfaceUtil {
|
|
|
395
398
|
}
|
|
396
399
|
callbackContext.success("success");
|
|
397
400
|
} catch (Exception e) {
|
|
398
|
-
callbackContext.error(e.getMessage());
|
|
401
|
+
callbackContext.error("copyFile failed exception is : "+e.getMessage());
|
|
399
402
|
}
|
|
400
403
|
}
|
|
401
404
|
|
|
@@ -460,7 +463,7 @@ public class mInterfaceUtil {
|
|
|
460
463
|
deleteFilesFromDirectory();
|
|
461
464
|
callbackContext.success("success");
|
|
462
465
|
} catch (Exception e) {
|
|
463
|
-
callbackContext.error(e.getMessage());
|
|
466
|
+
callbackContext.error("copyAttachmentFile failed, exception is : "+e.getMessage());
|
|
464
467
|
}
|
|
465
468
|
}
|
|
466
469
|
|
|
@@ -508,7 +511,7 @@ public class mInterfaceUtil {
|
|
|
508
511
|
}
|
|
509
512
|
callbackContext.success("success");
|
|
510
513
|
} catch (Exception e) {
|
|
511
|
-
callbackContext.error(e.getMessage());
|
|
514
|
+
callbackContext.error("Move File failed, exception is : "+e.getMessage());
|
|
512
515
|
}
|
|
513
516
|
}
|
|
514
517
|
|
|
@@ -655,7 +658,8 @@ public class mInterfaceUtil {
|
|
|
655
658
|
System.out.println("No my accounts file");
|
|
656
659
|
}
|
|
657
660
|
} catch (Exception e) {
|
|
658
|
-
|
|
661
|
+
callbackContext.error(e.getMessage());
|
|
662
|
+
System.out.println("Queue processor failed, exception is : "+ e.getMessage());
|
|
659
663
|
}
|
|
660
664
|
}
|
|
661
665
|
|
|
@@ -682,20 +686,24 @@ public class mInterfaceUtil {
|
|
|
682
686
|
|
|
683
687
|
@TargetApi(Build.VERSION_CODES.KITKAT)
|
|
684
688
|
public static String getPathToNonPrimaryVolume(Context context, String tag) {
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
689
|
+
try {
|
|
690
|
+
File[] volumes = context.getExternalCacheDirs();
|
|
691
|
+
if (volumes != null) {
|
|
692
|
+
for (File volume : volumes) {
|
|
693
|
+
if (volume != null) {
|
|
694
|
+
String path = volume.getAbsolutePath();
|
|
695
|
+
if (path != null) {
|
|
696
|
+
int index = path.indexOf(tag);
|
|
697
|
+
if (index != -1) {
|
|
698
|
+
return path.substring(0, index) + tag;
|
|
699
|
+
}
|
|
694
700
|
}
|
|
695
|
-
}
|
|
696
701
|
|
|
702
|
+
}
|
|
697
703
|
}
|
|
698
704
|
}
|
|
705
|
+
} catch (Exception e) {
|
|
706
|
+
e.printStackTrace();
|
|
699
707
|
}
|
|
700
708
|
return null;
|
|
701
709
|
}
|
|
@@ -775,21 +783,30 @@ public class mInterfaceUtil {
|
|
|
775
783
|
}
|
|
776
784
|
|
|
777
785
|
public void deleteFilesFromDirectory() {
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
if (dir.
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
786
|
+
try {
|
|
787
|
+
File dir = new File(rootDirectory + "/" + mInterfaceUtil.packageName + "/" + "images");
|
|
788
|
+
if (dir.isDirectory()) {
|
|
789
|
+
if (dir.exists()) {
|
|
790
|
+
String[] children = dir.list();
|
|
791
|
+
for (int i = 0; i < children.length; i++) {
|
|
792
|
+
new File(dir, children[i]).delete();
|
|
793
|
+
}
|
|
784
794
|
}
|
|
785
795
|
}
|
|
796
|
+
} catch (Exception e) {
|
|
797
|
+
e.printStackTrace();
|
|
786
798
|
}
|
|
787
799
|
}
|
|
788
800
|
|
|
789
801
|
public String convertBitmapToString(Bitmap bitmap) {
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
802
|
+
try {
|
|
803
|
+
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
804
|
+
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
|
|
805
|
+
return Base64.encodeToString(outputStream.toByteArray(), Base64.NO_WRAP);
|
|
806
|
+
} catch (Exception e) {
|
|
807
|
+
e.printStackTrace();
|
|
808
|
+
}
|
|
809
|
+
return "";
|
|
793
810
|
}
|
|
794
811
|
|
|
795
812
|
public String getFileThumbnail(String filePath, String extension, Context context) {
|
|
@@ -1032,9 +1049,13 @@ public class mInterfaceUtil {
|
|
|
1032
1049
|
}
|
|
1033
1050
|
|
|
1034
1051
|
private void UpdateProgressBar(CallbackContext callbackContext, int progress) {
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1052
|
+
try {
|
|
1053
|
+
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, progress);
|
|
1054
|
+
pluginResult.setKeepCallback(true); // keep callback
|
|
1055
|
+
callbackContext.sendPluginResult(pluginResult);
|
|
1056
|
+
} catch (Exception e) {
|
|
1057
|
+
e.printStackTrace();
|
|
1058
|
+
}
|
|
1038
1059
|
}
|
|
1039
1060
|
|
|
1040
1061
|
public String sendFilesToServer(String filePath, String fileName, String requestURL) {
|
|
@@ -1126,10 +1147,10 @@ public class mInterfaceUtil {
|
|
|
1126
1147
|
String content = new Scanner(filePath).useDelimiter("\\A").next();
|
|
1127
1148
|
callbackContext.success(content);
|
|
1128
1149
|
} else {
|
|
1129
|
-
callbackContext.error("There is no file at the given path
|
|
1150
|
+
callbackContext.error("There is no file at the given path. Path: " + filePath);
|
|
1130
1151
|
}
|
|
1131
1152
|
} catch (Exception e) {
|
|
1132
|
-
callbackContext.error(e.getMessage());
|
|
1153
|
+
callbackContext.error("unable to readFile, Exception is: "+e.getMessage());
|
|
1133
1154
|
}
|
|
1134
1155
|
}
|
|
1135
1156
|
|
|
@@ -1141,10 +1162,10 @@ public class mInterfaceUtil {
|
|
|
1141
1162
|
filePath.delete();
|
|
1142
1163
|
callbackContext.success();
|
|
1143
1164
|
} else {
|
|
1144
|
-
callbackContext.error("File not deleted
|
|
1165
|
+
callbackContext.error("File not deleted, Path: "+baseDirectory + "/" + args.getJSONObject(0).optString("filePath"));
|
|
1145
1166
|
}
|
|
1146
1167
|
} catch (Exception e) {
|
|
1147
|
-
callbackContext.error(e.getMessage());
|
|
1168
|
+
callbackContext.error("delete file failed, exception is : "+e.getMessage());
|
|
1148
1169
|
}
|
|
1149
1170
|
}
|
|
1150
1171
|
|
|
@@ -1166,7 +1187,11 @@ public class mInterfaceUtil {
|
|
|
1166
1187
|
fileWriterObj.close();
|
|
1167
1188
|
callbackContext.success();
|
|
1168
1189
|
} catch (Exception e) {
|
|
1169
|
-
|
|
1190
|
+
try {
|
|
1191
|
+
callbackContext.error("create File failed for path:"+ args.getJSONObject(0).optString("filePath") +" , exception is : "+e.getMessage());
|
|
1192
|
+
} catch (JSONException ex) {
|
|
1193
|
+
e.printStackTrace();
|
|
1194
|
+
}
|
|
1170
1195
|
}
|
|
1171
1196
|
}
|
|
1172
1197
|
|
|
@@ -1177,7 +1202,11 @@ public class mInterfaceUtil {
|
|
|
1177
1202
|
boolean sss = filePath.exists();
|
|
1178
1203
|
callbackContext.success(sss ? "true" : "false");
|
|
1179
1204
|
} catch (Exception e) {
|
|
1180
|
-
|
|
1205
|
+
try {
|
|
1206
|
+
callbackContext.error("validate file failed for path:"+baseDirectory + "/" + args.getJSONObject(0).optString("filePath")+" , exception is : "+e.getMessage());
|
|
1207
|
+
} catch (JSONException ex) {
|
|
1208
|
+
e.printStackTrace();
|
|
1209
|
+
}
|
|
1181
1210
|
}
|
|
1182
1211
|
}
|
|
1183
1212
|
|
|
@@ -1192,7 +1221,11 @@ public class mInterfaceUtil {
|
|
|
1192
1221
|
}
|
|
1193
1222
|
callbackContext.success();
|
|
1194
1223
|
} catch (Exception e) {
|
|
1195
|
-
|
|
1224
|
+
try {
|
|
1225
|
+
callbackContext.error("create directory failed for " + args.getJSONObject(0).optString("filePath") +", exception is : "+e.getMessage());
|
|
1226
|
+
} catch (JSONException ex) {
|
|
1227
|
+
e.printStackTrace();
|
|
1228
|
+
}
|
|
1196
1229
|
}
|
|
1197
1230
|
}
|
|
1198
1231
|
|
|
@@ -1202,31 +1235,39 @@ public class mInterfaceUtil {
|
|
|
1202
1235
|
try {
|
|
1203
1236
|
String fileName = args.getJSONObject(0).optString("filePath");
|
|
1204
1237
|
if (fileName.equals("")) {
|
|
1205
|
-
callbackContext.error("Given directory path is empty.");
|
|
1238
|
+
callbackContext.error("deleteDirectory: Given directory path is empty. path: "+args.getJSONObject(0).optString("filePath"));
|
|
1206
1239
|
} else {
|
|
1207
1240
|
File dir = new File(rootDirectory + "/" + fileName);
|
|
1208
1241
|
if (dir.exists()) {
|
|
1209
1242
|
deleteRecursive(dir);
|
|
1210
1243
|
callbackContext.success();
|
|
1211
1244
|
} else {
|
|
1212
|
-
callbackContext.error("File does not exists");
|
|
1245
|
+
callbackContext.error("deleteDirectory: File does not exists in "+args.getJSONObject(0).optString("filePath"));
|
|
1213
1246
|
}
|
|
1214
1247
|
|
|
1215
1248
|
}
|
|
1216
1249
|
} catch (Exception e) {
|
|
1217
|
-
|
|
1250
|
+
try {
|
|
1251
|
+
callbackContext.error("delete directory failed for "+args.getJSONObject(0).optString("filePath")+", exception is : "+e.getMessage());
|
|
1252
|
+
} catch (JSONException ex) {
|
|
1253
|
+
throw new RuntimeException(ex);
|
|
1254
|
+
}
|
|
1218
1255
|
}
|
|
1219
1256
|
}
|
|
1220
1257
|
|
|
1221
1258
|
public void deleteRecursive(File fileOrDirectory) {
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1259
|
+
try {
|
|
1260
|
+
if (fileOrDirectory.isDirectory()) {
|
|
1261
|
+
for (File child : fileOrDirectory.listFiles()) {
|
|
1262
|
+
System.out.println("Child directory path: " + child);
|
|
1263
|
+
deleteRecursive(child);
|
|
1264
|
+
}
|
|
1226
1265
|
}
|
|
1227
|
-
}
|
|
1228
1266
|
|
|
1229
|
-
|
|
1267
|
+
fileOrDirectory.delete();
|
|
1268
|
+
} catch (Exception e) {
|
|
1269
|
+
e.printStackTrace();
|
|
1270
|
+
}
|
|
1230
1271
|
}
|
|
1231
1272
|
|
|
1232
1273
|
private static final int BUFFER_SIZE = 6 * 1024;
|
|
@@ -1267,7 +1308,7 @@ public class mInterfaceUtil {
|
|
|
1267
1308
|
callbackContext.success();
|
|
1268
1309
|
} catch (Exception e) {
|
|
1269
1310
|
e.printStackTrace();
|
|
1270
|
-
callbackContext.error(e.getMessage());
|
|
1311
|
+
callbackContext.error("unzip failed, exception is : "+e.getMessage());
|
|
1271
1312
|
}
|
|
1272
1313
|
}
|
|
1273
1314
|
|
|
@@ -1293,7 +1334,11 @@ public class mInterfaceUtil {
|
|
|
1293
1334
|
callbackContext.success(fileNames.length() > 0 ? fileNames.substring(0, fileNames.length() - 1) : "");
|
|
1294
1335
|
}
|
|
1295
1336
|
} catch (Exception e) {
|
|
1296
|
-
|
|
1337
|
+
try {
|
|
1338
|
+
callbackContext.error("getSubDirectoryList failed for "+args.getJSONObject(0).optString("filePath")+", exception is : "+e.getMessage());
|
|
1339
|
+
} catch (JSONException ex) {
|
|
1340
|
+
e.printStackTrace();
|
|
1341
|
+
}
|
|
1297
1342
|
}
|
|
1298
1343
|
}
|
|
1299
1344
|
|
|
@@ -1319,7 +1364,11 @@ public class mInterfaceUtil {
|
|
|
1319
1364
|
callbackContext.success(fileNames.length() > 0 ? fileNames.substring(0, fileNames.length() - 1) : "");
|
|
1320
1365
|
}
|
|
1321
1366
|
} catch (Exception e) {
|
|
1322
|
-
|
|
1367
|
+
try {
|
|
1368
|
+
callbackContext.error("getFileList failed for "+args.getJSONObject(0).optString("filePath")+", exception is : "+e.getMessage());
|
|
1369
|
+
} catch (JSONException ex) {
|
|
1370
|
+
e.printStackTrace();
|
|
1371
|
+
}
|
|
1323
1372
|
}
|
|
1324
1373
|
}
|
|
1325
1374
|
|
|
@@ -1359,7 +1408,7 @@ public class mInterfaceUtil {
|
|
|
1359
1408
|
}
|
|
1360
1409
|
} catch (Exception e) {
|
|
1361
1410
|
System.out.println(e.getMessage());
|
|
1362
|
-
callbackContext.
|
|
1411
|
+
callbackContext.error("getAppStateInfo failed, exception is : "+e.getMessage());
|
|
1363
1412
|
}
|
|
1364
1413
|
}
|
|
1365
1414
|
|
|
@@ -1678,9 +1727,78 @@ public class mInterfaceUtil {
|
|
|
1678
1727
|
return true;
|
|
1679
1728
|
}
|
|
1680
1729
|
|
|
1730
|
+
|
|
1731
|
+
|
|
1681
1732
|
public static boolean isConnected(Context applicationContext) {
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1733
|
+
try {
|
|
1734
|
+
ConnectivityManager online = (ConnectivityManager) applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
1735
|
+
NetworkInfo networkInfo = online.getActiveNetworkInfo();
|
|
1736
|
+
return networkInfo != null && networkInfo.isConnected();
|
|
1737
|
+
} catch (Exception e) {
|
|
1738
|
+
e.printStackTrace();
|
|
1739
|
+
}
|
|
1740
|
+
return false;
|
|
1685
1741
|
}
|
|
1742
|
+
|
|
1743
|
+
public static void appCleanUp(CallbackContext callbackContext, Context applicationContext){
|
|
1744
|
+
try {
|
|
1745
|
+
if (isFirstLaunch(applicationContext)) {
|
|
1746
|
+
performCleanup(applicationContext);
|
|
1747
|
+
setFirstLaunch(applicationContext, false);
|
|
1748
|
+
}
|
|
1749
|
+
callbackContext.success("Success");
|
|
1750
|
+
} catch (Exception e) {
|
|
1751
|
+
e.printStackTrace();
|
|
1752
|
+
callbackContext.error("AppCleanUp Failed, Exception is" + e.getMessage());
|
|
1753
|
+
}
|
|
1754
|
+
}
|
|
1755
|
+
|
|
1756
|
+
private static void performCleanup(Context context) {
|
|
1757
|
+
// Delete files in the internal storage directory
|
|
1758
|
+
File internalFilesDir = context.getFilesDir();
|
|
1759
|
+
deleteDirectory(internalFilesDir);
|
|
1760
|
+
// Delete files in the cache directory
|
|
1761
|
+
File cacheDir = context.getCacheDir();
|
|
1762
|
+
deleteDirectory(cacheDir);
|
|
1763
|
+
// Delete files in the external storage directory
|
|
1764
|
+
File externalFilesDir = context.getExternalFilesDir(null);
|
|
1765
|
+
if (externalFilesDir != null) {
|
|
1766
|
+
deleteDirectory(externalFilesDir);
|
|
1767
|
+
}
|
|
1768
|
+
// Delete files in the external cache directory
|
|
1769
|
+
File externalCacheDir = context.getExternalCacheDir();
|
|
1770
|
+
if (externalCacheDir != null) {
|
|
1771
|
+
deleteDirectory(externalCacheDir);
|
|
1772
|
+
}
|
|
1773
|
+
|
|
1774
|
+
}
|
|
1775
|
+
|
|
1776
|
+
public static boolean isFirstLaunch(Context context) {
|
|
1777
|
+
SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
|
|
1778
|
+
return prefs.getBoolean(KEY_FIRST_LAUNCH, true);
|
|
1779
|
+
}
|
|
1780
|
+
public static void setFirstLaunch(Context context, boolean value) {
|
|
1781
|
+
SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
|
|
1782
|
+
SharedPreferences.Editor editor = prefs.edit();
|
|
1783
|
+
editor.putBoolean(KEY_FIRST_LAUNCH, value);
|
|
1784
|
+
editor.apply();
|
|
1785
|
+
}
|
|
1786
|
+
private static void deleteDirectory(File dir) {
|
|
1787
|
+
if (dir != null && dir.isDirectory()) {
|
|
1788
|
+
File[] files = dir.listFiles();
|
|
1789
|
+
if (files != null) {
|
|
1790
|
+
for (File file : files) {
|
|
1791
|
+
if (file.isDirectory()) {
|
|
1792
|
+
deleteDirectory(file);
|
|
1793
|
+
} else {
|
|
1794
|
+
boolean deleted = file.delete();
|
|
1795
|
+
if (!deleted) {
|
|
1796
|
+
Log.e("FileUtils", "Failed to delete file: " + file.getAbsolutePath());
|
|
1797
|
+
}
|
|
1798
|
+
}
|
|
1799
|
+
}
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
}
|
|
1803
|
+
|
|
1686
1804
|
}
|