Added some logging

This commit is contained in:
Joseph Reeve 2017-09-21 17:13:10 +01:00 committed by Julian Harty
parent 61ec22a88b
commit 1fda455f88
4 changed files with 26 additions and 5 deletions

View File

@ -1414,9 +1414,9 @@ public class KiwixMobileActivity extends BaseActivity implements WebViewCallback
} }
} }
if (file == null) { if (file == null) {
Log.i(TAG_KIWIX, "Could not find file");
return; return;
} }
finish(); finish();
Intent zimFile = new Intent(KiwixMobileActivity.this, KiwixMobileActivity.class); Intent zimFile = new Intent(KiwixMobileActivity.this, KiwixMobileActivity.class);
zimFile.setData(uri); zimFile.setData(uri);
@ -1428,6 +1428,8 @@ public class KiwixMobileActivity extends BaseActivity implements WebViewCallback
String title = String title =
data.getStringExtra(TAG_FILE_SEARCHED).replace("<b>", "").replace("</b>", ""); data.getStringExtra(TAG_FILE_SEARCHED).replace("<b>", "").replace("</b>", "");
searchForTitle(title); searchForTitle(title);
} else { //TODO: Inform the User
Log.w(TAG_KIWIX, "Unhandled search failure");
} }
break; break;
case REQUEST_PREFERENCES: case REQUEST_PREFERENCES:

View File

@ -118,10 +118,12 @@ public class DownloadService extends Service {
} }
if (intent.hasExtra(NOTIFICATION_ID) && (intent.getAction().equals(ACTION_PAUSE))) { if (intent.hasExtra(NOTIFICATION_ID) && (intent.getAction().equals(ACTION_PAUSE))) {
if (KiwixMobileActivity.wifiOnly && !NetworkUtils.isWiFi(getApplicationContext())) { 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)); 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)); this.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
} else } else {
toggleDownload(intent.getIntExtra(NOTIFICATION_ID, 0)); toggleDownload(intent.getIntExtra(NOTIFICATION_ID, 0));
}
return START_NOT_STICKY; return START_NOT_STICKY;
} }
@ -132,6 +134,8 @@ public class DownloadService extends Service {
KIWIX_ROOT = checkWritable(KIWIX_ROOT); KIWIX_ROOT = checkWritable(KIWIX_ROOT);
Log.i("kiwixdownloadservice", "Using Kiwix Root: " + KIWIX_ROOT);
notificationTitle = intent.getExtras().getString(DownloadIntent.DOWNLOAD_ZIM_TITLE); notificationTitle = intent.getExtras().getString(DownloadIntent.DOWNLOAD_ZIM_TITLE);
LibraryNetworkEntity.Book book = (LibraryNetworkEntity.Book) intent.getSerializableExtra("Book"); LibraryNetworkEntity.Book book = (LibraryNetworkEntity.Book) intent.getSerializableExtra("Book");
int notificationID = book.getId().hashCode(); int notificationID = book.getId().hashCode();
@ -176,6 +180,7 @@ public class DownloadService extends Service {
} }
public void stopDownload(int notificationID) { public void stopDownload(int notificationID) {
Log.i("kiwixdownloadservice", "Stopping ZIM Download");
downloadStatus.put(notificationID, CANCEL); downloadStatus.put(notificationID, CANCEL);
synchronized (pauseLock) { synchronized (pauseLock) {
pauseLock.notify(); pauseLock.notify();
@ -218,6 +223,7 @@ public class DownloadService extends Service {
} }
public void pauseDownload(int notificationID) { public void pauseDownload(int notificationID) {
Log.i("kiwixdownloadservice", "Pausing ZIM Download");
downloadStatus.put(notificationID, PAUSE); downloadStatus.put(notificationID, PAUSE);
notification.get(notificationID).mActions.get(0).title = getString(R.string.download_play); 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; 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) { public boolean playDownload(int notificationID) {
Log.i("kiwixdownloadservice", "Starting ZIM Download");
downloadStatus.put(notificationID, PLAY); downloadStatus.put(notificationID, PLAY);
synchronized (pauseLock) { synchronized (pauseLock) {
pauseLock.notify(); pauseLock.notify();
@ -259,7 +266,8 @@ public class DownloadService extends Service {
updateDownloadFragmentProgress(initial, notificationID); updateDownloadFragmentProgress(initial, notificationID);
notificationManager.notify(notificationID, notification.get(notificationID).build()); 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()) .subscribeOn(AndroidSchedulers.mainThread())
.flatMap(metaLink -> getMetaLinkContentLength(metaLink.getRelevantUrl().getValue())) .flatMap(metaLink -> getMetaLinkContentLength(metaLink.getRelevantUrl().getValue()))
.flatMap(pair -> Observable.from(ChunkUtils.getChunks(pair.first, pair.second, notificationID))) .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()); notificationManager.notify(notificationID, notification.get(notificationID).build());
if (progress == 0 || progress == 100) { if (progress == 0 || progress == 100) {
// Tells android to not kill the service // Tells android to not kill the service
updateForeground(); updateForeground();
} }
updateDownloadFragmentProgress(progress, notificationID); updateDownloadFragmentProgress(progress, notificationID);
if (progress == 100) { if (progress == 100) {
@ -404,6 +412,8 @@ public class DownloadService extends Service {
input = response.body().source(); input = response.body().source();
Log.d("kiwixdownloadservice", "Got valid chunk");
long lastTime = System.currentTimeMillis(); long lastTime = System.currentTimeMillis();
long lastSize = 0; long lastSize = 0;
@ -414,8 +424,9 @@ public class DownloadService extends Service {
break; break;
} }
if (KiwixMobileActivity.wifiOnly && !NetworkUtils.isWiFi(getApplicationContext())) if (KiwixMobileActivity.wifiOnly && !NetworkUtils.isWiFi(getApplicationContext())) {
pauseDownload(chunk.getNotificationID()); pauseDownload(chunk.getNotificationID());
}
if (downloadStatus.get(chunk.getNotificationID()) == PAUSE) { if (downloadStatus.get(chunk.getNotificationID()) == PAUSE) {
synchronized (pauseLock) { synchronized (pauseLock) {
@ -457,6 +468,7 @@ public class DownloadService extends Service {
} catch (Exception e) { } catch (Exception e) {
// Retry on network error // Retry on network error
attempts++; attempts++;
Log.d("kiwixdownloadservice", "Download Attempt Failed [" + attempts + "] times", e);
try { try {
Thread.sleep(1000 * attempts); // The more unsuccessful attempts the longer the wait Thread.sleep(1000 * attempts); // The more unsuccessful attempts the longer the wait
} catch (InterruptedException ex) { } 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 download is canceled clean up else remove .part from file name
if (downloadStatus.get(chunk.getNotificationID()) == CANCEL) { if (downloadStatus.get(chunk.getNotificationID()) == CANCEL) {
Log.i("kiwixdownloadservice", "Download Cancelled, deleting .part file");
String path = file.getPath(); String path = file.getPath();
if (path.substring(path.length() - 8).equals("zim.part")) { if (path.substring(path.length() - 8).equals("zim.part")) {
path = path.substring(0, path.length() - 5); path = path.substring(0, path.length() - 5);
@ -478,6 +491,7 @@ public class DownloadService extends Service {
FileUtils.deleteZimFile(path); FileUtils.deleteZimFile(path);
} }
} else { } else {
Log.i("kiwixdownloadservice", "Download completed, renaming file (.zim.part -> .zim)");
file.renameTo(new File(file.getPath().replace(".part", ""))); file.renameTo(new File(file.getPath().replace(".part", "")));
} }
// Mark chunk status as downloaded // Mark chunk status as downloaded

View File

@ -47,6 +47,7 @@ public class FileUtils {
if (path.substring(path.length() - 5).equals(".part")) { if (path.substring(path.length() - 5).equals(".part")) {
path = path.substring(0, path.length() - 5); path = path.substring(0, path.length() - 5);
} }
Log.i("kiwix", "Deleting file: " + path);
File file = new File(path); File file = new File(path);
if (!file.getPath().substring(file.getPath().length() - 3).equals("zim")) { if (!file.getPath().substring(file.getPath().length() - 3).equals("zim")) {
fileloop: fileloop:

View File

@ -16,6 +16,7 @@ import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.SearchView; import android.support.v7.widget.SearchView;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
@ -83,6 +84,7 @@ public class ZimManageActivity extends AppCompatActivity {
if (DownloadService.ACTION_NO_WIFI.equals(getIntent().getAction())) { if (DownloadService.ACTION_NO_WIFI.equals(getIntent().getAction())) {
DownloadFragment.showNoWiFiWarning(this, () -> {}); DownloadFragment.showNoWiFiWarning(this, () -> {});
Log.i("kiwix", "No WiFi, showing warning");
} }
// Create the adapter that will return a fragment for each of the three // 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) { private void updateMenu(int position) {