Skip to content

Avoid throwing in ForcedSender.sendBlocking #4293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,24 @@
import androidx.annotation.WorkerThread;
import com.google.android.datatransport.Priority;
import com.google.android.datatransport.Transport;
import com.google.android.datatransport.runtime.logging.Logging;

@Discouraged(
message =
"TransportRuntime is not a realtime delivery system, don't use unless you absolutely must.")
public final class ForcedSender {
private static final String LOG_TAG = "ForcedSender";

@SuppressLint("DiscouragedApi")
@WorkerThread
public static void sendBlocking(Transport<?> transport, Priority priority) {
@SuppressLint("DiscouragedApi")
TransportContext context = getTransportContextOrThrow(transport).withPriority(priority);
TransportRuntime.getInstance().getUploader().logAndUpdateState(context, 1);
}

private static TransportContext getTransportContextOrThrow(Transport<?> transport) {
if (transport instanceof TransportImpl) {
return ((TransportImpl<?>) transport).getTransportContext();
TransportContext context =
((TransportImpl<?>) transport).getTransportContext().withPriority(priority);
TransportRuntime.getInstance().getUploader().logAndUpdateState(context, 1);
} else {
Logging.w(LOG_TAG, "Expected instance of `TransportImpl`, got `%s`.", transport);
}
throw new IllegalArgumentException("Expected instance of TransportImpl.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a warning log statement here, there's logging util available in this sdk under
com.google.android.datatransport.runtime.logging.Logging

}

private ForcedSender() {}
Expand Down