mirror of
https://github.com/TrianguloY/LightningLauncher.git
synced 2025-01-13 20:01:34 +01:00
A fix for exposed files in URIs
This commit is contained in:
parent
2f9687d6bb
commit
44cdc618c7
3 changed files with 73 additions and 5 deletions
|
@ -100,10 +100,11 @@
|
|||
android:name="net.pierrox.lightning_launcher.util.EmptyService"
|
||||
android:exported="false" />
|
||||
|
||||
<!-- <provider -->
|
||||
<!-- android:name=".util.FileProvider" -->
|
||||
<!-- android:authorities="net.pierrox.lightning_launcher.files" -->
|
||||
<!-- android:exported="true"/> -->
|
||||
<provider
|
||||
android:name="net.pierrox.lightning_launcher.util.FileProvider"
|
||||
android:authorities="net.pierrox.lightning_launcher.files"
|
||||
android:exported="true"
|
||||
android:grantUriPermissions="true"/>
|
||||
|
||||
<activity
|
||||
android:name="net.pierrox.lightning_launcher.activities.RootSettings"
|
||||
|
|
|
@ -74,6 +74,7 @@ import net.pierrox.lightning_launcher.script.api.RectL;
|
|||
import net.pierrox.lightning_launcher.script.api.Shortcut;
|
||||
import net.pierrox.lightning_launcher.script.api.StopPoint;
|
||||
import net.pierrox.lightning_launcher.util.FileAndDirectoryPickerDialog;
|
||||
import net.pierrox.lightning_launcher.util.FileProvider;
|
||||
import net.pierrox.lightning_launcher_extreme.BuildConfig;
|
||||
import net.pierrox.lightning_launcher_extreme.R;
|
||||
|
||||
|
@ -802,7 +803,9 @@ public class ScriptEditor extends ResourceWrapperActivity implements View.OnClic
|
|||
|
||||
String type = "text/javascript";
|
||||
intent = new Intent(Intent.ACTION_EDIT);
|
||||
intent.setDataAndType(Uri.fromFile(to), type);
|
||||
Uri uri = FileProvider.getUriForFile(to);
|
||||
intent.setDataAndType(uri, type);
|
||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
|
||||
try {
|
||||
startActivityForResult(intent, REQUEST_EDIT_SCRIPT);
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
package net.pierrox.lightning_launcher.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
import android.content.ContentProvider;
|
||||
import android.content.ContentValues;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
|
||||
import net.pierrox.lightning_launcher.activities.ScriptEditor;
|
||||
|
||||
|
||||
/** A bare minimum provider to prevent exposng file uris */
|
||||
public class FileProvider extends ContentProvider {
|
||||
public static final Uri CONTENT_URI=Uri.parse("content://net.pierrox.lightning_launcher.files/");
|
||||
|
||||
@Override
|
||||
public int delete(Uri uri, String selection, String[] selectionArgs) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType(Uri uri) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uri insert(Uri uri, ContentValues values) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreate() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
|
||||
File f=new File(uri.getPath());
|
||||
|
||||
if (f.exists()) {
|
||||
ParcelFileDescriptor pfd=ParcelFileDescriptor.open(f, ParcelFileDescriptor.MODE_READ_WRITE);
|
||||
return pfd;
|
||||
}
|
||||
|
||||
throw new FileNotFoundException(uri.getPath());
|
||||
}
|
||||
|
||||
public static Uri getUriForFile(File to) {
|
||||
return Uri.parse(CONTENT_URI + to.getAbsolutePath());
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue