From b2d8af175fdfea301b6e6a90afa933d0452a9e09 Mon Sep 17 00:00:00 2001 From: Tim Sylvester Date: Tue, 15 Oct 2024 08:04:58 -0700 Subject: [PATCH] Ensure `ReentrantLock` is unlocked after being locked, and on same thread (#2759) Cherry-pick 30f3e416f070bd9d50dcf59feaf8c1fab694ebaa --- .../mapbox/mapboxsdk/storage/FileSource.java | 39 +++---------------- 1 file changed, 6 insertions(+), 33 deletions(-) diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/storage/FileSource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/storage/FileSource.java index b58337c7152..25c6f2e6405 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/storage/FileSource.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/storage/FileSource.java @@ -195,33 +195,16 @@ public static boolean isExternalStorageReadable() { @UiThread public static void initializeFileDirsPaths(Context context) { ThreadUtils.checkThread(TAG); - lockPathLoaders(); - if (resourcesCachePath == null || internalCachePath == null) { - new FileDirsPathsTask().execute(context); - } + new FileDirsPathsTask().execute(context); } - private static class FileDirsPathsTask extends AsyncTask { - - @Override - protected void onCancelled() { - unlockPathLoaders(); - } - - @NonNull - @Override - protected String[] doInBackground(Context... contexts) { - return new String[] { - getCachePath(contexts[0]), - contexts[0].getCacheDir().getAbsolutePath() - }; - } + private static class FileDirsPathsTask extends AsyncTask { @Override - protected void onPostExecute(String[] paths) { - resourcesCachePath = paths[0]; - internalCachePath = paths[1]; - unlockPathLoaders(); + protected Void doInBackground(Context... contexts) { + getResourcesCachePath(contexts[0]); + getInternalCachePath(contexts[0]); + return null; } } @@ -358,16 +341,6 @@ private static boolean isPathWritable(String path) { return new File(path).canWrite(); } - private static void lockPathLoaders() { - internalCachePathLoaderLock.lock(); - resourcesCachePathLoaderLock.lock(); - } - - private static void unlockPathLoaders() { - resourcesCachePathLoaderLock.unlock(); - internalCachePathLoaderLock.unlock(); - } - @Keep private long nativePtr;