Add keystore2_microdroid

Instead of changing keystore2 to use libsqlite_noicu, create another
variant of keystore2 (keystore2-microdroid) which uses libsqlite_noicu,
and use it only for microdroid.

Although keystore2 doesn't actually depend on the ICU extension, doing
it for Android caused a small regression (6ms) to the boot time because
keystore2 should spend time for loading the new library
libsqlite_noicu instead of sharing text pages from libsqlite.so which
were already preloaded by zygote.

With this change, keystore2 for Android goes back to use libsqlite.so.
The use of the noicu variant is limited to Microdroid.

Bug: 201344281
Test: measure SystemServerTiming_StartLockSettingsService-total
Change-Id: I6ff123415cdc3e7494a7857864e04525322bc079
diff --git a/keystore2/Android.bp b/keystore2/Android.bp
index 7f1d15d..8efc330 100644
--- a/keystore2/Android.bp
+++ b/keystore2/Android.bp
@@ -48,11 +48,9 @@
         "libkeystore2_vintf_rust",
         "liblazy_static",
         "liblibc",
-        "liblibsqlite3_sys_noicu",
         "liblog_event_list",
         "liblog_rust",
         "librand",
-        "librusqlite_noicu",
         "librustutils",
         "libthiserror",
     ],
@@ -67,6 +65,19 @@
 rust_library {
     name: "libkeystore2",
     defaults: ["libkeystore2_defaults"],
+    rustlibs: [
+        "liblibsqlite3_sys",
+        "librusqlite",
+    ],
+}
+
+rust_library {
+    name: "libkeystore2_noicu",
+    defaults: ["libkeystore2_defaults"],
+    rustlibs: [
+        "liblibsqlite3_sys_noicu",
+        "librusqlite_noicu",
+    ],
 }
 
 rust_library {
@@ -113,7 +124,9 @@
     rustlibs: [
         "libandroid_logger",
         "libkeystore2_test_utils",
+        "liblibsqlite3_sys",
         "libnix",
+        "librusqlite",
     ],
     // The test should always include watchdog.
     features: [
@@ -121,16 +134,13 @@
     ],
 }
 
-rust_binary {
-    name: "keystore2",
+rust_defaults {
+    name: "keystore2_defaults",
     srcs: ["src/keystore2_main.rs"],
     rustlibs: [
         "libandroid_logger",
         "libbinder_rs",
-        "libkeystore2",
         "liblog_rust",
-        "liblegacykeystore-rust",
-        "librusqlite",
     ],
     init_rc: ["keystore2.rc"],
 
@@ -168,3 +178,28 @@
 
     required: ["keystore_cli_v2"],
 }
+
+rust_binary {
+    name: "keystore2",
+    defaults: ["keystore2_defaults"],
+    rustlibs: [
+        "libkeystore2",
+        "liblegacykeystore-rust",
+        "librusqlite",
+    ],
+}
+
+// Variant of keystore2 for use in microdroid. It doesn't depend on the ICU-enabled sqlite.
+// This can be used also in Android, but we choose not to because it will bring two
+// variants of sqlite to the system causing more RAM usage and CPU cycles when loading.
+rust_binary {
+    name: "keystore2_microdroid",
+    stem: "keystore2",
+    defaults: ["keystore2_defaults"],
+    rustlibs: [
+        "libkeystore2_noicu",
+        "liblegacykeystore-rust_noicu",
+        "librusqlite_noicu",
+    ],
+    installable: false, // don't install this to Android
+}