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

Commit 6b93d547 authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 7010663 from 2a7491dd to sc-release

Change-Id: I755025f46903e9c93658cf29ed7b8ac84fd1a8ea
parents 2a95a877 2a7491dd
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -117,6 +117,9 @@
    },
    {
      "name" : "net_test_btif_hf_client_service"
    },
    {
      "name" : "net_test_stack_btm"
    }
  ]
}
+14 −6
Original line number Diff line number Diff line
@@ -125,7 +125,7 @@ class PySecurity(Closable):
            auth_reqs, "ERROR"))
        self._device.security.SetAuthenticationRequirements(AuthenticationRequirementsMessage(requirement=auth_reqs))

    def send_ui_callback(self, address, callback_type, b, uid):
    def __send_ui_callback(self, address, callback_type, b, uid, pin):
        """
            Send a callback from the UI as if the user pressed a button on the dialog
        """
@@ -135,6 +135,7 @@ class PySecurity(Closable):
                message_type=callback_type,
                boolean=b,
                unique_id=uid,
                pin=bytes(pin),
                address=common.BluetoothAddressWithType(
                    address=common.BluetoothAddress(address=address),
                    type=common.BluetoothAddressTypeEnum.PUBLIC_DEVICE_ADDRESS)))
@@ -172,7 +173,7 @@ class PySecurity(Closable):
        """
        passkey = -1

        def get_unique_id(event):
        def get_passkey(event):
            if event.message_type == UiMsgType.DISPLAY_PASSKEY:
                nonlocal passkey
                passkey = event.numeric_value
@@ -180,10 +181,17 @@ class PySecurity(Closable):
            return False

        logging.debug("DUT: Waiting for expected UI event")
        assertThat(self._ui_event_stream).emits(get_unique_id)
        assertThat(self._ui_event_stream).emits(get_passkey)
        return passkey

    def on_user_input(self, cert_address, reply_boolean, expected_ui_event):
    def input_pin(self, cert_address, pin):
        """
            Respond to the UI event
        """
        self.on_user_input(
            cert_address=cert_address, reply_boolean=True, expected_ui_event=UiMsgType.DISPLAY_PIN_ENTRY, pin=pin)

    def on_user_input(self, cert_address, reply_boolean, expected_ui_event, pin=[]):
        """
            Respond to the UI event
        """
@@ -201,8 +209,8 @@ class PySecurity(Closable):

        logging.debug("DUT: Waiting for expected UI event")
        assertThat(self._ui_event_stream).emits(get_unique_id)
        # TODO(optedoblivion): Make UiCallbackType dynamic for PASSKEY when added
        self.send_ui_callback(cert_address, UiCallbackType.YES_NO, reply_boolean, ui_id)
        callback_type = UiCallbackType.YES_NO if len(pin) == 0 else UiCallbackType.PIN
        self.__send_ui_callback(cert_address, callback_type, reply_boolean, ui_id, pin)

    def get_address(self):
        return self._device.address
+7 −1
Original line number Diff line number Diff line
@@ -90,5 +90,11 @@ std::string StringFormat(const std::string& format, Args... args) {
  return std::string(buffer, size);
}

inline std::string StringFormatTime(const std::string& format, const struct std::tm& tm) {
  std::ostringstream os;
  os << std::put_time(&tm, format.c_str());
  return os.str();
}

}  // namespace common
}  // namespace bluetooth
+10 −1
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ using bluetooth::common::BoolFromString;
using bluetooth::common::FromHexString;
using bluetooth::common::Int64FromString;
using bluetooth::common::StringFormat;
using bluetooth::common::StringFormatTime;
using bluetooth::common::StringJoin;
using bluetooth::common::StringSplit;
using bluetooth::common::StringTrim;
@@ -174,4 +175,12 @@ TEST(StringsTest, string_format_test) {
  ASSERT_THAT(StringFormat("%d %.1f 0x%02x", 42, 43.123, 0x8), StrEq("42 43.1 0x08"));
}

TEST(StringsTest, string_format_time_test) {
  std::string format("%Y-%m-%d %H:%M:%S");
  time_t then = 123456789;
  struct std::tm tm;
  localtime_r(&then, &tm);
  ASSERT_THAT(StringFormatTime(format, tm), StrEq("1973-11-29 13:33:09"));
}

}  // namespace testing
+20 −1
Original line number Diff line number Diff line
@@ -74,6 +74,9 @@ class CertSecurity(PySecurity):

    _hci = None

    MAX_PIN_LENGTH = 16
    MIN_PIN_LENGTH = 1

    def _enqueue_hci_command(self, command, expect_complete):
        if (expect_complete):
            self._hci.send_command_with_complete(command)
@@ -230,7 +233,23 @@ class CertSecurity(PySecurity):
            True)
        self._enqueue_hci_command(hci_packets.UserPasskeyRequestReplyBuilder(peer, passkey), True)

    def send_ui_callback(self, address, callback_type, b, uid):
    def input_pin(self, address, pin):
        """
            Pretend to answer the pairing dialog as a user
        """
        if len(pin) > self.MAX_PIN_LENGTH or len(pin) < self.MIN_PIN_LENGTH:
            raise Exception("Pin code must be within range")
        logging.info("Cert: Waiting for PIN request")
        assertThat(self._hci_event_stream).emits(HciMatchers.EventWithCode(hci_packets.EventCode.PIN_CODE_REQUEST))
        logging.info("Cert: Send user input PIN %s for %s" % (pin.decode(), address))
        peer = address.decode('utf-8')
        pin_list = list(pin)
        # Pad
        for i in range(self.MAX_PIN_LENGTH - len(pin_list)):
            pin_list.append(0)
        self._enqueue_hci_command(hci_packets.PinCodeRequestReplyBuilder(peer, len(pin), pin_list), True)

    def __send_ui_callback(self, address, callback_type, b, uid, pin):
        """
            Pretend to answer the pairing dailog as a user
        """
Loading