From 14fd1bac17cf10929fe511689abcf08b5a7f86be Mon Sep 17 00:00:00 2001 From: Roman Tsisyk Date: Sun, 22 Aug 2021 20:26:57 +0300 Subject: [PATCH] [android] Revert to original chunk downloader Android DownloadManager is unreliable. Signed-off-by: Roman Tsisyk --- android/AndroidManifest.xml | 14 -- android/jni/CMakeLists.txt | 2 - .../com/mapswithme/maps/DownloaderAdapter.cpp | 208 ------------------ .../com/mapswithme/maps/DownloaderAdapter.hpp | 48 ---- .../jni/com/mapswithme/maps/MapManager.cpp | 12 - android/multidex-config.txt | 1 - .../com/mapswithme/maps/MwmApplication.java | 12 - .../SystemDownloadCompletedReceiver.java | 25 --- .../SystemDownloadCompletedService.java | 58 ----- .../maps/downloader/DownloaderFragment.java | 16 -- .../MapDownloadCompletedProcessor.java | 109 --------- .../maps/downloader/MapDownloadManager.java | 171 -------------- .../MapDownloadProgressTracker.java | 96 -------- .../maps/downloader/MapManager.java | 8 - .../maps/downloader/OnmapDownloader.java | 4 - .../mapswithme/maps/scheduling/JobIdMap.java | 2 - .../maps/widget/placepage/PlacePageView.java | 4 - storage/CMakeLists.txt | 7 +- 18 files changed, 1 insertion(+), 796 deletions(-) delete mode 100644 android/jni/com/mapswithme/maps/DownloaderAdapter.cpp delete mode 100644 android/jni/com/mapswithme/maps/DownloaderAdapter.hpp delete mode 100644 android/src/com/mapswithme/maps/background/SystemDownloadCompletedReceiver.java delete mode 100644 android/src/com/mapswithme/maps/background/SystemDownloadCompletedService.java delete mode 100644 android/src/com/mapswithme/maps/downloader/MapDownloadCompletedProcessor.java delete mode 100644 android/src/com/mapswithme/maps/downloader/MapDownloadManager.java delete mode 100644 android/src/com/mapswithme/maps/downloader/MapDownloadProgressTracker.java diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index f5e5fa7939..c2f1d34967 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -325,20 +325,6 @@ android:permission="android.permission.BIND_JOB_SERVICE" android:exported="false"/> - - - - - - - - - diff --git a/android/jni/CMakeLists.txt b/android/jni/CMakeLists.txt index 0a2963dee2..1b1bd2f5d4 100644 --- a/android/jni/CMakeLists.txt +++ b/android/jni/CMakeLists.txt @@ -26,7 +26,6 @@ set( com/mapswithme/core/logging.hpp com/mapswithme/core/ScopedEnv.hpp com/mapswithme/core/ScopedLocalRef.hpp - com/mapswithme/maps/DownloaderAdapter.hpp com/mapswithme/maps/Framework.hpp com/mapswithme/maps/SearchEngine.hpp com/mapswithme/opengl/android_gl_utils.hpp @@ -43,7 +42,6 @@ set( com/mapswithme/core/logging.cpp com/mapswithme/maps/bookmarks/data/BookmarkManager.cpp com/mapswithme/maps/DisplayedCategories.cpp - com/mapswithme/maps/DownloaderAdapter.cpp com/mapswithme/maps/DownloadResourcesLegacyActivity.cpp com/mapswithme/maps/editor/Editor.cpp com/mapswithme/maps/editor/OpeningHours.cpp diff --git a/android/jni/com/mapswithme/maps/DownloaderAdapter.cpp b/android/jni/com/mapswithme/maps/DownloaderAdapter.cpp deleted file mode 100644 index f5a720b5c3..0000000000 --- a/android/jni/com/mapswithme/maps/DownloaderAdapter.cpp +++ /dev/null @@ -1,208 +0,0 @@ -#include "com/mapswithme/maps/DownloaderAdapter.hpp" - -#include "com/mapswithme/core/jni_helper.hpp" -#include "com/mapswithme/platform/Platform.hpp" - -#include "storage/downloader.hpp" - -#include "base/assert.hpp" -#include "base/file_name_utils.hpp" -#include "base/string_utils.hpp" - -#include -#include -#include - -using Callbacks = std::pair, - std::function>; -static std::unordered_map g_completionHandlers; - -namespace storage -{ -BackgroundDownloaderAdapter::BackgroundDownloaderAdapter() -{ - auto env = jni::GetEnv(); - auto downloadManagerClazz = jni::GetGlobalClassRef(env, "com/mapswithme/maps/downloader/MapDownloadManager"); - auto from = jni::GetStaticMethodID(env, downloadManagerClazz, "from", - "(Landroid/content/Context;)Lcom/mapswithme/maps/downloader/MapDownloadManager;"); - - auto context = android::Platform::Instance().GetContext(); - m_downloadManager = jni::make_global_ref(env->CallStaticObjectMethod(downloadManagerClazz, from, context)); - m_downloadManagerRemove = env->GetMethodID(downloadManagerClazz, "remove","(J)V"); - m_downloadManagerEnqueue = env->GetMethodID(downloadManagerClazz, "enqueue", "(Ljava/lang/String;)J"); - jni::HandleJavaException(env); -} - -BackgroundDownloaderAdapter::~BackgroundDownloaderAdapter() -{ - CHECK_THREAD_CHECKER(m_threadChecker, ()); - - g_completionHandlers.clear(); -} - -void BackgroundDownloaderAdapter::Remove(CountryId const & countryId) -{ - CHECK_THREAD_CHECKER(m_threadChecker, ()); - - MapFilesDownloader::Remove(countryId); - - if (!m_queue.Contains(countryId)) - return; - - auto const id = m_queue.GetTaskInfoForCountryId(countryId); - if (id) - { - RemoveByRequestId(*id); - g_completionHandlers.erase(*id); - } - m_queue.Remove(countryId); -} - -void BackgroundDownloaderAdapter::Clear() -{ - CHECK_THREAD_CHECKER(m_threadChecker, ()); - - MapFilesDownloader::Clear(); - - m_queue.ForEachTaskInfo([this](auto const id) - { - RemoveByRequestId(id); - g_completionHandlers.erase(id); - }); - - m_queue.Clear(); -} - -QueueInterface const & BackgroundDownloaderAdapter::GetQueue() const -{ - CHECK_THREAD_CHECKER(m_threadChecker, ()); - - if (m_queue.IsEmpty()) - return MapFilesDownloader::GetQueue(); - - return m_queue; -} - -void BackgroundDownloaderAdapter::Download(QueuedCountry && queuedCountry) -{ - CHECK_THREAD_CHECKER(m_threadChecker, ()); - - if (!IsDownloadingAllowed()) - { - queuedCountry.OnDownloadFinished(downloader::DownloadStatus::Failed); - return; - } - - auto const countryId = queuedCountry.GetCountryId(); - auto urls = MakeUrlList(queuedCountry.GetRelativeUrl()); - // Get urls order from worst to best. - std::reverse(urls.begin(), urls.end()); - auto const path = queuedCountry.GetFileDownloadPath(); - - // For safety reasons, add to the queue first and notify start downloading then, - // to avoid possible recursion. - m_queue.Append(QueuedCountry(queuedCountry)); - - queuedCountry.OnStartDownloading(); - - DownloadFromLastUrl(countryId, path, std::move(urls)); -} - -void BackgroundDownloaderAdapter::DownloadFromLastUrl(CountryId const & countryId, - std::string const & downloadPath, - std::vector && urls) -{ - CHECK_THREAD_CHECKER(m_threadChecker, ()); - if (urls.empty()) - return; - - auto env = jni::GetEnv(); - - jni::TScopedLocalRef url(env, jni::ToJavaString(env, urls.back())); - auto id = static_cast(env->CallLongMethod(*m_downloadManager, m_downloadManagerEnqueue, url.get())); - urls.pop_back(); - - jni::HandleJavaException(env); - - m_queue.SetTaskInfoForCountryId(countryId, id); - - auto onFinish = [this, countryId, downloadPath, urls = std::move(urls)](bool status) mutable - { - CHECK_THREAD_CHECKER(m_threadChecker, ()); - - if (!m_queue.Contains(countryId)) - return; - - if (!status && !urls.empty()) - { - DownloadFromLastUrl(countryId, downloadPath, std::move(urls)); - } - else - { - auto const country = m_queue.GetCountryById(countryId); - m_queue.Remove(countryId); - country.OnDownloadFinished(status - ? downloader::DownloadStatus::Completed - : downloader::DownloadStatus::Failed); - } - }; - - auto onProgress = [this, countryId](int64_t bytesDownloaded, int64_t bytesTotal) - { - CHECK_THREAD_CHECKER(m_threadChecker, ()); - - if (!m_queue.Contains(countryId)) - return; - - auto const & country = m_queue.GetCountryById(countryId); - country.OnDownloadProgress({bytesDownloaded, bytesTotal}); - }; - - g_completionHandlers.emplace(id, Callbacks(onFinish, onProgress)); -} - -void BackgroundDownloaderAdapter::RemoveByRequestId(int64_t id) -{ - auto env = jni::GetEnv(); - env->CallVoidMethod(*m_downloadManager, m_downloadManagerRemove, static_cast(id)); - - jni::HandleJavaException(env); -} - -std::unique_ptr GetDownloader() -{ - return std::make_unique(); -} -} // namespace storage - -extern "C" { -JNIEXPORT void JNICALL -Java_com_mapswithme_maps_downloader_MapManager_nativeOnDownloadFinished(JNIEnv *, jclass, - jboolean status, jlong id) -{ - auto const it = g_completionHandlers.find(static_cast(id)); - if (it == g_completionHandlers.end()) - return; - - it->second.first(static_cast(status)); -} - -JNIEXPORT void JNICALL -Java_com_mapswithme_maps_downloader_MapManager_nativeOnDownloadProgress(JNIEnv *, jclass, jlong id, - jlong bytesDownloaded, - jlong bytesTotal) -{ - auto const it = g_completionHandlers.find(static_cast(id)); - if (it == g_completionHandlers.end()) - return; - - it->second.second(static_cast(bytesDownloaded), static_cast(bytesTotal)); -} - -JNIEXPORT jboolean JNICALL -Java_com_mapswithme_maps_downloader_MapManager_nativeHasPendingDownloads(JNIEnv *, jclass) -{ - return !g_completionHandlers.empty(); -} - -} // extern "C" diff --git a/android/jni/com/mapswithme/maps/DownloaderAdapter.hpp b/android/jni/com/mapswithme/maps/DownloaderAdapter.hpp deleted file mode 100644 index b7772546ab..0000000000 --- a/android/jni/com/mapswithme/maps/DownloaderAdapter.hpp +++ /dev/null @@ -1,48 +0,0 @@ -#pragma once - -#include "storage/background_downloading/downloader_queue.hpp" -#include "storage/storage_defines.hpp" -#include "storage/map_files_downloader_with_ping.hpp" - -#include "base/thread_checker.hpp" - -#include - -#include -#include -#include - -namespace storage -{ -class BackgroundDownloaderAdapter : public MapFilesDownloaderWithPing -{ -public: - BackgroundDownloaderAdapter(); - ~BackgroundDownloaderAdapter(); - - // MapFilesDownloader overrides: - void Remove(CountryId const & countryId) override; - - void Clear() override; - - QueueInterface const & GetQueue() const override; - -private: - // MapFilesDownloaderWithServerList overrides: - void Download(QueuedCountry && queuedCountry) override; - - // Trying to download mwm from different servers recursively. - void DownloadFromLastUrl(CountryId const & countryId, std::string const & downloadPath, - std::vector && urls); - - void RemoveByRequestId(int64_t id); - - BackgroundDownloaderQueue m_queue; - - jmethodID m_downloadManagerRemove = nullptr; - jmethodID m_downloadManagerEnqueue = nullptr; - std::shared_ptr m_downloadManager; - - DECLARE_THREAD_CHECKER(m_threadChecker); -}; -} // namespace storage diff --git a/android/jni/com/mapswithme/maps/MapManager.cpp b/android/jni/com/mapswithme/maps/MapManager.cpp index ea85046313..068af595ed 100644 --- a/android/jni/com/mapswithme/maps/MapManager.cpp +++ b/android/jni/com/mapswithme/maps/MapManager.cpp @@ -576,16 +576,4 @@ Java_com_mapswithme_maps_downloader_MapManager_nativeGetSelectedCountry(JNIEnv * storage::CountryId const & res = g_framework->GetPlacePageInfo().GetCountryId(); return (res == storage::kInvalidCountryId ? nullptr : jni::ToJavaString(env, res)); } - -JNIEXPORT jboolean JNICALL -Java_com_mapswithme_maps_downloader_MapManager_nativeIsUrlSupported(JNIEnv * env, jclass, jstring url) -{ - return static_cast(downloader::IsUrlSupported(jni::ToNativeString(env, url))); -} - -JNIEXPORT jstring JNICALL -Java_com_mapswithme_maps_downloader_MapManager_nativeGetFilePathByUrl(JNIEnv * env, jclass, jstring url) -{ - return jni::ToJavaString(env, downloader::GetFilePathByUrl(jni::ToNativeString(env, url))); -} } // extern "C" diff --git a/android/multidex-config.txt b/android/multidex-config.txt index c0ff101900..e5798526ec 100644 --- a/android/multidex-config.txt +++ b/android/multidex-config.txt @@ -4,7 +4,6 @@ com/mapswithme/maps/bookmarks/data/Bookmark.class com/mapswithme/maps/bookmarks/data/ElevationInfo.class com/mapswithme/maps/bookmarks/data/FeatureId.class com/mapswithme/maps/bookmarks/data/MapObject.class -com/mapswithme/maps/downloader/MapDownloadManager.class com/mapswithme/maps/location/PlatformSocket.class com/mapswithme/maps/search/PopularityProvider.class com/mapswithme/maps/widget/placepage/PlacePageData.class diff --git a/android/src/com/mapswithme/maps/MwmApplication.java b/android/src/com/mapswithme/maps/MwmApplication.java index 8124afb3d9..ea2bfdd82a 100644 --- a/android/src/com/mapswithme/maps/MwmApplication.java +++ b/android/src/com/mapswithme/maps/MwmApplication.java @@ -17,7 +17,6 @@ import com.mapswithme.maps.background.Notifier; import com.mapswithme.maps.base.MediaPlayerWrapper; import com.mapswithme.maps.bookmarks.data.BookmarkManager; import com.mapswithme.maps.downloader.CountryItem; -import com.mapswithme.maps.downloader.MapDownloadManager; import com.mapswithme.maps.downloader.MapManager; import com.mapswithme.maps.editor.Editor; import com.mapswithme.maps.location.LocationHelper; @@ -59,10 +58,6 @@ public class MwmApplication extends Application implements AppBackgroundTracker. @NonNull private IsolinesManager mIsolinesManager; - @SuppressWarnings("NotNullFieldNotInitialized") - @NonNull - private MapDownloadManager mMapDownloadManager; - private volatile boolean mFrameworkInitialized; private volatile boolean mPlatformInitialized; @@ -148,7 +143,6 @@ public class MwmApplication extends Application implements AppBackgroundTracker. mBackgroundTracker = new AppBackgroundTracker(this); mSubwayManager = new SubwayManager(this); mIsolinesManager = new IsolinesManager(this); - mMapDownloadManager = new MapDownloadManager(this); mPlayer = new MediaPlayerWrapper(this); WebView.setWebContentsDebuggingEnabled(Utils.isDebugOrBeta()); @@ -323,12 +317,6 @@ public class MwmApplication extends Application implements AppBackgroundTracker. nativeOnTransit(foreground); } - @NonNull - public MapDownloadManager getMapDownloadManager() - { - return mMapDownloadManager; - } - private class StorageCallbackImpl implements MapManager.StorageCallback { @Override diff --git a/android/src/com/mapswithme/maps/background/SystemDownloadCompletedReceiver.java b/android/src/com/mapswithme/maps/background/SystemDownloadCompletedReceiver.java deleted file mode 100644 index 3a61192047..0000000000 --- a/android/src/com/mapswithme/maps/background/SystemDownloadCompletedReceiver.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.mapswithme.maps.background; - -import android.app.DownloadManager; -import android.content.Context; -import android.content.Intent; -import androidx.annotation.NonNull; -import androidx.core.app.JobIntentService; - -import com.mapswithme.maps.MwmBroadcastReceiver; -import com.mapswithme.maps.scheduling.JobIdMap; - -public class SystemDownloadCompletedReceiver extends MwmBroadcastReceiver -{ - @Override - public void onReceiveInitialized(@NonNull Context context, @NonNull Intent intent) - { - DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); - if (manager == null) - throw new IllegalStateException("Failed to get a download manager"); - - intent.setClass(context, SystemDownloadCompletedService.class); - int jobId = JobIdMap.getId(SystemDownloadCompletedService.class); - JobIntentService.enqueueWork(context, SystemDownloadCompletedService.class, jobId, intent); - } -} diff --git a/android/src/com/mapswithme/maps/background/SystemDownloadCompletedService.java b/android/src/com/mapswithme/maps/background/SystemDownloadCompletedService.java deleted file mode 100644 index dbe305c2b6..0000000000 --- a/android/src/com/mapswithme/maps/background/SystemDownloadCompletedService.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.mapswithme.maps.background; - -import android.app.DownloadManager; -import android.content.Context; -import android.content.Intent; -import android.database.Cursor; - -import androidx.annotation.NonNull; -import androidx.core.app.JobIntentService; -import com.mapswithme.maps.MwmApplication; -import com.mapswithme.maps.MwmJobIntentService; -import com.mapswithme.maps.downloader.MapDownloadCompletedProcessor; -import com.mapswithme.util.Utils; - -public class SystemDownloadCompletedService extends MwmJobIntentService -{ - private interface DownloadProcessor - { - boolean process(@NonNull Context context, long id, @NonNull Cursor cursor); - } - - @Override - protected void onHandleWorkInitialized(@NonNull Intent intent) - { - DownloadManager manager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); - if (manager == null) - throw new IllegalStateException("Failed to get a download manager"); - - processIntent(manager, intent); - } - - private void processIntent(@NonNull DownloadManager manager, @NonNull Intent intent) - { - Cursor cursor = null; - try - { - final long id = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0); - DownloadManager.Query query = new DownloadManager.Query().setFilterById(id); - cursor = manager.query(query); - if (!cursor.moveToFirst()) - return; - - final DownloadProcessor[] processors = { - MapDownloadCompletedProcessor::process - }; - - for (DownloadProcessor processor : processors) - { - if (processor.process(getApplicationContext(), id, cursor)) - break; - } - } - finally - { - Utils.closeSafely(cursor); - } - } -} diff --git a/android/src/com/mapswithme/maps/downloader/DownloaderFragment.java b/android/src/com/mapswithme/maps/downloader/DownloaderFragment.java index a2fb90b728..c37634d448 100644 --- a/android/src/com/mapswithme/maps/downloader/DownloaderFragment.java +++ b/android/src/com/mapswithme/maps/downloader/DownloaderFragment.java @@ -171,22 +171,6 @@ public class DownloaderFragment extends BaseMwmRecyclerFragment mRestoredRequests; - @NonNull - private MapDownloadProgressTracker mProgressTracker; - @NonNull - private String mAppName; - - public MapDownloadManager(@NonNull Context context) - { - DownloadManager downloadManager = - (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); - - if (downloadManager == null) - throw new NullPointerException("Download manager is null, failed to create MapDownloadManager"); - - mDownloadManager = downloadManager; - mProgressTracker = new MapDownloadProgressTracker(context); - mAppName = context.getString(R.string.app_name); - } - - @NonNull - private Map loadEnqueued() - { - Map result = new HashMap<>(); - DownloadManager.Query query = new DownloadManager.Query(); - query.setFilterByStatus(DownloadManager.STATUS_PENDING | DownloadManager.STATUS_RUNNING | - DownloadManager.STATUS_PAUSED | DownloadManager.STATUS_SUCCESSFUL); - Cursor cursor = null; - try - { - cursor = mDownloadManager.query(query); - - cursor.moveToFirst(); - int count = cursor.getCount(); - - for (int i = 0; i < count; ++i) - { - long id = cursor.getLong(cursor.getColumnIndex(DownloadManager.COLUMN_ID)); - String url = cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_URI)); - String urlPath = getUrlPath(url); - - if (!TextUtils.isEmpty(urlPath)) - result.put(urlPath, id); - - cursor.moveToNext(); - } - } - catch (Exception e) - { - LOGGER.e(TAG, "Failed to load enqueued requests. Exception ", e); - } - finally - { - Utils.closeSafely(cursor); - } - - return result; - } - - @Nullable - private String getUrlPath(@Nullable String url) - { - if (TextUtils.isEmpty(url)) - return null; - - String path = Uri.parse(url).getPath(); - if (TextUtils.isEmpty(path)|| !MapManager.nativeIsUrlSupported(path)) - return null; - - try - { - return URLDecoder.decode(path, "UTF-8"); - } - catch (UnsupportedEncodingException ignored) - { - return null; - } - } - - @MainThread - public long enqueue(@NonNull String url) - { - Uri uri = Uri.parse(url); - String uriPath = uri.getPath(); - if (uriPath == null) - throw new AssertionError("The path must be not null"); - - if (mRestoredRequests == null) - mRestoredRequests = loadEnqueued(); - - Long id = mRestoredRequests.get(uriPath); - long requestId = 0; - - if (id == null) - { - DownloadManager.Request request = new DownloadManager - .Request(uri) - .setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE) - .setDescription(mAppName); - - requestId = mDownloadManager.enqueue(request); - } - else - { - mRestoredRequests.remove(uriPath); - requestId = id; - } - - startProgressTracking(); - - return requestId; - } - - @MainThread - public void remove(long requestId) - { - mDownloadManager.remove(requestId); - } - - public void onDownloadFinished(boolean status, long id) - { - MapManager.nativeOnDownloadFinished(status, id); - } - - public void startProgressTracking() - { - mProgressTracker.start(); - } - - public void stopProgressTracking() - { - mProgressTracker.stop(); - } - - @NonNull - public static MapDownloadManager from(@NonNull Context context) - { - MwmApplication app = (MwmApplication) context.getApplicationContext(); - return app.getMapDownloadManager(); - } -} diff --git a/android/src/com/mapswithme/maps/downloader/MapDownloadProgressTracker.java b/android/src/com/mapswithme/maps/downloader/MapDownloadProgressTracker.java deleted file mode 100644 index b673708383..0000000000 --- a/android/src/com/mapswithme/maps/downloader/MapDownloadProgressTracker.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.mapswithme.maps.downloader; - -import android.app.DownloadManager; -import android.content.Context; -import android.database.Cursor; - -import androidx.annotation.NonNull; - -import com.mapswithme.util.Utils; -import com.mapswithme.util.concurrency.UiThread; -import com.mapswithme.util.log.Logger; -import com.mapswithme.util.log.LoggerFactory; - -public class MapDownloadProgressTracker -{ - private static final Logger LOGGER = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.DOWNLOADER); - private static final String TAG = MapDownloadProgressTracker.class.getSimpleName(); - - private static final long PROGRESS_TRACKING_INTERVAL_MILLISECONDS = 1000; - - @NonNull - private final DownloadManager mDownloadManager; - private boolean mTrackingEnabled = false; - private final Runnable mTrackingMethod = this::trackProgress; - - MapDownloadProgressTracker(@NonNull Context context) - { - DownloadManager downloadManager = - (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); - - if (downloadManager == null) - throw new NullPointerException("Download manager is null, failed to create MapDownloadManager"); - - mDownloadManager = downloadManager; - } - - public void start() - { - if (mTrackingEnabled) - return; - - mTrackingEnabled = true; - // Delayed start, because g_completionHandlers are empty until enquee() method finishes. - UiThread.runLater(mTrackingMethod, PROGRESS_TRACKING_INTERVAL_MILLISECONDS); - } - - public void stop() - { - mTrackingEnabled = false; - UiThread.cancelDelayedTasks(mTrackingMethod); - } - - private void trackProgress() - { - if (!mTrackingEnabled) - return; - - if (!MapManager.nativeHasPendingDownloads()) - { - mTrackingEnabled = false; - return; - } - - DownloadManager.Query query = new DownloadManager.Query(); - query.setFilterByStatus(DownloadManager.STATUS_RUNNING); - Cursor cursor = null; - try - { - cursor = mDownloadManager.query(query); - - cursor.moveToFirst(); - int count = cursor.getCount(); - for (int i = 0; i < count; ++i) - { - long id = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_ID)); - long bytesDownloaded = cursor.getLong(cursor.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR)); - long bytesTotal = cursor.getLong(cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES)); - - MapManager.nativeOnDownloadProgress(id, bytesDownloaded, bytesTotal); - - cursor.moveToNext(); - } - - UiThread.runLater(mTrackingMethod, PROGRESS_TRACKING_INTERVAL_MILLISECONDS); - } - catch (Exception e) - { - LOGGER.e(TAG, "Downloading progress tracking failed. Exception: " + e); - stop(); - } - finally - { - Utils.closeSafely(cursor); - } - } -} diff --git a/android/src/com/mapswithme/maps/downloader/MapManager.java b/android/src/com/mapswithme/maps/downloader/MapManager.java index 07cb84df95..5b300b6fae 100644 --- a/android/src/com/mapswithme/maps/downloader/MapManager.java +++ b/android/src/com/mapswithme/maps/downloader/MapManager.java @@ -411,12 +411,4 @@ public final class MapManager * Returns country ID which the current PP object points to, or {@code null}. */ public static native @Nullable String nativeGetSelectedCountry(); - - public static native boolean nativeIsUrlSupported(@NonNull String url); - @NonNull - public static native String nativeGetFilePathByUrl(@NonNull String url); - - public static native void nativeOnDownloadFinished(boolean status, long id); - public static native void nativeOnDownloadProgress(long id, long bytesDownloaded, long bytesTotal); - public static native boolean nativeHasPendingDownloads(); } diff --git a/android/src/com/mapswithme/maps/downloader/OnmapDownloader.java b/android/src/com/mapswithme/maps/downloader/OnmapDownloader.java index 014e48626b..ce5649614a 100644 --- a/android/src/com/mapswithme/maps/downloader/OnmapDownloader.java +++ b/android/src/com/mapswithme/maps/downloader/OnmapDownloader.java @@ -246,8 +246,6 @@ public class OnmapDownloader implements MwmActivity.LeftAnimationTrackListener mStorageSubscriptionSlot = 0; MapManager.nativeUnsubscribeOnCountryChanged(); - - MapDownloadManager.from(mActivity).stopProgressTracking(); } } @@ -258,8 +256,6 @@ public class OnmapDownloader implements MwmActivity.LeftAnimationTrackListener mStorageSubscriptionSlot = MapManager.nativeSubscribe(mStorageCallback); MapManager.nativeSubscribeOnCountryChanged(mCountryChangedListener); - - MapDownloadManager.from(mActivity).startProgressTracking(); } } diff --git a/android/src/com/mapswithme/maps/scheduling/JobIdMap.java b/android/src/com/mapswithme/maps/scheduling/JobIdMap.java index 41efffb72f..ff7369a65b 100644 --- a/android/src/com/mapswithme/maps/scheduling/JobIdMap.java +++ b/android/src/com/mapswithme/maps/scheduling/JobIdMap.java @@ -1,7 +1,6 @@ package com.mapswithme.maps.scheduling; import com.mapswithme.maps.background.OsmUploadService; -import com.mapswithme.maps.background.SystemDownloadCompletedService; import java.util.HashMap; import java.util.Map; @@ -11,7 +10,6 @@ public class JobIdMap private static final Map, Integer> MAP = new HashMap<>(); static { - MAP.put(SystemDownloadCompletedService.class, calcIdentifier(MAP.size())); MAP.put(OsmUploadService.class, calcIdentifier(MAP.size())); } diff --git a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java index 2748df674d..15009831ac 100644 --- a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java +++ b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java @@ -5,7 +5,6 @@ import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.Color; import android.location.Location; -import android.os.Build; import android.text.Html; import android.text.SpannableStringBuilder; import android.text.Spanned; @@ -47,7 +46,6 @@ import com.mapswithme.maps.bookmarks.data.Metadata; import com.mapswithme.maps.bookmarks.data.RoadWarningMarkType; import com.mapswithme.maps.downloader.CountryItem; import com.mapswithme.maps.downloader.DownloaderStatusIcon; -import com.mapswithme.maps.downloader.MapDownloadManager; import com.mapswithme.maps.downloader.MapManager; import com.mapswithme.maps.editor.Editor; import com.mapswithme.maps.editor.OpeningHours; @@ -1317,7 +1315,6 @@ public class PlacePageView extends NestedScrollViewClickFixed mCurrentCountry = map; if (mStorageCallbackSlot == 0) mStorageCallbackSlot = MapManager.nativeSubscribe(mStorageCallback); - MapDownloadManager.from(getContext()).startProgressTracking(); mDownloaderIcon.setOnIconClickListener(mDownloadClickListener) .setOnCancelClickListener(mCancelDownloadListener); @@ -1333,7 +1330,6 @@ public class PlacePageView extends NestedScrollViewClickFixed MapManager.nativeUnsubscribe(mStorageCallbackSlot); mStorageCallbackSlot = 0; - MapDownloadManager.from(getContext()).stopProgressTracking(); mCurrentCountry = null; mDownloaderIcon.setOnIconClickListener(null) .setOnCancelClickListener(null); diff --git a/storage/CMakeLists.txt b/storage/CMakeLists.txt index 5110efcc74..f1306cceb3 100644 --- a/storage/CMakeLists.txt +++ b/storage/CMakeLists.txt @@ -51,12 +51,7 @@ set( storage_helpers.hpp ) -if(${PLATFORM_ANDROID}) - append( - SRC - background_downloading/downloader_queue.hpp - ) -elseif(${PLATFORM_IPHONE}) +if(${PLATFORM_IPHONE}) append( SRC background_downloading/downloader_adapter_ios.h