Create basic data store to store keyboard classification
Implements a basic file system backed data store (using a json
file), to store keyboard classification information persisted
across reboots.
Test: atest --host libinput_rust_test
Bug: 263559234
Flag: com.android.input.flags.enable_keyboard_classifier
Change-Id: I521444342ae4e98191262273b881775fb2157ef2
diff --git a/libs/input/rust/lib.rs b/libs/input/rust/lib.rs
index af8f889..008f675 100644
--- a/libs/input/rust/lib.rs
+++ b/libs/input/rust/lib.rs
@@ -16,11 +16,13 @@
//! The rust component of libinput.
+mod data_store;
mod input;
mod input_verifier;
mod keyboard_classification_config;
mod keyboard_classifier;
+pub use data_store::{DataStore, DefaultFileReaderWriter};
pub use input::{
DeviceClass, DeviceId, InputDevice, ModifierState, MotionAction, MotionFlags, Source,
};
@@ -149,7 +151,14 @@
}
fn create_keyboard_classifier() -> Box<KeyboardClassifier> {
- Box::new(KeyboardClassifier::new())
+ // Future design: Make this data store singleton by passing it to C++ side and making it global
+ // and pass by reference to components that need to store persistent data.
+ //
+ // Currently only used by rust keyboard classifier so keeping it here.
+ let data_store = DataStore::new(Box::new(DefaultFileReaderWriter::new(
+ "/data/system/inputflinger-data.json".to_string(),
+ )));
+ Box::new(KeyboardClassifier::new(data_store))
}
fn notify_keyboard_changed(