Skip to content

Revert "Remove overrideChannelBuilder" #756

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
Aug 30, 2019
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 @@ -15,6 +15,7 @@
package com.google.firebase.firestore.remote;

import android.content.Context;
import androidx.annotation.VisibleForTesting;
import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
import com.google.android.gms.common.GooglePlayServicesRepairableException;
import com.google.android.gms.security.ProviderInstaller;
Expand All @@ -24,6 +25,7 @@
import com.google.firebase.firestore.util.AsyncQueue;
import com.google.firebase.firestore.util.Executors;
import com.google.firebase.firestore.util.Logger;
import com.google.firebase.firestore.util.Supplier;
import com.google.firestore.v1.FirestoreGrpc;
import io.grpc.CallCredentials;
import io.grpc.CallOptions;
Expand All @@ -41,11 +43,26 @@ public class GrpcCallProvider {

private static final String LOG_TAG = "GrpcCallProvider";

private static Supplier<ManagedChannelBuilder<?>> overrideChannelBuilderSupplier;

private final Task<ManagedChannel> channelTask;
private final AsyncQueue asyncQueue;

private CallOptions callOptions;

/**
* Helper function to globally override the channel that RPCs use. Useful for testing when you
* want to bypass SSL certificate checking.
*
* @param channelBuilderSupplier The supplier for a channel builder that is used to create gRPC
* channels.
*/
@VisibleForTesting
public static void overrideChannelBuilder(
Supplier<ManagedChannelBuilder<?>> channelBuilderSupplier) {
overrideChannelBuilderSupplier = channelBuilderSupplier;
}

GrpcCallProvider(
AsyncQueue asyncQueue,
Context context,
Expand Down Expand Up @@ -88,12 +105,16 @@ private ManagedChannel initChannel(Context context, DatabaseInfo databaseInfo) {
Logger.warn(LOG_TAG, "Failed to update ssl context: %s", e);
}

ManagedChannelBuilder<?> channelBuilder =
ManagedChannelBuilder.forTarget(databaseInfo.getHost());
if (!databaseInfo.isSslEnabled()) {
// Note that the boolean flag does *NOT* switch the wire format from Protobuf to Plaintext.
// It merely turns off SSL encryption.
channelBuilder.usePlaintext();
ManagedChannelBuilder<?> channelBuilder;
if (overrideChannelBuilderSupplier != null) {
channelBuilder = overrideChannelBuilderSupplier.get();
} else {
channelBuilder = ManagedChannelBuilder.forTarget(databaseInfo.getHost());
if (!databaseInfo.isSslEnabled()) {
// Note that the boolean flag does *NOT* switch the wire format from Protobuf to Plaintext.
// It merely turns off SSL encryption.
channelBuilder.usePlaintext();
}
}

// Ensure gRPC recovers from a dead connection. (Not typically necessary, as the OS will
Expand Down