Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 130857ff authored by Kihong Seong's avatar Kihong Seong Committed by Gerrit Code Review
Browse files

Merge "Add helper method for setting up initial environment for Bumble BT tests" into main

parents f3272f4c 7be24ba0
Loading
Loading
Loading
Loading
+4 −20
Original line number Diff line number Diff line
package android.bluetooth;

import static android.bluetooth.Utils.factoryResetAndCreateNewChannel;

import android.bluetooth.le.AdvertiseData;
import android.bluetooth.le.AdvertisingSet;
import android.bluetooth.le.AdvertisingSetCallback;
@@ -18,7 +20,6 @@ import com.google.protobuf.Empty;
import io.grpc.Context.CancellableContext;
import io.grpc.Deadline;
import io.grpc.ManagedChannel;
import io.grpc.okhttp.OkHttpChannelBuilder;
import io.grpc.stub.StreamObserver;

import java.util.concurrent.CompletableFuture;
@@ -59,25 +60,8 @@ public class LeAdvertisingTest {

    @Before
    public void setUp() throws Exception {
        // FactorReset is killing the server and restart
        // all channel created before the server restarted
        // cannot be reused
        ManagedChannel channel = OkHttpChannelBuilder
              .forAddress("localhost", 7999)
              .usePlaintext()
              .build();

        HostGrpc.HostBlockingStub stub = HostGrpc.newBlockingStub(channel);
        stub.factoryReset(Empty.getDefaultInstance());

        // terminate the channel
        channel.shutdown().awaitTermination(1, TimeUnit.SECONDS);

        // Create a new channel for all successive grpc calls
        mChannel = OkHttpChannelBuilder
              .forAddress("localhost", 7999)
              .usePlaintext()
              .build();
        // Cleanup previous channels and create a new channel for all successive grpc calls
        mChannel = factoryResetAndCreateNewChannel();

        mHostBlockingStub = HostGrpc.newBlockingStub(mChannel);
        mHostStub = HostGrpc.newStub(mChannel);
+5 −16
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.bluetooth;

import static android.bluetooth.Utils.factoryResetAndCreateNewChannel;

import static com.google.common.truth.Truth.assertThat;

import android.bluetooth.le.BluetoothLeScanner;
@@ -45,7 +47,6 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

import io.grpc.ManagedChannel;
import io.grpc.okhttp.OkHttpChannelBuilder;
import io.grpc.stub.StreamObserver;

import pandora.HostGrpc;
@@ -56,7 +57,7 @@ import pandora.HostProto.AdvertiseResponse;
@RunWith(AndroidJUnit4.class)
public class LeScanningTest {
    private static final String TAG = "LeScanningTest";
    private static final int TIMEOUT_SCANNING_MS = 1000;
    private static final int TIMEOUT_SCANNING_MS = 2000;

    private static ManagedChannel mChannel;

@@ -75,20 +76,8 @@ public class LeScanningTest {

    @Before
    public void setUp() throws Exception {
        // FactorReset is killing the server and restart
        // all channel created before the server restarted
        // cannot be reused
        ManagedChannel channel =
                OkHttpChannelBuilder.forAddress("localhost", 7999).usePlaintext().build();

        HostGrpc.HostBlockingStub stub = HostGrpc.newBlockingStub(channel);
        stub.factoryReset(Empty.getDefaultInstance());

        // terminate the channel
        channel.shutdown().awaitTermination(1, TimeUnit.SECONDS);

        // Create a new channel for all successive grpc calls
        mChannel = OkHttpChannelBuilder.forAddress("localhost", 7999).usePlaintext().build();
        // Cleanup previous channels and create a new channel for all successive grpc calls
        mChannel = factoryResetAndCreateNewChannel();

        mHostBlockingStub = HostGrpc.newBlockingStub(mChannel);
        mHostStub = HostGrpc.newStub(mChannel);
+25 −0
Original line number Diff line number Diff line
package android.bluetooth;

import com.google.protobuf.ByteString;
import com.google.protobuf.Empty;

import java.util.concurrent.TimeUnit;

import io.grpc.ManagedChannel;
import io.grpc.okhttp.OkHttpChannelBuilder;
import pandora.HostGrpc;

public final class Utils {
    public static String addressStringFromByteString(ByteString bs) {
@@ -13,4 +20,22 @@ public final class Utils {
        }
        return refAddrBuilder.toString();
    }

    public static ManagedChannel factoryResetAndCreateNewChannel() throws InterruptedException {
        // FactoryReset is killing the server and restarting all channels created before the server
        // restarted that cannot be reused
        ManagedChannel channel = OkHttpChannelBuilder
                .forAddress("localhost", 7999)
                .usePlaintext()
                .build();

        HostGrpc.HostBlockingStub stub = HostGrpc.newBlockingStub(channel);
        stub.factoryReset(Empty.getDefaultInstance());

        // terminate the channel
        channel.shutdown().awaitTermination(1, TimeUnit.SECONDS);

        // return new channel for future use
        return OkHttpChannelBuilder.forAddress("localhost", 7999).usePlaintext().build();
    }
}