summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2021-11-18 08:18:32 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2021-11-18 08:18:32 +0000
commit91510cd38488fc8efc885f4e49df712a32c5a0a1 (patch)
tree132b8acb02948af3561529cd6e321f98473b51eb
parent96fdc09881dba687586ca457d13729ed9e53b022 (diff)
parent3ac74cf14df63ad8e1b868cf10f656a1eadece56 (diff)
downloadBluetooth-91510cd38488fc8efc885f4e49df712a32c5a0a1.tar.gz
Merge "Removed hidden API call to getCanonicalUri"
-rw-r--r--src/com/android/bluetooth/opp/BluetoothOppUtility.java27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/com/android/bluetooth/opp/BluetoothOppUtility.java b/src/com/android/bluetooth/opp/BluetoothOppUtility.java
index 0b211af3c..a0a787844 100644
--- a/src/com/android/bluetooth/opp/BluetoothOppUtility.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppUtility.java
@@ -444,8 +444,31 @@ public class BluetoothOppUtility {
Log.e(TAG, "Not a file URI: " + uri);
return false;
}
- final File file = new File(uri.getCanonicalUri().getPath());
- return isSameOrSubDirectory(Environment.getExternalStorageDirectory(), file);
+
+ if ("file".equals(uri.getScheme())) {
+ String canonicalPath;
+ try {
+ canonicalPath = new File(uri.getPath()).getCanonicalPath();
+ } catch (IOException e) {
+ canonicalPath = uri.getPath();
+ }
+ File file = new File(canonicalPath);
+ //if emulated
+ if (Environment.isExternalStorageEmulated()) {
+ //Gets legacy external storage path
+ final String legacyPath = new File(
+ System.getenv("EXTERNAL_STORAGE")).toString();
+ // Splice in user-specific path when legacy path is found
+ if (canonicalPath.startsWith(legacyPath)) {
+ file = new File(
+ Environment.getExternalStorageDirectory().toString(),
+ canonicalPath.substring(legacyPath.length() + 1));
+ }
+ }
+ return isSameOrSubDirectory(Environment.getExternalStorageDirectory(), file);
+ }
+ return isSameOrSubDirectory(Environment.getExternalStorageDirectory(),
+ new File(uri.getPath()));
}
static boolean isForbiddenContent(Uri uri) {