Your Android phone and your Windows PC, working as one. Local-first, end-to-end encrypted, no account.
fix(android): Elevated uses the app's own application ID (#109)
averagecf7a8b26e619
diff --git a/android/app/src/main/kotlin/app/nectarlink/android/elevated/InputServer.kt b/android/app/src/main/kotlin/app/nectarlink/android/elevated/InputServer.ktindex e9305f4..036d89f 100644--- a/android/app/src/main/kotlin/app/nectarlink/android/elevated/InputServer.kt+++ b/android/app/src/main/kotlin/app/nectarlink/android/elevated/InputServer.kt@@ -43,12 +43,14 @@ import java.security.MessageDigest* on its own only during idle maintenance. Asked once per version by* [Elevated]; allowed by name in the helper.*/-internal const val COMPILE_APP_COMMAND = "cmd package compile -m speed-profile app.nectarlink"+internal const val COMPILE_APP_COMMAND = "cmd package compile -m speed-profile ${app.nectarlink.android.BuildConfig.APPLICATION_ID}"object InputServer {private const val POWER_MODE_OFF = 0private const val POWER_MODE_NORMAL = 2- private const val PKG = "app.nectarlink"+ // The installed package, so a build with an applicationIdSuffix (".dev")+ // grants itself and gets the attach broadcast, not the release app.+ private const val PKG = app.nectarlink.android.BuildConfig.APPLICATION_IDprivate val windows = java.util.Collections.synchronizedSet(LinkedHashSet<AppDisplay>())@Volatile private var serverSocket: ServerSocket? = nulldiff --git a/core/nectarlink-protocol/src/messages.rs b/core/nectarlink-protocol/src/messages.rsindex 93395cb..2eda5f7 100644--- a/core/nectarlink-protocol/src/messages.rs+++ b/core/nectarlink-protocol/src/messages.rs@@ -1726,6 +1726,13 @@ pub fn is_valid_app_apk(apk: &str) -> bool {&& is_shell_word(apk)}+/// NectarLink's package. Debug builds of the PC app also accept its local+/// test build (`app.nectarlink.dev`, the `applicationIdSuffix` of a+/// side-by-side build); release builds accept no other package.+pub fn is_own_package(p: &str) -> bool {+ p == elevated::PACKAGE || (cfg!(debug_assertions) && p.strip_prefix(elevated::PACKAGE) == Some(".dev"))+}+/// A grant the phone may ask for itself, and nothing else: a permission or/// app op for NectarLink's own package, or its own notification listener.pub fn is_valid_grant(grant: &str) -> bool {@@ -1733,15 +1740,14 @@ pub fn is_valid_grant(grant: &str) -> bool {if !words.iter().all(|w| is_shell_word(w)) {return false;}- let pkg = elevated::PACKAGE;match words.as_slice() {- ["pm", "grant", p, perm] => *p == pkg && perm.starts_with("android.permission."),+ ["pm", "grant", p, perm] => is_own_package(p) && perm.starts_with("android.permission."),["appops", "set", p, op, "allow"] => {- *p == pkg && op.bytes().all(|b| b.is_ascii_uppercase() || b == b'_')+ is_own_package(p) && op.bytes().all(|b| b.is_ascii_uppercase() || b == b'_')}- ["cmd", "notification", "allow_dnd", p] => *p == pkg,+ ["cmd", "notification", "allow_dnd", p] => is_own_package(p),["cmd", "notification", "allow_listener", component] => {- component.strip_prefix(pkg).is_some_and(|rest| rest.starts_with('/'))+ component.split_once('/').is_some_and(|(p, rest)| is_own_package(p) && !rest.is_empty())}_ => false,}@@ -4408,7 +4414,17 @@ mod tests {!ElevatedUsbStart { token: "not-hex-token-not-hex-token-not-hex".into(), ..start.clone() }.is_valid());- assert!(!ElevatedUsbStart { grants: vec![start.grants[0].clone(); 9], ..start }.is_valid());+ assert!(!ElevatedUsbStart { grants: vec![start.grants[0].clone(); 9], ..start.clone() }.is_valid());+ // The side-by-side test build grants itself, in debug builds only.+ let dev = ElevatedUsbStart {+ apk: "/data/app/~~kG3x_Q==/app.nectarlink.dev-Ab1-cD2==/base.apk".into(),+ grants: vec![+ "pm grant app.nectarlink.dev android.permission.WRITE_SECURE_SETTINGS".into(),+ "cmd notification allow_listener app.nectarlink.dev/app.nectarlink.android.notifications.NotificationListener".into(),+ ],+ ..start+ };+ assert_eq!(dev.is_valid(), cfg!(debug_assertions));}#[test]