Get XMLs directly

This commit is contained in:
topjohnwu 2019-11-08 02:59:09 -05:00
parent 61de63a518
commit c0216c0653
2 changed files with 7 additions and 34 deletions

View File

@ -16,6 +16,7 @@
<activity <activity
android:name="a.r" android:name="a.r"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:process=":remote" /> android:process=":remote" />
<provider <provider
@ -23,9 +24,6 @@
android:authorities="${applicationId}.provider" android:authorities="${applicationId}.provider"
android:exported="false" android:exported="false"
android:grantUriPermissions="true"> android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider> </provider>
</application> </application>
</manifest> </manifest>

View File

@ -3,7 +3,6 @@ package com.topjohnwu.magisk;
import android.content.ContentProvider; import android.content.ContentProvider;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.ProviderInfo; import android.content.pm.ProviderInfo;
import android.content.res.XmlResourceParser; import android.content.res.XmlResourceParser;
import android.database.Cursor; import android.database.Cursor;
@ -17,6 +16,8 @@ import android.provider.OpenableColumns;
import android.text.TextUtils; import android.text.TextUtils;
import android.webkit.MimeTypeMap; import android.webkit.MimeTypeMap;
import com.topjohnwu.shared.R;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
import java.io.File; import java.io.File;
@ -35,9 +36,6 @@ public class FileProvider extends ContentProvider {
private static final String[] COLUMNS = { private static final String[] COLUMNS = {
OpenableColumns.DISPLAY_NAME, OpenableColumns.SIZE }; OpenableColumns.DISPLAY_NAME, OpenableColumns.SIZE };
private static final String
META_DATA_FILE_PROVIDER_PATHS = "android.support.FILE_PROVIDER_PATHS";
private static final String TAG_ROOT_PATH = "root-path"; private static final String TAG_ROOT_PATH = "root-path";
private static final String TAG_FILES_PATH = "files-path"; private static final String TAG_FILES_PATH = "files-path";
private static final String TAG_CACHE_PATH = "cache-path"; private static final String TAG_CACHE_PATH = "cache-path";
@ -56,13 +54,12 @@ public class FileProvider extends ContentProvider {
private PathStrategy mStrategy; private PathStrategy mStrategy;
public static ProviderCallHandler callHandler; public static ProviderCallHandler callHandler;
@Override @Override
public boolean onCreate() { public boolean onCreate() {
return true; return true;
} }
@Override @Override
public void attachInfo(Context context, ProviderInfo info) { public void attachInfo(Context context, ProviderInfo info) {
super.attachInfo(context, info); super.attachInfo(context, info);
@ -85,7 +82,6 @@ public class FileProvider extends ContentProvider {
return strategy.getUriForFile(file); return strategy.getUriForFile(file);
} }
@Override @Override
public Cursor query(Uri uri, String[] projection, String selection, public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String[] selectionArgs,
@ -118,7 +114,6 @@ public class FileProvider extends ContentProvider {
return cursor; return cursor;
} }
@Override @Override
public String getType(Uri uri) { public String getType(Uri uri) {
@ -136,20 +131,17 @@ public class FileProvider extends ContentProvider {
return "application/octet-stream"; return "application/octet-stream";
} }
@Override @Override
public Uri insert(Uri uri, ContentValues values) { public Uri insert(Uri uri, ContentValues values) {
throw new UnsupportedOperationException("No external inserts"); throw new UnsupportedOperationException("No external inserts");
} }
@Override @Override
public int update(Uri uri, ContentValues values, String selection, public int update(Uri uri, ContentValues values, String selection,
String[] selectionArgs) { String[] selectionArgs) {
throw new UnsupportedOperationException("No external updates"); throw new UnsupportedOperationException("No external updates");
} }
@Override @Override
public int delete(Uri uri, String selection, public int delete(Uri uri, String selection,
String[] selectionArgs) { String[] selectionArgs) {
@ -158,7 +150,6 @@ public class FileProvider extends ContentProvider {
return file.delete() ? 1 : 0; return file.delete() ? 1 : 0;
} }
@Override @Override
public Bundle call(String method, String arg, Bundle extras) { public Bundle call(String method, String arg, Bundle extras) {
if (callHandler != null) if (callHandler != null)
@ -166,7 +157,6 @@ public class FileProvider extends ContentProvider {
return null; return null;
} }
@Override @Override
public ParcelFileDescriptor openFile(Uri uri, String mode) public ParcelFileDescriptor openFile(Uri uri, String mode)
throws FileNotFoundException { throws FileNotFoundException {
@ -176,7 +166,6 @@ public class FileProvider extends ContentProvider {
return ParcelFileDescriptor.open(file, fileMode); return ParcelFileDescriptor.open(file, fileMode);
} }
private static PathStrategy getPathStrategy(Context context, String authority) { private static PathStrategy getPathStrategy(Context context, String authority) {
PathStrategy strat; PathStrategy strat;
synchronized (sCache) { synchronized (sCache) {
@ -185,11 +174,9 @@ public class FileProvider extends ContentProvider {
try { try {
strat = parsePathStrategy(context, authority); strat = parsePathStrategy(context, authority);
} catch (IOException e) { } catch (IOException e) {
throw new IllegalArgumentException( throw new IllegalArgumentException("Failed to parse xml", e);
"Failed to parse " + META_DATA_FILE_PROVIDER_PATHS + " meta-data", e);
} catch (XmlPullParserException e) { } catch (XmlPullParserException e) {
throw new IllegalArgumentException( throw new IllegalArgumentException("Failed to parse xml", e);
"Failed to parse " + META_DATA_FILE_PROVIDER_PATHS + " meta-data", e);
} }
sCache.put(authority, strat); sCache.put(authority, strat);
} }
@ -197,19 +184,11 @@ public class FileProvider extends ContentProvider {
return strat; return strat;
} }
private static PathStrategy parsePathStrategy(Context context, String authority) private static PathStrategy parsePathStrategy(Context context, String authority)
throws IOException, XmlPullParserException { throws IOException, XmlPullParserException {
final SimplePathStrategy strat = new SimplePathStrategy(authority); final SimplePathStrategy strat = new SimplePathStrategy(authority);
final ProviderInfo info = context.getPackageManager() final XmlResourceParser in = context.getResources().getXml(R.xml.file_paths);
.resolveContentProvider(authority, PackageManager.GET_META_DATA);
final XmlResourceParser in = info.loadXmlMetaData(
context.getPackageManager(), META_DATA_FILE_PROVIDER_PATHS);
if (in == null) {
throw new IllegalArgumentException(
"Missing " + META_DATA_FILE_PROVIDER_PATHS + " meta-data");
}
int type; int type;
while ((type = in.next()) != END_DOCUMENT) { while ((type = in.next()) != END_DOCUMENT) {
@ -255,16 +234,13 @@ public class FileProvider extends ContentProvider {
return strat; return strat;
} }
interface PathStrategy { interface PathStrategy {
Uri getUriForFile(File file); Uri getUriForFile(File file);
File getFileForUri(Uri uri); File getFileForUri(Uri uri);
} }
static class SimplePathStrategy implements PathStrategy { static class SimplePathStrategy implements PathStrategy {
private final String mAuthority; private final String mAuthority;
private final HashMap<String, File> mRoots = new HashMap<>(); private final HashMap<String, File> mRoots = new HashMap<>();
@ -273,7 +249,6 @@ public class FileProvider extends ContentProvider {
mAuthority = authority; mAuthority = authority;
} }
void addRoot(String name, File root) { void addRoot(String name, File root) {
if (TextUtils.isEmpty(name)) { if (TextUtils.isEmpty(name)) {
throw new IllegalArgumentException("Name must not be empty"); throw new IllegalArgumentException("Name must not be empty");