Skip to content

Commit 0b964f0

Browse files
author
John Lines
committed
Fix/kludge issue with Send on Android 9.0
1 parent 5943a28 commit 0b964f0

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="org.paladyn.mediclog"
4-
android:versionCode="10"
5-
android:versionName="0.2.6" >
4+
android:versionCode="11"
5+
android:versionName="0.2.7" >
66

77

88
<!-- Am not currently using external storage, but being given it for compatibility

src/main/java/org/paladyn/mediclog/LocalFileProvider.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public ParcelFileDescriptor openFile(Uri uri, String mode)
5858
String LOG_TAG = CLASS_NAME + " - openFile";
5959

6060
// Log.v(LOG_TAG,"Called with uri: '" + uri + "'." + uri.getLastPathSegment());
61+
// URI always look like content://org.paladyn.mediclog.LocalFileProvider/mediclog.txt
6162

6263
// Check incoming Uri against the matcher
6364
switch (uriMatcher.match(uri)) {
@@ -76,12 +77,28 @@ public ParcelFileDescriptor openFile(Uri uri, String mode)
7677
+ uri.getLastPathSegment();
7778
// Protect against a possible Path Traversal vulnerablity by checking that the Cannonical
7879
// path starts with the right string
79-
// Log.v(LOG_TAG, "fileLocation: '" + fileLocation + "'.");
80+
// Log.v(LOG_TAG, "fileLocation: '" + fileLocation + "'.");
8081
File f;
8182
try {
8283
f = new File(fileLocation);
83-
if (!f.getCanonicalPath().startsWith(getContext().getFilesDir() + File.separator)) {
84-
Log.v(LOG_TAG, "fileLocation: " + fileLocation + "is invalid");
84+
String oldvalid = getContext().getFilesDir() + File.separator;
85+
String newvalid = "/data/data/" + getContext().getPackageName() + "/files/";
86+
Boolean ob = f.getCanonicalPath().startsWith(oldvalid);
87+
Boolean nb = f.getCanonicalPath().startsWith(newvalid);
88+
// Log.v(LOG_TAG, "oldvalid is " + oldvalid + "newvalid is " + newvalid);
89+
// if (ob) {
90+
// Log.v(LOG_TAG, "ob is true");
91+
// }
92+
// if (nb) {
93+
// Log.v(LOG_TAG, "nb is true");
94+
// }
95+
if (!( ob || nb ))
96+
{
97+
// The second case is a horrible kludge for API 28, where the path starts /data/data, as opposed to /data/user/0/
98+
99+
Log.v(LOG_TAG, "fileLocation: " + fileLocation + " is invalid");
100+
Log.v(LOG_TAG, "f.getCannonicalPath is " + f.getCanonicalPath());
101+
Log.v(LOG_TAG, "kludged path is /data/data/" + getContext().getPackageName() + "/files/");
85102
throw new IllegalArgumentException();
86103
}
87104
} catch (IOException ex) {

0 commit comments

Comments
 (0)