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

Commit 6314c799 authored by Kihong Seong's avatar Kihong Seong Committed by Automerger Merge Worker
Browse files

Merge "Add helper method for setting up initial environment for Bumble BT...

Merge "Add helper method for setting up initial environment for Bumble BT tests" into main am: 130857ff am: fecd4682

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/2722973



Change-Id: I32af2dd96d82edb580d90980f8f429433281d22d
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 930d9367 fecd4682
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();
    }
}