Change BindToDeviceSocketMutator to lib.

Test: Presubmit
Bug: 268750179
Change-Id: I7d338eef4f622631d0ead0af0a91e3b68bfa69eb
diff --git a/automotive/remoteaccess/hal/default/Android.bp b/automotive/remoteaccess/hal/default/Android.bp
index bfab1ed..0155667 100644
--- a/automotive/remoteaccess/hal/default/Android.bp
+++ b/automotive/remoteaccess/hal/default/Android.bp
@@ -24,27 +24,25 @@
     relative_install_path: "hw",
     srcs: [
         "src/RemoteAccessImpl.cpp",
-        "src/BindToDeviceSocketMutator.cpp",
     ],
     whole_static_libs: [
         "RemoteAccessService",
     ],
     static_libs: [
-        "android.hardware.automotive.can@libnetdevice",
-        "libnl++",
+        "BindToDeviceSocketMutatorLib",
     ],
     shared_libs: [
-        "libbase",
         "libbinder_ndk",
-        "liblog",
         "libutils",
-        "libgrpc++",
         "libprotobuf-cpp-full",
     ],
     defaults: [
         "vhalclient_defaults",
+        "BindToDeviceSocketMutatorDefaults",
     ],
     cflags: [
+        // This is already included in BindToDeviceSocketMutatorDefaults but
+        // might be overridden by vhalclient_defaults.
         "-Wno-unused-parameter",
     ],
 }
diff --git a/automotive/remoteaccess/hal/default/src/BindToDeviceSocketMutator.cpp b/automotive/remoteaccess/hal/default/src/BindToDeviceSocketMutator.cpp
deleted file mode 100644
index c6a96de..0000000
--- a/automotive/remoteaccess/hal/default/src/BindToDeviceSocketMutator.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (C) 2023 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "BindToDeviceSocketMutator.h"
-
-#include <android-base/logging.h>
-#include <errno.h>
-#include <sys/socket.h>
-
-namespace android::hardware::automotive::remoteaccess {
-
-bool BindToDeviceSocketMutator::mutateFd(int fd) {
-    int ret = setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, mIfname.c_str(), mIfname.size());
-    if (ret != 0) {
-        PLOG(ERROR) << "Can't bind socket to interface " << mIfname;
-        return false;
-    }
-    return true;
-}
-
-bool bind_to_device_mutator_mutate_fd(int fd, grpc_socket_mutator* mutator) {
-    BindToDeviceSocketMutator* bsm = (BindToDeviceSocketMutator*)mutator;
-    return bsm->mutateFd(fd);
-}
-
-int bind_to_device_mutator_compare(grpc_socket_mutator* a, grpc_socket_mutator* b) {
-    return ((a) < (b) ? -1 : ((a) > (b) ? 1 : 0));
-}
-
-void bind_to_device_mutator_destroy(grpc_socket_mutator* mutator) {
-    BindToDeviceSocketMutator* bsm = (BindToDeviceSocketMutator*)mutator;
-    delete bsm;
-}
-
-grpc_socket_mutator_vtable bind_to_device_mutator_vtable = {bind_to_device_mutator_mutate_fd,
-                                                            bind_to_device_mutator_compare,
-                                                            bind_to_device_mutator_destroy};
-
-BindToDeviceSocketMutator::BindToDeviceSocketMutator(const std::string_view& interface_name) {
-    mIfname = interface_name;
-    grpc_socket_mutator_init(this, &bind_to_device_mutator_vtable);
-}
-
-}  // namespace android::hardware::automotive::remoteaccess
diff --git a/automotive/remoteaccess/hal/default/src/BindToDeviceSocketMutator.h b/automotive/remoteaccess/hal/default/src/BindToDeviceSocketMutator.h
deleted file mode 100644
index bafcc65..0000000
--- a/automotive/remoteaccess/hal/default/src/BindToDeviceSocketMutator.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2023 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <grpc++/grpc++.h>
-#include <src/core/lib/iomgr/socket_mutator.h>
-#include <string>
-
-namespace android::hardware::automotive::remoteaccess {
-
-class BindToDeviceSocketMutator final : public grpc_socket_mutator {
-  public:
-    BindToDeviceSocketMutator(const std::string_view& interface_name);
-
-    bool mutateFd(int fd);
-
-  private:
-    std::string mIfname;
-};
-
-}  // namespace android::hardware::automotive::remoteaccess