Merge pull request #5833 from ByteHamster/crash-fixes

Various fixes for crashes reported through Google Play
This commit is contained in:
ByteHamster 2022-04-10 18:13:56 +02:00 committed by GitHub
commit 8473c6f40e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 12 deletions

View File

@ -84,7 +84,7 @@ public class EpisodeItemListAdapter extends SelectableAdapter<EpisodeItemViewHol
}); });
holder.itemView.setOnCreateContextMenuListener(this); holder.itemView.setOnCreateContextMenuListener(this);
holder.itemView.setOnLongClickListener(v -> { holder.itemView.setOnLongClickListener(v -> {
longPressedItem = getItem(holder.getBindingAdapterPosition()); longPressedItem = item;
longPressedPosition = holder.getBindingAdapterPosition(); longPressedPosition = holder.getBindingAdapterPosition();
return false; return false;
}); });
@ -92,7 +92,7 @@ public class EpisodeItemListAdapter extends SelectableAdapter<EpisodeItemViewHol
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (e.isFromSource(InputDevice.SOURCE_MOUSE) if (e.isFromSource(InputDevice.SOURCE_MOUSE)
&& e.getButtonState() == MotionEvent.BUTTON_SECONDARY) { && e.getButtonState() == MotionEvent.BUTTON_SECONDARY) {
longPressedItem = getItem(holder.getBindingAdapterPosition()); longPressedItem = item;
longPressedPosition = holder.getBindingAdapterPosition(); longPressedPosition = holder.getBindingAdapterPosition();
return false; return false;
} }
@ -127,6 +127,7 @@ public class EpisodeItemListAdapter extends SelectableAdapter<EpisodeItemViewHol
holder.itemView.setOnClickListener(null); holder.itemView.setOnClickListener(null);
holder.itemView.setOnCreateContextMenuListener(null); holder.itemView.setOnCreateContextMenuListener(null);
holder.itemView.setOnLongClickListener(null); holder.itemView.setOnLongClickListener(null);
holder.itemView.setOnTouchListener(null);
holder.secondaryActionButton.setOnClickListener(null); holder.secondaryActionButton.setOnClickListener(null);
holder.dragHandle.setOnTouchListener(null); holder.dragHandle.setOnTouchListener(null);
holder.coverHolder.setOnTouchListener(null); holder.coverHolder.setOnTouchListener(null);

View File

@ -118,7 +118,7 @@ public class SubscriptionsRecyclerAdapter extends SelectableAdapter<Subscription
if (isFeed) { if (isFeed) {
longPressedPosition = holder.getBindingAdapterPosition(); longPressedPosition = holder.getBindingAdapterPosition();
} }
selectedItem = (NavDrawerData.DrawerItem) getItem(holder.getBindingAdapterPosition()); selectedItem = drawerItem;
} }
return false; return false;
}); });
@ -131,7 +131,7 @@ public class SubscriptionsRecyclerAdapter extends SelectableAdapter<Subscription
if (isFeed) { if (isFeed) {
longPressedPosition = holder.getBindingAdapterPosition(); longPressedPosition = holder.getBindingAdapterPosition();
} }
selectedItem = (NavDrawerData.DrawerItem) getItem(holder.getBindingAdapterPosition()); selectedItem = drawerItem;
} }
} }
} }

View File

@ -173,6 +173,8 @@ public class ItemFragment extends Fragment {
&& UsageStatistics.hasSignificantBiasTo(UsageStatistics.ACTION_STREAM)) { && UsageStatistics.hasSignificantBiasTo(UsageStatistics.ACTION_STREAM)) {
showOnDemandConfigBalloon(true); showOnDemandConfigBalloon(true);
return; return;
} else if (actionButton1 == null) {
return; // Not loaded yet
} }
actionButton1.onClick(getContext()); actionButton1.onClick(getContext());
}); });
@ -181,6 +183,8 @@ public class ItemFragment extends Fragment {
&& UsageStatistics.hasSignificantBiasTo(UsageStatistics.ACTION_DOWNLOAD)) { && UsageStatistics.hasSignificantBiasTo(UsageStatistics.ACTION_DOWNLOAD)) {
showOnDemandConfigBalloon(false); showOnDemandConfigBalloon(false);
return; return;
} else if (actionButton2 == null) {
return; // Not loaded yet
} }
actionButton2.onClick(getContext()); actionButton2.onClick(getContext());
}); });

View File

@ -18,6 +18,7 @@ import androidx.annotation.VisibleForTesting;
import androidx.core.app.ServiceCompat; import androidx.core.app.ServiceCompat;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import de.danoeh.antennapod.core.BuildConfig;
import de.danoeh.antennapod.core.R; import de.danoeh.antennapod.core.R;
import de.danoeh.antennapod.core.feed.LocalFeedUpdater; import de.danoeh.antennapod.core.feed.LocalFeedUpdater;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
@ -139,9 +140,6 @@ public class DownloadService extends Service {
} }
public static void download(Context context, boolean cleanupMedia, DownloadRequest... requests) { public static void download(Context context, boolean cleanupMedia, DownloadRequest... requests) {
if (requests.length > 100) {
throw new IllegalArgumentException("Android silently drops intent payloads that are too large");
}
ArrayList<DownloadRequest> requestsToSend = new ArrayList<>(); ArrayList<DownloadRequest> requestsToSend = new ArrayList<>();
for (DownloadRequest request : requests) { for (DownloadRequest request : requests) {
if (!isDownloadingFile(request.getSource())) { if (!isDownloadingFile(request.getSource())) {
@ -150,7 +148,15 @@ public class DownloadService extends Service {
} }
if (requestsToSend.isEmpty()) { if (requestsToSend.isEmpty()) {
return; return;
} else if (requestsToSend.size() > 100) {
if (BuildConfig.DEBUG) {
throw new IllegalArgumentException("Android silently drops intent payloads that are too large");
} else {
Log.d(TAG, "Too many download requests. Dropping some to avoid Android dropping all.");
requestsToSend = new ArrayList<>(requestsToSend.subList(0, 100));
}
} }
Intent launchIntent = new Intent(context, DownloadService.class); Intent launchIntent = new Intent(context, DownloadService.class);
launchIntent.putParcelableArrayListExtra(DownloadService.EXTRA_REQUESTS, requestsToSend); launchIntent.putParcelableArrayListExtra(DownloadService.EXTRA_REQUESTS, requestsToSend);
if (cleanupMedia) { if (cleanupMedia) {
@ -512,6 +518,9 @@ public class DownloadService extends Service {
if (isDownloadingFile(request.getSource())) { if (isDownloadingFile(request.getSource())) {
Log.d(TAG, "Skipped enqueueing request. Already running."); Log.d(TAG, "Skipped enqueueing request. Already running.");
return; return;
} else if (downloadHandleExecutor.isShutdown()) {
Log.d(TAG, "Skipped enqueueing request. Service is already shutting down.");
return;
} }
Log.d(TAG, "Add new request: " + request.getSource()); Log.d(TAG, "Add new request: " + request.getSource());
if (request.getSource().startsWith(Feed.PREFIX_LOCAL_FOLDER)) { if (request.getSource().startsWith(Feed.PREFIX_LOCAL_FOLDER)) {

View File

@ -117,7 +117,9 @@ public class DownloadServiceNotification {
continue; continue;
} }
sb.append("").append(statuses.get(i).getTitle()); sb.append("").append(statuses.get(i).getTitle());
sb.append(": ").append(statuses.get(i).getReason().getErrorString(context)); if (statuses.get(i).getReason() != null) {
sb.append(": ").append(statuses.get(i).getReason().getErrorString(context));
}
if (i != statuses.size() - 1) { if (i != statuses.size() - 1) {
sb.append("\n"); sb.append("\n");
} }
@ -134,16 +136,18 @@ public class DownloadServiceNotification {
public void updateReport(List<DownloadStatus> reportQueue, boolean showAutoDownloadReport) { public void updateReport(List<DownloadStatus> reportQueue, boolean showAutoDownloadReport) {
// check if report should be created // check if report should be created
boolean createReport = false; boolean createReport = false;
int successfulDownloads = 0;
int failedDownloads = 0; int failedDownloads = 0;
// a download report is created if at least one download has failed // a download report is created if at least one download has failed
// (excluding failed image downloads) // (excluding failed image downloads)
for (DownloadStatus status : reportQueue) { for (DownloadStatus status : reportQueue) {
if (status == null || status.isCancelled()) {
continue;
}
if (status.isSuccessful()) { if (status.isSuccessful()) {
successfulDownloads++; createReport |= showAutoDownloadReport && !status.isInitiatedByUser()
createReport |= showAutoDownloadReport && !status.isInitiatedByUser() && status.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA; && status.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA;
} else if (!status.isCancelled()) { } else {
failedDownloads++; failedDownloads++;
createReport = true; createReport = true;
} }