cordova-plugin-mserviceinterface-2.0 1.0.26 → 1.0.27
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 +28 -28
- package/plugin.xml +153 -153
- package/src/android/CallbackProgressDialog.java +53 -53
- package/src/android/FileProvider.java +7 -7
- package/src/android/backgroundNotification.java +120 -120
- package/src/android/doubleogradle.gradle +5 -5
- package/src/android/mInterface.java +2123 -2087
- package/src/android/mInterfaceReceiver.java +59 -59
- package/src/android/mInterfaceService.java +749 -749
- package/src/android/mInterfaceUtil.java +1686 -1686
- package/src/android/res/xml/network_security_config.xml +8 -8
- package/src/android/res/xml/opener_paths.xml +16 -16
- package/src/ios/InternetConnection.h +64 -64
- package/src/ios/InternetConnection.m +242 -242
- package/src/ios/SSZipArchive.h +146 -146
- package/src/ios/SSZipArchive.m +1180 -1180
- package/src/ios/SSZipCommon.h +66 -66
- package/src/ios/UICKeyChainStore.h +64 -64
- package/src/ios/UICKeyChainStore.m +434 -434
- package/src/ios/XMLConverter.h +61 -61
- package/src/ios/XMLConverter.m +243 -243
- package/src/ios/ZipArchive.h +19 -19
- package/src/ios/aes/aes.h +270 -270
- package/src/ios/aes/aes_ni.c +687 -687
- package/src/ios/aes/aes_ni.h +59 -59
- package/src/ios/aes/aescrypt.c +301 -301
- package/src/ios/aes/aeskey.c +554 -554
- package/src/ios/aes/aesopt.h +776 -776
- package/src/ios/aes/aestab.c +418 -418
- package/src/ios/aes/aestab.h +173 -173
- package/src/ios/aes/brg_endian.h +127 -127
- package/src/ios/aes/brg_types.h +191 -191
- package/src/ios/aes/fileenc.c +145 -145
- package/src/ios/aes/fileenc.h +121 -121
- package/src/ios/aes/hmac.c +209 -209
- package/src/ios/aes/hmac.h +119 -119
- package/src/ios/aes/prng.c +155 -155
- package/src/ios/aes/prng.h +82 -82
- package/src/ios/aes/pwd2key.c +181 -181
- package/src/ios/aes/pwd2key.h +45 -45
- package/src/ios/aes/sha1.c +283 -283
- package/src/ios/aes/sha1.h +72 -72
- package/src/ios/minizip/crypt.c +146 -146
- package/src/ios/minizip/crypt.h +66 -66
- package/src/ios/minizip/ioapi.c +353 -353
- package/src/ios/minizip/ioapi.h +154 -154
- package/src/ios/minizip/ioapi_buf.c +452 -452
- package/src/ios/minizip/ioapi_buf.h +52 -52
- package/src/ios/minizip/ioapi_mem.c +167 -167
- package/src/ios/minizip/ioapi_mem.h +52 -52
- package/src/ios/minizip/minishared.c +292 -292
- package/src/ios/minizip/minishared.h +50 -50
- package/src/ios/minizip/unzip.c +2007 -2007
- package/src/ios/minizip/unzip.h +254 -254
- package/src/ios/minizip/zip.c +2007 -2007
- package/src/ios/minizip/zip.h +215 -215
- package/www/mInterface.js +3 -3
|
@@ -1,1687 +1,1687 @@
|
|
|
1
|
-
package com.selfservit.util;
|
|
2
|
-
|
|
3
|
-
import android.annotation.TargetApi;
|
|
4
|
-
import android.app.Activity;
|
|
5
|
-
import android.content.ContentUris;
|
|
6
|
-
import android.content.ContentValues;
|
|
7
|
-
import android.content.Context;
|
|
8
|
-
import android.database.Cursor;
|
|
9
|
-
import android.graphics.Bitmap;
|
|
10
|
-
import android.graphics.BitmapFactory;
|
|
11
|
-
import android.location.LocationListener;
|
|
12
|
-
import android.location.LocationManager;
|
|
13
|
-
import android.media.MediaMetadataRetriever;
|
|
14
|
-
import android.media.MediaScannerConnection;
|
|
15
|
-
import android.media.ThumbnailUtils;
|
|
16
|
-
import android.net.ConnectivityManager;
|
|
17
|
-
import android.net.NetworkInfo;
|
|
18
|
-
import android.net.Uri;
|
|
19
|
-
import android.os.AsyncTask;
|
|
20
|
-
import android.os.Build;
|
|
21
|
-
import android.os.Environment;
|
|
22
|
-
import android.provider.MediaStore;
|
|
23
|
-
import android.support.annotation.RequiresApi;
|
|
24
|
-
import android.util.Base64;
|
|
25
|
-
import android.util.Log;
|
|
26
|
-
import android.widget.Toast;
|
|
27
|
-
|
|
28
|
-
import org.apache.cordova.CallbackContext;
|
|
29
|
-
import org.apache.cordova.PluginResult;
|
|
30
|
-
import org.json.JSONArray;
|
|
31
|
-
import org.json.JSONException;
|
|
32
|
-
import org.json.JSONObject;
|
|
33
|
-
|
|
34
|
-
import java.io.BufferedInputStream;
|
|
35
|
-
import java.io.BufferedReader;
|
|
36
|
-
import java.io.BufferedWriter;
|
|
37
|
-
import java.io.ByteArrayOutputStream;
|
|
38
|
-
import java.io.DataOutputStream;
|
|
39
|
-
import java.io.File;
|
|
40
|
-
import java.io.FileInputStream;
|
|
41
|
-
import java.io.FileOutputStream;
|
|
42
|
-
import java.io.FileReader;
|
|
43
|
-
import java.io.FileWriter;
|
|
44
|
-
import java.io.FilenameFilter;
|
|
45
|
-
import java.io.IOException;
|
|
46
|
-
import java.io.InputStream;
|
|
47
|
-
import java.io.InputStreamReader;
|
|
48
|
-
import java.io.OutputStream;
|
|
49
|
-
import java.io.OutputStreamWriter;
|
|
50
|
-
import java.net.HttpURLConnection;
|
|
51
|
-
import java.net.URL;
|
|
52
|
-
import java.text.SimpleDateFormat;
|
|
53
|
-
import java.util.Arrays;
|
|
54
|
-
import java.util.Date;
|
|
55
|
-
import java.util.Locale;
|
|
56
|
-
import java.util.Scanner;
|
|
57
|
-
import java.util.zip.ZipEntry;
|
|
58
|
-
import java.util.zip.ZipInputStream;
|
|
59
|
-
|
|
60
|
-
import javax.crypto.Cipher;
|
|
61
|
-
import javax.crypto.spec.IvParameterSpec;
|
|
62
|
-
import javax.crypto.spec.SecretKeySpec;
|
|
63
|
-
|
|
64
|
-
import static com.selfservit.util.mInterface.pathComponent;
|
|
65
|
-
|
|
66
|
-
public class mInterfaceUtil {
|
|
67
|
-
|
|
68
|
-
LocationManager locationManager;
|
|
69
|
-
LocationListener locationListener;
|
|
70
|
-
public static String packageName = "";
|
|
71
|
-
public static File rootDirectory;
|
|
72
|
-
public static final Locale locale = Locale.US;
|
|
73
|
-
private static final String encryptionKey = "8080808080808080";
|
|
74
|
-
private static final String characterEncoding = "UTF-8";
|
|
75
|
-
private static final String cipherTransformation = "AES/CBC/PKCS5PADDING";
|
|
76
|
-
private static final String aesEncryptionAlgorithem = "AES";
|
|
77
|
-
//Account information
|
|
78
|
-
public static String app_id = "";
|
|
79
|
-
public static String platform = "";
|
|
80
|
-
public static String store = "";
|
|
81
|
-
public static String sessionID = "";
|
|
82
|
-
public static String localeID = "";
|
|
83
|
-
public static String clientID = "";
|
|
84
|
-
public static String countryCode = "";
|
|
85
|
-
public static String userID = "";
|
|
86
|
-
public static String employeeId = "";
|
|
87
|
-
public static String cvsUrl = "";
|
|
88
|
-
public static String clientUrl = "";
|
|
89
|
-
public static String deviceID = "";
|
|
90
|
-
public static String timerInd = "";
|
|
91
|
-
|
|
92
|
-
@RequiresApi(api = Build.VERSION_CODES.O)
|
|
93
|
-
public static String decrypt(String encryptedText) {
|
|
94
|
-
String decryptedText = "";
|
|
95
|
-
try {
|
|
96
|
-
Cipher cipher = Cipher.getInstance(cipherTransformation);
|
|
97
|
-
byte[] key = encryptionKey.getBytes(characterEncoding);
|
|
98
|
-
SecretKeySpec secretKey = new SecretKeySpec(key, aesEncryptionAlgorithem);
|
|
99
|
-
IvParameterSpec ivparameterspec = new IvParameterSpec(key);
|
|
100
|
-
cipher.init(Cipher.DECRYPT_MODE, secretKey, ivparameterspec);
|
|
101
|
-
byte[] cipherText = android.util.Base64.decode(encryptedText, 0);
|
|
102
|
-
decryptedText = new String(cipher.doFinal(cipherText), "UTF-8");
|
|
103
|
-
} catch (Exception E) {
|
|
104
|
-
System.out.println("decrypt Exception : " + E.getMessage());
|
|
105
|
-
}
|
|
106
|
-
return decryptedText;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
public void DownloadChatAttachment(String requestURL, String filePath, String thumbnailInd, Context context, CallbackContext callbackContext, Activity activity) {
|
|
110
|
-
try {
|
|
111
|
-
class DownloadFile extends AsyncTask<String, String, String> {
|
|
112
|
-
@Override
|
|
113
|
-
protected void onPreExecute() {
|
|
114
|
-
}
|
|
115
|
-
@Override
|
|
116
|
-
protected String doInBackground(String... args) {
|
|
117
|
-
BufferedInputStream input = null;
|
|
118
|
-
OutputStream output = null;
|
|
119
|
-
HttpURLConnection connection = null;
|
|
120
|
-
int count;
|
|
121
|
-
int progressCheck=10;
|
|
122
|
-
try {
|
|
123
|
-
URL url = new URL((requestURL).replaceAll(" ", "%20"));
|
|
124
|
-
connection = (HttpURLConnection) url.openConnection();
|
|
125
|
-
connection.setRequestProperty("Connection", "Keep-Alive");
|
|
126
|
-
connection.connect();
|
|
127
|
-
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
|
|
128
|
-
return "Server returned HTTP " + connection.getResponseCode() + " " + connection.getResponseMessage();
|
|
129
|
-
}
|
|
130
|
-
int fileLength = connection.getContentLength();
|
|
131
|
-
input = new BufferedInputStream(connection.getInputStream(),8192);
|
|
132
|
-
|
|
133
|
-
//File rootPath = Environment.getExternalStorageDirectory();
|
|
134
|
-
String rootPath = context.getExternalMediaDirs()[0].toString();
|
|
135
|
-
File filesourceDirecory = new File(rootPath + "/" + pathComponent(filePath));
|
|
136
|
-
if (!filesourceDirecory.exists()) {
|
|
137
|
-
filesourceDirecory.mkdirs();
|
|
138
|
-
}
|
|
139
|
-
File fileSavePath = new File(rootPath + "/" + filePath);
|
|
140
|
-
output = new FileOutputStream(fileSavePath);
|
|
141
|
-
byte data[] = new byte[1024];
|
|
142
|
-
long progress = 0;
|
|
143
|
-
int progressToSend = 0;
|
|
144
|
-
while ((count = input.read(data)) != -1) {
|
|
145
|
-
// allow canceling with back button
|
|
146
|
-
if (isCancelled()) {
|
|
147
|
-
input.close();
|
|
148
|
-
return null;
|
|
149
|
-
}
|
|
150
|
-
progress += count;
|
|
151
|
-
progressToSend = (int)((progress * 100) / fileLength);
|
|
152
|
-
|
|
153
|
-
if(progressToSend >= progressCheck){
|
|
154
|
-
JSONObject progressObj = new JSONObject();
|
|
155
|
-
progressObj.put("progress", progressCheck);
|
|
156
|
-
progressObj.put("fileLength", fileLength);
|
|
157
|
-
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, progressObj);
|
|
158
|
-
pluginResult.setKeepCallback(true);
|
|
159
|
-
callbackContext.sendPluginResult(pluginResult);
|
|
160
|
-
progressCheck = progressCheck + 10;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
output.write(data, 0, count);
|
|
164
|
-
}
|
|
165
|
-
} catch (Exception e) {
|
|
166
|
-
callbackContext.error("Failure" + e.getMessage());
|
|
167
|
-
}
|
|
168
|
-
if(thumbnailInd.equalsIgnoreCase("true")){
|
|
169
|
-
return filePath;
|
|
170
|
-
}else{
|
|
171
|
-
return null;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
public void onPostExecute(String result) {
|
|
175
|
-
try {
|
|
176
|
-
MediaScannerConnection.scanFile(context,
|
|
177
|
-
new String[] { context.getExternalMediaDirs()[0].toString() },
|
|
178
|
-
null,
|
|
179
|
-
(path, uri) -> {
|
|
180
|
-
Log.i("ExternalStorage", "Scanned " + path + ":");
|
|
181
|
-
Log.i("ExternalStorage", "-> uri=" + uri);
|
|
182
|
-
});
|
|
183
|
-
if (result != null) {
|
|
184
|
-
if(result.indexOf('.') != -1){
|
|
185
|
-
String extension = "." + result.substring(result.lastIndexOf(".") + 1).toLowerCase(),
|
|
186
|
-
filePath = context.getExternalMediaDirs()[0].toString()+"/"+result;
|
|
187
|
-
String thumbnail = getFileThumbnail(filePath,extension,context);
|
|
188
|
-
callbackContext.success(thumbnail);
|
|
189
|
-
} else{
|
|
190
|
-
callbackContext.error("Failure");
|
|
191
|
-
}
|
|
192
|
-
} else {
|
|
193
|
-
callbackContext.success("success");
|
|
194
|
-
}
|
|
195
|
-
} catch (Exception e) {
|
|
196
|
-
e.printStackTrace();
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
new DownloadFile().execute();
|
|
201
|
-
} catch (Exception e) {
|
|
202
|
-
e.printStackTrace();
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
public static String encrypt(String plainText) {
|
|
206
|
-
String encryptedText = "";
|
|
207
|
-
try {
|
|
208
|
-
Cipher cipher = Cipher.getInstance(cipherTransformation);
|
|
209
|
-
byte[] key = encryptionKey.getBytes(characterEncoding);
|
|
210
|
-
SecretKeySpec secretKey = new SecretKeySpec(key, aesEncryptionAlgorithem);
|
|
211
|
-
IvParameterSpec ivparameterspec = new IvParameterSpec(key);
|
|
212
|
-
cipher.init(Cipher.ENCRYPT_MODE, secretKey, ivparameterspec);
|
|
213
|
-
byte[] cipherText = android.util.Base64.encode(cipher.doFinal(plainText.getBytes("UTF8")), 0);
|
|
214
|
-
encryptedText = new String(cipherText);
|
|
215
|
-
} catch (Exception E) {
|
|
216
|
-
System.out.println("decrypt Exception : " + E.getMessage());
|
|
217
|
-
}
|
|
218
|
-
return encryptedText;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/*FOR GETTING CURRENT LOCATION */
|
|
222
|
-
public String getLocation(Context context) {
|
|
223
|
-
String latitude = "",
|
|
224
|
-
longitude = "";
|
|
225
|
-
|
|
226
|
-
String currentLine, lastKnownLocation = "";
|
|
227
|
-
try {
|
|
228
|
-
BufferedReader readerObj = new BufferedReader(new FileReader(new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/LastKnownLocation_encrypted.txt")));
|
|
229
|
-
while ((currentLine = readerObj.readLine()) != null) {
|
|
230
|
-
lastKnownLocation = currentLine;
|
|
231
|
-
}
|
|
232
|
-
readerObj.close();
|
|
233
|
-
String encryptedLocation = decrypt(lastKnownLocation);
|
|
234
|
-
String[] splitStr = encryptedLocation.split(",");
|
|
235
|
-
latitude = splitStr[0];
|
|
236
|
-
longitude = splitStr[1];
|
|
237
|
-
} catch (Exception e) {
|
|
238
|
-
e.printStackTrace();
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
//*** SUBSTRING LATITUDE,LONGITUDE IF GREATER THAN 10 POINTS ***//
|
|
242
|
-
if (latitude.length() > 10) {
|
|
243
|
-
latitude = latitude.substring(0, 10);
|
|
244
|
-
}
|
|
245
|
-
if (longitude.length() > 10) {
|
|
246
|
-
longitude = longitude.substring(0, 10);
|
|
247
|
-
}
|
|
248
|
-
//*** RETURN LATITUDE,LONGITUDE VALUE IN JSON OBJECT FORMAT ***//
|
|
249
|
-
return "{\"lat\":" + "\"" + latitude + "\"" + ",\"lon\":" + "\"" + longitude + "\"}";
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
/*FOR CHECK LOCATION SERVICE SETTING IS ENABLED OR NOT */
|
|
253
|
-
public String checkLocation(Context context) {
|
|
254
|
-
Boolean isEnabled = false;
|
|
255
|
-
|
|
256
|
-
//*** REGISTER THE LOCATION MANAGER *** //
|
|
257
|
-
locationManager = (LocationManager) context.getSystemService(context.LOCATION_SERVICE);
|
|
258
|
-
//*** CHECK LOCATION SETTING ENABLED OR NOT ***//
|
|
259
|
-
isEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
|
|
260
|
-
|
|
261
|
-
if (!isEnabled) {
|
|
262
|
-
isEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
return String.valueOf(isEnabled);
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
/*FOR CHECK QUEUE IS PROCESSING OR NOT */
|
|
269
|
-
public String getSyncIndicator(Context context) {
|
|
270
|
-
File queueFile, queueFolder;
|
|
271
|
-
Boolean syncIndication = false;
|
|
272
|
-
try {
|
|
273
|
-
queueFile = new File(rootDirectory + "/" + mInterfaceUtil.packageName + "/database/queue_mgr_encrypted.txt");
|
|
274
|
-
queueFolder = new File(rootDirectory + "/" + mInterfaceUtil.packageName + "/database/queue");
|
|
275
|
-
if (queueFile.exists()) {
|
|
276
|
-
if (queueFile.length() == 0) {
|
|
277
|
-
syncIndication = true;
|
|
278
|
-
}
|
|
279
|
-
} else {
|
|
280
|
-
syncIndication = true;
|
|
281
|
-
}
|
|
282
|
-
if (syncIndication) {
|
|
283
|
-
if (queueFolder.exists()) {
|
|
284
|
-
if (queueFolder.listFiles().length != 0) {
|
|
285
|
-
syncIndication = false;
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
return String.valueOf(syncIndication);
|
|
290
|
-
} catch (Exception e) {
|
|
291
|
-
return String.valueOf(e);
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
public void deleteMultipleFiles(String str, CallbackContext callbackContext) {
|
|
297
|
-
File baseDirectory = rootDirectory;
|
|
298
|
-
try {
|
|
299
|
-
File filePath = new File(baseDirectory + "/" + str);
|
|
300
|
-
if (filePath.exists()) {
|
|
301
|
-
filePath.delete();
|
|
302
|
-
} else {
|
|
303
|
-
callbackContext.error("No file there & File not deleted for " + str);
|
|
304
|
-
}
|
|
305
|
-
} catch (Exception e) {
|
|
306
|
-
callbackContext.error(e.getMessage());
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
public void copyConfigFile(CallbackContext callbackContext, JSONArray arguments) {
|
|
311
|
-
JSONObject inputFileObj;
|
|
312
|
-
String srcFilePath,
|
|
313
|
-
srcFileName,
|
|
314
|
-
desFilePath,
|
|
315
|
-
desFileName;
|
|
316
|
-
InputStream srcFileReader;
|
|
317
|
-
OutputStream desFileWriter;
|
|
318
|
-
int srcFileSize;
|
|
319
|
-
byte[] buf;
|
|
320
|
-
File sourceFileObj, desFileObj;
|
|
321
|
-
String aa = "aaaa";
|
|
322
|
-
try {
|
|
323
|
-
for (int index = 0; index < arguments.length(); index++) {
|
|
324
|
-
inputFileObj = arguments.getJSONObject(index);
|
|
325
|
-
File rootDir = rootDirectory;
|
|
326
|
-
srcFilePath = rootDir + "/" + inputFileObj.optString("srcPath").toString();
|
|
327
|
-
srcFileName = inputFileObj.optString("srcFile").toString();
|
|
328
|
-
desFilePath = rootDir + "/" + inputFileObj.optString("desPath").toString();
|
|
329
|
-
desFileName = inputFileObj.optString("desFile").toString();
|
|
330
|
-
sourceFileObj = new File(srcFilePath + "/" + srcFileName);
|
|
331
|
-
desFileObj = new File(desFilePath + "/" + desFileName);
|
|
332
|
-
//** CHECK DESTINATION FILE PATH EXITS OR NOT **//
|
|
333
|
-
if (!new File(desFilePath).exists()) {
|
|
334
|
-
new File(desFilePath).mkdirs();
|
|
335
|
-
}
|
|
336
|
-
//** CHECK SOURCE FILE EXITS OR NOT **//
|
|
337
|
-
if (sourceFileObj.exists()) {
|
|
338
|
-
srcFileReader = new FileInputStream(sourceFileObj);
|
|
339
|
-
desFileWriter = new FileOutputStream(desFileObj);
|
|
340
|
-
buf = new byte[1024];
|
|
341
|
-
//** WRITE SOURCE FILE INTO CONTENT_STORE DESTINATION PATH **//
|
|
342
|
-
while ((srcFileSize = srcFileReader.read(buf)) > 0) {
|
|
343
|
-
desFileWriter.write(buf, 0, srcFileSize);
|
|
344
|
-
}
|
|
345
|
-
srcFileReader.close();
|
|
346
|
-
desFileWriter.close();
|
|
347
|
-
} else {
|
|
348
|
-
callbackContext.error("failure");
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
callbackContext.success("success");
|
|
352
|
-
} catch (Exception e) {
|
|
353
|
-
callbackContext.error(e.getMessage());
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
/* COPY A FILE FROM ONE LOCATION TO ANOTHER LOCATION */
|
|
358
|
-
public void copyFile(CallbackContext callbackContext, JSONArray arguments) {
|
|
359
|
-
JSONObject inputFileObj;
|
|
360
|
-
String srcFilePath,
|
|
361
|
-
srcFileName,
|
|
362
|
-
desFilePath,
|
|
363
|
-
desFileName;
|
|
364
|
-
InputStream srcFileReader;
|
|
365
|
-
OutputStream desFileWriter;
|
|
366
|
-
int srcFileSize;
|
|
367
|
-
byte[] buf;
|
|
368
|
-
File sourceFileObj, desFileObj;
|
|
369
|
-
try {
|
|
370
|
-
for (int index = 0; index < arguments.length(); index++) {
|
|
371
|
-
inputFileObj = arguments.getJSONObject(index);
|
|
372
|
-
srcFilePath = rootDirectory + "/" + inputFileObj.optString("sourceFilePath").toString();
|
|
373
|
-
srcFileName = inputFileObj.optString("sourceFileName").toString();
|
|
374
|
-
desFilePath = rootDirectory + "/" + inputFileObj.optString("targetFilePath").toString();
|
|
375
|
-
desFileName = inputFileObj.optString("targetFileName").toString();
|
|
376
|
-
sourceFileObj = new File(srcFilePath + "/" + srcFileName);
|
|
377
|
-
desFileObj = new File(desFilePath + "/" + desFileName);
|
|
378
|
-
//** CHECK DESTINATION FILE PATH EXITS OR NOT **//
|
|
379
|
-
if (!new File(desFilePath).exists()) {
|
|
380
|
-
new File(desFilePath).mkdirs();
|
|
381
|
-
}
|
|
382
|
-
//** CHECK SOURCE FILE EXITS OR NOT **//
|
|
383
|
-
if (sourceFileObj.exists()) {
|
|
384
|
-
srcFileReader = new FileInputStream(sourceFileObj);
|
|
385
|
-
desFileWriter = new FileOutputStream(desFileObj);
|
|
386
|
-
buf = new byte[1024];
|
|
387
|
-
//** WRITE SOURCE FILE INTO CONTENT_STORE DESTINATION PATH **//
|
|
388
|
-
while ((srcFileSize = srcFileReader.read(buf)) > 0) {
|
|
389
|
-
desFileWriter.write(buf, 0, srcFileSize);
|
|
390
|
-
}
|
|
391
|
-
srcFileReader.close();
|
|
392
|
-
desFileWriter.close();
|
|
393
|
-
} else {
|
|
394
|
-
callbackContext.error("File not exists");
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
callbackContext.success("success");
|
|
398
|
-
} catch (Exception e) {
|
|
399
|
-
callbackContext.error(e.getMessage());
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
/* COPY A FILE FROM ONE LOCATION TO ANOTHER LOCATION */
|
|
404
|
-
public void copyAttachmentFile(CallbackContext callbackContext, JSONArray arguments) {
|
|
405
|
-
JSONObject inputFileObj;
|
|
406
|
-
String srcFilePath,
|
|
407
|
-
srcFileName,
|
|
408
|
-
desFilePath,
|
|
409
|
-
desFileName,
|
|
410
|
-
queueCopyPath,
|
|
411
|
-
queueCopyFileName;
|
|
412
|
-
InputStream srcFileReader;
|
|
413
|
-
OutputStream desFileWriter, queueFileWriter;
|
|
414
|
-
int srcFileSize;
|
|
415
|
-
byte[] buf;
|
|
416
|
-
File sourceFileObj, desFileObj, queueFileObj;
|
|
417
|
-
try {
|
|
418
|
-
for (int index = 0; index < arguments.length(); index++) {
|
|
419
|
-
inputFileObj = arguments.getJSONObject(index);
|
|
420
|
-
srcFilePath = inputFileObj.optString("srcPath").toString();
|
|
421
|
-
srcFileName = inputFileObj.optString("srcFile").toString();
|
|
422
|
-
desFilePath = rootDirectory + "/" + inputFileObj.optString("desPath").toString();
|
|
423
|
-
desFileName = inputFileObj.optString("desFile").toString();
|
|
424
|
-
queueCopyPath = rootDirectory + "/" + inputFileObj.optString("queueAttachPath").toString();
|
|
425
|
-
queueCopyFileName = inputFileObj.optString("queueAttachFile").toString();
|
|
426
|
-
sourceFileObj = new File(srcFilePath + "/" + srcFileName);
|
|
427
|
-
desFileObj = new File(desFilePath + "/" + desFileName);
|
|
428
|
-
queueFileObj = new File(queueCopyPath + "/" + queueCopyFileName);
|
|
429
|
-
//** CHECK DESTINATION FILE PATH EXITS OR NOT **//
|
|
430
|
-
if (!new File(desFilePath).exists()) {
|
|
431
|
-
new File(desFilePath).mkdirs();
|
|
432
|
-
}
|
|
433
|
-
if (!new File(queueCopyPath).exists()) {
|
|
434
|
-
new File(queueCopyPath).mkdirs();
|
|
435
|
-
}
|
|
436
|
-
//** CHECK SOURCE FILE EXITS OR NOT **//
|
|
437
|
-
if (sourceFileObj.exists()) {
|
|
438
|
-
srcFileReader = new FileInputStream(sourceFileObj);
|
|
439
|
-
desFileWriter = new FileOutputStream(desFileObj);
|
|
440
|
-
buf = new byte[1024];
|
|
441
|
-
//** WRITE SOURCE FILE INTO CONTENT_STORE DESTINATION PATH **//
|
|
442
|
-
while ((srcFileSize = srcFileReader.read(buf)) > 0) {
|
|
443
|
-
desFileWriter.write(buf, 0, srcFileSize);
|
|
444
|
-
}
|
|
445
|
-
srcFileReader.close();
|
|
446
|
-
desFileWriter.close();
|
|
447
|
-
|
|
448
|
-
srcFileReader = new FileInputStream(sourceFileObj);
|
|
449
|
-
queueFileWriter = new FileOutputStream(queueFileObj);
|
|
450
|
-
buf = new byte[1024];
|
|
451
|
-
//** WRITE SOURCE FILE INTO QUEUE DESTINATION PATH **//
|
|
452
|
-
while ((srcFileSize = srcFileReader.read(buf)) > 0) {
|
|
453
|
-
queueFileWriter.write(buf, 0, srcFileSize);
|
|
454
|
-
}
|
|
455
|
-
srcFileReader.close();
|
|
456
|
-
queueFileWriter.close();
|
|
457
|
-
} else {
|
|
458
|
-
callbackContext.error("failure");
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
deleteFilesFromDirectory();
|
|
462
|
-
callbackContext.success("success");
|
|
463
|
-
} catch (Exception e) {
|
|
464
|
-
callbackContext.error(e.getMessage());
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
/* Move A FILE FROM ONE LOCATION TO ANOTHER LOCATION */
|
|
469
|
-
public void moveFile(CallbackContext callbackContext, JSONArray arguments) {
|
|
470
|
-
JSONObject inputFileObj;
|
|
471
|
-
String srcFilePath,
|
|
472
|
-
srcFileName,
|
|
473
|
-
desFilePath,
|
|
474
|
-
desFileName;
|
|
475
|
-
InputStream srcFileReader;
|
|
476
|
-
OutputStream desFileWriter;
|
|
477
|
-
int srcFileSize;
|
|
478
|
-
byte[] buf;
|
|
479
|
-
File sourceFile, desFile;
|
|
480
|
-
try {
|
|
481
|
-
for (int index = 0; index < arguments.length(); index++) {
|
|
482
|
-
inputFileObj = arguments.getJSONObject(index);
|
|
483
|
-
srcFilePath = rootDirectory + "/" + inputFileObj.optString("sourceFilePath").toString();
|
|
484
|
-
srcFileName = inputFileObj.optString("sourceFileName").toString();
|
|
485
|
-
desFilePath = rootDirectory + "/" + inputFileObj.optString("targetFilePath").toString();
|
|
486
|
-
desFileName = inputFileObj.optString("targetFileName").toString();
|
|
487
|
-
sourceFile = new File(srcFilePath + "/" + srcFileName);
|
|
488
|
-
desFile = new File(desFilePath + "/" + desFileName);
|
|
489
|
-
//** CHECK DESTINATION FILE PATH EXITS OR NOT **//
|
|
490
|
-
if (!new File(desFilePath).exists()) {
|
|
491
|
-
new File(desFilePath).mkdirs();
|
|
492
|
-
}
|
|
493
|
-
//** CHECK SOURCE FILE EXITS OR NOT **//
|
|
494
|
-
if (sourceFile.exists()) {
|
|
495
|
-
srcFileReader = new FileInputStream(sourceFile);
|
|
496
|
-
desFileWriter = new FileOutputStream(desFile);
|
|
497
|
-
buf = new byte[1024];
|
|
498
|
-
//** WRITE SOURCE FILE INTO CONTENT_STORE DESTINATION PATH **//
|
|
499
|
-
while ((srcFileSize = srcFileReader.read(buf)) > 0) {
|
|
500
|
-
desFileWriter.write(buf, 0, srcFileSize);
|
|
501
|
-
}
|
|
502
|
-
srcFileReader.close();
|
|
503
|
-
desFileWriter.close();
|
|
504
|
-
/* Delete the source file */
|
|
505
|
-
sourceFile.delete();
|
|
506
|
-
} else {
|
|
507
|
-
callbackContext.error("File not exists");
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
callbackContext.success("success");
|
|
511
|
-
} catch (Exception e) {
|
|
512
|
-
callbackContext.error(e.getMessage());
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
public void copyFileOld(CallbackContext callbackContext, JSONArray arguments) {
|
|
517
|
-
JSONObject inputFileObj;
|
|
518
|
-
String srcFilePath,
|
|
519
|
-
srcFileName,
|
|
520
|
-
desFilePath,
|
|
521
|
-
desFileName,
|
|
522
|
-
queueCopyPath,
|
|
523
|
-
queueCopyFileName;
|
|
524
|
-
InputStream srcFileReader;
|
|
525
|
-
OutputStream desFileWriter, queueFileWriter;
|
|
526
|
-
int srcFileSize;
|
|
527
|
-
byte[] buf;
|
|
528
|
-
File sourceFileObj, desFileObj, queueFileObj;
|
|
529
|
-
try {
|
|
530
|
-
for (int index = 0; index < arguments.length(); index++) {
|
|
531
|
-
inputFileObj = arguments.getJSONObject(index);
|
|
532
|
-
srcFilePath = inputFileObj.optString("srcPath").toString();
|
|
533
|
-
srcFileName = inputFileObj.optString("srcFile").toString();
|
|
534
|
-
desFilePath = rootDirectory + "/" + inputFileObj.optString("desPath").toString();
|
|
535
|
-
desFileName = inputFileObj.optString("desFile").toString();
|
|
536
|
-
queueCopyPath = rootDirectory + "/" + inputFileObj.optString("queueAttachPath").toString();
|
|
537
|
-
queueCopyFileName = inputFileObj.optString("queueAttachFile").toString();
|
|
538
|
-
sourceFileObj = new File(srcFilePath + "/" + srcFileName);
|
|
539
|
-
desFileObj = new File(desFilePath + "/" + desFileName);
|
|
540
|
-
queueFileObj = new File(queueCopyPath + "/" + queueCopyFileName);
|
|
541
|
-
//** CHECK DESTINATION FILE PATH EXITS OR NOT **//
|
|
542
|
-
if (!new File(desFilePath).exists()) {
|
|
543
|
-
new File(desFilePath).mkdirs();
|
|
544
|
-
}
|
|
545
|
-
if (!new File(queueCopyPath).exists()) {
|
|
546
|
-
new File(queueCopyPath).mkdirs();
|
|
547
|
-
}
|
|
548
|
-
//** CHECK SOURCE FILE EXITS OR NOT **//
|
|
549
|
-
if (sourceFileObj.exists()) {
|
|
550
|
-
srcFileReader = new FileInputStream(sourceFileObj);
|
|
551
|
-
desFileWriter = new FileOutputStream(desFileObj);
|
|
552
|
-
buf = new byte[1024];
|
|
553
|
-
//** WRITE SOURCE FILE INTO CONTENT_STORE DESTINATION PATH **//
|
|
554
|
-
while ((srcFileSize = srcFileReader.read(buf)) > 0) {
|
|
555
|
-
desFileWriter.write(buf, 0, srcFileSize);
|
|
556
|
-
}
|
|
557
|
-
srcFileReader.close();
|
|
558
|
-
desFileWriter.close();
|
|
559
|
-
|
|
560
|
-
srcFileReader = new FileInputStream(sourceFileObj);
|
|
561
|
-
queueFileWriter = new FileOutputStream(queueFileObj);
|
|
562
|
-
buf = new byte[1024];
|
|
563
|
-
//** WRITE SOURCE FILE INTO QUEUE DESTINATION PATH **//
|
|
564
|
-
while ((srcFileSize = srcFileReader.read(buf)) > 0) {
|
|
565
|
-
queueFileWriter.write(buf, 0, srcFileSize);
|
|
566
|
-
}
|
|
567
|
-
srcFileReader.close();
|
|
568
|
-
queueFileWriter.close();
|
|
569
|
-
} else {
|
|
570
|
-
callbackContext.error("failure");
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
deleteFilesFromDirectory();
|
|
574
|
-
callbackContext.success("success");
|
|
575
|
-
} catch (Exception e) {
|
|
576
|
-
callbackContext.error(e.getMessage());
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
public void queueProcessor(CallbackContext callbackContext) {
|
|
581
|
-
String statusIndication = "false";
|
|
582
|
-
String breakIndication = "false";
|
|
583
|
-
try {
|
|
584
|
-
String clientID, countryCode, userID, clientUrl;
|
|
585
|
-
BufferedReader myAccountsFileReader;
|
|
586
|
-
StringBuilder myAccountsFileBuilder;
|
|
587
|
-
JSONArray accountsList;
|
|
588
|
-
JSONObject currentAccount;
|
|
589
|
-
String currentLine;
|
|
590
|
-
if (new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/" + "my_accounts_encrypted.txt").exists()) {
|
|
591
|
-
myAccountsFileReader = new BufferedReader(new FileReader(new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/" + "my_accounts_encrypted.txt")));
|
|
592
|
-
myAccountsFileBuilder = new StringBuilder();
|
|
593
|
-
while ((currentLine = myAccountsFileReader.readLine()) != null) {
|
|
594
|
-
myAccountsFileBuilder.append(currentLine);
|
|
595
|
-
}
|
|
596
|
-
myAccountsFileReader.close();
|
|
597
|
-
accountsList = new JSONArray(decrypt(myAccountsFileBuilder.toString()));
|
|
598
|
-
for (int index = 0; index < accountsList.length(); index++) {
|
|
599
|
-
currentAccount = accountsList.optJSONObject(index);
|
|
600
|
-
clientID = currentAccount.optString("client_id").toString();
|
|
601
|
-
countryCode = currentAccount.optString("country_code").toString();
|
|
602
|
-
userID = currentAccount.optString("user_id").toString();
|
|
603
|
-
clientUrl = currentAccount.optString("client_url").toString();
|
|
604
|
-
File baseDirectory = rootDirectory;
|
|
605
|
-
File databaseDir = new File(baseDirectory + "/" + mInterfaceUtil.packageName + "/" + clientID + "/" + countryCode + "/database");
|
|
606
|
-
File processFileDir = new File(mInterfaceUtil.packageName + "/" + clientID + "/" + countryCode + "/database/process/");
|
|
607
|
-
if (databaseDir.exists()) {
|
|
608
|
-
String attachmentsPath = baseDirectory + "/" + mInterfaceUtil.packageName + "/" + clientID + "/" + countryCode + "/database/attachments";
|
|
609
|
-
String queuesPath = baseDirectory + "/" + mInterfaceUtil.packageName + "/" + clientID + "/" + countryCode + "/database/queue";
|
|
610
|
-
if (new File(attachmentsPath).exists()) {
|
|
611
|
-
File[] attachmentsFiles = new File(attachmentsPath).listFiles();
|
|
612
|
-
if (attachmentsFiles != null) {
|
|
613
|
-
for (int attachIndex = 0; attachIndex < attachmentsFiles.length; attachIndex++) {
|
|
614
|
-
Arrays.sort(attachmentsFiles);
|
|
615
|
-
if (attachmentsFiles[attachIndex].length() == 0) {
|
|
616
|
-
breakIndication = "true";
|
|
617
|
-
break;
|
|
618
|
-
}
|
|
619
|
-
String[] fileName = attachmentsFiles[attachIndex].toString().split("/");
|
|
620
|
-
String attachURL = clientUrl + "/common/components/QueueManager/QueueUpload.aspx?file_path=attachments&client_id=" + clientID + "&country_code=" + countryCode + "&user_id=" + userID + "&file_name=" + fileName[fileName.length - 1].toString();
|
|
621
|
-
statusIndication = sendFilesToServer(attachmentsFiles[attachIndex].toString(), fileName[fileName.length - 1].toString(), attachURL);
|
|
622
|
-
if (statusIndication.equals("true")) {
|
|
623
|
-
breakIndication = "true";
|
|
624
|
-
break;
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
if (statusIndication.equals("false")) {
|
|
630
|
-
if (new File(queuesPath).exists()) {
|
|
631
|
-
File[] queueFiles = new File(queuesPath).listFiles();
|
|
632
|
-
if (queueFiles != null) {
|
|
633
|
-
for (int queueIndex = 0; queueIndex < queueFiles.length; queueIndex++) {
|
|
634
|
-
Arrays.sort(queueFiles);
|
|
635
|
-
if (queueFiles[queueIndex].length() == 0) {
|
|
636
|
-
breakIndication = "true";
|
|
637
|
-
break;
|
|
638
|
-
}
|
|
639
|
-
String[] fileName = queueFiles[queueIndex].toString().split("/");
|
|
640
|
-
String queueURL = clientUrl + "/common/components/QueueManager/QueueUpload.aspx?file_path=queue&client_id=" + clientID + "&country_code=" + countryCode + "&user_id=" + userID + "&file_name=" + fileName[fileName.length - 1].toString();
|
|
641
|
-
sendFilesToServer(queueFiles[queueIndex].toString(), fileName[fileName.length - 1].toString(), queueURL);
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
} else {
|
|
647
|
-
System.out.println("No database directory");
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
if (breakIndication.equals("false")) {
|
|
651
|
-
callbackContext.success();
|
|
652
|
-
} else {
|
|
653
|
-
callbackContext.error("failure");
|
|
654
|
-
}
|
|
655
|
-
} else {
|
|
656
|
-
System.out.println("No my accounts file");
|
|
657
|
-
}
|
|
658
|
-
} catch (Exception e) {
|
|
659
|
-
System.out.println("out exception : " + e.getMessage());
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
/*GETTING A FILEPATH OF API LEVEL 19 AND ABOVE */
|
|
664
|
-
public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
|
|
665
|
-
Cursor cursor = null;
|
|
666
|
-
final String column = "_data";
|
|
667
|
-
final String[] projection = {
|
|
668
|
-
column
|
|
669
|
-
};
|
|
670
|
-
|
|
671
|
-
try {
|
|
672
|
-
cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
|
|
673
|
-
if (cursor != null && cursor.moveToFirst()) {
|
|
674
|
-
final int column_index = cursor.getColumnIndexOrThrow(column);
|
|
675
|
-
return cursor.getString(column_index);
|
|
676
|
-
}
|
|
677
|
-
} finally {
|
|
678
|
-
if (cursor != null)
|
|
679
|
-
cursor.close();
|
|
680
|
-
}
|
|
681
|
-
return null;
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
@TargetApi(Build.VERSION_CODES.KITKAT)
|
|
685
|
-
public static String getPathToNonPrimaryVolume(Context context, String tag) {
|
|
686
|
-
File[] volumes = context.getExternalCacheDirs();
|
|
687
|
-
if (volumes != null) {
|
|
688
|
-
for (File volume : volumes) {
|
|
689
|
-
if (volume != null) {
|
|
690
|
-
String path = volume.getAbsolutePath();
|
|
691
|
-
if (path != null) {
|
|
692
|
-
int index = path.indexOf(tag);
|
|
693
|
-
if (index != -1) {
|
|
694
|
-
return path.substring(0, index) + tag;
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
return null;
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
public String refreshTimeProfile(String date, String hour, String minute) {
|
|
705
|
-
try {
|
|
706
|
-
String serverResponseDate, deviceDate, serverDate;
|
|
707
|
-
Date serverDateObj, todayDateobj;
|
|
708
|
-
SimpleDateFormat serverDateformat, deviceDateFormat, serverDateString;
|
|
709
|
-
BufferedWriter writerObj;
|
|
710
|
-
serverResponseDate = date + " " + hour + ":" + minute + ":00";
|
|
711
|
-
serverDateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", locale);
|
|
712
|
-
serverDateObj = serverDateformat.parse(serverResponseDate);
|
|
713
|
-
serverDateString = new SimpleDateFormat("yyyy,MM,dd,HH,mm,ss", locale);
|
|
714
|
-
serverDate = serverDateString.format(serverDateObj);
|
|
715
|
-
deviceDateFormat = new SimpleDateFormat("yyyy,MM,dd,HH,mm,ss", locale);
|
|
716
|
-
todayDateobj = new Date();
|
|
717
|
-
deviceDate = deviceDateFormat.format(todayDateobj);
|
|
718
|
-
JSONObject dateObj = new JSONObject();
|
|
719
|
-
dateObj.put("serverDate", serverDate);
|
|
720
|
-
dateObj.put("initServerDate", serverDate);
|
|
721
|
-
dateObj.put("initDeviceDate", deviceDate);
|
|
722
|
-
writerObj = new BufferedWriter(new FileWriter(new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/time_profile_encrypted.txt")));
|
|
723
|
-
writerObj.write(encrypt(dateObj.toString()));
|
|
724
|
-
writerObj.flush();
|
|
725
|
-
writerObj.close();
|
|
726
|
-
return "true";
|
|
727
|
-
} catch (Exception e) {
|
|
728
|
-
return "false";
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
|
|
732
|
-
public void getNewDate(CallbackContext callbackContext) {
|
|
733
|
-
String currentLine;
|
|
734
|
-
StringBuilder timeObj = new StringBuilder();
|
|
735
|
-
try {
|
|
736
|
-
Date mobileDate = new Date();
|
|
737
|
-
File baseDirectory = rootDirectory;
|
|
738
|
-
BufferedReader readerObj = new BufferedReader(new FileReader(new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/time_profile_encrypted.txt")));
|
|
739
|
-
while ((currentLine = readerObj.readLine()) != null) {
|
|
740
|
-
timeObj.append(currentLine);
|
|
741
|
-
}
|
|
742
|
-
readerObj.close();
|
|
743
|
-
JSONObject serverDateObj = new JSONObject(decrypt(timeObj.toString()));
|
|
744
|
-
String serverTimeObj = serverDateObj.optString("serverDate").toString();
|
|
745
|
-
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy,MM,dd,HH,mm,ss", locale);
|
|
746
|
-
Date serverDate = simpleDateFormat.parse(serverTimeObj);
|
|
747
|
-
long timeDiff = mobileDate.getTime() - serverDate.getTime();
|
|
748
|
-
serverDate.setTime(serverDate.getTime() + timeDiff);
|
|
749
|
-
SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy,MM,dd,HH,mm,ss", locale);
|
|
750
|
-
String serverDate1 = simpleDateFormat1.format(serverDate);
|
|
751
|
-
callbackContext.success(serverDate1);
|
|
752
|
-
} catch (Exception e) {
|
|
753
|
-
e.printStackTrace();
|
|
754
|
-
}
|
|
755
|
-
|
|
756
|
-
}
|
|
757
|
-
|
|
758
|
-
public void logData(String fileName, String data) {
|
|
759
|
-
File appDirectory;
|
|
760
|
-
FileWriter fileWriterObj;
|
|
761
|
-
try {
|
|
762
|
-
/* CHECKING THE DIRECTORY EXISTS OR NOT AND CREATING THE DIRECTORY */
|
|
763
|
-
appDirectory = new File(rootDirectory + "/" + fileName.substring(0, fileName.lastIndexOf("/")));
|
|
764
|
-
if (!appDirectory.exists()) {
|
|
765
|
-
appDirectory.mkdirs();
|
|
766
|
-
}
|
|
767
|
-
/* WRITING THE DATA TO THE FILE */
|
|
768
|
-
fileWriterObj = new FileWriter(new File(appDirectory, fileName.substring(fileName.lastIndexOf("/") + 1)), true);
|
|
769
|
-
fileWriterObj.write(data);
|
|
770
|
-
fileWriterObj.flush();
|
|
771
|
-
fileWriterObj.close();
|
|
772
|
-
|
|
773
|
-
} catch (Exception e) {
|
|
774
|
-
e.printStackTrace();
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
public void deleteFilesFromDirectory() {
|
|
779
|
-
File dir = new File(rootDirectory + "/" + mInterfaceUtil.packageName + "/" + "images");
|
|
780
|
-
if (dir.isDirectory()) {
|
|
781
|
-
if (dir.exists()) {
|
|
782
|
-
String[] children = dir.list();
|
|
783
|
-
for (int i = 0; i < children.length; i++) {
|
|
784
|
-
new File(dir, children[i]).delete();
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
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);
|
|
793
|
-
}
|
|
794
|
-
public String getFileThumbnail(String filePath, String extension, Context context){
|
|
795
|
-
Bitmap thumb;
|
|
796
|
-
String imgString = "";
|
|
797
|
-
try {
|
|
798
|
-
if(extension.equalsIgnoreCase(".mp4")){
|
|
799
|
-
thumb = ThumbnailUtils.createVideoThumbnail(filePath,
|
|
800
|
-
MediaStore.Images.Thumbnails.MINI_KIND);
|
|
801
|
-
imgString = convertBitmapToString(thumb);
|
|
802
|
-
}else if(extension.equalsIgnoreCase(".heic") || extension.equalsIgnoreCase(".jpeg")|| extension.equalsIgnoreCase(".jpg")|| extension.equalsIgnoreCase(".png")){
|
|
803
|
-
thumb = ThumbnailUtils.extractThumbnail(BitmapFactory.decodeFile(filePath),
|
|
804
|
-
76, 76);
|
|
805
|
-
|
|
806
|
-
imgString = convertBitmapToString(thumb);
|
|
807
|
-
}else if(extension.equalsIgnoreCase(".mp3")){
|
|
808
|
-
MediaMetadataRetriever mmr = new MediaMetadataRetriever();
|
|
809
|
-
byte[] bytes;
|
|
810
|
-
BitmapFactory.Options bfo=new BitmapFactory.Options();
|
|
811
|
-
|
|
812
|
-
mmr.setDataSource(context, Uri.fromFile(new File(filePath)));
|
|
813
|
-
bytes = mmr.getEmbeddedPicture();
|
|
814
|
-
if (bytes != null){
|
|
815
|
-
thumb = BitmapFactory.decodeByteArray(bytes, 0, bytes.length, bfo);
|
|
816
|
-
imgString = convertBitmapToString(thumb);
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
}catch (Exception e){
|
|
820
|
-
|
|
821
|
-
}
|
|
822
|
-
return imgString;
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
public void sendChatAttachment(String filePath, String fileName, String requestURL, Context context, CallbackContext callbackContext) {
|
|
826
|
-
try {
|
|
827
|
-
class SendFile extends AsyncTask<String, String, String> {
|
|
828
|
-
@Override
|
|
829
|
-
protected void onPreExecute() {
|
|
830
|
-
}
|
|
831
|
-
@Override
|
|
832
|
-
protected String doInBackground(String... args) {
|
|
833
|
-
FileInputStream fileInputStream;
|
|
834
|
-
HttpURLConnection urlConObj;
|
|
835
|
-
URL requestPath;
|
|
836
|
-
int bytesAvailable,
|
|
837
|
-
bufferSize;
|
|
838
|
-
int maxBufferSize = 1 * 1024 * 1024;
|
|
839
|
-
DataOutputStream dos;
|
|
840
|
-
String lineEnd = "\r\n";
|
|
841
|
-
String twoHyphens = "--";
|
|
842
|
-
String boundary = "*****";
|
|
843
|
-
StringBuilder serverResponseObj;
|
|
844
|
-
BufferedReader readerObj;
|
|
845
|
-
String currentLine,
|
|
846
|
-
receiveData = "", statusIndication = null;
|
|
847
|
-
int progressCheck=10;
|
|
848
|
-
try {
|
|
849
|
-
if (new File(filePath).exists()) {
|
|
850
|
-
if (new File(filePath).exists()) {
|
|
851
|
-
fileInputStream = new FileInputStream(new File(filePath));
|
|
852
|
-
|
|
853
|
-
requestPath = new URL((requestURL).replaceAll(" ", "%20"));
|
|
854
|
-
urlConObj = (HttpURLConnection) requestPath.openConnection();
|
|
855
|
-
urlConObj.setDoInput(true); // Allow Inputs
|
|
856
|
-
urlConObj.setDoOutput(true); // Allow Outputs
|
|
857
|
-
urlConObj.setUseCaches(false); // Don't use a Cached Copy
|
|
858
|
-
urlConObj.setRequestMethod("POST");
|
|
859
|
-
urlConObj.setRequestProperty("Connection", "Keep-Alive");
|
|
860
|
-
urlConObj.setRequestProperty("ENCTYPE", "multipart/form-data");
|
|
861
|
-
urlConObj.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
|
|
862
|
-
urlConObj.setRequestProperty("uploaded_file", fileName);
|
|
863
|
-
|
|
864
|
-
dos = new DataOutputStream(urlConObj.getOutputStream());
|
|
865
|
-
dos.writeBytes(twoHyphens + boundary + lineEnd);
|
|
866
|
-
dos.writeBytes("Content-Disposition: form-data; name=\"uploaded_file\";filename=\""
|
|
867
|
-
+ fileName + "\"" + lineEnd);
|
|
868
|
-
dos.writeBytes(lineEnd);
|
|
869
|
-
// create a buffer of maximum size
|
|
870
|
-
bytesAvailable = fileInputStream.available();
|
|
871
|
-
|
|
872
|
-
bufferSize = Math.min(bytesAvailable, maxBufferSize);
|
|
873
|
-
|
|
874
|
-
int progress = 0;
|
|
875
|
-
int progressToSend = 0;
|
|
876
|
-
int fileLength = (int) new File(filePath).length();
|
|
877
|
-
int bytesReadValue = 0;
|
|
878
|
-
byte buf[] = new byte[1024];
|
|
879
|
-
BufferedInputStream bufInput = new BufferedInputStream(new FileInputStream(new File(filePath)));
|
|
880
|
-
while ((bytesReadValue = bufInput.read(buf)) != -1) {
|
|
881
|
-
// write output
|
|
882
|
-
dos.write(buf, 0, bytesReadValue);
|
|
883
|
-
progress += bytesReadValue;
|
|
884
|
-
progressToSend = (int)((progress * 100) / fileLength);
|
|
885
|
-
|
|
886
|
-
if(progressToSend >= progressCheck){
|
|
887
|
-
JSONObject progressObj = new JSONObject();
|
|
888
|
-
progressObj.put("progress", progressCheck);
|
|
889
|
-
progressObj.put("fileLength", fileLength);
|
|
890
|
-
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, progressObj);
|
|
891
|
-
pluginResult.setKeepCallback(true);
|
|
892
|
-
callbackContext.sendPluginResult(pluginResult);
|
|
893
|
-
progressCheck = progressCheck + 10;
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
|
-
|
|
897
|
-
// send multipart form data necesssary after file data...
|
|
898
|
-
dos.writeBytes(lineEnd);
|
|
899
|
-
dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
|
|
900
|
-
urlConObj.getResponseCode();
|
|
901
|
-
//close the streams //
|
|
902
|
-
fileInputStream.close();
|
|
903
|
-
dos.flush();
|
|
904
|
-
dos.close();
|
|
905
|
-
readerObj = new BufferedReader(new InputStreamReader(urlConObj.getInputStream()));
|
|
906
|
-
currentLine = readerObj.readLine();
|
|
907
|
-
readerObj.close();
|
|
908
|
-
receiveData = currentLine.toString();
|
|
909
|
-
urlConObj.disconnect();
|
|
910
|
-
JSONObject resultObj = new JSONObject(receiveData);
|
|
911
|
-
if (resultObj.getString("status").equalsIgnoreCase("success")) {
|
|
912
|
-
statusIndication = "true";
|
|
913
|
-
} else {
|
|
914
|
-
statusIndication = "false";
|
|
915
|
-
}
|
|
916
|
-
urlConObj.disconnect();
|
|
917
|
-
}
|
|
918
|
-
}
|
|
919
|
-
|
|
920
|
-
} catch (Exception e) {
|
|
921
|
-
e.printStackTrace();
|
|
922
|
-
}
|
|
923
|
-
return statusIndication;
|
|
924
|
-
|
|
925
|
-
}
|
|
926
|
-
public void onPostExecute(String statusIndication) {
|
|
927
|
-
try {
|
|
928
|
-
if (statusIndication == null) {
|
|
929
|
-
callbackContext.error("failure");
|
|
930
|
-
} else {
|
|
931
|
-
if (statusIndication.equals("true")) {
|
|
932
|
-
callbackContext.success("success");
|
|
933
|
-
} else {
|
|
934
|
-
callbackContext.error("failure");
|
|
935
|
-
}
|
|
936
|
-
}
|
|
937
|
-
} catch (Exception e) {
|
|
938
|
-
e.printStackTrace();
|
|
939
|
-
}
|
|
940
|
-
|
|
941
|
-
}
|
|
942
|
-
}
|
|
943
|
-
new SendFile().execute();
|
|
944
|
-
} catch (Exception e) {
|
|
945
|
-
e.printStackTrace();
|
|
946
|
-
}
|
|
947
|
-
}
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
public String sendAttachmentToServer(String filePath, String fileName, String requestURL) {
|
|
951
|
-
String statusIndication = "false";
|
|
952
|
-
try {
|
|
953
|
-
FileInputStream fileInputStream;
|
|
954
|
-
HttpURLConnection urlConObj;
|
|
955
|
-
URL requestPath;
|
|
956
|
-
int bytesRead,
|
|
957
|
-
bytesAvailable,
|
|
958
|
-
bufferSize;
|
|
959
|
-
byte[] buffer;
|
|
960
|
-
int maxBufferSize = 1 * 1024 * 1024;
|
|
961
|
-
DataOutputStream dos;
|
|
962
|
-
String lineEnd = "\r\n";
|
|
963
|
-
String twoHyphens = "--";
|
|
964
|
-
String boundary = "*****";
|
|
965
|
-
StringBuilder serverResponseObj;
|
|
966
|
-
BufferedReader readerObj;
|
|
967
|
-
String currentLine,
|
|
968
|
-
receiveData = "";
|
|
969
|
-
if (new File(filePath).exists()) {
|
|
970
|
-
if (new File(filePath).exists()) {
|
|
971
|
-
fileInputStream = new FileInputStream(new File(filePath));
|
|
972
|
-
requestPath = new URL((requestURL).replaceAll(" ", "%20"));
|
|
973
|
-
urlConObj = (HttpURLConnection) requestPath.openConnection();
|
|
974
|
-
urlConObj.setDoInput(true); // Allow Inputs
|
|
975
|
-
urlConObj.setDoOutput(true); // Allow Outputs
|
|
976
|
-
urlConObj.setUseCaches(false); // Don't use a Cached Copy
|
|
977
|
-
urlConObj.setRequestMethod("POST");
|
|
978
|
-
urlConObj.setRequestProperty("Connection", "Keep-Alive");
|
|
979
|
-
urlConObj.setRequestProperty("ENCTYPE", "multipart/form-data");
|
|
980
|
-
urlConObj.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
|
|
981
|
-
urlConObj.setRequestProperty("uploaded_file", fileName);
|
|
982
|
-
|
|
983
|
-
dos = new DataOutputStream(urlConObj.getOutputStream());
|
|
984
|
-
dos.writeBytes(twoHyphens + boundary + lineEnd);
|
|
985
|
-
dos.writeBytes("Content-Disposition: form-data; name=\"uploaded_file\";filename=\""
|
|
986
|
-
+ fileName + "\"" + lineEnd);
|
|
987
|
-
dos.writeBytes(lineEnd);
|
|
988
|
-
// create a buffer of maximum size
|
|
989
|
-
bytesAvailable = fileInputStream.available();
|
|
990
|
-
|
|
991
|
-
bufferSize = Math.min(bytesAvailable, maxBufferSize);
|
|
992
|
-
buffer = new byte[bufferSize];
|
|
993
|
-
|
|
994
|
-
// read file and write it into form...
|
|
995
|
-
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
|
|
996
|
-
while (bytesRead > 0) {
|
|
997
|
-
dos.write(buffer, 0, bufferSize);
|
|
998
|
-
bytesAvailable = fileInputStream.available();
|
|
999
|
-
bufferSize = Math.min(bytesAvailable, maxBufferSize);
|
|
1000
|
-
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
|
|
1001
|
-
|
|
1002
|
-
}
|
|
1003
|
-
// send multipart form data necesssary after file data...
|
|
1004
|
-
dos.writeBytes(lineEnd);
|
|
1005
|
-
dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
|
|
1006
|
-
urlConObj.getResponseCode();
|
|
1007
|
-
//close the streams //
|
|
1008
|
-
fileInputStream.close();
|
|
1009
|
-
dos.flush();
|
|
1010
|
-
dos.close();
|
|
1011
|
-
readerObj = new BufferedReader(new InputStreamReader(urlConObj.getInputStream()));
|
|
1012
|
-
currentLine = readerObj.readLine();
|
|
1013
|
-
readerObj.close();
|
|
1014
|
-
receiveData = currentLine.toString();
|
|
1015
|
-
urlConObj.disconnect();
|
|
1016
|
-
JSONObject resultObj = new JSONObject(receiveData);
|
|
1017
|
-
if (resultObj.getString("status").equalsIgnoreCase("success")) {
|
|
1018
|
-
statusIndication = "true";
|
|
1019
|
-
} else {
|
|
1020
|
-
statusIndication = "false";
|
|
1021
|
-
}
|
|
1022
|
-
urlConObj.disconnect();
|
|
1023
|
-
}
|
|
1024
|
-
}
|
|
1025
|
-
} catch (Exception e) {
|
|
1026
|
-
statusIndication = "true";
|
|
1027
|
-
}
|
|
1028
|
-
return statusIndication;
|
|
1029
|
-
}
|
|
1030
|
-
|
|
1031
|
-
private void UpdateProgressBar(CallbackContext callbackContext, int progress) {
|
|
1032
|
-
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, progress);
|
|
1033
|
-
pluginResult.setKeepCallback(true); // keep callback
|
|
1034
|
-
callbackContext.sendPluginResult(pluginResult);
|
|
1035
|
-
}
|
|
1036
|
-
|
|
1037
|
-
public String sendFilesToServer(String filePath, String fileName, String requestURL) {
|
|
1038
|
-
String statusIndication = "false";
|
|
1039
|
-
try {
|
|
1040
|
-
FileInputStream fileInputStream;
|
|
1041
|
-
HttpURLConnection urlConObj;
|
|
1042
|
-
URL requestPath;
|
|
1043
|
-
int bytesRead,
|
|
1044
|
-
bytesAvailable,
|
|
1045
|
-
bufferSize;
|
|
1046
|
-
byte[] buffer;
|
|
1047
|
-
int maxBufferSize = 1 * 1024 * 1024;
|
|
1048
|
-
DataOutputStream dos;
|
|
1049
|
-
String lineEnd = "\r\n";
|
|
1050
|
-
String twoHyphens = "--";
|
|
1051
|
-
String boundary = "*****";
|
|
1052
|
-
StringBuilder serverResponseObj;
|
|
1053
|
-
BufferedReader readerObj;
|
|
1054
|
-
String currentLine,
|
|
1055
|
-
receiveData = "";
|
|
1056
|
-
if (new File(filePath).exists()) {
|
|
1057
|
-
if (new File(filePath).exists()) {
|
|
1058
|
-
fileInputStream = new FileInputStream(new File(filePath));
|
|
1059
|
-
requestPath = new URL((requestURL).replaceAll(" ", "%20"));
|
|
1060
|
-
urlConObj = (HttpURLConnection) requestPath.openConnection();
|
|
1061
|
-
urlConObj.setDoInput(true); // Allow Inputs
|
|
1062
|
-
urlConObj.setDoOutput(true); // Allow Outputs
|
|
1063
|
-
urlConObj.setUseCaches(false); // Don't use a Cached Copy
|
|
1064
|
-
urlConObj.setRequestMethod("POST");
|
|
1065
|
-
urlConObj.setRequestProperty("Connection", "Keep-Alive");
|
|
1066
|
-
urlConObj.setRequestProperty("ENCTYPE", "multipart/form-data");
|
|
1067
|
-
urlConObj.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
|
|
1068
|
-
urlConObj.setRequestProperty("uploaded_file", fileName);
|
|
1069
|
-
|
|
1070
|
-
dos = new DataOutputStream(urlConObj.getOutputStream());
|
|
1071
|
-
dos.writeBytes(twoHyphens + boundary + lineEnd);
|
|
1072
|
-
dos.writeBytes("Content-Disposition: form-data; name=\"uploaded_file\";filename=\""
|
|
1073
|
-
+ fileName + "\"" + lineEnd);
|
|
1074
|
-
dos.writeBytes(lineEnd);
|
|
1075
|
-
// create a buffer of maximum size
|
|
1076
|
-
bytesAvailable = fileInputStream.available();
|
|
1077
|
-
|
|
1078
|
-
bufferSize = Math.min(bytesAvailable, maxBufferSize);
|
|
1079
|
-
buffer = new byte[bufferSize];
|
|
1080
|
-
|
|
1081
|
-
// read file and write it into form...
|
|
1082
|
-
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
|
|
1083
|
-
while (bytesRead > 0) {
|
|
1084
|
-
dos.write(buffer, 0, bufferSize);
|
|
1085
|
-
bytesAvailable = fileInputStream.available();
|
|
1086
|
-
bufferSize = Math.min(bytesAvailable, maxBufferSize);
|
|
1087
|
-
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
|
|
1088
|
-
|
|
1089
|
-
}
|
|
1090
|
-
// send multipart form data necesssary after file data...
|
|
1091
|
-
dos.writeBytes(lineEnd);
|
|
1092
|
-
dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
|
|
1093
|
-
urlConObj.getResponseCode();
|
|
1094
|
-
//close the streams //
|
|
1095
|
-
fileInputStream.close();
|
|
1096
|
-
dos.flush();
|
|
1097
|
-
dos.close();
|
|
1098
|
-
readerObj = new BufferedReader(new InputStreamReader(urlConObj.getInputStream()));
|
|
1099
|
-
currentLine = readerObj.readLine();
|
|
1100
|
-
readerObj.close();
|
|
1101
|
-
receiveData = currentLine.toString();
|
|
1102
|
-
urlConObj.disconnect();
|
|
1103
|
-
if (receiveData.equals("true")) {
|
|
1104
|
-
new File(filePath).delete();
|
|
1105
|
-
} else {
|
|
1106
|
-
statusIndication = "true";
|
|
1107
|
-
}
|
|
1108
|
-
urlConObj.disconnect();
|
|
1109
|
-
}
|
|
1110
|
-
}
|
|
1111
|
-
} catch (Exception e) {
|
|
1112
|
-
statusIndication = "true";
|
|
1113
|
-
}
|
|
1114
|
-
return statusIndication;
|
|
1115
|
-
}
|
|
1116
|
-
|
|
1117
|
-
public void readFile(JSONArray args, CallbackContext callbackContext) throws IOException {
|
|
1118
|
-
String str = "";
|
|
1119
|
-
File baseDirectory = rootDirectory;
|
|
1120
|
-
try {
|
|
1121
|
-
File filePath = new File(baseDirectory + "/" + args.getJSONObject(0).optString("filePath"));
|
|
1122
|
-
if (filePath.exists()) {
|
|
1123
|
-
String content = new Scanner(filePath).useDelimiter("\\A").next();
|
|
1124
|
-
callbackContext.success(content);
|
|
1125
|
-
} else {
|
|
1126
|
-
callbackContext.error("There is no file at the given path..");
|
|
1127
|
-
}
|
|
1128
|
-
} catch (Exception e) {
|
|
1129
|
-
callbackContext.error(e.getMessage());
|
|
1130
|
-
}
|
|
1131
|
-
}
|
|
1132
|
-
|
|
1133
|
-
public void deleteFile(JSONArray args, CallbackContext callbackContext) {
|
|
1134
|
-
File baseDirectory = rootDirectory;
|
|
1135
|
-
try {
|
|
1136
|
-
File filePath = new File(baseDirectory + "/" + args.getJSONObject(0).optString("filePath"));
|
|
1137
|
-
if (filePath.exists()) {
|
|
1138
|
-
filePath.delete();
|
|
1139
|
-
callbackContext.success();
|
|
1140
|
-
} else {
|
|
1141
|
-
callbackContext.error("File not deleted..");
|
|
1142
|
-
}
|
|
1143
|
-
} catch (Exception e) {
|
|
1144
|
-
callbackContext.error(e.getMessage());
|
|
1145
|
-
}
|
|
1146
|
-
}
|
|
1147
|
-
|
|
1148
|
-
public void createFile(JSONArray args, CallbackContext callbackContext) {
|
|
1149
|
-
File appDirectory;
|
|
1150
|
-
FileWriter fileWriterObj;
|
|
1151
|
-
try {
|
|
1152
|
-
String fileName = args.getJSONObject(0).optString("filePath");
|
|
1153
|
-
String data = args.getJSONObject(0).optString("data");
|
|
1154
|
-
appDirectory = new File(rootDirectory + "/" + fileName.substring(0, fileName.lastIndexOf("/")));
|
|
1155
|
-
if (!appDirectory.exists()) {
|
|
1156
|
-
appDirectory.mkdirs();
|
|
1157
|
-
}
|
|
1158
|
-
/* WRITING THE DATA TO THE FILE */
|
|
1159
|
-
String bbbb = fileName.substring(fileName.lastIndexOf("/") + 1);
|
|
1160
|
-
fileWriterObj = new FileWriter(new File(appDirectory, fileName.substring(fileName.lastIndexOf("/") + 1)));
|
|
1161
|
-
fileWriterObj.write(data);
|
|
1162
|
-
fileWriterObj.flush();
|
|
1163
|
-
fileWriterObj.close();
|
|
1164
|
-
callbackContext.success();
|
|
1165
|
-
} catch (Exception e) {
|
|
1166
|
-
callbackContext.error(e.getMessage());
|
|
1167
|
-
}
|
|
1168
|
-
}
|
|
1169
|
-
|
|
1170
|
-
public void validateFile(JSONArray args, CallbackContext callbackContext) {
|
|
1171
|
-
File baseDirectory = rootDirectory;
|
|
1172
|
-
try {
|
|
1173
|
-
File filePath = new File(baseDirectory + "/" + args.getJSONObject(0).optString("filePath"));
|
|
1174
|
-
boolean sss = filePath.exists() ? true : false;
|
|
1175
|
-
callbackContext.success(sss ? "true" : "false");
|
|
1176
|
-
} catch (Exception e) {
|
|
1177
|
-
callbackContext.error(e.getMessage());
|
|
1178
|
-
}
|
|
1179
|
-
}
|
|
1180
|
-
|
|
1181
|
-
public void createDirectory(JSONArray args, CallbackContext callbackContext) {
|
|
1182
|
-
File appDirectory;
|
|
1183
|
-
FileWriter fileWriterObj;
|
|
1184
|
-
try {
|
|
1185
|
-
String fileName = args.getJSONObject(0).optString("filePath");
|
|
1186
|
-
appDirectory = new File(rootDirectory + "/" + fileName);
|
|
1187
|
-
if (!appDirectory.exists()) {
|
|
1188
|
-
appDirectory.mkdirs();
|
|
1189
|
-
}
|
|
1190
|
-
callbackContext.success();
|
|
1191
|
-
} catch (Exception e) {
|
|
1192
|
-
callbackContext.error(e.getMessage());
|
|
1193
|
-
}
|
|
1194
|
-
}
|
|
1195
|
-
|
|
1196
|
-
public void deleteDirectory(JSONArray args, CallbackContext callbackContext) {
|
|
1197
|
-
File appDirectory;
|
|
1198
|
-
FileWriter fileWriterObj;
|
|
1199
|
-
try {
|
|
1200
|
-
String fileName = args.getJSONObject(0).optString("filePath");
|
|
1201
|
-
if (fileName.equals("")) {
|
|
1202
|
-
callbackContext.error("Given directory path is empty.");
|
|
1203
|
-
} else {
|
|
1204
|
-
File dir = new File(rootDirectory + "/" + fileName);
|
|
1205
|
-
if (dir.exists()) {
|
|
1206
|
-
deleteRecursive(dir);
|
|
1207
|
-
callbackContext.success();
|
|
1208
|
-
}else{
|
|
1209
|
-
callbackContext.error("File does not exists");
|
|
1210
|
-
}
|
|
1211
|
-
|
|
1212
|
-
}
|
|
1213
|
-
} catch (Exception e) {
|
|
1214
|
-
callbackContext.error(e.getMessage());
|
|
1215
|
-
}
|
|
1216
|
-
}
|
|
1217
|
-
|
|
1218
|
-
public void deleteRecursive(File fileOrDirectory) {
|
|
1219
|
-
if (fileOrDirectory.isDirectory()) {
|
|
1220
|
-
for (File child : fileOrDirectory.listFiles()) {
|
|
1221
|
-
System.out.println("Child directory path: " + child);
|
|
1222
|
-
deleteRecursive(child);
|
|
1223
|
-
}
|
|
1224
|
-
}
|
|
1225
|
-
|
|
1226
|
-
fileOrDirectory.delete();
|
|
1227
|
-
}
|
|
1228
|
-
|
|
1229
|
-
private static int BUFFER_SIZE = 6 * 1024;
|
|
1230
|
-
|
|
1231
|
-
public static void unzip(String zipFile, String location, CallbackContext callbackContext) throws JSONException {
|
|
1232
|
-
try {
|
|
1233
|
-
File f = new File(location);
|
|
1234
|
-
if (!f.isDirectory()) {
|
|
1235
|
-
f.mkdirs();
|
|
1236
|
-
}
|
|
1237
|
-
ZipInputStream zin = new ZipInputStream(new FileInputStream(zipFile));
|
|
1238
|
-
try {
|
|
1239
|
-
ZipEntry ze = null;
|
|
1240
|
-
while ((ze = zin.getNextEntry()) != null) {
|
|
1241
|
-
String path = location + File.separator + ze.getName();
|
|
1242
|
-
|
|
1243
|
-
if (ze.isDirectory()) {
|
|
1244
|
-
File unzipFile = new File(path);
|
|
1245
|
-
if (!unzipFile.isDirectory()) {
|
|
1246
|
-
unzipFile.mkdirs();
|
|
1247
|
-
}
|
|
1248
|
-
} else {
|
|
1249
|
-
FileOutputStream fout = new FileOutputStream(path, false);
|
|
1250
|
-
|
|
1251
|
-
try {
|
|
1252
|
-
for (int c = zin.read(); c != -1; c = zin.read()) {
|
|
1253
|
-
fout.write(c);
|
|
1254
|
-
}
|
|
1255
|
-
zin.closeEntry();
|
|
1256
|
-
} finally {
|
|
1257
|
-
fout.close();
|
|
1258
|
-
}
|
|
1259
|
-
}
|
|
1260
|
-
}
|
|
1261
|
-
} finally {
|
|
1262
|
-
zin.close();
|
|
1263
|
-
}
|
|
1264
|
-
callbackContext.success();
|
|
1265
|
-
} catch (Exception e) {
|
|
1266
|
-
e.printStackTrace();
|
|
1267
|
-
callbackContext.error(e.getMessage());
|
|
1268
|
-
}
|
|
1269
|
-
}
|
|
1270
|
-
|
|
1271
|
-
public void getSubDirectoryList(JSONArray args, CallbackContext callbackContext) {
|
|
1272
|
-
try {
|
|
1273
|
-
String fileName = args.getJSONObject(0).optString("filePath");
|
|
1274
|
-
System.out.println("deleteFile Path is: " + fileName);
|
|
1275
|
-
if (fileName.equals("")) {
|
|
1276
|
-
callbackContext.error("Given directory path is empty.");
|
|
1277
|
-
} else {
|
|
1278
|
-
File dir = new File(rootDirectory + "/" + fileName);
|
|
1279
|
-
String[] subDirectories = dir.list(new FilenameFilter() {
|
|
1280
|
-
@Override
|
|
1281
|
-
public boolean accept(File current, String name) {
|
|
1282
|
-
return new File(current, name).isDirectory();
|
|
1283
|
-
}
|
|
1284
|
-
});
|
|
1285
|
-
StringBuilder fileNames = new StringBuilder();
|
|
1286
|
-
for (String subDirectory : subDirectories) {
|
|
1287
|
-
fileNames.append(subDirectory);
|
|
1288
|
-
fileNames.append("|");
|
|
1289
|
-
}
|
|
1290
|
-
callbackContext.success(fileNames.length() > 0 ? fileNames.substring(0, fileNames.length() - 1) : "");
|
|
1291
|
-
}
|
|
1292
|
-
} catch (Exception e) {
|
|
1293
|
-
callbackContext.error(e.getMessage());
|
|
1294
|
-
}
|
|
1295
|
-
}
|
|
1296
|
-
|
|
1297
|
-
public void getFileList(JSONArray args, CallbackContext callbackContext) {
|
|
1298
|
-
try {
|
|
1299
|
-
String fileName = args.getJSONObject(0).optString("filePath");
|
|
1300
|
-
System.out.println("deleteFile Path is: " + fileName);
|
|
1301
|
-
if (fileName.equals("")) {
|
|
1302
|
-
callbackContext.error("Given directory path is empty.");
|
|
1303
|
-
} else {
|
|
1304
|
-
File dir = new File(rootDirectory + "/" + fileName);
|
|
1305
|
-
String[] subDirectories = dir.list(new FilenameFilter() {
|
|
1306
|
-
@Override
|
|
1307
|
-
public boolean accept(File current, String name) {
|
|
1308
|
-
return new File(current, name).isFile();
|
|
1309
|
-
}
|
|
1310
|
-
});
|
|
1311
|
-
StringBuilder fileNames = new StringBuilder();
|
|
1312
|
-
for (String subDirectory : subDirectories) {
|
|
1313
|
-
fileNames.append(subDirectory);
|
|
1314
|
-
fileNames.append("|");
|
|
1315
|
-
}
|
|
1316
|
-
callbackContext.success(fileNames.length() > 0 ? fileNames.substring(0, fileNames.length() - 1) : "");
|
|
1317
|
-
}
|
|
1318
|
-
} catch (Exception e) {
|
|
1319
|
-
callbackContext.error(e.getMessage());
|
|
1320
|
-
}
|
|
1321
|
-
}
|
|
1322
|
-
|
|
1323
|
-
public static void getAppStateInfo(CallbackContext callbackContext, Context applicationContext) {
|
|
1324
|
-
String currentLine;
|
|
1325
|
-
File appStateIndicatorFile;
|
|
1326
|
-
try {
|
|
1327
|
-
appStateIndicatorFile = new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/" + clientID + "/" + countryCode + "/" + "app_state_info.txt");
|
|
1328
|
-
if (appStateIndicatorFile.exists()) {
|
|
1329
|
-
BufferedReader authFileReader = new BufferedReader(new FileReader(appStateIndicatorFile));
|
|
1330
|
-
StringBuilder authFileBuilder = new StringBuilder();
|
|
1331
|
-
while ((currentLine = authFileReader.readLine()) != null) {
|
|
1332
|
-
authFileBuilder.append(currentLine);
|
|
1333
|
-
}
|
|
1334
|
-
authFileReader.close();
|
|
1335
|
-
JSONObject authFileObj = new JSONObject(decrypt(authFileBuilder.toString()));
|
|
1336
|
-
long lastModifiedTime = appStateIndicatorFile.lastModified();
|
|
1337
|
-
Date date = new Date();
|
|
1338
|
-
date.setTime(lastModifiedTime);
|
|
1339
|
-
String lastModifiedDate = new SimpleDateFormat("yyyyMMdd", new mInterfaceUtil().locale).format(date);
|
|
1340
|
-
|
|
1341
|
-
if (authFileObj.optString("validDevice").toString().equals("nostatus") || !lastModifiedDate.equals(new SimpleDateFormat("yyyyMMdd", new mInterfaceUtil().locale).format(new Date()))) {
|
|
1342
|
-
if (isConnected(applicationContext)) {
|
|
1343
|
-
downloadAppStateInfo(callbackContext);
|
|
1344
|
-
} else {
|
|
1345
|
-
callbackContext.success(authFileObj.toString());
|
|
1346
|
-
}
|
|
1347
|
-
} else {
|
|
1348
|
-
callbackContext.success(authFileObj.toString());
|
|
1349
|
-
}
|
|
1350
|
-
} else {
|
|
1351
|
-
if (isConnected(applicationContext)) {
|
|
1352
|
-
downloadAppStateInfo(callbackContext);
|
|
1353
|
-
} else {
|
|
1354
|
-
callbackContext.success("");
|
|
1355
|
-
}
|
|
1356
|
-
}
|
|
1357
|
-
} catch (Exception e) {
|
|
1358
|
-
System.out.println(e.getMessage());
|
|
1359
|
-
callbackContext.success("");
|
|
1360
|
-
}
|
|
1361
|
-
}
|
|
1362
|
-
|
|
1363
|
-
public static void downloadAppStateInfo(CallbackContext callbackContext) {
|
|
1364
|
-
URL requestAuthenticationPath,
|
|
1365
|
-
requestValidateDevicePath, getKeysPath;
|
|
1366
|
-
HttpURLConnection urlConObj;
|
|
1367
|
-
OutputStreamWriter oStreamObj;
|
|
1368
|
-
BufferedWriter writerObj;
|
|
1369
|
-
StringBuilder serverResponseObj;
|
|
1370
|
-
BufferedReader responseReaderObj;
|
|
1371
|
-
JSONObject responseDataObj;
|
|
1372
|
-
String currentLine;
|
|
1373
|
-
try {
|
|
1374
|
-
getKeysPath = new URL(clientUrl + "/" + "common/components/Keys/" + "RetrieveKey.aspx");
|
|
1375
|
-
urlConObj = (HttpURLConnection)getKeysPath.openConnection();
|
|
1376
|
-
urlConObj.setDoOutput(true);
|
|
1377
|
-
urlConObj.setRequestMethod("POST");
|
|
1378
|
-
urlConObj.setRequestProperty("CONTENT-TYPE", "application/json");
|
|
1379
|
-
urlConObj.connect();
|
|
1380
|
-
JSONObject jsonObject1 = new JSONObject();
|
|
1381
|
-
jsonObject1 = jsonObject1.put("client_id", clientID);
|
|
1382
|
-
jsonObject1 = jsonObject1.put("country_code", countryCode);
|
|
1383
|
-
jsonObject1 = jsonObject1.put("purposeCode", "mobile_address_store");
|
|
1384
|
-
System.out.println("data format: " + jsonObject1.toString());
|
|
1385
|
-
oStreamObj = new OutputStreamWriter(urlConObj.getOutputStream());
|
|
1386
|
-
oStreamObj.write(jsonObject1.toString());
|
|
1387
|
-
oStreamObj.flush();
|
|
1388
|
-
oStreamObj.close();
|
|
1389
|
-
serverResponseObj = new StringBuilder();
|
|
1390
|
-
responseReaderObj = new BufferedReader(new InputStreamReader(urlConObj.getInputStream()));
|
|
1391
|
-
while ((currentLine = responseReaderObj.readLine()) != null) {
|
|
1392
|
-
serverResponseObj.append(currentLine);
|
|
1393
|
-
}
|
|
1394
|
-
responseReaderObj.close();
|
|
1395
|
-
urlConObj.disconnect();
|
|
1396
|
-
writerObj = new BufferedWriter(new FileWriter(new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/" + clientID + "/" + countryCode + "/" + "client_configuration_encrypted.txt")));
|
|
1397
|
-
writerObj.write(encrypt(serverResponseObj.toString()));
|
|
1398
|
-
writerObj.flush();
|
|
1399
|
-
writerObj.close();
|
|
1400
|
-
|
|
1401
|
-
/* App State info DATA REQUEST */
|
|
1402
|
-
requestAuthenticationPath = new URL(cvsUrl + "/" + "get_app_state_info.aspx");
|
|
1403
|
-
urlConObj = (HttpURLConnection) requestAuthenticationPath.openConnection();
|
|
1404
|
-
urlConObj.setDoOutput(true);
|
|
1405
|
-
urlConObj.setRequestMethod("POST");
|
|
1406
|
-
urlConObj.setRequestProperty("CONTENT-TYPE", "application/json");
|
|
1407
|
-
urlConObj.connect();
|
|
1408
|
-
|
|
1409
|
-
oStreamObj = new OutputStreamWriter(urlConObj.getOutputStream());
|
|
1410
|
-
JSONObject reqJson_obj = new JSONObject();
|
|
1411
|
-
reqJson_obj.put("client_id", clientID);
|
|
1412
|
-
reqJson_obj.put("country_code", countryCode);
|
|
1413
|
-
reqJson_obj.put("app_id", app_id);
|
|
1414
|
-
reqJson_obj.put("platform", platform);
|
|
1415
|
-
reqJson_obj.put("store", store);
|
|
1416
|
-
oStreamObj.write(reqJson_obj.toString());
|
|
1417
|
-
oStreamObj.flush();
|
|
1418
|
-
oStreamObj.close();
|
|
1419
|
-
serverResponseObj = new StringBuilder();
|
|
1420
|
-
responseReaderObj = new BufferedReader(new InputStreamReader(urlConObj.getInputStream()));
|
|
1421
|
-
while ((currentLine = responseReaderObj.readLine()) != null) {
|
|
1422
|
-
serverResponseObj.append(currentLine);
|
|
1423
|
-
}
|
|
1424
|
-
responseReaderObj.close();
|
|
1425
|
-
urlConObj.disconnect();
|
|
1426
|
-
responseDataObj = new JSONObject(serverResponseObj.toString());
|
|
1427
|
-
|
|
1428
|
-
/* VALIDATE DEVICE REQUEST */
|
|
1429
|
-
try {
|
|
1430
|
-
requestValidateDevicePath = new URL(clientUrl + "/api/security/validate_device");
|
|
1431
|
-
urlConObj = (HttpURLConnection) requestValidateDevicePath.openConnection();
|
|
1432
|
-
urlConObj.setDoOutput(true);
|
|
1433
|
-
urlConObj.setRequestMethod("POST");
|
|
1434
|
-
urlConObj.setRequestProperty("CONTENT-TYPE", "application/json");
|
|
1435
|
-
urlConObj.connect();
|
|
1436
|
-
oStreamObj = new OutputStreamWriter(urlConObj.getOutputStream());
|
|
1437
|
-
JSONObject inputJson_obj = new JSONObject();
|
|
1438
|
-
JSONObject context_obj = new JSONObject();
|
|
1439
|
-
JSONObject inputparam_obj = new JSONObject();
|
|
1440
|
-
|
|
1441
|
-
inputparam_obj.put("p_device_id", deviceID);
|
|
1442
|
-
inputparam_obj.put("p_company_id", clientID);
|
|
1443
|
-
inputparam_obj.put("p_country_code", countryCode);
|
|
1444
|
-
context_obj.put("sessionId", sessionID);
|
|
1445
|
-
context_obj.put("userId", userID);
|
|
1446
|
-
context_obj.put("client_id", clientID);
|
|
1447
|
-
context_obj.put("locale_id", localeID);
|
|
1448
|
-
context_obj.put("country_code", countryCode);
|
|
1449
|
-
context_obj.put("inputparam", inputparam_obj);
|
|
1450
|
-
|
|
1451
|
-
inputJson_obj.put("context", context_obj);
|
|
1452
|
-
oStreamObj.write(inputJson_obj.toString());
|
|
1453
|
-
oStreamObj.flush();
|
|
1454
|
-
oStreamObj.close();
|
|
1455
|
-
serverResponseObj = new StringBuilder();
|
|
1456
|
-
responseReaderObj = new BufferedReader(new InputStreamReader(urlConObj.getInputStream()));
|
|
1457
|
-
while ((currentLine = responseReaderObj.readLine()) != null) {
|
|
1458
|
-
serverResponseObj.append(currentLine);
|
|
1459
|
-
}
|
|
1460
|
-
responseReaderObj.close();
|
|
1461
|
-
urlConObj.disconnect();
|
|
1462
|
-
String responseStr = serverResponseObj.toString().replace("\\", "");
|
|
1463
|
-
responseStr = responseStr.substring(1, responseStr.length() - 1);
|
|
1464
|
-
JSONObject resultJsonObj = new JSONObject(responseStr).getJSONObject("outputparam");
|
|
1465
|
-
responseDataObj = responseDataObj.put("validDevice", "true");
|
|
1466
|
-
/* RESPONSE FOR AUTHENTICATION & VALIDATE DEVICE REQUESTS */
|
|
1467
|
-
writerObj = new BufferedWriter(new FileWriter(new File(rootDirectory, "/" + packageName + "/" + clientID + "/" + countryCode + "/" + "app_state_info.txt")));
|
|
1468
|
-
writerObj.write(encrypt(responseDataObj.toString()));
|
|
1469
|
-
writerObj.flush();
|
|
1470
|
-
writerObj.close();
|
|
1471
|
-
callbackContext.success(responseDataObj.toString());
|
|
1472
|
-
|
|
1473
|
-
} catch (Exception ex) {
|
|
1474
|
-
responseDataObj = responseDataObj.put("validDevice", "nostatus");
|
|
1475
|
-
writerObj = new BufferedWriter(new FileWriter(new File(rootDirectory, "/" + packageName + "/" + clientID + "/" + countryCode + "/" + "app_state_info.txt")));
|
|
1476
|
-
writerObj.write(encrypt(responseDataObj.toString()));
|
|
1477
|
-
writerObj.flush();
|
|
1478
|
-
writerObj.close();
|
|
1479
|
-
callbackContext.success(responseDataObj.toString());
|
|
1480
|
-
}
|
|
1481
|
-
} catch (Exception e) {
|
|
1482
|
-
System.out.println(e.getMessage());
|
|
1483
|
-
callbackContext.success("");
|
|
1484
|
-
}
|
|
1485
|
-
}
|
|
1486
|
-
|
|
1487
|
-
public static void validateAppStateInfo(Context applicationContext) {
|
|
1488
|
-
String currentLine;
|
|
1489
|
-
try {
|
|
1490
|
-
File appStateIndicatorFile = new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/" + clientID + "/" + countryCode + "/" + "app_state_info.txt");
|
|
1491
|
-
if (appStateIndicatorFile.exists()) {
|
|
1492
|
-
BufferedReader authFileReader = new BufferedReader(new FileReader(appStateIndicatorFile));
|
|
1493
|
-
StringBuilder authFileBuilder = new StringBuilder();
|
|
1494
|
-
while ((currentLine = authFileReader.readLine()) != null) {
|
|
1495
|
-
authFileBuilder.append(currentLine);
|
|
1496
|
-
}
|
|
1497
|
-
authFileReader.close();
|
|
1498
|
-
JSONObject authFileObj = new JSONObject(decrypt(authFileBuilder.toString()));
|
|
1499
|
-
long lastModifiedTime = appStateIndicatorFile.lastModified();
|
|
1500
|
-
Date date = new Date();
|
|
1501
|
-
date.setTime(lastModifiedTime);
|
|
1502
|
-
String lastModifiedDate = new SimpleDateFormat("yyyyMMdd", new mInterfaceUtil().locale).format(date);
|
|
1503
|
-
|
|
1504
|
-
if (authFileObj.optString("validDevice").toString().equals("nostatus") || !lastModifiedDate.equals(new SimpleDateFormat("yyyyMMdd", new mInterfaceUtil().locale).format(new Date()))) {
|
|
1505
|
-
if (isConnected(applicationContext)) {
|
|
1506
|
-
new UpdateAppStateInfo().execute();
|
|
1507
|
-
} else {
|
|
1508
|
-
mInterfaceService.handleAppStateTimer("success");
|
|
1509
|
-
}
|
|
1510
|
-
} else {
|
|
1511
|
-
mInterfaceService.handleAppStateTimer("success");
|
|
1512
|
-
}
|
|
1513
|
-
} else {
|
|
1514
|
-
if (isConnected(applicationContext)) {
|
|
1515
|
-
new UpdateAppStateInfo().execute();
|
|
1516
|
-
} else {
|
|
1517
|
-
mInterfaceService.handleAppStateTimer("failure");
|
|
1518
|
-
}
|
|
1519
|
-
}
|
|
1520
|
-
} catch (Exception e) {
|
|
1521
|
-
System.out.println(e.getMessage());
|
|
1522
|
-
mInterfaceService.handleAppStateTimer("failure");
|
|
1523
|
-
}
|
|
1524
|
-
}
|
|
1525
|
-
|
|
1526
|
-
/* App State info */
|
|
1527
|
-
private static class UpdateAppStateInfo extends AsyncTask<String,
|
|
1528
|
-
Void,
|
|
1529
|
-
String> {
|
|
1530
|
-
@Override
|
|
1531
|
-
protected String doInBackground(String... strings) {
|
|
1532
|
-
String currentLine;
|
|
1533
|
-
URL requestAuthenticationPath,
|
|
1534
|
-
requestValidateDevicePath, getKeysPath;
|
|
1535
|
-
HttpURLConnection urlConObj;
|
|
1536
|
-
OutputStreamWriter oStreamObj;
|
|
1537
|
-
BufferedWriter writerObj;
|
|
1538
|
-
StringBuilder serverResponseObj;
|
|
1539
|
-
BufferedReader responseReaderObj;
|
|
1540
|
-
JSONObject responseDataObj;
|
|
1541
|
-
try {
|
|
1542
|
-
getKeysPath = new URL(clientUrl + "/" + "common/components/Keys/" + "RetrieveKey.aspx");
|
|
1543
|
-
urlConObj = (HttpURLConnection)getKeysPath.openConnection();
|
|
1544
|
-
urlConObj.setDoOutput(true);
|
|
1545
|
-
urlConObj.setRequestMethod("POST");
|
|
1546
|
-
urlConObj.setRequestProperty("CONTENT-TYPE", "application/json");
|
|
1547
|
-
urlConObj.connect();
|
|
1548
|
-
JSONObject jsonObject1 = new JSONObject();
|
|
1549
|
-
jsonObject1 = jsonObject1.put("client_id", clientID);
|
|
1550
|
-
jsonObject1 = jsonObject1.put("country_code", countryCode);
|
|
1551
|
-
jsonObject1 = jsonObject1.put("purposeCode", "mobile_address_store");
|
|
1552
|
-
System.out.println("data format: " + jsonObject1.toString());
|
|
1553
|
-
oStreamObj = new OutputStreamWriter(urlConObj.getOutputStream());
|
|
1554
|
-
oStreamObj.write(jsonObject1.toString());
|
|
1555
|
-
oStreamObj.flush();
|
|
1556
|
-
oStreamObj.close();
|
|
1557
|
-
serverResponseObj = new StringBuilder();
|
|
1558
|
-
responseReaderObj = new BufferedReader(new InputStreamReader(urlConObj.getInputStream()));
|
|
1559
|
-
while ((currentLine = responseReaderObj.readLine()) != null) {
|
|
1560
|
-
serverResponseObj.append(currentLine);
|
|
1561
|
-
}
|
|
1562
|
-
responseReaderObj.close();
|
|
1563
|
-
urlConObj.disconnect();
|
|
1564
|
-
writerObj = new BufferedWriter(new FileWriter(new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/" + clientID + "/" + countryCode + "/" + "client_configuration_encrypted.txt")));
|
|
1565
|
-
writerObj.write(encrypt(serverResponseObj.toString()));
|
|
1566
|
-
writerObj.flush();
|
|
1567
|
-
writerObj.close();
|
|
1568
|
-
/* App State info DATA REQUEST */
|
|
1569
|
-
requestAuthenticationPath = new URL(cvsUrl + "/" + "get_app_state_info.aspx");
|
|
1570
|
-
urlConObj = (HttpURLConnection) requestAuthenticationPath.openConnection();
|
|
1571
|
-
urlConObj.setDoOutput(true);
|
|
1572
|
-
urlConObj.setRequestMethod("POST");
|
|
1573
|
-
urlConObj.setRequestProperty("CONTENT-TYPE", "application/json");
|
|
1574
|
-
urlConObj.connect();
|
|
1575
|
-
|
|
1576
|
-
oStreamObj = new OutputStreamWriter(urlConObj.getOutputStream());
|
|
1577
|
-
JSONObject reqJson_obj = new JSONObject();
|
|
1578
|
-
reqJson_obj.put("client_id", clientID);
|
|
1579
|
-
reqJson_obj.put("country_code", countryCode);
|
|
1580
|
-
reqJson_obj.put("app_id", app_id);
|
|
1581
|
-
reqJson_obj.put("platform", platform);
|
|
1582
|
-
reqJson_obj.put("store", store);
|
|
1583
|
-
oStreamObj.write(reqJson_obj.toString());
|
|
1584
|
-
oStreamObj.flush();
|
|
1585
|
-
oStreamObj.close();
|
|
1586
|
-
serverResponseObj = new StringBuilder();
|
|
1587
|
-
responseReaderObj = new BufferedReader(new InputStreamReader(urlConObj.getInputStream()));
|
|
1588
|
-
while ((currentLine = responseReaderObj.readLine()) != null) {
|
|
1589
|
-
serverResponseObj.append(currentLine);
|
|
1590
|
-
}
|
|
1591
|
-
responseReaderObj.close();
|
|
1592
|
-
urlConObj.disconnect();
|
|
1593
|
-
responseDataObj = new JSONObject(serverResponseObj.toString());
|
|
1594
|
-
|
|
1595
|
-
/* VALIDATE DEVICE REQUEST */
|
|
1596
|
-
try {
|
|
1597
|
-
requestValidateDevicePath = new URL(clientUrl + "/api/security/validate_device");
|
|
1598
|
-
urlConObj = (HttpURLConnection) requestValidateDevicePath.openConnection();
|
|
1599
|
-
urlConObj.setDoOutput(true);
|
|
1600
|
-
urlConObj.setRequestMethod("POST");
|
|
1601
|
-
urlConObj.setRequestProperty("CONTENT-TYPE", "application/json");
|
|
1602
|
-
urlConObj.connect();
|
|
1603
|
-
oStreamObj = new OutputStreamWriter(urlConObj.getOutputStream());
|
|
1604
|
-
JSONObject inputJson_obj = new JSONObject();
|
|
1605
|
-
JSONObject context_obj = new JSONObject();
|
|
1606
|
-
JSONObject inputparam_obj = new JSONObject();
|
|
1607
|
-
|
|
1608
|
-
inputparam_obj.put("p_device_id", deviceID);
|
|
1609
|
-
inputparam_obj.put("p_company_id", clientID);
|
|
1610
|
-
inputparam_obj.put("p_country_code", countryCode);
|
|
1611
|
-
context_obj.put("sessionId", sessionID);
|
|
1612
|
-
context_obj.put("userId", userID);
|
|
1613
|
-
context_obj.put("client_id", clientID);
|
|
1614
|
-
context_obj.put("locale_id", localeID);
|
|
1615
|
-
context_obj.put("country_code", countryCode);
|
|
1616
|
-
context_obj.put("inputparam", inputparam_obj);
|
|
1617
|
-
|
|
1618
|
-
inputJson_obj.put("context", context_obj);
|
|
1619
|
-
oStreamObj.write(inputJson_obj.toString());
|
|
1620
|
-
oStreamObj.flush();
|
|
1621
|
-
oStreamObj.close();
|
|
1622
|
-
serverResponseObj = new StringBuilder();
|
|
1623
|
-
responseReaderObj = new BufferedReader(new InputStreamReader(urlConObj.getInputStream()));
|
|
1624
|
-
while ((currentLine = responseReaderObj.readLine()) != null) {
|
|
1625
|
-
serverResponseObj.append(currentLine);
|
|
1626
|
-
}
|
|
1627
|
-
responseReaderObj.close();
|
|
1628
|
-
urlConObj.disconnect();
|
|
1629
|
-
String responseStr = serverResponseObj.toString().replace("\\", "");
|
|
1630
|
-
responseStr = responseStr.substring(1, responseStr.length() - 1);
|
|
1631
|
-
JSONObject resultJsonObj = new JSONObject(responseStr).getJSONObject("outputparam");
|
|
1632
|
-
responseDataObj = responseDataObj.put("validDevice", "true");
|
|
1633
|
-
/* RESPONSE FOR AUTHENTICATION & VALIDATE DEVICE REQUESTS */
|
|
1634
|
-
writerObj = new BufferedWriter(new FileWriter(new File(rootDirectory, "/" + packageName + "/" + clientID + "/" + countryCode + "/" + "app_state_info.txt")));
|
|
1635
|
-
writerObj.write(encrypt(responseDataObj.toString()));
|
|
1636
|
-
writerObj.flush();
|
|
1637
|
-
writerObj.close();
|
|
1638
|
-
|
|
1639
|
-
mInterfaceService.handleAppStateTimer("Success");
|
|
1640
|
-
|
|
1641
|
-
} catch (Exception ex) {
|
|
1642
|
-
responseDataObj = responseDataObj.put("validDevice", "nostatus");
|
|
1643
|
-
writerObj = new BufferedWriter(new FileWriter(new File(rootDirectory, "/" + packageName + "/" + clientID + "/" + countryCode + "/" + "app_state_info.txt")));
|
|
1644
|
-
writerObj.write(encrypt(responseDataObj.toString()));
|
|
1645
|
-
writerObj.flush();
|
|
1646
|
-
writerObj.close();
|
|
1647
|
-
mInterfaceService.handleAppStateTimer("Success");
|
|
1648
|
-
}
|
|
1649
|
-
} catch (Exception e) {
|
|
1650
|
-
System.out.println(e.getMessage());
|
|
1651
|
-
mInterfaceService.handleAppStateTimer("failure");
|
|
1652
|
-
}
|
|
1653
|
-
return null;
|
|
1654
|
-
}
|
|
1655
|
-
}
|
|
1656
|
-
|
|
1657
|
-
public boolean updateAppInfo(JSONArray args) {
|
|
1658
|
-
try {
|
|
1659
|
-
JSONObject appInfo = args.getJSONObject(0);
|
|
1660
|
-
mInterfaceUtil.app_id = appInfo.optString("app_id").toString();
|
|
1661
|
-
mInterfaceUtil.platform = appInfo.optString("platform").toString();
|
|
1662
|
-
mInterfaceUtil.deviceID = appInfo.optString("device_id").toString();
|
|
1663
|
-
mInterfaceUtil.clientID = appInfo.optString("client_id").toString();
|
|
1664
|
-
mInterfaceUtil.countryCode = appInfo.optString("country_code").toString();
|
|
1665
|
-
mInterfaceUtil.localeID = appInfo.optString("locale_id").toString();
|
|
1666
|
-
mInterfaceUtil.sessionID = appInfo.optString("session_id").toString();
|
|
1667
|
-
mInterfaceUtil.userID = appInfo.optString("user_Id").toString();
|
|
1668
|
-
mInterfaceUtil.employeeId = appInfo.optString("employee_id").toString();
|
|
1669
|
-
mInterfaceUtil.clientUrl = appInfo.optString("client_url").toString();
|
|
1670
|
-
mInterfaceUtil.cvsUrl = appInfo.optString("cvs_url").toString();
|
|
1671
|
-
mInterfaceUtil.store = appInfo.optString("store_name").toString();
|
|
1672
|
-
} catch (Exception e) {
|
|
1673
|
-
return false;
|
|
1674
|
-
}
|
|
1675
|
-
return true;
|
|
1676
|
-
}
|
|
1677
|
-
|
|
1678
|
-
public static boolean isConnected(Context applicationContext) {
|
|
1679
|
-
ConnectivityManager online = (ConnectivityManager) applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
1680
|
-
NetworkInfo networkInfo = online.getActiveNetworkInfo();
|
|
1681
|
-
if (networkInfo != null && networkInfo.isConnected()) {
|
|
1682
|
-
return true;
|
|
1683
|
-
} else {
|
|
1684
|
-
return false;
|
|
1685
|
-
}
|
|
1686
|
-
}
|
|
1
|
+
package com.selfservit.util;
|
|
2
|
+
|
|
3
|
+
import android.annotation.TargetApi;
|
|
4
|
+
import android.app.Activity;
|
|
5
|
+
import android.content.ContentUris;
|
|
6
|
+
import android.content.ContentValues;
|
|
7
|
+
import android.content.Context;
|
|
8
|
+
import android.database.Cursor;
|
|
9
|
+
import android.graphics.Bitmap;
|
|
10
|
+
import android.graphics.BitmapFactory;
|
|
11
|
+
import android.location.LocationListener;
|
|
12
|
+
import android.location.LocationManager;
|
|
13
|
+
import android.media.MediaMetadataRetriever;
|
|
14
|
+
import android.media.MediaScannerConnection;
|
|
15
|
+
import android.media.ThumbnailUtils;
|
|
16
|
+
import android.net.ConnectivityManager;
|
|
17
|
+
import android.net.NetworkInfo;
|
|
18
|
+
import android.net.Uri;
|
|
19
|
+
import android.os.AsyncTask;
|
|
20
|
+
import android.os.Build;
|
|
21
|
+
import android.os.Environment;
|
|
22
|
+
import android.provider.MediaStore;
|
|
23
|
+
import android.support.annotation.RequiresApi;
|
|
24
|
+
import android.util.Base64;
|
|
25
|
+
import android.util.Log;
|
|
26
|
+
import android.widget.Toast;
|
|
27
|
+
|
|
28
|
+
import org.apache.cordova.CallbackContext;
|
|
29
|
+
import org.apache.cordova.PluginResult;
|
|
30
|
+
import org.json.JSONArray;
|
|
31
|
+
import org.json.JSONException;
|
|
32
|
+
import org.json.JSONObject;
|
|
33
|
+
|
|
34
|
+
import java.io.BufferedInputStream;
|
|
35
|
+
import java.io.BufferedReader;
|
|
36
|
+
import java.io.BufferedWriter;
|
|
37
|
+
import java.io.ByteArrayOutputStream;
|
|
38
|
+
import java.io.DataOutputStream;
|
|
39
|
+
import java.io.File;
|
|
40
|
+
import java.io.FileInputStream;
|
|
41
|
+
import java.io.FileOutputStream;
|
|
42
|
+
import java.io.FileReader;
|
|
43
|
+
import java.io.FileWriter;
|
|
44
|
+
import java.io.FilenameFilter;
|
|
45
|
+
import java.io.IOException;
|
|
46
|
+
import java.io.InputStream;
|
|
47
|
+
import java.io.InputStreamReader;
|
|
48
|
+
import java.io.OutputStream;
|
|
49
|
+
import java.io.OutputStreamWriter;
|
|
50
|
+
import java.net.HttpURLConnection;
|
|
51
|
+
import java.net.URL;
|
|
52
|
+
import java.text.SimpleDateFormat;
|
|
53
|
+
import java.util.Arrays;
|
|
54
|
+
import java.util.Date;
|
|
55
|
+
import java.util.Locale;
|
|
56
|
+
import java.util.Scanner;
|
|
57
|
+
import java.util.zip.ZipEntry;
|
|
58
|
+
import java.util.zip.ZipInputStream;
|
|
59
|
+
|
|
60
|
+
import javax.crypto.Cipher;
|
|
61
|
+
import javax.crypto.spec.IvParameterSpec;
|
|
62
|
+
import javax.crypto.spec.SecretKeySpec;
|
|
63
|
+
|
|
64
|
+
import static com.selfservit.util.mInterface.pathComponent;
|
|
65
|
+
|
|
66
|
+
public class mInterfaceUtil {
|
|
67
|
+
|
|
68
|
+
LocationManager locationManager;
|
|
69
|
+
LocationListener locationListener;
|
|
70
|
+
public static String packageName = "";
|
|
71
|
+
public static File rootDirectory;
|
|
72
|
+
public static final Locale locale = Locale.US;
|
|
73
|
+
private static final String encryptionKey = "8080808080808080";
|
|
74
|
+
private static final String characterEncoding = "UTF-8";
|
|
75
|
+
private static final String cipherTransformation = "AES/CBC/PKCS5PADDING";
|
|
76
|
+
private static final String aesEncryptionAlgorithem = "AES";
|
|
77
|
+
//Account information
|
|
78
|
+
public static String app_id = "";
|
|
79
|
+
public static String platform = "";
|
|
80
|
+
public static String store = "";
|
|
81
|
+
public static String sessionID = "";
|
|
82
|
+
public static String localeID = "";
|
|
83
|
+
public static String clientID = "";
|
|
84
|
+
public static String countryCode = "";
|
|
85
|
+
public static String userID = "";
|
|
86
|
+
public static String employeeId = "";
|
|
87
|
+
public static String cvsUrl = "";
|
|
88
|
+
public static String clientUrl = "";
|
|
89
|
+
public static String deviceID = "";
|
|
90
|
+
public static String timerInd = "";
|
|
91
|
+
|
|
92
|
+
@RequiresApi(api = Build.VERSION_CODES.O)
|
|
93
|
+
public static String decrypt(String encryptedText) {
|
|
94
|
+
String decryptedText = "";
|
|
95
|
+
try {
|
|
96
|
+
Cipher cipher = Cipher.getInstance(cipherTransformation);
|
|
97
|
+
byte[] key = encryptionKey.getBytes(characterEncoding);
|
|
98
|
+
SecretKeySpec secretKey = new SecretKeySpec(key, aesEncryptionAlgorithem);
|
|
99
|
+
IvParameterSpec ivparameterspec = new IvParameterSpec(key);
|
|
100
|
+
cipher.init(Cipher.DECRYPT_MODE, secretKey, ivparameterspec);
|
|
101
|
+
byte[] cipherText = android.util.Base64.decode(encryptedText, 0);
|
|
102
|
+
decryptedText = new String(cipher.doFinal(cipherText), "UTF-8");
|
|
103
|
+
} catch (Exception E) {
|
|
104
|
+
System.out.println("decrypt Exception : " + E.getMessage());
|
|
105
|
+
}
|
|
106
|
+
return decryptedText;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
public void DownloadChatAttachment(String requestURL, String filePath, String thumbnailInd, Context context, CallbackContext callbackContext, Activity activity) {
|
|
110
|
+
try {
|
|
111
|
+
class DownloadFile extends AsyncTask<String, String, String> {
|
|
112
|
+
@Override
|
|
113
|
+
protected void onPreExecute() {
|
|
114
|
+
}
|
|
115
|
+
@Override
|
|
116
|
+
protected String doInBackground(String... args) {
|
|
117
|
+
BufferedInputStream input = null;
|
|
118
|
+
OutputStream output = null;
|
|
119
|
+
HttpURLConnection connection = null;
|
|
120
|
+
int count;
|
|
121
|
+
int progressCheck=10;
|
|
122
|
+
try {
|
|
123
|
+
URL url = new URL((requestURL).replaceAll(" ", "%20"));
|
|
124
|
+
connection = (HttpURLConnection) url.openConnection();
|
|
125
|
+
connection.setRequestProperty("Connection", "Keep-Alive");
|
|
126
|
+
connection.connect();
|
|
127
|
+
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
|
|
128
|
+
return "Server returned HTTP " + connection.getResponseCode() + " " + connection.getResponseMessage();
|
|
129
|
+
}
|
|
130
|
+
int fileLength = connection.getContentLength();
|
|
131
|
+
input = new BufferedInputStream(connection.getInputStream(),8192);
|
|
132
|
+
|
|
133
|
+
//File rootPath = Environment.getExternalStorageDirectory();
|
|
134
|
+
String rootPath = context.getExternalMediaDirs()[0].toString();
|
|
135
|
+
File filesourceDirecory = new File(rootPath + "/" + pathComponent(filePath));
|
|
136
|
+
if (!filesourceDirecory.exists()) {
|
|
137
|
+
filesourceDirecory.mkdirs();
|
|
138
|
+
}
|
|
139
|
+
File fileSavePath = new File(rootPath + "/" + filePath);
|
|
140
|
+
output = new FileOutputStream(fileSavePath);
|
|
141
|
+
byte data[] = new byte[1024];
|
|
142
|
+
long progress = 0;
|
|
143
|
+
int progressToSend = 0;
|
|
144
|
+
while ((count = input.read(data)) != -1) {
|
|
145
|
+
// allow canceling with back button
|
|
146
|
+
if (isCancelled()) {
|
|
147
|
+
input.close();
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
progress += count;
|
|
151
|
+
progressToSend = (int)((progress * 100) / fileLength);
|
|
152
|
+
|
|
153
|
+
if(progressToSend >= progressCheck){
|
|
154
|
+
JSONObject progressObj = new JSONObject();
|
|
155
|
+
progressObj.put("progress", progressCheck);
|
|
156
|
+
progressObj.put("fileLength", fileLength);
|
|
157
|
+
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, progressObj);
|
|
158
|
+
pluginResult.setKeepCallback(true);
|
|
159
|
+
callbackContext.sendPluginResult(pluginResult);
|
|
160
|
+
progressCheck = progressCheck + 10;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
output.write(data, 0, count);
|
|
164
|
+
}
|
|
165
|
+
} catch (Exception e) {
|
|
166
|
+
callbackContext.error("Failure" + e.getMessage());
|
|
167
|
+
}
|
|
168
|
+
if(thumbnailInd.equalsIgnoreCase("true")){
|
|
169
|
+
return filePath;
|
|
170
|
+
}else{
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
public void onPostExecute(String result) {
|
|
175
|
+
try {
|
|
176
|
+
MediaScannerConnection.scanFile(context,
|
|
177
|
+
new String[] { context.getExternalMediaDirs()[0].toString() },
|
|
178
|
+
null,
|
|
179
|
+
(path, uri) -> {
|
|
180
|
+
Log.i("ExternalStorage", "Scanned " + path + ":");
|
|
181
|
+
Log.i("ExternalStorage", "-> uri=" + uri);
|
|
182
|
+
});
|
|
183
|
+
if (result != null) {
|
|
184
|
+
if(result.indexOf('.') != -1){
|
|
185
|
+
String extension = "." + result.substring(result.lastIndexOf(".") + 1).toLowerCase(),
|
|
186
|
+
filePath = context.getExternalMediaDirs()[0].toString()+"/"+result;
|
|
187
|
+
String thumbnail = getFileThumbnail(filePath,extension,context);
|
|
188
|
+
callbackContext.success(thumbnail);
|
|
189
|
+
} else{
|
|
190
|
+
callbackContext.error("Failure");
|
|
191
|
+
}
|
|
192
|
+
} else {
|
|
193
|
+
callbackContext.success("success");
|
|
194
|
+
}
|
|
195
|
+
} catch (Exception e) {
|
|
196
|
+
e.printStackTrace();
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
new DownloadFile().execute();
|
|
201
|
+
} catch (Exception e) {
|
|
202
|
+
e.printStackTrace();
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
public static String encrypt(String plainText) {
|
|
206
|
+
String encryptedText = "";
|
|
207
|
+
try {
|
|
208
|
+
Cipher cipher = Cipher.getInstance(cipherTransformation);
|
|
209
|
+
byte[] key = encryptionKey.getBytes(characterEncoding);
|
|
210
|
+
SecretKeySpec secretKey = new SecretKeySpec(key, aesEncryptionAlgorithem);
|
|
211
|
+
IvParameterSpec ivparameterspec = new IvParameterSpec(key);
|
|
212
|
+
cipher.init(Cipher.ENCRYPT_MODE, secretKey, ivparameterspec);
|
|
213
|
+
byte[] cipherText = android.util.Base64.encode(cipher.doFinal(plainText.getBytes("UTF8")), 0);
|
|
214
|
+
encryptedText = new String(cipherText);
|
|
215
|
+
} catch (Exception E) {
|
|
216
|
+
System.out.println("decrypt Exception : " + E.getMessage());
|
|
217
|
+
}
|
|
218
|
+
return encryptedText;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/*FOR GETTING CURRENT LOCATION */
|
|
222
|
+
public String getLocation(Context context) {
|
|
223
|
+
String latitude = "",
|
|
224
|
+
longitude = "";
|
|
225
|
+
|
|
226
|
+
String currentLine, lastKnownLocation = "";
|
|
227
|
+
try {
|
|
228
|
+
BufferedReader readerObj = new BufferedReader(new FileReader(new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/LastKnownLocation_encrypted.txt")));
|
|
229
|
+
while ((currentLine = readerObj.readLine()) != null) {
|
|
230
|
+
lastKnownLocation = currentLine;
|
|
231
|
+
}
|
|
232
|
+
readerObj.close();
|
|
233
|
+
String encryptedLocation = decrypt(lastKnownLocation);
|
|
234
|
+
String[] splitStr = encryptedLocation.split(",");
|
|
235
|
+
latitude = splitStr[0];
|
|
236
|
+
longitude = splitStr[1];
|
|
237
|
+
} catch (Exception e) {
|
|
238
|
+
e.printStackTrace();
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
//*** SUBSTRING LATITUDE,LONGITUDE IF GREATER THAN 10 POINTS ***//
|
|
242
|
+
if (latitude.length() > 10) {
|
|
243
|
+
latitude = latitude.substring(0, 10);
|
|
244
|
+
}
|
|
245
|
+
if (longitude.length() > 10) {
|
|
246
|
+
longitude = longitude.substring(0, 10);
|
|
247
|
+
}
|
|
248
|
+
//*** RETURN LATITUDE,LONGITUDE VALUE IN JSON OBJECT FORMAT ***//
|
|
249
|
+
return "{\"lat\":" + "\"" + latitude + "\"" + ",\"lon\":" + "\"" + longitude + "\"}";
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/*FOR CHECK LOCATION SERVICE SETTING IS ENABLED OR NOT */
|
|
253
|
+
public String checkLocation(Context context) {
|
|
254
|
+
Boolean isEnabled = false;
|
|
255
|
+
|
|
256
|
+
//*** REGISTER THE LOCATION MANAGER *** //
|
|
257
|
+
locationManager = (LocationManager) context.getSystemService(context.LOCATION_SERVICE);
|
|
258
|
+
//*** CHECK LOCATION SETTING ENABLED OR NOT ***//
|
|
259
|
+
isEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
|
|
260
|
+
|
|
261
|
+
if (!isEnabled) {
|
|
262
|
+
isEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return String.valueOf(isEnabled);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/*FOR CHECK QUEUE IS PROCESSING OR NOT */
|
|
269
|
+
public String getSyncIndicator(Context context) {
|
|
270
|
+
File queueFile, queueFolder;
|
|
271
|
+
Boolean syncIndication = false;
|
|
272
|
+
try {
|
|
273
|
+
queueFile = new File(rootDirectory + "/" + mInterfaceUtil.packageName + "/database/queue_mgr_encrypted.txt");
|
|
274
|
+
queueFolder = new File(rootDirectory + "/" + mInterfaceUtil.packageName + "/database/queue");
|
|
275
|
+
if (queueFile.exists()) {
|
|
276
|
+
if (queueFile.length() == 0) {
|
|
277
|
+
syncIndication = true;
|
|
278
|
+
}
|
|
279
|
+
} else {
|
|
280
|
+
syncIndication = true;
|
|
281
|
+
}
|
|
282
|
+
if (syncIndication) {
|
|
283
|
+
if (queueFolder.exists()) {
|
|
284
|
+
if (queueFolder.listFiles().length != 0) {
|
|
285
|
+
syncIndication = false;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return String.valueOf(syncIndication);
|
|
290
|
+
} catch (Exception e) {
|
|
291
|
+
return String.valueOf(e);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
public void deleteMultipleFiles(String str, CallbackContext callbackContext) {
|
|
297
|
+
File baseDirectory = rootDirectory;
|
|
298
|
+
try {
|
|
299
|
+
File filePath = new File(baseDirectory + "/" + str);
|
|
300
|
+
if (filePath.exists()) {
|
|
301
|
+
filePath.delete();
|
|
302
|
+
} else {
|
|
303
|
+
callbackContext.error("No file there & File not deleted for " + str);
|
|
304
|
+
}
|
|
305
|
+
} catch (Exception e) {
|
|
306
|
+
callbackContext.error(e.getMessage());
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
public void copyConfigFile(CallbackContext callbackContext, JSONArray arguments) {
|
|
311
|
+
JSONObject inputFileObj;
|
|
312
|
+
String srcFilePath,
|
|
313
|
+
srcFileName,
|
|
314
|
+
desFilePath,
|
|
315
|
+
desFileName;
|
|
316
|
+
InputStream srcFileReader;
|
|
317
|
+
OutputStream desFileWriter;
|
|
318
|
+
int srcFileSize;
|
|
319
|
+
byte[] buf;
|
|
320
|
+
File sourceFileObj, desFileObj;
|
|
321
|
+
String aa = "aaaa";
|
|
322
|
+
try {
|
|
323
|
+
for (int index = 0; index < arguments.length(); index++) {
|
|
324
|
+
inputFileObj = arguments.getJSONObject(index);
|
|
325
|
+
File rootDir = rootDirectory;
|
|
326
|
+
srcFilePath = rootDir + "/" + inputFileObj.optString("srcPath").toString();
|
|
327
|
+
srcFileName = inputFileObj.optString("srcFile").toString();
|
|
328
|
+
desFilePath = rootDir + "/" + inputFileObj.optString("desPath").toString();
|
|
329
|
+
desFileName = inputFileObj.optString("desFile").toString();
|
|
330
|
+
sourceFileObj = new File(srcFilePath + "/" + srcFileName);
|
|
331
|
+
desFileObj = new File(desFilePath + "/" + desFileName);
|
|
332
|
+
//** CHECK DESTINATION FILE PATH EXITS OR NOT **//
|
|
333
|
+
if (!new File(desFilePath).exists()) {
|
|
334
|
+
new File(desFilePath).mkdirs();
|
|
335
|
+
}
|
|
336
|
+
//** CHECK SOURCE FILE EXITS OR NOT **//
|
|
337
|
+
if (sourceFileObj.exists()) {
|
|
338
|
+
srcFileReader = new FileInputStream(sourceFileObj);
|
|
339
|
+
desFileWriter = new FileOutputStream(desFileObj);
|
|
340
|
+
buf = new byte[1024];
|
|
341
|
+
//** WRITE SOURCE FILE INTO CONTENT_STORE DESTINATION PATH **//
|
|
342
|
+
while ((srcFileSize = srcFileReader.read(buf)) > 0) {
|
|
343
|
+
desFileWriter.write(buf, 0, srcFileSize);
|
|
344
|
+
}
|
|
345
|
+
srcFileReader.close();
|
|
346
|
+
desFileWriter.close();
|
|
347
|
+
} else {
|
|
348
|
+
callbackContext.error("failure");
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
callbackContext.success("success");
|
|
352
|
+
} catch (Exception e) {
|
|
353
|
+
callbackContext.error(e.getMessage());
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/* COPY A FILE FROM ONE LOCATION TO ANOTHER LOCATION */
|
|
358
|
+
public void copyFile(CallbackContext callbackContext, JSONArray arguments) {
|
|
359
|
+
JSONObject inputFileObj;
|
|
360
|
+
String srcFilePath,
|
|
361
|
+
srcFileName,
|
|
362
|
+
desFilePath,
|
|
363
|
+
desFileName;
|
|
364
|
+
InputStream srcFileReader;
|
|
365
|
+
OutputStream desFileWriter;
|
|
366
|
+
int srcFileSize;
|
|
367
|
+
byte[] buf;
|
|
368
|
+
File sourceFileObj, desFileObj;
|
|
369
|
+
try {
|
|
370
|
+
for (int index = 0; index < arguments.length(); index++) {
|
|
371
|
+
inputFileObj = arguments.getJSONObject(index);
|
|
372
|
+
srcFilePath = rootDirectory + "/" + inputFileObj.optString("sourceFilePath").toString();
|
|
373
|
+
srcFileName = inputFileObj.optString("sourceFileName").toString();
|
|
374
|
+
desFilePath = rootDirectory + "/" + inputFileObj.optString("targetFilePath").toString();
|
|
375
|
+
desFileName = inputFileObj.optString("targetFileName").toString();
|
|
376
|
+
sourceFileObj = new File(srcFilePath + "/" + srcFileName);
|
|
377
|
+
desFileObj = new File(desFilePath + "/" + desFileName);
|
|
378
|
+
//** CHECK DESTINATION FILE PATH EXITS OR NOT **//
|
|
379
|
+
if (!new File(desFilePath).exists()) {
|
|
380
|
+
new File(desFilePath).mkdirs();
|
|
381
|
+
}
|
|
382
|
+
//** CHECK SOURCE FILE EXITS OR NOT **//
|
|
383
|
+
if (sourceFileObj.exists()) {
|
|
384
|
+
srcFileReader = new FileInputStream(sourceFileObj);
|
|
385
|
+
desFileWriter = new FileOutputStream(desFileObj);
|
|
386
|
+
buf = new byte[1024];
|
|
387
|
+
//** WRITE SOURCE FILE INTO CONTENT_STORE DESTINATION PATH **//
|
|
388
|
+
while ((srcFileSize = srcFileReader.read(buf)) > 0) {
|
|
389
|
+
desFileWriter.write(buf, 0, srcFileSize);
|
|
390
|
+
}
|
|
391
|
+
srcFileReader.close();
|
|
392
|
+
desFileWriter.close();
|
|
393
|
+
} else {
|
|
394
|
+
callbackContext.error("File not exists");
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
callbackContext.success("success");
|
|
398
|
+
} catch (Exception e) {
|
|
399
|
+
callbackContext.error(e.getMessage());
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/* COPY A FILE FROM ONE LOCATION TO ANOTHER LOCATION */
|
|
404
|
+
public void copyAttachmentFile(CallbackContext callbackContext, JSONArray arguments) {
|
|
405
|
+
JSONObject inputFileObj;
|
|
406
|
+
String srcFilePath,
|
|
407
|
+
srcFileName,
|
|
408
|
+
desFilePath,
|
|
409
|
+
desFileName,
|
|
410
|
+
queueCopyPath,
|
|
411
|
+
queueCopyFileName;
|
|
412
|
+
InputStream srcFileReader;
|
|
413
|
+
OutputStream desFileWriter, queueFileWriter;
|
|
414
|
+
int srcFileSize;
|
|
415
|
+
byte[] buf;
|
|
416
|
+
File sourceFileObj, desFileObj, queueFileObj;
|
|
417
|
+
try {
|
|
418
|
+
for (int index = 0; index < arguments.length(); index++) {
|
|
419
|
+
inputFileObj = arguments.getJSONObject(index);
|
|
420
|
+
srcFilePath = inputFileObj.optString("srcPath").toString();
|
|
421
|
+
srcFileName = inputFileObj.optString("srcFile").toString();
|
|
422
|
+
desFilePath = rootDirectory + "/" + inputFileObj.optString("desPath").toString();
|
|
423
|
+
desFileName = inputFileObj.optString("desFile").toString();
|
|
424
|
+
queueCopyPath = rootDirectory + "/" + inputFileObj.optString("queueAttachPath").toString();
|
|
425
|
+
queueCopyFileName = inputFileObj.optString("queueAttachFile").toString();
|
|
426
|
+
sourceFileObj = new File(srcFilePath + "/" + srcFileName);
|
|
427
|
+
desFileObj = new File(desFilePath + "/" + desFileName);
|
|
428
|
+
queueFileObj = new File(queueCopyPath + "/" + queueCopyFileName);
|
|
429
|
+
//** CHECK DESTINATION FILE PATH EXITS OR NOT **//
|
|
430
|
+
if (!new File(desFilePath).exists()) {
|
|
431
|
+
new File(desFilePath).mkdirs();
|
|
432
|
+
}
|
|
433
|
+
if (!new File(queueCopyPath).exists()) {
|
|
434
|
+
new File(queueCopyPath).mkdirs();
|
|
435
|
+
}
|
|
436
|
+
//** CHECK SOURCE FILE EXITS OR NOT **//
|
|
437
|
+
if (sourceFileObj.exists()) {
|
|
438
|
+
srcFileReader = new FileInputStream(sourceFileObj);
|
|
439
|
+
desFileWriter = new FileOutputStream(desFileObj);
|
|
440
|
+
buf = new byte[1024];
|
|
441
|
+
//** WRITE SOURCE FILE INTO CONTENT_STORE DESTINATION PATH **//
|
|
442
|
+
while ((srcFileSize = srcFileReader.read(buf)) > 0) {
|
|
443
|
+
desFileWriter.write(buf, 0, srcFileSize);
|
|
444
|
+
}
|
|
445
|
+
srcFileReader.close();
|
|
446
|
+
desFileWriter.close();
|
|
447
|
+
|
|
448
|
+
srcFileReader = new FileInputStream(sourceFileObj);
|
|
449
|
+
queueFileWriter = new FileOutputStream(queueFileObj);
|
|
450
|
+
buf = new byte[1024];
|
|
451
|
+
//** WRITE SOURCE FILE INTO QUEUE DESTINATION PATH **//
|
|
452
|
+
while ((srcFileSize = srcFileReader.read(buf)) > 0) {
|
|
453
|
+
queueFileWriter.write(buf, 0, srcFileSize);
|
|
454
|
+
}
|
|
455
|
+
srcFileReader.close();
|
|
456
|
+
queueFileWriter.close();
|
|
457
|
+
} else {
|
|
458
|
+
callbackContext.error("failure");
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
deleteFilesFromDirectory();
|
|
462
|
+
callbackContext.success("success");
|
|
463
|
+
} catch (Exception e) {
|
|
464
|
+
callbackContext.error(e.getMessage());
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/* Move A FILE FROM ONE LOCATION TO ANOTHER LOCATION */
|
|
469
|
+
public void moveFile(CallbackContext callbackContext, JSONArray arguments) {
|
|
470
|
+
JSONObject inputFileObj;
|
|
471
|
+
String srcFilePath,
|
|
472
|
+
srcFileName,
|
|
473
|
+
desFilePath,
|
|
474
|
+
desFileName;
|
|
475
|
+
InputStream srcFileReader;
|
|
476
|
+
OutputStream desFileWriter;
|
|
477
|
+
int srcFileSize;
|
|
478
|
+
byte[] buf;
|
|
479
|
+
File sourceFile, desFile;
|
|
480
|
+
try {
|
|
481
|
+
for (int index = 0; index < arguments.length(); index++) {
|
|
482
|
+
inputFileObj = arguments.getJSONObject(index);
|
|
483
|
+
srcFilePath = rootDirectory + "/" + inputFileObj.optString("sourceFilePath").toString();
|
|
484
|
+
srcFileName = inputFileObj.optString("sourceFileName").toString();
|
|
485
|
+
desFilePath = rootDirectory + "/" + inputFileObj.optString("targetFilePath").toString();
|
|
486
|
+
desFileName = inputFileObj.optString("targetFileName").toString();
|
|
487
|
+
sourceFile = new File(srcFilePath + "/" + srcFileName);
|
|
488
|
+
desFile = new File(desFilePath + "/" + desFileName);
|
|
489
|
+
//** CHECK DESTINATION FILE PATH EXITS OR NOT **//
|
|
490
|
+
if (!new File(desFilePath).exists()) {
|
|
491
|
+
new File(desFilePath).mkdirs();
|
|
492
|
+
}
|
|
493
|
+
//** CHECK SOURCE FILE EXITS OR NOT **//
|
|
494
|
+
if (sourceFile.exists()) {
|
|
495
|
+
srcFileReader = new FileInputStream(sourceFile);
|
|
496
|
+
desFileWriter = new FileOutputStream(desFile);
|
|
497
|
+
buf = new byte[1024];
|
|
498
|
+
//** WRITE SOURCE FILE INTO CONTENT_STORE DESTINATION PATH **//
|
|
499
|
+
while ((srcFileSize = srcFileReader.read(buf)) > 0) {
|
|
500
|
+
desFileWriter.write(buf, 0, srcFileSize);
|
|
501
|
+
}
|
|
502
|
+
srcFileReader.close();
|
|
503
|
+
desFileWriter.close();
|
|
504
|
+
/* Delete the source file */
|
|
505
|
+
sourceFile.delete();
|
|
506
|
+
} else {
|
|
507
|
+
callbackContext.error("File not exists");
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
callbackContext.success("success");
|
|
511
|
+
} catch (Exception e) {
|
|
512
|
+
callbackContext.error(e.getMessage());
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
public void copyFileOld(CallbackContext callbackContext, JSONArray arguments) {
|
|
517
|
+
JSONObject inputFileObj;
|
|
518
|
+
String srcFilePath,
|
|
519
|
+
srcFileName,
|
|
520
|
+
desFilePath,
|
|
521
|
+
desFileName,
|
|
522
|
+
queueCopyPath,
|
|
523
|
+
queueCopyFileName;
|
|
524
|
+
InputStream srcFileReader;
|
|
525
|
+
OutputStream desFileWriter, queueFileWriter;
|
|
526
|
+
int srcFileSize;
|
|
527
|
+
byte[] buf;
|
|
528
|
+
File sourceFileObj, desFileObj, queueFileObj;
|
|
529
|
+
try {
|
|
530
|
+
for (int index = 0; index < arguments.length(); index++) {
|
|
531
|
+
inputFileObj = arguments.getJSONObject(index);
|
|
532
|
+
srcFilePath = inputFileObj.optString("srcPath").toString();
|
|
533
|
+
srcFileName = inputFileObj.optString("srcFile").toString();
|
|
534
|
+
desFilePath = rootDirectory + "/" + inputFileObj.optString("desPath").toString();
|
|
535
|
+
desFileName = inputFileObj.optString("desFile").toString();
|
|
536
|
+
queueCopyPath = rootDirectory + "/" + inputFileObj.optString("queueAttachPath").toString();
|
|
537
|
+
queueCopyFileName = inputFileObj.optString("queueAttachFile").toString();
|
|
538
|
+
sourceFileObj = new File(srcFilePath + "/" + srcFileName);
|
|
539
|
+
desFileObj = new File(desFilePath + "/" + desFileName);
|
|
540
|
+
queueFileObj = new File(queueCopyPath + "/" + queueCopyFileName);
|
|
541
|
+
//** CHECK DESTINATION FILE PATH EXITS OR NOT **//
|
|
542
|
+
if (!new File(desFilePath).exists()) {
|
|
543
|
+
new File(desFilePath).mkdirs();
|
|
544
|
+
}
|
|
545
|
+
if (!new File(queueCopyPath).exists()) {
|
|
546
|
+
new File(queueCopyPath).mkdirs();
|
|
547
|
+
}
|
|
548
|
+
//** CHECK SOURCE FILE EXITS OR NOT **//
|
|
549
|
+
if (sourceFileObj.exists()) {
|
|
550
|
+
srcFileReader = new FileInputStream(sourceFileObj);
|
|
551
|
+
desFileWriter = new FileOutputStream(desFileObj);
|
|
552
|
+
buf = new byte[1024];
|
|
553
|
+
//** WRITE SOURCE FILE INTO CONTENT_STORE DESTINATION PATH **//
|
|
554
|
+
while ((srcFileSize = srcFileReader.read(buf)) > 0) {
|
|
555
|
+
desFileWriter.write(buf, 0, srcFileSize);
|
|
556
|
+
}
|
|
557
|
+
srcFileReader.close();
|
|
558
|
+
desFileWriter.close();
|
|
559
|
+
|
|
560
|
+
srcFileReader = new FileInputStream(sourceFileObj);
|
|
561
|
+
queueFileWriter = new FileOutputStream(queueFileObj);
|
|
562
|
+
buf = new byte[1024];
|
|
563
|
+
//** WRITE SOURCE FILE INTO QUEUE DESTINATION PATH **//
|
|
564
|
+
while ((srcFileSize = srcFileReader.read(buf)) > 0) {
|
|
565
|
+
queueFileWriter.write(buf, 0, srcFileSize);
|
|
566
|
+
}
|
|
567
|
+
srcFileReader.close();
|
|
568
|
+
queueFileWriter.close();
|
|
569
|
+
} else {
|
|
570
|
+
callbackContext.error("failure");
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
deleteFilesFromDirectory();
|
|
574
|
+
callbackContext.success("success");
|
|
575
|
+
} catch (Exception e) {
|
|
576
|
+
callbackContext.error(e.getMessage());
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
public void queueProcessor(CallbackContext callbackContext) {
|
|
581
|
+
String statusIndication = "false";
|
|
582
|
+
String breakIndication = "false";
|
|
583
|
+
try {
|
|
584
|
+
String clientID, countryCode, userID, clientUrl;
|
|
585
|
+
BufferedReader myAccountsFileReader;
|
|
586
|
+
StringBuilder myAccountsFileBuilder;
|
|
587
|
+
JSONArray accountsList;
|
|
588
|
+
JSONObject currentAccount;
|
|
589
|
+
String currentLine;
|
|
590
|
+
if (new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/" + "my_accounts_encrypted.txt").exists()) {
|
|
591
|
+
myAccountsFileReader = new BufferedReader(new FileReader(new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/" + "my_accounts_encrypted.txt")));
|
|
592
|
+
myAccountsFileBuilder = new StringBuilder();
|
|
593
|
+
while ((currentLine = myAccountsFileReader.readLine()) != null) {
|
|
594
|
+
myAccountsFileBuilder.append(currentLine);
|
|
595
|
+
}
|
|
596
|
+
myAccountsFileReader.close();
|
|
597
|
+
accountsList = new JSONArray(decrypt(myAccountsFileBuilder.toString()));
|
|
598
|
+
for (int index = 0; index < accountsList.length(); index++) {
|
|
599
|
+
currentAccount = accountsList.optJSONObject(index);
|
|
600
|
+
clientID = currentAccount.optString("client_id").toString();
|
|
601
|
+
countryCode = currentAccount.optString("country_code").toString();
|
|
602
|
+
userID = currentAccount.optString("user_id").toString();
|
|
603
|
+
clientUrl = currentAccount.optString("client_url").toString();
|
|
604
|
+
File baseDirectory = rootDirectory;
|
|
605
|
+
File databaseDir = new File(baseDirectory + "/" + mInterfaceUtil.packageName + "/" + clientID + "/" + countryCode + "/database");
|
|
606
|
+
File processFileDir = new File(mInterfaceUtil.packageName + "/" + clientID + "/" + countryCode + "/database/process/");
|
|
607
|
+
if (databaseDir.exists()) {
|
|
608
|
+
String attachmentsPath = baseDirectory + "/" + mInterfaceUtil.packageName + "/" + clientID + "/" + countryCode + "/database/attachments";
|
|
609
|
+
String queuesPath = baseDirectory + "/" + mInterfaceUtil.packageName + "/" + clientID + "/" + countryCode + "/database/queue";
|
|
610
|
+
if (new File(attachmentsPath).exists()) {
|
|
611
|
+
File[] attachmentsFiles = new File(attachmentsPath).listFiles();
|
|
612
|
+
if (attachmentsFiles != null) {
|
|
613
|
+
for (int attachIndex = 0; attachIndex < attachmentsFiles.length; attachIndex++) {
|
|
614
|
+
Arrays.sort(attachmentsFiles);
|
|
615
|
+
if (attachmentsFiles[attachIndex].length() == 0) {
|
|
616
|
+
breakIndication = "true";
|
|
617
|
+
break;
|
|
618
|
+
}
|
|
619
|
+
String[] fileName = attachmentsFiles[attachIndex].toString().split("/");
|
|
620
|
+
String attachURL = clientUrl + "/common/components/QueueManager/QueueUpload.aspx?file_path=attachments&client_id=" + clientID + "&country_code=" + countryCode + "&user_id=" + userID + "&file_name=" + fileName[fileName.length - 1].toString();
|
|
621
|
+
statusIndication = sendFilesToServer(attachmentsFiles[attachIndex].toString(), fileName[fileName.length - 1].toString(), attachURL);
|
|
622
|
+
if (statusIndication.equals("true")) {
|
|
623
|
+
breakIndication = "true";
|
|
624
|
+
break;
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
if (statusIndication.equals("false")) {
|
|
630
|
+
if (new File(queuesPath).exists()) {
|
|
631
|
+
File[] queueFiles = new File(queuesPath).listFiles();
|
|
632
|
+
if (queueFiles != null) {
|
|
633
|
+
for (int queueIndex = 0; queueIndex < queueFiles.length; queueIndex++) {
|
|
634
|
+
Arrays.sort(queueFiles);
|
|
635
|
+
if (queueFiles[queueIndex].length() == 0) {
|
|
636
|
+
breakIndication = "true";
|
|
637
|
+
break;
|
|
638
|
+
}
|
|
639
|
+
String[] fileName = queueFiles[queueIndex].toString().split("/");
|
|
640
|
+
String queueURL = clientUrl + "/common/components/QueueManager/QueueUpload.aspx?file_path=queue&client_id=" + clientID + "&country_code=" + countryCode + "&user_id=" + userID + "&file_name=" + fileName[fileName.length - 1].toString();
|
|
641
|
+
sendFilesToServer(queueFiles[queueIndex].toString(), fileName[fileName.length - 1].toString(), queueURL);
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
} else {
|
|
647
|
+
System.out.println("No database directory");
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
if (breakIndication.equals("false")) {
|
|
651
|
+
callbackContext.success();
|
|
652
|
+
} else {
|
|
653
|
+
callbackContext.error("failure");
|
|
654
|
+
}
|
|
655
|
+
} else {
|
|
656
|
+
System.out.println("No my accounts file");
|
|
657
|
+
}
|
|
658
|
+
} catch (Exception e) {
|
|
659
|
+
System.out.println("out exception : " + e.getMessage());
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
/*GETTING A FILEPATH OF API LEVEL 19 AND ABOVE */
|
|
664
|
+
public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
|
|
665
|
+
Cursor cursor = null;
|
|
666
|
+
final String column = "_data";
|
|
667
|
+
final String[] projection = {
|
|
668
|
+
column
|
|
669
|
+
};
|
|
670
|
+
|
|
671
|
+
try {
|
|
672
|
+
cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
|
|
673
|
+
if (cursor != null && cursor.moveToFirst()) {
|
|
674
|
+
final int column_index = cursor.getColumnIndexOrThrow(column);
|
|
675
|
+
return cursor.getString(column_index);
|
|
676
|
+
}
|
|
677
|
+
} finally {
|
|
678
|
+
if (cursor != null)
|
|
679
|
+
cursor.close();
|
|
680
|
+
}
|
|
681
|
+
return null;
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
@TargetApi(Build.VERSION_CODES.KITKAT)
|
|
685
|
+
public static String getPathToNonPrimaryVolume(Context context, String tag) {
|
|
686
|
+
File[] volumes = context.getExternalCacheDirs();
|
|
687
|
+
if (volumes != null) {
|
|
688
|
+
for (File volume : volumes) {
|
|
689
|
+
if (volume != null) {
|
|
690
|
+
String path = volume.getAbsolutePath();
|
|
691
|
+
if (path != null) {
|
|
692
|
+
int index = path.indexOf(tag);
|
|
693
|
+
if (index != -1) {
|
|
694
|
+
return path.substring(0, index) + tag;
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
return null;
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
public String refreshTimeProfile(String date, String hour, String minute) {
|
|
705
|
+
try {
|
|
706
|
+
String serverResponseDate, deviceDate, serverDate;
|
|
707
|
+
Date serverDateObj, todayDateobj;
|
|
708
|
+
SimpleDateFormat serverDateformat, deviceDateFormat, serverDateString;
|
|
709
|
+
BufferedWriter writerObj;
|
|
710
|
+
serverResponseDate = date + " " + hour + ":" + minute + ":00";
|
|
711
|
+
serverDateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", locale);
|
|
712
|
+
serverDateObj = serverDateformat.parse(serverResponseDate);
|
|
713
|
+
serverDateString = new SimpleDateFormat("yyyy,MM,dd,HH,mm,ss", locale);
|
|
714
|
+
serverDate = serverDateString.format(serverDateObj);
|
|
715
|
+
deviceDateFormat = new SimpleDateFormat("yyyy,MM,dd,HH,mm,ss", locale);
|
|
716
|
+
todayDateobj = new Date();
|
|
717
|
+
deviceDate = deviceDateFormat.format(todayDateobj);
|
|
718
|
+
JSONObject dateObj = new JSONObject();
|
|
719
|
+
dateObj.put("serverDate", serverDate);
|
|
720
|
+
dateObj.put("initServerDate", serverDate);
|
|
721
|
+
dateObj.put("initDeviceDate", deviceDate);
|
|
722
|
+
writerObj = new BufferedWriter(new FileWriter(new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/time_profile_encrypted.txt")));
|
|
723
|
+
writerObj.write(encrypt(dateObj.toString()));
|
|
724
|
+
writerObj.flush();
|
|
725
|
+
writerObj.close();
|
|
726
|
+
return "true";
|
|
727
|
+
} catch (Exception e) {
|
|
728
|
+
return "false";
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
public void getNewDate(CallbackContext callbackContext) {
|
|
733
|
+
String currentLine;
|
|
734
|
+
StringBuilder timeObj = new StringBuilder();
|
|
735
|
+
try {
|
|
736
|
+
Date mobileDate = new Date();
|
|
737
|
+
File baseDirectory = rootDirectory;
|
|
738
|
+
BufferedReader readerObj = new BufferedReader(new FileReader(new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/time_profile_encrypted.txt")));
|
|
739
|
+
while ((currentLine = readerObj.readLine()) != null) {
|
|
740
|
+
timeObj.append(currentLine);
|
|
741
|
+
}
|
|
742
|
+
readerObj.close();
|
|
743
|
+
JSONObject serverDateObj = new JSONObject(decrypt(timeObj.toString()));
|
|
744
|
+
String serverTimeObj = serverDateObj.optString("serverDate").toString();
|
|
745
|
+
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy,MM,dd,HH,mm,ss", locale);
|
|
746
|
+
Date serverDate = simpleDateFormat.parse(serverTimeObj);
|
|
747
|
+
long timeDiff = mobileDate.getTime() - serverDate.getTime();
|
|
748
|
+
serverDate.setTime(serverDate.getTime() + timeDiff);
|
|
749
|
+
SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy,MM,dd,HH,mm,ss", locale);
|
|
750
|
+
String serverDate1 = simpleDateFormat1.format(serverDate);
|
|
751
|
+
callbackContext.success(serverDate1);
|
|
752
|
+
} catch (Exception e) {
|
|
753
|
+
e.printStackTrace();
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
public void logData(String fileName, String data) {
|
|
759
|
+
File appDirectory;
|
|
760
|
+
FileWriter fileWriterObj;
|
|
761
|
+
try {
|
|
762
|
+
/* CHECKING THE DIRECTORY EXISTS OR NOT AND CREATING THE DIRECTORY */
|
|
763
|
+
appDirectory = new File(rootDirectory + "/" + fileName.substring(0, fileName.lastIndexOf("/")));
|
|
764
|
+
if (!appDirectory.exists()) {
|
|
765
|
+
appDirectory.mkdirs();
|
|
766
|
+
}
|
|
767
|
+
/* WRITING THE DATA TO THE FILE */
|
|
768
|
+
fileWriterObj = new FileWriter(new File(appDirectory, fileName.substring(fileName.lastIndexOf("/") + 1)), true);
|
|
769
|
+
fileWriterObj.write(data);
|
|
770
|
+
fileWriterObj.flush();
|
|
771
|
+
fileWriterObj.close();
|
|
772
|
+
|
|
773
|
+
} catch (Exception e) {
|
|
774
|
+
e.printStackTrace();
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
public void deleteFilesFromDirectory() {
|
|
779
|
+
File dir = new File(rootDirectory + "/" + mInterfaceUtil.packageName + "/" + "images");
|
|
780
|
+
if (dir.isDirectory()) {
|
|
781
|
+
if (dir.exists()) {
|
|
782
|
+
String[] children = dir.list();
|
|
783
|
+
for (int i = 0; i < children.length; i++) {
|
|
784
|
+
new File(dir, children[i]).delete();
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
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);
|
|
793
|
+
}
|
|
794
|
+
public String getFileThumbnail(String filePath, String extension, Context context){
|
|
795
|
+
Bitmap thumb;
|
|
796
|
+
String imgString = "";
|
|
797
|
+
try {
|
|
798
|
+
if(extension.equalsIgnoreCase(".mp4")){
|
|
799
|
+
thumb = ThumbnailUtils.createVideoThumbnail(filePath,
|
|
800
|
+
MediaStore.Images.Thumbnails.MINI_KIND);
|
|
801
|
+
imgString = convertBitmapToString(thumb);
|
|
802
|
+
}else if(extension.equalsIgnoreCase(".heic") || extension.equalsIgnoreCase(".jpeg")|| extension.equalsIgnoreCase(".jpg")|| extension.equalsIgnoreCase(".png")){
|
|
803
|
+
thumb = ThumbnailUtils.extractThumbnail(BitmapFactory.decodeFile(filePath),
|
|
804
|
+
76, 76);
|
|
805
|
+
|
|
806
|
+
imgString = convertBitmapToString(thumb);
|
|
807
|
+
}else if(extension.equalsIgnoreCase(".mp3")){
|
|
808
|
+
MediaMetadataRetriever mmr = new MediaMetadataRetriever();
|
|
809
|
+
byte[] bytes;
|
|
810
|
+
BitmapFactory.Options bfo=new BitmapFactory.Options();
|
|
811
|
+
|
|
812
|
+
mmr.setDataSource(context, Uri.fromFile(new File(filePath)));
|
|
813
|
+
bytes = mmr.getEmbeddedPicture();
|
|
814
|
+
if (bytes != null){
|
|
815
|
+
thumb = BitmapFactory.decodeByteArray(bytes, 0, bytes.length, bfo);
|
|
816
|
+
imgString = convertBitmapToString(thumb);
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
}catch (Exception e){
|
|
820
|
+
|
|
821
|
+
}
|
|
822
|
+
return imgString;
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
public void sendChatAttachment(String filePath, String fileName, String requestURL, Context context, CallbackContext callbackContext) {
|
|
826
|
+
try {
|
|
827
|
+
class SendFile extends AsyncTask<String, String, String> {
|
|
828
|
+
@Override
|
|
829
|
+
protected void onPreExecute() {
|
|
830
|
+
}
|
|
831
|
+
@Override
|
|
832
|
+
protected String doInBackground(String... args) {
|
|
833
|
+
FileInputStream fileInputStream;
|
|
834
|
+
HttpURLConnection urlConObj;
|
|
835
|
+
URL requestPath;
|
|
836
|
+
int bytesAvailable,
|
|
837
|
+
bufferSize;
|
|
838
|
+
int maxBufferSize = 1 * 1024 * 1024;
|
|
839
|
+
DataOutputStream dos;
|
|
840
|
+
String lineEnd = "\r\n";
|
|
841
|
+
String twoHyphens = "--";
|
|
842
|
+
String boundary = "*****";
|
|
843
|
+
StringBuilder serverResponseObj;
|
|
844
|
+
BufferedReader readerObj;
|
|
845
|
+
String currentLine,
|
|
846
|
+
receiveData = "", statusIndication = null;
|
|
847
|
+
int progressCheck=10;
|
|
848
|
+
try {
|
|
849
|
+
if (new File(filePath).exists()) {
|
|
850
|
+
if (new File(filePath).exists()) {
|
|
851
|
+
fileInputStream = new FileInputStream(new File(filePath));
|
|
852
|
+
|
|
853
|
+
requestPath = new URL((requestURL).replaceAll(" ", "%20"));
|
|
854
|
+
urlConObj = (HttpURLConnection) requestPath.openConnection();
|
|
855
|
+
urlConObj.setDoInput(true); // Allow Inputs
|
|
856
|
+
urlConObj.setDoOutput(true); // Allow Outputs
|
|
857
|
+
urlConObj.setUseCaches(false); // Don't use a Cached Copy
|
|
858
|
+
urlConObj.setRequestMethod("POST");
|
|
859
|
+
urlConObj.setRequestProperty("Connection", "Keep-Alive");
|
|
860
|
+
urlConObj.setRequestProperty("ENCTYPE", "multipart/form-data");
|
|
861
|
+
urlConObj.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
|
|
862
|
+
urlConObj.setRequestProperty("uploaded_file", fileName);
|
|
863
|
+
|
|
864
|
+
dos = new DataOutputStream(urlConObj.getOutputStream());
|
|
865
|
+
dos.writeBytes(twoHyphens + boundary + lineEnd);
|
|
866
|
+
dos.writeBytes("Content-Disposition: form-data; name=\"uploaded_file\";filename=\""
|
|
867
|
+
+ fileName + "\"" + lineEnd);
|
|
868
|
+
dos.writeBytes(lineEnd);
|
|
869
|
+
// create a buffer of maximum size
|
|
870
|
+
bytesAvailable = fileInputStream.available();
|
|
871
|
+
|
|
872
|
+
bufferSize = Math.min(bytesAvailable, maxBufferSize);
|
|
873
|
+
|
|
874
|
+
int progress = 0;
|
|
875
|
+
int progressToSend = 0;
|
|
876
|
+
int fileLength = (int) new File(filePath).length();
|
|
877
|
+
int bytesReadValue = 0;
|
|
878
|
+
byte buf[] = new byte[1024];
|
|
879
|
+
BufferedInputStream bufInput = new BufferedInputStream(new FileInputStream(new File(filePath)));
|
|
880
|
+
while ((bytesReadValue = bufInput.read(buf)) != -1) {
|
|
881
|
+
// write output
|
|
882
|
+
dos.write(buf, 0, bytesReadValue);
|
|
883
|
+
progress += bytesReadValue;
|
|
884
|
+
progressToSend = (int)((progress * 100) / fileLength);
|
|
885
|
+
|
|
886
|
+
if(progressToSend >= progressCheck){
|
|
887
|
+
JSONObject progressObj = new JSONObject();
|
|
888
|
+
progressObj.put("progress", progressCheck);
|
|
889
|
+
progressObj.put("fileLength", fileLength);
|
|
890
|
+
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, progressObj);
|
|
891
|
+
pluginResult.setKeepCallback(true);
|
|
892
|
+
callbackContext.sendPluginResult(pluginResult);
|
|
893
|
+
progressCheck = progressCheck + 10;
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
// send multipart form data necesssary after file data...
|
|
898
|
+
dos.writeBytes(lineEnd);
|
|
899
|
+
dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
|
|
900
|
+
urlConObj.getResponseCode();
|
|
901
|
+
//close the streams //
|
|
902
|
+
fileInputStream.close();
|
|
903
|
+
dos.flush();
|
|
904
|
+
dos.close();
|
|
905
|
+
readerObj = new BufferedReader(new InputStreamReader(urlConObj.getInputStream()));
|
|
906
|
+
currentLine = readerObj.readLine();
|
|
907
|
+
readerObj.close();
|
|
908
|
+
receiveData = currentLine.toString();
|
|
909
|
+
urlConObj.disconnect();
|
|
910
|
+
JSONObject resultObj = new JSONObject(receiveData);
|
|
911
|
+
if (resultObj.getString("status").equalsIgnoreCase("success")) {
|
|
912
|
+
statusIndication = "true";
|
|
913
|
+
} else {
|
|
914
|
+
statusIndication = "false";
|
|
915
|
+
}
|
|
916
|
+
urlConObj.disconnect();
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
} catch (Exception e) {
|
|
921
|
+
e.printStackTrace();
|
|
922
|
+
}
|
|
923
|
+
return statusIndication;
|
|
924
|
+
|
|
925
|
+
}
|
|
926
|
+
public void onPostExecute(String statusIndication) {
|
|
927
|
+
try {
|
|
928
|
+
if (statusIndication == null) {
|
|
929
|
+
callbackContext.error("failure");
|
|
930
|
+
} else {
|
|
931
|
+
if (statusIndication.equals("true")) {
|
|
932
|
+
callbackContext.success("success");
|
|
933
|
+
} else {
|
|
934
|
+
callbackContext.error("failure");
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
} catch (Exception e) {
|
|
938
|
+
e.printStackTrace();
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
new SendFile().execute();
|
|
944
|
+
} catch (Exception e) {
|
|
945
|
+
e.printStackTrace();
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
|
|
950
|
+
public String sendAttachmentToServer(String filePath, String fileName, String requestURL) {
|
|
951
|
+
String statusIndication = "false";
|
|
952
|
+
try {
|
|
953
|
+
FileInputStream fileInputStream;
|
|
954
|
+
HttpURLConnection urlConObj;
|
|
955
|
+
URL requestPath;
|
|
956
|
+
int bytesRead,
|
|
957
|
+
bytesAvailable,
|
|
958
|
+
bufferSize;
|
|
959
|
+
byte[] buffer;
|
|
960
|
+
int maxBufferSize = 1 * 1024 * 1024;
|
|
961
|
+
DataOutputStream dos;
|
|
962
|
+
String lineEnd = "\r\n";
|
|
963
|
+
String twoHyphens = "--";
|
|
964
|
+
String boundary = "*****";
|
|
965
|
+
StringBuilder serverResponseObj;
|
|
966
|
+
BufferedReader readerObj;
|
|
967
|
+
String currentLine,
|
|
968
|
+
receiveData = "";
|
|
969
|
+
if (new File(filePath).exists()) {
|
|
970
|
+
if (new File(filePath).exists()) {
|
|
971
|
+
fileInputStream = new FileInputStream(new File(filePath));
|
|
972
|
+
requestPath = new URL((requestURL).replaceAll(" ", "%20"));
|
|
973
|
+
urlConObj = (HttpURLConnection) requestPath.openConnection();
|
|
974
|
+
urlConObj.setDoInput(true); // Allow Inputs
|
|
975
|
+
urlConObj.setDoOutput(true); // Allow Outputs
|
|
976
|
+
urlConObj.setUseCaches(false); // Don't use a Cached Copy
|
|
977
|
+
urlConObj.setRequestMethod("POST");
|
|
978
|
+
urlConObj.setRequestProperty("Connection", "Keep-Alive");
|
|
979
|
+
urlConObj.setRequestProperty("ENCTYPE", "multipart/form-data");
|
|
980
|
+
urlConObj.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
|
|
981
|
+
urlConObj.setRequestProperty("uploaded_file", fileName);
|
|
982
|
+
|
|
983
|
+
dos = new DataOutputStream(urlConObj.getOutputStream());
|
|
984
|
+
dos.writeBytes(twoHyphens + boundary + lineEnd);
|
|
985
|
+
dos.writeBytes("Content-Disposition: form-data; name=\"uploaded_file\";filename=\""
|
|
986
|
+
+ fileName + "\"" + lineEnd);
|
|
987
|
+
dos.writeBytes(lineEnd);
|
|
988
|
+
// create a buffer of maximum size
|
|
989
|
+
bytesAvailable = fileInputStream.available();
|
|
990
|
+
|
|
991
|
+
bufferSize = Math.min(bytesAvailable, maxBufferSize);
|
|
992
|
+
buffer = new byte[bufferSize];
|
|
993
|
+
|
|
994
|
+
// read file and write it into form...
|
|
995
|
+
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
|
|
996
|
+
while (bytesRead > 0) {
|
|
997
|
+
dos.write(buffer, 0, bufferSize);
|
|
998
|
+
bytesAvailable = fileInputStream.available();
|
|
999
|
+
bufferSize = Math.min(bytesAvailable, maxBufferSize);
|
|
1000
|
+
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
|
|
1001
|
+
|
|
1002
|
+
}
|
|
1003
|
+
// send multipart form data necesssary after file data...
|
|
1004
|
+
dos.writeBytes(lineEnd);
|
|
1005
|
+
dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
|
|
1006
|
+
urlConObj.getResponseCode();
|
|
1007
|
+
//close the streams //
|
|
1008
|
+
fileInputStream.close();
|
|
1009
|
+
dos.flush();
|
|
1010
|
+
dos.close();
|
|
1011
|
+
readerObj = new BufferedReader(new InputStreamReader(urlConObj.getInputStream()));
|
|
1012
|
+
currentLine = readerObj.readLine();
|
|
1013
|
+
readerObj.close();
|
|
1014
|
+
receiveData = currentLine.toString();
|
|
1015
|
+
urlConObj.disconnect();
|
|
1016
|
+
JSONObject resultObj = new JSONObject(receiveData);
|
|
1017
|
+
if (resultObj.getString("status").equalsIgnoreCase("success")) {
|
|
1018
|
+
statusIndication = "true";
|
|
1019
|
+
} else {
|
|
1020
|
+
statusIndication = "false";
|
|
1021
|
+
}
|
|
1022
|
+
urlConObj.disconnect();
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
} catch (Exception e) {
|
|
1026
|
+
statusIndication = "true";
|
|
1027
|
+
}
|
|
1028
|
+
return statusIndication;
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
private void UpdateProgressBar(CallbackContext callbackContext, int progress) {
|
|
1032
|
+
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, progress);
|
|
1033
|
+
pluginResult.setKeepCallback(true); // keep callback
|
|
1034
|
+
callbackContext.sendPluginResult(pluginResult);
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
public String sendFilesToServer(String filePath, String fileName, String requestURL) {
|
|
1038
|
+
String statusIndication = "false";
|
|
1039
|
+
try {
|
|
1040
|
+
FileInputStream fileInputStream;
|
|
1041
|
+
HttpURLConnection urlConObj;
|
|
1042
|
+
URL requestPath;
|
|
1043
|
+
int bytesRead,
|
|
1044
|
+
bytesAvailable,
|
|
1045
|
+
bufferSize;
|
|
1046
|
+
byte[] buffer;
|
|
1047
|
+
int maxBufferSize = 1 * 1024 * 1024;
|
|
1048
|
+
DataOutputStream dos;
|
|
1049
|
+
String lineEnd = "\r\n";
|
|
1050
|
+
String twoHyphens = "--";
|
|
1051
|
+
String boundary = "*****";
|
|
1052
|
+
StringBuilder serverResponseObj;
|
|
1053
|
+
BufferedReader readerObj;
|
|
1054
|
+
String currentLine,
|
|
1055
|
+
receiveData = "";
|
|
1056
|
+
if (new File(filePath).exists()) {
|
|
1057
|
+
if (new File(filePath).exists()) {
|
|
1058
|
+
fileInputStream = new FileInputStream(new File(filePath));
|
|
1059
|
+
requestPath = new URL((requestURL).replaceAll(" ", "%20"));
|
|
1060
|
+
urlConObj = (HttpURLConnection) requestPath.openConnection();
|
|
1061
|
+
urlConObj.setDoInput(true); // Allow Inputs
|
|
1062
|
+
urlConObj.setDoOutput(true); // Allow Outputs
|
|
1063
|
+
urlConObj.setUseCaches(false); // Don't use a Cached Copy
|
|
1064
|
+
urlConObj.setRequestMethod("POST");
|
|
1065
|
+
urlConObj.setRequestProperty("Connection", "Keep-Alive");
|
|
1066
|
+
urlConObj.setRequestProperty("ENCTYPE", "multipart/form-data");
|
|
1067
|
+
urlConObj.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
|
|
1068
|
+
urlConObj.setRequestProperty("uploaded_file", fileName);
|
|
1069
|
+
|
|
1070
|
+
dos = new DataOutputStream(urlConObj.getOutputStream());
|
|
1071
|
+
dos.writeBytes(twoHyphens + boundary + lineEnd);
|
|
1072
|
+
dos.writeBytes("Content-Disposition: form-data; name=\"uploaded_file\";filename=\""
|
|
1073
|
+
+ fileName + "\"" + lineEnd);
|
|
1074
|
+
dos.writeBytes(lineEnd);
|
|
1075
|
+
// create a buffer of maximum size
|
|
1076
|
+
bytesAvailable = fileInputStream.available();
|
|
1077
|
+
|
|
1078
|
+
bufferSize = Math.min(bytesAvailable, maxBufferSize);
|
|
1079
|
+
buffer = new byte[bufferSize];
|
|
1080
|
+
|
|
1081
|
+
// read file and write it into form...
|
|
1082
|
+
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
|
|
1083
|
+
while (bytesRead > 0) {
|
|
1084
|
+
dos.write(buffer, 0, bufferSize);
|
|
1085
|
+
bytesAvailable = fileInputStream.available();
|
|
1086
|
+
bufferSize = Math.min(bytesAvailable, maxBufferSize);
|
|
1087
|
+
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
|
|
1088
|
+
|
|
1089
|
+
}
|
|
1090
|
+
// send multipart form data necesssary after file data...
|
|
1091
|
+
dos.writeBytes(lineEnd);
|
|
1092
|
+
dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
|
|
1093
|
+
urlConObj.getResponseCode();
|
|
1094
|
+
//close the streams //
|
|
1095
|
+
fileInputStream.close();
|
|
1096
|
+
dos.flush();
|
|
1097
|
+
dos.close();
|
|
1098
|
+
readerObj = new BufferedReader(new InputStreamReader(urlConObj.getInputStream()));
|
|
1099
|
+
currentLine = readerObj.readLine();
|
|
1100
|
+
readerObj.close();
|
|
1101
|
+
receiveData = currentLine.toString();
|
|
1102
|
+
urlConObj.disconnect();
|
|
1103
|
+
if (receiveData.equals("true")) {
|
|
1104
|
+
new File(filePath).delete();
|
|
1105
|
+
} else {
|
|
1106
|
+
statusIndication = "true";
|
|
1107
|
+
}
|
|
1108
|
+
urlConObj.disconnect();
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
} catch (Exception e) {
|
|
1112
|
+
statusIndication = "true";
|
|
1113
|
+
}
|
|
1114
|
+
return statusIndication;
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
public void readFile(JSONArray args, CallbackContext callbackContext) throws IOException {
|
|
1118
|
+
String str = "";
|
|
1119
|
+
File baseDirectory = rootDirectory;
|
|
1120
|
+
try {
|
|
1121
|
+
File filePath = new File(baseDirectory + "/" + args.getJSONObject(0).optString("filePath"));
|
|
1122
|
+
if (filePath.exists()) {
|
|
1123
|
+
String content = new Scanner(filePath).useDelimiter("\\A").next();
|
|
1124
|
+
callbackContext.success(content);
|
|
1125
|
+
} else {
|
|
1126
|
+
callbackContext.error("There is no file at the given path..");
|
|
1127
|
+
}
|
|
1128
|
+
} catch (Exception e) {
|
|
1129
|
+
callbackContext.error(e.getMessage());
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
public void deleteFile(JSONArray args, CallbackContext callbackContext) {
|
|
1134
|
+
File baseDirectory = rootDirectory;
|
|
1135
|
+
try {
|
|
1136
|
+
File filePath = new File(baseDirectory + "/" + args.getJSONObject(0).optString("filePath"));
|
|
1137
|
+
if (filePath.exists()) {
|
|
1138
|
+
filePath.delete();
|
|
1139
|
+
callbackContext.success();
|
|
1140
|
+
} else {
|
|
1141
|
+
callbackContext.error("File not deleted..");
|
|
1142
|
+
}
|
|
1143
|
+
} catch (Exception e) {
|
|
1144
|
+
callbackContext.error(e.getMessage());
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1148
|
+
public void createFile(JSONArray args, CallbackContext callbackContext) {
|
|
1149
|
+
File appDirectory;
|
|
1150
|
+
FileWriter fileWriterObj;
|
|
1151
|
+
try {
|
|
1152
|
+
String fileName = args.getJSONObject(0).optString("filePath");
|
|
1153
|
+
String data = args.getJSONObject(0).optString("data");
|
|
1154
|
+
appDirectory = new File(rootDirectory + "/" + fileName.substring(0, fileName.lastIndexOf("/")));
|
|
1155
|
+
if (!appDirectory.exists()) {
|
|
1156
|
+
appDirectory.mkdirs();
|
|
1157
|
+
}
|
|
1158
|
+
/* WRITING THE DATA TO THE FILE */
|
|
1159
|
+
String bbbb = fileName.substring(fileName.lastIndexOf("/") + 1);
|
|
1160
|
+
fileWriterObj = new FileWriter(new File(appDirectory, fileName.substring(fileName.lastIndexOf("/") + 1)));
|
|
1161
|
+
fileWriterObj.write(data);
|
|
1162
|
+
fileWriterObj.flush();
|
|
1163
|
+
fileWriterObj.close();
|
|
1164
|
+
callbackContext.success();
|
|
1165
|
+
} catch (Exception e) {
|
|
1166
|
+
callbackContext.error(e.getMessage());
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
public void validateFile(JSONArray args, CallbackContext callbackContext) {
|
|
1171
|
+
File baseDirectory = rootDirectory;
|
|
1172
|
+
try {
|
|
1173
|
+
File filePath = new File(baseDirectory + "/" + args.getJSONObject(0).optString("filePath"));
|
|
1174
|
+
boolean sss = filePath.exists() ? true : false;
|
|
1175
|
+
callbackContext.success(sss ? "true" : "false");
|
|
1176
|
+
} catch (Exception e) {
|
|
1177
|
+
callbackContext.error(e.getMessage());
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
public void createDirectory(JSONArray args, CallbackContext callbackContext) {
|
|
1182
|
+
File appDirectory;
|
|
1183
|
+
FileWriter fileWriterObj;
|
|
1184
|
+
try {
|
|
1185
|
+
String fileName = args.getJSONObject(0).optString("filePath");
|
|
1186
|
+
appDirectory = new File(rootDirectory + "/" + fileName);
|
|
1187
|
+
if (!appDirectory.exists()) {
|
|
1188
|
+
appDirectory.mkdirs();
|
|
1189
|
+
}
|
|
1190
|
+
callbackContext.success();
|
|
1191
|
+
} catch (Exception e) {
|
|
1192
|
+
callbackContext.error(e.getMessage());
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
public void deleteDirectory(JSONArray args, CallbackContext callbackContext) {
|
|
1197
|
+
File appDirectory;
|
|
1198
|
+
FileWriter fileWriterObj;
|
|
1199
|
+
try {
|
|
1200
|
+
String fileName = args.getJSONObject(0).optString("filePath");
|
|
1201
|
+
if (fileName.equals("")) {
|
|
1202
|
+
callbackContext.error("Given directory path is empty.");
|
|
1203
|
+
} else {
|
|
1204
|
+
File dir = new File(rootDirectory + "/" + fileName);
|
|
1205
|
+
if (dir.exists()) {
|
|
1206
|
+
deleteRecursive(dir);
|
|
1207
|
+
callbackContext.success();
|
|
1208
|
+
}else{
|
|
1209
|
+
callbackContext.error("File does not exists");
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
}
|
|
1213
|
+
} catch (Exception e) {
|
|
1214
|
+
callbackContext.error(e.getMessage());
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
public void deleteRecursive(File fileOrDirectory) {
|
|
1219
|
+
if (fileOrDirectory.isDirectory()) {
|
|
1220
|
+
for (File child : fileOrDirectory.listFiles()) {
|
|
1221
|
+
System.out.println("Child directory path: " + child);
|
|
1222
|
+
deleteRecursive(child);
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
fileOrDirectory.delete();
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
private static int BUFFER_SIZE = 6 * 1024;
|
|
1230
|
+
|
|
1231
|
+
public static void unzip(String zipFile, String location, CallbackContext callbackContext) throws JSONException {
|
|
1232
|
+
try {
|
|
1233
|
+
File f = new File(location);
|
|
1234
|
+
if (!f.isDirectory()) {
|
|
1235
|
+
f.mkdirs();
|
|
1236
|
+
}
|
|
1237
|
+
ZipInputStream zin = new ZipInputStream(new FileInputStream(zipFile));
|
|
1238
|
+
try {
|
|
1239
|
+
ZipEntry ze = null;
|
|
1240
|
+
while ((ze = zin.getNextEntry()) != null) {
|
|
1241
|
+
String path = location + File.separator + ze.getName();
|
|
1242
|
+
|
|
1243
|
+
if (ze.isDirectory()) {
|
|
1244
|
+
File unzipFile = new File(path);
|
|
1245
|
+
if (!unzipFile.isDirectory()) {
|
|
1246
|
+
unzipFile.mkdirs();
|
|
1247
|
+
}
|
|
1248
|
+
} else {
|
|
1249
|
+
FileOutputStream fout = new FileOutputStream(path, false);
|
|
1250
|
+
|
|
1251
|
+
try {
|
|
1252
|
+
for (int c = zin.read(); c != -1; c = zin.read()) {
|
|
1253
|
+
fout.write(c);
|
|
1254
|
+
}
|
|
1255
|
+
zin.closeEntry();
|
|
1256
|
+
} finally {
|
|
1257
|
+
fout.close();
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
} finally {
|
|
1262
|
+
zin.close();
|
|
1263
|
+
}
|
|
1264
|
+
callbackContext.success();
|
|
1265
|
+
} catch (Exception e) {
|
|
1266
|
+
e.printStackTrace();
|
|
1267
|
+
callbackContext.error(e.getMessage());
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
public void getSubDirectoryList(JSONArray args, CallbackContext callbackContext) {
|
|
1272
|
+
try {
|
|
1273
|
+
String fileName = args.getJSONObject(0).optString("filePath");
|
|
1274
|
+
System.out.println("deleteFile Path is: " + fileName);
|
|
1275
|
+
if (fileName.equals("")) {
|
|
1276
|
+
callbackContext.error("Given directory path is empty.");
|
|
1277
|
+
} else {
|
|
1278
|
+
File dir = new File(rootDirectory + "/" + fileName);
|
|
1279
|
+
String[] subDirectories = dir.list(new FilenameFilter() {
|
|
1280
|
+
@Override
|
|
1281
|
+
public boolean accept(File current, String name) {
|
|
1282
|
+
return new File(current, name).isDirectory();
|
|
1283
|
+
}
|
|
1284
|
+
});
|
|
1285
|
+
StringBuilder fileNames = new StringBuilder();
|
|
1286
|
+
for (String subDirectory : subDirectories) {
|
|
1287
|
+
fileNames.append(subDirectory);
|
|
1288
|
+
fileNames.append("|");
|
|
1289
|
+
}
|
|
1290
|
+
callbackContext.success(fileNames.length() > 0 ? fileNames.substring(0, fileNames.length() - 1) : "");
|
|
1291
|
+
}
|
|
1292
|
+
} catch (Exception e) {
|
|
1293
|
+
callbackContext.error(e.getMessage());
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
public void getFileList(JSONArray args, CallbackContext callbackContext) {
|
|
1298
|
+
try {
|
|
1299
|
+
String fileName = args.getJSONObject(0).optString("filePath");
|
|
1300
|
+
System.out.println("deleteFile Path is: " + fileName);
|
|
1301
|
+
if (fileName.equals("")) {
|
|
1302
|
+
callbackContext.error("Given directory path is empty.");
|
|
1303
|
+
} else {
|
|
1304
|
+
File dir = new File(rootDirectory + "/" + fileName);
|
|
1305
|
+
String[] subDirectories = dir.list(new FilenameFilter() {
|
|
1306
|
+
@Override
|
|
1307
|
+
public boolean accept(File current, String name) {
|
|
1308
|
+
return new File(current, name).isFile();
|
|
1309
|
+
}
|
|
1310
|
+
});
|
|
1311
|
+
StringBuilder fileNames = new StringBuilder();
|
|
1312
|
+
for (String subDirectory : subDirectories) {
|
|
1313
|
+
fileNames.append(subDirectory);
|
|
1314
|
+
fileNames.append("|");
|
|
1315
|
+
}
|
|
1316
|
+
callbackContext.success(fileNames.length() > 0 ? fileNames.substring(0, fileNames.length() - 1) : "");
|
|
1317
|
+
}
|
|
1318
|
+
} catch (Exception e) {
|
|
1319
|
+
callbackContext.error(e.getMessage());
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
public static void getAppStateInfo(CallbackContext callbackContext, Context applicationContext) {
|
|
1324
|
+
String currentLine;
|
|
1325
|
+
File appStateIndicatorFile;
|
|
1326
|
+
try {
|
|
1327
|
+
appStateIndicatorFile = new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/" + clientID + "/" + countryCode + "/" + "app_state_info.txt");
|
|
1328
|
+
if (appStateIndicatorFile.exists()) {
|
|
1329
|
+
BufferedReader authFileReader = new BufferedReader(new FileReader(appStateIndicatorFile));
|
|
1330
|
+
StringBuilder authFileBuilder = new StringBuilder();
|
|
1331
|
+
while ((currentLine = authFileReader.readLine()) != null) {
|
|
1332
|
+
authFileBuilder.append(currentLine);
|
|
1333
|
+
}
|
|
1334
|
+
authFileReader.close();
|
|
1335
|
+
JSONObject authFileObj = new JSONObject(decrypt(authFileBuilder.toString()));
|
|
1336
|
+
long lastModifiedTime = appStateIndicatorFile.lastModified();
|
|
1337
|
+
Date date = new Date();
|
|
1338
|
+
date.setTime(lastModifiedTime);
|
|
1339
|
+
String lastModifiedDate = new SimpleDateFormat("yyyyMMdd", new mInterfaceUtil().locale).format(date);
|
|
1340
|
+
|
|
1341
|
+
if (authFileObj.optString("validDevice").toString().equals("nostatus") || !lastModifiedDate.equals(new SimpleDateFormat("yyyyMMdd", new mInterfaceUtil().locale).format(new Date()))) {
|
|
1342
|
+
if (isConnected(applicationContext)) {
|
|
1343
|
+
downloadAppStateInfo(callbackContext);
|
|
1344
|
+
} else {
|
|
1345
|
+
callbackContext.success(authFileObj.toString());
|
|
1346
|
+
}
|
|
1347
|
+
} else {
|
|
1348
|
+
callbackContext.success(authFileObj.toString());
|
|
1349
|
+
}
|
|
1350
|
+
} else {
|
|
1351
|
+
if (isConnected(applicationContext)) {
|
|
1352
|
+
downloadAppStateInfo(callbackContext);
|
|
1353
|
+
} else {
|
|
1354
|
+
callbackContext.success("");
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
} catch (Exception e) {
|
|
1358
|
+
System.out.println(e.getMessage());
|
|
1359
|
+
callbackContext.success("");
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
public static void downloadAppStateInfo(CallbackContext callbackContext) {
|
|
1364
|
+
URL requestAuthenticationPath,
|
|
1365
|
+
requestValidateDevicePath, getKeysPath;
|
|
1366
|
+
HttpURLConnection urlConObj;
|
|
1367
|
+
OutputStreamWriter oStreamObj;
|
|
1368
|
+
BufferedWriter writerObj;
|
|
1369
|
+
StringBuilder serverResponseObj;
|
|
1370
|
+
BufferedReader responseReaderObj;
|
|
1371
|
+
JSONObject responseDataObj;
|
|
1372
|
+
String currentLine;
|
|
1373
|
+
try {
|
|
1374
|
+
getKeysPath = new URL(clientUrl + "/" + "common/components/Keys/" + "RetrieveKey.aspx");
|
|
1375
|
+
urlConObj = (HttpURLConnection)getKeysPath.openConnection();
|
|
1376
|
+
urlConObj.setDoOutput(true);
|
|
1377
|
+
urlConObj.setRequestMethod("POST");
|
|
1378
|
+
urlConObj.setRequestProperty("CONTENT-TYPE", "application/json");
|
|
1379
|
+
urlConObj.connect();
|
|
1380
|
+
JSONObject jsonObject1 = new JSONObject();
|
|
1381
|
+
jsonObject1 = jsonObject1.put("client_id", clientID);
|
|
1382
|
+
jsonObject1 = jsonObject1.put("country_code", countryCode);
|
|
1383
|
+
jsonObject1 = jsonObject1.put("purposeCode", "mobile_address_store");
|
|
1384
|
+
System.out.println("data format: " + jsonObject1.toString());
|
|
1385
|
+
oStreamObj = new OutputStreamWriter(urlConObj.getOutputStream());
|
|
1386
|
+
oStreamObj.write(jsonObject1.toString());
|
|
1387
|
+
oStreamObj.flush();
|
|
1388
|
+
oStreamObj.close();
|
|
1389
|
+
serverResponseObj = new StringBuilder();
|
|
1390
|
+
responseReaderObj = new BufferedReader(new InputStreamReader(urlConObj.getInputStream()));
|
|
1391
|
+
while ((currentLine = responseReaderObj.readLine()) != null) {
|
|
1392
|
+
serverResponseObj.append(currentLine);
|
|
1393
|
+
}
|
|
1394
|
+
responseReaderObj.close();
|
|
1395
|
+
urlConObj.disconnect();
|
|
1396
|
+
writerObj = new BufferedWriter(new FileWriter(new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/" + clientID + "/" + countryCode + "/" + "client_configuration_encrypted.txt")));
|
|
1397
|
+
writerObj.write(encrypt(serverResponseObj.toString()));
|
|
1398
|
+
writerObj.flush();
|
|
1399
|
+
writerObj.close();
|
|
1400
|
+
|
|
1401
|
+
/* App State info DATA REQUEST */
|
|
1402
|
+
requestAuthenticationPath = new URL(cvsUrl + "/" + "get_app_state_info.aspx");
|
|
1403
|
+
urlConObj = (HttpURLConnection) requestAuthenticationPath.openConnection();
|
|
1404
|
+
urlConObj.setDoOutput(true);
|
|
1405
|
+
urlConObj.setRequestMethod("POST");
|
|
1406
|
+
urlConObj.setRequestProperty("CONTENT-TYPE", "application/json");
|
|
1407
|
+
urlConObj.connect();
|
|
1408
|
+
|
|
1409
|
+
oStreamObj = new OutputStreamWriter(urlConObj.getOutputStream());
|
|
1410
|
+
JSONObject reqJson_obj = new JSONObject();
|
|
1411
|
+
reqJson_obj.put("client_id", clientID);
|
|
1412
|
+
reqJson_obj.put("country_code", countryCode);
|
|
1413
|
+
reqJson_obj.put("app_id", app_id);
|
|
1414
|
+
reqJson_obj.put("platform", platform);
|
|
1415
|
+
reqJson_obj.put("store", store);
|
|
1416
|
+
oStreamObj.write(reqJson_obj.toString());
|
|
1417
|
+
oStreamObj.flush();
|
|
1418
|
+
oStreamObj.close();
|
|
1419
|
+
serverResponseObj = new StringBuilder();
|
|
1420
|
+
responseReaderObj = new BufferedReader(new InputStreamReader(urlConObj.getInputStream()));
|
|
1421
|
+
while ((currentLine = responseReaderObj.readLine()) != null) {
|
|
1422
|
+
serverResponseObj.append(currentLine);
|
|
1423
|
+
}
|
|
1424
|
+
responseReaderObj.close();
|
|
1425
|
+
urlConObj.disconnect();
|
|
1426
|
+
responseDataObj = new JSONObject(serverResponseObj.toString());
|
|
1427
|
+
|
|
1428
|
+
/* VALIDATE DEVICE REQUEST */
|
|
1429
|
+
try {
|
|
1430
|
+
requestValidateDevicePath = new URL(clientUrl + "/api/security/validate_device");
|
|
1431
|
+
urlConObj = (HttpURLConnection) requestValidateDevicePath.openConnection();
|
|
1432
|
+
urlConObj.setDoOutput(true);
|
|
1433
|
+
urlConObj.setRequestMethod("POST");
|
|
1434
|
+
urlConObj.setRequestProperty("CONTENT-TYPE", "application/json");
|
|
1435
|
+
urlConObj.connect();
|
|
1436
|
+
oStreamObj = new OutputStreamWriter(urlConObj.getOutputStream());
|
|
1437
|
+
JSONObject inputJson_obj = new JSONObject();
|
|
1438
|
+
JSONObject context_obj = new JSONObject();
|
|
1439
|
+
JSONObject inputparam_obj = new JSONObject();
|
|
1440
|
+
|
|
1441
|
+
inputparam_obj.put("p_device_id", deviceID);
|
|
1442
|
+
inputparam_obj.put("p_company_id", clientID);
|
|
1443
|
+
inputparam_obj.put("p_country_code", countryCode);
|
|
1444
|
+
context_obj.put("sessionId", sessionID);
|
|
1445
|
+
context_obj.put("userId", userID);
|
|
1446
|
+
context_obj.put("client_id", clientID);
|
|
1447
|
+
context_obj.put("locale_id", localeID);
|
|
1448
|
+
context_obj.put("country_code", countryCode);
|
|
1449
|
+
context_obj.put("inputparam", inputparam_obj);
|
|
1450
|
+
|
|
1451
|
+
inputJson_obj.put("context", context_obj);
|
|
1452
|
+
oStreamObj.write(inputJson_obj.toString());
|
|
1453
|
+
oStreamObj.flush();
|
|
1454
|
+
oStreamObj.close();
|
|
1455
|
+
serverResponseObj = new StringBuilder();
|
|
1456
|
+
responseReaderObj = new BufferedReader(new InputStreamReader(urlConObj.getInputStream()));
|
|
1457
|
+
while ((currentLine = responseReaderObj.readLine()) != null) {
|
|
1458
|
+
serverResponseObj.append(currentLine);
|
|
1459
|
+
}
|
|
1460
|
+
responseReaderObj.close();
|
|
1461
|
+
urlConObj.disconnect();
|
|
1462
|
+
String responseStr = serverResponseObj.toString().replace("\\", "");
|
|
1463
|
+
responseStr = responseStr.substring(1, responseStr.length() - 1);
|
|
1464
|
+
JSONObject resultJsonObj = new JSONObject(responseStr).getJSONObject("outputparam");
|
|
1465
|
+
responseDataObj = responseDataObj.put("validDevice", "true");
|
|
1466
|
+
/* RESPONSE FOR AUTHENTICATION & VALIDATE DEVICE REQUESTS */
|
|
1467
|
+
writerObj = new BufferedWriter(new FileWriter(new File(rootDirectory, "/" + packageName + "/" + clientID + "/" + countryCode + "/" + "app_state_info.txt")));
|
|
1468
|
+
writerObj.write(encrypt(responseDataObj.toString()));
|
|
1469
|
+
writerObj.flush();
|
|
1470
|
+
writerObj.close();
|
|
1471
|
+
callbackContext.success(responseDataObj.toString());
|
|
1472
|
+
|
|
1473
|
+
} catch (Exception ex) {
|
|
1474
|
+
responseDataObj = responseDataObj.put("validDevice", "nostatus");
|
|
1475
|
+
writerObj = new BufferedWriter(new FileWriter(new File(rootDirectory, "/" + packageName + "/" + clientID + "/" + countryCode + "/" + "app_state_info.txt")));
|
|
1476
|
+
writerObj.write(encrypt(responseDataObj.toString()));
|
|
1477
|
+
writerObj.flush();
|
|
1478
|
+
writerObj.close();
|
|
1479
|
+
callbackContext.success(responseDataObj.toString());
|
|
1480
|
+
}
|
|
1481
|
+
} catch (Exception e) {
|
|
1482
|
+
System.out.println(e.getMessage());
|
|
1483
|
+
callbackContext.success("");
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
|
|
1487
|
+
public static void validateAppStateInfo(Context applicationContext) {
|
|
1488
|
+
String currentLine;
|
|
1489
|
+
try {
|
|
1490
|
+
File appStateIndicatorFile = new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/" + clientID + "/" + countryCode + "/" + "app_state_info.txt");
|
|
1491
|
+
if (appStateIndicatorFile.exists()) {
|
|
1492
|
+
BufferedReader authFileReader = new BufferedReader(new FileReader(appStateIndicatorFile));
|
|
1493
|
+
StringBuilder authFileBuilder = new StringBuilder();
|
|
1494
|
+
while ((currentLine = authFileReader.readLine()) != null) {
|
|
1495
|
+
authFileBuilder.append(currentLine);
|
|
1496
|
+
}
|
|
1497
|
+
authFileReader.close();
|
|
1498
|
+
JSONObject authFileObj = new JSONObject(decrypt(authFileBuilder.toString()));
|
|
1499
|
+
long lastModifiedTime = appStateIndicatorFile.lastModified();
|
|
1500
|
+
Date date = new Date();
|
|
1501
|
+
date.setTime(lastModifiedTime);
|
|
1502
|
+
String lastModifiedDate = new SimpleDateFormat("yyyyMMdd", new mInterfaceUtil().locale).format(date);
|
|
1503
|
+
|
|
1504
|
+
if (authFileObj.optString("validDevice").toString().equals("nostatus") || !lastModifiedDate.equals(new SimpleDateFormat("yyyyMMdd", new mInterfaceUtil().locale).format(new Date()))) {
|
|
1505
|
+
if (isConnected(applicationContext)) {
|
|
1506
|
+
new UpdateAppStateInfo().execute();
|
|
1507
|
+
} else {
|
|
1508
|
+
mInterfaceService.handleAppStateTimer("success");
|
|
1509
|
+
}
|
|
1510
|
+
} else {
|
|
1511
|
+
mInterfaceService.handleAppStateTimer("success");
|
|
1512
|
+
}
|
|
1513
|
+
} else {
|
|
1514
|
+
if (isConnected(applicationContext)) {
|
|
1515
|
+
new UpdateAppStateInfo().execute();
|
|
1516
|
+
} else {
|
|
1517
|
+
mInterfaceService.handleAppStateTimer("failure");
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
} catch (Exception e) {
|
|
1521
|
+
System.out.println(e.getMessage());
|
|
1522
|
+
mInterfaceService.handleAppStateTimer("failure");
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
|
|
1526
|
+
/* App State info */
|
|
1527
|
+
private static class UpdateAppStateInfo extends AsyncTask<String,
|
|
1528
|
+
Void,
|
|
1529
|
+
String> {
|
|
1530
|
+
@Override
|
|
1531
|
+
protected String doInBackground(String... strings) {
|
|
1532
|
+
String currentLine;
|
|
1533
|
+
URL requestAuthenticationPath,
|
|
1534
|
+
requestValidateDevicePath, getKeysPath;
|
|
1535
|
+
HttpURLConnection urlConObj;
|
|
1536
|
+
OutputStreamWriter oStreamObj;
|
|
1537
|
+
BufferedWriter writerObj;
|
|
1538
|
+
StringBuilder serverResponseObj;
|
|
1539
|
+
BufferedReader responseReaderObj;
|
|
1540
|
+
JSONObject responseDataObj;
|
|
1541
|
+
try {
|
|
1542
|
+
getKeysPath = new URL(clientUrl + "/" + "common/components/Keys/" + "RetrieveKey.aspx");
|
|
1543
|
+
urlConObj = (HttpURLConnection)getKeysPath.openConnection();
|
|
1544
|
+
urlConObj.setDoOutput(true);
|
|
1545
|
+
urlConObj.setRequestMethod("POST");
|
|
1546
|
+
urlConObj.setRequestProperty("CONTENT-TYPE", "application/json");
|
|
1547
|
+
urlConObj.connect();
|
|
1548
|
+
JSONObject jsonObject1 = new JSONObject();
|
|
1549
|
+
jsonObject1 = jsonObject1.put("client_id", clientID);
|
|
1550
|
+
jsonObject1 = jsonObject1.put("country_code", countryCode);
|
|
1551
|
+
jsonObject1 = jsonObject1.put("purposeCode", "mobile_address_store");
|
|
1552
|
+
System.out.println("data format: " + jsonObject1.toString());
|
|
1553
|
+
oStreamObj = new OutputStreamWriter(urlConObj.getOutputStream());
|
|
1554
|
+
oStreamObj.write(jsonObject1.toString());
|
|
1555
|
+
oStreamObj.flush();
|
|
1556
|
+
oStreamObj.close();
|
|
1557
|
+
serverResponseObj = new StringBuilder();
|
|
1558
|
+
responseReaderObj = new BufferedReader(new InputStreamReader(urlConObj.getInputStream()));
|
|
1559
|
+
while ((currentLine = responseReaderObj.readLine()) != null) {
|
|
1560
|
+
serverResponseObj.append(currentLine);
|
|
1561
|
+
}
|
|
1562
|
+
responseReaderObj.close();
|
|
1563
|
+
urlConObj.disconnect();
|
|
1564
|
+
writerObj = new BufferedWriter(new FileWriter(new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/" + clientID + "/" + countryCode + "/" + "client_configuration_encrypted.txt")));
|
|
1565
|
+
writerObj.write(encrypt(serverResponseObj.toString()));
|
|
1566
|
+
writerObj.flush();
|
|
1567
|
+
writerObj.close();
|
|
1568
|
+
/* App State info DATA REQUEST */
|
|
1569
|
+
requestAuthenticationPath = new URL(cvsUrl + "/" + "get_app_state_info.aspx");
|
|
1570
|
+
urlConObj = (HttpURLConnection) requestAuthenticationPath.openConnection();
|
|
1571
|
+
urlConObj.setDoOutput(true);
|
|
1572
|
+
urlConObj.setRequestMethod("POST");
|
|
1573
|
+
urlConObj.setRequestProperty("CONTENT-TYPE", "application/json");
|
|
1574
|
+
urlConObj.connect();
|
|
1575
|
+
|
|
1576
|
+
oStreamObj = new OutputStreamWriter(urlConObj.getOutputStream());
|
|
1577
|
+
JSONObject reqJson_obj = new JSONObject();
|
|
1578
|
+
reqJson_obj.put("client_id", clientID);
|
|
1579
|
+
reqJson_obj.put("country_code", countryCode);
|
|
1580
|
+
reqJson_obj.put("app_id", app_id);
|
|
1581
|
+
reqJson_obj.put("platform", platform);
|
|
1582
|
+
reqJson_obj.put("store", store);
|
|
1583
|
+
oStreamObj.write(reqJson_obj.toString());
|
|
1584
|
+
oStreamObj.flush();
|
|
1585
|
+
oStreamObj.close();
|
|
1586
|
+
serverResponseObj = new StringBuilder();
|
|
1587
|
+
responseReaderObj = new BufferedReader(new InputStreamReader(urlConObj.getInputStream()));
|
|
1588
|
+
while ((currentLine = responseReaderObj.readLine()) != null) {
|
|
1589
|
+
serverResponseObj.append(currentLine);
|
|
1590
|
+
}
|
|
1591
|
+
responseReaderObj.close();
|
|
1592
|
+
urlConObj.disconnect();
|
|
1593
|
+
responseDataObj = new JSONObject(serverResponseObj.toString());
|
|
1594
|
+
|
|
1595
|
+
/* VALIDATE DEVICE REQUEST */
|
|
1596
|
+
try {
|
|
1597
|
+
requestValidateDevicePath = new URL(clientUrl + "/api/security/validate_device");
|
|
1598
|
+
urlConObj = (HttpURLConnection) requestValidateDevicePath.openConnection();
|
|
1599
|
+
urlConObj.setDoOutput(true);
|
|
1600
|
+
urlConObj.setRequestMethod("POST");
|
|
1601
|
+
urlConObj.setRequestProperty("CONTENT-TYPE", "application/json");
|
|
1602
|
+
urlConObj.connect();
|
|
1603
|
+
oStreamObj = new OutputStreamWriter(urlConObj.getOutputStream());
|
|
1604
|
+
JSONObject inputJson_obj = new JSONObject();
|
|
1605
|
+
JSONObject context_obj = new JSONObject();
|
|
1606
|
+
JSONObject inputparam_obj = new JSONObject();
|
|
1607
|
+
|
|
1608
|
+
inputparam_obj.put("p_device_id", deviceID);
|
|
1609
|
+
inputparam_obj.put("p_company_id", clientID);
|
|
1610
|
+
inputparam_obj.put("p_country_code", countryCode);
|
|
1611
|
+
context_obj.put("sessionId", sessionID);
|
|
1612
|
+
context_obj.put("userId", userID);
|
|
1613
|
+
context_obj.put("client_id", clientID);
|
|
1614
|
+
context_obj.put("locale_id", localeID);
|
|
1615
|
+
context_obj.put("country_code", countryCode);
|
|
1616
|
+
context_obj.put("inputparam", inputparam_obj);
|
|
1617
|
+
|
|
1618
|
+
inputJson_obj.put("context", context_obj);
|
|
1619
|
+
oStreamObj.write(inputJson_obj.toString());
|
|
1620
|
+
oStreamObj.flush();
|
|
1621
|
+
oStreamObj.close();
|
|
1622
|
+
serverResponseObj = new StringBuilder();
|
|
1623
|
+
responseReaderObj = new BufferedReader(new InputStreamReader(urlConObj.getInputStream()));
|
|
1624
|
+
while ((currentLine = responseReaderObj.readLine()) != null) {
|
|
1625
|
+
serverResponseObj.append(currentLine);
|
|
1626
|
+
}
|
|
1627
|
+
responseReaderObj.close();
|
|
1628
|
+
urlConObj.disconnect();
|
|
1629
|
+
String responseStr = serverResponseObj.toString().replace("\\", "");
|
|
1630
|
+
responseStr = responseStr.substring(1, responseStr.length() - 1);
|
|
1631
|
+
JSONObject resultJsonObj = new JSONObject(responseStr).getJSONObject("outputparam");
|
|
1632
|
+
responseDataObj = responseDataObj.put("validDevice", "true");
|
|
1633
|
+
/* RESPONSE FOR AUTHENTICATION & VALIDATE DEVICE REQUESTS */
|
|
1634
|
+
writerObj = new BufferedWriter(new FileWriter(new File(rootDirectory, "/" + packageName + "/" + clientID + "/" + countryCode + "/" + "app_state_info.txt")));
|
|
1635
|
+
writerObj.write(encrypt(responseDataObj.toString()));
|
|
1636
|
+
writerObj.flush();
|
|
1637
|
+
writerObj.close();
|
|
1638
|
+
|
|
1639
|
+
mInterfaceService.handleAppStateTimer("Success");
|
|
1640
|
+
|
|
1641
|
+
} catch (Exception ex) {
|
|
1642
|
+
responseDataObj = responseDataObj.put("validDevice", "nostatus");
|
|
1643
|
+
writerObj = new BufferedWriter(new FileWriter(new File(rootDirectory, "/" + packageName + "/" + clientID + "/" + countryCode + "/" + "app_state_info.txt")));
|
|
1644
|
+
writerObj.write(encrypt(responseDataObj.toString()));
|
|
1645
|
+
writerObj.flush();
|
|
1646
|
+
writerObj.close();
|
|
1647
|
+
mInterfaceService.handleAppStateTimer("Success");
|
|
1648
|
+
}
|
|
1649
|
+
} catch (Exception e) {
|
|
1650
|
+
System.out.println(e.getMessage());
|
|
1651
|
+
mInterfaceService.handleAppStateTimer("failure");
|
|
1652
|
+
}
|
|
1653
|
+
return null;
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1656
|
+
|
|
1657
|
+
public boolean updateAppInfo(JSONArray args) {
|
|
1658
|
+
try {
|
|
1659
|
+
JSONObject appInfo = args.getJSONObject(0);
|
|
1660
|
+
mInterfaceUtil.app_id = appInfo.optString("app_id").toString();
|
|
1661
|
+
mInterfaceUtil.platform = appInfo.optString("platform").toString();
|
|
1662
|
+
mInterfaceUtil.deviceID = appInfo.optString("device_id").toString();
|
|
1663
|
+
mInterfaceUtil.clientID = appInfo.optString("client_id").toString();
|
|
1664
|
+
mInterfaceUtil.countryCode = appInfo.optString("country_code").toString();
|
|
1665
|
+
mInterfaceUtil.localeID = appInfo.optString("locale_id").toString();
|
|
1666
|
+
mInterfaceUtil.sessionID = appInfo.optString("session_id").toString();
|
|
1667
|
+
mInterfaceUtil.userID = appInfo.optString("user_Id").toString();
|
|
1668
|
+
mInterfaceUtil.employeeId = appInfo.optString("employee_id").toString();
|
|
1669
|
+
mInterfaceUtil.clientUrl = appInfo.optString("client_url").toString();
|
|
1670
|
+
mInterfaceUtil.cvsUrl = appInfo.optString("cvs_url").toString();
|
|
1671
|
+
mInterfaceUtil.store = appInfo.optString("store_name").toString();
|
|
1672
|
+
} catch (Exception e) {
|
|
1673
|
+
return false;
|
|
1674
|
+
}
|
|
1675
|
+
return true;
|
|
1676
|
+
}
|
|
1677
|
+
|
|
1678
|
+
public static boolean isConnected(Context applicationContext) {
|
|
1679
|
+
ConnectivityManager online = (ConnectivityManager) applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
1680
|
+
NetworkInfo networkInfo = online.getActiveNetworkInfo();
|
|
1681
|
+
if (networkInfo != null && networkInfo.isConnected()) {
|
|
1682
|
+
return true;
|
|
1683
|
+
} else {
|
|
1684
|
+
return false;
|
|
1685
|
+
}
|
|
1686
|
+
}
|
|
1687
1687
|
}
|