secure_element: Check for support of basic channel in VTS tests

Do not use the basic channel in VTS tests if the channel is not
supported by the SE.

Bug: 266384111
Test: m VtsHalSecureElementTargetTest
Change-Id: Id40e7f43f5437f8e682bbd41495d89a4a4c45997
diff --git a/secure_element/aidl/vts/VtsHalSecureElementTargetTest.cpp b/secure_element/aidl/vts/VtsHalSecureElementTargetTest.cpp
index 37ff1b2..2e96f7d 100644
--- a/secure_element/aidl/vts/VtsHalSecureElementTargetTest.cpp
+++ b/secure_element/aidl/vts/VtsHalSecureElementTargetTest.cpp
@@ -106,6 +106,15 @@
 
         EXPECT_OK(secure_element_->init(secure_element_callback_));
         secure_element_callback_->expectCallbackHistory({true});
+
+        // Check if the basic channel is supported by the bound SE.
+        std::vector<uint8_t> basic_channel_response;
+        auto status =
+                secure_element_->openBasicChannel(kSelectableAid, 0x00, &basic_channel_response);
+        if (status.isOk()) {
+            basic_channel_supported_ = true;
+            secure_element_->closeChannel(0);
+        }
     }
 
     void TearDown() override {
@@ -143,6 +152,7 @@
 
     std::shared_ptr<ISecureElement> secure_element_;
     std::shared_ptr<MySecureElementCallback> secure_element_callback_;
+    bool basic_channel_supported_{false};
 };
 
 TEST_P(SecureElementAidl, init) {
@@ -159,14 +169,18 @@
     LogicalChannelResponse logical_channel_response;
 
     // reset called after init shall succeed.
-    EXPECT_OK(secure_element_->openBasicChannel(kSelectableAid, 0x00, &basic_channel_response));
+    if (basic_channel_supported_) {
+        EXPECT_OK(secure_element_->openBasicChannel(kSelectableAid, 0x00, &basic_channel_response));
+    }
     EXPECT_OK(secure_element_->openLogicalChannel(kSelectableAid, 0x00, &logical_channel_response));
 
     EXPECT_OK(secure_element_->reset());
     secure_element_callback_->expectCallbackHistory({true, false, true});
 
     // All opened channels must be closed.
-    EXPECT_NE(transmit(0), 0x9000);
+    if (basic_channel_supported_) {
+        EXPECT_NE(transmit(0), 0x9000);
+    }
     EXPECT_NE(transmit(logical_channel_response.channelNumber), 0x9000);
 }
 
@@ -190,6 +204,10 @@
 TEST_P(SecureElementAidl, openBasicChannel) {
     std::vector<uint8_t> response;
 
+    if (!basic_channel_supported_) {
+        return;
+    }
+
     // openBasicChannel called with an invalid AID shall fail.
     EXPECT_ERR(secure_element_->openBasicChannel(kNonSelectableAid, 0x00, &response));
 
@@ -199,7 +217,7 @@
     EXPECT_OK(secure_element_->openBasicChannel(kSelectableAid, 0x00, &response));
     EXPECT_GE(response.size(), 2u);
 
-    // tramsmit called on the basic channel should succeed.
+    // transmit called on the basic channel should succeed.
     EXPECT_EQ(transmit(0), 0x9000);
 
     // openBasicChannel called a second time shall fail.
@@ -225,7 +243,7 @@
     EXPECT_GE(response.channelNumber, 1u);
     EXPECT_LE(response.channelNumber, 19u);
 
-    // tramsmit called on the logical channel should succeed.
+    // transmit called on the logical channel should succeed.
     EXPECT_EQ(transmit(response.channelNumber), 0x9000);
 }
 
@@ -239,17 +257,19 @@
     EXPECT_ERR(secure_element_->closeChannel(1));
 
     // closeChannel called on basic channel closes the basic channel.
-    EXPECT_OK(secure_element_->openBasicChannel(kSelectableAid, 0x00, &basic_channel_response));
-    EXPECT_OK(secure_element_->closeChannel(0));
+    if (basic_channel_supported_) {
+        EXPECT_OK(secure_element_->openBasicChannel(kSelectableAid, 0x00, &basic_channel_response));
+        EXPECT_OK(secure_element_->closeChannel(0));
 
-    // tramsmit called on the basic channel should fail.
-    EXPECT_NE(transmit(0), 0x9000);
+        // transmit called on the basic channel should fail.
+        EXPECT_NE(transmit(0), 0x9000);
+    }
 
     // closeChannel called on logical channel closes the logical channel.
     EXPECT_OK(secure_element_->openLogicalChannel(kSelectableAid, 0x00, &logical_channel_response));
     EXPECT_OK(secure_element_->closeChannel(logical_channel_response.channelNumber));
 
-    // tramsmit called on the basic channel should fail.
+    // transmit called on the logical channel should fail.
     EXPECT_NE(transmit(logical_channel_response.channelNumber), 0x9000);
 }