diff --git a/app/src/main/java/org/kiwix/kiwixmobile/KiwixMobileActivity.java b/app/src/main/java/org/kiwix/kiwixmobile/KiwixMobileActivity.java index 7311b28d8..84cdff87d 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/KiwixMobileActivity.java +++ b/app/src/main/java/org/kiwix/kiwixmobile/KiwixMobileActivity.java @@ -1414,9 +1414,9 @@ public class KiwixMobileActivity extends BaseActivity implements WebViewCallback } } if (file == null) { + Log.i(TAG_KIWIX, "Could not find file"); return; } - finish(); Intent zimFile = new Intent(KiwixMobileActivity.this, KiwixMobileActivity.class); zimFile.setData(uri); @@ -1428,6 +1428,8 @@ public class KiwixMobileActivity extends BaseActivity implements WebViewCallback String title = data.getStringExtra(TAG_FILE_SEARCHED).replace("", "").replace("", ""); searchForTitle(title); + } else { //TODO: Inform the User + Log.w(TAG_KIWIX, "Unhandled search failure"); } break; case REQUEST_PREFERENCES: diff --git a/app/src/main/java/org/kiwix/kiwixmobile/downloader/DownloadService.java b/app/src/main/java/org/kiwix/kiwixmobile/downloader/DownloadService.java index 4d986fffa..d44b6eff7 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/downloader/DownloadService.java +++ b/app/src/main/java/org/kiwix/kiwixmobile/downloader/DownloadService.java @@ -118,10 +118,12 @@ public class DownloadService extends Service { } if (intent.hasExtra(NOTIFICATION_ID) && (intent.getAction().equals(ACTION_PAUSE))) { if (KiwixMobileActivity.wifiOnly && !NetworkUtils.isWiFi(getApplicationContext())) { + Log.i("kiwixdownloadservice", "Not connected to WiFi, and wifiOnly is enabled"); startActivity(new Intent(this, ZimManageActivity.class).setAction(ACTION_NO_WIFI).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); this.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); - } else + } else { toggleDownload(intent.getIntExtra(NOTIFICATION_ID, 0)); + } return START_NOT_STICKY; } @@ -132,6 +134,8 @@ public class DownloadService extends Service { KIWIX_ROOT = checkWritable(KIWIX_ROOT); + Log.i("kiwixdownloadservice", "Using Kiwix Root: " + KIWIX_ROOT); + notificationTitle = intent.getExtras().getString(DownloadIntent.DOWNLOAD_ZIM_TITLE); LibraryNetworkEntity.Book book = (LibraryNetworkEntity.Book) intent.getSerializableExtra("Book"); int notificationID = book.getId().hashCode(); @@ -176,6 +180,7 @@ public class DownloadService extends Service { } public void stopDownload(int notificationID) { + Log.i("kiwixdownloadservice", "Stopping ZIM Download"); downloadStatus.put(notificationID, CANCEL); synchronized (pauseLock) { pauseLock.notify(); @@ -218,6 +223,7 @@ public class DownloadService extends Service { } public void pauseDownload(int notificationID) { + Log.i("kiwixdownloadservice", "Pausing ZIM Download"); downloadStatus.put(notificationID, PAUSE); notification.get(notificationID).mActions.get(0).title = getString(R.string.download_play); notification.get(notificationID).mActions.get(0).icon = R.drawable.ic_play_arrow_black_24dp; @@ -230,6 +236,7 @@ public class DownloadService extends Service { } public boolean playDownload(int notificationID) { + Log.i("kiwixdownloadservice", "Starting ZIM Download"); downloadStatus.put(notificationID, PLAY); synchronized (pauseLock) { pauseLock.notify(); @@ -259,7 +266,8 @@ public class DownloadService extends Service { updateDownloadFragmentProgress(initial, notificationID); notificationManager.notify(notificationID, notification.get(notificationID).build()); } - kiwixService.getMetaLinks(url).retryWhen(errors -> errors.flatMap(error -> Observable.timer(5, TimeUnit.SECONDS))) + kiwixService.getMetaLinks(url) + .retryWhen(errors -> errors.flatMap(error -> Observable.timer(5, TimeUnit.SECONDS))) .subscribeOn(AndroidSchedulers.mainThread()) .flatMap(metaLink -> getMetaLinkContentLength(metaLink.getRelevantUrl().getValue())) .flatMap(pair -> Observable.from(ChunkUtils.getChunks(pair.first, pair.second, notificationID))) @@ -288,7 +296,7 @@ public class DownloadService extends Service { notificationManager.notify(notificationID, notification.get(notificationID).build()); if (progress == 0 || progress == 100) { // Tells android to not kill the service - updateForeground(); + updateForeground(); } updateDownloadFragmentProgress(progress, notificationID); if (progress == 100) { @@ -404,6 +412,8 @@ public class DownloadService extends Service { input = response.body().source(); + Log.d("kiwixdownloadservice", "Got valid chunk"); + long lastTime = System.currentTimeMillis(); long lastSize = 0; @@ -414,8 +424,9 @@ public class DownloadService extends Service { break; } - if (KiwixMobileActivity.wifiOnly && !NetworkUtils.isWiFi(getApplicationContext())) + if (KiwixMobileActivity.wifiOnly && !NetworkUtils.isWiFi(getApplicationContext())) { pauseDownload(chunk.getNotificationID()); + } if (downloadStatus.get(chunk.getNotificationID()) == PAUSE) { synchronized (pauseLock) { @@ -457,6 +468,7 @@ public class DownloadService extends Service { } catch (Exception e) { // Retry on network error attempts++; + Log.d("kiwixdownloadservice", "Download Attempt Failed [" + attempts + "] times", e); try { Thread.sleep(1000 * attempts); // The more unsuccessful attempts the longer the wait } catch (InterruptedException ex) { @@ -469,6 +481,7 @@ public class DownloadService extends Service { } // If download is canceled clean up else remove .part from file name if (downloadStatus.get(chunk.getNotificationID()) == CANCEL) { + Log.i("kiwixdownloadservice", "Download Cancelled, deleting .part file"); String path = file.getPath(); if (path.substring(path.length() - 8).equals("zim.part")) { path = path.substring(0, path.length() - 5); @@ -478,6 +491,7 @@ public class DownloadService extends Service { FileUtils.deleteZimFile(path); } } else { + Log.i("kiwixdownloadservice", "Download completed, renaming file (.zim.part -> .zim)"); file.renameTo(new File(file.getPath().replace(".part", ""))); } // Mark chunk status as downloaded diff --git a/app/src/main/java/org/kiwix/kiwixmobile/utils/files/FileUtils.java b/app/src/main/java/org/kiwix/kiwixmobile/utils/files/FileUtils.java index 8ec260dce..ec16de094 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/utils/files/FileUtils.java +++ b/app/src/main/java/org/kiwix/kiwixmobile/utils/files/FileUtils.java @@ -47,6 +47,7 @@ public class FileUtils { if (path.substring(path.length() - 5).equals(".part")) { path = path.substring(0, path.length() - 5); } + Log.i("kiwix", "Deleting file: " + path); File file = new File(path); if (!file.getPath().substring(file.getPath().length() - 3).equals("zim")) { fileloop: diff --git a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/ZimManageActivity.java b/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/ZimManageActivity.java index 9d0293671..213da6a92 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/ZimManageActivity.java +++ b/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/ZimManageActivity.java @@ -16,6 +16,7 @@ import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.SearchView; import android.support.v7.widget.Toolbar; +import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -83,6 +84,7 @@ public class ZimManageActivity extends AppCompatActivity { if (DownloadService.ACTION_NO_WIFI.equals(getIntent().getAction())) { DownloadFragment.showNoWiFiWarning(this, () -> {}); + Log.i("kiwix", "No WiFi, showing warning"); } // Create the adapter that will return a fragment for each of the three @@ -114,6 +116,8 @@ public class ZimManageActivity extends AppCompatActivity { } }); + + Log.i("kiwik", "ZimManageActivity successfully bootstrapped"); } private void updateMenu(int position) {