diff options
author | Etienne Ruffieux <eruffieux@google.com> | 2021-11-16 14:11:01 +0000 |
---|---|---|
committer | Etienne Ruffieux <eruffieux@google.com> | 2021-11-17 14:55:34 +0000 |
commit | 3ac74cf14df63ad8e1b868cf10f656a1eadece56 (patch) | |
tree | 2abcf19ecac1b553cdd50894d3a61da9668d2c75 | |
parent | ef4ebcd689e287c80729a9bf32340426c22a91c5 (diff) | |
download | Bluetooth-3ac74cf14df63ad8e1b868cf10f656a1eadece56.tar.gz |
Removed hidden API call to getCanonicalUri
Replaced call to getCanonicalUri by keeping the same logic
but with non-hidden methods calls instead. Also checks for
legacy external storage.
Tag: #feature
Bug: 190438212
Test: make and manual tests
Change-Id: I66f73908c15a691c2959935678231a37a9286f2f
-rw-r--r-- | src/com/android/bluetooth/opp/BluetoothOppUtility.java | 27 |
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) { |