28
28
import java .util .concurrent .LinkedBlockingQueue ;
29
29
import java .util .concurrent .ThreadPoolExecutor ;
30
30
import java .util .concurrent .TimeUnit ;
31
+ import java .util .Arrays ;
31
32
32
33
import static android .app .Activity .RESULT_OK ;
33
34
import static com .RNFetchBlob .RNFetchBlobConst .GET_CONTENT_INTENT ;
34
35
36
+ import android .util .Log ;
37
+
35
38
public class RNFetchBlob extends ReactContextBaseJavaModule {
36
39
40
+ private static final String TAG = "RNFetchBlob" ;
41
+
37
42
// Cookies
38
43
private final ForwardingCookieHandler mCookieHandler ;
39
44
private final CookieJarContainer mCookieJarContainer ;
@@ -47,6 +52,9 @@ public class RNFetchBlob extends ReactContextBaseJavaModule {
47
52
static public boolean ActionViewVisible = false ;
48
53
static HashMap <Integer , Promise > promiseTable = new HashMap <>();
49
54
55
+ // Added by Rick Terrill 11-2017
56
+ public static byte [] appSalt ;
57
+
50
58
public RNFetchBlob (ReactApplicationContext reactContext ) {
51
59
52
60
super (reactContext );
@@ -60,7 +68,7 @@ public RNFetchBlob(ReactApplicationContext reactContext) {
60
68
reactContext .addActivityEventListener (new ActivityEventListener () {
61
69
@ Override
62
70
public void onActivityResult (Activity activity , int requestCode , int resultCode , Intent data ) {
63
- if (requestCode == GET_CONTENT_INTENT && resultCode == RESULT_OK ) {
71
+ if (requestCode == GET_CONTENT_INTENT && resultCode == RESULT_OK ) {
64
72
Uri d = data .getData ();
65
73
promiseTable .get (GET_CONTENT_INTENT ).resolve (d .toString ());
66
74
promiseTable .remove (GET_CONTENT_INTENT );
@@ -84,6 +92,14 @@ public Map<String, Object> getConstants() {
84
92
return RNFetchBlobFS .getSystemfolders (this .getReactApplicationContext ());
85
93
}
86
94
95
+ // Added by Rick Terrill 11-2017
96
+ @ ReactMethod
97
+ public void setSalt (String salt ) {
98
+ Log .d (TAG , "setting app salt: " + salt );
99
+ RNFetchBlob .appSalt = Arrays .copyOfRange (salt .getBytes (), 0 , 8 );
100
+ Log .d (TAG , "setting app salt: " + Arrays .toString (RNFetchBlob .appSalt ));
101
+ }
102
+
87
103
@ ReactMethod
88
104
public void createFile (final String path , final String content , final String encode , final Callback callback ) {
89
105
threadPool .execute (new Runnable () {
@@ -98,16 +114,15 @@ public void run() {
98
114
@ ReactMethod
99
115
public void actionViewIntent (String path , String mime , final Promise promise ) {
100
116
try {
101
- Intent intent = new Intent (Intent .ACTION_VIEW )
102
- .setDataAndType (Uri .parse ("file://" + path ), mime );
117
+ Intent intent = new Intent (Intent .ACTION_VIEW ).setDataAndType (Uri .parse ("file://" + path ), mime );
103
118
intent .setFlags (Intent .FLAG_ACTIVITY_NEW_TASK );
104
119
this .getReactApplicationContext ().startActivity (intent );
105
120
ActionViewVisible = true ;
106
121
107
122
final LifecycleEventListener listener = new LifecycleEventListener () {
108
123
@ Override
109
124
public void onHostResume () {
110
- if (ActionViewVisible )
125
+ if (ActionViewVisible )
111
126
promise .resolve (null );
112
127
RCTContext .removeLifecycleEventListener (this );
113
128
}
@@ -123,7 +138,7 @@ public void onHostDestroy() {
123
138
}
124
139
};
125
140
RCTContext .addLifecycleEventListener (listener );
126
- } catch (Exception ex ) {
141
+ } catch (Exception ex ) {
127
142
promise .reject (ex .getLocalizedMessage ());
128
143
}
129
144
}
@@ -211,7 +226,8 @@ public void run() {
211
226
}
212
227
213
228
@ ReactMethod
214
- public void writeFileArray (final String path , final ReadableArray data , final boolean append , final Promise promise ) {
229
+ public void writeFileArray (final String path , final ReadableArray data , final boolean append ,
230
+ final Promise promise ) {
215
231
threadPool .execute (new Runnable () {
216
232
@ Override
217
233
public void run () {
@@ -221,7 +237,8 @@ public void run() {
221
237
}
222
238
223
239
@ ReactMethod
224
- public void writeFile (final String path , final String encoding , final String data , final boolean append , final Promise promise ) {
240
+ public void writeFile (final String path , final String encoding , final String data , final boolean append ,
241
+ final Promise promise ) {
225
242
threadPool .execute (new Runnable () {
226
243
@ Override
227
244
public void run () {
@@ -248,13 +265,13 @@ public void scanFile(final ReadableArray pairs, final Callback callback) {
248
265
@ Override
249
266
public void run () {
250
267
int size = pairs .size ();
251
- String [] p = new String [size ];
252
- String [] m = new String [size ];
253
- for (int i = 0 ; i < size ;i ++) {
268
+ String [] p = new String [size ];
269
+ String [] m = new String [size ];
270
+ for (int i = 0 ; i < size ; i ++) {
254
271
ReadableMap pair = pairs .getMap (i );
255
- if (pair .hasKey ("path" )) {
272
+ if (pair .hasKey ("path" )) {
256
273
p [i ] = pair .getString ("path" );
257
- if (pair .hasKey ("mime" ))
274
+ if (pair .hasKey ("mime" ))
258
275
m [i ] = pair .getString ("mime" );
259
276
else
260
277
m [i ] = null ;
@@ -272,7 +289,8 @@ public void run() {
272
289
* @param encoding Stream encoding, should be one of `base64`, `ascii`, and `utf8`
273
290
* @param bufferSize Stream buffer size, default to 4096 or 4095(base64).
274
291
*/
275
- public void readStream (final String path , final String encoding , final int bufferSize , final int tick , final String streamId ) {
292
+ public void readStream (final String path , final String encoding , final int bufferSize , final int tick ,
293
+ final String streamId ) {
276
294
final ReactApplicationContext ctx = this .getReactApplicationContext ();
277
295
fsThreadPool .execute (new Runnable () {
278
296
@ Override
@@ -300,7 +318,8 @@ public void slice(String src, String dest, int start, int end, Promise promise)
300
318
301
319
@ ReactMethod
302
320
public void enableProgressReport (String taskId , int interval , int count ) {
303
- RNFetchBlobProgressConfig config = new RNFetchBlobProgressConfig (true , interval , count , RNFetchBlobProgressConfig .ReportType .Download );
321
+ RNFetchBlobProgressConfig config = new RNFetchBlobProgressConfig (true , interval , count ,
322
+ RNFetchBlobProgressConfig .ReportType .Download );
304
323
RNFetchBlobReq .progressReport .put (taskId , config );
305
324
}
306
325
@@ -314,27 +333,29 @@ public void run() {
314
333
});
315
334
}
316
335
317
-
318
336
@ ReactMethod
319
337
public void enableUploadProgressReport (String taskId , int interval , int count ) {
320
- RNFetchBlobProgressConfig config = new RNFetchBlobProgressConfig (true , interval , count , RNFetchBlobProgressConfig .ReportType .Upload );
338
+ RNFetchBlobProgressConfig config = new RNFetchBlobProgressConfig (true , interval , count ,
339
+ RNFetchBlobProgressConfig .ReportType .Upload );
321
340
RNFetchBlobReq .uploadProgressReport .put (taskId , config );
322
341
}
323
342
324
343
@ ReactMethod
325
- public void fetchBlob (ReadableMap options , String taskId , String method , String url , ReadableMap headers , String body , final Callback callback ) {
344
+ public void fetchBlob (ReadableMap options , String taskId , String method , String url , ReadableMap headers ,
345
+ String body , final Callback callback ) {
326
346
new RNFetchBlobReq (options , taskId , method , url , headers , body , null , mClient , callback ).run ();
327
- }
347
+ }
328
348
329
349
@ ReactMethod
330
- public void fetchBlobForm (ReadableMap options , String taskId , String method , String url , ReadableMap headers , ReadableArray body , final Callback callback ) {
350
+ public void fetchBlobForm (ReadableMap options , String taskId , String method , String url , ReadableMap headers ,
351
+ ReadableArray body , final Callback callback ) {
331
352
new RNFetchBlobReq (options , taskId , method , url , headers , null , body , mClient , callback ).run ();
332
353
}
333
354
334
355
@ ReactMethod
335
356
public void getContentIntent (String mime , Promise promise ) {
336
357
Intent i = new Intent (Intent .ACTION_GET_CONTENT );
337
- if (mime != null )
358
+ if (mime != null )
338
359
i .setType (mime );
339
360
else
340
361
i .setType ("*/*" );
@@ -344,27 +365,23 @@ public void getContentIntent(String mime, Promise promise) {
344
365
}
345
366
346
367
@ ReactMethod
347
- public void addCompleteDownload (ReadableMap config , Promise promise ) {
348
- DownloadManager dm = (DownloadManager ) RNFetchBlob .RCTContext .getSystemService (RNFetchBlob .RCTContext .DOWNLOAD_SERVICE );
368
+ public void addCompleteDownload (ReadableMap config , Promise promise ) {
369
+ DownloadManager dm = (DownloadManager ) RNFetchBlob .RCTContext
370
+ .getSystemService (RNFetchBlob .RCTContext .DOWNLOAD_SERVICE );
349
371
String path = RNFetchBlobFS .normalizePath (config .getString ("path" ));
350
- if (path == null ) {
351
- promise .reject ("RNFetchblob.addCompleteDownload can not resolve URI:" + config .getString ("path" ), "RNFetchblob.addCompleteDownload can not resolve URI:" + path );
372
+ if (path == null ) {
373
+ promise .reject ("RNFetchblob.addCompleteDownload can not resolve URI:" + config .getString ("path" ),
374
+ "RNFetchblob.addCompleteDownload can not resolve URI:" + path );
352
375
return ;
353
376
}
354
377
try {
355
378
WritableMap stat = RNFetchBlobFS .statFile (path );
356
- dm .addCompletedDownload (
357
- config .hasKey ("title" ) ? config .getString ("title" ) : "" ,
358
- config .hasKey ("description" ) ? config .getString ("description" ) : "" ,
359
- true ,
360
- config .hasKey ("mime" ) ? config .getString ("mime" ) : null ,
361
- path ,
362
- Long .valueOf (stat .getString ("size" )),
363
- config .hasKey ("showNotification" ) && config .getBoolean ("showNotification" )
364
- );
379
+ dm .addCompletedDownload (config .hasKey ("title" ) ? config .getString ("title" ) : "" ,
380
+ config .hasKey ("description" ) ? config .getString ("description" ) : "" , true ,
381
+ config .hasKey ("mime" ) ? config .getString ("mime" ) : null , path , Long .valueOf (stat .getString ("size" )),
382
+ config .hasKey ("showNotification" ) && config .getBoolean ("showNotification" ));
365
383
promise .resolve (null );
366
- }
367
- catch (Exception ex ) {
384
+ } catch (Exception ex ) {
368
385
promise .reject ("RNFetchblob.addCompleteDownload failed" , ex .getStackTrace ().toString ());
369
386
}
370
387
0 commit comments