feat: close all windows when parked and a door opens
Ports WinClose's SWI69 window control as an opt-in foreground service that is independent of ABRP: no token, no GPS, no upload cadence. The driver opening a door while the car is in P at a readable 0 km/h pulses UP at all four areas for five seconds, then STOP. Only the parts that serve that one behaviour are taken. WinClose's speed and time arming, configurable delay, warning beep, per-window modes and position reads are all absent — the target car is a Comfort trim whose motors carry no position sensor, so a close can be neither verified nor cancelled. The pulse, the door edge detector and the eligibility policy are pure classes with unit tests. STOP is attempted from a finally block on every exit, including an interrupted sleep, a refused write and a sender that throws, because a pulse that stops arriving leaves the motors wherever they were. Guards worth naming, several of them learned from reading WinClose rather than from the port itself: - A wake lock spans the pulse. This fires as the driver leaves, which is exactly when the head unit suspends; without it the glass can stop halfway with no STOP sent. - A fresh listener registration replays the door's current state. That replay seeds the edge detector instead of triggering it, or a binder reconnect while the door stands open would close the windows on someone halfway out. - WinClose's 60-second cooldown, so reaching back into the car does not run a second pulse. - The service stops itself on a non-SWI69 generation, and the switch is disabled unless the process holds system uid — only the unstable flavor declares android.uid.system, so a stable build could otherwise offer a toggle whose every command would fail. This is the project's first write to the vehicle. README, SECURITY, AGENTS, CONTRIBUTING and DISCLAIMER all claimed the app never writes; that claim is retracted and scoped rather than quietly left standing. Untested on a car. The feature is off by default. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
07d76700e0
commit
444732438d
@@ -12,6 +12,7 @@ import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
@@ -60,6 +61,10 @@ public class MainActivity extends AppCompatActivity {
|
||||
private TextInputEditText tokenInput;
|
||||
private SwitchMaterial serviceSwitch;
|
||||
private SwitchMaterial autostartSwitch;
|
||||
private SwitchMaterial windowCloseSwitch;
|
||||
private CompoundButton.OnCheckedChangeListener windowCloseListener;
|
||||
private TextView windowCloseStatus;
|
||||
private TextView windowCloseLog;
|
||||
private TextView statusText;
|
||||
private Button testButton;
|
||||
private View connectionStatusRow;
|
||||
@@ -170,6 +175,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
refreshCallLog();
|
||||
refreshVehicle();
|
||||
refreshWifi();
|
||||
refreshWindowClose();
|
||||
uiHandler.postDelayed(this, 2_000L);
|
||||
}
|
||||
};
|
||||
@@ -210,6 +216,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
bindVehiclePane();
|
||||
bindWifiPane();
|
||||
bindWindowClose();
|
||||
|
||||
apiKeyLayout = abrpPane.findViewById(R.id.api_key_layout);
|
||||
apiKeyInput = abrpPane.findViewById(R.id.api_key_input);
|
||||
@@ -318,6 +325,48 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
private void bindWindowClose() {
|
||||
windowCloseSwitch = servicePane.findViewById(R.id.window_close_switch);
|
||||
windowCloseStatus = servicePane.findViewById(R.id.window_close_status);
|
||||
windowCloseLog = servicePane.findViewById(R.id.window_close_log);
|
||||
windowCloseListener = (button, enabled) -> {
|
||||
prefs.edit().putBoolean(WindowCloseService.KEY_ENABLED, enabled).apply();
|
||||
if (enabled) WindowCloseService.startIfEnabled(this);
|
||||
else stopService(new Intent(this, WindowCloseService.class));
|
||||
refreshWindowClose();
|
||||
};
|
||||
windowCloseSwitch.setChecked(prefs.getBoolean(WindowCloseService.KEY_ENABLED, false));
|
||||
windowCloseSwitch.setOnCheckedChangeListener(windowCloseListener);
|
||||
// A build that cannot reach the vehicle service would accept the toggle and then fail
|
||||
// every command, which reads as a broken feature rather than an inapplicable one.
|
||||
if (!WindowCloseService.canWriteToVehicle()) windowCloseSwitch.setEnabled(false);
|
||||
WindowCloseService.startIfEnabled(this);
|
||||
refreshWindowClose();
|
||||
}
|
||||
|
||||
private void refreshWindowClose() {
|
||||
if (windowCloseSwitch == null) return;
|
||||
boolean enabled = prefs.getBoolean(WindowCloseService.KEY_ENABLED, false);
|
||||
if (windowCloseSwitch.isChecked() != enabled) {
|
||||
// Detached first: setChecked re-enters the listener, which would write the pref
|
||||
// and restart the service on every one of these two-second refreshes.
|
||||
windowCloseSwitch.setOnCheckedChangeListener(null);
|
||||
windowCloseSwitch.setChecked(enabled);
|
||||
windowCloseSwitch.setOnCheckedChangeListener(windowCloseListener);
|
||||
}
|
||||
FirmwareInfo.Gen generation = FirmwareInfo.INSTANCE.getGeneration();
|
||||
if (!WindowCloseService.canWriteToVehicle()) {
|
||||
windowCloseStatus.setText(R.string.window_close_no_system_uid);
|
||||
} else if (!enabled) {
|
||||
windowCloseStatus.setText(R.string.window_close_stopped);
|
||||
} else if (generation != FirmwareInfo.Gen.UNKNOWN && generation != FirmwareInfo.Gen.SWI69) {
|
||||
windowCloseStatus.setText(R.string.window_close_unsupported);
|
||||
} else {
|
||||
windowCloseStatus.setText(WindowCloseService.statusResource());
|
||||
}
|
||||
windowCloseLog.setText(WindowCloseService.eventLog());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
Reference in New Issue
Block a user