Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Magisk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Magisk
Commits
d382b00e
Commit
d382b00e
authored
Mar 28, 2020
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Accept all paths in FileProvider
Get rid of file_paths.xml
parent
ef9d077c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
76 deletions
+22
-76
FileProvider.java
shared/src/main/java/com/topjohnwu/magisk/FileProvider.java
+22
-68
file_paths.xml
shared/src/main/res/xml/file_paths.xml
+0
-8
No files found.
shared/src/main/java/com/topjohnwu/magisk/FileProvider.java
View file @
d382b00e
...
@@ -4,7 +4,6 @@ import android.content.ContentProvider;
...
@@ -4,7 +4,6 @@ import android.content.ContentProvider;
import
android.content.ContentValues
;
import
android.content.ContentValues
;
import
android.content.Context
;
import
android.content.Context
;
import
android.content.pm.ProviderInfo
;
import
android.content.pm.ProviderInfo
;
import
android.content.res.XmlResourceParser
;
import
android.database.Cursor
;
import
android.database.Cursor
;
import
android.database.MatrixCursor
;
import
android.database.MatrixCursor
;
import
android.net.Uri
;
import
android.net.Uri
;
...
@@ -16,19 +15,12 @@ import android.provider.OpenableColumns;
...
@@ -16,19 +15,12 @@ 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
java.io.File
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
import
static
org
.
xmlpull
.
v1
.
XmlPullParser
.
END_DOCUMENT
;
import
static
org
.
xmlpull
.
v1
.
XmlPullParser
.
START_TAG
;
/**
/**
* Modified from androidx.core.content.FileProvider
* Modified from androidx.core.content.FileProvider
*/
*/
...
@@ -36,17 +28,6 @@ public class FileProvider extends ContentProvider {
...
@@ -36,17 +28,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
TAG_ROOT_PATH
=
"root-path"
;
private
static
final
String
TAG_FILES_PATH
=
"files-path"
;
private
static
final
String
TAG_CACHE_PATH
=
"cache-path"
;
private
static
final
String
TAG_EXTERNAL
=
"external-path"
;
private
static
final
String
TAG_EXTERNAL_FILES
=
"external-files-path"
;
private
static
final
String
TAG_EXTERNAL_CACHE
=
"external-cache-path"
;
private
static
final
String
TAG_EXTERNAL_MEDIA
=
"external-media-path"
;
private
static
final
String
ATTR_NAME
=
"name"
;
private
static
final
String
ATTR_PATH
=
"path"
;
private
static
final
File
DEVICE_ROOT
=
new
File
(
"/"
);
private
static
final
File
DEVICE_ROOT
=
new
File
(
"/"
);
private
static
HashMap
<
String
,
PathStrategy
>
sCache
=
new
HashMap
<>();
private
static
HashMap
<
String
,
PathStrategy
>
sCache
=
new
HashMap
<>();
...
@@ -171,63 +152,36 @@ public class FileProvider extends ContentProvider {
...
@@ -171,63 +152,36 @@ public class FileProvider extends ContentProvider {
synchronized
(
sCache
)
{
synchronized
(
sCache
)
{
strat
=
sCache
.
get
(
authority
);
strat
=
sCache
.
get
(
authority
);
if
(
strat
==
null
)
{
if
(
strat
==
null
)
{
try
{
strat
=
createPathStrategy
(
context
,
authority
);
strat
=
parsePathStrategy
(
context
,
authority
);
}
catch
(
IOException
e
)
{
throw
new
IllegalArgumentException
(
"Failed to parse xml"
,
e
);
}
catch
(
XmlPullParserException
e
)
{
throw
new
IllegalArgumentException
(
"Failed to parse xml"
,
e
);
}
sCache
.
put
(
authority
,
strat
);
sCache
.
put
(
authority
,
strat
);
}
}
}
}
return
strat
;
return
strat
;
}
}
private
static
PathStrategy
parsePathStrategy
(
Context
context
,
String
authority
)
private
static
PathStrategy
createPathStrategy
(
Context
context
,
String
authority
)
{
throws
IOException
,
XmlPullParserException
{
final
SimplePathStrategy
strat
=
new
SimplePathStrategy
(
authority
);
final
SimplePathStrategy
strat
=
new
SimplePathStrategy
(
authority
);
final
XmlResourceParser
in
=
context
.
getResources
().
getXml
(
R
.
xml
.
file_paths
);
strat
.
addRoot
(
"root_files"
,
buildPath
(
DEVICE_ROOT
,
"."
));
strat
.
addRoot
(
"internal_files"
,
buildPath
(
context
.
getFilesDir
(),
"."
));
int
type
;
strat
.
addRoot
(
"cache_files"
,
buildPath
(
context
.
getCacheDir
(),
"."
));
while
((
type
=
in
.
next
())
!=
END_DOCUMENT
)
{
strat
.
addRoot
(
"external_files"
,
buildPath
(
Environment
.
getExternalStorageDirectory
(),
"."
));
if
(
type
==
START_TAG
)
{
{
final
String
tag
=
in
.
getName
();
File
[]
externalFilesDirs
=
getExternalFilesDirs
(
context
,
null
);
if
(
externalFilesDirs
.
length
>
0
)
{
final
String
name
=
in
.
getAttributeValue
(
null
,
ATTR_NAME
);
strat
.
addRoot
(
"external_file_files"
,
buildPath
(
externalFilesDirs
[
0
],
"."
));
String
path
=
in
.
getAttributeValue
(
null
,
ATTR_PATH
);
}
}
File
target
=
null
;
{
if
(
TAG_ROOT_PATH
.
equals
(
tag
))
{
File
[]
externalCacheDirs
=
getExternalCacheDirs
(
context
);
target
=
DEVICE_ROOT
;
if
(
externalCacheDirs
.
length
>
0
)
{
}
else
if
(
TAG_FILES_PATH
.
equals
(
tag
))
{
strat
.
addRoot
(
"external_cache_files"
,
buildPath
(
externalCacheDirs
[
0
],
"."
));
target
=
context
.
getFilesDir
();
}
}
else
if
(
TAG_CACHE_PATH
.
equals
(
tag
))
{
}
target
=
context
.
getCacheDir
();
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
LOLLIPOP
)
{
}
else
if
(
TAG_EXTERNAL
.
equals
(
tag
))
{
File
[]
externalMediaDirs
=
context
.
getExternalMediaDirs
();
target
=
Environment
.
getExternalStorageDirectory
();
if
(
externalMediaDirs
.
length
>
0
)
{
}
else
if
(
TAG_EXTERNAL_FILES
.
equals
(
tag
))
{
strat
.
addRoot
(
"external_media_files"
,
buildPath
(
externalMediaDirs
[
0
],
"."
));
File
[]
externalFilesDirs
=
getExternalFilesDirs
(
context
,
null
);
if
(
externalFilesDirs
.
length
>
0
)
{
target
=
externalFilesDirs
[
0
];
}
}
else
if
(
TAG_EXTERNAL_CACHE
.
equals
(
tag
))
{
File
[]
externalCacheDirs
=
getExternalCacheDirs
(
context
);
if
(
externalCacheDirs
.
length
>
0
)
{
target
=
externalCacheDirs
[
0
];
}
}
else
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
LOLLIPOP
&&
TAG_EXTERNAL_MEDIA
.
equals
(
tag
))
{
File
[]
externalMediaDirs
=
context
.
getExternalMediaDirs
();
if
(
externalMediaDirs
.
length
>
0
)
{
target
=
externalMediaDirs
[
0
];
}
}
if
(
target
!=
null
)
{
strat
.
addRoot
(
name
,
buildPath
(
target
,
path
));
}
}
}
}
}
...
...
shared/src/main/res/xml/file_paths.xml
deleted
100644 → 0
View file @
ef9d077c
<?xml version="1.0" encoding="utf-8"?>
<paths>
<files-path
name=
"internal_files"
path=
"."
/>
<cache-path
name=
"cache_files"
path=
"."
/>
<external-path
name=
"external_files"
path=
"."
/>
<external-cache-path
name=
"external_cache_files"
path=
"."
/>
<external-files-path
name=
"private_external_files"
path=
"."
/>
</paths>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment