66import android .content .pm .PackageManager ;
77import android .net .Uri ;
88import android .os .Build ;
9+
910import androidx .core .content .FileProvider ;
11+
1012import android .util .SparseArray ;
1113import android .content .ActivityNotFoundException ;
1214
3032import okhttp3 .OkHttpClient ;
3133
3234import javax .annotation .Nullable ;
35+
3336import java .io .File ;
3437import java .util .Map ;
3538import java .util .concurrent .LinkedBlockingQueue ;
@@ -44,12 +47,12 @@ public class ReactNativeBlobUtil extends ReactContextBaseJavaModule {
4447 private final OkHttpClient mClient ;
4548
4649 static ReactApplicationContext RCTContext ;
47- private static LinkedBlockingQueue <Runnable > taskQueue = new LinkedBlockingQueue <>();
48- private static ThreadPoolExecutor threadPool = new ThreadPoolExecutor (5 , 10 , 5000 , TimeUnit .MILLISECONDS , taskQueue );
50+ private static final LinkedBlockingQueue <Runnable > taskQueue = new LinkedBlockingQueue <>();
51+ private static final ThreadPoolExecutor threadPool = new ThreadPoolExecutor (5 , 10 , 5000 , TimeUnit .MILLISECONDS , taskQueue );
4952 static LinkedBlockingQueue <Runnable > fsTaskQueue = new LinkedBlockingQueue <>();
50- private static ThreadPoolExecutor fsThreadPool = new ThreadPoolExecutor (2 , 10 , 5000 , TimeUnit .MILLISECONDS , taskQueue );
53+ private static final ThreadPoolExecutor fsThreadPool = new ThreadPoolExecutor (2 , 10 , 5000 , TimeUnit .MILLISECONDS , taskQueue );
5154 private static boolean ActionViewVisible = false ;
52- private static SparseArray <Promise > promiseTable = new SparseArray <>();
55+ private static final SparseArray <Promise > promiseTable = new SparseArray <>();
5356
5457 public ReactNativeBlobUtil (ReactApplicationContext reactContext ) {
5558
@@ -64,7 +67,7 @@ public ReactNativeBlobUtil(ReactApplicationContext reactContext) {
6467 reactContext .addActivityEventListener (new ActivityEventListener () {
6568 @ Override
6669 public void onActivityResult (Activity activity , int requestCode , int resultCode , Intent data ) {
67- if (requestCode == GET_CONTENT_INTENT && resultCode == RESULT_OK ) {
70+ if (requestCode == GET_CONTENT_INTENT && resultCode == RESULT_OK ) {
6871 Uri d = data .getData ();
6972 promiseTable .get (GET_CONTENT_INTENT ).resolve (d .toString ());
7073 promiseTable .remove (GET_CONTENT_INTENT );
@@ -142,7 +145,7 @@ public void actionViewIntent(String path, String mime, @Nullable String chooserT
142145 try {
143146 this .getReactApplicationContext ().startActivity (intent );
144147 promise .resolve (true );
145- } catch (ActivityNotFoundException ex ) {
148+ } catch (ActivityNotFoundException ex ) {
146149 promise .reject ("ENOAPP" , "No app installed for " + mime );
147150 }
148151 }
@@ -152,7 +155,7 @@ public void actionViewIntent(String path, String mime, @Nullable String chooserT
152155
153156 @ Override
154157 public void onHostResume () {
155- if (ActionViewVisible )
158+ if (ActionViewVisible )
156159 promise .resolve (null );
157160 RCTContext .removeLifecycleEventListener (this );
158161 }
@@ -168,7 +171,7 @@ public void onHostDestroy() {
168171 }
169172 };
170173 RCTContext .addLifecycleEventListener (listener );
171- } catch (Exception ex ) {
174+ } catch (Exception ex ) {
172175 promise .reject ("EUNSPECIFIED" , ex .getLocalizedMessage ());
173176 }
174177 }
@@ -280,13 +283,13 @@ public void scanFile(final ReadableArray pairs, final Callback callback) {
280283 @ Override
281284 public void run () {
282285 int size = pairs .size ();
283- String [] p = new String [size ];
284- String [] m = new String [size ];
285- for (int i = 0 ; i < size ;i ++) {
286+ String [] p = new String [size ];
287+ String [] m = new String [size ];
288+ for (int i = 0 ; i < size ; i ++) {
286289 ReadableMap pair = pairs .getMap (i );
287- if (pair .hasKey ("path" )) {
290+ if (pair .hasKey ("path" )) {
288291 p [i ] = pair .getString ("path" );
289- if (pair .hasKey ("mime" ))
292+ if (pair .hasKey ("mime" ))
290293 m [i ] = pair .getString ("mime" );
291294 else
292295 m [i ] = null ;
@@ -308,8 +311,8 @@ public void run() {
308311 }
309312
310313 /**
311- * @param path Stream file path
312- * @param encoding Stream encoding, should be one of `base64`, `ascii`, and `utf8`
314+ * @param path Stream file path
315+ * @param encoding Stream encoding, should be one of `base64`, `ascii`, and `utf8`
313316 * @param bufferSize Stream buffer size, default to 4096 or 4095(base64).
314317 */
315318 @ ReactMethod
@@ -375,7 +378,7 @@ public void fetchBlobForm(ReadableMap options, String taskId, String method, Str
375378 @ ReactMethod
376379 public void getContentIntent (String mime , Promise promise ) {
377380 Intent i = new Intent (Intent .ACTION_GET_CONTENT );
378- if (mime != null )
381+ if (mime != null )
379382 i .setType (mime );
380383 else
381384 i .setType ("*/*" );
@@ -385,15 +388,14 @@ public void getContentIntent(String mime, Promise promise) {
385388 }
386389
387390 @ ReactMethod
388- public void addCompleteDownload (ReadableMap config , Promise promise ) {
391+ public void addCompleteDownload (ReadableMap config , Promise promise ) {
389392 DownloadManager dm = (DownloadManager ) RCTContext .getSystemService (RCTContext .DOWNLOAD_SERVICE );
390- if (config == null || !config .hasKey ("path" ))
391- {
393+ if (config == null || !config .hasKey ("path" )) {
392394 promise .reject ("EINVAL" , "ReactNativeBlobUtil.addCompleteDownload config or path missing." );
393395 return ;
394396 }
395397 String path = ReactNativeBlobUtilFS .normalizePath (config .getString ("path" ));
396- if (path == null ) {
398+ if (path == null ) {
397399 promise .reject ("EINVAL" , "ReactNativeBlobUtil.addCompleteDownload can not resolve URI:" + config .getString ("path" ));
398400 return ;
399401 }
@@ -409,8 +411,7 @@ public void addCompleteDownload (ReadableMap config, Promise promise) {
409411 config .hasKey ("showNotification" ) && config .getBoolean ("showNotification" )
410412 );
411413 promise .resolve (null );
412- }
413- catch (Exception ex ) {
414+ } catch (Exception ex ) {
414415 promise .reject ("EUNSPECIFIED" , ex .getLocalizedMessage ());
415416 }
416417
0 commit comments