synchronized void startNextDownload() { if (!isDownloading && !isPausing) { isDownloading = true; getNextDownload().first() .subscribe(download -> { if (download != null) { new DownloadTask(downloadAccessor, download, fileUtils, analytics, this, apkPath, obbPath, downloadsStoragePath, fileDownloader).startDownload(); Logger.getInstance() .d(TAG, "Download with md5 " + download.getMd5() + " started"); } else { isDownloading = false; cacheHelper.cleanCache() .subscribe(cleanedSize -> Logger.getInstance() .d(TAG, "cleaned size: " + AptoideUtils.StringU.formatBytes(cleanedSize, false)), throwable -> { CrashReport.getInstance() .log(throwable); }); } }, throwable -> throwable.printStackTrace()); } }