Skip to content

Commit

Permalink
add debug view for pending downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
moving-bits committed May 1, 2021
1 parent 8589260 commit 5455828
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 0 deletions.
1 change: 1 addition & 0 deletions main/res/values/preference_keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@
<string translatable="false" name="pref_ec_icons">ec_icons</string>
<string translatable="false" name="pref_memory_dump">memory_dump</string>
<string translatable="false" name="pref_generate_logcat">generate_logcat</string>
<string translatable="false" name="pref_generate_infos_downloadmanager">generate_infos_downloadmanager</string>
<string translatable="false" name="pref_view_settings">view_settings</string>
<string translatable="false" name="pref_appearance">pref_appearance</string>
<string translatable="false" name="pref_changelog_last_checksum">changelog_last_checksum</string>
Expand Down
1 change: 1 addition & 0 deletions main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@
<string name="about_system_write_logcat_type_extended">Extended</string>
<string name="about_system_write_logcat_success">Logfile \"%1$s\" written to folder \"%2$s\"</string>
<string name="about_system_write_logcat_error">Error writing logfile</string>
<string name="about_system_write_infos_downloadmanager">View downloads</string>
<string name="changelog_github">List of all changes</string>
<string name="about_nutshellmanual">Online manual</string>

Expand Down
4 changes: 4 additions & 0 deletions main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,10 @@
android:key="@string/pref_memory_dump"
android:title="@string/init_create_memory_dump"
android:layout="@layout/preference_button" />
<Preference
android:key="@string/pref_generate_infos_downloadmanager"
android:title="@string/about_system_write_infos_downloadmanager"
android:layout="@layout/preference_button" />
<Preference
android:key="@string/pref_view_settings"
android:title="@string/view_settings"
Expand Down
4 changes: 4 additions & 0 deletions main/src/cgeo/geocaching/settings/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,10 @@ private void initMaintenanceButtons() {
DebugUtils.createLogcat(SettingsActivity.this);
return true;
});
getPreference(R.string.pref_generate_infos_downloadmanager).setOnPreferenceClickListener(preference -> {
DebugUtils.dumpDownloadmanagerInfos(SettingsActivity.this);
return true;
});
getPreference(R.string.pref_view_settings).setOnPreferenceClickListener(preference -> {
startActivity(new Intent(this, ViewSettingsActivity.class));
return true;
Expand Down
82 changes: 82 additions & 0 deletions main/src/cgeo/geocaching/utils/DebugUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import cgeo.geocaching.ui.dialog.Dialogs;

import android.app.Activity;
import android.app.DownloadManager;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
Expand Down Expand Up @@ -87,6 +89,86 @@ public static void createLogcat(@NonNull final Activity activity) {
}
}

public static void dumpDownloadmanagerInfos(@NonNull final Activity activity) {
final DownloadManager downloadManager = (DownloadManager) activity.getSystemService(Context.DOWNLOAD_SERVICE);
final DownloadManager.Query query = new DownloadManager.Query();
final StringBuilder sb = new StringBuilder();
try (Cursor c = downloadManager.query(query)) {
final int columnStatus = c.getColumnIndex(DownloadManager.COLUMN_STATUS);
final int columnReason = c.getColumnIndex(DownloadManager.COLUMN_REASON);
final int[] columns = {
c.getColumnIndex(DownloadManager.COLUMN_ID),
c.getColumnIndex(DownloadManager.COLUMN_TITLE),
columnStatus,
columnReason,
c.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR),
c.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES),
c.getColumnIndex(DownloadManager.COLUMN_LAST_MODIFIED_TIMESTAMP),
c.getColumnIndex(DownloadManager.COLUMN_MEDIA_TYPE),
c.getColumnIndex(DownloadManager.COLUMN_URI),
c.getColumnIndex(DownloadManager.COLUMN_MEDIAPROVIDER_URI),
c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI)
};
while (c.moveToNext()) {
for (int column : columns) {
sb.append(c.getColumnName(column)).append(" = ");
if (column == columnStatus) {
sb.append(c.getString(column));
final int status = c.getInt(column);
if (status == DownloadManager.STATUS_FAILED) {
sb.append(" - download has failed (and will not be retried)");
} else if (status == DownloadManager.STATUS_PAUSED) {
sb.append(" - download is waiting to retry or resume");
} else if (status == DownloadManager.STATUS_PENDING) {
sb.append(" - download is waiting to start");
} else if (status == DownloadManager.STATUS_RUNNING) {
sb.append(" - download is currently running");
} else if (status == DownloadManager.STATUS_SUCCESSFUL) {
sb.append(" - download has successfully completed");
}
} else if (column == columnReason) {
final int reason = c.getInt(column);
sb.append(reason);
if (reason == DownloadManager.PAUSED_QUEUED_FOR_WIFI) {
sb.append(" - paused: download exceeds a size limit for downloads over mobile network / waiting for Wifi");
} else if (reason == DownloadManager.PAUSED_UNKNOWN) {
sb.append(" - paused: for some other reason");
} else if (reason == DownloadManager.PAUSED_WAITING_FOR_NETWORK) {
sb.append(" - paused: waiting for network connectivity to proceed");
} else if (reason == DownloadManager.PAUSED_WAITING_TO_RETRY) {
sb.append(" - paused: some network error occurred and the download manager is waiting before retrying the request");
} else if (reason == DownloadManager.ERROR_CANNOT_RESUME) {
sb.append(" - error: some possibly transient error occurred but we can't resume the download");
} else if (reason == DownloadManager.ERROR_DEVICE_NOT_FOUND) {
sb.append(" - error: no external storage device was found. SD card mounted?");
} else if (reason == DownloadManager.ERROR_FILE_ALREADY_EXISTS) {
sb.append(" - error: requested destination file already exists, will not be overwritten");
} else if (reason == DownloadManager.ERROR_FILE_ERROR) {
sb.append(" - error: unknown storage issue");
} else if (reason == DownloadManager.ERROR_HTTP_DATA_ERROR) {
sb.append(" - error: HTTP processing error at data level");
} else if (reason == DownloadManager.ERROR_INSUFFICIENT_SPACE) {
sb.append(" - error: insufficient storage space");
} else if (reason == DownloadManager.ERROR_TOO_MANY_REDIRECTS) {
sb.append(" - error: too many redirects");
} else if (reason == DownloadManager.ERROR_UNHANDLED_HTTP_CODE) {
sb.append(" - error: unhandled HTTP cod");
} else if (reason == DownloadManager.ERROR_UNKNOWN) {
sb.append(" - error: unknown error");
}

} else {
sb.append(c.getString(column));
}
sb.append("\n");
}
sb.append("\n------------------------\n\n");
}
}
Dialogs.message(activity, "current downloads", sb.toString());
}


private static void createLogcatHelper(@NonNull final Activity activity, final boolean fullInfo, final boolean forceEmail, final String additionalMessage) {
final AtomicReference<Uri> result = new AtomicReference(null);

Expand Down

0 comments on commit 5455828

Please sign in to comment.