Skip to content

Android security expose #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed May 18 12:33:41 CST 2016
#Wed Nov 29 11:45:41 CET 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
10 changes: 10 additions & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@
android:name=".RNFetchBlobService"
>
</service>

<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true" />
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
</application>

</manifest>
36 changes: 30 additions & 6 deletions android/src/main/java/com/RNFetchBlob/RNFetchBlob.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import android.app.Activity;
import android.app.DownloadManager;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.support.v4.content.FileProvider;

import com.RNFetchBlob.Utils.DataConverter;
import com.facebook.react.bridge.ActivityEventListener;
Expand All @@ -20,6 +23,7 @@
import com.facebook.react.modules.network.ForwardingCookieHandler;
import com.facebook.react.modules.network.OkHttpClientProvider;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.LinkedBlockingQueue;
Expand Down Expand Up @@ -101,16 +105,36 @@ public void run() {
@ReactMethod
public void actionViewIntent(String path, String mime, final Promise promise) {
try {
Intent intent= new Intent(Intent.ACTION_VIEW)
.setDataAndType(Uri.parse("file://" + path), mime);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.getReactApplicationContext().startActivity(intent);
Uri uriForFile = FileProvider.getUriForFile(getCurrentActivity(),
this.getReactApplicationContext().getPackageName() + ".provider", new File(path));

if (Build.VERSION.SDK_INT >= 24) {
// Create the intent with data and type
Intent intent = new Intent(Intent.ACTION_VIEW)
.setDataAndType(uriForFile, mime);

// Set flag to give temporary permission to external app to use FileProvider
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

// Validate that the device can open the file
PackageManager pm = getCurrentActivity().getPackageManager();
if (intent.resolveActivity(pm) != null) {
this.getReactApplicationContext().startActivity(intent);
}

} else {
Intent intent = new Intent(Intent.ACTION_VIEW)
.setDataAndType(Uri.parse("file://" + path), mime).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

this.getReactApplicationContext().startActivity(intent);
}

ActionViewVisible = true;

final LifecycleEventListener listener = new LifecycleEventListener() {
@Override
public void onHostResume() {
if(ActionViewVisible)
if (ActionViewVisible)
promise.resolve(null);
RCTContext.removeLifecycleEventListener(this);
}
Expand All @@ -126,7 +150,7 @@ public void onHostDestroy() {
}
};
RCTContext.addLifecycleEventListener(listener);
} catch(Exception ex) {
} catch (Exception ex) {
promise.reject(ex.getLocalizedMessage());
}
}
Expand Down
5 changes: 5 additions & 0 deletions android/src/main/res/xml/provider_paths.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="."/>
<files-path name="files-path" path="." /> <!-- Used to access into application data files -->
</paths>