Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 578f0a0e authored by Steve Kondik's avatar Steve Kondik
Browse files

cmfm: Use FileProvider for serving files

 * On N, apps can no longer share file:// uris to other packages.
   Apps that wish to do this must use a FileProvider to
   generate content uris which can then be shared.
 * This patch only currently handles the external storage case and does
   not consider arbitrary filesystem paths or root access. This could
   be implemented in the future, if necessary. The common case of
   opening a media file is a good start, though.

Change-Id: I83aef923dfa26173171a13c0881aeb43337b4e47
parent 0c04e1da
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -76,6 +76,16 @@
      android:authorities="com.cyanogenmod.filemanager.providers.index"
      android:name=".providers.MimeTypeIndexProvider"/>

    <provider
      android:name="android.support.v4.content.FileProvider"
      android:authorities="com.cyanogenmod.filemanager.providers.file"
      android:exported="false"
      android:grantUriPermissions="true">
        <meta-data
          android:name="android.support.FILE_PROVIDER_PATHS"
          android:resource="@xml/provider_paths" />
    </provider>

    <service
      android:name=".service.MimeTypeIndexService"
      android:label="@string/app_name">
+4 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path name="external_files" path="."/>
</paths>
+5 −1
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ import android.os.Parcelable;
import android.os.storage.StorageVolume;
import android.provider.Settings;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.content.FileProvider;
import android.support.v4.widget.DrawerLayout;
import android.text.TextUtils;
import android.util.Log;
@@ -623,7 +624,10 @@ public class NavigationActivity extends Activity
                        for (FileSystemObject f : selectedFiles) {
                            //Beam ignores folders and system files
                            if (!FileHelper.isDirectory(f) && !FileHelper.isSystemFile(f)) {
                                fileUri.add(Uri.fromFile(new File(f.getFullPath())));
                                fileUri.add(FileProvider.getUriForFile(
                                            NavigationActivity.this,
                                            "com.cyanogenmod.filemanager.providers.file",
                                            new File(f.getFullPath())));
                            }
                        }
                        if (fileUri.size() > 0) {
+5 −2
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.storage.StorageVolume;
import android.support.v4.content.FileProvider;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
@@ -466,7 +467,8 @@ public class PickerActivity extends Activity
                    if (getIntent().getType() != null) {
                        intent.setType(getIntent().getType());
                    }
                    intent.setData(Uri.fromFile(src));
                    intent.setData(FileProvider.getUriForFile(this,
                                "com.cyanogenmod.filemanager.providers.file", src));
                    intent.putExtras(extras);
                    intent.setComponent(CROP_COMPONENT);
                    try {
@@ -572,7 +574,8 @@ public class PickerActivity extends Activity
        // Try to find the preferred uri scheme
        Uri result = MediaHelper.fileToContentUri(context, src);
        if (result == null) {
            result = Uri.fromFile(src);
            result = FileProvider.getUriForFile(context,
                    "com.cyanogenmod.filemanager.providers.file", src);
        }

        if (Intent.ACTION_PICK.equals(intent.getAction()) && intent.getData() != null) {
+1 −1
Original line number Diff line number Diff line
@@ -166,7 +166,7 @@ public class AssociationsDialog implements OnItemClickListener {
                    public void onClick(DialogInterface dialog, int which) {
                        ResolveInfo ri = getSelected();
                        Intent intent =
                                IntentsActionPolicy.getIntentFromResolveInfo(
                                IntentsActionPolicy.getIntentFromResolveInfo(mContext,
                                        ri, AssociationsDialog.this.mRequestIntent);

                        // Open the intent (and remember the action is the check is marked)
Loading