floss: Implement descriptor and notificaton methods

This implements IBluetoothGatt methods:
* ReadDescriptor
* WriteDescriptor
* RegisterForNotification

Bug: 193685325
Tag: #floss
Test: Build floss on Linux and AOSP

Change-Id: I3d264723a8583c63c805bd0a17f62e6957a547b7
diff --git a/system/gd/rust/linux/service/src/iface_bluetooth_gatt.rs b/system/gd/rust/linux/service/src/iface_bluetooth_gatt.rs
index eae7457..8357d0c 100644
--- a/system/gd/rust/linux/service/src/iface_bluetooth_gatt.rs
+++ b/system/gd/rust/linux/service/src/iface_bluetooth_gatt.rs
@@ -172,4 +172,21 @@
     ) -> GattWriteRequestStatus {
         GattWriteRequestStatus::Success
     }
+
+    #[dbus_method("ReadDescriptor")]
+    fn read_descriptor(&self, client_id: i32, addr: String, handle: i32, auth_req: i32) {}
+
+    #[dbus_method("WriteDescriptor")]
+    fn write_descriptor(
+        &self,
+        client_id: i32,
+        addr: String,
+        handle: i32,
+        auth_req: i32,
+        value: Vec<u8>,
+    ) {
+    }
+
+    #[dbus_method("RegisterForNotification")]
+    fn register_for_notification(&self, client_id: i32, addr: String, handle: i32, enable: bool) {}
 }
diff --git a/system/gd/rust/linux/stack/src/bluetooth_gatt.rs b/system/gd/rust/linux/stack/src/bluetooth_gatt.rs
index dd79c9e..1fdc45e 100644
--- a/system/gd/rust/linux/stack/src/bluetooth_gatt.rs
+++ b/system/gd/rust/linux/stack/src/bluetooth_gatt.rs
@@ -185,6 +185,22 @@
         auth_req: i32,
         value: Vec<u8>,
     ) -> GattWriteRequestStatus;
+
+    /// Reads the descriptor for a given characteristic.
+    fn read_descriptor(&self, client_id: i32, addr: String, handle: i32, auth_req: i32);
+
+    /// Writes a remote descriptor for a given characteristic.
+    fn write_descriptor(
+        &self,
+        client_id: i32,
+        addr: String,
+        handle: i32,
+        auth_req: i32,
+        value: Vec<u8>,
+    );
+
+    /// Registers to receive notifications or indications for a given characteristic.
+    fn register_for_notification(&self, client_id: i32, addr: String, handle: i32, enable: bool);
 }
 
 /// Callback for GATT Client API.
@@ -533,6 +549,67 @@
 
         return GattWriteRequestStatus::Success;
     }
+
+    fn read_descriptor(&self, client_id: i32, addr: String, handle: i32, auth_req: i32) {
+        let conn_id = self.context_map.get_conn_id_from_address(client_id, &addr);
+        if conn_id.is_none() {
+            return;
+        }
+
+        // TODO(b/193685325): Perform check on restricted handles.
+
+        self.gatt.as_ref().unwrap().client.read_descriptor(
+            conn_id.unwrap(),
+            handle as u16,
+            auth_req,
+        );
+    }
+
+    fn write_descriptor(
+        &self,
+        client_id: i32,
+        addr: String,
+        handle: i32,
+        auth_req: i32,
+        value: Vec<u8>,
+    ) {
+        let conn_id = self.context_map.get_conn_id_from_address(client_id, &addr);
+        if conn_id.is_none() {
+            return;
+        }
+
+        // TODO(b/193685325): Perform check on restricted handles.
+
+        self.gatt.as_ref().unwrap().client.write_descriptor(
+            conn_id.unwrap(),
+            handle as u16,
+            auth_req,
+            &value,
+        );
+    }
+
+    fn register_for_notification(&self, client_id: i32, addr: String, handle: i32, enable: bool) {
+        let conn_id = self.context_map.get_conn_id_from_address(client_id, &addr);
+        if conn_id.is_none() {
+            return;
+        }
+
+        // TODO(b/193685325): Perform check on restricted handles.
+
+        if enable {
+            self.gatt.as_ref().unwrap().client.register_for_notification(
+                client_id,
+                &RawAddress::from_string(addr).unwrap(),
+                handle as u16,
+            );
+        } else {
+            self.gatt.as_ref().unwrap().client.deregister_for_notification(
+                client_id,
+                &RawAddress::from_string(addr).unwrap(),
+                handle as u16,
+            );
+        }
+    }
 }
 
 #[btif_callbacks_dispatcher(BluetoothGatt, dispatch_gatt_client_callbacks, GattClientCallbacks)]