Skip to content

Latest commit

 

History

History
256 lines (217 loc) · 15.5 KB

CONTRIBUTING.md

File metadata and controls

256 lines (217 loc) · 15.5 KB

Contributing to VirtualAP

A feature that does not exist is better than a broken one. VirtualAP runs as root on rooted phones, on Wi-Fi chips whose drivers disagree about basic things, so a patch that works on your phone and breaks on someone else's is a regression, not a contribution. And ten lines that do the job beat a hundred that do the same job: delete before you add, reuse before you write.

What must hold

The rules for anyone changing this repository, agents included, are in AGENTS.md: the style, the commit format, the choke points and the hard constraints. In short: Android only, the engine is single-threaded C on musl that talks to the kernel itself, split one concern per module, the app runs on Android 8, and the binaries come only from scripts/build-static.sh and, for virtualap, the root Makefile.

VirtualAP runs on Qualcomm, Broadcom FullMAC (Samsung) and MediaTek chips. A fix for one chip's quirk is accepted only when the backend adapts to it at runtime, by detection, a conditional path or a fallback, without changing behaviour on the others; nl80211_sta_freq reading the associated BSS's frequency because Samsung omits the channel, and ensure_5g_ir firing only when the phy reports NO-IR, are the pattern. If the fix cannot be gated that way, it belongs in a fork. Test on a real phone, there is no emulator for a Wi-Fi chip, and say in your PR which devices, drivers, bands and upstreams you tested on; an untested claim counts as untested.

Building

./scripts/build-static.sh    # from the repository root: both arches, needs Docker
./build.sh [release]         # from Android/: the APK, needs JDK 17 or newer, ANDROID_HOME and musl-cross gcc

What the scripts do, and what CI does, is in the Building section of How-It-Works.md. A release is a tag: make bump NEW=x.y.z, commit it as VirtualAP: bump vX.Y.Z, then push main and the tag vX.Y.Z.

Code style

The four rules are in AGENTS.md, Style. On top of them:

  • Backend: coreutils are $ECHO, $GREP, $SED and friends, never bare, and never quoted. Output is log, warn, error. Subcommands are cmd_*, Droidspaces helpers ds_*, radio probes phy_*, policy pick_* and resolve_*. Teardown mirrors setup step for step and every step tolerates absence. Each daemon logs to its own file under logs/.
  • App: state lives in a ViewModel, not in a stateful composable and not in a util singleton. Lists render with LazyColumn and stable keys. Colours come from MaterialTheme.colorScheme, type from MaterialTheme.typography, timings from AnimationUtils, every other visual value from DESIGN.md. Any value that reaches a root shell goes through Backend.quote() or an allow-list validator.

Commits are signed off and prefixed as AGENTS.md, Commits, says.

Translations

Translators work on Weblate, which commits to the values-<lang>/ folders; a pull request touches only the English in res/values/. How the components are set up is in the Translations section of How-It-Works.md.

Adding a string:

  • Put it in strings.xml under the comment for its screen, or in plurals.xml if a count changes its wording. Kotlin reads it with stringResource, or getString outside composition.
  • Placeholders are positional, %1$s, so a translation can reorder them. Say what each one is in a comment directly above the string, which Weblate shows to the translator; do the same for a short word that could mean two things.
  • One whole phrase per string. Never glue translated pieces together.
  • Paths, commands, preference keys and what the engine prints stay in code, in English. A value in the file that no language changes, a product name or an example address, is translatable="false".

Reuse inventory

Grep this list before you write anything new. If something close exists, extend it rather than adding a sibling. Android paths are relative to Android/app/src/main/java/com/virtualap/app/; engine modules are paths under src/, each folder's header under src/include/<folder>/. This list answers "what do I call"; DESIGN.md answers "what should it look like" when nothing here fits. The shared components were ported from Droidspaces; when a caller for one of its other components appears, copy the upstream file rather than writing a new one.

Forms and inputs:

  • DsDropdown(label, selected, options, displayName, onSelect, ...) in ui/component/DsDropdown.kt: any select field. Never hand-roll ExposedDropdownMenuBox.
  • DsTextFieldDefaults.colors() in ui/component/DsTextFieldDefaults.kt: every OutlinedTextField.
  • rememberClearFocus(), which DsDialog uses, and ClearFocusOnClickOutside, the main screen's root, in ui/util/FocusUtils.kt: drop the keyboard on an outside tap.

Dialogs and sheets:

  • DsDialog(onDismiss, modifier, footer) { } in ui/component/DsDialog.kt: every dialog. Never set a width, padding or scroll.
  • DialogFooterRow(dismissLabel, confirmLabel, onDismiss, onConfirm, confirmEnabled) in ui/component/DialogFooterRow.kt: the two buttons in a dialog with a choice, in the footer slot.
  • DialogCloseButton(onClick, enabled) in ui/component/DialogCloseButton.kt: the 36dp close square in a header row, for content that closes from the top.
  • LogActionRow(logs, isBlocking, onClear) in ui/component/LogActionRow.kt: the Clear and Copy row above a log console; onClear = null gives Copy alone.
  • DeviceRow, DeviceSheet(title, onDismiss, content), BlockedList, AllowedList, BlockedDevicesSheet, AllowedDevicesSheet and rememberDeviceAction(reload) in ui/component/DeviceList.kt: a device with its action, the sheet they sit in, the two lists, and running a change to them with the failure said out loud.
  • AddDeviceDialog and AllowOnlyDialog in ui/component/AddDeviceDialog.kt: the MAC field that takes only hex digits, and who drops off when only allowed devices can join.
  • Caption(text) in ui/component/Caption.kt: a line of secondary text.
  • The Wi-Fi QR sheet, the devices sheet and the logs sheet are private to ui/screen/MainScreen.kt, the About dialog and the language picker to ui/screen/SettingsScreen.kt. Do not import or copy them.

Bars, setup, feedback:

  • PrimaryActionBottomBar(label, icon, onClick, ...) in ui/component/PrimaryActionBottomBar.kt: the Start and Stop bar. The overload taking a content slot is for a button that swaps its contents.
  • SetupPage, SetupFrame, SetupHero, SetupActionBar in ui/component/SetupHero.kt: every screen of the setup flow, the welcome pager, the root check and the installer. See DESIGN.md, "The setup flow".
  • PullToRefreshWrapper(onRefresh) { } in ui/component/PullToRefreshWrapper.kt: any pull to refresh screen body.
  • ToggleCard in ui/component/ToggleCard.kt: a switch row in its own card, the main screen's options. SwitchItem in ui/component/SwitchItem.kt: the flat switch row inside a grouped surface, the Settings screen.
  • StatusPill(label, color) in ui/component/StatusPill.kt: any small status chip. SectionHeader(text) in ui/component/SectionHeader.kt: a heading above a group of cards.
  • CardContentPadding, CardHeaderHeight in ui/component/CardMetrics.kt: any card with a title-and-pill header, so the dividers line up.
  • LoadingIndicator(size, color) with LoadingSize, and FullScreenLoading(message), in ui/util/LoadingIndicator.kt: every spinner and every whole-screen loading state.
  • TerminalConsole(logs, isProcessing, maxHeight) and ShimmerAnimation(enabled) { } in ui/component/TerminalConsole.kt: the scrolling log view and its frame.

Theme:

  • VirtualAPTheme(darkTheme, dynamicColor, amoledMode, themePalette) in ui/theme/Theme.kt: the one theme root, applied in MainActivity.
  • rememberThemeState() and ThemeState in ui/theme/ThemeStateHolder.kt: the live theme preferences.
  • ThemePalette in ui/theme/Color.kt: adding an accent palette, here and nowhere else. Theme.kt and Color.kt are the only files that name a colour literally.
  • MaterialTheme.typography.* and JetBrainsMono in ui/theme/Type.kt: all text styles, and the mono font for log and code text.
  • AnimationUtils in util/AnimationUtils.kt: the tween specs. Never a literal tween(300).
  • AccentColorPicker and ColorPaletteSwatch in ui/component/: the palette picker.
  • There is no spacing or shape token object; the numbers live in DESIGN.md and are written as literal dp.

Navigation:

  • Screen and the when over it in MainActivity.kt: the one place a top-level screen is chosen, the welcome flag first, then root and install state, then the Settings flag. A new screen goes there.

Shell, root and the backend:

  • Backend.quote(value) and Backend.startAp in util/Backend.kt: every dynamic value that reaches a root command, and the engine's command prefix (with its fallback to the script an older release extracted, until the setup flow replaces it).
  • APManager.getStatus/start/stop/getInterfaces/getCaps/isInstalled in util/APManager.kt: driving virtualap, and getContainers/parseContainers, which ask Droidspaces for its running containers directly. Never assemble one of these commands by hand.
  • Hotspot.start(cfg)/stop()/refresh(), phase, status, actionLogs in util/Hotspot.kt: starting or stopping the AP from anywhere and reading the session state; also posts the running notification and wakes the tile.
  • APConfig with isValid(), isValidIpv4, isValidDnsList, channelsForBand in util/APConfig.kt: the saved hotspot config, the one start validation, and the address checks the fields share with it.
  • BackendLogger and classifyLine(line) in util/BackendLogger.kt: the log sink the AP calls take, and the [ERROR]/[WARN] level tagging.
  • PreferencesManager in util/PreferencesManager.kt: the app's own settings. APManager.loadConfig/saveConfig: the hotspot config, read and written whole in ap.conf. Constants in util/Constants.kt: every path and preference key.
  • RootChecker.checkRootAccess(reprompt) and RootStatus in util/RootChecker.kt; VirtualAPInstaller.deviceArch/bundledPayloadVersion/payloadUpdateAvailable/install in util/VirtualAPInstaller.kt; ModuleInstaller.install in util/ModuleInstaller.kt, the boot module; QrCodeGenerator.wifiPayload/encode in util/QrCodeGenerator.kt, the only zxing caller.
  • HotspotTileService, HotspotStopReceiver and HotspotBootReceiver: the Quick Settings toggle, the notification's Stop action, and the boot module's word that it started a hotspot. None hold state of their own.
  • LocaleHelper.availableLanguages/currentLanguage/changeLanguage in util/LocaleHelper.kt: the app's language, the only caller of AppCompatDelegate.setApplicationLocales.
  • AppViewModel owns the welcome flag, root status and install state; APViewModel owns the editable config, the interface and container lists and the tailed log, and forwards start and stop to Hotspot. The 3 s status poll lives in MainScreen, bound to its lifecycle.
  • The global libsu configuration lives in VirtualAPApplication.kt, and only there.

Engine (src/):

  • core/: proc (every program run, the pid files, and the lock that lets one start or stop run at a time), io (the log: vap_log, vap_warn, vap_error, log_stamp; read_file, write_file, write_atomic; the parsers valid_ip4, prefix_parse, subnet_from_gw, and csv_each for the comma lists of -d).
  • cli/: options (the vap_keys table, opt_set, opts_parse, print_usage), conf (ap.conf and run.state).
  • net/: nl (the rtnetlink transport, nl_dump, and the namespace helpers netns_open, in_netns), link (links, addresses and neighbours), route (routes, policy rules, and netd's tables: upstream_resolve, upstream_v6_iface), ipt/, kept apart because on musl the kernel's netfilter headers and libc's networking headers cannot meet in one file: ipt (the ip_tables engine), ipt_rules (FORWARD, MASQUERADE, the presence check, the NAT probe, ipt_bin, the TTL fix).
  • radio/: driver (nl80211 over genetlink: create and delete ap0, the phy, the station's frequency, the width; the wpa control socket; wifi_mac, the factory MAC), channel (band, channel and width policy, and ensure_5g_ir).
  • mode/: ap (ap0, the daemons, radio planning, the signal hold both modes share, and hostapd and dnsmasq: their configs and starts, the client count), routed (with the pinned policy rules both families use), ipv6 (ipv6_decide, setup, teardown, NAT66 and the shared /64 with its client discovery), managed (the Droidspaces container: its pid, the OpenWrt provisioning, the RPS masks), maclist (the blocked and allowed devices' files, which are hostapd's deny_mac_file and accept_mac_file, and telling a running hostapd).
  • monitor/: monitor (the daemon's loop), upstream (reprobe).
  • cmd/: the commands the app calls, dispatched from main.c: start (start and stop), status (the read-only ones: status, clients, interfaces, caps) and block (block, unblock, blocked, allow, disallow, allowed, allow-only).

Opening a PR

Fork, work in a branch, open the PR against main, and stay responsive: an unanswered PR is closed, and feedback is addressed in the same PR, not a new one. There is no CLA; by submitting you agree that your contribution may be distributed under the project's licence.

Every PR says:

  1. What real-world problem it solves. "I wanted this" is not one; say what breaks, fails or is missing for real users on real hardware.
  2. Screenshots or terminal output showing it working.
  3. The tested environments: for the app, device, Android version and root provider; for the backend, device, SoC and Wi-Fi chip, driver, band and width, upstream (mobile data, Wi-Fi, VPN), and whether managed mode was exercised.
  4. For UI changes, the DESIGN.md rules you followed, and which one you deviated from and why. A radius or a colour that disagrees with DESIGN.md without a reason is sent back.

What is merged: fixes with a reproduction and a verified resolution, features validated across devices, security hardening, measured performance improvements, deletions, and documentation corrections. What is rejected: an engine change that spawns a tool for what netlink or the kernel's own files can do, or that grows a module past its one concern; a prebuilt or dynamically linked binary; a feature no real user has reported or that only works on one hardware configuration; code its author cannot explain; an app change that breaks Android 8; a second copy of something in the inventory; any dynamic value reaching a root shell unquoted; anything that regresses what worked, however useful the new behaviour.

A merged feature is yours going forward: when a new Android version or driver breaks it, you are expected to fix it, and a feature whose author is unreachable is removed. A contributor whose PRs keep being rejected for the same reasons, no real problem, untested, or padding the codebase, is blocked; there is no strike count, the decision is the maintainer's.

Security

Anything that lets a hotspot client, or a value typed into the app, reach the root shell unquoted is a vulnerability. Do not open a public issue; report it privately to droidcasts@protonmail.com or t.me/ravindu with a reproduction, the affected configurations and the device or driver, and hold public disclosure until a fix is out. Hardening patches are reviewed first.