Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9d84dc6d15 | ||
|
|
418883beb0 | ||
|
|
e52d7f01fc | ||
|
|
6b55bec419 |
@@ -79,9 +79,17 @@ analyser's peak, bass, mid, treble and rms, and a result line. Levels only, no s
|
|||||||
to move for music to count as heard. Ask what was playing when the check ran, and whether the
|
to move for music to count as heard. Ask what was playing when the check ran, and whether the
|
||||||
music kept playing and any prompt came up.
|
music kept playing and any prompt came up.
|
||||||
|
|
||||||
|
## Update checks
|
||||||
|
|
||||||
|
`fetch-logs` also brings `update-check-YYYYMMDD-HHMMSS.txt` (each Settings → Check for updates,
|
||||||
|
`UpdateHook`, 2.43.5 on): the networks Android sees, whether the server's name resolves, the
|
||||||
|
result and, on a failure, whether `www.gstatic.com/generate_204` answers (204: the internet
|
||||||
|
works, so look at the server). A report written offline arrives once the car is back online, or
|
||||||
|
is on a USB stick that was plugged in.
|
||||||
|
|
||||||
## Rules
|
## Rules
|
||||||
|
|
||||||
- Recordings and checks are the car's data: `logs/`, `/signal-recording-*.txt` and
|
- Recordings and checks are the car's data: `logs/`, `/signal-recording-*.txt` and
|
||||||
`/media-probe-*.txt`, `/sound-probe-*.txt` are gitignored. Never
|
`/media-probe-*.txt`, `/sound-probe-*.txt`, `/update-check-*.txt` are gitignored. Never
|
||||||
commit, publish or upload them anywhere.
|
commit, publish or upload them anywhere.
|
||||||
- Findings that change what the project knows go into a `SPECS.md` done-log entry, as usual.
|
- Findings that change what the project knows go into a `SPECS.md` done-log entry, as usual.
|
||||||
|
|||||||
@@ -47,3 +47,4 @@ mise.local.toml
|
|||||||
/signal-recording-*.txt
|
/signal-recording-*.txt
|
||||||
/media-probe-*.txt
|
/media-probe-*.txt
|
||||||
/sound-probe-*.txt
|
/sound-probe-*.txt
|
||||||
|
/update-check-*.txt
|
||||||
|
|||||||
@@ -77,12 +77,12 @@ Repository: `ssh://git@git.stinnesbeck.com:2222/nils/mg4.git` (remote `origin`),
|
|||||||
|
|
||||||
| Tab | Contents |
|
| Tab | Contents |
|
||||||
|---|---|
|
|---|---|
|
||||||
| Overview | value tiles (battery, range, range/usage/energy since start, 5-min averages of range, usage, power, speed), vehicle info (odometer, lease allowance and the odometer against it), tyre pressures; read every 0.2 s on a background thread. Styles (Settings → Overview style): Tiles, Gauges (`GaugeView` needles), Cockpit (`RingView` rings, `TraceView` power trace), Retro (`RetroView`, seven-segment VFD), Futuristic (`FlowView`, animated energy flow), Sci-fi (`SciFiView`, starship console), Cartoon (`CartoonView`), MG (`OctagonView`, octagonal dials after the classic MG dashboards), and on `ClusterCanvasView`: Minimal, Terminal, Nixie tubes, Chronograph, Grid (`GridView`, neon lines over a moving grid floor, power as a light-cycle trail from `ClusterValues.powerTrail`), Grid with map (the same `GridView` over the roads round the car, top-down: GPS while it is shown, tiles from the server's `/v1/map/roads` through `MapRoads`, cached in `files/map`; `RoadTile`, `MapGeometry`; the map is `MapLayerView`, a hardware layer drawn once and moved and turned by the GPU every display frame), Time circuits (`TimeCircuitsView`, the time machine's LED rows with `Segments14` letters and a flux capacitor), Quest (`QuestView`, a fantasy game interface), Visor (`VisorView`, a helmet display with a motion tracker of the power trail), Empire (`EmpireView`, a strategy game with an isometric world and ages by odometer, `EmpireAge`), Día de Muertos (`MuertosView`, an ofrenda: papel picado, candles, a calavera in a ring of marigolds), Halloween (`HalloweenView`, a jack-o'-lantern, a potion flask, a tombstone on a graveyard hill), both counting with `Tally`, the pumpkin's light following the music on screen (`MusicTap`, `MusicPulse`: Android's audio analyser, levels only; Bluetooth and CarPlay, not the radio); the drawn styles share `ClusterValues`. A style shown in its own palette (Sci-fi, Cartoon, Nixie, Time circuits, Quest, Empire, Día de Muertos, Halloween; Retro, Terminal, Grid and Visor with "Original") gives the whole app its colours (`StylePalette`, `res/values/style_palettes.xml`) instead of the accent colour. A button in the navigation's header hides the navigation for a full-width Overview (`PREF_OVERVIEW_FULLSCREEN`); a swipe in from the left edge (`EdgeSwipe`) brings it back; without the app's own full screen the car's sidebar takes that edge, so a tab at the left edge (`edge_tab`) is tapped or swiped instead. Pages change only by the navigation (the pager's own swiping is off) |
|
| Overview | value tiles (battery, range, range/usage/energy since start, 5-min averages of range, usage, power, speed), vehicle info (odometer, lease allowance and the odometer against it), tyre pressures; read every 0.2 s on a background thread. Styles (Settings → Overview style): Tiles, Gauges (`GaugeView` needles), Cockpit (`RingView` rings, `TraceView` power trace), Retro (`RetroView`, seven-segment VFD), Futuristic (`FlowView`, animated energy flow), Sci-fi (`SciFiView`, starship console), Cartoon (`CartoonView`), MG (`OctagonView`, octagonal dials after the classic MG dashboards), and on `ClusterCanvasView`: Minimal, Terminal, Nixie tubes, Chronograph, Grid (`GridView`, neon lines over a moving grid floor, power as a light-cycle trail from `ClusterValues.powerTrail`), Grid with map (the same `GridView` over the roads round the car, top-down: GPS while it is shown, tiles from the server's `/v1/map/roads` through `MapRoads`, cached in `files/map`; `RoadTile`, `MapGeometry`; the map is `MapLayerView`, a hardware layer drawn once and moved and turned by the GPU every display frame), Time circuits (`TimeCircuitsView`, the time machine's LED rows with `Segments14` letters and a flux capacitor), Quest (`QuestView`, a fantasy game interface), Visor (`VisorView`, a helmet display with a motion tracker of the power trail), Empire (`EmpireView`, a strategy game with an isometric world and ages by odometer, `EmpireAge`), Día de Muertos (`MuertosView`, an ofrenda: papel picado, candles, a calavera in a ring of marigolds), Halloween (`HalloweenView`, a jack-o'-lantern, a potion flask, a tombstone on a graveyard hill), both counting with `Tally`, the pumpkin's light flaring on the kick drum while on screen, when "Pumpkin light follows the music" is on (off by default, `PREF_MUSIC_LIGHT`; `MusicTap`, `MusicPulse`: Android's audio analyser, 40–120 Hz, jumps not levels; Bluetooth and CarPlay, not the radio); the drawn styles share `ClusterValues`. A style shown in its own palette (Sci-fi, Cartoon, Nixie, Time circuits, Quest, Empire, Día de Muertos, Halloween; Retro, Terminal, Grid and Visor with "Original") gives the whole app its colours (`StylePalette`, `res/values/style_palettes.xml`) instead of the accent colour. A button in the navigation's header hides the navigation for a full-width Overview (`PREF_OVERVIEW_FULLSCREEN`); a swipe in from the left edge (`EdgeSwipe`) brings it back; without the app's own full screen the car's sidebar takes that edge, so a tab at the left edge (`edge_tab`) is tapped or swiped instead. Pages change only by the navigation (the pager's own swiping is off) |
|
||||||
| Consumption / Charging | period totals, daily log, charging sessions and curve |
|
| Consumption / Charging | period totals, daily log, charging sessions and curve |
|
||||||
| Live data | on/off, ABRP API key and user token, upload frequency |
|
| Live data | on/off, ABRP API key and user token, upload frequency |
|
||||||
| Server | URL, pairing by QR, ingest token, installation ID (read-only), config import |
|
| Server | URL, pairing by QR, ingest token, installation ID (read-only), config import |
|
||||||
| Settings | drive mode (Eco, Normal, Sport, Snow, Custom; the lit one is what the car reports; changes only in P at a standstill, `DriveModeWrite`; "Set at start" sets the last confirmed choice again when the service starts with the head unit), full screen, voice key, Overview style with the accent colour beside it (offered only for styles drawn in it, `OverviewStyle.usesAccent`; Retro, Terminal, Grid (and Grid with map, sharing Grid's choice) and Visor add "Original" for their own palette, `hasOriginal`), tyre unit, battery and charging price (one card on wide screens), version, update check, install from USB, About |
|
| Settings | drive mode (Eco, Normal, Sport, Snow, Custom; the lit one is what the car reports; changes only in P at a standstill, `DriveModeWrite`; "Set at start" sets the last confirmed choice again when the service starts with the head unit), full screen, voice key, Overview style with the accent colour beside it (offered only for styles drawn in it, `OverviewStyle.usesAccent`; Retro, Terminal, Grid (and Grid with map, sharing Grid's choice) and Visor add "Original" for their own palette, `hasOriginal`), tyre unit, battery and charging price (one card on wide screens), version, update check, install from USB, About |
|
||||||
| Logs | signal recorder (`SignalRecorder`/`SignalRecording`: every property and vendor getter via `VendorSurfaceProbe.capture`, again and again for 3 minutes, plus change events of the driver-assistance block it subscribes to, `EVHardware.listenToProperties` with `AssistBlock`, and steering-wheel key broadcasts; lists what changed, rarest first; saved to the app, a USB stick and the server, through `LogOutbox`, which sends it again later when the car is offline; how to find where the car publishes something), music-sources check (`MediaProbe`: audio players and the active media sessions, CarPlay's and Bluetooth's among them, with their song, and the media browser services by name — never connected to: binding them stopped the music in 2.42.0; saved and sent like a recording), sound check (`SoundProbe`, `SoundLevels`: on a tap, 10 seconds of levels from Android's audio analyser, to learn whether it hears what plays; saved and sent like a recording), update log (every install step, with the platform's words), upload log |
|
| Logs | signal recorder (`SignalRecorder`/`SignalRecording`: every property and vendor getter via `VendorSurfaceProbe.capture`, again and again for 3 minutes, plus change events of the driver-assistance block it subscribes to, `EVHardware.listenToProperties` with `AssistBlock`, and steering-wheel key broadcasts; lists what changed, rarest first; saved to the app, a USB stick and the server, through `LogOutbox`, which sends it again later when the car is offline; how to find where the car publishes something), music-sources check (`MediaProbe`: audio players and the active media sessions, CarPlay's and Bluetooth's among them, with their song, and the media browser services by name — never connected to: binding them stopped the music in 2.42.0; saved and sent like a recording), sound check (`SoundProbe`, `SoundLevels`: on a tap, 10 seconds of levels from Android's audio analyser, to learn whether it hears what plays; saved and sent like a recording), update log (every check and install step, with the platform's words; a check also writes down the networks, the server's name lookup and, when it fails, an internet test, `UpdateNetworkCheck`, `UpdateDiagnosis`, and saves a report like a recording), upload log |
|
||||||
|
|
||||||
Key classes (`app/src/main/java/com/evsuite/abrp/`): `AbrpUploadService` (foreground service,
|
Key classes (`app/src/main/java/com/evsuite/abrp/`): `AbrpUploadService` (foreground service,
|
||||||
15 s tick), `TelemetryUploader` (+ `TelemetryQueue`, persisted), `TelemetryPayload` (server
|
15 s tick), `TelemetryUploader` (+ `TelemetryQueue`, persisted), `TelemetryPayload` (server
|
||||||
|
|||||||
@@ -89,7 +89,11 @@ platform's own words, is on the Logs tab under "Updates".
|
|||||||
| `Installation failed: INSTALL_FAILED_… The APK is in Downloads.` | The package manager's own words. A signature error means the APK was not signed by `build-car`. |
|
| `Installation failed: INSTALL_FAILED_… The APK is in Downloads.` | The package manager's own words. A signature error means the APK was not signed by `build-car`. |
|
||||||
| `… is in Downloads — tap the file to install` | A session could not start; install from Downloads by hand. |
|
| `… is in Downloads — tap the file to install` | A session could not start; install from Downloads by hand. |
|
||||||
|
|
||||||
On the car's Logs tab, or with a cable: `adb logcat -s EVABRP.Update OtaUpdater`.
|
On the car's Logs tab, or with a cable: `adb logcat -s EVABRP.Update OtaUpdater`. Each check
|
||||||
|
writes down the networks Android sees, whether the server's name resolves, its result and, when
|
||||||
|
it fails, whether `www.gstatic.com/generate_204` answers, which tells a SIM without data from a
|
||||||
|
server that is down. That report also goes to a USB stick and, once online, to the server
|
||||||
|
(`update-check-*.txt`, read with `fetch-logs`). No address or token is written.
|
||||||
|
|
||||||
## Why a PackageInstaller session, not `pm install`
|
## Why a PackageInstaller session, not `pm install`
|
||||||
|
|
||||||
|
|||||||
@@ -140,6 +140,10 @@ tyre pressures, GPS (lat, lon, elevation, heading) and the is_* flags. It does *
|
|||||||
confirmed car facts, app structure, UI conventions, build/test/ship, documents. It replaces
|
confirmed car facts, app structure, UI conventions, build/test/ship, documents. It replaces
|
||||||
upstream's EVABRPUploader text. The test emulator is now in the flake: `nix run .#car-emulator`
|
upstream's EVABRPUploader text. The test emulator is now in the flake: `nix run .#car-emulator`
|
||||||
(Android 9 AOSP at 1920×720, 160 dpi; the car build installs as the system user — checked).
|
(Android 9 AOSP at 1920×720, 160 dpi; the car build installs as the system user — checked).
|
||||||
|
- 2026-11-02 — App 2.44.0: **the pumpkin light follows the bass, and only when switched on** (owner: "more focussed on the bass", "optional via a settings flag"). `MusicPulse` now reads the kick drum's band (40–120 Hz, was 20–250 Hz) and lights only on a jump since the last reading, against the biggest jumps of the last 4 s; a jump under a fifth of that, or under half the bass's average level, lights nothing. So kicks flash, and a held note, a wobbling bass line or a swelling note stay dark (unit tests with made-up patterns). It flares at once and falls in 0.2 s. New switch under the Overview style, shown only for Halloween: "Pumpkin light follows the music" (`PREF_MUSIC_LIGHT`), **off by default**; off, the analyser never starts. Tuned on made-up signals only: no Bluetooth or CarPlay sound report from the car has arrived yet. Next: now playing (title, artist, source) from the media sessions, in its own version. Tested: unit tests, lint, emulator (switch off by default and the analyser thread absent; on, it runs only on the Overview; a throwaway build playing a pulsing test tone: the glow flares with the switch on, and stays exactly still with it off). With Halloween chosen, the Settings card now scrolls a little to reach the tyre unit. Not tried on the car.
|
||||||
|
- 2026-11-01 — App 2.43.5 published (`car-2.43.5`).
|
||||||
|
- 2026-11-01 — App 2.43.5: **update checks log what happens** (`UpdateNetworkCheck`, `UpdateDiagnosis`; owner: updating from the car fails, "Can we log what happens? Maybe my SIM card has no data left"). Each check on Settings writes to the Logs tab: the networks Android sees (type, in use, internet, validated, roaming), whether the server's name resolves, how a failure happened, in words from its type or status only, and how many reports wait. On a failure it also asks `https://www.gstatic.com/generate_204`, the one request to anyone but the car server, to tell no data from a server that is down. A report goes to a USB stick and, when online, the server (`update-check-*.txt`; only the newest waits, so it cannot push out a recording). A check at start logs only a failure. The update log keeps 40 lines, not 10. An out-of-data SIM would also explain why the Bluetooth and CarPlay sound reports did not arrive; not confirmed. Tested: unit tests, lint, emulator with a fake server (online: the name fails, the internet test says it works; airplane mode: both fail, "none in use"; the real build installs and starts, its check not run there, having no server). Not tried on the car.
|
||||||
|
- 2026-11-01 — App 2.43.4 published (`car-2.43.4`).
|
||||||
- 2026-11-01 — App 2.43.4: **the Halloween pumpkin's light follows the music** (`MusicTap`, `MusicPulse`; owner: "make the light in the pumpkin react to the equalizer/sound of the music"). The bass, 25 times a second off the main thread, drives the glow and brightens the carving on the beat; yellow and green still mean drawing and regenerating, the embers still the power, and no signal leaves the light as it was. It listens only with the app in front, on the Overview, in Halloween. The owner reports the sound check worked with Bluetooth and CarPlay; those two reports never reached the server (why not is unexplained), so their levels are unseen and the pulse's feel is untuned for the car. Tested: unit tests, lint, emulator (a tone already playing when the analyser starts: the carving and glow move with it; no sound: unchanged; the analyser is released on another tab and when the app leaves the front; no crash). Not tried on the car; how it looks there, and its effect on the head unit over a long drive, are unknown.
|
- 2026-11-01 — App 2.43.4: **the Halloween pumpkin's light follows the music** (`MusicTap`, `MusicPulse`; owner: "make the light in the pumpkin react to the equalizer/sound of the music"). The bass, 25 times a second off the main thread, drives the glow and brightens the carving on the beat; yellow and green still mean drawing and regenerating, the embers still the power, and no signal leaves the light as it was. It listens only with the app in front, on the Overview, in Halloween. The owner reports the sound check worked with Bluetooth and CarPlay; those two reports never reached the server (why not is unexplained), so their levels are unseen and the pulse's feel is untuned for the car. Tested: unit tests, lint, emulator (a tone already playing when the analyser starts: the carving and glow move with it; no sound: unchanged; the analyser is released on another tab and when the app leaves the front; no crash). Not tried on the car; how it looks there, and its effect on the head unit over a long drive, are unknown.
|
||||||
- 2026-10-31 — Sound check on the car (2.43.3), radio: `com.saicmotor.radio` playing, `isMusicActive` false, analyser enabled without error and silent for all 10 seconds (peak 0.00, -9600 mB). The audio analyser does not hear the radio. The owner ran Bluetooth and CarPlay too; those reports have not reached the server yet (the outbox sends oldest first and stops at the first failure, retrying while the service runs).
|
- 2026-10-31 — Sound check on the car (2.43.3), radio: `com.saicmotor.radio` playing, `isMusicActive` false, analyser enabled without error and silent for all 10 seconds (peak 0.00, -9600 mB). The audio analyser does not hear the radio. The owner ran Bluetooth and CarPlay too; those reports have not reached the server yet (the outbox sends oldest first and stops at the first failure, retrying while the service runs).
|
||||||
- 2026-10-31 — App 2.43.3 published (`car-2.43.3`).
|
- 2026-10-31 — App 2.43.3 published (`car-2.43.3`).
|
||||||
|
|||||||
@@ -262,8 +262,9 @@ the range ("here lies … km"), and the bats are the range too, one per 50 km; P
|
|||||||
gravestones, the one engaged lit. The moon holds the clock, a sign hanging from a cobweb has trip,
|
gravestones, the one engaged lit. The moon holds the clock, a sign hanging from a cobweb has trip,
|
||||||
usage, climate and odometer, and the hill along the bottom is the last two minutes of power. While
|
usage, climate and odometer, and the hill along the bottom is the last two minutes of power. While
|
||||||
you drive the bats fly, the potion bubbles and the ghost floats (where there is room for it, as on
|
you drive the bats fly, the potion bubbles and the ghost floats (where there is room for it, as on
|
||||||
this screen). With Bluetooth or CarPlay music playing, the pumpkin's glow swells and its carving
|
this screen). With "Pumpkin light follows the music" on (Settings, shown with this style; off by
|
||||||
brightens on the beat; the radio cannot be heard, so it burns as usual then. The app turns the
|
default) and Bluetooth or CarPlay music playing, the pumpkin's glow flares and its carving
|
||||||
|
brightens on each kick drum; the radio cannot be heard, so it burns as usual then. The app turns the
|
||||||
pumpkin's orange with it.
|
pumpkin's orange with it.
|
||||||
|
|
||||||

|

|
||||||
|
|||||||
+2
-2
@@ -34,8 +34,8 @@ android {
|
|||||||
applicationId "com.stinnesbeck.nilsmg4"
|
applicationId "com.stinnesbeck.nilsmg4"
|
||||||
minSdk 27
|
minSdk 27
|
||||||
targetSdk 36
|
targetSdk 36
|
||||||
versionCode 157
|
versionCode 159
|
||||||
versionName "2.43.4"
|
versionName "2.44.0"
|
||||||
|
|
||||||
// Nothing about the server ships in the APK: its URL and ingest token are entered in
|
// Nothing about the server ships in the APK: its URL and ingest token are entered in
|
||||||
// the app's Server tab (ServerConfig), and the database is only reachable by the server.
|
// the app's Server tab (ServerConfig), and the database is only reachable by the server.
|
||||||
|
|||||||
@@ -85,6 +85,12 @@ final class LogOutbox {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Removes what waits under names starting with [prefix]. */
|
||||||
|
static synchronized void dropWaiting(Context context, String prefix) {
|
||||||
|
File dir = new File(context.getFilesDir(), DIR);
|
||||||
|
for (String name : waiting(dir)) if (name.startsWith(prefix)) new File(dir, name).delete();
|
||||||
|
}
|
||||||
|
|
||||||
/** Sends what waits, unless the last attempt failed less than {@link #RETRY_MS} ago. Blocking:
|
/** Sends what waits, unless the last attempt failed less than {@link #RETRY_MS} ago. Blocking:
|
||||||
* call it off the main thread. */
|
* call it off the main thread. */
|
||||||
static void sendIfDue(Context context) {
|
static void sendIfDue(Context context) {
|
||||||
|
|||||||
@@ -215,6 +215,8 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
/** Whether the Overview hides the navigation (the button in the navigation's header). */
|
/** Whether the Overview hides the navigation (the button in the navigation's header). */
|
||||||
static final String PREF_OVERVIEW_FULLSCREEN = "overview_fullscreen";
|
static final String PREF_OVERVIEW_FULLSCREEN = "overview_fullscreen";
|
||||||
|
/** The Halloween pumpkin's light follows the music; off by default, so the analyser stays off. */
|
||||||
|
static final String PREF_MUSIC_LIGHT = "music_light";
|
||||||
|
|
||||||
/** True while the Overview is full screen: the navigation hidden, the edge swipe armed. */
|
/** True while the Overview is full screen: the navigation hidden, the edge swipe armed. */
|
||||||
private boolean overviewFull;
|
private boolean overviewFull;
|
||||||
@@ -1223,6 +1225,12 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
bindDriveMode();
|
bindDriveMode();
|
||||||
bindOverviewStyle();
|
bindOverviewStyle();
|
||||||
bindAccentColor();
|
bindAccentColor();
|
||||||
|
SwitchMaterial musicLight = settingsPane.findViewById(R.id.music_light_switch);
|
||||||
|
musicLight.setChecked(prefs.getBoolean(PREF_MUSIC_LIGHT, false));
|
||||||
|
musicLight.setOnCheckedChangeListener((btn, checked) -> {
|
||||||
|
prefs.edit().putBoolean(PREF_MUSIC_LIGHT, checked).apply();
|
||||||
|
updateMusicTap();
|
||||||
|
});
|
||||||
fullScreenSwitch = settingsPane.findViewById(R.id.full_screen_switch);
|
fullScreenSwitch = settingsPane.findViewById(R.id.full_screen_switch);
|
||||||
fullScreenSwitch.setChecked(UploadSettings.fullScreen(prefs));
|
fullScreenSwitch.setChecked(UploadSettings.fullScreen(prefs));
|
||||||
fullScreenSwitch.setOnCheckedChangeListener((btn, checked) -> {
|
fullScreenSwitch.setOnCheckedChangeListener((btn, checked) -> {
|
||||||
@@ -1761,10 +1769,14 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
updateMusicTap();
|
updateMusicTap();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The pumpkin listens only while it can be seen: the app in front, on the Overview, in Halloween. */
|
/**
|
||||||
|
* The pumpkin listens only while it can be seen (the app in front, on the Overview, in
|
||||||
|
* Halloween) and only when "Pumpkin light follows the music" is on.
|
||||||
|
*/
|
||||||
private void updateMusicTap() {
|
private void updateMusicTap() {
|
||||||
ViewPager2 pager = findViewById(R.id.content);
|
ViewPager2 pager = findViewById(R.id.content);
|
||||||
musicTap.setRunning(inFront && overviewStyle() == OverviewStyle.HALLOWEEN
|
musicTap.setRunning(inFront && overviewStyle() == OverviewStyle.HALLOWEEN
|
||||||
|
&& prefs.getBoolean(PREF_MUSIC_LIGHT, false)
|
||||||
&& pager != null && pager.getCurrentItem() == 0);
|
&& pager != null && pager.getCurrentItem() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1828,6 +1840,9 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
TextView note = settingsPane.findViewById(R.id.accent_note);
|
TextView note = settingsPane.findViewById(R.id.accent_note);
|
||||||
note.setVisibility(style.usesAccent ? View.GONE : View.VISIBLE);
|
note.setVisibility(style.usesAccent ? View.GONE : View.VISIBLE);
|
||||||
note.setText(getString(R.string.accent_not_used, styleLabels()[style.ordinal()]));
|
note.setText(getString(R.string.accent_not_used, styleLabels()[style.ordinal()]));
|
||||||
|
int music = style == OverviewStyle.HALLOWEEN ? View.VISIBLE : View.GONE;
|
||||||
|
settingsPane.findViewById(R.id.music_light_switch).setVisibility(music);
|
||||||
|
settingsPane.findViewById(R.id.music_light_hint).setVisibility(music);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The drop-down's labels, by {@link OverviewStyle} ordinal. */
|
/** The drop-down's labels, by {@link OverviewStyle} ordinal. */
|
||||||
|
|||||||
@@ -2,32 +2,45 @@ package com.evsuite.abrp;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* How strongly the Halloween pumpkin's light answers the music at this moment, from 0 to 1, out of
|
* How strongly the Halloween pumpkin's light answers the music at this moment, from 0 to 1, out of
|
||||||
* the bass the audio analyser reports. What counts is the beat, not the loudness: each reading is
|
* the kick drum's band the audio analyser reports. What counts is the hit, not the loudness: only
|
||||||
* placed between the bass's recent average and its recent peak, so quiet and loud songs both
|
* a jump of the bass since the last reading lights it, measured against the biggest jumps of the
|
||||||
* pulse and a steady hum settles at nothing. It rises fast and falls slowly, as a flame does. No
|
* last seconds, so quiet and loud songs both flash, and a held bass note or a steady hum does not.
|
||||||
* reading or silence falls back to 0, so without music the light stays as it is. Android-free and
|
* Jumps that are small against the bass's own level (a swelling note, noise) are ignored. It
|
||||||
* unit-tested.
|
* flares at once and dies down within a beat, as a flame does. No reading or silence falls back to
|
||||||
|
* 0, so without music the light stays as it is. Android-free and unit-tested.
|
||||||
*/
|
*/
|
||||||
final class MusicPulse {
|
final class MusicPulse {
|
||||||
|
|
||||||
/** Below this the bass counts as silence. */
|
/** Below this the bass counts as silence. */
|
||||||
static final float SILENT = 0.005f;
|
static final float SILENT = 0.005f;
|
||||||
private static final float RISE_S = 0.03f, FALL_S = 0.25f, AVERAGE_S = 2f, PEAK_S = 4f;
|
/** The kick drum's band, in Hz, that {@link MusicTap} reads. */
|
||||||
|
static final float FROM_HZ = 40f, TO_HZ = 120f;
|
||||||
|
private static final float FALL_S = 0.2f, AVERAGE_S = 2f, PEAK_S = 4f;
|
||||||
|
/** A jump below this share of the recent biggest one lights nothing. */
|
||||||
|
private static final float THRESHOLD = 0.2f;
|
||||||
|
/** A jump has to be at least this share of the bass's average level to count at all. */
|
||||||
|
private static final float LEVEL_SHARE = 0.5f;
|
||||||
|
|
||||||
private float average, peak, pulse;
|
private float last, average, peakJump, pulse;
|
||||||
|
|
||||||
/** One reading, {@code seconds} after the last; null when it failed. Returns the new pulse. */
|
/** One reading, {@code seconds} after the last; null when it failed. Returns the new pulse. */
|
||||||
float update(Float bass, float seconds) {
|
float update(Float bass, float seconds) {
|
||||||
float target = 0f;
|
float target = 0f;
|
||||||
if (bass == null || bass.isNaN() || bass < SILENT) {
|
if (bass == null || bass.isNaN() || bass < SILENT) {
|
||||||
|
last = 0f;
|
||||||
average = 0f;
|
average = 0f;
|
||||||
peak = 0f;
|
peakJump = 0f;
|
||||||
} else {
|
} else {
|
||||||
|
float jump = Math.max(0f, bass - last);
|
||||||
|
last = bass;
|
||||||
average = average == 0f ? bass : average + (bass - average) * share(seconds, AVERAGE_S);
|
average = average == 0f ? bass : average + (bass - average) * share(seconds, AVERAGE_S);
|
||||||
peak = Math.max(bass, peak - peak * share(seconds, PEAK_S));
|
peakJump = Math.max(jump, peakJump - peakJump * share(seconds, PEAK_S));
|
||||||
if (peak > average) target = Math.max(0f, Math.min(1f, (bass - average) / (peak - average)));
|
float reference = Math.max(peakJump, average * LEVEL_SHARE);
|
||||||
|
if (reference > 0f) {
|
||||||
|
target = Math.max(0f, Math.min(1f, (jump / reference - THRESHOLD) / (1f - THRESHOLD)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pulse += (target - pulse) * share(seconds, target > pulse ? RISE_S : FALL_S);
|
pulse = target > pulse ? target : pulse + (target - pulse) * share(seconds, FALL_S);
|
||||||
if (pulse < 0.005f) pulse = 0f;
|
if (pulse < 0.005f) pulse = 0f;
|
||||||
return pulse;
|
return pulse;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ import android.media.audiofx.Visualizer;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Listens to what the head unit plays for the Halloween pumpkin's light: Android's audio analyser
|
* Listens to what the head unit plays for the Halloween pumpkin's light: Android's audio analyser
|
||||||
* on the output mix, its bass read 25 times a second on a thread of its own, made into a
|
* on the output mix, its kick-drum band read 25 times a second on a thread of its own, made into a
|
||||||
* {@link MusicPulse}. Runs only while MainActivity says so (the style on screen, the app in
|
* {@link MusicPulse}. Runs only while MainActivity says so (the style on screen, the app in
|
||||||
* front). Levels only: no sound is kept and no microphone used. Where the analyser hears nothing
|
* front, and "Pumpkin light follows the music" on). Levels only: no sound is kept and no microphone used. Where the analyser hears nothing
|
||||||
* (the radio) or is not available, the pulse stays 0 and the pumpkin burns as usual.
|
* (the radio) or is not available, the pulse stays 0 and the pumpkin burns as usual.
|
||||||
*/
|
*/
|
||||||
final class MusicTap {
|
final class MusicTap {
|
||||||
@@ -64,7 +64,7 @@ final class MusicTap {
|
|||||||
boolean read = analyser.getFft(fft) == Visualizer.SUCCESS;
|
boolean read = analyser.getFft(fft) == Visualizer.SUCCESS;
|
||||||
failures = read ? 0 : failures + 1;
|
failures = read ? 0 : failures + 1;
|
||||||
long now = System.nanoTime();
|
long now = System.nanoTime();
|
||||||
float value = music.update(read ? SoundLevels.band(fft, rateHz, 20f, 250f) : null, (now - last) / 1e9f);
|
float value = music.update(read ? SoundLevels.band(fft, rateHz, MusicPulse.FROM_HZ, MusicPulse.TO_HZ) : null, (now - last) / 1e9f);
|
||||||
last = now;
|
last = now;
|
||||||
if (worker == me) pulse = value;
|
if (worker == me) pulse = value;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,69 @@
|
|||||||
|
package com.evsuite.abrp;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.ConnectException;
|
||||||
|
import java.net.NoRouteToHostException;
|
||||||
|
import java.net.SocketException;
|
||||||
|
import java.net.SocketTimeoutException;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import javax.net.ssl.SSLException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Why an update check failed, in words for the update log, and what the car's networks look
|
||||||
|
* like. Built from an error's type and an HTTP status only, because an error's own text can carry
|
||||||
|
* the server's address: nothing here holds a URL or a credential. Android-free and unit-tested.
|
||||||
|
*/
|
||||||
|
final class UpdateDiagnosis {
|
||||||
|
|
||||||
|
private static final Pattern STATUS = Pattern.compile("^Release API returned (\\d{3})$");
|
||||||
|
|
||||||
|
private UpdateDiagnosis() {}
|
||||||
|
|
||||||
|
/** One line about a failed step. */
|
||||||
|
static String failure(Throwable t) {
|
||||||
|
if (t == null) return "unknown failure";
|
||||||
|
String type = " (" + t.getClass().getSimpleName() + ")";
|
||||||
|
if (t instanceof UnknownHostException) return "the name could not be looked up: no data connection, or no name service" + type;
|
||||||
|
if (t instanceof SocketTimeoutException) return "no answer in time: a very slow or blocked connection" + type;
|
||||||
|
if (t instanceof ConnectException || t instanceof NoRouteToHostException) return "no connection could be made" + type;
|
||||||
|
if (t instanceof SSLException) return "the secure connection failed: something in between may have answered, or the head unit's clock is wrong" + type;
|
||||||
|
if (t instanceof SocketException) return "the connection broke off" + type;
|
||||||
|
if (t instanceof IOException && t.getMessage() != null) {
|
||||||
|
Matcher status = STATUS.matcher(t.getMessage());
|
||||||
|
if (status.matches()) return status(Integer.parseInt(status.group(1)));
|
||||||
|
if (t.getMessage().equals("Invalid release response")) return "the answer was not a list of releases";
|
||||||
|
}
|
||||||
|
return "failed" + type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** What a status from the car server means here. */
|
||||||
|
static String status(int code) {
|
||||||
|
String what;
|
||||||
|
if (code >= 300 && code < 400) what = "something in between redirected it, as a SIM without data may";
|
||||||
|
else if (code == 401 || code == 403) what = "the server refuses the car's token";
|
||||||
|
else if (code == 404) what = "the server does not know this address";
|
||||||
|
else if (code >= 500) what = "the server or the forge behind it has a problem";
|
||||||
|
else what = "not what was expected";
|
||||||
|
return "the server answered HTTP " + code + ": " + what;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The outside-world test: a 204 is the internet working; anything else stands in between. */
|
||||||
|
static String internet(int code) {
|
||||||
|
if (code == 204) return "the internet works (HTTP 204)";
|
||||||
|
return "something in between answered HTTP " + code + " instead, as a SIM without data may";
|
||||||
|
}
|
||||||
|
|
||||||
|
/** One network as Android sees it. */
|
||||||
|
static String network(List<String> transports, boolean internet, boolean validated,
|
||||||
|
boolean active, boolean roaming) {
|
||||||
|
return (transports.isEmpty() ? "unknown type" : String.join("+", transports))
|
||||||
|
+ (active ? ", in use" : "")
|
||||||
|
+ (internet ? ", offers internet" : ", no internet")
|
||||||
|
+ (validated ? ", confirmed by Android" : ", not confirmed by Android")
|
||||||
|
+ (roaming ? ", roaming" : "");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,7 +21,7 @@ import java.util.Locale;
|
|||||||
*/
|
*/
|
||||||
final class UpdateLog {
|
final class UpdateLog {
|
||||||
|
|
||||||
static final int MAX_LINES = 10;
|
static final int MAX_LINES = 40;
|
||||||
private static final String PREFS = "update_log";
|
private static final String PREFS = "update_log";
|
||||||
private static final String KEY = "lines";
|
private static final String KEY = "lines";
|
||||||
private static final String KEY_VERSION = "version";
|
private static final String KEY_VERSION = "version";
|
||||||
|
|||||||
@@ -26,6 +26,9 @@
|
|||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
<TextView android:id="@+id/accent_note" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="4dp" android:textAppearance="@style/Text.EV.Secondary" android:visibility="gone" />
|
<TextView android:id="@+id/accent_note" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="4dp" android:textAppearance="@style/Text.EV.Secondary" android:visibility="gone" />
|
||||||
|
<!-- Only Halloween listens to the music. -->
|
||||||
|
<com.google.android.material.switchmaterial.SwitchMaterial android:id="@+id/music_light_switch" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="72dp" android:text="@string/label_music_light" android:textAppearance="@style/Text.EV.Body" android:paddingTop="8dp" android:paddingBottom="8dp" app:useMaterialThemeColors="true" app:thumbTint="@color/switch_thumb" app:trackTint="@color/switch_track" android:textColor="@color/ev_text_primary" android:visibility="gone" />
|
||||||
|
<TextView android:id="@+id/music_light_hint" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/hint_music_light" android:textAppearance="@style/Text.EV.Secondary" android:visibility="gone" />
|
||||||
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:baselineAligned="false">
|
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:baselineAligned="false">
|
||||||
<LinearLayout android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:layout_marginEnd="12dp" android:orientation="vertical">
|
<LinearLayout android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:layout_marginEnd="12dp" android:orientation="vertical">
|
||||||
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/label_tire_unit" android:textAppearance="@style/Text.EV.Body" android:layout_marginTop="8dp" />
|
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/label_tire_unit" android:textAppearance="@style/Text.EV.Body" android:layout_marginTop="8dp" />
|
||||||
|
|||||||
@@ -17,6 +17,9 @@
|
|||||||
<com.google.android.material.textfield.MaterialAutoCompleteTextView android:id="@+id/accent_choices" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="72dp" android:inputType="none" android:textSize="20sp" app:simpleItemLayout="@layout/dropdown_item" />
|
<com.google.android.material.textfield.MaterialAutoCompleteTextView android:id="@+id/accent_choices" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="72dp" android:inputType="none" android:textSize="20sp" app:simpleItemLayout="@layout/dropdown_item" />
|
||||||
</com.google.android.material.textfield.TextInputLayout>
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
<TextView android:id="@+id/accent_note" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="4dp" android:textAppearance="@style/Text.EV.Secondary" android:visibility="gone" />
|
<TextView android:id="@+id/accent_note" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="4dp" android:textAppearance="@style/Text.EV.Secondary" android:visibility="gone" />
|
||||||
|
<!-- Only Halloween listens to the music. -->
|
||||||
|
<com.google.android.material.switchmaterial.SwitchMaterial android:id="@+id/music_light_switch" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="72dp" android:text="@string/label_music_light" android:textAppearance="@style/Text.EV.Body" android:paddingTop="8dp" android:paddingBottom="8dp" app:useMaterialThemeColors="true" app:thumbTint="@color/switch_thumb" app:trackTint="@color/switch_track" android:textColor="@color/ev_text_primary" android:visibility="gone" />
|
||||||
|
<TextView android:id="@+id/music_light_hint" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/hint_music_light" android:textAppearance="@style/Text.EV.Secondary" android:visibility="gone" />
|
||||||
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/label_tire_unit" android:textAppearance="@style/Text.EV.Body" android:layout_marginTop="20dp" />
|
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/label_tire_unit" android:textAppearance="@style/Text.EV.Body" android:layout_marginTop="20dp" />
|
||||||
<com.google.android.material.textfield.TextInputLayout style="@style/Widget.EV.Dropdown" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="12dp">
|
<com.google.android.material.textfield.TextInputLayout style="@style/Widget.EV.Dropdown" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="12dp">
|
||||||
<com.google.android.material.textfield.MaterialAutoCompleteTextView android:id="@+id/tire_unit_choices" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="72dp" android:inputType="none" android:textSize="20sp" app:simpleItemLayout="@layout/dropdown_item" />
|
<com.google.android.material.textfield.MaterialAutoCompleteTextView android:id="@+id/tire_unit_choices" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="72dp" android:inputType="none" android:textSize="20sp" app:simpleItemLayout="@layout/dropdown_item" />
|
||||||
|
|||||||
@@ -129,6 +129,8 @@
|
|||||||
<string name="overview_style_scifi">Sci-fi</string>
|
<string name="overview_style_scifi">Sci-fi</string>
|
||||||
<string name="overview_style_cartoon">Cartoon</string>
|
<string name="overview_style_cartoon">Cartoon</string>
|
||||||
<string name="overview_style_mg">MG</string>
|
<string name="overview_style_mg">MG</string>
|
||||||
|
<string name="label_music_light">Pumpkin light follows the music</string>
|
||||||
|
<string name="hint_music_light">Flares on the kick drum over Bluetooth or CarPlay, not the radio. Levels only, no sound kept.</string>
|
||||||
<string name="accent_not_used">%1$s has its own colours, and the app takes them on. To change the accent colour, pick a style that uses it.</string>
|
<string name="accent_not_used">%1$s has its own colours, and the app takes them on. To change the accent colour, pick a style that uses it.</string>
|
||||||
<string name="overview_fullscreen_enter">Overview full screen: hide the navigation</string>
|
<string name="overview_fullscreen_enter">Overview full screen: hide the navigation</string>
|
||||||
<string name="overview_fullscreen_exit">Show the navigation again</string>
|
<string name="overview_fullscreen_exit">Show the navigation again</string>
|
||||||
|
|||||||
@@ -36,6 +36,45 @@ public class MusicPulseTest {
|
|||||||
assertEquals(0f, last, 0f);
|
assertEquals(0f, last, 0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void aHeldBassNoteLightsOnlyItsStart() {
|
||||||
|
MusicPulse p = new MusicPulse();
|
||||||
|
for (int i = 0; i < 50; i++) p.update(0.05f, STEP);
|
||||||
|
assertTrue(p.update(0.4f, STEP) > 0.8f);
|
||||||
|
float last = 1f;
|
||||||
|
for (int i = 0; i < 25; i++) last = p.update(0.4f, STEP);
|
||||||
|
assertEquals(0f, last, 0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void aWobblingBassLineStaysDark() {
|
||||||
|
MusicPulse p = new MusicPulse();
|
||||||
|
for (int i = 0; i < 50; i++) p.update(0.3f, STEP);
|
||||||
|
float top = 0f;
|
||||||
|
for (int i = 0; i < 200; i++) top = Math.max(top, p.update(i % 3 == 0 ? 0.33f : 0.3f, STEP));
|
||||||
|
assertEquals(0f, top, 0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void aSwellingNoteStaysDark() {
|
||||||
|
MusicPulse p = new MusicPulse();
|
||||||
|
for (int i = 0; i < 50; i++) p.update(0.1f, STEP);
|
||||||
|
float top = 0f;
|
||||||
|
for (int i = 0; i < 100; i++) top = Math.max(top, p.update(0.1f + i * 0.004f, STEP));
|
||||||
|
assertEquals(0f, top, 0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void aKickOverABassLineLights() {
|
||||||
|
MusicPulse p = new MusicPulse();
|
||||||
|
float top = 0f;
|
||||||
|
for (int i = 0; i < 300; i++) {
|
||||||
|
float v = p.update(i % 12 == 0 ? 0.6f : (i % 3 == 0 ? 0.33f : 0.3f), STEP);
|
||||||
|
if (i > 100) top = Math.max(top, v);
|
||||||
|
}
|
||||||
|
assertTrue("a kick lights it, got " + top, top > 0.8f);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void quietAndLoudSongsPulseAlike() {
|
public void quietAndLoudSongsPulseAlike() {
|
||||||
assertEquals(beatOf(0.5f), beatOf(0.05f), 0.02f);
|
assertEquals(beatOf(0.5f), beatOf(0.05f), 0.02f);
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
package com.evsuite.abrp;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.ConnectException;
|
||||||
|
import java.net.SocketTimeoutException;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import javax.net.ssl.SSLHandshakeException;
|
||||||
|
|
||||||
|
public class UpdateDiagnosisTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void errorsAreToldApart() {
|
||||||
|
assertTrue(UpdateDiagnosis.failure(new UnknownHostException()).contains("no data connection"));
|
||||||
|
assertTrue(UpdateDiagnosis.failure(new SocketTimeoutException()).contains("in time"));
|
||||||
|
assertTrue(UpdateDiagnosis.failure(new ConnectException()).contains("no connection"));
|
||||||
|
assertTrue(UpdateDiagnosis.failure(new SSLHandshakeException("x")).contains("in between"));
|
||||||
|
assertTrue(UpdateDiagnosis.failure(new IOException("Release API returned 401")).contains("token"));
|
||||||
|
assertTrue(UpdateDiagnosis.failure(new IOException("Invalid release response")).contains("not a list"));
|
||||||
|
assertEquals("unknown failure", UpdateDiagnosis.failure(null));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void anErrorsOwnTextNeverReachesTheLog() {
|
||||||
|
String secret = "https://car.example.com/v1/app/releases?token=abc";
|
||||||
|
for (Throwable t : Arrays.asList(new UnknownHostException(secret), new SocketTimeoutException(secret),
|
||||||
|
new ConnectException(secret), new SSLHandshakeException(secret), new IOException(secret),
|
||||||
|
new RuntimeException(secret))) {
|
||||||
|
String line = UpdateDiagnosis.failure(t);
|
||||||
|
assertFalse(line, line.contains("example"));
|
||||||
|
assertFalse(line, line.contains("abc"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void statusesSayWhoIsAtFault() {
|
||||||
|
assertTrue(UpdateDiagnosis.status(302).contains("SIM without data"));
|
||||||
|
assertTrue(UpdateDiagnosis.status(401).contains("token"));
|
||||||
|
assertTrue(UpdateDiagnosis.status(403).contains("token"));
|
||||||
|
assertTrue(UpdateDiagnosis.status(404).contains("does not know"));
|
||||||
|
assertTrue(UpdateDiagnosis.status(502).contains("forge"));
|
||||||
|
assertTrue(UpdateDiagnosis.status(418).contains("HTTP 418"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onlyA204IsTheInternetWorking() {
|
||||||
|
assertTrue(UpdateDiagnosis.internet(204).startsWith("the internet works"));
|
||||||
|
assertTrue(UpdateDiagnosis.internet(200).contains("in between"));
|
||||||
|
assertTrue(UpdateDiagnosis.internet(302).contains("SIM without data"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void aNetworkInOneLine() {
|
||||||
|
assertEquals("cellular, in use, offers internet, not confirmed by Android, roaming",
|
||||||
|
UpdateDiagnosis.network(Collections.singletonList("cellular"), true, false, true, true));
|
||||||
|
assertEquals("unknown type, no internet, confirmed by Android",
|
||||||
|
UpdateDiagnosis.network(Collections.emptyList(), false, true, false, false));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,6 +18,8 @@
|
|||||||
android:name="android.permission.MEDIA_CONTENT_CONTROL"
|
android:name="android.permission.MEDIA_CONTENT_CONTROL"
|
||||||
tools:ignore="ProtectedPermissions" />
|
tools:ignore="ProtectedPermissions" />
|
||||||
|
|
||||||
|
<!-- An update check writes down which networks Android sees (UpdateNetworkCheck). -->
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
<!-- The Logs tab's sound check (SoundProbe): Android's audio analyser asks for both. The
|
<!-- The Logs tab's sound check (SoundProbe): Android's audio analyser asks for both. The
|
||||||
system user holds them without a prompt; the analyser reports levels only, no sound. -->
|
system user holds them without a prompt; the analyser reports levels only, no sound. -->
|
||||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||||
|
|||||||
@@ -55,6 +55,9 @@ final class OtaUpdater {
|
|||||||
private static final String TAG = "OtaUpdater";
|
private static final String TAG = "OtaUpdater";
|
||||||
private static final String CACHE_PREFIX = "NilsMG4-ota-";
|
private static final String CACHE_PREFIX = "NilsMG4-ota-";
|
||||||
|
|
||||||
|
/** Why the last download failed, for the update log. */
|
||||||
|
static volatile String downloadProblem = "unknown";
|
||||||
|
|
||||||
/** The release list on the car server, for the server configured in the app. */
|
/** The release list on the car server, for the server configured in the app. */
|
||||||
static String releasesUrl(ServerConfig config) {
|
static String releasesUrl(ServerConfig config) {
|
||||||
return config.url + "/v1/app/releases";
|
return config.url + "/v1/app/releases";
|
||||||
@@ -366,6 +369,7 @@ final class OtaUpdater {
|
|||||||
connection.setRequestProperty("User-Agent", "NilsMG4-Android");
|
connection.setRequestProperty("User-Agent", "NilsMG4-Android");
|
||||||
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
|
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
|
||||||
Log.w(TAG, "Update download returned " + connection.getResponseCode());
|
Log.w(TAG, "Update download returned " + connection.getResponseCode());
|
||||||
|
downloadProblem = UpdateDiagnosis.status(connection.getResponseCode());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
long total = connection.getContentLengthLong();
|
long total = connection.getContentLengthLong();
|
||||||
@@ -390,10 +394,14 @@ final class OtaUpdater {
|
|||||||
out.getFD().sync();
|
out.getFD().sync();
|
||||||
}
|
}
|
||||||
ok = hex(digest.digest()).equalsIgnoreCase(expectedSha256);
|
ok = hex(digest.digest()).equalsIgnoreCase(expectedSha256);
|
||||||
if (!ok) Log.w(TAG, "Update APK does not match its SHA-256");
|
if (!ok) {
|
||||||
|
Log.w(TAG, "Update APK does not match its SHA-256");
|
||||||
|
downloadProblem = "it does not match its SHA-256";
|
||||||
|
}
|
||||||
return ok ? target : null;
|
return ok ? target : null;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.w(TAG, "Update download failed: " + e.getClass().getSimpleName());
|
Log.w(TAG, "Update download failed: " + e.getClass().getSimpleName());
|
||||||
|
downloadProblem = UpdateDiagnosis.failure(e);
|
||||||
return null;
|
return null;
|
||||||
} finally {
|
} finally {
|
||||||
if (connection != null) connection.disconnect();
|
if (connection != null) connection.disconnect();
|
||||||
|
|||||||
@@ -5,6 +5,11 @@ import android.util.Log;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -58,7 +63,8 @@ final class UpdateHook {
|
|||||||
"Update available: " + update.versionName,
|
"Update available: " + update.versionName,
|
||||||
android.widget.Toast.LENGTH_LONG).show());
|
android.widget.Toast.LENGTH_LONG).show());
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
Log.w(TAG, "Startup update check failed", t);
|
Log.w(TAG, "Startup update check failed: " + t.getClass().getSimpleName());
|
||||||
|
UpdateLog.record(app, "Check at start: " + UpdateDiagnosis.failure(t));
|
||||||
}
|
}
|
||||||
}, "ota-startup-check").start();
|
}, "ota-startup-check").start();
|
||||||
}
|
}
|
||||||
@@ -78,24 +84,46 @@ final class UpdateHook {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
|
long startedMs = System.currentTimeMillis();
|
||||||
|
List<String> steps = new ArrayList<>();
|
||||||
|
step(app, steps, "Check started, app " + BuildConfig.VERSION_NAME);
|
||||||
String message;
|
String message;
|
||||||
try {
|
try {
|
||||||
|
for (String network : UpdateNetworkCheck.networks(app)) step(app, steps, network);
|
||||||
|
ServerConfig config = ServerConfig.get(app);
|
||||||
|
String host = config.isConfigured() ? OtaUpdater.allowedHost(config) : null;
|
||||||
|
if (host != null) step(app, steps, UpdateNetworkCheck.lookup(host));
|
||||||
message = runCheck(app, listener, main);
|
message = runCheck(app, listener, main);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
Log.w(TAG, "Update check threw", t);
|
Log.w(TAG, "Update check threw: " + t.getClass().getSimpleName());
|
||||||
// The class only: a network error's text can carry the server's address.
|
message = "Update check failed: " + UpdateDiagnosis.failure(t);
|
||||||
message = "Update check failed (" + t.getClass().getSimpleName() + ")";
|
// Is it the server or the connection? The answer to "is my SIM out of data".
|
||||||
|
step(app, steps, UpdateNetworkCheck.internet());
|
||||||
} finally {
|
} finally {
|
||||||
checking.set(false);
|
checking.set(false);
|
||||||
}
|
}
|
||||||
UpdateLog.record(app, "Check: " + message);
|
step(app, steps, "Check: " + message);
|
||||||
|
String waiting = LogOutbox.status(app);
|
||||||
|
if (waiting != null) step(app, steps, "Reports: " + waiting);
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
final String result = message;
|
final String result = message;
|
||||||
main.post(() -> listener.onResult(result));
|
main.post(() -> listener.onResult(result));
|
||||||
}
|
}
|
||||||
|
// After the answer: without a connection this waits for the send to fail.
|
||||||
|
String name = "update-check-" + new SimpleDateFormat("yyyyMMdd-HHmmss", Locale.US)
|
||||||
|
.format(new Date(startedMs)) + ".txt";
|
||||||
|
// Only the newest waits: repeated checks offline must not push out a recording.
|
||||||
|
LogOutbox.dropWaiting(app, "update-check-");
|
||||||
|
SignalRecorder.saveCopies(app, "update_check.txt", name, steps);
|
||||||
}, "ota-check").start();
|
}, "ota-check").start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** One step of a check: on the Logs tab now, and in the report saved when it ends. */
|
||||||
|
private static void step(Context app, List<String> steps, String what) {
|
||||||
|
UpdateLog.record(app, what);
|
||||||
|
steps.add(what);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Installs the newest car build from the top folder of a USB stick (UsbUpdate), with the
|
* Installs the newest car build from the top folder of a USB stick (UsbUpdate), with the
|
||||||
* same checks as the over-the-air update except the server. Background thread; [listener]
|
* same checks as the over-the-air update except the server. Background thread; [listener]
|
||||||
@@ -195,14 +223,14 @@ final class UpdateHook {
|
|||||||
try {
|
try {
|
||||||
expectedHash = OtaUpdater.fetchExpectedSha256(update, config);
|
expectedHash = OtaUpdater.fetchExpectedSha256(update, config);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.w(TAG, "OTA hash unavailable: " + e.getMessage());
|
Log.w(TAG, "OTA hash unavailable: " + e.getClass().getSimpleName());
|
||||||
return "Update refused: no SHA-256 verification";
|
return "Update refused, no SHA-256 verification: " + UpdateDiagnosis.failure(e);
|
||||||
}
|
}
|
||||||
File apk = OtaUpdater.download(update, expectedHash, config, percent -> {
|
File apk = OtaUpdater.download(update, expectedHash, config, percent -> {
|
||||||
if (listener != null) main.post(() -> listener.onProgress(percent));
|
if (listener != null) main.post(() -> listener.onProgress(percent));
|
||||||
});
|
});
|
||||||
if (apk == null) return "Download or SHA-256 verification failed ("
|
if (apk == null) return "Download or SHA-256 verification failed ("
|
||||||
+ update.versionName + ")";
|
+ update.versionName + "): " + OtaUpdater.downloadProblem;
|
||||||
|
|
||||||
switch (OtaUpdater.install(app, apk)) {
|
switch (OtaUpdater.install(app, apk)) {
|
||||||
case SESSION_STARTED:
|
case SESSION_STARTED:
|
||||||
|
|||||||
@@ -0,0 +1,92 @@
|
|||||||
|
package com.evsuite.abrp;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.Network;
|
||||||
|
import android.net.NetworkCapabilities;
|
||||||
|
import android.net.NetworkInfo;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* What an update check writes down about the connection before and after it fails: the networks
|
||||||
|
* Android sees, whether the server's name can be looked up, and whether the internet answers at
|
||||||
|
* all, which tells a SIM without data from a server that is down. Blocking: background thread.
|
||||||
|
* Never logs the server's address or anything about the car. — UNSTABLE BUILDS ONLY.
|
||||||
|
*/
|
||||||
|
final class UpdateNetworkCheck {
|
||||||
|
|
||||||
|
/** Android's own connectivity test, as Android itself uses it; no data about the car is sent. */
|
||||||
|
private static final String INTERNET_TEST = "https://www.gstatic.com/generate_204";
|
||||||
|
private static final int TIMEOUT_MS = 10_000;
|
||||||
|
|
||||||
|
private UpdateNetworkCheck() {}
|
||||||
|
|
||||||
|
/** One line per network, or one saying there is none. */
|
||||||
|
static List<String> networks(Context app) {
|
||||||
|
List<String> out = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
ConnectivityManager cm = (ConnectivityManager) app.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
if (cm == null) {
|
||||||
|
out.add("Network: no connectivity service");
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
Network active = cm.getActiveNetwork();
|
||||||
|
if (active == null) out.add("Network: none in use");
|
||||||
|
for (Network network : cm.getAllNetworks()) {
|
||||||
|
NetworkCapabilities caps = cm.getNetworkCapabilities(network);
|
||||||
|
if (caps == null) continue;
|
||||||
|
NetworkInfo info = cm.getNetworkInfo(network);
|
||||||
|
out.add("Network: " + UpdateDiagnosis.network(transports(caps),
|
||||||
|
caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET),
|
||||||
|
caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED),
|
||||||
|
network.equals(active), info != null && info.isRoaming()));
|
||||||
|
}
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
out.add("Network: unreadable (" + e.getClass().getSimpleName() + ")");
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<String> transports(NetworkCapabilities caps) {
|
||||||
|
List<String> out = new ArrayList<>();
|
||||||
|
if (caps.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) out.add("cellular");
|
||||||
|
if (caps.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) out.add("Wi-Fi");
|
||||||
|
if (caps.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET)) out.add("ethernet");
|
||||||
|
if (caps.hasTransport(NetworkCapabilities.TRANSPORT_BLUETOOTH)) out.add("Bluetooth");
|
||||||
|
if (caps.hasTransport(NetworkCapabilities.TRANSPORT_VPN)) out.add("VPN");
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Whether the host's name resolves, without saying the name. */
|
||||||
|
static String lookup(String host) {
|
||||||
|
long started = System.currentTimeMillis();
|
||||||
|
try {
|
||||||
|
InetAddress.getByName(host);
|
||||||
|
return "Server's name: found in " + (System.currentTimeMillis() - started) + " ms";
|
||||||
|
} catch (IOException | RuntimeException e) {
|
||||||
|
return "Server's name: " + UpdateDiagnosis.failure(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Whether the world outside the car server answers. */
|
||||||
|
static String internet() {
|
||||||
|
HttpURLConnection conn = null;
|
||||||
|
try {
|
||||||
|
conn = (HttpURLConnection) new URL(INTERNET_TEST).openConnection();
|
||||||
|
conn.setInstanceFollowRedirects(false);
|
||||||
|
conn.setConnectTimeout(TIMEOUT_MS);
|
||||||
|
conn.setReadTimeout(TIMEOUT_MS);
|
||||||
|
return "Internet test: " + UpdateDiagnosis.internet(conn.getResponseCode());
|
||||||
|
} catch (IOException | RuntimeException e) {
|
||||||
|
return "Internet test: " + UpdateDiagnosis.failure(e);
|
||||||
|
} finally {
|
||||||
|
if (conn != null) conn.disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user