Merge "Edit hidl instances to remove vintf"
diff --git a/keystore2/Android.bp b/keystore2/Android.bp
index 4084ace..79b938c 100644
--- a/keystore2/Android.bp
+++ b/keystore2/Android.bp
@@ -47,7 +47,7 @@
         "libkeystore2_crypto_rust",
         "libkeystore2_km_compat",
         "libkeystore2_selinux",
-        "libkeystore2_vintf_rust",
+        "libkeystore2_hal_names_rust",
         "liblazy_static",
         "liblibc",
         "liblog_event_list",
diff --git a/keystore2/src/fuzzers/Android.bp b/keystore2/src/fuzzers/Android.bp
index 4ac83e3..9f3e104 100644
--- a/keystore2/src/fuzzers/Android.bp
+++ b/keystore2/src/fuzzers/Android.bp
@@ -23,7 +23,7 @@
         "libbinder_rs",
         "libkeystore2",
         "libkeystore2_crypto_rust",
-        "libkeystore2_vintf_rust",
+        "libkeystore2_hal_names_rust",
         "libkeystore2_aaid-rust",
         "libkeystore2_apc_compat-rust",
         "libkeystore2_selinux",
@@ -46,7 +46,7 @@
     rustlibs: [
         "libkeystore2",
         "libkeystore2_crypto_rust",
-        "libkeystore2_vintf_rust",
+        "libkeystore2_hal_names_rust",
         "libkeystore2_aaid-rust",
         "libkeystore2_apc_compat-rust",
         "libkeystore2_selinux",
diff --git a/keystore2/src/fuzzers/keystore2_unsafe_fuzzer.rs b/keystore2/src/fuzzers/keystore2_unsafe_fuzzer.rs
index 0dca3a2..b8259cf 100644
--- a/keystore2/src/fuzzers/keystore2_unsafe_fuzzer.rs
+++ b/keystore2/src/fuzzers/keystore2_unsafe_fuzzer.rs
@@ -26,8 +26,8 @@
     ec_point_point_to_oct, ecdh_compute_key, generate_random_data, hkdf_expand, hkdf_extract,
     hmac_sha256, parse_subject_from_certificate, Password, ZVec,
 };
+use keystore2_hal_names::get_hidl_instances;
 use keystore2_selinux::{check_access, getpidcon, setcon, Backend, Context, KeystoreKeyBackend};
-use keystore2_vintf::get_hidl_instances;
 use libfuzzer_sys::{arbitrary::Arbitrary, fuzz_target};
 use std::{ffi::CString, sync::Arc};
 
diff --git a/keystore2/src/vintf/Android.bp b/keystore2/src/hal_instance_names/Android.bp
similarity index 74%
rename from keystore2/src/vintf/Android.bp
rename to keystore2/src/hal_instance_names/Android.bp
index 34719aa..2f1d5c3 100644
--- a/keystore2/src/vintf/Android.bp
+++ b/keystore2/src/hal_instance_names/Android.bp
@@ -22,41 +22,41 @@
 }
 
 rust_library {
-    name: "libkeystore2_vintf_rust",
-    crate_name: "keystore2_vintf",
+    name: "libkeystore2_hal_names_rust",
+    crate_name: "keystore2_hal_names",
     srcs: ["lib.rs"],
     rustlibs: [
         "libcxx",
     ],
     shared_libs: [
-        "libvintf",
+        "libhidlbase",
     ],
     static_libs: [
-        "libkeystore2_vintf_cpp",
+        "libkeystore2_hal_names_cpp",
     ],
 }
 
 cc_library_static {
-    name: "libkeystore2_vintf_cpp",
-    srcs: ["vintf.cpp"],
+    name: "libkeystore2_hal_names_cpp",
+    srcs: ["hal_names.cpp"],
     generated_headers: ["cxx-bridge-header"],
-    generated_sources: ["vintf_bridge_code"],
+    generated_sources: ["hal_names_bridge_code"],
     shared_libs: [
-        "libvintf",
+        "libhidlbase",
     ],
 }
 
 genrule {
-    name: "vintf_bridge_code",
+    name: "hal_names_bridge_code",
     tools: ["cxxbridge"],
     cmd: "$(location cxxbridge) $(in) >> $(out)",
     srcs: ["lib.rs"],
-    out: ["vintf_cxx_generated.cc"],
+    out: ["hal_names_cxx_generated.cc"],
 }
 
 rust_test {
-    name: "keystore2_vintf_test",
-    crate_name: "keystore2_vintf_test",
+    name: "keystore2_hal_names_test",
+    crate_name: "keystore2_hal_names_test",
     srcs: ["lib.rs"],
     test_suites: ["general-tests"],
     auto_gen_config: true,
@@ -64,10 +64,10 @@
         "libcxx",
     ],
     static_libs: [
-        "libkeystore2_vintf_cpp",
+        "libkeystore2_hal_names_cpp",
     ],
     shared_libs: [
         "libc++",
-        "libvintf",
+        "libhidlbase",
     ],
 }
diff --git a/keystore2/src/vintf/vintf.cpp b/keystore2/src/hal_instance_names/hal_names.cpp
similarity index 64%
rename from keystore2/src/vintf/vintf.cpp
rename to keystore2/src/hal_instance_names/hal_names.cpp
index bf77f5e..316c26c 100644
--- a/keystore2/src/vintf/vintf.cpp
+++ b/keystore2/src/hal_instance_names/hal_names.cpp
@@ -14,13 +14,11 @@
  * limitations under the License.
  */
 
-#include <algorithm>
-#include <vintf/HalManifest.h>
-#include <vintf/VintfObject.h>
+#include <hidl/ServiceManagement.h>
 
 #include "rust/cxx.h"
 
-rust::Vec<rust::String> convert(const std::set<std::string>& names) {
+rust::Vec<rust::String> convert(const std::vector<std::string>& names) {
     rust::Vec<rust::String> result;
     std::copy(names.begin(), names.end(), std::back_inserter(result));
     return result;
@@ -28,9 +26,10 @@
 
 rust::Vec<rust::String> get_hidl_instances(rust::Str package, size_t major_version,
                                            size_t minor_version, rust::Str interfaceName) {
-    android::vintf::Version version(major_version, minor_version);
-    const auto manifest = android::vintf::VintfObject::GetDeviceHalManifest();
-    const auto names = manifest->getHidlInstances(static_cast<std::string>(package), version,
-                                                  static_cast<std::string>(interfaceName));
-    return convert(names);
+    std::string version = std::to_string(major_version) + "." + std::to_string(minor_version);
+    std::string factoryName = static_cast<std::string>(package) + "@" + version +
+                              "::" + static_cast<std::string>(interfaceName);
+
+    const auto halNames = android::hardware::getAllHalInstanceNames(factoryName);
+    return convert(halNames);
 }
diff --git a/keystore2/src/vintf/vintf.hpp b/keystore2/src/hal_instance_names/hal_names.hpp
similarity index 100%
rename from keystore2/src/vintf/vintf.hpp
rename to keystore2/src/hal_instance_names/hal_names.hpp
diff --git a/keystore2/src/vintf/lib.rs b/keystore2/src/hal_instance_names/lib.rs
similarity index 96%
rename from keystore2/src/vintf/lib.rs
rename to keystore2/src/hal_instance_names/lib.rs
index 5bb015f..36a9c4f 100644
--- a/keystore2/src/vintf/lib.rs
+++ b/keystore2/src/hal_instance_names/lib.rs
@@ -17,7 +17,7 @@
 #[cxx::bridge]
 mod ffi {
     unsafe extern "C++" {
-        include!("vintf.hpp");
+        include!("hal_names.hpp");
 
         /// Gets the instances of the given package, version, and interface tuple.
         /// Note that this is not a zero-cost shim: it will make copies of the strings.
diff --git a/keystore2/src/shared_secret_negotiation.rs b/keystore2/src/shared_secret_negotiation.rs
index 739f4ba..1941419 100644
--- a/keystore2/src/shared_secret_negotiation.rs
+++ b/keystore2/src/shared_secret_negotiation.rs
@@ -24,15 +24,15 @@
 use android_security_compat::aidl::android::security::compat::IKeystoreCompatService::IKeystoreCompatService;
 use anyhow::Result;
 use binder::get_declared_instances;
-use keystore2_vintf::get_hidl_instances;
+use keystore2_hal_names::get_hidl_instances;
 use std::fmt::{self, Display, Formatter};
 use std::time::Duration;
 
 /// This function initiates the shared secret negotiation. It starts a thread and then returns
-/// immediately. The thread consults the vintf manifest to enumerate expected negotiation
-/// participants. It then attempts to connect to all of these participants. If any connection
-/// fails the thread will retry once per second to connect to the failed instance(s) until all of
-/// the instances are connected. It then performs the negotiation.
+/// immediately. The thread gets hal names from the android ServiceManager. It then attempts
+/// to connect to all of these participants. If any connection fails the thread will retry once
+/// per second to connect to the failed instance(s) until all of the instances are connected.
+/// It then performs the negotiation.
 ///
 /// During the first phase of the negotiation it will again try every second until
 /// all instances have responded successfully to account for instances that register early but