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

Commit 62b5318a authored by Charlie Boutier's avatar Charlie Boutier Committed by Automerger Merge Worker
Browse files

Merge "PandoraServer: Add AcceptPutOperation in OPP" into main am: 4dca7627

parents f4b67d03 4dca7627
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ from mmi2grpc._proxy import ProfileProxy

from pandora.host_grpc import Host
from pandora.host_pb2 import Connection
from pandora_experimental._android_grpc import Android
from pandora_experimental.opp_grpc import Opp


@@ -35,7 +34,6 @@ class OPPProxy(ProfileProxy):
        super().__init__(channel)

        self.host = Host(channel)
        self._android = Android(channel)
        self.opp = Opp(channel)

        self.connection = None
@@ -67,7 +65,7 @@ class OPPProxy(ProfileProxy):
        """
        Please accept the PUT REQUEST.
        """
        self._android.AcceptIncomingFile()
        self.opp.AcceptPutOperation()

        return "OK"

+0 −30
Original line number Diff line number Diff line
@@ -24,10 +24,6 @@ import android.telephony.SmsManager
import android.telephony.SubscriptionManager
import android.telephony.TelephonyManager
import android.util.Log
import androidx.test.InstrumentationRegistry
import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.Until
import com.google.protobuf.Empty
import io.grpc.stub.StreamObserver
import kotlinx.coroutines.CoroutineScope
@@ -41,22 +37,11 @@ private const val TAG = "PandoraAndroidInternal"
class AndroidInternal(val context: Context) : AndroidImplBase() {

    private val scope: CoroutineScope = CoroutineScope(Dispatchers.Default.limitedParallelism(1))
    private val INCOMING_FILE_ACCEPT_BTN = "ACCEPT"
    private val INCOMING_FILE_TITLE = "Incoming file"
    private val INCOMING_FILE_WAIT_TIMEOUT = 2000L

    // PTS does not configure the Extended Inquiry Response with the
    // device name; the device will be found after the Inquiry Timeout
    // (40 secondes) has elapsed.
    private val BT_DEVICE_SELECT_WAIT_TIMEOUT = 40000L
    private val IMAGE_FILE_NAME = "OPP_TEST_IMAGE.bmp"

    private val bluetoothManager = context.getSystemService(BluetoothManager::class.java)!!
    private val bluetoothAdapter = bluetoothManager.adapter
    private var telephonyManager = context.getSystemService(TelephonyManager::class.java)!!
    private val DEFAULT_MESSAGE_LEN = 130
    private var device: UiDevice =
        UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())

    override fun log(request: LogRequest, responseObserver: StreamObserver<LogResponse>) {
        grpcUnary(scope, responseObserver) {
@@ -102,21 +87,6 @@ class AndroidInternal(val context: Context) : AndroidImplBase() {
        }
    }

    override fun acceptIncomingFile(request: Empty, responseObserver: StreamObserver<Empty>) {
        grpcUnary<Empty>(scope, responseObserver) {
            device
                .wait(Until.findObject(By.text(INCOMING_FILE_TITLE)), INCOMING_FILE_WAIT_TIMEOUT)
                .click()
            device
                .wait(
                    Until.findObject(By.text(INCOMING_FILE_ACCEPT_BTN)),
                    INCOMING_FILE_WAIT_TIMEOUT
                )
                .click()
            Empty.getDefaultInstance()
        }
    }

    override fun sendPing(request: SendPingRequest, responseObserver: StreamObserver<Empty>) {
        grpcUnary<Empty>(scope, responseObserver) {
            val pingStatus =
+28 −1
Original line number Diff line number Diff line
@@ -29,6 +29,10 @@ import android.graphics.Bitmap
import android.os.Environment
import android.provider.MediaStore.Images.Media
import android.provider.MediaStore.MediaColumns
import androidx.test.InstrumentationRegistry
import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.Until
import com.google.protobuf.Empty
import io.grpc.stub.StreamObserver
import java.io.Closeable
@@ -49,11 +53,15 @@ private const val TAG = "PandoraOpp"
@kotlinx.coroutines.ExperimentalCoroutinesApi
class Opp(val context: Context) : OppImplBase(), Closeable {
    private val IMAGE_FILE_NAME = "OPP_TEST_IMAGE.bmp"
    private val INCOMING_FILE_TITLE = "Incoming file"
    private val INCOMING_FILE_ACCEPT_BTN = "ACCEPT"
    private val INCOMING_FILE_WAIT_TIMEOUT = 2000L
    private val flow: Flow<Intent>
    private val scope: CoroutineScope = CoroutineScope(Dispatchers.Default.limitedParallelism(1))
    private val bluetoothManager = context.getSystemService(BluetoothManager::class.java)!!
    private val bluetoothAdapter = bluetoothManager.adapter

    private var uiDevice: UiDevice =
        UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
    init {
        createImageFile()

@@ -96,6 +104,25 @@ class Opp(val context: Context) : OppImplBase(), Closeable {
        }
    }

    override fun acceptPutOperation(
        request: Empty,
        responseObserver: StreamObserver<AcceptPutOperationResponse>
    ) {
        grpcUnary<AcceptPutOperationResponse>(scope, responseObserver) {
            acceptIncomingFile()
            AcceptPutOperationResponse.newBuilder().setStatus(PutStatus.ACCEPTED).build()
        }
    }

    fun acceptIncomingFile() {
        uiDevice
            .wait(Until.findObject(By.text(INCOMING_FILE_TITLE)), INCOMING_FILE_WAIT_TIMEOUT)
            .click()
        uiDevice
            .wait(Until.findObject(By.text(INCOMING_FILE_ACCEPT_BTN)), INCOMING_FILE_WAIT_TIMEOUT)
            .click()
    }

    private suspend fun sendFile(bluetoothDevice: BluetoothDevice) {
        initiateSendFile(getImageId(IMAGE_FILE_NAME), "image/bmp")
        waitBluetoothDevice(bluetoothDevice)
+0 −2
Original line number Diff line number Diff line
@@ -19,8 +19,6 @@ service Android {
  rpc SetAccessPermission(SetAccessPermissionRequest) returns (google.protobuf.Empty);
  // Send SMS
  rpc SendSMS(google.protobuf.Empty) returns (google.protobuf.Empty);
  // Accept incoming file
  rpc AcceptIncomingFile(google.protobuf.Empty) returns (google.protobuf.Empty);

  // Send ping
  rpc SendPing(SendPingRequest) returns (google.protobuf.Empty);
+13 −2
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@ service Opp {
  rpc OpenRfcommChannel(OpenRfcommChannelRequest) returns (google.protobuf.Empty);
  // Open an l2cap channel for an OBEX connection.
  rpc OpenL2capChannel(OpenL2capChannelRequest) returns (google.protobuf.Empty);
  // Accept Put request by the Push Client to the Push Server within an OBEX connection.
  rpc AcceptPutOperation(google.protobuf.Empty) returns (AcceptPutOperationResponse);
}

message OpenRfcommChannelRequest {
@@ -34,3 +36,12 @@ message OpenRfcommChannelRequest {
message OpenL2capChannelRequest {
  bytes address = 1;
}

enum PutStatus {
  ACCEPTED = 0;
  DECLINED = 1;
}

message AcceptPutOperationResponse {
  PutStatus status = 1;
}
 No newline at end of file