Implement Discovery PLATFORM logic in Rust
Add RemoteAuthConnectionCache and RemoteAuthPlatform
with support to sendMessage
Design doc: go/remote-auth-manager-fishfood-design
Test: built successfully.
Bug: : 291333048
Change-Id: I17f73b4fb2e22924a484eeb3baa9b933ae980076
diff --git a/remoteauth/service/jni/src/lib.rs b/remoteauth/service/jni/src/lib.rs
index a816c94..c6f8c72 100644
--- a/remoteauth/service/jni/src/lib.rs
+++ b/remoteauth/service/jni/src/lib.rs
@@ -21,5 +21,7 @@
mod unique_jvm;
mod utils;
+/// Implementation of JNI platform functionality.
pub mod remoteauth_jni_android_platform;
+/// Implementation of JNI protocol functionality.
pub mod remoteauth_jni_android_protocol;
diff --git a/remoteauth/service/jni/src/remoteauth_jni_android_platform.rs b/remoteauth/service/jni/src/remoteauth_jni_android_platform.rs
index 1967c1a..0a189f2 100644
--- a/remoteauth/service/jni/src/remoteauth_jni_android_platform.rs
+++ b/remoteauth/service/jni/src/remoteauth_jni_android_platform.rs
@@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+//! Implementation of JNI platform functionality.
use crate::jnames::{SEND_REQUEST_MNAME, SEND_REQUEST_MSIG};
use crate::unique_jvm;
use anyhow::anyhow;
@@ -73,11 +74,15 @@
HANDLE_MAPPING.lock().unwrap().insert(handle, Arc::clone(&item));
}
+/// Reports a response from remote device.
pub trait ResponseCallback {
+ /// Invoked upon successful response
fn on_response(&mut self, response: Vec<u8>);
+ /// Invoked upon failure
fn on_error(&mut self, error_code: i32);
}
+/// Trait to platform functionality
pub trait Platform {
/// Send a binary message to the remote with the given connection id and return the response.
fn send_request(
@@ -89,6 +94,7 @@
}
//////////////////////////////////
+/// Implementation of Platform trait
pub struct JavaPlatform {
platform_handle: i64,
vm: &'static Arc<JavaVM>,
@@ -99,7 +105,7 @@
}
impl JavaPlatform {
- // Method to create JavaPlatform
+ /// Creates JavaPlatform and associates with unique handle id
pub fn create(
java_platform_native: JObject<'_>,
) -> Result<Arc<Mutex<impl Platform>>, JNIError> {
@@ -219,6 +225,7 @@
}
}
+/// Returns successful response from remote device
#[no_mangle]
pub extern "system" fn Java_com_android_server_remoteauth_jni_NativeRemoteAuthJavaPlatform_native_on_send_request_success(
env: JNIEnv,
@@ -250,6 +257,7 @@
}
}
+/// Notifies about failure to receive a response from remote device
#[no_mangle]
pub extern "system" fn Java_com_android_server_remoteauth_jni_NativeRemoteAuthJavaPlatform_native_on_send_request_error(
env: JNIEnv,
diff --git a/remoteauth/service/jni/src/remoteauth_jni_android_protocol.rs b/remoteauth/service/jni/src/remoteauth_jni_android_protocol.rs
index 1f73207..ac2eb8c 100644
--- a/remoteauth/service/jni/src/remoteauth_jni_android_protocol.rs
+++ b/remoteauth/service/jni/src/remoteauth_jni_android_protocol.rs
@@ -14,12 +14,14 @@
* limitations under the License.
*/
+//! Implementation of JNI protocol functionality.
use crate::unique_jvm;
use crate::utils::get_boolean_result;
use jni::objects::JObject;
use jni::sys::jboolean;
use jni::JNIEnv;
+/// Initialize native library. Captures Java VM:
#[no_mangle]
pub extern "system" fn Java_com_android_server_remoteauth_jni_NativeRemoteAuthJavaPlatform_native_init(
env: JNIEnv,